Search in sources :

Example 36 with ObjectNode

use of com.fasterxml.jackson.databind.node.ObjectNode 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 37 with ObjectNode

use of com.fasterxml.jackson.databind.node.ObjectNode 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 38 with ObjectNode

use of com.fasterxml.jackson.databind.node.ObjectNode in project jsonschema2pojo by joelittlejohn.

the class ArrayRuleTest method arrayWithNonUniqueItemsProducesList.

@Test
public void arrayWithNonUniqueItemsProducesList() {
    JCodeModel codeModel = new JCodeModel();
    JPackage jpackage = codeModel._package(getClass().getPackage().getName());
    ObjectMapper mapper = new ObjectMapper();
    ObjectNode itemsNode = mapper.createObjectNode();
    itemsNode.put("type", "number");
    ObjectNode propertyNode = mapper.createObjectNode();
    propertyNode.set("uniqueItems", BooleanNode.FALSE);
    propertyNode.set("items", itemsNode);
    Schema schema = mock(Schema.class);
    when(schema.getId()).thenReturn(URI.create("http://example/nonUniqueArray"));
    when(config.isUseDoubleNumbers()).thenReturn(true);
    JClass propertyType = rule.apply("fooBars", propertyNode, jpackage, schema);
    assertThat(propertyType, notNullValue());
    assertThat(propertyType.erasure(), is(codeModel.ref(List.class)));
    assertThat(propertyType.getTypeParameters().get(0).fullName(), is(Double.class.getName()));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Schema(org.jsonschema2pojo.Schema) JClass(com.sun.codemodel.JClass) JPackage(com.sun.codemodel.JPackage) JCodeModel(com.sun.codemodel.JCodeModel) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 39 with ObjectNode

use of com.fasterxml.jackson.databind.node.ObjectNode in project jsonschema2pojo by joelittlejohn.

the class ArrayRuleTest method arrayWithUniqueItemsProducesSet.

@Test
public void arrayWithUniqueItemsProducesSet() {
    JCodeModel codeModel = new JCodeModel();
    JPackage jpackage = codeModel._package(getClass().getPackage().getName());
    ObjectMapper mapper = new ObjectMapper();
    ObjectNode itemsNode = mapper.createObjectNode();
    itemsNode.put("type", "integer");
    ObjectNode propertyNode = mapper.createObjectNode();
    propertyNode.set("uniqueItems", BooleanNode.TRUE);
    propertyNode.set("items", itemsNode);
    JClass propertyType = rule.apply("fooBars", propertyNode, jpackage, mock(Schema.class));
    assertThat(propertyType, notNullValue());
    assertThat(propertyType.erasure(), is(codeModel.ref(Set.class)));
    assertThat(propertyType.getTypeParameters().get(0).fullName(), is(Integer.class.getName()));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JClass(com.sun.codemodel.JClass) Schema(org.jsonschema2pojo.Schema) JPackage(com.sun.codemodel.JPackage) JCodeModel(com.sun.codemodel.JCodeModel) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 40 with ObjectNode

use of com.fasterxml.jackson.databind.node.ObjectNode 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

ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)767 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)185 JsonNode (com.fasterxml.jackson.databind.JsonNode)165 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)165 Test (org.junit.Test)112 StringEntity (org.apache.http.entity.StringEntity)88 Deployment (org.activiti.engine.test.Deployment)84 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)67 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)64 Task (org.activiti.engine.task.Task)49 HttpPost (org.apache.http.client.methods.HttpPost)49 JCodeModel (com.sun.codemodel.JCodeModel)45 JPackage (com.sun.codemodel.JPackage)44 IOException (java.io.IOException)43 HttpPut (org.apache.http.client.methods.HttpPut)40 JType (com.sun.codemodel.JType)39 HashMap (java.util.HashMap)39 Cluster (org.apache.geode.tools.pulse.internal.data.Cluster)39 ArrayList (java.util.ArrayList)32 Map (java.util.Map)32