Search in sources :

Example 56 with JsonDocument

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

the class SchemaInspectorTest method inspectJsonSchemaSimpleArray.

@Test
public void inspectJsonSchemaSimpleArray() 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.UNSUPPORTED, jsonField.getStatus());
    assertEquals(CollectionType.LIST, jsonField.getCollectionType());
    assertEquals(FieldType.INTEGER, 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 57 with JsonDocument

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

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

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

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

Aggregations

JsonDocument (io.atlasmap.json.v2.JsonDocument)73 JsonField (io.atlasmap.json.v2.JsonField)65 JsonComplexType (io.atlasmap.json.v2.JsonComplexType)38 Test (org.junit.jupiter.api.Test)32 Test (org.junit.Test)29 Field (io.atlasmap.v2.Field)11 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 JsonEnumField (io.atlasmap.json.v2.JsonEnumField)6 IOException (java.io.IOException)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 JsonInspectionService (io.atlasmap.json.inspect.JsonInspectionService)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ValueNode (com.fasterxml.jackson.databind.node.ValueNode)2 JsonFields (io.atlasmap.json.v2.JsonFields)2 JsonInspectionRequest (io.atlasmap.json.v2.JsonInspectionRequest)2 JsonInspectionResponse (io.atlasmap.json.v2.JsonInspectionResponse)2 Path (java.nio.file.Path)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2