use of io.atlasmap.json.v2.JsonDocument in project atlasmap by atlasmap.
the class JsonInstanceInspectorTest method inspectJsonDocumentSimpleArrayStartsWithWhiteSpace.
@Test
public void inspectJsonDocumentSimpleArrayStartsWithWhiteSpace() throws Exception {
final String instance = "\n\t\r [ 100, 500, 300, 200, 400 ]";
JsonDocument document = inspectionService.inspectJsonDocument(instance);
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.INTEGER, jsonField.getFieldType());
assertEquals("", jsonField.getName());
assertEquals("/<>", jsonField.getPath());
}
use of io.atlasmap.json.v2.JsonDocument in project atlasmap by atlasmap.
the class JsonInstanceInspectorTest method inspectFlatPrimitiveWithRoot.
@Test
public void inspectFlatPrimitiveWithRoot() throws Exception {
final String instance = new String(Files.readAllBytes(Paths.get("src/test/resources/inspect/flatprimitive-base-rooted.json")));
JsonDocument document = inspectionService.inspectJsonDocument(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(8, root.getJsonFields().getJsonField().size());
for (int i = 0; i < root.getJsonFields().getJsonField().size(); i++) {
JsonField field = root.getJsonFields().getJsonField().get(i);
if (i == 0) {
assertEquals("booleanField", field.getName());
assertEquals(false, field.getValue());
assertEquals("/SourceFlatPrimitive/".concat(field.getName()), field.getPath());
assertEquals(FieldType.BOOLEAN, field.getFieldType());
assertEquals(FieldStatus.SUPPORTED, field.getStatus());
} else if (i == 1) {
assertEquals("charField", field.getName());
assertEquals("a", field.getValue());
assertEquals("/SourceFlatPrimitive/".concat(field.getName()), field.getPath());
assertEquals(FieldType.STRING, field.getFieldType());
assertEquals(FieldStatus.SUPPORTED, field.getStatus());
} else if (i == 2) {
assertEquals("doubleField", field.getName());
assertEquals(-27152745.3422, field.getValue());
assertEquals("/SourceFlatPrimitive/".concat(field.getName()), field.getPath());
assertEquals(FieldType.DOUBLE, field.getFieldType());
assertEquals(FieldStatus.SUPPORTED, field.getStatus());
} else if (i == 3) {
assertEquals("floatField", field.getName());
assertEquals(-63988281.00, field.getValue());
assertEquals("/SourceFlatPrimitive/".concat(field.getName()), field.getPath());
assertEquals(FieldType.DOUBLE, field.getFieldType());
assertEquals(FieldStatus.SUPPORTED, field.getStatus());
} else if (i == 4) {
assertEquals("intField", field.getName());
assertEquals(8281, field.getValue());
assertEquals("/SourceFlatPrimitive/".concat(field.getName()), field.getPath());
assertEquals(FieldType.INTEGER, field.getFieldType());
assertEquals(FieldStatus.SUPPORTED, field.getStatus());
} else if (i == 5) {
assertEquals("shortField", field.getName());
assertEquals(81, field.getValue());
assertEquals("/SourceFlatPrimitive/".concat(field.getName()), field.getPath());
assertEquals(FieldType.INTEGER, field.getFieldType());
assertEquals(FieldStatus.SUPPORTED, field.getStatus());
} else if (i == 6) {
assertEquals("longField", field.getName());
assertEquals(3988281, field.getValue());
assertEquals("/SourceFlatPrimitive/".concat(field.getName()), field.getPath());
assertEquals(FieldType.INTEGER, field.getFieldType());
assertEquals(FieldStatus.SUPPORTED, field.getStatus());
}
}
}
use of io.atlasmap.json.v2.JsonDocument in project atlasmap by atlasmap.
the class JsonInstanceInspectorTest method inspectJsonDocumentNoRoot.
@Test
public void inspectJsonDocumentNoRoot() throws Exception {
final String instance = "{ \"brand\" : \"Mercedes\", \"doors\" : 5 }";
JsonDocument document = inspectionService.inspectJsonDocument(instance);
assertNotNull(document);
assertEquals(2, document.getFields().getField().size());
JsonField field1 = (JsonField) document.getFields().getField().get(0);
assertNotNull(field1);
assertEquals("brand", field1.getName());
assertEquals("Mercedes", field1.getValue());
assertEquals("/brand", field1.getPath());
assertEquals(FieldType.STRING, field1.getFieldType());
assertEquals(FieldStatus.SUPPORTED, field1.getStatus());
JsonField field2 = (JsonField) document.getFields().getField().get(1);
assertNotNull(field2);
assertEquals("doors", field2.getName());
assertEquals(5, field2.getValue());
assertEquals("/doors", field2.getPath());
assertEquals(FieldType.INTEGER, field2.getFieldType());
assertEquals(FieldStatus.SUPPORTED, field2.getStatus());
// printDocument(document);
}
use of io.atlasmap.json.v2.JsonDocument in project atlasmap by atlasmap.
the class JsonInstanceInspectorTest method inspectJsonDocumentSimpleArray.
@Test
public void inspectJsonDocumentSimpleArray() throws Exception {
final String instance = "[ 100, 500, 300, 200, 400 ]";
JsonDocument document = inspectionService.inspectJsonDocument(instance);
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.INTEGER, jsonField.getFieldType());
assertEquals("", jsonField.getName());
assertEquals("/<>", jsonField.getPath());
// printDocument(document);
}
use of io.atlasmap.json.v2.JsonDocument in project atlasmap by atlasmap.
the class JsonInstanceInspectorTest method inspectJsonDocumentEscapedCharsInKeys.
@Test
public void inspectJsonDocumentEscapedCharsInKeys() throws Exception {
final String instance = new String(Files.readAllBytes(Paths.get("src/test/resources/inspect/keys-with-escaped-characters.json")));
JsonDocument document = inspectionService.inspectJsonDocument(instance);
assertNotNull(document);
assertEquals(7, document.getFields().getField().size());
for (int i = 0; i < document.getFields().getField().size(); i++) {
JsonField field = (JsonField) document.getFields().getField().get(i);
if (i == 0) {
assertEquals("'booleanField'", field.getName());
assertEquals(false, field.getValue());
assertEquals("/".concat(field.getName()), field.getPath());
assertEquals(FieldType.BOOLEAN, field.getFieldType());
assertEquals(FieldStatus.SUPPORTED, field.getStatus());
} else if (i == 1) {
assertEquals("\"charField\"", field.getName());
assertEquals("a", field.getValue());
assertEquals("/".concat(field.getName()), field.getPath());
assertEquals(FieldType.STRING, field.getFieldType());
assertEquals(FieldStatus.SUPPORTED, field.getStatus());
} else if (i == 2) {
assertEquals("\\doubleField", field.getName());
assertEquals(-27152745.3422, field.getValue());
assertEquals("/".concat(field.getName()), field.getPath());
assertEquals(FieldType.DOUBLE, field.getFieldType());
assertEquals(FieldStatus.SUPPORTED, field.getStatus());
} else if (i == 3) {
assertEquals("floatField\t", field.getName());
assertEquals(-63988281.00, field.getValue());
assertEquals("/".concat(field.getName()), field.getPath());
assertEquals(FieldType.DOUBLE, field.getFieldType());
assertEquals(FieldStatus.SUPPORTED, field.getStatus());
} else if (i == 4) {
assertEquals("intField\n", field.getName());
assertEquals(8281, field.getValue());
assertEquals("/".concat(field.getName()), field.getPath());
assertEquals(FieldType.INTEGER, field.getFieldType());
assertEquals(FieldStatus.SUPPORTED, field.getStatus());
} else if (i == 5) {
assertEquals("shortField", field.getName());
assertEquals(81, field.getValue());
assertEquals("/".concat(field.getName()), field.getPath());
assertEquals(FieldType.INTEGER, field.getFieldType());
assertEquals(FieldStatus.SUPPORTED, field.getStatus());
} else if (i == 6) {
assertEquals("longField", field.getName());
assertEquals(3988281, field.getValue());
assertEquals("/".concat(field.getName()), field.getPath());
assertEquals(FieldType.INTEGER, field.getFieldType());
assertEquals(FieldStatus.SUPPORTED, field.getStatus());
}
}
// printDocument(document);
}
Aggregations