Search in sources :

Example 21 with ReadRequest

use of org.forgerock.json.resource.ReadRequest in project OpenAM by OpenRock.

the class DecisionCombinersResourceTest method testSuccessfulJsonificationAndReadAndNamePropertyRemoved.

@Test
public void testSuccessfulJsonificationAndReadAndNamePropertyRemoved() throws JsonMappingException, ResourceException {
    //given
    SubjectContext mockSubjectContext = mock(SubjectContext.class);
    RealmContext realmContext = new RealmContext(mockSubjectContext);
    Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
    Subject mockSubject = new Subject();
    given(mockSubjectContext.getCallerSubject()).willReturn(mockSubject);
    ReadRequest mockRequest = mock(ReadRequest.class);
    JsonSchema mockSchema = mock(JsonSchema.class);
    given(mockMapper.generateJsonSchema((Class<?>) any(Class.class))).willReturn(mockSchema);
    //when
    Promise<ResourceResponse, ResourceException> result = testResource.readInstance(mockServerContext, TEST_COMBINER, mockRequest);
    //then
    Map resultMap = result.getOrThrowUninterruptibly().getContent().asMap();
    assertThat(resultMap.containsKey("title")).isTrue();
    assertThat(resultMap.get("title")).isEqualTo(TEST_COMBINER);
}
Also used : ClientContext(org.forgerock.services.context.ClientContext) RealmContext(org.forgerock.openam.rest.RealmContext) Context(org.forgerock.services.context.Context) SubjectContext(org.forgerock.openam.rest.resource.SubjectContext) RealmContext(org.forgerock.openam.rest.RealmContext) ResourceResponse(org.forgerock.json.resource.ResourceResponse) SubjectContext(org.forgerock.openam.rest.resource.SubjectContext) JsonSchema(com.fasterxml.jackson.databind.jsonschema.JsonSchema) ResourceException(org.forgerock.json.resource.ResourceException) Map(java.util.Map) Subject(javax.security.auth.Subject) ReadRequest(org.forgerock.json.resource.ReadRequest) Test(org.testng.annotations.Test)

Example 22 with ReadRequest

use of org.forgerock.json.resource.ReadRequest in project OpenAM by OpenRock.

the class ApplicationV1FilterTest method forwardOnRead.

/**
     * Verify that read requests are forwarded on and that the response is tailored to represent v1.0 application.
     */
@Test
public void forwardOnRead() throws Exception {
    // Given
    given(contextHelper.getRealm(context)).willReturn("/abc");
    given(contextHelper.getSubject(context)).willReturn(subject);
    ReadRequest readRequest = mock(ReadRequest.class);
    given(requestHandler.handleRead(context, readRequest)).willReturn(mockPromise);
    // When
    filter.filterRead(context, readRequest, requestHandler);
    // Then
    verify(requestHandler).handleRead(eq(context), eq(readRequest));
    verify(applicationTransformer).transform(mockPromise, context);
}
Also used : ReadRequest(org.forgerock.json.resource.ReadRequest) Test(org.testng.annotations.Test)

Example 23 with ReadRequest

use of org.forgerock.json.resource.ReadRequest in project OpenAM by OpenRock.

the class ResourceTypesResourceTest method shouldReadResourceTypes.

@Test
public void shouldReadResourceTypes() throws Exception {
    //given
    ResourceResponse createdResource = setupExistingResourceTypeFromJson(jsonResourceType);
    ReadRequest readRequest = mock(ReadRequest.class);
    when(resourceTypeService.getResourceType(any(Subject.class), anyString(), anyString())).thenCallRealMethod();
    //when
    Promise<ResourceResponse, ResourceException> promise = resourceTypesResource.readInstance(mockServerContext, createdResource.getId(), readRequest);
    //then
    assertThat(promise).succeeded();
}
Also used : ResourceResponse(org.forgerock.json.resource.ResourceResponse) ResourceException(org.forgerock.json.resource.ResourceException) Subject(javax.security.auth.Subject) ReadRequest(org.forgerock.json.resource.ReadRequest) Test(org.testng.annotations.Test)

Example 24 with ReadRequest

use of org.forgerock.json.resource.ReadRequest in project OpenAM by OpenRock.

the class SubjectTypesResourceTest method testSuccessfulJsonificationAndLogicalIsCorrect.

