Search in sources :

Example 6 with ApplicationTypeManagerWrapper

use of org.forgerock.openam.entitlement.rest.wrappers.ApplicationTypeManagerWrapper in project OpenAM by OpenRock.

the class ApplicationsResourceTest method reservedInternalAppIsMappedDuringQuery.

@Test
public void reservedInternalAppIsMappedDuringQuery() throws EntitlementException, IllegalAccessException, InstantiationException {
    // Override the creation of the application wrapper so to return a mocked version.
    applicationsResource = new ApplicationsResource(debug, applicationManagerWrapper, applicationTypeManagerWrapper, queryAttributes, resourceErrorHandler) {

        @Override
        protected ApplicationWrapper createApplicationWrapper(Application application, ApplicationTypeManagerWrapper type) {
            ApplicationWrapper wrapper = mock(ApplicationWrapper.class);
            String appName = application.getName();
            given(wrapper.getName()).willReturn(appName);
            try {
                JsonValue jsonValue = JsonValueBuilder.jsonValue().put("name", "agentProtectedApplication").build();
                given(wrapper.toJsonValue()).willReturn(jsonValue);
            } catch (EntitlementException e) {
                fail();
            }
            return wrapper;
        }
    };
    // Given...
    SSOTokenContext mockSubjectContext = mock(SSOTokenContext.class);
    RealmContext realmContext = new RealmContext(mockSubjectContext);
    realmContext.setSubRealm("abc", "abc");
    Context serverContext = ClientContext.newInternalClientContext(realmContext);
    QueryRequest request = mock(QueryRequest.class);
    given(request.getSortKeys()).willReturn(Arrays.asList(SortKey.ascendingOrder("name")));
    Subject subject = new Subject();
    given(mockSubjectContext.getCallerSubject()).willReturn(subject);
    Set<String> appNames = asSet("iPlanetAMWebAgentService");
    given(applicationManagerWrapper.search(eq(subject), eq("/abc"), any(Set.class))).willReturn(appNames);
    Application app = mock(Application.class);
    given(applicationManagerWrapper.getApplication(eq(subject), eq("/abc"), eq("iPlanetAMWebAgentService"))).willReturn(app);
    given(app.getName()).willReturn("agentProtectedApplication");
    QueryResourceHandler handler = mock(QueryResourceHandler.class);
    given(handler.handleResource(any(ResourceResponse.class))).willReturn(true);
    // When...
    applicationsResource.queryCollection(serverContext, request, handler);
    // Then...
    verify(applicationManagerWrapper).search(eq(subject), eq("/abc"), any(Set.class));
    verify(applicationManagerWrapper).getApplication(eq(subject), eq("/abc"), anyString());
    ArgumentCaptor<ResourceResponse> resourceCapture = ArgumentCaptor.forClass(ResourceResponse.class);
    verify(handler).handleResource(resourceCapture.capture());
    ResourceResponse resource = resourceCapture.getValue();
    assertThat(resource.getId()).isEqualTo("agentProtectedApplication");
}
Also used : ClientContext(org.forgerock.services.context.ClientContext) RealmContext(org.forgerock.openam.rest.RealmContext) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) Context(org.forgerock.services.context.Context) Set(java.util.Set) RealmContext(org.forgerock.openam.rest.RealmContext) QueryRequest(org.forgerock.json.resource.QueryRequest) ApplicationTypeManagerWrapper(org.forgerock.openam.entitlement.rest.wrappers.ApplicationTypeManagerWrapper) JsonValue(org.forgerock.json.JsonValue) Matchers.anyString(org.mockito.Matchers.anyString) Subject(javax.security.auth.Subject) EntitlementException(com.sun.identity.entitlement.EntitlementException) ApplicationWrapper(org.forgerock.openam.entitlement.rest.wrappers.ApplicationWrapper) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) ResourceResponse(org.forgerock.json.resource.ResourceResponse) QueryResourceHandler(org.forgerock.json.resource.QueryResourceHandler) Application(com.sun.identity.entitlement.Application) Test(org.testng.annotations.Test)

Aggregations

EntitlementException (com.sun.identity.entitlement.EntitlementException)6 Subject (javax.security.auth.Subject)6 ApplicationTypeManagerWrapper (org.forgerock.openam.entitlement.rest.wrappers.ApplicationTypeManagerWrapper)6 ApplicationWrapper (org.forgerock.openam.entitlement.rest.wrappers.ApplicationWrapper)6 Application (com.sun.identity.entitlement.Application)5 JsonValue (org.forgerock.json.JsonValue)5 ResourceResponse (org.forgerock.json.resource.ResourceResponse)5 RealmContext (org.forgerock.openam.rest.RealmContext)5 SSOTokenContext (org.forgerock.openam.rest.resource.SSOTokenContext)5 Test (org.testng.annotations.Test)5 ResourceException (org.forgerock.json.resource.ResourceException)4 Matchers.anyString (org.mockito.Matchers.anyString)4 Set (java.util.Set)3 QueryRequest (org.forgerock.json.resource.QueryRequest)3 QueryResourceHandler (org.forgerock.json.resource.QueryResourceHandler)3 ClientContext (org.forgerock.services.context.ClientContext)3 Context (org.forgerock.services.context.Context)3 CreateRequest (org.forgerock.json.resource.CreateRequest)2 QueryResponse (org.forgerock.json.resource.QueryResponse)2 SearchAttribute (com.sun.identity.entitlement.util.SearchAttribute)1