Search in sources :

Example 46 with JsonDocument

use of io.atlasmap.json.v2.JsonDocument in project atlasmap by atlasmap.

the class JsonDocumentInspectionServiceTest method inspectFlatPrimitiveWithRoot.

@Test
public void inspectFlatPrimitiveWithRoot() throws Exception {
    final String instance = new String(Files.readAllBytes(Paths.get("src/test/resources/inspect/flatprimitive-base-rooted.json")));
    JsonDocument document = inspectionService.inspectJsonDocument(instance);
    Assert.assertNotNull(document);
    Assert.assertThat(document.getFields().getField().size(), Is.is(1));
    JsonComplexType root = (JsonComplexType) document.getFields().getField().get(0);
    Assert.assertNotNull(root);
    Assert.assertThat(root.getName(), Is.is("SourceFlatPrimitive"));
    Assert.assertThat(root.getPath(), Is.is("/SourceFlatPrimitive"));
    Assert.assertThat(root.getFieldType(), Is.is(FieldType.COMPLEX));
    Assert.assertThat(root.getStatus(), Is.is(FieldStatus.SUPPORTED));
    Assert.assertThat(root.getJsonFields().getJsonField().size(), Is.is(8));
    for (int i = 0; i < root.getJsonFields().getJsonField().size(); i++) {
        JsonField field = root.getJsonFields().getJsonField().get(i);
        if (i == 0) {
            Assert.assertThat(field.getName(), Is.is("booleanField"));
            Assert.assertThat(field.getValue(), Is.is(false));
            Assert.assertThat(field.getPath(), Is.is("/SourceFlatPrimitive/".concat(field.getName())));
            Assert.assertThat(field.getFieldType(), Is.is(FieldType.BOOLEAN));
            Assert.assertThat(field.getStatus(), Is.is(FieldStatus.SUPPORTED));
        } else if (i == 1) {
            Assert.assertThat(field.getName(), Is.is("charField"));
            Assert.assertThat(field.getValue(), Is.is("a"));
            Assert.assertThat(field.getPath(), Is.is("/SourceFlatPrimitive/".concat(field.getName())));
            Assert.assertThat(field.getFieldType(), Is.is(FieldType.STRING));
            Assert.assertThat(field.getStatus(), Is.is(FieldStatus.SUPPORTED));
        } else if (i == 2) {
            Assert.assertThat(field.getName(), Is.is("doubleField"));
            Assert.assertThat(field.getValue(), Is.is(-27152745.3422));
            Assert.assertThat(field.getPath(), Is.is("/SourceFlatPrimitive/".concat(field.getName())));
            Assert.assertThat(field.getFieldType(), Is.is(FieldType.DOUBLE));
            Assert.assertThat(field.getStatus(), Is.is(FieldStatus.SUPPORTED));
        } else if (i == 3) {
            Assert.assertThat(field.getName(), Is.is("floatField"));
            Assert.assertThat(field.getValue(), Is.is(-63988281.00));
            Assert.assertThat(field.getPath(), Is.is("/SourceFlatPrimitive/".concat(field.getName())));
            Assert.assertThat(field.getFieldType(), Is.is(FieldType.DOUBLE));
            Assert.assertThat(field.getStatus(), Is.is(FieldStatus.SUPPORTED));
        } else if (i == 4) {
            Assert.assertThat(field.getName(), Is.is("intField"));
            Assert.assertThat(field.getValue(), Is.is(8281));
            Assert.assertThat(field.getPath(), Is.is("/SourceFlatPrimitive/".concat(field.getName())));
            Assert.assertThat(field.getFieldType(), Is.is(FieldType.INTEGER));
            Assert.assertThat(field.getStatus(), Is.is(FieldStatus.SUPPORTED));
        } else if (i == 5) {
            Assert.assertThat(field.getName(), Is.is("shortField"));
            Assert.assertThat(field.getValue(), Is.is(81));
            Assert.assertThat(field.getPath(), Is.is("/SourceFlatPrimitive/".concat(field.getName())));
            Assert.assertThat(field.getFieldType(), Is.is(FieldType.INTEGER));
            Assert.assertThat(field.getStatus(), Is.is(FieldStatus.SUPPORTED));
        } else if (i == 6) {
            Assert.assertThat(field.getName(), Is.is("longField"));
            Assert.assertThat(field.getValue(), Is.is(3988281));
            Assert.assertThat(field.getPath(), Is.is("/SourceFlatPrimitive/".concat(field.getName())));
            Assert.assertThat(field.getFieldType(), Is.is(FieldType.INTEGER));
            Assert.assertThat(field.getStatus(), Is.is(FieldStatus.SUPPORTED));
        }
    }
}
Also used : JsonField(io.atlasmap.json.v2.JsonField) JsonComplexType(io.atlasmap.json.v2.JsonComplexType) JsonDocument(io.atlasmap.json.v2.JsonDocument) Test(org.junit.Test)

