Search in sources :

Example 61 with AtlasInternalSession

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

the class XmlFieldReaderTest method testNullDocument.

@Test
public void testNullDocument() throws Exception {
    reader.setDocument(null);
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    when(session.head().getSourceField()).thenReturn(new XmlField());
    Audits audits = new Audits();
    when(session.getAudits()).thenReturn(audits);
    reader.read(session);
    assertEquals(1, audits.getAudit().size());
    assertEquals(AuditStatus.ERROR, audits.getAudit().get(0).getStatus());
}
Also used : Head(io.atlasmap.spi.AtlasInternalSession.Head) Audits(io.atlasmap.v2.Audits) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) XmlField(io.atlasmap.xml.v2.XmlField) Test(org.junit.jupiter.api.Test)

Example 62 with AtlasInternalSession

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

the class XmlFieldReaderTest method testReadDocumentSetValueFromAttrAsString.

@Test
public void testReadDocumentSetValueFromAttrAsString() throws Exception {
    Document doc = getDocumentFromFile("src/test/resources/simple_example.xml", false);
    reader.setDocument(doc);
    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());
    assertEquals("12525.00", 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 63 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.jupiter.api.Test)

Example 64 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.jupiter.api.Test)

Example 65 with AtlasInternalSession

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

the class XmlFieldReaderTest method testReadParentCollectionEmptyItem.

@Test
public void testReadParentCollectionEmptyItem() throws Exception {
    final Document document = getDocumentFromFile("src/test/resources/complex-repeated-empty-item.xml", false);
    reader.setDocument(document);
    FieldGroup orders = new FieldGroup();
    orders.setFieldType(FieldType.COMPLEX);
    orders.setDocId("xml");
    orders.setPath("/orders/order[]");
    orders.setCollectionType(CollectionType.ARRAY);
    FieldGroup address = new FieldGroup();
    address.setFieldType(FieldType.COMPLEX);
    address.setDocId("xml");
    address.setPath("/orders/order[]/address");
    orders.getField().add(address);
    XmlField addressLine1 = AtlasXmlModelFactory.createXmlField();
    addressLine1.setFieldType(FieldType.STRING);
    addressLine1.setDocId("xml");
    addressLine1.setPath("/orders/order[]/address/addressLine1");
    address.getField().add(addressLine1);
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    when(session.head().getSourceField()).thenReturn(address);
    Field readField = reader.read(session);
    assertNotNull(readField);
    assertEquals(FieldGroup.class, readField.getClass());
    FieldGroup readGroup = FieldGroup.class.cast(readField);
    assertEquals(2, readGroup.getField().size());
    FieldGroup address0 = (FieldGroup) readGroup.getField().get(0);
    assertEquals("/orders/order[0]/address", address0.getPath());
    assertEquals(1, address0.getField().size());
    Field addressLine0 = (Field) address0.getField().get(0);
    assertEquals("/orders/order[0]/address/addressLine1", addressLine0.getPath());
    assertEquals("123 Main St (1)", addressLine0.getValue());
    FieldGroup address2 = (FieldGroup) readGroup.getField().get(1);
    assertEquals("/orders/order[2]/address", address2.getPath());
    assertEquals(1, address2.getField().size());
    Field addressLine2 = (Field) address2.getField().get(0);
    assertEquals("/orders/order[2]/address/addressLine1", addressLine2.getPath());
    assertEquals("123 Main St (3)", addressLine2.getValue());
}
Also used : Field(io.atlasmap.v2.Field) XmlField(io.atlasmap.xml.v2.XmlField) Head(io.atlasmap.spi.AtlasInternalSession.Head) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) FieldGroup(io.atlasmap.v2.FieldGroup) 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