From 8a88a6ca532a15c6f85d0d9d01fadefc564a6443 Mon Sep 17 00:00:00 2001 From: Mark Thomas Date: Fri, 22 Mar 2024 11:43:54 +0000 Subject: [PATCH] Fix #524 - TCK challenge - remove test that no longer applies The require this test checks has been removed from the Servlet spec --- .../RequestDispatcherTests.java | 73 ++++++---------- .../spec/requestdispatcher/TestServlet.java | 33 ------- .../spec/requestdispatcher/WrapServlet.java | 86 ------------------- .../servlet_spec_requestdispatcher_web.xml | 8 -- 4 files changed, 25 insertions(+), 175 deletions(-) delete mode 100644 tck/tck-runtime/src/main/java/servlet/tck/spec/requestdispatcher/WrapServlet.java diff --git a/tck/tck-runtime/src/main/java/servlet/tck/spec/requestdispatcher/RequestDispatcherTests.java b/tck/tck-runtime/src/main/java/servlet/tck/spec/requestdispatcher/RequestDispatcherTests.java index 561108950..f86bfb005 100644 --- a/tck/tck-runtime/src/main/java/servlet/tck/spec/requestdispatcher/RequestDispatcherTests.java +++ b/tck/tck-runtime/src/main/java/servlet/tck/spec/requestdispatcher/RequestDispatcherTests.java @@ -42,7 +42,7 @@ public static WebArchive getTestArchive() throws Exception { return ShrinkWrap.create(WebArchive.class, "servlet_spec_requestdispatcher_web.war") .addAsLibraries(CommonServlets.getCommonServletsArchive()) .addClasses(ForwardedServlet.class, HttpTestServlet.class, IncludedServlet.class, - MultiForwardedServlet.class, TestServlet.class, WrapServlet.class) + MultiForwardedServlet.class, TestServlet.class) .setWebXML(RequestDispatcherTests.class.getResource("servlet_spec_requestdispatcher_web.xml")); } @@ -123,9 +123,9 @@ public void getRequestAttributes2() throws Exception { /* * @testName: requestDispatcherIncludeIOAndServletExceptionTest - * + * * @assertion_ids: Servlet:SPEC:82; Servlet:JAVADOC:279; Servlet:JAVADOC:280; - * + * * @test_Strategy: Validate an exception thrown during a * RequestDispatcher.include() operation results in an IOException or * ServletException being thrown, the Servlet or IOException will be @@ -143,9 +143,9 @@ public void requestDispatcherIncludeIOAndServletExceptionTest() throws Exception /* * @testName: requestDispatcherIncludeRuntimeExceptionTest - * + * * @assertion_ids: Servlet:SPEC:82 - * + * * @test_Strategy: Validate a RuntimeException thrown during a * RequestDispacher.include() operation results in the RuntimeException being * propagated back to the caller and will not be wrapped by a @@ -162,9 +162,9 @@ public void requestDispatcherIncludeRuntimeExceptionTest() throws Exception { /* * @testName: requestDispatcherIncludeCheckedExceptionTest - * + * * @assertion_ids: Servlet:SPEC:82 - * + * * @test_Strategy: Validate a checked exception that is thrown during a * RequetDispatcher.include() operation and is not an instance of * ServletException or IOException is returned to the caller wrapped by @@ -181,9 +181,9 @@ public void requestDispatcherIncludeCheckedExceptionTest() throws Exception { /* * @testName: requestDispatcherForwardIOAndServletExceptionTest - * + * * @assertion_ids: Servlet:SPEC:82; Servlet:JAVADOC:275; Servlet:JAVADOC:276; - * + * * @test_Strategy: Validate an exception thrown during a * RequestDispatcher.forward() operation results in an IOException or * ServletException being thrown, the Servlet or IOException will be @@ -201,9 +201,9 @@ public void requestDispatcherForwardIOAndServletExceptionTest() throws Exception /* * @testName: requestDispatcherForwardRuntimeExceptionTest - * + * * @assertion_ids: Servlet:SPEC:82 - * + * * @test_Strategy: Validate a RuntimeException thrown during a * RequestDispacher.forward() operation results in the RuntimeException being * propagated back to the caller and will not be wrapped by a @@ -220,9 +220,9 @@ public void requestDispatcherForwardRuntimeExceptionTest() throws Exception { /* * @testName: requestDispatcherForwardCheckedExceptionTest - * + * * @assertion_ids: Servlet:SPEC:82 - * + * * @test_Strategy: Validate a checked exception that is thrown during a * RequetDispatcher.forward() operation and is not an instance of * ServletException or IOException is returned to the caller wrapped by @@ -372,34 +372,11 @@ public void bufferContent() throws Exception { invoke(); } - /* - * @testName: requestDispatcherNoWrappingTest - * - * @assertion_ids: Servlet:SPEC:50; - * - * @test_Strategy: Validate the container passes the same objects from a - * RequestDispatcher operation to the target entity. The container should not - * wrap the object at any point. - */ - @Test - public void requestDispatcherNoWrappingTest() throws Exception { - TEST_PROPS.get().setProperty(REQUEST, - "GET /servlet_spec_requestdispatcher_web/TestServlet?testname=rdNoWrappingTest&operation=0 HTTP/1.1"); - TEST_PROPS.get().setProperty(SEARCH_STRING, "Test PASSED"); - TEST_PROPS.get().setProperty(UNEXPECTED_RESPONSE_MATCH, "Test FAILED"); - invoke(); - TEST_PROPS.get().setProperty(REQUEST, - "GET /servlet_spec_requestdispatcher_web/TestServlet?testname=rdNoWrappingTest&operation=1 HTTP/1.1"); - TEST_PROPS.get().setProperty(SEARCH_STRING, "Test PASSED"); - TEST_PROPS.get().setProperty(UNEXPECTED_RESPONSE_MATCH, "Test FAILED"); - invoke(); - } - /* * @testName: getRequestURIIncludeTest - * + * * @assertion_ids: Servlet:SPEC:76; Servlet:JAVADOC:561; - * + * * @test_Strategy: 1. Create servlets TestServlet and HttpTestServlet; 2. In * TestServlet;, access HttpTestServlet using RequestDispatcher.include. 3. * Verify in HttpTestServlet, that getRequestURI returns correct URI according @@ -413,9 +390,9 @@ public void getRequestURIIncludeTest() throws Exception { /* * @testName: getRequestURLIncludeTest - * + * * @assertion_ids: Servlet:SPEC:76; Servlet:JAVADOC:562; - * + * * @test_Strategy: 1. Create servlets TestServlet and HttpTestServlet; 2. In * TestServlet;, access HttpTestServlet using RequestDispatcher.include. 3. * Verify in HttpTestServlet, that getRequestURL returns correct URI according @@ -429,9 +406,9 @@ public void getRequestURLIncludeTest() throws Exception { /* * @testName: getRequestURIForwardTest - * + * * @assertion_ids: Servlet:SPEC:78;; Servlet:JAVADOC:561; - * + * * @test_Strategy: 1. Create servlets TestServlet and HttpTestServlet; 2. In * TestServlet;, access HttpTestServlet using RequestDispatcher.forward. 3. * Verify in HttpTestServlet, that getRequestURI returns correct URI according @@ -445,9 +422,9 @@ public void getRequestURIForwardTest() throws Exception { /* * @testName: getRequestURLForwardTest - * + * * @assertion_ids: Servlet:SPEC:78; Servlet:JAVADOC:562; - * + * * @test_Strategy: 1. Create servlets TestServlet and HttpTestServlet; 2. In * TestServlet;, access HttpTestServlet using RequestDispatcher.forward. 3. * Verify in HttpTestServlet, that getRequestURL returns correct URL according @@ -461,9 +438,9 @@ public void getRequestURLForwardTest() throws Exception { /* * @testName: getQueryStringIncludeTest - * + * * @assertion_ids: Servlet:SPEC:192; Servlet:JAVADOC:552; - * + * * @test_Strategy: 1. Create servlets TestServlet and HttpTestServlet; 2. Send * request to TestServlet with ?testname=getQueryStringIncludeTest; 3. In * TestServlet, access HttpTestServlet using RequestDispatcher.include, with @@ -479,9 +456,9 @@ public void getQueryStringIncludeTest() throws Exception { /* * @testName: getQueryStringForwardTest - * + * * @assertion_ids: Servlet:SPEC:78; Servlet:JAVADOC:552; - * + * * @test_Strategy: 1. Create servlets TestServlet and HttpTestServlet; 2. Send * request to TestServlet with ?testname=getQueryStringForwardTest; 3. In * TestServlet, access HttpTestServlet using RequestDispatcher.forward, with diff --git a/tck/tck-runtime/src/main/java/servlet/tck/spec/requestdispatcher/TestServlet.java b/tck/tck-runtime/src/main/java/servlet/tck/spec/requestdispatcher/TestServlet.java index 74e7abc44..d34f77c27 100644 --- a/tck/tck-runtime/src/main/java/servlet/tck/spec/requestdispatcher/TestServlet.java +++ b/tck/tck-runtime/src/main/java/servlet/tck/spec/requestdispatcher/TestServlet.java @@ -391,39 +391,6 @@ public void bufferContent(HttpServletRequest request, rd.forward(request, response); } - public void rdNoWrappingTest(HttpServletRequest request, - HttpServletResponse response) throws ServletException, IOException { - - // when calling the request dispatcher, the objects passed to the included - // or forwarded servlet must be the same objects passed to the - // RequestDispatcher - - int operation = Integer.parseInt(request.getParameter("operation")); - System.out.println("Operation: " + operation); - HttpServletRequestWrapper reqw = new HttpServletRequestWrapper(request); - HttpServletResponseWrapper resw = new HttpServletResponseWrapper(response); - - ServletContext ctx = getServletConfig().getServletContext(); - ctx.setAttribute("tck.request", reqw); - ctx.setAttribute("tck.response", resw); - - RequestDispatcher rd = request.getRequestDispatcher("/WrapServlet"); - - if (rd != null) { - switch (operation) { - case 0: - System.out.println("PERFORMING RD.FORWARD...."); - System.out.println("COMMITTED: " + response.isCommitted()); - rd.forward(reqw, resw); - break; - case 1: - System.out.println("PERFORMING RD.INCLUDE..."); - rd.include(reqw, resw); - break; - } - } - } - public void getRequestURIIncludeTest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter pw = response.getWriter(); diff --git a/tck/tck-runtime/src/main/java/servlet/tck/spec/requestdispatcher/WrapServlet.java b/tck/tck-runtime/src/main/java/servlet/tck/spec/requestdispatcher/WrapServlet.java deleted file mode 100644 index 6bc31decb..000000000 --- a/tck/tck-runtime/src/main/java/servlet/tck/spec/requestdispatcher/WrapServlet.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v. 2.0, which is available at - * http://www.eclipse.org/legal/epl-2.0. - * - * This Source Code may also be made available under the following Secondary - * Licenses when the conditions for such availability set forth in the - * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, - * version 2 with the GNU Classpath Exception, which is available at - * https://www.gnu.org/software/classpath/license.html. - * - * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 - */ - -/* - * $Id$ - */ - -/* - * $URL$ $LastChangedDate$ - */ - -package servlet.tck.spec.requestdispatcher; - -import java.io.IOException; -import java.io.PrintWriter; - -import jakarta.servlet.ServletConfig; -import jakarta.servlet.ServletContext; -import jakarta.servlet.ServletException; -import jakarta.servlet.http.HttpServlet; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class WrapServlet extends HttpServlet { - - private static final Logger LOGGER = LoggerFactory.getLogger(WrapServlet.class); - - ServletContext ctx = null; - - public void init(ServletConfig servletConfig) throws ServletException { - super.init(servletConfig); - LOGGER.info("WRAP INIT..."); - ctx = servletConfig.getServletContext(); - } - - public void service(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - LOGGER.info("IN WRAP SERVLET..."); - Object ctxRequest = ctx.getAttribute("tck.request"); - Object ctxResponse = ctx.getAttribute("tck.response"); - ctx.removeAttribute("tck.request"); - ctx.removeAttribute("tck.response"); - - PrintWriter pw = response.getWriter(); - pw.println("In Wrap servlet..."); - if (ctxRequest != null && ctxResponse != null) { - if (ctxRequest == request) { - if (ctxResponse == response) { - pw.println("Test PASSED"); - } else { - pw.println("Test FAILED. Expected the response object passed to" - + " the target of a RequestDispatcher operation to be the same that" - + " was passed to the RequestDispatcher."); - pw.println("Original response: " + ctxResponse); - pw.println("Passed responset: " + response); - } - } else { - pw.println("Test FAILED. Expected the request object passed to" - + " the target of a RequestDispatcher operation to be the same that" - + " was passed to the RequestDispatcher."); - pw.println("Original request: " + ctxRequest); - pw.println("Passed request: " + request); - } - } else { - pw.println( - "Test FAILED. Unable to find all required ServletContext values."); - pw.println("tck.request: " + ctxRequest); - pw.println("tck.response: " + ctxResponse); - } - } -} diff --git a/tck/tck-runtime/src/main/java/servlet/tck/spec/requestdispatcher/servlet_spec_requestdispatcher_web.xml b/tck/tck-runtime/src/main/java/servlet/tck/spec/requestdispatcher/servlet_spec_requestdispatcher_web.xml index 071054ed8..c7d517542 100644 --- a/tck/tck-runtime/src/main/java/servlet/tck/spec/requestdispatcher/servlet_spec_requestdispatcher_web.xml +++ b/tck/tck-runtime/src/main/java/servlet/tck/spec/requestdispatcher/servlet_spec_requestdispatcher_web.xml @@ -39,10 +39,6 @@ ForwardedServlet servlet.tck.spec.requestdispatcher.ForwardedServlet - - WrapServlet - servlet.tck.spec.requestdispatcher.WrapServlet - TestServlet /TestServlet @@ -63,10 +59,6 @@ MultiForwardedServlet /forward/MultiForwardedServlet - - WrapServlet - /WrapServlet - 54