Search in sources :

Example 41 with ProjectConfig

use of com.optimizely.ab.config.ProjectConfig in project java-sdk by optimizely.

the class BucketerTest method testBucketWithBucketingId.

@Test
public void testBucketWithBucketingId() {
    final AtomicInteger bucketValue = new AtomicInteger();
    Bucketer algorithm = testBucketAlgorithm(bucketValue);
    bucketValue.set(0);
    String bucketingId = "blah";
    String userId = "blahUser";
    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 \"" + bucketingId + "\" is in variation \"e1_vtag1\" of experiment \"overlapping_etag1\".");
    assertThat(algorithm.bucket(groupExperiment, bucketingId, 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)

Example 42 with ProjectConfig

use of com.optimizely.ab.config.ProjectConfig in project java-sdk by optimizely.

the class DefaultConfigParserTest method testPropertyDefaultParser.

/**
 * This method is to test DefaultConfigParser when different default_parser gets set.
 * For example: when optimizely_default_parser environment variable will be set to "GSON_CONFIG_PARSER" than
 * "DefaultConfigParser.getInstance()" returns "GsonConfigParser" and parse ProjectConfig using it. Also
 * this test will assertThat "configParser" (Provided in env variable) is instance of "GsonConfigParser.class"
 *
 * @throws Exception
 */
@Test
public void testPropertyDefaultParser() throws Exception {
    String defaultParser = PropertyUtils.get("default_parser");
    ConfigParser configParser = DefaultConfigParser.getInstance();
    ProjectConfig actual = configParser.parseProjectConfig(validDatafile);
    ProjectConfig expected = validProjectConfig;
    verifyProjectConfig(actual, expected);
    Class expectedParser = GsonConfigParser.class;
    if (defaultParser != null) {
        DefaultConfigParser.ConfigParserSupplier defaultParserSupplier = DefaultConfigParser.ConfigParserSupplier.valueOf(defaultParser);
        switch(defaultParserSupplier) {
            case GSON_CONFIG_PARSER:
                expectedParser = GsonConfigParser.class;
                break;
            case JACKSON_CONFIG_PARSER:
                expectedParser = JacksonConfigParser.class;
                break;
            case JSON_CONFIG_PARSER:
                expectedParser = JsonConfigParser.class;
                break;
            case JSON_SIMPLE_CONFIG_PARSER:
                expectedParser = JsonSimpleConfigParser.class;
                break;
            default:
                fail("Not a valid config parser");
        }
    }
    Assert.assertThat(configParser, CoreMatchers.instanceOf(expectedParser));
}
Also used : ProjectConfig(com.optimizely.ab.config.ProjectConfig) Test(org.junit.Test)

Example 43 with ProjectConfig

use of com.optimizely.ab.config.ProjectConfig in project java-sdk by optimizely.

the class JacksonConfigParserTest method parseFeatureVariablesWithFutureType.

@Test
public void parseFeatureVariablesWithFutureType() throws Exception {
    JsonSimpleConfigParser parser = new JsonSimpleConfigParser();
    ProjectConfig actual = parser.parseProjectConfig(validConfigJsonV4());
    // unknown type
    FeatureFlag featureFlag = actual.getFeatureKeyMapping().get("multi_variate_future_feature");
    FeatureVariable variable = featureFlag.getVariableKeyToFeatureVariableMap().get("future_variable");
    assertEquals(variable.getType(), "future_type");
}
Also used : DatafileProjectConfigTestUtils.verifyProjectConfig(com.optimizely.ab.config.DatafileProjectConfigTestUtils.verifyProjectConfig) ProjectConfig(com.optimizely.ab.config.ProjectConfig) FeatureFlag(com.optimizely.ab.config.FeatureFlag) FeatureVariable(com.optimizely.ab.config.FeatureVariable) Test(org.junit.Test)

Example 44 with ProjectConfig

use of com.optimizely.ab.config.ProjectConfig in project java-sdk by optimizely.

the class JacksonConfigParserTest method parseProjectConfigV4.

@Test
public void parseProjectConfigV4() throws Exception {
    JacksonConfigParser parser = new JacksonConfigParser();
    ProjectConfig actual = parser.parseProjectConfig(validConfigJsonV4());
    ProjectConfig expected = validProjectConfigV4();
    verifyProjectConfig(actual, expected);
}
Also used : DatafileProjectConfigTestUtils.verifyProjectConfig(com.optimizely.ab.config.DatafileProjectConfigTestUtils.verifyProjectConfig) ProjectConfig(com.optimizely.ab.config.ProjectConfig) Test(org.junit.Test)

Example 45 with ProjectConfig

use of com.optimizely.ab.config.ProjectConfig in project java-sdk by optimizely.

the class JacksonConfigParserTest method parseFeatureVariablesWithJsonNative.

@Test
public void parseFeatureVariablesWithJsonNative() throws Exception {
    JsonSimpleConfigParser parser = new JsonSimpleConfigParser();
    ProjectConfig actual = parser.parseProjectConfig(validConfigJsonV4());
    // native "json" type
    FeatureFlag featureFlag = actual.getFeatureKeyMapping().get("multi_variate_future_feature");
    FeatureVariable variable = featureFlag.getVariableKeyToFeatureVariableMap().get("json_native");
    assertEquals(variable.getType(), "json");
}
Also used : DatafileProjectConfigTestUtils.verifyProjectConfig(com.optimizely.ab.config.DatafileProjectConfigTestUtils.verifyProjectConfig) ProjectConfig(com.optimizely.ab.config.ProjectConfig) FeatureFlag(com.optimizely.ab.config.FeatureFlag) FeatureVariable(com.optimizely.ab.config.FeatureVariable) Test(org.junit.Test)

Aggregations

ProjectConfig (com.optimizely.ab.config.ProjectConfig)51 Test (org.junit.Test)45 DatafileProjectConfigTestUtils.verifyProjectConfig (com.optimizely.ab.config.DatafileProjectConfigTestUtils.verifyProjectConfig)28 Experiment (com.optimizely.ab.config.Experiment)19 FeatureFlag (com.optimizely.ab.config.FeatureFlag)14 FeatureVariable (com.optimizely.ab.config.FeatureVariable)12 LogEvent (com.optimizely.ab.event.LogEvent)10 Variation (com.optimizely.ab.config.Variation)9 Attribute (com.optimizely.ab.config.Attribute)7 EventBatch (com.optimizely.ab.event.internal.payload.EventBatch)7 ExhaustiveTest (com.optimizely.ab.categories.ExhaustiveTest)6 EventType (com.optimizely.ab.config.EventType)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 HashMap (java.util.HashMap)3 DecisionService (com.optimizely.ab.bucketing.DecisionService)2 Group (com.optimizely.ab.config.Group)2 LiveVariable (com.optimizely.ab.config.LiveVariable)2 Rollout (com.optimizely.ab.config.Rollout)2 Audience (com.optimizely.ab.config.audience.Audience)2 EventBuilder (com.optimizely.ab.event.internal.EventBuilder)2