Search in sources :

Example 21 with JCodeModel

use of com.sun.codemodel.JCodeModel 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, null, 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 22 with JCodeModel

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

the class TypeRuleTest method applyGeneratesIntegerUsingJavaTypeLongPrimitiveWhenMaximumGreaterThanIntegerMax.

@Test
public void applyGeneratesIntegerUsingJavaTypeLongPrimitiveWhenMaximumGreaterThanIntegerMax() {
    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(true);
    JType result = rule.apply("fooBar", objectNode, null, 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 23 with JCodeModel

use of com.sun.codemodel.JCodeModel 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, null, 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 24 with JCodeModel

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

the class TypeRuleTest method applyGeneratesIntegerUsingJavaTypeInteger.

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

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

the class TypeRuleTest method applyGeneratesBigIntegerOverridingLong.

@Test
public void applyGeneratesBigIntegerOverridingLong() {
    JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());
    ObjectNode objectNode = new ObjectMapper().createObjectNode();
    objectNode.put("type", "integer");
    // isUseBigIntegers should override isUseLongIntegers
    when(config.isUseBigIntegers()).thenReturn(true);
    when(config.isUseLongIntegers()).thenReturn(true);
    JType result = rule.apply("fooBar", objectNode, null, jpackage, null);
    assertThat(result.fullName(), is(BigInteger.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)

Aggregations

JCodeModel (com.sun.codemodel.JCodeModel)89 Test (org.junit.Test)70 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)58 JPackage (com.sun.codemodel.JPackage)50 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)45 JType (com.sun.codemodel.JType)43 JDefinedClass (com.sun.codemodel.JDefinedClass)18 JClass (com.sun.codemodel.JClass)14 RuleFactory (org.jsonschema2pojo.rules.RuleFactory)14 Schema (org.jsonschema2pojo.Schema)13 JsonNode (com.fasterxml.jackson.databind.JsonNode)9 TextNode (com.fasterxml.jackson.databind.node.TextNode)7 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)5 File (java.io.File)5 IOException (java.io.IOException)5 URL (java.net.URL)5 JBlock (com.sun.codemodel.JBlock)4 JCatchBlock (com.sun.codemodel.JCatchBlock)4 JDocComment (com.sun.codemodel.JDocComment)4 JMethod (com.sun.codemodel.JMethod)4