Search in sources :

Example 21 with AtlasInternalSession

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

the class XmlFieldReaderTest method testReadDocumentSetElementValueAsString.

@Test
public void testReadDocumentSetElementValueAsString() throws Exception {
    String doc = getDocumentString("src/test/resources/simple_example.xml");
    reader.setDocument(doc, false);
    XmlField xmlField = AtlasXmlModelFactory.createXmlField();
    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 22 with AtlasInternalSession

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

the class JsonFieldWriterTest method write.

private void write(Field field) throws Exception {
    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) JsonField(io.atlasmap.json.v2.JsonField) Head(io.atlasmap.spi.AtlasInternalSession.Head) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession)

Example 23 with AtlasInternalSession

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

the class JsonFieldWriterTest method testMinRangeOutValue.

private void testMinRangeOutValue(String fileName, String fieldPath, Object testObject, FieldType inputFieldType, FieldType outputFieldType, Object expectedValue) throws Exception, IOException, JsonGenerationException, JsonMappingException, AtlasException {
    Path path = Paths.get("target" + File.separator + fileName);
    write(path, fieldPath, testObject, inputFieldType);
    AtlasInternalSession session = read(path, outputFieldType, fieldPath);
    assertEquals(expectedValue, session.head().getSourceField().getValue());
    assertEquals(0, session.getAudits().getAudit().size());
}
Also used : Path(java.nio.file.Path) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession)

Example 24 with AtlasInternalSession

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

the class JsonFieldWriterTest method testRangeOutValue.

private void testRangeOutValue(String fileName, String fieldPath, Object testObject, FieldType inputFieldType, FieldType outputFieldType) throws Exception {
    Path path = Paths.get("target" + File.separator + fileName);
    write(path, fieldPath, testObject, inputFieldType);
    AtlasInternalSession session = read(path, outputFieldType, fieldPath);
    assertEquals(null, session.head().getSourceField().getValue());
    assertEquals(1, session.getAudits().getAudit().size());
    assertEquals("Failed to convert field value '" + testObject.toString() + "' into type '" + outputFieldType.value().toUpperCase() + "'", session.getAudits().getAudit().get(0).getMessage());
    assertEquals(testObject.toString(), 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 25 with AtlasInternalSession

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

the class JsonFieldReaderTest method testSimpleJsonDocumentWithRoot.

@Test
public void testSimpleJsonDocumentWithRoot() throws Exception {
    final String document = " {\"car\" :{ \"brand\" : \"Mercedes\", \"doors\" : 5 } }";
    reader.setDocument(document);
    JsonField field = AtlasJsonModelFactory.createJsonField();
    field.setPath("/car/doors");
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    when(session.head().getSourceField()).thenReturn(field);
    reader.read(session);
    assertNotNull(field.getValue());
    assertThat(field.getValue(), Is.is(5));
    resetField(field);
    field.setPath("/car/brand");
    reader.read(session);
    assertNotNull(field.getValue());
    assertThat(field.getValue(), Is.is("Mercedes"));
}
Also used : JsonField(io.atlasmap.json.v2.JsonField) Head(io.atlasmap.spi.AtlasInternalSession.Head) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) 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