Search in sources :

Example 11 with JCodeModel

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

the class CommentRuleTest method applyAddsCommentToJavadoc.

@Test
public void applyAddsCommentToJavadoc() throws JClassAlreadyExistsException {
    JDefinedClass jclass = new JCodeModel()._class(TARGET_CLASS_NAME);
    ObjectMapper mapper = new ObjectMapper();
    TextNode commentNode = mapper.createObjectNode().textNode("some comment");
    JDocComment result = rule.apply("fooBar", commentNode, null, jclass, null);
    assertThat(result, sameInstance(jclass.javadoc()));
    assertThat(result.size(), is(1));
    assertThat((String) result.get(0), is("some comment"));
}
Also used : JDefinedClass(com.sun.codemodel.JDefinedClass) TextNode(com.fasterxml.jackson.databind.node.TextNode) JCodeModel(com.sun.codemodel.JCodeModel) JDocComment(com.sun.codemodel.JDocComment) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 12 with JCodeModel

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

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

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

the class RequiredRuleTest method applyAddsTextWhenRequired.

@Test
public void applyAddsTextWhenRequired() throws JClassAlreadyExistsException {
    JDefinedClass jclass = new JCodeModel()._class(TARGET_CLASS_NAME);
    ObjectMapper mapper = new ObjectMapper();
    BooleanNode descriptionNode = mapper.createObjectNode().booleanNode(true);
    JDocCommentable result = rule.apply("fooBar", descriptionNode, null, jclass, null);
    assertThat(result.javadoc(), sameInstance(jclass.javadoc()));
    assertThat(result.javadoc().size(), is(1));
    assertThat((String) result.javadoc().get(0), is("\n(Required)"));
}
Also used : JDocCommentable(com.sun.codemodel.JDocCommentable) JDefinedClass(com.sun.codemodel.JDefinedClass) JCodeModel(com.sun.codemodel.JCodeModel) BooleanNode(com.fasterxml.jackson.databind.node.BooleanNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 15 with JCodeModel

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

the class RequiredRuleTest method applySkipsTextWhenNotRequired.

@Test
public void applySkipsTextWhenNotRequired() throws JClassAlreadyExistsException {
    JDefinedClass jclass = new JCodeModel()._class(TARGET_CLASS_NAME);
    ObjectMapper mapper = new ObjectMapper();
    BooleanNode descriptionNode = mapper.createObjectNode().booleanNode(false);
    JDocCommentable result = rule.apply("fooBar", descriptionNode, null, jclass, null);
    assertThat(result.javadoc(), sameInstance(jclass.javadoc()));
    assertThat(result.javadoc().size(), is(0));
}
Also used : JDocCommentable(com.sun.codemodel.JDocCommentable) JDefinedClass(com.sun.codemodel.JDefinedClass) JCodeModel(com.sun.codemodel.JCodeModel) BooleanNode(com.fasterxml.jackson.databind.node.BooleanNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) 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