use of org.apache.beam.sdk.schemas.utils.TestPOJOs.NestedPOJO in project beam by apache.
the class JavaFieldSchemaTest method testRecursiveGetters.
@Test
public void testRecursiveGetters() throws NoSuchSchemaException {
SchemaRegistry registry = SchemaRegistry.createDefault();
SchemaTestUtils.assertSchemaEquivalent(NESTED_POJO_SCHEMA, registry.getSchema(NestedPOJO.class));
NestedPOJO pojo = new NestedPOJO(createSimple("string"));
Row row = registry.getToRowFunction(NestedPOJO.class).apply(pojo);
Row nestedRow = row.getRow("nested");
assertEquals("string", nestedRow.getString("str"));
assertEquals((byte) 1, (Object) nestedRow.getByte("aByte"));
assertEquals((short) 2, (Object) nestedRow.getInt16("aShort"));
assertEquals((int) 3, (Object) nestedRow.getInt32("anInt"));
assertEquals((long) 4, (Object) nestedRow.getInt64("aLong"));
assertTrue(nestedRow.getBoolean("aBoolean"));
assertEquals(DATE.toInstant(), nestedRow.getDateTime("dateTime"));
assertEquals(INSTANT, nestedRow.getDateTime("instant").toInstant());
assertArrayEquals("not equal", BYTE_ARRAY, nestedRow.getBytes("bytes"));
assertArrayEquals("not equal", BYTE_BUFFER.array(), nestedRow.getBytes("byteBuffer"));
assertEquals(BigDecimal.ONE, nestedRow.getDecimal("bigDecimal"));
assertEquals("stringbuilder", nestedRow.getString("stringBuilder"));
}
use of org.apache.beam.sdk.schemas.utils.TestPOJOs.NestedPOJO in project beam by apache.
the class JavaFieldSchemaTest method testRecursiveSetters.
@Test
public void testRecursiveSetters() throws NoSuchSchemaException {
SchemaRegistry registry = SchemaRegistry.createDefault();
Row nestedRow = createSimpleRow("string");
Row row = Row.withSchema(NESTED_POJO_SCHEMA).addValue(nestedRow).build();
NestedPOJO pojo = registry.getFromRowFunction(NestedPOJO.class).apply(row);
assertEquals("string", pojo.nested.str);
assertEquals((byte) 1, pojo.nested.aByte);
assertEquals((short) 2, pojo.nested.aShort);
assertEquals((int) 3, pojo.nested.anInt);
assertEquals((long) 4, pojo.nested.aLong);
assertTrue(pojo.nested.aBoolean);
assertEquals(DATE, pojo.nested.dateTime);
assertEquals(INSTANT, pojo.nested.instant);
assertArrayEquals("not equal", BYTE_ARRAY, pojo.nested.bytes);
assertEquals(BYTE_BUFFER, pojo.nested.byteBuffer);
assertEquals(BigDecimal.ONE, pojo.nested.bigDecimal);
assertEquals("stringbuilder", pojo.nested.stringBuilder.toString());
}
Aggregations