use of org.apache.beam.sdk.schemas.utils.TestPOJOs.SimplePOJO in project beam by apache.
the class JavaFieldSchemaTest method testFromRow.
@Test
public void testFromRow() throws NoSuchSchemaException {
SchemaRegistry registry = SchemaRegistry.createDefault();
Row row = createSimpleRow("string");
SimplePOJO pojo = registry.getFromRowFunction(SimplePOJO.class).apply(row);
assertEquals("string", pojo.str);
assertEquals((byte) 1, pojo.aByte);
assertEquals((short) 2, pojo.aShort);
assertEquals((int) 3, pojo.anInt);
assertEquals((long) 4, pojo.aLong);
assertTrue(pojo.aBoolean);
assertEquals(DATE, pojo.dateTime);
assertEquals(INSTANT, pojo.instant);
assertArrayEquals("not equal", BYTE_ARRAY, pojo.bytes);
assertEquals(BYTE_BUFFER, pojo.byteBuffer);
assertEquals(BigDecimal.ONE, pojo.bigDecimal);
assertEquals("stringbuilder", pojo.stringBuilder.toString());
}
use of org.apache.beam.sdk.schemas.utils.TestPOJOs.SimplePOJO in project beam by apache.
the class JavaFieldSchemaTest method testNestedArraysFromRow.
@Test
public void testNestedArraysFromRow() throws NoSuchSchemaException {
SchemaRegistry registry = SchemaRegistry.createDefault();
Schema schema = registry.getSchema(PojoWithNestedArray.class);
SchemaTestUtils.assertSchemaEquivalent(POJO_WITH_NESTED_ARRAY_SCHEMA, schema);
Row simpleRow = createSimpleRow("string");
List<Row> list = ImmutableList.of(simpleRow, simpleRow);
List<List<Row>> listOfList = ImmutableList.of(list, list);
Row nestedRow = Row.withSchema(POJO_WITH_NESTED_ARRAY_SCHEMA).addValue(listOfList).build();
SimplePOJO simplePojo = createSimple("string");
List<SimplePOJO> simplePojoList = ImmutableList.of(simplePojo, simplePojo);
List<List<SimplePOJO>> simplePojoListOfList = ImmutableList.of(simplePojoList, simplePojoList);
PojoWithNestedArray converted = registry.getFromRowFunction(PojoWithNestedArray.class).apply(nestedRow);
assertEquals(simplePojoListOfList, converted.pojos);
}
use of org.apache.beam.sdk.schemas.utils.TestPOJOs.SimplePOJO in project beam by apache.
the class JavaFieldSchemaTest method testMapFieldGetters.
@Test
public void testMapFieldGetters() throws NoSuchSchemaException {
SchemaRegistry registry = SchemaRegistry.createDefault();
SchemaTestUtils.assertSchemaEquivalent(NESTED_MAP_POJO_SCHEMA, registry.getSchema(NestedMapPOJO.class));
SimplePOJO simple1 = createSimple("string1");
SimplePOJO simple2 = createSimple("string2");
SimplePOJO simple3 = createSimple("string3");
NestedMapPOJO pojo = new NestedMapPOJO(ImmutableMap.of("simple1", simple1, "simple2", simple2, "simple3", simple3));
Row row = registry.getToRowFunction(NestedMapPOJO.class).apply(pojo);
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.TestPOJOs.SimplePOJO in project beam by apache.
the class POJOUtilsTest method testGeneratedSimpleGetters.
@Test
public void testGeneratedSimpleGetters() {
SimplePOJO simplePojo = new SimplePOJO("field1", (byte) 41, (short) 42, 43, 44L, true, DATE, INSTANT, BYTE_ARRAY, BYTE_BUFFER, new BigDecimal(42), new StringBuilder("stringBuilder"));
List<FieldValueGetter> getters = POJOUtils.getGetters(SimplePOJO.class, SIMPLE_POJO_SCHEMA, JavaFieldTypeSupplier.INSTANCE, new DefaultTypeConversionsFactory());
assertEquals(12, getters.size());
assertEquals("str", getters.get(0).name());
assertEquals("field1", getters.get(0).get(simplePojo));
assertEquals((byte) 41, getters.get(1).get(simplePojo));
assertEquals((short) 42, getters.get(2).get(simplePojo));
assertEquals((int) 43, getters.get(3).get(simplePojo));
assertEquals((long) 44, getters.get(4).get(simplePojo));
assertTrue((Boolean) getters.get(5).get(simplePojo));
assertEquals(DATE.toInstant(), getters.get(6).get(simplePojo));
assertEquals(INSTANT, getters.get(7).get(simplePojo));
assertArrayEquals("Unexpected bytes", BYTE_ARRAY, (byte[]) getters.get(8).get(simplePojo));
assertArrayEquals("Unexpected bytes", BYTE_BUFFER.array(), (byte[]) getters.get(9).get(simplePojo));
assertEquals(new BigDecimal(42), getters.get(10).get(simplePojo));
assertEquals("stringBuilder", getters.get(11).get(simplePojo));
}
Aggregations