use of com.fasterxml.jackson.databind.jsonschema.JsonSchema in project jackson-databind by FasterXML.
the class TestReadJsonSchema method testDeserializeSimple.
/**
* Verifies that a simple schema that is serialized can be
* deserialized back to equal schema instance
*/
public void testDeserializeSimple() throws Exception {
ObjectMapper mapper = new ObjectMapper();
JsonSchema schema = mapper.generateJsonSchema(Schemable.class);
assertNotNull(schema);
String schemaStr = mapper.writeValueAsString(schema);
assertNotNull(schemaStr);
JsonSchema result = mapper.readValue(schemaStr, JsonSchema.class);
assertEquals("Trying to read from '" + schemaStr + "'", schema, result);
}
use of com.fasterxml.jackson.databind.jsonschema.JsonSchema in project OpenAM by OpenRock.
the class ConditionTypesResource method jsonify.
/**
* Transforms a subclass of {@link EntitlementCondition} in to a JsonSchema representation.
* This schema is then combined with the Condition'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 conditionClass The class whose schema to produce.
* @param resourceId The ID of the resource to return
* @return A JsonValue containing the schema of the EntitlementCondition
*/
private JsonValue jsonify(Class<? extends EntitlementCondition> conditionClass, String resourceId, boolean logical) {
try {
final JsonSchema schema = mapper.generateJsonSchema(conditionClass);
//this will remove the 'name' attribute from those conditions which incorporate it unnecessarily
final JsonNode node = schema.getSchemaNode().get("properties");
if (node instanceof ObjectNode) {
final ObjectNode alter = (ObjectNode) node;
alter.remove("name");
}
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("ConditionTypesResource :: JSONIFY - Error applying " + "jsonification to the Condition class representation.", e);
}
return null;
}
}
use of com.fasterxml.jackson.databind.jsonschema.JsonSchema in project OpenAM by OpenRock.
the class ConditionTypesResourceTest 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 DecisionCombinersResourceTest method testSuccessfulJsonificationAndQuery.
@Test
public void testSuccessfulJsonificationAndQuery() throws JsonMappingException {
//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);
QueryRequest mockRequest = mock(QueryRequest.class);
QueryResourceHandler mockHandler = mock(QueryResourceHandler.class);
JsonSchema mockSchema = mock(JsonSchema.class);
given(mockMapper.generateJsonSchema((Class<?>) any(Class.class))).willReturn(mockSchema);
//when
testResource.queryCollection(mockServerContext, mockRequest, mockHandler);
//then
verify(mockHandler, times(1)).handleResource(any(ResourceResponse.class));
}
use of com.fasterxml.jackson.databind.jsonschema.JsonSchema 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);
}
Aggregations