-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSwitcherSilentModeTest.java
More file actions
82 lines (62 loc) · 2.2 KB
/
SwitcherSilentModeTest.java
File metadata and controls
82 lines (62 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package com.github.switcherapi.client;
import com.github.switcherapi.Switchers;
import com.github.switcherapi.client.model.SwitcherRequest;
import com.github.switcherapi.fixture.CountDownHelper;
import com.github.switcherapi.fixture.MockWebServerHelper;
import mockwebserver3.QueueDispatcher;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.file.Paths;
import static org.junit.jupiter.api.Assertions.assertTrue;
class SwitcherSilentModeTest extends MockWebServerHelper {
private static final String SNAPSHOTS_LOCAL = Paths.get(StringUtils.EMPTY).toAbsolutePath() + "/src/test/resources/snapshot";
@BeforeAll
static void setup() throws IOException {
MockWebServerHelper.setupMockServer();
Switchers.loadProperties();
Switchers.configure(ContextBuilder.builder().url(String.format("http://localhost:%s", mockBackEnd.getPort())));
}
@AfterAll
static void tearDown() {
MockWebServerHelper.tearDownMockServer();
}
@BeforeEach
void resetSwitcherContextState() {
((QueueDispatcher) mockBackEnd.getDispatcher()).clear();
Switchers.configure(ContextBuilder.builder()
.local(false)
.snapshotLocation(null)
.snapshotSkipValidation(false)
.environment("default")
.silentMode(null)
.snapshotAutoLoad(false)
.snapshotAutoUpdateInterval(null));
}
@Test
void shouldReturnTrue_silentMode() {
//given
Switchers.configure(ContextBuilder.builder()
.snapshotLocation(SNAPSHOTS_LOCAL)
.environment("fixture1")
.silentMode("5s"));
Switchers.initializeClient();
//auth
givenResponse(generateMockAuth(10));
//criteria
givenResponse(generateCriteriaResponse("true", false));
//test
SwitcherRequest switcher = Switchers.getSwitcher(Switchers.USECASE11);
assertTrue(switcher.isItOn());
CountDownHelper.wait(2);
//isAlive - service unavailable
givenResponse(generateStatusResponse("503"));
//test will trigger silent
assertTrue(switcher.isItOn());
//test will use silent (read from snapshot)
assertTrue(switcher.isItOn());
}
}