Search in sources :

Example 6 with Owner

use of org.springframework.samples.petclinic.owner.Owner 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)

Aggregations

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