Search in sources :

Example 81 with AtlasInternalSession

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

the class JsonFieldReaderTest method read.

private AtlasInternalSession read(JsonField field) throws AtlasException {
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    when(session.head().getSourceField()).thenReturn(field);
    Audits audits = new Audits();
    when(session.getAudits()).thenReturn(audits);
    reader.read(session);
    return session;
}
Also used : Head(io.atlasmap.spi.AtlasInternalSession.Head) Audits(io.atlasmap.v2.Audits) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession)

Example 82 with AtlasInternalSession

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

the class JsonFieldReaderTest method testJsonFieldFloatMinRangOut.

@Test
public void testJsonFieldFloatMinRangOut() throws Exception {
    AtlasInternalSession session = testBoundaryValue("field-float-min-range-out.json", "/floatValue", FieldType.FLOAT, 0.0f);
    assertEquals(0, session.getAudits().getAudit().size());
}
Also used : AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) Test(org.junit.jupiter.api.Test)

Example 83 with AtlasInternalSession

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

the class JsonFieldReaderTest method testRangeOutValue.

private void testRangeOutValue(String fileName, String fieldPath, FieldType fieldType, String errorMessage, String errorValue) throws Exception {
    String filePath = "src" + File.separator + "test" + File.separator + "resources" + File.separator + "jsonFields" + File.separator + fileName;
    String document = new String(Files.readAllBytes(Paths.get(filePath)));
    reader.setDocument(document);
    JsonField field = AtlasJsonModelFactory.createJsonField();
    field.setPath(fieldPath);
    field.setFieldType(fieldType);
    AtlasInternalSession session = read(field);
    assertEquals(null, field.getValue());
    assertEquals(1, session.getAudits().getAudit().size());
    assertEquals(errorMessage, session.getAudits().getAudit().get(0).getMessage());
    assertEquals(errorValue, session.getAudits().getAudit().get(0).getValue());
    assertEquals(AuditStatus.ERROR, session.getAudits().getAudit().get(0).getStatus());
}
Also used : JsonField(io.atlasmap.json.v2.JsonField) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession)

Example 84 with AtlasInternalSession

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

the class JsonFieldReaderTest method testSameFieldNameInDifferentPath.

@Test
public void testSameFieldNameInDifferentPath() throws Exception {
    final String document = new String(Files.readAllBytes(Paths.get("src/test/resources/same-field-name-in-different-path.json")));
    reader.setDocument(document);
    JsonField field = AtlasJsonModelFactory.createJsonField();
    field.setPath("/name");
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    when(session.head().getSourceField()).thenReturn(field);
    reader.read(session);
    assertEquals("name", field.getValue());
    field.setPath("/object1/name");
    reader.read(session);
    assertEquals("object1-name", field.getValue());
    field.setPath("/object2/name");
    reader.read(session);
    assertEquals("object2-name", field.getValue());
    field.setPath("/object1/object2/name");
    reader.read(session);
    assertEquals("object1-object2-name", field.getValue());
}
Also used : JsonField(io.atlasmap.json.v2.JsonField) Head(io.atlasmap.spi.AtlasInternalSession.Head) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) Test(org.junit.jupiter.api.Test)

Example 85 with AtlasInternalSession

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

the class JsonFieldReaderTest method testComplexJsonDocumentNestedObjectArray.

@Test
public void testComplexJsonDocumentNestedObjectArray() throws Exception {
    final String document = "{\"menu\": {\n" + "  \"id\": \"file\",\n" + "  \"value\": \"Filed\",\n" + "  \"popup\": {\n" + "    \"menuitem\": [\n" + "      {\"value\": \"New\", \"onclick\": \"CreateNewDoc()\"},\n" + "      {\"value\": \"Open\", \"onclick\": \"OpenDoc()\"},\n" + "      {\"value\": \"Close\", \"onclick\": \"CloseDoc()\"}\n" + "    ]\n" + "  }\n" + "}}";
    reader.setDocument(document);
    JsonField field = AtlasJsonModelFactory.createJsonField();
    field.setPath("/menu/id");
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    when(session.head().getSourceField()).thenReturn(field);
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("file", field.getValue());
    field.setPath("/menu/value");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("Filed", field.getValue());
    field.setPath("/menu/popup/menuitem[0]/value");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("New", field.getValue());
    field.setPath("/menu/popup/menuitem[0]/onclick");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("CreateNewDoc()", field.getValue());
    field.setPath("/menu/popup/menuitem[1]/value");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("Open", field.getValue());
    field.setPath("/menu/popup/menuitem[1]/onclick");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("OpenDoc()", field.getValue());
    field.setPath("/menu/popup/menuitem[2]/value");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("Close", field.getValue());
    field.setPath("/menu/popup/menuitem[2]/onclick");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("CloseDoc()", field.getValue());
}
Also used : JsonField(io.atlasmap.json.v2.JsonField) Head(io.atlasmap.spi.AtlasInternalSession.Head) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) 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