Modifier and Type | Class and Description |
---|---|
class |
TestData.FlagBuilder.FlagRuleBuilder
A builder for feature flag rules to be used with
TestData.FlagBuilder . |
Modifier and Type | Method and 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 |
clearTargets()
Removes any existing user/context 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(ContextKind contextKind,
java.lang.String attribute,
LDValue... values)
Starts defining a flag rule, using the "is one of" operator.
|
TestData.FlagBuilder.FlagRuleBuilder |
ifMatch(java.lang.String attribute,
LDValue... values)
Starts defining a flag rule, using the "is one of" operator.
|
TestData.FlagBuilder.FlagRuleBuilder |
ifNotMatch(ContextKind contextKind,
java.lang.String attribute,
LDValue... values)
Starts defining a flag rule, using the "is not one of" operator.
|
TestData.FlagBuilder.FlagRuleBuilder |
ifNotMatch(java.lang.String attribute,
LDValue... values)
Starts defining a flag rule, using the "is not one of" operator.
|
TestData.FlagBuilder |
migrationCheckRatio(long checkRatio)
Turn this flag into a migration flag and set the check ratio.
|
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 |
samplingRatio(long samplingRatio)
Set the samplingRatio, used for event generation, for this flag.
|
TestData.FlagBuilder |
valueForAll(LDValue value)
Sets the flag to always return the specified variation value for all users.
|
TestData.FlagBuilder |
variationForAll(boolean variation)
Sets the flag to always return the specified boolean variation for all contexts.
|
TestData.FlagBuilder |
variationForAll(int variationIndex)
Sets the flag to always return the specified variation for all contexts.
|
TestData.FlagBuilder |
variationForKey(ContextKind contextKind,
java.lang.String key,
boolean variation)
Sets the flag to return the specified boolean variation for a specific context, identified
by context kind and key, when targeting is on.
|
TestData.FlagBuilder |
variationForKey(ContextKind contextKind,
java.lang.String key,
int variationIndex)
Sets the flag to return the specified boolean variation for a specific context, identified
by context kind and key, when targeting is on.
|
TestData.FlagBuilder |
variationForUser(java.lang.String userKey,
boolean variation)
Sets the flag to return the specified boolean variation for a specific user key (that is,
for a context with that key whose context kind is "user") 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 (that is,
for a context with that key whose context kind is "user") when targeting is on.
|
TestData.FlagBuilder |
variations(LDValue... values)
Changes the allowable variation values for the flag.
|
public TestData.FlagBuilder booleanFlag()
This is the default for all new flags created with TestData.flag(String)
. The flag
will have two variations, true
and false
(in that order); it will return
false
whenever targeting is off, and true
when targeting is on if no other
settings specify otherwise.
public TestData.FlagBuilder on(boolean on)
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 return false
whenever targeting is off, and true
when targeting is on.
on
- true if targeting should be onpublic TestData.FlagBuilder fallthroughVariation(boolean value)
If the flag was previously configured with other variations, this also changes it to a boolean flag.
value
- true if the flag should return true by default when targeting is onpublic TestData.FlagBuilder fallthroughVariation(int variationIndex)
variationIndex
- the desired fallthrough variation: 0 for the first, 1 for the second, etc.public TestData.FlagBuilder offVariation(boolean value)
value
- true if the flag should return true when targeting is offpublic TestData.FlagBuilder offVariation(int variationIndex)
variationIndex
- the desired off variation: 0 for the first, 1 for the second, etc.public TestData.FlagBuilder variationForAll(boolean variation)
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.
variation
- the desired true/false variation to be returned for all contextsvariationForAll(int)
,
valueForAll(LDValue)
public TestData.FlagBuilder variationForAll(int variationIndex)
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.
variationIndex
- the desired variation: 0 for the first, 1 for the second, etc.variationForAll(boolean)
,
valueForAll(LDValue)
public TestData.FlagBuilder valueForAll(LDValue value)
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.
value
- the desired value to be returned for all usersvariationForAll(boolean)
,
variationForAll(int)
public TestData.FlagBuilder variationForUser(java.lang.String userKey, boolean variation)
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.
userKey
- a user keyvariation
- the desired true/false variation to be returned for this user when
targeting is onvariationForUser(String, int)
,
variationForKey(ContextKind, String, boolean)
public TestData.FlagBuilder variationForKey(ContextKind contextKind, java.lang.String key, boolean variation)
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.
contextKind
- the context kindkey
- the context keyvariation
- the desired true/false variation to be returned for this context when
targeting is onvariationForKey(ContextKind, String, int)
,
variationForUser(String, boolean)
public TestData.FlagBuilder variationForUser(java.lang.String userKey, int variationIndex)
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.
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.variationForKey(ContextKind, String, int)
,
variationForUser(String, boolean)
public TestData.FlagBuilder variationForKey(ContextKind contextKind, java.lang.String key, int variationIndex)
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.
contextKind
- the context kindkey
- the context keyvariationIndex
- the desired variation to be returned for this context when targeting is on:
0 for the first, 1 for the second, etc.variationForKey(ContextKind, String, boolean)
,
variationForUser(String, int)
public TestData.FlagBuilder variations(LDValue... values)
The value may be of any JSON type, as defined by LDValue
. For instance, a boolean flag
normally has LDValue.of(true), LDValue.of(false)
; a string-valued flag might have
LDValue.of("red"), LDValue.of("green")
; etc.
values
- the desired variationspublic TestData.FlagBuilder.FlagRuleBuilder ifMatch(ContextKind contextKind, java.lang.String attribute, LDValue... values)
For example, this creates a rule that returns true
if the name attribute for the
"company" context is "Ella" or "Monsoon":
testData.flag("flag")
.ifMatch(ContextKind.of("company"), "name",
LDValue.of("Ella"), LDValue.of("Monsoon"))
.thenReturn(true));
contextKind
- the context kind to matchattribute
- the attribute to match againstvalues
- values to compare toTestData.FlagBuilder.FlagRuleBuilder
; call TestData.FlagBuilder.FlagRuleBuilder.thenReturn(boolean)
or
TestData.FlagBuilder.FlagRuleBuilder.thenReturn(int)
to finish the rule, or add more tests with another
method like TestData.FlagBuilder.FlagRuleBuilder.andMatch(ContextKind, String, LDValue...)
ifMatch(String, LDValue...)
,
ifNotMatch(ContextKind, String, LDValue...)
public TestData.FlagBuilder.FlagRuleBuilder ifMatch(java.lang.String attribute, LDValue... values)
ifMatch(ContextKind, String, LDValue...)
with ContextKind.DEFAULT
as the
context kind.
For example, this creates a rule that returns true
if the name is "Patsy" or "Edina":
testData.flag("flag")
.ifMatch("name", LDValue.of("Patsy"), LDValue.of("Edina"))
.thenReturn(true));
attribute
- the user attribute to match againstvalues
- values to compare toTestData.FlagBuilder.FlagRuleBuilder
; call TestData.FlagBuilder.FlagRuleBuilder.thenReturn(boolean)
or
TestData.FlagBuilder.FlagRuleBuilder.thenReturn(int)
to finish the rule, or add more tests with another
method like TestData.FlagBuilder.FlagRuleBuilder.andMatch(String, LDValue...)
ifMatch(ContextKind, String, LDValue...)
,
ifNotMatch(String, LDValue...)
public TestData.FlagBuilder.FlagRuleBuilder ifNotMatch(ContextKind contextKind, java.lang.String attribute, LDValue... values)
For example, this creates a rule that returns true
if the name attribute for the
"company" context is neither "Pendant" nor "Sterling Cooper":
testData.flag("flag")
.ifNotMatch(ContextKind.of("company"), "name",
LDValue.of("Pendant"), LDValue.of("Sterling Cooper"))
.thenReturn(true));
contextKind
- the context kind to matchattribute
- the attribute to match againstvalues
- values to compare toTestData.FlagBuilder.FlagRuleBuilder
; call TestData.FlagBuilder.FlagRuleBuilder.thenReturn(boolean)
or
TestData.FlagBuilder.FlagRuleBuilder.thenReturn(int)
to finish the rule, or add more tests with another
method like TestData.FlagBuilder.FlagRuleBuilder.andMatch(ContextKind, String, LDValue...)
ifMatch(ContextKind, String, LDValue...)
,
ifNotMatch(String, LDValue...)
public TestData.FlagBuilder.FlagRuleBuilder ifNotMatch(java.lang.String attribute, LDValue... values)
ifNotMatch(ContextKind, String, LDValue...)
with ContextKind.DEFAULT
as the
context kind.
For example, this creates a rule that returns true
if the name is neither "Saffron" nor "Bubble":
testData.flag("flag")
.ifNotMatch("name", LDValue.of("Saffron"), LDValue.of("Bubble"))
.thenReturn(true));
attribute
- the user attribute to match againstvalues
- values to compare toTestData.FlagBuilder.FlagRuleBuilder
; call TestData.FlagBuilder.FlagRuleBuilder.thenReturn(boolean)
or
TestData.FlagBuilder.FlagRuleBuilder.thenReturn(int)
to finish the rule, or add more tests with another
method like TestData.FlagBuilder.FlagRuleBuilder.andMatch(String, LDValue...)
ifNotMatch(ContextKind, String, LDValue...)
,
ifMatch(String, LDValue...)
public TestData.FlagBuilder clearRules()
ifMatch(String, LDValue...)
.public TestData.FlagBuilder clearTargets()
variationForUser(String, boolean)
.public TestData.FlagBuilder samplingRatio(long samplingRatio)
samplingRatio
- the event sampling ratiopublic TestData.FlagBuilder migrationCheckRatio(long checkRatio)
checkRatio
- the check ratio