42
42
*/
43
43
class StatsigProviderTest {
44
44
45
- public static final String FLAG_NAME = "enabledFeature" ;
46
- public static final String CONFIG_FLAG_NAME = "alias" ;
47
- public static final String LAYER_FLAG_NAME = "alias" ;
48
- public static final String CONFIG_FLAG_VALUE = "test" ;
49
- public static final String INT_FLAG_NAME = "revision" ;
50
- public static final String LAYER_INT_FLAG_NAME = "revision" ;
51
- public static final Integer INT_FLAG_VALUE = 5 ;
52
- public static final String DOUBLE_FLAG_NAME = "price" ;
53
- public static final String LAYER_DOUBLE_FLAG_NAME = "price" ;
54
- public static final Double DOUBLE_FLAG_VALUE = 3.14 ;
55
- public static final String USERS_FLAG_NAME = "userIdMatching" ;
56
- public static final String PROPERTIES_FLAG_NAME = "emailMatching" ;
45
+ private static final String FLAG_NAME = "enabledFeature" ;
46
+ private static final String CONFIG_FLAG_NAME = "alias" ;
47
+ private static final String LAYER_FLAG_NAME = "alias" ;
48
+ private static final String CONFIG_FLAG_VALUE = "test" ;
49
+ private static final String INT_FLAG_NAME = "revision" ;
50
+ private static final String LAYER_INT_FLAG_NAME = "revision" ;
51
+ private static final Integer INT_FLAG_VALUE = 5 ;
52
+ private static final String DOUBLE_FLAG_NAME = "price" ;
53
+ private static final String LAYER_DOUBLE_FLAG_NAME = "price" ;
54
+ private static final Double DOUBLE_FLAG_VALUE = 3.14 ;
55
+ private static final String USERS_FLAG_NAME = "userIdMatching" ;
56
+ private static final String PROPERTIES_FLAG_NAME = "emailMatching" ;
57
+ private static final String TARGETING_KEY = "a-targeting-key" ;
57
58
private static StatsigProvider statsigProvider ;
58
59
private static Client client ;
59
60
@@ -115,10 +116,10 @@ static void shutdown() {
115
116
116
117
@ Test
117
118
void getBooleanEvaluation () {
118
- assertEquals (true , statsigProvider .getBooleanEvaluation (FLAG_NAME , false , new ImmutableContext ()).getValue ());
119
- assertEquals (true , client .getBooleanValue (FLAG_NAME , false ));
120
- assertEquals (false , statsigProvider .getBooleanEvaluation ("non-existing" , false , new ImmutableContext ()).getValue ());
121
- assertEquals (false , client .getBooleanValue ("non-existing" , false ));
119
+ assertEquals (true , statsigProvider .getBooleanEvaluation (FLAG_NAME , false , new ImmutableContext (TARGETING_KEY )).getValue ());
120
+ assertEquals (true , client .getBooleanValue (FLAG_NAME , false , new ImmutableContext ( TARGETING_KEY ) ));
121
+ assertEquals (false , statsigProvider .getBooleanEvaluation ("non-existing" , false , new ImmutableContext (TARGETING_KEY )).getValue ());
122
+ assertEquals (false , client .getBooleanValue ("non-existing" , false , new ImmutableContext ( TARGETING_KEY ) ));
122
123
123
124
// expected to succeed when https://github.com/statsig-io/java-server-sdk/issues/22 is resolved and adopted
124
125
// assertEquals(true, client.getBooleanValue("non-existing", true));
@@ -128,6 +129,7 @@ void getBooleanEvaluation() {
128
129
featureConfig .add ("type" , "CONFIG" );
129
130
featureConfig .add ("name" , "product" );
130
131
evaluationContext .add ("feature_config" , featureConfig );
132
+ evaluationContext .setTargetingKey (TARGETING_KEY );
131
133
assertEquals (true , statsigProvider .getBooleanEvaluation ("boolean" , false ,
132
134
evaluationContext ).getValue ());
133
135
}
@@ -139,6 +141,7 @@ void getStringEvaluation() {
139
141
featureConfig .add ("type" , "CONFIG" );
140
142
featureConfig .add ("name" , "product" );
141
143
evaluationContext .add ("feature_config" , featureConfig );
144
+ evaluationContext .setTargetingKey (TARGETING_KEY );
142
145
assertEquals (CONFIG_FLAG_VALUE , statsigProvider .getStringEvaluation (CONFIG_FLAG_NAME , "" ,
143
146
evaluationContext ).getValue ());
144
147
assertEquals (CONFIG_FLAG_VALUE , statsigProvider .getStringEvaluation (LAYER_FLAG_NAME , "" ,
@@ -153,6 +156,7 @@ void getObjectConfigEvaluation() {
153
156
featureConfig .add ("type" , "CONFIG" );
154
157
featureConfig .add ("name" , "object-config-name" );
155
158
evaluationContext .add ("feature_config" , featureConfig );
159
+ evaluationContext .setTargetingKey (TARGETING_KEY );
156
160
Value objectEvaluation = statsigProvider .getObjectEvaluation ("dummy" , new Value ("fallback" ),
157
161
evaluationContext ).getValue ();
158
162
@@ -168,6 +172,7 @@ void getObjectLayerEvaluation() {
168
172
featureConfig .add ("type" , "LAYER" );
169
173
featureConfig .add ("name" , "layer-name" );
170
174
evaluationContext .add ("feature_config" , featureConfig );
175
+ evaluationContext .setTargetingKey (TARGETING_KEY );
171
176
Value objectEvaluation = statsigProvider .getObjectEvaluation ("dummy" , new Value ("fallback" ),
172
177
evaluationContext ).getValue ();
173
178
@@ -184,6 +189,7 @@ void getIntegerEvaluation() {
184
189
featureConfig .add ("type" , "CONFIG" );
185
190
featureConfig .add ("name" , "product" );
186
191
evaluationContext .add ("feature_config" , featureConfig );
192
+ evaluationContext .setTargetingKey (TARGETING_KEY );
187
193
assertEquals (INT_FLAG_VALUE , statsigProvider .getIntegerEvaluation (INT_FLAG_NAME , 1 ,
188
194
evaluationContext ).getValue ());
189
195
assertEquals (INT_FLAG_VALUE , statsigProvider .getIntegerEvaluation (LAYER_INT_FLAG_NAME , 1 ,
@@ -201,6 +207,7 @@ void getDoubleEvaluation() {
201
207
featureConfig .add ("type" , "CONFIG" );
202
208
featureConfig .add ("name" , "product" );
203
209
evaluationContext .add ("feature_config" , featureConfig );
210
+ evaluationContext .setTargetingKey (TARGETING_KEY );
204
211
assertEquals (DOUBLE_FLAG_VALUE , statsigProvider .getDoubleEvaluation (DOUBLE_FLAG_NAME , 1.1 ,
205
212
evaluationContext ).getValue ());
206
213
assertEquals (DOUBLE_FLAG_VALUE , statsigProvider .getDoubleEvaluation (LAYER_DOUBLE_FLAG_NAME , 1.1 ,
@@ -314,6 +321,7 @@ void contextTransformTest() {
314
321
String locale = "locale1" ;
315
322
String customPropertyValue = "customProperty_value" ;
316
323
String customPropertyKey = "customProperty" ;
324
+ String targetingKeyKey = "targetingKey" ;
317
325
318
326
MutableContext evaluationContext = new MutableContext ();
319
327
evaluationContext .setTargetingKey (userId );
@@ -331,6 +339,7 @@ void contextTransformTest() {
331
339
332
340
HashMap <String , String > customMap = new HashMap <>();
333
341
customMap .put (customPropertyKey , customPropertyValue );
342
+ customMap .put (targetingKeyKey , userId );
334
343
StatsigUser expectedUser = new StatsigUser (evaluationContext .getTargetingKey ());
335
344
expectedUser .setEmail (email );
336
345
expectedUser .setCountry (country );
0 commit comments