List of usage examples for org.springframework.mock.web MockHttpServletResponse MockHttpServletResponse
MockHttpServletResponse
From source file:org.terasoluna.gfw.web.logging.mdc.MDCClearFilterTest.java
/** * setup all test case./*from w w w .j a va 2 s .c o m*/ */ @Before public void setup() { // create test target. this.testTarget = new MDCClearFilter(); // setup mock. this.mockRequest = new MockHttpServletRequest(); this.mockResponse = new MockHttpServletResponse(); this.mockFilterChain = spy(new MockFilterChainForMDCClearFilterTest()); // setup MDC. MDC.clear(); }
From source file:org.raxa.module.raxacore.web.v1_0.controller.PatientListControllerTest.java
@Before public void before() throws Exception { executeDataSet(MODULE_TEST_DATA_XML); this.request = new MockHttpServletRequest(); this.response = new MockHttpServletResponse(); this.controller = new PatientListController(); this.service = Context.getService(PatientListService.class); }
From source file:com.doitnext.http.router.responsehandlers.DefaultErrorHandlerTest.java
@Test public void testHandleResponseYes() throws IOException { DefaultErrorHandler h = new DefaultErrorHandler(); Exception responseData = new IllegalArgumentException("Hidey Ho!!", new NumberFormatException("3r3")); MockHttpServletResponse response = new MockHttpServletResponse(); boolean handled = h.handleResponse(null, null, response, responseData); Assert.assertTrue(handled);/*from w w w . j av a 2 s.c o m*/ String content = response.getContentAsString(); String expectedContent = IOUtils.toString(this.getClass().getResourceAsStream("error1.dat"), "UTF-8"); Assert.assertEquals(expectedContent, content); }
From source file:org.jasig.cas.web.FlowExecutionExceptionResolverTests.java
@Test public void testNoSuchFlowExecutionException() { MockHttpServletRequest request = new MockHttpServletRequest(); request.setRequestURI("test"); ModelAndView model = this.resolver.resolveException(request, new MockHttpServletResponse(), null, new NoSuchFlowExecutionException(new FlowExecutionKey() { private static final long serialVersionUID = 1443616250214416520L; @Override// w w w .ja v a 2s. com public String toString() { return "test"; } @Override public boolean equals(final Object o) { return true; } @Override public int hashCode() { return 0; } }, new RuntimeException())); assertEquals(request.getRequestURI(), ((RedirectView) model.getView()).getUrl()); }
From source file:com.gu.management.manifest.ManifestReportingControllerTest.java
@Test public void shouldNotThrowExceptionWhenCodeOrViewRevisionIsNullJustLikeItWillBeOnDeveloperMachines() throws Exception { when(manifest.getRevisionNumber()).thenReturn(null); MockHttpServletResponse responseMock = new MockHttpServletResponse(); ManifestReportingServlet servlet = new ManifestReportingServlet(Arrays.asList(manifest)); servlet.doGet(null, responseMock);//from ww w .jav a 2 s.co m assertThat(responseMock.getContentType(), equalTo("text/plain")); assertThat(responseMock.getContentAsString(), equalTo("Code Manifest Information\n")); verify(manifest).reload(); }
From source file:org.craftercms.security.authentication.impl.AuthenticationRequiredHandlerImplTest.java
@Test public void testRedirectToLoginFormUrl() throws Exception { handler.setLoginFormUrl(LOGIN_FORM_URL); MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); RequestContext context = new RequestContext(request, response); handler.handle(context, new AuthenticationRequiredException("")); verify(requestCache).saveRequest(request, response); assertEquals(LOGIN_FORM_URL, response.getRedirectedUrl()); assertEquals(HttpServletResponse.SC_MOVED_TEMPORARILY, response.getStatus()); assertTrue(response.isCommitted());/*from w w w .ja va2 s . c om*/ }
From source file:org.floggy.synchronization.jme.server.SynchronizationServletTest.java
/** * DOCUMENT ME!/* ww w. jav a2s.co m*/ */ @Test public void testDoGetServletRequestServletResponseException() { MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); SynchronizationServlet servlet = new SynchronizationServlet(); try { request.setContent(getContent(Person.class)); servlet.doGet(request, response); } catch (Exception e) { Assert.assertEquals(e.getCause().getClass(), SynchronizationException.class); } }
From source file:com.gopivotal.cla.security.AdminEmailDomainFilterTest.java
@Test(expected = AccessDeniedException.class) public void attemptAuthenticationNonVerifiedEmail() throws IOException, ServletException { Emails emails = new Emails(); when(this.gitHubClient.getEmails()).thenReturn(emails); emails.add(new Email("email@test.domain", false, false)); this.filter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockFilterChain()); }
From source file:otherpackage.MyConfigurerTests.java
@Before public void setup() { request = new MockHttpServletRequest(); response = new MockHttpServletResponse(); chain = new MockFilterChain(); request.setMethod("GET"); }
From source file:org.jasig.cas.web.ProxyControllerTests.java
@Test public void testNoParams() throws Exception { assertEquals("INVALID_REQUEST", this.proxyController .handleRequestInternal(new MockHttpServletRequest(), new MockHttpServletResponse()) .getModel().get("code")); }