use of com.optimizely.ab.bucketing.UserProfileService in project java-sdk by optimizely.
the class OptimizelyUserContextTest method decideReasons_gotVariationFromUserProfile.
@Test
public void decideReasons_gotVariationFromUserProfile() throws Exception {
// embedding experiment: "exp_no_audience"
String flagKey = "feature_2";
// "exp_no_audience"
String experimentId = "10420810910";
String experimentKey = "exp_no_audience";
String variationId2 = "10418510624";
String variationKey2 = "variation_no_traffic";
UserProfileService ups = mock(UserProfileService.class);
when(ups.lookup(userId)).thenReturn(createUserProfileMap(experimentId, variationId2));
optimizely = new Optimizely.Builder().withDatafile(datafile).withUserProfileService(ups).build();
OptimizelyUserContext user = optimizely.createUserContext(userId);
OptimizelyDecision decision = user.decide(flagKey, Arrays.asList(OptimizelyDecideOption.INCLUDE_REASONS));
assertTrue(decision.getReasons().contains(String.format("Returning previously activated variation \"%s\" of experiment \"%s\" for user \"%s\" from user profile.", variationKey2, experimentKey, userId)));
}
use of com.optimizely.ab.bucketing.UserProfileService in project java-sdk by optimizely.
the class OptimizelyBuilderTest method withUserProfileService.
@Test
public void withUserProfileService() throws Exception {
UserProfileService userProfileService = mock(UserProfileService.class);
Optimizely optimizelyClient = Optimizely.builder(validConfigJsonV2(), mockEventHandler).withUserProfileService(userProfileService).build();
assertThat(optimizelyClient.getUserProfileService(), is(userProfileService));
}
use of com.optimizely.ab.bucketing.UserProfileService in project java-sdk by optimizely.
the class OptimizelyUserContextTest method decideOptions_bypassUPS.
// options
@Test
public void decideOptions_bypassUPS() throws Exception {
// embedding experiment: "exp_no_audience"
String flagKey = "feature_2";
// "exp_no_audience"
String experimentId = "10420810910";
String variationId1 = "10418551353";
String variationId2 = "10418510624";
String variationKey1 = "variation_with_traffic";
String variationKey2 = "variation_no_traffic";
UserProfileService ups = mock(UserProfileService.class);
when(ups.lookup(userId)).thenReturn(createUserProfileMap(experimentId, variationId2));
optimizely = new Optimizely.Builder().withDatafile(datafile).withUserProfileService(ups).build();
OptimizelyUserContext user = optimizely.createUserContext(userId);
OptimizelyDecision decision = user.decide(flagKey);
// should return variationId2 set by UPS
assertEquals(decision.getVariationKey(), variationKey2);
decision = user.decide(flagKey, Arrays.asList(OptimizelyDecideOption.IGNORE_USER_PROFILE_SERVICE));
// should ignore variationId2 set by UPS and return variationId1
assertEquals(decision.getVariationKey(), variationKey1);
// also should not save either
verify(ups, never()).save(anyObject());
}
Aggregations