Example 47 with JsonDocument

use of io.atlasmap.json.v2.JsonDocument in project atlasmap by atlasmap.

the class JsonDocumentInspectionServiceTest method inspectJsonDocumentEscapedCharsInValue.

@Test
public void inspectJsonDocumentEscapedCharsInValue() throws Exception {
    final String instance = new String(Files.readAllBytes(Paths.get("src/test/resources/inspect/value-with-escaped-characters.json")));
    JsonDocument document = inspectionService.inspectJsonDocument(instance);
    Assert.assertNotNull(document);
    Assert.assertThat(document.getFields().getField().size(), Is.is(5));
    for (int i = 0; i < document.getFields().getField().size(); i++) {
        JsonField field = (JsonField) document.getFields().getField().get(i);
        if (i == 0) {
            Assert.assertThat(field.getName(), Is.is("quote"));
            Assert.assertThat(field.getValue(), Is.is("\"yadda\""));
            Assert.assertThat(field.getPath(), Is.is("/".concat(field.getName())));
            Assert.assertThat(field.getFieldType(), Is.is(FieldType.STRING));
            Assert.assertThat(field.getStatus(), Is.is(FieldStatus.SUPPORTED));
        } else if (i == 1) {
            Assert.assertThat(field.getName(), Is.is("singlequote"));
            Assert.assertThat(field.getValue(), Is.is("'a'"));
            Assert.assertThat(field.getPath(), Is.is("/".concat(field.getName())));
            Assert.assertThat(field.getFieldType(), Is.is(FieldType.STRING));
            Assert.assertThat(field.getStatus(), Is.is(FieldStatus.SUPPORTED));
        } else if (i == 2) {
            Assert.assertThat(field.getName(), Is.is("backslash"));
            Assert.assertThat(field.getValue(), Is.is("\\qwerty"));
            Assert.assertThat(field.getPath(), Is.is("/".concat(field.getName())));
            Assert.assertThat(field.getFieldType(), Is.is(FieldType.STRING));
            Assert.assertThat(field.getStatus(), Is.is(FieldStatus.SUPPORTED));
        } else if (i == 3) {
            Assert.assertThat(field.getName(), Is.is("tab"));
            Assert.assertThat(field.getValue(), Is.is("foo\t"));
            Assert.assertThat(field.getPath(), Is.is("/".concat(field.getName())));
            Assert.assertThat(field.getFieldType(), Is.is(FieldType.STRING));
            Assert.assertThat(field.getStatus(), Is.is(FieldStatus.SUPPORTED));
        } else if (i == 4) {
            Assert.assertThat(field.getName(), Is.is("linefeed"));
            Assert.assertThat(field.getValue(), Is.is("bar\n"));
            Assert.assertThat(field.getPath(), Is.is("/".concat(field.getName())));
            Assert.assertThat(field.getFieldType(), Is.is(FieldType.STRING));
            Assert.assertThat(field.getStatus(), Is.is(FieldStatus.SUPPORTED));
        }
    }
// printDocument(document);
}
Also used : JsonField(io.atlasmap.json.v2.JsonField) JsonDocument(io.atlasmap.json.v2.JsonDocument) Test(org.junit.Test)

Example 48 with JsonDocument

use of io.atlasmap.json.v2.JsonDocument in project atlasmap by atlasmap.

the class JsonDocumentInspectionServiceTest method inspectJsonDocumentEmptyDocument.

