Search in sources :

Example 1 with AtlasInternalSession

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

the class JsonFieldWriterTest method testMinRangeOutValue.

private void testMinRangeOutValue(String fileName, String fieldPath, Object testObject, FieldType inputFieldType, FieldType outputFieldType, Object expectedValue) throws Exception, IOException, JsonGenerationException, JsonMappingException, AtlasException {
    Path path = Paths.get("target" + File.separator + fileName);
    write(path, fieldPath, testObject, inputFieldType);
    AtlasInternalSession session = read(path, outputFieldType, fieldPath);
    assertEquals(expectedValue, session.head().getSourceField().getValue());
    assertEquals(0, session.getAudits().getAudit().size());
}
Also used : Path(java.nio.file.Path) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession)

Example 2 with AtlasInternalSession

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

the class XmlFieldReaderTest method testReadDocumentElementWithMultipleNamespaceComplexConstructorArg.

@Test
public void testReadDocumentElementWithMultipleNamespaceComplexConstructorArg() throws Exception {
    Document doc = getDocumentFromFile("src/test/resources/complex_example_multiple_ns.xml", true);
    reader.setDocument(doc);
    XmlField xmlField = AtlasXmlModelFactory.createXmlField();
    xmlField.setPath("/orders/q:order/id/@y:custId");
    String docId = "docId";
    xmlField.setDocId(docId);
    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/", "");
    XmlFieldReader multipleNamespacesReader = new XmlFieldReader(XmlFieldReader.class.getClassLoader(), DefaultAtlasConversionService.getInstance(), namespaces);
    multipleNamespacesReader.setDocument(doc);
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    mockDataSources(docId, session);
    when(session.head()).thenReturn(mock(Head.class));
    when(session.head().getSourceField()).thenReturn(xmlField);
    multipleNamespacesReader.read(session);
    assertNotNull(xmlField.getValue());
    assertEquals("cx", xmlField.getValue());
    XmlField xmlField2 = AtlasXmlModelFactory.createXmlField();
    xmlField2.setPath("/orders/order/id/@y:custId");
    assertNull(xmlField2.getValue());
    when(session.head().getSourceField()).thenReturn(xmlField2);
    multipleNamespacesReader.read(session);
    assertNotNull(xmlField2.getValue());
    assertEquals("aa", xmlField2.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) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.jupiter.api.Test)

Example 3 with AtlasInternalSession

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

the class XmlFieldReaderTest method testReadDocumentWithMultipleNamespaceSetElementValueAsString.

@Test
public void testReadDocumentWithMultipleNamespaceSetElementValueAsString() throws Exception {
    Document doc = getDocumentFromFile("src/test/resources/simple_example_multiple_ns.xml", true);
    reader.setDocument(doc);
    XmlField xmlField = AtlasXmlModelFactory.createXmlField();
    xmlField.setPath("/x:orders/order/y: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());
    assertEquals("a", 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 4 with AtlasInternalSession

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

the class XmlFieldReaderTest method testReadDocumentSetAttributeValueAsString.

@Test
public void testReadDocumentSetAttributeValueAsString() throws Exception {
    Document doc = getDocumentFromFile("src/test/resources/simple_example.xml", false);
    reader.setDocument(doc);
    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());
    assertEquals("a", 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 5 with AtlasInternalSession

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

the class XmlFieldReaderTest method testReadDocumentMixedNamespacesNoNSOnPaths.

@Test
public void testReadDocumentMixedNamespacesNoNSOnPaths() throws Exception {
    Document doc = getDocumentFromFile("src/test/resources/simple_example_single_ns.xml", true);
    reader.setDocument(doc);
    XmlField xmlField = AtlasXmlModelFactory.createXmlField();
    // there is a namespace on the document but there is not on the paths....
    xmlField.setPath("/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());
    assertEquals("12312", 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)

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