-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSwitcherFail2Test.java
More file actions
71 lines (55 loc) · 2.13 KB
/
SwitcherFail2Test.java
File metadata and controls
71 lines (55 loc) · 2.13 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
package com.github.switcherapi.client;
import com.github.switcherapi.Switchers;
import com.github.switcherapi.client.exception.SwitcherContextException;
import com.github.switcherapi.client.exception.SwitcherRemoteException;
import com.github.switcherapi.client.model.SwitcherRequest;
import com.github.switcherapi.fixture.MockWebServerHelper;
import mockwebserver3.QueueDispatcher;
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 static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
class SwitcherFail2Test extends MockWebServerHelper {
@BeforeAll
static void setup() throws IOException {
MockWebServerHelper.setupMockServer();
Switchers.loadProperties();
Switchers.configure(ContextBuilder.builder().url(String.format("http://localhost:%s", mockBackEnd.getPort())));
Switchers.initializeClient();
}
@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));
Switchers.initializeClient();
}
@Test
void shouldReturnError_componentNotRegistered() {
//auth
givenResponse(generateMockAuth(10));
//criteria
givenResponse(generateStatusResponse("401"));
SwitcherRequest switcher = Switchers.getSwitcher(Switchers.REMOTE_KEY);
assertThrows(SwitcherRemoteException.class, switcher::isItOn);
}
@Test
void shouldReturnError_switcherCannotRunLocally() {
SwitcherRequest switcher = Switchers.getSwitcher(Switchers.REMOTE_KEY);
Exception ex = assertThrows(SwitcherContextException.class, () -> switcher.remote(false));
assertEquals("Something went wrong: Context has errors - Switcher is not configured to run locally", ex.getMessage());
}
}