Class TestData.FlagBuilder
- java.lang.Object
-
- com.launchdarkly.sdk.server.integrations.TestData.FlagBuilder
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
TestData.FlagBuilder.FlagRuleBuilder
A builder for feature flag rules to be used withTestData.FlagBuilder
.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description TestData.FlagBuilder
booleanFlag()
A shortcut for setting the flag to use the standard boolean configuration.TestData.FlagBuilder
clearRules()
Removes any existing rules from the flag.TestData.FlagBuilder
clearUserTargets()
Removes any existing user targets from the flag.TestData.FlagBuilder
fallthroughVariation(boolean value)
Specifies the fallthrough variation for a boolean flag.TestData.FlagBuilder
fallthroughVariation(int variationIndex)
Specifies the index of the fallthrough variation.TestData.FlagBuilder.FlagRuleBuilder
ifMatch(UserAttribute attribute, LDValue... values)
Starts defining a flag rule, using the "is one of" operator.TestData.FlagBuilder.FlagRuleBuilder
ifNotMatch(UserAttribute attribute, LDValue... values)
Starts defining a flag rule, using the "is not one of" operator.TestData.FlagBuilder
offVariation(boolean value)
Specifies the off variation for a boolean flag.TestData.FlagBuilder
offVariation(int variationIndex)
Specifies the index of the off variation.TestData.FlagBuilder
on(boolean on)
Sets targeting to be on or off for this flag.TestData.FlagBuilder
valueForAll(LDValue value)
Sets the flag to always return the specified variation value for all users.TestData.FlagBuilder
valueForAllUsers(LDValue value)
Deprecated.UsevalueForAll(LDValue)
.TestData.FlagBuilder
variationForAll(boolean variation)
Sets the flag to always return the specified boolean variation for all users.TestData.FlagBuilder
variationForAll(int variationIndex)
Sets the flag to always return the specified variation for all users.TestData.FlagBuilder
variationForAllUsers(boolean variation)
Deprecated.TestData.FlagBuilder
variationForAllUsers(int variationIndex)
Deprecated.UsevariationForAll(int)
.TestData.FlagBuilder
variationForUser(java.lang.String userKey, boolean variation)
Sets the flag to return the specified boolean variation for a specific user key when targeting is on.TestData.FlagBuilder
variationForUser(java.lang.String userKey, int variationIndex)
Sets the flag to return the specified variation for a specific user key when targeting is on.TestData.FlagBuilder
variations(LDValue... values)
Changes the allowable variation values for the flag.
-
-
-
Method Detail
-
booleanFlag
public TestData.FlagBuilder booleanFlag()
A shortcut for setting the flag to use the standard boolean configuration.This is the default for all new flags created with
TestData.flag(String)
. The flag will have two variations,true
andfalse
(in that order); it will returnfalse
whenever targeting is off, andtrue
when targeting is on if no other settings specify otherwise.- Returns:
- the builder
-
on
public TestData.FlagBuilder on(boolean on)
Sets targeting to be on or off for this flag.The effect of this depends on the rest of the flag configuration, just as it does on the real LaunchDarkly dashboard. In the default configuration that you get from calling
TestData.flag(String)
with a new flag key, the flag will returnfalse
whenever targeting is off, andtrue
when targeting is on.- Parameters:
on
- true if targeting should be on- Returns:
- the builder
-
fallthroughVariation
public TestData.FlagBuilder fallthroughVariation(boolean value)
Specifies the fallthrough variation for a boolean flag. The fallthrough is the value that is returned if targeting is on and the user was not matched by a more specific target or rule.If the flag was previously configured with other variations, this also changes it to a boolean flag.
- Parameters:
value
- true if the flag should return true by default when targeting is on- Returns:
- the builder
-
fallthroughVariation
public TestData.FlagBuilder fallthroughVariation(int variationIndex)
Specifies the index of the fallthrough variation. The fallthrough is the variation that is returned if targeting is on and the user was not matched by a more specific target or rule.- Parameters:
variationIndex
- the desired fallthrough variation: 0 for the first, 1 for the second, etc.- Returns:
- the builder
-
offVariation
public TestData.FlagBuilder offVariation(boolean value)
Specifies the off variation for a boolean flag. This is the variation that is returned whenever targeting is off.- Parameters:
value
- true if the flag should return true when targeting is off- Returns:
- the builder
-
offVariation
public TestData.FlagBuilder offVariation(int variationIndex)
Specifies the index of the off variation. This is the variation that is returned whenever targeting is off.- Parameters:
variationIndex
- the desired off variation: 0 for the first, 1 for the second, etc.- Returns:
- the builder
-
variationForAll
public TestData.FlagBuilder variationForAll(boolean variation)
Sets the flag to always return the specified boolean variation for all users.Targeting is switched on, any existing targets or rules are removed, and the flag's variations are set to true and false. The fallthrough variation is set to the specified value. The off variation is left unchanged.
- Parameters:
variation
- the desired true/false variation to be returned for all users- Returns:
- the builder
- Since:
- 5.10.0
-
variationForAll
public TestData.FlagBuilder variationForAll(int variationIndex)
Sets the flag to always return the specified variation for all users.The variation is specified by number, out of whatever variation values have already been defined. Targeting is switched on, and any existing targets or rules are removed. The fallthrough variation is set to the specified value. The off variation is left unchanged.
- Parameters:
variationIndex
- the desired variation: 0 for the first, 1 for the second, etc.- Returns:
- the builder
- Since:
- 5.10.0
-
variationForAllUsers
@Deprecated public TestData.FlagBuilder variationForAllUsers(boolean variation)
Deprecated.Deprecated name forvariationForAll(boolean)
.This method name will be dropped in a future SDK version because "users" will not always be the only kind of input for an evaluation.
- Parameters:
variation
- the desired true/false variation to be returned for all users- Returns:
- the builder
-
variationForAllUsers
@Deprecated public TestData.FlagBuilder variationForAllUsers(int variationIndex)
Deprecated.UsevariationForAll(int)
.Deprecated name forvariationForAll(int)
.This method name will be dropped in a future SDK version because "users" will not always be the only kind of input for an evaluation.
- Parameters:
variationIndex
- the desired variation: 0 for the first, 1 for the second, etc.- Returns:
- the builder
-
valueForAll
public TestData.FlagBuilder valueForAll(LDValue value)
Sets the flag to always return the specified variation value for all users.The value may be of any JSON type, as defined by
LDValue
. This method changes the flag to have only a single variation, which is this value, and to return the same variation regardless of whether targeting is on or off. Any existing targets or rules are removed.- Parameters:
value
- the desired value to be returned for all users- Returns:
- the builder
-
valueForAllUsers
@Deprecated public TestData.FlagBuilder valueForAllUsers(LDValue value)
Deprecated.UsevalueForAll(LDValue)
.Deprecated name forvalueForAll(LDValue)
.This method name will be dropped in a future SDK version because "users" will not always be the only kind of input for an evaluation.
- Parameters:
value
- the desired value to be returned for all users- Returns:
- the builder'
-
variationForUser
public TestData.FlagBuilder variationForUser(java.lang.String userKey, boolean variation)
Sets the flag to return the specified boolean variation for a specific user key when targeting is on.This has no effect when targeting is turned off for the flag.
If the flag was not already a boolean flag, this also changes it to a boolean flag.
- Parameters:
userKey
- a user keyvariation
- the desired true/false variation to be returned for this user when targeting is on- Returns:
- the builder
-
variationForUser
public TestData.FlagBuilder variationForUser(java.lang.String userKey, int variationIndex)
Sets the flag to return the specified variation for a specific user key when targeting is on.This has no effect when targeting is turned off for the flag.
The variation is specified by number, out of whatever variation values have already been defined.
- Parameters:
userKey
- a user keyvariationIndex
- the desired variation to be returned for this user when targeting is on: 0 for the first, 1 for the second, etc.- Returns:
- the builder
-
variations
public TestData.FlagBuilder variations(LDValue... values)
Changes the allowable variation values for the flag.The value may be of any JSON type, as defined by
LDValue
. For instance, a boolean flag normally hasLDValue.of(true), LDValue.of(false)
; a string-valued flag might haveLDValue.of("red"), LDValue.of("green")
; etc.- Parameters:
values
- the desired variations- Returns:
- the builder
-
ifMatch
public TestData.FlagBuilder.FlagRuleBuilder ifMatch(UserAttribute attribute, LDValue... values)
Starts defining a flag rule, using the "is one of" operator.For example, this creates a rule that returns
true
if the name is "Patsy" or "Edina":testData.flag("flag") .ifMatch(UserAttribute.NAME, LDValue.of("Patsy"), LDValue.of("Edina")) .thenReturn(true));
- Parameters:
attribute
- the user attribute to match againstvalues
- values to compare to- Returns:
- a
TestData.FlagBuilder.FlagRuleBuilder
; callTestData.FlagBuilder.FlagRuleBuilder.thenReturn(boolean)
orTestData.FlagBuilder.FlagRuleBuilder.thenReturn(int)
to finish the rule, or add more tests with another method likeTestData.FlagBuilder.FlagRuleBuilder.andMatch(UserAttribute, LDValue...)
-
ifNotMatch
public TestData.FlagBuilder.FlagRuleBuilder ifNotMatch(UserAttribute attribute, LDValue... values)
Starts defining a flag rule, using the "is not one of" operator.For example, this creates a rule that returns
true
if the name is neither "Saffron" nor "Bubble":testData.flag("flag") .ifNotMatch(UserAttribute.NAME, LDValue.of("Saffron"), LDValue.of("Bubble")) .thenReturn(true));
- Parameters:
attribute
- the user attribute to match againstvalues
- values to compare to- Returns:
- a
TestData.FlagBuilder.FlagRuleBuilder
; callTestData.FlagBuilder.FlagRuleBuilder.thenReturn(boolean)
orTestData.FlagBuilder.FlagRuleBuilder.thenReturn(int)
to finish the rule, or add more tests with another method likeTestData.FlagBuilder.FlagRuleBuilder.andMatch(UserAttribute, LDValue...)
-
clearRules
public TestData.FlagBuilder clearRules()
Removes any existing rules from the flag. This undoes the effect of methods likeifMatch(UserAttribute, LDValue...)
.- Returns:
- the same builder
-
clearUserTargets
public TestData.FlagBuilder clearUserTargets()
Removes any existing user targets from the flag. This undoes the effect of methods likevariationForUser(String, boolean)
.- Returns:
- the same builder
-
-