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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations