use of org.jsonschema2pojo.GenerationConfig in project jsonschema2pojo by joelittlejohn.
the class SchemaRuleTest method refsToOtherSchemasAreLoaded.
@Test
public void refsToOtherSchemasAreLoaded() throws URISyntaxException, JClassAlreadyExistsException {
URI schemaUri = getClass().getResource("/schema/address.json").toURI();
ObjectNode schemaWithRef = new ObjectMapper().createObjectNode();
schemaWithRef.put("$ref", schemaUri.toString());
JDefinedClass jclass = new JCodeModel()._class(TARGET_CLASS_NAME);
final GenerationConfig mockGenerationConfig = mock(GenerationConfig.class);
when(mockGenerationConfig.getRefFragmentPathDelimiters()).thenReturn("#/.");
TypeRule mockTypeRule = mock(TypeRule.class);
when(mockRuleFactory.getTypeRule()).thenReturn(mockTypeRule);
when(mockRuleFactory.getSchemaStore()).thenReturn(new SchemaStore());
when(mockRuleFactory.getGenerationConfig()).thenReturn(mockGenerationConfig);
ArgumentCaptor<JsonNode> captureJsonNode = ArgumentCaptor.forClass(JsonNode.class);
ArgumentCaptor<Schema> captureSchema = ArgumentCaptor.forClass(Schema.class);
rule.apply(NODE_NAME, schemaWithRef, jclass, null);
verify(mockTypeRule).apply(eq(NODE_NAME), captureJsonNode.capture(), eq(jclass.getPackage()), captureSchema.capture());
assertThat(captureSchema.getValue().getId(), is(equalTo(schemaUri)));
assertThat(captureSchema.getValue().getContent(), is(equalTo(captureJsonNode.getValue())));
assertThat(captureJsonNode.getValue().get("description").asText(), is(equalTo("An Address following the convention of http://microformats.org/wiki/hcard")));
}
Aggregations