diff --git a/src/test/java/org/springframework/samples/petclinic/model/ValidatorTests.java b/src/test/java/org/springframework/samples/petclinic/model/ValidatorTests.java deleted file mode 100644 index 933d8dd88..000000000 --- a/src/test/java/org/springframework/samples/petclinic/model/ValidatorTests.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.springframework.samples.petclinic.model; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.Locale; -import java.util.Set; - -import javax.validation.ConstraintViolation; -import javax.validation.Validator; - -import org.junit.Test; -import org.springframework.context.i18n.LocaleContextHolder; -import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; - -/** - * @author Michael Isvy - * Simple test to make sure that Bean Validation is working - * (useful when upgrading to a new version of Hibernate Validator/ Bean Validation) - */ -public class ValidatorTests { - - private Validator createValidator() { - LocalValidatorFactoryBean localValidatorFactoryBean = new LocalValidatorFactoryBean(); - localValidatorFactoryBean.afterPropertiesSet(); - return localValidatorFactoryBean; - } - - @Test - public void shouldNotValidateWhenFirstNameEmpty() { - - LocaleContextHolder.setLocale(Locale.ENGLISH); - Person person = new Person(); - person.setFirstName(""); - person.setLastName("smith"); - - Validator validator = createValidator(); - Set> constraintViolations = validator.validate(person); - - assertThat(constraintViolations.size()).isEqualTo(1); - ConstraintViolation violation = constraintViolations.iterator().next(); - assertThat(violation.getPropertyPath().toString()).isEqualTo("firstName"); - assertThat(violation.getMessage()).isEqualTo("may not be empty"); - } - -} diff --git a/src/test/java/org/springframework/samples/petclinic/owner/OwnerControllerTests.java b/src/test/java/org/springframework/samples/petclinic/owner/OwnerControllerTests.java deleted file mode 100644 index 0956ffada..000000000 --- a/src/test/java/org/springframework/samples/petclinic/owner/OwnerControllerTests.java +++ /dev/null @@ -1,179 +0,0 @@ -package org.springframework.samples.petclinic.owner; - -import static org.hamcrest.Matchers.hasProperty; -import static org.hamcrest.Matchers.is; -import static org.mockito.BDDMockito.given; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; - -import org.assertj.core.util.Lists; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.samples.petclinic.owner.Owner; -import org.springframework.samples.petclinic.owner.OwnerController; -import org.springframework.samples.petclinic.owner.OwnerRepository; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; - -/** - * Test class for {@link OwnerController} - * - * @author Colin But - */ -@RunWith(SpringRunner.class) -@WebMvcTest(OwnerController.class) -public class OwnerControllerTests { - - private static final int TEST_OWNER_ID = 1; - - @Autowired - private MockMvc mockMvc; - - @MockBean - private OwnerRepository owners; - - private Owner george; - - @Before - public void setup() { - george = new Owner(); - george.setId(TEST_OWNER_ID); - george.setFirstName("George"); - george.setLastName("Franklin"); - george.setAddress("110 W. Liberty St."); - george.setCity("Madison"); - george.setTelephone("6085551023"); - given(this.owners.findById(TEST_OWNER_ID)).willReturn(george); - } - - @Test - public void testInitCreationForm() throws Exception { - mockMvc.perform(get("/owners/new")) - .andExpect(status().isOk()) - .andExpect(model().attributeExists("owner")) - .andExpect(view().name("owners/createOrUpdateOwnerForm")); - } - - @Test - public void testProcessCreationFormSuccess() throws Exception { - mockMvc.perform(post("/owners/new") - .param("firstName", "Joe") - .param("lastName", "Bloggs") - .param("address", "123 Caramel Street") - .param("city", "London") - .param("telephone", "01316761638") - ) - .andExpect(status().is3xxRedirection()); - } - - @Test - public void testProcessCreationFormHasErrors() throws Exception { - mockMvc.perform(post("/owners/new") - .param("firstName", "Joe") - .param("lastName", "Bloggs") - .param("city", "London") - ) - .andExpect(status().isOk()) - .andExpect(model().attributeHasErrors("owner")) - .andExpect(model().attributeHasFieldErrors("owner", "address")) - .andExpect(model().attributeHasFieldErrors("owner", "telephone")) - .andExpect(view().name("owners/createOrUpdateOwnerForm")); - } - - @Test - public void testInitFindForm() throws Exception { - mockMvc.perform(get("/owners/find")) - .andExpect(status().isOk()) - .andExpect(model().attributeExists("owner")) - .andExpect(view().name("owners/findOwners")); - } - - @Test - public void testProcessFindFormSuccess() throws Exception { - given(this.owners.findByLastName("")).willReturn(Lists.newArrayList(george, new Owner())); - mockMvc.perform(get("/owners")) - .andExpect(status().isOk()) - .andExpect(view().name("owners/ownersList")); - } - - @Test - public void testProcessFindFormByLastName() throws Exception { - given(this.owners.findByLastName(george.getLastName())).willReturn(Lists.newArrayList(george)); - mockMvc.perform(get("/owners") - .param("lastName", "Franklin") - ) - .andExpect(status().is3xxRedirection()) - .andExpect(view().name("redirect:/owners/" + TEST_OWNER_ID)); - } - - @Test - public void testProcessFindFormNoOwnersFound() throws Exception { - mockMvc.perform(get("/owners") - .param("lastName", "Unknown Surname") - ) - .andExpect(status().isOk()) - .andExpect(model().attributeHasFieldErrors("owner", "lastName")) - .andExpect(model().attributeHasFieldErrorCode("owner", "lastName", "notFound")) - .andExpect(view().name("owners/findOwners")); - } - - @Test - public void testInitUpdateOwnerForm() throws Exception { - mockMvc.perform(get("/owners/{ownerId}/edit", TEST_OWNER_ID)) - .andExpect(status().isOk()) - .andExpect(model().attributeExists("owner")) - .andExpect(model().attribute("owner", hasProperty("lastName", is("Franklin")))) - .andExpect(model().attribute("owner", hasProperty("firstName", is("George")))) - .andExpect(model().attribute("owner", hasProperty("address", is("110 W. Liberty St.")))) - .andExpect(model().attribute("owner", hasProperty("city", is("Madison")))) - .andExpect(model().attribute("owner", hasProperty("telephone", is("6085551023")))) - .andExpect(view().name("owners/createOrUpdateOwnerForm")); - } - - @Test - public void testProcessUpdateOwnerFormSuccess() throws Exception { - mockMvc.perform(post("/owners/{ownerId}/edit", TEST_OWNER_ID) - .param("firstName", "Joe") - .param("lastName", "Bloggs") - .param("address", "123 Caramel Street") - .param("city", "London") - .param("telephone", "01616291589") - ) - .andExpect(status().is3xxRedirection()) - .andExpect(view().name("redirect:/owners/{ownerId}")); - } - - @Test - public void testProcessUpdateOwnerFormHasErrors() throws Exception { - mockMvc.perform(post("/owners/{ownerId}/edit", TEST_OWNER_ID) - .param("firstName", "Joe") - .param("lastName", "Bloggs") - .param("city", "London") - ) - .andExpect(status().isOk()) - .andExpect(model().attributeHasErrors("owner")) - .andExpect(model().attributeHasFieldErrors("owner", "address")) - .andExpect(model().attributeHasFieldErrors("owner", "telephone")) - .andExpect(view().name("owners/createOrUpdateOwnerForm")); - } - - @Test - public void testShowOwner() throws Exception { - mockMvc.perform(get("/owners/{ownerId}", TEST_OWNER_ID)) - .andExpect(status().isOk()) - .andExpect(model().attribute("owner", hasProperty("lastName", is("Franklin")))) - .andExpect(model().attribute("owner", hasProperty("firstName", is("George")))) - .andExpect(model().attribute("owner", hasProperty("address", is("110 W. Liberty St.")))) - .andExpect(model().attribute("owner", hasProperty("city", is("Madison")))) - .andExpect(model().attribute("owner", hasProperty("telephone", is("6085551023")))) - .andExpect(view().name("owners/ownerDetails")); - } - -} diff --git a/src/test/java/org/springframework/samples/petclinic/owner/PetControllerTests.java b/src/test/java/org/springframework/samples/petclinic/owner/PetControllerTests.java deleted file mode 100644 index f07847c61..000000000 --- a/src/test/java/org/springframework/samples/petclinic/owner/PetControllerTests.java +++ /dev/null @@ -1,127 +0,0 @@ -package org.springframework.samples.petclinic.owner; - -import static org.mockito.BDDMockito.given; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; - -import org.assertj.core.util.Lists; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.FilterType; -import org.springframework.samples.petclinic.owner.Owner; -import org.springframework.samples.petclinic.owner.OwnerRepository; -import org.springframework.samples.petclinic.owner.Pet; -import org.springframework.samples.petclinic.owner.PetController; -import org.springframework.samples.petclinic.owner.PetRepository; -import org.springframework.samples.petclinic.owner.PetType; -import org.springframework.samples.petclinic.owner.PetTypeFormatter; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; - -/** - * Test class for the {@link PetController} - * - * @author Colin But - */ -@RunWith(SpringRunner.class) -@WebMvcTest(value = PetController.class, - includeFilters = @ComponentScan.Filter( - value = PetTypeFormatter.class, - type = FilterType.ASSIGNABLE_TYPE)) -public class PetControllerTests { - - private static final int TEST_OWNER_ID = 1; - private static final int TEST_PET_ID = 1; - - - @Autowired - private MockMvc mockMvc; - - @MockBean - private PetRepository pets; - - @MockBean - private OwnerRepository owners; - - @Before - public void setup() { - PetType cat = new PetType(); - cat.setId(3); - cat.setName("hamster"); - given(this.pets.findPetTypes()).willReturn(Lists.newArrayList(cat)); - given(this.owners.findById(TEST_OWNER_ID)).willReturn(new Owner()); - given(this.pets.findById(TEST_PET_ID)).willReturn(new Pet()); - - } - - @Test - public void testInitCreationForm() throws Exception { - mockMvc.perform(get("/owners/{ownerId}/pets/new", TEST_OWNER_ID)) - .andExpect(status().isOk()) - .andExpect(view().name("pets/createOrUpdatePetForm")) - .andExpect(model().attributeExists("pet")); - } - - @Test - public void testProcessCreationFormSuccess() throws Exception { - mockMvc.perform(post("/owners/{ownerId}/pets/new", TEST_OWNER_ID) - .param("name", "Betty") - .param("type", "hamster") - .param("birthDate", "2015/02/12") - ) - .andExpect(status().is3xxRedirection()) - .andExpect(view().name("redirect:/owners/{ownerId}")); - } - - @Test - public void testProcessCreationFormHasErrors() throws Exception { - mockMvc.perform(post("/owners/{ownerId}/pets/{petId}/edit", TEST_OWNER_ID, TEST_PET_ID) - .param("name", "Betty") - .param("birthDate", "2015/02/12") - ) - .andExpect(model().attributeHasNoErrors("owner")) - .andExpect(model().attributeHasErrors("pet")) - .andExpect(status().isOk()) - .andExpect(view().name("pets/createOrUpdatePetForm")); - } - - @Test - public void testInitUpdateForm() throws Exception { - mockMvc.perform(get("/owners/{ownerId}/pets/{petId}/edit", TEST_OWNER_ID, TEST_PET_ID)) - .andExpect(status().isOk()) - .andExpect(model().attributeExists("pet")) - .andExpect(view().name("pets/createOrUpdatePetForm")); - } - - @Test - public void testProcessUpdateFormSuccess() throws Exception { - mockMvc.perform(post("/owners/{ownerId}/pets/{petId}/edit", TEST_OWNER_ID, TEST_PET_ID) - .param("name", "Betty") - .param("type", "hamster") - .param("birthDate", "2015/02/12") - ) - .andExpect(status().is3xxRedirection()) - .andExpect(view().name("redirect:/owners/{ownerId}")); - } - - @Test - public void testProcessUpdateFormHasErrors() throws Exception { - mockMvc.perform(post("/owners/{ownerId}/pets/{petId}/edit", TEST_OWNER_ID, TEST_PET_ID) - .param("name", "Betty") - .param("birthDate", "2015/02/12") - ) - .andExpect(model().attributeHasNoErrors("owner")) - .andExpect(model().attributeHasErrors("pet")) - .andExpect(status().isOk()) - .andExpect(view().name("pets/createOrUpdatePetForm")); - } - -} diff --git a/src/test/java/org/springframework/samples/petclinic/owner/PetTypeFormatterTests.java b/src/test/java/org/springframework/samples/petclinic/owner/PetTypeFormatterTests.java deleted file mode 100644 index cbd97b61f..000000000 --- a/src/test/java/org/springframework/samples/petclinic/owner/PetTypeFormatterTests.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.springframework.samples.petclinic.owner; - -import static org.junit.Assert.assertEquals; - -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Locale; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; -import org.springframework.samples.petclinic.owner.PetRepository; -import org.springframework.samples.petclinic.owner.PetType; -import org.springframework.samples.petclinic.owner.PetTypeFormatter; - -/** - * Test class for {@link PetTypeFormatter} - * - * @author Colin But - */ -@RunWith(MockitoJUnitRunner.class) -public class PetTypeFormatterTests { - - @Mock - private PetRepository pets; - - private PetTypeFormatter petTypeFormatter; - - @Before - public void setup() { - this.petTypeFormatter = new PetTypeFormatter(pets); - } - - @Test - public void testPrint() { - PetType petType = new PetType(); - petType.setName("Hamster"); - String petTypeName = this.petTypeFormatter.print(petType, Locale.ENGLISH); - assertEquals("Hamster", petTypeName); - } - - @Test - public void shouldParse() throws ParseException { - Mockito.when(this.pets.findPetTypes()).thenReturn(makePetTypes()); - PetType petType = petTypeFormatter.parse("Bird", Locale.ENGLISH); - assertEquals("Bird", petType.getName()); - } - - @Test(expected = ParseException.class) - public void shouldThrowParseException() throws ParseException { - Mockito.when(this.pets.findPetTypes()).thenReturn(makePetTypes()); - petTypeFormatter.parse("Fish", Locale.ENGLISH); - } - - /** - * Helper method to produce some sample pet types just for test purpose - * - * @return {@link Collection} of {@link PetType} - */ - private List makePetTypes() { - List petTypes = new ArrayList<>(); - petTypes.add(new PetType(){ - { - setName("Dog"); - } - }); - petTypes.add(new PetType(){ - { - setName("Bird"); - } - }); - return petTypes; - } - -} diff --git a/src/test/java/org/springframework/samples/petclinic/owner/VisitControllerTests.java b/src/test/java/org/springframework/samples/petclinic/owner/VisitControllerTests.java deleted file mode 100644 index 32a72daac..000000000 --- a/src/test/java/org/springframework/samples/petclinic/owner/VisitControllerTests.java +++ /dev/null @@ -1,75 +0,0 @@ -package org.springframework.samples.petclinic.owner; - -import static org.mockito.BDDMockito.given; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.samples.petclinic.owner.Pet; -import org.springframework.samples.petclinic.owner.PetRepository; -import org.springframework.samples.petclinic.owner.VisitController; -import org.springframework.samples.petclinic.visit.VisitRepository; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; - -/** - * Test class for {@link VisitController} - * - * @author Colin But - */ -@RunWith(SpringRunner.class) -@WebMvcTest(VisitController.class) -public class VisitControllerTests { - - private static final int TEST_PET_ID = 1; - - @Autowired - private MockMvc mockMvc; - - @MockBean - private VisitRepository visits; - - @MockBean - private PetRepository pets; - - @Before - public void init() { - given(this.pets.findById(TEST_PET_ID)).willReturn(new Pet()); - } - - @Test - public void testInitNewVisitForm() throws Exception { - mockMvc.perform(get("/owners/*/pets/{petId}/visits/new", TEST_PET_ID)) - .andExpect(status().isOk()) - .andExpect(view().name("pets/createOrUpdateVisitForm")); - } - - @Test - public void testProcessNewVisitFormSuccess() throws Exception { - mockMvc.perform(post("/owners/*/pets/{petId}/visits/new", TEST_PET_ID) - .param("name", "George") - .param("description", "Visit Description") - ) - .andExpect(status().is3xxRedirection()) - .andExpect(view().name("redirect:/owners/{ownerId}")); - } - - @Test - public void testProcessNewVisitFormHasErrors() throws Exception { - mockMvc.perform(post("/owners/*/pets/{petId}/visits/new", TEST_PET_ID) - .param("name", "George") - ) - .andExpect(model().attributeHasErrors("visit")) - .andExpect(status().isOk()) - .andExpect(view().name("pets/createOrUpdateVisitForm")); - } - -} diff --git a/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceTests.java b/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceTests.java deleted file mode 100644 index a3fca3fc6..000000000 --- a/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceTests.java +++ /dev/null @@ -1,206 +0,0 @@ -package org.springframework.samples.petclinic.service; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.Collection; -import java.util.Date; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.samples.petclinic.owner.Owner; -import org.springframework.samples.petclinic.owner.OwnerRepository; -import org.springframework.samples.petclinic.owner.Pet; -import org.springframework.samples.petclinic.owner.PetRepository; -import org.springframework.samples.petclinic.owner.PetType; -import org.springframework.samples.petclinic.vet.Vet; -import org.springframework.samples.petclinic.vet.VetRepository; -import org.springframework.samples.petclinic.visit.Visit; -import org.springframework.samples.petclinic.visit.VisitRepository; -import org.springframework.stereotype.Service; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.transaction.annotation.Transactional; - -/** - * Integration test of the Service and the Repository layer. - *

- * ClinicServiceSpringDataJpaTests subclasses benefit from the following services provided by the Spring - * TestContext Framework:

  • Spring IoC container caching which spares us unnecessary set up - * time between test execution.
  • Dependency Injection of test fixture instances, meaning that - * we don't need to perform application context lookups. See the use of {@link Autowired @Autowired} on the {@link - * ClinicServiceTests#clinicService clinicService} instance variable, which uses autowiring by - * type.
  • Transaction management, 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.
  • An {@link org.springframework.context.ApplicationContext - * ApplicationContext} is also inherited and can be used for explicit bean lookup if necessary.
- * - * @author Ken Krebs - * @author Rod Johnson - * @author Juergen Hoeller - * @author Sam Brannen - * @author Michael Isvy - * @author Dave Syer - */ - -@RunWith(SpringRunner.class) -@DataJpaTest(includeFilters = @ComponentScan.Filter(Service.class)) -public class ClinicServiceTests { - - @Autowired - protected OwnerRepository owners; - - @Autowired - protected PetRepository pets; - - @Autowired - protected VisitRepository visits; - - @Autowired - protected VetRepository vets; - - @Test - public void shouldFindOwnersByLastName() { - Collection owners = this.owners.findByLastName("Davis"); - assertThat(owners.size()).isEqualTo(2); - - owners = this.owners.findByLastName("Daviss"); - assertThat(owners.isEmpty()).isTrue(); - } - - @Test - public void shouldFindSingleOwnerWithPet() { - Owner owner = this.owners.findById(1); - assertThat(owner.getLastName()).startsWith("Franklin"); - assertThat(owner.getPets().size()).isEqualTo(1); - assertThat(owner.getPets().get(0).getType()).isNotNull(); - assertThat(owner.getPets().get(0).getType().getName()).isEqualTo("cat"); - } - - @Test - @Transactional - public void shouldInsertOwner() { - Collection owners = this.owners.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.owners.save(owner); - assertThat(owner.getId().longValue()).isNotEqualTo(0); - - owners = this.owners.findByLastName("Schultz"); - assertThat(owners.size()).isEqualTo(found + 1); - } - - @Test - @Transactional - public void shouldUpdateOwner() { - Owner owner = this.owners.findById(1); - String oldLastName = owner.getLastName(); - String newLastName = oldLastName + "X"; - - owner.setLastName(newLastName); - this.owners.save(owner); - - // retrieving new name from database - owner = this.owners.findById(1); - assertThat(owner.getLastName()).isEqualTo(newLastName); - } - - @Test - public void shouldFindPetWithCorrectId() { - Pet pet7 = this.pets.findById(7); - assertThat(pet7.getName()).startsWith("Samantha"); - assertThat(pet7.getOwner().getFirstName()).isEqualTo("Jean"); - - } - - @Test - public void shouldFindAllPetTypes() { - Collection petTypes = this.pets.findPetTypes(); - - PetType petType1 = EntityUtils.getById(petTypes, PetType.class, 1); - assertThat(petType1.getName()).isEqualTo("cat"); - PetType petType4 = EntityUtils.getById(petTypes, PetType.class, 4); - assertThat(petType4.getName()).isEqualTo("snake"); - } - - @Test - @Transactional - public void shouldInsertPetIntoDatabaseAndGenerateId() { - Owner owner6 = this.owners.findById(6); - int found = owner6.getPets().size(); - - Pet pet = new Pet(); - pet.setName("bowser"); - Collection types = this.pets.findPetTypes(); - pet.setType(EntityUtils.getById(types, PetType.class, 2)); - pet.setBirthDate(new Date()); - owner6.addPet(pet); - assertThat(owner6.getPets().size()).isEqualTo(found + 1); - - this.pets.save(pet); - this.owners.save(owner6); - - owner6 = this.owners.findById(6); - assertThat(owner6.getPets().size()).isEqualTo(found + 1); - // checks that id has been generated - assertThat(pet.getId()).isNotNull(); - } - - @Test - @Transactional - public void shouldUpdatePetName() throws Exception { - Pet pet7 = this.pets.findById(7); - String oldName = pet7.getName(); - - String newName = oldName + "X"; - pet7.setName(newName); - this.pets.save(pet7); - - pet7 = this.pets.findById(7); - assertThat(pet7.getName()).isEqualTo(newName); - } - - @Test - public void shouldFindVets() { - Collection vets = this.vets.findAll(); - - Vet vet = EntityUtils.getById(vets, Vet.class, 3); - assertThat(vet.getLastName()).isEqualTo("Douglas"); - assertThat(vet.getNrOfSpecialties()).isEqualTo(2); - assertThat(vet.getSpecialties().get(0).getName()).isEqualTo("dentistry"); - assertThat(vet.getSpecialties().get(1).getName()).isEqualTo("surgery"); - } - - @Test - @Transactional - public void shouldAddNewVisitForPet() { - Pet pet7 = this.pets.findById(7); - int found = pet7.getVisits().size(); - Visit visit = new Visit(); - pet7.addVisit(visit); - visit.setDescription("test"); - this.visits.save(visit); - this.pets.save(pet7); - - pet7 = this.pets.findById(7); - assertThat(pet7.getVisits().size()).isEqualTo(found + 1); - assertThat(visit.getId()).isNotNull(); - } - - @Test - public void shouldFindVisitsByPetId() throws Exception { - Collection visits = this.visits.findByPetId(7); - assertThat(visits.size()).isEqualTo(2); - Visit[] visitArr = visits.toArray(new Visit[visits.size()]); - assertThat(visitArr[0].getDate()).isNotNull(); - assertThat(visitArr[0].getPetId()).isEqualTo(7); - } - -} diff --git a/src/test/java/org/springframework/samples/petclinic/service/EntityUtils.java b/src/test/java/org/springframework/samples/petclinic/service/EntityUtils.java deleted file mode 100644 index ce83cc38c..000000000 --- a/src/test/java/org/springframework/samples/petclinic/service/EntityUtils.java +++ /dev/null @@ -1,54 +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.service; - -import java.util.Collection; - -import org.springframework.orm.ObjectRetrievalFailureException; -import org.springframework.samples.petclinic.model.BaseEntity; - -/** - * Utility methods for handling entities. Separate from the BaseEntity class mainly because of dependency on the - * ORM-associated ObjectRetrievalFailureException. - * - * @author Juergen Hoeller - * @author Sam Brannen - * @see org.springframework.samples.petclinic.model.BaseEntity - * @since 29.10.2003 - */ -public abstract class EntityUtils { - - /** - * Look up the entity of the given class with the given id in the given collection. - * - * @param entities the collection to search - * @param entityClass the entity class to look up - * @param entityId the entity id to look up - * @return the found entity - * @throws ObjectRetrievalFailureException if the entity was not found - */ - public static T getById(Collection entities, Class entityClass, int entityId) - throws ObjectRetrievalFailureException { - for (T entity : entities) { - if (entity.getId() == entityId && entityClass.isInstance(entity)) { - return entity; - } - } - throw new ObjectRetrievalFailureException(entityClass, entityId); - } - -} diff --git a/src/test/java/org/springframework/samples/petclinic/system/CrashControllerTests.java b/src/test/java/org/springframework/samples/petclinic/system/CrashControllerTests.java deleted file mode 100644 index 5b6c5b130..000000000 --- a/src/test/java/org/springframework/samples/petclinic/system/CrashControllerTests.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.springframework.samples.petclinic.system; - -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; - -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.forwardedUrl; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; - -/** - * Test class for {@link CrashController} - * - * @author Colin But - */ -@RunWith(SpringRunner.class) -// Waiting https://github.com/spring-projects/spring-boot/issues/5574 -@Ignore -@WebMvcTest(controllers = CrashController.class) -public class CrashControllerTests { - - @Autowired - private MockMvc mockMvc; - - @Test - public void testTriggerException() throws Exception { - mockMvc.perform(get("/oups")).andExpect(view().name("exception")) - .andExpect(model().attributeExists("exception")) - .andExpect(forwardedUrl("exception")).andExpect(status().isOk()); - } -} diff --git a/src/test/java/org/springframework/samples/petclinic/system/ProductionConfigurationTests.java b/src/test/java/org/springframework/samples/petclinic/system/ProductionConfigurationTests.java deleted file mode 100644 index ecbfd33cf..000000000 --- a/src/test/java/org/springframework/samples/petclinic/system/ProductionConfigurationTests.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.springframework.samples.petclinic.system; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.samples.petclinic.vet.VetRepository; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class ProductionConfigurationTests { - - @Autowired - private VetRepository vets; - - @Test - public void testFindAll() throws Exception { - vets.findAll(); - vets.findAll(); // served from cache - } -} diff --git a/src/test/java/org/springframework/samples/petclinic/vet/VetControllerTests.java b/src/test/java/org/springframework/samples/petclinic/vet/VetControllerTests.java deleted file mode 100644 index 3035d8096..000000000 --- a/src/test/java/org/springframework/samples/petclinic/vet/VetControllerTests.java +++ /dev/null @@ -1,82 +0,0 @@ -package org.springframework.samples.petclinic.vet; - -import static org.hamcrest.xml.HasXPath.hasXPath; -import static org.mockito.BDDMockito.given; -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.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; - -import org.assertj.core.util.Lists; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.MediaType; -import org.springframework.samples.petclinic.vet.Specialty; -import org.springframework.samples.petclinic.vet.Vet; -import org.springframework.samples.petclinic.vet.VetController; -import org.springframework.samples.petclinic.vet.VetRepository; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.ResultActions; - -/** - * Test class for the {@link VetController} - */ -@RunWith(SpringRunner.class) -@WebMvcTest(VetController.class) -public class VetControllerTests { - - @Autowired - private MockMvc mockMvc; - - @MockBean - private VetRepository vets; - - @Before - public void setup() { - Vet james = new Vet(); - james.setFirstName("James"); - james.setLastName("Carter"); - james.setId(1); - Vet helen = new Vet(); - helen.setFirstName("Helen"); - helen.setLastName("Leary"); - helen.setId(2); - Specialty radiology = new Specialty(); - radiology.setId(1); - radiology.setName("radiology"); - helen.addSpecialty(radiology); - given(this.vets.findAll()).willReturn(Lists.newArrayList(james, helen)); - } - - @Test - public void testShowVetListHtml() throws Exception { - mockMvc.perform(get("/vets.html")) - .andExpect(status().isOk()) - .andExpect(model().attributeExists("vets")) - .andExpect(view().name("vets/vetList")); - } - - @Test - public void testShowResourcesVetList() throws Exception { - ResultActions actions = mockMvc.perform(get("/vets.json").accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()); - actions.andExpect(content().contentType("application/json;charset=UTF-8")) - .andExpect(jsonPath("$.vetList[0].id").value(1)); - } - - @Test - public void testShowVetListXml() throws Exception { - mockMvc.perform(get("/vets.xml").accept(MediaType.APPLICATION_XML)) - .andExpect(status().isOk()) - .andExpect(content().contentType(MediaType.APPLICATION_XML_VALUE)) - .andExpect(content().node(hasXPath("/vets/vetList[id=1]/id"))); - } - -} diff --git a/src/test/java/org/springframework/samples/petclinic/vet/VetTests.java b/src/test/java/org/springframework/samples/petclinic/vet/VetTests.java deleted file mode 100644 index da79a52d1..000000000 --- a/src/test/java/org/springframework/samples/petclinic/vet/VetTests.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2016-2017 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.vet; - -import org.junit.Test; - -import org.springframework.util.SerializationUtils; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * @author Dave Syer - * - */ -public class VetTests { - - @Test - public void testSerialization() { - Vet vet = new Vet(); - vet.setFirstName("Zaphod"); - vet.setLastName("Beeblebrox"); - vet.setId(123); - Vet other = (Vet) SerializationUtils - .deserialize(SerializationUtils.serialize(vet)); - assertThat(other.getFirstName()).isEqualTo(vet.getFirstName()); - assertThat(other.getLastName()).isEqualTo(vet.getLastName()); - assertThat(other.getId()).isEqualTo(vet.getId()); - } - -} diff --git a/src/test/jmeter/petclinic_test_plan.jmx b/src/test/jmeter/petclinic_test_plan.jmx deleted file mode 100644 index b9adf8849..000000000 --- a/src/test/jmeter/petclinic_test_plan.jmx +++ /dev/null @@ -1,411 +0,0 @@ - - - - - - false - false - - - - PETCLINIC_HOST - localhost - = - - - PETCLINIC_PORT - 8080 - = - - - CONTEXT_WEB - - = - - - - - - - - continue - - false - 10 - - 500 - 10 - 1361531541000 - 1361531541000 - false - - - true - Original : 500 - 10 - 10 - - - - 300 - - - - - - - ${PETCLINIC_HOST} - ${PETCLINIC_PORT} - - - - - - 4 - - - - - true - - - - 1 - 10 - 1 - count - - false - - - - 1 - 13 - 1 - petCount - - false - - - - - - - - - - - - - ${CONTEXT_WEB}/ - GET - true - false - true - false - false - - - - - - - - - - - - - - ${CONTEXT_WEB}/resources/css/petclinic.css - GET - true - false - true - false - false - - - - - - - - - - - - - - ${CONTEXT_WEB}/vendors/jquery/jquery.js - GET - true - false - true - false - false - - - - - - - - - - - - - - ${CONTEXT_WEB}/vets.html - GET - true - false - true - false - false - - - - - - - - - - - - - - ${CONTEXT_WEB}/owners/find.html - GET - true - false - true - false - false - - - - - - - - - - - - - - ${CONTEXT_WEB}/owners.html?lastName= - GET - true - false - true - false - false - - - - - - - - - - - - - - ${CONTEXT_WEB}/owners/${count}.html - GET - true - false - true - false - false - - - - - - - - - - - - - - ${CONTEXT_WEB}/owners/${count}/edit.html - GET - true - false - true - false - false - - - - - true - - - - false - firstName=Test&lastName=${count}&address=1234+Test+St.&city=TestCity&telephone=612345678 - = - - - - - - - - - - ${CONTEXT_WEB}/owners/${count}/edit.html - POST - true - false - true - false - false - - - - - - - - - - - - - - ${CONTEXT_WEB}/owners/${count}/pets/${petCount}/visits/new - GET - true - false - true - false - false - - - - - true - - - - false - date=2013%2F02%2F22&description=visit - = - - - - - - - - - - ${CONTEXT_WEB}/owners/${count}/pets/${petCount}/visits/new - POST - true - false - true - false - false - - - - - - - - - - - - - - ${CONTEXT_WEB}/owners/${count}.html - GET - true - false - true - false - false - - - - - false - - saveConfig - - - true - true - true - - true - true - true - true - false - true - true - false - false - false - false - false - false - false - false - 0 - true - true - - - - - - - false - - saveConfig - - - true - true - true - - true - true - true - true - false - true - true - false - false - false - false - false - false - false - false - 0 - true - true - - - - - - - - - diff --git a/text.txt b/text.txt deleted file mode 100644 index 1504fd190..000000000 --- a/text.txt +++ /dev/null @@ -1 +0,0 @@ -austin messed up