Search in sources :

Example 6 with JType

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

the class TypeRuleTest method applyGeneratesInteger.

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

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

the class TypeRuleTest method applyGeneratesBigInteger.

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

Example 8 with JType

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

the class FormatRuleJodaTest method applyGeneratesTypeFromFormatValue.

@Test
public void applyGeneratesTypeFromFormatValue() {
    TextNode formatNode = TextNode.valueOf(formatValue);
    JType result = rule.apply("fooBar", formatNode, new JCodeModel().ref(String.class), null);
    assertThat(result.fullName(), equalTo(expectedType.getName()));
}
Also used : TextNode(com.fasterxml.jackson.databind.node.TextNode) JCodeModel(com.sun.codemodel.JCodeModel) JType(com.sun.codemodel.JType) Test(org.junit.Test)

Example 9 with JType

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

the class FormatRuleTest method applyDefaultsToBaseType.

@Test
public void applyDefaultsToBaseType() {
    TextNode formatNode = TextNode.valueOf("unknown-format");
    JType baseType = new JCodeModel().ref(Long.class);
    JType result = rule.apply("fooBar", formatNode, baseType, null);
    assertThat(result, equalTo(baseType));
}
Also used : TextNode(com.fasterxml.jackson.databind.node.TextNode) JCodeModel(com.sun.codemodel.JCodeModel) JType(com.sun.codemodel.JType) Test(org.junit.Test)

Example 10 with JType

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

the class SchemaRuleTest method existingTypeIsUsedWhenTypeIsAlreadyGenerated.

@Test
public void existingTypeIsUsedWhenTypeIsAlreadyGenerated() throws URISyntaxException {
    JType previouslyGeneratedType = mock(JType.class);
    URI schemaUri = getClass().getResource("/schema/address.json").toURI();
    SchemaStore schemaStore = new SchemaStore();
    Schema schema = schemaStore.create(schemaUri, "#/.");
    schema.setJavaType(previouslyGeneratedType);
    final GenerationConfig mockGenerationConfig = mock(GenerationConfig.class);
    when(mockGenerationConfig.getRefFragmentPathDelimiters()).thenReturn("#/.");
    when(mockRuleFactory.getSchemaStore()).thenReturn(schemaStore);
    when(mockRuleFactory.getGenerationConfig()).thenReturn(mockGenerationConfig);
    ObjectNode schemaNode = new ObjectMapper().createObjectNode();
    schemaNode.put("$ref", schemaUri.toString());
    JType result = rule.apply(NODE_NAME, schemaNode, null, schema);
    assertThat(result, is(sameInstance(previouslyGeneratedType)));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) SchemaStore(org.jsonschema2pojo.SchemaStore) Schema(org.jsonschema2pojo.Schema) URI(java.net.URI) JType(com.sun.codemodel.JType) GenerationConfig(org.jsonschema2pojo.GenerationConfig) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) 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