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