use of io.atlasmap.json.v2.JsonField in project atlasmap by atlasmap.
the class SchemaInspectorTest method inspectJsonSchemaAddress.
@Test
public void inspectJsonSchemaAddress() throws Exception {
final String schema = new String(Files.readAllBytes(Paths.get("src/test/resources/inspect/schema/address.json")));
JsonDocument document = inspectionService.inspectJsonSchema(schema);
List<Field> fields = document.getFields().getField();
JsonField f = (JsonField) fields.get(0);
assertEquals("post-office-box", f.getName());
assertEquals("/post-office-box", f.getPath());
assertEquals(FieldType.STRING, f.getFieldType());
f = (JsonField) fields.get(1);
assertEquals("extended-address", f.getName());
assertEquals("/extended-address", f.getPath());
assertEquals(FieldType.STRING, f.getFieldType());
f = (JsonField) fields.get(2);
assertEquals("street-address", f.getName());
assertEquals("/street-address", f.getPath());
assertEquals(FieldType.STRING, f.getFieldType());
f = (JsonField) fields.get(3);
assertEquals("locality", f.getName());
assertEquals("/locality", f.getPath());
assertEquals(FieldType.STRING, f.getFieldType());
f = (JsonField) fields.get(4);
assertEquals("region", f.getName());
assertEquals("/region", f.getPath());
assertEquals(FieldType.STRING, f.getFieldType());
f = (JsonField) fields.get(5);
assertEquals("postal-code", f.getName());
assertEquals("/postal-code", f.getPath());
assertEquals(FieldType.STRING, f.getFieldType());
f = (JsonField) fields.get(6);
assertEquals("country-name", f.getName());
assertEquals("/country-name", f.getPath());
assertEquals(FieldType.STRING, f.getFieldType());
}
use of io.atlasmap.json.v2.JsonField in project atlasmap by atlasmap.
the class JsonValidationServiceTest method testValidateMappingInvalidSeparateInputFieldType.
@Test
public void testValidateMappingInvalidSeparateInputFieldType() {
AtlasMapping atlasMapping = getAtlasMappingFullValid();
Mapping separateFieldMapping = AtlasModelFactory.createMapping(MappingType.SEPARATE);
separateFieldMapping.setId("separate.firstName.lastName");
JsonField bIJavaField = jsonModelFactory.createJsonField();
bIJavaField.setFieldType(FieldType.BOOLEAN);
bIJavaField.setValue(Boolean.TRUE);
bIJavaField.setPath("firstName");
separateFieldMapping.getInputField().add(bIJavaField);
JsonField sOJavaField = jsonModelFactory.createJsonField();
sOJavaField.setFieldType(FieldType.STRING);
sOJavaField.setPath("lastName");
sOJavaField.setIndex(0);
separateFieldMapping.getOutputField().add(sOJavaField);
atlasMapping.getMappings().getMapping().add(separateFieldMapping);
validations.addAll(sourceValidationService.validateMapping(atlasMapping));
validations.addAll(targetValidationService.validateMapping(atlasMapping));
assertTrue(validationHelper.hasErrors());
assertFalse(validationHelper.hasWarnings());
assertFalse(validationHelper.hasInfos());
assertEquals(new Integer(1), new Integer(validationHelper.getCount()));
Validation validation = validations.get(0);
assertNotNull(validation);
assertEquals(ValidationScope.MAPPING, validation.getScope());
assertEquals("separate.firstName.lastName", validation.getId());
assertEquals("Input field 'firstName' must be of type 'STRING' for a Separate Mapping", validation.getMessage());
assertEquals(ValidationStatus.ERROR, validation.getStatus());
}
use of io.atlasmap.json.v2.JsonField in project atlasmap by atlasmap.
the class JsonValidationServiceTest method testValidateMappingPathNull.
@Test
public void testValidateMappingPathNull() throws Exception {
AtlasMapping mapping = mappingUtil.loadMapping("src/test/resources/mappings/HappyPathMapping.xml");
assertNotNull(mapping);
Mapping fieldMapping = (Mapping) mapping.getMappings().getMapping().get(0);
JsonField in = (JsonField) fieldMapping.getInputField().get(0);
in.setPath(null);
validations.addAll(sourceValidationService.validateMapping(mapping));
validations.addAll(targetValidationService.validateMapping(mapping));
assertTrue(validationHelper.hasErrors());
assertFalse(validationHelper.hasWarnings());
assertFalse(validationHelper.hasInfos());
}
use of io.atlasmap.json.v2.JsonField in project atlasmap by atlasmap.
the class JsonFieldReaderTest method testRangeOutValue.
private void testRangeOutValue(String fileName, String fieldPath, FieldType fieldType, String errorMessage, String errorValue) throws Exception {
String filePath = "src" + File.separator + "test" + File.separator + "resources" + File.separator + "jsonFields" + File.separator + fileName;
String document = new String(Files.readAllBytes(Paths.get(filePath)));
reader.setDocument(document);
JsonField field = AtlasJsonModelFactory.createJsonField();
field.setPath(fieldPath);
field.setFieldType(fieldType);
AtlasInternalSession session = read(field);
assertEquals(null, field.getValue());
assertEquals(1, session.getAudits().getAudit().size());
assertEquals(errorMessage, session.getAudits().getAudit().get(0).getMessage());
assertEquals(errorValue, session.getAudits().getAudit().get(0).getValue());
assertEquals(AuditStatus.ERROR, session.getAudits().getAudit().get(0).getStatus());
}
use of io.atlasmap.json.v2.JsonField in project atlasmap by atlasmap.
the class JsonFieldReaderTest method testArrayUnderRoot.
@Test
public void testArrayUnderRoot() throws Exception {
final String document = new String(Files.readAllBytes(Paths.get("src/test/resources/array-under-root.json")));
reader.setDocument(document);
JsonField field = AtlasJsonModelFactory.createJsonField();
field.setPath("/array[0]");
AtlasInternalSession session = mock(AtlasInternalSession.class);
when(session.head()).thenReturn(mock(Head.class));
when(session.head().getSourceField()).thenReturn(field);
reader.read(session);
assertEquals("array-zero", field.getValue());
field.setPath("/array[1]");
reader.read(session);
assertEquals("array-one", field.getValue());
field.setPath("/array[2]");
reader.read(session);
assertEquals("array-two", field.getValue());
}
Aggregations