Search in sources :

Example 6 with GenerationConfig

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")));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JDefinedClass(com.sun.codemodel.JDefinedClass) SchemaStore(org.jsonschema2pojo.SchemaStore) Schema(org.jsonschema2pojo.Schema) JsonNode(com.fasterxml.jackson.databind.JsonNode) URI(java.net.URI) JCodeModel(com.sun.codemodel.JCodeModel) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) GenerationConfig(org.jsonschema2pojo.GenerationConfig) Test(org.junit.Test)

Aggregations

GenerationConfig (org.jsonschema2pojo.GenerationConfig)6 SchemaStore (org.jsonschema2pojo.SchemaStore)4 Test (org.junit.Test)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 JCodeModel (com.sun.codemodel.JCodeModel)2 URI (java.net.URI)2 DefaultGenerationConfig (org.jsonschema2pojo.DefaultGenerationConfig)2 Schema (org.jsonschema2pojo.Schema)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 JDefinedClass (com.sun.codemodel.JDefinedClass)1 JType (com.sun.codemodel.JType)1 File (java.io.File)1 URL (java.net.URL)1 Jackson2Annotator (org.jsonschema2pojo.Jackson2Annotator)1 NoopAnnotator (org.jsonschema2pojo.NoopAnnotator)1 SchemaGenerator (org.jsonschema2pojo.SchemaGenerator)1 SchemaMapper (org.jsonschema2pojo.SchemaMapper)1 RuleFactory (org.jsonschema2pojo.rules.RuleFactory)1