mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-17 21:15:50 +00:00
Merge branch 'master' into javaconfig
Conflicts: src/main/webapp/WEB-INF/web.xml src/test/java/org/springframework/samples/petclinic/web/CrashControllerTests.java src/test/java/org/springframework/samples/petclinic/web/OwnerControllerTests.java src/test/java/org/springframework/samples/petclinic/web/PetControllerTests.java src/test/java/org/springframework/samples/petclinic/web/VetControllerTests.java src/test/java/org/springframework/samples/petclinic/web/VisitControllerTests.java
This commit is contained in:
commit
b45457993c
13 changed files with 239 additions and 203 deletions
29
pom.xml
29
pom.xml
|
@ -4,7 +4,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.springframework.samples</groupId>
|
||||
<artifactId>spring-petclinic</artifactId>
|
||||
<version>4.2.5-SNAPSHOT</version>
|
||||
<version>4.2.6-SNAPSHOT</version>
|
||||
|
||||
<name>petclinic</name>
|
||||
<packaging>war</packaging>
|
||||
|
@ -17,7 +17,7 @@
|
|||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
|
||||
<!-- Spring -->
|
||||
<spring-io-platform.version>2.0.5.RELEASE</spring-io-platform.version>
|
||||
<spring-io-platform.version>2.0.7.RELEASE</spring-io-platform.version>
|
||||
<spring-data-jdbc.version>1.1.0.RELEASE</spring-data-jdbc.version>
|
||||
|
||||
|
||||
|
@ -96,12 +96,8 @@
|
|||
</dependency>
|
||||
<!-- SPRING, SPRING, SPRINGITY SPRING -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-jpa</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
@ -275,6 +271,7 @@
|
|||
<!-- Maven plugin versions are mentioned in order to guarantee the build reproducibility in the long term -->
|
||||
<build>
|
||||
<defaultGoal>install</defaultGoal>
|
||||
<finalName>petclinic</finalName>
|
||||
<testResources>
|
||||
<testResource>
|
||||
<!-- declared explicitly so Spring config files can be placed next to their corresponding JUnit test class -->
|
||||
|
@ -314,7 +311,7 @@
|
|||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>2.3</version>
|
||||
<configuration>
|
||||
<warName>petclinic</warName>
|
||||
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
@ -383,18 +380,18 @@
|
|||
</build>
|
||||
<reporting>
|
||||
<plugins>
|
||||
|
||||
<!-- integrate maven-cobertura-plugin to project site -->
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>cobertura-maven-plugin</artifactId>
|
||||
<version>${cobertura.version}</version>
|
||||
<configuration>
|
||||
<formats>
|
||||
<format>html</format>
|
||||
</formats>
|
||||
<check/>
|
||||
</configuration>
|
||||
<reportSets>
|
||||
<reportSet>
|
||||
<reports>
|
||||
<report>cobertura</report>
|
||||
</reports>
|
||||
</reportSet>
|
||||
</reportSets>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</reporting>
|
||||
|
|
|
@ -96,7 +96,7 @@ File -> Import -> Maven -> Existing Maven project
|
|||
<td>
|
||||
<a href="/src/main/webapp/WEB-INF/jsp/owners/ownersList.jsp">ownersList.jsp</a>
|
||||
<a href="/src/main/webapp/WEB-INF/jsp/vets/vetList.jsp">vetList.jsp</a>
|
||||
<a href="/src/main/webapp/WEB-INF/web.xml">web.xml</a>
|
||||
<a href="/src/main/java/org/springframework/samples/petclinic/PetclinicInitializer.java">PetclinicInitializer.java</a>
|
||||
<a href="/src/main/resources/dandelion/datatables/datatables.properties">datatables.properties</a>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -135,7 +135,7 @@ File -> Import -> Maven -> Existing Maven project
|
|||
<td>
|
||||
<a href="/src/main/resources/spring/business-config.xml">business-config.xml</a>
|
||||
<a href="/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceJdbcTests.java">ClinicServiceJdbcTests.java</a>
|
||||
<a href="/src/main/webapp/WEB-INF/web.xml">web.xml</a>
|
||||
<a href="/src/main/java/org/springframework/samples/petclinic/PetclinicInitializer.java">PetclinicInitializer.java</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
|
|
@ -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.
|
||||
* <p/>
|
||||
* Create the Spring "<strong>root</strong>" application context.<br/>
|
||||
* Register a {@link DispatcherServlet} and a {@link DandelionServlet} in the servlet context.<br/>
|
||||
* For both servlets, register a {@link CharacterEncodingFilter}, a {@link DandelionFilter} an a {@link DatatablesFilter}.
|
||||
* <p/>
|
||||
*
|
||||
* @author Antoine Rey
|
||||
*/
|
||||
public class PetclinicInitializer extends AbstractDispatcherServletInitializer {
|
||||
|
||||
/**
|
||||
* Spring profile used to choose the persistence layer implementation.
|
||||
* <p/>
|
||||
* 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/*");
|
||||
}
|
||||
}
|
7
src/main/webapp/WEB-INF/jetty-web.xml
Normal file
7
src/main/webapp/WEB-INF/jetty-web.xml
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
|
||||
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
|
||||
<!-- Fix Jetty 9 issue -->
|
||||
<!-- http://stackoverflow.com/questions/32643530/classpath-issue-between-jetty-maven-plugin-and-tomcat-jdbc-8-0-9-leading-to-ser -->
|
||||
<Set name="parentLoaderPriority">true</Set>
|
||||
</Configure>
|
|
@ -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
|
|
@ -8,14 +8,14 @@
|
|||
<div class="container">
|
||||
<div class="navbar-header">
|
||||
<a class="navbar-brand" href="<spring:url value="/" htmlEscape="true" />"><span></span></a>
|
||||
<button type="button" class="navbar-toggle" data-toggle="collapse">
|
||||
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#main-navbar">
|
||||
<span class="sr-only"><os-p>Toggle navigation</os-p></span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="navbar-collapse collapse">
|
||||
<div class="navbar-collapse collapse" id="main-navbar">
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
|
||||
<petclinic:menuItem active="${name eq 'home'}" url="/" title="home page">
|
||||
|
|
|
@ -1,127 +0,0 @@
|
|||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://java.sun.com/xml/ns/javaee"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
|
||||
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
|
||||
version="3.0" metadata-complete="true">
|
||||
|
||||
<display-name>Spring PetClinic</display-name>
|
||||
<description>Spring PetClinic sample application</description>
|
||||
|
||||
<!-- When using Spring jpa, use the following: -->
|
||||
<context-param>
|
||||
<param-name>spring.profiles.active</param-name>
|
||||
<param-value>jpa</param-value>
|
||||
</context-param>
|
||||
|
||||
<!-- When using Spring JDBC, use the following: -->
|
||||
<!-- <context-param>
|
||||
<param-name>spring.profiles.active</param-name>
|
||||
<param-value>jdbc</param-value>
|
||||
</context-param> -->
|
||||
|
||||
<!-- the CallMonitoringAspect counts invocations on classes with @Repository on them. Classes in spring-data-jpa don't have that annotation -->
|
||||
<!-- When using Spring Data JPA, uncomment the following: -->
|
||||
<!--
|
||||
<context-param>
|
||||
<param-name>spring.profiles.active</param-name>
|
||||
<param-value>spring-data-jpa</param-value>
|
||||
</context-param>
|
||||
-->
|
||||
|
||||
<!--
|
||||
- Location of the Java configuration that defines the root application context.
|
||||
- Applied by ContextLoaderListener.
|
||||
-->
|
||||
<context-param>
|
||||
<param-name>contextClass</param-name>
|
||||
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
|
||||
</context-param>
|
||||
<context-param>
|
||||
<param-name>contextConfigLocation</param-name>
|
||||
<param-value>org.springframework.samples.petclinic.config.RootApplicationContextConfig</param-value>
|
||||
</context-param>
|
||||
|
||||
|
||||
<listener>
|
||||
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
|
||||
</listener>
|
||||
|
||||
<!--
|
||||
- Servlet that dispatches request to registered handlers (Controller implementations).
|
||||
-->
|
||||
<servlet>
|
||||
<servlet-name>petclinic</servlet-name>
|
||||
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
|
||||
<init-param>
|
||||
<param-name>contextClass</param-name>
|
||||
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>contextConfigLocation</param-name>
|
||||
<param-value>org.springframework.samples.petclinic.config.MvcCoreConfig</param-value>
|
||||
</init-param>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>petclinic</servlet-name>
|
||||
<url-pattern>/</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<!-- Dandelion servlet definition and mapping -->
|
||||
<servlet>
|
||||
<servlet-name>dandelionServlet</servlet-name>
|
||||
<servlet-class>com.github.dandelion.core.web.DandelionServlet</servlet-class>
|
||||
<load-on-startup>2</load-on-startup>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>dandelionServlet</servlet-name>
|
||||
<url-pattern>/dandelion-assets/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<!-- used to provide the ability to enter Chinese characters inside the Owner Form -->
|
||||
<filter>
|
||||
<filter-name>encodingFilter</filter-name>
|
||||
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
|
||||
<init-param>
|
||||
<param-name>encoding</param-name>
|
||||
<param-value>UTF-8</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>forceEncoding</param-name>
|
||||
<param-value>true</param-value>
|
||||
</init-param>
|
||||
</filter>
|
||||
|
||||
<filter-mapping>
|
||||
<filter-name>encodingFilter</filter-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</filter-mapping>
|
||||
|
||||
<!-- Dandelion filter definition and mapping -->
|
||||
<filter>
|
||||
<filter-name>dandelionFilter</filter-name>
|
||||
<filter-class>com.github.dandelion.core.web.DandelionFilter</filter-class>
|
||||
</filter>
|
||||
<filter-mapping>
|
||||
<filter-name>dandelionFilter</filter-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</filter-mapping>
|
||||
|
||||
<!-- Dandelion-Datatables filter, used for basic export -->
|
||||
<filter>
|
||||
<filter-name>datatables</filter-name>
|
||||
<filter-class>com.github.dandelion.datatables.core.web.filter.DatatablesFilter</filter-class>
|
||||
</filter>
|
||||
<filter-mapping>
|
||||
<filter-name>datatables</filter-name>
|
||||
<url-pattern>/*</url-pattern>
|
||||
</filter-mapping>
|
||||
|
||||
<!-- No need for welcome-file declaration here.
|
||||
See inside spring/mvc-core-config.xml :
|
||||
<mvc:view-controller path="/" view-name="welcome" />
|
||||
-->
|
||||
|
||||
</web-app>
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue