Search in sources :

Example 1 with AttributeParser

use of org.forgerock.opendj.ldap.AttributeParser 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");
}
Also used : SearchRequest(org.forgerock.opendj.ldap.requests.SearchRequest) Attribute(org.forgerock.opendj.ldap.Attribute) LinkedAttribute(org.forgerock.opendj.ldap.LinkedAttribute) JsonValue(org.forgerock.json.JsonValue) OpenSSOPrivilege(com.sun.identity.entitlement.opensso.OpenSSOPrivilege) ResourceType(org.forgerock.openam.entitlement.ResourceType) Subject(javax.security.auth.Subject) LinkedAttribute(org.forgerock.opendj.ldap.LinkedAttribute) AttributeParser(org.forgerock.opendj.ldap.AttributeParser) OpenSSOPrivilege(com.sun.identity.entitlement.opensso.OpenSSOPrivilege) Privilege(com.sun.identity.entitlement.Privilege) Application(com.sun.identity.entitlement.Application) DeleteRequest(org.forgerock.opendj.ldap.requests.DeleteRequest) Test(org.testng.annotations.Test)

Aggregations

Application (com.sun.identity.entitlement.Application)1 Privilege (com.sun.identity.entitlement.Privilege)1 OpenSSOPrivilege (com.sun.identity.entitlement.opensso.OpenSSOPrivilege)1 Subject (javax.security.auth.Subject)1 JsonValue (org.forgerock.json.JsonValue)1 ResourceType (org.forgerock.openam.entitlement.ResourceType)1 Attribute (org.forgerock.opendj.ldap.Attribute)1 AttributeParser (org.forgerock.opendj.ldap.AttributeParser)1 LinkedAttribute (org.forgerock.opendj.ldap.LinkedAttribute)1 DeleteRequest (org.forgerock.opendj.ldap.requests.DeleteRequest)1 SearchRequest (org.forgerock.opendj.ldap.requests.SearchRequest)1 Test (org.testng.annotations.Test)1