List of usage examples for org.springframework.mock.web MockHttpServletRequest setContextPath
public void setContextPath(String contextPath)
From source file:org.hdiv.urlProcessor.LinkUrlProcessorTest.java
public void testProcessActionRelative3() { MockHttpServletRequest request = (MockHttpServletRequest) HDIVUtil.getHttpServletRequest(); request.setContextPath("/path"); String url = "../testAction.do"; String result = this.linkUrlProcessor.processUrl(request, url); assertTrue(result.equals("../testAction.do")); }
From source file:org.hdiv.urlProcessor.LinkUrlProcessorTest.java
public void testProcessAbsoluteExternalUrlWithContextPath() { MockHttpServletRequest request = (MockHttpServletRequest) HDIVUtil.getHttpServletRequest(); request.setContextPath("/path"); String url = "http://www.google.com"; String result = this.linkUrlProcessor.processUrl(request, url); assertEquals("http://www.google.com", result); }
From source file:org.hdiv.urlProcessor.LinkUrlProcessorTest.java
public void testProcessAbsoluteInternalUrlWithContextPath() { MockHttpServletRequest request = (MockHttpServletRequest) HDIVUtil.getHttpServletRequest(); request.setContextPath("/path"); String url = "http://localhost:8080/path/sample.do"; String result = this.linkUrlProcessor.processUrl(request, url); assertTrue(result.startsWith("http://localhost:8080/path/sample.do?_HDIV_STATE_=")); }
From source file:org.hdiv.urlProcessor.LinkUrlProcessorTest.java
public void testProcessAbsoluteInternalUrlWithContextPath2() { MockHttpServletRequest request = (MockHttpServletRequest) HDIVUtil.getHttpServletRequest(); request.setContextPath("/diferentPath"); String url = "http://localhost:8080/path/sample.do"; String result = this.linkUrlProcessor.processUrl(request, url); assertTrue(result.startsWith("http://localhost:8080/path/sample.do")); }
From source file:com.amashchenko.struts2.pdfstream.PdfStreamResultTest.java
@Test public void testFindBaseUrl() throws Exception { Assert.assertNotNull(pdfStreamResult); MockHttpServletRequest request = new MockHttpServletRequest(); request.setLocalName("localhost"); request.setRequestURI("/contextPath/requestURI"); request.setQueryString("queryString"); request.setContextPath("/contextPath"); final String baseUrl = pdfStreamResult.findBaseUrl(request); Assert.assertEquals("http://localhost/contextPath/", baseUrl); }
From source file:org.openmrs.module.referenceapplication.page.controller.LoginPageControllerTest.java
/** * @see LoginPageController#get(PageModel,UiUtils,PageRequest,String,LocationService,AppFrameworkService) * @verifies not set the referer as the redirectUrl in the page model if referer URL is outside context path *///www . j a v a 2s. co m @Test public void get_shouldNotSetTheRefererAsTheRedirectUrlInThePageModelIfRefererUrlIsOutsideContextPath() throws Exception { when(Context.isAuthenticated()).thenReturn(false); String refererUrl = "http://openmrs.org/demo/"; MockHttpServletRequest request = new MockHttpServletRequest(); request.setContextPath(TEST_CONTEXT_PATH); request.addHeader("Referer", refererUrl); PageModel pageModel = new PageModel(); new LoginPageController().get(pageModel, uiUtils, createPageRequest(request, null), null, null, appFrameworkService); assertEquals("", pageModel.get(REQUEST_PARAMETER_NAME_REDIRECT_URL)); }
From source file:org.openmrs.module.referenceapplication.page.controller.LoginPageControllerTest.java
/** * @see LoginPageController#get(org.openmrs.ui.framework.page.PageModel, * org.openmrs.ui.framework.UiUtils, org.openmrs.ui.framework.page.PageRequest, String, * org.openmrs.api.LocationService, * org.openmrs.module.appframework.service.AppFrameworkService) *//*ww w.jav a 2 s. c o m*/ @Test @Verifies(value = "should set redirectUrl in the page model if any was specified in the request", method = "get(PageModel,UiUtils,PageRequest)") public void get_shouldSetRedirectUrlInThePageModelIfAnyWasSpecifiedInTheRequest() throws Exception { when(Context.isAuthenticated()).thenReturn(false); String redirectUrl = TEST_CONTEXT_PATH + "/referenceapplication/patient.page"; MockHttpServletRequest request = new MockHttpServletRequest(); request.setContextPath(TEST_CONTEXT_PATH); request.addParameter(REQUEST_PARAMETER_NAME_REDIRECT_URL, redirectUrl); PageModel pageModel = new PageModel(); new LoginPageController().get(pageModel, uiUtils, createPageRequest(request, null), null, null, appFrameworkService); assertEquals(redirectUrl, pageModel.get(REQUEST_PARAMETER_NAME_REDIRECT_URL)); }
From source file:org.openmrs.module.referenceapplication.page.controller.LoginPageControllerTest.java
/** * @see LoginPageController#get(org.openmrs.ui.framework.page.PageModel, * org.openmrs.ui.framework.UiUtils, org.openmrs.ui.framework.page.PageRequest, String, * org.openmrs.api.LocationService, * org.openmrs.module.appframework.service.AppFrameworkService) *//*from www . j av a2 s.c o m*/ @Test @Verifies(value = "should set the referer as the redirectUrl in the page model if no redirect param exists", method = "get(PageModel,UiUtils,PageRequest)") public void get_shouldSetTheRefererAsTheRedirectUrlInThePageModelIfNoRedirectParamExists() throws Exception { when(Context.isAuthenticated()).thenReturn(false); String refererUrl = TEST_CONTEXT_PATH + "/referenceapplication/patient.page"; MockHttpServletRequest request = new MockHttpServletRequest(); request.setContextPath(TEST_CONTEXT_PATH); request.addHeader("Referer", refererUrl); PageModel pageModel = new PageModel(); new LoginPageController().get(pageModel, uiUtils, createPageRequest(request, null), null, null, appFrameworkService); assertEquals(refererUrl, pageModel.get(REQUEST_PARAMETER_NAME_REDIRECT_URL)); }
From source file:org.openmrs.module.referenceapplication.page.controller.LoginPageControllerTest.java
/** * @see LoginPageController#get(PageModel,UiUtils,PageRequest,String,LocationService,AppFrameworkService) * @verifies set the referer as the redirectUrl in the page model if referer URL is within context path *///from ww w. j av a 2 s . co m @Test public void get_shouldSetTheRefererAsTheRedirectUrlInThePageModelIfRefererUrlIsWithinContextPath() throws Exception { when(Context.isAuthenticated()).thenReturn(false); String redirectUrl = TEST_CONTEXT_PATH + "/demo/"; String refererUrl = "http://openmrs.org" + redirectUrl; MockHttpServletRequest request = new MockHttpServletRequest(); request.setContextPath(TEST_CONTEXT_PATH); request.addHeader("Referer", refererUrl); PageModel pageModel = new PageModel(); new LoginPageController().get(pageModel, uiUtils, createPageRequest(request, null), null, null, appFrameworkService); assertEquals(redirectUrl, pageModel.get(REQUEST_PARAMETER_NAME_REDIRECT_URL)); }
From source file:org.openmrs.module.referenceapplication.page.controller.LoginPageControllerTest.java
/** * @see LoginPageController#post(String, String, Integer, org.openmrs.api.LocationService, * org.openmrs.ui.framework.UiUtils, org.openmrs.ui.framework.page.PageRequest, * org.openmrs.module.appui.UiSessionContext) *///from w ww . jav a2 s . c om @Test @Ignore @Verifies(value = "should redirect the user to the home page if the redirectUrl is the login page", method = "post(String,String,UiUtils,PageRequest)") public void post_shouldRedirectTheUserToTheHomePageIfTheRedirectUrlIsTheLoginPage() throws Exception { setupMocksForSuccessfulAuthentication(true); final String redirectUrl = uiUtils.pageLink(ReferenceApplicationConstants.MODULE_ID, "login"); final String homeRedirect = "redirect:" + uiUtils.pageLink(ReferenceApplicationConstants.MODULE_ID, "home"); MockHttpServletRequest request = new MockHttpServletRequest(); request.setContextPath("/openmrs"); request.setParameter(REQUEST_PARAMETER_NAME_REDIRECT_URL, redirectUrl); PageRequest pageRequest = createPageRequest(request, null); assertEquals(homeRedirect, new LoginPageController().post(USERNAME, PASSWORD, SESSION_LOCATION_ID, locationService, uiUtils, pageRequest, sessionContext)); }