Search in sources :

Example 21 with JsonComplexType

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

the class JsonFieldWriterTest method testWriteHighlyComplexObject.

@Test
@Ignore
public // with nested arrays.
void testWriteHighlyComplexObject() throws Exception {
    JsonComplexType items = JsonComplexTypeFactory.createJsonComlexField();
    items.setPath("/items");
    items.setJsonFields(new JsonFields());
    write(items);
    JsonComplexType item = JsonComplexTypeFactory.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 = JsonComplexTypeFactory.createJsonComlexField();
    batters.setJsonFields(new JsonFields());
    batters.setPath("/items/item/batters");
    items.getJsonFields().getJsonField().add(batters);
    write(batters);
    JsonComplexType batter = JsonComplexTypeFactory.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 = JsonComplexTypeFactory.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");
    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");
    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 = JsonComplexTypeFactory.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 = JsonComplexTypeFactory.createJsonComlexField();
    batters1.setJsonFields(new JsonFields());
    batters1.setPath("/items/item[1]/batters");
    items.getJsonFields().getJsonField().add(batters1);
    write(batters1);
    JsonComplexType batter1 = JsonComplexTypeFactory.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);
    // FIXME this writes to the items/item/batters/batter and not at
    // items/item[1]/batters/batter
    // 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);
    // writer.write(batter1_1_id, root);
    // 
    // 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);
    // writer.write(batter1_1_type, root);
    System.out.println(prettyPrintJson(writer.getRootNode().toString()));
}
Also used : JsonField(io.atlasmap.json.v2.JsonField) JsonFields(io.atlasmap.json.v2.JsonFields) JsonComplexType(io.atlasmap.json.v2.JsonComplexType) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 22 with JsonComplexType

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

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

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

JsonComplexType (io.atlasmap.json.v2.JsonComplexType)21 JsonField (io.atlasmap.json.v2.JsonField)18 JsonDocument (io.atlasmap.json.v2.JsonDocument)17 Test (org.junit.Test)14 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 JsonFields (io.atlasmap.json.v2.JsonFields)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Field (io.atlasmap.v2.Field)2 Map (java.util.Map)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Ignore (org.junit.Ignore)1