Search in sources :

Example 1 with JPackage

use of com.sun.codemodel.JPackage in project jsonschema2pojo by joelittlejohn.

the class TypeRuleTest method applyGeneratesIntegerUsingJavaTypeLongWhenMaximumGreaterThanIntegerMax.

@Test
public void applyGeneratesIntegerUsingJavaTypeLongWhenMaximumGreaterThanIntegerMax() {
    JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());
    ObjectNode objectNode = new ObjectMapper().createObjectNode();
    objectNode.put("type", "integer");
    objectNode.put("maximum", Integer.MAX_VALUE + 1L);
    when(config.isUsePrimitives()).thenReturn(false);
    JType result = rule.apply("fooBar", objectNode, jpackage, null);
    assertThat(result.fullName(), is(Long.class.getName()));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JPackage(com.sun.codemodel.JPackage) JCodeModel(com.sun.codemodel.JCodeModel) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JType(com.sun.codemodel.JType) Test(org.junit.Test)

Example 2 with JPackage

use of com.sun.codemodel.JPackage in project jsonschema2pojo by joelittlejohn.

the class TypeRuleTest method applyGeneratesIntegerUsingJavaTypeBigInteger.

@Test
public void applyGeneratesIntegerUsingJavaTypeBigInteger() {
    JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());
    ObjectNode objectNode = new ObjectMapper().createObjectNode();
    objectNode.put("type", "integer");
    objectNode.put("javaType", "java.math.BigInteger");
    JType result = rule.apply("fooBar", objectNode, jpackage, null);
    assertThat(result.fullName(), is("java.math.BigInteger"));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JPackage(com.sun.codemodel.JPackage) JCodeModel(com.sun.codemodel.JCodeModel) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JType(com.sun.codemodel.JType) Test(org.junit.Test)

Example 3 with JPackage

use of com.sun.codemodel.JPackage in project jsonschema2pojo by joelittlejohn.

the class TypeRuleTest method applyGeneratesIntegerUsingJavaTypeIntegerPrimitive.

@Test
public void applyGeneratesIntegerUsingJavaTypeIntegerPrimitive() {
    JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());
    ObjectNode objectNode = new ObjectMapper().createObjectNode();
    objectNode.put("type", "integer");
    objectNode.put("javaType", "int");
    when(config.isUsePrimitives()).thenReturn(false);
    JType result = rule.apply("fooBar", objectNode, jpackage, null);
    assertThat(result.fullName(), is("int"));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JPackage(com.sun.codemodel.JPackage) JCodeModel(com.sun.codemodel.JCodeModel) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JType(com.sun.codemodel.JType) Test(org.junit.Test)

Example 4 with JPackage

use of com.sun.codemodel.JPackage in project jsonschema2pojo by joelittlejohn.

the class TypeRuleTest method applyGeneratesIntegerUsingJavaTypeLongWhenMinimumLessThanIntegerMin.

@Test
public void applyGeneratesIntegerUsingJavaTypeLongWhenMinimumLessThanIntegerMin() {
    JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());
    ObjectNode objectNode = new ObjectMapper().createObjectNode();
    objectNode.put("type", "integer");
    objectNode.put("minimum", Integer.MIN_VALUE - 1L);
    when(config.isUsePrimitives()).thenReturn(false);
    JType result = rule.apply("fooBar", objectNode, jpackage, null);
    assertThat(result.fullName(), is(Long.class.getName()));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JPackage(com.sun.codemodel.JPackage) JCodeModel(com.sun.codemodel.JCodeModel) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JType(com.sun.codemodel.JType) Test(org.junit.Test)

Example 5 with JPackage

use of com.sun.codemodel.JPackage 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, jpackage, null)).thenReturn(mockObjectType);
    when(ruleFactory.getObjectRule()).thenReturn(mockObjectRule);
    JType result = rule.apply("fooBar", objectNode, jpackage, null);
    assertThat(result, is((JType) mockObjectType));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JDefinedClass(com.sun.codemodel.JDefinedClass) JPackage(com.sun.codemodel.JPackage) JCodeModel(com.sun.codemodel.JCodeModel) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JType(com.sun.codemodel.JType) Test(org.junit.Test)

Aggregations

JPackage (com.sun.codemodel.JPackage)53 JCodeModel (com.sun.codemodel.JCodeModel)47 Test (org.junit.Test)47 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)44 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)44 JType (com.sun.codemodel.JType)37 JsonNode (com.fasterxml.jackson.databind.JsonNode)7 JClass (com.sun.codemodel.JClass)7 Schema (org.jsonschema2pojo.Schema)7 RuleFactory (org.jsonschema2pojo.rules.RuleFactory)6 SchemaRule (org.jsonschema2pojo.rules.SchemaRule)4 JDefinedClass (com.sun.codemodel.JDefinedClass)3 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 TextNode (com.fasterxml.jackson.databind.node.TextNode)1 DataList (com.linkedin.data.DataList)1 DataMap (com.linkedin.data.DataMap)1 ValidationOptions (com.linkedin.data.schema.validation.ValidationOptions)1 ValidationResult (com.linkedin.data.schema.validation.ValidationResult)1