Search in sources :

Example 46 with JCodeModel

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

the class TypeRuleTest method applyGeneratesBigDecimalOverridingDouble.

@Test
public void applyGeneratesBigDecimalOverridingDouble() {
    JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());
    ObjectNode objectNode = new ObjectMapper().createObjectNode();
    objectNode.put("type", "number");
    //this shows that isUseBigDecimals overrides isUseDoubleNumbers
    when(config.isUseDoubleNumbers()).thenReturn(true);
    when(config.isUseBigDecimals()).thenReturn(true);
    JType result = rule.apply("fooBar", objectNode, jpackage, null);
    assertThat(result.fullName(), is(BigDecimal.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 47 with JCodeModel

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

the class TypeRuleTest method applyGeneratesIntegerUsingJavaTypeLongPrimitiveWhenMinimumGreaterThanIntegerMax.

@Test
public void applyGeneratesIntegerUsingJavaTypeLongPrimitiveWhenMinimumGreaterThanIntegerMax() {
    JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());
    ObjectNode objectNode = new ObjectMapper().createObjectNode();
    objectNode.put("type", "integer");
    objectNode.put("minimum", Integer.MAX_VALUE + 1L);
    when(config.isUsePrimitives()).thenReturn(true);
    JType result = rule.apply("fooBar", objectNode, jpackage, null);
    assertThat(result.fullName(), is("long"));
}
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 48 with JCodeModel

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

the class TypeRuleTest method applyGeneratesNumberUsingJavaTypeDouble.

@Test
public void applyGeneratesNumberUsingJavaTypeDouble() {
    JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());
    ObjectNode objectNode = new ObjectMapper().createObjectNode();
    objectNode.put("type", "number");
    objectNode.put("javaType", "java.lang.Double");
    when(config.isUsePrimitives()).thenReturn(true);
    JType result = rule.apply("fooBar", objectNode, jpackage, null);
    assertThat(result.fullName(), is("java.lang.Double"));
}
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 49 with JCodeModel

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

the class TypeRuleTest method applyDefaultsToTypeAnyObject.

@Test
public void applyDefaultsToTypeAnyObject() {
    JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());
    ObjectNode objectNode = new ObjectMapper().createObjectNode();
    JType result = rule.apply("fooBar", objectNode, jpackage, null);
    assertThat(result.fullName(), is(Object.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 50 with JCodeModel

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

the class TypeRuleTest method applyGeneratesIntegerUsingJavaTypeLongPrimitiveWhenMinimumLessThanIntegerMin.

@Test
public void applyGeneratesIntegerUsingJavaTypeLongPrimitiveWhenMinimumLessThanIntegerMin() {
    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(true);
    JType result = rule.apply("fooBar", objectNode, jpackage, null);
    assertThat(result.fullName(), is("long"));
}
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)

Aggregations

JCodeModel (com.sun.codemodel.JCodeModel)77 Test (org.junit.Test)59 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)52 JPackage (com.sun.codemodel.JPackage)47 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)45 JType (com.sun.codemodel.JType)41 JDefinedClass (com.sun.codemodel.JDefinedClass)15 JClass (com.sun.codemodel.JClass)12 Schema (org.jsonschema2pojo.Schema)11 RuleFactory (org.jsonschema2pojo.rules.RuleFactory)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 TextNode (com.fasterxml.jackson.databind.node.TextNode)6 File (java.io.File)6 IOException (java.io.IOException)5 JBlock (com.sun.codemodel.JBlock)4 JCatchBlock (com.sun.codemodel.JCatchBlock)4 JMethod (com.sun.codemodel.JMethod)4 JTryBlock (com.sun.codemodel.JTryBlock)4 JVar (com.sun.codemodel.JVar)4 URL (java.net.URL)4