diff --git a/.springBeans b/.springBeans index 1dea40264..91f4b0eb1 100644 --- a/.springBeans +++ b/.springBeans @@ -7,26 +7,9 @@ - src/main/webapp/WEB-INF/mvc-core-config.xml - src/main/webapp/WEB-INF/mvc-view-config.xml - src/main/resources/spring/dao-config.xml src/main/resources/spring/datasource-config.xml - src/main/resources/spring/tools-config.xml + src/main/webapp/WEB-INF/mvc-view-config.xml - - - true - false - - src/main/webapp/WEB-INF/mvc-core-config.xml - src/main/webapp/WEB-INF/mvc-view-config.xml - src/main/resources/spring/dao-config.xml - src/main/resources/spring/datasource-config.xml - src/main/resources/spring/tools-config.xml - - - - diff --git a/pom.xml b/pom.xml index a6d787106..8e0c71261 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ war 1.0.0-SNAPSHOT - 3.2.0.RELEASE + 3.2.1.RELEASE 1.7.0 1.2.17 4.1.4.Final @@ -51,6 +51,20 @@ spring-webmvc ${spring.version} + + + + org.springframework + spring-web + ${spring.version} + + + + + org.springframework + spring-jdbc + ${spring.version} + @@ -234,6 +248,13 @@ 1.1 + + + org.hamcrest + hamcrest-all + 1.3 + + @@ -291,5 +312,21 @@ + + + src/test/resources + true + + + + src/main/webapp/WEB-INF + + true + + + **/mvc-*-config.xml + + + \ No newline at end of file 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 6c79082f5..7e81a8c05 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,67 @@ 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; /** - * @author Arjen Poutsma + * @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 ... ) +@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 Map 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(); @@ -55,14 +98,14 @@ public class VisitsAtomViewTest { bello.setType(dog); Visit belloVisit = new Visit(); belloVisit.setPet(bello); - belloVisit.setDate(new DateTime(2009, 1, 1,1,1)); + belloVisit.setDate(new DateTime(2009, 1, 1, 1, 1)); belloVisit.setDescription("Bello visit"); Pet wodan = new Pet(); wodan.setName("Wodan"); wodan.setType(dog); Visit wodanVisit = new Visit(); wodanVisit.setPet(wodan); - wodanVisit.setDate(new DateTime(2009, 1, 2,1,1)); + wodanVisit.setDate(new DateTime(2009, 1, 2, 1, 1)); wodanVisit.setDescription("Wodan visit"); List visits = new ArrayList(); visits.add(belloVisit); @@ -74,13 +117,14 @@ public class VisitsAtomViewTest { } + @Test public void buildFeedMetadata() { visitView.buildFeedMetadata(model, feed, null); assertNotNull("No id set", feed.getId()); assertNotNull("No title set", feed.getTitle()); - assertEquals("Invalid update set", new DateTime(2009, 1, 2,1,1).toDate(), feed.getUpdated()); + assertEquals("Invalid update set", new DateTime(2009, 1, 2, 1, 1).toDate(), feed.getUpdated()); } @Test