Skip to content

Instantly share code, notes, and snippets.

@keesun
Created June 11, 2013 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keesun/5754095 to your computer and use it in GitHub Desktop.
Save keesun/5754095 to your computer and use it in GitHub Desktop.
package sandbox.requestmapping;
import org.junit.Test;
import org.springframework.stereotype.Controller;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
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;
/**
* @author Keesun Baik
*/
public class TestRequestMappings {
@Test
public void mockMvc() throws Exception {
MockMvc mockMvc = MockMvcBuilders
.standaloneSetup(new ProductController(), new ServerController())
.build();
mockMvc.perform(get("/").param("action", "getServerInstanceList"))
.andExpect(status().isOk())
.andExpect(content().string("getServerInstanceList"));
mockMvc.perform(get("/").param("action", "createServerInstances"))
.andExpect(status().isOk())
.andExpect(content().string("createServerInstances"));
mockMvc.perform(get("/").param("action", "getServerImageProductList"))
.andExpect(status().isOk())
.andExpect(content().string("getServerImageProductList"));
}
@Controller
private static class ServerController {
@RequestMapping(value = "/*", params = {"action=getServerInstanceList"})
public @ResponseBody
String getServerInstanceList() {
return "getServerInstanceList";
}
@RequestMapping(value = "/*", params = {"action=createServerInstances"})
public @ResponseBody String createServerInstances() {
return "createServerInstances";
}
}
@Controller
private static class ProductController {
@RequestMapping(value = "/*", params = {"action=getServerImageProductList"})
public @ResponseBody String getServerImageProductList() {
return "getServerImageProductList";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment