@Test
public void testDeleteDomainTemplate() {

    ZMSClient client = createClient(systemAdminUser);
    String domName = "templesofold";
    String domName2 = "templesofold2";
    try {
        client.deleteTopLevelDomain(domName, AUDIT_REF);
    } catch (ZMSClientException ex) {
        // ignore cleanup errors - e.g. not found
    }
    TopLevelDomain dom1 = createTopLevelDomainObject(domName,
            "Test Domain", "testOrg", systemAdminFullUser);
    ZMSRDLGeneratedClient c = Mockito.mock(ZMSRDLGeneratedClient.class);
    client.setZMSRDLGeneratedClient(c);
    Domain domainMock = Mockito.mock(Domain.class);
    Mockito.when(c.postTopLevelDomain(AUDIT_REF, dom1)).thenReturn(domainMock);
    client.postTopLevelDomain(AUDIT_REF, dom1);
    ServerTemplateList svrTemplListMock = Mockito.mock(ServerTemplateList.class);
    @SuppressWarnings("unchecked")
    List<String> svrTemplNamesMock = Mockito.mock(List.class);
    Mockito.when(c.getServerTemplateList()).thenReturn(svrTemplListMock);
    ServerTemplateList svrTemplList = client.getServerTemplateList();
    Mockito.when(svrTemplListMock.getTemplateNames()).thenReturn(svrTemplNamesMock);
    List<String> svrTemplNames = svrTemplList.getTemplateNames();
    DomainTemplate domTempl = new DomainTemplate().setTemplateNames(svrTemplNames);
    client.putDomainTemplate(domName, AUDIT_REF, domTempl);
    DomainTemplateList domTemplListMock = Mockito.mock(DomainTemplateList.class);
    Mockito.when(c.getDomainTemplateList(domName)).thenReturn(domTemplListMock);
    DomainTemplateList domTemplList = client.getDomainTemplateList(domName);
    assertNotNull(domTemplList);
    try {
        Mockito.when(c.getDomainTemplateList(domName2)).thenThrow(new NullPointerException())
                .thenThrow(new ResourceException(404));
        client.getDomainTemplateList(domName2);
        fail();
    } catch (ResourceException ex) {
        assertTrue(true);
    }
    try {
        client.getDomainTemplateList(domName2);
        fail();
    } catch (ResourceException ex) {
        assertTrue(true);
    }
    List<String> templNames = domTemplList.getTemplateNames();
    assertNotNull(templNames);
    assertEquals(templNames.size(), svrTemplNames.size());
    // HAVE: domain has all the templates
    // domain has multiple templates: deleting 1 at a time
    for (int cnt = 0; cnt < svrTemplNames.size(); ++cnt) {
        client.deleteDomainTemplate(domName, svrTemplNames.get(cnt), AUDIT_REF);
        domTemplList = client.getDomainTemplateList(domName);
        assertNotNull(domTemplList);
        templNames = domTemplList.getTemplateNames();
        assertNotNull(templNames);
        int templCnt = svrTemplNames.size() - (cnt + 1);
        assertEquals(templNames.size(), templCnt, "template should be count=" + templCnt);
        for (int cnt2 = cnt + 1; cnt2 < svrTemplNames.size(); ++cnt2) {
            assertTrue(templNames.contains(svrTemplNames.get(cnt2)), "should contain=" + svrTemplNames.get(cnt2));
        }
    }
    client.deleteTopLevelDomain(domName, AUDIT_REF);
}