Search in sources :

Example 76 with JsonDocument

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

the class JsonInstanceInspectorTest method inspectFlatPrimitiveNoRoot.

// FlatPrimitive
@Test
public void inspectFlatPrimitiveNoRoot() throws Exception {
    final String instance = new String(Files.readAllBytes(Paths.get("src/test/resources/inspect/flatprimitive-base-unrooted.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());
            // FIXME DOES NOT RECOGNIZE CHAR DISTINCTLY AND RETURNS THIS AS A STRING
            // (TEXTUAL)
            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", field.getName());
            assertEquals(-63988281.00, field.getValue());
            assertEquals("/".concat(field.getName()), field.getPath());
            // FIXME DOES NOT RECOGNIZE FLOAT DISTINCTLY AND RETURNS THIS AS A DOUBLE
            assertEquals(FieldType.DOUBLE, field.getFieldType());
            assertEquals(FieldStatus.SUPPORTED, field.getStatus());
        } else if (i == 4) {
            assertEquals("intField", 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());
            // FIXME JSON DOES NOT RECOGNIZE SHORT DISTINCTLY AND RETURNS THIS AS A INTEGER
            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());
            // FIXME JSON DOES NOT RECOGNIZE LONG DISTINCTLY AND RETURNS THIS AS A INTEGER
            assertEquals(FieldType.INTEGER, field.getFieldType());
            assertEquals(FieldStatus.SUPPORTED, field.getStatus());
        }
    }
}
Also used : JsonField(io.atlasmap.json.v2.JsonField) JsonDocument(io.atlasmap.json.v2.JsonDocument) Test(org.junit.jupiter.api.Test)

Example 77 with JsonDocument

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

the class JsonInstanceInspectorTest method inspectComplexObjectWithRoot.

