Search in sources :

Example 1 with Pet

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();
}
Also used : Visit(org.springframework.samples.petclinic.visit.Visit) Pet(org.springframework.samples.petclinic.owner.Pet) Test(org.junit.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with Pet

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());
}
Also used : Owner(org.springframework.samples.petclinic.owner.Owner) Pet(org.springframework.samples.petclinic.owner.Pet) PetType(org.springframework.samples.petclinic.owner.PetType) Before(org.junit.Before)

Example 3 with 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();
}
Also used : Owner(org.springframework.samples.petclinic.owner.Owner) Pet(org.springframework.samples.petclinic.owner.Pet) Date(java.util.Date) PetType(org.springframework.samples.petclinic.owner.PetType) Test(org.junit.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with Pet

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);
}
Also used : Pet(org.springframework.samples.petclinic.owner.Pet) Test(org.junit.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with Pet

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");
}
Also used : Pet(org.springframework.samples.petclinic.owner.Pet) Test(org.junit.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)

Aggregations

Pet (org.springframework.samples.petclinic.owner.Pet)5 Test (org.junit.Test)4 DataJpaTest (org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)4 Transactional (org.springframework.transaction.annotation.Transactional)3 Owner (org.springframework.samples.petclinic.owner.Owner)2 PetType (org.springframework.samples.petclinic.owner.PetType)2 Date (java.util.Date)1 Before (org.junit.Before)1 Visit (org.springframework.samples.petclinic.visit.Visit)1