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));
}
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));
}
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");
}
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);
}
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");
}
Aggregations