Updating dependencies and docker containers to current versions

This commit is contained in:
Patrick Baumgartner 2023-03-10 14:22:53 +01:00
parent ccb14e0f71
commit 65554e4ac3
16 changed files with 191 additions and 120 deletions

Binary file not shown.

View file

@ -1,2 +1,18 @@
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.zip # Licensed to the Apache Software Foundation (ASF) under one
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar # or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.7/apache-maven-3.8.7-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar

View file

@ -1,8 +1,8 @@
plugins { plugins {
id 'java' id 'java'
id 'org.springframework.boot' version '3.0.2' id 'org.springframework.boot' version '3.0.4'
id 'io.spring.dependency-management' version '1.1.0' id 'io.spring.dependency-management' version '1.1.0'
id 'org.graalvm.buildtools.native' version '0.9.18' id 'org.graalvm.buildtools.native' version '0.9.20'
} }
apply plugin: 'java' apply plugin: 'java'
@ -16,7 +16,7 @@ repositories {
} }
ext.webjarsFontawesomeVersion = "4.7.0" ext.webjarsFontawesomeVersion = "4.7.0"
ext.webjarsBootstrapVersion = "5.1.3" ext.webjarsBootstrapVersion = "5.2.3"
dependencies { dependencies {
implementation 'org.springframework.boot:spring-boot-starter-cache' implementation 'org.springframework.boot:spring-boot-starter-cache'

View file

@ -2,7 +2,7 @@ version: "2.2"
services: services:
mysql: mysql:
image: mysql:5.7 image: mysql:8.0
ports: ports:
- "3306:3306" - "3306:3306"
environment: environment:
@ -14,7 +14,7 @@ services:
volumes: volumes:
- "./conf.d:/etc/mysql/conf.d:ro" - "./conf.d:/etc/mysql/conf.d:ro"
postgres: postgres:
image: postgres:14.1 image: postgres:15.2
ports: ports:
- "5432:5432" - "5432:5432"
environment: environment:

View file

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

0
mvnw vendored Executable file → Normal file
View file

View file

@ -25,7 +25,7 @@
<jacoco.version>0.8.8</jacoco.version> <jacoco.version>0.8.8</jacoco.version>
<nohttp-checkstyle.version>0.0.11</nohttp-checkstyle.version> <nohttp-checkstyle.version>0.0.11</nohttp-checkstyle.version>
<spring-format.version>0.0.35</spring-format.version> <spring-format.version>0.0.38</spring-format.version>
</properties> </properties>
@ -132,12 +132,12 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId> <artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.2</version> <version>3.2.1</version>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.puppycrawl.tools</groupId> <groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId> <artifactId>checkstyle</artifactId>
<version>8.45.1</version> <version>10.8.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>io.spring.nohttp</groupId> <groupId>io.spring.nohttp</groupId>
@ -300,7 +300,7 @@
<plugin> <plugin>
<groupId>com.gitlab.haynes</groupId> <groupId>com.gitlab.haynes</groupId>
<artifactId>libsass-maven-plugin</artifactId> <artifactId>libsass-maven-plugin</artifactId>
<version>0.2.26</version> <version>0.2.29</version>
<executions> <executions>
<execution> <execution>
<phase>generate-resources</phase> <phase>generate-resources</phase>

View file

@ -56,13 +56,13 @@ A similar setup is provided for MySQL and PostgreSQL if a persistent database co
You can start MySQL or PostgreSQL locally with whatever installer works for your OS or use docker: You can start MySQL or PostgreSQL locally with whatever installer works for your OS or use docker:
``` ```
docker run -e MYSQL_USER=petclinic -e MYSQL_PASSWORD=petclinic -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=petclinic -p 3306:3306 mysql:5.7.8 docker run -e MYSQL_USER=petclinic -e MYSQL_PASSWORD=petclinic -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=petclinic -p 3306:3306 mysql:8.0
``` ```
or or
``` ```
docker run -e POSTGRES_USER=petclinic -e POSTGRES_PASSWORD=petclinic -e POSTGRES_DB=petclinic -p 5432:5432 postgres:14.1 docker run -e POSTGRES_USER=petclinic -e POSTGRES_PASSWORD=petclinic -e POSTGRES_DB=petclinic -p 5432:5432 postgres:15.2
``` ```
Further documentation is provided for [MySQL](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/resources/db/mysql/petclinic_db_setup_mysql.txt) Further documentation is provided for [MySQL](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/resources/db/mysql/petclinic_db_setup_mysql.txt)

View file

@ -145,10 +145,14 @@ public class Owner extends Person {
@Override @Override
public String toString() { public String toString() {
return new ToStringCreator(this).append("id", this.getId()).append("new", this.isNew()) return new ToStringCreator(this).append("id", this.getId())
.append("lastName", this.getLastName()).append("firstName", this.getFirstName()) .append("new", this.isNew())
.append("address", this.address).append("city", this.city).append("telephone", this.telephone) .append("lastName", this.getLastName())
.toString(); .append("firstName", this.getFirstName())
.append("address", this.address)
.append("city", this.city)
.append("telephone", this.telephone)
.toString();
} }
/** /**

View file

@ -87,7 +87,7 @@
</div> </div>
</div> </div>
<script th:src="@{/webjars/bootstrap/5.1.3/dist/js/bootstrap.bundle.min.js}"></script> <script th:src="@{/webjars/bootstrap/5.2.3/dist/js/bootstrap.bundle.min.js}"></script>
</body> </body>

View file

@ -87,7 +87,7 @@ class OwnerControllerTests {
Owner george = george(); Owner george = george();
given(this.owners.findByLastName(eq("Franklin"), any(Pageable.class))) given(this.owners.findByLastName(eq("Franklin"), any(Pageable.class)))
.willReturn(new PageImpl<Owner>(Lists.newArrayList(george))); .willReturn(new PageImpl<Owner>(Lists.newArrayList(george)));
given(this.owners.findAll(any(Pageable.class))).willReturn(new PageImpl<Owner>(Lists.newArrayList(george))); given(this.owners.findAll(any(Pageable.class))).willReturn(new PageImpl<Owner>(Lists.newArrayList(george)));
@ -100,31 +100,40 @@ class OwnerControllerTests {
@Test @Test
void testInitCreationForm() throws Exception { void testInitCreationForm() throws Exception {
mockMvc.perform(get("/owners/new")).andExpect(status().isOk()).andExpect(model().attributeExists("owner")) mockMvc.perform(get("/owners/new"))
.andExpect(view().name("owners/createOrUpdateOwnerForm")); .andExpect(status().isOk())
.andExpect(model().attributeExists("owner"))
.andExpect(view().name("owners/createOrUpdateOwnerForm"));
} }
@Test @Test
void testProcessCreationFormSuccess() throws Exception { void testProcessCreationFormSuccess() throws Exception {
mockMvc.perform(post("/owners/new").param("firstName", "Joe").param("lastName", "Bloggs") mockMvc
.param("address", "123 Caramel Street").param("city", "London").param("telephone", "01316761638")) .perform(post("/owners/new").param("firstName", "Joe")
.andExpect(status().is3xxRedirection()); .param("lastName", "Bloggs")
.param("address", "123 Caramel Street")
.param("city", "London")
.param("telephone", "01316761638"))
.andExpect(status().is3xxRedirection());
} }
@Test @Test
void testProcessCreationFormHasErrors() throws Exception { void testProcessCreationFormHasErrors() throws Exception {
mockMvc.perform( mockMvc
post("/owners/new").param("firstName", "Joe").param("lastName", "Bloggs").param("city", "London")) .perform(post("/owners/new").param("firstName", "Joe").param("lastName", "Bloggs").param("city", "London"))
.andExpect(status().isOk()).andExpect(model().attributeHasErrors("owner")) .andExpect(status().isOk())
.andExpect(model().attributeHasFieldErrors("owner", "address")) .andExpect(model().attributeHasErrors("owner"))
.andExpect(model().attributeHasFieldErrors("owner", "telephone")) .andExpect(model().attributeHasFieldErrors("owner", "address"))
.andExpect(view().name("owners/createOrUpdateOwnerForm")); .andExpect(model().attributeHasFieldErrors("owner", "telephone"))
.andExpect(view().name("owners/createOrUpdateOwnerForm"));
} }
@Test @Test
void testInitFindForm() throws Exception { void testInitFindForm() throws Exception {
mockMvc.perform(get("/owners/find")).andExpect(status().isOk()).andExpect(model().attributeExists("owner")) mockMvc.perform(get("/owners/find"))
.andExpect(view().name("owners/findOwners")); .andExpect(status().isOk())
.andExpect(model().attributeExists("owner"))
.andExpect(view().name("owners/findOwners"));
} }
@Test @Test
@ -138,84 +147,98 @@ class OwnerControllerTests {
void testProcessFindFormByLastName() throws Exception { void testProcessFindFormByLastName() throws Exception {
Page<Owner> tasks = new PageImpl<Owner>(Lists.newArrayList(george())); Page<Owner> tasks = new PageImpl<Owner>(Lists.newArrayList(george()));
Mockito.when(this.owners.findByLastName(eq("Franklin"), any(Pageable.class))).thenReturn(tasks); Mockito.when(this.owners.findByLastName(eq("Franklin"), any(Pageable.class))).thenReturn(tasks);
mockMvc.perform(get("/owners?page=1").param("lastName", "Franklin")).andExpect(status().is3xxRedirection()) mockMvc.perform(get("/owners?page=1").param("lastName", "Franklin"))
.andExpect(view().name("redirect:/owners/" + TEST_OWNER_ID)); .andExpect(status().is3xxRedirection())
.andExpect(view().name("redirect:/owners/" + TEST_OWNER_ID));
} }
@Test @Test
void testProcessFindFormNoOwnersFound() throws Exception { void testProcessFindFormNoOwnersFound() throws Exception {
Page<Owner> tasks = new PageImpl<Owner>(Lists.newArrayList()); Page<Owner> tasks = new PageImpl<Owner>(Lists.newArrayList());
Mockito.when(this.owners.findByLastName(eq("Unknown Surname"), any(Pageable.class))).thenReturn(tasks); Mockito.when(this.owners.findByLastName(eq("Unknown Surname"), any(Pageable.class))).thenReturn(tasks);
mockMvc.perform(get("/owners?page=1").param("lastName", "Unknown Surname")).andExpect(status().isOk()) mockMvc.perform(get("/owners?page=1").param("lastName", "Unknown Surname"))
.andExpect(model().attributeHasFieldErrors("owner", "lastName")) .andExpect(status().isOk())
.andExpect(model().attributeHasFieldErrorCode("owner", "lastName", "notFound")) .andExpect(model().attributeHasFieldErrors("owner", "lastName"))
.andExpect(view().name("owners/findOwners")); .andExpect(model().attributeHasFieldErrorCode("owner", "lastName", "notFound"))
.andExpect(view().name("owners/findOwners"));
} }
@Test @Test
void testInitUpdateOwnerForm() throws Exception { void testInitUpdateOwnerForm() throws Exception {
mockMvc.perform(get("/owners/{ownerId}/edit", TEST_OWNER_ID)).andExpect(status().isOk()) mockMvc.perform(get("/owners/{ownerId}/edit", TEST_OWNER_ID))
.andExpect(model().attributeExists("owner")) .andExpect(status().isOk())
.andExpect(model().attribute("owner", hasProperty("lastName", is("Franklin")))) .andExpect(model().attributeExists("owner"))
.andExpect(model().attribute("owner", hasProperty("firstName", is("George")))) .andExpect(model().attribute("owner", hasProperty("lastName", is("Franklin"))))
.andExpect(model().attribute("owner", hasProperty("address", is("110 W. Liberty St.")))) .andExpect(model().attribute("owner", hasProperty("firstName", is("George"))))
.andExpect(model().attribute("owner", hasProperty("city", is("Madison")))) .andExpect(model().attribute("owner", hasProperty("address", is("110 W. Liberty St."))))
.andExpect(model().attribute("owner", hasProperty("telephone", is("6085551023")))) .andExpect(model().attribute("owner", hasProperty("city", is("Madison"))))
.andExpect(view().name("owners/createOrUpdateOwnerForm")); .andExpect(model().attribute("owner", hasProperty("telephone", is("6085551023"))))
.andExpect(view().name("owners/createOrUpdateOwnerForm"));
} }
@Test @Test
void testProcessUpdateOwnerFormSuccess() throws Exception { void testProcessUpdateOwnerFormSuccess() throws Exception {
mockMvc.perform(post("/owners/{ownerId}/edit", TEST_OWNER_ID).param("firstName", "Joe") mockMvc
.param("lastName", "Bloggs").param("address", "123 Caramel Street").param("city", "London") .perform(post("/owners/{ownerId}/edit", TEST_OWNER_ID).param("firstName", "Joe")
.param("telephone", "01616291589")).andExpect(status().is3xxRedirection()) .param("lastName", "Bloggs")
.andExpect(view().name("redirect:/owners/{ownerId}")); .param("address", "123 Caramel Street")
.param("city", "London")
.param("telephone", "01616291589"))
.andExpect(status().is3xxRedirection())
.andExpect(view().name("redirect:/owners/{ownerId}"));
} }
@Test @Test
void testProcessUpdateOwnerFormUnchangedSuccess() throws Exception { void testProcessUpdateOwnerFormUnchangedSuccess() throws Exception {
mockMvc.perform(post("/owners/{ownerId}/edit", TEST_OWNER_ID)).andExpect(status().is3xxRedirection()) mockMvc.perform(post("/owners/{ownerId}/edit", TEST_OWNER_ID))
.andExpect(view().name("redirect:/owners/{ownerId}")); .andExpect(status().is3xxRedirection())
.andExpect(view().name("redirect:/owners/{ownerId}"));
} }
@Test @Test
void testProcessUpdateOwnerFormHasErrors() throws Exception { void testProcessUpdateOwnerFormHasErrors() throws Exception {
mockMvc.perform(post("/owners/{ownerId}/edit", TEST_OWNER_ID).param("firstName", "Joe") mockMvc
.param("lastName", "Bloggs").param("address", "").param("telephone", "")).andExpect(status().isOk()) .perform(post("/owners/{ownerId}/edit", TEST_OWNER_ID).param("firstName", "Joe")
.andExpect(model().attributeHasErrors("owner")) .param("lastName", "Bloggs")
.andExpect(model().attributeHasFieldErrors("owner", "address")) .param("address", "")
.andExpect(model().attributeHasFieldErrors("owner", "telephone")) .param("telephone", ""))
.andExpect(view().name("owners/createOrUpdateOwnerForm")); .andExpect(status().isOk())
.andExpect(model().attributeHasErrors("owner"))
.andExpect(model().attributeHasFieldErrors("owner", "address"))
.andExpect(model().attributeHasFieldErrors("owner", "telephone"))
.andExpect(view().name("owners/createOrUpdateOwnerForm"));
} }
@Test @Test
void testShowOwner() throws Exception { void testShowOwner() throws Exception {
mockMvc.perform(get("/owners/{ownerId}", TEST_OWNER_ID)).andExpect(status().isOk()) mockMvc.perform(get("/owners/{ownerId}", TEST_OWNER_ID))
.andExpect(model().attribute("owner", hasProperty("lastName", is("Franklin")))) .andExpect(status().isOk())
.andExpect(model().attribute("owner", hasProperty("firstName", is("George")))) .andExpect(model().attribute("owner", hasProperty("lastName", is("Franklin"))))
.andExpect(model().attribute("owner", hasProperty("address", is("110 W. Liberty St.")))) .andExpect(model().attribute("owner", hasProperty("firstName", is("George"))))
.andExpect(model().attribute("owner", hasProperty("city", is("Madison")))) .andExpect(model().attribute("owner", hasProperty("address", is("110 W. Liberty St."))))
.andExpect(model().attribute("owner", hasProperty("telephone", is("6085551023")))) .andExpect(model().attribute("owner", hasProperty("city", is("Madison"))))
.andExpect(model().attribute("owner", hasProperty("pets", not(empty())))) .andExpect(model().attribute("owner", hasProperty("telephone", is("6085551023"))))
.andExpect(model().attribute("owner", hasProperty("pets", new BaseMatcher<List<Pet>>() { .andExpect(model().attribute("owner", hasProperty("pets", not(empty()))))
.andExpect(model().attribute("owner", hasProperty("pets", new BaseMatcher<List<Pet>>() {
@Override @Override
public boolean matches(Object item) { public boolean matches(Object item) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
List<Pet> pets = (List<Pet>) item; List<Pet> pets = (List<Pet>) item;
Pet pet = pets.get(0); Pet pet = pets.get(0);
if (pet.getVisits().isEmpty()) { if (pet.getVisits().isEmpty()) {
return false; return false;
}
return true;
} }
return true;
}
@Override @Override
public void describeTo(Description description) { public void describeTo(Description description) {
description.appendText("Max did not have any visits"); description.appendText("Max did not have any visits");
} }
}))).andExpect(view().name("owners/ownerDetails")); })))
.andExpect(view().name("owners/ownerDetails"));
} }
} }

View file

@ -65,46 +65,62 @@ class PetControllerTests {
@Test @Test
void testInitCreationForm() throws Exception { void testInitCreationForm() throws Exception {
mockMvc.perform(get("/owners/{ownerId}/pets/new", TEST_OWNER_ID)).andExpect(status().isOk()) mockMvc.perform(get("/owners/{ownerId}/pets/new", TEST_OWNER_ID))
.andExpect(view().name("pets/createOrUpdatePetForm")).andExpect(model().attributeExists("pet")); .andExpect(status().isOk())
.andExpect(view().name("pets/createOrUpdatePetForm"))
.andExpect(model().attributeExists("pet"));
} }
@Test @Test
void testProcessCreationFormSuccess() throws Exception { void testProcessCreationFormSuccess() throws Exception {
mockMvc.perform(post("/owners/{ownerId}/pets/new", TEST_OWNER_ID).param("name", "Betty") mockMvc
.param("type", "hamster").param("birthDate", "2015-02-12")).andExpect(status().is3xxRedirection()) .perform(post("/owners/{ownerId}/pets/new", TEST_OWNER_ID).param("name", "Betty")
.andExpect(view().name("redirect:/owners/{ownerId}")); .param("type", "hamster")
.param("birthDate", "2015-02-12"))
.andExpect(status().is3xxRedirection())
.andExpect(view().name("redirect:/owners/{ownerId}"));
} }
@Test @Test
void testProcessCreationFormHasErrors() throws Exception { void testProcessCreationFormHasErrors() throws Exception {
mockMvc.perform(post("/owners/{ownerId}/pets/new", TEST_OWNER_ID).param("name", "Betty").param("birthDate", mockMvc
"2015-02-12")).andExpect(model().attributeHasNoErrors("owner")) .perform(post("/owners/{ownerId}/pets/new", TEST_OWNER_ID).param("name", "Betty")
.andExpect(model().attributeHasErrors("pet")).andExpect(model().attributeHasFieldErrors("pet", "type")) .param("birthDate", "2015-02-12"))
.andExpect(model().attributeHasFieldErrorCode("pet", "type", "required")).andExpect(status().isOk()) .andExpect(model().attributeHasNoErrors("owner"))
.andExpect(view().name("pets/createOrUpdatePetForm")); .andExpect(model().attributeHasErrors("pet"))
.andExpect(model().attributeHasFieldErrors("pet", "type"))
.andExpect(model().attributeHasFieldErrorCode("pet", "type", "required"))
.andExpect(status().isOk())
.andExpect(view().name("pets/createOrUpdatePetForm"));
} }
@Test @Test
void testInitUpdateForm() throws Exception { void testInitUpdateForm() throws Exception {
mockMvc.perform(get("/owners/{ownerId}/pets/{petId}/edit", TEST_OWNER_ID, TEST_PET_ID)) mockMvc.perform(get("/owners/{ownerId}/pets/{petId}/edit", TEST_OWNER_ID, TEST_PET_ID))
.andExpect(status().isOk()).andExpect(model().attributeExists("pet")) .andExpect(status().isOk())
.andExpect(view().name("pets/createOrUpdatePetForm")); .andExpect(model().attributeExists("pet"))
.andExpect(view().name("pets/createOrUpdatePetForm"));
} }
@Test @Test
void testProcessUpdateFormSuccess() throws Exception { void testProcessUpdateFormSuccess() throws Exception {
mockMvc.perform(post("/owners/{ownerId}/pets/{petId}/edit", TEST_OWNER_ID, TEST_PET_ID).param("name", "Betty") mockMvc
.param("type", "hamster").param("birthDate", "2015-02-12")).andExpect(status().is3xxRedirection()) .perform(post("/owners/{ownerId}/pets/{petId}/edit", TEST_OWNER_ID, TEST_PET_ID).param("name", "Betty")
.andExpect(view().name("redirect:/owners/{ownerId}")); .param("type", "hamster")
.param("birthDate", "2015-02-12"))
.andExpect(status().is3xxRedirection())
.andExpect(view().name("redirect:/owners/{ownerId}"));
} }
@Test @Test
void testProcessUpdateFormHasErrors() throws Exception { void testProcessUpdateFormHasErrors() throws Exception {
mockMvc.perform(post("/owners/{ownerId}/pets/{petId}/edit", TEST_OWNER_ID, TEST_PET_ID).param("name", "Betty") mockMvc
.param("birthDate", "2015/02/12")).andExpect(model().attributeHasNoErrors("owner")) .perform(post("/owners/{ownerId}/pets/{petId}/edit", TEST_OWNER_ID, TEST_PET_ID).param("name", "Betty")
.andExpect(model().attributeHasErrors("pet")).andExpect(status().isOk()) .param("birthDate", "2015/02/12"))
.andExpect(view().name("pets/createOrUpdatePetForm")); .andExpect(model().attributeHasNoErrors("owner"))
.andExpect(model().attributeHasErrors("pet"))
.andExpect(status().isOk())
.andExpect(view().name("pets/createOrUpdatePetForm"));
} }
} }

View file

@ -60,22 +60,28 @@ class VisitControllerTests {
@Test @Test
void testInitNewVisitForm() throws Exception { void testInitNewVisitForm() throws Exception {
mockMvc.perform(get("/owners/{ownerId}/pets/{petId}/visits/new", TEST_OWNER_ID, TEST_PET_ID)) mockMvc.perform(get("/owners/{ownerId}/pets/{petId}/visits/new", TEST_OWNER_ID, TEST_PET_ID))
.andExpect(status().isOk()).andExpect(view().name("pets/createOrUpdateVisitForm")); .andExpect(status().isOk())
.andExpect(view().name("pets/createOrUpdateVisitForm"));
} }
@Test @Test
void testProcessNewVisitFormSuccess() throws Exception { void testProcessNewVisitFormSuccess() throws Exception {
mockMvc.perform(post("/owners/{ownerId}/pets/{petId}/visits/new", TEST_OWNER_ID, TEST_PET_ID) mockMvc
.param("name", "George").param("description", "Visit Description")) .perform(post("/owners/{ownerId}/pets/{petId}/visits/new", TEST_OWNER_ID, TEST_PET_ID)
.andExpect(status().is3xxRedirection()).andExpect(view().name("redirect:/owners/{ownerId}")); .param("name", "George")
.param("description", "Visit Description"))
.andExpect(status().is3xxRedirection())
.andExpect(view().name("redirect:/owners/{ownerId}"));
} }
@Test @Test
void testProcessNewVisitFormHasErrors() throws Exception { void testProcessNewVisitFormHasErrors() throws Exception {
mockMvc.perform( mockMvc
post("/owners/{ownerId}/pets/{petId}/visits/new", TEST_OWNER_ID, TEST_PET_ID).param("name", "George")) .perform(post("/owners/{ownerId}/pets/{petId}/visits/new", TEST_OWNER_ID, TEST_PET_ID).param("name",
.andExpect(model().attributeHasErrors("visit")).andExpect(status().isOk()) "George"))
.andExpect(view().name("pets/createOrUpdateVisitForm")); .andExpect(model().attributeHasErrors("visit"))
.andExpect(status().isOk())
.andExpect(view().name("pets/createOrUpdateVisitForm"));
} }
} }

View file

@ -208,8 +208,8 @@ class ClinicServiceTests {
owner6 = this.owners.findById(6); owner6 = this.owners.findById(6);
assertThat(pet7.getVisits()) // assertThat(pet7.getVisits()) //
.hasSize(found + 1) // .hasSize(found + 1) //
.allMatch(value -> value.getId() != null); .allMatch(value -> value.getId() != null);
} }
@Test @Test
@ -219,8 +219,10 @@ class ClinicServiceTests {
Collection<Visit> visits = pet7.getVisits(); Collection<Visit> visits = pet7.getVisits();
assertThat(visits) // assertThat(visits) //
.hasSize(2) // .hasSize(2) //
.element(0).extracting(Visit::getDate).isNotNull(); .element(0)
.extracting(Visit::getDate)
.isNotNull();
} }
} }

View file

@ -40,9 +40,11 @@ class CrashControllerTests {
@Test @Test
void testTriggerException() throws Exception { void testTriggerException() throws Exception {
mockMvc.perform(get("/oups")).andExpect(view().name("exception")) mockMvc.perform(get("/oups"))
.andExpect(model().attributeExists("exception")).andExpect(forwardedUrl("exception")) .andExpect(view().name("exception"))
.andExpect(status().isOk()); .andExpect(model().attributeExists("exception"))
.andExpect(forwardedUrl("exception"))
.andExpect(status().isOk());
} }
} }

View file

@ -71,24 +71,26 @@ class VetControllerTests {
void setup() { void setup() {
given(this.vets.findAll()).willReturn(Lists.newArrayList(james(), helen())); given(this.vets.findAll()).willReturn(Lists.newArrayList(james(), helen()));
given(this.vets.findAll(any(Pageable.class))) given(this.vets.findAll(any(Pageable.class)))
.willReturn(new PageImpl<Vet>(Lists.newArrayList(james(), helen()))); .willReturn(new PageImpl<Vet>(Lists.newArrayList(james(), helen())));
} }
@Test @Test
void testShowVetListHtml() throws Exception { void testShowVetListHtml() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.get("/vets.html?page=1")).andExpect(status().isOk()) mockMvc.perform(MockMvcRequestBuilders.get("/vets.html?page=1"))
.andExpect(model().attributeExists("listVets")).andExpect(view().name("vets/vetList")); .andExpect(status().isOk())
.andExpect(model().attributeExists("listVets"))
.andExpect(view().name("vets/vetList"));
} }
@Test @Test
void testShowResourcesVetList() throws Exception { void testShowResourcesVetList() throws Exception {
ResultActions actions = mockMvc.perform(get("/vets").accept(MediaType.APPLICATION_JSON)) ResultActions actions = mockMvc.perform(get("/vets").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk()); .andExpect(status().isOk());
actions.andExpect(content().contentType(MediaType.APPLICATION_JSON)) actions.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.vetList[0].id").value(1)); .andExpect(jsonPath("$.vetList[0].id").value(1));
} }
} }