use of org.apache.beam.sdk.schemas.utils.TestJavaBeans.SimpleBean in project beam by apache.
the class SchemaRegistryTest method testGetSchemaCoder.
@Test
public void testGetSchemaCoder() throws NoSuchSchemaException {
SchemaRegistry registry = SchemaRegistry.createDefault();
registry.registerJavaBean(SimpleBean.class);
Schema schema = registry.getSchema(SimpleBean.class);
SerializableFunction<SimpleBean, Row> toRowFunction = registry.getToRowFunction(SimpleBean.class);
SerializableFunction<Row, SimpleBean> fromRowFunction = registry.getFromRowFunction(SimpleBean.class);
SchemaCoder schemaCoder = registry.getSchemaCoder(SimpleBean.class);
assertTrue(schema.equivalent(schemaCoder.getSchema()));
assertTrue(toRowFunction.equals(schemaCoder.getToRowFunction()));
assertTrue(fromRowFunction.equals(schemaCoder.getFromRowFunction()));
thrown.expect(NoSuchSchemaException.class);
registry.getSchemaCoder(Double.class);
}
use of org.apache.beam.sdk.schemas.utils.TestJavaBeans.SimpleBean in project beam by apache.
the class JavaBeanSchemaTest method testFromRow.
@Test
public void testFromRow() throws NoSuchSchemaException {
SchemaRegistry registry = SchemaRegistry.createDefault();
Row row = createSimpleRow("string");
SimpleBean bean = registry.getFromRowFunction(SimpleBean.class).apply(row);
assertEquals("string", bean.getStr());
assertEquals((byte) 1, bean.getaByte());
assertEquals((short) 2, bean.getaShort());
assertEquals((int) 3, bean.getAnInt());
assertEquals((long) 4, bean.getaLong());
assertTrue(bean.isaBoolean());
assertEquals(DATE, bean.getDateTime());
assertEquals(DATE.toInstant(), bean.getInstant());
assertArrayEquals("not equal", BYTE_ARRAY, bean.getBytes());
assertArrayEquals("not equal", BYTE_ARRAY, bean.getByteBuffer().array());
assertEquals(BigDecimal.ONE, bean.getBigDecimal());
assertEquals("stringbuilder", bean.getStringBuilder().toString());
}
use of org.apache.beam.sdk.schemas.utils.TestJavaBeans.SimpleBean in project beam by apache.
the class JavaBeanSchemaTest method testFromRowWithGetters.
@Test
public void testFromRowWithGetters() throws NoSuchSchemaException {
SchemaRegistry registry = SchemaRegistry.createDefault();
SimpleBean bean = createSimple("string");
Row row = registry.getToRowFunction(SimpleBean.class).apply(bean);
// Test that the fromRowFunction simply returns the original object back.
SimpleBean extracted = registry.getFromRowFunction(SimpleBean.class).apply(row);
assertSame(bean, extracted);
}
Aggregations