Skip to content

Commit 31f8e6b

Browse files
[FSSDK-12337] Add experiment type constants for type-safe experiment type checks
1 parent 68c959f commit 31f8e6b

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

core-api/src/main/java/com/optimizely/ab/config/DatafileProjectConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ private List<Experiment> injectFeatureRolloutVariations(
403403
continue;
404404
}
405405
Experiment experiment = result.get(index);
406-
if (!"feature_rollout".equals(experiment.getType())) {
406+
if (!Experiment.TYPE_FR.equals(experiment.getType())) {
407407
continue;
408408
}
409409

core-api/src/main/java/com/optimizely/ab/config/Experiment.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ public class Experiment implements ExperimentCore {
5353
private final Map<String, Variation> variationIdToVariationMap;
5454
private final Map<String, String> userIdToVariationKeyMap;
5555

56+
public static final String TYPE_AB = "a/b";
57+
public static final String TYPE_MAB = "multi_armed_bandit";
58+
public static final String TYPE_CMAB = "contextual_multi_armed_bandit";
59+
public static final String TYPE_TD = "targeted_delivery";
60+
public static final String TYPE_FR = "feature_rollout";
61+
5662
public enum ExperimentStatus {
5763
RUNNING("Running"),
5864
LAUNCHED("Launched"),

core-api/src/test/java/com/optimizely/ab/config/FeatureRolloutConfigTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void experimentWithoutTypeFieldHasNullType() {
6363
public void featureRolloutExperimentGetsEveryoneElseVariationInjected() {
6464
Experiment experiment = projectConfig.getExperimentKeyMapping().get("feature_rollout_experiment");
6565
assertNotNull("Experiment should exist", experiment);
66-
assertEquals("feature_rollout", experiment.getType());
66+
assertEquals(Experiment.TYPE_FR, experiment.getType());
6767

6868
// Should have 2 variations: original + everyone else
6969
assertEquals("Should have 2 variations after injection", 2, experiment.getVariations().size());
@@ -107,7 +107,7 @@ public void variationMapsContainInjectedVariation() {
107107
public void abTestExperimentNotModified() {
108108
Experiment experiment = projectConfig.getExperimentKeyMapping().get("ab_test_experiment");
109109
assertNotNull("Experiment should exist", experiment);
110-
assertEquals("a/b", experiment.getType());
110+
assertEquals(Experiment.TYPE_AB, experiment.getType());
111111

112112
// Should still have exactly 2 original variations
113113
assertEquals("A/B test should keep original 2 variations", 2, experiment.getVariations().size());
@@ -127,7 +127,7 @@ public void abTestExperimentNotModified() {
127127
public void featureRolloutWithEmptyRolloutIdDoesNotCrash() {
128128
Experiment experiment = projectConfig.getExperimentKeyMapping().get("rollout_no_rollout_id_experiment");
129129
assertNotNull("Experiment should exist", experiment);
130-
assertEquals("feature_rollout", experiment.getType());
130+
assertEquals(Experiment.TYPE_FR, experiment.getType());
131131

132132
// Should keep only original variation since rollout cannot be resolved
133133
assertEquals("Should keep only original variation", 1, experiment.getVariations().size());
@@ -142,11 +142,11 @@ public void featureRolloutWithEmptyRolloutIdDoesNotCrash() {
142142
public void typeFieldCorrectlyParsed() {
143143
Experiment rolloutExp = projectConfig.getExperimentKeyMapping().get("feature_rollout_experiment");
144144
assertNotNull(rolloutExp);
145-
assertEquals("feature_rollout", rolloutExp.getType());
145+
assertEquals(Experiment.TYPE_FR, rolloutExp.getType());
146146

147147
Experiment abExp = projectConfig.getExperimentKeyMapping().get("ab_test_experiment");
148148
assertNotNull(abExp);
149-
assertEquals("a/b", abExp.getType());
149+
assertEquals(Experiment.TYPE_AB, abExp.getType());
150150

151151
Experiment noTypeExp = projectConfig.getExperimentKeyMapping().get("no_type_experiment");
152152
assertNotNull(noTypeExp);

0 commit comments

Comments
 (0)