use of io.atlasmap.spi.AtlasInternalSession in project atlasmap by atlasmap.
the class JsonFieldReaderTest method read.
private AtlasInternalSession read(JsonField field) throws AtlasException {
AtlasInternalSession session = mock(AtlasInternalSession.class);
when(session.head()).thenReturn(mock(Head.class));
when(session.head().getSourceField()).thenReturn(field);
Audits audits = new Audits();
when(session.getAudits()).thenReturn(audits);
reader.read(session);
return session;
}
use of io.atlasmap.spi.AtlasInternalSession in project atlasmap by atlasmap.
the class JsonFieldReaderTest method testJsonFieldFloatMinRangOut.
@Test
public void testJsonFieldFloatMinRangOut() throws Exception {
AtlasInternalSession session = testBoundaryValue("field-float-min-range-out.json", "/floatValue", FieldType.FLOAT, 0.0f);
assertEquals(0, session.getAudits().getAudit().size());
}
use of io.atlasmap.spi.AtlasInternalSession 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.spi.AtlasInternalSession in project atlasmap by atlasmap.
the class JsonFieldReaderTest method testSameFieldNameInDifferentPath.
@Test
public void testSameFieldNameInDifferentPath() throws Exception {
final String document = new String(Files.readAllBytes(Paths.get("src/test/resources/same-field-name-in-different-path.json")));
reader.setDocument(document);
JsonField field = AtlasJsonModelFactory.createJsonField();
field.setPath("/name");
AtlasInternalSession session = mock(AtlasInternalSession.class);
when(session.head()).thenReturn(mock(Head.class));
when(session.head().getSourceField()).thenReturn(field);
reader.read(session);
assertEquals("name", field.getValue());
field.setPath("/object1/name");
reader.read(session);
assertEquals("object1-name", field.getValue());
field.setPath("/object2/name");
reader.read(session);
assertEquals("object2-name", field.getValue());
field.setPath("/object1/object2/name");
reader.read(session);
assertEquals("object1-object2-name", field.getValue());
}
use of io.atlasmap.spi.AtlasInternalSession in project atlasmap by atlasmap.
the class JsonFieldReaderTest method testComplexJsonDocumentNestedObjectArray.
@Test
public void testComplexJsonDocumentNestedObjectArray() throws Exception {
final String document = "{\"menu\": {\n" + " \"id\": \"file\",\n" + " \"value\": \"Filed\",\n" + " \"popup\": {\n" + " \"menuitem\": [\n" + " {\"value\": \"New\", \"onclick\": \"CreateNewDoc()\"},\n" + " {\"value\": \"Open\", \"onclick\": \"OpenDoc()\"},\n" + " {\"value\": \"Close\", \"onclick\": \"CloseDoc()\"}\n" + " ]\n" + " }\n" + "}}";
reader.setDocument(document);
JsonField field = AtlasJsonModelFactory.createJsonField();
field.setPath("/menu/id");
AtlasInternalSession session = mock(AtlasInternalSession.class);
when(session.head()).thenReturn(mock(Head.class));
when(session.head().getSourceField()).thenReturn(field);
reader.read(session);
assertNotNull(field.getValue());
assertEquals("file", field.getValue());
field.setPath("/menu/value");
reader.read(session);
assertNotNull(field.getValue());
assertEquals("Filed", field.getValue());
field.setPath("/menu/popup/menuitem[0]/value");
reader.read(session);
assertNotNull(field.getValue());
assertEquals("New", field.getValue());
field.setPath("/menu/popup/menuitem[0]/onclick");
reader.read(session);
assertNotNull(field.getValue());
assertEquals("CreateNewDoc()", field.getValue());
field.setPath("/menu/popup/menuitem[1]/value");
reader.read(session);
assertNotNull(field.getValue());
assertEquals("Open", field.getValue());
field.setPath("/menu/popup/menuitem[1]/onclick");
reader.read(session);
assertNotNull(field.getValue());
assertEquals("OpenDoc()", field.getValue());
field.setPath("/menu/popup/menuitem[2]/value");
reader.read(session);
assertNotNull(field.getValue());
assertEquals("Close", field.getValue());
field.setPath("/menu/popup/menuitem[2]/onclick");
reader.read(session);
assertNotNull(field.getValue());
assertEquals("CloseDoc()", field.getValue());
}
Aggregations