Search in sources :

Example 71 with JsonDocument

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

the class JsonInstanceInspectorTest method inspectJsonDocumentSimpleArrayStartsWithWhiteSpace.

@Test
public void inspectJsonDocumentSimpleArrayStartsWithWhiteSpace() throws Exception {
    final String instance = "\n\t\r [ 100, 500, 300, 200, 400 ]";
    JsonDocument document = inspectionService.inspectJsonDocument(instance);
    assertNotNull(document);
    assertEquals(1, document.getFields().getField().size());
    JsonField jsonField = (JsonField) document.getFields().getField().get(0);
    assertEquals(FieldStatus.SUPPORTED, jsonField.getStatus());
    assertEquals(CollectionType.LIST, jsonField.getCollectionType());
    assertEquals(FieldType.INTEGER, jsonField.getFieldType());
    assertEquals("", jsonField.getName());
    assertEquals("/<>", jsonField.getPath());
}
Also used : JsonField(io.atlasmap.json.v2.JsonField) JsonDocument(io.atlasmap.json.v2.JsonDocument) Test(org.junit.jupiter.api.Test)

Example 72 with JsonDocument

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

the class JsonInstanceInspectorTest 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);
    assertNotNull(document);
    assertEquals(1, document.getFields().getField().size());
    JsonComplexType root = (JsonComplexType) document.getFields().getField().get(0);
    assertNotNull(root);
    assertEquals("SourceFlatPrimitive", root.getName());
    assertEquals("/SourceFlatPrimitive", root.getPath());
    assertEquals(FieldType.COMPLEX, root.getFieldType());
    assertEquals(FieldStatus.SUPPORTED, root.getStatus());
    assertEquals(8, root.getJsonFields().getJsonField().size());
    for (int i = 0; i < root.getJsonFields().getJsonField().size(); i++) {
        JsonField field = root.getJsonFields().getJsonField().get(i);
        if (i == 0) {
            assertEquals("booleanField", field.getName());
            assertEquals(false, field.getValue());
            assertEquals("/SourceFlatPrimitive/".concat(field.getName()), field.getPath());
            assertEquals(FieldType.BOOLEAN, field.getFieldType());
            assertEquals(FieldStatus.SUPPORTED, field.getStatus());
        } else if (i == 1) {
            assertEquals("charField", field.getName());
            assertEquals("a", field.getValue());
            assertEquals("/SourceFlatPrimitive/".concat(field.getName()), field.getPath());
            assertEquals(FieldType.STRING, field.getFieldType());
            assertEquals(FieldStatus.SUPPORTED, field.getStatus());
        } else if (i == 2) {
            assertEquals("doubleField", field.getName());
            assertEquals(-27152745.3422, field.getValue());
            assertEquals("/SourceFlatPrimitive/".concat(field.getName()), field.getPath());
            assertEquals(FieldType.DOUBLE, field.getFieldType());
            assertEquals(FieldStatus.SUPPORTED, field.getStatus());
        } else if (i == 3) {
            assertEquals("floatField", field.getName());
            assertEquals(-63988281.00, field.getValue());
            assertEquals("/SourceFlatPrimitive/".concat(field.getName()), field.getPath());
            assertEquals(FieldType.DOUBLE, field.getFieldType());
            assertEquals(FieldStatus.SUPPORTED, field.getStatus());
        } else if (i == 4) {
            assertEquals("intField", field.getName());
            assertEquals(8281, field.getValue());
            assertEquals("/SourceFlatPrimitive/".concat(field.getName()), field.getPath());
            assertEquals(FieldType.INTEGER, field.getFieldType());
            assertEquals(FieldStatus.SUPPORTED, field.getStatus());
        } else if (i == 5) {
            assertEquals("shortField", field.getName());
            assertEquals(81, field.getValue());
            assertEquals("/SourceFlatPrimitive/".concat(field.getName()), field.getPath());
            assertEquals(FieldType.INTEGER, field.getFieldType());
            assertEquals(FieldStatus.SUPPORTED, field.getStatus());
        } else if (i == 6) {
            assertEquals("longField", field.getName());
            assertEquals(3988281, field.getValue());
            assertEquals("/SourceFlatPrimitive/".concat(field.getName()), field.getPath());
            assertEquals(FieldType.INTEGER, field.getFieldType());
            assertEquals(FieldStatus.SUPPORTED, field.getStatus());
        }
    }
}
Also used : JsonField(io.atlasmap.json.v2.JsonField) JsonComplexType(io.atlasmap.json.v2.JsonComplexType) JsonDocument(io.atlasmap.json.v2.JsonDocument) Test(org.junit.jupiter.api.Test)

