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