Search in sources :

Example 51 with JsonField

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

the class SchemaInspectorTest method inspectFlatPrimitiveWithRoot.

@Test
public void inspectFlatPrimitiveWithRoot() throws Exception {
    final String instance = new String(Files.readAllBytes(Paths.get("src/test/resources/inspect/schema/flatprimitive-base-rooted.json")));
    JsonDocument document = inspectionService.inspectJsonSchema(instance);
    assertNotNull(document);
    assertEquals(1, document.getFields().getField().size());
    JsonComplexType root = (JsonComplexType) document.getFields().getField().get(0);
    assertNotNull(root);
    assertEquals("SourceFlatPrimitive", root.getName());
    assertEquals("/SourceFlatPrimitive", root.getPath());
    assertEquals(FieldType.COMPLEX, root.getFieldType());
    assertEquals(FieldStatus.SUPPORTED, root.getStatus());
    assertEquals(5, root.getJsonFields().getJsonField().size());
    List<JsonField> fields = root.getJsonFields().getJsonField();
    JsonField field = fields.get(0);
    assertEquals("booleanField", field.getName());
    assertEquals("/SourceFlatPrimitive/booleanField", field.getPath());
    assertEquals(FieldType.BOOLEAN, field.getFieldType());
    assertEquals(FieldStatus.SUPPORTED, field.getStatus());
    field = fields.get(1);
    assertEquals("stringField", field.getName());
    assertEquals("/SourceFlatPrimitive/stringField", field.getPath());
    assertEquals(FieldType.STRING, field.getFieldType());
    assertEquals(FieldStatus.SUPPORTED, field.getStatus());
    field = fields.get(2);
    assertEquals("numberField", field.getName());
    assertEquals("/SourceFlatPrimitive/numberField", field.getPath());
    assertEquals(FieldType.NUMBER, field.getFieldType());
    assertEquals(FieldStatus.SUPPORTED, field.getStatus());
    field = fields.get(3);
    assertEquals("intField", field.getName());
    assertEquals("/SourceFlatPrimitive/intField", field.getPath());
    assertEquals(FieldType.INTEGER, field.getFieldType());
    assertEquals(FieldStatus.SUPPORTED, field.getStatus());
    field = fields.get(4);
    assertEquals("nullField", field.getName());
    assertEquals("/SourceFlatPrimitive/nullField", field.getPath());
    assertEquals(FieldType.NONE, field.getFieldType());
    assertEquals(FieldStatus.SUPPORTED, field.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 52 with JsonField

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

the class SchemaInspectorTest method inspectJsonSchemaSimpleString.

@Test
public void inspectJsonSchemaSimpleString() throws Exception {
    final String schema = "{\"$schema\": \"http://json-schema.org/\", \"type\": \"string\"}";
    JsonDocument document = inspectionService.inspectJsonSchema(schema);
    assertNotNull(document);
    assertEquals(1, document.getFields().getField().size());
    JsonField jsonField = (JsonField) document.getFields().getField().get(0);
    assertTrue(jsonField.getStatus().compareTo(FieldStatus.SUPPORTED) == 0);
    assertEquals(FieldType.STRING, jsonField.getFieldType());
    assertNull(jsonField.getName());
    assertNull(jsonField.getPath());
}
Also used : JsonField(io.atlasmap.json.v2.JsonField) JsonDocument(io.atlasmap.json.v2.JsonDocument) Test(org.junit.Test)

Example 53 with JsonField

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

the class SchemaInspectorTest method inspectJsonSchemaGeo.

// examples from json-schema.org
@Test
public void inspectJsonSchemaGeo() throws Exception {
    final String schema = new String(Files.readAllBytes(Paths.get("src/test/resources/inspect/schema/geo.json")));
    JsonDocument document = inspectionService.inspectJsonSchema(schema);
    List<Field> fields = document.getFields().getField();
    JsonField f = (JsonField) fields.get(0);
    assertEquals("latitude", f.getName());
    assertEquals("/latitude", f.getPath());
    assertEquals(FieldType.NUMBER, f.getFieldType());
    f = (JsonField) fields.get(1);
    assertEquals("longitude", f.getName());
    assertEquals("/longitude", f.getPath());
    assertEquals(FieldType.NUMBER, f.getFieldType());
}
Also used : Field(io.atlasmap.v2.Field) JsonField(io.atlasmap.json.v2.JsonField) JsonField(io.atlasmap.json.v2.JsonField) JsonDocument(io.atlasmap.json.v2.JsonDocument) Test(org.junit.Test)

Example 54 with JsonField

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

the class SchemaInspectorTest method doInspectJsonSchemaCard.

private void doInspectJsonSchemaCard(String schema) throws Exception {
    JsonDocument document = inspectionService.inspectJsonSchema(schema);
    List<Field> fields = document.getFields().getField();
    JsonField f = (JsonField) fields.get(0);
    assertEquals("fn", f.getName());
    assertEquals("/fn", f.getPath());
    assertEquals(FieldType.STRING, f.getFieldType());
    f = (JsonField) fields.get(1);
    assertEquals("familyName", f.getName());
    assertEquals("/familyName", f.getPath());
    assertEquals(FieldType.STRING, f.getFieldType());
    f = (JsonField) fields.get(2);
    assertEquals("givenName", f.getName());
    assertEquals("/givenName", f.getPath());
    assertEquals(FieldType.STRING, f.getFieldType());
    f = (JsonField) fields.get(3);
    assertEquals("additionalName", f.getName());
    assertEquals("/additionalName", f.getPath());
    assertEquals(FieldType.STRING, f.getFieldType());
    assertEquals(CollectionType.LIST, f.getCollectionType());
    f = (JsonField) fields.get(4);
    assertEquals("honorificPrefix", f.getName());
    assertEquals("/honorificPrefix", f.getPath());
    assertEquals(FieldType.STRING, f.getFieldType());
    assertEquals(CollectionType.LIST, f.getCollectionType());
    f = (JsonField) fields.get(5);
    assertEquals("honorificSuffix", f.getName());
    assertEquals("/honorificSuffix", f.getPath());
    assertEquals(FieldType.STRING, f.getFieldType());
    assertEquals(CollectionType.LIST, f.getCollectionType());
    f = (JsonField) fields.get(6);
    assertEquals("nickname", f.getName());
    assertEquals("/nickname", f.getPath());
    assertEquals(FieldType.STRING, f.getFieldType());
    f = (JsonField) fields.get(7);
    assertEquals("url", f.getName());
    assertEquals("/url", f.getPath());
    assertEquals(FieldType.STRING, f.getFieldType());
    f = (JsonComplexType) fields.get(8);
    assertEquals("email", f.getName());
    assertEquals("/email", f.getPath());
    assertEquals(FieldType.COMPLEX, f.getFieldType());
    List<JsonField> emailfields = ((JsonComplexType) f).getJsonFields().getJsonField();
    f = emailfields.get(0);
    assertEquals("type", f.getName());
    assertEquals("/email/type", f.getPath());
    assertEquals(FieldType.STRING, f.getFieldType());
    f = emailfields.get(1);
    assertEquals("value", f.getName());
    assertEquals("/email/value", f.getPath());
    assertEquals(FieldType.STRING, f.getFieldType());
    f = (JsonComplexType) fields.get(9);
    assertEquals("tel", f.getName());
    assertEquals("/tel", f.getPath());
    assertEquals(FieldType.COMPLEX, f.getFieldType());
    List<JsonField> telfields = ((JsonComplexType) f).getJsonFields().getJsonField();
    f = telfields.get(0);
    assertEquals("type", f.getName());
    assertEquals("/tel/type", f.getPath());
    assertEquals(FieldType.STRING, f.getFieldType());
    f = telfields.get(1);
    assertEquals("value", f.getName());
    assertEquals("/tel/value", f.getPath());
    assertEquals(FieldType.STRING, f.getFieldType());
    f = (JsonComplexType) fields.get(10);
    assertEquals("adr", f.getName());
    assertEquals("/adr", f.getPath());
    assertEquals(FieldType.COMPLEX, f.getFieldType());
    List<JsonField> addrfields = ((JsonComplexType) f).getJsonFields().getJsonField();
    f = addrfields.get(0);
    assertEquals("post-office-box", f.getName());
    assertEquals("/adr/post-office-box", f.getPath());
    assertEquals(FieldType.STRING, f.getFieldType());
    f = addrfields.get(1);
    assertEquals("extended-address", f.getName());
    assertEquals("/adr/extended-address", f.getPath());
    assertEquals(FieldType.STRING, f.getFieldType());
    f = addrfields.get(2);
    assertEquals("street-address", f.getName());
    assertEquals("/adr/street-address", f.getPath());
    assertEquals(FieldType.STRING, f.getFieldType());
    f = addrfields.get(3);
    assertEquals("locality", f.getName());
    assertEquals("/adr/locality", f.getPath());
    assertEquals(FieldType.STRING, f.getFieldType());
    f = addrfields.get(4);
    assertEquals("region", f.getName());
    assertEquals("/adr/region", f.getPath());
    assertEquals(FieldType.STRING, f.getFieldType());
    f = addrfields.get(5);
    assertEquals("postal-code", f.getName());
    assertEquals("/adr/postal-code", f.getPath());
    assertEquals(FieldType.STRING, f.getFieldType());
    f = addrfields.get(6);
    assertEquals("country-name", f.getName());
    assertEquals("/adr/country-name", f.getPath());
    assertEquals(FieldType.STRING, f.getFieldType());
    f = (JsonComplexType) fields.get(11);
    assertEquals("geo", f.getName());
    assertEquals("/geo", f.getPath());
    assertEquals(FieldType.COMPLEX, f.getFieldType());
    List<JsonField> geofields = ((JsonComplexType) f).getJsonFields().getJsonField();
    f = geofields.get(0);
    assertEquals("latitude", f.getName());
    assertEquals("/geo/latitude", f.getPath());
    assertEquals(FieldType.NUMBER, f.getFieldType());
    f = geofields.get(1);
    assertEquals("longitude", f.getName());
    assertEquals("/geo/longitude", f.getPath());
    assertEquals(FieldType.NUMBER, f.getFieldType());
    f = (JsonField) fields.get(12);
    assertEquals("tz", f.getName());
    assertEquals("/tz", f.getPath());
    assertEquals(FieldType.STRING, f.getFieldType());
    f = (JsonField) fields.get(13);
    assertEquals("photo", f.getName());
    assertEquals("/photo", f.getPath());
    assertEquals(FieldType.STRING, f.getFieldType());
    f = (JsonField) fields.get(14);
    assertEquals("logo", f.getName());
    assertEquals("/logo", f.getPath());
    assertEquals(FieldType.STRING, f.getFieldType());
    f = (JsonField) fields.get(15);
    assertEquals("sound", f.getName());
    assertEquals("/sound", f.getPath());
    assertEquals(FieldType.STRING, f.getFieldType());
    f = (JsonField) fields.get(16);
    assertEquals("bday", f.getName());
    assertEquals("/bday", f.getPath());
    assertEquals(FieldType.STRING, f.getFieldType());
    f = (JsonField) fields.get(17);
    assertEquals("title", f.getName());
    assertEquals("/title", f.getPath());
    assertEquals(FieldType.STRING, f.getFieldType());
    f = (JsonField) fields.get(18);
    assertEquals("role", f.getName());
    assertEquals("/role", f.getPath());
    assertEquals(FieldType.STRING, f.getFieldType());
    f = (JsonComplexType) fields.get(19);
    assertEquals("org", f.getName());
    assertEquals("/org", f.getPath());
    assertEquals(FieldType.COMPLEX, f.getFieldType());
    List<JsonField> orgfields = ((JsonComplexType) f).getJsonFields().getJsonField();
    f = orgfields.get(0);
    assertEquals("organizationName", f.getName());
    assertEquals("/org/organizationName", f.getPath());
    assertEquals(FieldType.STRING, f.getFieldType());
    f = orgfields.get(1);
    assertEquals("organizationUnit", f.getName());
    assertEquals("/org/organizationUnit", f.getPath());
    assertEquals(FieldType.STRING, f.getFieldType());
}
Also used : Field(io.atlasmap.v2.Field) JsonField(io.atlasmap.json.v2.JsonField) JsonField(io.atlasmap.json.v2.JsonField) JsonDocument(io.atlasmap.json.v2.JsonDocument)

Example 55 with JsonField

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

the class SchemaInspectorTest method doInspectJsonSchemaCalendar.

private void doInspectJsonSchemaCalendar(String instance) throws Exception {
    JsonDocument document = inspectionService.inspectJsonSchema(instance);
    List<Field> fields = document.getFields().getField();
    JsonField f = (JsonField) fields.get(0);
    assertEquals("dtstart", f.getName());
    assertEquals("/dtstart", f.getPath());
    assertEquals(FieldType.STRING, f.getFieldType());
    f = (JsonField) fields.get(1);
    assertEquals("dtend", f.getName());
    assertEquals("/dtend", f.getPath());
    assertEquals(FieldType.STRING, f.getFieldType());
    f = (JsonField) fields.get(2);
    assertEquals("summary", f.getName());
    assertEquals("/summary", f.getPath());
    assertEquals(FieldType.STRING, f.getFieldType());
    f = (JsonField) fields.get(3);
    assertEquals("location", f.getName());
    assertEquals("/location", f.getPath());
    assertEquals(FieldType.STRING, f.getFieldType());
    f = (JsonField) fields.get(4);
    assertEquals("url", f.getName());
    assertEquals("/url", f.getPath());
    assertEquals(FieldType.STRING, f.getFieldType());
    f = (JsonField) fields.get(5);
    assertEquals("duration", f.getName());
    assertEquals("/duration", f.getPath());
    assertEquals(FieldType.STRING, f.getFieldType());
    f = (JsonField) fields.get(6);
    assertEquals("rdate", f.getName());
    assertEquals("/rdate", f.getPath());
    assertEquals(FieldType.STRING, f.getFieldType());
    f = (JsonField) fields.get(7);
    assertEquals("rrule", f.getName());
    assertEquals("/rrule", f.getPath());
    assertEquals(FieldType.STRING, f.getFieldType());
    f = (JsonField) fields.get(8);
    assertEquals("category", f.getName());
    assertEquals("/category", f.getPath());
    assertEquals(FieldType.STRING, f.getFieldType());
    f = (JsonField) fields.get(9);
    assertEquals("description", f.getName());
    assertEquals("/description", f.getPath());
    assertEquals(FieldType.STRING, f.getFieldType());
    f = (JsonComplexType) fields.get(10);
    assertEquals("geo", f.getName());
    assertEquals("/geo", f.getPath());
    assertEquals(FieldType.COMPLEX, f.getFieldType());
    List<JsonField> geofields = ((JsonComplexType) f).getJsonFields().getJsonField();
    f = geofields.get(0);
    assertEquals("latitude", f.getName());
    assertEquals("/geo/latitude", f.getPath());
    assertEquals(FieldType.NUMBER, f.getFieldType());
    f = geofields.get(1);
    assertEquals("longitude", f.getName());
    assertEquals("/geo/longitude", f.getPath());
    assertEquals(FieldType.NUMBER, f.getFieldType());
}
Also used : Field(io.atlasmap.v2.Field) JsonField(io.atlasmap.json.v2.JsonField) JsonField(io.atlasmap.json.v2.JsonField) JsonDocument(io.atlasmap.json.v2.JsonDocument)

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