Search in sources :

Example 66 with AtlasInternalSession

use of io.atlasmap.spi.AtlasInternalSession in project atlasmap by atlasmap.

the class XmlFieldReaderTest method testReadDocumentSetAttributeValueComplex.

@Test
public void testReadDocumentSetAttributeValueComplex() throws Exception {
    Document doc = getDocumentFromFile("src/test/resources/complex_example.xml", false);
    reader.setDocument(doc);
    XmlField xmlField = AtlasXmlModelFactory.createXmlField();
    xmlField.setPath("/orders/order[2]/id[1]/@custId");
    assertNull(xmlField.getValue());
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    when(session.head().getSourceField()).thenReturn(xmlField);
    reader.read(session);
    assertNotNull(xmlField.getValue());
    assertEquals("b", xmlField.getValue());
}
Also used : Head(io.atlasmap.spi.AtlasInternalSession.Head) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) XmlField(io.atlasmap.xml.v2.XmlField) Document(org.w3c.dom.Document) Test(org.junit.jupiter.api.Test)

Example 67 with AtlasInternalSession

use of io.atlasmap.spi.AtlasInternalSession in project atlasmap by atlasmap.

the class XmlFieldReaderTest method testThrowExceptionOnNullXmlField.

@Test
public void testThrowExceptionOnNullXmlField() throws Exception {
    Document doc = getDocumentFromFile("src/test/resources/complex_example.xml", false);
    reader.setDocument(doc);
    XmlField xmlField = null;
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    when(session.head().getSourceField()).thenReturn(xmlField);
    assertThrows(AtlasException.class, () -> {
        reader.read(session);
    });
}
Also used : Head(io.atlasmap.spi.AtlasInternalSession.Head) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) XmlField(io.atlasmap.xml.v2.XmlField) Document(org.w3c.dom.Document) Test(org.junit.jupiter.api.Test)

Example 68 with AtlasInternalSession

use of io.atlasmap.spi.AtlasInternalSession in project atlasmap by atlasmap.

the class XmlFieldReaderTest method testReadDocumentSetElementValueComplex.

@Test
public void testReadDocumentSetElementValueComplex() throws Exception {
    Document doc = getDocumentFromFile("src/test/resources/complex_example.xml", false);
    reader.setDocument(doc);
    XmlField xmlField = AtlasXmlModelFactory.createXmlField();
    xmlField.setPath("/orders/order[3]/id[1]");
    assertNull(xmlField.getValue());
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    when(session.head().getSourceField()).thenReturn(xmlField);
    reader.read(session);
    assertNotNull(xmlField.getValue());
    assertEquals("54554555", xmlField.getValue());
}
Also used : Head(io.atlasmap.spi.AtlasInternalSession.Head) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) XmlField(io.atlasmap.xml.v2.XmlField) Document(org.w3c.dom.Document) Test(org.junit.jupiter.api.Test)

Example 69 with AtlasInternalSession

use of io.atlasmap.spi.AtlasInternalSession in project atlasmap by atlasmap.

the class XmlFieldReaderTest method testReadDocumentWithMultipleNamespaceComplex.

@Test
public void testReadDocumentWithMultipleNamespaceComplex() throws Exception {
    Document doc = getDocumentFromFile("src/test/resources/complex_example_ns.xml", true);
    reader.setDocument(doc);
    XmlField xmlField = AtlasXmlModelFactory.createXmlField();
    xmlField.setPath("/orders/order[2]/id[1]/@y:custId");
    assertNull(xmlField.getValue());
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    when(session.head().getSourceField()).thenReturn(xmlField);
    reader.read(session);
    assertNotNull(xmlField.getValue());
    assertEquals("b", xmlField.getValue());
}
Also used : Head(io.atlasmap.spi.AtlasInternalSession.Head) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) XmlField(io.atlasmap.xml.v2.XmlField) Document(org.w3c.dom.Document) Test(org.junit.jupiter.api.Test)

Example 70 with AtlasInternalSession

use of io.atlasmap.spi.AtlasInternalSession in project atlasmap by atlasmap.

the class BaseDefaultAtlasContextTest method mockAtlasModule.

private BaseAtlasModule mockAtlasModule() throws AtlasException {
    BaseAtlasModule module = spy(BaseAtlasModule.class);
    when(module.getConversionService()).thenReturn(DefaultAtlasConversionService.getInstance());
    when(module.createField()).thenReturn(new SimpleField());
    when(module.isSupportedField(any(Field.class))).thenReturn(true);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            AtlasInternalSession session = (AtlasInternalSession) invocation.getArguments()[0];
            reader.read(session);
            return null;
        }
    }).when(module).readSourceValue(any());
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            AtlasInternalSession session = (AtlasInternalSession) invocation.getArguments()[0];
            LookupTable table = session.head().getLookupTable();
            Field source = session.head().getSourceField();
            Field target = session.head().getTargetField();
            Object value = source.getValue();
            if (table != null) {
                for (LookupEntry e : table.getLookupEntry()) {
                    if (value.equals(e.getSourceValue())) {
                        value = e.getTargetValue();
                    }
                }
            }
            target.setValue(value);
            return null;
        }
    }).when(module).populateTargetField(any());
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            AtlasInternalSession session = (AtlasInternalSession) invocation.getArguments()[0];
            writer.write(session);
            return null;
        }
    }).when(module).writeTargetValue(any());
    return module;
}
Also used : Field(io.atlasmap.v2.Field) SimpleField(io.atlasmap.v2.SimpleField) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) InvocationOnMock(org.mockito.invocation.InvocationOnMock) LookupEntry(io.atlasmap.v2.LookupEntry) LookupTable(io.atlasmap.v2.LookupTable) SimpleField(io.atlasmap.v2.SimpleField)

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