Search in sources :

Example 16 with AtlasInternalSession

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

the class XmlFieldReaderTest method validateBoundaryValue.

private void validateBoundaryValue(FieldType fieldType, String fileName, Object testObject) throws Exception {
    Path path = Paths.get("src" + File.separator + "test" + File.separator + "resources" + File.separator + "xmlFields" + File.separator + fileName);
    AtlasInternalSession session = readFromFile("/primitive/value", fieldType, path);
    assertNotNull(session.head().getSourceField().getValue());
    assertEquals(testObject, session.head().getSourceField().getValue());
}
Also used : Path(java.nio.file.Path) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession)

Example 17 with AtlasInternalSession

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

the class XmlFieldReaderTest method testReadDocumentMixedNamespacesNoNSOnPaths.

@Test
public void testReadDocumentMixedNamespacesNoNSOnPaths() throws Exception {
    String doc = getDocumentString("src/test/resources/simple_example_single_ns.xml");
    reader.setDocument(doc, true);
    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());
    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 18 with AtlasInternalSession

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

the class XmlFieldReaderTest method readFromFile.

private AtlasInternalSession readFromFile(String fieldPath, FieldType fieldType, Path path) throws Exception {
    String input = new String(Files.readAllBytes(path));
    reader.setDocument(input, false);
    XmlField xmlField = AtlasXmlModelFactory.createXmlField();
    xmlField.setPath(fieldPath);
    xmlField.setPrimitive(Boolean.TRUE);
    xmlField.setFieldType(fieldType);
    assertNull(xmlField.getValue());
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    when(session.head().getSourceField()).thenReturn(xmlField);
    Audits audits = new Audits();
    when(session.getAudits()).thenReturn(audits);
    reader.read(session);
    return session;
}
Also used : Head(io.atlasmap.spi.AtlasInternalSession.Head) Audits(io.atlasmap.v2.Audits) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) XmlField(io.atlasmap.xml.v2.XmlField)

Example 19 with AtlasInternalSession

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

the class XmlFieldReaderTest method validateRangeOutValue.

private void validateRangeOutValue(FieldType fieldType, String fileName, String inputValue) throws Exception {
    Path path = Paths.get("src" + File.separator + "test" + File.separator + "resources" + File.separator + "xmlFields" + File.separator + fileName);
    AtlasInternalSession session = readFromFile("/primitive/value", fieldType, path);
    assertEquals(null, session.head().getSourceField().getValue());
    assertEquals(1, session.getAudits().getAudit().size());
    assertEquals("Failed to convert field value '" + inputValue + "' into type '" + fieldType.value().toUpperCase() + "'", session.getAudits().getAudit().get(0).getMessage());
    assertEquals(inputValue, session.getAudits().getAudit().get(0).getValue());
    assertEquals(AuditStatus.ERROR, session.getAudits().getAudit().get(0).getStatus());
}
Also used : Path(java.nio.file.Path) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession)

Example 20 with AtlasInternalSession

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

the class XmlFieldReaderTest method testReadDocumentWithMultipleNamespaceSetElementValueAsString.

@Test
public void testReadDocumentWithMultipleNamespaceSetElementValueAsString() throws Exception {
    String doc = getDocumentString("src/test/resources/simple_example_multiple_ns.xml");
    reader.setDocument(doc, true);
    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());
    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