use of org.apache.beam.sdk.schemas.utils.TestJavaBeans.NestedArrayBean in project beam by apache.
the class JavaBeanSchemaTest method testRecursiveArrayGetters.
@Test
public void testRecursiveArrayGetters() throws NoSuchSchemaException {
SchemaRegistry registry = SchemaRegistry.createDefault();
SchemaTestUtils.assertSchemaEquivalent(NESTED_ARRAY_BEAN_SCHEMA, registry.getSchema(NestedArrayBean.class));
SimpleBean simple1 = createSimple("string1");
SimpleBean simple2 = createSimple("string2");
SimpleBean simple3 = createSimple("string3");
NestedArrayBean bean = new NestedArrayBean(simple1, simple2, simple3);
Row row = registry.getToRowFunction(NestedArrayBean.class).apply(bean);
List<Row> rows = (List) row.getArray("beans");
assertSame(simple1, registry.getFromRowFunction(SimpleBean.class).apply(rows.get(0)));
assertSame(simple2, registry.getFromRowFunction(SimpleBean.class).apply(rows.get(1)));
assertSame(simple3, registry.getFromRowFunction(SimpleBean.class).apply(rows.get(2)));
}
use of org.apache.beam.sdk.schemas.utils.TestJavaBeans.NestedArrayBean in project beam by apache.
the class JavaBeanSchemaTest 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_BEAN_SCHEMA).addArray(row1, row2, row3).build();
NestedArrayBean bean = registry.getFromRowFunction(NestedArrayBean.class).apply(row);
assertEquals(3, bean.getBeans().length);
assertEquals("string1", bean.getBeans()[0].getStr());
assertEquals("string2", bean.getBeans()[1].getStr());
assertEquals("string3", bean.getBeans()[2].getStr());
}
Aggregations