@Test
public void testGetPolicy() {

    TestAuditLogger alogger = new TestAuditLogger();
    List<String> aLogMsgs = alogger.getLogMsgList();
    ZMSImpl zmsImpl = getZmsImpl(alogger);
    TopLevelDomain dom1 = createTopLevelDomainObject("PolicyGetDom1",
            "Test Domain1", "testOrg", adminUser);
    Mockito.when(mockDomRsrcCtx.getApiName()).thenReturn("posttopleveldomain").thenReturn("putpolicy");
    zmsImpl.postTopLevelDomain(mockDomRsrcCtx, auditRef, dom1);
    Policy policy1 = createPolicyObject("PolicyGetDom1", "Policy1");
    zmsImpl.putPolicy(mockDomRsrcCtx, "PolicyGetDom1", "Policy1", auditRef, policy1);
    Policy policy = zmsImpl.getPolicy(mockDomRsrcCtx, "PolicyGetDom1", "Policy1");
    assertNotNull(policy);
    assertEquals(policy.getName(), "PolicyGetDom1:policy.Policy1".toLowerCase());
    List<Assertion> assertList = policy.getAssertions();
    assertNotNull(assertList);
    assertEquals(assertList.size(), 1);
    Assertion obj = assertList.get(0);
    assertEquals(obj.getAction(), "*");
    assertEquals(obj.getEffect(), AssertionEffect.ALLOW);
    assertEquals(obj.getResource(), "policygetdom1:*");
    assertEquals(obj.getRole(), "PolicyGetDom1:role.Role1".toLowerCase());
    boolean foundError = false;
    System.err.println("testGetPolicy: Number of lines: " + aLogMsgs.size());
    for (String msg: aLogMsgs) {
        if (!msg.contains("WHAT-api=(putpolicy)")) {
            continue;
        }
        assertTrue(msg.contains("CLIENT-IP=(" + MOCKCLIENTADDR + ")"), msg);
        int index = msg.indexOf("WHAT-details=(");
        assertTrue(index != -1, msg);
        int index2 = msg.indexOf("\"added-assertions\": [{\"role\": \"policygetdom1:role.role1\", \"action\": \"*\", \"effect\": \"ALLOW\", \"resource\": \"policygetdom1:*\"}]");
        assertTrue(index < index2, msg);
        index2 = msg.indexOf("ERROR");
        assertEquals(index2, -1, msg);
        foundError = true;
        break;
    }
    assertTrue(foundError);
    // modify the assertion: result is add of new assertion, delete of old
    //
    obj.setAction("layup");
    obj.setEffect(AssertionEffect.DENY);
    List<Assertion> assertions = new ArrayList<>();
    assertions.add(obj);
    policy1.setAssertions(assertions);
    aLogMsgs.clear();
    zmsImpl.putPolicy(mockDomRsrcCtx, "PolicyGetDom1", "Policy1", auditRef, policy1);
    foundError = false;
    System.err.println("testGetPolicy: Number of lines: " + aLogMsgs.size());
    for (String msg: aLogMsgs) {
        if (!msg.contains("WHAT-api=(putpolicy)")) {
            continue;
        }
        assertTrue(msg.contains("CLIENT-IP=(" + MOCKCLIENTADDR + ")"), msg);
        int index = msg.indexOf("WHAT-details=(");
        assertTrue(index != -1, msg);
        int index2 = msg.indexOf("\"added-assertions\": [{\"role\": \"policygetdom1:role.role1\", \"action\": \"layup\", \"effect\": \"DENY\", \"resource\": \"policygetdom1:*\"}]");
        assertTrue(index < index2, msg);
        index2 = msg.indexOf("ERROR");
        assertEquals(index2, -1, msg);
        foundError = true;
        break;
    }
    assertTrue(foundError);
    // this should throw an exception
    try {
        zmsImpl.getPolicy(mockDomRsrcCtx, "PolicyGetDom1", "Policy2");
        fail();
    } catch (Exception ex) {
        assertTrue(true);
    }
    zmsImpl.deleteTopLevelDomain(mockDomRsrcCtx, "PolicyGetDom1", auditRef);
}