public final class TestData.FlagBuilder.FlagRuleBuilder
extends java.lang.Object
TestData.FlagBuilder
.
In the LaunchDarkly model, a flag can have any number of rules, and a rule can have any number of clauses. A clause is an individual test such as "name is 'X'". A rule matches a user if all of the rule's clauses match the user.
To start defining a rule, use one of the flag builder's matching methods such as
TestData.FlagBuilder.ifMatch(UserAttribute, LDValue...)
. This defines the first clause for the rule.
Optionally, you may add more clauses with the rule builder's methods such as
andMatch(UserAttribute, LDValue...)
. Finally, call thenReturn(boolean)
or
thenReturn(int)
to finish defining the rule.
Constructor and Description |
---|
FlagRuleBuilder() |
Modifier and Type | Method and Description |
---|---|
TestData.FlagBuilder.FlagRuleBuilder |
andMatch(UserAttribute attribute,
LDValue... values)
Adds another clause, using the "is one of" operator.
|
TestData.FlagBuilder.FlagRuleBuilder |
andNotMatch(UserAttribute attribute,
LDValue... values)
Adds another clause, using the "is not one of" operator.
|
TestData.FlagBuilder |
thenReturn(boolean variation)
Finishes defining the rule, specifying the result value as a boolean.
|
TestData.FlagBuilder |
thenReturn(int variationIndex)
Finishes defining the rule, specifying the result as a variation index.
|
public TestData.FlagBuilder.FlagRuleBuilder andMatch(UserAttribute attribute, LDValue... values)
For example, this creates a rule that returns true
if the name is "Patsy" and the
country is "gb":
testData.flag("flag")
.ifMatch(UserAttribute.NAME, LDValue.of("Patsy"))
.andMatch(UserAttribute.COUNTRY, LDValue.of("gb"))
.thenReturn(true));
attribute
- the user attribute to match againstvalues
- values to compare topublic TestData.FlagBuilder.FlagRuleBuilder andNotMatch(UserAttribute attribute, LDValue... values)
For example, this creates a rule that returns true
if the name is "Patsy" and the
country is not "gb":
testData.flag("flag")
.ifMatch(UserAttribute.NAME, LDValue.of("Patsy"))
.andNotMatch(UserAttribute.COUNTRY, LDValue.of("gb"))
.thenReturn(true));
attribute
- the user attribute to match againstvalues
- values to compare topublic TestData.FlagBuilder thenReturn(boolean variation)
variation
- the value to return if the rule matches the userpublic TestData.FlagBuilder thenReturn(int variationIndex)
variationIndex
- the variation to return if the rule matches the user: 0 for the first, 1
for the second, etc.