Search in sources :

Example 86 with AtlasInternalSession

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

the class JsonFieldReaderTest method testJsonFieldTopmostArraySimple.

@Test
public void testJsonFieldTopmostArraySimple() throws Exception {
    final String document = "[ 100, 500, 300, 200, 400 ]";
    reader.setDocument(document);
    JsonField field = AtlasJsonModelFactory.createJsonField();
    field.setPath("/<1>");
    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(500, field.getValue());
    field.setFieldType(null);
    field.setPath("/<>");
    Field readField = reader.read(session);
    assertEquals(FieldGroup.class, readField.getClass());
    FieldGroup readFieldGroup = (FieldGroup) readField;
    assertEquals(5, readFieldGroup.getField().size());
    assertEquals(100, readFieldGroup.getField().get(0).getValue());
    assertEquals(500, readFieldGroup.getField().get(1).getValue());
    assertEquals(300, readFieldGroup.getField().get(2).getValue());
    assertEquals(200, readFieldGroup.getField().get(3).getValue());
    assertEquals(400, readFieldGroup.getField().get(4).getValue());
}
Also used : JsonField(io.atlasmap.json.v2.JsonField) Field(io.atlasmap.v2.Field) JsonField(io.atlasmap.json.v2.JsonField) Head(io.atlasmap.spi.AtlasInternalSession.Head) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) FieldGroup(io.atlasmap.v2.FieldGroup) Test(org.junit.jupiter.api.Test)

Example 87 with AtlasInternalSession

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

the class JsonFieldReaderTest method testJsonFieldDoubleMinRangeOut.

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

Example 88 with AtlasInternalSession

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

the class JsonFieldReaderTest method testComplexJsonDocumentHighlyComplexNested.

@Test
public void testComplexJsonDocumentHighlyComplexNested() throws Exception {
    final String document = new String(Files.readAllBytes(Paths.get("src/test/resources/highly-complex-nested-object.json")));
    reader.setDocument(document);
    JsonField field = AtlasJsonModelFactory.createJsonField();
    field.setPath("/items/item[0]/id");
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    when(session.head().getSourceField()).thenReturn(field);
    when(session.getAudits()).thenReturn(new Audits());
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("0001", field.getValue());
    resetField(field);
    field.setPath("/items/item[0]/type");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("donut", field.getValue());
    resetField(field);
    field.setPath("/items/item[0]/name");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("Cake", field.getValue());
    resetField(field);
    field.setPath("/items/item[0]/ppu");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals(0.55, field.getValue());
    resetField(field);
    // array of objects
    field.setPath("/items/item[0]/batters/batter[0]/id");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("1001", field.getValue());
    resetField(field);
    field.setPath("/items/item[0]/batters/batter[0]/type");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("Regular", field.getValue());
    resetField(field);
    field.setPath("/items/item[0]/batters/batter[1]/id");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("1002", field.getValue());
    resetField(field);
    field.setPath("/items/item[0]/batters/batter[1]/type");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("Chocolate", field.getValue());
    resetField(field);
    field.setPath("/items/item[0]/batters/batter[2]/id");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("1003", field.getValue());
    resetField(field);
    field.setPath("/items/item[0]/batters/batter[2]/type");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("Blueberry", field.getValue());
    resetField(field);
    field.setPath("/items/item[0]/batters/batter[3]/id");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("1004", field.getValue());
    resetField(field);
    field.setPath("/items/item[0]/batters/batter[3]/type");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("Devil's Food", field.getValue());
    resetField(field);
    // simple array
    field.setPath("/items/item[0]/topping[0]/id");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("5001", field.getValue());
    resetField(field);
    field.setPath("/items/item[0]/topping[0]/type");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("None", field.getValue());
    resetField(field);
    field.setPath("/items/item[0]/topping[1]/id");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("5002", field.getValue());
    resetField(field);
    field.setPath("/items/item[0]/topping[1]/type");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("Glazed", field.getValue());
    resetField(field);
    field.setPath("/items/item[0]/topping[2]/id");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("5005", field.getValue());
    resetField(field);
    field.setPath("/items/item[0]/topping[2]/type");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("Sugar", field.getValue());
    resetField(field);
    field.setPath("/items/item[0]/topping[3]/id");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("5007", field.getValue());
    resetField(field);
    field.setPath("/items/item[0]/topping[3]/type");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("Powdered Sugar", field.getValue());
    resetField(field);
    field.setPath("/items/item[0]/topping[4]/id");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("5006", field.getValue());
    resetField(field);
    field.setPath("/items/item[0]/topping[4]/type");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("Chocolate with Sprinkles", field.getValue());
    resetField(field);
    field.setPath("/items/item[0]/topping[5]/id");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("5003", field.getValue());
    resetField(field);
    field.setPath("/items/item[0]/topping[5]/type");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("Chocolate", field.getValue());
    resetField(field);
    field.setPath("/items/item[0]/topping[6]/id");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("5004", field.getValue());
    resetField(field);
    field.setPath("/items/item[0]/topping[6]/type");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("Maple", field.getValue());
    resetField(field);
    field.setPath("/items/item[1]/id");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("0002", field.getValue());
    resetField(field);
    field.setPath("/items/item[1]/type");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("donut", field.getValue());
    resetField(field);
    field.setPath("/items/item[1]/name");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("Raised", field.getValue());
    resetField(field);
    field.setPath("/items/item[1]/ppu");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals(0.55, field.getValue());
    resetField(field);
    // array of objects
    field.setPath("/items/item[1]/batters/batter[0]/id");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("1001", field.getValue());
    resetField(field);
    field.setPath("/items/item[1]/batters/batter[0]/type");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("Regular", field.getValue());
    resetField(field);
    field.setPath("/items/item[1]/topping[0]/id");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("5001", field.getValue());
    resetField(field);
    field.setPath("/items/item[1]/topping[0]/type");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("None", field.getValue());
    resetField(field);
    field.setPath("/items/item[1]/topping[1]/id");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("5002", field.getValue());
    resetField(field);
    field.setPath("/items/item[1]/topping[1]/type");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("Glazed", field.getValue());
    resetField(field);
    field.setPath("/items/item[1]/topping[2]/id");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("5005", field.getValue());
    resetField(field);
    field.setPath("/items/item[1]/topping[2]/type");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("Sugar", field.getValue());
    resetField(field);
    field.setPath("/items/item[1]/topping[3]/id");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("5003", field.getValue());
    resetField(field);
    field.setPath("/items/item[1]/topping[3]/type");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("Chocolate", field.getValue());
    resetField(field);
    field.setPath("/items/item[1]/topping[4]/id");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("5004", field.getValue());
    resetField(field);
    field.setPath("/items/item[1]/topping[4]/type");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("Maple", field.getValue());
    resetField(field);
    field.setPath("/items/item[1]/topping[5]/id");
    reader.read(session);
    assertNull(field.getValue());
    resetField(field);
    field.setPath("/items/item[2]/id");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("0003", field.getValue());
    resetField(field);
    field.setPath("/items/item[2]/type");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("donut", field.getValue());
    resetField(field);
    field.setPath("/items/item[2]/name");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("Old Fashioned", field.getValue());
    resetField(field);
    field.setPath("/items/item[2]/ppu");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals(0.55, field.getValue());
    resetField(field);
    field.setPath("/items/item[3]/id");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("0004", field.getValue());
    resetField(field);
    field.setPath("/items/item[3]/type");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("bar", field.getValue());
    resetField(field);
    field.setPath("/items/item[3]/name");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("Bar", field.getValue());
    resetField(field);
    field.setPath("/items/item[3]/ppu");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals(0.75, field.getValue());
    resetField(field);
    field.setPath("/items/item[4]/id");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("0005", field.getValue());
    resetField(field);
    field.setPath("/items/item[4]/type");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("twist", field.getValue());
    resetField(field);
    field.setPath("/items/item[4]/name");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("Twist", field.getValue());
    resetField(field);
    field.setPath("/items/item[4]/ppu");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals(0.65, field.getValue());
    resetField(field);
    field.setPath("/items/item[5]/id");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("0006", field.getValue());
    resetField(field);
    field.setPath("/items/item[5]/type");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("filled", field.getValue());
    resetField(field);
    field.setPath("/items/item[5]/name");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("Filled", field.getValue());
    resetField(field);
    field.setPath("/items/item[5]/ppu");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals(0.75, field.getValue());
    resetField(field);
    field.setPath("/items/item[5]/fillings/filling[2]/id");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals("7004", field.getValue());
    resetField(field);
    field.setPath("/items/item[5]/fillings/filling[3]/addcost");
    reader.read(session);
    assertNotNull(field.getValue());
    assertEquals(new BigInteger("100000000000000000000000000000000000"), field.getValue());
    resetField(field);
}
Also used : JsonField(io.atlasmap.json.v2.JsonField) Head(io.atlasmap.spi.AtlasInternalSession.Head) Audits(io.atlasmap.v2.Audits) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) BigInteger(java.math.BigInteger) Test(org.junit.jupiter.api.Test)