@Test()
public void inspectJsonDocumentEmptyDocument() throws Exception {
    final String instance = "{}";
    JsonDocument document = inspectionService.inspectJsonDocument(instance);
    Assert.assertNotNull(document);
    Assert.assertThat(document.getFields().getField().size(), Is.is(0));
}
Also used : JsonDocument(io.atlasmap.json.v2.JsonDocument) Test(org.junit.Test)

Example 49 with JsonDocument

use of io.atlasmap.json.v2.JsonDocument in project atlasmap by atlasmap.

the class JsonDocumentInspectionServiceTest method inspectJsonDocumentHighlyNestedObject.

@Test
public void inspectJsonDocumentHighlyNestedObject() throws Exception {
    final String instance = new String(Files.readAllBytes(Paths.get("src/test/resources/inspect/highly-nested-object.json")));
    JsonDocument document = inspectionService.inspectJsonDocument(instance);
    Assert.assertNotNull(document);
    Assert.assertThat(document.getFields().getField().size(), Is.is(6));
    JsonField id = (JsonField) document.getFields().getField().get(0);
    Assert.assertNotNull(id);
    Assert.assertThat(id.getName(), Is.is("id"));
    Assert.assertThat(id.getValue(), Is.is("0001"));
    Assert.assertThat(id.getPath(), Is.is("/id"));
    Assert.assertThat(id.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(id.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonField value = (JsonField) document.getFields().getField().get(1);
    Assert.assertNotNull(value);
    Assert.assertThat(value.getName(), Is.is("type"));
    Assert.assertThat(value.getValue(), Is.is("donut"));
    Assert.assertThat(value.getPath(), Is.is("/type"));
    Assert.assertThat(value.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(value.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonField name = (JsonField) document.getFields().getField().get(2);
    Assert.assertNotNull(name);
    Assert.assertThat(name.getName(), Is.is("name"));
    Assert.assertThat(name.getValue(), Is.is("Cake"));
    Assert.assertThat(name.getPath(), Is.is("/name"));
    Assert.assertThat(name.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(name.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonField itemPPU = (JsonField) document.getFields().getField().get(3);
    Assert.assertNotNull(itemPPU);
    Assert.assertThat(itemPPU.getName(), Is.is("ppu"));
    Assert.assertThat(itemPPU.getPath(), Is.is("/ppu"));
    Assert.assertThat(itemPPU.getValue(), Is.is(0.55));
    Assert.assertThat(itemPPU.getFieldType(), Is.is(FieldType.DOUBLE));
    Assert.assertThat(itemPPU.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonComplexType batters = (JsonComplexType) document.getFields().getField().get(4);
    Assert.assertNotNull(batters);
    Assert.assertThat(batters.getJsonFields().getJsonField().size(), Is.is(1));
    JsonComplexType batterParent = (JsonComplexType) batters.getJsonFields().getJsonField().get(0);
    Assert.assertNotNull(batterParent);
    Assert.assertThat(batterParent.getJsonFields().getJsonField().size(), Is.is(8));
    JsonField batter0Id = batterParent.getJsonFields().getJsonField().get(0);
    Assert.assertNotNull(batter0Id);
    Assert.assertThat(batter0Id.getName(), Is.is("id"));
    Assert.assertThat(batter0Id.getValue(), Is.is("1001"));
    Assert.assertThat(batter0Id.getPath(), Is.is("/batters/batter/id"));
    Assert.assertThat(batter0Id.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(batter0Id.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonField batter0Type = batterParent.getJsonFields().getJsonField().get(1);
    Assert.assertNotNull(batter0Type);
    Assert.assertThat(batter0Type.getName(), Is.is("type"));
    Assert.assertThat(batter0Type.getValue(), Is.is("Regular"));
    Assert.assertThat(batter0Type.getPath(), Is.is("/batters/batter/type"));
    Assert.assertThat(batter0Type.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(batter0Type.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonField batter1Id = batterParent.getJsonFields().getJsonField().get(2);
    Assert.assertNotNull(batter1Id);
    Assert.assertThat(batter1Id.getName(), Is.is("id"));
    Assert.assertThat(batter1Id.getValue(), Is.is("1002"));
    Assert.assertThat(batter1Id.getPath(), Is.is("/batters/batter[1]/id"));
    Assert.assertThat(batter1Id.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(batter1Id.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonField batter1Type = batterParent.getJsonFields().getJsonField().get(3);
    Assert.assertNotNull(batter1Type);
    Assert.assertThat(batter1Type.getName(), Is.is("type"));
    Assert.assertThat(batter1Type.getValue(), Is.is("Chocolate"));
    Assert.assertThat(batter1Type.getPath(), Is.is("/batters/batter[1]/type"));
    Assert.assertThat(batter1Type.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(batter1Type.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonField batter2Id = batterParent.getJsonFields().getJsonField().get(4);
    Assert.assertNotNull(batter2Id);
    Assert.assertThat(batter2Id.getName(), Is.is("id"));
    Assert.assertThat(batter2Id.getValue(), Is.is("1003"));
    Assert.assertThat(batter2Id.getPath(), Is.is("/batters/batter[2]/id"));
    Assert.assertThat(batter2Id.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(batter2Id.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonField batter2Type = batterParent.getJsonFields().getJsonField().get(5);
    Assert.assertNotNull(batter2Type);
    Assert.assertThat(batter2Type.getName(), Is.is("type"));
    Assert.assertThat(batter2Type.getValue(), Is.is("Blueberry"));
    Assert.assertThat(batter2Type.getPath(), Is.is("/batters/batter[2]/type"));
    Assert.assertThat(batter2Type.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(batter2Type.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonField batter3Id = batterParent.getJsonFields().getJsonField().get(6);
    Assert.assertNotNull(batter3Id);
    Assert.assertThat(batter3Id.getName(), Is.is("id"));
    Assert.assertThat(batter3Id.getValue(), Is.is("1004"));
    Assert.assertThat(batter3Id.getPath(), Is.is("/batters/batter[3]/id"));
    Assert.assertThat(batter3Id.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(batter3Id.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonField batter3Type = batterParent.getJsonFields().getJsonField().get(7);
    Assert.assertNotNull(batter3Type);
    Assert.assertThat(batter3Type.getName(), Is.is("type"));
    Assert.assertThat(batter3Type.getValue(), Is.is("Devil's Food"));
    Assert.assertThat(batter3Type.getPath(), Is.is("/batters/batter[3]/type"));
    Assert.assertThat(batter3Type.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(batter3Type.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonComplexType topping = (JsonComplexType) document.getFields().getField().get(5);
    Assert.assertNotNull(topping);
    Assert.assertThat(topping.getJsonFields().getJsonField().size(), Is.is(14));
    JsonField toppingId0 = topping.getJsonFields().getJsonField().get(0);
    Assert.assertNotNull(toppingId0);
    Assert.assertThat(toppingId0.getName(), Is.is("id"));
    Assert.assertThat(toppingId0.getValue(), Is.is("5001"));
    Assert.assertThat(toppingId0.getPath(), Is.is("/topping/id"));
    Assert.assertThat(toppingId0.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(toppingId0.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonField toppingType0 = topping.getJsonFields().getJsonField().get(1);
    Assert.assertNotNull(toppingType0);
    Assert.assertThat(toppingType0.getName(), Is.is("type"));
    Assert.assertThat(toppingType0.getValue(), Is.is("None"));
    Assert.assertThat(toppingType0.getPath(), Is.is("/topping/type"));
    Assert.assertThat(toppingType0.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(toppingType0.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonField toppingId1 = topping.getJsonFields().getJsonField().get(2);
    Assert.assertNotNull(toppingId1);
    Assert.assertThat(toppingId1.getName(), Is.is("id"));
    Assert.assertThat(toppingId1.getValue(), Is.is("5002"));
    Assert.assertThat(toppingId1.getPath(), Is.is("/topping/id[1]"));
    Assert.assertThat(toppingId1.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(toppingId1.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonField toppingType1 = topping.getJsonFields().getJsonField().get(3);
    Assert.assertNotNull(toppingType1);
    Assert.assertThat(toppingType1.getName(), Is.is("type"));
    Assert.assertThat(toppingType1.getValue(), Is.is("Glazed"));
    Assert.assertThat(toppingType1.getPath(), Is.is("/topping/type[1]"));
    Assert.assertThat(toppingType1.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(toppingType1.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonField toppingId2 = topping.getJsonFields().getJsonField().get(4);
    Assert.assertNotNull(toppingId2);
    Assert.assertThat(toppingId2.getName(), Is.is("id"));
    Assert.assertThat(toppingId2.getValue(), Is.is("5005"));
    Assert.assertThat(toppingId2.getPath(), Is.is("/topping/id[2]"));
    Assert.assertThat(toppingId2.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(toppingId2.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonField toppingType2 = topping.getJsonFields().getJsonField().get(5);
    Assert.assertNotNull(toppingType2);
    Assert.assertThat(toppingType2.getName(), Is.is("type"));
    Assert.assertThat(toppingType2.getValue(), Is.is("Sugar"));
    Assert.assertThat(toppingType2.getPath(), Is.is("/topping/type[2]"));
    Assert.assertThat(toppingType2.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(toppingType2.getStatus(), Is.is(FieldStatus.SUPPORTED));
// etc....
// printDocument(document);
}
Also used : JsonField(io.atlasmap.json.v2.JsonField) JsonComplexType(io.atlasmap.json.v2.JsonComplexType) JsonDocument(io.atlasmap.json.v2.JsonDocument) Test(org.junit.Test)

Example 50 with JsonDocument

use of io.atlasmap.json.v2.JsonDocument in project atlasmap by atlasmap.

the class JsonDocumentInspectionServiceTest method inspectJsonDocumentWithRoot.

@Test
public void inspectJsonDocumentWithRoot() throws Exception {
    final String instance = "{\"car\" :{ \"brand\" : \"Mercedes\", \"doors\" : 5 } }";
    JsonDocument document = inspectionService.inspectJsonDocument(instance);
    Assert.assertNotNull(document);
    Assert.assertThat(document.getFields().getField().size(), Is.is(1));
    JsonComplexType car = (JsonComplexType) document.getFields().getField().get(0);
    Assert.assertNotNull(car);
    Assert.assertThat(car.getName(), Is.is("car"));
    Assert.assertThat(car.getFieldType(), Is.is(FieldType.COMPLEX));
    Assert.assertThat(car.getPath(), Is.is("/car"));
    Assert.assertThat(car.getStatus(), Is.is(FieldStatus.SUPPORTED));
    Assert.assertThat(car.getJsonFields().getJsonField().size(), Is.is(2));
    JsonField field1 = car.getJsonFields().getJsonField().get(0);
    Assert.assertNotNull(field1);
    Assert.assertThat(field1.getName(), Is.is("brand"));
    Assert.assertThat(field1.getValue(), Is.is("Mercedes"));
    Assert.assertThat(field1.getPath(), Is.is("/car/brand"));
    Assert.assertThat(field1.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(field1.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonField field2 = car.getJsonFields().getJsonField().get(1);
    Assert.assertNotNull(field2);
    Assert.assertThat(field2.getName(), Is.is("doors"));
    Assert.assertThat(field2.getValue(), Is.is(5));
    Assert.assertThat(field2.getPath(), Is.is("/car/doors"));
    Assert.assertThat(field2.getFieldType(), Is.is(FieldType.INTEGER));
    Assert.assertThat(field2.getStatus(), Is.is(FieldStatus.SUPPORTED));
// printDocument(document);
}
Also used : JsonField(io.atlasmap.json.v2.JsonField) JsonComplexType(io.atlasmap.json.v2.JsonComplexType) JsonDocument(io.atlasmap.json.v2.JsonDocument) Test(org.junit.Test)

Aggregations

JsonDocument (io.atlasmap.json.v2.JsonDocument)73 JsonField (io.atlasmap.json.v2.JsonField)65 JsonComplexType (io.atlasmap.json.v2.JsonComplexType)38 Test (org.junit.jupiter.api.Test)32 Test (org.junit.Test)29 Field (io.atlasmap.v2.Field)11 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 JsonEnumField (io.atlasmap.json.v2.JsonEnumField)6 IOException (java.io.IOException)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 JsonInspectionService (io.atlasmap.json.inspect.JsonInspectionService)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ValueNode (com.fasterxml.jackson.databind.node.ValueNode)2 JsonFields (io.atlasmap.json.v2.JsonFields)2 JsonInspectionRequest (io.atlasmap.json.v2.JsonInspectionRequest)2 JsonInspectionResponse (io.atlasmap.json.v2.JsonInspectionResponse)2 Path (java.nio.file.Path)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2