List of usage examples for org.springframework.mock.web MockHttpServletRequest MockHttpServletRequest
public MockHttpServletRequest(@Nullable String method, @Nullable String requestURI)
From source file:nl.surfnet.coin.api.AccessConfirmationControllerTest.java
@Test public void test() { MockHttpServletRequest req = new MockHttpServletRequest("GET", "/foobar123"); String url = AccessConfirmationController.getUrlWithLanguageParam(req, "tr"); assertThat(url, IsEqual.equalTo("?lang=tr")); // see that a current lang-parameter is replaced req.setQueryString("lang=abc&def=123"); url = AccessConfirmationController.getUrlWithLanguageParam(req, "tr"); assertThat(url, IsEqual.equalTo("?def=123&lang=tr")); // see that a not-lang-parameter is not touched req.setQueryString("notlang=abc"); url = AccessConfirmationController.getUrlWithLanguageParam(req, "tr"); assertThat(url, IsEqual.equalTo("?notlang=abc&lang=tr")); }
From source file:org.ngrinder.script.controller.MyHttpServletRequestWrapperTest.java
@Test public void testHandleRequest() { HttpServletRequest req = new MockHttpServletRequest("GET", "http://127.0.0.1:80/hello/svn/admin/"); wrapper = new MyHttpServletRequestWrapper(req) { public String getRequestURI() { return "/hello/svn/admin/"; }/*w ww . ja v a 2s .c om*/ @Override public String getContextPath() { return "/hello"; } }; String path = wrapper.getPathInfo(); assertThat(path, is("/admin/%ED%95%9C%EA%B8%80")); }
From source file:org.fedoracommons.funapi.UnapiServletTest.java
@Test public void testFoo() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest("GET", "/main.app"); request.setSession(new MockHttpSession(null)); request.addParameter("choice", "expanded"); request.addParameter("contextMenu", "left"); HttpServletResponse response = new MockHttpServletResponse(); response.hashCode();/*from ww w . ja va 2 s. co m*/ }
From source file:de.otto.jsonhome.controller.DocControllerTest.java
@Test public void shouldReturnMarkdown() throws IOException { // given//from w w w . j a v a 2 s .com final DocController controller = new DocController(); controller.setRootDir(new ClassPathResource("/test/**")); // when final String markdown = controller.getMarkdown(new MockHttpServletRequest("GET", "/test/doc/test.md")); // then assertTrue(markdown.startsWith("Test")); }
From source file:com.navercorp.lucy.security.xss.servletfilter.XssEscapeServletFilterWrapperTest.java
@Test public void testGetMethodGetParameter() { request = new MockHttpServletRequest("GET", "/notExistUrl.do"); request.addParameter("title", "<b>Text</b>"); request.addParameter("globalParameter", "<b>Text</b>"); wrapper = new XssEscapeServletFilterWrapper(request, filter); assertThat(wrapper.getParameter("title"), is("<b>Text</b>")); assertThat(wrapper.getParameter("globalParameter"), is("<b>Text</b>")); request = new MockHttpServletRequest("GET", "/url1.do"); request.addParameter("title", "<b>Text</b>"); request.addParameter("mode", "<script>Text</script>"); request.addParameter("globalParameter", "<script>Text</script>"); wrapper = new XssEscapeServletFilterWrapper(request, filter); assertThat(wrapper.getParameter("title"), is("<b>Text</b>")); assertThat(wrapper.getParameter("mode"), is("<script>Text</script>")); assertThat(wrapper.getParameter("globalParameter"), is("<script>Text</script>")); }
From source file:org.openmrs.scheduler.web.controller.SchedulerFormTest.java
/** * See TRUNK-3970: Error when adding a task in version 1.9.3 * https://tickets.openmrs.org/browse/TRUNK-3970 *///www.ja v a 2s . c o m @Test public void addANewTaskShouldNotError() throws Exception { HttpServletRequest request = new MockHttpServletRequest("GET", "/openmrs/admin/scheduler/scheduler.form"); ModelAndView mav = controller.handleRequest(request, new MockHttpServletResponse()); assertNotNull(mav); }
From source file:org.openmrs.web.servlet.LoginServletTest.java
/** * The servlet should send the user back to the login box if the user enters the wrong username * or password./*from w ww. ja v a 2 s .c o m*/ * * @throws Exception */ @Test public void shouldRedirectBackToLoginScreenOnBadUsernameAndPassword() throws Exception { LoginServlet loginServlet = new LoginServlet(); MockHttpServletRequest request = new MockHttpServletRequest("POST", "/loginServlet"); request.setContextPath("/somecontextpath"); MockHttpServletResponse response = new MockHttpServletResponse(); request.setParameter("uname", "some wrong username"); request.setParameter("pw", "some wrong password"); loginServlet.service(request, response); Assert.assertEquals("/somecontextpath/login.htm", response.getRedirectedUrl()); }
From source file:com.nominanuda.web.http.ServletHelperTest.java
@Test public void testGetRequestLineURI() { MockHttpServletRequest req = new MockHttpServletRequest("GET", "/foo%20bar?z=+1"); String reqLineURI = servletHelper.getRequestLineURI(req, false); System.err.println(reqLineURI); }
From source file:org.openmrs.module.reportingcompatibility.web.controller.analysis.CohortBuilderControllerTest.java
@Test public void shouldSortDrugs() throws Exception { executeDataSet("org/openmrs/include/drugs.xml"); CohortBuilderController controller = (CohortBuilderController) applicationContext .getBean("cohortBuilderController"); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/openmrs/cohortBuilder.list"); request.setSession(new MockHttpSession(null)); HttpServletResponse response = new MockHttpServletResponse(); controller.handleRequest(request, response); }
From source file:net.eusashead.hateoas.response.impl.DeleteResponseBuilderImplTest.java
@Before public void before() { request = new MockHttpServletRequest("DELETE", "http://localhost/resource/1"); builder = new DeleteResponseBuilderImpl(request); }