-
Notifications
You must be signed in to change notification settings - Fork 167
Expand file tree
/
Copy pathFeatureTogglesIT.java
More file actions
58 lines (50 loc) · 2.26 KB
/
FeatureTogglesIT.java
File metadata and controls
58 lines (50 loc) · 2.26 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
package my.bookshop.it;
import static org.hamcrest.CoreMatchers.containsString;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.MockMvc;
// This test case is executable only when MTX sidecar is running.
@ActiveProfiles({"default", "ft"})
@AutoConfigureMockMvc
@SpringBootTest
class FeatureTogglesIT {
private static final String ENDPOINT = "/api/browse/Books(aebdfc8a-0dfa-4468-bd36-48aabd65e663)";
@Autowired private MockMvc client;
@Test
@WithMockUser("authenticated") // This user has all feature toggles disabled
void withoutToggles_basicModelVisible() throws Exception {
// Elements are not visible and not changed by the event handler
client
.perform(get(ENDPOINT))
.andExpect(status().isOk())
.andExpect(jsonPath("$.isbn").doesNotExist())
.andExpect(jsonPath("$.title").value(containsString("11%")));
}
@Test
@WithMockUser("admin") // This user has all feature toggles enabled
void togglesOn_extensionsAndChangesAreVisible() throws Exception {
// Elements are visible and changed by the event handler
client
.perform(get(ENDPOINT))
.andExpect(status().isOk())
.andExpect(jsonPath("$.isbn").value("979-8669820985"))
.andExpect(jsonPath("$.title").value(containsString("14%")));
}
@Test
@WithMockUser("user") // This user has only 'isbn' toggle enabled
void toggleIsbnOn_extensionsAndChangesAreVisible() throws Exception {
// Elements are visible
client
.perform(get(ENDPOINT))
.andExpect(status().isOk())
.andExpect(jsonPath("$.isbn").value("979-8669820985"))
.andExpect(jsonPath("$.title").value(containsString("11%")));
}
}