Search in sources :

Example 6 with ReadRequest

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

the class DecisionCombinersResourceTest method shouldThrowErrorWthInvalidCondition.

@Test(expectedExceptions = NotFoundException.class)
public void shouldThrowErrorWthInvalidCondition() 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, "invalidCondition", mockRequest);
    //then
    result.getOrThrowUninterruptibly();
}
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) Subject(javax.security.auth.Subject) ReadRequest(org.forgerock.json.resource.ReadRequest) Test(org.testng.annotations.Test)

Example 7 with ReadRequest

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

the class ApplicationTypesResourceTest method shouldReadInstanceCorrectly.

@Test
public void shouldReadInstanceCorrectly() throws IllegalAccessException, InstantiationException, ExecutionException, InterruptedException {
    //given
    SSOTokenContext mockSubjectContext = mock(SSOTokenContext.class);
    RealmContext realmContext = new RealmContext(mockSubjectContext);
    Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
    Subject subject = new Subject();
    given(mockSubjectContext.getCallerSubject()).willReturn(subject);
    ReadRequest request = mock(ReadRequest.class);
    ApplicationType mockApplicationType = new ApplicationType("test", null, null, null, null);
    given(mockApplicationTypeManager.getApplicationType(subject, "test")).willReturn(mockApplicationType);
    //when
    Promise<ResourceResponse, ResourceException> result = testResource.readInstance(mockServerContext, "test", request);
    //then
    assertTrue(result.get().getId().equals("test"));
}
Also used : Context(org.forgerock.services.context.Context) ClientContext(org.forgerock.services.context.ClientContext) RealmContext(org.forgerock.openam.rest.RealmContext) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) ApplicationType(com.sun.identity.entitlement.ApplicationType) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) RealmContext(org.forgerock.openam.rest.RealmContext) 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 8 with ReadRequest

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

the class ResourceSetResourceTest method shouldReadResourceSet.

@Test
public void shouldReadResourceSet() throws Exception {
    //Given
    Context context = mock(Context.class);
    ReadRequest request = mock(ReadRequest.class);
    given(request.getFields()).willReturn(Arrays.asList(new JsonPointer("/fred")));
    ResourceSetDescription resourceSet = new ResourceSetDescription();
    resourceSet.setDescription(json(object()));
    Promise<ResourceSetDescription, ResourceException> resourceSetPromise = Promises.newResultPromise(resourceSet);
    given(contextHelper.getRealm(context)).willReturn("REALM");
    given(contextHelper.getUserId(context)).willReturn("RESOURCE_OWNER_ID");
    given(resourceSetService.getResourceSet(context, "REALM", "RESOURCE_SET_ID", "RESOURCE_OWNER_ID", false)).willReturn(resourceSetPromise);
    //When
    Promise<ResourceResponse, ResourceException> readPromise = resource.readInstance(context, "RESOURCE_SET_ID", request);
    //Then
    assertThat(readPromise).succeeded().withObject().isNotNull();
}
Also used : Context(org.forgerock.services.context.Context) ResourceResponse(org.forgerock.json.resource.ResourceResponse) ResourceException(org.forgerock.json.resource.ResourceException) JsonPointer(org.forgerock.json.JsonPointer) ResourceSetDescription(org.forgerock.oauth2.resources.ResourceSetDescription) ReadRequest(org.forgerock.json.resource.ReadRequest) Test(org.testng.annotations.Test)

Example 9 with ReadRequest

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

the class PendingRequestResourceTest method shouldReadPendingRequest.

@SuppressWarnings("unchecked")
@Test
public void shouldReadPendingRequest() throws Exception {
    //Given
    Context context = mock(Context.class);
    ReadRequest request = Requests.newReadRequest("");
    String id = mockPendingRequest();
    //When
    Promise<ResourceResponse, ResourceException> promise = resource.readInstance(context, id, request);
    //Then
    assertThat(promise).succeeded();
}
Also used : RealmContext(org.forgerock.openam.rest.RealmContext) Context(org.forgerock.services.context.Context) ResourceResponse(org.forgerock.json.resource.ResourceResponse) ResourceException(org.forgerock.json.resource.ResourceException) Matchers.anyString(org.mockito.Matchers.anyString) ReadRequest(org.forgerock.json.resource.ReadRequest) Test(org.testng.annotations.Test)

Example 10 with ReadRequest

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

the class RestRouterIT method shouldBeAbleToReachInternalViaInternalRouter.

@Test
public void shouldBeAbleToReachInternalViaInternalRouter() throws Exception {
    // Given
    Promise<ResourceResponse, ResourceException> promise = newResultPromise(newResourceResponse("1", "1", json(object())));
    given(internalResource.readInstance(any(Context.class), eq("123"), any(ReadRequest.class))).willReturn(promise);
    Router internalRouter = InjectorHolder.getInstance(Key.get(Router.class, Names.named("InternalCrestRouter")));
    Context context = mockRequiredContexts();
    ReadRequest request = Requests.newReadRequest("internal/123");
    // When
    internalRouter.handleRead(context, request);
    // Then
    verify(internalResource).readInstance(any(Context.class), eq("123"), any(ReadRequest.class));
}
Also used : RootContext(org.forgerock.services.context.RootContext) RequestAuditContext(org.forgerock.services.context.RequestAuditContext) HttpContext(org.forgerock.json.resource.http.HttpContext) SessionContext(org.forgerock.http.session.SessionContext) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) AttributesContext(org.forgerock.services.context.AttributesContext) SecurityContext(org.forgerock.services.context.SecurityContext) Context(org.forgerock.services.context.Context) Responses.newResourceResponse(org.forgerock.json.resource.Responses.newResourceResponse) ResourceResponse(org.forgerock.json.resource.ResourceResponse) Router(org.forgerock.json.resource.Router) ResourceException(org.forgerock.json.resource.ResourceException) 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