Example 89 with AtlasInternalSession

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

the class JsonFieldReaderTest method testArrayUnderRoot.

@Test
public void testArrayUnderRoot() throws Exception {
    final String document = new String(Files.readAllBytes(Paths.get("src/test/resources/array-under-root.json")));
    reader.setDocument(document);
    JsonField field = AtlasJsonModelFactory.createJsonField();
    field.setPath("/array[0]");
    AtlasInternalSession session = mock(AtlasInternalSession.class);
    when(session.head()).thenReturn(mock(Head.class));
    when(session.head().getSourceField()).thenReturn(field);
    reader.read(session);
    assertEquals("array-zero", field.getValue());
    field.setPath("/array[1]");
    reader.read(session);
    assertEquals("array-one", field.getValue());
    field.setPath("/array[2]");
    reader.read(session);
    assertEquals("array-two", 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 90 with AtlasInternalSession

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

the class JsonFieldReaderTest method testReadParentCollectionEmpty.

@Test
public void testReadParentCollectionEmpty() throws Exception {
    final String document = new String(Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource("complex-repeated-result-empty.json").toURI())));
    reader.setDocument(document);
    FieldGroup address = new FieldGroup();
    address.setFieldType(FieldType.COMPLEX);
    address.setDocId("json");
    address.setPath("/orders[]/address");
    JsonField addressLine1 = AtlasJsonModelFactory.createJsonField();
    addressLine1.setFieldType(FieldType.STRING);
    addressLine1.setDocId("json");
    addressLine1.setPath("/orders[]/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(0, readGroup.getField().size());
}
Also used : JsonField(io.atlasmap.json.v2.JsonField) Field(io.atlasmap.v2.Field) JsonField(io.atlasmap.json.v2.JsonField) Head(io.atlasmap.spi.AtlasInternalSession.Head) AtlasInternalSession(io.atlasmap.spi.AtlasInternalSession) FieldGroup(io.atlasmap.v2.FieldGroup) 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