diff --git a/src/test/java/org/springframework/samples/petclinic/repository/AbstractPetRepositoryTests.java b/src/test/java/org/springframework/samples/petclinic/repository/AbstractPetRepositoryTests.java deleted file mode 100644 index d1c715db020c4b29984efd5463560bf8c4edf91a..0000000000000000000000000000000000000000 --- a/src/test/java/org/springframework/samples/petclinic/repository/AbstractPetRepositoryTests.java +++ /dev/null @@ -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()); - } - -} diff --git a/src/test/java/org/springframework/samples/petclinic/repository/AbstractVetRepositoryTests.java b/src/test/java/org/springframework/samples/petclinic/repository/AbstractVetRepositoryTests.java deleted file mode 100644 index 6e25f9b702c5a7e29ecf42a72cdff5b7778343c0..0000000000000000000000000000000000000000 --- a/src/test/java/org/springframework/samples/petclinic/repository/AbstractVetRepositoryTests.java +++ /dev/null @@ -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()); - } - -} diff --git a/src/test/java/org/springframework/samples/petclinic/repository/AbstractVisitRepositoryTests.java b/src/test/java/org/springframework/samples/petclinic/repository/AbstractVisitRepositoryTests.java deleted file mode 100644 index 0d122a6777cb5b9737060d7c9ff07c1e96aff518..0000000000000000000000000000000000000000 --- a/src/test/java/org/springframework/samples/petclinic/repository/AbstractVisitRepositoryTests.java +++ /dev/null @@ -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()); - } - -} diff --git a/src/test/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetRepositoryImplTests.java b/src/test/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetRepositoryImplTests.java deleted file mode 100644 index 403d5f219cdd6ab067a584fc5dee4d4adfaf7183..0000000000000000000000000000000000000000 --- a/src/test/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetRepositoryImplTests.java +++ /dev/null @@ -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 { - - -} diff --git a/src/test/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVetRepositoryImplTests.java b/src/test/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVetRepositoryImplTests.java deleted file mode 100644 index dd94080eb601db252c400e54488ad120d716fedd..0000000000000000000000000000000000000000 --- a/src/test/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVetRepositoryImplTests.java +++ /dev/null @@ -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 { - - -} diff --git a/src/test/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRepositoryImplTests.java b/src/test/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRepositoryImplTests.java deleted file mode 100644 index 43c5036416c7df6c58ab0759f906ed2da3a0954b..0000000000000000000000000000000000000000 --- a/src/test/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRepositoryImplTests.java +++ /dev/null @@ -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 { - - -} diff --git a/src/test/java/org/springframework/samples/petclinic/repository/jpa/JpaPetRepositoryImplTests.java b/src/test/java/org/springframework/samples/petclinic/repository/jpa/JpaPetRepositoryImplTests.java deleted file mode 100644 index 96b8df3496a374f89f620684f7e875e7ccaaa071..0000000000000000000000000000000000000000 --- a/src/test/java/org/springframework/samples/petclinic/repository/jpa/JpaPetRepositoryImplTests.java +++ /dev/null @@ -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 { - - -} diff --git a/src/test/java/org/springframework/samples/petclinic/repository/jpa/JpaVetRepositoryImplTests.java b/src/test/java/org/springframework/samples/petclinic/repository/jpa/JpaVetRepositoryImplTests.java deleted file mode 100644 index 3289153ef680d4f4fdf81dab86bfa92bd5551d97..0000000000000000000000000000000000000000 --- a/src/test/java/org/springframework/samples/petclinic/repository/jpa/JpaVetRepositoryImplTests.java +++ /dev/null @@ -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 { - - -} diff --git a/src/test/java/org/springframework/samples/petclinic/repository/jpa/JpaVisitRepositoryImplTests.java b/src/test/java/org/springframework/samples/petclinic/repository/jpa/JpaVisitRepositoryImplTests.java deleted file mode 100644 index dbaffde4b1766dcca7afd98e34a7152aea5f2ee5..0000000000000000000000000000000000000000 --- a/src/test/java/org/springframework/samples/petclinic/repository/jpa/JpaVisitRepositoryImplTests.java +++ /dev/null @@ -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 { - - -} diff --git a/src/test/java/org/springframework/samples/petclinic/repository/springdatajpa/JpaOwnerRepositoryImplTests.java b/src/test/java/org/springframework/samples/petclinic/repository/springdatajpa/JpaOwnerRepositoryImplTests.java deleted file mode 100644 index 1cb385a738a8d7b767f4a790210f704ef8bb4ce7..0000000000000000000000000000000000000000 --- a/src/test/java/org/springframework/samples/petclinic/repository/springdatajpa/JpaOwnerRepositoryImplTests.java +++ /dev/null @@ -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 { - -} \ No newline at end of file diff --git a/src/test/java/org/springframework/samples/petclinic/repository/springdatajpa/JpaPetRepositoryImplTests.java b/src/test/java/org/springframework/samples/petclinic/repository/springdatajpa/JpaPetRepositoryImplTests.java deleted file mode 100644 index f3fefdaa6f8db54dbb08b07e9258b3ea0129e8c3..0000000000000000000000000000000000000000 --- a/src/test/java/org/springframework/samples/petclinic/repository/springdatajpa/JpaPetRepositoryImplTests.java +++ /dev/null @@ -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 { - - -} diff --git a/src/test/java/org/springframework/samples/petclinic/repository/springdatajpa/JpaVetRepositoryImplTests.java b/src/test/java/org/springframework/samples/petclinic/repository/springdatajpa/JpaVetRepositoryImplTests.java deleted file mode 100644 index f3583b1b5e093aeb46f0c39d77941745a424dca1..0000000000000000000000000000000000000000 --- a/src/test/java/org/springframework/samples/petclinic/repository/springdatajpa/JpaVetRepositoryImplTests.java +++ /dev/null @@ -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 { - - -} diff --git a/src/test/java/org/springframework/samples/petclinic/repository/springdatajpa/JpaVisitRepositoryImplTests.java b/src/test/java/org/springframework/samples/petclinic/repository/springdatajpa/JpaVisitRepositoryImplTests.java deleted file mode 100644 index a3b37ed001b2ebbf0f537bedc8f09a845936dc4f..0000000000000000000000000000000000000000 --- a/src/test/java/org/springframework/samples/petclinic/repository/springdatajpa/JpaVisitRepositoryImplTests.java +++ /dev/null @@ -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 { - - -} diff --git a/src/test/java/org/springframework/samples/petclinic/repository/AbstractOwnerRepositoryTests.java b/src/test/java/org/springframework/samples/petclinic/service/AbstractClinicServiceTests.java similarity index 53% rename from src/test/java/org/springframework/samples/petclinic/repository/AbstractOwnerRepositoryTests.java rename to src/test/java/org/springframework/samples/petclinic/service/AbstractClinicServiceTests.java index 57a57844f7984487cdf06e07f9ff237b01e48c83..e0571f7791d847dd5251ed239ca898ae049458b1 100644 --- a/src/test/java/org/springframework/samples/petclinic/repository/AbstractOwnerRepositoryTests.java +++ b/src/test/java/org/springframework/samples/petclinic/service/AbstractClinicServiceTests.java @@ -13,12 +13,18 @@ * See the License for the specific language governing permissions and * 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.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.model.Vet; +import org.springframework.samples.petclinic.model.Visit; import org.springframework.samples.petclinic.service.ClinicService; +import org.springframework.samples.petclinic.util.EntityUtils; import org.springframework.test.context.ContextConfiguration; import org.springframework.transaction.annotation.Transactional; @@ -46,7 +52,7 @@ import static org.junit.Assert.assertTrue; * @author Sam Brannen * @author Michael Isvy */ -public abstract class AbstractOwnerRepositoryTests { +public abstract class AbstractClinicServiceTests { @Autowired protected ClinicService clinicService; @@ -97,5 +103,88 @@ public abstract class AbstractOwnerRepositoryTests { 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()); + } + } diff --git a/src/test/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImplTests.java b/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceJdbcTests.java similarity index 83% rename from src/test/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImplTests.java rename to src/test/java/org/springframework/samples/petclinic/service/ClinicServiceJdbcTests.java index f821dbf2a406ccf771948b95e6a53ec2fb7f4d03..787733c1e11c1e81db8e1c62c64bc8f950d4542d 100644 --- a/src/test/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImplTests.java +++ b/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceJdbcTests.java @@ -13,10 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.samples.petclinic.repository.jdbc; +package org.springframework.samples.petclinic.service; 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; @@ -30,7 +29,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @ContextConfiguration(locations = {"classpath:spring/business-config.xml"}) @RunWith(SpringJUnit4ClassRunner.class) @ActiveProfiles("jdbc") -public class JdbcOwnerRepositoryImplTests extends AbstractOwnerRepositoryTests { +public class ClinicServiceJdbcTests extends AbstractClinicServiceTests { } diff --git a/src/test/java/org/springframework/samples/petclinic/repository/jpa/JpaOwnerRepositoryImplTests.java b/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceJpaTests.java similarity index 80% rename from src/test/java/org/springframework/samples/petclinic/repository/jpa/JpaOwnerRepositoryImplTests.java rename to src/test/java/org/springframework/samples/petclinic/service/ClinicServiceJpaTests.java index 77462cdfb6e04a3b15e570d71f26eff10de93653..2a3d544855bf09468e990d8457f8c8249c5c7c7f 100644 --- a/src/test/java/org/springframework/samples/petclinic/repository/jpa/JpaOwnerRepositoryImplTests.java +++ b/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceJpaTests.java @@ -1,8 +1,7 @@ -package org.springframework.samples.petclinic.repository.jpa; +package org.springframework.samples.petclinic.service; 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; @@ -21,6 +20,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @ContextConfiguration(locations = {"classpath:spring/business-config.xml"}) @RunWith(SpringJUnit4ClassRunner.class) @ActiveProfiles("jpa") -public class JpaOwnerRepositoryImplTests extends AbstractOwnerRepositoryTests { +public class ClinicServiceJpaTests extends AbstractClinicServiceTests { } \ No newline at end of file diff --git a/src/test/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataOwnerRepositoryTests.java b/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceSpringDataJpaTests.java similarity index 63% rename from src/test/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataOwnerRepositoryTests.java rename to src/test/java/org/springframework/samples/petclinic/service/ClinicServiceSpringDataJpaTests.java index 28fc5f1f8920df1a58490f9b558339663c2500e6..b624abca767012dba6cb656da1d01a27c50da324 100644 --- a/src/test/java/org/springframework/samples/petclinic/repository/springdatajpa/SpringDataOwnerRepositoryTests.java +++ b/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceSpringDataJpaTests.java @@ -1,8 +1,7 @@ -package org.springframework.samples.petclinic.repository.springdatajpa; +package org.springframework.samples.petclinic.service; 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; @@ -14,6 +13,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @ContextConfiguration(locations = {"classpath:spring/business-config.xml"}) @RunWith(SpringJUnit4ClassRunner.class) @ActiveProfiles("spring-data-jpa") -public class SpringDataOwnerRepositoryTests extends AbstractOwnerRepositoryTests { +public class ClinicServiceSpringDataJpaTests extends AbstractClinicServiceTests { } \ No newline at end of file