@@ -275,6 +271,7 @@
install
+ petclinic
@@ -314,7 +311,7 @@
maven-war-plugin
2.3
- petclinic
+ false
@@ -383,18 +380,18 @@
-
-
+
org.codehaus.mojo
cobertura-maven-plugin
${cobertura.version}
-
-
- html
-
-
-
+
+
+
+ cobertura
+
+
+
diff --git a/readme.md b/readme.md
index 5cf6aeef4..4b6a0f4cd 100644
--- a/readme.md
+++ b/readme.md
@@ -96,7 +96,7 @@ File -> Import -> Maven -> Existing Maven project
ownersList.jsp
vetList.jsp
- web.xml
+ PetclinicInitializer.java
datatables.properties
|
@@ -135,7 +135,7 @@ File -> Import -> Maven -> Existing Maven project
business-config.xml
ClinicServiceJdbcTests.java
- web.xml
+ PetclinicInitializer.java
|
diff --git a/src/main/java/org/springframework/samples/petclinic/PetclinicInitializer.java b/src/main/java/org/springframework/samples/petclinic/PetclinicInitializer.java
new file mode 100644
index 000000000..75d3e6320
--- /dev/null
+++ b/src/main/java/org/springframework/samples/petclinic/PetclinicInitializer.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2002-2016 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;
+
+import com.github.dandelion.core.web.DandelionFilter;
+import com.github.dandelion.core.web.DandelionServlet;
+import com.github.dandelion.datatables.core.web.filter.DatatablesFilter;
+import org.springframework.samples.petclinic.config.MvcCoreConfig;
+import org.springframework.samples.petclinic.config.RootApplicationContextConfig;
+import org.springframework.web.context.WebApplicationContext;
+import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
+import org.springframework.web.filter.CharacterEncodingFilter;
+import org.springframework.web.servlet.DispatcherServlet;
+import org.springframework.web.servlet.support.AbstractDispatcherServletInitializer;
+
+import javax.servlet.*;
+import java.util.EnumSet;
+
+
+/**
+ * In Servlet 3.0+ environments, this class replaces the traditional {@code web.xml}-based approach in order to configure the
+ * {@link ServletContext} programmatically.
+ *
+ * Create the Spring "root" application context.
+ * Register a {@link DispatcherServlet} and a {@link DandelionServlet} in the servlet context.
+ * For both servlets, register a {@link CharacterEncodingFilter}, a {@link DandelionFilter} an a {@link DatatablesFilter}.
+ *
+ *
+ * @author Antoine Rey
+ */
+public class PetclinicInitializer extends AbstractDispatcherServletInitializer {
+
+ /**
+ * Spring profile used to choose the persistence layer implementation.
+ *
+ * When using Spring jpa, use: jpa
+ * When using Spring JDBC, use: jdbc
+ * When using Spring Data JPA, use: spring-data-jpa
+ */
+ private static final String SPRING_PROFILE = "jpa";
+
+ private static final String DANDELION_SERVLET = "dandelionServlet";
+
+ @Override
+ public void onStartup(ServletContext servletContext) throws ServletException {
+ super.onStartup(servletContext);
+ registerDandelionServlet(servletContext);
+ }
+
+ @Override
+ protected WebApplicationContext createRootApplicationContext() {
+ AnnotationConfigWebApplicationContext rootAppContext = new AnnotationConfigWebApplicationContext();
+ rootAppContext.register(RootApplicationContextConfig.class);
+ rootAppContext.getEnvironment().setActiveProfiles(SPRING_PROFILE);
+ return rootAppContext;
+ }
+
+
+ @Override
+ protected WebApplicationContext createServletApplicationContext() {
+ AnnotationConfigWebApplicationContext webAppContext = new AnnotationConfigWebApplicationContext();
+ webAppContext.register(MvcCoreConfig.class);
+ return webAppContext;
+ }
+
+ @Override
+ protected String[] getServletMappings() {
+ return new String[]{"/"};
+ }
+
+ @Override
+ protected Filter[] getServletFilters() {
+ // Used to provide the ability to enter Chinese characters inside the Owner Form
+ CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter("UTF-8", true);
+
+ // Dandelion filter definition and mapping -->
+ DandelionFilter dandelionFilter = new DandelionFilter();
+
+ // Dandelion-Datatables filter, used for basic export -->
+ DatatablesFilter datatablesFilter = new DatatablesFilter();
+
+ return new Filter[]{characterEncodingFilter, dandelionFilter, datatablesFilter};
+ }
+
+ @Override
+ protected FilterRegistration.Dynamic registerServletFilter(ServletContext servletContext, Filter filter) {
+ FilterRegistration.Dynamic registration = super.registerServletFilter(servletContext, filter);
+ registration.addMappingForServletNames(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE), false, DANDELION_SERVLET);
+ return registration;
+ }
+
+ private void registerDandelionServlet(ServletContext servletContext) {
+ DandelionServlet dandelionServlet = new DandelionServlet();
+ ServletRegistration.Dynamic registration = servletContext.addServlet(DANDELION_SERVLET, dandelionServlet);
+ registration.setLoadOnStartup(2);
+ registration.addMapping("/dandelion-assets/*");
+ }
+}
diff --git a/src/main/webapp/WEB-INF/jetty-web.xml b/src/main/webapp/WEB-INF/jetty-web.xml
new file mode 100644
index 000000000..5bb92f033
--- /dev/null
+++ b/src/main/webapp/WEB-INF/jetty-web.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+ true
+
diff --git a/src/main/webapp/WEB-INF/no-spring-config-files-there.txt b/src/main/webapp/WEB-INF/no-spring-config-files-there.txt
deleted file mode 100644
index 45fb7bf0a..000000000
--- a/src/main/webapp/WEB-INF/no-spring-config-files-there.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-All Spring config files (including Spring MVC ones) are inside src/main/resource.
-There are mostly 2 reasons to that:
-- All Spring config files are grouped into one single place
-- It is simpler to reference them from inside JUnit tests
\ No newline at end of file
diff --git a/src/main/webapp/WEB-INF/tags/menu.tag b/src/main/webapp/WEB-INF/tags/menu.tag
index f7e8652b2..6afb0f3f5 100644
--- a/src/main/webapp/WEB-INF/tags/menu.tag
+++ b/src/main/webapp/WEB-INF/tags/menu.tag
@@ -8,14 +8,14 @@
-
+
diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml
deleted file mode 100644
index 27602966a..000000000
--- a/src/main/webapp/WEB-INF/web.xml
+++ /dev/null
@@ -1,127 +0,0 @@
-
-
-
- Spring PetClinic
- Spring PetClinic sample application
-
-
-
- spring.profiles.active
- jpa
-
-
-
-
-
-
-
-
-
-
-
- contextClass
- org.springframework.web.context.support.AnnotationConfigWebApplicationContext
-
-
- contextConfigLocation
- org.springframework.samples.petclinic.config.RootApplicationContextConfig
-
-
-
-
- org.springframework.web.context.ContextLoaderListener
-
-
-
-
- petclinic
- org.springframework.web.servlet.DispatcherServlet
-
- contextClass
- org.springframework.web.context.support.AnnotationConfigWebApplicationContext
-
-
- contextConfigLocation
- org.springframework.samples.petclinic.config.MvcCoreConfig
-
- 1
-
-
-
- petclinic
- /
-
-
-
-
- dandelionServlet
- com.github.dandelion.core.web.DandelionServlet
- 2
-
-
- dandelionServlet
- /dandelion-assets/*
-
-
-
-
- encodingFilter
- org.springframework.web.filter.CharacterEncodingFilter
-
- encoding
- UTF-8
-
-
- forceEncoding
- true
-
-
-
-
- encodingFilter
- /*
-
-
-
-
- dandelionFilter
- com.github.dandelion.core.web.DandelionFilter
-
-
- dandelionFilter
- /*
-
-
-
-
- datatables
- com.github.dandelion.datatables.core.web.filter.DatatablesFilter
-
-
- datatables
- /*
-
-
-
-
-
diff --git a/src/test/java/org/springframework/samples/petclinic/config/MvcTestConfig.java b/src/test/java/org/springframework/samples/petclinic/config/MvcTestConfig.java
new file mode 100644
index 000000000..1bd5810c3
--- /dev/null
+++ b/src/test/java/org/springframework/samples/petclinic/config/MvcTestConfig.java
@@ -0,0 +1,15 @@
+package org.springframework.samples.petclinic.config;
+
+import org.mockito.Mockito;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.samples.petclinic.service.ClinicService;
+
+@Configuration
+public class MvcTestConfig {
+
+ @Bean
+ public ClinicService clinicService() {
+ return Mockito.mock(ClinicService.class);
+ }
+}
diff --git a/src/test/java/org/springframework/samples/petclinic/web/CrashControllerTests.java b/src/test/java/org/springframework/samples/petclinic/web/CrashControllerTests.java
index 2c8ac61d0..eebf0eb86 100644
--- a/src/test/java/org/springframework/samples/petclinic/web/CrashControllerTests.java
+++ b/src/test/java/org/springframework/samples/petclinic/web/CrashControllerTests.java
@@ -1,24 +1,20 @@
package org.springframework.samples.petclinic.web;
-import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
-import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
-
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.samples.petclinic.config.BusinessConfig;
import org.springframework.samples.petclinic.config.MvcCoreConfig;
-import org.springframework.samples.petclinic.config.ToolsConfig;
-import org.springframework.test.context.ActiveProfiles;
+import org.springframework.samples.petclinic.config.MvcTestConfig;
import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.ContextHierarchy;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.servlet.HandlerExceptionResolver;
-import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver;
+
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
/**
* Test class for {@link CrashController}
@@ -27,10 +23,7 @@ import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver;
*/
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
-@ContextHierarchy({
- @ContextConfiguration(classes = { BusinessConfig.class, ToolsConfig.class }),
- @ContextConfiguration(classes = MvcCoreConfig.class)})
-@ActiveProfiles("spring-data-jpa")
+@ContextConfiguration(classes = { MvcCoreConfig.class, MvcTestConfig.class })
public class CrashControllerTests {
@Autowired
diff --git a/src/test/java/org/springframework/samples/petclinic/web/OwnerControllerTests.java b/src/test/java/org/springframework/samples/petclinic/web/OwnerControllerTests.java
index 602b49ffb..02b520bbb 100644
--- a/src/test/java/org/springframework/samples/petclinic/web/OwnerControllerTests.java
+++ b/src/test/java/org/springframework/samples/petclinic/web/OwnerControllerTests.java
@@ -1,15 +1,15 @@
package org.springframework.samples.petclinic.web;
+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.samples.petclinic.config.BusinessConfig;
import org.springframework.samples.petclinic.config.MvcCoreConfig;
-import org.springframework.samples.petclinic.config.ToolsConfig;
-import org.springframework.test.context.ActiveProfiles;
+import org.springframework.samples.petclinic.config.MvcTestConfig;
+import org.springframework.samples.petclinic.model.Owner;
+import org.springframework.samples.petclinic.service.ClinicService;
import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.ContextHierarchy;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
@@ -17,12 +17,11 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
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 static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
+
/**
* Test class for {@link OwnerController}
@@ -31,10 +30,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
*/
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
-@ContextHierarchy({
- @ContextConfiguration(classes = { BusinessConfig.class, ToolsConfig.class }),
- @ContextConfiguration(classes = MvcCoreConfig.class)})
-@ActiveProfiles("spring-data-jpa")
+@ContextConfiguration(classes = { MvcCoreConfig.class, MvcTestConfig.class })
public class OwnerControllerTests {
private static final int TEST_OWNER_ID = 1;
@@ -42,11 +38,26 @@ public class OwnerControllerTests {
@Autowired
private OwnerController ownerController;
+ @Autowired
+ private ClinicService clinicService;
+
private MockMvc mockMvc;
+ private Owner george;
+
@Before
public void setup() {
this.mockMvc = MockMvcBuilders.standaloneSetup(ownerController).build();
+
+ 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.clinicService.findOwnerById(TEST_OWNER_ID)).willReturn(george);
+
}
@Test
@@ -93,6 +104,8 @@ public class OwnerControllerTests {
@Test
public void testProcessFindFormSuccess() throws Exception {
+ given(this.clinicService.findOwnerByLastName("")).willReturn(Lists.newArrayList(george, new Owner()));
+
mockMvc.perform(get("/owners"))
.andExpect(status().isOk())
.andExpect(view().name("owners/ownersList"));
@@ -100,6 +113,8 @@ public class OwnerControllerTests {
@Test
public void testProcessFindFormByLastName() throws Exception {
+ given(this.clinicService.findOwnerByLastName(george.getLastName())).willReturn(Lists.newArrayList(george));
+
mockMvc.perform(get("/owners")
.param("lastName", "Franklin")
)
diff --git a/src/test/java/org/springframework/samples/petclinic/web/PetControllerTests.java b/src/test/java/org/springframework/samples/petclinic/web/PetControllerTests.java
index ca34febd1..d30a8484f 100644
--- a/src/test/java/org/springframework/samples/petclinic/web/PetControllerTests.java
+++ b/src/test/java/org/springframework/samples/petclinic/web/PetControllerTests.java
@@ -1,25 +1,29 @@
package org.springframework.samples.petclinic.web;
+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.format.support.DefaultFormattingConversionService;
-import org.springframework.samples.petclinic.config.BusinessConfig;
import org.springframework.samples.petclinic.config.MvcCoreConfig;
-import org.springframework.samples.petclinic.config.ToolsConfig;
-import org.springframework.test.context.ActiveProfiles;
+import org.springframework.samples.petclinic.config.MvcTestConfig;
+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.test.context.ContextConfiguration;
-import org.springframework.test.context.ContextHierarchy;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
+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.*;
+
/**
* Test class for the {@link PetController}
*
@@ -27,10 +31,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
*/
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
-@ContextHierarchy({
- @ContextConfiguration(classes = { BusinessConfig.class, ToolsConfig.class }),
- @ContextConfiguration(classes = MvcCoreConfig.class)})
-@ActiveProfiles("spring-data-jpa")
+@ContextConfiguration(classes = { MvcCoreConfig.class, MvcTestConfig.class })
public class PetControllerTests {
private static final int TEST_OWNER_ID = 1;
@@ -42,6 +43,9 @@ public class PetControllerTests {
@Autowired
private PetTypeFormatter petTypeFormatter;
+ @Autowired
+ private ClinicService clinicService;
+
private MockMvc mockMvc;
@Before
@@ -52,6 +56,13 @@ public class PetControllerTests {
.standaloneSetup(petController)
.setConversionService(formattingConversionService)
.build();
+
+ PetType cat = new PetType();
+ cat.setId(3);
+ cat.setName("hamster");
+ given(this.clinicService.findPetTypes()).willReturn(Lists.newArrayList(cat));
+ given(this.clinicService.findOwnerById(TEST_OWNER_ID)).willReturn(new Owner());
+ given(this.clinicService.findPetById(TEST_PET_ID)).willReturn(new Pet());
}
@Test
diff --git a/src/test/java/org/springframework/samples/petclinic/web/VetControllerTests.java b/src/test/java/org/springframework/samples/petclinic/web/VetControllerTests.java
index 7cf0c13e5..b86e35f52 100644
--- a/src/test/java/org/springframework/samples/petclinic/web/VetControllerTests.java
+++ b/src/test/java/org/springframework/samples/petclinic/web/VetControllerTests.java
@@ -1,16 +1,17 @@
package org.springframework.samples.petclinic.web;
+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.http.MediaType;
-import org.springframework.samples.petclinic.config.BusinessConfig;
import org.springframework.samples.petclinic.config.MvcCoreConfig;
-import org.springframework.samples.petclinic.config.ToolsConfig;
-import org.springframework.test.context.ActiveProfiles;
+import org.springframework.samples.petclinic.config.MvcTestConfig;
+import org.springframework.samples.petclinic.model.Specialty;
+import org.springframework.samples.petclinic.model.Vet;
+import org.springframework.samples.petclinic.service.ClinicService;
import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.ContextHierarchy;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
@@ -18,28 +19,44 @@ import org.springframework.test.web.servlet.ResultActions;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
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.*;
+
/**
* Test class for the {@link VetController}
*/
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
-@ContextHierarchy({
- @ContextConfiguration(classes = { BusinessConfig.class, ToolsConfig.class }),
- @ContextConfiguration(classes = MvcCoreConfig.class)})
-@ActiveProfiles("spring-data-jpa")
+@ContextConfiguration(classes = { MvcCoreConfig.class, MvcTestConfig.class })
public class VetControllerTests {
@Autowired
private VetController vetController;
+ @Autowired
+ private ClinicService clinicService;
+
private MockMvc mockMvc;
@Before
public void setup() {
this.mockMvc = MockMvcBuilders.standaloneSetup(vetController).build();
+
+ 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.clinicService.findVets()).willReturn(Lists.newArrayList(james, helen));
}
@Test
diff --git a/src/test/java/org/springframework/samples/petclinic/web/VisitControllerTests.java b/src/test/java/org/springframework/samples/petclinic/web/VisitControllerTests.java
index 32f261b60..cb40125aa 100644
--- a/src/test/java/org/springframework/samples/petclinic/web/VisitControllerTests.java
+++ b/src/test/java/org/springframework/samples/petclinic/web/VisitControllerTests.java
@@ -4,22 +4,21 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.samples.petclinic.config.BusinessConfig;
import org.springframework.samples.petclinic.config.MvcCoreConfig;
-import org.springframework.samples.petclinic.config.ToolsConfig;
-import org.springframework.test.context.ActiveProfiles;
+import org.springframework.samples.petclinic.config.MvcTestConfig;
+import org.springframework.samples.petclinic.model.Pet;
+import org.springframework.samples.petclinic.service.ClinicService;
import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.ContextHierarchy;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
+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 static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
+
/**
* Test class for {@link VisitController}
@@ -28,10 +27,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
*/
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
-@ContextHierarchy({
- @ContextConfiguration(classes = { BusinessConfig.class, ToolsConfig.class }),
- @ContextConfiguration(classes = MvcCoreConfig.class)})
-@ActiveProfiles("spring-data-jpa")
+@ContextConfiguration(classes = { MvcCoreConfig.class, MvcTestConfig.class })
public class VisitControllerTests {
private static final int TEST_PET_ID = 1;
@@ -39,11 +35,16 @@ public class VisitControllerTests {
@Autowired
private VisitController visitController;
+ @Autowired
+ private ClinicService clinicService;
+
private MockMvc mockMvc;
@Before
public void setup() {
this.mockMvc = MockMvcBuilders.standaloneSetup(visitController).build();
+
+ given(this.clinicService.findPetById(TEST_PET_ID)).willReturn(new Pet());
}
@Test