Search in sources :

Example 76 with AtlasInternalSession

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

the class KafkaConnectFieldReaderTest method testWithNullDocument.

@Test
public void testWithNullDocument() throws Exception {
    reader.setDocument(null);
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    when(session.head().getSourceField()).thenReturn(AtlasKafkaConnectModelFactory.createKafkaConnectField());
    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) Test(org.junit.jupiter.api.Test)

Example 77 with AtlasInternalSession

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

the class ConstantModuleTest method testProcessSourceFieldMapping.

@Test
public void testProcessSourceFieldMapping() throws AtlasException {
    ConstantField field = mock(ConstantField.class);
    when(field.getValue()).thenReturn("fieldValue");
    Head head = mock(Head.class);
    when(head.getSourceField()).thenReturn(field);
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(head);
    DefaultAtlasConversionService atlasConversionService = mock(DefaultAtlasConversionService.class);
    when(atlasConversionService.fieldTypeFromClass(any(String.class))).thenReturn(FieldType.ANY);
    module.setConversionService(atlasConversionService);
    module.readSourceValue(session);
}
Also used : Head(io.atlasmap.spi.AtlasInternalSession.Head) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) ConstantField(io.atlasmap.v2.ConstantField) Test(org.junit.jupiter.api.Test)

Example 78 with AtlasInternalSession

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

the class JsonFieldWriterTest method testValue.

private void testValue(String fileName, String fieldPath, Object testObject, FieldType inputFieldType, FieldType outputFieldType, Object expectedValue) throws Exception {
    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 79 with AtlasInternalSession

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

the class JsonFieldWriterTest method testJsonFieldBooleanString.

@Test
public void testJsonFieldBooleanString() throws Exception {
    Path path = Paths.get("target" + File.separator + "test-write-field-byte-string.json");
    String fieldPath = "/primitiveValue";
    Object testObject = "abcd";
    FieldType inputFieldType = FieldType.STRING;
    FieldType outputFieldType = FieldType.BOOLEAN;
    write(path, fieldPath, testObject, inputFieldType);
    AtlasInternalSession session = read(path, outputFieldType, fieldPath);
    assertEquals(false, session.head().getSourceField().getValue());
}
Also used : Path(java.nio.file.Path) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) FieldType(io.atlasmap.v2.FieldType) Test(org.junit.jupiter.api.Test)

Example 80 with AtlasInternalSession

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

the class JsonFieldWriterTest method read.

private AtlasInternalSession read(Path path, FieldType outputFieldType, String fieldPath) throws IOException, AtlasException {
    String document = new String(Files.readAllBytes(path));
    reader.setDocument(document);
    JsonField jsonField = AtlasJsonModelFactory.createJsonField();
    jsonField.setPath(fieldPath);
    jsonField.setFieldType(outputFieldType);
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    when(session.head().getSourceField()).thenReturn(jsonField);
    Audits audits = new Audits();
    when(session.getAudits()).thenReturn(audits);
    reader.read(session);
    return session;
}
Also used : JsonField(io.atlasmap.json.v2.JsonField) Head(io.atlasmap.spi.AtlasInternalSession.Head) Audits(io.atlasmap.v2.Audits) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession)

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