001package com.lucidtech.puttingalltogether.samples; 002 003import org.junit.jupiter.api.Test; 004import org.springframework.beans.factory.annotation.Autowired; 005import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; 006import org.springframework.test.web.servlet.MockMvc; 007 008import static org.hamcrest.Matchers.containsString; 009import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; 010import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; 011import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; 012import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; 013 014@WebMvcTest 015//In this test, the full Spring application context is started but without the server. 016// We can narrow the tests to only the web layer by using @WebMvcTest 017class StartSpringContextWithWebLayerOnlyAndWithoutServerTest { 018 @Autowired 019 private MockMvc mockMvc; 020 021 @Test 022 public void shouldReturnDefaultMessage() throws Exception { 023 this.mockMvc.perform(get("/greeting")).andDo(print()).andExpect(status().isOk()) 024 .andExpect(content().string(containsString("World"))); 025 } 026}