Added a `@RestController`
[demos/spring-boot] / src / test / java / de / juplo / demo / DemoApplicationTests.java
index f2981dc..576544f 100644 (file)
@@ -8,11 +8,14 @@ import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.web.servlet.MockMvc;
 
 import static de.juplo.demo.BackendVersionInterceptor.BACKEND_VERSION;
+import static org.springframework.http.HttpHeaders.ACCEPT;
 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
 
 
-@SpringBootTest
+@SpringBootTest(properties = { "application.name=FOO", "build.version=BAR" })
 @AutoConfigureMockMvc
 class DemoApplicationTests
 {
@@ -50,4 +53,38 @@ class DemoApplicationTests
                                                .header(BACKEND_VERSION, "FOO"))
                                .andExpect(status().isGone());
        }
+
+       @Test
+       void getGreetingIfBackendHeaderIsNotSet(@Autowired MockMvc mvc) throws Exception
+       {
+               mvc
+                               .perform(post("/peter")
+                                               .header(ACCEPT, "application/json")
+                                               .header(BACKEND_VERSION, projectVersion)
+                                               .content("Hello TO_NAME, nice to meet you. I'm FROM_NAME."))
+                               .andExpect(status().isOk())
+                               .andExpect(content().json("{\"greeting\": \"Hello peter, nice to meet you. I'm FOO@BAR.\"}"));
+       }
+
+       @Test
+       void getGreetingIfBackendHeaderDoesMatch(@Autowired MockMvc mvc) throws Exception
+       {
+               mvc
+                               .perform(post("/peter")
+                                               .header(ACCEPT, "application/json")
+                                               .header(BACKEND_VERSION, "FOO")
+                                               .content("Hello TO_NAME, nice to meet you. I'm FROM_NAME."))
+                               .andExpect(status().isGone());
+       }
+
+       @Test
+       void getGreetingIfBackendHeaderDoesNotMatch(@Autowired MockMvc mvc) throws Exception
+       {
+               mvc
+                               .perform(post("/peter")
+                                               .header(ACCEPT, "application/json")
+                                               .content("Hello TO_NAME, nice to meet you. I'm FROM_NAME."))
+                               .andExpect(status().isOk())
+                               .andExpect(content().json("{\"greeting\": \"Hello peter, nice to meet you. I'm FOO@BAR.\"}"));
+       }
 }