@Test
public void testGetPrincipal() {

    String zmsUrl = getZMSUrl();
    ZMSClient client = new ZMSClient(zmsUrl);
    ZMSRDLGeneratedClient c = Mockito.mock(ZMSRDLGeneratedClient.class);
    client.setZMSRDLGeneratedClient(c);
    try {
        client.getPrincipal("serviceToken", null);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), 401);
    }
    try {
        client.getPrincipal("v=S1;d=domain;s=signature", null);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), 401);
    }
    ServicePrincipal svcPrincipal = new ServicePrincipal().setDomain("domain").setService("service");
    Mockito.when(c.getServicePrincipal())
            .thenThrow(new ResourceException(403))
            .thenThrow(new NullPointerException())
            .thenReturn(null)
            .thenReturn(svcPrincipal);
    //                .thenThrow(new ResourceException(403))
    try {
        client.getPrincipal("v=S1;d=domain;n=service;s=signature", null);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), 403);
    }
    //                .thenThrow(new NullPointerException())
    try {
        client.getPrincipal("v=S1;d=domain;n=service;s=signature", null);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), 400);
    }
    //                .thenReturn(null)
    try {
        client.getPrincipal("v=S1;d=domain;n=service;s=signature", null);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), 401);
    }
    //                .thenReturn(svcPrincipal);
    assertNotNull(client.getPrincipal("v=S1;d=domain;n=service;s=signature", null));
    try {
        client.getPrincipal("v=S1;d=domain1;n=service;s=signature", null);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), 401);
    }
    try {
        client.getPrincipal("v=S1;d=domain;n=service1;s=signature", null);
        fail();
    } catch (ResourceException ex) {
        assertEquals(ex.getCode(), 401);
    }
}