Search in sources :

Example 11 with JsonField

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

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

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

Example 14 with JsonField

use of io.atlasmap.json.v2.JsonField 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());
}
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 15 with JsonField

use of io.atlasmap.json.v2.JsonField 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());
}
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

JsonField (io.atlasmap.json.v2.JsonField)63 Test (org.junit.Test)45 JsonDocument (io.atlasmap.json.v2.JsonDocument)30 JsonComplexType (io.atlasmap.json.v2.JsonComplexType)15 AtlasInternalSession (io.atlasmap.spi.AtlasInternalSession)10 Head (io.atlasmap.spi.AtlasInternalSession.Head)8 AtlasMapping (io.atlasmap.v2.AtlasMapping)7 Mapping (io.atlasmap.v2.Mapping)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 Field (io.atlasmap.v2.Field)4 Validation (io.atlasmap.v2.Validation)4 AtlasMappingUtil (io.atlasmap.core.AtlasMappingUtil)2 DefaultAtlasConversionService (io.atlasmap.core.DefaultAtlasConversionService)2 AtlasJsonModelFactory (io.atlasmap.json.v2.AtlasJsonModelFactory)2 AtlasModuleDetail (io.atlasmap.spi.AtlasModuleDetail)2 AtlasModuleMode (io.atlasmap.spi.AtlasModuleMode)2 AtlasModelFactory (io.atlasmap.v2.AtlasModelFactory)2 DataSource (io.atlasmap.v2.DataSource)2 DataSourceType (io.atlasmap.v2.DataSourceType)2 FieldType (io.atlasmap.v2.FieldType)2