mirror of
https://github.com/jlengrand/spring-petclinic-kotlin.git
synced 2026-03-10 08:41:20 +00:00
Repair gradle test and CrashControllerTest
This commit is contained in:
@@ -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")
|
||||
|
||||
11
src/main/resources/templates/error.html
Normal file
11
src/main/resources/templates/error.html
Normal file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html xmlns:th="http://www.thymeleaf.org" th:replace="~{fragments/layout :: layout (~{::body},'error')}">
|
||||
|
||||
<body>
|
||||
<img src="../../static/resources/images/pets.png" th:src="@{/resources/images/pets.png}"/>
|
||||
<h2>Something happened...</h2>
|
||||
<p th:text="${message}">Exception message</p>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -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")))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
1
src/test/resources/application-test.properties
Normal file
1
src/test/resources/application-test.properties
Normal file
@@ -0,0 +1 @@
|
||||
server.error.include-message=always
|
||||
Reference in New Issue
Block a user