petclinic-uncached

moved Spring config files and changed AtomView example so it

2/19/2013 5:36:23 AM

Details

.springBeans 3(+2 -1)

diff --git a/.springBeans b/.springBeans
index 91f4b0e..0c2dbe4 100644
--- a/.springBeans
+++ b/.springBeans
@@ -8,7 +8,8 @@
 	<enableImports><![CDATA[false]]></enableImports>
 	<configs>
 		<config>src/main/resources/spring/datasource-config.xml</config>
-		<config>src/main/webapp/WEB-INF/mvc-view-config.xml</config>
+		<config>src/main/resources/spring/mvc-core-config.xml</config>
+		<config>src/main/resources/spring/mvc-view-config.xml</config>
 	</configs>
 	<configSets>
 	</configSets>

pom.xml 22(+4 -18)

diff --git a/pom.xml b/pom.xml
index 8e0c712..803ccc6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -15,6 +15,8 @@
 		<aspectj.version>1.7.1</aspectj.version>
 		<hibernate.validator.version>4.2.0.Final</hibernate.validator.version>
 		<joda.version>2.0</joda.version>
+		<spring.data.jpa>1.1.0.RELEASE</spring.data.jpa>
+		<junit.version>4.10</junit.version>
 	</properties>
 	<dependencies> 
 
@@ -152,7 +154,7 @@
 		<dependency>
  			<groupId>org.springframework.data</groupId>
  			<artifactId>spring-data-jpa</artifactId>
- 			<version>1.1.0.RELEASE</version>
+ 			<version>${spring.data.jpa}</version>
 		</dependency> 
 
 		<!-- Servlet -->
@@ -207,7 +209,7 @@
 		<dependency>
 			<groupId>junit</groupId>
 			<artifactId>junit</artifactId>
-			<version>4.10</version>
+			<version>${junit.version}</version>
 			<scope>test</scope>
 		</dependency>
 		<dependency>
@@ -312,21 +314,5 @@
 				</executions>
 			</plugin>
 		</plugins>
-		<testResources>
-            <testResource>
-                <directory>src/test/resources</directory>
-                <filtering>true</filtering>
-            </testResource>
-
-            <testResource>
-                <directory>src/main/webapp/WEB-INF</directory>
-
-                <filtering>true</filtering>
-
-                <includes>
-                    <include>**/mvc-*-config.xml</include>
-                </includes>
-            </testResource>
-        </testResources>
 	</build>
 </project>
\ No newline at end of file
diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaVisitRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaVisitRepositoryImpl.java
index ff43486..3500a43 100644
--- a/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaVisitRepositoryImpl.java
+++ b/src/main/java/org/springframework/samples/petclinic/repository/jpa/JpaVisitRepositoryImpl.java
@@ -48,7 +48,6 @@ public class JpaVisitRepositoryImpl implements VisitRepository {
 	}
 
 
