mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-17 04:55:50 +00:00
Updating using GitHub API 2025-06-19-15:31
This commit is contained in:
parent
f75823ddc2
commit
f07727b6f3
1 changed files with 27 additions and 25 deletions
|
@ -73,25 +73,27 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
class ClinicServiceTests {
|
class ClinicServiceTests {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
protected OwnerRepository owners;
|
protected OwnerRepository ownerRepository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
protected VetRepository vets;
|
protected VetRepository vetRepository;
|
||||||
|
|
||||||
Pageable pageable;
|
Pageable pageable;
|
||||||
|
|
||||||
|
private static final String SCHULTZ_LAST_NAME = "Schultz";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldFindOwnersByLastName() {
|
void shouldFindOwnersByLastName() {
|
||||||
Page<Owner> owners = this.owners.findByLastNameStartingWith("Davis", pageable);
|
Page<Owner> owners = this.ownerRepository.findByLastNameStartingWith("Davis", pageable);
|
||||||
assertThat(owners).hasSize(2);
|
assertThat(owners).hasSize(2);
|
||||||
|
|
||||||
owners = this.owners.findByLastNameStartingWith("Daviss", pageable);
|
owners = this.ownerRepository.findByLastNameStartingWith("Daviss", pageable);
|
||||||
assertThat(owners).isEmpty();
|
assertThat(owners).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldFindSingleOwnerWithPet() {
|
void shouldFindSingleOwnerWithPet() {
|
||||||
Optional<Owner> optionalOwner = this.owners.findById(1);
|
Optional<Owner> optionalOwner = this.ownerRepository.findById(1);
|
||||||
assertThat(optionalOwner).isPresent();
|
assertThat(optionalOwner).isPresent();
|
||||||
Owner owner = optionalOwner.get();
|
Owner owner = optionalOwner.get();
|
||||||
assertThat(owner.getLastName()).startsWith("Franklin");
|
assertThat(owner.getLastName()).startsWith("Franklin");
|
||||||
|
@ -103,36 +105,36 @@ class ClinicServiceTests {
|
||||||
@Test
|
@Test
|
||||||
@Transactional
|
@Transactional
|
||||||
void shouldInsertOwner() {
|
void shouldInsertOwner() {
|
||||||
Page<Owner> owners = this.owners.findByLastNameStartingWith("Schultz", pageable);
|
Page<Owner> owners = this.ownerRepository.findByLastNameStartingWith(SCHULTZ_LAST_NAME, pageable);
|
||||||
int found = (int) owners.getTotalElements();
|
int found = (int) owners.getTotalElements();
|
||||||
|
|
||||||
Owner owner = new Owner();
|
Owner owner = new Owner();
|
||||||
owner.setFirstName("Sam");
|
owner.setFirstName("Sam");
|
||||||
owner.setLastName("Schultz");
|
owner.setLastName(SCHULTZ_LAST_NAME);
|
||||||
owner.setAddress("4, Evans Street");
|
owner.setAddress("4, Evans Street");
|
||||||
owner.setCity("Wollongong");
|
owner.setCity("Wollongong");
|
||||||
owner.setTelephone("4444444444");
|
owner.setTelephone("4444444444");
|
||||||
this.owners.save(owner);
|
this.ownerRepository.save(owner);
|
||||||
assertThat(owner.getId()).isNotZero();
|
assertThat(owner.getId()).isNotZero();
|
||||||
|
|
||||||
owners = this.owners.findByLastNameStartingWith("Schultz", pageable);
|
owners = this.ownerRepository.findByLastNameStartingWith(SCHULTZ_LAST_NAME, pageable);
|
||||||
assertThat(owners.getTotalElements()).isEqualTo(found + 1);
|
assertThat(owners.getTotalElements()).isEqualTo(found + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Transactional
|
@Transactional
|
||||||
void shouldUpdateOwner() {
|
void shouldUpdateOwner() {
|
||||||
Optional<Owner> optionalOwner = this.owners.findById(1);
|
Optional<Owner> optionalOwner = this.ownerRepository.findById(1);
|
||||||
assertThat(optionalOwner).isPresent();
|
assertThat(optionalOwner).isPresent();
|
||||||
Owner owner = optionalOwner.get();
|
Owner owner = optionalOwner.get();
|
||||||
String oldLastName = owner.getLastName();
|
String oldLastName = owner.getLastName();
|
||||||
String newLastName = oldLastName + "X";
|
String newLastName = oldLastName + "X";
|
||||||
|
|
||||||
owner.setLastName(newLastName);
|
owner.setLastName(newLastName);
|
||||||
this.owners.save(owner);
|
this.ownerRepository.save(owner);
|
||||||
|
|
||||||
// retrieving new name from database
|
// retrieving new name from database
|
||||||
optionalOwner = this.owners.findById(1);
|
optionalOwner = this.ownerRepository.findById(1);
|
||||||
assertThat(optionalOwner).isPresent();
|
assertThat(optionalOwner).isPresent();
|
||||||
owner = optionalOwner.get();
|
owner = optionalOwner.get();
|
||||||
assertThat(owner.getLastName()).isEqualTo(newLastName);
|
assertThat(owner.getLastName()).isEqualTo(newLastName);
|
||||||
|
@ -140,7 +142,7 @@ class ClinicServiceTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldFindAllPetTypes() {
|
void shouldFindAllPetTypes() {
|
||||||
Collection<PetType> petTypes = this.owners.findPetTypes();
|
Collection<PetType> petTypes = this.ownerRepository.findPetTypes();
|
||||||
|
|
||||||
PetType petType1 = EntityUtils.getById(petTypes, PetType.class, 1);
|
PetType petType1 = EntityUtils.getById(petTypes, PetType.class, 1);
|
||||||
assertThat(petType1.getName()).isEqualTo("cat");
|
assertThat(petType1.getName()).isEqualTo("cat");
|
||||||
|
@ -151,7 +153,7 @@ class ClinicServiceTests {
|
||||||
@Test
|
@Test
|
||||||
@Transactional
|
@Transactional
|
||||||
void shouldInsertPetIntoDatabaseAndGenerateId() {
|
void shouldInsertPetIntoDatabaseAndGenerateId() {
|
||||||
Optional<Owner> optionalOwner = this.owners.findById(6);
|
Optional<Owner> optionalOwner = this.ownerRepository.findById(6);
|
||||||
assertThat(optionalOwner).isPresent();
|
assertThat(optionalOwner).isPresent();
|
||||||
Owner owner6 = optionalOwner.get();
|
Owner owner6 = optionalOwner.get();
|
||||||
|
|
||||||
|
@ -159,15 +161,15 @@ class ClinicServiceTests {
|
||||||
|
|
||||||
Pet pet = new Pet();
|
Pet pet = new Pet();
|
||||||
pet.setName("bowser");
|
pet.setName("bowser");
|
||||||
Collection<PetType> types = this.owners.findPetTypes();
|
Collection<PetType> types = this.ownerRepository.findPetTypes();
|
||||||
pet.setType(EntityUtils.getById(types, PetType.class, 2));
|
pet.setType(EntityUtils.getById(types, PetType.class, 2));
|
||||||
pet.setBirthDate(LocalDate.now());
|
pet.setBirthDate(LocalDate.now());
|
||||||
owner6.addPet(pet);
|
owner6.addPet(pet);
|
||||||
assertThat(owner6.getPets()).hasSize(found + 1);
|
assertThat(owner6.getPets()).hasSize(found + 1);
|
||||||
|
|
||||||
this.owners.save(owner6);
|
this.ownerRepository.save(owner6);
|
||||||
|
|
||||||
optionalOwner = this.owners.findById(6);
|
optionalOwner = this.ownerRepository.findById(6);
|
||||||
assertThat(optionalOwner).isPresent();
|
assertThat(optionalOwner).isPresent();
|
||||||
owner6 = optionalOwner.get();
|
owner6 = optionalOwner.get();
|
||||||
assertThat(owner6.getPets()).hasSize(found + 1);
|
assertThat(owner6.getPets()).hasSize(found + 1);
|
||||||
|
@ -179,7 +181,7 @@ class ClinicServiceTests {
|
||||||
@Test
|
@Test
|
||||||
@Transactional
|
@Transactional
|
||||||
void shouldUpdatePetName() {
|
void shouldUpdatePetName() {
|
||||||
Optional<Owner> optionalOwner = this.owners.findById(6);
|
Optional<Owner> optionalOwner = this.ownerRepository.findById(6);
|
||||||
assertThat(optionalOwner).isPresent();
|
assertThat(optionalOwner).isPresent();
|
||||||
Owner owner6 = optionalOwner.get();
|
Owner owner6 = optionalOwner.get();
|
||||||
|
|
||||||
|
@ -188,9 +190,9 @@ class ClinicServiceTests {
|
||||||
|
|
||||||
String newName = oldName + "X";
|
String newName = oldName + "X";
|
||||||
pet7.setName(newName);
|
pet7.setName(newName);
|
||||||
this.owners.save(owner6);
|
this.ownerRepository.save(owner6);
|
||||||
|
|
||||||
optionalOwner = this.owners.findById(6);
|
optionalOwner = this.ownerRepository.findById(6);
|
||||||
assertThat(optionalOwner).isPresent();
|
assertThat(optionalOwner).isPresent();
|
||||||
owner6 = optionalOwner.get();
|
owner6 = optionalOwner.get();
|
||||||
pet7 = owner6.getPet(7);
|
pet7 = owner6.getPet(7);
|
||||||
|
@ -199,7 +201,7 @@ class ClinicServiceTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldFindVets() {
|
void shouldFindVets() {
|
||||||
Collection<Vet> vets = this.vets.findAll();
|
Collection<Vet> vets = this.vetRepository.findAll();
|
||||||
|
|
||||||
Vet vet = EntityUtils.getById(vets, Vet.class, 3);
|
Vet vet = EntityUtils.getById(vets, Vet.class, 3);
|
||||||
assertThat(vet.getLastName()).isEqualTo("Douglas");
|
assertThat(vet.getLastName()).isEqualTo("Douglas");
|
||||||
|
@ -211,7 +213,7 @@ class ClinicServiceTests {
|
||||||
@Test
|
@Test
|
||||||
@Transactional
|
@Transactional
|
||||||
void shouldAddNewVisitForPet() {
|
void shouldAddNewVisitForPet() {
|
||||||
Optional<Owner> optionalOwner = this.owners.findById(6);
|
Optional<Owner> optionalOwner = this.ownerRepository.findById(6);
|
||||||
assertThat(optionalOwner).isPresent();
|
assertThat(optionalOwner).isPresent();
|
||||||
Owner owner6 = optionalOwner.get();
|
Owner owner6 = optionalOwner.get();
|
||||||
|
|
||||||
|
@ -221,7 +223,7 @@ class ClinicServiceTests {
|
||||||
visit.setDescription("test");
|
visit.setDescription("test");
|
||||||
|
|
||||||
owner6.addVisit(pet7.getId(), visit);
|
owner6.addVisit(pet7.getId(), visit);
|
||||||
this.owners.save(owner6);
|
this.ownerRepository.save(owner6);
|
||||||
|
|
||||||
assertThat(pet7.getVisits()) //
|
assertThat(pet7.getVisits()) //
|
||||||
.hasSize(found + 1) //
|
.hasSize(found + 1) //
|
||||||
|
@ -230,7 +232,7 @@ class ClinicServiceTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldFindVisitsByPetId() {
|
void shouldFindVisitsByPetId() {
|
||||||
Optional<Owner> optionalOwner = this.owners.findById(6);
|
Optional<Owner> optionalOwner = this.ownerRepository.findById(6);
|
||||||
assertThat(optionalOwner).isPresent();
|
assertThat(optionalOwner).isPresent();
|
||||||
Owner owner6 = optionalOwner.get();
|
Owner owner6 = optionalOwner.get();
|
||||||
|
|
||||||
|
@ -244,4 +246,4 @@ class ClinicServiceTests {
|
||||||
.isNotNull();
|
.isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue