Search in sources :

Example 1 with JType

use of com.sun.codemodel.JType 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 JType

use of com.sun.codemodel.JType 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 JType

use of com.sun.codemodel.JType 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 JType

use of com.sun.codemodel.JType 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 JType

use of com.sun.codemodel.JType 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

JType (com.sun.codemodel.JType)65 Test (org.junit.Test)42 JCodeModel (com.sun.codemodel.JCodeModel)41 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)39 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)38 JPackage (com.sun.codemodel.JPackage)37 JVar (com.sun.codemodel.JVar)13 JBlock (com.sun.codemodel.JBlock)10 JMethod (com.sun.codemodel.JMethod)10 JClass (com.sun.codemodel.JClass)9 JDefinedClass (com.sun.codemodel.JDefinedClass)9 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 Map (java.util.Map)5 TextNode (com.fasterxml.jackson.databind.node.TextNode)4 JClassAlreadyExistsException (com.sun.codemodel.JClassAlreadyExistsException)3 JExpression (com.sun.codemodel.JExpression)3 JFieldVar (com.sun.codemodel.JFieldVar)3 JInvocation (com.sun.codemodel.JInvocation)3 JConditional (com.sun.codemodel.JConditional)2 JSwitch (com.sun.codemodel.JSwitch)2