Search in sources :

Example 6 with FieldValueSetter

use of org.apache.beam.sdk.schemas.FieldValueSetter in project beam by apache.

the class POJOUtilsTest method testGeneratedSimpleBoxedSetters.

@Test
public void testGeneratedSimpleBoxedSetters() {
    POJOWithBoxedFields pojo = new POJOWithBoxedFields();
    List<FieldValueSetter> setters = POJOUtils.getSetters(POJOWithBoxedFields.class, POJO_WITH_BOXED_FIELDS_SCHEMA, JavaFieldTypeSupplier.INSTANCE, new DefaultTypeConversionsFactory());
    setters.get(0).set(pojo, (byte) 41);
    setters.get(1).set(pojo, (short) 42);
    setters.get(2).set(pojo, (int) 43);
    setters.get(3).set(pojo, (long) 44);
    setters.get(4).set(pojo, true);
    assertEquals((byte) 41, pojo.aByte.byteValue());
    assertEquals((short) 42, pojo.aShort.shortValue());
    assertEquals((int) 43, pojo.anInt.intValue());
    assertEquals((long) 44, pojo.aLong.longValue());
    assertTrue(pojo.aBoolean.booleanValue());
}
Also used : DefaultTypeConversionsFactory(org.apache.beam.sdk.schemas.utils.ByteBuddyUtils.DefaultTypeConversionsFactory) FieldValueSetter(org.apache.beam.sdk.schemas.FieldValueSetter) POJOWithBoxedFields(org.apache.beam.sdk.schemas.utils.TestPOJOs.POJOWithBoxedFields) Test(org.junit.Test)

Example 7 with FieldValueSetter

use of org.apache.beam.sdk.schemas.FieldValueSetter 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 8 with FieldValueSetter

use of org.apache.beam.sdk.schemas.FieldValueSetter 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)8 DefaultTypeConversionsFactory (org.apache.beam.sdk.schemas.utils.ByteBuddyUtils.DefaultTypeConversionsFactory)6 Test (org.junit.Test)6 SetterTypeSupplier (org.apache.beam.sdk.schemas.JavaBeanSchema.SetterTypeSupplier)3 BigDecimal (java.math.BigDecimal)2 Field (java.lang.reflect.Field)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Field (org.apache.beam.sdk.schemas.Schema.Field)1 OneOfType (org.apache.beam.sdk.schemas.logicaltypes.OneOfType)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 POJOWithBoxedFields (org.apache.beam.sdk.schemas.utils.TestPOJOs.POJOWithBoxedFields)1 POJOWithByteArray (org.apache.beam.sdk.schemas.utils.TestPOJOs.POJOWithByteArray)1 SimplePOJO (org.apache.beam.sdk.schemas.utils.TestPOJOs.SimplePOJO)1 AsmVisitorWrapper (org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.asm.AsmVisitorWrapper)1 ForLoadedField (org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.field.FieldDescription.ForLoadedField)1 ForLoadedMethod (org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.method.MethodDescription.ForLoadedMethod)1 DynamicType (org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.dynamic.DynamicType)1