Search in sources :

Example 71 with AtlasInternalSession

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"));
}
Also used : PropertyField(io.atlasmap.v2.PropertyField) Head(io.atlasmap.spi.AtlasInternalSession.Head) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 72 with AtlasInternalSession

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);
}
Also used : AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) AtlasFieldReader(io.atlasmap.spi.AtlasFieldReader) Test(org.junit.jupiter.api.Test)

Example 73 with AtlasInternalSession

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);
    });
}
Also used : Field(io.atlasmap.v2.Field) XmlField(io.atlasmap.xml.v2.XmlField) Head(io.atlasmap.spi.AtlasInternalSession.Head) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) XmlField(io.atlasmap.xml.v2.XmlField) Test(org.junit.jupiter.api.Test)

Example 74 with AtlasInternalSession

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());
}
Also used : Path(java.nio.file.Path) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession)

Example 75 with AtlasInternalSession

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());
}
Also used : KafkaConnectField(io.atlasmap.kafkaconnect.v2.KafkaConnectField) Field(io.atlasmap.v2.Field) Head(io.atlasmap.spi.AtlasInternalSession.Head) Audits(io.atlasmap.v2.Audits) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) FieldGroup(io.atlasmap.v2.FieldGroup) KafkaConnectField(io.atlasmap.kafkaconnect.v2.KafkaConnectField) Test(org.junit.jupiter.api.Test)

Aggregations

AtlasInternalSession (io.atlasmap.spi.AtlasInternalSession)90 Test (org.junit.jupiter.api.Test)61 Head (io.atlasmap.spi.AtlasInternalSession.Head)56 XmlField (io.atlasmap.xml.v2.XmlField)26 Audits (io.atlasmap.v2.Audits)22 Field (io.atlasmap.v2.Field)20 Document (org.w3c.dom.Document)19 FieldGroup (io.atlasmap.v2.FieldGroup)17 JsonField (io.atlasmap.json.v2.JsonField)16 Path (java.nio.file.Path)14 ByteArrayInputStream (java.io.ByteArrayInputStream)7 CsvField (io.atlasmap.csv.v2.CsvField)6 KafkaConnectField (io.atlasmap.kafkaconnect.v2.KafkaConnectField)6 AtlasPath (io.atlasmap.core.AtlasPath)3 FieldType (io.atlasmap.v2.FieldType)3 CsvComplexType (io.atlasmap.csv.v2.CsvComplexType)2 JavaField (io.atlasmap.java.v2.JavaField)2 AtlasFieldReader (io.atlasmap.spi.AtlasFieldReader)2 AtlasFieldWriter (io.atlasmap.spi.AtlasFieldWriter)2 Document (io.atlasmap.v2.Document)2