use of org.apache.beam.sdk.schemas.utils.TestPOJOs.PojoWithEnum in project beam by apache.
the class JavaFieldSchemaTest method testEnumFieldFromRow.
@Test
public void testEnumFieldFromRow() throws NoSuchSchemaException {
SchemaRegistry registry = SchemaRegistry.createDefault();
Schema schema = registry.getSchema(PojoWithEnum.class);
SchemaTestUtils.assertSchemaEquivalent(POJO_WITH_ENUM_SCHEMA, schema);
EnumerationType enumerationType = ENUMERATION;
List<EnumerationType.Value> allColors = Lists.newArrayList(enumerationType.valueOf("RED"), enumerationType.valueOf("GREEN"), enumerationType.valueOf("BLUE"));
Row redRow = Row.withSchema(POJO_WITH_ENUM_SCHEMA).addValues(enumerationType.valueOf("RED"), allColors).build();
Row greenRow = Row.withSchema(POJO_WITH_ENUM_SCHEMA).addValues(enumerationType.valueOf("GREEN"), allColors).build();
Row blueRow = Row.withSchema(POJO_WITH_ENUM_SCHEMA).addValues(enumerationType.valueOf("BLUE"), allColors).build();
SerializableFunction<Row, PojoWithEnum> fromRow = registry.getFromRowFunction(PojoWithEnum.class);
List<Color> allColorsJava = Lists.newArrayList(Color.RED, Color.GREEN, Color.BLUE);
assertEquals(new PojoWithEnum(Color.RED, allColorsJava), fromRow.apply(redRow));
assertEquals(new PojoWithEnum(Color.GREEN, allColorsJava), fromRow.apply(greenRow));
assertEquals(new PojoWithEnum(Color.BLUE, allColorsJava), fromRow.apply(blueRow));
}
use of org.apache.beam.sdk.schemas.utils.TestPOJOs.PojoWithEnum in project beam by apache.
the class JavaFieldSchemaTest method testEnumFieldToRow.
@Test
public void testEnumFieldToRow() throws NoSuchSchemaException {
SchemaRegistry registry = SchemaRegistry.createDefault();
Schema schema = registry.getSchema(PojoWithEnum.class);
SchemaTestUtils.assertSchemaEquivalent(POJO_WITH_ENUM_SCHEMA, schema);
EnumerationType enumerationType = ENUMERATION;
List<EnumerationType.Value> allColors = Lists.newArrayList(enumerationType.valueOf("RED"), enumerationType.valueOf("GREEN"), enumerationType.valueOf("BLUE"));
Row redRow = Row.withSchema(POJO_WITH_ENUM_SCHEMA).addValues(enumerationType.valueOf("RED"), allColors).build();
Row greenRow = Row.withSchema(POJO_WITH_ENUM_SCHEMA).addValues(enumerationType.valueOf("GREEN"), allColors).build();
Row blueRow = Row.withSchema(POJO_WITH_ENUM_SCHEMA).addValues(enumerationType.valueOf("BLUE"), allColors).build();
List<Color> allColorsJava = Lists.newArrayList(Color.RED, Color.GREEN, Color.BLUE);
SerializableFunction<PojoWithEnum, Row> toRow = registry.getToRowFunction(PojoWithEnum.class);
assertEquals(redRow, toRow.apply(new PojoWithEnum(Color.RED, allColorsJava)));
assertEquals(greenRow, toRow.apply(new PojoWithEnum(Color.GREEN, allColorsJava)));
assertEquals(blueRow, toRow.apply(new PojoWithEnum(Color.BLUE, allColorsJava)));
}
Aggregations