Search in sources :

Example 66 with HttpServletResponse

use of jakarta.servlet.http.HttpServletResponse in project tomcat by apache.

the class TestExpiresFilter method testSkipBecauseExpiresIsDefined.

@Test
public void testSkipBecauseExpiresIsDefined() throws Exception {
    HttpServlet servlet = new HttpServlet() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            response.setContentType("text/xml; charset=utf-8");
            response.addDateHeader("Expires", System.currentTimeMillis());
            response.getWriter().print("Hello world");
        }
    };
    validate(servlet, null);
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) HttpServlet(jakarta.servlet.http.HttpServlet) HttpServletResponse(jakarta.servlet.http.HttpServletResponse) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 67 with HttpServletResponse

use of jakarta.servlet.http.HttpServletResponse in project tomcat by apache.

the class TestExpiresFilter method testUseDefaultConfiguration2.

@Test
public void testUseDefaultConfiguration2() throws Exception {
    HttpServlet servlet = new HttpServlet() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            response.setContentType("image/jpeg");
            response.addHeader("Cache-Control", "private");
            response.getWriter().print("Hello world");
        }
    };
    validate(servlet, Integer.valueOf(1 * 60));
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) HttpServlet(jakarta.servlet.http.HttpServlet) HttpServletResponse(jakarta.servlet.http.HttpServletResponse) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 68 with HttpServletResponse

use of jakarta.servlet.http.HttpServletResponse in project tomcat by apache.

the class TestExpiresFilter method testEmptyContent.

/*
     * Test that a resource with empty content is also processed
     */
@Test
public void testEmptyContent() throws Exception {
    HttpServlet servlet = new HttpServlet() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            response.setContentType("text/plain");
        // no content is written in the response
        }
    };
    validate(servlet, Integer.valueOf(7 * 60));
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) HttpServlet(jakarta.servlet.http.HttpServlet) HttpServletResponse(jakarta.servlet.http.HttpServletResponse) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 69 with HttpServletResponse

use of jakarta.servlet.http.HttpServletResponse in project tomcat by apache.

the class TestExpiresFilter method testNullContentType.

@Test
public void testNullContentType() throws Exception {
    HttpServlet servlet = new HttpServlet() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            response.setContentType(null);
        }
    };
    validate(servlet, Integer.valueOf(1 * 60));
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) HttpServlet(jakarta.servlet.http.HttpServlet) HttpServletResponse(jakarta.servlet.http.HttpServletResponse) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 70 with HttpServletResponse

use of jakarta.servlet.http.HttpServletResponse in project tomcat by apache.

the class TestExpiresFilter method testSkipBecauseCacheControlMaxAgeIsDefined.

@Test
public void testSkipBecauseCacheControlMaxAgeIsDefined() throws Exception {
    HttpServlet servlet = new HttpServlet() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            response.setContentType("text/xml; charset=utf-8");
            response.addHeader("Cache-Control", "private, max-age=232");
            response.getWriter().print("Hello world");
        }
    };
    validate(servlet, Integer.valueOf(232));
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) HttpServlet(jakarta.servlet.http.HttpServlet) HttpServletResponse(jakarta.servlet.http.HttpServletResponse) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Aggregations

HttpServletResponse (jakarta.servlet.http.HttpServletResponse)118 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)76 Test (org.junit.jupiter.api.Test)47 MockHttpServletResponse (org.springframework.web.testfixture.servlet.MockHttpServletResponse)34 MockHttpServletRequest (org.springframework.web.testfixture.servlet.MockHttpServletRequest)31 FilterChain (jakarta.servlet.FilterChain)22 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)18 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)16 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)15 ServletException (jakarta.servlet.ServletException)14 StandardCharsets (java.nio.charset.StandardCharsets)14 HttpServlet (jakarta.servlet.http.HttpServlet)13 IOException (java.io.IOException)12 HashMap (java.util.HashMap)12 TomcatBaseTest (org.apache.catalina.startup.TomcatBaseTest)10 Test (org.junit.Test)10 Authentication (org.springframework.security.core.Authentication)10 FileCopyUtils (org.springframework.util.FileCopyUtils)9 BeforeEach (org.junit.jupiter.api.BeforeEach)8 Collections (java.util.Collections)7