use of com.sun.identity.entitlement.NotCondition in project OpenAM by OpenRock.
the class PolicyConditionUpgraderTest method shouldMigratePolicyWithNotEnvironmentCondition.
@Test
public void shouldMigratePolicyWithNotEnvironmentCondition() throws EntitlementException, UpgradeException {
//Given
Privilege policy = mock(Privilege.class);
NotCondition notCondition = mock(NotCondition.class);
Set<EntitlementCondition> notConditions = new HashSet<EntitlementCondition>();
PolicyCondition condition = mock(PolicyCondition.class);
notConditions.add(condition);
EntitlementCondition migratedCondition = mock(EntitlementCondition.class);
given(policy.getCondition()).willReturn(notCondition);
given(notCondition.getEConditions()).willReturn(notConditions);
given(condition.getClassName()).willReturn("CONDITION_CLASS_NAME");
given(conditionUpgradeMap.migrateEnvironmentCondition(eq("CONDITION_CLASS_NAME"), eq(condition), Matchers.<MigrationReport>anyObject())).willReturn(migratedCondition);
//When
conditionUpgrader.dryRunPolicyUpgrade(policy);
//Then
ArgumentCaptor<Set> conditionCaptor = ArgumentCaptor.forClass(Set.class);
verify(notCondition).setEConditions(conditionCaptor.capture());
assertThat(conditionCaptor.getValue()).hasSize(1).contains(migratedCondition);
verify(policy, never()).setSubject(Matchers.<EntitlementSubject>anyObject());
verify(policy, never()).setCondition(Matchers.<EntitlementCondition>anyObject());
}
use of com.sun.identity.entitlement.NotCondition in project OpenAM by OpenRock.
the class PolicyConditionUpgraderTest method isPolicyWithNotEnvironmentConditionUpgradable.
@Test(dataProvider = "isPolicyWithNotEnvironmentConditionUpgradableDataProvider")
public void isPolicyWithNotEnvironmentConditionUpgradable(Class<? extends EntitlementCondition> condition, boolean conditionInMap, boolean expectedResult) {
//Given
Privilege policy = mock(Privilege.class);
NotCondition notCondition = mock(NotCondition.class);
Set<EntitlementCondition> notConditions = new HashSet<EntitlementCondition>();
EntitlementCondition con = mock(condition);
notConditions.add(con);
given(policy.getCondition()).willReturn(notCondition);
given(notCondition.getEConditions()).willReturn(notConditions);
if (con instanceof PolicyCondition) {
given(((PolicyCondition) con).getClassName()).willReturn("CONDITION_CLASS_NAME");
}
given(conditionUpgradeMap.containsEnvironmentCondition("CONDITION_CLASS_NAME")).willReturn(conditionInMap);
//When
boolean upgradable = conditionUpgrader.isPolicyUpgradable(policy);
//Then
assertThat(upgradable).isEqualTo(expectedResult);
}
use of com.sun.identity.entitlement.NotCondition in project OpenAM by OpenRock.
the class JsonPolicyParserTest method shouldPrintComplexConditions.
@Test
public void shouldPrintComplexConditions() throws Exception {
// Given
Privilege policy = new StubPrivilege();
AndCondition and = new AndCondition();
Set<EntitlementCondition> subConditions = new LinkedHashSet<EntitlementCondition>();
Map<String, Set<String>> props = new HashMap<String, Set<String>>();
props.put("AuthenticateToRealm", Collections.singleton("REALM"));
PolicyCondition policyCondition = new PolicyCondition("test", AuthenticateToRealmCondition.class.getName(), props);
NotCondition not = new NotCondition(policyCondition);
subConditions.add(not);
and.setEConditions(subConditions);
policy.setCondition(and);
// When
JsonValue result = parser.printPolicy(policy);
// Then
assertThat(result.get(new JsonPointer("condition/type")).asString()).isEqualTo("AND");
assertThat(result.get(new JsonPointer("condition/conditions/0/type")).asString()).isEqualTo("NOT");
assertThat(result.get(new JsonPointer("condition/conditions/0/condition/type")).asString()).isEqualTo("Policy");
assertThat(result.get(new JsonPointer("condition/conditions/0/condition/className")).asString()).isEqualTo(AuthenticateToRealmCondition.class.getName());
assertThat(result.get(new JsonPointer("condition/conditions/0/condition/properties")).asMapOfList(String.class)).includes(entry("AuthenticateToRealm", Arrays.asList("REALM")));
}
use of com.sun.identity.entitlement.NotCondition in project OpenAM by OpenRock.
the class JsonPolicyParserTest method shouldParseNotConditions.
@Test
public void shouldParseNotConditions() throws Exception {
// Given
// A NOT condition containing an OAuth2Scope condition
String scope = "givenName";
JsonValue content = buildJson(field("condition", object(field("type", "NOT"), field("condition", object(field("type", "OAuth2Scope"), field("requiredScopes", array(scope)))))));
// When
Privilege result = parser.parsePolicy(POLICY_NAME, content);
// Then
assertThat(result.getCondition()).isInstanceOf(NotCondition.class);
NotCondition not = (NotCondition) result.getCondition();
assertThat(not.getECondition()).isInstanceOf(OAuth2ScopeCondition.class);
OAuth2ScopeCondition ip = (OAuth2ScopeCondition) not.getECondition();
assertThat(ip.getRequiredScopes()).isEqualTo(Collections.singleton(scope));
}
Aggregations