@Test(expected = IllegalArgumentException.class) @Category(NeedsRunner.class) public void testTypeNarrowFail() throws Exception { // narrowing is the opposite of widening Schema inputSchema = pipeline.getSchemaRegistry().getSchema(TypeWiden2.class); Schema outputSchema = pipeline.getSchemaRegistry().getSchema(TypeWiden1.class); Cast.narrowing(outputSchema).verifyCompatibility(inputSchema); }
@Test @Category(NeedsRunner.class) public void testWeakedNullable() throws Exception { Schema outputSchema = pipeline.getSchemaRegistry().getSchema(Nullable2.class); PCollection<Nullable2> pojos = pipeline .apply(Create.of(new Nullable1())) .apply(Cast.narrowing(outputSchema)) .apply(Convert.to(Nullable2.class)); PAssert.that(pojos).containsInAnyOrder(new Nullable2()); pipeline.run(); }
@Test @Category(NeedsRunner.class) public void testTypeNarrow() throws Exception { // narrowing is the opposite of widening Schema outputSchema = pipeline.getSchemaRegistry().getSchema(TypeWiden1.class); PCollection<TypeWiden1> pojos = pipeline .apply(Create.of(new TypeWiden2())) .apply(Cast.narrowing(outputSchema)) .apply(Convert.to(TypeWiden1.class)); PAssert.that(pojos).containsInAnyOrder(new TypeWiden1()); pipeline.run(); }
@Test @Category(NeedsRunner.class) public void testComplexCast() throws Exception { Schema outputSchema = pipeline.getSchemaRegistry().getSchema(All2.class); PCollection<All2> pojos = pipeline .apply(Create.of(new All1())) .apply(Cast.narrowing(outputSchema)) .apply(Convert.to(All2.class)); PAssert.that(pojos).containsInAnyOrder(new All2()); pipeline.run(); }
@Test @Category(NeedsRunner.class) public void testIgnoreNullable() throws Exception { // ignoring nullable is opposite of weakening Schema outputSchema = pipeline.getSchemaRegistry().getSchema(Nullable1.class); PCollection<Nullable1> pojos = pipeline .apply(Create.of(new Nullable2())) .apply(Cast.narrowing(outputSchema)) .apply(Convert.to(Nullable1.class)); PAssert.that(pojos).containsInAnyOrder(new Nullable1()); pipeline.run(); }