use of io.atlasmap.json.v2.JsonDocument in project atlasmap by atlasmap.
the class SchemaInspectorTest method inspectComplexObjectNoRoot.
@Test
public void inspectComplexObjectNoRoot() throws Exception {
final String schema = new String(Files.readAllBytes(Paths.get("src/test/resources/inspect/schema/complex-object-unrooted.json")));
JsonDocument document = inspectionService.inspectJsonSchema(schema);
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("/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("/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("/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("/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("/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("/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("/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("/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("/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("/orderId", orderId.getPath());
assertEquals(FieldType.INTEGER, orderId.getFieldType());
assertEquals(FieldStatus.SUPPORTED, orderId.getStatus());
}
use of io.atlasmap.json.v2.JsonDocument in project atlasmap by atlasmap.
the class SchemaInspectorTest method inspectJsonSchemaEmptyDocument.
@Test
public void inspectJsonSchemaEmptyDocument() throws Exception {
final String schema = "{\"$schema\": \"http://json-schema.org/\"}";
JsonDocument document = inspectionService.inspectJsonSchema(schema);
assertNotNull(document);
assertEquals(0, document.getFields().getField().size());
}
use of io.atlasmap.json.v2.JsonDocument in project atlasmap by atlasmap.
the class SchemaInspectorTest method inspectObjectArrayWithRoot.
@Test
public void inspectObjectArrayWithRoot() throws Exception {
final String schema = new String(Files.readAllBytes(Paths.get("src/test/resources/inspect/schema/complex-array-rooted.json")));
JsonDocument document = inspectionService.inspectJsonSchema(schema);
assertNotNull(document);
assertEquals(1, document.getFields().getField().size());
JsonComplexType root = (JsonComplexType) document.getFields().getField().get(0);
assertNotNull(root);
assertEquals(3, root.getJsonFields().getJsonField().size());
assertEquals("SourceOrderList", root.getName());
JsonComplexType orders = (JsonComplexType) root.getJsonFields().getJsonField().get(0);
assertNotNull(orders);
assertEquals(3, orders.getJsonFields().getJsonField().size());
assertEquals("orders", orders.getName());
assertEquals(CollectionType.LIST, orders.getCollectionType());
assertEquals(FieldType.COMPLEX, orders.getFieldType());
JsonField orderBatchNumber = root.getJsonFields().getJsonField().get(1);
assertNotNull(orderBatchNumber);
assertEquals("orderBatchNumber", orderBatchNumber.getName());
assertEquals("/SourceOrderList/orderBatchNumber", orderBatchNumber.getPath());
assertEquals(FieldType.INTEGER, orderBatchNumber.getFieldType());
assertEquals(FieldStatus.SUPPORTED, orderBatchNumber.getStatus());
JsonField numberOrders = root.getJsonFields().getJsonField().get(2);
assertNotNull(numberOrders);
assertEquals("numberOrders", numberOrders.getName());
assertEquals("/SourceOrderList/numberOrders", numberOrders.getPath());
assertEquals(FieldType.INTEGER, numberOrders.getFieldType());
assertEquals(FieldStatus.SUPPORTED, numberOrders.getStatus());
JsonComplexType address = (JsonComplexType) orders.getJsonFields().getJsonField().get(0);
assertNotNull(address);
assertEquals(5, address.getJsonFields().getJsonField().size());
assertEquals("address", address.getName());
assertEquals("/SourceOrderList/orders/address", address.getPath());
JsonField addressLine1 = address.getJsonFields().getJsonField().get(0);
assertNotNull(addressLine1);
assertEquals("addressLine1", addressLine1.getName());
assertEquals("/SourceOrderList/orders/address/addressLine1", addressLine1.getPath());
assertEquals(FieldType.STRING, addressLine1.getFieldType());
assertEquals(FieldStatus.SUPPORTED, addressLine1.getStatus());
JsonField addressLine2 = address.getJsonFields().getJsonField().get(1);
assertNotNull(addressLine2);
assertEquals("addressLine2", addressLine2.getName());
assertEquals("/SourceOrderList/orders/address/addressLine2", addressLine2.getPath());
assertEquals(FieldType.STRING, addressLine2.getFieldType());
assertEquals(FieldStatus.SUPPORTED, addressLine2.getStatus());
JsonField city = address.getJsonFields().getJsonField().get(2);
assertNotNull(city);
assertEquals("city", city.getName());
assertEquals("/SourceOrderList/orders/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("/SourceOrderList/orders/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("/SourceOrderList/orders/address/zipCode", postalCode.getPath());
assertEquals(FieldType.STRING, postalCode.getFieldType());
assertEquals(FieldStatus.SUPPORTED, postalCode.getStatus());
JsonComplexType contact = (JsonComplexType) orders.getJsonFields().getJsonField().get(1);
assertNotNull(contact);
assertEquals(4, contact.getJsonFields().getJsonField().size());
assertEquals("contact", contact.getName());
assertEquals("/SourceOrderList/orders/contact", contact.getPath());
JsonField firstName = contact.getJsonFields().getJsonField().get(0);
assertNotNull(firstName);
assertEquals("firstName", firstName.getName());
assertEquals("/SourceOrderList/orders/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("/SourceOrderList/orders/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("/SourceOrderList/orders/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("/SourceOrderList/orders/contact/zipCode", zipCode.getPath());
assertEquals(FieldType.STRING, zipCode.getFieldType());
assertEquals(FieldStatus.SUPPORTED, zipCode.getStatus());
JsonField orderId = orders.getJsonFields().getJsonField().get(2);
assertNotNull(orderId);
assertEquals("orderId", orderId.getName());
assertEquals("/SourceOrderList/orders/orderId", orderId.getPath());
assertEquals(FieldType.INTEGER, orderId.getFieldType());
assertEquals(FieldStatus.SUPPORTED, orderId.getStatus());
}
use of io.atlasmap.json.v2.JsonDocument in project atlasmap by atlasmap.
the class SchemaInspectorTest method inspectFlatPrimitiveNoRoot.
@Test
public void inspectFlatPrimitiveNoRoot() throws Exception {
final String instance = new String(Files.readAllBytes(Paths.get("src/test/resources/inspect/schema/flatprimitive-base-unrooted.json")));
JsonDocument document = inspectionService.inspectJsonSchema(instance);
assertNotNull(document);
assertEquals(5, document.getFields().getField().size());
List<Field> fields = document.getFields().getField();
JsonField field = (JsonField) fields.get(0);
assertEquals("booleanField", field.getName());
assertEquals("/booleanField", field.getPath());
assertEquals(FieldType.BOOLEAN, field.getFieldType());
assertEquals(FieldStatus.SUPPORTED, field.getStatus());
field = (JsonField) fields.get(1);
assertEquals("stringField", field.getName());
assertEquals("/stringField", field.getPath());
assertEquals(FieldType.STRING, field.getFieldType());
assertEquals(FieldStatus.SUPPORTED, field.getStatus());
field = (JsonField) fields.get(2);
assertEquals("numberField", field.getName());
assertEquals("/numberField", field.getPath());
assertEquals(FieldType.NUMBER, field.getFieldType());
assertEquals(FieldStatus.SUPPORTED, field.getStatus());
field = (JsonField) fields.get(3);
assertEquals("intField", field.getName());
assertEquals("/intField", field.getPath());
assertEquals(FieldType.INTEGER, field.getFieldType());
assertEquals(FieldStatus.SUPPORTED, field.getStatus());
field = (JsonField) fields.get(4);
assertEquals("nullField", field.getName());
assertEquals("/nullField", field.getPath());
assertEquals(FieldType.NONE, field.getFieldType());
assertEquals(FieldStatus.SUPPORTED, field.getStatus());
}
use of io.atlasmap.json.v2.JsonDocument in project atlasmap by atlasmap.
the class InstanceInspector method handleArrayNode.
private void handleArrayNode(JsonDocument jsonDocument, ArrayNode aNode, JsonComplexType parent, String aKey, int index) throws IOException {
if (aNode.get(0).isObject()) {
LOG.trace("ARRAY OF OBJECTS WITH PARENT ---> " + parent.getName().concat(String.valueOf(index)) + " WITH KEY ----> " + aKey + " AND SIZE OF ---> " + aNode.size());
int childIndex = 0;
JsonComplexType childObject = null;
if (!aKey.equals(parent.getName())) {
childObject = getJsonComplexType(parent, aKey, index);
childObject.setCollectionType(CollectionType.LIST);
}
for (JsonNode jsonNode : aNode) {
if (childObject != null) {
// rest for child fields...
handleObjectNode(jsonDocument, jsonNode, childObject, childIndex);
} else {
handleObjectNode(jsonDocument, jsonNode, parent, index);
}
childIndex++;
index++;
}
} else if (aNode.get(0).isArray()) {
LOG.trace("**TODO** > HANDLE ARRAY OF AN ARRAY WITH PARENT ---> " + parent.getName() + " WITH KEY ----> " + aKey);
} else if (aNode.get(0).isValueNode()) {
LOG.trace("**TODO** > HANDLE ARRAY OF A VALUES WITH PARENT ---> " + parent.getName() + " WITH KEY ----> " + aKey);
}
}
Aggregations