use of io.atlasmap.json.v2.JsonField in project atlasmap by atlasmap.
the class JsonValidationServiceTest method testValidateMappingPathNull.
@Test
public void testValidateMappingPathNull() throws Exception {
AtlasMapping mapping = mappingUtil.loadMapping("src/test/resources/mappings/HappyPathMapping.json");
assertNotNull(mapping);
Mapping fieldMapping = (Mapping) mapping.getMappings().getMapping().get(0);
JsonField in = (JsonField) fieldMapping.getInputField().get(0);
in.setPath(null);
validations.addAll(sourceValidationService.validateMapping(mapping));
validations.addAll(targetValidationService.validateMapping(mapping));
assertTrue(validationHelper.hasErrors());
assertFalse(validationHelper.hasWarnings());
assertFalse(validationHelper.hasInfos());
}
use of io.atlasmap.json.v2.JsonField in project atlasmap by atlasmap.
the class JsonFieldWriterTest method testWriteHighlyComplexObject.
@Test
public void testWriteHighlyComplexObject() throws Exception {
JsonComplexType items = AtlasJsonModelFactory.createJsonComlexField();
items.setPath("/items");
items.setJsonFields(new JsonFields());
write(items);
JsonComplexType item = AtlasJsonModelFactory.createJsonComlexField();
item.setJsonFields(new JsonFields());
item.setPath("/items/item");
item.setCollectionType(CollectionType.LIST);
items.getJsonFields().getJsonField().add(item);
write(item);
JsonField itemid = new JsonField();
itemid.setPath("/items/item/id");
itemid.setValue("0001");
itemid.setFieldType(FieldType.STRING);
itemid.setStatus(FieldStatus.SUPPORTED);
item.getJsonFields().getJsonField().add(itemid);
write(itemid);
JsonField type = new JsonField();
type.setPath("/items/item/type");
type.setValue("donut");
type.setFieldType(FieldType.STRING);
type.setStatus(FieldStatus.SUPPORTED);
item.getJsonFields().getJsonField().add(type);
write(type);
JsonField name = new JsonField();
name.setPath("/items/item/name");
name.setValue("Cake");
name.setFieldType(FieldType.STRING);
name.setStatus(FieldStatus.SUPPORTED);
item.getJsonFields().getJsonField().add(name);
write(name);
JsonField ppu = new JsonField();
ppu.setPath("/items/item/ppu");
ppu.setValue(0.55);
ppu.setFieldType(FieldType.DOUBLE);
ppu.setStatus(FieldStatus.SUPPORTED);
item.getJsonFields().getJsonField().add(ppu);
write(ppu);
JsonComplexType batters = AtlasJsonModelFactory.createJsonComlexField();
batters.setJsonFields(new JsonFields());
batters.setPath("/items/item/batters");
items.getJsonFields().getJsonField().add(batters);
write(batters);
JsonComplexType batter = AtlasJsonModelFactory.createJsonComlexField();
batter.setPath("/items/item/batters/batter");
batter.setJsonFields(new JsonFields());
batter.setStatus(FieldStatus.SUPPORTED);
batter.setCollectionType(CollectionType.LIST);
batters.getJsonFields().getJsonField().add(batter);
write(batter);
JsonField batter1Id = new JsonField();
batter1Id.setPath("/items/item/batters/batter/id");
batter1Id.setValue("1001");
batter1Id.setFieldType(FieldType.STRING);
batter1Id.setStatus(FieldStatus.SUPPORTED);
batter.getJsonFields().getJsonField().add(batter1Id);
write(batter1Id);
JsonField batter1Type = new JsonField();
batter1Type.setPath("/items/item/batters/batter/type");
batter1Type.setValue("Regular");
batter1Type.setFieldType(FieldType.STRING);
batter1Type.setStatus(FieldStatus.SUPPORTED);
batter.getJsonFields().getJsonField().add(batter1Type);
write(batter1Type);
JsonField batter2Id = new JsonField();
batter2Id.setPath("/items/item/batters/batter[1]/id");
batter2Id.setValue("1002");
batter2Id.setFieldType(FieldType.STRING);
batter2Id.setStatus(FieldStatus.SUPPORTED);
batter.getJsonFields().getJsonField().add(batter2Id);
write(batter2Id);
JsonField batter2Type = new JsonField();
batter2Type.setPath("/items/item/batters/batter[1]/type");
batter2Type.setValue("Chocolate");
batter2Type.setFieldType(FieldType.STRING);
batter2Type.setStatus(FieldStatus.SUPPORTED);
batter.getJsonFields().getJsonField().add(batter2Type);
write(batter2Type);
JsonField batter3Id = new JsonField();
batter3Id.setPath("/items/item/batters/batter[2]/id");
batter3Id.setValue("1003");
batter3Id.setFieldType(FieldType.STRING);
batter3Id.setStatus(FieldStatus.SUPPORTED);
batter.getJsonFields().getJsonField().add(batter3Id);
write(batter3Id);
JsonField batter3Type = new JsonField();
batter3Type.setPath("/items/item/batters/batter[2]/type");
batter3Type.setValue("Blueberry");
batter3Type.setFieldType(FieldType.STRING);
batter3Type.setStatus(FieldStatus.SUPPORTED);
batter.getJsonFields().getJsonField().add(batter3Type);
write(batter3Type);
JsonField batter4Id = new JsonField();
batter4Id.setPath("/items/item/batters/batter[3]/id");
batter4Id.setValue("1004");
batter4Id.setFieldType(FieldType.STRING);
batter4Id.setStatus(FieldStatus.SUPPORTED);
batter.getJsonFields().getJsonField().add(batter4Id);
write(batter4Id);
JsonField batter4Type = new JsonField();
batter4Type.setPath("/items/item/batters/batter[3]/type");
batter4Type.setValue("Devil's Food");
batter4Type.setFieldType(FieldType.STRING);
batter4Type.setStatus(FieldStatus.SUPPORTED);
batter.getJsonFields().getJsonField().add(batter4Type);
write(batter4Type);
JsonComplexType topping = AtlasJsonModelFactory.createJsonComlexField();
topping.setJsonFields(new JsonFields());
topping.setPath("/items/item/topping");
topping.setCollectionType(CollectionType.ARRAY);
items.getJsonFields().getJsonField().add(topping);
write(topping);
JsonField topping1Id = new JsonField();
topping1Id.setPath("/items/item/topping/id[0]");
topping1Id.setValue("5001");
topping1Id.setFieldType(FieldType.STRING);
topping1Id.setStatus(FieldStatus.SUPPORTED);
topping.getJsonFields().getJsonField().add(topping1Id);
write(topping1Id);
JsonField topping1Type = new JsonField();
topping1Type.setPath("/items/item/topping/type[0]");
topping1Type.setValue("None");
topping1Type.setFieldType(FieldType.STRING);
topping1Type.setStatus(FieldStatus.SUPPORTED);
topping.getJsonFields().getJsonField().add(topping1Type);
write(topping1Type);
JsonField topping2Id = new JsonField();
topping2Id.setPath("/items/item/topping/id[1]");
topping2Id.setValue("5002");
topping2Id.setFieldType(FieldType.STRING);
topping2Id.setStatus(FieldStatus.SUPPORTED);
topping.getJsonFields().getJsonField().add(topping2Id);
write(topping2Id);
JsonField topping2Type = new JsonField();
topping2Type.setPath("/items/item/topping/type[1]");
topping2Type.setValue("Glazed");
topping2Type.setFieldType(FieldType.STRING);
topping2Type.setStatus(FieldStatus.SUPPORTED);
topping.getJsonFields().getJsonField().add(topping2Type);
write(topping2Type);
JsonField topping3Id = new JsonField();
topping3Id.setPath("/items/item/topping/id[2]");
topping3Id.setValue("5005");
topping3Id.setFieldType(FieldType.STRING);
topping3Id.setStatus(FieldStatus.SUPPORTED);
topping.getJsonFields().getJsonField().add(topping3Id);
write(topping3Id);
JsonField topping3Type = new JsonField();
topping3Type.setPath("/items/item/topping/type[2]");
topping3Type.setValue("Sugar");
topping3Type.setFieldType(FieldType.STRING);
topping3Type.setStatus(FieldStatus.SUPPORTED);
topping.getJsonFields().getJsonField().add(topping3Type);
write(topping3Type);
JsonField topping4Id = new JsonField();
topping4Id.setPath("/items/item/topping/id[3]");
topping4Id.setValue("5007");
topping4Id.setFieldType(FieldType.STRING);
topping4Id.setStatus(FieldStatus.SUPPORTED);
topping.getJsonFields().getJsonField().add(topping4Id);
write(topping4Id);
JsonField topping4Type = new JsonField();
topping4Type.setPath("/items/item/topping/type[3]");
topping4Type.setValue("Powdered Sugar");
topping4Type.setFieldType(FieldType.STRING);
topping4Type.setStatus(FieldStatus.SUPPORTED);
topping.getJsonFields().getJsonField().add(topping4Type);
write(topping4Type);
JsonField topping5Id = new JsonField();
topping5Id.setPath("/items/item/topping/id[4]");
topping5Id.setValue("5006");
topping5Id.setFieldType(FieldType.STRING);
topping5Id.setStatus(FieldStatus.SUPPORTED);
topping.getJsonFields().getJsonField().add(topping5Id);
write(topping5Id);
JsonField topping5Type = new JsonField();
topping5Type.setPath("/items/item/topping/type[4]");
topping5Type.setValue("Chocolate with Sprinkles");
topping5Type.setFieldType(FieldType.STRING);
topping5Type.setStatus(FieldStatus.SUPPORTED);
topping.getJsonFields().getJsonField().add(topping5Type);
write(topping5Type);
JsonField topping6Id = new JsonField();
topping6Id.setPath("/items/item/topping/id[5]");
topping6Id.setValue("5003");
topping6Id.setFieldType(FieldType.STRING);
topping6Id.setStatus(FieldStatus.SUPPORTED);
topping.getJsonFields().getJsonField().add(topping6Id);
write(topping6Id);
JsonField topping6Type = new JsonField();
topping6Type.setPath("/items/item/topping/type[5]");
topping6Type.setValue("Chocolate");
topping6Type.setFieldType(FieldType.STRING);
topping6Type.setStatus(FieldStatus.SUPPORTED);
topping.getJsonFields().getJsonField().add(topping6Type);
write(topping6Type);
JsonField topping7Id = new JsonField();
topping7Id.setPath("/items/item/topping/id[6]");
topping7Id.setValue("5004");
topping7Id.setFieldType(FieldType.STRING);
topping7Id.setStatus(FieldStatus.SUPPORTED);
topping.getJsonFields().getJsonField().add(topping7Id);
write(topping7Id);
JsonField topping7Type = new JsonField();
topping7Type.setPath("/items/item/topping/type[6]");
topping7Type.setValue("Maple");
topping7Type.setFieldType(FieldType.STRING);
topping7Type.setStatus(FieldStatus.SUPPORTED);
topping.getJsonFields().getJsonField().add(topping7Type);
write(topping7Type);
// repeat complex
JsonComplexType item1 = AtlasJsonModelFactory.createJsonComlexField();
item1.setJsonFields(new JsonFields());
item1.setPath("/items/item[1]");
item1.setCollectionType(CollectionType.LIST);
items.getJsonFields().getJsonField().add(item1);
write(item1);
JsonField itemId1 = new JsonField();
itemId1.setPath("/items/item[1]/id");
itemId1.setValue("0002");
itemId1.setFieldType(FieldType.STRING);
itemId1.setStatus(FieldStatus.SUPPORTED);
item1.getJsonFields().getJsonField().add(itemId1);
write(itemId1);
JsonField type1 = new JsonField();
type1.setPath("/items/item[1]/type");
type1.setValue("donut");
type1.setFieldType(FieldType.STRING);
type1.setStatus(FieldStatus.SUPPORTED);
item.getJsonFields().getJsonField().add(type1);
write(type1);
JsonField name1 = new JsonField();
name1.setPath("/items/item[1]/name");
name1.setValue("Raised");
name1.setFieldType(FieldType.STRING);
name1.setStatus(FieldStatus.SUPPORTED);
item.getJsonFields().getJsonField().add(name1);
write(name1);
JsonField ppu2 = new JsonField();
ppu2.setPath("/items/item[1]/ppu");
ppu2.setValue(0.55);
ppu2.setFieldType(FieldType.DOUBLE);
ppu2.setStatus(FieldStatus.SUPPORTED);
item.getJsonFields().getJsonField().add(ppu2);
write(ppu2);
JsonComplexType batters1 = AtlasJsonModelFactory.createJsonComlexField();
batters1.setJsonFields(new JsonFields());
batters1.setPath("/items/item[1]/batters");
items.getJsonFields().getJsonField().add(batters1);
write(batters1);
JsonComplexType batter1 = AtlasJsonModelFactory.createJsonComlexField();
batter1.setPath("/items/item[1]/batters/batter");
batter1.setJsonFields(new JsonFields());
batter1.setStatus(FieldStatus.SUPPORTED);
batter1.setCollectionType(CollectionType.LIST);
batters1.getJsonFields().getJsonField().add(batter1);
write(batter1);
JsonField batter1_1_id = new JsonField();
batter1_1_id.setPath("/items/item[1]/batters/batter/id");
batter1_1_id.setValue("1001");
batter1_1_id.setFieldType(FieldType.STRING);
batter1_1_id.setStatus(FieldStatus.SUPPORTED);
batter1.getJsonFields().getJsonField().add(batter1_1_id);
write(batter1_1_id);
JsonField batter1_1_type = new JsonField();
batter1_1_type.setPath("/items/item[1]/batters/batter/type");
batter1_1_type.setValue("Regular");
batter1_1_type.setFieldType(FieldType.STRING);
batter1_1_type.setStatus(FieldStatus.SUPPORTED);
batter1.getJsonFields().getJsonField().add(batter1_1_type);
write(batter1_1_type);
System.out.println(prettyPrintJson(writer.getRootNode().toString()));
}
use of io.atlasmap.json.v2.JsonField in project atlasmap by atlasmap.
the class JsonSchemaInspectorTest 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.BIG_INTEGER, orderId.getFieldType());
assertEquals(FieldStatus.SUPPORTED, orderId.getStatus());
}
use of io.atlasmap.json.v2.JsonField in project atlasmap by atlasmap.
the class JsonSchemaInspectorTest 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.BIG_INTEGER, orderId.getFieldType());
assertEquals(FieldStatus.SUPPORTED, orderId.getStatus());
}
use of io.atlasmap.json.v2.JsonField in project atlasmap by atlasmap.
the class JsonSchemaInspectorTest method inspectJsonSchemaTopmostArraySimple.
@Test
public void inspectJsonSchemaTopmostArraySimple() throws Exception {
final String schema = "{\"$schema\": \"http://json-schema.org/\"," + " \"type\": \"array\"," + " \"items\": { \"type\": \"integer\"}}";
JsonDocument document = inspectionService.inspectJsonSchema(schema);
assertNotNull(document);
assertEquals(1, document.getFields().getField().size());
JsonField jsonField = (JsonField) document.getFields().getField().get(0);
assertEquals(FieldStatus.SUPPORTED, jsonField.getStatus());
assertEquals(CollectionType.LIST, jsonField.getCollectionType());
assertEquals(FieldType.BIG_INTEGER, jsonField.getFieldType());
assertEquals("", jsonField.getName());
assertEquals("/<>", jsonField.getPath());
}
Aggregations