<version>2.3.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
- <groupId>de.juplo</groupId>
- <artifactId>thymeleafe-test</artifactId>
+ <groupId>de.juplo.demo</groupId>
+ <artifactId>exception-handling</artifactId>
<version>0.0.1-SNAPSHOT</version>
- <name>Thymeleaf-Test</name>
- <description>Standalone version of the ThymeleafTest in http-resources</description>
+ <name>Testing Exception-Handling</name>
+ <description>Example-project, that showcases, how to test exception-handling in the springframework</description>
<properties>
<java.version>11</java.version>
+++ /dev/null
-package de.juplo;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.http.HttpStatus;
-import org.springframework.stereotype.Controller;
-import org.springframework.ui.Model;
-import org.springframework.web.bind.annotation.ExceptionHandler;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.ResponseStatus;
-import org.thymeleaf.exceptions.TemplateInputException;
-
-@Controller
-public class TestController
-{
- private final static Logger LOG =
- LoggerFactory.getLogger(TestController.class);
-
-
- @RequestMapping("/controller.html")
- public String controller(
- @RequestParam String template,
- Model model
- )
- {
- model.addAttribute("template", template);
- return template;
- }
-
- @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
- @ExceptionHandler(TemplateInputException.class)
- public void templateInputException(TemplateInputException e)
- {
- LOG.error("{}: {}", HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
- }
-}
-
+++ /dev/null
-package de.juplo;
-
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-
-@SpringBootApplication
-public class ThymeleafTestApplication {
-
- public static void main(String[] args) {
- SpringApplication.run(ThymeleafTestApplication.class, args);
- }
-
-}
--- /dev/null
+package de.juplo.demo;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class ExceptionHandlingApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(ExceptionHandlingApplication.class, args);
+ }
+
+}
--- /dev/null
+package de.juplo.demo;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.http.HttpStatus;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import org.thymeleaf.exceptions.TemplateInputException;
+
+@Controller
+public class ThymeleafController
+{
+ private final static Logger LOG =
+ LoggerFactory.getLogger(ThymeleafController.class);
+
+
+ @RequestMapping("/controller.html")
+ public String controller(
+ @RequestParam String template,
+ Model model
+ )
+ {
+ model.addAttribute("template", template);
+ return template;
+ }
+
+ @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
+ @ExceptionHandler(TemplateInputException.class)
+ public void templateInputException(TemplateInputException e)
+ {
+ LOG.error("{}: {}", HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
+ }
+}
+
+++ /dev/null
-package de.juplo;
-
-import org.junit.jupiter.api.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
-import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureWebMvc;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.test.web.servlet.MockMvc;
-import org.springframework.test.web.servlet.MvcResult;
-
-import java.net.URI;
-
-import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
-import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
-
-@SpringBootTest
-@AutoConfigureWebMvc
-@AutoConfigureMockMvc
-class ThymeleafTestApplicationTests {
- private final static Logger LOG =
- LoggerFactory.getLogger(ThymeleafTestApplicationTests.class);
-
- @Autowired
- MockMvc mvc;
-
-
- @Test
- void contextLoads() throws Exception {
- }
-
- @Test
- void requests() throws Exception {
- mvc
- .perform(get(URI.create("http://test/controller.html?template=remote")))
- .andExpect(status().isOk());
- mvc
- .perform(get(URI.create("http://test/controller.html?template=local")))
- .andExpect(status().isOk());
- // The expected behaviour of the following test is, that the
- // TemplateInputException, that is thrown by Thymeleaf because of the non-existent
- // template-resource, is catched and reported as 503 Internal Server Error, as it
- // happens in the real Spring-MVC environment, when you start the web-server and
- // trigger the error manually.
- // Instead, the exception bubbles up, becomes wrapped in a NestedServletException
- // and is thrown in the call to perform()!
- mvc
- .perform(get(URI.create("http://test/controller.html?template=foo")))
- .andExpect(status().isInternalServerError());
- }
-
-}
--- /dev/null
+package de.juplo.demo;
+
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureWebMvc;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.web.servlet.MockMvc;
+
+import java.net.URI;
+
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
+@SpringBootTest
+@AutoConfigureWebMvc
+@AutoConfigureMockMvc
+class ExceptionHandlingApplicationTests {
+ private final static Logger LOG =
+ LoggerFactory.getLogger(ExceptionHandlingApplicationTests.class);
+
+ @Autowired
+ MockMvc mvc;
+
+
+ @Test
+ void contextLoads() throws Exception {
+ }
+
+ @Test
+ void requests() throws Exception {
+ mvc
+ .perform(get(URI.create("http://test/controller.html?template=remote")))
+ .andExpect(status().isOk());
+ mvc
+ .perform(get(URI.create("http://test/controller.html?template=local")))
+ .andExpect(status().isOk());
+ // The expected behaviour of the following test is, that the
+ // TemplateInputException, that is thrown by Thymeleaf because of the non-existent
+ // template-resource, is catched and reported as 503 Internal Server Error, as it
+ // happens in the real Spring-MVC environment, when you start the web-server and
+ // trigger the error manually.
+ // Instead, the exception bubbles up, becomes wrapped in a NestedServletException
+ // and is thrown in the call to perform()!
+ mvc
+ .perform(get(URI.create("http://test/controller.html?template=foo")))
+ .andExpect(status().isInternalServerError());
+ }
+
+}