Search in sources :

Example 11 with AtlasInternalSession

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

the class DefaultAtlasSessionTest method testGetFieldReader.

@Test
public void testGetFieldReader() {
    AtlasFieldReader reader = new AtlasFieldReader() {

        @Override
        public void read(AtlasInternalSession session) throws AtlasException {
            LOG.debug("read method");
        }
    };
    session.setFieldReader(AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID, reader);
    assertNotNull(session.getFieldReader(null));
    assertNotNull(session.getFieldReader(""));
    assertNotNull(session.getFieldReader(AtlasConstants.DEFAULT_SOURCE_DOCUMENT_ID));
    assertNotNull(session.getFieldReader("", AtlasFieldReader.class));
}
Also used : AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) AtlasFieldReader(io.atlasmap.spi.AtlasFieldReader) Test(org.junit.Test)

Example 12 with AtlasInternalSession

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

the class PropertyModuleTest method testProcessSourceFieldMapping.

@Test
public void testProcessSourceFieldMapping() throws AtlasException {
    PropertyField field = mock(PropertyField.class);
    when(field.getValue()).thenReturn("fieldValue");
    Head head = mock(Head.class);
    when(head.getSourceField()).thenReturn(field);
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(head);
    DefaultAtlasConversionService atlasConversionService = mock(DefaultAtlasConversionService.class);
    when(atlasConversionService.fieldTypeFromClass(any(String.class))).thenReturn(FieldType.ANY);
    module.setConversionService(atlasConversionService);
    module.processSourceFieldMapping(session);
}
Also used : PropertyField(io.atlasmap.v2.PropertyField) Head(io.atlasmap.spi.AtlasInternalSession.Head) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) Test(org.junit.Test)

Example 13 with AtlasInternalSession

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

the class XmlFieldReaderTest method testReadDocumentMixedNamespacesNoNSDocument.

@Test
public void testReadDocumentMixedNamespacesNoNSDocument() throws Exception {
    String doc = getDocumentString("src/test/resources/simple_example.xml");
    reader.setDocument(doc, false);
    XmlField xmlField = AtlasXmlModelFactory.createXmlField();
    // there is no namespace on the document but there is this field....
    xmlField.setPath("/ns:orders/order/id");
    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());
    assertThat(xmlField.getValue(), is("12312"));
}
Also used : Head(io.atlasmap.spi.AtlasInternalSession.Head) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) XmlField(io.atlasmap.xml.v2.XmlField) Test(org.junit.Test)

Example 14 with AtlasInternalSession

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

the class XmlFieldReaderTest method testReadDocumentElementWithMultipleNamespaceComplex.

@Test
public void testReadDocumentElementWithMultipleNamespaceComplex() throws Exception {
    String doc = getDocumentString("src/test/resources/complex_example_multiple_ns.xml");
    reader.setDocument(doc, true);
    XmlField xmlField = AtlasXmlModelFactory.createXmlField();
    xmlField.setPath("/orders/q:order/id/@y:custId");
    assertNull(xmlField.getValue());
    Map<String, String> namespaces = new LinkedHashMap<>();
    namespaces.put("http://www.example.com/q/", "q");
    namespaces.put("http://www.example.com/y/", "y");
    namespaces.put("http://www.example.com/x/", "");
    reader.setNamespaces(namespaces);
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    when(session.head().getSourceField()).thenReturn(xmlField);
    reader.read(session);
    assertNotNull(xmlField.getValue());
    assertThat(xmlField.getValue(), is("cx"));
    XmlField xmlField2 = AtlasXmlModelFactory.createXmlField();
    xmlField2.setPath("/orders/order/id/@y:custId");
    assertNull(xmlField2.getValue());
    when(session.head().getSourceField()).thenReturn(xmlField2);
    reader.read(session);
    assertNotNull(xmlField2.getValue());
    assertThat(xmlField2.getValue(), is("aa"));
    XmlField xmlField3 = AtlasXmlModelFactory.createXmlField();
    xmlField3.setPath("/orders/q:order[1]/id/@y:custId");
    assertNull(xmlField3.getValue());
    when(session.head().getSourceField()).thenReturn(xmlField3);
    reader.read(session);
    assertNotNull(xmlField3.getValue());
    assertThat(xmlField3.getValue(), is("ea"));
}
Also used : Head(io.atlasmap.spi.AtlasInternalSession.Head) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) XmlField(io.atlasmap.xml.v2.XmlField) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 15 with AtlasInternalSession

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

the class XmlFieldReaderTest method testReadDocumentSetAttributeValueAsString.

@Test
public void testReadDocumentSetAttributeValueAsString() throws Exception {
    String doc = getDocumentString("src/test/resources/simple_example.xml");
    reader.setDocument(doc, false);
    XmlField xmlField = AtlasXmlModelFactory.createXmlField();
    xmlField.setPath("/orders/order/id/@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());
    assertThat(xmlField.getValue(), is("a"));
}
Also used : Head(io.atlasmap.spi.AtlasInternalSession.Head) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) XmlField(io.atlasmap.xml.v2.XmlField) Test(org.junit.Test)

Aggregations

AtlasInternalSession (io.atlasmap.spi.AtlasInternalSession)57 Test (org.junit.Test)37 Head (io.atlasmap.spi.AtlasInternalSession.Head)34 XmlField (io.atlasmap.xml.v2.XmlField)21 JsonField (io.atlasmap.json.v2.JsonField)11 Path (java.nio.file.Path)11 Audits (io.atlasmap.v2.Audits)4 Field (io.atlasmap.v2.Field)4 FieldType (io.atlasmap.v2.FieldType)3 AtlasFieldReader (io.atlasmap.spi.AtlasFieldReader)2 AtlasFieldWriter (io.atlasmap.spi.AtlasFieldWriter)2 LinkedHashMap (java.util.LinkedHashMap)2 AtlasException (io.atlasmap.api.AtlasException)1 TargetAddress (io.atlasmap.java.test.TargetAddress)1 TargetContact (io.atlasmap.java.test.TargetContact)1 TargetOrder (io.atlasmap.java.test.TargetOrder)1 TargetOrderArray (io.atlasmap.java.test.TargetOrderArray)1 TargetTestClass (io.atlasmap.java.test.TargetTestClass)1 TestListOrders (io.atlasmap.java.test.TestListOrders)1 JavaEnumField (io.atlasmap.java.v2.JavaEnumField)1