3 import org.junit.jupiter.api.Test;
4 import org.slf4j.Logger;
5 import org.slf4j.LoggerFactory;
6 import org.springframework.beans.factory.annotation.Autowired;
7 import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
8 import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureWebMvc;
9 import org.springframework.boot.test.context.SpringBootTest;
10 import org.springframework.test.web.servlet.MockMvc;
11 import org.springframework.test.web.servlet.MvcResult;
15 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
16 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
21 class ThymeleafTestApplicationTests {
22 private final static Logger LOG =
23 LoggerFactory.getLogger(ThymeleafTestApplicationTests.class);
30 void contextLoads() throws Exception {
34 void requests() throws Exception {
36 .perform(get(URI.create("http://test/controller.html?template=remote")))
37 .andExpect(status().isOk());
39 .perform(get(URI.create("http://test/controller.html?template=local")))
40 .andExpect(status().isOk());
41 // The expected behaviour of the following test is, that the
42 // TemplateInputException, that is thrown by Thymeleaf because of the non-existent
43 // template-resource, is catched and reported as 503 Internal Server Error, as it
44 // happens in the real Spring-MVC environment, when you start the web-server and
45 // trigger the error manually.
46 // Instead, the exception bubbles up, becomes wrapped in a NestedServletException
47 // and is thrown in the call to perform()!
49 .perform(get(URI.create("http://test/controller.html?template=foo")))
50 .andExpect(status().isInternalServerError());