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

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

Introduction

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

Prototype

@Override
    public boolean containsHeader(String name) 

Source Link

Usage

From source file:ch.silviowangler.dox.web.admin.RepositoryControllerTest.java

@Test
public void testGetDocument() throws Exception {

    when(doxExporter.export()).thenReturn(folder.newFile("archive.zip"));
    when(mimeTypes.getProperty("zip")).thenReturn("my content type");

    MockHttpServletResponse response = new MockHttpServletResponse();

    controller.getDocument(response);/*from ww  w  .  j a va2s . com*/

    assertThat(response.getContentType(), is("my content type"));
    assertThat(response.containsHeader(CONTENT_DISPOSITION), is(true));
}

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

protected MockHttpServletResponse testRange(String rangeHeader) throws Exception {

    String fileName = "Test Range.txt";

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId(),
            TestPropsValues.getUserId());

    FileEntry fileEntry = _dlAppLocalService.addFileEntry(TestPropsValues.getUserId(), group.getGroupId(),
            parentFolder.getFolderId(), fileName, ContentTypes.TEXT_PLAIN, _SAMPLE_DATA.getBytes(),
            serviceContext);/*from   w ww . j  a va  2s. c om*/

    String path = fileEntry.getGroupId() + "/" + fileEntry.getFolderId() + "/" + fileEntry.getTitle();

    Map<String, String> headers = new HashMap<>();

    if (Validator.isNotNull(rangeHeader)) {
        headers.put(HttpHeaders.RANGE, rangeHeader);
    }

    MockHttpServletResponse mockHttpServletResponse = service(Method.GET, path, headers, null, null, null);

    int status = mockHttpServletResponse.getStatus();

    Assert.assertTrue(mockHttpServletResponse.containsHeader(HttpHeaders.ACCEPT_RANGES));

    if (Validator.isNotNull(rangeHeader)) {
        Assert.assertEquals(HttpServletResponse.SC_PARTIAL_CONTENT, status);
    } else {
        Assert.assertEquals(HttpServletResponse.SC_OK, status);
    }

    String contentType = mockHttpServletResponse.getContentType();

    if (Validator.isNotNull(rangeHeader) && rangeHeader.contains(StringPool.COMMA)) {

        Assert.assertTrue(contentType.startsWith("multipart/byteranges"));
    } else {
        Assert.assertEquals(ContentTypes.TEXT_PLAIN, contentType);
    }

    return mockHttpServletResponse;
}

From source file:com.tasktop.c2c.server.common.service.tests.http.HttpProxyTest.java

@Test
public void testBasicGet() throws IOException {
    setupMock(HttpStatus.OK);//ww w  . j a  v  a 2  s . c  o  m
    MockHttpServletRequest clientRequest = new MockHttpServletRequest("GET", "unused");
    String randomRequestHeader = "RandomRequestHeader";
    String randomResponseHeader = "RandomResponseHeader";
    String connectionHeader = "Connection";

    clientRequest.addHeader(randomRequestHeader, "RandomHeaderValue");
    clientRequest.addHeader(connectionHeader, "ConnectionValue");
    proxyResponseHeaders.add(new Header(randomResponseHeader, "RandomHeaderValue"));
    proxyResponseHeaders.add(new Header(connectionHeader, "ConnectionValue")); // Should not pass along

    MockHttpServletResponse clientResponse = new MockHttpServletResponse();

    proxy.proxyRequest("foo", clientRequest, clientResponse);

    Assert.assertNotNull(getProxyRequestHeaderValues(randomRequestHeader));
    Assert.assertNull(getProxyRequestHeaderValues(connectionHeader));
    Assert.assertTrue(clientResponse.containsHeader(randomResponseHeader));
    Assert.assertFalse(clientResponse.containsHeader(connectionHeader)); // FIXME, unsure if this req is correct

    context.assertIsSatisfied();
}