Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated to springboot 2.4.11 #25

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<version>2.4.11</version>
</parent>

<groupId>org.springframework.samples</groupId>
Expand Down
5 changes: 5 additions & 0 deletions spring-petclinic-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.samples</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,39 @@
import javax.validation.ConstraintViolation;
import javax.validation.Validator;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;

/**
*
* @author Michael Isvy
* Simple test to make sure that Bean Validation is working
* (useful when upgrading to a new version of Hibernate Validator/ Bean Validation)
* @author Michael Isvy Simple test to make sure that Bean Validation is working (useful when upgrading to a new version of Hibernate
* Validator/ Bean Validation)
*
*/
public class ValidatorTests {

private Validator createValidator() {
LocalValidatorFactoryBean localValidatorFactoryBean = new LocalValidatorFactoryBean();
localValidatorFactoryBean.afterPropertiesSet();
return localValidatorFactoryBean;
}
LocalValidatorFactoryBean localValidatorFactoryBean = new LocalValidatorFactoryBean();
localValidatorFactoryBean.afterPropertiesSet();
return localValidatorFactoryBean;
}

@Test
public void shouldNotValidateWhenFirstNameEmpty() {
public void shouldNotValidateWhenFirstNameEmpty() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By migration to Spring 5, you may remove the public visibility.


LocaleContextHolder.setLocale(Locale.ENGLISH);
Person person = new Person();
person.setFirstName("");
person.setLastName("smith");
LocaleContextHolder.setLocale(Locale.ENGLISH);
Person person = new Person();
person.setFirstName("");
person.setLastName("smith");

Validator validator = createValidator();
Set<ConstraintViolation<Person>> constraintViolations = validator.validate(person);
Validator validator = createValidator();
Set<ConstraintViolation<Person>> constraintViolations = validator.validate(person);

assertThat(constraintViolations.size()).isEqualTo(1);
ConstraintViolation<Person> violation = constraintViolations.iterator().next();
assertThat(violation.getPropertyPath().toString()).isEqualTo("firstName");
assertThat(violation.getMessage()).isEqualTo("must not be empty");
}
assertThat(constraintViolations.size()).isEqualTo(1);
ConstraintViolation<Person> violation = constraintViolations.iterator().next();
assertThat(violation.getPropertyPath().toString()).isEqualTo("firstName");
assertThat(violation.getMessage()).isEqualTo("must not be empty");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to GitHub, there is some conflicts to resolve

package org.springframework.samples.petclinic.service;

import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;

import java.util.Collection;
import java.util.Date;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.samples.petclinic.model.Owner;
import org.springframework.samples.petclinic.model.Pet;
Expand All @@ -25,22 +30,25 @@
import org.springframework.test.context.ContextConfiguration;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;
import java.util.Date;

import static org.assertj.core.api.Assertions.assertThat;

