Search in sources :

Example 1 with SetterTypeSupplier

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());
}
Also used : SimpleBean(org.apache.beam.sdk.schemas.utils.TestJavaBeans.SimpleBean) DefaultTypeConversionsFactory(org.apache.beam.sdk.schemas.utils.ByteBuddyUtils.DefaultTypeConversionsFactory) FieldValueSetter(org.apache.beam.sdk.schemas.FieldValueSetter) SetterTypeSupplier(org.apache.beam.sdk.schemas.JavaBeanSchema.SetterTypeSupplier) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 2 with SetterTypeSupplier

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());
}
Also used : BeanWithBoxedFields(org.apache.beam.sdk.schemas.utils.TestJavaBeans.BeanWithBoxedFields) DefaultTypeConversionsFactory(org.apache.beam.sdk.schemas.utils.ByteBuddyUtils.DefaultTypeConversionsFactory) FieldValueSetter(org.apache.beam.sdk.schemas.FieldValueSetter) SetterTypeSupplier(org.apache.beam.sdk.schemas.JavaBeanSchema.SetterTypeSupplier) Test(org.junit.Test)

Example 3 with SetterTypeSupplier

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());
}
Also used : BeanWithByteArray(org.apache.beam.sdk.schemas.utils.TestJavaBeans.BeanWithByteArray) DefaultTypeConversionsFactory(org.apache.beam.sdk.schemas.utils.ByteBuddyUtils.DefaultTypeConversionsFactory) FieldValueSetter(org.apache.beam.sdk.schemas.FieldValueSetter) SetterTypeSupplier(org.apache.beam.sdk.schemas.JavaBeanSchema.SetterTypeSupplier) Test(org.junit.Test)

Aggregations

FieldValueSetter (org.apache.beam.sdk.schemas.FieldValueSetter)3 SetterTypeSupplier (org.apache.beam.sdk.schemas.JavaBeanSchema.SetterTypeSupplier)3 DefaultTypeConversionsFactory (org.apache.beam.sdk.schemas.utils.ByteBuddyUtils.DefaultTypeConversionsFactory)3 Test (org.junit.Test)3 BigDecimal (java.math.BigDecimal)1 BeanWithBoxedFields (org.apache.beam.sdk.schemas.utils.TestJavaBeans.BeanWithBoxedFields)1 BeanWithByteArray (org.apache.beam.sdk.schemas.utils.TestJavaBeans.BeanWithByteArray)1 SimpleBean (org.apache.beam.sdk.schemas.utils.TestJavaBeans.SimpleBean)1