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();
}
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"));
}
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();
}
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();
}
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));
}
Aggregations