-
Notifications
You must be signed in to change notification settings - Fork 95
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
xaldama
wants to merge
4
commits into
spring-petclinic:master
Choose a base branch
from
hdiv:feature/hateoas1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,12 @@ | |
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
@@ -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 | ||
|
@@ -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(); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.