mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-15 12:25:50 +00:00
Update vetsXml test using xpath
This commit is contained in:
parent
647985cdaf
commit
4c722465d8
2 changed files with 16 additions and 16 deletions
|
@ -41,7 +41,7 @@ public class VetController {
|
|||
this.clinicService = clinicService;
|
||||
}
|
||||
|
||||
@RequestMapping(value = {"/vets.xml", "/vets.html"})
|
||||
@RequestMapping(value = { "/vets.html"})
|
||||
public String showVetList(Map<String, Object> model) {
|
||||
// Here we are returning an object of type 'Vets' rather than a collection of Vet objects
|
||||
// so it is simpler for Object-Xml mapping
|
||||
|
@ -51,7 +51,7 @@ public class VetController {
|
|||
return "vets/vetList";
|
||||
}
|
||||
|
||||
@RequestMapping("/vets.json")
|
||||
@RequestMapping(value = { "/vets.json", "/vets.xml"})
|
||||
public
|
||||
@ResponseBody
|
||||
Vets showResourcesVetList() {
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
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;
|
||||
|
@ -16,6 +13,10 @@ 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.hamcrest.xml.HasXPath.hasXPath;
|
||||
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}
|
||||
*/
|
||||
|
@ -35,14 +36,12 @@ public class VetControllerTests {
|
|||
this.mockMvc = MockMvcBuilders.standaloneSetup(vetController).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShowVetListXml() throws Exception {
|
||||
testShowVetList("/vets.xml");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShowVetListHtml() throws Exception {
|
||||
testShowVetList("/vets.html");
|
||||
mockMvc.perform(get("/vets.html"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(model().attributeExists("vets"))
|
||||
.andExpect(view().name("vets/vetList"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -53,12 +52,13 @@ public class VetControllerTests {
|
|||
.andExpect(jsonPath("$.vetList[0].id").value(1));
|
||||
}
|
||||
|
||||
private void testShowVetList(String url) throws Exception {
|
||||
mockMvc.perform(get(url))
|
||||
@Test
|
||||
public void testShowVetListXml() throws Exception {
|
||||
mockMvc.perform(get("/vets.xml").accept(MediaType.APPLICATION_XML))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(model().attributeExists("vets"))
|
||||
.andExpect(view().name("vets/vetList"));
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_XML_VALUE))
|
||||
.andExpect(content().node(hasXPath("/vets/vetList[id=1]/id")));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue