use of com.optimizely.ab.config.Experiment in project java-sdk by optimizely.
the class ExperimentUtilsTest method isUserInExperimentReturnsTrueIfUserDoesNotSatisfyAnyAudiences.
/**
* If the attributes satisfies no {@link Condition} of any {@link Audience} of the {@link Experiment},
* then {@link ExperimentUtils#isUserInExperiment(ProjectConfig, Experiment, Map)} should return false.
*/
@Test
public void isUserInExperimentReturnsTrueIfUserDoesNotSatisfyAnyAudiences() {
Experiment experiment = projectConfig.getExperiments().get(0);
Map<String, String> attributes = Collections.singletonMap("browser_type", "firefox");
assertFalse(isUserInExperiment(projectConfig, experiment, attributes));
}
use of com.optimizely.ab.config.Experiment in project java-sdk by optimizely.
the class ExperimentUtilsTest method isUserInExperimentReturnsFalseIfExperimentHasAudiencesButUserHasNoAttributes.
/**
* If the {@link Experiment} contains at least one {@link Audience}, but attributes is empty,
* then {@link ExperimentUtils#isUserInExperiment(ProjectConfig, Experiment, Map)} should return false.
*/
@Test
public void isUserInExperimentReturnsFalseIfExperimentHasAudiencesButUserHasNoAttributes() {
Experiment experiment = projectConfig.getExperiments().get(0);
assertFalse(isUserInExperiment(projectConfig, experiment, Collections.<String, String>emptyMap()));
}
use of com.optimizely.ab.config.Experiment in project java-sdk by optimizely.
the class ExperimentUtilsTest method doesUserMeetAudienceConditionsReturnsTrueIfUserSatisfiesAnAudience.
/**
* If the attributes satisfies at least one {@link Condition} in an {@link Audience} of the {@link Experiment},
* then {@link ExperimentUtils#doesUserMeetAudienceConditions(ProjectConfig, Experiment, Map, String, String)} should return true.
*/
@Test
public void doesUserMeetAudienceConditionsReturnsTrueIfUserSatisfiesAnAudience() {
Experiment experiment = projectConfig.getExperiments().get(0);
Map<String, String> attributes = Collections.singletonMap("browser_type", "chrome");
Boolean result = doesUserMeetAudienceConditions(projectConfig, experiment, attributes, EXPERIMENT, experiment.getKey()).getResult();
assertTrue(result);
logbackVerifier.expectMessage(Level.DEBUG, "Evaluating audiences for experiment \"etag1\": [100].");
logbackVerifier.expectMessage(Level.DEBUG, "Starting to evaluate audience \"100\" with conditions: [and, [or, [not, [or, {name='browser_type', type='custom_attribute', match='null', value='firefox'}]]]].");
logbackVerifier.expectMessage(Level.DEBUG, "Audience \"100\" evaluated to true.");
logbackVerifier.expectMessage(Level.INFO, "Audiences for experiment \"etag1\" collectively evaluated to true.");
}
use of com.optimizely.ab.config.Experiment in project java-sdk by optimizely.
the class BucketerTest method bucketUserNotInExperiment.
/**
* Verify that {@link Bucketer#bucket(Experiment, String, ProjectConfig)} doesn't return a variation when a user isn't bucketed
* into the group experiment.
*/
@Test
public void bucketUserNotInExperiment() throws Exception {
final AtomicInteger bucketValue = new AtomicInteger();
Bucketer algorithm = testBucketAlgorithm(bucketValue);
bucketValue.set(3000);
ProjectConfig projectConfig = validProjectConfigV2();
List<Experiment> groupExperiments = projectConfig.getGroups().get(0).getExperiments();
Experiment groupExperiment = groupExperiments.get(1);
// the user should be bucketed to a different experiment than the one provided, resulting in no variation being
// returned.
logbackVerifier.expectMessage(Level.DEBUG, "Assigned bucket 3000 to user with bucketingId \"blah\" during experiment bucketing.");
logbackVerifier.expectMessage(Level.INFO, "User with bucketingId \"blah\" is not in experiment \"group_etag1\" of group 42");
assertNull(algorithm.bucket(groupExperiment, "blah", projectConfig).getResult());
}
use of com.optimizely.ab.config.Experiment in project java-sdk by optimizely.
the class BucketerTest method bucketUserToVariationInOverlappingGroupExperiment.
/**
* Verify that {@link Bucketer#bucket(Experiment, String, ProjectConfig)} returns a variation when the user falls into an
* experiment within an overlapping group.
*/
@Test
public void bucketUserToVariationInOverlappingGroupExperiment() throws Exception {
final AtomicInteger bucketValue = new AtomicInteger();
Bucketer algorithm = testBucketAlgorithm(bucketValue);
bucketValue.set(0);
ProjectConfig projectConfig = validProjectConfigV2();
List<Experiment> groupExperiments = projectConfig.getGroups().get(1).getExperiments();
Experiment groupExperiment = groupExperiments.get(0);
Variation expectedVariation = groupExperiment.getVariations().get(0);
logbackVerifier.expectMessage(Level.INFO, "User with bucketingId \"blah\" is in variation \"e1_vtag1\" of experiment \"overlapping_etag1\".");
assertThat(algorithm.bucket(groupExperiment, "blah", projectConfig).getResult(), is(expectedVariation));
}
Aggregations