file formatting and missing @Override on Java classes

This commit is contained in:
Gordon Dickens 2013-02-19 10:56:21 -05:00
parent 46260018d1
commit 14f882221f
84 changed files with 2267 additions and 2373 deletions

View file

@ -15,14 +15,12 @@
*/
package org.springframework.samples.petclinic.model;
import org.junit.Test;
import org.springframework.transaction.annotation.Transactional;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import org.junit.Test;
import org.springframework.samples.petclinic.model.Owner;
import org.springframework.samples.petclinic.model.Pet;
import org.springframework.transaction.annotation.Transactional;
/**
* JUnit test for the {@link Owner} class.
*
@ -30,16 +28,17 @@ import org.springframework.transaction.annotation.Transactional;
*/
public class OwnerTests {
@Test @Transactional
public void testHasPet() {
Owner owner = new Owner();
Pet fido = new Pet();
fido.setName("Fido");
assertNull(owner.getPet("Fido"));
assertNull(owner.getPet("fido"));
owner.addPet(fido);
assertEquals(fido, owner.getPet("Fido"));
assertEquals(fido, owner.getPet("fido"));
}
@Test
@Transactional
public void testHasPet() {
Owner owner = new Owner();
Pet fido = new Pet();
fido.setName("Fido");
assertNull(owner.getPet("Fido"));
assertNull(owner.getPet("fido"));
owner.addPet(fido);
assertEquals(fido, owner.getPet("Fido"));
assertEquals(fido, owner.getPet("fido"));
}
}

View file

