Search in sources :

Example 36 with AtlasInternalSession

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

the class DefaultAtlasSessionTest method testSetFieldReader.

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

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

Example 37 with AtlasInternalSession

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

the class XmlFieldReaderTest method testXmlFieldDoubleMinRangeOut.

@Test
public void testXmlFieldDoubleMinRangeOut() throws Exception {
    String fieldPath = "/primitive/value";
    FieldType fieldType = FieldType.DOUBLE;
    Path path = Paths.get("src" + File.separator + "test" + File.separator + "resources" + File.separator + "xmlFields" + File.separator + "test-read-field-double-min-range-out.xml");
    AtlasInternalSession session = readFromFile(fieldPath, fieldType, path);
    assertEquals(0.0, session.head().getSourceField().getValue());
    assertEquals(0, session.getAudits().getAudit().size());
}
Also used : Path(java.nio.file.Path) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) FieldType(io.atlasmap.v2.FieldType) Test(org.junit.Test)

Example 38 with AtlasInternalSession

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

the class XmlFieldReaderTest method testReadDocumentMultipleFieldsSetElementValuesComplex.

@Test
public void testReadDocumentMultipleFieldsSetElementValuesComplex() throws Exception {
    String doc = getDocumentString("src/test/resources/complex_example.xml");
    reader.setDocument(doc, false);
    LinkedList<XmlField> fieldList = new LinkedList<>();
    XmlField xmlField = AtlasXmlModelFactory.createXmlField();
    xmlField.setPath("/orders/order[3]/id[1]");
    fieldList.addLast(xmlField);
    XmlField xmlField2 = AtlasXmlModelFactory.createXmlField();
    xmlField2.setPath("/orders/order[1]/id");
    fieldList.addLast(xmlField2);
    XmlField xmlField3 = AtlasXmlModelFactory.createXmlField();
    xmlField3.setPath("/orders/order[2]/id[2]");
    fieldList.addLast(xmlField3);
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    for (XmlField field : fieldList) {
        assertNull(field.getValue());
        when(session.head().getSourceField()).thenReturn(field);
        reader.read(session);
        assertNotNull(field.getValue());
    }
    assertThat(fieldList.getFirst().getValue(), is("54554555"));
    assertThat(fieldList.get(1).getValue(), is("12312"));
    assertThat(fieldList.getLast().getValue(), is("54554555"));
}
Also used : Head(io.atlasmap.spi.AtlasInternalSession.Head) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) XmlField(io.atlasmap.xml.v2.XmlField) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 39 with AtlasInternalSession

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

the class XmlFieldReaderTest method testThrowExceptionOnNullXmlField.

@Test(expected = AtlasException.class)
public void testThrowExceptionOnNullXmlField() throws Exception {
    String doc = getDocumentString("src/test/resources/complex_example.xml");
    reader.setDocument(doc, false);
    XmlField xmlField = null;
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    when(session.head().getSourceField()).thenReturn(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)

Example 40 with AtlasInternalSession

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

the class XmlFieldReaderTest method testXmlFieldFloatMinRangeOut.

@Test
public void testXmlFieldFloatMinRangeOut() throws Exception {
    String fieldPath = "/primitive/value";
    FieldType fieldType = FieldType.FLOAT;
    Path path = Paths.get("src" + File.separator + "test" + File.separator + "resources" + File.separator + "xmlFields" + File.separator + "test-read-field-float-min-range-out.xml");
    AtlasInternalSession session = readFromFile(fieldPath, fieldType, path);
    assertEquals(0.0f, session.head().getSourceField().getValue());
    assertEquals(0, session.getAudits().getAudit().size());
}
Also used : Path(java.nio.file.Path) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) FieldType(io.atlasmap.v2.FieldType) 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