mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-15 12:25:50 +00:00
moved to tests to service level package
This commit is contained in:
parent
ebfa300f91
commit
faca0eb1c2
17 changed files with 97 additions and 448 deletions
|
@ -1,103 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2002-2013 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.samples.petclinic.repository;
|
|
||||||
|
|
||||||
import org.joda.time.DateTime;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.samples.petclinic.model.Owner;
|
|
||||||
import org.springframework.samples.petclinic.model.Pet;
|
|
||||||
import org.springframework.samples.petclinic.model.PetType;
|
|
||||||
import org.springframework.samples.petclinic.service.ClinicService;
|
|
||||||
import org.springframework.samples.petclinic.util.EntityUtils;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p> Base class for {@link OwnerRepository} integration tests. </p>
|
|
||||||
* <p/>
|
|
||||||
* see javadoc inside {@link AbstractOwnerRepositoryTests} for more details
|
|
||||||
*
|
|
||||||
* @author Ken Krebs
|
|
||||||
* @author Rod Johnson
|
|
||||||
* @author Juergen Hoeller
|
|
||||||
* @author Sam Brannen
|
|
||||||
* @author Michael Isvy
|
|
||||||
*/
|
|
||||||
public abstract class AbstractPetRepositoryTests {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
protected ClinicService clinicService;
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getPetTypes() {
|
|
||||||
Collection<PetType> petTypes = this.clinicService.findPetTypes();
|
|
||||||
|
|
||||||
PetType petType1 = EntityUtils.getById(petTypes, PetType.class, 1);
|
|
||||||
assertEquals("cat", petType1.getName());
|
|
||||||
PetType petType4 = EntityUtils.getById(petTypes, PetType.class, 4);
|
|
||||||
assertEquals("snake", petType4.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void findPet() {
|
|
||||||
Collection<PetType> types = this.clinicService.findPetTypes();
|
|
||||||
Pet pet7 = this.clinicService.findPetById(7);
|
|
||||||
assertTrue(pet7.getName().startsWith("Samantha"));
|
|
||||||
assertEquals(EntityUtils.getById(types, PetType.class, 1).getId(), pet7.getType().getId());
|
|
||||||
assertEquals("Jean", pet7.getOwner().getFirstName());
|
|
||||||
Pet pet6 = this.clinicService.findPetById(6);
|
|
||||||
assertEquals("George", pet6.getName());
|
|
||||||
assertEquals(EntityUtils.getById(types, PetType.class, 4).getId(), pet6.getType().getId());
|
|
||||||
assertEquals("Peter", pet6.getOwner().getFirstName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Transactional
|
|
||||||
public void insertPet() {
|
|
||||||
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 DateTime());
|
|
||||||
owner6.addPet(pet);
|
|
||||||
assertEquals(found + 1, owner6.getPets().size());
|
|
||||||
// both storePet and storeOwner are necessary to cover all ORM tools
|
|
||||||
this.clinicService.savePet(pet);
|
|
||||||
this.clinicService.saveOwner(owner6);
|
|
||||||
owner6 = this.clinicService.findOwnerById(6);
|
|
||||||
assertEquals(found + 1, owner6.getPets().size());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Transactional
|
|
||||||
public void updatePet() throws Exception {
|
|
||||||
Pet pet7 = this.clinicService.findPetById(7);
|
|
||||||
String old = pet7.getName();
|
|
||||||
pet7.setName(old + "X");
|
|
||||||
this.clinicService.savePet(pet7);
|
|
||||||
pet7 = this.clinicService.findPetById(7);
|
|
||||||
assertEquals(old + "X", pet7.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,60 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2002-2013 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.samples.petclinic.repository;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.samples.petclinic.model.Vet;
|
|
||||||
import org.springframework.samples.petclinic.service.ClinicService;
|
|
||||||
import org.springframework.samples.petclinic.util.EntityUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p> Base class for {@link OwnerRepository} integration tests. </p>
|
|
||||||
* <p/>
|
|
||||||
* see javadoc inside {@link AbstractVetRepositoryTests} for more details
|
|
||||||
*
|
|
||||||
* @author Ken Krebs
|
|
||||||
* @author Rod Johnson
|
|
||||||
* @author Juergen Hoeller
|
|
||||||
* @author Sam Brannen
|
|
||||||
* @author Michael Isvy
|
|
||||||
*/
|
|
||||||
public abstract class AbstractVetRepositoryTests {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
protected ClinicService clinicService;
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void findVets() {
|
|
||||||
Collection<Vet> vets = this.clinicService.findVets();
|
|
||||||
|
|
||||||
Vet v1 = EntityUtils.getById(vets, Vet.class, 2);
|
|
||||||
assertEquals("Leary", v1.getLastName());
|
|
||||||
assertEquals(1, v1.getNrOfSpecialties());
|
|
||||||
assertEquals("radiology", (v1.getSpecialties().get(0)).getName());
|
|
||||||
Vet v2 = EntityUtils.getById(vets, Vet.class, 3);
|
|
||||||
assertEquals("Douglas", v2.getLastName());
|
|
||||||
assertEquals(2, v2.getNrOfSpecialties());
|
|
||||||
assertEquals("dentistry", (v2.getSpecialties().get(0)).getName());
|
|
||||||
assertEquals("surgery", (v2.getSpecialties().get(1)).getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,59 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2002-2013 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.samples.petclinic.repository;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.samples.petclinic.model.Pet;
|
|
||||||
import org.springframework.samples.petclinic.model.Visit;
|
|
||||||
import org.springframework.samples.petclinic.service.ClinicService;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p> Base class for {@link OwnerRepository} integration tests. </p>
|
|
||||||
* <p/>
|
|
||||||
* see javadoc inside {@link AbstractVetRepositoryTests} for more details
|
|
||||||
*
|
|
||||||
* @author Ken Krebs
|
|
||||||
* @author Rod Johnson
|
|
||||||
* @author Juergen Hoeller
|
|
||||||
* @author Sam Brannen
|
|
||||||
* @author Michael Isvy
|
|
||||||
*/
|
|
||||||
public abstract class AbstractVisitRepositoryTests {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
protected ClinicService clinicService;
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Transactional
|
|
||||||
public void insertVisit() {
|
|
||||||
Pet pet7 = this.clinicService.findPetById(7);
|
|
||||||
int found = pet7.getVisits().size();
|
|
||||||
Visit visit = new Visit();
|
|
||||||
pet7.addVisit(visit);
|
|
||||||
visit.setDescription("test");
|
|
||||||
// both storeVisit and storePet are necessary to cover all ORM tools
|
|
||||||
this.clinicService.saveVisit(visit);
|
|
||||||
this.clinicService.savePet(pet7);
|
|
||||||
pet7 = this.clinicService.findPetById(7);
|
|
||||||
assertEquals(found + 1, pet7.getVisits().size());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
package org.springframework.samples.petclinic.repository.jdbc;
|
|
||||||
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.samples.petclinic.repository.AbstractPetRepositoryTests;
|
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p> Integration tests for the {@link JdbcClinicImpl} implementation. </p> <p> </p>
|
|
||||||
*
|
|
||||||
* @author Thomas Risberg
|
|
||||||
* @author Michael Isvy
|
|
||||||
*/
|
|
||||||
@ContextConfiguration(locations = {"classpath:spring/business-config.xml"})
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
@ActiveProfiles("jdbc")
|
|
||||||
public class JdbcPetRepositoryImplTests extends AbstractPetRepositoryTests {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
package org.springframework.samples.petclinic.repository.jdbc;
|
|
||||||
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.samples.petclinic.repository.AbstractVetRepositoryTests;
|
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p> Integration tests for the {@link JdbcClinicImpl} implementation. </p> <p> </p>
|
|
||||||
*
|
|
||||||
* @author Thomas Risberg
|
|
||||||
* @author Michael Isvy
|
|
||||||
*/
|
|
||||||
@ContextConfiguration(locations = {"classpath:spring/business-config.xml"})
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
@ActiveProfiles("jdbc")
|
|
||||||
public class JdbcVetRepositoryImplTests extends AbstractVetRepositoryTests {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
package org.springframework.samples.petclinic.repository.jdbc;
|
|
||||||
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.samples.petclinic.repository.AbstractVisitRepositoryTests;
|
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p> Integration tests for the {@link JdbcClinicImpl} implementation. </p> <p> </p>
|
|
||||||
*
|
|
||||||
* @author Thomas Risberg
|
|
||||||
* @author Michael Isvy
|
|
||||||
*/
|
|
||||||
@ContextConfiguration(locations = {"classpath:spring/business-config.xml"})
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
@ActiveProfiles("jdbc")
|
|
||||||
public class JdbcVisitRepositoryImplTests extends AbstractVisitRepositoryTests {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
package org.springframework.samples.petclinic.repository.jpa;
|
|
||||||
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.samples.petclinic.repository.AbstractPetRepositoryTests;
|
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p> Integration tests for the {@link JdbcClinicImpl} implementation. </p> <p> </p>
|
|
||||||
*
|
|
||||||
* @author Thomas Risberg
|
|
||||||
* @author Michael Isvy
|
|
||||||
*/
|
|
||||||
@ContextConfiguration(locations = {"classpath:spring/business-config.xml"})
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
@ActiveProfiles("jpa")
|
|
||||||
public class JpaPetRepositoryImplTests extends AbstractPetRepositoryTests {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
package org.springframework.samples.petclinic.repository.jpa;
|
|
||||||
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.samples.petclinic.repository.AbstractVetRepositoryTests;
|
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p> Integration tests for the {@link JdbcClinicImpl} implementation. </p> <p> </p>
|
|
||||||
*
|
|
||||||
* @author Thomas Risberg
|
|
||||||
* @author Michael Isvy
|
|
||||||
*/
|
|
||||||
@ContextConfiguration(locations = {"classpath:spring/business-config.xml"})
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
@ActiveProfiles("jpa")
|
|
||||||
public class JpaVetRepositoryImplTests extends AbstractVetRepositoryTests {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
package org.springframework.samples.petclinic.repository.jpa;
|
|
||||||
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.samples.petclinic.repository.AbstractVisitRepositoryTests;
|
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p> Integration tests for the {@link JdbcClinicImpl} implementation. </p> <p> </p>
|
|
||||||
*
|
|
||||||
* @author Thomas Risberg
|
|
||||||
* @author Michael Isvy
|
|
||||||
*/
|
|
||||||
@ContextConfiguration(locations = {"classpath:spring/business-config.xml"})
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
@ActiveProfiles("jpa")
|
|
||||||
public class JpaVisitRepositoryImplTests extends AbstractVisitRepositoryTests {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
|
|
||||||
package org.springframework.samples.petclinic.repository.springdatajpa;
|
|
||||||
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.samples.petclinic.repository.AbstractOwnerRepositoryTests;
|
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p> Provides the following services: <ul> <li>Injects test dependencies, meaning that we don't need to perform
|
|
||||||
* application context lookups. See the setClinic() method. Injection uses autowiring by type.</li> <li>Executes each
|
|
||||||
* test method in its own transaction, which is automatically rolled back by default. This means that even if tests
|
|
||||||
* insert or otherwise change database state, there is no need for a teardown or cleanup script.</li> </ul> <p> </p>
|
|
||||||
*
|
|
||||||
* @author Rod Johnson
|
|
||||||
* @author Sam Brannen
|
|
||||||
* @author Michael Isvy
|
|
||||||
*/
|
|
||||||
|
|
||||||
@ContextConfiguration(locations = {"classpath:spring/business-config.xml"})
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
@ActiveProfiles("spring-data-jpa")
|
|
||||||
public class JpaOwnerRepositoryImplTests extends AbstractOwnerRepositoryTests {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
package org.springframework.samples.petclinic.repository.springdatajpa;
|
|
||||||
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.samples.petclinic.repository.AbstractPetRepositoryTests;
|
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p> Integration tests for the {@link JdbcClinicImpl} implementation. </p> <p> </p>
|
|
||||||
*
|
|
||||||
* @author Thomas Risberg
|
|
||||||
* @author Michael Isvy
|
|
||||||
*/
|
|
||||||
@ContextConfiguration(locations = {"classpath:spring/business-config.xml"})
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
@ActiveProfiles("spring-data-jpa")
|
|
||||||
public class JpaPetRepositoryImplTests extends AbstractPetRepositoryTests {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
package org.springframework.samples.petclinic.repository.springdatajpa;
|
|
||||||
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.samples.petclinic.repository.AbstractVetRepositoryTests;
|
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p> Integration tests for the {@link JdbcClinicImpl} implementation. </p> <p> </p>
|
|
||||||
*
|
|
||||||
* @author Thomas Risberg
|
|
||||||
* @author Michael Isvy
|
|
||||||
*/
|
|
||||||
@ContextConfiguration(locations = {"classpath:spring/business-config.xml"})
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
@ActiveProfiles("spring-data-jpa")
|
|
||||||
public class JpaVetRepositoryImplTests extends AbstractVetRepositoryTests {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
package org.springframework.samples.petclinic.repository.springdatajpa;
|
|
||||||
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.samples.petclinic.repository.AbstractVisitRepositoryTests;
|
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p> Integration tests for the {@link JdbcClinicImpl} implementation. </p> <p> </p>
|
|
||||||
*
|
|
||||||
* @author Thomas Risberg
|
|
||||||
* @author Michael Isvy
|
|
||||||
*/
|
|
||||||
@ContextConfiguration(locations = {"classpath:spring/business-config.xml"})
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
@ActiveProfiles("spring-data-jpa")
|
|
||||||
public class JpaVisitRepositoryImplTests extends AbstractVisitRepositoryTests {
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -13,12 +13,18 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.samples.petclinic.repository;
|
package org.springframework.samples.petclinic.service;
|
||||||
|
|
||||||
|
import org.joda.time.DateTime;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.samples.petclinic.model.Owner;
|
import org.springframework.samples.petclinic.model.Owner;
|
||||||
|
import org.springframework.samples.petclinic.model.Pet;
|
||||||
|
import org.springframework.samples.petclinic.model.PetType;
|
||||||
|
import org.springframework.samples.petclinic.model.Vet;
|
||||||
|
import org.springframework.samples.petclinic.model.Visit;
|
||||||
import org.springframework.samples.petclinic.service.ClinicService;
|
import org.springframework.samples.petclinic.service.ClinicService;
|
||||||
|
import org.springframework.samples.petclinic.util.EntityUtils;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
@ -46,7 +52,7 @@ import static org.junit.Assert.assertTrue;
|
||||||
* @author Sam Brannen
|
* @author Sam Brannen
|
||||||
* @author Michael Isvy
|
* @author Michael Isvy
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractOwnerRepositoryTests {
|
public abstract class AbstractClinicServiceTests {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
protected ClinicService clinicService;
|
protected ClinicService clinicService;
|
||||||
|
@ -97,5 +103,88 @@ public abstract class AbstractOwnerRepositoryTests {
|
||||||
assertEquals(old + "X", o1.getLastName());
|
assertEquals(old + "X", o1.getLastName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findPet() {
|
||||||
|
Collection<PetType> types = this.clinicService.findPetTypes();
|
||||||
|
Pet pet7 = this.clinicService.findPetById(7);
|
||||||
|
assertTrue(pet7.getName().startsWith("Samantha"));
|
||||||
|
assertEquals(EntityUtils.getById(types, PetType.class, 1).getId(), pet7.getType().getId());
|
||||||
|
assertEquals("Jean", pet7.getOwner().getFirstName());
|
||||||
|
Pet pet6 = this.clinicService.findPetById(6);
|
||||||
|
assertEquals("George", pet6.getName());
|
||||||
|
assertEquals(EntityUtils.getById(types, PetType.class, 4).getId(), pet6.getType().getId());
|
||||||
|
assertEquals("Peter", pet6.getOwner().getFirstName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getPetTypes() {
|
||||||
|
Collection<PetType> petTypes = this.clinicService.findPetTypes();
|
||||||
|
|
||||||
|
PetType petType1 = EntityUtils.getById(petTypes, PetType.class, 1);
|
||||||
|
assertEquals("cat", petType1.getName());
|
||||||
|
PetType petType4 = EntityUtils.getById(petTypes, PetType.class, 4);
|
||||||
|
assertEquals("snake", petType4.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Transactional
|
||||||
|
public void insertPet() {
|
||||||
|
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 DateTime());
|
||||||
|
owner6.addPet(pet);
|
||||||
|
assertEquals(found + 1, owner6.getPets().size());
|
||||||
|
// both storePet and storeOwner are necessary to cover all ORM tools
|
||||||
|
this.clinicService.savePet(pet);
|
||||||
|
this.clinicService.saveOwner(owner6);
|
||||||
|
owner6 = this.clinicService.findOwnerById(6);
|
||||||
|
assertEquals(found + 1, owner6.getPets().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Transactional
|
||||||
|
public void updatePet() throws Exception {
|
||||||
|
Pet pet7 = this.clinicService.findPetById(7);
|
||||||
|
String old = pet7.getName();
|
||||||
|
pet7.setName(old + "X");
|
||||||
|
this.clinicService.savePet(pet7);
|
||||||
|
pet7 = this.clinicService.findPetById(7);
|
||||||
|
assertEquals(old + "X", pet7.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void findVets() {
|
||||||
|
Collection<Vet> vets = this.clinicService.findVets();
|
||||||
|
|
||||||
|
Vet v1 = EntityUtils.getById(vets, Vet.class, 2);
|
||||||
|
assertEquals("Leary", v1.getLastName());
|
||||||
|
assertEquals(1, v1.getNrOfSpecialties());
|
||||||
|
assertEquals("radiology", (v1.getSpecialties().get(0)).getName());
|
||||||
|
Vet v2 = EntityUtils.getById(vets, Vet.class, 3);
|
||||||
|
assertEquals("Douglas", v2.getLastName());
|
||||||
|
assertEquals(2, v2.getNrOfSpecialties());
|
||||||
|
assertEquals("dentistry", (v2.getSpecialties().get(0)).getName());
|
||||||
|
assertEquals("surgery", (v2.getSpecialties().get(1)).getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Transactional
|
||||||
|
public void insertVisit() {
|
||||||
|
Pet pet7 = this.clinicService.findPetById(7);
|
||||||
|
int found = pet7.getVisits().size();
|
||||||
|
Visit visit = new Visit();
|
||||||
|
pet7.addVisit(visit);
|
||||||
|
visit.setDescription("test");
|
||||||
|
// both storeVisit and storePet are necessary to cover all ORM tools
|
||||||
|
this.clinicService.saveVisit(visit);
|
||||||
|
this.clinicService.savePet(pet7);
|
||||||
|
pet7 = this.clinicService.findPetById(7);
|
||||||
|
assertEquals(found + 1, pet7.getVisits().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -13,10 +13,9 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.samples.petclinic.repository.jdbc;
|
package org.springframework.samples.petclinic.service;
|
||||||
|
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.samples.petclinic.repository.AbstractOwnerRepositoryTests;
|
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
@ -30,7 +29,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
@ContextConfiguration(locations = {"classpath:spring/business-config.xml"})
|
@ContextConfiguration(locations = {"classpath:spring/business-config.xml"})
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ActiveProfiles("jdbc")
|
@ActiveProfiles("jdbc")
|
||||||
public class JdbcOwnerRepositoryImplTests extends AbstractOwnerRepositoryTests {
|
public class ClinicServiceJdbcTests extends AbstractClinicServiceTests {
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,8 +1,7 @@
|
||||||
|
|
||||||
package org.springframework.samples.petclinic.repository.jpa;
|
package org.springframework.samples.petclinic.service;
|
||||||
|
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.samples.petclinic.repository.AbstractOwnerRepositoryTests;
|
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
@ -21,6 +20,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
@ContextConfiguration(locations = {"classpath:spring/business-config.xml"})
|
@ContextConfiguration(locations = {"classpath:spring/business-config.xml"})
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ActiveProfiles("jpa")
|
@ActiveProfiles("jpa")
|
||||||
public class JpaOwnerRepositoryImplTests extends AbstractOwnerRepositoryTests {
|
public class ClinicServiceJpaTests extends AbstractClinicServiceTests {
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,8 +1,7 @@
|
||||||
|
|
||||||
package org.springframework.samples.petclinic.repository.springdatajpa;
|
package org.springframework.samples.petclinic.service;
|
||||||
|
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.samples.petclinic.repository.AbstractOwnerRepositoryTests;
|
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
@ -14,6 +13,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
@ContextConfiguration(locations = {"classpath:spring/business-config.xml"})
|
@ContextConfiguration(locations = {"classpath:spring/business-config.xml"})
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ActiveProfiles("spring-data-jpa")
|
@ActiveProfiles("spring-data-jpa")
|
||||||
public class SpringDataOwnerRepositoryTests extends AbstractOwnerRepositoryTests {
|
public class ClinicServiceSpringDataJpaTests extends AbstractClinicServiceTests {
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue