@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(LocalDate.now());
        owner6.addPet(pet);
        assertThat(owner6.getPets()).hasSize(found + 1);

        this.clinicService.savePet(pet);
        this.clinicService.saveOwner(owner6);

        owner6 = this.clinicService.findOwnerById(6);
        assertThat(owner6.getPets()).hasSize(found + 1);
        // checks that id has been generated
        assertThat(pet.getId()).isNotNull();
    }
<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>{@link
AbstractClinicServiceTests#clinicService clinicService}</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
@author Juergen Hoeller
@author Sam Brannen
@author Michael Isvy
src/test/java/org/springframework/samples/petclinic/service/AbstractClinicServiceTests.java