|
5 | 5 | import org.junit.Test; |
6 | 6 |
|
7 | 7 | import java.io.IOException; |
| 8 | +import java.io.ObjectInput; |
| 9 | +import java.util.concurrent.ExecutionException; |
8 | 10 | import java.util.concurrent.Future; |
9 | 11 | import java.util.concurrent.TimeUnit; |
10 | 12 | import java.util.concurrent.TimeoutException; |
11 | 13 |
|
12 | 14 | import static org.easymock.EasyMock.anyObject; |
13 | 15 | import static org.easymock.EasyMock.expect; |
14 | 16 | import static org.junit.Assert.assertEquals; |
| 17 | +import static org.junit.Assert.assertFalse; |
15 | 18 | import static org.junit.Assert.assertTrue; |
16 | 19 |
|
17 | 20 | public class LDClientTest extends EasyMockSupport { |
@@ -45,6 +48,76 @@ public void testOffline() throws IOException { |
45 | 48 | verifyAll(); |
46 | 49 | } |
47 | 50 |
|
| 51 | + @Test |
| 52 | + public void testTestFeatureStoreFlagOn() throws IOException, InterruptedException, ExecutionException, TimeoutException { |
| 53 | + TestFeatureStore testFeatureStore = new TestFeatureStore(); |
| 54 | + LDConfig config = new LDConfig.Builder() |
| 55 | + .startWaitMillis(10L) |
| 56 | + .stream(false) |
| 57 | + .featureStore(testFeatureStore) |
| 58 | + .build(); |
| 59 | + |
| 60 | + expect(initFuture.get(10L, TimeUnit.MILLISECONDS)).andReturn(new Object()); |
| 61 | + expect(pollingProcessor.start()).andReturn(initFuture); |
| 62 | + expect(pollingProcessor.initialized()).andReturn(true).times(1); |
| 63 | + expect(eventProcessor.sendEvent(anyObject(Event.class))).andReturn(true); |
| 64 | + replayAll(); |
| 65 | + |
| 66 | + client = createMockClient(config); |
| 67 | + testFeatureStore.turnFeatureOn("key"); |
| 68 | + assertTrue("Test flag should be on, but was not.", client.toggle("key", new LDUser("user"), false)); |
| 69 | + |
| 70 | + verifyAll(); |
| 71 | + } |
| 72 | + |
| 73 | + @Test |
| 74 | + public void testTestFeatureStoreFlagOff() throws IOException, InterruptedException, ExecutionException, TimeoutException { |
| 75 | + TestFeatureStore testFeatureStore = new TestFeatureStore(); |
| 76 | + LDConfig config = new LDConfig.Builder() |
| 77 | + .startWaitMillis(10L) |
| 78 | + .stream(false) |
| 79 | + .featureStore(testFeatureStore) |
| 80 | + .build(); |
| 81 | + |
| 82 | + expect(initFuture.get(10L, TimeUnit.MILLISECONDS)).andReturn(new Object()); |
| 83 | + expect(pollingProcessor.start()).andReturn(initFuture); |
| 84 | + expect(pollingProcessor.initialized()).andReturn(true).times(1); |
| 85 | + expect(eventProcessor.sendEvent(anyObject(Event.class))).andReturn(true); |
| 86 | + replayAll(); |
| 87 | + |
| 88 | + client = createMockClient(config); |
| 89 | + testFeatureStore.turnFeatureOff("key"); |
| 90 | + assertFalse("Test flag should be off, but was on (the default).", client.toggle("key", new LDUser("user"), true)); |
| 91 | + |
| 92 | + verifyAll(); |
| 93 | + } |
| 94 | + |
| 95 | + @Test |
| 96 | + public void testTestFeatureStoreFlagOnThenOff() throws IOException, InterruptedException, ExecutionException, TimeoutException { |
| 97 | + TestFeatureStore testFeatureStore = new TestFeatureStore(); |
| 98 | + LDConfig config = new LDConfig.Builder() |
| 99 | + .startWaitMillis(10L) |
| 100 | + .stream(false) |
| 101 | + .featureStore(testFeatureStore) |
| 102 | + .build(); |
| 103 | + |
| 104 | + expect(initFuture.get(10L, TimeUnit.MILLISECONDS)).andReturn(new Object()); |
| 105 | + expect(pollingProcessor.start()).andReturn(initFuture); |
| 106 | + expect(pollingProcessor.initialized()).andReturn(true).times(2); |
| 107 | + expect(eventProcessor.sendEvent(anyObject(Event.class))).andReturn(true).times(2); |
| 108 | + replayAll(); |
| 109 | + |
| 110 | + client = createMockClient(config); |
| 111 | + |
| 112 | + testFeatureStore.turnFeatureOn("key"); |
| 113 | + assertTrue("Test flag should be on, but was not.", client.toggle("key", new LDUser("user"), false)); |
| 114 | + |
| 115 | + testFeatureStore.turnFeatureOff("key"); |
| 116 | + assertFalse("Test flag should be off, but was on (the default).", client.toggle("key", new LDUser("user"), true)); |
| 117 | + |
| 118 | + verifyAll(); |
| 119 | + } |
| 120 | + |
48 | 121 | @Test |
49 | 122 | public void testUseLdd() throws IOException { |
50 | 123 | LDConfig config = new LDConfig.Builder() |
|
0 commit comments