use of com.sun.identity.entitlement.opensso.OpenSSOPrivilege in project OpenAM by OpenRock.
the class RemoveReferralsStepTest method simpleSuccessfulPassThrough.
@Test
public void simpleSuccessfulPassThrough() throws Exception {
// Given
given(connectionFactory.create()).willReturn(connection);
given(connection.search(isA(SearchRequest.class))).willReturn(entryReader);
given(entryReader.hasNext()).willReturn(true).willReturn(false);
given(entryReader.readEntry()).willReturn(resultEntry);
given(resultEntry.getName()).willReturn(DN.valueOf("ou=test,ou=forgerock,ou=org"));
JsonValue jsonValue = json(object(field("name", "ref"), field("mapApplNameToResources", object(field("app1", array("*://*:*/*")))), field("realms", array("/a"))));
Set<String> values = singleton("serializable=" + jsonValue.toString());
Attribute attribute = new LinkedAttribute("ou", values);
AttributeParser attributeParser = AttributeParser.parseAttribute(attribute);
given(resultEntry.parseAttribute("sunKeyValue")).willReturn(attributeParser);
Application app1 = new Application();
app1.setName("app1");
app1.addAllResourceTypeUuids(singleton("123"));
given(applicationService.getApplication(isA(Subject.class), eq("/"), eq("app1"))).willReturn(app1);
given(policyServiceFactory.get(eq("/a"), isA(Subject.class))).willReturn(policyService);
Privilege policy1 = new OpenSSOPrivilege();
policy1.setName("pol1");
given(policyService.findAllPoliciesByApplication("app1")).willReturn(singletonList(policy1));
ResourceType resourceType1 = ResourceType.builder().setName("resourceType1").setUUID("123").build();
given(resourceTypeService.getResourceType(isA(Subject.class), eq("/"), eq("123"))).willReturn(resourceType1);
// When
testStep.initialize();
boolean isApplicable = testStep.isApplicable();
testStep.perform();
String shortReport = testStep.getShortReport("");
String longReport = testStep.getDetailedReport("");
// Then
assertThat(isApplicable).isTrue();
assertThat(shortReport).containsSequence("applications to be cloned", "Referrals found");
assertThat(longReport).containsSequence("app1", "ou=test,ou=forgerock,ou=org");
verify(resourceTypeService).saveResourceType(isA(Subject.class), eq("/a"), resourceTypeCaptor.capture());
verify(applicationService).saveApplication(isA(Subject.class), eq("/a"), applicationCaptor.capture());
verify(policyService).modify(policyCaptor.capture());
ResourceType clonedResourceType = resourceTypeCaptor.getValue();
assertThat(clonedResourceType).isNotEqualTo(resourceType1);
assertThat(clonedResourceType.getName()).isEqualTo("resourceType1");
Application clonedApplication = applicationCaptor.getValue();
assertThat(clonedApplication).isNotEqualTo(app1);
assertThat(clonedApplication.getName()).isEqualTo("app1");
assertThat(clonedApplication.getResourceTypeUuids()).containsExactly(clonedResourceType.getUUID());
Privilege modifiedPolicy = policyCaptor.getValue();
assertThat(modifiedPolicy).isEqualTo(modifiedPolicy);
assertThat(modifiedPolicy.getResourceTypeUuid()).isEqualTo(clonedResourceType.getUUID());
verify(connection).delete(deleteRequestCaptor.capture());
DeleteRequest request = deleteRequestCaptor.getValue();
assertThat(request.getName().toString()).isEqualTo("ou=test,ou=forgerock,ou=org");
}
Aggregations