use of org.apache.beam.sdk.schemas.utils.TestPOJOs.NestedArrayPOJO in project beam by apache.
the class JavaFieldSchemaTest method testRecursiveArraySetters.
@Test
public void testRecursiveArraySetters() throws NoSuchSchemaException {
SchemaRegistry registry = SchemaRegistry.createDefault();
Row row1 = createSimpleRow("string1");
Row row2 = createSimpleRow("string2");
Row row3 = createSimpleRow("string3");
;
Row row = Row.withSchema(NESTED_ARRAY_POJO_SCHEMA).addArray(row1, row2, row3).build();
NestedArrayPOJO pojo = registry.getFromRowFunction(NestedArrayPOJO.class).apply(row);
assertEquals(3, pojo.pojos.length);
assertEquals("string1", pojo.pojos[0].str);
assertEquals("string2", pojo.pojos[1].str);
assertEquals("string3", pojo.pojos[2].str);
}
use of org.apache.beam.sdk.schemas.utils.TestPOJOs.NestedArrayPOJO in project beam by apache.
the class JavaFieldSchemaTest method testRecursiveArrayGetters.
@Test
public void testRecursiveArrayGetters() throws NoSuchSchemaException {
SchemaRegistry registry = SchemaRegistry.createDefault();
SchemaTestUtils.assertSchemaEquivalent(NESTED_ARRAY_POJO_SCHEMA, registry.getSchema(NestedArrayPOJO.class));
SimplePOJO simple1 = createSimple("string1");
SimplePOJO simple2 = createSimple("string2");
SimplePOJO simple3 = createSimple("string3");
NestedArrayPOJO pojo = new NestedArrayPOJO(simple1, simple2, simple3);
Row row = registry.getToRowFunction(NestedArrayPOJO.class).apply(pojo);
List<Row> rows = (List) row.getArray("pojos");
assertSame(simple1, registry.getFromRowFunction(SimplePOJO.class).apply(rows.get(0)));
assertSame(simple2, registry.getFromRowFunction(SimplePOJO.class).apply(rows.get(1)));
assertSame(simple3, registry.getFromRowFunction(SimplePOJO.class).apply(rows.get(2)));
}
Aggregations