Search in sources :

Example 6 with JsonDocument

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

the class JsonDocumentInspectionServiceTest 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);
    Assert.assertNotNull(document);
    Assert.assertThat(document.getFields().getField().size(), Is.is(7));
    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("booleanField"));
            Assert.assertThat(field.getValue(), Is.is(false));
            Assert.assertThat(field.getPath(), Is.is("/".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("/".concat(field.getName())));
            // FIXME DOES NOT RECOGNIZE CHAR DISTINCTLY AND RETURNS THIS AS A STRING
            // (TEXTUAL)
            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("/".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("/".concat(field.getName())));
            // FIXME DOES NOT RECOGNIZE FLOAT DISTINCTLY AND RETURNS THIS AS A DOUBLE
            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("/".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("/".concat(field.getName())));
            // FIXME JSON DOES NOT RECOGNIZE SHORT DISTINCTLY AND RETURNS THIS AS A INTEGER
            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("/".concat(field.getName())));
            // FIXME JSON DOES NOT RECOGNIZE LONG DISTINCTLY AND RETURNS THIS AS A INTEGER
            Assert.assertThat(field.getFieldType(), Is.is(FieldType.INTEGER));
            Assert.assertThat(field.getStatus(), Is.is(FieldStatus.SUPPORTED));
        }
    }
}
Also used : JsonField(io.atlasmap.json.v2.JsonField) JsonDocument(io.atlasmap.json.v2.JsonDocument) Test(org.junit.Test)

Example 7 with JsonDocument

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

the class JsonDocumentInspectionServiceTest method inspectJsonDocumentArrayHighlyNestedObjects.

@Test
public void inspectJsonDocumentArrayHighlyNestedObjects() throws Exception {
    final String instance = new String(Files.readAllBytes(Paths.get("src/test/resources/inspect/array-highly-nested-objects.json")));
    JsonDocument document = inspectionService.inspectJsonDocument(instance);
    Assert.assertNotNull(document);
    Assert.assertThat(document.getFields().getField().size(), Is.is(1));
    JsonField jsonField = (JsonField) document.getFields().getField().get(0);
    Assert.assertTrue(jsonField.getStatus().compareTo(FieldStatus.UNSUPPORTED) == 0);
    Assert.assertTrue(jsonField.getCollectionType().compareTo(CollectionType.ARRAY) == 0);
// printDocument(document);
}
Also used : JsonField(io.atlasmap.json.v2.JsonField) JsonDocument(io.atlasmap.json.v2.JsonDocument) Test(org.junit.Test)

Example 8 with JsonDocument

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

the class JsonDocumentInspectionServiceTest method inspectJsonDocumentSimpleArrayStartsWithWhiteSpace.

@Test
public void inspectJsonDocumentSimpleArrayStartsWithWhiteSpace() throws Exception {
    final String instance = "\n\t\r [ 100, 500, 300, 200, 400 ]";
    JsonDocument document = inspectionService.inspectJsonDocument(instance);
    Assert.assertNotNull(document);
    Assert.assertThat(1, Is.is(document.getFields().getField().size()));
    JsonField jsonField = (JsonField) document.getFields().getField().get(0);
    Assert.assertTrue(jsonField.getStatus().compareTo(FieldStatus.UNSUPPORTED) == 0);
    Assert.assertTrue(jsonField.getCollectionType().compareTo(CollectionType.ARRAY) == 0);
    Assert.assertNull(jsonField.getFieldType());
    Assert.assertNull(jsonField.getName());
    Assert.assertNull(jsonField.getPath());
// printDocument(document);
}
Also used : JsonField(io.atlasmap.json.v2.JsonField) JsonDocument(io.atlasmap.json.v2.JsonDocument) Test(org.junit.Test)

Example 9 with JsonDocument

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

the class SchemaInspectorTest method inspectComplexObjectWithRoot.

