use of org.springframework.samples.petclinic.owner.Pet in project spring-petclinic by spring-projects.
the class ClinicServiceTests method shouldAddNewVisitForPet.
@Test
@Transactional
public void shouldAddNewVisitForPet() {
Pet pet7 = this.pets.findById(7);
int found = pet7.getVisits().size();
Visit visit = new Visit();
pet7.addVisit(visit);
visit.setDescription("test");
this.visits.save(visit);
this.pets.save(pet7);
pet7 = this.pets.findById(7);
assertThat(pet7.getVisits().size()).isEqualTo(found + 1);
assertThat(visit.getId()).isNotNull();
}
use of org.springframework.samples.petclinic.owner.Pet in project spring-petclinic by spring-projects.
the class PetControllerTests method setup.
@Before
public void setup() {
PetType cat = new PetType();
cat.setId(3);
cat.setName("hamster");
given(this.pets.findPetTypes()).willReturn(Lists.newArrayList(cat));
given(this.owners.findById(TEST_OWNER_ID)).willReturn(new Owner());
given(this.pets.findById(TEST_PET_ID)).willReturn(new Pet());
}
use of org.springframework.samples.petclinic.owner.Pet in project spring-petclinic by spring-projects.
the class ClinicServiceTests method shouldInsertPetIntoDatabaseAndGenerateId.
@Test
@Transactional
public void shouldInsertPetIntoDatabaseAndGenerateId() {
Owner owner6 = this.owners.findById(6);
int found = owner6.getPets().size();
Pet pet = new Pet();
pet.setName("bowser");
Collection<PetType> types = this.pets.findPetTypes();
pet.setType(EntityUtils.getById(types, PetType.class, 2));
pet.setBirthDate(new Date());
owner6.addPet(pet);
assertThat(owner6.getPets().size()).isEqualTo(found + 1);
this.pets.save(pet);
this.owners.save(owner6);
owner6 = this.owners.findById(6);
assertThat(owner6.getPets().size()).isEqualTo(found + 1);
// checks that id has been generated
assertThat(pet.getId()).isNotNull();
}
use of org.springframework.samples.petclinic.owner.Pet in project spring-petclinic by spring-projects.
the class ClinicServiceTests method shouldUpdatePetName.
@Test
@Transactional
public void shouldUpdatePetName() throws Exception {
Pet pet7 = this.pets.findById(7);
String oldName = pet7.getName();
String newName = oldName + "X";
pet7.setName(newName);
this.pets.save(pet7);
pet7 = this.pets.findById(7);
assertThat(pet7.getName()).isEqualTo(newName);
}
use of org.springframework.samples.petclinic.owner.Pet in project spring-petclinic by spring-projects.
the class ClinicServiceTests method shouldFindPetWithCorrectId.
@Test
public void shouldFindPetWithCorrectId() {
Pet pet7 = this.pets.findById(7);
assertThat(pet7.getName()).startsWith("Samantha");
assertThat(pet7.getOwner().getFirstName()).isEqualTo("Jean");
}
Aggregations