use of com.sun.codemodel.JDefinedClass in project jsonschema2pojo by joelittlejohn.
the class RequiredArrayRuleTest method shouldUpdateJavaDoc.
@Test
public void shouldUpdateJavaDoc() throws JClassAlreadyExistsException {
JDefinedClass jclass = new JCodeModel()._class(TARGET_CLASS_NAME);
jclass.field(JMod.PRIVATE, jclass.owner().ref(String.class), "fooBar");
jclass.field(JMod.PRIVATE, jclass.owner().ref(String.class), "foo");
ObjectMapper mapper = new ObjectMapper();
ArrayNode requiredNode = mapper.createArrayNode().add("fooBar");
rule.apply("Class", requiredNode, jclass, new Schema(null, requiredNode, requiredNode));
JDocComment fooBarJavaDoc = jclass.fields().get("fooBar").javadoc();
JDocComment fooJavaDoc = jclass.fields().get("foo").javadoc();
assertThat(fooBarJavaDoc.size(), is(1));
assertThat((String) fooBarJavaDoc.get(0), is("\n(Required)"));
assertThat(fooJavaDoc.size(), is(0));
}
use of com.sun.codemodel.JDefinedClass in project jsonschema2pojo by joelittlejohn.
the class RequiredArrayRuleTest method shouldUpdateAnnotations.
@Test
public void shouldUpdateAnnotations() throws JClassAlreadyExistsException {
setupRuleFactoryToIncludeJsr303();
JDefinedClass jclass = new JCodeModel()._class(TARGET_CLASS_NAME);
jclass.field(JMod.PRIVATE, jclass.owner().ref(String.class), "fooBar");
jclass.field(JMod.PRIVATE, jclass.owner().ref(String.class), "foo");
ObjectMapper mapper = new ObjectMapper();
ArrayNode requiredNode = mapper.createArrayNode().add("foo_bar");
rule.apply("Class", requiredNode, jclass, new Schema(null, requiredNode, requiredNode));
Collection<JAnnotationUse> fooBarAnnotations = jclass.fields().get("fooBar").annotations();
Collection<JAnnotationUse> fooAnnotations = jclass.fields().get("foo").annotations();
assertThat(fooBarAnnotations.size(), is(1));
assertThat(fooBarAnnotations.iterator().next().getAnnotationClass().name(), is(NotNull.class.getSimpleName()));
assertThat(fooAnnotations.size(), is(0));
}
use of com.sun.codemodel.JDefinedClass 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, jclass, null);
assertThat(result.javadoc(), sameInstance(jclass.javadoc()));
assertThat(result.javadoc().size(), is(1));
assertThat((String) result.javadoc().get(0), is("\n(Required)"));
}
use of com.sun.codemodel.JDefinedClass 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, jclass, null);
assertThat(result.javadoc(), sameInstance(jclass.javadoc()));
assertThat(result.javadoc().size(), is(0));
}
use of com.sun.codemodel.JDefinedClass in project jsonschema2pojo by joelittlejohn.
the class SchemaRuleTest method enumAsRootIsGeneratedCorrectly.
@Test
public void enumAsRootIsGeneratedCorrectly() throws URISyntaxException, JClassAlreadyExistsException {
ObjectNode schemaContent = new ObjectMapper().createObjectNode();
ObjectNode enumNode = schemaContent.objectNode();
enumNode.put("type", "string");
schemaContent.set("enum", enumNode);
JDefinedClass jclass = new JCodeModel()._class(TARGET_CLASS_NAME);
Schema schema = mock(Schema.class);
when(schema.getContent()).thenReturn(schemaContent);
schema.setJavaTypeIfEmpty(jclass);
EnumRule enumRule = mock(EnumRule.class);
when(mockRuleFactory.getEnumRule()).thenReturn(enumRule);
when(enumRule.apply(NODE_NAME, enumNode, jclass, schema)).thenReturn(jclass);
rule.apply(NODE_NAME, schemaContent, jclass, schema);
verify(enumRule).apply(NODE_NAME, schemaContent, jclass, schema);
verify(schema, atLeastOnce()).setJavaTypeIfEmpty(jclass);
}
Aggregations