@Test
public void inspectComplexObjectWithRoot() throws Exception {
    final String schema = new String(Files.readAllBytes(Paths.get("src/test/resources/inspect/schema/complex-object-rooted.json")));
    JsonDocument document = inspectionService.inspectJsonSchema(schema);
    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("/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("/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("/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("/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("/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("/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("/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("/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("/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("/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.Test)

Example 10 with JsonDocument

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

the class SchemaInspectorTest method inspectJsonSchemaRef.

@Test
public void inspectJsonSchemaRef() throws Exception {
    final String schema = new String(Files.readAllBytes(Paths.get("src/test/resources/inspect/schema/ref.json")));
    JsonDocument document = inspectionService.inspectJsonSchema(schema);
    assertNotNull(document);
    assertEquals(3, document.getFields().getField().size());
    JsonField refA = (JsonField) document.getFields().getField().get(0);
    assertNotNull(refA);
    assertEquals("ref-a", refA.getName());
    assertEquals("/ref-a", refA.getPath());
    assertEquals(FieldType.STRING, refA.getFieldType());
    assertEquals(FieldStatus.SUPPORTED, refA.getStatus());
    JsonComplexType refB = (JsonComplexType) document.getFields().getField().get(1);
    assertNotNull(refB);
    assertEquals("ref-b", refB.getName());
    assertEquals("/ref-b", refB.getPath());
    assertEquals(FieldType.COMPLEX, refB.getFieldType());
    assertEquals(FieldStatus.SUPPORTED, refB.getStatus());
    assertEquals(2, refB.getJsonFields().getJsonField().size());
    JsonComplexType refCFromB = (JsonComplexType) refB.getJsonFields().getJsonField().get(0);
    assertNotNull(refCFromB);
    assertEquals("ref-c-from-b", refCFromB.getName());
    assertEquals("/ref-b/ref-c-from-b", refCFromB.getPath());
    assertEquals(FieldType.COMPLEX, refCFromB.getFieldType());
    assertEquals(FieldStatus.SUPPORTED, refCFromB.getStatus());
    assertEquals(1, refCFromB.getJsonFields().getJsonField().size());
    JsonField strCFromB = refCFromB.getJsonFields().getJsonField().get(0);
    assertNotNull(strCFromB);
    assertEquals("str-c", strCFromB.getName());
    assertEquals("/ref-b/ref-c-from-b/str-c", strCFromB.getPath());
    assertEquals(FieldType.STRING, strCFromB.getFieldType());
    assertEquals(FieldStatus.SUPPORTED, strCFromB.getStatus());
    JsonField strB = refB.getJsonFields().getJsonField().get(1);
    assertNotNull(strB);
    assertEquals("str-b", strB.getName());
    assertEquals("/ref-b/str-b", strB.getPath());
    assertEquals(FieldType.STRING, strB.getFieldType());
    assertEquals(FieldStatus.SUPPORTED, strB.getStatus());
    JsonComplexType refC = (JsonComplexType) document.getFields().getField().get(2);
    assertNotNull(refC);
    assertEquals("ref-c", refC.getName());
    assertEquals("/ref-c", refC.getPath());
    assertEquals(FieldType.COMPLEX, refC.getFieldType());
    assertEquals(FieldStatus.SUPPORTED, refC.getStatus());
    assertEquals(1, refC.getJsonFields().getJsonField().size());
    JsonField strC = refC.getJsonFields().getJsonField().get(0);
    assertNotNull(strC);
    assertEquals("str-c", strC.getName());
    assertEquals("/ref-c/str-c", strC.getPath());
    assertEquals(FieldType.STRING, strC.getFieldType());
    assertEquals(FieldStatus.SUPPORTED, strC.getStatus());
}
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)34 JsonField (io.atlasmap.json.v2.JsonField)31 Test (org.junit.Test)29 JsonComplexType (io.atlasmap.json.v2.JsonComplexType)17 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 Field (io.atlasmap.v2.Field)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 IOException (java.io.IOException)2 Map (java.util.Map)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 JsonDocumentInspectionService (io.atlasmap.json.inspect.JsonDocumentInspectionService)1 JsonFields (io.atlasmap.json.v2.JsonFields)1 JsonInspectionRequest (io.atlasmap.json.v2.JsonInspectionRequest)1 JsonInspectionResponse (io.atlasmap.json.v2.JsonInspectionResponse)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 ApplicationPath (javax.ws.rs.ApplicationPath)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1