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

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

Introduction

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

Prototype

@Override
public Collection<String> getHeaderNames() 

Source Link

Document

Return the names of all specified headers as a Set of Strings.

Usage

From source file:ch.ralscha.extdirectspring.controller.ApiControllerTest.java

private void testGroup1(Configuration config, String fingerprint) throws Exception {
    ApiRequestParams params = ApiRequestParams.builder().apiNs("Ext.ns").actionNs("actionns").group("group1")
            .configuration(config).build();
    doTest("/api-debug-doc.js", params, group1Apis("actionns"));
    doTest("/api-debug.js", params, group1Apis("actionns"));

    if (fingerprint == null) {
        doTest("/api.js", params, group1Apis("actionns"));
    } else {//  w  ww . j  a v a2 s. c o m
        MvcResult result = doTest("/api" + fingerprint + ".js", params, group1Apis("actionns"));

        MockHttpServletResponse response = result.getResponse();

        assertThat(response.getHeaderNames()).hasSize(5);
        assertThat(response.getHeader("ETag")).isNotNull();
        assertThat(response.getHeader("Cache-Control")).isEqualTo("public, max-age=" + 6 * 30 * 24 * 60 * 60);

        Long expiresMillis = (Long) response.getHeaderValue("Expires");
        DateTime expires = new DateTime(expiresMillis, DateTimeZone.UTC);
        DateTime inSixMonths = DateTime.now(DateTimeZone.UTC).plusSeconds(6 * 30 * 24 * 60 * 60);
        assertThat(expires.getYear()).isEqualTo(inSixMonths.getYear());
        assertThat(expires.getMonthOfYear()).isEqualTo(inSixMonths.getMonthOfYear());
        assertThat(expires.getDayOfMonth()).isEqualTo(inSixMonths.getDayOfMonth());
        assertThat(expires.getHourOfDay()).isEqualTo(inSixMonths.getHourOfDay());
        assertThat(expires.getMinuteOfDay()).isEqualTo(inSixMonths.getMinuteOfDay());
    }
}

From source file:org.opennms.core.test.rest.AbstractSpringJerseyRestTestCase.java

protected String stringifyResponse(final MockHttpServletResponse response) {
    final StringBuilder string = new StringBuilder();
    try {//from   w  ww  . j a  v  a 2  s. co m
        string.append("HttpServletResponse[").append("status=").append(response.getStatus()).append(",content=")
                .append(response.getContentAsString()).append(",headers=[");
        boolean first = true;
        for (final Iterator<String> i = response.getHeaderNames().iterator(); i.hasNext(); first = false) {
            if (!first) {
                string.append(",");
            }
            final String name = i.next();
            string.append(name).append("=").append(response.getHeader(name));
        }
        string.append("]").append("]");
    } catch (UnsupportedEncodingException e) {
        LOG.warn("Unable to get response content", e);
    }
    return string.toString();
}

From source file:org.opennms.web.rest.AbstractSpringJerseyRestTestCase.java

protected String stringifyResponse(final MockHttpServletResponse response) {
    final StringBuilder string = new StringBuilder();
    try {/*w ww . j a v  a  2s . c om*/
        string.append("HttpServletResponse[").append("status=").append(response.getStatus()).append(",content=")
                .append(response.getContentAsString()).append(",headers=[");
        boolean first = true;
        for (final Iterator<String> i = response.getHeaderNames().iterator(); i.hasNext(); first = false) {
            if (!first) {
                string.append(",");
            }
            final String name = i.next();
            string.append("name=").append(response.getHeader(name));
        }
        string.append("]").append("]");
    } catch (UnsupportedEncodingException e) {
        LOG.warn("Unable to get response content", e);
    }
    return string.toString();
}