Class TestData
- All Implemented Interfaces:
ComponentConfigurer<DataSource>
This mechanism does not use any external resources. It provides only the data that the
application has put into it using the update(FlagBuilder) method.
The example code below uses a simple boolean flag, but more complex configurations are possible using
the methods of the TestData.FlagBuilder that is returned by flag(String).
TestData td = TestData.dataSource();
td.update(testData.flag("flag-key-1").booleanFlag().variation(true));
LDConfig config = new LDConfig.Builder()
.mobileKey("my-mobile-key")
.dataSource(td)
.build();
LDClient client = new LDClient(sdkKey, config, initialContext, startWaitSeconds);
// flags can be updated at any time:
td.update(testData.flag("flag-key-2")
.variationForUser("some-user-key", false));
- Since:
- 4.0.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA builder for feature flag configurations to be used withTestData. -
Method Summary
Modifier and TypeMethodDescriptionbuild(ClientContext clientContext) Called internally by the SDK to create an implementation instance.static TestDataCreates a new instance of the test data source.Creates or copies aTestData.FlagBuilderfor building a test flag configuration.update(TestData.FlagBuilder flagBuilder) Updates the test data with the specified flag configuration.
-
Method Details
-
dataSource
Creates a new instance of the test data source.See
TestDatafor details.- Returns:
- a new configurable test data source
-
flag
Creates or copies aTestData.FlagBuilderfor building a test flag configuration.If this flag key has already been defined in this
TestDatainstance, then the builder starts with the same configuration that was last provided for this flag.Otherwise, it starts with a new default configuration in which the flag has
trueandfalsevariations, and istrueby default for all contexts. You can change any of those properties, and provide more complex behavior, using theTestData.FlagBuilder\ methods.Once you have set the desired configuration, pass the builder to
update(FlagBuilder).- Parameters:
key- the flag key- Returns:
- a flag configuration builder
- See Also:
-
update
Updates the test data with the specified flag configuration.This has the same effect as if a flag were added or modified on the LaunchDarkly dashboard. It immediately propagates the flag change to any
LDClientinstance(s) that you have already configured to use thisTestData. If noLDClienthas been started yet, it simply adds this flag to the test data which will be provided to anyLDClientthat you subsequently configure.Any subsequent changes to this
TestData.FlagBuilderinstance do not affect the test data, unless you callupdate(FlagBuilder)again.- Parameters:
flagBuilder- a flag configuration builder- Returns:
- the same
TestDatainstance - See Also:
-
build
Description copied from interface:ComponentConfigurerCalled internally by the SDK to create an implementation instance. Applications should not need to call this method.- Specified by:
buildin interfaceComponentConfigurer<DataSource>- Parameters:
clientContext- provides configuration properties and other components from the current SDK client instance- Returns:
- a instance of the component type
-