use of org.apache.beam.sdk.schemas.utils.TestJavaBeans.NestedMapBean in project beam by apache.
the class JavaBeanSchemaTest method testMapFieldGetters.
@Test
public void testMapFieldGetters() throws NoSuchSchemaException {
SchemaRegistry registry = SchemaRegistry.createDefault();
SchemaTestUtils.assertSchemaEquivalent(NESTED_MAP_BEAN_SCHEMA, registry.getSchema(NestedMapBean.class));
SimpleBean simple1 = createSimple("string1");
SimpleBean simple2 = createSimple("string2");
SimpleBean simple3 = createSimple("string3");
NestedMapBean bean = new NestedMapBean(ImmutableMap.of("simple1", simple1, "simple2", simple2, "simple3", simple3));
Row row = registry.getToRowFunction(NestedMapBean.class).apply(bean);
Map<String, Row> extractedMap = row.getMap("map");
assertEquals(3, extractedMap.size());
assertEquals("string1", extractedMap.get("simple1").getString("str"));
assertEquals("string2", extractedMap.get("simple2").getString("str"));
assertEquals("string3", extractedMap.get("simple3").getString("str"));
}
use of org.apache.beam.sdk.schemas.utils.TestJavaBeans.NestedMapBean in project beam by apache.
the class JavaBeanSchemaTest method testMapFieldSetters.
@Test
public void testMapFieldSetters() throws NoSuchSchemaException {
SchemaRegistry registry = SchemaRegistry.createDefault();
Row row1 = createSimpleRow("string1");
Row row2 = createSimpleRow("string2");
Row row3 = createSimpleRow("string3");
Row row = Row.withSchema(NESTED_MAP_BEAN_SCHEMA).addValue(ImmutableMap.of("simple1", row1, "simple2", row2, "simple3", row3)).build();
NestedMapBean bean = registry.getFromRowFunction(NestedMapBean.class).apply(row);
assertEquals(3, bean.getMap().size());
assertEquals("string1", bean.getMap().get("simple1").getStr());
assertEquals("string2", bean.getMap().get("simple2").getStr());
assertEquals("string3", bean.getMap().get("simple3").getStr());
}
Aggregations