List of usage examples for org.springframework.mock.web MockHttpServletResponse MockHttpServletResponse
MockHttpServletResponse
From source file:com.gopivotal.cla.security.AdminEmailDomainFilterTest.java
@Test public void attemptAuthentication() throws IOException, ServletException { Emails emails = new Emails(); when(this.gitHubClient.getEmails()).thenReturn(emails); emails.add(new Email("email@test.domain", false, true)); this.filter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockFilterChain()); }
From source file:fr.mby.portal.coreimpl.EndToEndTest.java
/** * End to end test.//from ww w. ja v a 2 s . c o m * * @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: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:org.terasoluna.gfw.security.web.redirect.RedirectAuthenticationHandlerTest.java
@Before public void setUp() throws Exception { request = new MockHttpServletRequest(); request.setContextPath("/foo"); response = new MockHttpServletResponse(); auth = mock(Authentication.class); }
From source file:de.otto.jsonhome.spring.SpringControllerTest.java
@Test @SuppressWarnings("unchecked") public void shouldFindJsonHomeWithAspects() { final MockHttpServletResponse response = new MockHttpServletResponse(); final Map<String, ?> json = jsonHomeController.getAsApplicationJson(response); final Map<String, Map<String, ?>> resources = (Map<String, Map<String, ?>>) json.get("resources"); assertNotNull(resources);/*from w w w.j av a 2 s.c o m*/ final Map<String, ?> fooResource = resources.get("http://specs.example.org/rel/foo"); assertNotNull(fooResource); final Map<String, String> hrefVars = (Map<String, String>) fooResource.get("href-vars"); assertEquals(hrefVars.get("fooId"), "http://specs.example.org/rel/foo#fooId"); assertEquals(fooResource.get("href-template"), "http://example.org/{fooId}"); }
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:com.amashchenko.struts2.pdfstream.SimpleServletResponseWrapperTest.java
/** * Tests writing to output stream.//w ww .java2s .c o m * * @throws Exception */ @Test public void testWritingToOutputStream() throws Exception { MockHttpServletResponse response = new MockHttpServletResponse(); SimpleServletResponseWrapper responseWrapper = new SimpleServletResponseWrapper(response); Assert.assertNotNull(responseWrapper); final String expected = "Testing wrapper. ? . 🀰🀱🀲"; // write to output stream responseWrapper.getOutputStream().write(expected.getBytes()); final String actual = responseWrapper.toString(); Assert.assertEquals(expected, actual); }
From source file:com.hp.autonomy.frontend.find.hod.view.HodViewControllerTest.java
@Override @Before//w ww .j a v a2s . co m public void setUp() { viewServerService = hodViewService; viewController = new HodViewController(viewServerService, controllerUtils); response = new MockHttpServletResponse(); super.setUp(); }
From source file:com.alexshabanov.springrestapi.restapitest.DefaultRestTestSupport.java
@Override public final MockHttpServletResponse handle(HttpServletRequest request) { final MockHttpServletResponse response = new MockHttpServletResponse(); Object handler = null;//from w w w. j a v a 2 s. co m try { // delegates request processing to the spring facilities for (HandlerMapping mapping : context.getBeansOfType(HandlerMapping.class).values()) { final HandlerExecutionChain chain = mapping.getHandler(request); if (chain == null) { continue; } handler = chain.getHandler(); if (handler != null) { handlerAdapter.handle(request, response, chain.getHandler()); break; } } if (handler == null) { throw new AssertionError("Can't handle request in the current context"); } } catch (Exception e) { if (handleException(e, request, response, handler)) { return response; } // exception mapping has not been found - propagate error outside the method boundaries throw new AssertionError(e); } return response; }
From source file:fr.keemto.web.ControllerTestCase.java
@Before public void setUp() throws Exception { initMocks(this); request = new MockHttpServletRequest(); response = new MockHttpServletResponse(); handlerAdapter = new AnnotationMethodHandlerAdapter(); addJackonMessageConverter();/*from w w w. j a v a2 s . co m*/ request.setAttribute(HandlerMapping.INTROSPECT_TYPE_LEVEL_MAPPING, true); }