@@ -1283,7 +1283,7 @@ public void testGetEnabledFeaturesWithInValidUserIDandValidAttributes(){
12831283 * return empty List of enabledFeatures
12841284 */
12851285 @ Test
1286- public void testGetEnabledFeaturesWithValidUserIDAndInvalidAttributes (){
1286+ public void testGetEnabledFeaturesWithValidUserIDAndInvalidAttributes () {
12871287 assumeTrue (datafileVersion == Integer .parseInt (ProjectConfig .Version .V4 .toString ()));
12881288 OptimizelyClient optimizelyClient = new OptimizelyClient (
12891289 optimizely ,
@@ -1293,6 +1293,87 @@ public void testGetEnabledFeaturesWithValidUserIDAndInvalidAttributes(){
12931293 Collections .singletonMap ("invalidKey" , "invalidVal" ));
12941294 assertTrue (enabledFeatures .isEmpty ());
12951295 }
1296+
1297+ /**
1298+ * Verify {@link Optimizely#isFeatureEnabled(String, String, Map)}
1299+ * returns True
1300+ * when the user is bucketed into a variation for the feature.
1301+ * The user is also bucketed into an experiment
1302+ * and featureEnabled is also set to true
1303+ */
1304+ @ Test
1305+ public void testIsFeatureEnabledWithFeatureEnabledTrue (){
1306+ assumeTrue (datafileVersion == Integer .parseInt (ProjectConfig .Version .V4 .toString ()));
1307+ OptimizelyClient optimizelyClient = new OptimizelyClient (
1308+ optimizely ,
1309+ logger
1310+ );
1311+
1312+ //with valid attributes
1313+ assertTrue (optimizelyClient .isFeatureEnabled (
1314+ FEATURE_MULTI_VARIATE_FEATURE_KEY ,
1315+ GENERIC_USER_ID ,
1316+ Collections .singletonMap ("house" , "Gryffindor" )
1317+ ));
1318+
1319+ verifyZeroInteractions (logger );
1320+
1321+ }
1322+
1323+ /**
1324+ * Verify using forced variation to force the user into the fourth variation of experiment
1325+ * FEATURE_MULTI_VARIATE_EXPERIMENT_KEY in which FeatureEnabled is set to
1326+ * false so {@link Optimizely#isFeatureEnabled(String, String, Map)} will return false
1327+ */
1328+ @ Test
1329+ public void testIsFeatureEnabledWithfeatureEnabledFalse (){
1330+ assumeTrue (datafileVersion == Integer .parseInt (ProjectConfig .Version .V4 .toString ()));
1331+ OptimizelyClient optimizelyClient = new OptimizelyClient (
1332+ optimizely ,
1333+ logger
1334+ );
1335+ Experiment activatedExperiment = optimizelyClient .getProjectConfig ().getExperimentKeyMapping ().get (
1336+ FEATURE_MULTI_VARIATE_EXPERIMENT_KEY );
1337+ Variation forcedVariation = activatedExperiment .getVariations ().get (3 );
1338+ optimizelyClient .setForcedVariation (
1339+ activatedExperiment .getKey (),
1340+ GENERIC_USER_ID ,
1341+ forcedVariation .getKey ()
1342+ );
1343+ assertFalse (optimizelyClient .isFeatureEnabled (
1344+ FEATURE_MULTI_VARIATE_FEATURE_KEY ,
1345+ GENERIC_USER_ID ,
1346+ Collections .singletonMap ("house" , "Gryffindor" )
1347+ ));
1348+ }
1349+
1350+ /**
1351+ * Verify using forced variation to force the user into the third variation of experiment
1352+ * FEATURE_MULTI_VARIATE_EXPERIMENT_KEY in which FeatureEnabled is not set so by default it should return
1353+ * false so {@link Optimizely#isFeatureEnabled(String, String, Map)} will return false
1354+ */
1355+ @ Test
1356+ public void testIsFeatureEnabledWithfeatureEnabledNotSet () {
1357+ assumeTrue (datafileVersion == Integer .parseInt (ProjectConfig .Version .V4 .toString ()));
1358+ OptimizelyClient optimizelyClient = new OptimizelyClient (
1359+ optimizely ,
1360+ logger
1361+ );
1362+ Experiment activatedExperiment = optimizelyClient .getProjectConfig ().getExperimentKeyMapping ().get (
1363+ FEATURE_MULTI_VARIATE_EXPERIMENT_KEY );
1364+ Variation forcedVariation = activatedExperiment .getVariations ().get (2 );
1365+ optimizelyClient .setForcedVariation (
1366+ activatedExperiment .getKey (),
1367+ GENERIC_USER_ID ,
1368+ forcedVariation .getKey ()
1369+ );
1370+ assertFalse (optimizelyClient .isFeatureEnabled (
1371+ FEATURE_MULTI_VARIATE_FEATURE_KEY ,
1372+ GENERIC_USER_ID ,
1373+ Collections .singletonMap ("house" , "Gryffindor" )
1374+ ));
1375+ }
1376+
12961377 //=======Feature Variables Testing===========
12971378
12981379 /* FeatureVariableBoolean
@@ -1725,5 +1806,4 @@ public void testBadGetFeatureVariableString() {
17251806 GENERIC_USER_ID
17261807 );
17271808 }
1728-
17291809}
0 commit comments