XACMLPrivilegeUtilsTest.java revision 024fd4c1fab17ad66496e7e72e1c31d8d8ecc6ef
/*
* The contents of this file are subject to the terms of the Common Development and
* Distribution License (the License). You may not use this file except in compliance with the
* License.
*
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
* specific language governing permission and limitations under the License.
*
* When distributing Covered Software, include this CDDL Header Notice in each file and include
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information: "Portions copyright [year] [name of copyright owner]".
*
* Copyright 2014 Nomura Research Institute, Ltd.
*/
/*
* Portions Copyrighted 2014 ForgeRock AS.
*/
/**
* Unit tests for {@link XACMLPrivilegeUtils}. These are limited scope to only cover the functionality used
* within com.sun.identity.cli.entitlement.ListXACML#handleRequest(com.sun.identity.cli.RequestContext) and
* com.sun.identity.cli.entitlement.CreateXACML#handleRequest(com.sun.identity.cli.RequestContext). They will
* indicate when changes to the code directly used by these methods has broken the existing functionality.
*
* Note that the custom JSON-in-XACML is not catered for here.
*
* @since 12.0.0
*/
public class XACMLPrivilegeUtilsTest {
public static final int NUMBER_OF_PRIVILEGES_IN_ARBITRARY_PRIVILEGE_SET = 2;
@Test
public void shouldReturnEmptyListWhenNull() {
// When...
// Then...
}
@Test
public void shouldResultInEquivalentPrivilegesWhenValidPrivilegeSetSerializedToXACMLThenDeserialized()
throws EntitlementException {
//Given
//When
}
//Then
}
@Test
public void shouldResultInEquivalentReferralPrivilegeWhenValidReferralPrivilegeSerializedToXACMLThenDeserialized()
throws JSONException, EntitlementException {
//Given
//When
//Then
}
@Test
public void shouldReturnXACMLPolicySetWhenGivenValidPrivilegeSet() {
//Given
//When
//Then
}
@Test
public void shouldReturnNullWhenGivenNullAsPrivilegeSet() {
//Given
//When
//Then
}
@Test
public void shouldReturnXACMLPolicyWhenGivenValidReferralPrivilegeSet() throws JSONException, EntitlementException {
//Given
//When
//Then
}
@Test
public void shouldReturnNullWhenGivenNullAsReferralPrivilege() throws JSONException {
//Given
//When
//Then
}
@Test
public void shouldAddPolicyToPolicySet() throws JAXBException {
//Given
//When
//Then
}
@Test
public void shouldNotAddNullToPolicySetAndSoShouldLeavePolicySetUnchanged() throws JAXBException {
//Given
//When
//Then
assertEquals(policySet.getPolicySetOrPolicyOrPolicySetIdReference().size(), 0, "Expected PolicySet to remain " +
"empty as a result of not adding null to the empty PolicySet.");
}
@Test
public void shouldIndicateReferralPolicyWhenGivenReferralPrivilege() throws EntitlementException, JSONException {
//Given
//When
//Then
}
@Test
public void shouldIndicateNotAReferralPolicyWhenGivenPolicy() {
//Given
//When
//Then
}
private void assertPolicySetContentsMatchPrivilegesContent(PolicySet policySet, Set<Privilege> privileges) {
}
assertEquals(policies.size(), privileges.size(), "Mismatch between number of Policy elements in PolicySet, " +
"and number of original Privileges.");
}
}
assertTrue(policyIdList.containsAll(privilegeIdList), "Not all Privilege names were included in the " +
"PolicySet.");
assertTrue(privilegeIdList.containsAll(policyIdList), "Extra names were added to the PolicySet which were " +
"not in the list of Privilege names.");
}
assertTrue(descriptionList.contains(description), "Privilege with description '" + description + "' not " +
"found in PolicySet.");
}
assertEquals(policy.getVersion().getValue(), privilegesVersion, "Policy found with version not matching " +
"Privilege creation date.");
}
}
if (referralPrivilege != null) {
}
"ReferralPrivilege name.");
assertEquals(policy.getDescription(), referralPrivilege.getDescription(), "Expected Policy description to " +
"match ReferralPrivilege description.");
String referralPrivilegeCreationDate = formatMillisecondsAsTimestamp(referralPrivilege.getCreationDate());
assertEquals(policy.getVersion().getValue(), referralPrivilegeCreationDate, "Expected Policy creation date " +
"to match ReferralPrivilege creation date.");
}
assertSame(policies.get(0), policy, "Policy that was added to PolicySet does not match the original Policy " +
"to be added.");
}
private void assertDeserializedPrivilegesMatchOriginalPrivileges(List<Privilege> deserializedPrivileges,
assertEquals(deserializedPrivileges.size(), originalPrivileges.size(), "Expected deserialized Privileges " +
"List to contain the same number of Privileges as the original list.");
}
}
}
assertEquals(originalPrivileges.size(), 0, "Original Privileges found which were not represented in the " +
"list of deserialized Privileges.");
assertEquals(deserializedPrivileges.size(), 0, "Deserialized Privileges contained Privileges which were not " +
"present in the original set.");
}
"Deserialized ReferralPrivilege name does not match name of original ReferralPrivilege.");
Map<String, Set<String>> originalMapApplNameToResources = originalReferralPrivilege.getMapApplNameToResources();
"Deserialized ReferralPrivilege map of application names to resources' size does not match original.");
assertTrue(deserializedMapApplNameToResourcesKeySet.containsAll(originalMapApplNameToResourcesKeySet),
"The application name entries in deserialized ReferralPrivilege map of application names to " +
"resources' do not match originals.");
}
assertEquals(deserializedReferralPrivilege.getRealms().size(), originalReferralPrivilege.getRealms().size(),
"Deserialized ReferralPrivilege list of realms' size does not match original.");
assertTrue(originalReferralPrivilege.getRealms().containsAll(deserializedReferralPrivilege.getRealms()),
"Realms were specified in the deserialized ReferralPrivilege which were not in the original " +
"ReferralPrivilege.");
assertEquals(deserializedReferralPrivilege.getCreationDate(), originalReferralPrivilege.getCreationDate(),
"Deserialized ReferralPrivilege creation date does not match original ReferralPrivilege creation " +
"date.");
originalReferralPrivilege.getLastModifiedDate(), "Deserialized ReferralPrivilege last modified date " +
"does not match original ReferralPrivilege last modified date.");
assertEquals(deserializedReferralPrivilege.getCreatedBy(), originalReferralPrivilege.getCreatedBy(),
"Deserialized ReferralPrivilege created by field does not match original ReferralPrivilege created " +
"by field.");
}
privilegeNumber++) {
}
return privilegeSet;
}
try {
} catch (EntitlementException ee) {
}
return privilege;
}
referralPrivilege.setActive(true);
return referralPrivilege;
}
return policy;
}
private Policy getArbitraryPrivilegeAsPolicy() {
return policy;
}
}
return policies;
}
}
}