Search in sources :

Example 1 with NotSubject

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);
}
Also used : EntitlementSubject(com.sun.identity.entitlement.EntitlementSubject) PolicySubject(com.sun.identity.entitlement.opensso.PolicySubject) Privilege(com.sun.identity.entitlement.Privilege) NotSubject(com.sun.identity.entitlement.NotSubject) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 2 with NotSubject

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());
}
Also used : EntitlementSubject(com.sun.identity.entitlement.EntitlementSubject) PolicySubject(com.sun.identity.entitlement.opensso.PolicySubject) HashSet(java.util.HashSet) Set(java.util.Set) Privilege(com.sun.identity.entitlement.Privilege) NotSubject(com.sun.identity.entitlement.NotSubject) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

EntitlementSubject (com.sun.identity.entitlement.EntitlementSubject)2 NotSubject (com.sun.identity.entitlement.NotSubject)2 Privilege (com.sun.identity.entitlement.Privilege)2 PolicySubject (com.sun.identity.entitlement.opensso.PolicySubject)2 HashSet (java.util.HashSet)2 Test (org.testng.annotations.Test)2 Set (java.util.Set)1