Example usage for org.springframework.mock.web MockHttpServletResponse getHeader

List of usage examples for org.springframework.mock.web MockHttpServletResponse getHeader

Introduction

In this page you can find the example usage for org.springframework.mock.web MockHttpServletResponse getHeader.

Prototype

@Override
@Nullable
public String getHeader(String name) 

Source Link

Document

Return the primary value for the given header as a String, if any.

Usage

From source file:eionet.webq.web.interceptor.CdrAuthorizationInterceptorTest.java

private void assertThatResponseIsBasicAuthorizationCommence(MockHttpServletResponse response) {
    assertThat(response.getHeader("WWW-Authenticate"), containsString("Basic"));
    assertThat(response.getStatus(), equalTo(HttpServletResponse.SC_UNAUTHORIZED));
}

From source file:com.liferay.document.library.webserver.test.WebServerRangeTest.java

@Test
public void testSingleRangeFirst() throws Exception {
    MockHttpServletResponse mockHttpServletResponse = testRange("bytes=0-9");

    Assert.assertEquals("10", mockHttpServletResponse.getHeader(HttpHeaders.CONTENT_LENGTH));
    Assert.assertEquals("bytes 0-9/80", mockHttpServletResponse.getHeader(HttpHeaders.CONTENT_RANGE));
    Assert.assertEquals("A123456789", mockHttpServletResponse.getContentAsString());
}

From source file:com.liferay.document.library.webserver.test.WebServerRangeTest.java

@Test
public void testSingleRangeByte() throws Exception {
    MockHttpServletResponse mockHttpServletResponse = testRange("bytes=10-10");

    Assert.assertEquals("1", mockHttpServletResponse.getHeader(HttpHeaders.CONTENT_LENGTH));
    Assert.assertEquals("bytes 10-10/80", mockHttpServletResponse.getHeader(HttpHeaders.CONTENT_RANGE));
    Assert.assertEquals("B", mockHttpServletResponse.getContentAsString());
}

From source file:com.liferay.document.library.webserver.test.WebServerRangeTest.java

@Test
public void testSingleRangeLast() throws Exception {
    MockHttpServletResponse mockHttpServletResponse = testRange("bytes=70-79");

    Assert.assertEquals("10", mockHttpServletResponse.getHeader(HttpHeaders.CONTENT_LENGTH));
    Assert.assertEquals("bytes 70-79/80", mockHttpServletResponse.getHeader(HttpHeaders.CONTENT_RANGE));
    Assert.assertArrayEquals(_UNICODE_DATA.getBytes(), mockHttpServletResponse.getContentAsByteArray());
}

From source file:com.xyxy.platform.examples.showcase.demos.web.CacheControlHeaderFilterTest.java

@Test
public void test() throws IOException, ServletException {
    MockFilterConfig config = new MockFilterConfig();
    MockFilterChain chain = new MockFilterChain();
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    config.addInitParameter("expiresSeconds", "123");

    CacheControlHeaderFilter filter = new CacheControlHeaderFilter();
    filter.init(config);/*from   w  w  w  . j  a v  a  2 s .  com*/
    filter.doFilter(request, response, chain);

    assertThat(response.getHeader("Cache-Control")).isEqualTo("private, max-age=123");
}

From source file:fr.mby.portal.coreimpl.EndToEndTest.java

/**
 * End to end test./*from   w  w w .  j  av  a  2 s. com*/
 * 
 * @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:de.fau.amos4.test.integration.EmployeeTest.java

@Test
@WithUserDetails("datev@example.com")
public void testEmployeeAsLodasFileDownload() throws Exception {
    final MockHttpServletResponse response = mockMvc.perform(get("/employee/download/text").param("id", "2"))
            .andExpect(status().isOk()).andExpect(content().contentType(MediaType.TEXT_PLAIN)).andReturn()
            .getResponse();//from  www .  j  av  a  2  s .co  m

    final String contentDisp = response.getHeader("Content-Disposition");
    Assert.assertNotNull("Content-Disposition is null", contentDisp);
    Assert.assertTrue("Content-Disposition .", contentDisp.contains("attachment;filename"));
}

From source file:com.cognitivabrasil.repositorio.web.FileControllerIT.java

@Test
public void testGetFile() throws IOException {
    createFile();/*from w  w w  .j  a  v a2s .  co  m*/
    MockHttpServletResponse response = new MockHttpServletResponse();
    Files f = fService.get(1);
    f.setLocation(FILETEST);
    fController.getFile(1, response);
    assertThat(response.getStatus(), equalTo(200));
    assertThat(response.getHeader("Content-Disposition"), equalTo("attachment; filename=" + f.getName()));

    FileUtils.forceDelete(new java.io.File(FILETEST));

}

From source file:com.xemantic.tadedon.guice.servlet.mock.FakeServletContainerTest.java

/**
 * Tests {@link SessionIdReturningServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)}.
 *
 * @throws IOException if an input or output error is detected during request handling
 * @throws ServletException if container cannot handle request. 
 *//* w w  w.java  2s.  com*/
@Test
public void shouldReturnSessionIdAndAddFooHeader() throws IOException, ServletException {
    // given
    servletContainer.newSession("42"); // magic number
    MockHttpServletRequest request = servletContainer.newRequest("GET", "/SessionIdReturningServlet");
    MockHttpServletResponse response = new MockHttpServletResponse();

    // when
    servletContainer.service(request, response);

    // then
    assertThat(response.getContentAsString(), is("42"));
    assertThat((String) response.getHeader("Foo"), is("foo"));
}

From source file:org.terasoluna.gfw.web.logging.mdc.XTrackMDCPutFilterTest.java

@Test
public void testGetMDCValue_default_attributeName() throws ServletException {
    xTrackMDCPutFilter.init(mockFilterConfig);
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    String xTrack = xTrackMDCPutFilter.getMDCValue(request, response);
    assertThat(xTrack, is(notNullValue()));
    assertThat(xTrack.matches("^[a-f0-9]{32}$"), is(true));
    assertThat(response.getHeader("X-Track"), is(xTrack));
    assertThat((String) request.getAttribute("X-Track"), is(xTrack));
}