Search in sources :

Example 1 with FeatureVariable

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

the class GsonHelpers method parseFeatureFlag.

static FeatureFlag parseFeatureFlag(JsonObject featureFlagJson, JsonDeserializationContext context) {
    String id = featureFlagJson.get("id").getAsString();
    String key = featureFlagJson.get("key").getAsString();
    String layerId = featureFlagJson.get("rolloutId").getAsString();
    JsonArray experimentIdsJson = featureFlagJson.getAsJsonArray("experimentIds");
    List<String> experimentIds = new ArrayList<String>();
    for (JsonElement experimentIdObj : experimentIdsJson) {
        experimentIds.add(experimentIdObj.getAsString());
    }
    List<FeatureVariable> FeatureVariables = new ArrayList<>();
    try {
        Type FeatureVariableType = new TypeToken<List<FeatureVariable>>() {
        }.getType();
        FeatureVariables = context.deserialize(featureFlagJson.getAsJsonArray("variables"), FeatureVariableType);
    } catch (JsonParseException exception) {
        logger.warn("Unable to parse variables for feature \"" + key + "\". JsonParseException: " + exception);
    }
    return new FeatureFlag(id, key, layerId, experimentIds, FeatureVariables);
}
Also used : JsonArray(com.google.gson.JsonArray) Type(java.lang.reflect.Type) JsonElement(com.google.gson.JsonElement) ArrayList(java.util.ArrayList) FeatureFlag(com.optimizely.ab.config.FeatureFlag) ArrayList(java.util.ArrayList) List(java.util.List) JsonParseException(com.google.gson.JsonParseException) FeatureVariable(com.optimizely.ab.config.FeatureVariable)

Example 2 with FeatureVariable

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

the class GsonConfigParserTest 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 : ProjectConfig(com.optimizely.ab.config.ProjectConfig) DatafileProjectConfigTestUtils.verifyProjectConfig(com.optimizely.ab.config.DatafileProjectConfigTestUtils.verifyProjectConfig) FeatureFlag(com.optimizely.ab.config.FeatureFlag) FeatureVariable(com.optimizely.ab.config.FeatureVariable) Test(org.junit.Test)

Example 3 with FeatureVariable

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

the class JsonConfigParserTest method parseFeatureVariablesWithJsonPatched.

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

Example 4 with FeatureVariable

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

the class JsonSimpleConfigParserTest 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 : ProjectConfig(com.optimizely.ab.config.ProjectConfig) DatafileProjectConfigTestUtils.verifyProjectConfig(com.optimizely.ab.config.DatafileProjectConfigTestUtils.verifyProjectConfig) FeatureFlag(com.optimizely.ab.config.FeatureFlag) FeatureVariable(com.optimizely.ab.config.FeatureVariable) Test(org.junit.Test)

Example 5 with FeatureVariable

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

the class JsonSimpleConfigParserTest 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 : ProjectConfig(com.optimizely.ab.config.ProjectConfig) DatafileProjectConfigTestUtils.verifyProjectConfig(com.optimizely.ab.config.DatafileProjectConfigTestUtils.verifyProjectConfig) FeatureFlag(com.optimizely.ab.config.FeatureFlag) FeatureVariable(com.optimizely.ab.config.FeatureVariable) Test(org.junit.Test)

Aggregations

FeatureFlag (com.optimizely.ab.config.FeatureFlag)13 FeatureVariable (com.optimizely.ab.config.FeatureVariable)13 DatafileProjectConfigTestUtils.verifyProjectConfig (com.optimizely.ab.config.DatafileProjectConfigTestUtils.verifyProjectConfig)12 ProjectConfig (com.optimizely.ab.config.ProjectConfig)12 Test (org.junit.Test)12 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonParseException (com.google.gson.JsonParseException)1 Type (java.lang.reflect.Type)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1