mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-16 12:55:50 +00:00
cleanup on tests
This commit is contained in:
parent
1dfc3b7a3a
commit
d8a2b5c737
1 changed files with 35 additions and 39 deletions
|
@ -56,21 +56,19 @@ public abstract class AbstractClinicServiceTests {
|
||||||
protected ClinicService clinicService;
|
protected ClinicService clinicService;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldFindOwners() {
|
public void shouldFindOwnersByLastName() {
|
||||||
Collection<Owner> owners = this.clinicService.findOwnerByLastName("Davis");
|
Collection<Owner> owners = this.clinicService.findOwnerByLastName("Davis");
|
||||||
assertThat(owners.size()).isEqualTo(2);
|
assertThat(owners.size()).isEqualTo(2);
|
||||||
|
|
||||||
owners = this.clinicService.findOwnerByLastName("Daviss");
|
owners = this.clinicService.findOwnerByLastName("Daviss");
|
||||||
assertThat(owners.size()).isEqualTo(0);
|
assertThat(owners.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldFindSingleOwner() {
|
public void shouldFindSingleOwnerWithPet() {
|
||||||
Owner owner1 = this.clinicService.findOwnerById(1);
|
Owner owner = this.clinicService.findOwnerById(1);
|
||||||
assertThat(owner1.getLastName()).startsWith("Franklin");
|
assertThat(owner.getLastName()).startsWith("Franklin");
|
||||||
|
assertThat(owner.getPets().size()).isEqualTo(1);
|
||||||
Owner owner10 = this.clinicService.findOwnerById(10);
|
|
||||||
assertThat(owner10.getFirstName()).isEqualTo("Carlos");
|
|
||||||
assertThat(owner1.getPets().size()).isEqualTo(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -78,6 +76,7 @@ public abstract class AbstractClinicServiceTests {
|
||||||
public void shouldInsertOwner() {
|
public void shouldInsertOwner() {
|
||||||
Collection<Owner> owners = this.clinicService.findOwnerByLastName("Schultz");
|
Collection<Owner> owners = this.clinicService.findOwnerByLastName("Schultz");
|
||||||
int found = owners.size();
|
int found = owners.size();
|
||||||
|
|
||||||
Owner owner = new Owner();
|
Owner owner = new Owner();
|
||||||
owner.setFirstName("Sam");
|
owner.setFirstName("Sam");
|
||||||
owner.setLastName("Schultz");
|
owner.setLastName("Schultz");
|
||||||
|
@ -94,29 +93,24 @@ public abstract class AbstractClinicServiceTests {
|
||||||
@Test
|
@Test
|
||||||
@Transactional
|
@Transactional
|
||||||
public void shouldUpdateOwner() {
|
public void shouldUpdateOwner() {
|
||||||
Owner o1 = this.clinicService.findOwnerById(1);
|
Owner owner = this.clinicService.findOwnerById(1);
|
||||||
String old = o1.getLastName();
|
String oldLastName = owner.getLastName();
|
||||||
o1.setLastName(old + "X");
|
String newLastName = oldLastName + "X";
|
||||||
this.clinicService.saveOwner(o1);
|
|
||||||
o1 = this.clinicService.findOwnerById(1);
|
|
||||||
|
|
||||||
assertThat(o1.getLastName()).isEqualTo(old + "X");
|
owner.setLastName(newLastName);
|
||||||
|
this.clinicService.saveOwner(owner);
|
||||||
|
|
||||||
|
// retrieving new name from database
|
||||||
|
owner = this.clinicService.findOwnerById(1);
|
||||||
|
assertThat(owner.getLastName()).isEqualTo(newLastName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldFindPetWithCorrectId() {
|
public void shouldFindPetWithCorrectId() {
|
||||||
Collection<PetType> types = this.clinicService.findPetTypes();
|
|
||||||
|
|
||||||
Pet pet7 = this.clinicService.findPetById(7);
|
Pet pet7 = this.clinicService.findPetById(7);
|
||||||
assertThat(pet7.getName()).startsWith("Samantha");
|
assertThat(pet7.getName()).startsWith("Samantha");
|
||||||
assertThat(EntityUtils.getById(types, PetType.class, 1).getId()).isEqualTo(pet7.getType().getId());
|
|
||||||
assertThat(pet7.getOwner().getFirstName()).isEqualTo("Jean");
|
assertThat(pet7.getOwner().getFirstName()).isEqualTo("Jean");
|
||||||
|
|
||||||
Pet pet6 = this.clinicService.findPetById(6);
|
|
||||||
assertThat(pet6.getName()).isEqualTo("George");
|
|
||||||
|
|
||||||
assertThat(EntityUtils.getById(types, PetType.class, 4).getId()).isEqualTo(pet6.getType().getId());
|
|
||||||
assertThat(pet6.getOwner().getFirstName()).isEqualTo("Peter");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -134,6 +128,7 @@ public abstract class AbstractClinicServiceTests {
|
||||||
public void shouldInsertPetIntoDatabaseAndGenerateId() {
|
public void shouldInsertPetIntoDatabaseAndGenerateId() {
|
||||||
Owner owner6 = this.clinicService.findOwnerById(6);
|
Owner owner6 = this.clinicService.findOwnerById(6);
|
||||||
int found = owner6.getPets().size();
|
int found = owner6.getPets().size();
|
||||||
|
|
||||||
Pet pet = new Pet();
|
Pet pet = new Pet();
|
||||||
pet.setName("bowser");
|
pet.setName("bowser");
|
||||||
Collection<PetType> types = this.clinicService.findPetTypes();
|
Collection<PetType> types = this.clinicService.findPetTypes();
|
||||||
|
@ -141,38 +136,39 @@ public abstract class AbstractClinicServiceTests {
|
||||||
pet.setBirthDate(new DateTime());
|
pet.setBirthDate(new DateTime());
|
||||||
owner6.addPet(pet);
|
owner6.addPet(pet);
|
||||||
assertThat(owner6.getPets().size()).isEqualTo(found + 1);
|
assertThat(owner6.getPets().size()).isEqualTo(found + 1);
|
||||||
// both storePet and storeOwner are necessary to cover all ORM tools
|
|
||||||
this.clinicService.savePet(pet);
|
this.clinicService.savePet(pet);
|
||||||
this.clinicService.saveOwner(owner6);
|
this.clinicService.saveOwner(owner6);
|
||||||
|
|
||||||
owner6 = this.clinicService.findOwnerById(6);
|
owner6 = this.clinicService.findOwnerById(6);
|
||||||
assertThat(owner6.getPets().size()).isEqualTo(found + 1);
|
assertThat(owner6.getPets().size()).isEqualTo(found + 1);
|
||||||
|
// checks that id has been generated
|
||||||
assertThat(pet.getId()).isNotNull();
|
assertThat(pet.getId()).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Transactional
|
@Transactional
|
||||||
public void sholdUpdatePet() throws Exception {
|
public void sholdUpdatePetName() throws Exception {
|
||||||
Pet pet7 = this.clinicService.findPetById(7);
|
Pet pet7 = this.clinicService.findPetById(7);
|
||||||
String old = pet7.getName();
|
String oldName = pet7.getName();
|
||||||
pet7.setName(old + "X");
|
|
||||||
|
String newName = oldName + "X";
|
||||||
|
pet7.setName(newName);
|
||||||
this.clinicService.savePet(pet7);
|
this.clinicService.savePet(pet7);
|
||||||
|
|
||||||
pet7 = this.clinicService.findPetById(7);
|
pet7 = this.clinicService.findPetById(7);
|
||||||
assertThat(pet7.getName()).isEqualTo(old + "X");
|
assertThat(pet7.getName()).isEqualTo(newName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldFindVets() {
|
public void shouldFindVets() {
|
||||||
Collection<Vet> vets = this.clinicService.findVets();
|
Collection<Vet> vets = this.clinicService.findVets();
|
||||||
|
|
||||||
Vet v1 = EntityUtils.getById(vets, Vet.class, 2);
|
Vet vet = EntityUtils.getById(vets, Vet.class, 3);
|
||||||
assertThat(v1.getLastName()).isEqualTo("Leary");
|
assertThat(vet.getLastName()).isEqualTo("Douglas");
|
||||||
assertThat(v1.getNrOfSpecialties()).isEqualTo(1);
|
assertThat(vet.getNrOfSpecialties()).isEqualTo(2);
|
||||||
assertThat(v1.getSpecialties().get(0).getName()).isEqualTo("radiology");
|
assertThat(vet.getSpecialties().get(0).getName()).isEqualTo("dentistry");
|
||||||
Vet v2 = EntityUtils.getById(vets, Vet.class, 3);
|
assertThat(vet.getSpecialties().get(1).getName()).isEqualTo("surgery");
|
||||||
assertThat(v2.getLastName()).isEqualTo("Douglas");
|
|
||||||
assertThat(v2.getNrOfSpecialties()).isEqualTo(2);
|
|
||||||
assertThat(v2.getSpecialties().get(0).getName()).isEqualTo("dentistry");
|
|
||||||
assertThat(v2.getSpecialties().get(1).getName()).isEqualTo("surgery");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -183,9 +179,9 @@ public abstract class AbstractClinicServiceTests {
|
||||||
Visit visit = new Visit();
|
Visit visit = new Visit();
|
||||||
pet7.addVisit(visit);
|
pet7.addVisit(visit);
|
||||||
visit.setDescription("test");
|
visit.setDescription("test");
|
||||||
// both storeVisit and storePet are necessary to cover all ORM tools
|
|
||||||
this.clinicService.saveVisit(visit);
|
this.clinicService.saveVisit(visit);
|
||||||
this.clinicService.savePet(pet7);
|
this.clinicService.savePet(pet7);
|
||||||
|
|
||||||
pet7 = this.clinicService.findPetById(7);
|
pet7 = this.clinicService.findPetById(7);
|
||||||
assertThat(pet7.getVisits().size()).isEqualTo(found + 1);
|
assertThat(pet7.getVisits().size()).isEqualTo(found + 1);
|
||||||
assertThat(visit.getId()).isNotNull();
|
assertThat(visit.getId()).isNotNull();
|
||||||
|
|
Loading…
Reference in a new issue