use of com.fasterxml.jackson.databind.jsonschema.JsonSchema in project OpenAM by OpenRock.
the class ConditionTypesResourceTest method testSuccessfulJsonificationAndQuery.
@Test
public void testSuccessfulJsonificationAndQuery() throws JsonMappingException {
//given
SubjectContext mockSubjectContext = mock(SubjectContext.class);
RealmContext realmContext = new RealmContext(mockSubjectContext);
Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
QueryResourceHandler mockHandler = mock(QueryResourceHandler.class);
Subject mockSubject = new Subject();
given(mockSubjectContext.getCallerSubject()).willReturn(mockSubject);
QueryRequest mockRequest = mock(QueryRequest.class);
JsonSchema mockSchema = mock(JsonSchema.class);
given(mockRequest.getPageSize()).willReturn(2);
given(mockHandler.handleResource(any(ResourceResponse.class))).willReturn(true);
given(mockMapper.generateJsonSchema((Class<?>) any(Class.class))).willReturn(mockSchema);
//when
testResource.queryCollection(mockServerContext, mockRequest, mockHandler);
//then
verify(mockHandler, times(2)).handleResource(any(ResourceResponse.class));
}
use of com.fasterxml.jackson.databind.jsonschema.JsonSchema 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 com.fasterxml.jackson.databind.jsonschema.JsonSchema 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);
}
use of com.fasterxml.jackson.databind.jsonschema.JsonSchema in project OpenAM by OpenRock.
the class SubjectTypesResourceTest method testSuccessfulJsonificationAndReadAndSubjectNamePropertyRemoved.
@Test
public void testSuccessfulJsonificationAndReadAndSubjectNamePropertyRemoved() throws Exception {
//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, TEST_CONDITION_WITH_NAME, mockRequest);
//then
assertThat(promise).succeeded().withContent().hasString("title");
assertThat(promise).succeeded().withContent().stringAt("title").isEqualTo(TEST_CONDITION_WITH_NAME);
assertThat(promise).succeeded().withContent().hasBoolean("logical");
assertThat(promise).succeeded().withContent().booleanAt("logical").isFalse();
assertThat(promise.get().getContent().get("config").getObject().toString()).isEqualTo("{\"type\":\"object\",\"properties\":{}}");
}
Aggregations