Repair gradle test and CrashControllerTest

This commit is contained in:
Antoine Rey
2020-05-23 15:07:41 +02:00
parent 83e3bc18e7
commit 7e1ba0f252
5 changed files with 23 additions and 4 deletions

View File

@@ -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")

View 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>

View File

@@ -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")))
}
}

View File

@@ -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)
}
}

View File

@@ -0,0 +1 @@
server.error.include-message=always