resp = rest.exchange("http://localhost:" + port + "/oups", HttpMethod.GET,
+ new HttpEntity<>(headers), String.class);
+ assertThat(resp).isNotNull();
+ assertThat(resp.getStatusCode().is5xxServerError());
+ assertThat(resp.getBody()).isNotNull();
+ // html:
+ assertThat(resp.getBody()).containsSubsequence("", "", "Something happened...", "
", "",
+ "Expected:", "controller", "used", "to", "showcase", "what", "happens", "when", "an", "exception", "is",
+ "thrown", "
", "");
+ // Not the whitelabel error page:
+ assertThat(resp.getBody()).doesNotContain("Whitelabel Error Page",
+ "This application has no explicit mapping for");
+ }
+
+}
diff --git a/src/test/java/org/springframework/samples/petclinic/system/CrashControllerTests.java b/src/test/java/org/springframework/samples/petclinic/system/CrashControllerTests.java
index 142a136b0..65d3b8921 100644
--- a/src/test/java/org/springframework/samples/petclinic/system/CrashControllerTests.java
+++ b/src/test/java/org/springframework/samples/petclinic/system/CrashControllerTests.java
@@ -16,35 +16,31 @@
package org.springframework.samples.petclinic.system;
-import org.junit.jupiter.api.Disabled;
-import org.junit.jupiter.api.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
-import org.springframework.test.web.servlet.MockMvc;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
-import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
+import org.junit.jupiter.api.Test;
/**
* Test class for {@link CrashController}
*
* @author Colin But
+ * @author Alex Lutz
*/
-// Waiting https://github.com/spring-projects/spring-boot/issues/5574
-@Disabled
-@WebMvcTest(controllers = CrashController.class)
+// Waiting https://github.com/spring-projects/spring-boot/issues/5574 ..good
+// luck ((plain(st) UNIT test)! :)
class CrashControllerTests {
- @Autowired
- private MockMvc mockMvc;
+ CrashController testee = new CrashController();
@Test
void testTriggerException() throws Exception {
- mockMvc.perform(get("/oups"))
- .andExpect(view().name("exception"))
- .andExpect(model().attributeExists("exception"))
- .andExpect(forwardedUrl("exception"))
- .andExpect(status().isOk());
+ RuntimeException thrown = assertThrows(RuntimeException.class, () -> {
+ testee.triggerException();
+ });
+
+ assertEquals("Expected: controller used to showcase what happens when an exception is thrown",
+ thrown.getMessage());
}
}
diff --git a/src/test/java/org/springframework/samples/petclinic/vet/VetControllerTests.java b/src/test/java/org/springframework/samples/petclinic/vet/VetControllerTests.java
index 8a872be69..739ac01d8 100644
--- a/src/test/java/org/springframework/samples/petclinic/vet/VetControllerTests.java
+++ b/src/test/java/org/springframework/samples/petclinic/vet/VetControllerTests.java
@@ -19,6 +19,7 @@ package org.springframework.samples.petclinic.vet;
import org.assertj.core.util.Lists;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.DisabledInNativeImage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
@@ -39,6 +40,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
*/
@WebMvcTest(VetController.class)
+@DisabledInNativeImage
class VetControllerTests {
@Autowired
diff --git a/src/test/java/org/springframework/samples/petclinic/vet/VetTests.java b/src/test/java/org/springframework/samples/petclinic/vet/VetTests.java
index d8df78b85..b29c6d100 100644
--- a/src/test/java/org/springframework/samples/petclinic/vet/VetTests.java
+++ b/src/test/java/org/springframework/samples/petclinic/vet/VetTests.java
@@ -31,6 +31,7 @@ class VetTests {
vet.setFirstName("Zaphod");
vet.setLastName("Beeblebrox");
vet.setId(123);
+ @SuppressWarnings("deprecation")
Vet other = (Vet) SerializationUtils.deserialize(SerializationUtils.serialize(vet));
assertThat(other.getFirstName()).isEqualTo(vet.getFirstName());
assertThat(other.getLastName()).isEqualTo(vet.getLastName());
diff --git a/src/test/jmeter/petclinic_test_plan.jmx b/src/test/jmeter/petclinic_test_plan.jmx
index 0a9a3a5f9..8014ffbec 100644
--- a/src/test/jmeter/petclinic_test_plan.jmx
+++ b/src/test/jmeter/petclinic_test_plan.jmx
@@ -1,5 +1,5 @@
-
+
@@ -69,7 +69,7 @@
1
- 10
+ 3
1
count
@@ -78,7 +78,7 @@
1
- 13
+ 3
1
petCount
@@ -135,7 +135,7 @@
- ${CONTEXT_WEB}/webjars/jquery/jquery.min.js
+ ${CONTEXT_WEB}/webjars/bootstrap/5.2.3/dist/js/bootstrap.bundle.min.js
GET
true
false
@@ -246,13 +246,42 @@
- true
-
+
-
+
false
- firstName=Test&lastName=${count}&address=1234+Test+St.&city=TestCity&telephone=612345678
+ Test
=
+ true
+ firstName
+
+
+ false
+ ${count}
+ =
+ true
+ lastName
+
+
+ false
+ 1234+Test+St.
+ =
+ true
+ address
+
+
+ false
+ TestCity
+ =
+ true
+ city
+
+
+ false
+ 612345678
+ =
+ true
+ telephone
@@ -272,7 +301,7 @@
-
+
@@ -282,7 +311,7 @@
- ${CONTEXT_WEB}/owners/${count}/pets/${petCount}/visits/new
+ ${CONTEXT_WEB}/owners/${count}/pets/new
GET
true
false
@@ -292,14 +321,29 @@
-
- true
-
+
+
-
+
false
- date=2013%2F02%2F22&description=visit
+ Test+Fluffy+${petCount}
=
+ true
+ name
+
+
+ false
+ 2020-12-20
+ =
+ true
+ birthDate
+
+
+ false
+ cat
+ =
+ true
+ type
@@ -309,7 +353,7 @@
- ${CONTEXT_WEB}/owners/${count}/pets/${petCount}/visits/new
+ ${CONTEXT_WEB}/owners/${count}/pets/new
POST
true
false
@@ -319,22 +363,54 @@
-
+
-
-
- ${CONTEXT_WEB}/owners/${count}
+ ${CONTEXT_WEB}/owners/${count}/pets/${petCount}/visits/new
GET
true
false
true
false
+
+
+
+
+
+
+
+
+
+ false
+ 2013-02-22
+ =
+ true
+ date
+
+
+ false
+ visit
+ =
+ true
+ description
+
+
+
+
+
+
+
+ ${CONTEXT_WEB}/owners/${count}/pets/${petCount}/visits/new
+ POST
+ true
+ false
+ true
+ false
false