|
1 | 1 | package my.bookshop; |
2 | 2 |
|
3 | | -import static org.assertj.core.api.Assertions.assertThat; |
| 3 | +import static org.hamcrest.CoreMatchers.containsString; |
4 | 4 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; |
5 | 5 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; |
6 | 6 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
7 | 7 |
|
8 | | -import java.util.Collections; |
9 | | - |
10 | 8 | import org.junit.jupiter.api.Test; |
11 | 9 | import org.springframework.beans.factory.annotation.Autowired; |
12 | 10 | import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; |
13 | 11 | import org.springframework.boot.test.context.SpringBootTest; |
14 | 12 | import org.springframework.security.test.context.support.WithMockUser; |
15 | 13 | import org.springframework.test.context.ActiveProfiles; |
16 | 14 | import org.springframework.test.web.servlet.MockMvc; |
17 | | -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; |
18 | | -import org.springframework.test.web.servlet.result.MockMvcResultMatchers; |
19 | | - |
20 | | -import com.sap.cds.reflect.CdsEntity; |
21 | | -import com.sap.cds.reflect.CdsModel; |
22 | | -import com.sap.cds.services.request.FeatureTogglesInfo; |
23 | | -import com.sap.cds.services.runtime.CdsRuntime; |
24 | | - |
25 | | -import cds.gen.catalogservice.Books_; |
26 | 15 |
|
27 | 16 | // This test case is executable only when MTX sidecar is running. |
28 | | -@ActiveProfiles("ft") |
| 17 | +@ActiveProfiles({"default", "ft"}) |
29 | 18 | @AutoConfigureMockMvc |
30 | 19 | @SpringBootTest |
31 | | -class FeatureToggles_IT { |
| 20 | +class FeatureTogglesIT { |
32 | 21 |
|
33 | | - private static final String ENDPOINT = "/api/browse/Books(%s)"; |
| 22 | + private static final String ENDPOINT = "/api/browse/Books(aebdfc8a-0dfa-4468-bd36-48aabd65e663)"; |
34 | 23 |
|
35 | 24 | @Autowired |
36 | 25 | private MockMvc client; |
37 | 26 |
|
38 | | - @Autowired |
39 | | - CdsRuntime runtime; |
40 | | - |
41 | 27 | @Test |
42 | | - @WithMockUser("fred") // This user has all feature toggles disabled |
| 28 | + @WithMockUser("authenticated") // This user has all feature toggles disabled |
43 | 29 | void withoutToggles_basicModelVisible() throws Exception { |
44 | 30 | // Elements are not visible and not changed by the event handler |
45 | | - client.perform(get(String.format(ENDPOINT, "4a519e61-3c3a-4bd9-ab12-d7e0c5329933"))) |
| 31 | + client.perform(get(ENDPOINT)) |
46 | 32 | .andExpect(status().isOk()) |
47 | 33 | .andExpect(jsonPath("$.isbn").doesNotExist()) |
48 | | - .andExpect(jsonPath("$.price").value(15)); |
| 34 | + .andExpect(jsonPath("$.title").value(containsString("11%"))); |
49 | 35 | } |
50 | 36 |
|
51 | 37 | @Test |
52 | | - @WithMockUser("erin") // This user has all feature toggles enabled |
| 38 | + @WithMockUser("admin") // This user has all feature toggles enabled |
53 | 39 | void togglesOn_extensionsAndChangesAreVisible() throws Exception { |
54 | 40 | // Elements are visible and changed by the event handler |
55 | | - client.perform(get(String.format(ENDPOINT, "4a519e61-3c3a-4bd9-ab12-d7e0c5329933"))) |
| 41 | + client.perform(get(ENDPOINT)) |
56 | 42 | .andExpect(status().isOk()) |
57 | | - .andExpect(jsonPath("$.isbn").value("978-3473523023")) |
58 | | - .andExpect(jsonPath("$.price").value(13.50)); |
| 43 | + .andExpect(jsonPath("$.isbn").value("979-8669820985")) |
| 44 | + .andExpect(jsonPath("$.title").value(containsString("14%"))); |
59 | 45 | } |
60 | 46 |
|
61 | 47 | @Test |
62 | | - @WithMockUser("carol") // This user has only 'isbn' toggle enabled |
| 48 | + @WithMockUser("user") // This user has only 'isbn' toggle enabled |
63 | 49 | void toggleIsbnOn_extensionsAndChangesAreVisible() throws Exception { |
64 | 50 | // Elements are visible |
65 | | - client.perform(get(String.format(ENDPOINT, "4a519e61-3c3a-4bd9-ab12-d7e0c5329933"))) |
| 51 | + client.perform(get(ENDPOINT)) |
66 | 52 | .andExpect(status().isOk()) |
67 | | - .andExpect(jsonPath("$.isbn").value("978-3473523023")) |
68 | | - .andExpect(jsonPath("$.price").value(15)); |
| 53 | + .andExpect(jsonPath("$.isbn").value("979-8669820985")) |
| 54 | + .andExpect(jsonPath("$.title").value(containsString("11%"))); |
69 | 55 | } |
70 | 56 |
|
71 | 57 | } |
|
0 commit comments