PipelineOptionsFactory { public static <T extends PipelineOptions> T as(Class<T> klass) { return new Builder().as(klass); }  static PipelineOptions create(); static T as(Class<T> klass); static Builder fromArgs(String... args); Builder withValidation(); static synchronized void register(Class<? extends PipelineOptions> iface); @Experimental static synchronized void resetCache(); static Set<Class<? extends PipelineOptions>> getRegisteredOptions(); static void printHelp(PrintStream out); static void printHelp(PrintStream out, Class<? extends PipelineOptions> iface); static List<PipelineOptionDescriptor> describe(
      Set<Class<? extends PipelineOptions>> ifaces);  }
@Test public void testAppNameIsSet() { ApplicationNameOptions options = PipelineOptionsFactory.as(ApplicationNameOptions.class); assertEquals(PipelineOptionsFactoryTest.class.getSimpleName(), options.getAppName()); }
@Test public void testAppNameIsSetWhenUsingAs() { TestPipelineOptions options = PipelineOptionsFactory.as(TestPipelineOptions.class); assertEquals( PipelineOptionsFactoryTest.class.getSimpleName(), options.as(ApplicationNameOptions.class).getAppName()); }
@Test public void testMissingGetterThrows() throws Exception { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage( "Expected getter for property [object] of type [java.lang.Object] on " + "[org.apache.beam.sdk.options.PipelineOptionsFactoryTest$MissingGetter]."); PipelineOptionsFactory.as(MissingGetter.class); }
@Test public void testMultipleMissingGettersThrows() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage( "missing property methods on [org.apache.beam.sdk.options." + "PipelineOptionsFactoryTest$MissingMultipleGetters]"); expectedException.expectMessage("getter for property [object] of type [java.lang.Object]"); expectedException.expectMessage("getter for property [otherObject] of type [java.lang.Object]"); PipelineOptionsFactory.as(MissingMultipleGetters.class); }
@Test public void testMissingSetterThrows() throws Exception { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage( "Expected setter for property [object] of type [java.lang.Object] on " + "[org.apache.beam.sdk.options.PipelineOptionsFactoryTest$MissingSetter]."); PipelineOptionsFactory.as(MissingSetter.class); }
@Test public void testMissingMultipleSettersThrows() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage( "missing property methods on [org.apache.beam.sdk.options." + "PipelineOptionsFactoryTest$MissingMultipleSetters]"); expectedException.expectMessage("setter for property [object] of type [java.lang.Object]"); expectedException.expectMessage("setter for property [otherObject] of type [java.lang.Object]"); PipelineOptionsFactory.as(MissingMultipleSetters.class); }
@Test public void testMissingGettersAndSettersThrows() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage( "missing property methods on [org.apache.beam.sdk.options." + "PipelineOptionsFactoryTest$MissingGettersAndSetters]"); expectedException.expectMessage("getter for property [object] of type [java.lang.Object]"); expectedException.expectMessage("setter for property [otherObject] of type [java.lang.Object]"); PipelineOptionsFactory.as(MissingGettersAndSetters.class); }
@Test public void testGetterSetterTypeMismatchThrows() throws Exception { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage( "Type mismatch between getter and setter methods for property [value]. Getter is of type " + "[boolean] whereas setter is of type [int]."); PipelineOptionsFactory.as(GetterSetterTypeMismatch.class); }
@Test public void testMultiGetterSetterTypeMismatchThrows() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Type mismatches between getters and setters detected:"); expectedException.expectMessage( "Property [value]: Getter is of type " + "[boolean] whereas setter is of type [int]."); expectedException.expectMessage( "Property [other]: Getter is of type [long] " + "whereas setter is of type [class java.lang.String]."); PipelineOptionsFactory.as(MultiGetterSetterTypeMismatch.class); }
@Test public void testHavingSettersGettersFromSeparateInterfacesIsValid() { PipelineOptionsFactory.as(CombinedObject.class); }
@Test public void testHavingExtraneousMethodThrows() throws Exception { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage( "Methods [extraneousMethod(int, String)] on " + "[org.apache.beam.sdk.options.PipelineOptionsFactoryTest$ExtraneousMethod] " + "do not conform to being bean properties."); PipelineOptionsFactory.as(ExtraneousMethod.class); }
@Test public void testReturnTypeConflictThrows() throws Exception { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage( "Method [getObject] has multiple definitions [public abstract java.lang.Object " + "org.apache.beam.sdk.options.PipelineOptionsFactoryTest$MissingSetter" + ".getObject(), public abstract java.lang.String " + "org.apache.beam.sdk.options.PipelineOptionsFactoryTest$ReturnTypeConflict" + ".getObject()] with different return types for [" + "org.apache.beam.sdk.options.PipelineOptionsFactoryTest$ReturnTypeConflict]."); PipelineOptionsFactory.as(ReturnTypeConflict.class); }
@Test public void testMultipleReturnTypeConflictsThrows() throws Exception { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage( "[org.apache.beam.sdk.options." + "PipelineOptionsFactoryTest$MultiReturnTypeConflict]"); expectedException.expectMessage( "Methods with multiple definitions with different return types"); expectedException.expectMessage("Method [getObject] has multiple definitions"); expectedException.expectMessage( "public abstract java.lang.Object " + "org.apache.beam.sdk.options.PipelineOptionsFactoryTest$" + "MissingSetter.getObject()"); expectedException.expectMessage( "public abstract java.lang.String org.apache.beam.sdk.options." + "PipelineOptionsFactoryTest$MultiReturnTypeConflict.getObject()"); expectedException.expectMessage("Method [getOther] has multiple definitions"); expectedException.expectMessage( "public abstract java.lang.Object " + "org.apache.beam.sdk.options.PipelineOptionsFactoryTest$" + "MultiReturnTypeConflictBase.getOther()"); expectedException.expectMessage( "public abstract java.lang.Long org.apache.beam.sdk.options." + "PipelineOptionsFactoryTest$MultiReturnTypeConflict.getOther()"); PipelineOptionsFactory.as(MultiReturnTypeConflict.class); }
@Test public void testSetterAnnotatedWithJsonIgnore() throws Exception { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage( "Expected setter for property [value] to not be marked with @JsonIgnore on [" + "org.apache.beam.sdk.options.PipelineOptionsFactoryTest$SetterWithJsonIgnore]"); PipelineOptionsFactory.as(SetterWithJsonIgnore.class); }
@Test public void testMultipleSettersAnnotatedWithJsonIgnore() throws Exception { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Found setters marked with @JsonIgnore:"); expectedException.expectMessage( "property [other] should not be marked with @JsonIgnore on [" + "org.apache.beam.sdk.options.PipelineOptionsFactoryTest$MultiSetterWithJsonIgnore]"); expectedException.expectMessage( "property [value] should not be marked with @JsonIgnore on [" + "org.apache.beam.sdk.options.PipelineOptionsFactoryTest$SetterWithJsonIgnore]"); PipelineOptionsFactory.as(MultiSetterWithJsonIgnore.class); }
@Test public void testNotAllGettersAnnotatedWithJsonIgnore() throws Exception { GetterWithJsonIgnore options = PipelineOptionsFactory.as(GetterWithJsonIgnore.class); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage( "Expected getter for property [object] to be marked with @JsonIgnore on all [" + "org.apache.beam.sdk.options.PipelineOptionsFactoryTest$GetterWithJsonIgnore, " + "org.apache.beam.sdk.options.PipelineOptionsFactoryTest$MissingSetter], " + "found only on [org.apache.beam.sdk.options." + "PipelineOptionsFactoryTest$GetterWithJsonIgnore]"); options.as(CombinedObject.class); }
@Test public void testMultipleGettersWithInconsistentJsonIgnore() { MultiGetters options = PipelineOptionsFactory.as(MultiGetters.class); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Property getters are inconsistently marked with @JsonIgnore:"); expectedException.expectMessage("property [object] to be marked on all"); expectedException.expectMessage( "found only on [org.apache.beam.sdk.options." + "PipelineOptionsFactoryTest$MultiGetters]"); expectedException.expectMessage("property [other] to be marked on all"); expectedException.expectMessage( "found only on [org.apache.beam.sdk.options." + "PipelineOptionsFactoryTest$MultipleGettersWithInconsistentJsonIgnore]"); expectedException.expectMessage( anyOf( containsString( java.util.Arrays.toString( new String[] { "org.apache.beam.sdk.options." + "PipelineOptionsFactoryTest$MultipleGettersWithInconsistentJsonIgnore", "org.apache.beam.sdk.options.PipelineOptionsFactoryTest$MultiGetters" })), containsString( java.util.Arrays.toString( new String[] { "org.apache.beam.sdk.options.PipelineOptionsFactoryTest$MultiGetters", "org.apache.beam.sdk.options." + "PipelineOptionsFactoryTest$MultipleGettersWithInconsistentJsonIgnore" })))); expectedException.expectMessage(not(containsString("property [consistent]"))); options.as(MultipleGettersWithInconsistentJsonIgnore.class); }
@Test public void testSetterAnnotatedWithDefault() throws Exception { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage( "Expected setter for property [value] to not be marked with @Default on [" + "org.apache.beam.sdk.options.PipelineOptionsFactoryTest$SetterWithDefault]"); PipelineOptionsFactory.as(SetterWithDefault.class); }
@Test public void testMultipleSettersAnnotatedWithDefault() throws Exception { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Found setters marked with @Default:"); expectedException.expectMessage( "property [other] should not be marked with @Default on [" + "org.apache.beam.sdk.options.PipelineOptionsFactoryTest$MultiSetterWithDefault]"); expectedException.expectMessage( "property [value] should not be marked with @Default on [" + "org.apache.beam.sdk.options.PipelineOptionsFactoryTest$SetterWithDefault]"); PipelineOptionsFactory.as(MultiSetterWithDefault.class); }
@Test public void testNotAllGettersAnnotatedWithDefault() throws Exception { GetterWithDefault options = PipelineOptionsFactory.as(GetterWithDefault.class); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage( "Expected getter for property [object] to be marked with @Default on all [" + "org.apache.beam.sdk.options.PipelineOptionsFactoryTest$GetterWithDefault, " + "org.apache.beam.sdk.options.PipelineOptionsFactoryTest$MissingSetter], " + "found only on [org.apache.beam.sdk.options." + "PipelineOptionsFactoryTest$GetterWithDefault]"); options.as(CombinedObject.class); }
@Test public void testGettersAnnotatedWithConsistentDefault() throws Exception { GetterWithConsistentDefault options = PipelineOptionsFactory.as(GetterWithDefault.class).as(GetterWithConsistentDefault.class); assertEquals(1, options.getObject()); }
@Test public void testGettersAnnotatedWithInconsistentDefault() throws Exception { GetterWithDefault options = PipelineOptionsFactory.as(GetterWithDefault.class); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("contradictory annotations"); expectedException.expectMessage( anyOf( containsString("Default.String(value=\"abc\")"), containsString("Default.String(value=abc)"))); expectedException.expectMessage("Default.Integer(value=1"); options.as(GetterWithInconsistentDefaultType.class); }
@Test public void testGettersAnnotatedWithInconsistentDefaultValue() throws Exception { GetterWithDefault options = PipelineOptionsFactory.as(GetterWithDefault.class); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage( "Property [object] is marked with contradictory annotations. Found [" + "[Default.Integer(value=1) on org.apache.beam.sdk.options.PipelineOptionsFactoryTest" + "$GetterWithDefault#getObject()], " + "[Default.Integer(value=0) on org.apache.beam.sdk.options.PipelineOptionsFactoryTest" + "$GetterWithInconsistentDefaultValue#getObject()]]."); options.as(GetterWithInconsistentDefaultValue.class); }
@Test public void testGettersAnnotatedWithInconsistentJsonIgnoreValue() throws Exception { GetterWithJsonIgnore options = PipelineOptionsFactory.as(GetterWithJsonIgnore.class); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage( "Property [object] is marked with contradictory annotations. Found [" + "[JsonIgnore(value=false) on org.apache.beam.sdk.options.PipelineOptionsFactoryTest" + "$GetterWithInconsistentJsonIgnoreValue#getObject()], " + "[JsonIgnore(value=true) on org.apache.beam.sdk.options.PipelineOptionsFactoryTest" + "$GetterWithJsonIgnore#getObject()]]."); options.as(GetterWithInconsistentJsonIgnoreValue.class); }
@Test public void testGettersWithMultipleDefaults() throws Exception { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("contradictory annotations"); expectedException.expectMessage( anyOf( containsString("Default.String(value=\"abc\")"), containsString("Default.String(value=abc)"))); expectedException.expectMessage("Default.Integer(value=0)"); PipelineOptionsFactory.as(GettersWithMultipleDefault.class); }
@Test public void testMultipleGettersWithInconsistentDefault() { MultiGettersWithDefault options = PipelineOptionsFactory.as(MultiGettersWithDefault.class); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Property getters are inconsistently marked with @Default:"); expectedException.expectMessage("property [object] to be marked on all"); expectedException.expectMessage( "found only on [org.apache.beam.sdk.options." + "PipelineOptionsFactoryTest$MultiGettersWithDefault]"); expectedException.expectMessage("property [other] to be marked on all"); expectedException.expectMessage( "found only on [org.apache.beam.sdk.options." + "PipelineOptionsFactoryTest$MultipleGettersWithInconsistentDefault]"); expectedException.expectMessage( anyOf( containsString( java.util.Arrays.toString( new String[] { "org.apache.beam.sdk.options." + "PipelineOptionsFactoryTest$MultipleGettersWithInconsistentDefault", "org.apache.beam.sdk.options.PipelineOptionsFactoryTest$MultiGettersWithDefault" })), containsString( java.util.Arrays.toString( new String[] { "org.apache.beam.sdk.options.PipelineOptionsFactoryTest$MultiGettersWithDefault", "org.apache.beam.sdk.options." + "PipelineOptionsFactoryTest$MultipleGettersWithInconsistentDefault" })))); expectedException.expectMessage(not(containsString("property [consistent]"))); options.as(MultipleGettersWithInconsistentDefault.class); }
@Test public void testNonPublicInterfaceThrowsException() throws Exception { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage( "Please mark non-public interface " + NonPublicPipelineOptions.class.getName() + " as public."); PipelineOptionsFactory.as(NonPublicPipelineOptions.class); }
@Test public void testAllFromPipelineOptions() { assumeFalse(SystemUtils.IS_OS_WINDOWS); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage( "All inherited interfaces of" + " [org.apache.beam.sdk.options.PipelineOptionsFactoryTest$PipelineOptionsInheritedInvalid]" + " should inherit from the PipelineOptions interface. The following inherited" + " interfaces do not:\n" + " - org.apache.beam.sdk.options.PipelineOptionsFactoryTest$InvalidPipelineOptions1\n" + " - org.apache.beam.sdk.options.PipelineOptionsFactoryTest$InvalidPipelineOptions2"); PipelineOptionsFactory.as(PipelineOptionsInheritedInvalid.class); }
@Test public void testDefaultMethodIgnoresDefaultImplementation() { OptionsWithDefaultMethod optsWithDefault = PipelineOptionsFactory.as(OptionsWithDefaultMethod.class); assertThat(optsWithDefault.getValue(), nullValue()); optsWithDefault.setValue(12.25); assertThat(optsWithDefault.getValue(), equalTo(12.25)); }
@Test public void testDefaultMethodInExtendedClassIgnoresDefaultImplementation() { OptionsWithDefaultMethod extendedOptsWithDefault = PipelineOptionsFactory.as(ExtendedOptionsWithDefault.class); assertThat(extendedOptsWithDefault.getValue(), nullValue()); extendedOptsWithDefault.setValue(Double.NEGATIVE_INFINITY); assertThat(extendedOptsWithDefault.getValue(), equalTo(Double.NEGATIVE_INFINITY)); }
@Test public void testMultipleGettersWithInconsistentJsonIgnore() { MultiGetters options = PipelineOptionsFactory.as(MultiGetters.class); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Property getters are inconsistently marked with @JsonIgnore:"); expectedException.expectMessage("property [object] to be marked on all"); expectedException.expectMessage( "found only on [org.apache.beam.sdk.options." + "PipelineOptionsFactoryTest$MultiGetters]"); expectedException.expectMessage("property [other] to be marked on all"); expectedException.expectMessage( "found only on [org.apache.beam.sdk.options." + "PipelineOptionsFactoryTest$MultipleGettersWithInconsistentJsonIgnore]"); expectedException.expectMessage( Matchers.anyOf( containsString( java.util.Arrays.toString( new String[] { "org.apache.beam.sdk.options." + "PipelineOptionsFactoryTest$MultipleGettersWithInconsistentJsonIgnore", "org.apache.beam.sdk.options.PipelineOptionsFactoryTest$MultiGetters" })), containsString( java.util.Arrays.toString( new String[] { "org.apache.beam.sdk.options.PipelineOptionsFactoryTest$MultiGetters", "org.apache.beam.sdk.options." + "PipelineOptionsFactoryTest$MultipleGettersWithInconsistentJsonIgnore" })))); expectedException.expectMessage(not(containsString("property [consistent]"))); options.as(MultipleGettersWithInconsistentJsonIgnore.class); }
@Test public void testGettersAnnotatedWithInconsistentDefault() throws Exception { GetterWithDefault options = PipelineOptionsFactory.as(GetterWithDefault.class); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage( "Property [object] is marked with contradictory annotations. Found [" + "[Default.Integer(value=1) on org.apache.beam.sdk.options.PipelineOptionsFactoryTest" + "$GetterWithDefault#getObject()], " + "[Default.String(value=abc) on org.apache.beam.sdk.options.PipelineOptionsFactoryTest" + "$GetterWithInconsistentDefaultType#getObject()]]."); options.as(GetterWithInconsistentDefaultType.class); }
@Test public void testGettersWithMultipleDefaults() throws Exception { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage( "Property [object] is marked with contradictory annotations. Found [" + "[Default.String(value=abc) on org.apache.beam.sdk.options.PipelineOptionsFactoryTest" + "$GettersWithMultipleDefault#getObject()], " + "[Default.Integer(value=0) on org.apache.beam.sdk.options.PipelineOptionsFactoryTest" + "$GettersWithMultipleDefault#getObject()]]."); PipelineOptionsFactory.as(GettersWithMultipleDefault.class); }
@Test public void testMultipleGettersWithInconsistentDefault() { MultiGettersWithDefault options = PipelineOptionsFactory.as(MultiGettersWithDefault.class); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Property getters are inconsistently marked with @Default:"); expectedException.expectMessage("property [object] to be marked on all"); expectedException.expectMessage( "found only on [org.apache.beam.sdk.options." + "PipelineOptionsFactoryTest$MultiGettersWithDefault]"); expectedException.expectMessage("property [other] to be marked on all"); expectedException.expectMessage( "found only on [org.apache.beam.sdk.options." + "PipelineOptionsFactoryTest$MultipleGettersWithInconsistentDefault]"); expectedException.expectMessage( Matchers.anyOf( containsString( java.util.Arrays.toString( new String[] { "org.apache.beam.sdk.options." + "PipelineOptionsFactoryTest$MultipleGettersWithInconsistentDefault", "org.apache.beam.sdk.options.PipelineOptionsFactoryTest$MultiGettersWithDefault" })), containsString( java.util.Arrays.toString( new String[] { "org.apache.beam.sdk.options.PipelineOptionsFactoryTest$MultiGettersWithDefault", "org.apache.beam.sdk.options." + "PipelineOptionsFactoryTest$MultipleGettersWithInconsistentDefault" })))); expectedException.expectMessage(not(containsString("property [consistent]"))); options.as(MultipleGettersWithInconsistentDefault.class); }
@Test public void testAllFromPipelineOptions() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage( "All inherited interfaces of [org.apache.beam.sdk.options.PipelineOptionsFactoryTest" + "$PipelineOptionsInheritedInvalid] should inherit from the PipelineOptions interface. " + "The following inherited interfaces do not:\n" + " - org.apache.beam.sdk.options.PipelineOptionsFactoryTest" + "$InvalidPipelineOptions1\n" + " - org.apache.beam.sdk.options.PipelineOptionsFactoryTest" + "$InvalidPipelineOptions2"); PipelineOptionsFactory.as(PipelineOptionsInheritedInvalid.class); }