diff --git a/build.gradle.kts b/build.gradle.kts index 0693aa5..deb8af3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -56,9 +56,7 @@ dependencies { implementation("org.webjars:jquery-ui:$jQueryUIVersion") implementation("org.webjars:bootstrap:$boostrapVersion") - testImplementation("org.springframework.boot:spring-boot-starter-test") { - exclude(module = "junit") - } + testImplementation("org.springframework.boot:spring-boot-starter-test") testImplementation("org.springframework.boot:spring-boot-starter-webflux") testImplementation("org.junit.jupiter:junit-jupiter-api") testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine") diff --git a/src/main/resources/templates/error.html b/src/main/resources/templates/error.html new file mode 100644 index 0000000..0c3decb --- /dev/null +++ b/src/main/resources/templates/error.html @@ -0,0 +1,11 @@ + + + + +
+
+Exception message
+ + + diff --git a/src/test/kotlin/org/springframework/samples/petclinic/system/CrashControllerTest.kt b/src/test/kotlin/org/springframework/samples/petclinic/system/CrashControllerTest.kt index 368cbae..1e3b733 100644 --- a/src/test/kotlin/org/springframework/samples/petclinic/system/CrashControllerTest.kt +++ b/src/test/kotlin/org/springframework/samples/petclinic/system/CrashControllerTest.kt @@ -6,10 +6,13 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest +import org.springframework.test.context.ActiveProfiles import org.springframework.test.context.junit.jupiter.SpringExtension import org.springframework.test.web.servlet.MockMvc import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get import org.springframework.test.web.servlet.result.MockMvcResultMatchers.* +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.ResponseBody /** * Test class for [CrashController] @@ -17,6 +20,7 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers.* * @author Colin But */ @ExtendWith(SpringExtension::class) +@ActiveProfiles("test") @WebMvcTest(controllers = [MockMvcValidationConfiguration::class, CrashController::class]) class CrashControllerTest { @@ -28,7 +32,9 @@ class CrashControllerTest { mockMvc.perform(get("/oups")) .andExpect(view().name("error")) .andExpect(model().attributeExists("error")) - .andExpect(content().string(containsString("Whitelabel Error Page"))) + .andExpect(content().string(containsString("PetClinic :: a Spring Framework demonstration"))) + .andExpect(content().string(containsString("Something happened..."))) .andExpect(content().string(containsString("Expected: controller used to showcase what happens when an exception is thrown"))) } + } diff --git a/src/test/kotlin/org/springframework/samples/petclinic/system/MockMvcValidationConfiguration.kt b/src/test/kotlin/org/springframework/samples/petclinic/system/MockMvcValidationConfiguration.kt index 68bab90..e9cc737 100644 --- a/src/test/kotlin/org/springframework/samples/petclinic/system/MockMvcValidationConfiguration.kt +++ b/src/test/kotlin/org/springframework/samples/petclinic/system/MockMvcValidationConfiguration.kt @@ -4,6 +4,8 @@ import org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorContro import org.springframework.boot.web.servlet.error.ErrorController import org.springframework.web.bind.annotation.ControllerAdvice import org.springframework.web.bind.annotation.ExceptionHandler +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.ResponseBody import org.springframework.web.servlet.ModelAndView import javax.servlet.http.HttpServletRequest import javax.servlet.http.HttpServletResponse @@ -22,4 +24,5 @@ internal class MockMvcValidationConfiguration(private val errorController: Basic fun defaultErrorHandler(request: HttpServletRequest, response: HttpServletResponse, ex: Exception): ModelAndView { return errorController.errorHtml(request, response) } + } diff --git a/src/test/resources/application-test.properties b/src/test/resources/application-test.properties new file mode 100644 index 0000000..3e7fc8a --- /dev/null +++ b/src/test/resources/application-test.properties @@ -0,0 +1 @@ +server.error.include-message=always