Search in sources :

Example 66 with JsonField

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

the class JsonDocumentInspectionServiceTest 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);
    Assert.assertNotNull(document);
    Assert.assertThat(document.getFields().getField().size(), Is.is(1));
    JsonComplexType root = (JsonComplexType) document.getFields().getField().get(0);
    Assert.assertThat(root.getJsonFields().getJsonField().size(), Is.is(3));
    JsonComplexType address = (JsonComplexType) root.getJsonFields().getJsonField().get(0);
    Assert.assertNotNull(address);
    Assert.assertThat(address.getJsonFields().getJsonField().size(), Is.is(5));
    JsonField address1 = address.getJsonFields().getJsonField().get(0);
    Assert.assertNotNull(address1);
    Assert.assertThat(address1.getName(), Is.is("addressLine1"));
    Assert.assertThat(address1.getValue(), Is.is("123 Main St"));
    Assert.assertThat(address1.getPath(), Is.is("/order/address/addressLine1"));
    Assert.assertThat(address1.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(address1.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonField address2 = address.getJsonFields().getJsonField().get(1);
    Assert.assertNotNull(address2);
    Assert.assertThat(address2.getName(), Is.is("addressLine2"));
    Assert.assertThat(address2.getValue(), Is.is("Suite 42b"));
    Assert.assertThat(address2.getPath(), Is.is("/order/address/addressLine2"));
    Assert.assertThat(address2.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(address2.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonField city = address.getJsonFields().getJsonField().get(2);
    Assert.assertNotNull(city);
    Assert.assertThat(city.getName(), Is.is("city"));
    Assert.assertThat(city.getValue(), Is.is("Anytown"));
    Assert.assertThat(city.getPath(), Is.is("/order/address/city"));
    Assert.assertThat(city.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(city.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonField state = address.getJsonFields().getJsonField().get(3);
    Assert.assertNotNull(state);
    Assert.assertThat(state.getName(), Is.is("state"));
    Assert.assertThat(state.getValue(), Is.is("NY"));
    Assert.assertThat(state.getPath(), Is.is("/order/address/state"));
    Assert.assertThat(state.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(state.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonField postalCode = address.getJsonFields().getJsonField().get(4);
    Assert.assertNotNull(postalCode);
    Assert.assertThat(postalCode.getName(), Is.is("zipCode"));
    Assert.assertThat(postalCode.getValue(), Is.is("90210"));
    Assert.assertThat(postalCode.getPath(), Is.is("/order/address/zipCode"));
    Assert.assertThat(postalCode.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(postalCode.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonComplexType contact = (JsonComplexType) root.getJsonFields().getJsonField().get(1);
    Assert.assertNotNull(contact);
    Assert.assertThat(contact.getJsonFields().getJsonField().size(), Is.is(4));
    JsonField firstName = contact.getJsonFields().getJsonField().get(0);
    Assert.assertNotNull(firstName);
    Assert.assertThat(firstName.getName(), Is.is("firstName"));
    Assert.assertThat(firstName.getValue(), Is.is("Ozzie"));
    Assert.assertThat(firstName.getPath(), Is.is("/order/contact/firstName"));
    Assert.assertThat(firstName.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(firstName.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonField lastName = contact.getJsonFields().getJsonField().get(1);
    Assert.assertNotNull(lastName);
    Assert.assertThat(lastName.getName(), Is.is("lastName"));
    Assert.assertThat(lastName.getValue(), Is.is("Smith"));
    Assert.assertThat(lastName.getPath(), Is.is("/order/contact/lastName"));
    Assert.assertThat(lastName.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(lastName.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonField phoneNumber = contact.getJsonFields().getJsonField().get(2);
    Assert.assertNotNull(phoneNumber);
    Assert.assertThat(phoneNumber.getName(), Is.is("phoneNumber"));
    Assert.assertThat(phoneNumber.getValue(), Is.is("5551212"));
    Assert.assertThat(phoneNumber.getPath(), Is.is("/order/contact/phoneNumber"));
    Assert.assertThat(phoneNumber.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(phoneNumber.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonField zipCode = contact.getJsonFields().getJsonField().get(3);
    Assert.assertNotNull(zipCode);
    Assert.assertThat(zipCode.getName(), Is.is("zipCode"));
    Assert.assertThat(zipCode.getValue(), Is.is("81111"));
    Assert.assertThat(zipCode.getPath(), Is.is("/order/contact/zipCode"));
    Assert.assertThat(zipCode.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(zipCode.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonField orderId = root.getJsonFields().getJsonField().get(2);
    Assert.assertNotNull(orderId);
    Assert.assertThat(orderId.getName(), Is.is("orderId"));
    Assert.assertThat(orderId.getValue(), Is.is(0));
    Assert.assertThat(orderId.getPath(), Is.is("/order/orderId"));
    Assert.assertThat(orderId.getFieldType(), Is.is(FieldType.INTEGER));
    Assert.assertThat(orderId.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 67 with JsonField

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

the class JsonDocumentInspectionServiceTest method inspectJsonDocumentNoRoot.

@Test
public void inspectJsonDocumentNoRoot() throws Exception {
    final String instance = "{ \"brand\" : \"Mercedes\", \"doors\" : 5 }";
    JsonDocument document = inspectionService.inspectJsonDocument(instance);
    Assert.assertNotNull(document);
    Assert.assertThat(document.getFields().getField().size(), Is.is(2));
    JsonField field1 = (JsonField) document.getFields().getField().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("/brand"));
    Assert.assertThat(field1.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(field1.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonField field2 = (JsonField) document.getFields().getField().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("/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) JsonDocument(io.atlasmap.json.v2.JsonDocument) Test(org.junit.Test)

Example 68 with JsonField

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

the class JsonDocumentInspectionServiceTest 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);
    Assert.assertNotNull(document);
    Assert.assertThat(document.getFields().getField().size(), Is.is(3));
    JsonComplexType address = (JsonComplexType) document.getFields().getField().get(0);
    Assert.assertNotNull(address);
    Assert.assertThat(address.getJsonFields().getJsonField().size(), Is.is(5));
    JsonField address1 = address.getJsonFields().getJsonField().get(0);
    Assert.assertNotNull(address1);
    Assert.assertThat(address1.getName(), Is.is("addressLine1"));
    Assert.assertThat(address1.getValue(), Is.is("123 Main St"));
    Assert.assertThat(address1.getPath(), Is.is("/address/addressLine1"));
    Assert.assertThat(address1.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(address1.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonField address2 = address.getJsonFields().getJsonField().get(1);
    Assert.assertNotNull(address2);
    Assert.assertThat(address2.getName(), Is.is("addressLine2"));
    Assert.assertThat(address2.getValue(), Is.is("Suite 42b"));
    Assert.assertThat(address2.getPath(), Is.is("/address/addressLine2"));
    Assert.assertThat(address2.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(address2.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonField city = address.getJsonFields().getJsonField().get(2);
    Assert.assertNotNull(city);
    Assert.assertThat(city.getName(), Is.is("city"));
    Assert.assertThat(city.getValue(), Is.is("Anytown"));
    Assert.assertThat(city.getPath(), Is.is("/address/city"));
    Assert.assertThat(city.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(city.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonField state = address.getJsonFields().getJsonField().get(3);
    Assert.assertNotNull(state);
    Assert.assertThat(state.getName(), Is.is("state"));
    Assert.assertThat(state.getValue(), Is.is("NY"));
    Assert.assertThat(state.getPath(), Is.is("/address/state"));
    Assert.assertThat(state.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(state.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonField postalCode = address.getJsonFields().getJsonField().get(4);
    Assert.assertNotNull(postalCode);
    Assert.assertThat(postalCode.getName(), Is.is("zipCode"));
    Assert.assertThat(postalCode.getValue(), Is.is("90210"));
    Assert.assertThat(postalCode.getPath(), Is.is("/address/zipCode"));
    Assert.assertThat(postalCode.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(postalCode.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonComplexType contact = (JsonComplexType) document.getFields().getField().get(1);
    Assert.assertNotNull(contact);
    Assert.assertThat(contact.getJsonFields().getJsonField().size(), Is.is(4));
    JsonField firstName = contact.getJsonFields().getJsonField().get(0);
    Assert.assertNotNull(firstName);
    Assert.assertThat(firstName.getName(), Is.is("firstName"));
    Assert.assertThat(firstName.getValue(), Is.is("Ozzie"));
    Assert.assertThat(firstName.getPath(), Is.is("/contact/firstName"));
    Assert.assertThat(firstName.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(firstName.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonField lastName = contact.getJsonFields().getJsonField().get(1);
    Assert.assertNotNull(lastName);
    Assert.assertThat(lastName.getName(), Is.is("lastName"));
    Assert.assertThat(lastName.getValue(), Is.is("Smith"));
    Assert.assertThat(lastName.getPath(), Is.is("/contact/lastName"));
    Assert.assertThat(lastName.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(lastName.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonField phoneNumber = contact.getJsonFields().getJsonField().get(2);
    Assert.assertNotNull(phoneNumber);
    Assert.assertThat(phoneNumber.getName(), Is.is("phoneNumber"));
    Assert.assertThat(phoneNumber.getValue(), Is.is("5551212"));
    Assert.assertThat(phoneNumber.getPath(), Is.is("/contact/phoneNumber"));
    Assert.assertThat(phoneNumber.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(phoneNumber.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonField zipCode = contact.getJsonFields().getJsonField().get(3);
    Assert.assertNotNull(zipCode);
    Assert.assertThat(zipCode.getName(), Is.is("zipCode"));
    Assert.assertThat(zipCode.getValue(), Is.is("81111"));
    Assert.assertThat(zipCode.getPath(), Is.is("/contact/zipCode"));
    Assert.assertThat(zipCode.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(zipCode.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonField orderId = (JsonField) document.getFields().getField().get(2);
    Assert.assertNotNull(orderId);
    Assert.assertThat(orderId.getName(), Is.is("orderId"));
    Assert.assertThat(orderId.getValue(), Is.is(0));
    Assert.assertThat(orderId.getPath(), Is.is("/orderId"));
    Assert.assertThat(orderId.getFieldType(), Is.is(FieldType.INTEGER));
    Assert.assertThat(orderId.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 69 with JsonField

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

the class JsonDocumentInspectionServiceTest method inspectJsonDocumentNestedObjectArray.

@Test
public void inspectJsonDocumentNestedObjectArray() throws Exception {
    final String instance = "{\"menu\": {\n" + "  \"id\": \"file\",\n" + "  \"value\": \"Filed\",\n" + "  \"popup\": {\n" + "    \"menuitem\": [\n" + "      {\"value\": \"New\", \"onclick\": \"CreateNewDoc()\"},\n" + "      {\"value\": \"Open\", \"onclick\": \"OpenDoc()\"},\n" + "      {\"value\": \"Close\", \"onclick\": \"CloseDoc()\"}\n" + "    ]\n" + "  }\n" + "}}";
    JsonDocument document = inspectionService.inspectJsonDocument(instance);
    Assert.assertNotNull(document);
    Assert.assertThat(1, Is.is(document.getFields().getField().size()));
    Assert.assertNotNull(document.getFields().getField());
    JsonComplexType jsonComplexType = (JsonComplexType) document.getFields().getField().get(0);
    Assert.assertNotNull(jsonComplexType);
    Assert.assertNotNull(jsonComplexType.getJsonFields().getJsonField());
    Assert.assertThat(jsonComplexType.getJsonFields().getJsonField().size(), Is.is(3));
    Assert.assertThat(jsonComplexType.getName(), Is.is("menu"));
    JsonField jsonField1 = jsonComplexType.getJsonFields().getJsonField().get(0);
    Assert.assertNotNull(jsonField1);
    Assert.assertThat(jsonField1.getName(), Is.is("id"));
    Assert.assertThat(jsonField1.getValue(), Is.is("file"));
    Assert.assertThat(jsonField1.getPath(), Is.is("/menu/id"));
    Assert.assertThat(jsonField1.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(jsonField1.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonField jsonField2 = jsonComplexType.getJsonFields().getJsonField().get(1);
    Assert.assertNotNull(jsonField2);
    Assert.assertThat(jsonField2.getName(), Is.is("value"));
    Assert.assertThat(jsonField2.getValue(), Is.is("Filed"));
    Assert.assertThat(jsonField2.getPath(), Is.is("/menu/value"));
    Assert.assertThat(jsonField2.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(jsonField2.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonComplexType popup = (JsonComplexType) jsonComplexType.getJsonFields().getJsonField().get(2);
    Assert.assertNotNull(popup);
    Assert.assertNotNull(popup.getJsonFields().getJsonField());
    Assert.assertThat(popup.getJsonFields().getJsonField().size(), Is.is(1));
    Assert.assertThat(popup.getName(), Is.is("popup"));
    Assert.assertThat(popup.getPath(), Is.is("/menu/popup"));
    Assert.assertThat(popup.getFieldType(), Is.is(FieldType.COMPLEX));
    JsonComplexType menuitem = (JsonComplexType) popup.getJsonFields().getJsonField().get(0);
    Assert.assertNotNull(menuitem);
    Assert.assertNotNull(menuitem.getJsonFields().getJsonField());
    Assert.assertThat(menuitem.getJsonFields().getJsonField().size(), Is.is(6));
    JsonField menuitemValue = menuitem.getJsonFields().getJsonField().get(0);
    Assert.assertNotNull(menuitemValue);
    Assert.assertThat(menuitemValue.getName(), Is.is("value"));
    Assert.assertThat(menuitemValue.getValue(), Is.is("New"));
    Assert.assertThat(menuitemValue.getPath(), Is.is("/menu/popup/menuitem/value"));
    Assert.assertThat(menuitemValue.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(menuitemValue.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonField menuitemOnclick = menuitem.getJsonFields().getJsonField().get(1);
    Assert.assertNotNull(menuitemOnclick);
    Assert.assertThat(menuitemOnclick.getName(), Is.is("onclick"));
    Assert.assertThat(menuitemOnclick.getValue(), Is.is("CreateNewDoc()"));
    Assert.assertThat(menuitemOnclick.getPath(), Is.is("/menu/popup/menuitem/onclick"));
    Assert.assertThat(menuitemOnclick.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(menuitemOnclick.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonField menuitem1Value = menuitem.getJsonFields().getJsonField().get(2);
    Assert.assertNotNull(menuitem1Value);
    Assert.assertThat(menuitem1Value.getName(), Is.is("value"));
    Assert.assertThat(menuitem1Value.getValue(), Is.is("Open"));
    Assert.assertThat(menuitem1Value.getPath(), Is.is("/menu/popup/menuitem[1]/value"));
    Assert.assertThat(menuitem1Value.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(menuitem1Value.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonField menuitem1Onclick = menuitem.getJsonFields().getJsonField().get(3);
    Assert.assertNotNull(menuitem1Onclick);
    Assert.assertThat(menuitem1Onclick.getName(), Is.is("onclick"));
    Assert.assertThat(menuitem1Onclick.getValue(), Is.is("OpenDoc()"));
    Assert.assertThat(menuitem1Onclick.getPath(), Is.is("/menu/popup/menuitem[1]/onclick"));
    Assert.assertThat(menuitem1Onclick.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(menuitem1Onclick.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonField menuitem2Value = menuitem.getJsonFields().getJsonField().get(4);
    Assert.assertNotNull(menuitem2Value);
    Assert.assertThat(menuitem2Value.getName(), Is.is("value"));
    Assert.assertThat(menuitem2Value.getValue(), Is.is("Close"));
    Assert.assertThat(menuitem2Value.getPath(), Is.is("/menu/popup/menuitem[2]/value"));
    Assert.assertThat(menuitem2Value.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(menuitem2Value.getStatus(), Is.is(FieldStatus.SUPPORTED));
    JsonField menuitem2Onclick = menuitem.getJsonFields().getJsonField().get(5);
    Assert.assertNotNull(menuitem2Onclick);
    Assert.assertThat(menuitem2Onclick.getName(), Is.is("onclick"));
    Assert.assertThat(menuitem2Onclick.getValue(), Is.is("CloseDoc()"));
    Assert.assertThat(menuitem2Onclick.getPath(), Is.is("/menu/popup/menuitem[2]/onclick"));
    Assert.assertThat(menuitem2Onclick.getFieldType(), Is.is(FieldType.STRING));
    Assert.assertThat(menuitem2Onclick.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)

Example 70 with JsonField

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

the class JsonDocumentInspectionServiceTest method inspectJsonDocumentSimpleArray.

@Test
public void inspectJsonDocumentSimpleArray() throws Exception {
    final String instance = "[ 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)

Aggregations

JsonField (io.atlasmap.json.v2.JsonField)119 JsonDocument (io.atlasmap.json.v2.JsonDocument)62 Test (org.junit.jupiter.api.Test)57 JsonComplexType (io.atlasmap.json.v2.JsonComplexType)34 Test (org.junit.Test)27 Field (io.atlasmap.v2.Field)18 AtlasInternalSession (io.atlasmap.spi.AtlasInternalSession)15 Head (io.atlasmap.spi.AtlasInternalSession.Head)13 Mapping (io.atlasmap.v2.Mapping)13 AtlasMapping (io.atlasmap.v2.AtlasMapping)11 FieldGroup (io.atlasmap.v2.FieldGroup)9 JsonEnumField (io.atlasmap.json.v2.JsonEnumField)8 JsonNode (com.fasterxml.jackson.databind.JsonNode)7 ArrayList (java.util.ArrayList)5 AtlasPath (io.atlasmap.core.AtlasPath)4 Validation (io.atlasmap.v2.Validation)4 BaseMapping (io.atlasmap.v2.BaseMapping)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 AtlasException (io.atlasmap.api.AtlasException)2 SegmentContext (io.atlasmap.core.AtlasPath.SegmentContext)2