Search in sources :

Example 16 with JsonComplexType

use of io.atlasmap.json.v2.JsonComplexType 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 17 with JsonComplexType

use of io.atlasmap.json.v2.JsonComplexType 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)

Example 18 with JsonComplexType

use of io.atlasmap.json.v2.JsonComplexType 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 19 with JsonComplexType

use of io.atlasmap.json.v2.JsonComplexType 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 20 with JsonComplexType

use of io.atlasmap.json.v2.JsonComplexType 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)

Aggregations

JsonComplexType (io.atlasmap.json.v2.JsonComplexType)21 JsonField (io.atlasmap.json.v2.JsonField)18 JsonDocument (io.atlasmap.json.v2.JsonDocument)17 Test (org.junit.Test)14 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 JsonFields (io.atlasmap.json.v2.JsonFields)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Field (io.atlasmap.v2.Field)2 Map (java.util.Map)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Ignore (org.junit.Ignore)1