mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-20 14:55:50 +00:00
Migration successfully
This commit is contained in:
parent
dd769bebab
commit
a7dd2ffc29
29 changed files with 139 additions and 171 deletions
69
pom.xml
69
pom.xml
|
@ -10,14 +10,16 @@
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
<version>1.5.4.RELEASE</version>
|
<version>3.3.3</version>
|
||||||
</parent>
|
</parent>
|
||||||
<name>petclinic</name>
|
<name>petclinic</name>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
|
||||||
<!-- Generic properties -->
|
<!-- Generic properties -->
|
||||||
<java.version>1.8</java.version>
|
<java.version>17</java.version>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
|
|
||||||
|
@ -25,8 +27,7 @@
|
||||||
<webjars-bootstrap.version>3.3.6</webjars-bootstrap.version>
|
<webjars-bootstrap.version>3.3.6</webjars-bootstrap.version>
|
||||||
<webjars-jquery-ui.version>1.11.4</webjars-jquery-ui.version>
|
<webjars-jquery-ui.version>1.11.4</webjars-jquery-ui.version>
|
||||||
<webjars-jquery.version>2.2.4</webjars-jquery.version>
|
<webjars-jquery.version>2.2.4</webjars-jquery.version>
|
||||||
<wro4j.version>1.8.0</wro4j.version>
|
<wro4j.version>2.1.1</wro4j.version>
|
||||||
<thymeleaf.version>3.0.6.RELEASE</thymeleaf.version>
|
|
||||||
|
|
||||||
<cobertura.version>2.7</cobertura.version>
|
<cobertura.version>2.7</cobertura.version>
|
||||||
|
|
||||||
|
@ -34,6 +35,10 @@
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<!-- Spring and Spring Boot dependencies -->
|
<!-- Spring and Spring Boot dependencies -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>jakarta.xml.bind</groupId>
|
||||||
|
<artifactId>jakarta.xml.bind-api</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||||
|
@ -60,6 +65,10 @@
|
||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-validation</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
@ -73,8 +82,8 @@
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>mysql</groupId>
|
<groupId>com.mysql</groupId>
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
<artifactId>mysql-connector-j</artifactId>
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
@ -86,12 +95,13 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.ehcache</groupId>
|
<groupId>org.ehcache</groupId>
|
||||||
<artifactId>ehcache</artifactId>
|
<artifactId>ehcache</artifactId>
|
||||||
|
<classifier>jakarta</classifier>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- webjars -->
|
<!-- webjars -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.webjars</groupId>
|
<groupId>org.webjars</groupId>
|
||||||
<artifactId>webjars-locator</artifactId>
|
<artifactId>webjars-locator-core</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.webjars</groupId>
|
<groupId>org.webjars</groupId>
|
||||||
|
@ -140,22 +150,6 @@
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
|
||||||
<artifactId>cobertura-maven-plugin</artifactId>
|
|
||||||
<version>${cobertura.version}</version>
|
|
||||||
<configuration>
|
|
||||||
<check />
|
|
||||||
</configuration>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<goals>
|
|
||||||
<goal>clean</goal>
|
|
||||||
<goal>check</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
|
|
||||||
<!-- Spring Boot Actuator displays build-related information if a git.properties
|
<!-- Spring Boot Actuator displays build-related information if a git.properties
|
||||||
file is present at the classpath -->
|
file is present at the classpath -->
|
||||||
|
@ -209,15 +203,13 @@
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.openrewrite.maven</groupId>
|
<groupId>org.openrewrite.maven</groupId>
|
||||||
<artifactId>rewrite-maven-plugin</artifactId>
|
<artifactId>rewrite-maven-plugin</artifactId>
|
||||||
<version>5.36.0</version>
|
<version>5.39.1</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<exportDatatables>true</exportDatatables>
|
<exportDatatables>true</exportDatatables>
|
||||||
<activeRecipes>
|
<activeRecipes>
|
||||||
<!--
|
<!--
|
||||||
<recipe>com.example.MigrateToSpringBoot3_3</recipe>
|
<recipe>com.example.MigrateToSpringBoot3_3_Before_Solve_Issues</recipe>
|
||||||
<recipe>com.example.PostMigrateToSpringBoot3_3</recipe>
|
<recipe>org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_3</recipe>
|
||||||
|
|
||||||
<recipe>org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_3</recipe>
|
|
||||||
-->
|
-->
|
||||||
<recipe>org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_3</recipe>
|
<recipe>org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_3</recipe>
|
||||||
</activeRecipes>
|
</activeRecipes>
|
||||||
|
@ -226,9 +218,13 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.openrewrite.recipe</groupId>
|
<groupId>org.openrewrite.recipe</groupId>
|
||||||
<artifactId>rewrite-spring</artifactId>
|
<artifactId>rewrite-spring</artifactId>
|
||||||
<version>5.15.1</version>
|
<version>5.17.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-web</artifactId>
|
||||||
|
<version>6.1.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
@ -236,17 +232,6 @@
|
||||||
<reporting>
|
<reporting>
|
||||||
<plugins>
|
<plugins>
|
||||||
<!-- integrate maven-cobertura-plugin to project site -->
|
<!-- integrate maven-cobertura-plugin to project site -->
|
||||||
<plugin>
|
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
|
||||||
<artifactId>cobertura-maven-plugin</artifactId>
|
|
||||||
<version>${cobertura.version}</version>
|
|
||||||
<configuration>
|
|
||||||
<formats>
|
|
||||||
<format>html</format>
|
|
||||||
</formats>
|
|
||||||
<check />
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</reporting>
|
</reporting>
|
||||||
|
|
||||||
|
|
13
rewrite.yml
13
rewrite.yml
|
@ -1,6 +1,6 @@
|
||||||
---
|
---
|
||||||
type: specs.openrewrite.org/v1beta/recipe
|
type: specs.openrewrite.org/v1beta/recipe
|
||||||
name: com.example.MigrateToSpringBoot3_3
|
name: com.example.MigrateToSpringBoot3_3_Before_Solve_Issues
|
||||||
displayName: Migrate to Spring Boot and add some fixes
|
displayName: Migrate to Spring Boot and add some fixes
|
||||||
causesAnotherCycle: true
|
causesAnotherCycle: true
|
||||||
recipeList:
|
recipeList:
|
||||||
|
@ -15,3 +15,14 @@ recipeList:
|
||||||
groupId: jakarta.xml.bind
|
groupId: jakarta.xml.bind
|
||||||
artifactId: jakarta.xml.bind-api
|
artifactId: jakarta.xml.bind-api
|
||||||
newVersion: 4.0.2
|
newVersion: 4.0.2
|
||||||
|
---
|
||||||
|
type: specs.openrewrite.org/v1beta/recipe
|
||||||
|
name: com.example.ReplaceStringLiteral
|
||||||
|
displayName: Replace String literal with constant example
|
||||||
|
recipeList:
|
||||||
|
- org.openrewrite.java.ReplaceStringLiteralWithConstant:
|
||||||
|
literalValue: application/json;charset=UTF-8
|
||||||
|
fullyQualifiedConstantName: org.springframework.http.MediaType.APPLICATION_JSON_VALUE
|
||||||
|
- org.openrewrite.java.migrate.ReplaceStringLiteralValue:
|
||||||
|
oldLiteralValue: may not be empty
|
||||||
|
newLiteralValue: must not be empty
|
|
@ -17,10 +17,10 @@ package org.springframework.samples.petclinic.model;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import javax.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import javax.persistence.GenerationType;
|
import jakarta.persistence.GenerationType;
|
||||||
import javax.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import javax.persistence.MappedSuperclass;
|
import jakarta.persistence.MappedSuperclass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple JavaBean domain object with an id property. Used as a base class for objects
|
* Simple JavaBean domain object with an id property. Used as a base class for objects
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package org.springframework.samples.petclinic.model;
|
package org.springframework.samples.petclinic.model;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import javax.persistence.MappedSuperclass;
|
import jakarta.persistence.MappedSuperclass;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -15,10 +15,9 @@
|
||||||
*/
|
*/
|
||||||
package org.springframework.samples.petclinic.model;
|
package org.springframework.samples.petclinic.model;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import javax.persistence.MappedSuperclass;
|
import jakarta.persistence.MappedSuperclass;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import org.hibernate.validator.constraints.NotEmpty;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple JavaBean domain object representing an person.
|
* Simple JavaBean domain object representing an person.
|
||||||
|
|
|
@ -21,14 +21,14 @@ import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.persistence.CascadeType;
|
import jakarta.persistence.CascadeType;
|
||||||
import javax.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import javax.persistence.OneToMany;
|
import jakarta.persistence.OneToMany;
|
||||||
import javax.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
import javax.validation.constraints.Digits;
|
import jakarta.validation.constraints.Digits;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
|
||||||
import org.hibernate.validator.constraints.NotEmpty;
|
|
||||||
import org.springframework.beans.support.MutableSortDefinition;
|
import org.springframework.beans.support.MutableSortDefinition;
|
||||||
import org.springframework.beans.support.PropertyComparator;
|
import org.springframework.beans.support.PropertyComparator;
|
||||||
import org.springframework.core.style.ToStringCreator;
|
import org.springframework.core.style.ToStringCreator;
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
*/
|
*/
|
||||||
package org.springframework.samples.petclinic.owner;
|
package org.springframework.samples.petclinic.owner;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.validation.BindingResult;
|
import org.springframework.validation.BindingResult;
|
||||||
|
@ -26,7 +25,7 @@ import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.servlet.ModelAndView;
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -43,7 +42,6 @@ class OwnerController {
|
||||||
private final OwnerRepository owners;
|
private final OwnerRepository owners;
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public OwnerController(OwnerRepository clinicService) {
|
public OwnerController(OwnerRepository clinicService) {
|
||||||
this.owners = clinicService;
|
this.owners = clinicService;
|
||||||
}
|
}
|
||||||
|
@ -102,14 +100,14 @@ class OwnerController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/owners/{ownerId}/edit")
|
@GetMapping("/owners/{ownerId}/edit")
|
||||||
public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) {
|
public String initUpdateOwnerForm(@PathVariable int ownerId, Model model) {
|
||||||
Owner owner = this.owners.findById(ownerId);
|
Owner owner = this.owners.findById(ownerId);
|
||||||
model.addAttribute(owner);
|
model.addAttribute(owner);
|
||||||
return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
|
return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/owners/{ownerId}/edit")
|
@PostMapping("/owners/{ownerId}/edit")
|
||||||
public String processUpdateOwnerForm(@Valid Owner owner, BindingResult result, @PathVariable("ownerId") int ownerId) {
|
public String processUpdateOwnerForm(@Valid Owner owner, BindingResult result, @PathVariable int ownerId) {
|
||||||
if (result.hasErrors()) {
|
if (result.hasErrors()) {
|
||||||
return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
|
return VIEWS_OWNER_CREATE_OR_UPDATE_FORM;
|
||||||
} else {
|
} else {
|
||||||
|
@ -126,7 +124,7 @@ class OwnerController {
|
||||||
* @return a ModelMap with the model attributes for the view
|
* @return a ModelMap with the model attributes for the view
|
||||||
*/
|
*/
|
||||||
@GetMapping("/owners/{ownerId}")
|
@GetMapping("/owners/{ownerId}")
|
||||||
public ModelAndView showOwner(@PathVariable("ownerId") int ownerId) {
|
public ModelAndView showOwner(@PathVariable int ownerId) {
|
||||||
ModelAndView mav = new ModelAndView("owners/ownerDetails");
|
ModelAndView mav = new ModelAndView("owners/ownerDetails");
|
||||||
mav.addObject(this.owners.findById(ownerId));
|
mav.addObject(this.owners.findById(ownerId));
|
||||||
return mav;
|
return mav;
|
||||||
|
|
|
@ -23,16 +23,16 @@ import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.persistence.CascadeType;
|
import jakarta.persistence.CascadeType;
|
||||||
import javax.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import javax.persistence.FetchType;
|
import jakarta.persistence.FetchType;
|
||||||
import javax.persistence.JoinColumn;
|
import jakarta.persistence.JoinColumn;
|
||||||
import javax.persistence.ManyToOne;
|
import jakarta.persistence.ManyToOne;
|
||||||
import javax.persistence.OneToMany;
|
import jakarta.persistence.OneToMany;
|
||||||
import javax.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
import javax.persistence.Temporal;
|
import jakarta.persistence.Temporal;
|
||||||
import javax.persistence.TemporalType;
|
import jakarta.persistence.TemporalType;
|
||||||
|
|
||||||
import org.springframework.beans.support.MutableSortDefinition;
|
import org.springframework.beans.support.MutableSortDefinition;
|
||||||
import org.springframework.beans.support.PropertyComparator;
|
import org.springframework.beans.support.PropertyComparator;
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
*/
|
*/
|
||||||
package org.springframework.samples.petclinic.owner;
|
package org.springframework.samples.petclinic.owner;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.ModelMap;
|
import org.springframework.ui.ModelMap;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
@ -23,7 +22,7 @@ import org.springframework.validation.BindingResult;
|
||||||
import org.springframework.web.bind.WebDataBinder;
|
import org.springframework.web.bind.WebDataBinder;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,7 +38,6 @@ class PetController {
|
||||||
private final PetRepository pets;
|
private final PetRepository pets;
|
||||||
private final OwnerRepository owners;
|
private final OwnerRepository owners;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public PetController(PetRepository pets, OwnerRepository owners) {
|
public PetController(PetRepository pets, OwnerRepository owners) {
|
||||||
this.pets = pets;
|
this.pets = pets;
|
||||||
this.owners = owners;
|
this.owners = owners;
|
||||||
|
@ -51,7 +49,7 @@ class PetController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ModelAttribute("owner")
|
@ModelAttribute("owner")
|
||||||
public Owner findOwner(@PathVariable("ownerId") int ownerId) {
|
public Owner findOwner(@PathVariable int ownerId) {
|
||||||
return this.owners.findById(ownerId);
|
return this.owners.findById(ownerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,7 +87,7 @@ class PetController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/pets/{petId}/edit")
|
@GetMapping("/pets/{petId}/edit")
|
||||||
public String initUpdateForm(@PathVariable("petId") int petId, ModelMap model) {
|
public String initUpdateForm(@PathVariable int petId, ModelMap model) {
|
||||||
Pet pet = this.pets.findById(petId);
|
Pet pet = this.pets.findById(petId);
|
||||||
model.put("pet", pet);
|
model.put("pet", pet);
|
||||||
return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
|
return VIEWS_PETS_CREATE_OR_UPDATE_FORM;
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package org.springframework.samples.petclinic.owner;
|
package org.springframework.samples.petclinic.owner;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import javax.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
import org.springframework.samples.petclinic.model.NamedEntity;
|
import org.springframework.samples.petclinic.model.NamedEntity;
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@ import java.text.ParseException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.format.Formatter;
|
import org.springframework.format.Formatter;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@ -41,7 +40,6 @@ public class PetTypeFormatter implements Formatter<PetType> {
|
||||||
private final PetRepository pets;
|
private final PetRepository pets;
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public PetTypeFormatter(PetRepository pets) {
|
public PetTypeFormatter(PetRepository pets) {
|
||||||
this.pets = pets;
|
this.pets = pets;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
*/
|
*/
|
||||||
package org.springframework.samples.petclinic.owner;
|
package org.springframework.samples.petclinic.owner;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.samples.petclinic.visit.Visit;
|
import org.springframework.samples.petclinic.visit.Visit;
|
||||||
import org.springframework.samples.petclinic.visit.VisitRepository;
|
import org.springframework.samples.petclinic.visit.VisitRepository;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
|
@ -23,7 +22,7 @@ import org.springframework.validation.BindingResult;
|
||||||
import org.springframework.web.bind.WebDataBinder;
|
import org.springframework.web.bind.WebDataBinder;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -40,7 +39,6 @@ class VisitController {
|
||||||
private final PetRepository pets;
|
private final PetRepository pets;
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public VisitController(VisitRepository visits, PetRepository pets) {
|
public VisitController(VisitRepository visits, PetRepository pets) {
|
||||||
this.visits = visits;
|
this.visits = visits;
|
||||||
this.pets = pets;
|
this.pets = pets;
|
||||||
|
@ -62,7 +60,7 @@ class VisitController {
|
||||||
* @return Pet
|
* @return Pet
|
||||||
*/
|
*/
|
||||||
@ModelAttribute("visit")
|
@ModelAttribute("visit")
|
||||||
public Visit loadPetWithVisit(@PathVariable("petId") int petId, Map<String, Object> model) {
|
public Visit loadPetWithVisit(@PathVariable int petId, Map<String, Object> model) {
|
||||||
Pet pet = this.pets.findById(petId);
|
Pet pet = this.pets.findById(petId);
|
||||||
model.put("pet", pet);
|
model.put("pet", pet);
|
||||||
Visit visit = new Visit();
|
Visit visit = new Visit();
|
||||||
|
@ -72,7 +70,7 @@ class VisitController {
|
||||||
|
|
||||||
// Spring MVC calls method loadPetWithVisit(...) before initNewVisitForm is called
|
// Spring MVC calls method loadPetWithVisit(...) before initNewVisitForm is called
|
||||||
@GetMapping("/owners/*/pets/{petId}/visits/new")
|
@GetMapping("/owners/*/pets/{petId}/visits/new")
|
||||||
public String initNewVisitForm(@PathVariable("petId") int petId, Map<String, Object> model) {
|
public String initNewVisitForm(@PathVariable int petId, Map<String, Object> model) {
|
||||||
return "pets/createOrUpdateVisitForm";
|
return "pets/createOrUpdateVisitForm";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,10 @@ class CrashController {
|
||||||
@GetMapping("/oups")
|
@GetMapping("/oups")
|
||||||
public String triggerException() {
|
public String triggerException() {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"Expected: controller used to showcase what " + "happens when an exception is thrown");
|
"""
|
||||||
|
Expected: controller used to showcase what \
|
||||||
|
happens when an exception is thrown\
|
||||||
|
""");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,8 @@ package org.springframework.samples.petclinic.vet;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import javax.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
import org.springframework.samples.petclinic.model.NamedEntity;
|
import org.springframework.samples.petclinic.model.NamedEntity;
|
||||||
|
|
||||||
|
|
|
@ -21,13 +21,13 @@ import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import javax.persistence.FetchType;
|
import jakarta.persistence.FetchType;
|
||||||
import javax.persistence.JoinColumn;
|
import jakarta.persistence.JoinColumn;
|
||||||
import javax.persistence.JoinTable;
|
import jakarta.persistence.JoinTable;
|
||||||
import javax.persistence.ManyToMany;
|
import jakarta.persistence.ManyToMany;
|
||||||
import javax.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
import jakarta.xml.bind.annotation.XmlElement;
|
||||||
|
|
||||||
import org.springframework.beans.support.MutableSortDefinition;
|
import org.springframework.beans.support.MutableSortDefinition;
|
||||||
import org.springframework.beans.support.PropertyComparator;
|
import org.springframework.beans.support.PropertyComparator;
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
*/
|
*/
|
||||||
package org.springframework.samples.petclinic.vet;
|
package org.springframework.samples.petclinic.vet;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
@ -33,7 +32,6 @@ class VetController {
|
||||||
|
|
||||||
private final VetRepository vets;
|
private final VetRepository vets;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public VetController(VetRepository clinicService) {
|
public VetController(VetRepository clinicService) {
|
||||||
this.vets = clinicService;
|
this.vets = clinicService;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,8 @@ package org.springframework.samples.petclinic.vet;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
import jakarta.xml.bind.annotation.XmlElement;
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
import jakarta.xml.bind.annotation.XmlRootElement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple domain object representing a list of veterinarians. Mostly here to be used for the 'vets' {@link
|
* Simple domain object representing a list of veterinarians. Mostly here to be used for the 'vets' {@link
|
||||||
|
|
|
@ -17,13 +17,13 @@ package org.springframework.samples.petclinic.visit;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import javax.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
import javax.persistence.Temporal;
|
import jakarta.persistence.Temporal;
|
||||||
import javax.persistence.TemporalType;
|
import jakarta.persistence.TemporalType;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
|
||||||
import org.hibernate.validator.constraints.NotEmpty;
|
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
import org.springframework.samples.petclinic.model.BaseEntity;
|
import org.springframework.samples.petclinic.model.BaseEntity;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# database init, supports mysql too
|
# database init, supports mysql too
|
||||||
database=hsqldb
|
database=hsqldb
|
||||||
spring.datasource.schema=classpath*:db/${database}/schema.sql
|
spring.sql.init.schema-locations=classpath*:db/${database}/schema.sql
|
||||||
spring.datasource.data=classpath*:db/${database}/data.sql
|
spring.sql.init.data-locations=classpath*:db/${database}/data.sql
|
||||||
|
|
||||||
# Web
|
# Web
|
||||||
spring.thymeleaf.mode=HTML
|
spring.thymeleaf.mode=HTML
|
||||||
|
@ -13,7 +13,7 @@ spring.jpa.hibernate.ddl-auto=none
|
||||||
spring.messages.basename=messages/messages
|
spring.messages.basename=messages/messages
|
||||||
|
|
||||||
# Actuator / Management
|
# Actuator / Management
|
||||||
management.contextPath=/manage
|
management.server.base-path=/manage
|
||||||
# Spring Boot 1.5 makes actuator secure by default
|
# Spring Boot 1.5 makes actuator secure by default
|
||||||
management.security.enabled=false
|
management.security.enabled=false
|
||||||
|
|
||||||
|
|
|
@ -5,10 +5,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.validation.ConstraintViolation;
|
import jakarta.validation.ConstraintViolation;
|
||||||
import javax.validation.Validator;
|
import jakarta.validation.Validator;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.context.i18n.LocaleContextHolder;
|
import org.springframework.context.i18n.LocaleContextHolder;
|
||||||
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
|
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ public class ValidatorTests {
|
||||||
assertThat(constraintViolations.size()).isEqualTo(1);
|
assertThat(constraintViolations.size()).isEqualTo(1);
|
||||||
ConstraintViolation<Person> violation = constraintViolations.iterator().next();
|
ConstraintViolation<Person> violation = constraintViolations.iterator().next();
|
||||||
assertThat(violation.getPropertyPath().toString()).isEqualTo("firstName");
|
assertThat(violation.getPropertyPath().toString()).isEqualTo("firstName");
|
||||||
assertThat(violation.getMessage()).isEqualTo("may not be empty");
|
assertThat(violation.getMessage()).isEqualTo("must not be empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,16 +10,14 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
|
||||||
|
|
||||||
import org.assertj.core.util.Lists;
|
import org.assertj.core.util.Lists;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||||
import org.springframework.samples.petclinic.owner.Owner;
|
import org.springframework.samples.petclinic.owner.Owner;
|
||||||
import org.springframework.samples.petclinic.owner.OwnerController;
|
import org.springframework.samples.petclinic.owner.OwnerController;
|
||||||
import org.springframework.samples.petclinic.owner.OwnerRepository;
|
import org.springframework.samples.petclinic.owner.OwnerRepository;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,7 +25,6 @@ import org.springframework.test.web.servlet.MockMvc;
|
||||||
*
|
*
|
||||||
* @author Colin But
|
* @author Colin But
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
|
||||||
@WebMvcTest(OwnerController.class)
|
@WebMvcTest(OwnerController.class)
|
||||||
public class OwnerControllerTests {
|
public class OwnerControllerTests {
|
||||||
|
|
||||||
|
@ -41,7 +38,7 @@ public class OwnerControllerTests {
|
||||||
|
|
||||||
private Owner george;
|
private Owner george;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setup() {
|
public void setup() {
|
||||||
george = new Owner();
|
george = new Owner();
|
||||||
george.setId(TEST_OWNER_ID);
|
george.setId(TEST_OWNER_ID);
|
||||||
|
|
|
@ -8,9 +8,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
|
||||||
|
|
||||||
import org.assertj.core.util.Lists;
|
import org.assertj.core.util.Lists;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||||
|
@ -23,7 +22,6 @@ import org.springframework.samples.petclinic.owner.PetController;
|
||||||
import org.springframework.samples.petclinic.owner.PetRepository;
|
import org.springframework.samples.petclinic.owner.PetRepository;
|
||||||
import org.springframework.samples.petclinic.owner.PetType;
|
import org.springframework.samples.petclinic.owner.PetType;
|
||||||
import org.springframework.samples.petclinic.owner.PetTypeFormatter;
|
import org.springframework.samples.petclinic.owner.PetTypeFormatter;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,7 +29,6 @@ import org.springframework.test.web.servlet.MockMvc;
|
||||||
*
|
*
|
||||||
* @author Colin But
|
* @author Colin But
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
|
||||||
@WebMvcTest(value = PetController.class,
|
@WebMvcTest(value = PetController.class,
|
||||||
includeFilters = @ComponentScan.Filter(
|
includeFilters = @ComponentScan.Filter(
|
||||||
value = PetTypeFormatter.class,
|
value = PetTypeFormatter.class,
|
||||||
|
@ -51,7 +48,7 @@ public class PetControllerTests {
|
||||||
@MockBean
|
@MockBean
|
||||||
private OwnerRepository owners;
|
private OwnerRepository owners;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setup() {
|
public void setup() {
|
||||||
PetType cat = new PetType();
|
PetType cat = new PetType();
|
||||||
cat.setId(3);
|
cat.setId(3);
|
||||||
|
|
|
@ -1,19 +1,20 @@
|
||||||
package org.springframework.samples.petclinic.owner;
|
package org.springframework.samples.petclinic.owner;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.junit.Before;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import org.junit.Test;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
import org.mockito.runners.MockitoJUnitRunner;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
import org.springframework.samples.petclinic.owner.PetRepository;
|
import org.springframework.samples.petclinic.owner.PetRepository;
|
||||||
import org.springframework.samples.petclinic.owner.PetType;
|
import org.springframework.samples.petclinic.owner.PetType;
|
||||||
import org.springframework.samples.petclinic.owner.PetTypeFormatter;
|
import org.springframework.samples.petclinic.owner.PetTypeFormatter;
|
||||||
|
@ -23,7 +24,7 @@ import org.springframework.samples.petclinic.owner.PetTypeFormatter;
|
||||||
*
|
*
|
||||||
* @author Colin But
|
* @author Colin But
|
||||||
*/
|
*/
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class PetTypeFormatterTests {
|
public class PetTypeFormatterTests {
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
|
@ -31,7 +32,7 @@ public class PetTypeFormatterTests {
|
||||||
|
|
||||||
private PetTypeFormatter petTypeFormatter;
|
private PetTypeFormatter petTypeFormatter;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setup() {
|
public void setup() {
|
||||||
this.petTypeFormatter = new PetTypeFormatter(pets);
|
this.petTypeFormatter = new PetTypeFormatter(pets);
|
||||||
}
|
}
|
||||||
|
@ -51,10 +52,12 @@ public class PetTypeFormatterTests {
|
||||||
assertEquals("Bird", petType.getName());
|
assertEquals("Bird", petType.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = ParseException.class)
|
@Test
|
||||||
public void shouldThrowParseException() throws ParseException {
|
public void shouldThrowParseException() {
|
||||||
Mockito.when(this.pets.findPetTypes()).thenReturn(makePetTypes());
|
assertThrows(ParseException.class, () -> {
|
||||||
petTypeFormatter.parse("Fish", Locale.ENGLISH);
|
Mockito.when(this.pets.findPetTypes()).thenReturn(makePetTypes());
|
||||||
|
petTypeFormatter.parse("Fish", Locale.ENGLISH);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -7,9 +7,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||||
|
@ -17,7 +16,6 @@ import org.springframework.samples.petclinic.owner.Pet;
|
||||||
import org.springframework.samples.petclinic.owner.PetRepository;
|
import org.springframework.samples.petclinic.owner.PetRepository;
|
||||||
import org.springframework.samples.petclinic.owner.VisitController;
|
import org.springframework.samples.petclinic.owner.VisitController;
|
||||||
import org.springframework.samples.petclinic.visit.VisitRepository;
|
import org.springframework.samples.petclinic.visit.VisitRepository;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -25,7 +23,6 @@ import org.springframework.test.web.servlet.MockMvc;
|
||||||
*
|
*
|
||||||
* @author Colin But
|
* @author Colin But
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
|
||||||
@WebMvcTest(VisitController.class)
|
@WebMvcTest(VisitController.class)
|
||||||
public class VisitControllerTests {
|
public class VisitControllerTests {
|
||||||
|
|
||||||
|
@ -40,7 +37,7 @@ public class VisitControllerTests {
|
||||||
@MockBean
|
@MockBean
|
||||||
private PetRepository pets;
|
private PetRepository pets;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void init() {
|
public void init() {
|
||||||
given(this.pets.findById(TEST_PET_ID)).willReturn(new Pet());
|
given(this.pets.findById(TEST_PET_ID)).willReturn(new Pet());
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
|
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
@ -20,7 +19,6 @@ import org.springframework.samples.petclinic.vet.VetRepository;
|
||||||
import org.springframework.samples.petclinic.visit.Visit;
|
import org.springframework.samples.petclinic.visit.Visit;
|
||||||
import org.springframework.samples.petclinic.visit.VisitRepository;
|
import org.springframework.samples.petclinic.visit.VisitRepository;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -44,7 +42,6 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
|
||||||
@DataJpaTest(includeFilters = @ComponentScan.Filter(Service.class))
|
@DataJpaTest(includeFilters = @ComponentScan.Filter(Service.class))
|
||||||
public class ClinicServiceTests {
|
public class ClinicServiceTests {
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
package org.springframework.samples.petclinic.system;
|
package org.springframework.samples.petclinic.system;
|
||||||
|
|
||||||
import org.junit.Ignore;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
|
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
|
@ -20,9 +18,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||||
*
|
*
|
||||||
* @author Colin But
|
* @author Colin But
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@Disabled
|
||||||
// Waiting https://github.com/spring-projects/spring-boot/issues/5574
|
|
||||||
@Ignore
|
|
||||||
@WebMvcTest(controllers = CrashController.class)
|
@WebMvcTest(controllers = CrashController.class)
|
||||||
public class CrashControllerTests {
|
public class CrashControllerTests {
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,11 @@
|
||||||
package org.springframework.samples.petclinic.system;
|
package org.springframework.samples.petclinic.system;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.samples.petclinic.vet.VetRepository;
|
import org.springframework.samples.petclinic.vet.VetRepository;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
public class ProductionConfigurationTests {
|
public class ProductionConfigurationTests {
|
||||||
|
|
||||||
|
|
|
@ -10,9 +10,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
|
||||||
|
|
||||||
import org.assertj.core.util.Lists;
|
import org.assertj.core.util.Lists;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||||
|
@ -21,14 +20,12 @@ import org.springframework.samples.petclinic.vet.Specialty;
|
||||||
import org.springframework.samples.petclinic.vet.Vet;
|
import org.springframework.samples.petclinic.vet.Vet;
|
||||||
import org.springframework.samples.petclinic.vet.VetController;
|
import org.springframework.samples.petclinic.vet.VetController;
|
||||||
import org.springframework.samples.petclinic.vet.VetRepository;
|
import org.springframework.samples.petclinic.vet.VetRepository;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
import org.springframework.test.web.servlet.ResultActions;
|
import org.springframework.test.web.servlet.ResultActions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test class for the {@link VetController}
|
* Test class for the {@link VetController}
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
|
||||||
@WebMvcTest(VetController.class)
|
@WebMvcTest(VetController.class)
|
||||||
public class VetControllerTests {
|
public class VetControllerTests {
|
||||||
|
|
||||||
|
@ -38,7 +35,7 @@ public class VetControllerTests {
|
||||||
@MockBean
|
@MockBean
|
||||||
private VetRepository vets;
|
private VetRepository vets;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setup() {
|
public void setup() {
|
||||||
Vet james = new Vet();
|
Vet james = new Vet();
|
||||||
james.setFirstName("James");
|
james.setFirstName("James");
|
||||||
|
@ -67,7 +64,7 @@ public class VetControllerTests {
|
||||||
public void testShowResourcesVetList() throws Exception {
|
public void testShowResourcesVetList() throws Exception {
|
||||||
ResultActions actions = mockMvc.perform(get("/vets.json").accept(MediaType.APPLICATION_JSON))
|
ResultActions actions = mockMvc.perform(get("/vets.json").accept(MediaType.APPLICATION_JSON))
|
||||||
.andExpect(status().isOk());
|
.andExpect(status().isOk());
|
||||||
actions.andExpect(content().contentType("application/json;charset=UTF-8"))
|
actions.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
|
||||||
.andExpect(jsonPath("$.vetList[0].id").value(1));
|
.andExpect(jsonPath("$.vetList[0].id").value(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package org.springframework.samples.petclinic.vet;
|
package org.springframework.samples.petclinic.vet;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.util.SerializationUtils;
|
import org.springframework.util.SerializationUtils;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
Loading…
Reference in a new issue