@Test
public void testPutGroup() {

    final String domainName = "put-group-test";
    final String groupName1 = "group1";
    final String groupName2 = "group2";
    final String groupName3 = "group3";
    ZMSClient client = createClient(systemAdminUser);
    ZMSRDLGeneratedClient c = Mockito.mock(ZMSRDLGeneratedClient.class);
    client.setZMSRDLGeneratedClient(c);
    TopLevelDomain dom1Mock = Mockito.mock(TopLevelDomain.class);
    Domain domainMock = Mockito.mock(Domain.class);
    Mockito.when(c.postTopLevelDomain(AUDIT_REF, dom1Mock)).thenReturn(domainMock);
    Group group1 = createGroupObject(client, domainName, groupName1, "user.joe", "user.jane");
    Mockito.when(c.putGroup(domainName, groupName1, AUDIT_REF, group1)).thenReturn(group1);
    Mockito.when(c.getGroup(domainName, groupName1, false, false)).thenReturn(group1);
    Mockito.when(c.putGroup(domainName, groupName2, AUDIT_REF, group1)).thenThrow(new NullPointerException());
    Mockito.when(c.putGroup(domainName, groupName3, AUDIT_REF, group1)).thenThrow(new ResourceException(404));
    Mockito.when(c.getGroup(domainName, groupName2, false, false)).thenThrow(new NullPointerException());
    Mockito.when(c.getGroup(domainName, groupName3, false, false)).thenThrow(new ResourceException(404));
    TopLevelDomain dom1 = createTopLevelDomainObject(domainName,
            "Test Domain1", "testOrg", systemAdminUser);
    client.postTopLevelDomain(AUDIT_REF, dom1);
    client.putGroup(domainName, groupName1, AUDIT_REF, group1);
    Group group1Res = client.getGroup(domainName, groupName1, false, false);
    assertNotNull(group1Res);
    assertEquals(group1Res.getName(), domainName + ":group." + groupName1);
    try {
        client.putGroup(domainName, groupName2, AUDIT_REF, group1);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), 400);
    }
    try {
        client.putGroup(domainName, groupName3, AUDIT_REF, group1);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), 404);
    }
    try {
        client.getGroup(domainName, groupName2, false, false);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), 400);
    }
    try {
        client.getGroup(domainName, groupName3, false, false);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), 404);
    }
    client.deleteTopLevelDomain(domainName, AUDIT_REF);
}