Search in sources :

Example 46 with Experiment

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));
}
Also used : Experiment(com.optimizely.ab.config.Experiment) ExperimentUtils.isUserInExperiment(com.optimizely.ab.internal.ExperimentUtils.isUserInExperiment) Test(org.junit.Test)

Example 47 with Experiment

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()));
}
Also used : Experiment(com.optimizely.ab.config.Experiment) ExperimentUtils.isUserInExperiment(com.optimizely.ab.internal.ExperimentUtils.isUserInExperiment) Test(org.junit.Test)

Example 48 with Experiment

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.");
}
Also used : Experiment(com.optimizely.ab.config.Experiment) Test(org.junit.Test)

Example 49 with Experiment

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());
}
Also used : ProjectConfig(com.optimizely.ab.config.ProjectConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Experiment(com.optimizely.ab.config.Experiment) Test(org.junit.Test) ExhaustiveTest(com.optimizely.ab.categories.ExhaustiveTest)

Example 50 with Experiment

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));
}
Also used : ProjectConfig(com.optimizely.ab.config.ProjectConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Experiment(com.optimizely.ab.config.Experiment) Variation(com.optimizely.ab.config.Variation) Test(org.junit.Test) ExhaustiveTest(com.optimizely.ab.categories.ExhaustiveTest)

Aggregations

Experiment (com.optimizely.ab.config.Experiment)125 Test (org.junit.Test)108 Variation (com.optimizely.ab.config.Variation)77 Matchers.anyString (org.mockito.Matchers.anyString)44 LogEvent (com.optimizely.ab.event.LogEvent)42 HashMap (java.util.HashMap)36 EventType (com.optimizely.ab.config.EventType)24 EventBuilder (com.optimizely.ab.event.internal.EventBuilder)23 ProjectConfig (com.optimizely.ab.config.ProjectConfig)19 Map (java.util.Map)14 EventBatch (com.optimizely.ab.event.internal.payload.EventBatch)12 ImmutableMap (com.google.common.collect.ImmutableMap)11 Attribute (com.optimizely.ab.config.Attribute)11 EventBuilderTest.createExperimentVariationMap (com.optimizely.ab.event.internal.EventBuilderTest.createExperimentVariationMap)11 Bucketer (com.optimizely.ab.bucketing.Bucketer)9 ExhaustiveTest (com.optimizely.ab.categories.ExhaustiveTest)9 Rollout (com.optimizely.ab.config.Rollout)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 DecisionService (com.optimizely.ab.bucketing.DecisionService)8 ArrayList (java.util.ArrayList)8