use of com.sun.codemodel.JCodeModel in project jsonschema2pojo by joelittlejohn.
the class SchemaRuleTest method enumAsRootIsGeneratedCorrectly.
@Test
public void enumAsRootIsGeneratedCorrectly() throws JClassAlreadyExistsException {
ObjectNode schemaContent = new ObjectMapper().createObjectNode();
ObjectNode enumNode = schemaContent.objectNode();
enumNode.put("type", "string");
schemaContent.set("enum", enumNode);
JDefinedClass jclass = new JCodeModel()._class(TARGET_CLASS_NAME);
Schema schema = mock(Schema.class);
when(schema.getContent()).thenReturn(schemaContent);
schema.setJavaTypeIfEmpty(jclass);
EnumRule enumRule = mock(EnumRule.class);
when(mockRuleFactory.getEnumRule()).thenReturn(enumRule);
when(enumRule.apply(NODE_NAME, enumNode, null, jclass, schema)).thenReturn(jclass);
rule.apply(NODE_NAME, schemaContent, null, jclass, schema);
verify(enumRule).apply(NODE_NAME, schemaContent, null, jclass, schema);
verify(schema, atLeastOnce()).setJavaTypeIfEmpty(jclass);
}
use of com.sun.codemodel.JCodeModel in project jsonschema2pojo by joelittlejohn.
the class TypeRuleTest method applyGeneratesIntegerUsingJavaTypeLong.
@Test
public void applyGeneratesIntegerUsingJavaTypeLong() {
JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());
ObjectNode objectNode = new ObjectMapper().createObjectNode();
objectNode.put("type", "integer");
objectNode.put("existingJavaType", "java.lang.Long");
when(config.isUsePrimitives()).thenReturn(true);
JType result = rule.apply("fooBar", objectNode, null, jpackage, null);
assertThat(result.fullName(), is("java.lang.Long"));
}
use of com.sun.codemodel.JCodeModel in project jsonschema2pojo by joelittlejohn.
the class TypeRuleTest method applyGeneratesBigInteger.
@Test
public void applyGeneratesBigInteger() {
JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());
ObjectNode objectNode = new ObjectMapper().createObjectNode();
objectNode.put("type", "integer");
when(config.isUseBigIntegers()).thenReturn(true);
JType result = rule.apply("fooBar", objectNode, null, jpackage, null);
assertThat(result.fullName(), is(BigInteger.class.getName()));
}
use of com.sun.codemodel.JCodeModel in project jsonschema2pojo by joelittlejohn.
the class TypeRuleTest method applyGeneratesInteger.
@Test
public void applyGeneratesInteger() {
JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());
ObjectNode objectNode = new ObjectMapper().createObjectNode();
objectNode.put("type", "integer");
JType result = rule.apply("fooBar", objectNode, null, jpackage, null);
assertThat(result.fullName(), is(Integer.class.getName()));
}
use of com.sun.codemodel.JCodeModel in project jsonschema2pojo by joelittlejohn.
the class TypeRuleTest method applyGeneratesCustomObject.
@Test
public void applyGeneratesCustomObject() {
JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());
ObjectNode objectNode = new ObjectMapper().createObjectNode();
objectNode.put("type", "object");
JDefinedClass mockObjectType = mock(JDefinedClass.class);
ObjectRule mockObjectRule = mock(ObjectRule.class);
when(mockObjectRule.apply("fooBar", objectNode, null, jpackage, null)).thenReturn(mockObjectType);
when(ruleFactory.getObjectRule()).thenReturn(mockObjectRule);
JType result = rule.apply("fooBar", objectNode, null, jpackage, null);
assertThat(result, is(mockObjectType));
}
Aggregations