Example 73 with JsonDocument

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

the class JsonInstanceInspectorTest method inspectJsonDocumentNoRoot.

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

Example 74 with JsonDocument

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

the class JsonInstanceInspectorTest method inspectJsonDocumentSimpleArray.

@Test
public void inspectJsonDocumentSimpleArray() throws Exception {
    final String instance = "[ 100, 500, 300, 200, 400 ]";
    JsonDocument document = inspectionService.inspectJsonDocument(instance);
    assertNotNull(document);
    assertEquals(1, document.getFields().getField().size());
    JsonField jsonField = (JsonField) document.getFields().getField().get(0);
    assertEquals(FieldStatus.SUPPORTED, jsonField.getStatus());
    assertEquals(CollectionType.LIST, jsonField.getCollectionType());
    assertEquals(FieldType.INTEGER, jsonField.getFieldType());
    assertEquals("", jsonField.getName());
    assertEquals("/<>", jsonField.getPath());
// printDocument(document);
}
Also used : JsonField(io.atlasmap.json.v2.JsonField) JsonDocument(io.atlasmap.json.v2.JsonDocument) Test(org.junit.jupiter.api.Test)

Example 75 with JsonDocument

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

the class JsonInstanceInspectorTest method inspectJsonDocumentEscapedCharsInKeys.

@Test
public void inspectJsonDocumentEscapedCharsInKeys() throws Exception {
    final String instance = new String(Files.readAllBytes(Paths.get("src/test/resources/inspect/keys-with-escaped-characters.json")));
    JsonDocument document = inspectionService.inspectJsonDocument(instance);
    assertNotNull(document);
    assertEquals(7, document.getFields().getField().size());
    for (int i = 0; i < document.getFields().getField().size(); i++) {
        JsonField field = (JsonField) document.getFields().getField().get(i);
        if (i == 0) {
            assertEquals("'booleanField'", field.getName());
            assertEquals(false, field.getValue());
            assertEquals("/".concat(field.getName()), field.getPath());
            assertEquals(FieldType.BOOLEAN, field.getFieldType());
            assertEquals(FieldStatus.SUPPORTED, field.getStatus());
        } else if (i == 1) {
            assertEquals("\"charField\"", field.getName());
            assertEquals("a", field.getValue());
            assertEquals("/".concat(field.getName()), field.getPath());
            assertEquals(FieldType.STRING, field.getFieldType());
            assertEquals(FieldStatus.SUPPORTED, field.getStatus());
        } else if (i == 2) {
            assertEquals("\\doubleField", field.getName());
            assertEquals(-27152745.3422, field.getValue());
            assertEquals("/".concat(field.getName()), field.getPath());
            assertEquals(FieldType.DOUBLE, field.getFieldType());
            assertEquals(FieldStatus.SUPPORTED, field.getStatus());
        } else if (i == 3) {
            assertEquals("floatField\t", field.getName());
            assertEquals(-63988281.00, field.getValue());
            assertEquals("/".concat(field.getName()), field.getPath());
            assertEquals(FieldType.DOUBLE, field.getFieldType());
            assertEquals(FieldStatus.SUPPORTED, field.getStatus());
        } else if (i == 4) {
            assertEquals("intField\n", field.getName());
            assertEquals(8281, field.getValue());
            assertEquals("/".concat(field.getName()), field.getPath());
            assertEquals(FieldType.INTEGER, field.getFieldType());
            assertEquals(FieldStatus.SUPPORTED, field.getStatus());
        } else if (i == 5) {
            assertEquals("shortField", field.getName());
            assertEquals(81, field.getValue());
            assertEquals("/".concat(field.getName()), field.getPath());
            assertEquals(FieldType.INTEGER, field.getFieldType());
            assertEquals(FieldStatus.SUPPORTED, field.getStatus());
        } else if (i == 6) {
            assertEquals("longField", field.getName());
            assertEquals(3988281, field.getValue());
            assertEquals("/".concat(field.getName()), field.getPath());
            assertEquals(FieldType.INTEGER, field.getFieldType());
            assertEquals(FieldStatus.SUPPORTED, field.getStatus());
        }
    }
// printDocument(document);
}
Also used : JsonField(io.atlasmap.json.v2.JsonField) JsonDocument(io.atlasmap.json.v2.JsonDocument) Test(org.junit.jupiter.api.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