@ -15,44 +15,29 @@
*/
package org.springframework.samples.petclinic.repository;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Collection;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.samples.petclinic.model.Owner;
import org.springframework.samples.petclinic.repository.OwnerRepository;
import org.springframework.test.context.ContextConfiguration;
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>
* Subclasses should specify Spring context configuration using {@link ContextConfiguration @ContextConfiguration} annotation
* </p>
* <p>
* AbstractOwnerRepositoryTests and its subclasses benefit from the following services
* provided by the Spring TestContext Framework:
* </p>
* <ul>
* <li><strong>Spring IoC container caching</strong> which spares us
* unnecessary set up time between test execution.</li>
* <li><strong>Dependency Injection</strong> of test fixture instances,
* meaning that we don't need to perform application context lookups. See the
* use of {@link Autowired @Autowired} on the <code>{@link AbstractOwnerRepositoryTests#ownerRepository ownerRepository}</code> instance
* variable, which uses autowiring <em>by type</em>.
* <li><strong>Transaction management</strong>, meaning each test method is
* executed in its own transaction, which is automatically rolled back by
* default. Thus, even if tests insert or otherwise change database state, there
* is no need for a teardown or cleanup script.
* <li> An {@link org.springframework.context.ApplicationContext ApplicationContext} is
* also inherited and can be used for explicit bean lookup if necessary.
* </li>
* </ul>
* <p> Base class for {@link OwnerRepository} integration tests. </p> <p> Subclasses should specify Spring context
* configuration using {@link ContextConfiguration @ContextConfiguration} annotation </p> <p>
* AbstractOwnerRepositoryTests and its subclasses benefit from the following services provided by the Spring
* TestContext Framework: </p> <ul> <li><strong>Spring IoC container caching</strong> which spares us unnecessary set up
* time between test execution.</li> <li><strong>Dependency Injection</strong> of test fixture instances, meaning that
* we don't need to perform application context lookups. See the use of {@link Autowired @Autowired} on the <code>{@link
* AbstractOwnerRepositoryTests#ownerRepository ownerRepository}</code> instance variable, which uses autowiring <em>by
* type</em>. <li><strong>Transaction management</strong>, meaning each test method is executed in its own transaction,
* which is automatically rolled back by default. Thus, even if tests insert or otherwise change database state, there
* is no need for a teardown or cleanup script. <li> An {@link org.springframework.context.ApplicationContext
* ApplicationContext} is also inherited and can be used for explicit bean lookup if necessary. </li> </ul>
*
* @author Ken Krebs
* @author Rod Johnson
@ -62,52 +47,55 @@ import org.springframework.transaction.annotation.Transactional;
*/
public abstract class AbstractOwnerRepositoryTests {
@Autowired
protected OwnerRepository ownerRepository;
@Autowired
protected OwnerRepository ownerRepository;
@Test @Transactional
public void findOwners() {
Collection<Owner> owners = this.ownerRepository.findByLastName("Davis");
assertEquals(2, owners.size());
owners = this.ownerRepository.findByLastName("Daviss");
assertEquals(0, owners.size());
}
@Test
@Transactional
public void findOwners() {
Collection<Owner> owners = this.ownerRepository.findByLastName("Davis");
assertEquals(2, owners.size());
owners = this.ownerRepository.findByLastName("Daviss");
assertEquals(0, owners.size());
}
@Test @Transactional
public void findSingleOwner() {
Owner owner1 = this.ownerRepository.findById(1);
assertTrue(owner1.getLastName().startsWith("Franklin"));
Owner owner10 = this.ownerRepository.findById(10);
assertEquals("Carlos", owner10.getFirstName());
@Test
@Transactional
public void findSingleOwner() {
Owner owner1 = this.ownerRepository.findById(1);
assertTrue(owner1.getLastName().startsWith("Franklin"));
Owner owner10 = this.ownerRepository.findById(10);
assertEquals("Carlos", owner10.getFirstName());
assertEquals(owner1.getPets().size(), 1);
}
assertEquals(owner1.getPets().size(), 1);
}
@Test @Transactional
public void insertOwner() {
Collection<Owner> owners = this.ownerRepository.findByLastName("Schultz");
int found = owners.size();
Owner owner = new Owner();
owner.setFirstName("Sam");
owner.setLastName("Schultz");
owner.setAddress("4, Evans Street");
owner.setCity("Wollongong");
owner.setTelephone("4444444444");
this.ownerRepository.save(owner);
owners = this.ownerRepository.findByLastName("Schultz");
assertEquals("Verifying number of owners after inserting a new one.", found + 1, owners.size());
}
@Test @Transactional
public void updateOwner() throws Exception {
Owner o1 = this.ownerRepository.findById(1);
String old = o1.getLastName();
o1.setLastName(old + "X");
this.ownerRepository.save(o1);
o1 = this.ownerRepository.findById(1);
assertEquals(old + "X", o1.getLastName());
}
@Test
@Transactional
public void insertOwner() {
Collection<Owner> owners = this.ownerRepository.findByLastName("Schultz");
int found = owners.size();
Owner owner = new Owner();
owner.setFirstName("Sam");
owner.setLastName("Schultz");
owner.setAddress("4, Evans Street");
owner.setCity("Wollongong");
owner.setTelephone("4444444444");
this.ownerRepository.save(owner);
owners = this.ownerRepository.findByLastName("Schultz");
assertEquals("Verifying number of owners after inserting a new one.", found + 1, owners.size());
}
@Test
@Transactional
public void updateOwner() throws Exception {
Owner o1 = this.ownerRepository.findById(1);
String old = o1.getLastName();
o1.setLastName(old + "X");
this.ownerRepository.save(o1);
o1 = this.ownerRepository.findById(1);
assertEquals(old + "X", o1.getLastName());
}
}

View file

@ -15,27 +15,23 @@
*/
package org.springframework.samples.petclinic.repository;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Collection;
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.repository.OwnerRepository;
import org.springframework.samples.petclinic.repository.PetRepository;
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>
* <p> Base class for {@link OwnerRepository} integration tests. </p>
* <p/>
* see javadoc inside {@link AbstractOwnerRepositoryTests} for more details
*
* @author Ken Krebs
@ -46,62 +42,66 @@ import org.springframework.transaction.annotation.Transactional;
*/
public abstract class AbstractPetRepositoryTests {
@Autowired
protected PetRepository petRepository;
@Autowired
protected OwnerRepository ownerRepository;
@Autowired
protected PetRepository petRepository;
@Autowired
protected OwnerRepository ownerRepository;
@Test @Transactional
public void getPetTypes() {
Collection<PetType> petTypes = this.petRepository.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 getPetTypes() {
Collection<PetType> petTypes = this.petRepository.findPetTypes();
@Test @Transactional
public void findPet() {
Collection<PetType> types = this.petRepository.findPetTypes();
Pet pet7 = this.petRepository.findById(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.petRepository.findById(6);
assertEquals("George", pet6.getName());
assertEquals(EntityUtils.getById(types, PetType.class, 4).getId(), pet6.getType().getId());
assertEquals("Peter", pet6.getOwner().getFirstName());
}
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.ownerRepository.findById(6);
int found = owner6.getPets().size();
Pet pet = new Pet();
pet.setName("bowser");
Collection<PetType> types = this.petRepository.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.petRepository.save(pet);
this.ownerRepository.save(owner6);
owner6 = this.ownerRepository.findById(6);
assertEquals(found + 1, owner6.getPets().size());
}
@Test
@Transactional
public void findPet() {
Collection<PetType> types = this.petRepository.findPetTypes();
Pet pet7 = this.petRepository.findById(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.petRepository.findById(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 updatePet() throws Exception {
Pet pet7 = this.petRepository.findById(7);
String old = pet7.getName();
pet7.setName(old + "X");
this.petRepository.save(pet7);
pet7 = this.petRepository.findById(7);
assertEquals(old + "X", pet7.getName());
}
@Test
@Transactional
public void insertPet() {
Owner owner6 = this.ownerRepository.findById(6);
int found = owner6.getPets().size();
Pet pet = new Pet();
pet.setName("bowser");
Collection<PetType> types = this.petRepository.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.petRepository.save(pet);
this.ownerRepository.save(owner6);
owner6 = this.ownerRepository.findById(6);
assertEquals(found + 1, owner6.getPets().size());
}
@Test
@Transactional
public void updatePet() throws Exception {
Pet pet7 = this.petRepository.findById(7);
String old = pet7.getName();
pet7.setName(old + "X");
this.petRepository.save(pet7);
pet7 = this.petRepository.findById(7);
assertEquals(old + "X", pet7.getName());
}
}

View file

@ -15,23 +15,19 @@
*/
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.repository.OwnerRepository;
import org.springframework.samples.petclinic.repository.VetRepository;
import org.springframework.samples.petclinic.util.EntityUtils;
import org.springframework.transaction.annotation.Transactional;
import java.util.Collection;
import static org.junit.Assert.assertEquals;
/**
* <p>
* Base class for {@link OwnerRepository} integration tests.
* </p>
* <p>
* <p> Base class for {@link OwnerRepository} integration tests. </p>
* <p/>
* see javadoc inside {@link AbstractVetRepositoryTests} for more details
*
* @author Ken Krebs
@ -42,23 +38,24 @@ import org.springframework.transaction.annotation.Transactional;
*/
public abstract class AbstractVetRepositoryTests {
@Autowired
protected VetRepository vetRepository;
@Autowired
protected VetRepository vetRepository;
@Test @Transactional
public void findVets() {
Collection<Vet> vets = this.vetRepository.findAll();
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 findVets() {
Collection<Vet> vets = this.vetRepository.findAll();
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());
}
}

View file

@ -15,22 +15,17 @@
*/
package org.springframework.samples.petclinic.repository;
import static org.junit.Assert.assertEquals;
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.repository.OwnerRepository;
import org.springframework.samples.petclinic.repository.PetRepository;
import org.springframework.samples.petclinic.repository.VisitRepository;
import org.springframework.transaction.annotation.Transactional;
import static org.junit.Assert.assertEquals;
/**
* <p>
* Base class for {@link OwnerRepository} integration tests.
* </p>
* <p>
* <p> Base class for {@link OwnerRepository} integration tests. </p>
* <p/>
* see javadoc inside {@link AbstractVetRepositoryTests} for more details
*
* @author Ken Krebs
@ -41,25 +36,26 @@ import org.springframework.transaction.annotation.Transactional;
*/
public abstract class AbstractVisitRepositoryTests {
@Autowired
protected VisitRepository visitRepository;
@Autowired
protected PetRepository petRepository;
@Autowired
protected VisitRepository visitRepository;
@Autowired
protected PetRepository petRepository;
@Test @Transactional
public void insertVisit() {
Pet pet7 = this.petRepository.findById(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.visitRepository.save(visit);
this.petRepository.save(pet7);
pet7 = this.petRepository.findById(7);
assertEquals(found + 1, pet7.getVisits().size());
}
@Test
@Transactional
public void insertVisit() {
Pet pet7 = this.petRepository.findById(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.visitRepository.save(visit);
this.petRepository.save(pet7);
pet7 = this.petRepository.findById(7);
assertEquals(found + 1, pet7.getVisits().size());
}
}

View file

@ -22,20 +22,15 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* <p>
* Integration tests for the {@link JdbcClinicImpl} implementation.
* </p>
* <p>
* </p>
* <p> Integration tests for the {@link JdbcClinicImpl} implementation. </p> <p> </p>
*
* @author Thomas Risberg
* @author Michael Isvy
* @author Michael Isvy
*/
@ContextConfiguration(locations={"classpath:spring/dao-config.xml"})
@ContextConfiguration(locations = {"classpath:spring/dao-config.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
@ActiveProfiles("jdbc")
public class JdbcOwnerRepositoryImplTests extends AbstractOwnerRepositoryTests {
}

View file

@ -7,20 +7,15 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* <p>
* Integration tests for the {@link JdbcClinicImpl} implementation.
* </p>
* <p>
* </p>
* <p> Integration tests for the {@link JdbcClinicImpl} implementation. </p> <p> </p>
*
* @author Thomas Risberg
* @author Michael Isvy
* @author Michael Isvy
*/
@ContextConfiguration(locations={"classpath:spring/dao-config.xml"})
@ContextConfiguration(locations = {"classpath:spring/dao-config.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
@ActiveProfiles("jdbc")
public class JdbcPetRepositoryImplTests extends AbstractPetRepositoryTests {
}

View file

@ -7,20 +7,15 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* <p>
* Integration tests for the {@link JdbcClinicImpl} implementation.
* </p>
* <p>
* </p>
* <p> Integration tests for the {@link JdbcClinicImpl} implementation. </p> <p> </p>
*
* @author Thomas Risberg
* @author Michael Isvy
* @author Michael Isvy
*/
@ContextConfiguration(locations={"classpath:spring/dao-config.xml"})
@ContextConfiguration(locations = {"classpath:spring/dao-config.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
@ActiveProfiles("jdbc")
public class JdbcVetRepositoryImplTests extends AbstractVetRepositoryTests {
}

View file

@ -7,20 +7,15 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* <p>
* Integration tests for the {@link JdbcClinicImpl} implementation.
* </p>
* <p>
* </p>
* <p> Integration tests for the {@link JdbcClinicImpl} implementation. </p> <p> </p>
*
* @author Thomas Risberg
* @author Michael Isvy
* @author Michael Isvy
*/
@ContextConfiguration(locations={"classpath:spring/dao-config.xml"})
@ContextConfiguration(locations = {"classpath:spring/dao-config.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
@ActiveProfiles("jdbc")
public class JdbcVisitRepositoryImplTests extends AbstractVisitRepositoryTests {
}

View file

@ -8,27 +8,19 @@ 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>
* <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/dao-config.xml"})
@ContextConfiguration(locations = {"classpath:spring/dao-config.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
@ActiveProfiles("jpa")
public class JpaOwnerRepositoryImplTests extends AbstractOwnerRepositoryTests {
}

View file

@ -7,20 +7,15 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* <p>
* Integration tests for the {@link JdbcClinicImpl} implementation.
* </p>
* <p>
* </p>
* <p> Integration tests for the {@link JdbcClinicImpl} implementation. </p> <p> </p>
*
* @author Thomas Risberg
* @author Michael Isvy
* @author Michael Isvy
*/
@ContextConfiguration(locations={"classpath:spring/dao-config.xml"})
@ContextConfiguration(locations = {"classpath:spring/dao-config.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
@ActiveProfiles("jpa")
public class JpaPetRepositoryImplTests extends AbstractPetRepositoryTests {
}

View file

@ -7,20 +7,15 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* <p>
* Integration tests for the {@link JdbcClinicImpl} implementation.
* </p>
* <p>
* </p>
* <p> Integration tests for the {@link JdbcClinicImpl} implementation. </p> <p> </p>
*
* @author Thomas Risberg
* @author Michael Isvy
* @author Michael Isvy
*/
@ContextConfiguration(locations={"classpath:spring/dao-config.xml"})
@ContextConfiguration(locations = {"classpath:spring/dao-config.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
@ActiveProfiles("jpa")
public class JpaVetRepositoryImplTests extends AbstractVetRepositoryTests {
}

View file

@ -7,20 +7,15 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* <p>
* Integration tests for the {@link JdbcClinicImpl} implementation.
* </p>
* <p>
* </p>
* <p> Integration tests for the {@link JdbcClinicImpl} implementation. </p> <p> </p>
*
* @author Thomas Risberg
* @author Michael Isvy
* @author Michael Isvy
*/
@ContextConfiguration(locations={"classpath:spring/dao-config.xml"})
@ContextConfiguration(locations = {"classpath:spring/dao-config.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
@ActiveProfiles("jpa")
public class JpaVisitRepositoryImplTests extends AbstractVisitRepositoryTests {
}

View file

@ -8,27 +8,19 @@ 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>
* <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/dao-config.xml"})
@ContextConfiguration(locations = {"classpath:spring/dao-config.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
@ActiveProfiles("spring-data-jpa")
public class JpaOwnerRepositoryImplTests extends AbstractOwnerRepositoryTests {
}

View file

@ -7,20 +7,15 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* <p>
* Integration tests for the {@link JdbcClinicImpl} implementation.
* </p>
* <p>
* </p>
* <p> Integration tests for the {@link JdbcClinicImpl} implementation. </p> <p> </p>
*
* @author Thomas Risberg
* @author Michael Isvy
* @author Michael Isvy
*/
@ContextConfiguration(locations={"classpath:spring/dao-config.xml"})
@ContextConfiguration(locations = {"classpath:spring/dao-config.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
@ActiveProfiles("spring-data-jpa")
public class JpaPetRepositoryImplTests extends AbstractPetRepositoryTests {
}

View file

@ -7,20 +7,15 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* <p>
* Integration tests for the {@link JdbcClinicImpl} implementation.
* </p>
* <p>
* </p>
* <p> Integration tests for the {@link JdbcClinicImpl} implementation. </p> <p> </p>
*
* @author Thomas Risberg
* @author Michael Isvy
* @author Michael Isvy
*/
@ContextConfiguration(locations={"classpath:spring/dao-config.xml"})
@ContextConfiguration(locations = {"classpath:spring/dao-config.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
@ActiveProfiles("spring-data-jpa")
public class JpaVetRepositoryImplTests extends AbstractVetRepositoryTests {
}

View file

@ -7,20 +7,15 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* <p>
* Integration tests for the {@link JdbcClinicImpl} implementation.
* </p>
* <p>
* </p>
* <p> Integration tests for the {@link JdbcClinicImpl} implementation. </p> <p> </p>
*
* @author Thomas Risberg
* @author Michael Isvy
* @author Michael Isvy
*/
@ContextConfiguration(locations={"classpath:spring/dao-config.xml"})
@ContextConfiguration(locations = {"classpath:spring/dao-config.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
@ActiveProfiles("spring-data-jpa")
public class JpaVisitRepositoryImplTests extends AbstractVisitRepositoryTests {
}

View file

@ -11,9 +11,9 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* @author Michael Isvy
*/
@ContextConfiguration(locations={"classpath:spring/dao-config.xml"})
@ContextConfiguration(locations = {"classpath:spring/dao-config.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
@ActiveProfiles("spring-data-jpa")
public class SpringDataOwnerRepositoryTests extends AbstractOwnerRepositoryTests {
}

View file

@ -16,14 +16,8 @@
package org.springframework.samples.petclinic.web;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.sun.syndication.feed.atom.Entry;
import com.sun.syndication.feed.atom.Feed;
import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Test;
@ -31,63 +25,68 @@ import org.springframework.samples.petclinic.model.Pet;
import org.springframework.samples.petclinic.model.PetType;
import org.springframework.samples.petclinic.model.Visit;
import com.sun.syndication.feed.atom.Entry;
import com.sun.syndication.feed.atom.Feed;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
/**
* @author Arjen Poutsma
* @author Arjen Poutsma
* @author Michael Isvy
*/
public class VisitsAtomViewTest {
private VetsAtomView visitView;
private VetsAtomView visitView;
private Map<String, Object> model;
private Map<String, Object> model;
private Feed feed;
private Feed feed;
@Before
public void setUp() {
visitView = new VetsAtomView();
PetType dog = new PetType();
dog.setName("dog");
Pet bello = new Pet();
bello.setName("Bello");
bello.setType(dog);
Visit belloVisit = new Visit();
belloVisit.setPet(bello);
belloVisit.setDate(new DateTime(2009, 1, 1, 1, 1));
belloVisit.setDescription("Bello visit");
Pet wodan = new Pet();
wodan.setName("Wodan");
wodan.setType(dog);
Visit wodanVisit = new Visit();
wodanVisit.setPet(wodan);
wodanVisit.setDate(new DateTime(2009, 1, 2, 1, 1));
wodanVisit.setDescription("Wodan visit");
List<Visit> visits = new ArrayList<Visit>();
visits.add(belloVisit);
visits.add(wodanVisit);
@Before
public void setUp() {
visitView = new VetsAtomView();
PetType dog = new PetType();
dog.setName("dog");
Pet bello = new Pet();
bello.setName("Bello");
bello.setType(dog);
Visit belloVisit = new Visit();
belloVisit.setPet(bello);
belloVisit.setDate(new DateTime(2009, 1, 1, 1, 1));
belloVisit.setDescription("Bello visit");
Pet wodan = new Pet();
wodan.setName("Wodan");
wodan.setType(dog);
Visit wodanVisit = new Visit();
wodanVisit.setPet(wodan);
wodanVisit.setDate(new DateTime(2009, 1, 2, 1, 1));
wodanVisit.setDescription("Wodan visit");
List<Visit> visits = new ArrayList<Visit>();
visits.add(belloVisit);
visits.add(wodanVisit);
model = new HashMap<String, Object>();
model.put("visits", visits);
feed = new Feed();
model = new HashMap<String, Object>();
model.put("visits", visits);
feed = new Feed();
}
}
@Test
public void buildFeedMetadata() {
visitView.buildFeedMetadata(model, feed, null);
@Test
public void buildFeedMetadata() {
visitView.buildFeedMetadata(model, feed, null);
assertNotNull("No id set", feed.getId());
assertNotNull("No title set", feed.getTitle());
assertEquals("Invalid update set", new DateTime(2009, 1, 2, 1, 1).toDate(), feed.getUpdated());
}
assertNotNull("No id set", feed.getId());
assertNotNull("No title set", feed.getTitle());
assertEquals("Invalid update set", new DateTime(2009, 1, 2, 1, 1).toDate(), feed.getUpdated());
}
@Test
public void buildFeedEntries() throws Exception {
List<Entry> entries = visitView.buildFeedEntries(model, null, null);
assertEquals("Invalid amount of entries", 2, entries.size());
}
@Test
public void buildFeedEntries() throws Exception {
List<Entry> entries = visitView.buildFeedEntries(model, null, null);
assertEquals("Invalid amount of entries", 2, entries.size());
}
}

View file

@ -2,10 +2,12 @@
<!--
- DispatcherServlet application context for PetClinic's web tier.
-->
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<import resource="classpath:spring/dao-config.xml"/>
<import resource="classpath:spring/mvc-core-config.xml"/>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<import resource="classpath:spring/dao-config.xml"/>
<import resource="classpath:spring/mvc-core-config.xml"/>
</beans>

View file

@ -16,12 +16,6 @@
package org.springframework.samples.petclinic.web;
import static org.hamcrest.Matchers.containsString;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.xpath;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -36,8 +30,12 @@ import org.springframework.test.web.servlet.ResultActions;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import static org.hamcrest.Matchers.containsString;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
/**
* @author Arjen Poutsma
* @author Arjen Poutsma
* @author Michael Isvy
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ -48,23 +46,24 @@ import org.springframework.web.context.WebApplicationContext;
@ActiveProfiles("jdbc")
public class VisitsAtomViewWithContainerTest {
@Autowired
private WebApplicationContext webApplicationContext;
@Autowired
private WebApplicationContext webApplicationContext;
private MockMvc mockMvc;
@Before
public void setup() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.webApplicationContext).build();
}
private MockMvc mockMvc;
@Test
public void getVisits() throws Exception {
MediaType mediaType = MediaType.APPLICATION_ATOM_XML;
ResultActions actions = this.mockMvc.perform(get("/vets.atom"));
actions.andExpect(status().isOk());
actions.andExpect(xpath("//*").string(containsString("Pet ClinicService Visits")));
actions.andExpect(content().contentType("application/atom+xml"));
}
@Before
public void setup() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.webApplicationContext).build();
}
@Test
public void getVisits() throws Exception {
//gDickens: MediaType is not used
MediaType mediaType = MediaType.APPLICATION_ATOM_XML;
ResultActions actions = this.mockMvc.perform(get("/vets.atom"));
actions.andExpect(status().isOk());
actions.andExpect(xpath("//*").string(containsString("Pet ClinicService Visits")));
actions.andExpect(content().contentType("application/atom+xml"));
}
}