use of com.sun.identity.entitlement.NotSubject in project OpenAM by OpenRock.
the class PolicyConditionUpgraderTest method isPolicyWithNotSubjectConditionUpgradable.
@Test(dataProvider = "isPolicyWithNotSubjectConditionUpgradableDataProvider")
public void isPolicyWithNotSubjectConditionUpgradable(Class<? extends EntitlementSubject> sub, boolean subInMap, boolean expectedResult) {
//Given
Privilege policy = mock(Privilege.class);
NotSubject notSubject = mock(NotSubject.class);
Set<EntitlementSubject> notSubjects = new HashSet<EntitlementSubject>();
EntitlementSubject subject = mock(sub);
notSubjects.add(subject);
given(policy.getSubject()).willReturn(notSubject);
given(notSubject.getESubjects()).willReturn(notSubjects);
if (subject instanceof PolicySubject) {
given(((PolicySubject) subject).getClassName()).willReturn("SUBJECT_CLASS_NAME");
}
given(conditionUpgradeMap.containsSubjectCondition("SUBJECT_CLASS_NAME")).willReturn(subInMap);
//When
boolean upgradable = conditionUpgrader.isPolicyUpgradable(policy);
//Then
assertThat(upgradable).isEqualTo(expectedResult);
}
use of com.sun.identity.entitlement.NotSubject in project OpenAM by OpenRock.
the class PolicyConditionUpgraderTest method shouldMigratePolicyWithNotSubjectCondition.
@Test
public void shouldMigratePolicyWithNotSubjectCondition() throws EntitlementException, UpgradeException {
//Given
Privilege policy = mock(Privilege.class);
NotSubject notSubject = mock(NotSubject.class);
Set<EntitlementSubject> notSubjects = new HashSet<EntitlementSubject>();
PolicySubject subject = mock(PolicySubject.class);
notSubjects.add(subject);
EntitlementSubject migratedSubject = mock(EntitlementSubject.class);
given(policy.getSubject()).willReturn(notSubject);
given(notSubject.getESubjects()).willReturn(notSubjects);
given(subject.getClassName()).willReturn("SUBJECT_CLASS_NAME");
given(conditionUpgradeMap.migrateSubjectCondition(eq("SUBJECT_CLASS_NAME"), eq(subject), Matchers.<MigrationReport>anyObject())).willReturn(migratedSubject);
//When
conditionUpgrader.dryRunPolicyUpgrade(policy);
//Then
ArgumentCaptor<Set> subjectCaptor = ArgumentCaptor.forClass(Set.class);
verify(notSubject).setESubjects(subjectCaptor.capture());
assertThat(subjectCaptor.getValue()).hasSize(1).contains(migratedSubject);
verify(policy, never()).setSubject(Matchers.<EntitlementSubject>anyObject());
verify(policy, never()).setCondition(Matchers.<EntitlementCondition>anyObject());
}
Aggregations