/**
* <p> Base class for {@link ClinicService} integration tests. </p> <p> Subclasses should specify Spring context
* configuration using {@link ContextConfiguration @ContextConfiguration} annotation </p> <p>
* AbstractclinicServiceTests and its subclasses benefit from the following services provided by the Spring
* TestContext Framework: </p> <ul> <li><strong>Spring IoC container caching</strong> which spares us unnecessary set up
* time between test execution.</li> <li><strong>Dependency Injection</strong> of test fixture instances, meaning that
* we don't need to perform application context lookups. See the use of {@link Autowired @Autowired} on the <code></code> instance variable, which uses autowiring <em>by
* type</em>. <li><strong>Transaction management</strong>, meaning each test method is executed in its own transaction,
* which is automatically rolled back by default. Thus, even if tests insert or otherwise change database state, there
* is no need for a teardown or cleanup script. <li> An {@link org.springframework.context.ApplicationContext
* ApplicationContext} is also inherited and can be used for explicit bean lookup if necessary. </li> </ul>
* <p>
* Base class for {@link ClinicService} integration tests.
* </p>
* <p>
* Subclasses should specify Spring context configuration using {@link ContextConfiguration @ContextConfiguration} annotation
* </p>
* <p>
* AbstractclinicServiceTests and its subclasses benefit from the following services provided by the Spring TestContext Framework:
* </p>
* <ul>
* <li><strong>Spring IoC container caching</strong> which spares us unnecessary set up time between test execution.</li>
* <li><strong>Dependency Injection</strong> of test fixture instances, meaning that we don't need to perform application context lookups.
* See the use of {@link Autowired @Autowired} on the <code></code> instance variable, which uses autowiring <em>by type</em>.
* <li><strong>Transaction management</strong>, meaning each test method is executed in its own transaction, which is automatically rolled
* back by default. Thus, even if tests insert or otherwise change database state, there is no need for a teardown or cleanup script.
* <li>An {@link org.springframework.context.ApplicationContext ApplicationContext} is also inherited and can be used for explicit bean
* lookup if necessary.</li>
* </ul>
*
* @author Ken Krebs
* @author Rod Johnson
Expand All @@ -50,137 +58,136 @@
*/
public abstract class AbstractClinicServiceTests {

@Autowired
protected ClinicService clinicService;

@Test
public void shouldFindSingleOwnerWithPet() {
Owner owner = this.clinicService.findOwnerById(1);
assertThat(owner.getLastName()).startsWith("Franklin");
assertThat(owner.getPets().size()).isEqualTo(1);
}
@Test
public void shouldReturnAllOwnersInCaseLastNameIsEmpty() {
Collection<Owner> owners = this.clinicService.findAll();
assertThat(owners).extracting("lastName").contains("Davis", "Franklin");
}

@Test
@Transactional
public void shouldInsertOwner() {
Collection<Owner> owners = this.clinicService.findAll();
int found = owners.size();
Owner owner = new Owner();
owner.setFirstName("Sam");
owner.setLastName("Schultz");
owner.setAddress("4, Evans Street");
owner.setCity("Wollongong");
owner.setTelephone("4444444444");
this.clinicService.saveOwner(owner);
assertThat(owner.getId().longValue()).isNotEqualTo(0);

owners = this.clinicService.findAll();
assertThat(owners.size()).isEqualTo(found + 1);
}

@Test
@Transactional
public void shouldUpdateOwner() {
Owner owner = this.clinicService.findOwnerById(1);
String oldLastName = owner.getLastName();
String newLastName = oldLastName + "X";
owner.setLastName(newLastName);
this.clinicService.saveOwner(owner);

// retrieving new name from database
owner = this.clinicService.findOwnerById(1);
assertThat(owner.getLastName()).isEqualTo(newLastName);
}
@Autowired
protected ClinicService clinicService;

@Test
public void shouldFindSingleOwnerWithPet() {
Owner owner = clinicService.findOwnerById(1);
assertThat(owner.getLastName()).startsWith("Franklin");
assertThat(owner.getPets().size()).isEqualTo(1);
}

@Test
public void shouldReturnAllOwnersInCaseLastNameIsEmpty() {
Collection<Owner> owners = clinicService.findAll();
assertThat(owners).extracting("lastName").contains("Davis", "Franklin");
}

@Test
@Transactional
public void shouldInsertOwner() {
Collection<Owner> owners = clinicService.findAll();
int found = owners.size();

Owner owner = new Owner();
owner.setFirstName("Sam");
owner.setLastName("Schultz");
owner.setAddress("4, Evans Street");
owner.setCity("Wollongong");
owner.setTelephone("4444444444");
clinicService.saveOwner(owner);
assertThat(owner.getId().longValue()).isNotEqualTo(0);

owners = clinicService.findAll();
assertThat(owners.size()).isEqualTo(found + 1);
}

@Test
@Transactional
public void shouldUpdateOwner() {
Owner owner = clinicService.findOwnerById(1);
String oldLastName = owner.getLastName();
String newLastName = oldLastName + "X";

owner.setLastName(newLastName);
clinicService.saveOwner(owner);

// retrieving new name from database
owner = clinicService.findOwnerById(1);
assertThat(owner.getLastName()).isEqualTo(newLastName);
}

@Test
public void shouldFindPetWithCorrectId() {
Pet pet7 = this.clinicService.findPetById(7);
assertThat(pet7.getName()).startsWith("Samantha");
assertThat(pet7.getOwner().getFirstName()).isEqualTo("Jean");
Pet pet7 = clinicService.findPetById(7);
assertThat(pet7.getName()).startsWith("Samantha");
assertThat(pet7.getOwner().getFirstName()).isEqualTo("Jean");

}

@Test
public void shouldFindAllPetTypes() {
Collection<PetType> petTypes = this.clinicService.findPetTypes();
PetType petType1 = EntityUtils.getById(petTypes, PetType.class, 1);
assertThat(petType1.getName()).isEqualTo("cat");
PetType petType4 = EntityUtils.getById(petTypes, PetType.class, 4);
assertThat(petType4.getName()).isEqualTo("snake");
Collection<PetType> petTypes = clinicService.findPetTypes();

PetType petType1 = EntityUtils.getById(petTypes, PetType.class, 1);
assertThat(petType1.getName()).isEqualTo("cat");
PetType petType4 = EntityUtils.getById(petTypes, PetType.class, 4);
assertThat(petType4.getName()).isEqualTo("snake");
}

@Test
@Transactional
public void shouldInsertPetIntoDatabaseAndGenerateId() {
Owner owner6 = this.clinicService.findOwnerById(6);
int found = owner6.getPets().size();
Pet pet = new Pet();
pet.setName("bowser");
Collection<PetType> types = this.clinicService.findPetTypes();
pet.setType(EntityUtils.getById(types, PetType.class, 2));
pet.setBirthDate(new Date());
owner6.addPet(pet);
assertThat(owner6.getPets().size()).isEqualTo(found + 1);
this.clinicService.savePet(pet);
this.clinicService.saveOwner(owner6);
owner6 = this.clinicService.findOwnerById(6);
assertThat(owner6.getPets().size()).isEqualTo(found + 1);
// checks that id has been generated
assertThat(pet.getId()).isNotNull();
Owner owner6 = clinicService.findOwnerById(6);
int found = owner6.getPets().size();

Pet pet = new Pet();
pet.setName("bowser");
Collection<PetType> types = clinicService.findPetTypes();
pet.setType(EntityUtils.getById(types, PetType.class, 2));
pet.setBirthDate(new Date());
owner6.addPet(pet);
assertThat(owner6.getPets().size()).isEqualTo(found + 1);

clinicService.savePet(pet);
clinicService.saveOwner(owner6);

owner6 = clinicService.findOwnerById(6);
assertThat(owner6.getPets().size()).isEqualTo(found + 1);
// checks that id has been generated
assertThat(pet.getId()).isNotNull();
}

@Test
@Transactional
public void shouldUpdatePetName() throws Exception {
Pet pet7 = this.clinicService.findPetById(7);
String oldName = pet7.getName();
String newName = oldName + "X";
Pet pet7 = clinicService.findPetById(7);
String oldName = pet7.getName();

String newName = oldName + "X";
pet7.setName(newName);
this.clinicService.savePet(pet7);
clinicService.savePet(pet7);

pet7 = this.clinicService.findPetById(7);
assertThat(pet7.getName()).isEqualTo(newName);
pet7 = clinicService.findPetById(7);
assertThat(pet7.getName()).isEqualTo(newName);
}

@Test
public void shouldFindVets() {
Collection<Vet> vets = this.clinicService.findVets();
Vet vet = EntityUtils.getById(vets, Vet.class, 3);
assertThat(vet.getLastName()).isEqualTo("Douglas");
assertThat(vet.getNrOfSpecialties()).isEqualTo(2);
assertThat(vet.getSpecialties().get(0).getName()).isEqualTo("dentistry");
assertThat(vet.getSpecialties().get(1).getName()).isEqualTo("surgery");
Collection<Vet> vets = clinicService.findVets();

Vet vet = EntityUtils.getById(vets, Vet.class, 3);
assertThat(vet.getLastName()).isEqualTo("Douglas");
assertThat(vet.getNrOfSpecialties()).isEqualTo(2);
assertThat(vet.getSpecialties().get(0).getName()).isEqualTo("dentistry");
assertThat(vet.getSpecialties().get(1).getName()).isEqualTo("surgery");
}

@Test
@Transactional
public void shouldAddNewVisitForPet() {
Pet pet7 = this.clinicService.findPetById(7);
int found = pet7.getVisits().size();
Visit visit = new Visit();
pet7.addVisit(visit);
visit.setDescription("test");
this.clinicService.saveVisit(visit);
this.clinicService.savePet(pet7);

pet7 = this.clinicService.findPetById(7);
assertThat(pet7.getVisits().size()).isEqualTo(found + 1);
assertThat(visit.getId()).isNotNull();
Pet pet7 = clinicService.findPetById(7);
int found = pet7.getVisits().size();
Visit visit = new Visit();
pet7.addVisit(visit);
visit.setDescription("test");
clinicService.saveVisit(visit);
clinicService.savePet(pet7);

pet7 = clinicService.findPetById(7);
assertThat(pet7.getVisits().size()).isEqualTo(found + 1);
assertThat(visit.getId()).isNotNull();
}


}
Loading