@Test
public void testSuccessfulJsonificationAndLogicalIsCorrect() throws JsonMappingException {
    //given
    SSOTokenContext mockSubjectContext = mock(SSOTokenContext.class);
    RealmContext realmContext = new RealmContext(mockSubjectContext);
    Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
    Subject mockSubject = new Subject();
    given(mockSubjectContext.getCallerSubject()).willReturn(mockSubject);
    ReadRequest mockRequest = mock(ReadRequest.class);
    QueryResourceHandler mockHandler = mock(QueryResourceHandler.class);
    JsonSchema mockSchema = mock(JsonSchema.class);
    given(mockMapper.generateJsonSchema((Class<?>) any(Class.class))).willReturn(mockSchema);
    //when
    Promise<ResourceResponse, ResourceException> promise = testResource.readInstance(mockServerContext, TEST_LOGICAL_CONDITION, mockRequest);
    //then
    assertThat(promise).succeeded().withContent().hasBoolean("logical");
    assertThat(promise).succeeded().withContent().booleanAt("logical").isTrue();
}
Also used : ClientContext(org.forgerock.services.context.ClientContext) RealmContext(org.forgerock.openam.rest.RealmContext) Context(org.forgerock.services.context.Context) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) RealmContext(org.forgerock.openam.rest.RealmContext) ResourceResponse(org.forgerock.json.resource.ResourceResponse) JsonSchema(com.fasterxml.jackson.databind.jsonschema.JsonSchema) ResourceException(org.forgerock.json.resource.ResourceException) QueryResourceHandler(org.forgerock.json.resource.QueryResourceHandler) EntitlementSubject(com.sun.identity.entitlement.EntitlementSubject) Subject(javax.security.auth.Subject) LogicalSubject(com.sun.identity.entitlement.LogicalSubject) ReadRequest(org.forgerock.json.resource.ReadRequest) Test(org.testng.annotations.Test)

Example 25 with ReadRequest

use of org.forgerock.json.resource.ReadRequest in project OpenAM by OpenRock.

the class SubjectTypesResourceTest method shouldThrowErrorWthInvalidCondition.

@Test
public void shouldThrowErrorWthInvalidCondition() throws JsonMappingException {
    //given
    SSOTokenContext mockSubjectContext = mock(SSOTokenContext.class);
    RealmContext realmContext = new RealmContext(mockSubjectContext);
    Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
    Subject mockSubject = new Subject();
    given(mockSubjectContext.getCallerSubject()).willReturn(mockSubject);
    ReadRequest mockRequest = mock(ReadRequest.class);
    JsonSchema mockSchema = mock(JsonSchema.class);
    given(mockMapper.generateJsonSchema((Class<?>) any(Class.class))).willReturn(mockSchema);
    //when
    Promise<ResourceResponse, ResourceException> promise = testResource.readInstance(mockServerContext, "invalidCondition", mockRequest);
    //then
    assertThat(promise).failedWithException().isInstanceOf(NotFoundException.class);
}
Also used : ClientContext(org.forgerock.services.context.ClientContext) RealmContext(org.forgerock.openam.rest.RealmContext) Context(org.forgerock.services.context.Context) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) RealmContext(org.forgerock.openam.rest.RealmContext) ResourceResponse(org.forgerock.json.resource.ResourceResponse) JsonSchema(com.fasterxml.jackson.databind.jsonschema.JsonSchema) ResourceException(org.forgerock.json.resource.ResourceException) EntitlementSubject(com.sun.identity.entitlement.EntitlementSubject) Subject(javax.security.auth.Subject) LogicalSubject(com.sun.identity.entitlement.LogicalSubject) ReadRequest(org.forgerock.json.resource.ReadRequest) Test(org.testng.annotations.Test)

Aggregations

ReadRequest (org.forgerock.json.resource.ReadRequest)35 Test (org.testng.annotations.Test)31 ResourceException (org.forgerock.json.resource.ResourceException)28 ResourceResponse (org.forgerock.json.resource.ResourceResponse)27 Context (org.forgerock.services.context.Context)23 RealmContext (org.forgerock.openam.rest.RealmContext)15 Subject (javax.security.auth.Subject)13 ClientContext (org.forgerock.services.context.ClientContext)11 JsonSchema (com.fasterxml.jackson.databind.jsonschema.JsonSchema)8 SSOTokenContext (org.forgerock.openam.rest.resource.SSOTokenContext)7 JsonValue (org.forgerock.json.JsonValue)6 SubjectContext (org.forgerock.openam.rest.resource.SubjectContext)6 RequestHandler (org.forgerock.json.resource.RequestHandler)4 EntitlementSubject (com.sun.identity.entitlement.EntitlementSubject)3 LogicalSubject (com.sun.identity.entitlement.LogicalSubject)3 Map (java.util.Map)3 AuthorizationResult (org.forgerock.authz.filter.api.AuthorizationResult)3 Router (org.forgerock.json.resource.Router)3 EntitlementException (com.sun.identity.entitlement.EntitlementException)2 CreateRequest (org.forgerock.json.resource.CreateRequest)2