|
1 |
| -package com.statsig.sdk; |
2 |
| - |
3 |
| -import kotlin.jvm.JvmStatic; |
4 |
| -import org.junit.*; |
5 |
| - |
6 |
| -import java.lang.reflect.Field; |
7 |
| -import java.util.HashMap; |
8 |
| -import java.util.Map; |
9 |
| -import java.util.concurrent.Future; |
10 |
| - |
11 |
| -import static org.junit.Assert.*; |
12 |
| - |
13 |
| -public class LocalOverridesTestJava { |
14 |
| - private Evaluator evaluator; |
15 |
| - private StatsigServer driver; |
16 |
| - private StatsigUser userA = new StatsigUser("user-a"); |
17 |
| - private StatsigUser userB = new StatsigUser(new HashMap<String, String>() {{ |
18 |
| - put("customID", "abc123"); |
19 |
| - }}); |
20 |
| - |
21 |
| - @Before |
22 |
| - @JvmStatic |
23 |
| - public void setUp() throws Exception { |
24 |
| - StatsigOptions options = new StatsigOptions(); |
25 |
| - options.setLocalMode(true); |
26 |
| - |
27 |
| - driver = StatsigServer.create("secret-local", options); |
28 |
| - Future initFuture = driver.initializeAsync(); |
29 |
| - initFuture.get(); |
30 |
| - |
31 |
| - evaluator = TestUtilJava.getEvaluatorFromStatsigServer(driver); |
32 |
| - } |
33 |
| - |
34 |
| - @Test |
35 |
| - public void testGateOverrides() throws Exception { |
36 |
| - assertEquals(userA.getCopyForLogging$StatsigSDK().getUserID(), "user-a"); |
37 |
| - assertEquals(userB.getCopyForLogging$StatsigSDK().getCustomIDs().get("customID"), "abc123"); |
38 |
| - assertEquals(userB.getCopyForLogging$StatsigSDK().getCustomIDs().size(), 1); |
39 |
| - |
40 |
| - assertFalse(driver.checkGateAsync(userA, "override_me").get()); |
41 |
| - |
42 |
| - evaluator.overrideGate("override_me", true); |
43 |
| - assertTrue(driver.checkGateAsync(userA, "override_me").get()); |
44 |
| - assertTrue(driver.checkGateAsync(userB, "override_me").get()); |
45 |
| - |
46 |
| - evaluator.overrideGate("override_me", false); |
47 |
| - assertFalse(driver.checkGateAsync(userB, "override_me").get()); |
48 |
| - } |
49 |
| - |
50 |
| - @Test |
51 |
| - public void testConfigOverrides() throws Exception { |
52 |
| - assertEquals(userA.getCopyForLogging$StatsigSDK().getUserID(), "user-a"); |
53 |
| - assertEquals(userB.getCopyForLogging$StatsigSDK().getCustomIDs().get("customID"), "abc123"); |
54 |
| - assertEquals(userB.getCopyForLogging$StatsigSDK().getCustomIDs().size(), 1); |
55 |
| - |
56 |
| - Map<String, String> emptyMap = new HashMap<>(); |
57 |
| - |
58 |
| - assertEquals(driver.getConfigAsync(userA, "override_me").get().getValue(), emptyMap); |
59 |
| - |
60 |
| - Map<String, String> overriddenValue = new HashMap<>(); |
61 |
| - overriddenValue.put("hello", "its me"); |
62 |
| - evaluator.overrideConfig("override_me", overriddenValue); |
63 |
| - |
64 |
| - assertEquals(driver.getConfigAsync(userA, "override_me").get().getValue(), overriddenValue); |
65 |
| - |
66 |
| - overriddenValue.put("hello", "its no longer me"); |
67 |
| - evaluator.overrideConfig("override_me", overriddenValue); |
68 |
| - assertEquals(driver.getConfigAsync(userB, "override_me").get().getValue(), overriddenValue); |
69 |
| - |
70 |
| - evaluator.overrideConfig("override_me", emptyMap); |
71 |
| - assertEquals(driver.getConfigAsync(userB, "override_me").get().getValue(), emptyMap); |
72 |
| - } |
73 |
| -} |
| 1 | +//package com.statsig.sdk; |
| 2 | +// |
| 3 | +//import kotlin.jvm.JvmStatic; |
| 4 | +//import org.junit.*; |
| 5 | +// |
| 6 | +//import java.lang.reflect.Field; |
| 7 | +//import java.util.HashMap; |
| 8 | +//import java.util.Map; |
| 9 | +//import java.util.concurrent.Future; |
| 10 | +// |
| 11 | +//import static org.junit.Assert.*; |
| 12 | +// |
| 13 | +//public class LocalOverridesTestJava { |
| 14 | +// private Evaluator evaluator; |
| 15 | +// private StatsigServer driver; |
| 16 | +// private StatsigUser userA = new StatsigUser("user-a"); |
| 17 | +// private StatsigUser userB = new StatsigUser(new HashMap<String, String>() {{ |
| 18 | +// put("customID", "abc123"); |
| 19 | +// }}); |
| 20 | +// |
| 21 | +// @Before |
| 22 | +// @JvmStatic |
| 23 | +// public void setUp() throws Exception { |
| 24 | +// StatsigOptions options = new StatsigOptions(); |
| 25 | +// options.setLocalMode(true); |
| 26 | +// |
| 27 | +// driver = StatsigServer.create("secret-local", options); |
| 28 | +// Future initFuture = driver.initializeAsync(); |
| 29 | +// initFuture.get(); |
| 30 | +// |
| 31 | +// evaluator = TestUtilJava.getEvaluatorFromStatsigServer(driver); |
| 32 | +// } |
| 33 | +// |
| 34 | +// @Test |
| 35 | +// public void testGateOverrides() throws Exception { |
| 36 | +// assertEquals(userA.getCopyForLogging$StatsigSDK().getUserID(), "user-a"); |
| 37 | +// assertEquals(userB.getCopyForLogging$StatsigSDK().getCustomIDs().get("customID"), "abc123"); |
| 38 | +// assertEquals(userB.getCopyForLogging$StatsigSDK().getCustomIDs().size(), 1); |
| 39 | +// |
| 40 | +// assertFalse(driver.checkGateAsync(userA, "override_me").get()); |
| 41 | +// |
| 42 | +// evaluator.overrideGate("override_me", true); |
| 43 | +// assertTrue(driver.checkGateAsync(userA, "override_me").get()); |
| 44 | +// assertTrue(driver.checkGateAsync(userB, "override_me").get()); |
| 45 | +// |
| 46 | +// evaluator.overrideGate("override_me", false); |
| 47 | +// assertFalse(driver.checkGateAsync(userB, "override_me").get()); |
| 48 | +// } |
| 49 | +// |
| 50 | +// @Test |
| 51 | +// public void testConfigOverrides() throws Exception { |
| 52 | +// assertEquals(userA.getCopyForLogging$StatsigSDK().getUserID(), "user-a"); |
| 53 | +// assertEquals(userB.getCopyForLogging$StatsigSDK().getCustomIDs().get("customID"), "abc123"); |
| 54 | +// assertEquals(userB.getCopyForLogging$StatsigSDK().getCustomIDs().size(), 1); |
| 55 | +// |
| 56 | +// Map<String, String> emptyMap = new HashMap<>(); |
| 57 | +// |
| 58 | +// assertEquals(driver.getConfigAsync(userA, "override_me").get().getValue(), emptyMap); |
| 59 | +// |
| 60 | +// Map<String, String> overriddenValue = new HashMap<>(); |
| 61 | +// overriddenValue.put("hello", "its me"); |
| 62 | +// evaluator.overrideConfig("override_me", overriddenValue); |
| 63 | +// |
| 64 | +// assertEquals(driver.getConfigAsync(userA, "override_me").get().getValue(), overriddenValue); |
| 65 | +// |
| 66 | +// overriddenValue.put("hello", "its no longer me"); |
| 67 | +// evaluator.overrideConfig("override_me", overriddenValue); |
| 68 | +// assertEquals(driver.getConfigAsync(userB, "override_me").get().getValue(), overriddenValue); |
| 69 | +// |
| 70 | +// evaluator.overrideConfig("override_me", emptyMap); |
| 71 | +// assertEquals(driver.getConfigAsync(userB, "override_me").get().getValue(), emptyMap); |
| 72 | +// } |
| 73 | +//} |
0 commit comments