@Test
public void inspectComplexObjectWithRoot() throws Exception {
    final String instance = new String(Files.readAllBytes(Paths.get("src/test/resources/inspect/complex-object-rooted.json")));
    JsonDocument document = inspectionService.inspectJsonDocument(instance);
    assertNotNull(document);
    assertEquals(1, document.getFields().getField().size());
    JsonComplexType root = (JsonComplexType) document.getFields().getField().get(0);
    assertEquals(3, root.getJsonFields().getJsonField().size());
    JsonComplexType address = (JsonComplexType) root.getJsonFields().getJsonField().get(0);
    assertNotNull(address);
    assertEquals(5, address.getJsonFields().getJsonField().size());
    JsonField address1 = address.getJsonFields().getJsonField().get(0);
    assertNotNull(address1);
    assertEquals("addressLine1", address1.getName());
    assertEquals("123 Main St", address1.getValue());
    assertEquals("/order/address/addressLine1", address1.getPath());
    assertEquals(FieldType.STRING, address1.getFieldType());
    assertEquals(FieldStatus.SUPPORTED, address1.getStatus());
    JsonField address2 = address.getJsonFields().getJsonField().get(1);
    assertNotNull(address2);
    assertEquals("addressLine2", address2.getName());
    assertEquals("Suite 42b", address2.getValue());
    assertEquals("/order/address/addressLine2", address2.getPath());
    assertEquals(FieldType.STRING, address2.getFieldType());
    assertEquals(FieldStatus.SUPPORTED, address2.getStatus());
    JsonField city = address.getJsonFields().getJsonField().get(2);
    assertNotNull(city);
    assertEquals("city", city.getName());
    assertEquals("Anytown", city.getValue());
    assertEquals("/order/address/city", city.getPath());
    assertEquals(FieldType.STRING, city.getFieldType());
    assertEquals(FieldStatus.SUPPORTED, city.getStatus());
    JsonField state = address.getJsonFields().getJsonField().get(3);
    assertNotNull(state);
    assertEquals("state", state.getName());
    assertEquals("NY", state.getValue());
    assertEquals("/order/address/state", state.getPath());
    assertEquals(FieldType.STRING, state.getFieldType());
    assertEquals(FieldStatus.SUPPORTED, state.getStatus());
    JsonField postalCode = address.getJsonFields().getJsonField().get(4);
    assertNotNull(postalCode);
    assertEquals("zipCode", postalCode.getName());
    assertEquals("90210", postalCode.getValue());
    assertEquals("/order/address/zipCode", postalCode.getPath());
    assertEquals(FieldType.STRING, postalCode.getFieldType());
    assertEquals(FieldStatus.SUPPORTED, postalCode.getStatus());
    JsonComplexType contact = (JsonComplexType) root.getJsonFields().getJsonField().get(1);
    assertNotNull(contact);
    assertEquals(4, contact.getJsonFields().getJsonField().size());
    JsonField firstName = contact.getJsonFields().getJsonField().get(0);
    assertNotNull(firstName);
    assertEquals("firstName", firstName.getName());
    assertEquals("Ozzie", firstName.getValue());
    assertEquals("/order/contact/firstName", firstName.getPath());
    assertEquals(FieldType.STRING, firstName.getFieldType());
    assertEquals(FieldStatus.SUPPORTED, firstName.getStatus());
    JsonField lastName = contact.getJsonFields().getJsonField().get(1);
    assertNotNull(lastName);
    assertEquals("lastName", lastName.getName());
    assertEquals("Smith", lastName.getValue());
    assertEquals("/order/contact/lastName", lastName.getPath());
    assertEquals(FieldType.STRING, lastName.getFieldType());
    assertEquals(FieldStatus.SUPPORTED, lastName.getStatus());
    JsonField phoneNumber = contact.getJsonFields().getJsonField().get(2);
    assertNotNull(phoneNumber);
    assertEquals("phoneNumber", phoneNumber.getName());
    assertEquals("5551212", phoneNumber.getValue());
    assertEquals("/order/contact/phoneNumber", phoneNumber.getPath());
    assertEquals(FieldType.STRING, phoneNumber.getFieldType());
    assertEquals(FieldStatus.SUPPORTED, phoneNumber.getStatus());
    JsonField zipCode = contact.getJsonFields().getJsonField().get(3);
    assertNotNull(zipCode);
    assertEquals("zipCode", zipCode.getName());
    assertEquals("81111", zipCode.getValue());
    assertEquals("/order/contact/zipCode", zipCode.getPath());
    assertEquals(FieldType.STRING, zipCode.getFieldType());
    assertEquals(FieldStatus.SUPPORTED, zipCode.getStatus());
    JsonField orderId = root.getJsonFields().getJsonField().get(2);
    assertNotNull(orderId);
    assertEquals("orderId", orderId.getName());
    assertEquals(0, orderId.getValue());
    assertEquals("/order/orderId", orderId.getPath());
    assertEquals(FieldType.INTEGER, orderId.getFieldType());
    assertEquals(FieldStatus.SUPPORTED, orderId.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 78 with JsonDocument

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

the class JsonInstanceInspectorTest method inspectComplexObjectNoRoot.

@Test
public void inspectComplexObjectNoRoot() throws Exception {
    final String instance = new String(Files.readAllBytes(Paths.get("src/test/resources/inspect/complex-object-unrooted.json")));
    JsonDocument document = inspectionService.inspectJsonDocument(instance);
    assertNotNull(document);
    assertEquals(3, document.getFields().getField().size());
    JsonComplexType address = (JsonComplexType) document.getFields().getField().get(0);
    assertNotNull(address);
    assertEquals(5, address.getJsonFields().getJsonField().size());
    JsonField address1 = address.getJsonFields().getJsonField().get(0);
    assertNotNull(address1);
    assertEquals("addressLine1", address1.getName());
    assertEquals("123 Main St", address1.getValue());
    assertEquals("/address/addressLine1", address1.getPath());
    assertEquals(FieldType.STRING, address1.getFieldType());
    assertEquals(FieldStatus.SUPPORTED, address1.getStatus());
    JsonField address2 = address.getJsonFields().getJsonField().get(1);
    assertNotNull(address2);
    assertEquals("addressLine2", address2.getName());
    assertEquals("Suite 42b", address2.getValue());
    assertEquals("/address/addressLine2", address2.getPath());
    assertEquals(FieldType.STRING, address2.getFieldType());
    assertEquals(FieldStatus.SUPPORTED, address2.getStatus());
    JsonField city = address.getJsonFields().getJsonField().get(2);
    assertNotNull(city);
    assertEquals("city", city.getName());
    assertEquals("Anytown", city.getValue());
    assertEquals("/address/city", city.getPath());
    assertEquals(FieldType.STRING, city.getFieldType());
    assertEquals(FieldStatus.SUPPORTED, city.getStatus());
    JsonField state = address.getJsonFields().getJsonField().get(3);
    assertNotNull(state);
    assertEquals("state", state.getName());
    assertEquals("NY", state.getValue());
    assertEquals("/address/state", state.getPath());
    assertEquals(FieldType.STRING, state.getFieldType());
    assertEquals(FieldStatus.SUPPORTED, state.getStatus());
    JsonField postalCode = address.getJsonFields().getJsonField().get(4);
    assertNotNull(postalCode);
    assertEquals("zipCode", postalCode.getName());
    assertEquals("90210", postalCode.getValue());
    assertEquals("/address/zipCode", postalCode.getPath());
    assertEquals(FieldType.STRING, postalCode.getFieldType());
    assertEquals(FieldStatus.SUPPORTED, postalCode.getStatus());
    JsonComplexType contact = (JsonComplexType) document.getFields().getField().get(1);
    assertNotNull(contact);
    assertEquals(4, contact.getJsonFields().getJsonField().size());
    JsonField firstName = contact.getJsonFields().getJsonField().get(0);
    assertNotNull(firstName);
    assertEquals("firstName", firstName.getName());
    assertEquals("Ozzie", firstName.getValue());
    assertEquals("/contact/firstName", firstName.getPath());
    assertEquals(FieldType.STRING, firstName.getFieldType());
    assertEquals(FieldStatus.SUPPORTED, firstName.getStatus());
    JsonField lastName = contact.getJsonFields().getJsonField().get(1);
    assertNotNull(lastName);
    assertEquals("lastName", lastName.getName());
    assertEquals("Smith", lastName.getValue());
    assertEquals("/contact/lastName", lastName.getPath());
    assertEquals(FieldType.STRING, lastName.getFieldType());
    assertEquals(FieldStatus.SUPPORTED, lastName.getStatus());
    JsonField phoneNumber = contact.getJsonFields().getJsonField().get(2);
    assertNotNull(phoneNumber);
    assertEquals("phoneNumber", phoneNumber.getName());
    assertEquals("5551212", phoneNumber.getValue());
    assertEquals("/contact/phoneNumber", phoneNumber.getPath());
    assertEquals(FieldType.STRING, phoneNumber.getFieldType());
    assertEquals(FieldStatus.SUPPORTED, phoneNumber.getStatus());
    JsonField zipCode = contact.getJsonFields().getJsonField().get(3);
    assertNotNull(zipCode);
    assertEquals("zipCode", zipCode.getName());
    assertEquals("81111", zipCode.getValue());
    assertEquals("/contact/zipCode", zipCode.getPath());
    assertEquals(FieldType.STRING, zipCode.getFieldType());
    assertEquals(FieldStatus.SUPPORTED, zipCode.getStatus());
    JsonField orderId = (JsonField) document.getFields().getField().get(2);
    assertNotNull(orderId);
    assertEquals("orderId", orderId.getName());
    assertEquals(0, orderId.getValue());
    assertEquals("/orderId", orderId.getPath());
    assertEquals(FieldType.INTEGER, orderId.getFieldType());
    assertEquals(FieldStatus.SUPPORTED, orderId.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 79 with JsonDocument

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

the class JsonInstanceInspectorTest method inspectJsonDocumentEmptyDocument.

@Test
public void inspectJsonDocumentEmptyDocument() throws Exception {
    final String instance = "{}";
    JsonDocument document = inspectionService.inspectJsonDocument(instance);
    assertNotNull(document);
    assertEquals(0, document.getFields().getField().size());
}
Also used : 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