use of io.atlasmap.spi.AtlasInternalSession in project atlasmap by atlasmap.
the class PropertyModuleTest method testProcessTargetFieldMapping.
@Test
public void testProcessTargetFieldMapping() throws Exception {
PropertyField field = mock(PropertyField.class);
when(field.getName()).thenReturn("testProp");
when(field.getValue()).thenReturn("testValue");
Head head = mock(Head.class);
when(head.getTargetField()).thenReturn(field);
AtlasInternalSession session = mock(AtlasInternalSession.class);
when(session.head()).thenReturn(head);
Map<String, Object> targetProps = new HashMap<>();
when(session.getTargetProperties()).thenReturn(targetProps);
DefaultAtlasConversionService atlasConversionService = mock(DefaultAtlasConversionService.class);
when(atlasConversionService.fieldTypeFromClass(any(String.class))).thenReturn(FieldType.ANY);
module.setConversionService(atlasConversionService);
module.writeTargetValue(session);
assertEquals("testValue", targetProps.get("testProp"));
}
use of io.atlasmap.spi.AtlasInternalSession in project atlasmap by atlasmap.
the class DefaultAtlasSessionTest method testSetFieldReader.
@Test
public void testSetFieldReader() {
AtlasFieldReader reader = new AtlasFieldReader() {
@Override
public Field read(AtlasInternalSession session) throws AtlasException {
LOG.debug("read method");
return session.head().getSourceField();
}
};
session.setFieldReader(null, reader);
session.setFieldReader("", reader);
}
use of io.atlasmap.spi.AtlasInternalSession in project atlasmap by atlasmap.
the class XmlFieldWriterTest method testThrowExceptionOnNullXmlField.
@Test
public void testThrowExceptionOnNullXmlField() throws Exception {
createWriter();
XmlField field = null;
AtlasInternalSession session = mock(AtlasInternalSession.class);
when(session.head()).thenReturn(mock(Head.class));
when(session.head().getSourceField()).thenReturn(mock(Field.class));
when(session.head().getTargetField()).thenReturn(field);
assertThrows(AtlasException.class, () -> {
writer.write(session);
});
}
use of io.atlasmap.spi.AtlasInternalSession in project atlasmap by atlasmap.
the class XmlFieldWriterTest method validatePrimitiveValue.
private void validatePrimitiveValue(FieldType fieldType, String fileName, Object testObject, Object expectedObject) throws Exception {
Path path = Paths.get("target" + File.separator + fileName);
AtlasInternalSession session = readSession(fieldType, path, testObject);
assertNotNull(session.head().getSourceField().getValue());
assertEquals(expectedObject, session.head().getSourceField().getValue());
}
use of io.atlasmap.spi.AtlasInternalSession in project atlasmap by atlasmap.
the class KafkaConnectFieldReaderTest method testReadPrimitiveArray.
@Test
public void testReadPrimitiveArray() throws Exception {
reader.setDocument(Arrays.asList(new String[] { "foo", "bar", "val" }));
AtlasInternalSession session = mock(AtlasInternalSession.class);
when(session.head()).thenReturn(mock(Head.class));
KafkaConnectField field = AtlasKafkaConnectModelFactory.createKafkaConnectField();
field.setPath("/<>");
field.setFieldType(FieldType.STRING);
when(session.head().getSourceField()).thenReturn(field);
Audits audits = new Audits();
when(session.getAudits()).thenReturn(audits);
Field answer = reader.read(session);
assertEquals(0, audits.getAudit().size());
assertTrue(answer instanceof FieldGroup);
FieldGroup group = (FieldGroup) answer;
assertEquals("/<>", group.getPath());
Field child = group.getField().get(0);
assertEquals(FieldType.STRING, child.getFieldType());
assertEquals("foo", child.getValue());
assertEquals("/<0>", child.getPath());
child = group.getField().get(1);
assertEquals(FieldType.STRING, child.getFieldType());
assertEquals("bar", child.getValue());
assertEquals("/<1>", child.getPath());
child = group.getField().get(2);
assertEquals(FieldType.STRING, child.getFieldType());
assertEquals("val", child.getValue());
assertEquals("/<2>", child.getPath());
field.setPath("/<1>");
answer = reader.read(session);
assertEquals("bar", answer.getValue());
}
Aggregations