List of usage examples for org.springframework.mock.web MockHttpServletRequest MockHttpServletRequest
public MockHttpServletRequest()
From source file:fr.mby.portal.coreimpl.EndToEndTest.java
/** * End to end test.//from w w w. j a va 2 s. c om * * @throws Exception */ @Test public void testDispatch() throws Exception { final MockHttpServletRequest request = new MockHttpServletRequest(); final MockHttpServletResponse response = new MockHttpServletResponse(); this.sessionManager.initPortalSession(request, response); this.userActionDispatcher.dispatch(request, response); // Test headers final String actionHeader1 = response.getHeader("actionProp1"); final String renderHeader1 = response.getHeader("renderProp1"); Assert.assertEquals("Bad action header value !", "actionVal1", actionHeader1); Assert.assertEquals("Bad render header value !", "renderVal1", renderHeader1); final Cookie actionCookie1 = response.getCookie("actionCookie1"); final Cookie renderCookie1 = response.getCookie("renderCookie1"); Assert.assertNotNull("Action cookie is null !", actionCookie1); Assert.assertNotNull("Render cookie is null !", renderCookie1); Assert.assertEquals("Bad action cookie value !", "actionCookieVal1", actionCookie1.getValue()); Assert.assertEquals("Bad render cookie value !", "renderCookieVal1", renderCookie1.getValue()); // Test response response.flushBuffer(); final String reponseOutputStream = response.getContentAsString(); Assert.assertEquals("Bad response output stream !", "<html><body><h1>Test</h1></body></html>", reponseOutputStream); }
From source file:org.sventon.web.filter.ConfigAuthorizationFilterTest.java
@Test public void testDoFilterInternalApplicationNotConfigured() throws Exception { final ConfigAuthorizationFilter filter = new ConfigAuthorizationFilter(application); final HttpServletRequest request = new MockHttpServletRequest(); final HttpServletResponse response = EasyMock.createMock(HttpServletResponse.class); final MockFilterChain filterChain = new MockFilterChain(); application.setConfigured(false);//from ww w. ja va 2s . com EasyMock.replay(response); filter.doFilterInternal(request, response, filterChain); EasyMock.verify(response); assertSame(request, filterChain.getRequest()); assertSame(response, filterChain.getResponse()); }
From source file:org.jasig.cas.web.NoSuchFlowExecutionExceptionResolverTests.java
public void testNullPointerException() { assertNull(this.resolver.resolveException(new MockHttpServletRequest(), new MockHttpServletResponse(), null, new NullPointerException())); }
From source file:org.openmrs.web.controller.encounter.EncounterRoleFormControllerTest.java
/** * @verifies save a new encounter role object * @see EncounterRoleFormController#save(javax.servlet.http.HttpSession, org.openmrs.EncounterRole, org.springframework.validation.BindingResult) *//*www . jav a 2 s . c o m*/ @Test public void saveEncounterRole_shouldSaveANewEncounterRoleObject() throws Exception { EncounterRoleFormController controller = new EncounterRoleFormController(); MockHttpServletRequest request = new MockHttpServletRequest(); HttpSession session = request.getSession(); EncounterRole encounterRole = new EncounterRole(); encounterRole.setName("attending physician"); encounterRole.setDescription("person in charge"); BindException errors = new BindException(encounterRole, "encounterRole"); controller.save(session, encounterRole, errors); Assert.assertNotNull(encounterRole.getId()); }
From source file:be.dnsbelgium.rdap.spring.security.RDAPErrorHandlerTest.java
@Test public void testHandlerNullDescription() throws IOException, ServletException { RDAPErrorHandler errorHandler = new RDAPErrorHandler(); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); RDAPErrorException exception = new RDAPErrorException(499, "title", (String[]) null); errorHandler.handle(request, response, exception); Assert.assertEquals("{\"errorCode\":499,\"title\":\"title\"}", response.getContentAsString()); }
From source file:fr.xebia.audit.AuditAspectTest.java
@Before public void before() { MockHttpServletRequest request = new MockHttpServletRequest(); request.setRemoteAddr("10.0.0.1"); WebAuthenticationDetails details = new WebAuthenticationDetails(request); UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken("ze-principal", "ze-credentials"); authentication.setDetails(details);// w ww. jav a2 s. co m SecurityContextHolder.getContext().setAuthentication(authentication); }
From source file:org.jasig.cas.client.util.CasFilterTests.java
@Test public void serverName() { final String serverNameWithoutSlash = "http://www.cnn.com"; final String serverNameWithSlash = "http://www.cnn.com/"; final TestCasFilter testCasFilter = new TestCasFilter(); testCasFilter.setServerName(serverNameWithoutSlash); final MockHttpServletRequest request = new MockHttpServletRequest(); final MockHttpServletResponse response = new MockHttpServletResponse(); request.setContextPath("/cas"); request.setRequestURI("/cas/test"); assertTrue(testCasFilter.constructServiceUrl(request, response).startsWith("http://www.cnn.com/cas/test")); testCasFilter.setServerName(serverNameWithSlash); assertTrue(testCasFilter.constructServiceUrl(request, response).startsWith("http://www.cnn.com/cas/test")); }
From source file:org.terasoluna.gfw.security.web.logging.UserIdMDCPutFilterTest.java
@Before public void setUp() throws Exception { request = new MockHttpServletRequest(); response = new MockHttpServletResponse(); }
From source file:ar.com.zauber.commons.web.proxy.impl.MutableURLRequestMapperTest.java
/** @throws MalformedURLException on error */ public final void testChange() throws MalformedURLException { final MutableURLRequestMapper c = new MutableURLRequestMapper( new InmutableURLRequestMapper(new InmutableURLResult(new URL("http://localhost")))); assertEquals(new URL("http://localhost"), c.getProxiedURLFromRequest(new MockHttpServletRequest()).getURL()); c.setTarget(new InmutableURLRequestMapper(new InmutableURLResult(new URL("http://127.0.0.1")))); assertEquals(new URL("http://127.0.0.1"), c.getProxiedURLFromRequest(new MockHttpServletRequest()).getURL()); }
From source file:ai.api.twilio.test.SmsServletTest.java
@Before public void setUp() { servlet = new TwilioSmsServlet(); request = new MockHttpServletRequest(); response = new MockHttpServletResponse(); }