Search in sources :

Example 41 with AtlasInternalSession

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

the class XmlFieldReaderTest method testReadDocumentSetValueFromAttrAsString.

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

Example 42 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 43 with AtlasInternalSession

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

the class XmlFieldWriterTest method testThrowExceptionOnNullXmlField.

@Test(expected = AtlasException.class)
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);
    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.Test)

Example 44 with AtlasInternalSession

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

the class XmlFieldReaderTest method testReadDocumentMisMatchedFieldNameAT416.

@Test
public void testReadDocumentMisMatchedFieldNameAT416() throws Exception {
    String doc = getDocumentString("src/test/resources/simple_example.xml");
    reader.setDocument(doc, false);
    XmlField xmlField = AtlasXmlModelFactory.createXmlField();
    // correct field name should be id or id[1]
    xmlField.setPath("/orders/order/id1");
    assertNull(xmlField.getValue());
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    when(session.head().getSourceField()).thenReturn(xmlField);
    reader.read(session);
    assertNull(xmlField.getValue());
}
Also used : Head(io.atlasmap.spi.AtlasInternalSession.Head) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) XmlField(io.atlasmap.xml.v2.XmlField) Test(org.junit.Test)

Example 45 with AtlasInternalSession

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

the class XmlFieldReaderTest method testThrowExceptionOnNullDocument.

@Test(expected = AtlasException.class)
public void testThrowExceptionOnNullDocument() throws Exception {
    reader.setDocument(null, false);
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    when(session.head().getSourceField()).thenReturn(new XmlField());
    reader.read(session);
}
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