Demo: Send Status-Code in InterceptorHandler
[demos/spring-boot] / src / test / java / de / juplo / demo / DemoApplicationTests.java
index e16b8ec..f2981dc 100644 (file)
@@ -2,25 +2,52 @@ package de.juplo.demo;
 
 import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
 import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.test.web.reactive.server.WebTestClient;
+import org.springframework.test.web.servlet.MockMvc;
+
+import static de.juplo.demo.BackendVersionInterceptor.BACKEND_VERSION;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
 
 
 @SpringBootTest
-@AutoConfigureWebTestClient
-class DemoApplicationTests {
+@AutoConfigureMockMvc
+class DemoApplicationTests
+{
+
+       @Value("${build.version}")
+       String projectVersion;
+
 
        @Test
-       void contextLoads() {
+       void contextLoads()
+       {
        }
 
 
        @Test
-       void getWelcomeResponseIsOk(@Autowired WebTestClient webClient) {
-               webClient
-                               .get().uri("/")
-                               .exchange()
-                               .expectStatus().isOk();
+       void getWelcomeResponseIsOkIfBackendHeaderIsNotSet(@Autowired MockMvc mvc) throws Exception
+       {
+               mvc.perform(get("/")).andExpect(status().isOk());
+       }
+
+       @Test
+       void getWelcomeResponseIsOkIfBackendHeaderDoesMatch(@Autowired MockMvc mvc) throws Exception
+       {
+               mvc
+                               .perform(get("/")
+                                               .header(BACKEND_VERSION, projectVersion))
+                               .andExpect(status().isOk());
+       }
+
+       @Test
+       void getWelcomeResponseIsGoneIfBackendHeaderDoesNotMatch(@Autowired MockMvc mvc) throws Exception
+       {
+               mvc
+                               .perform(get("/")
+                                               .header(BACKEND_VERSION, "FOO"))
+                               .andExpect(status().isGone());
        }
 }