Created
June 11, 2013 02:20
-
-
Save keesun/5754095 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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