Search in sources :

Example 51 with JCodeModel

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

the class TypeRuleTest method applyGeneratesArray.

@Test
public void applyGeneratesArray() {
    JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());
    ObjectNode objectNode = new ObjectMapper().createObjectNode();
    objectNode.put("type", "array");
    JClass mockArrayType = mock(JClass.class);
    ArrayRule mockArrayRule = mock(ArrayRule.class);
    when(mockArrayRule.apply("fooBar", objectNode, jpackage, null)).thenReturn(mockArrayType);
    when(ruleFactory.getArrayRule()).thenReturn(mockArrayRule);
    JType result = rule.apply("fooBar", objectNode, jpackage, null);
    assertThat(result, is((JType) mockArrayType));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JClass(com.sun.codemodel.JClass) 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 52 with JCodeModel

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

the class TypeRuleTest method applyGeneratesAnyAsObject.

@Test
public void applyGeneratesAnyAsObject() {
    JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());
    ObjectNode objectNode = new ObjectMapper().createObjectNode();
    objectNode.put("type", "any");
    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 53 with JCodeModel

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

the class TypeRuleTest method applyGeneratesNumberUsingJavaTypeDoublePrimitive.

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

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

the class TypeRuleTest method applyGeneratesIntegerUsingJavaTypeLongWhenMinimumGreaterThanIntegerMax.

@Test
public void applyGeneratesIntegerUsingJavaTypeLongWhenMinimumGreaterThanIntegerMax() {
    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(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 55 with JCodeModel

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

the class TypeRuleTest method applyGeneratesBigDecimal.

@Test
public void applyGeneratesBigDecimal() {
    JPackage jpackage = new JCodeModel()._package(getClass().getPackage().getName());
    ObjectNode objectNode = new ObjectMapper().createObjectNode();
    objectNode.put("type", "number");
    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)

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