use of org.apache.beam.sdk.schemas.JavaBeanSchema.SetterTypeSupplier in project beam by apache.
the class JavaBeanUtilsTest method testGeneratedSimpleSetters.
@Test
public void testGeneratedSimpleSetters() {
SimpleBean simpleBean = new SimpleBean();
List<FieldValueSetter> setters = JavaBeanUtils.getSetters(SimpleBean.class, SIMPLE_BEAN_SCHEMA, new SetterTypeSupplier(), new DefaultTypeConversionsFactory());
assertEquals(12, setters.size());
setters.get(0).set(simpleBean, "field1");
setters.get(1).set(simpleBean, (byte) 41);
setters.get(2).set(simpleBean, (short) 42);
setters.get(3).set(simpleBean, (int) 43);
setters.get(4).set(simpleBean, (long) 44);
setters.get(5).set(simpleBean, true);
setters.get(6).set(simpleBean, DateTime.parse("1979-03-14").toInstant());
setters.get(7).set(simpleBean, DateTime.parse("1979-03-15").toInstant());
setters.get(8).set(simpleBean, "bytes1".getBytes(StandardCharsets.UTF_8));
setters.get(9).set(simpleBean, "bytes2".getBytes(StandardCharsets.UTF_8));
setters.get(10).set(simpleBean, new BigDecimal(42));
setters.get(11).set(simpleBean, "stringBuilder");
assertEquals("field1", simpleBean.getStr());
assertEquals((byte) 41, simpleBean.getaByte());
assertEquals((short) 42, simpleBean.getaShort());
assertEquals((int) 43, simpleBean.getAnInt());
assertEquals((long) 44, simpleBean.getaLong());
assertTrue(simpleBean.isaBoolean());
assertEquals(DateTime.parse("1979-03-14"), simpleBean.getDateTime());
assertEquals(DateTime.parse("1979-03-15").toInstant(), simpleBean.getInstant());
assertArrayEquals("Unexpected bytes", "bytes1".getBytes(StandardCharsets.UTF_8), simpleBean.getBytes());
assertEquals(ByteBuffer.wrap("bytes2".getBytes(StandardCharsets.UTF_8)), simpleBean.getByteBuffer());
assertEquals(new BigDecimal(42), simpleBean.getBigDecimal());
assertEquals("stringBuilder", simpleBean.getStringBuilder().toString());
}
use of org.apache.beam.sdk.schemas.JavaBeanSchema.SetterTypeSupplier in project beam by apache.
the class JavaBeanUtilsTest method testGeneratedSimpleBoxedSetters.
@Test
public void testGeneratedSimpleBoxedSetters() {
BeanWithBoxedFields bean = new BeanWithBoxedFields();
List<FieldValueSetter> setters = JavaBeanUtils.getSetters(BeanWithBoxedFields.class, BEAN_WITH_BOXED_FIELDS_SCHEMA, new SetterTypeSupplier(), new DefaultTypeConversionsFactory());
setters.get(0).set(bean, (byte) 41);
setters.get(1).set(bean, (short) 42);
setters.get(2).set(bean, (int) 43);
setters.get(3).set(bean, (long) 44);
setters.get(4).set(bean, true);
assertEquals((byte) 41, bean.getaByte().byteValue());
assertEquals((short) 42, bean.getaShort().shortValue());
assertEquals((int) 43, bean.getAnInt().intValue());
assertEquals((long) 44, bean.getaLong().longValue());
assertTrue(bean.getaBoolean().booleanValue());
}
use of org.apache.beam.sdk.schemas.JavaBeanSchema.SetterTypeSupplier in project beam by apache.
the class JavaBeanUtilsTest method testGeneratedByteBufferSetters.
@Test
public void testGeneratedByteBufferSetters() {
BeanWithByteArray bean = new BeanWithByteArray();
List<FieldValueSetter> setters = JavaBeanUtils.getSetters(BeanWithByteArray.class, BEAN_WITH_BYTE_ARRAY_SCHEMA, new SetterTypeSupplier(), new DefaultTypeConversionsFactory());
setters.get(0).set(bean, "field1".getBytes(StandardCharsets.UTF_8));
setters.get(1).set(bean, "field2".getBytes(StandardCharsets.UTF_8));
assertArrayEquals("not equal", "field1".getBytes(StandardCharsets.UTF_8), bean.getBytes1());
assertEquals(ByteBuffer.wrap("field2".getBytes(StandardCharsets.UTF_8)), bean.getBytes2());
}
Aggregations