@Test
public void testValidatePolicyAssertionInValid() {

    
    // assertion missing domain name
    
    Assertion assertion = new Assertion();
    assertion.setAction("update");
    assertion.setEffect(AssertionEffect.ALLOW);
    assertion.setResource("resource1");
    assertion.setRole(ZMSUtils.roleResourceName("domain1", "role1"));
    
    try {
        zms.validatePolicyAssertion(assertion, "unitTest");
        fail();
    } catch (ResourceException ex) {
        assertEquals(400, ex.getCode());
    }
    
    // assertion with empty domain name
    
    assertion = new Assertion();
    assertion.setAction("update");
    assertion.setEffect(AssertionEffect.ALLOW);
    assertion.setResource(":resource1");
    assertion.setRole(ZMSUtils.roleResourceName("domain1", "role1"));
    
    try {
        zms.validatePolicyAssertion(assertion, "unitTest");
        fail();
    } catch (ResourceException ex) {
        assertEquals(400, ex.getCode());
    }
    
    // assertion with invalid domain name
    
    assertion = new Assertion();
    assertion.setAction("update");
    assertion.setEffect(AssertionEffect.ALLOW);
    assertion.setResource("domain name:resource1");
    assertion.setRole(ZMSUtils.roleResourceName("domain1", "role1"));
    
    try {
        zms.validatePolicyAssertion(assertion, "unitTest");
        fail();
    } catch (ResourceException ex) {
        assertEquals(400, ex.getCode());
    }
    
    // assertion with invalid resource name
    
    assertion = new Assertion();
    assertion.setAction("update");
    assertion.setEffect(AssertionEffect.ALLOW);
    assertion.setResource("domain1:resource\t\ntest");
    assertion.setRole(ZMSUtils.roleResourceName("domain1", "role1"));
    
    try {
        zms.validatePolicyAssertion(assertion, "unitTest");
        fail();
    } catch (ResourceException ex) {
        assertEquals(400, ex.getCode());
    }
    
    // assertion with null action
    
    assertion = new Assertion();
    assertion.setAction(null);
    assertion.setEffect(AssertionEffect.ALLOW);
    assertion.setResource("domain1:resource1");
    assertion.setRole(ZMSUtils.roleResourceName("domain1", "role1"));
    
    try {
        zms.validatePolicyAssertion(assertion, "unitTest");
        fail();
    } catch (ResourceException ex) {
        assertEquals(400, ex.getCode());
    }
    
    // assertion with empty action
    
    assertion = new Assertion();
    assertion.setAction("");
    assertion.setEffect(AssertionEffect.ALLOW);
    assertion.setResource("domain1:resource1");
    assertion.setRole(ZMSUtils.roleResourceName("domain1", "role1"));
    
    try {
        zms.validatePolicyAssertion(assertion, "unitTest");
        fail();
    } catch (ResourceException ex) {
        assertEquals(400, ex.getCode());
    }
    
    // assertion with action containing control characters
    
    assertion = new Assertion();
    assertion.setAction("update\t");
    assertion.setEffect(AssertionEffect.ALLOW);
    assertion.setResource("domain1:resource1");
    assertion.setRole(ZMSUtils.roleResourceName("domain1", "role1"));
    
    try {
        zms.validatePolicyAssertion(assertion, "unitTest");
        fail();
    } catch (ResourceException ex) {
        assertEquals(400, ex.getCode());
    }
}