use of org.jsonschema2pojo.rules.SchemaRule in project jsonschema2pojo by joelittlejohn.
the class SchemaMapperTest method generateReadsSchemaAsObject.
@Test
public void generateReadsSchemaAsObject() throws IOException {
final SchemaRule mockSchemaRule = mock(SchemaRule.class);
final RuleFactory mockRuleFactory = mock(RuleFactory.class);
when(mockRuleFactory.getSchemaRule()).thenReturn(mockSchemaRule);
when(mockRuleFactory.getGenerationConfig()).thenReturn(new DefaultGenerationConfig());
URL schemaContent = this.getClass().getResource("/schema/address.json");
new SchemaMapper(mockRuleFactory, new SchemaGenerator()).generate(new JCodeModel(), "Address", "com.example.package", schemaContent);
ArgumentCaptor<JPackage> capturePackage = ArgumentCaptor.forClass(JPackage.class);
ArgumentCaptor<JsonNode> captureNode = ArgumentCaptor.forClass(JsonNode.class);
verify(mockSchemaRule).apply(eq("Address"), captureNode.capture(), capturePackage.capture(), Mockito.isA(Schema.class));
assertThat(capturePackage.getValue().name(), is("com.example.package"));
assertThat(captureNode.getValue(), is(notNullValue()));
}
use of org.jsonschema2pojo.rules.SchemaRule in project jsonschema2pojo by joelittlejohn.
the class SchemaMapperTest method generateCreatesSchemaFromSchemaAsStringInput.
@Test
public void generateCreatesSchemaFromSchemaAsStringInput() throws IOException {
String schemaContent = IOUtils.toString(this.getClass().getResourceAsStream("/schema/address.json"));
final SchemaRule mockSchemaRule = mock(SchemaRule.class);
final RuleFactory mockRuleFactory = mock(RuleFactory.class);
when(mockRuleFactory.getSchemaRule()).thenReturn(mockSchemaRule);
when(mockRuleFactory.getGenerationConfig()).thenReturn(new DefaultGenerationConfig());
new SchemaMapper(mockRuleFactory, new SchemaGenerator()).generate(new JCodeModel(), "Address", "com.example.package", schemaContent);
ArgumentCaptor<JPackage> capturePackage = ArgumentCaptor.forClass(JPackage.class);
ArgumentCaptor<JsonNode> captureNode = ArgumentCaptor.forClass(JsonNode.class);
verify(mockSchemaRule).apply(eq("Address"), captureNode.capture(), capturePackage.capture(), Mockito.isA(Schema.class));
assertThat(capturePackage.getValue().name(), is("com.example.package"));
assertThat(captureNode.getValue(), is(notNullValue()));
}
use of org.jsonschema2pojo.rules.SchemaRule in project jsonschema2pojo by joelittlejohn.
the class SchemaMapperTest method generateCreatesSchemaFromExampleJSONAsStringInput.
@Test
public void generateCreatesSchemaFromExampleJSONAsStringInput() throws IOException {
String jsonContent = IOUtils.toString(this.getClass().getResourceAsStream("/example-json/user.json"));
ObjectNode schemaNode = JsonNodeFactory.instance.objectNode();
final SchemaRule mockSchemaRule = mock(SchemaRule.class);
final GenerationConfig mockGenerationConfig = mock(GenerationConfig.class);
when(mockGenerationConfig.getSourceType()).thenReturn(SourceType.JSON);
final SchemaGenerator mockSchemaGenerator = mock(SchemaGenerator.class);
when(mockSchemaGenerator.schemaFromExample(new ObjectMapper().readTree(jsonContent))).thenReturn(schemaNode);
final RuleFactory mockRuleFactory = mock(RuleFactory.class);
when(mockRuleFactory.getSchemaRule()).thenReturn(mockSchemaRule);
when(mockRuleFactory.getGenerationConfig()).thenReturn(mockGenerationConfig);
new SchemaMapper(mockRuleFactory, mockSchemaGenerator).generate(new JCodeModel(), "User", "com.example.package", jsonContent);
ArgumentCaptor<JPackage> capturePackage = ArgumentCaptor.forClass(JPackage.class);
verify(mockSchemaRule).apply(eq("User"), eq(schemaNode), capturePackage.capture(), Mockito.isA(Schema.class));
assertThat(capturePackage.getValue().name(), is("com.example.package"));
}
use of org.jsonschema2pojo.rules.SchemaRule in project jsonschema2pojo by joelittlejohn.
the class SchemaMapperTest method generateCreatesSchemaFromExampleJsonWhenInJsonMode.
@Test
public void generateCreatesSchemaFromExampleJsonWhenInJsonMode() throws IOException {
URL schemaContent = this.getClass().getResource("/schema/address.json");
ObjectNode schemaNode = JsonNodeFactory.instance.objectNode();
final SchemaRule mockSchemaRule = mock(SchemaRule.class);
final GenerationConfig mockGenerationConfig = mock(GenerationConfig.class);
when(mockGenerationConfig.getSourceType()).thenReturn(SourceType.JSON);
final SchemaGenerator mockSchemaGenerator = mock(SchemaGenerator.class);
when(mockSchemaGenerator.schemaFromExample(schemaContent)).thenReturn(schemaNode);
final RuleFactory mockRuleFactory = mock(RuleFactory.class);
when(mockRuleFactory.getSchemaRule()).thenReturn(mockSchemaRule);
when(mockRuleFactory.getGenerationConfig()).thenReturn(mockGenerationConfig);
new SchemaMapper(mockRuleFactory, mockSchemaGenerator).generate(new JCodeModel(), "Address", "com.example.package", schemaContent);
ArgumentCaptor<JPackage> capturePackage = ArgumentCaptor.forClass(JPackage.class);
verify(mockSchemaRule).apply(eq("Address"), eq(schemaNode), capturePackage.capture(), Mockito.isA(Schema.class));
assertThat(capturePackage.getValue().name(), is("com.example.package"));
}
Aggregations