use of com.fasterxml.jackson.databind.jsonschema.JsonSchema in project OpenAM by OpenRock.
the class SubjectTypesResourceTest method testSuccessfulJsonificationAndQuery.
@Test
public void testSuccessfulJsonificationAndQuery() 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);
QueryRequest mockRequest = mock(QueryRequest.class);
JsonSchema mockSchema = mock(JsonSchema.class);
QueryResourceHandler mockHandler = mock(QueryResourceHandler.class);
given(mockRequest.getPageSize()).willReturn(2);
given(mockHandler.handleResource(any(ResourceResponse.class))).willReturn(true);
given(mockMapper.generateJsonSchema((Class<?>) any(Class.class))).willReturn(mockSchema);
//when
Promise<QueryResponse, ResourceException> promise = testResource.queryCollection(mockServerContext, mockRequest, mockHandler);
//then
assertThat(promise).succeeded();
verify(mockHandler, times(2)).handleResource(any(ResourceResponse.class));
}
use of com.fasterxml.jackson.databind.jsonschema.JsonSchema in project OpenAM by OpenRock.
the class ConditionTypesResourceTest method testSuccessfulJsonificationAndReadAndNamePropertyRemoved.
@Test
public void testSuccessfulJsonificationAndReadAndNamePropertyRemoved() throws JsonMappingException, ExecutionException, InterruptedException {
//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_CONDITION_WITH_NAME, mockRequest);
//then
Map resultMap = result.get().getContent().asMap();
assertThat(resultMap.containsKey("title")).isTrue();
assertThat(resultMap.containsKey("config")).isTrue();
assertThat(resultMap.containsKey("logical")).isTrue();
assertThat(resultMap.get("title")).isEqualTo(TEST_CONDITION_WITH_NAME);
assertThat(resultMap.get("logical")).isEqualTo(false);
assertThat(resultMap.get("config")).isInstanceOf(JsonSchema.class);
JsonSchema resultSchema = (JsonSchema) resultMap.get("config");
assertThat(resultSchema.toString().equals("{\"type\":\"object\",\"properties\":{}}")).isTrue();
}
use of com.fasterxml.jackson.databind.jsonschema.JsonSchema in project OpenAM by OpenRock.
the class ConditionTypesResourceTest method testSuccessfulJsonificationAndLogicalIsCorrect.
@Test
public void testSuccessfulJsonificationAndLogicalIsCorrect() throws JsonMappingException, ExecutionException, InterruptedException {
//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_LOGICAL_CONDITION, mockRequest);
//then
Map resultMap = result.get().getContent().asMap();
assertThat(resultMap.containsKey("logical")).isTrue();
assertThat(resultMap.get("logical")).isEqualTo(true);
}
use of com.fasterxml.jackson.databind.jsonschema.JsonSchema 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 com.fasterxml.jackson.databind.jsonschema.JsonSchema in project OpenAM by OpenRock.
the class SubjectTypesResource method jsonify.
/**
* Transforms a subclass of {@link EntitlementSubject} in to a JsonSchema representation.
* This schema is then combined with the Subject's name (taken as the resourceId) and all this is
* compiled together into a new {@link JsonValue} object until "title" and "config" fields respectively.
*
* @param subjectClass The class whose schema to produce.
* @param resourceId The ID of the resource to return
* @return A JsonValue containing the schema of the EntitlementSubject
*/
private JsonValue jsonify(Class<? extends EntitlementSubject> subjectClass, String resourceId, boolean logical) {
try {
final JsonSchema schema = mapper.generateJsonSchema(subjectClass);
//this will remove the 'subjectName' attribute from those subjects which incorporate it unnecessarily
final JsonNode node = schema.getSchemaNode().get("properties");
if (node instanceof ObjectNode) {
final ObjectNode alter = (ObjectNode) node;
alter.remove("subjectName");
}
return JsonValue.json(JsonValue.object(JsonValue.field(JSON_OBJ_TITLE, resourceId), JsonValue.field(JSON_OBJ_LOGICAL, logical), JsonValue.field(JSON_OBJ_CONFIG, schema)));
} catch (JsonMappingException e) {
if (debug.errorEnabled()) {
debug.error("SubjectTypesResource :: JSONIFY - Error applying " + "jsonification to the Subject class representation.", e);
}
return null;
}
}
Aggregations