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 d1c715db0..000000000 --- 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; - -/** - *

Base class for {@link OwnerRepository} integration tests.

- *

- * 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 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 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 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 6e25f9b70..000000000 --- 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; - -/** - *

Base class for {@link OwnerRepository} integration tests.

- *

- * 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 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 0d122a677..000000000 --- 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; - -/** - *

Base class for {@link OwnerRepository} integration tests.

- *

- * 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 403d5f219..000000000 --- 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; - -/** - *

Integration tests for the {@link JdbcClinicImpl} implementation.

- * - * @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 dd94080eb..000000000 --- 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; - -/** - *

Integration tests for the {@link JdbcClinicImpl} implementation.

- * - * @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 43c503641..000000000 --- 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; - -/** - *

Integration tests for the {@link JdbcClinicImpl} implementation.

- * - * @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 96b8df349..000000000 --- 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; - -/** - *

Integration tests for the {@link JdbcClinicImpl} implementation.

- * - * @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 3289153ef..000000000 --- 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; - -/** - *

Integration tests for the {@link JdbcClinicImpl} implementation.

- * - * @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 dbaffde4b..000000000 --- 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; - -/** - *

Integration tests for the {@link JdbcClinicImpl} implementation.

- * - * @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 1cb385a73..000000000 --- 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; - -/** - *

Provides the following services:

- * - * @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 f3fefdaa6..000000000 --- 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; - -/** - *

Integration tests for the {@link JdbcClinicImpl} implementation.

- * - * @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 f3583b1b5..000000000 --- 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; - -/** - *

Integration tests for the {@link JdbcClinicImpl} implementation.

- * - * @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 a3b37ed00..000000000 --- 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; - -/** - *

Integration tests for the {@link JdbcClinicImpl} implementation.

- * - * @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 57a57844f..e0571f779 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 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 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 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 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 f821dbf2a..787733c1e 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 77462cdfb..2a3d54485 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 28fc5f1f8..b624abca7 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