Demo: Send Status-Code in InterceptorHandler
[demos/spring-boot] / src / test / java / de / juplo / demo / DemoApplicationTests.java
1 package de.juplo.demo;
2
3 import org.junit.jupiter.api.Test;
4 import org.springframework.beans.factory.annotation.Autowired;
5 import org.springframework.beans.factory.annotation.Value;
6 import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
7 import org.springframework.boot.test.context.SpringBootTest;
8 import org.springframework.test.web.servlet.MockMvc;
9
10 import static de.juplo.demo.BackendVersionInterceptor.BACKEND_VERSION;
11 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
12 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
13
14
15 @SpringBootTest
16 @AutoConfigureMockMvc
17 class DemoApplicationTests
18 {
19
20         @Value("${build.version}")
21         String projectVersion;
22
23
24         @Test
25         void contextLoads()
26         {
27         }
28
29
30         @Test
31         void getWelcomeResponseIsOkIfBackendHeaderIsNotSet(@Autowired MockMvc mvc) throws Exception
32         {
33                 mvc.perform(get("/")).andExpect(status().isOk());
34         }
35
36         @Test
37         void getWelcomeResponseIsOkIfBackendHeaderDoesMatch(@Autowired MockMvc mvc) throws Exception
38         {
39                 mvc
40                                 .perform(get("/")
41                                                 .header(BACKEND_VERSION, projectVersion))
42                                 .andExpect(status().isOk());
43         }
44
45         @Test
46         void getWelcomeResponseIsGoneIfBackendHeaderDoesNotMatch(@Autowired MockMvc mvc) throws Exception
47         {
48                 mvc
49                                 .perform(get("/")
50                                                 .header(BACKEND_VERSION, "FOO"))
51                                 .andExpect(status().isGone());
52         }
53 }