-	@Override
 	@SuppressWarnings("unchecked")
 	public List<Visit> findByPetId(Integer petId) { 
 		Query query = this.em.createQuery("SELECT visit FROM Visit v where v.pets.id= :id");
diff --git a/src/main/resources/log4j.xml b/src/main/resources/log4j.xml
index f865a84..f52e0fc 100755
--- a/src/main/resources/log4j.xml
+++ b/src/main/resources/log4j.xml
@@ -11,6 +11,10 @@
 		</layout>
 	</appender>
 	
+	<logger name="org.springframework.test.web">
+		<level value="trace" />
+	</logger>
+	
 	<!-- Root Logger -->
 	<root>
 		<priority value="info" /><!--
diff --git a/src/main/webapp/WEB-INF/jsp/vets/vetList.jsp b/src/main/webapp/WEB-INF/jsp/vets/vetList.jsp
index fc68b56..54bb103 100644
--- a/src/main/webapp/WEB-INF/jsp/vets/vetList.jsp
+++ b/src/main/webapp/WEB-INF/jsp/vets/vetList.jsp
@@ -40,6 +40,9 @@
 			    <td>
 			      <a href="<spring:url value="/vets.xml" htmlEscape="true" />">View as XML</a>
 			    </td>
+			    <td>
+			      <a href="<spring:url value="/vets.atom" htmlEscape="true" />">Subscribe to Atom feed</a>
+			    </td>
 			  </tr>
 			</table>
 	
diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml
index 2817b89..79b9bf6 100644
--- a/src/main/webapp/WEB-INF/web.xml
+++ b/src/main/webapp/WEB-INF/web.xml
@@ -38,7 +38,7 @@ id="WebApp_ID" version="2.5">
 		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
 		<init-param>
 			<param-name>contextConfigLocation</param-name>
-			<param-value>/WEB-INF/mvc-core-config.xml</param-value>
+			<param-value>classpath:spring/mvc-core-config.xml</param-value>
 		</init-param>
 		<load-on-startup>1</load-on-startup>
 	</servlet>
diff --git a/src/test/java/org/springframework/samples/petclinic/web/VisitsAtomViewTest.java b/src/test/java/org/springframework/samples/petclinic/web/VisitsAtomViewTest.java
index c785c5d..90b52e0 100644
--- a/src/test/java/org/springframework/samples/petclinic/web/VisitsAtomViewTest.java
+++ b/src/test/java/org/springframework/samples/petclinic/web/VisitsAtomViewTest.java
@@ -27,24 +27,9 @@ import java.util.Map;
 import org.joda.time.DateTime;
 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.model.Pet;
 import org.springframework.samples.petclinic.model.PetType;
 import org.springframework.samples.petclinic.model.Visit;
-import org.springframework.test.context.ActiveProfiles;
-import org.springframework.test.context.ContextConfiguration;
-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.ResultActions;
-import org.springframework.test.web.servlet.setup.MockMvcBuilders;
-
-import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; 
-import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
-import org.springframework.web.context.WebApplicationContext;
-import static org.hamcrest.Matchers.containsString;
 
 import com.sun.syndication.feed.atom.Entry;
 import com.sun.syndication.feed.atom.Feed;
@@ -53,44 +38,17 @@ import com.sun.syndication.feed.atom.Feed;
  * @author Arjen Poutsma 
  * @author Michael Isvy
  */
-@RunWith(SpringJUnit4ClassRunner.class)
-@WebAppConfiguration
-// Spring configuration files that are inside WEB-INF folder can be referenced here because they've been 
-// added to the classpath inside the Maven pom.xml file (inside <build> <testResources> ... </testResources> </build>)
-@ContextConfiguration({"classpath*:mvc-*-config.xml", "classpath*:spring/*-config.xml"})
-@ActiveProfiles("jdbc")
 public class VisitsAtomViewTest {
 
-	@Autowired
-	private WebApplicationContext webApplicationContext;
-
-	private MockMvc mockMvc;
-	
-	@Before
-	public void setup() {
-		this.mockMvc = MockMvcBuilders.webAppContextSetup(this.webApplicationContext).build();
-	}
-
-	private VisitsAtomView visitView;
+	private VetsAtomView visitView;
 
 	private Map<String, Object> model;
 
 	private Feed feed;
 
-	//@Test
-	public void getVisits() throws Exception { 
-		MediaType mediaType = MediaType.APPLICATION_ATOM_XML;
-		ResultActions actions = this.mockMvc.perform(get("/owners/7/pets/9/visits.atom").accept(mediaType));
-		actions.andExpect(status().isOk());
-		actions.andExpect(content().contentType("application/atom+xml"));
-		//actions.andExpect(content().xml("Pet ClinicService Visits"));
-		actions.andExpect(xpath("//*").string(containsString("Pet ClinicService Visits")));
-		
-	}
-
 	@Before
 	public void setUp() {
-		visitView = new VisitsAtomView();
+		visitView = new VetsAtomView();
 		PetType dog = new PetType();
 		dog.setName("dog");
 		Pet bello = new Pet();
diff --git a/src/test/java/org/springframework/samples/petclinic/web/VisitsAtomViewTestWithContainer-config.xml b/src/test/java/org/springframework/samples/petclinic/web/VisitsAtomViewTestWithContainer-config.xml
new file mode 100644
index 0000000..e0fd0ac
--- /dev/null
+++ b/src/test/java/org/springframework/samples/petclinic/web/VisitsAtomViewTestWithContainer-config.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+	- DispatcherServlet application context for PetClinic's web tier.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
+	
+	<import resource="classpath:spring/dao-config.xml"/>
+	<import resource="classpath:spring/mvc-core-config.xml"/>
+
+</beans>
diff --git a/src/test/java/org/springframework/samples/petclinic/web/VisitsAtomViewWithContainerTest.java b/src/test/java/org/springframework/samples/petclinic/web/VisitsAtomViewWithContainerTest.java
new file mode 100644
index 0000000..1cfcdcf
--- /dev/null
+++ b/src/test/java/org/springframework/samples/petclinic/web/VisitsAtomViewWithContainerTest.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2002-2009 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.web;
+
+import static org.hamcrest.Matchers.containsString;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.xpath;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.MediaType;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.ContextConfiguration;
+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.ResultActions;
+import org.springframework.test.web.servlet.setup.MockMvcBuilders;
+import org.springframework.web.context.WebApplicationContext;
+
+/**
+ * @author Arjen Poutsma 
+ * @author Michael Isvy
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@WebAppConfiguration
+// Spring configuration files that are inside WEB-INF folder can be referenced here because they've been 
+// added to the classpath inside the Maven pom.xml file (inside <build> <testResources> ... </testResources> </build>)
+@ContextConfiguration("VisitsAtomViewTestWithContainer-config.xml")
+@ActiveProfiles("jdbc")
+public class VisitsAtomViewWithContainerTest {
+
+	@Autowired
+	private WebApplicationContext webApplicationContext;
+
+	private MockMvc mockMvc;
+	
+	@Before
+	public void setup() {
+		this.mockMvc = MockMvcBuilders.webAppContextSetup(this.webApplicationContext).build();
+	}
+
+	@Test
+	public void getVisits() throws Exception { 
+		MediaType mediaType = MediaType.APPLICATION_ATOM_XML;
+		ResultActions actions = this.mockMvc.perform(get("/vets.atom"));
+		actions.andExpect(status().isOk());
+		actions.andExpect(xpath("//*").string(containsString("Pet ClinicService Visits")));
+		actions.andExpect(content().contentType("application/atom+xml"));
+		
+	}
+}