diff --git a/pom.xml b/pom.xml index 5657614051..7786470b01 100644 --- a/pom.xml +++ b/pom.xml @@ -50,9 +50,13 @@ + + 11 + api spec + tck @@ -104,6 +108,9 @@ 3.5.4 + + 11 + diff --git a/tck/pom.xml b/tck/pom.xml new file mode 100644 index 0000000000..4b686af55f --- /dev/null +++ b/tck/pom.xml @@ -0,0 +1,77 @@ + + + + + 4.0.0 + + + jakarta.servlet + servlet-parent + 6.1.0-SNAPSHOT + + + tck + pom + + Jakarta Servlet TCK + https://projects.eclipse.org/projects/ee4j.servlet + + + EPL 2.0 + http://www.eclipse.org/legal/epl-2.0 + repo + + + GPL2 w/ CPE + https://www.gnu.org/software/classpath/license.html + repo + + + + + tck-util + tck-runtime + + + + + + org.junit + junit-bom + 5.9.1 + pom + import + + + org.jboss.arquillian + arquillian-bom + 1.7.0.Final + pom + import + + + org.slf4j + slf4j-api + 2.0.7 + + + + + diff --git a/tck/tck-runtime/pom.xml b/tck/tck-runtime/pom.xml new file mode 100644 index 0000000000..5f4bd4964c --- /dev/null +++ b/tck/tck-runtime/pom.xml @@ -0,0 +1,104 @@ + + + + + 4.0.0 + + + jakarta.servlet + tck + 6.1.0-SNAPSHOT + + + tck-runtime + jar + + Jakarta Servlet TCK Runtime + + + + jakarta.servlet + jakarta.servlet-api + ${project.version} + provided + + + jakarta.annotation + jakarta.annotation-api + 2.1.1 + + + org.jboss.shrinkwrap.resolver + shrinkwrap-resolver-api-maven + 3.1.4 + + + commons-io + commons-io + 2.10.0 + + + org.junit.jupiter + junit-jupiter + compile + + + org.jboss.arquillian.junit5 + arquillian-junit5-container + + + org.jboss.arquillian.junit + arquillian-junit-core + + + jakarta.servlet + tck-util + ${project.version} + + + org.slf4j + slf4j-api + + + commons-httpclient + commons-httpclient + 3.1 + + + + + + + src/main/java + + **/**.xml + **/jakarta.servlet.ServletContainerInitializer + **/web-fragment*.xml + **/*.txt + **/*.tld + + + + src/main/resources + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/build.xml new file mode 100644 index 0000000000..d93411beb8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/build.xml @@ -0,0 +1,22 @@ + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/common/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/common/build.xml new file mode 100644 index 0000000000..cf5ce7930e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/common/build.xml @@ -0,0 +1,22 @@ + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/common/sharedfiles/HSessionAttributeListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/common/sharedfiles/HSessionAttributeListener.java new file mode 100644 index 0000000000..135d87059b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/common/sharedfiles/HSessionAttributeListener.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.api.common.sharedfiles; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.http.HttpSessionAttributeListener; +import jakarta.servlet.http.HttpSessionBindingEvent; + +public final class HSessionAttributeListener + implements HttpSessionAttributeListener { + + public void attributeAdded(HttpSessionBindingEvent arg0) { + StaticLog.add("HSessionAttribute Added."); + } + + public void attributeRemoved(HttpSessionBindingEvent arg0) { + StaticLog.add("HSessionAttribute Removed."); + } + + public void attributeReplaced(HttpSessionBindingEvent arg0) { + StaticLog.add("HSessionAttribute Replaced."); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/common/sharedfiles/HSessionListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/common/sharedfiles/HSessionListener.java new file mode 100644 index 0000000000..ddb0235066 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/common/sharedfiles/HSessionListener.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.api.common.sharedfiles; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.http.HttpSessionEvent; +import jakarta.servlet.http.HttpSessionListener; + +public final class HSessionListener implements HttpSessionListener { + + public void sessionCreated(HttpSessionEvent arg0) { + StaticLog.add("HSessionListener created."); + } + + public void sessionDestroyed(HttpSessionEvent arg0) { + StaticLog.add("HSessionListener destroyed."); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/common/sharedfiles/SCAttributeListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/common/sharedfiles/SCAttributeListener.java new file mode 100644 index 0000000000..9d2d1bd8a7 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/common/sharedfiles/SCAttributeListener.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.api.common.sharedfiles; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.ServletContextAttributeEvent; +import jakarta.servlet.ServletContextAttributeListener; + +public final class SCAttributeListener + implements ServletContextAttributeListener { + + public void attributeAdded(ServletContextAttributeEvent event) { + StaticLog.add( + "SCAttributeListenerAdded:" + event.getName() + "," + event.getValue()); + } + + public void attributeRemoved(ServletContextAttributeEvent event) { + StaticLog.add("SCAttributeListenerRemoved:" + event.getName() + "," + + event.getValue()); + } + + public void attributeReplaced(ServletContextAttributeEvent event) { + StaticLog.add("SCAttributeListenerReplaced:" + event.getName() + "," + + event.getValue()); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/common/sharedfiles/SCListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/common/sharedfiles/SCListener.java new file mode 100644 index 0000000000..c6224a8633 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/common/sharedfiles/SCListener.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.api.common.sharedfiles; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; + +public final class SCListener implements ServletContextListener { + + public void contextInitialized(ServletContextEvent sce) { + StaticLog.add("SCListener_ContextInitialized."); + } + + public void contextDestroyed(ServletContextEvent sce) { + StaticLog.add("SCListener_ContextDestroyed."); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/common/sharedfiles/SRAttributeListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/common/sharedfiles/SRAttributeListener.java new file mode 100644 index 0000000000..6feb6e3d3f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/common/sharedfiles/SRAttributeListener.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.api.common.sharedfiles; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.ServletRequestAttributeEvent; +import jakarta.servlet.ServletRequestAttributeListener; + +public final class SRAttributeListener + implements ServletRequestAttributeListener { + + public void attributeAdded(ServletRequestAttributeEvent event) { + StaticLog.add( + "SRAttributeListenerAdded:" + event.getName() + "," + event.getValue()); + + } + + public void attributeRemoved(ServletRequestAttributeEvent event) { + StaticLog.add("SRAttributeListenerRemoved:" + event.getName() + "," + + event.getValue()); + } + + public void attributeReplaced(ServletRequestAttributeEvent event) { + StaticLog.add("SRAttributeListenerReplaced:" + event.getName() + "," + + event.getValue()); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/common/sharedfiles/SRListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/common/sharedfiles/SRListener.java new file mode 100644 index 0000000000..4abde1afd8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/common/sharedfiles/SRListener.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.api.common.sharedfiles; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.ServletRequestEvent; +import jakarta.servlet.ServletRequestListener; + +public final class SRListener implements ServletRequestListener { + + public void requestDestroyed(ServletRequestEvent event) { + StaticLog.add("SRListenerDestroyed."); + } + + public void requestInitialized(ServletRequestEvent event) { + StaticLog.add("SRListenerInitialized."); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asynccontext/ACListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asynccontext/ACListener.java new file mode 100644 index 0000000000..848dce544a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asynccontext/ACListener.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2009, 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.asynccontext; + +import java.io.IOException; + +import jakarta.servlet.AsyncEvent; +import jakarta.servlet.AsyncListener; + +public final class ACListener implements AsyncListener { + + public ACListener() throws IOException { + } + + public void onError(AsyncEvent event) throws IOException { + event.getAsyncContext().getResponse().getWriter() + .println("in onError method of ACListener"); + } + + public void onStartAsync(AsyncEvent event) throws IOException { + event.getAsyncContext().getResponse().getWriter() + .println("in onStartAsync method of ACListener"); + } + + public void onComplete(AsyncEvent event) throws IOException { + // bug 19258007: illegal to call getResponse() in here + // event.getAsyncContext().getResponse().getWriter().println("in onComplete + // method of ACListener"); + } + + public void onTimeout(AsyncEvent event) throws IOException { + event.getAsyncContext().getResponse().getWriter() + .println("in onTimeout method of ACListener"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asynccontext/ACListener1.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asynccontext/ACListener1.java new file mode 100644 index 0000000000..9ed4f45e41 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asynccontext/ACListener1.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2011, 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.asynccontext; + +import java.io.IOException; + +import jakarta.servlet.AsyncEvent; +import jakarta.servlet.AsyncListener; + +public final class ACListener1 implements AsyncListener { + + public ACListener1() throws IOException { + } + + public void onError(AsyncEvent event) throws IOException { + event.getAsyncContext().getResponse().getWriter() + .println("in onError method of ACListener1"); + } + + public void onStartAsync(AsyncEvent event) throws IOException { + event.getAsyncContext().getResponse().getWriter() + .println("in onStartAsync method of ACListener1"); + } + + public void onComplete(AsyncEvent event) throws IOException { + throw new IOException("in onComplete method of ACListener1"); + } + + public void onTimeout(AsyncEvent event) throws IOException { + event.getAsyncContext().getResponse().getWriter() + .println("in onTimeout method of ACListener1"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asynccontext/ACListener2.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asynccontext/ACListener2.java new file mode 100644 index 0000000000..d5df1d93c8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asynccontext/ACListener2.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2012, 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.asynccontext; + +import java.io.IOException; + +import jakarta.servlet.AsyncEvent; +import jakarta.servlet.AsyncListener; + +public final class ACListener2 implements AsyncListener { + + public ACListener2() throws IOException { + } + + public void onError(AsyncEvent event) throws IOException { + event.getAsyncContext().getResponse().getWriter() + .println("in onError method of ACListener2"); + } + + public void onStartAsync(AsyncEvent event) throws IOException { + event.getAsyncContext().getResponse().getWriter() + .println("in onStartAsync method of ACListener2"); + } + + public void onComplete(AsyncEvent event) throws IOException { + throw new IOException("in onComplete method of ACListener2"); + } + + public void onTimeout(AsyncEvent event) throws IOException { + event.getAsyncContext().getResponse().getWriter() + .println("in onTimeout method of ACListener2"); + event.getAsyncContext().complete(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asynccontext/ACListenerBad.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asynccontext/ACListenerBad.java new file mode 100644 index 0000000000..30420112cb --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asynccontext/ACListenerBad.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2011, 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.asynccontext; + +import java.io.IOException; + +import jakarta.servlet.AsyncEvent; +import jakarta.servlet.AsyncListener; + +public final class ACListenerBad implements AsyncListener { + + public ACListenerBad() throws IOException { + throw new IOException("Make sure that ACListenerBad does not instantiate"); + } + + public void onError(AsyncEvent event) throws IOException { + event.getAsyncContext().getResponse().getWriter() + .println("in onError method of ACListenerBad"); + } + + public void onStartAsync(AsyncEvent event) throws IOException { + event.getAsyncContext().getResponse().getWriter() + .println("in onStartAsync method of ACListenerBad"); + } + + public void onComplete(AsyncEvent event) throws IOException { + event.getAsyncContext().getResponse().getWriter() + .println("in onComplete method of ACListenerBad"); + } + + public void onTimeout(AsyncEvent event) throws IOException { + event.getAsyncContext().getResponse().getWriter() + .println("in onTimeout method of ACListenerBad"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asynccontext/AsyncTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asynccontext/AsyncTestServlet.java new file mode 100644 index 0000000000..f69f4e6f70 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asynccontext/AsyncTestServlet.java @@ -0,0 +1,1075 @@ +/* + * Copyright (c) 2009, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.asynccontext; + +import java.io.IOException; +import java.util.Timer; +import java.util.TimerTask; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.AsyncListener; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class AsyncTestServlet extends GenericTCKServlet { + + // Test for AsyncContext.dispatch() + public void dispatchZeroArgTest(ServletRequest request, + ServletResponse response) throws IOException { + + String where = (String) request.getAttribute("WHERE"); + if ("ASYNC".equals(where)) { + response.getWriter().println("ASYNC_STARTED_dispatchZeroArgTest"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + } else { + response.getWriter().println("ASYNC_NOT_STARTED_dispatchZeroArgTest"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(); + request.setAttribute("WHERE", "ASYNC"); + ac.dispatch(); + } + } + + // Test for AsyncContext.dispatch() + public void dispatchZeroArgTest1(ServletRequest request, + ServletResponse response) throws IOException { + + String where = (String) request.getAttribute("WHERE"); + if ("ASYNC".equals(where)) { + response.getWriter().println("ASYNC_STARTED_dispatchZeroArgTest1"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + } else { + response.getWriter().println("ASYNC_NOT_STARTED_dispatchZeroArgTest1"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(request, response); + request.setAttribute("WHERE", "ASYNC"); + ac.dispatch(); + } + } + // Test for AsyncContext.dispatch() + + public void dispatchZeroArgTest2(ServletRequest request, + ServletResponse response) throws IOException { + + String where = (String) request.getAttribute("WHERE"); + if ("ASYNC".equals(where)) { + response.getWriter().println("ASYNC_STARTED_dispatchZeroArgTest2"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + } else { + response.getWriter().println("ASYNC_NOT_STARTED_dispatchZeroArgTest2"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(new RequestWrapper(request), + new ResponseWrapper(response)); + request.setAttribute("WHERE", "ASYNC"); + ac.dispatch(); + } + } + + // Test for AsyncContext.dispatch(ServletContext, String path) + public void dispatchContextPathTest(ServletRequest request, + ServletResponse response) throws IOException { + String path = "/async/AsyncTests?testname=asyncTest"; + + response.getWriter().println("ASYNC_NOT_STARTED_dispatchContextPathTest"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(); + ac.dispatch(request.getServletContext(), path); + } + + // Test for AsyncContext.dispatch(ServletContext, String path) + public void dispatchContextPathTest1(ServletRequest request, + ServletResponse response) throws IOException { + String path = "/async/AsyncTests?testname=asyncTest"; + + response.getWriter().println("ASYNC_NOT_STARTED_dispatchContextPathTest1"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(request, response); + ac.dispatch(request.getServletContext(), path); + } + + // Test for AsyncContext.dispatch(ServletContext, String path) + public void dispatchContextPathTest2(ServletRequest request, + ServletResponse response) throws IOException { + String path = "/async/AsyncTests?testname=asyncTest"; + + response.getWriter().println("ASYNC_NOT_STARTED_dispatchContextPathTest2"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(new RequestWrapper(request), + new ResponseWrapper(response)); + ac.dispatch(request.getServletContext(), path); + } + + public void forwardTest(ServletRequest request, ServletResponse response) + throws IOException, ServletException { + + response.getWriter().println("forwardTest"); + + String where = (String) request.getAttribute("WHERE"); + if ("ASYNC".equals(where)) { + response.getWriter().println("ASYNC_STARTED_forwardTest"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + } else { + response.getWriter().println("ASYNC_NOT_STARTED_forwardTest"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + getServletContext() + .getRequestDispatcher("/AsyncTestServlet?testname=forwardDummy") + .forward(request, response); + } + } + + public void forwardTest1(ServletRequest request, ServletResponse response) + throws IOException, ServletException { + + response.getWriter().println("forwardTest1"); + + String where = (String) request.getAttribute("WHERE"); + if ("ASYNC".equals(where)) { + response.getWriter().println("ASYNC_STARTED_forwardTest1"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + } else { + response.getWriter().println("ASYNC_NOT_STARTED_forwardTest1"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + getServletContext() + .getRequestDispatcher("/AsyncTestServlet?testname=forwardDummy1") + .forward(request, response); + } + } + + public void forwardDummy(ServletRequest request, ServletResponse response) + throws IOException { + response.getWriter().println("forwardDummy"); + + String where = (String) request.getAttribute("WHERE"); + if ("ASYNC".equals(where)) { + response.getWriter().println("ASYNC_STARTED_forwardDummy"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + } else { + response.getWriter().println("ASYNC_NOT_STARTED_forwardDummy"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + + AsyncContext ac = request.startAsync(); + request.setAttribute("WHERE", "ASYNC"); + ac.dispatch(); + } + } + + public void forwardDummy1(ServletRequest request, ServletResponse response) + throws IOException { + response.getWriter().println("forwardDummy1"); + + String where = (String) request.getAttribute("WHERE"); + if ("ASYNC".equals(where)) { + response.getWriter().println("ASYNC_STARTED_forwardDummy1"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + } else { + response.getWriter().println("ASYNC_NOT_STARTED_forwardDummy1"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + + AsyncContext ac = request.startAsync(request, response); + request.setAttribute("WHERE", "ASYNC"); + ac.dispatch(); + } + } + + // Test for AsyncContext.getRequest() + public void getRequestTest(ServletRequest request, ServletResponse response) + throws IOException { + AsyncContext ac = request.startAsync(); + + if (ac.getRequest() == request) { + response.getWriter().println("getRequest() worked. Test PASSED."); + } else { + response.getWriter() + .println("getRequest() didnot work as expected. Test FAILED."); + } + ac.complete(); + } + + // Test for AsyncContext.getRequest() + public void getRequestTest1(ServletRequest request, ServletResponse response) + throws IOException { + + AsyncContext ac = request.startAsync(request, response); + if (ac.getRequest() == request) { + response.getWriter().println("getRequest() worked. Test PASSED."); + } else { + response.getWriter() + .println("getRequest() didnot work as expected. Test FAILED."); + } + ac.complete(); + } + + // Test for AsyncContext.getRequest() + public void getRequestTest2(ServletRequest request, ServletResponse response) + throws IOException { + RequestWrapper newRequest = new RequestWrapper(request); + ResponseWrapper newResponse = new ResponseWrapper(response); + + AsyncContext ac = request.startAsync(newRequest, newResponse); + + if (ac.getRequest() == newRequest) { + response.getWriter().println("getRequest() worked. Test PASSED."); + } else { + response.getWriter() + .println("getRequest() didnot work as expected. Test FAILED."); + } + ac.complete(); + } + + // Test for AsyncContext.getRequest() + public void getRequestTest3(ServletRequest request, ServletResponse response) + throws IOException { + ResponseWrapper newResponse = new ResponseWrapper(response); + + AsyncContext ac = request.startAsync(request, newResponse); + + if (ac.getRequest() == request) { + response.getWriter().println("getRequest() worked. Test PASSED."); + } else { + response.getWriter() + .println("getRequest() didnot work as expected. Test FAILED."); + } + ac.complete(); + } + + // Test for AsyncContext.getRequest() + public void getRequestTest4(ServletRequest request, ServletResponse response) + throws IOException { + RequestWrapper newRequest = new RequestWrapper(request); + + AsyncContext ac = request.startAsync(newRequest, response); + + if (ac.getRequest() == newRequest) { + response.getWriter().println("getRequest() worked. Test PASSED."); + } else { + response.getWriter() + .println("getRequest() didnot work as expected. Test FAILED."); + } + ac.complete(); + } + + // Test for AsyncContext.getRequest() + public void getRequestTest6(final ServletRequest request, + ServletResponse response) throws IOException { + final AsyncContext ac = request.startAsync(); + + Timer asyncTimer = new Timer("AsyncTimer", true); + asyncTimer.schedule(new TimerTask() { + + @Override + public void run() { + try { + if (ac.getRequest() == request) { + ac.getResponse().getWriter() + .println("getRequest() worked. Test PASSED."); + } else { + ac.getResponse().getWriter() + .println("getRequest() didnot work as expected. Test FAILED."); + } + ac.complete(); + } catch (java.io.IOException ioe) { + ioe.printStackTrace(); + } + } + }, 0); + + } + + // Test for AsyncContext.getRequest() + public void getRequestTest7(final ServletRequest request, + ServletResponse response) throws IOException { + final AsyncContext ac = request.startAsync(request, response); + Timer asyncTimer = new Timer("AsyncTimer", true); + asyncTimer.schedule(new TimerTask() { + + @Override + public void run() { + try { + if (ac.getRequest() == request) { + ac.getResponse().getWriter() + .println("getRequest() worked. Test PASSED."); + } else { + ac.getResponse().getWriter() + .println("getRequest() didnot work as expected. Test FAILED."); + } + ac.complete(); + } catch (java.io.IOException ioe) { + ioe.printStackTrace(); + } + } + }, 0); + + } + + // Test for AsyncContext.getRequest() + public void getRequestTest8(ServletRequest request, ServletResponse response) + throws IOException { + final RequestWrapper newRequest = new RequestWrapper(request); + ResponseWrapper newResponse = new ResponseWrapper(response); + + final AsyncContext ac = request.startAsync(newRequest, newResponse); + + Timer asyncTimer = new Timer("AsyncTimer", true); + asyncTimer.schedule(new TimerTask() { + + @Override + public void run() { + try { + if (ac.getRequest() == newRequest) { + ac.getResponse().getWriter() + .println("getRequest() worked. Test PASSED."); + } else { + ac.getResponse().getWriter() + .println("getRequest() didnot work as expected. Test FAILED."); + } + ac.complete(); + } catch (java.io.IOException ioe) { + ioe.printStackTrace(); + } + } + }, 0); + + } + + // Test for AsyncContext.getRequest() + public void getRequestTest9(final ServletRequest request, + ServletResponse response) throws IOException { + ResponseWrapper newResponse = new ResponseWrapper(response); + + final AsyncContext ac = request.startAsync(request, newResponse); + + Timer asyncTimer = new Timer("AsyncTimer", true); + asyncTimer.schedule(new TimerTask() { + + @Override + public void run() { + try { + if (ac.getRequest() == request) { + ac.getResponse().getWriter() + .println("getRequest() worked. Test PASSED."); + } else { + ac.getResponse().getWriter() + .println("getRequest() didnot work as expected. Test FAILED."); + } + ac.complete(); + } catch (java.io.IOException ioe) { + ioe.printStackTrace(); + } + } + }, 0); + + } + + // Test for AsyncContext.getRequest() + public void getRequestTest10(ServletRequest request, ServletResponse response) + throws IOException { + final RequestWrapper newRequest = new RequestWrapper(request); + + final AsyncContext ac = request.startAsync(newRequest, response); + + Timer asyncTimer = new Timer("AsyncTimer", true); + asyncTimer.schedule(new TimerTask() { + + @Override + public void run() { + try { + if (ac.getRequest() == newRequest) { + ac.getResponse().getWriter() + .println("getRequest() worked. Test PASSED."); + } else { + ac.getResponse().getWriter() + .println("getRequest() didnot work as expected. Test FAILED."); + } + ac.complete(); + } catch (java.io.IOException ioe) { + ioe.printStackTrace(); + } + } + }, 0); + } + + // Test for AsyncContext.getRequest() + public void getRequestTest12(final ServletRequest request, + ServletResponse response) throws IOException { + final AsyncContext ac = request.startAsync(); + + ac.start(new TimerTask() { + + @Override + public void run() { + try { + if (ac.getRequest() == request) { + ac.getResponse().getWriter() + .println("getRequest() worked. Test PASSED."); + } else { + ac.getResponse().getWriter() + .println("getRequest() didnot work as expected. Test FAILED."); + } + ac.complete(); + } catch (java.io.IOException ioe) { + ioe.printStackTrace(); + } + } + }); + } + + // Test for AsyncContext.getRequest() + public void getRequestTest13(final ServletRequest request, + ServletResponse response) throws IOException { + final AsyncContext ac = request.startAsync(request, response); + + ac.start(new TimerTask() { + + @Override + public void run() { + try { + if (ac.getRequest() == request) { + ac.getResponse().getWriter() + .println("getRequest() worked. Test PASSED."); + } else { + ac.getResponse().getWriter() + .println("getRequest() didnot work as expected. Test FAILED."); + } + ac.complete(); + } catch (java.io.IOException ioe) { + ioe.printStackTrace(); + } + } + }); + + } + + // Test for AsyncContext.getRequest() + public void getRequestTest14(ServletRequest request, ServletResponse response) + throws IOException { + final RequestWrapper newRequest = new RequestWrapper(request); + ResponseWrapper newResponse = new ResponseWrapper(response); + + final AsyncContext ac = request.startAsync(newRequest, newResponse); + + ac.start(new TimerTask() { + + @Override + public void run() { + try { + if (ac.getRequest() == newRequest) { + ac.getResponse().getWriter() + .println("getRequest() worked. Test PASSED."); + } else { + ac.getResponse().getWriter() + .println("getRequest() didnot work as expected. Test FAILED."); + } + ac.complete(); + } catch (java.io.IOException ioe) { + ioe.printStackTrace(); + } + } + }); + + } + + // Test for AsyncContext.getRequest() + public void getRequestTest15(final ServletRequest request, + ServletResponse response) throws IOException { + ResponseWrapper newResponse = new ResponseWrapper(response); + + final AsyncContext ac = request.startAsync(request, newResponse); + + ac.start(new TimerTask() { + + @Override + public void run() { + try { + if (ac.getRequest() == request) { + ac.getResponse().getWriter() + .println("getRequest() worked. Test PASSED."); + } else { + ac.getResponse().getWriter() + .println("getRequest() didnot work as expected. Test FAILED."); + } + ac.complete(); + } catch (java.io.IOException ioe) { + ioe.printStackTrace(); + } + } + }); + + } + + // Test for AsyncContext.getRequest() + public void getRequestTest16(ServletRequest request, ServletResponse response) + throws IOException { + final RequestWrapper newRequest = new RequestWrapper(request); + + final AsyncContext ac = request.startAsync(newRequest, response); + + ac.start(new TimerTask() { + + @Override + public void run() { + try { + if (ac.getRequest() == newRequest) { + ac.getResponse().getWriter() + .println("getRequest() worked. Test PASSED."); + } else { + ac.getResponse().getWriter() + .println("getRequest() didnot work as expected. Test FAILED."); + } + ac.complete(); + } catch (java.io.IOException ioe) { + ioe.printStackTrace(); + } + } + }); + } + + // Test for AsyncContext.createListener and + // AsyncContext.addListener(AsyncListener) + public void asyncListenerTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + AsyncContext ac = request.startAsync(); + AsyncListener acl = ac.createListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.asynccontext.ACListener.class); + ac.addListener(acl); + + ac.complete(); + } + + // Negative test for AsyncContext.createListener + public void asyncListenerTest1(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + long timeout_set = 5015L; + + AsyncContext ac = request.startAsync(); + response.getWriter().println("Default timeout: " + ac.getTimeout()); + + try { + AsyncListener acl = ac.createListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.asynccontext.ACListenerBad.class); + response.getWriter() + .println("Test FAILED without throwing expected exception."); + } catch (ServletException ex) { + response.getWriter() + .println("Test PASSED with exception: " + ex.getMessage()); + } catch (Exception ex1) { + response.getWriter().println( + "Test FAILED with wrong type exception: " + ex1.getMessage()); + } + ac.complete(); + } + + // Test for AsyncContext.createListener and + // AsyncContext.addListener(AsyncListener, ServletRequest, ServletResponse) + public void asyncListenerTest2(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + AsyncContext ac = request.startAsync(); + AsyncListener acl = ac.createListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.asynccontext.ACListener.class); + ac.addListener(acl, request, response); + + ac.complete(); + } + + // Test for AsyncContext.createListener and + // AsyncContext.addListener(AsyncListener) + public void asyncListenerTest5(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + final AsyncContext ac = request.startAsync(); + + AsyncListener acl = ac.createListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.asynccontext.ACListener.class); + ac.addListener(acl); + ac.start(new TimerTask() { + + @Override + public void run() { + ac.complete(); + + } + }); + } + + // Negative test for AsyncContext.createListener + public void asyncListenerTest6(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + long timeout_set = 5015L; + + final AsyncContext ac = request.startAsync(); + response.getWriter().println("Default timeout: " + ac.getTimeout()); + + try { + AsyncListener acl = ac.createListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.asynccontext.ACListenerBad.class); + response.getWriter() + .println("Test FAILED without throwing expected exception."); + } catch (ServletException ex) { + response.getWriter() + .println("Test PASSED with exception: " + ex.getMessage()); + } catch (Exception ex1) { + response.getWriter().println( + "Test FAILED with wrong type exception: " + ex1.getMessage()); + } + + ac.start(new TimerTask() { + + @Override + public void run() { + ac.complete(); + + } + }); + } + + // Test for AsyncContext.createListener and + // AsyncContext.addListener(AsyncListener, ServletRequest, ServletResponse) + public void asyncListenerTest7(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + final AsyncContext ac = request.startAsync(); + AsyncListener acl = ac.createListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.asynccontext.ACListener.class); + ac.addListener(acl, request, response); + + ac.start(new TimerTask() { + + @Override + public void run() { + ac.complete(); + + } + }); + } + + // Test for AsyncContext.setTimeout and AsyncContext.getTimeout + public void timeOutTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + long timeout_set = 5015L; + long timeout_actual; + + AsyncContext ac = request.startAsync(); + response.getWriter().println("Default timeout: " + ac.getTimeout()); + + ac.setTimeout(timeout_set); + timeout_actual = ac.getTimeout(); + + if (timeout_actual == timeout_set) { + response.getWriter().println("Test PASSED."); + } else { + response.getWriter() + .println("Test FAILED. setTimeout to " + timeout_set); + response.getWriter().println("getTimeout returned " + timeout_actual); + } + + ac.complete(); + } + + // Test for AsyncContext.setTimeout(0L) and AsyncContext.getTimeout + public void timeOutTest1(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + long timeout_set = 0L; + long timeout_actual; + + AsyncContext ac = request.startAsync(); + ac.setTimeout(timeout_set); + timeout_actual = ac.getTimeout(); + + if (timeout_actual == timeout_set) { + response.getWriter().println("Test PASSED."); + } else { + response.getWriter() + .println("Test FAILED. setTimeout to " + timeout_set); + response.getWriter().println("getTimeout returned " + timeout_actual); + } + + ac.complete(); + } + + // Test for AsyncContext.createListener, + // AsyncContext.addListener(AsyncListener), and timeout + public void timeOutTest2(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + long timeout_default; + + AsyncContext ac = request.startAsync(); + timeout_default = ac.getTimeout(); + response.getWriter().println("Default timeout: " + timeout_default); + AsyncListener acl2 = ac.createListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.asynccontext.ACListener2.class); + ac.addListener(acl2); + + ac.setTimeout(timeout_default); + + try { + Thread.sleep(timeout_default * 2); + } catch (InterruptedException ex) { + response.getWriter() + .println("Test FAILED with exception: " + ex.getMessage()); + } + } + + // Test for AsyncContext.createListener, + // AsyncContext.addListener(AsyncListener), and AsyncContext.setTimeout(0L) + public void timeOutTest3(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + long timeout_default; + + AsyncContext ac = request.startAsync(); + timeout_default = ac.getTimeout(); + response.getWriter().println("Default timeout: " + timeout_default); + AsyncListener acl = ac.createListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.asynccontext.ACListener.class); + ac.addListener(acl); + + ac.setTimeout(0L); + + try { + if (timeout_default * 5 < 3000000L) { + Thread.sleep(timeout_default * 5); + } else { + Thread.sleep(3000000L); + } + } catch (InterruptedException ex) { + response.getWriter() + .println("Test FAILED with exception: " + ex.getMessage()); + } + ac.complete(); + } + + // Test for AsyncContext.createListener, + // AsyncContext.addListener(AsyncListener), and AsyncContext timeout + public void timeOutTest4(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + long timeout_default; + + AsyncContext ac = request.startAsync(); + timeout_default = ac.getTimeout(); + response.getWriter().println("Default timeout: " + timeout_default); + AsyncListener acl2 = ac.createListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.asynccontext.ACListener2.class); + ac.addListener(acl2); + + try { + Thread.sleep(timeout_default + 18000L); + } catch (InterruptedException ex) { + response.getWriter() + .println("Test FAILED with exception: " + ex.getMessage()); + } + } + + // Test for AsyncContext.hasOriginalRequestAndResponse() + public void originalRequestTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + AsyncContext ac = request.startAsync(); + if (ac.hasOriginalRequestAndResponse()) { + response.getWriter().println( + "Test PASSED. AsyncContext.hasOriginalRequestAndRespons()=true"); + } else { + response.getWriter().println( + "Test FAILED. AsyncContext.hasOriginalRequestAndRespons()=false"); + } + ac.complete(); + } + + // Test for AsyncContext.hasOriginalRequestAndResponse() + public void originalRequestTest1(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + AsyncContext ac = request.startAsync(request, response); + if (ac.hasOriginalRequestAndResponse()) { + response.getWriter().println( + "Test PASSED. AsyncContext.hasOriginalRequestAndRespons()=true"); + } else { + response.getWriter().println( + "Test FAILED. AsyncContext.hasOriginalRequestAndRespons()=false"); + } + ac.complete(); + } + + // Negative test for AsyncContext.hasOriginalRequestAndResponse() + public void originalRequestTest2(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + AsyncContext ac = request.startAsync(new RequestWrapper(request), + new ResponseWrapper(response)); + if (ac.hasOriginalRequestAndResponse()) { + response.getWriter().println( + "Test FAILED. AsyncContext.hasOriginalRequestAndRespons()=true"); + } else { + response.getWriter().println( + "Test PASSED. AsyncContext.hasOriginalRequestAndRespons()=false"); + } + ac.complete(); + } + + // Negative test for AsyncContext.hasOriginalRequestAndResponse() + public void originalRequestTest3(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + AsyncContext ac = request.startAsync(new RequestWrapper(request), response); + if (ac.hasOriginalRequestAndResponse()) { + response.getWriter().println( + "Test FAILED. AsyncContext.hasOriginalRequestAndRespons()=true"); + } else { + response.getWriter().println( + "Test PASSED. AsyncContext.hasOriginalRequestAndRespons()=false"); + } + ac.complete(); + } + + // Negative test for AsyncContext.hasOriginalRequestAndResponse() + public void originalRequestTest4(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + AsyncContext ac = request.startAsync(request, + new ResponseWrapper(response)); + if (ac.hasOriginalRequestAndResponse()) { + response.getWriter().println( + "Test FAILED. AsyncContext.hasOriginalRequestAndRespons()=true"); + } else { + response.getWriter().println( + "Test PASSED. AsyncContext.hasOriginalRequestAndRespons()=false"); + } + ac.complete(); + } + + // Test for AsyncContext.getResponse() + public void getResponseTest(ServletRequest request, ServletResponse response) + throws IOException { + String path = "/async/AsyncTests?testname=asyncTest"; + + AsyncContext ac = request.startAsync(); + if (ac.getResponse() == response) { + response.getWriter().println("getResponse() worked. Test PASSED."); + } else { + response.getWriter() + .println("getResponse() didnot work as expected. Test FAILED."); + } + ac.complete(); + } + + // Test for AsyncContext.getResponse() + public void getResponseTest1(ServletRequest request, ServletResponse response) + throws IOException { + + AsyncContext ac = request.startAsync(request, response); + if (ac.getResponse() == response) { + response.getWriter().println("getResponse() worked. Test PASSED."); + } else { + response.getWriter() + .println("getResponse() didnot work as expected. Test FAILED."); + } + ac.complete(); + } + + // Test for AsyncContext.getResponse() + public void getResponseTest2(ServletRequest request, ServletResponse response) + throws IOException { + RequestWrapper newRequest = new RequestWrapper(request); + ResponseWrapper newResponse = new ResponseWrapper(response); + + AsyncContext ac = request.startAsync(newRequest, newResponse); + + if (ac.getResponse() == newResponse) { + response.getWriter().println("getResponse() worked. Test PASSED."); + } else { + response.getWriter() + .println("getResponse() didnot work as expected. Test FAILED."); + } + ac.complete(); + } + + // Test for AsyncContext.getResponse() + public void getResponseTest3(ServletRequest request, ServletResponse response) + throws IOException { + ResponseWrapper newResponse = new ResponseWrapper(response); + + AsyncContext ac = request.startAsync(request, newResponse); + + if (ac.getResponse() == newResponse) { + response.getWriter().println("getResponse() worked. Test PASSED."); + } else { + response.getWriter() + .println("getResponse() didnot work as expected. Test FAILED."); + } + ac.complete(); + } + + // Test for AsyncContext.getResponse() + public void getResponseTest4(ServletRequest request, ServletResponse response) + throws IOException { + RequestWrapper newRequest = new RequestWrapper(request); + + AsyncContext ac = request.startAsync(newRequest, response); + + if (ac.getResponse() == response) { + response.getWriter().println("getResponse() worked. Test PASSED."); + } else { + response.getWriter() + .println("getResponse() didnot work as expected. Test FAILED."); + } + ac.complete(); + } + + // Test for ServletRequest.startAsync() called twice + public void startAsyncAgainTest(ServletRequest request, + ServletResponse response) throws IOException { + + response.getWriter().println("ASYNC_NOT_STARTED_startAsyncAgainTest"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(); + response.getWriter().println("startAsync called"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + try { + request.startAsync(); + } catch (java.lang.IllegalStateException ex) { + response.getWriter().println("startAsync called again"); + response.getWriter() + .println("Expected IllegalStateException thrown" + ex.getMessage()); + } + + ac.complete(); + } + + // Test for ServletRequest.startAsync(request, response) called twice + public void startAsyncAgainTest1(ServletRequest request, + ServletResponse response) throws IOException { + + response.getWriter().println("ASYNC_NOT_STARTED_startAsyncAgainTest1"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(request, response); + response.getWriter().println("startAsync called"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + try { + request.startAsync(request, response); + } catch (java.lang.IllegalStateException ex) { + response.getWriter().println("startAsync called again"); + response.getWriter() + .println("Expected IllegalStateException thrown" + ex.getMessage()); + } + ac.complete(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asynccontext/AsyncTests.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asynccontext/AsyncTests.java new file mode 100644 index 0000000000..2abc17d808 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asynccontext/AsyncTests.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2009, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.asynccontext; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class AsyncTests extends GenericServlet { + + private static final String TEST_HEADER = "testname"; + + private static final Class[] TEST_ARGS = { ServletRequest.class, + ServletResponse.class }; + + public void service(ServletRequest req, ServletResponse res) + throws ServletException, IOException { + String test = req.getParameter(TEST_HEADER); + try { + Method method = this.getClass().getMethod(test, TEST_ARGS); + method.invoke(this, new Object[] { req, res }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + } + + public void asyncTest(ServletRequest request, ServletResponse response) + throws IOException { + response.getWriter().println("ASYNC_STARTED_asyncTest"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asynccontext/RequestWrapper.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asynccontext/RequestWrapper.java new file mode 100644 index 0000000000..2be9bb764b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asynccontext/RequestWrapper.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2011, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.asynccontext; + +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletRequestWrapper; + +public class RequestWrapper extends ServletRequestWrapper { + + protected ServletRequest origRequest = null; + + public RequestWrapper(ServletRequest request) { + super(request); + origRequest = request; + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asynccontext/ResponseWrapper.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asynccontext/ResponseWrapper.java new file mode 100644 index 0000000000..f255fad816 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asynccontext/ResponseWrapper.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2011, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.asynccontext; + +import jakarta.servlet.ServletResponse; +import jakarta.servlet.ServletResponseWrapper; + +public class ResponseWrapper extends ServletResponseWrapper { + + protected ServletResponse origResponse = null; + + public ResponseWrapper(ServletResponse response) { + super(response); + response.setContentType("text/plain"); + origResponse = response; + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asynccontext/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asynccontext/URLClient.java new file mode 100644 index 0000000000..f6c4bf9af4 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asynccontext/URLClient.java @@ -0,0 +1,831 @@ +/* + * Copyright (c) 2009, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.asynccontext; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("AsyncTestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_asynccontext_web.war") + .addClasses(ACListener.class, ACListener1.class, ACListener2.class) + .addClasses(ACListenerBad.class, AsyncTests.class, AsyncTestServlet.class) + .addClasses(RequestWrapper.class, ResponseWrapper.class) + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .setWebXML(URLClient.class.getResource("servlet_js_asynccontext_web.xml")); + } + + + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + /* + * Test set up: + * + * Define two servets AsyncTestServlet and AsyncTests that supports async in + * web.xml; Define three AsyncListeners using annotation: ACListener, + * ACListener1, ACListenerBad; - ACListener1 does not complete properly - + * ACListenerBad does not instantiate; Define a ServletRequestWrapper that + * wraps the original request; Define a ServletResponseWrapper that wraps the + * original response; + * + */ + + /* + * @testName: dispatchZeroArgTest + * + * @assertion_ids: Servlet:JAVADOC:639; Servlet:JAVADOC:639.2; + * Servlet:JAVADOC:639.4; Servlet:JAVADOC:703; Servlet:JAVADOC:707; + * Servlet:JAVADOC:708; Servlet:JAVADOC:710; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which supports async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet + * ServletRequest.startAsync(); call ac.dispatch(); call + * ServletRequest.isAsyncSupported() call ServletRequest.isAsyncStarted() call + * ServletRequest.getDispatcherType() verifies all work accordingly. + */ + @Test + public void dispatchZeroArgTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "dispatchZeroArgTest"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_dispatchZeroArgTest|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "ASYNC_STARTED_dispatchZeroArgTest|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: dispatchZeroArgTest1 + * + * @assertion_ids: Servlet:JAVADOC:639; Servlet:JAVADOC:639.2; + * Servlet:JAVADOC:639.4; Servlet:JAVADOC:703; Servlet:JAVADOC:707; + * Servlet:JAVADOC:708; Servlet:JAVADOC:710; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which supports async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet + * ServletRequest.startAsync(ServletRequest, ServletResponse); call + * ac.dispatch(); call ServletRequest.isAsyncSupported() call + * ServletRequest.isAsyncStarted() call ServletRequest.getDispatcherType() + * verifies all work accordingly. + */ + @Test + public void dispatchZeroArgTest1() throws Exception { + TEST_PROPS.setProperty(APITEST, "dispatchZeroArgTest1"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_dispatchZeroArgTest1|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "ASYNC_STARTED_dispatchZeroArgTest1|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: dispatchZeroArgTest2 + * + * @assertion_ids: Servlet:JAVADOC:639; Servlet:JAVADOC:639.2; + * Servlet:JAVADOC:639.4; Servlet:JAVADOC:703; Servlet:JAVADOC:707; + * Servlet:JAVADOC:708; Servlet:JAVADOC:710; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which supports async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet + * ServletRequest.startAsync(ServletRequestWrapper, ServletResponseWrapper); + * call ac.dispatch(); call ServletRequest.isAsyncSupported() call + * ServletRequest.isAsyncStarted() call ServletRequest.getDispatcherType() + * verifies all work accordingly. + */ + @Test + public void dispatchZeroArgTest2() throws Exception { + TEST_PROPS.setProperty(APITEST, "dispatchZeroArgTest2"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_dispatchZeroArgTest2|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "ASYNC_STARTED_dispatchZeroArgTest2|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: dispatchContextPathTest + * + * @assertion_ids: Servlet:JAVADOC:641; Servlet:JAVADOC:703; + * Servlet:JAVADOC:707; Servlet:JAVADOC:708; Servlet:JAVADOC:710; + * + * @test_Strategy: Create two Servlets AsyncTestServlet and AsynTest both + * support async; Client send a request to AsyncTestServlet; StartAsync in + * AsyncTestServlet ServletRequest.startAsync(); call + * ac.dispatch(ServletContext, path to AsynTest); call + * ServletRequest.isAsyncSupported() call ServletRequest.isAsyncStarted() call + * ServletRequest.getDispatcherType() verifies all work accordingly. + */ + @Test + public void dispatchContextPathTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "dispatchContextPathTest"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_dispatchContextPathTest|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "ASYNC_STARTED_asyncTest|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: dispatchContextPathTest1 + * + * @assertion_ids: Servlet:JAVADOC:641; Servlet:JAVADOC:703; + * Servlet:JAVADOC:707; Servlet:JAVADOC:708; Servlet:JAVADOC:710; + * + * @test_Strategy: Create two Servlets AsyncTestServlet and AsynTest both + * support async; Client send a request to AsyncTestServlet; StartAsync in + * AsyncTestServlet ServletRequest.startAsync(ServletRequest, + * ServletResponse); call ac.dispatch(ServletContext, path to AsynTest); call + * ServletRequest.isAsyncSupported() call ServletRequest.isAsyncStarted() call + * ServletRequest.getDispatcherType() verifies all work accordingly. + */ + @Test + public void dispatchContextPathTest1() throws Exception { + TEST_PROPS.setProperty(APITEST, "dispatchContextPathTest1"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_dispatchContextPathTest1|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "ASYNC_STARTED_asyncTest|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: dispatchContextPathTest2 + * + * @assertion_ids: Servlet:JAVADOC:641; Servlet:JAVADOC:703; + * Servlet:JAVADOC:707; Servlet:JAVADOC:708; Servlet:JAVADOC:710; + * + * @test_Strategy: Create two Servlets AsyncTestServlet and AsynTest both + * support async; Client send a request to AsyncTestServlet; StartAsync in + * AsyncTestServlet ServletRequest.startAsync(ServletRequestWrapper, + * ServletResponseWrapper); call ac.dispatch(ServletContext, path to + * AsynTest); call ServletRequest.isAsyncSupported() call + * ServletRequest.isAsyncStarted() call ServletRequest.getDispatcherType() + * verifies all work accordingly. + */ + @Test + public void dispatchContextPathTest2() throws Exception { + TEST_PROPS.setProperty(APITEST, "dispatchContextPathTest2"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_dispatchContextPathTest2|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "ASYNC_STARTED_asyncTest|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: forwardTest1 + * + * @assertion_ids: Servlet:JAVADOC:639; Servlet:JAVADOC:639.2; + * Servlet:JAVADOC:639.4; Servlet:JAVADOC:703; Servlet:JAVADOC:707; + * Servlet:JAVADOC:708; Servlet:JAVADOC:710; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which supports async; + * Client send a request to AsyncTestServlet at + * "/AsyncTestServlet?testname=forwardTest1"; + * getRequestDispatcher("/AsyncTestServlet?testname=forwardDummy1").forward( + * request, response); In forwardDummy1: AsyncContext ac = + * request.startAsync(request, response); ac.dispatch(); verifies that it + * dispatches to "/AsyncTestServlet?testname=forwardDummy1". + */ + @Test + public void forwardTest1() throws Exception { + TEST_PROPS.setProperty(APITEST, "forwardTest1"); + TEST_PROPS.setProperty(SEARCH_STRING, + "forwardDummy1|" + "ASYNC_NOT_STARTED_forwardDummy1|" + + "IsAsyncSupported=true|" + "IsAsyncStarted=false|" + + "DispatcherType=FORWARD|" + "forwardDummy1|" + + "ASYNC_STARTED_forwardDummy1|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, + "ASYNC_STARTED_forwardTest1"); + invoke(); + } + + /* + * @testName: getRequestTest + * + * @assertion_ids: Servlet:JAVADOC:642; Servlet:JAVADOC:710; + * Servlet:JAVADOC:710.1; Servlet:SPEC:270; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet + * ServletRequest.startAsync(); call AsyncContext.getRequest() verifies it + * works. + */ + @Test + public void getRequestTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getRequestTest"); + invoke(); + } + + /* + * @testName: getRequestTest1 + * + * @assertion_ids: Servlet:JAVADOC:642; Servlet:JAVADOC:712; + * Servlet:JAVADOC:712.1; Servlet:SPEC:270; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet + * ServletRequest.startAsync(Request, Response); call + * AsyncContext.getRequest() verifies it works. + */ + @Test + public void getRequestTest1() throws Exception { + TEST_PROPS.setProperty(APITEST, "getRequestTest1"); + invoke(); + } + + /* + * @testName: getRequestTest2 + * + * @assertion_ids: Servlet:JAVADOC:642; Servlet:JAVADOC:712; + * Servlet:JAVADOC:712.1; Servlet:SPEC:270; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet + * ServletRequest.startAsync(RequestWrapper, ResponseWrapper); call + * AsyncContext.getRequest() verifies it works. + */ + @Test + public void getRequestTest2() throws Exception { + TEST_PROPS.setProperty(APITEST, "getRequestTest2"); + invoke(); + } + + /* + * @testName: getRequestTest3 + * + * @assertion_ids: Servlet:JAVADOC:642; Servlet:JAVADOC:712; + * Servlet:JAVADOC:712.1; Servlet:SPEC:270; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet + * ServletRequest.startAsync(Request, ResponseWrapper); call + * AsyncContext.getRequest() verifies it works. + */ + @Test + public void getRequestTest3() throws Exception { + TEST_PROPS.setProperty(APITEST, "getRequestTest3"); + invoke(); + } + + /* + * @testName: getRequestTest4 + * + * @assertion_ids: Servlet:JAVADOC:642; Servlet:JAVADOC:712; + * Servlet:JAVADOC:712.1; Servlet:SPEC:270; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet + * ServletRequest.startAsync(RequestWrapper, Response); call + * AsyncContext.getRequest() verifies it works. + */ + @Test + public void getRequestTest4() throws Exception { + TEST_PROPS.setProperty(APITEST, "getRequestTest4"); + invoke(); + } + + /* + * @testName: getRequestTest6 + * + * @assertion_ids: Servlet:JAVADOC:642; Servlet:JAVADOC:710; + * Servlet:JAVADOC:710.1; Servlet:SPEC:270; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet + * ServletRequest.startAsync(); In a separate thread, call + * AsyncContext.getRequest() verifies it works. + */ + @Test + public void getRequestTest6() throws Exception { + TEST_PROPS.setProperty(APITEST, "getRequestTest6"); + invoke(); + } + + /* + * @testName: getRequestTest7 + * + * @assertion_ids: Servlet:JAVADOC:642; Servlet:JAVADOC:712; + * Servlet:JAVADOC:712.1; Servlet:SPEC:270; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet + * ServletRequest.startAsync(Request, Response); In a separate thread, call + * AsyncContext.getRequest() verifies it works. + */ + @Test + public void getRequestTest7() throws Exception { + TEST_PROPS.setProperty(APITEST, "getRequestTest7"); + invoke(); + } + + /* + * @testName: getRequestTest8 + * + * @assertion_ids: Servlet:JAVADOC:642; Servlet:JAVADOC:712; + * Servlet:JAVADOC:712.1; Servlet:SPEC:270; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet + * ServletRequest.startAsync(RequestWrapper, ResponseWrapper); In a separate + * thread, call AsyncContext.getRequest() verifies it works. + */ + @Test + public void getRequestTest8() throws Exception { + TEST_PROPS.setProperty(APITEST, "getRequestTest8"); + invoke(); + } + + /* + * @testName: getRequestTest9 + * + * @assertion_ids: Servlet:JAVADOC:642; Servlet:JAVADOC:712; + * Servlet:JAVADOC:712.1; Servlet:SPEC:270; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet + * ServletRequest.startAsync(Request, ResponseWrapper); In a separate thread, + * call AsyncContext.getRequest() verifies it works. + */ + @Test + public void getRequestTest9() throws Exception { + TEST_PROPS.setProperty(APITEST, "getRequestTest9"); + invoke(); + } + + /* + * @testName: getRequestTest10 + * + * @assertion_ids: Servlet:JAVADOC:642; Servlet:JAVADOC:712; + * Servlet:JAVADOC:712.1; Servlet:SPEC:270; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet + * ServletRequest.startAsync(RequestWrapper, Response); In a separate thread, + * call AsyncContext.getRequest() verifies it works. + */ + @Test + public void getRequestTest10() throws Exception { + TEST_PROPS.setProperty(APITEST, "getRequestTest10"); + invoke(); + } + + /* + * @testName: getRequestTest12 + * + * @assertion_ids: Servlet:JAVADOC:642; Servlet:JAVADOC:645; + * Servlet:JAVADOC:710; Servlet:JAVADOC:710.1; Servlet:SPEC:270; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet + * ServletRequest.startAsync(); In a separate thread, call + * AsyncContext.getRequest() verifies it works. + */ + @Test + public void getRequestTest12() throws Exception { + TEST_PROPS.setProperty(APITEST, "getRequestTest12"); + invoke(); + } + + /* + * @testName: getRequestTest13 + * + * @assertion_ids: Servlet:JAVADOC:642; Servlet:JAVADOC:645; + * Servlet:JAVADOC:712; Servlet:JAVADOC:712.1; Servlet:SPEC:270; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet + * ServletRequest.startAsync(Request, Response); In a separate thread, call + * AsyncContext.getRequest() verifies it works. + */ + @Test + public void getRequestTest13() throws Exception { + TEST_PROPS.setProperty(APITEST, "getRequestTest13"); + invoke(); + } + + /* + * @testName: getRequestTest14 + * + * @assertion_ids: Servlet:JAVADOC:642; Servlet:JAVADOC:645; + * Servlet:JAVADOC:712; Servlet:JAVADOC:712.1; Servlet:SPEC:270; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet + * ServletRequest.startAsync(RequestWrapper, ResponseWrapper); In a separate + * thread, call AsyncContext.getRequest() verifies it works. + */ + @Test + public void getRequestTest14() throws Exception { + TEST_PROPS.setProperty(APITEST, "getRequestTest14"); + invoke(); + } + + /* + * @testName: getRequestTest15 + * + * @assertion_ids: Servlet:JAVADOC:642; Servlet:JAVADOC:645; + * Servlet:JAVADOC:712; Servlet:JAVADOC:712.1; Servlet:SPEC:270; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet + * ServletRequest.startAsync(Request, ResponseWrapper); In a separate thread, + * call AsyncContext.getRequest() verifies it works. + */ + @Test + public void getRequestTest15() throws Exception { + TEST_PROPS.setProperty(APITEST, "getRequestTest15"); + invoke(); + } + + /* + * @testName: getRequestTest16 + * + * @assertion_ids: Servlet:JAVADOC:642; Servlet:JAVADOC:645; + * Servlet:JAVADOC:712; Servlet:JAVADOC:712.1; Servlet:SPEC:270; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet + * ServletRequest.startAsync(RequestWrapper, Response); In a separate thread, + * call AsyncContext.getRequest() verifies it works. + */ + @Test + public void getRequestTest16() throws Exception { + TEST_PROPS.setProperty(APITEST, "getRequestTest16"); + invoke(); + } + + /* + * @testName: asyncListenerTest1 + * + * @assertion_ids: Servlet:JAVADOC:649; Servlet:JAVADOC:710; + * Servlet:JAVADOC:846; Servlet:JAVADOC:866; Servlet:JAVADOC:873; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Create an AsyncListenerBad; Client send a request to AsyncTestServlet; + * StartAsync in AsyncTestServlet; AsyncContext.createistener(clazz) verifies + * ServletException is thrown when clazz fails to be instantiated. + */ + @Test + public void asyncListenerTest1() throws Exception { + TEST_PROPS.setProperty(APITEST, "asyncListenerTest1"); + invoke(); + } + + /* + * @testName: asyncListenerTest6 + * + * @assertion_ids: Servlet:JAVADOC:645; Servlet:JAVADOC:649; + * Servlet:JAVADOC:710; Servlet:JAVADOC:846; Servlet:JAVADOC:866; + * Servlet:JAVADOC:873; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Create an AsyncListenerBad; Client send a request to AsyncTestServlet; + * StartAsync in AsyncTestServlet; AsyncContext.createistener(clazz) In a + * separate thread, call AsyncContext.complete(); verifies ServletException is + * thrown when clazz fails to be instantiated. + */ + @Test + public void asyncListenerTest6() throws Exception { + TEST_PROPS.setProperty(APITEST, "asyncListenerTest6"); + invoke(); + } + + /* + * @testName: timeOutTest + * + * @assertion_ids: Servlet:JAVADOC:649; Servlet:JAVADOC:710; + * Servlet:JAVADOC:846; Servlet:JAVADOC:868; Servlet:JAVADOC:869; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet; + * AsyncContext.setTimeout(L) verifies it works using getTimeout. + */ + @Test + public void timeOutTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "timeOutTest"); + invoke(); + } + + /* + * @testName: timeOutTest1 + * + * @assertion_ids: Servlet:JAVADOC:649; Servlet:JAVADOC:710; + * Servlet:JAVADOC:846; Servlet:JAVADOC:868; Servlet:JAVADOC:868.1; + * Servlet:JAVADOC:869; Servlet:JAVADOC:869.3; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet; + * AsyncContext.setTimeout(0L) verifies it works using getTimeout. + */ + @Test + public void timeOutTest1() throws Exception { + TEST_PROPS.setProperty(APITEST, "timeOutTest1"); + invoke(); + } + + /* + * @testName: timeOutTest2 + * + * @assertion_ids: Servlet:JAVADOC:651; Servlet:JAVADOC:710; + * Servlet:JAVADOC:846; Servlet:JAVADOC:868; Servlet:JAVADOC:869; + * Servlet:JAVADOC:869.1; Servlet:JAVADOC:869.2; Servlet:JAVADOC:869.5; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet; + * AsyncContext.setTimeout(L) verifies it works by letting it timeout. + */ + @Test + public void timeOutTest2() throws Exception { + TEST_PROPS.setProperty(APITEST, "timeOutTest2"); + TEST_PROPS.setProperty(SEARCH_STRING, "in onTimeout method of ACListener2"); + TEST_PROPS.setProperty(STATUS_CODE, "-1"); + invoke(); + } + + /* + * @testName: timeOutTest4 + * + * @assertion_ids: Servlet:JAVADOC:651; Servlet:JAVADOC:710; + * Servlet:JAVADOC:846; Servlet:JAVADOC:868; Servlet:JAVADOC:869.4; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet; + * verifies it times out at default timeout. + */ + @Test + public void timeOutTest4() throws Exception { + TEST_PROPS.setProperty(APITEST, "timeOutTest4"); + TEST_PROPS.setProperty(SEARCH_STRING, "in onTimeout method of ACListener2"); + TEST_PROPS.setProperty(STATUS_CODE, "-1"); + invoke(); + } + + /* + * @testName: originalRequestTest + * + * @assertion_ids: Servlet:JAVADOC:638; Servlet:JAVADOC:644; + * Servlet:JAVADOC:710; Servlet:JAVADOC:710.2; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; Call ServletRequest.startAsync() + * in AsyncTestServlet; verifies AsyncContext.hasOriginalRequestAndResponse + * works. + */ + @Test + public void originalRequestTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "originalRequestTest"); + invoke(); + } + + /* + * @testName: originalRequestTest1 + * + * @assertion_ids: Servlet:JAVADOC:638; Servlet:JAVADOC:644; + * Servlet:JAVADOC:712; Servlet:JAVADOC:712.1; Servlet:JAVADOC:712.3; * + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; Call + * ServletRequest.startAsync(ServletRequest, ServletResponse); verifies + * AsyncContext.hasOriginalRequestAndResponse works. + */ + @Test + public void originalRequestTest1() throws Exception { + TEST_PROPS.setProperty(APITEST, "originalRequestTest1"); + invoke(); + } + + /* + * @testName: originalRequestTest2 + * + * @assertion_ids: Servlet:JAVADOC:638; Servlet:JAVADOC:644; + * Servlet:JAVADOC:712; Servlet:JAVADOC:712.1; Servlet:JAVADOC:712.3; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; Call + * ServletRequest.startAsync(ServletRequestWrapper, ServletResponseWrapper); + * verifies AsyncContext.hasOriginalRequestAndResponse works. + */ + @Test + public void originalRequestTest2() throws Exception { + TEST_PROPS.setProperty(APITEST, "originalRequestTest2"); + invoke(); + } + + /* + * @testName: originalRequestTest3 + * + * @assertion_ids: Servlet:JAVADOC:638; Servlet:JAVADOC:644; + * Servlet:JAVADOC:712; Servlet:JAVADOC:712.1; Servlet:JAVADOC:712.3; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; Call + * ServletRequest.startAsync(ServletRequestWrapper, ServletResponse); verifies + * AsyncContext.hasOriginalRequestAndResponse works. + */ + @Test + public void originalRequestTest3() throws Exception { + TEST_PROPS.setProperty(APITEST, "originalRequestTest3"); + invoke(); + } + + /* + * @testName: originalRequestTest4 + * + * @assertion_ids: Servlet:JAVADOC:638; Servlet:JAVADOC:644; + * Servlet:JAVADOC:712; Servlet:JAVADOC:712.1; Servlet:JAVADOC:712.3; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; Call + * ServletRequest.startAsync(ServletRequest, ServletResponseWrapper); verifies + * AsyncContext.hasOriginalRequestAndResponse works. + */ + @Test + public void originalRequestTest4() throws Exception { + TEST_PROPS.setProperty(APITEST, "originalRequestTest4"); + invoke(); + } + + /* + * @testName: getResponseTest + * + * @assertion_ids: Servlet:JAVADOC:643; Servlet:JAVADOC:710; + * Servlet:JAVADOC:710.1; Servlet:SPEC:271; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet + * ServletRequest.startAsync(); call AsyncContext.getResponse() verifies it + * works. + */ + @Test + public void getResponseTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getResponseTest"); + invoke(); + } + + /* + * @testName: getResponseTest1 + * + * @assertion_ids: Servlet:JAVADOC:643; Servlet:JAVADOC:712; + * Servlet:JAVADOC:712.1; Servlet:SPEC:271; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet + * ServletRequest.startAsync(Request, Response); call + * AsyncContext.getResponse() verifies it works. + */ + @Test + public void getResponseTest1() throws Exception { + TEST_PROPS.setProperty(APITEST, "getResponseTest1"); + invoke(); + } + + /* + * @testName: getResponseTest2 + * + * @assertion_ids: Servlet:JAVADOC:643; Servlet:JAVADOC:712; + * Servlet:JAVADOC:712.1; Servlet:SPEC:271; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet + * ServletRequest.startAsync(RequestWrapper, ResponseWrapper); call + * AsyncContext.getResponse() verifies it works. + */ + @Test + public void getResponseTest2() throws Exception { + TEST_PROPS.setProperty(APITEST, "getResponseTest2"); + invoke(); + } + + /* + * @testName: getResponseTest3 + * + * @assertion_ids: Servlet:JAVADOC:643; Servlet:JAVADOC:712; + * Servlet:JAVADOC:712.1; Servlet:SPEC:271; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet + * ServletRequest.startAsync(Request, ResponseWrapper); call + * AsyncContext.getResponse() verifies it works. + */ + @Test + public void getResponseTest3() throws Exception { + TEST_PROPS.setProperty(APITEST, "getResponseTest3"); + invoke(); + } + + /* + * @testName: getResponseTest4 + * + * @assertion_ids: Servlet:JAVADOC:643; Servlet:JAVADOC:712; + * Servlet:JAVADOC:712.1; Servlet:SPEC:271; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet + * ServletRequest.startAsync(RequestWrapper, Response); call + * AsyncContext.getResponse() verifies it works. + */ + @Test + public void getResponseTest4() throws Exception { + TEST_PROPS.setProperty(APITEST, "getResponseTest4"); + invoke(); + } + + /* + * @testName: startAsyncAgainTest + * + * @assertion_ids: Servlet:JAVADOC:639; Servlet:JAVADOC:639.2; + * Servlet:JAVADOC:639.3; Servlet:JAVADOC:639.4; Servlet:JAVADOC:639.5; + * Servlet:JAVADOC:639.9; Servlet:JAVADOC:703; Servlet:JAVADOC:707; + * Servlet:JAVADOC:708; Servlet:JAVADOC:710; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which supports async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet + * ServletRequest.startAsync(); call ServletRequest.isAsyncSupported() call + * ServletRequest.isAsyncStarted() call ServletRequest.getDispatcherType() + * StartAsync again verifies all work accordingly. + */ + @Test + public void startAsyncAgainTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "startAsyncAgainTest"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_startAsyncAgainTest|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "startAsync called|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=true|" + "DispatcherType=REQUEST|" + + "startAsync called again|" + + "Expected IllegalStateException thrown"); + invoke(); + } + + /* + * @testName: startAsyncAgainTest1 + * + * @assertion_ids: Servlet:JAVADOC:639; Servlet:JAVADOC:639.2; + * Servlet:JAVADOC:639.3; Servlet:JAVADOC:639.4; Servlet:JAVADOC:639.5; + * Servlet:JAVADOC:639.9; Servlet:JAVADOC:703; Servlet:JAVADOC:707; + * Servlet:JAVADOC:708; Servlet:JAVADOC:712; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which supports async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet + * ServletRequest.startAsync(request,response); call + * ServletRequest.isAsyncSupported() call ServletRequest.isAsyncStarted() call + * ServletRequest.getDispatcherType() StartAsync again verifies all work + * accordingly. + */ + @Test + public void startAsyncAgainTest1() throws Exception { + TEST_PROPS.setProperty(APITEST, "startAsyncAgainTest1"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_startAsyncAgainTest1|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "startAsync called|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=true|" + "DispatcherType=REQUEST|" + + "startAsync called again|" + + "Expected IllegalStateException thrown"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asynccontext/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asynccontext/build.xml new file mode 100644 index 0000000000..681a1fc64b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asynccontext/build.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asynccontext/servlet_js_asynccontext_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asynccontext/servlet_js_asynccontext_web.xml new file mode 100644 index 0000000000..c73c8f2ff7 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asynccontext/servlet_js_asynccontext_web.xml @@ -0,0 +1,43 @@ + + + + + SerJaxSerasynccontext + + AsyncTestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.asynccontext.AsyncTestServlet + true + + + AsyncTests + com.sun.ts.tests.servlet.api.jakarta_servlet.asynccontext.AsyncTests + true + + + AsyncTestServlet + /AsyncTestServlet + + + AsyncTests + /async/AsyncTests + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asyncevent/AsyncTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asyncevent/AsyncTestServlet.java new file mode 100644 index 0000000000..d4cc6ba09e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asyncevent/AsyncTestServlet.java @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2009, 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.asyncevent; + +import java.io.IOException; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.AsyncEvent; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class AsyncTestServlet extends GenericTCKServlet { + + public void constructorTest1(ServletRequest request, ServletResponse response) + throws IOException { + AsyncContext ac = request.startAsync(); + AsyncEvent ae = new AsyncEvent(ac); + if (ae == null) { + response.getWriter().println( + "The constructor for AsyncEvent(AsyncContext) returned a null. Test FAILED"); + } else { + response.getWriter().println("Test PASSED"); + } + ac.complete(); + } + + public void constructorTest2(ServletRequest request, ServletResponse response) + throws IOException { + AsyncContext ac = request.startAsync(); + AsyncEvent ae = new AsyncEvent(ac, request, response); + if (ae == null) { + response.getWriter().println( + "The constructor for AsyncEvent(AsyncContext, ServletRequest, ServletResponse) returned a null. Test FAILED"); + } else { + response.getWriter().println("Test PASSED"); + } + ac.complete(); + } + + public void constructorTest3(ServletRequest request, ServletResponse response) + throws IOException { + AsyncContext ac = request.startAsync(); + AsyncEvent ae = new AsyncEvent(ac, new IOException("AsyncEvent")); + if (ae == null) { + response.getWriter().println( + "The constructor for AsyncEvent(AsyncContext, Throwable) returned a null. Test FAILED"); + } else { + response.getWriter().println("Test PASSED"); + } + ac.complete(); + } + + public void constructorTest4(ServletRequest request, ServletResponse response) + throws IOException { + AsyncContext ac = request.startAsync(); + AsyncEvent ae = new AsyncEvent(ac, request, response, + new IOException("AsyncEvent")); + if (ae == null) { + response.getWriter().println( + "The constructor for AsyncEvent(AsyncContext, Throwable) returned a null. Test FAILED"); + } else { + response.getWriter().println("Test PASSED"); + } + ac.complete(); + } + + public void getSuppliedRequestTest1(ServletRequest request, + ServletResponse response) throws IOException { + AsyncContext ac = request.startAsync(); + AsyncEvent ae = new AsyncEvent(ac, request, response); + if (request != ae.getSuppliedRequest()) { + response.getWriter() + .println("getSuppliedRequest() returned are incorrect. Test FAILED"); + } else { + response.getWriter().println("Test PASSED"); + } + ac.complete(); + } + + public void getSuppliedRequestTest2(ServletRequest request, + ServletResponse response) throws IOException { + AsyncContext ac = request.startAsync(); + AsyncEvent ae = new AsyncEvent(ac, request, response, + new IOException("AsyncEvent")); + if (request != ae.getSuppliedRequest()) { + response.getWriter() + .println("getSuppliedRequest() returned are incorrect. Test FAILED"); + } else { + response.getWriter().println("Test PASSED"); + } + ac.complete(); + } + + public void getSuppliedResponseTest1(ServletRequest request, + ServletResponse response) throws IOException { + AsyncContext ac = request.startAsync(); + AsyncEvent ae = new AsyncEvent(ac, request, response); + if (response != ae.getSuppliedResponse()) { + response.getWriter() + .println("getSuppliedResponse() returned are incorrect. Test FAILED"); + } else { + response.getWriter().println("Test PASSED"); + } + ac.complete(); + } + + public void getSuppliedResponseTest2(ServletRequest request, + ServletResponse response) throws IOException { + AsyncContext ac = request.startAsync(); + AsyncEvent ae = new AsyncEvent(ac, request, response, + new IOException("AsyncEvent")); + if (response != ae.getSuppliedResponse()) { + response.getWriter() + .println("getSuppliedResponse() returned are incorrect. Test FAILED"); + } else { + response.getWriter().println("Test PASSED"); + } + ac.complete(); + } + + public void getThrowableTest(ServletRequest request, ServletResponse response) + throws IOException { + AsyncContext ac = request.startAsync(); + IOException ie = new IOException("AsyncEvent"); + AsyncEvent ae = new AsyncEvent(ac, request, response, ie); + if (ie != ae.getThrowable()) { + response.getWriter() + .println("getThrowable() returned are incorrect. Test FAILED"); + } else { + response.getWriter().println("Test PASSED"); + } + ac.complete(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asyncevent/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asyncevent/URLClient.java new file mode 100644 index 0000000000..b3e314e710 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asyncevent/URLClient.java @@ -0,0 +1,181 @@ +/* + * Copyright (c) 2009, 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.asyncevent; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import jakarta.servlet.GenericServlet; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("AsyncTestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_asyncevent_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(AsyncTestServlet.class, GenericTCKServlet.class, GenericServlet.class) + .setWebXML(URLClient.class.getResource("servlet_js_asyncevent_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + + /* + * @testName: constructorTest1 + * + * @assertion_ids: Servlet:JAVADOC:842; + * + * @test_Strategy: test the constructor AsyncEvent( AsyncContext ) + */ + @Test + public void constructorTest1() throws Exception { + TEST_PROPS.setProperty(APITEST, "constructorTest1"); + invoke(); + } + + /* + * @testName: constructorTest2 + * + * @assertion_ids: Servlet:JAVADOC:843; + * + * @test_Strategy: test the constructor AsyncEvent(AsyncContext, + * ServletRequest, ServletResponse) + */ + @Test + public void constructorTest2() throws Exception { + TEST_PROPS.setProperty(APITEST, "constructorTest2"); + invoke(); + } + + /* + * @testName: constructorTest3 + * + * @assertion_ids: Servlet:JAVADOC:844; + * + * @test_Strategy: test the constructor AsyncEvent(AsyncContext, Throwable) + */ + @Test + public void constructorTest3() throws Exception { + TEST_PROPS.setProperty(APITEST, "constructorTest3"); + invoke(); + } + + /* + * @testName: constructorTest4 + * + * @assertion_ids: Servlet:JAVADOC:845; + * + * @test_Strategy: test the constructor AsyncEvent(AsyncContext, + * ServletRequest, ServletResponse, Throwable) + */ + @Test + public void constructorTest4() throws Exception { + TEST_PROPS.setProperty(APITEST, "constructorTest4"); + invoke(); + } + + /* + * @testName: getSuppliedRequestTest1 + * + * @assertion_ids: Servlet:JAVADOC:847; + * + * @test_Strategy: test the constructor AsyncEvent(AsyncContext, + * ServletRequest, ServletResponse) verify AsyncEvent.getSuplliedRequest() + * works + */ + @Test + public void getSuppliedRequestTest1() throws Exception { + TEST_PROPS.setProperty(APITEST, "getSuppliedRequestTest1"); + invoke(); + } + + /* + * @testName: getSuppliedRequestTest2 + * + * @assertion_ids: Servlet:JAVADOC:847; + * + * @test_Strategy: test the constructor AsyncEvent(AsyncContext, + * ServletRequest, ServletResponse, Throwable) verify + * AsyncEvent.getSuplliedRequest() works + */ + @Test + public void getSuppliedRequestTest2() throws Exception { + TEST_PROPS.setProperty(APITEST, "getSuppliedRequestTest2"); + invoke(); + } + + /* + * @testName: getSuppliedResponseTest1 + * + * @assertion_ids: Servlet:JAVADOC:848; + * + * @test_Strategy: test the constructor AsyncEvent(AsyncContext, + * ServletRequest, ServletResponse) verify AsyncEvent.getSuplliedResponse() + * works + */ + @Test + public void getSuppliedResponseTest1() throws Exception { + TEST_PROPS.setProperty(APITEST, "getSuppliedResponseTest1"); + invoke(); + } + + /* + * @testName: getSuppliedResponseTest2 + * + * @assertion_ids: Servlet:JAVADOC:848; + * + * @test_Strategy: test the constructor AsyncEvent(AsyncContext, + * ServletRequest, ServletResponse, Throwable) verify + * AsyncEvent.getSuplliedResponse() works + */ + @Test + public void getSuppliedResponseTest2() throws Exception { + TEST_PROPS.setProperty(APITEST, "getSuppliedResponseTest2"); + invoke(); + } + + /* + * @testName: getThrowableTest + * + * @assertion_ids: Servlet:JAVADOC:849; + * + * @test_Strategy: test the constructor AsyncEvent(AsyncContext, + * ServletRequest, ServletResponse, Throwable) verify + * AsyncEvent.getThrowable() works + */ + @Test + public void getThrowableTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getThrowableTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asyncevent/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asyncevent/build.xml new file mode 100644 index 0000000000..11fef2f61c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asyncevent/build.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asyncevent/servlet_js_asyncevent_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asyncevent/servlet_js_asyncevent_web.xml new file mode 100644 index 0000000000..64c1679bbf --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/asyncevent/servlet_js_asyncevent_web.xml @@ -0,0 +1,34 @@ + + + + + AsyncEvent + + AsyncTestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.asyncevent.AsyncTestServlet + true + + + AsyncTestServlet + /AsyncTestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/build.xml new file mode 100644 index 0000000000..5add83ecd1 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/build.xml @@ -0,0 +1,22 @@ + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchertype/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchertype/TestServlet.java new file mode 100644 index 0000000000..d2f5303f55 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchertype/TestServlet.java @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2009, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchertype; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.DispatcherType; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void valuesTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + Boolean pass = true; + PrintWriter pw = response.getWriter(); + + DispatcherType[] types = jakarta.servlet.DispatcherType.values(); + DispatcherType[] expected_types = { DispatcherType.FORWARD, + DispatcherType.INCLUDE, DispatcherType.REQUEST, DispatcherType.ASYNC, + DispatcherType.ERROR }; + + int i = 0; + for (DispatcherType type : types) { + if (!type.equals(expected_types[i])) { + pw.println( + "The DispatcherType value at position " + i + " is incorrect."); + pw.println("Expecting " + expected_types[i] + "; got " + type + "."); + pass = false; + } + i++; + } + ServletTestUtil.printResult(pw, pass); + } + + public void valueOfTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + Boolean pass = true; + PrintWriter pw = response.getWriter(); + + String[] types = { "FORWARD", "INCLUDE", "REQUEST", "ASYNC", "ERROR" }; + DispatcherType[] expected_types = { DispatcherType.FORWARD, + DispatcherType.INCLUDE, DispatcherType.REQUEST, DispatcherType.ASYNC, + DispatcherType.ERROR }; + + int i = 0; + for (DispatcherType type : expected_types) { + if (!type.equals(DispatcherType.valueOf(types[i]))) { + pw.println("DispatcherType.valueOf does not work correctly."); + pw.println("Expecting " + expected_types[i] + "; got " + + DispatcherType.valueOf(types[i]) + "."); + pass = false; + } + i++; + } + ServletTestUtil.printResult(pw, pass); + } + + public void valueOfNullTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + Boolean pass = true; + PrintWriter pw = response.getWriter(); + String name = null; + + try { + DispatcherType.valueOf(name); + pass = false; + pw.println("DispatcherType.valueOf(null) does not work correctly."); + pw.println("Expected NullPointerException not thrown."); + } catch (NullPointerException npe) { + pw.println("Test Passed. Expected NullPointerException thrown for name =" + + name + "."); + } + + ServletTestUtil.printResult(pw, pass); + } + + public void valueOfInvalidTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + Boolean pass = true; + PrintWriter pw = response.getWriter(); + + String[] names = { "Forward", " INCLUDE", "REQUEST ", "ASYNc", "ERROr ", + "bogus" }; + + for (String name : names) { + try { + DispatcherType.valueOf(name); + pass = false; + pw.println( + "DispatcherType.valueOf(bad dispatchertype) does not work correctly."); + pw.println("Expected IllegalArgumentException not thrown."); + } catch (IllegalArgumentException ile) { + pw.println( + "Test Passed. Expected IllegalArgumentException thrown for name =" + + name + "."); + } + } + ServletTestUtil.printResult(pw, pass); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchertype/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchertype/URLClient.java new file mode 100644 index 0000000000..ef98137fb4 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchertype/URLClient.java @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2009, 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:$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchertype; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_dispatchertype_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClass(TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_js_dispatchertype_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + + /* + * @testName: valuesTest + * + * @assertion_ids: Servlet:JAVADOC:654; + * + * @test_Strategy: 1. Create a servlet - TestServlet 2. Client send a request + * to TestServlet 3. In TestServlet, call DispatcherType.values 4. Verify that + * DispatcherType.values works properly. + */ + @Test + public void valuesTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "valuesTest"); + invoke(); + } + + /* + * @testName: valueOfTest + * + * @assertion_ids: Servlet:JAVADOC:653; + * + * @test_Strategy: 1. Create a servlet - TestServlet 2. Client send a request + * to TestServlet 3. In TestServlet, call DispatcherType.valueOf 4. Verify + * that DispatcherType.valueOf works properly. + */ + @Test + public void valueOfTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "valueOfTest"); + invoke(); + } + /* + * @testName: valueOfNullTest + * + * @assertion_ids: Servlet:JAVADOC:653; + * + * @test_Strategy: 1. Create a servlet - TestServlet 2. Client send a request + * to TestServlet 3. In TestServlet, call DispatcherType.valueOf(String name) + * 4. Verify that DispatcherType.valueOf throws NullPointerException when name + * is null + */ + @Test + public void valueOfNullTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "valueOfNullTest"); + invoke(); + } + /* + * @testName: valueOfInvalidTest + * + * @assertion_ids: Servlet:JAVADOC:653; + * + * @test_Strategy: 1. Create a servlet - TestServlet 2. Client send a request + * to TestServlet 3. In TestServlet, call DispatcherType.valueOf(String name) + * 4. Verify that DispatcherType.valueOf throws IllegalArgumentException when + * name is invalid Dispatcher type + */ + @Test + public void valueOfInvalidTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "valueOfInvalidTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchertype/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchertype/build.xml new file mode 100644 index 0000000000..f56eb202f3 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchertype/build.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchertype/servlet_js_dispatchertype_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchertype/servlet_js_dispatchertype_web.xml new file mode 100644 index 0000000000..c4a8fd6356 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchertype/servlet_js_dispatchertype_web.xml @@ -0,0 +1,33 @@ + + + + + SerJaxSerdispatchertype + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchertype.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTestServlet.java new file mode 100644 index 0000000000..c75a56d2b7 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTestServlet.java @@ -0,0 +1,1119 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest; + +import java.io.IOException; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class DispatchTestServlet extends GenericTCKServlet { + + public static String DISPATCH_TEST1_CTX_KEY = "DISPATCH_TEST1_CTX_KEY"; + + public static String DISPATCH_TEST_CTX_KEY = "DISPATCH_TEST_CTX_KEY"; + + public static String getDispatcherContextRoot() { + return System.getProperty(DISPATCH_TEST_CTX_KEY, "/servlet_js_dispatchtest_web"); + } + + public static String getDispatcher1ContextRoot() { + return System.getProperty(DISPATCH_TEST1_CTX_KEY, "/servlet_js_dispatchtest1_web"); + } + + // Test for AsyncContext.dispatch() + public void dispatchReturnTest(ServletRequest request, + ServletResponse response) throws IOException { + + String where = (String) request.getAttribute("WHERE"); + if ("ASYNC".equals(where)) { + response.getWriter() + .println("After dispatch=" + System.currentTimeMillis()); + response.getWriter().println("ASYNC_STARTED_dispatchReturnTest"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + } else { + response.getWriter().println("ASYNC_NOT_STARTED_dispatchReturnTest"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(); + request.setAttribute("WHERE", "ASYNC"); + response.getWriter() + .println("Before dispatch=" + System.currentTimeMillis()); + ac.dispatch(); + response.getWriter() + .println("dispatch return=" + System.currentTimeMillis()); + } + } + + // Test for AsyncContext.dispatch(request, response) + public void dispatchReturnTest1(ServletRequest request, + ServletResponse response) throws IOException { + + String where = (String) request.getAttribute("WHERE"); + if ("ASYNC".equals(where)) { + response.getWriter() + .println("After dispatch=" + System.currentTimeMillis()); + response.getWriter().println("ASYNC_STARTED_dispatchReturnTest1"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + } else { + response.getWriter().println("ASYNC_NOT_STARTED_dispatchReturnTest1"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(request, response); + request.setAttribute("WHERE", "ASYNC"); + response.getWriter() + .println("Before dispatch=" + System.currentTimeMillis()); + ac.dispatch(); + response.getWriter() + .println("dispatch return=" + System.currentTimeMillis()); + } + } + + // Test for AsyncContext.dispatch(String) + public void dispatchReturnTest2(ServletRequest request, + ServletResponse response) throws IOException { + + response.getWriter().println("ASYNC_NOT_STARTED_dispatchReturnTest2"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(); + response.getWriter() + .println("Before dispatch=" + System.currentTimeMillis()); + ac.dispatch("/DispatchTests?testname=dispatchTest"); + response.getWriter() + .println("dispatch return=" + System.currentTimeMillis()); + } + + // Test for AsyncContext.dispatch(String) + public void dispatchReturnTest3(ServletRequest request, + ServletResponse response) throws IOException { + + response.getWriter().println("ASYNC_NOT_STARTED_dispatchReturnTest3"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(request, response); + response.getWriter() + .println("Before dispatch=" + System.currentTimeMillis()); + ac.dispatch("/DispatchTests?testname=dispatchTest"); + response.getWriter() + .println("dispatch return=" + System.currentTimeMillis()); + } + + // Test for AsyncContext.dispatch(ServletContext, String) + public void dispatchReturnTest4(ServletRequest request, + ServletResponse response) throws IOException { + + response.getWriter().println("ASYNC_NOT_STARTED_dispatchReturnTest4"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(); + response.getWriter() + .println("Before dispatch=" + System.currentTimeMillis()); + ac.dispatch( + request.getServletContext().getContext(getDispatcher1ContextRoot()), + "/DispatchTests10?testname=dispatchTest10"); + response.getWriter() + .println("dispatch return=" + System.currentTimeMillis()); + } + + // Test for AsyncContext.dispatch(ServletContext, String) + public void dispatchReturnTest5(ServletRequest request, + ServletResponse response) throws IOException { + + response.getWriter().println("ASYNC_NOT_STARTED_dispatchReturnTest5"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(request, response); + response.getWriter() + .println("Before dispatch=" + System.currentTimeMillis()); + ac.dispatch( + request.getServletContext().getContext(getDispatcher1ContextRoot()), + "/DispatchTests10?testname=dispatchTest10"); + response.getWriter() + .println("dispatch return=" + System.currentTimeMillis()); + } + + // Test for AsyncContext.dispatch() when startAsync called twice + public void startAsyncAgainTest(ServletRequest request, + ServletResponse response) throws IOException { + + String where = (String) request.getAttribute("WHERE"); + if ("ASYNC".equals(where)) { + response.getWriter() + .println("After dispatch=" + System.currentTimeMillis()); + response.getWriter().println("ASYNC_STARTED_startAsyncAgainTest"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(); + request.setAttribute("WHERE", "LAST"); + response.getWriter() + .println("Before second dispatch=" + System.currentTimeMillis()); + ac.dispatch(); + response.getWriter() + .println("second dispatch return=" + System.currentTimeMillis()); + } else if ("LAST".equals(where)) { + response.getWriter() + .println("After second dispatch=" + System.currentTimeMillis()); + response.getWriter().println("ASYNC_STARTED_AGAIN_startAsyncAgainTest"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + } else { + response.getWriter().println("ASYNC_NOT_STARTED_startAsyncAgainTest"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(); + request.setAttribute("WHERE", "ASYNC"); + response.getWriter() + .println("Before dispatch=" + System.currentTimeMillis()); + ac.dispatch(); + response.getWriter() + .println("dispatch return=" + System.currentTimeMillis()); + } + } + + // Test for AsyncContext.dispatch() when startAsync called twice + public void startAsyncAgainTest1(ServletRequest request, + ServletResponse response) throws IOException { + + String where = (String) request.getAttribute("WHERE"); + if ("ASYNC".equals(where)) { + response.getWriter() + .println("After dispatch=" + System.currentTimeMillis()); + response.getWriter().println("ASYNC_STARTED_startAsyncAgainTest1"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(request, response); + request.setAttribute("WHERE", "LAST"); + response.getWriter() + .println("Before second dispatch=" + System.currentTimeMillis()); + ac.dispatch(); + response.getWriter() + .println("second dispatch return=" + System.currentTimeMillis()); + } else if ("LAST".equals(where)) { + response.getWriter() + .println("After second dispatch=" + System.currentTimeMillis()); + response.getWriter().println("ASYNC_STARTED_AGAIN_startAsyncAgainTest1"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + } else { + response.getWriter().println("ASYNC_NOT_STARTED_startAsyncAgainTest1"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(request, response); + request.setAttribute("WHERE", "ASYNC"); + response.getWriter() + .println("Before dispatch=" + System.currentTimeMillis()); + ac.dispatch(); + response.getWriter() + .println("dispatch return=" + System.currentTimeMillis()); + } + } + + // Test for AsyncContext.dispatch() when startAsync called twice + public void startAsyncAgainTest2(ServletRequest request, + ServletResponse response) throws IOException { + + String where = (String) request.getAttribute("WHERE"); + if ("ASYNC".equals(where)) { + response.getWriter() + .println("After dispatch=" + System.currentTimeMillis()); + response.getWriter().println("ASYNC_STARTED_startAsyncAgainTest2"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(); + response.getWriter() + .println("Before complete=" + System.currentTimeMillis()); + ac.complete(); + response.getWriter() + .println("After complete=" + System.currentTimeMillis()); + } else { + response.getWriter().println("ASYNC_NOT_STARTED_startAsyncAgainTest2"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(request, response); + request.setAttribute("WHERE", "ASYNC"); + response.getWriter() + .println("Before dispatch=" + System.currentTimeMillis()); + ac.dispatch(); + response.getWriter() + .println("dispatch return=" + System.currentTimeMillis()); + } + } + + // Test for AsyncContext.dispatch() when startAsync called twice + public void startAsyncAgainTest3(ServletRequest request, + ServletResponse response) throws IOException { + + String where = (String) request.getAttribute("WHERE"); + if ("ASYNC".equals(where)) { + response.getWriter() + .println("After dispatch=" + System.currentTimeMillis()); + response.getWriter().println("ASYNC_STARTED_startAsyncAgainTest3"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(request, response); + response.getWriter() + .println("Before complete=" + System.currentTimeMillis()); + ac.complete(); + response.getWriter() + .println("After complete=" + System.currentTimeMillis()); + } else { + response.getWriter().println("ASYNC_NOT_STARTED_startAsyncAgainTest3"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(); + request.setAttribute("WHERE", "ASYNC"); + response.getWriter() + .println("Before dispatch=" + System.currentTimeMillis()); + ac.dispatch(); + response.getWriter() + .println("dispatch return=" + System.currentTimeMillis()); + } + } + + // Test AsyncContext.dispatch() when startAsync() called in an asynchrounous + // thread + public void startAsyncAgainTest4(ServletRequest request, + ServletResponse response) throws IOException { + + String where = (String) request.getAttribute("WHERE"); + if ("ASYNC".equals(where)) { + response.getWriter() + .println("After dispatch=" + System.currentTimeMillis()); + response.getWriter().println("ASYNC_STARTED_startAsyncAgainTest4"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(); + response.getWriter().println("startAsync called"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + try { + request.startAsync(); + } catch (java.lang.IllegalStateException ex) { + response.getWriter().println("startAsync called again"); + response.getWriter() + .println("Expected IllegalStateException thrown" + ex.getMessage()); + } + ac.complete(); + } else { + response.getWriter().println("ASYNC_NOT_STARTED_startAsyncAgainTest4"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(); + request.setAttribute("WHERE", "ASYNC"); + response.getWriter() + .println("Before dispatch=" + System.currentTimeMillis()); + ac.dispatch(); + response.getWriter() + .println("dispatch return=" + System.currentTimeMillis()); + } + } + + // Test AsyncContext.dispatch() when startAsync(request, response) called in + // an asynchrounous thread + public void startAsyncAgainTest5(ServletRequest request, + ServletResponse response) throws IOException { + + String where = (String) request.getAttribute("WHERE"); + if ("ASYNC".equals(where)) { + response.getWriter() + .println("After dispatch=" + System.currentTimeMillis()); + response.getWriter().println("ASYNC_STARTED_startAsyncAgainTest5"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(request, response); + response.getWriter().println("startAsync called"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + try { + request.startAsync(request, response); + } catch (java.lang.IllegalStateException ex) { + response.getWriter().println("startAsync called again"); + response.getWriter() + .println("Expected IllegalStateException thrown" + ex.getMessage()); + } + ac.complete(); + } else { + response.getWriter().println("ASYNC_NOT_STARTED_startAsyncAgainTest5"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(request, response); + request.setAttribute("WHERE", "ASYNC"); + response.getWriter() + .println("Before dispatch=" + System.currentTimeMillis()); + ac.dispatch(); + response.getWriter() + .println("dispatch return=" + System.currentTimeMillis()); + } + } + + // Test for AsyncContext.dispatch(URI) when startAsync called twice + public void startAsyncAgainTest6(ServletRequest request, + ServletResponse response) throws IOException { + + response.getWriter().println("ASYNC_NOT_STARTED_startAsyncAgainTest6"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(); + request.setAttribute("WHERE", "ASYNC"); + response.getWriter() + .println("Before dispatch=" + System.currentTimeMillis()); + ac.dispatch("/DispatchTests1?testname=dispatchTest1"); + response.getWriter() + .println("dispatch return=" + System.currentTimeMillis()); + } + + // Test for AsyncContext.dispatch(URI) when startAsync called twice + public void startAsyncAgainTest7(ServletRequest request, + ServletResponse response) throws IOException { + + response.getWriter().println("ASYNC_NOT_STARTED_startAsyncAgainTest7"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(request, response); + response.getWriter() + .println("Before dispatch=" + System.currentTimeMillis()); + ac.dispatch("/DispatchTests2?testname=dispatchTest2"); + response.getWriter() + .println("dispatch return=" + System.currentTimeMillis()); + } + + // Test for AsyncContext.dispatch(URI) when startAsync called twice + public void startAsyncAgainTest8(ServletRequest request, + ServletResponse response) throws IOException { + + response.getWriter().println("ASYNC_NOT_STARTED_startAsyncAgainTest8"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(); + response.getWriter() + .println("Before dispatch=" + System.currentTimeMillis()); + ac.dispatch("/DispatchTests3?testname=dispatchTest3"); + response.getWriter() + .println("dispatch return=" + System.currentTimeMillis()); + } + + // Test for AsyncContext.dispatch(URI) when startAsync called twice + public void startAsyncAgainTest9(ServletRequest request, + ServletResponse response) throws IOException { + + response.getWriter().println("ASYNC_NOT_STARTED_startAsyncAgainTest9"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(request, response); + response.getWriter() + .println("Before dispatch=" + System.currentTimeMillis()); + ac.dispatch("/DispatchTests4?testname=dispatchTest4"); + response.getWriter() + .println("dispatch return=" + System.currentTimeMillis()); + } + + // Test AsyncContext.dispatch(URI) when startAsync() called in an + // asynchrounous thread + public void startAsyncAgainTest10(ServletRequest request, + ServletResponse response) throws IOException { + response.getWriter().println("ASYNC_NOT_STARTED_startAsyncAgainTest10"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(); + response.getWriter() + .println("Before dispatch=" + System.currentTimeMillis()); + ac.dispatch("/DispatchTests5?testname=dispatchTest5"); + response.getWriter() + .println("dispatch return=" + System.currentTimeMillis()); + } + + // Test AsyncContext.dispatch(URI) when startAsync(request, response) called + // in an asynchrounous thread + public void startAsyncAgainTest11(ServletRequest request, + ServletResponse response) throws IOException { + response.getWriter().println("ASYNC_NOT_STARTED_startAsyncAgainTest11"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(request, response); + response.getWriter() + .println("Before dispatch=" + System.currentTimeMillis()); + ac.dispatch("/DispatchTests6?testname=dispatchTest6"); + response.getWriter() + .println("dispatch return=" + System.currentTimeMillis()); + } + + // Test for AsyncContext.dispatch(ServletContext,URI) when startAsync called + // twice + public void startAsyncAgainTest12(ServletRequest request, + ServletResponse response) throws IOException { + + response.getWriter().println("ASYNC_NOT_STARTED_startAsyncAgainTest12"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(); + response.getWriter() + .println("Before dispatch=" + System.currentTimeMillis()); + ac.dispatch( + request.getServletContext().getContext(getDispatcher1ContextRoot()), + "/DispatchTests11?testname=dispatchTest11"); + response.getWriter() + .println("dispatch return=" + System.currentTimeMillis()); + } + + // Test for AsyncContext.dispatch(ServletContext,URI) when startAsync called + // twice + public void startAsyncAgainTest13(ServletRequest request, + ServletResponse response) throws IOException { + response.getWriter().println("ASYNC_NOT_STARTED_startAsyncAgainTest13"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(request, response); + response.getWriter() + .println("Before dispatch=" + System.currentTimeMillis()); + ac.dispatch( + request.getServletContext().getContext(getDispatcher1ContextRoot()), + "/DispatchTests12?testname=dispatchTest12"); + response.getWriter() + .println("dispatch return=" + System.currentTimeMillis()); + } + + // Test for AsyncContext.dispatch(ServletContext, URI) when startAsync called + // twice + public void startAsyncAgainTest14(ServletRequest request, + ServletResponse response) throws IOException { + response.getWriter().println("ASYNC_NOT_STARTED_startAsyncAgainTest14"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(); + response.getWriter() + .println("Before dispatch=" + System.currentTimeMillis()); + ac.dispatch( + request.getServletContext().getContext(getDispatcher1ContextRoot()), + "/DispatchTests13?testname=dispatchTest13"); + response.getWriter() + .println("dispatch return=" + System.currentTimeMillis()); + } + + // Test for AsyncContext.dispatch(ServletContext, URI) when startAsync called + // twice + public void startAsyncAgainTest15(ServletRequest request, + ServletResponse response) throws IOException { + response.getWriter().println("ASYNC_NOT_STARTED_startAsyncAgainTest15"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(request, response); + response.getWriter() + .println("Before dispatch=" + System.currentTimeMillis()); + ac.dispatch( + request.getServletContext().getContext(getDispatcher1ContextRoot()), + "/DispatchTests14?testname=dispatchTest14"); + response.getWriter() + .println("dispatch return=" + System.currentTimeMillis()); + } + + // Test AsyncContext.dispatch(ServletContext, URI) when startAsync() called in + // an asynchrounous thread + public void startAsyncAgainTest16(ServletRequest request, + ServletResponse response) throws IOException { + response.getWriter().println("ASYNC_NOT_STARTED_startAsyncAgainTest16"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(); + response.getWriter() + .println("Before dispatch=" + System.currentTimeMillis()); + ac.dispatch( + request.getServletContext().getContext(getDispatcher1ContextRoot()), + "/DispatchTests15?testname=dispatchTest15"); + response.getWriter() + .println("dispatch return=" + System.currentTimeMillis()); + } + + // Test AsyncContext.dispatch(ServletContext, URI) when startAsync(request, + // response) called in an asynchrounous thread + public void startAsyncAgainTest17(ServletRequest request, + ServletResponse response) throws IOException { + response.getWriter().println("ASYNC_NOT_STARTED_startAsyncAgainTest17"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(request, response); + response.getWriter() + .println("Before dispatch=" + System.currentTimeMillis()); + ac.dispatch( + request.getServletContext().getContext(getDispatcher1ContextRoot()), + "/DispatchTests16?testname=dispatchTest16"); + response.getWriter() + .println("dispatch return=" + System.currentTimeMillis()); + } + + // Negative test AsyncContext.dispatch() - calling dispatch() after it already + // happened. + public void negativeDispatchTest(ServletRequest request, + ServletResponse response) throws IOException { + + String where = (String) request.getAttribute("WHERE"); + if ("ASYNC".equals(where)) { + response.getWriter() + .println("After dispatch=" + System.currentTimeMillis()); + response.getWriter().println("ASYNC_STARTED_negativeDispatchTest"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + } else { + response.getWriter().println("ASYNC_NOT_STARTED_negativeDispatchTest"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(); + request.setAttribute("WHERE", "ASYNC"); + response.getWriter() + .println("Before dispatch=" + System.currentTimeMillis()); + ac.dispatch(); + response.getWriter() + .println("dispatch return=" + System.currentTimeMillis()); + + try { + response.getWriter().println("dispatch again"); + ac.dispatch(); + } catch (IllegalStateException ex) { + response.getWriter().println("dispatch() called again"); + response.getWriter() + .println("Expected IllegalStateException thrown" + ex.getMessage()); + } + } + } + + // Negative test AsyncContext.dispatch() - calling dispatch() after it already + // happened. + public void negativeDispatchTest1(ServletRequest request, + ServletResponse response) throws IOException { + + String where = (String) request.getAttribute("WHERE"); + if ("ASYNC".equals(where)) { + response.getWriter() + .println("After dispatch=" + System.currentTimeMillis()); + response.getWriter().println("ASYNC_STARTED_negativeDispatchTest1"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + } else { + response.getWriter().println("ASYNC_NOT_STARTED_negativeDispatchTest1"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(); + request.setAttribute("WHERE", "ASYNC"); + response.getWriter() + .println("Before dispatch=" + System.currentTimeMillis()); + ac.dispatch(); + response.getWriter() + .println("dispatch return=" + System.currentTimeMillis()); + + try { + response.getWriter().println("dispatch again"); + ac.dispatch(); + } catch (IllegalStateException ex) { + response.getWriter().println("dispatch() called again"); + response.getWriter() + .println("Expected IllegalStateException thrown" + ex.getMessage()); + } + } + } + + // Negative test AsyncContext.dispatch(URI) - calling dispatch(URI) after it + // already happened. + public void negativeDispatchTest4(ServletRequest request, + ServletResponse response) throws IOException { + + response.getWriter().println("ASYNC_NOT_STARTED_negativeDispatchTest4"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(); + response.getWriter() + .println("Before dispatch=" + System.currentTimeMillis()); + ac.dispatch("/DispatchTests?testname=dispatchTest"); + response.getWriter() + .println("dispatch return=" + System.currentTimeMillis()); + + try { + response.getWriter().println("dispatch again"); + ac.dispatch("/DispatchTests?testname=dispatchTest"); + } catch (IllegalStateException ex) { + response.getWriter().println("dispatch(URI) called again"); + response.getWriter() + .println("Expected IllegalStateException thrown" + ex.getMessage()); + } + } + + // Negative test AsyncContext.dispatch(URI) - calling dispatch(URI) after it + // already happened. + public void negativeDispatchTest5(ServletRequest request, + ServletResponse response) throws IOException { + + response.getWriter().println("ASYNC_NOT_STARTED_negativeDispatchTest5"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(request, response); + response.getWriter() + .println("Before dispatch=" + System.currentTimeMillis()); + ac.dispatch("/DispatchTests?testname=dispatchTest"); + response.getWriter() + .println("dispatch return=" + System.currentTimeMillis()); + + try { + response.getWriter().println("dispatch again"); + ac.dispatch("/DispatchTests?testname=dispatchTest"); + } catch (IllegalStateException ex) { + response.getWriter().println("dispatch(URI) called again"); + response.getWriter() + .println("Expected IllegalStateException thrown" + ex.getMessage()); + } + } + + // Negative test AsyncContext.dispatch(ServletContext, URI) + // calling dispatch(ServletContext, URI) after it already happened. + public void negativeDispatchTest8(ServletRequest request, + ServletResponse response) throws IOException { + + response.getWriter().println("ASYNC_NOT_STARTED_negativeDispatchTest8"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(); + response.getWriter() + .println("Before dispatch=" + System.currentTimeMillis()); + ac.dispatch( + request.getServletContext().getContext(getDispatcher1ContextRoot()), + "/DispatchTests10?testname=dispatchTest10"); + response.getWriter() + .println("dispatch return=" + System.currentTimeMillis()); + + try { + response.getWriter().println("dispatch again"); + ac.dispatch( + request.getServletContext() + .getContext(getDispatcher1ContextRoot()), + "/DispatchTests19?testname=dispatchTest19"); + } catch (IllegalStateException ex) { + response.getWriter().println("dispatch() called again"); + response.getWriter() + .println("Expected IllegalStateException thrown" + ex.getMessage()); + } + } + + // Negative test AsyncContext.dispatch(ServletContext,URI) + // calling dispatch(ServletContext, URI) after it already happened. + public void negativeDispatchTest9(ServletRequest request, + ServletResponse response) throws IOException { + response.getWriter().println("ASYNC_NOT_STARTED_negativeDispatchTest9"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(request, response); + response.getWriter() + .println("Before dispatch=" + System.currentTimeMillis()); + ac.dispatch( + request.getServletContext().getContext(getDispatcher1ContextRoot()), + "/DispatchTests10?testname=dispatchTest10"); + response.getWriter() + .println("dispatch return=" + System.currentTimeMillis()); + + try { + response.getWriter().println("dispatch again"); + ac.dispatch( + request.getServletContext() + .getContext(getDispatcher1ContextRoot()), + "/DispatchTests19?testname=dispatchTest19"); + } catch (IllegalStateException ex) { + response.getWriter().println("dispatch() called again"); + response.getWriter() + .println("Expected IllegalStateException thrown" + ex.getMessage()); + } + } + + // Negative test AsyncContext.dispatch(ServletContext,URI) + // calling dispatch(URI) after it already happened. + public void negativeDispatchTest12(ServletRequest request, + ServletResponse response) throws IOException { + + response.getWriter().println("ASYNC_NOT_STARTED_negativeDispatchTest12"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(); + response.getWriter() + .println("Before dispatch=" + System.currentTimeMillis()); + ac.dispatch( + request.getServletContext().getContext(getDispatcher1ContextRoot()), + "/DispatchTests10?testname=dispatchTest10"); + response.getWriter() + .println("dispatch return=" + System.currentTimeMillis()); + + try { + response.getWriter().println("dispatch again"); + ac.dispatch("/DispatchTests?testname=dispatchTest"); + } catch (IllegalStateException ex) { + response.getWriter().println("dispatch(URI) called again"); + response.getWriter() + .println("Expected IllegalStateException thrown" + ex.getMessage()); + } + } + + // Negative test AsyncContext.dispatch(ServletContext,URI) + // calling dispatch(URI) after it already happened. + public void negativeDispatchTest13(ServletRequest request, + ServletResponse response) throws IOException { + + response.getWriter().println("ASYNC_NOT_STARTED_negativeDispatchTest13"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(request, response); + response.getWriter() + .println("Before dispatch=" + System.currentTimeMillis()); + ac.dispatch( + request.getServletContext().getContext(getDispatcher1ContextRoot()), + "/DispatchTests10?testname=dispatchTest10"); + response.getWriter() + .println("dispatch return=" + System.currentTimeMillis()); + + try { + response.getWriter().println("dispatch again"); + ac.dispatch("/DispatchTests?testname=dispatchTest"); + } catch (IllegalStateException ex) { + response.getWriter().println("dispatch(URI) called again"); + response.getWriter() + .println("Expected IllegalStateException thrown" + ex.getMessage()); + } + } + + // Test AsyncContext.dispatch() - test dispatch after response has been + // committed + public void dispatchAfterCommitTest(ServletRequest request, + ServletResponse response) throws IOException { + + String where = (String) request.getAttribute("WHERE"); + if ("ASYNC".equals(where)) { + response.getWriter() + .println("After dispatch=" + System.currentTimeMillis()); + response.getWriter().println("ASYNC_STARTED_dispatchAfterCommitTest"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + } else { + response.getWriter().println("ASYNC_NOT_STARTED_dispatchAfterCommitTest"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + response.flushBuffer(); + response.getWriter().println("After commmit"); + AsyncContext ac = request.startAsync(); + request.setAttribute("WHERE", "ASYNC"); + response.getWriter() + .println("Before dispatch=" + System.currentTimeMillis()); + ac.dispatch(); + response.getWriter() + .println("dispatch return=" + System.currentTimeMillis()); + } + } + + // Test AsyncContext.dispatch() - test dispatch after response has been + // committed + public void dispatchAfterCommitTest1(ServletRequest request, + ServletResponse response) throws IOException { + + String where = (String) request.getAttribute("WHERE"); + if ("ASYNC".equals(where)) { + response.getWriter() + .println("After dispatch=" + System.currentTimeMillis()); + response.getWriter().println("ASYNC_STARTED_dispatchAfterCommitTest1"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + } else { + response.getWriter() + .println("ASYNC_NOT_STARTED_dispatchAfterCommitTest1"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + response.flushBuffer(); + response.getWriter().println("After commmit"); + AsyncContext ac = request.startAsync(request, response); + request.setAttribute("WHERE", "ASYNC"); + response.getWriter() + .println("Before dispatch=" + System.currentTimeMillis()); + ac.dispatch(); + response.getWriter() + .println("dispatch return=" + System.currentTimeMillis()); + } + } + + // Test AsyncContext.dispatch(URI) - test dispatch after response has been + // committed + public void dispatchAfterCommitTest2(ServletRequest request, + ServletResponse response) throws IOException { + response.getWriter().println("ASYNC_NOT_STARTED_dispatchAfterCommitTest2"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + response.flushBuffer(); + response.getWriter().println("After commmit"); + AsyncContext ac = request.startAsync(); + response.getWriter() + .println("Before dispatch=" + System.currentTimeMillis()); + ac.dispatch("/DispatchTests?testname=dispatchTest"); + response.getWriter() + .println("dispatch return=" + System.currentTimeMillis()); + } + + // Test AsyncContext.dispatch(URI) - test dispatch after response has been + // committed + public void dispatchAfterCommitTest3(ServletRequest request, + ServletResponse response) throws IOException { + + response.getWriter().println("ASYNC_NOT_STARTED_dispatchAfterCommitTest3"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + response.flushBuffer(); + response.getWriter().println("After commmit"); + AsyncContext ac = request.startAsync(request, response); + response.getWriter() + .println("Before dispatch=" + System.currentTimeMillis()); + ac.dispatch("/DispatchTests?testname=dispatchTest"); + response.getWriter() + .println("dispatch return=" + System.currentTimeMillis()); + } + + // Test AsyncContext.dispatch(ServletContext,URI) - test dispatch after + // response has been committed + public void dispatchAfterCommitTest4(ServletRequest request, + ServletResponse response) throws IOException { + response.getWriter().println("ASYNC_NOT_STARTED_dispatchAfterCommitTest4"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + response.flushBuffer(); + response.getWriter().println("After commmit"); + AsyncContext ac = request.startAsync(); + response.getWriter() + .println("Before dispatch=" + System.currentTimeMillis()); + ac.dispatch( + request.getServletContext().getContext(getDispatcher1ContextRoot()), + "/DispatchTests10?testname=dispatchTest10"); + response.getWriter() + .println("dispatch return=" + System.currentTimeMillis()); + } + + // Test AsyncContext.dispatch(ServletContext,URI) - test dispatch after + // response has been committed + public void dispatchAfterCommitTest5(ServletRequest request, + ServletResponse response) throws IOException { + + response.getWriter().println("ASYNC_NOT_STARTED_dispatchAfterCommitTest5"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + response.flushBuffer(); + response.getWriter().println("After commmit"); + AsyncContext ac = request.startAsync(request, response); + response.getWriter() + .println("Before dispatch=" + System.currentTimeMillis()); + ac.dispatch( + request.getServletContext().getContext(getDispatcher1ContextRoot()), + "/DispatchTests10?testname=dispatchTest10"); + response.getWriter() + .println("dispatch return=" + System.currentTimeMillis()); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests.java new file mode 100644 index 0000000000..fec676d1a2 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests.java @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class DispatchTests extends GenericServlet { + + private static final String TEST_HEADER = "testname"; + + private static final Class[] TEST_ARGS = { ServletRequest.class, + ServletResponse.class }; + + public void service(ServletRequest req, ServletResponse res) + throws ServletException, IOException { + String test = req.getParameter(TEST_HEADER); + try { + Method method = this.getClass().getMethod(test, TEST_ARGS); + method.invoke(this, new Object[] { req, res }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + } + + public void dispatchTest(ServletRequest request, ServletResponse response) + throws IOException { + response.getWriter() + .println("After dispatch=" + System.currentTimeMillis()); + response.getWriter().println("ASYNC_STARTED_dispatchTest"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + response.getWriter() + .println("REQUEST_URI=" + request.getAttribute("REQUEST_URI")); + response.getWriter() + .println("CONTEXT_PATH=" + request.getAttribute("CONTEXT_PATH")); + response.getWriter() + .println("PATH_INFO=" + request.getAttribute("PATH_INFO")); + response.getWriter() + .println("SERVLET_PATH=" + request.getAttribute("SERVLET_PATH")); + response.getWriter() + .println("QUERY_STRING=" + request.getAttribute("QUERY_STRING")); + response.getWriter().println( + "ASYNC_REQUEST_URI=" + request.getAttribute("ASYNC_REQUEST_URI")); + response.getWriter().println( + "ASYNC_CONTEXT_PATH=" + request.getAttribute("ASYNC_CONTEXT_PATH")); + response.getWriter() + .println("ASYNC_PATH_INFO=" + request.getAttribute("ASYNC_PATH_INFO")); + response.getWriter().println( + "ASYNC_SERVLET_PATH=" + request.getAttribute("ASYNC_SERVLET_PATH")); + response.getWriter().println( + "ASYNC_QUERY_STRING=" + request.getAttribute("ASYNC_QUERY_STRING")); + } + + public void dispatchTest1(ServletRequest request, ServletResponse response) + throws IOException { + response.getWriter() + .println("After dispatch=" + System.currentTimeMillis()); + response.getWriter().println("ASYNC_STARTED_dispatchTest1"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + response.getWriter() + .println("REQUEST_URI=" + request.getAttribute("REQUEST_URI")); + response.getWriter() + .println("CONTEXT_PATH=" + request.getAttribute("CONTEXT_PATH")); + response.getWriter() + .println("PATH_INFO=" + request.getAttribute("PATH_INFO")); + response.getWriter() + .println("SERVLET_PATH=" + request.getAttribute("SERVLET_PATH")); + response.getWriter() + .println("QUERY_STRING=" + request.getAttribute("QUERY_STRING")); + response.getWriter().println( + "ASYNC_REQUEST_URI=" + request.getAttribute("ASYNC_REQUEST_URI")); + response.getWriter().println( + "ASYNC_CONTEXT_PATH=" + request.getAttribute("ASYNC_CONTEXT_PATH")); + response.getWriter() + .println("ASYNC_PATH_INFO=" + request.getAttribute("ASYNC_PATH_INFO")); + response.getWriter().println( + "ASYNC_SERVLET_PATH=" + request.getAttribute("ASYNC_SERVLET_PATH")); + response.getWriter().println( + "ASYNC_QUERY_STRING=" + request.getAttribute("ASYNC_QUERY_STRING")); + throw new IOException("A_UNIQUE_EXCEPTION_MESSAGE_TO_CHECK_LATER"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests1.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests1.java new file mode 100644 index 0000000000..bd4c4f2a10 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests1.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class DispatchTests1 extends GenericServlet { + + private static final String TEST_HEADER = "testname"; + + private static final Class[] TEST_ARGS = { ServletRequest.class, + ServletResponse.class }; + + public void service(ServletRequest req, ServletResponse res) + throws ServletException, IOException { + String test = req.getParameter(TEST_HEADER); + try { + Method method = this.getClass().getMethod(test, TEST_ARGS); + method.invoke(this, new Object[] { req, res }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + } + + public void dispatchTest1(ServletRequest request, ServletResponse response) + throws IOException { + response.getWriter() + .println("After dispatch=" + System.currentTimeMillis()); + response.getWriter().println("ASYNC_STARTED_dispatchTest1"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + response.getWriter() + .println("REQUEST_URI=" + request.getAttribute("REQUEST_URI")); + response.getWriter() + .println("CONTEXT_PATH=" + request.getAttribute("CONTEXT_PATH")); + response.getWriter() + .println("PATH_INFO=" + request.getAttribute("PATH_INFO")); + response.getWriter() + .println("SERVLET_PATH=" + request.getAttribute("SERVLET_PATH")); + response.getWriter() + .println("QUERY_STRING=" + request.getAttribute("QUERY_STRING")); + response.getWriter().println( + "ASYNC_REQUEST_URI=" + request.getAttribute("ASYNC_REQUEST_URI")); + response.getWriter().println( + "ASYNC_CONTEXT_PATH=" + request.getAttribute("ASYNC_CONTEXT_PATH")); + response.getWriter() + .println("ASYNC_PATH_INFO=" + request.getAttribute("ASYNC_PATH_INFO")); + response.getWriter().println( + "ASYNC_SERVLET_PATH=" + request.getAttribute("ASYNC_SERVLET_PATH")); + response.getWriter().println( + "ASYNC_QUERY_STRING=" + request.getAttribute("ASYNC_QUERY_STRING")); + + AsyncContext ac = request.startAsync(); + response.getWriter() + .println("Before second dispatch=" + System.currentTimeMillis()); + ac.dispatch("/DispatchTests?testname=dispatchTest"); + response.getWriter() + .println("second dispatch return=" + System.currentTimeMillis()); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests10.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests10.java new file mode 100644 index 0000000000..17b9a3d661 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests10.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class DispatchTests10 extends GenericServlet { + + private static final String TEST_HEADER = "testname"; + + private static final Class[] TEST_ARGS = { ServletRequest.class, + ServletResponse.class }; + + public void service(ServletRequest req, ServletResponse res) + throws ServletException, IOException { + String test = req.getParameter(TEST_HEADER); + try { + Method method = this.getClass().getMethod(test, TEST_ARGS); + method.invoke(this, new Object[] { req, res }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + } + + public void dispatchTest10(ServletRequest request, ServletResponse response) + throws IOException { + response.getWriter() + .println("After dispatch=" + System.currentTimeMillis()); + response.getWriter().println("ASYNC_STARTED_dispatchTest10"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + response.getWriter() + .println("REQUEST_URI=" + request.getAttribute("REQUEST_URI")); + response.getWriter() + .println("CONTEXT_PATH=" + request.getAttribute("CONTEXT_PATH")); + response.getWriter() + .println("PATH_INFO=" + request.getAttribute("PATH_INFO")); + response.getWriter() + .println("SERVLET_PATH=" + request.getAttribute("SERVLET_PATH")); + response.getWriter() + .println("QUERY_STRING=" + request.getAttribute("QUERY_STRING")); + response.getWriter().println( + "ASYNC_REQUEST_URI=" + request.getAttribute("ASYNC_REQUEST_URI")); + response.getWriter().println( + "ASYNC_CONTEXT_PATH=" + request.getAttribute("ASYNC_CONTEXT_PATH")); + response.getWriter() + .println("ASYNC_PATH_INFO=" + request.getAttribute("ASYNC_PATH_INFO")); + response.getWriter().println( + "ASYNC_SERVLET_PATH=" + request.getAttribute("ASYNC_SERVLET_PATH")); + response.getWriter().println( + "ASYNC_QUERY_STRING=" + request.getAttribute("ASYNC_QUERY_STRING")); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests11.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests11.java new file mode 100644 index 0000000000..a25698efe5 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests11.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class DispatchTests11 extends GenericServlet { + + private static final String TEST_HEADER = "testname"; + + private static final Class[] TEST_ARGS = { ServletRequest.class, + ServletResponse.class }; + + public void service(ServletRequest req, ServletResponse res) + throws ServletException, IOException { + String test = req.getParameter(TEST_HEADER); + try { + Method method = this.getClass().getMethod(test, TEST_ARGS); + method.invoke(this, new Object[] { req, res }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + } + + public void dispatchTest11(ServletRequest request, ServletResponse response) + throws IOException { + response.getWriter() + .println("After dispatch=" + System.currentTimeMillis()); + response.getWriter().println("ASYNC_STARTED_dispatchTest11"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + response.getWriter() + .println("REQUEST_URI=" + request.getAttribute("REQUEST_URI")); + response.getWriter() + .println("CONTEXT_PATH=" + request.getAttribute("CONTEXT_PATH")); + response.getWriter() + .println("PATH_INFO=" + request.getAttribute("PATH_INFO")); + response.getWriter() + .println("SERVLET_PATH=" + request.getAttribute("SERVLET_PATH")); + response.getWriter() + .println("QUERY_STRING=" + request.getAttribute("QUERY_STRING")); + response.getWriter().println( + "ASYNC_REQUEST_URI=" + request.getAttribute("ASYNC_REQUEST_URI")); + response.getWriter().println( + "ASYNC_CONTEXT_PATH=" + request.getAttribute("ASYNC_CONTEXT_PATH")); + response.getWriter() + .println("ASYNC_PATH_INFO=" + request.getAttribute("ASYNC_PATH_INFO")); + response.getWriter().println( + "ASYNC_SERVLET_PATH=" + request.getAttribute("ASYNC_SERVLET_PATH")); + response.getWriter().println( + "ASYNC_QUERY_STRING=" + request.getAttribute("ASYNC_QUERY_STRING")); + AsyncContext ac = request.startAsync(); + response.getWriter() + .println("Before second dispatch=" + System.currentTimeMillis()); + ac.dispatch( + request.getServletContext().getContext(DispatchTestServlet.getDispatcherContextRoot()), + "/DispatchTests?testname=dispatchTest"); + response.getWriter() + .println("second dispatch return=" + System.currentTimeMillis()); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests12.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests12.java new file mode 100644 index 0000000000..8b177f4983 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests12.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class DispatchTests12 extends GenericServlet { + + private static final String TEST_HEADER = "testname"; + + private static final Class[] TEST_ARGS = { ServletRequest.class, + ServletResponse.class }; + + public void service(ServletRequest req, ServletResponse res) + throws ServletException, IOException { + String test = req.getParameter(TEST_HEADER); + try { + Method method = this.getClass().getMethod(test, TEST_ARGS); + method.invoke(this, new Object[] { req, res }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + } + + public void dispatchTest12(ServletRequest request, ServletResponse response) + throws IOException { + response.getWriter() + .println("After dispatch=" + System.currentTimeMillis()); + response.getWriter().println("ASYNC_STARTED_dispatchTest12"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + response.getWriter() + .println("REQUEST_URI=" + request.getAttribute("REQUEST_URI")); + response.getWriter() + .println("CONTEXT_PATH=" + request.getAttribute("CONTEXT_PATH")); + response.getWriter() + .println("PATH_INFO=" + request.getAttribute("PATH_INFO")); + response.getWriter() + .println("SERVLET_PATH=" + request.getAttribute("SERVLET_PATH")); + response.getWriter() + .println("QUERY_STRING=" + request.getAttribute("QUERY_STRING")); + response.getWriter().println( + "ASYNC_REQUEST_URI=" + request.getAttribute("ASYNC_REQUEST_URI")); + response.getWriter().println( + "ASYNC_CONTEXT_PATH=" + request.getAttribute("ASYNC_CONTEXT_PATH")); + response.getWriter() + .println("ASYNC_PATH_INFO=" + request.getAttribute("ASYNC_PATH_INFO")); + response.getWriter().println( + "ASYNC_SERVLET_PATH=" + request.getAttribute("ASYNC_SERVLET_PATH")); + response.getWriter().println( + "ASYNC_QUERY_STRING=" + request.getAttribute("ASYNC_QUERY_STRING")); + AsyncContext ac = request.startAsync(request, response); + response.getWriter() + .println("Before second dispatch=" + System.currentTimeMillis()); + ac.dispatch( + request.getServletContext().getContext(DispatchTestServlet.getDispatcherContextRoot()), + "/DispatchTests?testname=dispatchTest"); + response.getWriter() + .println("second dispatch return=" + System.currentTimeMillis()); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests13.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests13.java new file mode 100644 index 0000000000..b607c7fc5f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests13.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class DispatchTests13 extends GenericServlet { + + private static final String TEST_HEADER = "testname"; + + private static final Class[] TEST_ARGS = { ServletRequest.class, + ServletResponse.class }; + + public void service(ServletRequest req, ServletResponse res) + throws ServletException, IOException { + String test = req.getParameter(TEST_HEADER); + try { + Method method = this.getClass().getMethod(test, TEST_ARGS); + method.invoke(this, new Object[] { req, res }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + } + + public void dispatchTest13(ServletRequest request, ServletResponse response) + throws IOException { + response.getWriter() + .println("After dispatch=" + System.currentTimeMillis()); + response.getWriter().println("ASYNC_STARTED_dispatchTest13"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + response.getWriter() + .println("REQUEST_URI=" + request.getAttribute("REQUEST_URI")); + response.getWriter() + .println("CONTEXT_PATH=" + request.getAttribute("CONTEXT_PATH")); + response.getWriter() + .println("PATH_INFO=" + request.getAttribute("PATH_INFO")); + response.getWriter() + .println("SERVLET_PATH=" + request.getAttribute("SERVLET_PATH")); + response.getWriter() + .println("QUERY_STRING=" + request.getAttribute("QUERY_STRING")); + response.getWriter().println( + "ASYNC_REQUEST_URI=" + request.getAttribute("ASYNC_REQUEST_URI")); + response.getWriter().println( + "ASYNC_CONTEXT_PATH=" + request.getAttribute("ASYNC_CONTEXT_PATH")); + response.getWriter() + .println("ASYNC_PATH_INFO=" + request.getAttribute("ASYNC_PATH_INFO")); + response.getWriter().println( + "ASYNC_SERVLET_PATH=" + request.getAttribute("ASYNC_SERVLET_PATH")); + response.getWriter().println( + "ASYNC_QUERY_STRING=" + request.getAttribute("ASYNC_QUERY_STRING")); + AsyncContext ac = request.startAsync(); + response.getWriter() + .println("Before complete=" + System.currentTimeMillis()); + ac.complete(); + response.getWriter() + .println("After complete=" + System.currentTimeMillis()); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests14.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests14.java new file mode 100644 index 0000000000..33060c9f93 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests14.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class DispatchTests14 extends GenericServlet { + + private static final String TEST_HEADER = "testname"; + + private static final Class[] TEST_ARGS = { ServletRequest.class, + ServletResponse.class }; + + public void service(ServletRequest req, ServletResponse res) + throws ServletException, IOException { + String test = req.getParameter(TEST_HEADER); + try { + Method method = this.getClass().getMethod(test, TEST_ARGS); + method.invoke(this, new Object[] { req, res }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + } + + public void dispatchTest14(ServletRequest request, ServletResponse response) + throws IOException { + response.getWriter() + .println("After dispatch=" + System.currentTimeMillis()); + response.getWriter().println("ASYNC_STARTED_dispatchTest14"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + response.getWriter() + .println("REQUEST_URI=" + request.getAttribute("REQUEST_URI")); + response.getWriter() + .println("CONTEXT_PATH=" + request.getAttribute("CONTEXT_PATH")); + response.getWriter() + .println("PATH_INFO=" + request.getAttribute("PATH_INFO")); + response.getWriter() + .println("SERVLET_PATH=" + request.getAttribute("SERVLET_PATH")); + response.getWriter() + .println("QUERY_STRING=" + request.getAttribute("QUERY_STRING")); + response.getWriter().println( + "ASYNC_REQUEST_URI=" + request.getAttribute("ASYNC_REQUEST_URI")); + response.getWriter().println( + "ASYNC_CONTEXT_PATH=" + request.getAttribute("ASYNC_CONTEXT_PATH")); + response.getWriter() + .println("ASYNC_PATH_INFO=" + request.getAttribute("ASYNC_PATH_INFO")); + response.getWriter().println( + "ASYNC_SERVLET_PATH=" + request.getAttribute("ASYNC_SERVLET_PATH")); + response.getWriter().println( + "ASYNC_QUERY_STRING=" + request.getAttribute("ASYNC_QUERY_STRING")); + AsyncContext ac = request.startAsync(request, response); + response.getWriter() + .println("Before complete=" + System.currentTimeMillis()); + ac.complete(); + response.getWriter() + .println("After complete=" + System.currentTimeMillis()); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests15.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests15.java new file mode 100644 index 0000000000..885fdcc90e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests15.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class DispatchTests15 extends GenericServlet { + + private static final String TEST_HEADER = "testname"; + + private static final Class[] TEST_ARGS = { ServletRequest.class, + ServletResponse.class }; + + public void service(ServletRequest req, ServletResponse res) + throws ServletException, IOException { + String test = req.getParameter(TEST_HEADER); + try { + Method method = this.getClass().getMethod(test, TEST_ARGS); + method.invoke(this, new Object[] { req, res }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + } + + public void dispatchTest15(ServletRequest request, ServletResponse response) + throws IOException { + response.getWriter() + .println("After dispatch=" + System.currentTimeMillis()); + response.getWriter().println("ASYNC_STARTED_dispatchTest15"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + response.getWriter() + .println("REQUEST_URI=" + request.getAttribute("REQUEST_URI")); + response.getWriter() + .println("CONTEXT_PATH=" + request.getAttribute("CONTEXT_PATH")); + response.getWriter() + .println("PATH_INFO=" + request.getAttribute("PATH_INFO")); + response.getWriter() + .println("SERVLET_PATH=" + request.getAttribute("SERVLET_PATH")); + response.getWriter() + .println("QUERY_STRING=" + request.getAttribute("QUERY_STRING")); + response.getWriter().println( + "ASYNC_REQUEST_URI=" + request.getAttribute("ASYNC_REQUEST_URI")); + response.getWriter().println( + "ASYNC_CONTEXT_PATH=" + request.getAttribute("ASYNC_CONTEXT_PATH")); + response.getWriter() + .println("ASYNC_PATH_INFO=" + request.getAttribute("ASYNC_PATH_INFO")); + response.getWriter().println( + "ASYNC_SERVLET_PATH=" + request.getAttribute("ASYNC_SERVLET_PATH")); + response.getWriter().println( + "ASYNC_QUERY_STRING=" + request.getAttribute("ASYNC_QUERY_STRING")); + AsyncContext ac = request.startAsync(); + response.getWriter().println("startAsync called"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + try { + request.startAsync(); + } catch (java.lang.IllegalStateException ex) { + response.getWriter().println("startAsync called again"); + response.getWriter() + .println("Expected IllegalStateException thrown" + ex.getMessage()); + } + response.getWriter() + .println("Before complete=" + System.currentTimeMillis()); + ac.complete(); + response.getWriter() + .println("After complete=" + System.currentTimeMillis()); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests16.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests16.java new file mode 100644 index 0000000000..1631928879 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests16.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class DispatchTests16 extends GenericServlet { + + private static final String TEST_HEADER = "testname"; + + private static final Class[] TEST_ARGS = { ServletRequest.class, + ServletResponse.class }; + + public void service(ServletRequest req, ServletResponse res) + throws ServletException, IOException { + String test = req.getParameter(TEST_HEADER); + try { + Method method = this.getClass().getMethod(test, TEST_ARGS); + method.invoke(this, new Object[] { req, res }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + } + + public void dispatchTest16(ServletRequest request, ServletResponse response) + throws IOException { + response.getWriter() + .println("After dispatch=" + System.currentTimeMillis()); + response.getWriter().println("ASYNC_STARTED_dispatchTest16"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + response.getWriter() + .println("REQUEST_URI=" + request.getAttribute("REQUEST_URI")); + response.getWriter() + .println("CONTEXT_PATH=" + request.getAttribute("CONTEXT_PATH")); + response.getWriter() + .println("PATH_INFO=" + request.getAttribute("PATH_INFO")); + response.getWriter() + .println("SERVLET_PATH=" + request.getAttribute("SERVLET_PATH")); + response.getWriter() + .println("QUERY_STRING=" + request.getAttribute("QUERY_STRING")); + response.getWriter().println( + "ASYNC_REQUEST_URI=" + request.getAttribute("ASYNC_REQUEST_URI")); + response.getWriter().println( + "ASYNC_CONTEXT_PATH=" + request.getAttribute("ASYNC_CONTEXT_PATH")); + response.getWriter() + .println("ASYNC_PATH_INFO=" + request.getAttribute("ASYNC_PATH_INFO")); + response.getWriter().println( + "ASYNC_SERVLET_PATH=" + request.getAttribute("ASYNC_SERVLET_PATH")); + response.getWriter().println( + "ASYNC_QUERY_STRING=" + request.getAttribute("ASYNC_QUERY_STRING")); + AsyncContext ac = request.startAsync(request, response); + response.getWriter().println("startAsync called"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + try { + request.startAsync(request, response); + } catch (java.lang.IllegalStateException ex) { + response.getWriter().println("startAsync called again"); + response.getWriter() + .println("Expected IllegalStateException thrown" + ex.getMessage()); + } + response.getWriter() + .println("Before complete=" + System.currentTimeMillis()); + ac.complete(); + response.getWriter() + .println("After complete=" + System.currentTimeMillis()); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests17.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests17.java new file mode 100644 index 0000000000..7fb2e23731 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests17.java @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class DispatchTests17 extends GenericServlet { + + private static final String TEST_HEADER = "testname"; + + private static final Class[] TEST_ARGS = { ServletRequest.class, + ServletResponse.class }; + + public void service(ServletRequest req, ServletResponse res) + throws ServletException, IOException { + String test = req.getParameter(TEST_HEADER); + try { + Method method = this.getClass().getMethod(test, TEST_ARGS); + method.invoke(this, new Object[] { req, res }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + } + + public void dispatchTest17(ServletRequest request, ServletResponse response) + throws IOException { + response.getWriter() + .println("After dispatch=" + System.currentTimeMillis()); + response.getWriter().println("ASYNC_STARTED_dispatchTest17"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + response.getWriter() + .println("REQUEST_URI=" + request.getAttribute("REQUEST_URI")); + response.getWriter() + .println("CONTEXT_PATH=" + request.getAttribute("CONTEXT_PATH")); + response.getWriter() + .println("PATH_INFO=" + request.getAttribute("PATH_INFO")); + response.getWriter() + .println("SERVLET_PATH=" + request.getAttribute("SERVLET_PATH")); + response.getWriter() + .println("QUERY_STRING=" + request.getAttribute("QUERY_STRING")); + response.getWriter().println( + "ASYNC_REQUEST_URI=" + request.getAttribute("ASYNC_REQUEST_URI")); + response.getWriter().println( + "ASYNC_CONTEXT_PATH=" + request.getAttribute("ASYNC_CONTEXT_PATH")); + response.getWriter() + .println("ASYNC_PATH_INFO=" + request.getAttribute("ASYNC_PATH_INFO")); + response.getWriter().println( + "ASYNC_SERVLET_PATH=" + request.getAttribute("ASYNC_SERVLET_PATH")); + response.getWriter().println( + "ASYNC_QUERY_STRING=" + request.getAttribute("ASYNC_QUERY_STRING")); + AsyncContext ac = request.startAsync(); + response.getWriter().println("startAsync called"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + + response.getWriter() + .println("Before second dispatch=" + System.currentTimeMillis()); + ac.dispatch("/DispatchTests10?testname=dispatchTest10"); + response.getWriter() + .println("second dispatch return=" + System.currentTimeMillis()); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests18.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests18.java new file mode 100644 index 0000000000..5632ebb4b9 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests18.java @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class DispatchTests18 extends GenericServlet { + + private static final String TEST_HEADER = "testname"; + + private static final Class[] TEST_ARGS = { ServletRequest.class, + ServletResponse.class }; + + public void service(ServletRequest req, ServletResponse res) + throws ServletException, IOException { + String test = req.getParameter(TEST_HEADER); + try { + Method method = this.getClass().getMethod(test, TEST_ARGS); + method.invoke(this, new Object[] { req, res }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + } + + public void dispatchTest18(ServletRequest request, ServletResponse response) + throws IOException { + response.getWriter() + .println("After dispatch=" + System.currentTimeMillis()); + response.getWriter().println("ASYNC_STARTED_dispatchTest18"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + response.getWriter() + .println("REQUEST_URI=" + request.getAttribute("REQUEST_URI")); + response.getWriter() + .println("CONTEXT_PATH=" + request.getAttribute("CONTEXT_PATH")); + response.getWriter() + .println("PATH_INFO=" + request.getAttribute("PATH_INFO")); + response.getWriter() + .println("SERVLET_PATH=" + request.getAttribute("SERVLET_PATH")); + response.getWriter() + .println("QUERY_STRING=" + request.getAttribute("QUERY_STRING")); + response.getWriter().println( + "ASYNC_REQUEST_URI=" + request.getAttribute("ASYNC_REQUEST_URI")); + response.getWriter().println( + "ASYNC_CONTEXT_PATH=" + request.getAttribute("ASYNC_CONTEXT_PATH")); + response.getWriter() + .println("ASYNC_PATH_INFO=" + request.getAttribute("ASYNC_PATH_INFO")); + response.getWriter().println( + "ASYNC_SERVLET_PATH=" + request.getAttribute("ASYNC_SERVLET_PATH")); + response.getWriter().println( + "ASYNC_QUERY_STRING=" + request.getAttribute("ASYNC_QUERY_STRING")); + AsyncContext ac = request.startAsync(request, response); + response.getWriter().println("startAsync called"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + + response.getWriter() + .println("Before second dispatch=" + System.currentTimeMillis()); + ac.dispatch("/DispatchTests10?testname=dispatchTest10"); + response.getWriter() + .println("second dispatch return=" + System.currentTimeMillis()); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests19.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests19.java new file mode 100644 index 0000000000..8cfac696bd --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests19.java @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class DispatchTests19 extends GenericServlet { + + private static final String TEST_HEADER = "testname"; + + private static final Class[] TEST_ARGS = { ServletRequest.class, + ServletResponse.class }; + + public void service(ServletRequest req, ServletResponse res) + throws ServletException, IOException { + String test = req.getParameter(TEST_HEADER); + try { + Method method = this.getClass().getMethod(test, TEST_ARGS); + method.invoke(this, new Object[] { req, res }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + } + + public void dispatchTest19(ServletRequest request, ServletResponse response) + throws IOException { + response.getWriter() + .println("After dispatch=" + System.currentTimeMillis()); + response.getWriter().println("ASYNC_STARTED_dispatchTest18"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + response.getWriter() + .println("REQUEST_URI=" + request.getAttribute("REQUEST_URI")); + response.getWriter() + .println("CONTEXT_PATH=" + request.getAttribute("CONTEXT_PATH")); + response.getWriter() + .println("PATH_INFO=" + request.getAttribute("PATH_INFO")); + response.getWriter() + .println("SERVLET_PATH=" + request.getAttribute("SERVLET_PATH")); + response.getWriter() + .println("QUERY_STRING=" + request.getAttribute("QUERY_STRING")); + response.getWriter().println( + "ASYNC_REQUEST_URI=" + request.getAttribute("ASYNC_REQUEST_URI")); + response.getWriter().println( + "ASYNC_CONTEXT_PATH=" + request.getAttribute("ASYNC_CONTEXT_PATH")); + response.getWriter() + .println("ASYNC_PATH_INFO=" + request.getAttribute("ASYNC_PATH_INFO")); + response.getWriter().println( + "ASYNC_SERVLET_PATH=" + request.getAttribute("ASYNC_SERVLET_PATH")); + response.getWriter().println( + "ASYNC_QUERY_STRING=" + request.getAttribute("ASYNC_QUERY_STRING")); + AsyncContext ac = request.startAsync(request, response); + response.getWriter().println("startAsync called"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + + response.getWriter() + .println("Before second dispatch=" + System.currentTimeMillis()); + ac.dispatch("/DispatchTests10?testname=dispatchTest10"); + response.getWriter() + .println("second dispatch return=" + System.currentTimeMillis()); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests2.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests2.java new file mode 100644 index 0000000000..7ce69e79c9 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests2.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class DispatchTests2 extends GenericServlet { + + private static final String TEST_HEADER = "testname"; + + private static final Class[] TEST_ARGS = { ServletRequest.class, + ServletResponse.class }; + + public void service(ServletRequest req, ServletResponse res) + throws ServletException, IOException { + String test = req.getParameter(TEST_HEADER); + try { + Method method = this.getClass().getMethod(test, TEST_ARGS); + method.invoke(this, new Object[] { req, res }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + } + + public void dispatchTest2(ServletRequest request, ServletResponse response) + throws IOException { + response.getWriter() + .println("After dispatch=" + System.currentTimeMillis()); + response.getWriter().println("ASYNC_STARTED_dispatchTest2"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + response.getWriter() + .println("REQUEST_URI=" + request.getAttribute("REQUEST_URI")); + response.getWriter() + .println("CONTEXT_PATH=" + request.getAttribute("CONTEXT_PATH")); + response.getWriter() + .println("PATH_INFO=" + request.getAttribute("PATH_INFO")); + response.getWriter() + .println("SERVLET_PATH=" + request.getAttribute("SERVLET_PATH")); + response.getWriter() + .println("QUERY_STRING=" + request.getAttribute("QUERY_STRING")); + response.getWriter().println( + "ASYNC_REQUEST_URI=" + request.getAttribute("ASYNC_REQUEST_URI")); + response.getWriter().println( + "ASYNC_CONTEXT_PATH=" + request.getAttribute("ASYNC_CONTEXT_PATH")); + response.getWriter() + .println("ASYNC_PATH_INFO=" + request.getAttribute("ASYNC_PATH_INFO")); + response.getWriter().println( + "ASYNC_SERVLET_PATH=" + request.getAttribute("ASYNC_SERVLET_PATH")); + response.getWriter().println( + "ASYNC_QUERY_STRING=" + request.getAttribute("ASYNC_QUERY_STRING")); + + AsyncContext ac = request.startAsync(request, response); + response.getWriter() + .println("Before second dispatch=" + System.currentTimeMillis()); + ac.dispatch("/DispatchTests?testname=dispatchTest"); + response.getWriter() + .println("second dispatch return=" + System.currentTimeMillis()); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests20.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests20.java new file mode 100644 index 0000000000..b49a77260f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests20.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class DispatchTests20 extends GenericServlet { + + private static final String TEST_HEADER = "testname"; + + private static final Class[] TEST_ARGS = { ServletRequest.class, + ServletResponse.class }; + + public void service(ServletRequest req, ServletResponse res) + throws ServletException, IOException { + String test = req.getParameter(TEST_HEADER); + try { + Method method = this.getClass().getMethod(test, TEST_ARGS); + method.invoke(this, new Object[] { req, res }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + } + + public void dispatchTest20(ServletRequest request, ServletResponse response) + throws IOException { + response.getWriter() + .println("After dispatch=" + System.currentTimeMillis()); + response.getWriter().println("ASYNC_STARTED_dispatchTest20"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + response.getWriter() + .println("REQUEST_URI=" + request.getAttribute("REQUEST_URI")); + response.getWriter() + .println("CONTEXT_PATH=" + request.getAttribute("CONTEXT_PATH")); + response.getWriter() + .println("PATH_INFO=" + request.getAttribute("PATH_INFO")); + response.getWriter() + .println("SERVLET_PATH=" + request.getAttribute("SERVLET_PATH")); + response.getWriter() + .println("QUERY_STRING=" + request.getAttribute("QUERY_STRING")); + response.getWriter().println( + "ASYNC_REQUEST_URI=" + request.getAttribute("ASYNC_REQUEST_URI")); + response.getWriter().println( + "ASYNC_CONTEXT_PATH=" + request.getAttribute("ASYNC_CONTEXT_PATH")); + response.getWriter() + .println("ASYNC_PATH_INFO=" + request.getAttribute("ASYNC_PATH_INFO")); + response.getWriter().println( + "ASYNC_SERVLET_PATH=" + request.getAttribute("ASYNC_SERVLET_PATH")); + response.getWriter().println( + "ASYNC_QUERY_STRING=" + request.getAttribute("ASYNC_QUERY_STRING")); + + throw new IOException("A_UNIQUE_EXCEPTION_MESSAGE_TO_CHECK_LATER"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests3.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests3.java new file mode 100644 index 0000000000..a044c8747c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests3.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class DispatchTests3 extends GenericServlet { + + private static final String TEST_HEADER = "testname"; + + private static final Class[] TEST_ARGS = { ServletRequest.class, + ServletResponse.class }; + + public void service(ServletRequest req, ServletResponse res) + throws ServletException, IOException { + String test = req.getParameter(TEST_HEADER); + try { + Method method = this.getClass().getMethod(test, TEST_ARGS); + method.invoke(this, new Object[] { req, res }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + } + + public void dispatchTest3(ServletRequest request, ServletResponse response) + throws IOException { + response.getWriter() + .println("After dispatch=" + System.currentTimeMillis()); + response.getWriter().println("ASYNC_STARTED_dispatchTest3"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + response.getWriter() + .println("REQUEST_URI=" + request.getAttribute("REQUEST_URI")); + response.getWriter() + .println("CONTEXT_PATH=" + request.getAttribute("CONTEXT_PATH")); + response.getWriter() + .println("PATH_INFO=" + request.getAttribute("PATH_INFO")); + response.getWriter() + .println("SERVLET_PATH=" + request.getAttribute("SERVLET_PATH")); + response.getWriter() + .println("QUERY_STRING=" + request.getAttribute("QUERY_STRING")); + response.getWriter().println( + "ASYNC_REQUEST_URI=" + request.getAttribute("ASYNC_REQUEST_URI")); + response.getWriter().println( + "ASYNC_CONTEXT_PATH=" + request.getAttribute("ASYNC_CONTEXT_PATH")); + response.getWriter() + .println("ASYNC_PATH_INFO=" + request.getAttribute("ASYNC_PATH_INFO")); + response.getWriter().println( + "ASYNC_SERVLET_PATH=" + request.getAttribute("ASYNC_SERVLET_PATH")); + response.getWriter().println( + "ASYNC_QUERY_STRING=" + request.getAttribute("ASYNC_QUERY_STRING")); + + AsyncContext ac = request.startAsync(); + response.getWriter() + .println("Before complete=" + System.currentTimeMillis()); + ac.complete(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests4.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests4.java new file mode 100644 index 0000000000..aeb7a1b106 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests4.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class DispatchTests4 extends GenericServlet { + + private static final String TEST_HEADER = "testname"; + + private static final Class[] TEST_ARGS = { ServletRequest.class, + ServletResponse.class }; + + public void service(ServletRequest req, ServletResponse res) + throws ServletException, IOException { + String test = req.getParameter(TEST_HEADER); + try { + Method method = this.getClass().getMethod(test, TEST_ARGS); + method.invoke(this, new Object[] { req, res }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + } + + public void dispatchTest4(ServletRequest request, ServletResponse response) + throws IOException { + response.getWriter() + .println("After dispatch=" + System.currentTimeMillis()); + response.getWriter().println("ASYNC_STARTED_dispatchTest4"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + response.getWriter() + .println("REQUEST_URI=" + request.getAttribute("REQUEST_URI")); + response.getWriter() + .println("CONTEXT_PATH=" + request.getAttribute("CONTEXT_PATH")); + response.getWriter() + .println("PATH_INFO=" + request.getAttribute("PATH_INFO")); + response.getWriter() + .println("SERVLET_PATH=" + request.getAttribute("SERVLET_PATH")); + response.getWriter() + .println("QUERY_STRING=" + request.getAttribute("QUERY_STRING")); + response.getWriter().println( + "ASYNC_REQUEST_URI=" + request.getAttribute("ASYNC_REQUEST_URI")); + response.getWriter().println( + "ASYNC_CONTEXT_PATH=" + request.getAttribute("ASYNC_CONTEXT_PATH")); + response.getWriter() + .println("ASYNC_PATH_INFO=" + request.getAttribute("ASYNC_PATH_INFO")); + response.getWriter().println( + "ASYNC_SERVLET_PATH=" + request.getAttribute("ASYNC_SERVLET_PATH")); + response.getWriter().println( + "ASYNC_QUERY_STRING=" + request.getAttribute("ASYNC_QUERY_STRING")); + + AsyncContext ac = request.startAsync(request, response); + response.getWriter() + .println("Before complete=" + System.currentTimeMillis()); + ac.complete(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests5.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests5.java new file mode 100644 index 0000000000..639106e5a1 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests5.java @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class DispatchTests5 extends GenericServlet { + + private static final String TEST_HEADER = "testname"; + + private static final Class[] TEST_ARGS = { ServletRequest.class, + ServletResponse.class }; + + public void service(ServletRequest req, ServletResponse res) + throws ServletException, IOException { + String test = req.getParameter(TEST_HEADER); + try { + Method method = this.getClass().getMethod(test, TEST_ARGS); + method.invoke(this, new Object[] { req, res }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + } + + public void dispatchTest5(ServletRequest request, ServletResponse response) + throws IOException { + response.getWriter() + .println("After dispatch=" + System.currentTimeMillis()); + response.getWriter().println("ASYNC_STARTED_dispatchTest5"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + response.getWriter() + .println("REQUEST_URI=" + request.getAttribute("REQUEST_URI")); + response.getWriter() + .println("CONTEXT_PATH=" + request.getAttribute("CONTEXT_PATH")); + response.getWriter() + .println("PATH_INFO=" + request.getAttribute("PATH_INFO")); + response.getWriter() + .println("SERVLET_PATH=" + request.getAttribute("SERVLET_PATH")); + response.getWriter() + .println("QUERY_STRING=" + request.getAttribute("QUERY_STRING")); + response.getWriter().println( + "ASYNC_REQUEST_URI=" + request.getAttribute("ASYNC_REQUEST_URI")); + response.getWriter().println( + "ASYNC_CONTEXT_PATH=" + request.getAttribute("ASYNC_CONTEXT_PATH")); + response.getWriter() + .println("ASYNC_PATH_INFO=" + request.getAttribute("ASYNC_PATH_INFO")); + response.getWriter().println( + "ASYNC_SERVLET_PATH=" + request.getAttribute("ASYNC_SERVLET_PATH")); + response.getWriter().println( + "ASYNC_QUERY_STRING=" + request.getAttribute("ASYNC_QUERY_STRING")); + + AsyncContext ac = request.startAsync(); + response.getWriter().println("startAsync called"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + response.getWriter() + .println("REQUEST_URI=" + request.getAttribute("REQUEST_URI")); + response.getWriter() + .println("CONTEXT_PATH=" + request.getAttribute("CONTEXT_PATH")); + response.getWriter() + .println("PATH_INFO=" + request.getAttribute("PATH_INFO")); + response.getWriter() + .println("SERVLET_PATH=" + request.getAttribute("SERVLET_PATH")); + response.getWriter() + .println("QUERY_STRING=" + request.getAttribute("QUERY_STRING")); + response.getWriter().println( + "ASYNC_REQUEST_URI=" + request.getAttribute("ASYNC_REQUEST_URI")); + response.getWriter().println( + "ASYNC_CONTEXT_PATH=" + request.getAttribute("ASYNC_CONTEXT_PATH")); + response.getWriter() + .println("ASYNC_PATH_INFO=" + request.getAttribute("ASYNC_PATH_INFO")); + response.getWriter().println( + "ASYNC_SERVLET_PATH=" + request.getAttribute("ASYNC_SERVLET_PATH")); + response.getWriter().println( + "ASYNC_QUERY_STRING=" + request.getAttribute("ASYNC_QUERY_STRING")); + + try { + request.startAsync(); + } catch (java.lang.IllegalStateException ex) { + response.getWriter().println("startAsync called again"); + response.getWriter() + .println("Expected IllegalStateException thrown" + ex.getMessage()); + } + ac.complete(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests6.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests6.java new file mode 100644 index 0000000000..e9db4973a9 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/DispatchTests6.java @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class DispatchTests6 extends GenericServlet { + + private static final String TEST_HEADER = "testname"; + + private static final Class[] TEST_ARGS = { ServletRequest.class, + ServletResponse.class }; + + public void service(ServletRequest req, ServletResponse res) + throws ServletException, IOException { + String test = req.getParameter(TEST_HEADER); + try { + Method method = this.getClass().getMethod(test, TEST_ARGS); + method.invoke(this, new Object[] { req, res }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + } + + public void dispatchTest6(ServletRequest request, ServletResponse response) + throws IOException { + response.getWriter() + .println("After dispatch=" + System.currentTimeMillis()); + response.getWriter().println("ASYNC_STARTED_dispatchTest6"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + response.getWriter() + .println("REQUEST_URI=" + request.getAttribute("REQUEST_URI")); + response.getWriter() + .println("CONTEXT_PATH=" + request.getAttribute("CONTEXT_PATH")); + response.getWriter() + .println("PATH_INFO=" + request.getAttribute("PATH_INFO")); + response.getWriter() + .println("SERVLET_PATH=" + request.getAttribute("SERVLET_PATH")); + response.getWriter() + .println("QUERY_STRING=" + request.getAttribute("QUERY_STRING")); + response.getWriter().println( + "ASYNC_REQUEST_URI=" + request.getAttribute("ASYNC_REQUEST_URI")); + response.getWriter().println( + "ASYNC_CONTEXT_PATH=" + request.getAttribute("ASYNC_CONTEXT_PATH")); + response.getWriter() + .println("ASYNC_PATH_INFO=" + request.getAttribute("ASYNC_PATH_INFO")); + response.getWriter().println( + "ASYNC_SERVLET_PATH=" + request.getAttribute("ASYNC_SERVLET_PATH")); + response.getWriter().println( + "ASYNC_QUERY_STRING=" + request.getAttribute("ASYNC_QUERY_STRING")); + + AsyncContext ac = request.startAsync(request, response); + response.getWriter().println("startAsync called"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + response.getWriter() + .println("REQUEST_URI=" + request.getAttribute("REQUEST_URI")); + response.getWriter() + .println("CONTEXT_PATH=" + request.getAttribute("CONTEXT_PATH")); + response.getWriter() + .println("PATH_INFO=" + request.getAttribute("PATH_INFO")); + response.getWriter() + .println("SERVLET_PATH=" + request.getAttribute("SERVLET_PATH")); + response.getWriter() + .println("QUERY_STRING=" + request.getAttribute("QUERY_STRING")); + response.getWriter().println( + "ASYNC_REQUEST_URI=" + request.getAttribute("ASYNC_REQUEST_URI")); + response.getWriter().println( + "ASYNC_CONTEXT_PATH=" + request.getAttribute("ASYNC_CONTEXT_PATH")); + response.getWriter() + .println("ASYNC_PATH_INFO=" + request.getAttribute("ASYNC_PATH_INFO")); + response.getWriter().println( + "ASYNC_SERVLET_PATH=" + request.getAttribute("ASYNC_SERVLET_PATH")); + response.getWriter().println( + "ASYNC_QUERY_STRING=" + request.getAttribute("ASYNC_QUERY_STRING")); + + try { + request.startAsync(request, response); + } catch (java.lang.IllegalStateException ex) { + response.getWriter().println("startAsync called again"); + response.getWriter() + .println("Expected IllegalStateException thrown" + ex.getMessage()); + } + ac.complete(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/TestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/TestListener.java new file mode 100644 index 0000000000..9eba8221f1 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/TestListener.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2012, 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest; + +import java.io.IOException; + +import jakarta.servlet.AsyncEvent; +import jakarta.servlet.AsyncListener; +import jakarta.servlet.RequestDispatcher; + +public final class TestListener implements AsyncListener { + + public TestListener() throws IOException { + } + + public void onError(AsyncEvent event) throws IOException { + event.getSuppliedResponse().getWriter() + .println("in onError method of TestListener"); + event.getSuppliedResponse().getWriter() + .println(event.getThrowable().getMessage()); + event.getSuppliedResponse().getWriter().println(event.getSuppliedRequest() + .getAttribute(RequestDispatcher.ERROR_EXCEPTION)); + } + + public void onStartAsync(AsyncEvent event) throws IOException { + event.getSuppliedResponse().getWriter() + .println("in onStartAsync method of TestListener"); + } + + public void onComplete(AsyncEvent event) throws IOException { + event.getSuppliedResponse().getWriter() + .println("in onComplete method of TestListener"); + } + + public void onTimeout(AsyncEvent event) throws IOException { + event.getSuppliedResponse().getWriter() + .println("in onTimeout method of TestListener"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/TestListener0.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/TestListener0.java new file mode 100644 index 0000000000..4c2c76dd03 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/TestListener0.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2013, 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest; + +import java.io.IOException; + +import jakarta.servlet.AsyncEvent; +import jakarta.servlet.AsyncListener; +import jakarta.servlet.RequestDispatcher; + +public final class TestListener0 implements AsyncListener { + + public TestListener0() throws IOException { + } + + public void onError(AsyncEvent event) throws IOException { + event.getSuppliedResponse().getWriter() + .println("in onError method of TestListener0"); + event.getSuppliedResponse().getWriter() + .println(event.getThrowable().getMessage()); + event.getSuppliedResponse().getWriter().println(event.getSuppliedRequest() + .getAttribute(RequestDispatcher.ERROR_EXCEPTION)); + } + + public void onStartAsync(AsyncEvent event) throws IOException { + event.getSuppliedResponse().getWriter() + .println("in onStartAsync method of TestListener0"); + } + + public void onComplete(AsyncEvent event) throws IOException { + event.getSuppliedResponse().getWriter() + .println("in onComplete method of TestListener0"); + } + + public void onTimeout(AsyncEvent event) throws IOException { + event.getSuppliedResponse().getWriter() + .println("in onTimeout method of TestListener0"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/TestListener1.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/TestListener1.java new file mode 100644 index 0000000000..3f033bc661 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/TestListener1.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2012, 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest; + +import java.io.IOException; + +import jakarta.servlet.AsyncEvent; +import jakarta.servlet.AsyncListener; +import jakarta.servlet.RequestDispatcher; + +public final class TestListener1 implements AsyncListener { + + public TestListener1() throws IOException { + } + + public void onError(AsyncEvent event) throws IOException { + event.getSuppliedResponse().getWriter() + .println("in onError method of TestListener1"); + event.getSuppliedResponse().getWriter() + .println(event.getThrowable().getMessage()); + event.getSuppliedResponse().getWriter().println(event.getSuppliedRequest() + .getAttribute(RequestDispatcher.ERROR_EXCEPTION)); + } + + public void onStartAsync(AsyncEvent event) throws IOException { + event.getSuppliedResponse().getWriter() + .println("in onStartAsync method of TestListener1"); + } + + public void onComplete(AsyncEvent event) throws IOException { + throw new IOException("in onComplete method of TestListener1"); + } + + public void onTimeout(AsyncEvent event) throws IOException { + event.getSuppliedResponse().getWriter() + .println("in onTimeout method of TestListener1"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/TestListener2.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/TestListener2.java new file mode 100644 index 0000000000..be0bbcadb8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/TestListener2.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2012, 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest; + +import java.io.IOException; + +import jakarta.servlet.AsyncEvent; +import jakarta.servlet.AsyncListener; +import jakarta.servlet.RequestDispatcher; + +public final class TestListener2 implements AsyncListener { + + public TestListener2() throws IOException { + } + + public void onError(AsyncEvent event) throws IOException { + event.getSuppliedResponse().getWriter() + .println("in onError method of TestListener2"); + event.getSuppliedResponse().getWriter() + .println(event.getThrowable().getMessage()); + event.getSuppliedResponse().getWriter().println(event.getSuppliedRequest() + .getAttribute(RequestDispatcher.ERROR_EXCEPTION)); + event.getAsyncContext().complete(); + } + + public void onStartAsync(AsyncEvent event) throws IOException { + event.getSuppliedResponse().getWriter() + .println("in onStartAsync method of TestListener2"); + } + + public void onComplete(AsyncEvent event) throws IOException { + event.getSuppliedResponse().getWriter() + .println("in onComplete method of TestListener2"); + } + + public void onTimeout(AsyncEvent event) throws IOException { + event.getSuppliedResponse().getWriter() + .println("in onTimeout method of TestListener2"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/TestListener3.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/TestListener3.java new file mode 100644 index 0000000000..1b73ce8fde --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/TestListener3.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2012, 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest; + +import java.io.IOException; + +import jakarta.servlet.AsyncEvent; +import jakarta.servlet.AsyncListener; +import jakarta.servlet.RequestDispatcher; + +public final class TestListener3 implements AsyncListener { + + public TestListener3() throws IOException { + } + + public void onError(AsyncEvent event) throws IOException { + event.getSuppliedResponse().getWriter() + .println("in onError method of TestListener3"); + event.getSuppliedResponse().getWriter() + .println(event.getThrowable().getMessage()); + event.getSuppliedResponse().getWriter().println(event.getSuppliedRequest() + .getAttribute(RequestDispatcher.ERROR_EXCEPTION)); + event.getAsyncContext().complete(); + } + + public void onStartAsync(AsyncEvent event) throws IOException { + event.getSuppliedResponse().getWriter() + .println("in onStartAsync method of TestListener3"); + } + + public void onComplete(AsyncEvent event) throws IOException { + event.getSuppliedResponse().getWriter() + .println("in onComplete method of TestListener3"); + } + + public void onTimeout(AsyncEvent event) throws IOException { + event.getSuppliedResponse().getWriter() + .println("in onTimeout method of TestListener3"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/URLClient.java new file mode 100644 index 0000000000..c50218a248 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/URLClient.java @@ -0,0 +1,1223 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.container.test.api.OperateOnDeployment; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.net.URL; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("DispatchTestServlet"); + } + + @ArquillianResource + @OperateOnDeployment("servlet_js_dispatchtest_web1") + public URL url2; + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_dispatchtest_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(DispatchTestServlet.class, DispatchTests.class, DispatchTests1.class, DispatchTests2.class, + DispatchTests3.class, DispatchTests4.class, DispatchTests5.class, DispatchTests6.class, TestListener.class, + TestListener0.class, TestListener1.class, TestListener2.class, TestListener3.class, + DispatchTestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_js_dispatchtest_web.xml")); + } + + @Deployment(testable = false, name = "servlet_js_dispatchtest_web1") + public static WebArchive getTestArchive1() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_dispatchtest1_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(DispatchTests10.class, DispatchTests11.class, DispatchTests12.class, + DispatchTests13.class, DispatchTests14.class, DispatchTests15.class, + DispatchTests16.class, DispatchTests17.class, DispatchTests18.class, + DispatchTests19.class,DispatchTests20.class, + DispatchTestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_js_dispatchtest1_web.xml")); + } + + + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + /* + * @testName: dispatchReturnTest + * + * @assertion_ids: Servlet:JAVADOC:639; Servlet:JAVADOC:639.2; + * Servlet:JAVADOC:639.3; Servlet:JAVADOC:639.4; Servlet:JAVADOC:639.5; + * Servlet:JAVADOC:703; Servlet:JAVADOC:707; Servlet:JAVADOC:708; + * Servlet:JAVADOC:710; + * + * @test_Strategy: Create a Servlet DispatchTestServlet which supports async; + * Client send a request to DispatchTestServlet; StartAsync in + * DispatchTestServlet ServletRequest.startAsync(); call ac.dispatch(); call + * ServletRequest.isAsyncSupported() call ServletRequest.isAsyncStarted() call + * ServletRequest.getDispatcherType() check System times: before calling + * dispatch; dispatch returns dispatch operation starts. verifies all work + * accordingly. + */ + @Test + public void dispatchReturnTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "dispatchReturnTest"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_dispatchReturnTest|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "Before dispatch|" + "dispatch return|" + "After dispatch|" + + "ASYNC_STARTED_dispatchReturnTest|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: dispatchReturnTest1 + * + * @assertion_ids: Servlet:JAVADOC:639; Servlet:JAVADOC:639.2; + * Servlet:JAVADOC:639.3; Servlet:JAVADOC:639.4; Servlet:JAVADOC:639.5; + * Servlet:JAVADOC:703; Servlet:JAVADOC:707; Servlet:JAVADOC:708; + * Servlet:JAVADOC:712; + * + * @test_Strategy: Create a Servlet DispatchTestServlet which supports async; + * Client send a request to DispatchTestServlet; StartAsync in + * DispatchTestServlet ServletRequest.startAsync(request, response); call + * ac.dispatch(); call ServletRequest.isAsyncSupported() call + * ServletRequest.isAsyncStarted() call ServletRequest.getDispatcherType() + * check System times: before calling dispatch; dispatch returns dispatch + * operation starts. verifies all work accordingly. + */ + @Test + public void dispatchReturnTest1() throws Exception { + TEST_PROPS.setProperty(APITEST, "dispatchReturnTest1"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_dispatchReturnTest1|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "Before dispatch|" + "dispatch return|" + "After dispatch|" + + "ASYNC_STARTED_dispatchReturnTest1|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: dispatchReturnTest2 + * + * @assertion_ids: Servlet:JAVADOC:640; Servlet:JAVADOC:640.1; + * Servlet:JAVADOC:703; Servlet:JAVADOC:707; Servlet:JAVADOC:708; + * Servlet:JAVADOC:710; + * + * @test_Strategy: Create a Servlet DispatchTestServlet which supports async; + * Client send a request to DispatchTestServlet; StartAsync in + * DispatchTestServlet ServletRequest.startAsync(); call ac.dispatch(URI); + * call ServletRequest.isAsyncSupported() call ServletRequest.isAsyncStarted() + * call ServletRequest.getDispatcherType() check System times: before calling + * dispatch; dispatch returns dispatch operation starts. verifies all work + * accordingly. + */ + @Test + public void dispatchReturnTest2() throws Exception { + TEST_PROPS.setProperty(APITEST, "dispatchReturnTest2"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_dispatchReturnTest2|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "Before dispatch|" + "dispatch return|" + "After dispatch|" + + "ASYNC_STARTED_dispatchTest|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: dispatchReturnTest3 + * + * @assertion_ids: Servlet:JAVADOC:640; Servlet:JAVADOC:640.1; + * Servlet:JAVADOC:703; Servlet:JAVADOC:707; Servlet:JAVADOC:708; + * Servlet:JAVADOC:712; + * + * @test_Strategy: Create a Servlet DispatchTestServlet which supports async; + * Client send a request to DispatchTestServlet; StartAsync in + * DispatchTestServlet ServletRequest.startAsync(request, response); call + * ac.dispatch(URI); call ServletRequest.isAsyncSupported() call + * ServletRequest.isAsyncStarted() call ServletRequest.getDispatcherType() + * check System times: before calling dispatch; dispatch returns dispatch + * operation starts. verifies all work accordingly. + */ + @Test + public void dispatchReturnTest3() throws Exception { + TEST_PROPS.setProperty(APITEST, "dispatchReturnTest3"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_dispatchReturnTest3|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "Before dispatch|" + "dispatch return|" + "After dispatch|" + + "ASYNC_STARTED_dispatchTest|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: dispatchReturnTest4 + * + * @assertion_ids: Servlet:JAVADOC:219; Servlet:JAVADOC:641; + * Servlet:JAVADOC:641.1; Servlet:JAVADOC:703; Servlet:JAVADOC:706; + * Servlet:JAVADOC:707; Servlet:JAVADOC:708; Servlet:JAVADOC:710; + * + * @test_Strategy: Create a Servlet DispatchTestServlet which supports async; + * Client send a request to DispatchTestServlet; StartAsync in + * DispatchTestServlet ServletRequest.startAsync(); call + * ac.dispatch(ServletContext,URI); call ServletRequest.isAsyncSupported() + * call ServletRequest.isAsyncStarted() call + * ServletRequest.getDispatcherType() check System times: before calling + * dispatch; dispatch returns dispatch operation starts. verifies all work + * accordingly. + */ + @Test + public void dispatchReturnTest4() throws Exception { + TEST_PROPS.setProperty(APITEST, "dispatchReturnTest4"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_dispatchReturnTest4|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "Before dispatch|" + "dispatch return|" + "After dispatch|" + + "ASYNC_STARTED_dispatchTest10|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: dispatchReturnTest5 + * + * @assertion_ids: Servlet:JAVADOC:219; Servlet:JAVADOC:641; + * Servlet:JAVADOC:641.1; Servlet:JAVADOC:703; Servlet:JAVADOC:706; + * Servlet:JAVADOC:707; Servlet:JAVADOC:708; Servlet:JAVADOC:712; + * + * @test_Strategy: Create a Servlet DispatchTestServlet which supports async; + * Client send a request to DispatchTestServlet; StartAsync in + * DispatchTestServlet ServletRequest.startAsync(request, response); call + * ac.dispatch(ServletContext,URI); call ServletRequest.isAsyncSupported() + * call ServletRequest.isAsyncStarted() call + * ServletRequest.getDispatcherType() check System times: before calling + * dispatch; dispatch returns dispatch operation starts. verifies all work + * accordingly. + */ + @Test + public void dispatchReturnTest5() throws Exception { + TEST_PROPS.setProperty(APITEST, "dispatchReturnTest5"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_dispatchReturnTest5|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "Before dispatch|" + "dispatch return|" + "After dispatch|" + + "ASYNC_STARTED_dispatchTest10|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: startAsyncAgainTest + * + * @assertion_ids: Servlet:JAVADOC:639; Servlet:JAVADOC:639.2; + * Servlet:JAVADOC:639.3; Servlet:JAVADOC:639.4; Servlet:JAVADOC:639.5; + * Servlet:JAVADOC:703; Servlet:JAVADOC:707; Servlet:JAVADOC:708; + * Servlet:JAVADOC:710; + * + * @test_Strategy: Create a Servlet DispatchTestServlet which supports async; + * Client send a request to DispatchTestServlet; StartAsync in + * DispatchTestServlet ServletRequest.startAsync(); call ac.dispatch(); call + * ServletRequest.isAsyncSupported() call ServletRequest.isAsyncStarted() call + * ServletRequest.getDispatcherType() check System times: before calling + * dispatch; dispatch returns dispatch operation starts. StartAsync and + * dispatch again, and check all above; verifies all work accordingly. + */ + @Test + public void startAsyncAgainTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "startAsyncAgainTest"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_startAsyncAgainTest|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "Before dispatch|" + "dispatch return|" + "After dispatch|" + + "ASYNC_STARTED_startAsyncAgainTest|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC|" + + "Before second dispatch|" + "second dispatch return|" + + "After second dispatch|" + + "ASYNC_STARTED_AGAIN_startAsyncAgainTest|" + + "IsAsyncSupported=true|" + "IsAsyncStarted=false|" + + "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: startAsyncAgainTest1 + * + * @assertion_ids: Servlet:JAVADOC:639; Servlet:JAVADOC:639.2; + * Servlet:JAVADOC:639.3; Servlet:JAVADOC:639.4; Servlet:JAVADOC:639.5; + * Servlet:JAVADOC:703; Servlet:JAVADOC:707; Servlet:JAVADOC:708; + * Servlet:JAVADOC:712; + * + * @test_Strategy: Create a Servlet DispatchTestServlet which supports async; + * Client send a request to DispatchTestServlet; StartAsync in + * DispatchTestServlet ServletRequest.startAsync(request, response); call + * ac.dispatch(); call ServletRequest.isAsyncSupported() call + * ServletRequest.isAsyncStarted() call ServletRequest.getDispatcherType() + * check System times: before calling dispatch; dispatch returns dispatch + * operation starts. StartAsync and dispatch again, and check all above; + * verifies all work accordingly. + */ + @Test + public void startAsyncAgainTest1() throws Exception { + TEST_PROPS.setProperty(APITEST, "startAsyncAgainTest1"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_startAsyncAgainTest1|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "Before dispatch|" + "dispatch return|" + "After dispatch|" + + "ASYNC_STARTED_startAsyncAgainTest1|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC|" + + "Before second dispatch|" + "second dispatch return|" + + "After second dispatch|" + + "ASYNC_STARTED_AGAIN_startAsyncAgainTest1|" + + "IsAsyncSupported=true|" + "IsAsyncStarted=false|" + + "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: startAsyncAgainTest2 + * + * @assertion_ids: Servlet:JAVADOC:639; Servlet:JAVADOC:639.2; + * Servlet:JAVADOC:639.3; Servlet:JAVADOC:639.4; Servlet:JAVADOC:639.5; + * Servlet:JAVADOC:639.10; Servlet:JAVADOC:703; Servlet:JAVADOC:707; + * Servlet:JAVADOC:708; Servlet:JAVADOC:710; + * + * @test_Strategy: Create a Servlet DispatchTestServlet which supports async; + * Client send a request to DispatchTestServlet; StartAsync in + * DispatchTestServlet ServletRequest.startAsync(); call ac.dispatch(); call + * ServletRequest.isAsyncSupported() call ServletRequest.isAsyncStarted() call + * ServletRequest.getDispatcherType() check System times: before calling + * dispatch; dispatch returns dispatch operation starts. StartAsync again in + * dispatched thread, and check all above; ac.complete(); verifies all work + * accordingly. + */ + @Test + public void startAsyncAgainTest2() throws Exception { + TEST_PROPS.setProperty(APITEST, "startAsyncAgainTest2"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_startAsyncAgainTest2|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "Before dispatch|" + "dispatch return|" + "After dispatch|" + + "ASYNC_STARTED_startAsyncAgainTest2|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC|" + + "Before complete"); + invoke(); + } + + /* + * @testName: startAsyncAgainTest3 + * + * @assertion_ids: Servlet:JAVADOC:639; Servlet:JAVADOC:639.2; + * Servlet:JAVADOC:639.3; Servlet:JAVADOC:639.4; Servlet:JAVADOC:639.5; + * Servlet:JAVADOC:639.10; Servlet:JAVADOC:703; Servlet:JAVADOC:707; + * Servlet:JAVADOC:708; Servlet:JAVADOC:712; + * + * @test_Strategy: Create a Servlet DispatchTestServlet which supports async; + * Client send a request to DispatchTestServlet; StartAsync in + * DispatchTestServlet ServletRequest.startAsync(request, response); call + * ac.dispatch(); call ServletRequest.isAsyncSupported() call + * ServletRequest.isAsyncStarted() call ServletRequest.getDispatcherType() + * check System times: before calling dispatch; dispatch returns dispatch + * operation starts. StartAsync again in dispatched thread, and check all + * above; call ac.complete(); verifies all work accordingly. + */ + @Test + public void startAsyncAgainTest3() throws Exception { + TEST_PROPS.setProperty(APITEST, "startAsyncAgainTest3"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_startAsyncAgainTest3|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "Before dispatch|" + "dispatch return|" + "After dispatch|" + + "ASYNC_STARTED_startAsyncAgainTest3|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC|" + + "Before complete"); + invoke(); + } + + /* + * @testName: startAsyncAgainTest4 + * + * @assertion_ids: Servlet:JAVADOC:639; Servlet:JAVADOC:639.2; + * Servlet:JAVADOC:639.3; Servlet:JAVADOC:639.4; Servlet:JAVADOC:639.5; + * Servlet:JAVADOC:639.9; Servlet:JAVADOC:703; Servlet:JAVADOC:707; + * Servlet:JAVADOC:708; Servlet:JAVADOC:710; + * + * @test_Strategy: Create a Servlet DispatchTestServlet which supports async; + * Client send a request to DispatchTestServlet; StartAsync in + * DispatchTestServlet ServletRequest.startAsync(); call ac.dispatch(); call + * ServletRequest.isAsyncSupported() call ServletRequest.isAsyncStarted() call + * ServletRequest.getDispatcherType() check System times: before calling + * dispatch; dispatch returns dispatch operation starts. StartAsync in + * dispatched thread, and check all above; StartAsync again in the + * asynchrounous thread verifies all work accordingly. + */ + @Test + public void startAsyncAgainTest4() throws Exception { + TEST_PROPS.setProperty(APITEST, "startAsyncAgainTest4"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_startAsyncAgainTest4|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "Before dispatch|" + "dispatch return|" + "After dispatch|" + + "ASYNC_STARTED_startAsyncAgainTest4|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC|" + + "startAsync called|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=true|" + "DispatcherType=ASYNC|" + + "startAsync called again|" + + "Expected IllegalStateException thrown"); + invoke(); + } + + /* + * @testName: startAsyncAgainTest5 + * + * @assertion_ids: Servlet:JAVADOC:639; Servlet:JAVADOC:639.2; + * Servlet:JAVADOC:639.3; Servlet:JAVADOC:639.4; Servlet:JAVADOC:639.5; + * Servlet:JAVADOC:639.9; Servlet:JAVADOC:703; Servlet:JAVADOC:707; + * Servlet:JAVADOC:708; Servlet:JAVADOC:712; + * + * @test_Strategy: Create a Servlet DispatchTestServlet which supports async; + * Client send a request to DispatchTestServlet; StartAsync in + * DispatchTestServlet ServletRequest.startAsync(request, response); call + * ac.dispatch(); call ServletRequest.isAsyncSupported() call + * ServletRequest.isAsyncStarted() call ServletRequest.getDispatcherType() + * check System times: before calling dispatch; dispatch returns dispatch + * operation starts. StartAsync in dispatched thread, and check all above; + * StartAsync again in the asynchrounous thread verifies all work accordingly. + */ + @Test + public void startAsyncAgainTest5() throws Exception { + TEST_PROPS.setProperty(APITEST, "startAsyncAgainTest5"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_startAsyncAgainTest5|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "Before dispatch|" + "dispatch return|" + "After dispatch|" + + "ASYNC_STARTED_startAsyncAgainTest5|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC|" + + "startAsync called|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=true|" + "DispatcherType=ASYNC|" + + "startAsync called again|" + + "Expected IllegalStateException thrown"); + invoke(); + } + + /* + * @testName: startAsyncAgainTest6 + * + * @assertion_ids: Servlet:JAVADOC:640; Servlet:JAVADOC:640.1; + * Servlet:JAVADOC:640.2; Servlet:JAVADOC:640.4; Servlet:JAVADOC:703; + * Servlet:JAVADOC:707; Servlet:JAVADOC:708; Servlet:JAVADOC:710; + * + * @test_Strategy: Create a Servlet DispatchTestServlet which supports async; + * Client send a request to DispatchTestServlet; StartAsync in + * DispatchTestServlet ServletRequest.startAsync(); call ac.dispatch(URI); + * call ServletRequest.isAsyncSupported() call ServletRequest.isAsyncStarted() + * call ServletRequest.getDispatcherType() check request's attributes: + * REQUEST_URI CONTEXT_PATH PATH_INFO SERVLET_PATH QUERY_STRING + * ASYNC_REQUEST_URI ASYNC_CONTEXT_PATH ASYNC_PATH_INFO ASYNC_SERVLET_PATH + * ASYNC_QUERY_STRING check System times: before calling dispatch; dispatch + * returns dispatch operation starts. StartAsync again, and check all above; + * call ac.dispatch(URI); verifies all work accordingly. + */ + @Test + public void startAsyncAgainTest6() throws Exception { + TEST_PROPS.setProperty(APITEST, "startAsyncAgainTest6"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_startAsyncAgainTest6|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "Before dispatch|" + "dispatch return|" + "After dispatch|" + + "ASYNC_STARTED_dispatchTest1|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC|" + + "Before second dispatch|" + "second dispatch return|" + + "After dispatch|" + "ASYNC_STARTED_dispatchTest|" + + "IsAsyncSupported=true|" + "IsAsyncStarted=false|" + + "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: startAsyncAgainTest7 + * + * @assertion_ids: Servlet:JAVADOC:640; Servlet:JAVADOC:640.1; + * Servlet:JAVADOC:640.2; Servlet:JAVADOC:640.4; Servlet:JAVADOC:703; + * Servlet:JAVADOC:707; Servlet:JAVADOC:708; Servlet:JAVADOC:712; + * + * @test_Strategy: Create a Servlet DispatchTestServlet which supports async; + * Client send a request to DispatchTestServlet; StartAsync in + * DispatchTestServlet ServletRequest.startAsync(request, response); call + * ac.dispatch(URI); call ServletRequest.isAsyncSupported() call + * ServletRequest.isAsyncStarted() call ServletRequest.getDispatcherType() + * check request's attributes: REQUEST_URI CONTEXT_PATH PATH_INFO SERVLET_PATH + * QUERY_STRING ASYNC_REQUEST_URI ASYNC_CONTEXT_PATH ASYNC_PATH_INFO + * ASYNC_SERVLET_PATH ASYNC_QUERY_STRING check System times: before calling + * dispatch; dispatch returns dispatch operation starts. StartAsync again, and + * check all above; call ac.dispatch(URI); verifies all work accordingly. + */ + @Test + public void startAsyncAgainTest7() throws Exception { + TEST_PROPS.setProperty(APITEST, "startAsyncAgainTest7"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_startAsyncAgainTest7|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "Before dispatch|" + "dispatch return|" + "After dispatch|" + + "ASYNC_STARTED_dispatchTest2|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC|" + + "Before second dispatch|" + "second dispatch return|" + + "After dispatch|" + "ASYNC_STARTED_dispatchTest|" + + "IsAsyncSupported=true|" + "IsAsyncStarted=false|" + + "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: startAsyncAgainTest8 + * + * @assertion_ids: Servlet:JAVADOC:640; Servlet:JAVADOC:640.1; + * Servlet:JAVADOC:640.2; Servlet:JAVADOC:640.4; Servlet:JAVADOC:703; + * Servlet:JAVADOC:707; Servlet:JAVADOC:708; Servlet:JAVADOC:710; + * + * @test_Strategy: Create a Servlet DispatchTestServlet which supports async; + * Client send a request to DispatchTestServlet; StartAsync in + * DispatchTestServlet ServletRequest.startAsync(); call ac.dispatch(URI); + * call ServletRequest.isAsyncSupported() call ServletRequest.isAsyncStarted() + * call ServletRequest.getDispatcherType() check request's attributes: + * REQUEST_URI CONTEXT_PATH PATH_INFO SERVLET_PATH QUERY_STRING + * ASYNC_REQUEST_URI ASYNC_CONTEXT_PATH ASYNC_PATH_INFO ASYNC_SERVLET_PATH + * ASYNC_QUERY_STRING check System times: before calling dispatch; dispatch + * returns dispatch operation starts. StartAsync again in dispatched thread, + * and check all above; ac.complete(); verifies all work accordingly. + */ + @Test + public void startAsyncAgainTest8() throws Exception { + TEST_PROPS.setProperty(APITEST, "startAsyncAgainTest8"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_startAsyncAgainTest8|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "Before dispatch|" + "dispatch return|" + "After dispatch|" + + "ASYNC_STARTED_dispatchTest3|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC|" + + "Before complete"); + invoke(); + } + + /* + * @testName: startAsyncAgainTest9 + * + * @assertion_ids: Servlet:JAVADOC:640; Servlet:JAVADOC:640.1; + * Servlet:JAVADOC:640.2; Servlet:JAVADOC:640.4; Servlet:JAVADOC:703; + * Servlet:JAVADOC:707; Servlet:JAVADOC:708; Servlet:JAVADOC:712; + * + * @test_Strategy: Create a Servlet DispatchTestServlet which supports async; + * Client send a request to DispatchTestServlet; StartAsync in + * DispatchTestServlet ServletRequest.startAsync(request, response); call + * ac.dispatch(URI); call ServletRequest.isAsyncSupported() call + * ServletRequest.isAsyncStarted() call ServletRequest.getDispatcherType() + * check request's attributes: REQUEST_URI CONTEXT_PATH PATH_INFO SERVLET_PATH + * QUERY_STRING ASYNC_REQUEST_URI ASYNC_CONTEXT_PATH ASYNC_PATH_INFO + * ASYNC_SERVLET_PATH ASYNC_QUERY_STRING check System times: before calling + * dispatch; dispatch returns dispatch operation starts. StartAsync again in + * dispatched thread, and check all above; call ac.complete(); verifies all + * work accordingly. + */ + @Test + public void startAsyncAgainTest9() throws Exception { + TEST_PROPS.setProperty(APITEST, "startAsyncAgainTest9"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_startAsyncAgainTest9|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "Before dispatch|" + "dispatch return|" + "After dispatch|" + + "ASYNC_STARTED_dispatchTest4|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC|" + + "Before complete"); + invoke(); + } + + /* + * @testName: startAsyncAgainTest10 + * + * @assertion_ids: Servlet:JAVADOC:640; Servlet:JAVADOC:640.1; + * Servlet:JAVADOC:640.2; Servlet:JAVADOC:640.3; Servlet:JAVADOC:703; + * Servlet:JAVADOC:707; Servlet:JAVADOC:708; Servlet:JAVADOC:710; + * + * @test_Strategy: Create a Servlet DispatchTestServlet which supports async; + * Client send a request to DispatchTestServlet; StartAsync in + * DispatchTestServlet ServletRequest.startAsync(); call ac.dispatch(URI); + * call ServletRequest.isAsyncSupported() call ServletRequest.isAsyncStarted() + * call ServletRequest.getDispatcherType() check request's attributes: + * REQUEST_URI CONTEXT_PATH PATH_INFO SERVLET_PATH QUERY_STRING + * ASYNC_REQUEST_URI ASYNC_CONTEXT_PATH ASYNC_PATH_INFO ASYNC_SERVLET_PATH + * ASYNC_QUERY_STRING check System times: before calling dispatch; dispatch + * returns dispatch operation starts. StartAsync in dispatched thread, and + * check all above; StartAsync again in the asynchrounous thread verifies all + * work accordingly. + */ + @Test + public void startAsyncAgainTest10() throws Exception { + TEST_PROPS.setProperty(APITEST, "startAsyncAgainTest10"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_startAsyncAgainTest10|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "Before dispatch|" + "dispatch return|" + "After dispatch|" + + "ASYNC_STARTED_dispatchTest5|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC|" + + "startAsync called|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=true|" + "DispatcherType=ASYNC|" + + "startAsync called again|" + + "Expected IllegalStateException thrown"); + invoke(); + } + + /* + * @testName: startAsyncAgainTest11 + * + * @assertion_ids: Servlet:JAVADOC:640; Servlet:JAVADOC:640.1; + * Servlet:JAVADOC:640.2; Servlet:JAVADOC:640.3; Servlet:JAVADOC:703; + * Servlet:JAVADOC:707; Servlet:JAVADOC:708; Servlet:JAVADOC:712; + * + * @test_Strategy: Create a Servlet DispatchTestServlet which supports async; + * Client send a request to DispatchTestServlet; StartAsync in + * DispatchTestServlet ServletRequest.startAsync(request, response); call + * ac.dispatch(); call ServletRequest.isAsyncSupported() call + * ServletRequest.isAsyncStarted() call ServletRequest.getDispatcherType() + * check request's attributes: REQUEST_URI CONTEXT_PATH PATH_INFO SERVLET_PATH + * QUERY_STRING ASYNC_REQUEST_URI ASYNC_CONTEXT_PATH ASYNC_PATH_INFO + * ASYNC_SERVLET_PATH ASYNC_QUERY_STRING check System times: before calling + * dispatch; dispatch returns dispatch operation starts. StartAsync in + * dispatched thread, and check all above; StartAsync again in the + * asynchrounous thread verifies all work accordingly. + */ + @Test + public void startAsyncAgainTest11() throws Exception { + TEST_PROPS.setProperty(APITEST, "startAsyncAgainTest11"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_startAsyncAgainTest11|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "Before dispatch|" + "dispatch return|" + "After dispatch|" + + "ASYNC_STARTED_dispatchTest6|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC|" + + "startAsync called|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=true|" + "DispatcherType=ASYNC|" + + "startAsync called again|" + + "Expected IllegalStateException thrown"); + invoke(); + } + + /* + * @testName: startAsyncAgainTest12 + * + * @assertion_ids: Servlet:JAVADOC:219; Servlet:JAVADOC:641; + * Servlet:JAVADOC:641.1; Servlet:JAVADOC:641.4; Servlet:JAVADOC:703; + * Servlet:JAVADOC:706; Servlet:JAVADOC:707; Servlet:JAVADOC:708; + * Servlet:JAVADOC:710; + * + * @test_Strategy: Create a Servlet DispatchTestServlet which supports async; + * Client send a request to DispatchTestServlet; StartAsync in + * DispatchTestServlet ServletRequest.startAsync(); call + * ac.dispatch(ServletContext, URI); call ServletRequest.isAsyncSupported() + * call ServletRequest.isAsyncStarted() call + * ServletRequest.getDispatcherType() check System times: before calling + * dispatch; dispatch returns dispatch operation starts. StartAsync and + * dispatch again, and check all above; verifies all work accordingly. + */ + @Test + public void startAsyncAgainTest12() throws Exception { + TEST_PROPS.setProperty(APITEST, "startAsyncAgainTest12"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_startAsyncAgainTest12|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "Before dispatch|" + "dispatch return|" + "After dispatch|" + + "ASYNC_STARTED_dispatchTest11|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC|" + + "Before second dispatch|" + "second dispatch return|" + + "After dispatch|" + "ASYNC_STARTED_dispatchTest|" + + "IsAsyncSupported=true|" + "IsAsyncStarted=false|" + + "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: startAsyncAgainTest13 + * + * @assertion_ids: Servlet:JAVADOC:219; Servlet:JAVADOC:641; + * Servlet:JAVADOC:641.1; Servlet:JAVADOC:641.4; Servlet:JAVADOC:703; + * Servlet:JAVADOC:706; Servlet:JAVADOC:707; Servlet:JAVADOC:708; + * Servlet:JAVADOC:712; + * + * @test_Strategy: Create a Servlet DispatchTestServlet which supports async; + * Client send a request to DispatchTestServlet; StartAsync in + * DispatchTestServlet ServletRequest.startAsync(request, response); call + * ac.dispatch(ServletContext, URI); call ServletRequest.isAsyncSupported() + * call ServletRequest.isAsyncStarted() call + * ServletRequest.getDispatcherType() check System times: before calling + * dispatch; dispatch returns dispatch operation starts. StartAsync and + * dispatch again, and check all above; verifies all work accordingly. + */ + @Test + public void startAsyncAgainTest13() throws Exception { + TEST_PROPS.setProperty(APITEST, "startAsyncAgainTest13"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_startAsyncAgainTest13|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "Before dispatch|" + "dispatch return|" + "After dispatch|" + + "ASYNC_STARTED_dispatchTest12|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC|" + + "Before second dispatch|" + "second dispatch return|" + + "After dispatch|" + "ASYNC_STARTED_dispatchTest|" + + "IsAsyncSupported=true|" + "IsAsyncStarted=false|" + + "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: startAsyncAgainTest14 + * + * @assertion_ids: Servlet:JAVADOC:219; Servlet:JAVADOC:641; + * Servlet:JAVADOC:641.1; Servlet:JAVADOC:641.4; Servlet:JAVADOC:703; + * Servlet:JAVADOC:706;; Servlet:JAVADOC:707; Servlet:JAVADOC:708; + * Servlet:JAVADOC:710; + * + * @test_Strategy: Create a Servlet DispatchTestServlet which supports async; + * Client send a request to DispatchTestServlet; StartAsync in + * DispatchTestServlet ServletRequest.startAsync(); call + * ac.dispatch(ServletContext, URI); call ServletRequest.isAsyncSupported() + * call ServletRequest.isAsyncStarted() call + * ServletRequest.getDispatcherType() check System times: before calling + * dispatch; dispatch returns dispatch operation starts. StartAsync again in + * dispatched thread, and check all above; ac.complete(); verifies all work + * accordingly. + */ + @Test + public void startAsyncAgainTest14() throws Exception { + TEST_PROPS.setProperty(APITEST, "startAsyncAgainTest14"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_startAsyncAgainTest14|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "Before dispatch|" + "dispatch return|" + "After dispatch|" + + "ASYNC_STARTED_dispatchTest13|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC|" + + "Before complete"); + invoke(); + } + + /* + * @testName: startAsyncAgainTest15 + * + * @assertion_ids: Servlet:JAVADOC:219; Servlet:JAVADOC:641; + * Servlet:JAVADOC:641.1; Servlet:JAVADOC:641.4; Servlet:JAVADOC:703; + * Servlet:JAVADOC:706; Servlet:JAVADOC:707; Servlet:JAVADOC:708; + * Servlet:JAVADOC:712; + * + * @test_Strategy: Create a Servlet DispatchTestServlet which supports async; + * Client send a request to DispatchTestServlet; StartAsync in + * DispatchTestServlet ServletRequest.startAsync(request, response); call + * ac.dispatch(); call ServletRequest.isAsyncSupported() call + * ServletRequest.isAsyncStarted() call ServletRequest.getDispatcherType() + * check System times: before calling dispatch; dispatch returns dispatch + * operation starts. StartAsync again in dispatched thread, and check all + * above; call ac.complete(); verifies all work accordingly. + */ + @Test + public void startAsyncAgainTest15() throws Exception { + TEST_PROPS.setProperty(APITEST, "startAsyncAgainTest15"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_startAsyncAgainTest15|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "Before dispatch|" + "dispatch return|" + "After dispatch|" + + "ASYNC_STARTED_dispatchTest14|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC|" + + "Before complete"); + invoke(); + } + + /* + * @testName: startAsyncAgainTest16 + * + * @assertion_ids: Servlet:JAVADOC:219; Servlet:JAVADOC:641; + * Servlet:JAVADOC:641.3; Servlet:JAVADOC:703; Servlet:JAVADOC:706; + * Servlet:JAVADOC:707; Servlet:JAVADOC:708; Servlet:JAVADOC:710; + * + * @test_Strategy: Create a Servlet DispatchTestServlet which supports async; + * Client send a request to DispatchTestServlet; StartAsync in + * DispatchTestServlet ServletRequest.startAsync(); call + * ac.dispatch(ServletContext, URI); call ServletRequest.isAsyncSupported() + * call ServletRequest.isAsyncStarted() call + * ServletRequest.getDispatcherType() check System times: before calling + * dispatch; dispatch returns dispatch operation starts. StartAsync in + * dispatched thread, and check all above; StartAsync again in the + * asynchrounous thread verifies all work accordingly. + */ + @Test + public void startAsyncAgainTest16() throws Exception { + TEST_PROPS.setProperty(APITEST, "startAsyncAgainTest16"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_startAsyncAgainTest16|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "Before dispatch|" + "dispatch return|" + "After dispatch|" + + "ASYNC_STARTED_dispatchTest15|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC|" + + "startAsync called|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=true|" + "DispatcherType=ASYNC|" + + "startAsync called again|" + + "Expected IllegalStateException thrown"); + invoke(); + } + + /* + * @testName: startAsyncAgainTest17 + * + * @assertion_ids: Servlet:JAVADOC:219; Servlet:JAVADOC:641; + * Servlet:JAVADOC:641.3; Servlet:JAVADOC:703; Servlet:JAVADOC:706; + * Servlet:JAVADOC:707; Servlet:JAVADOC:708; Servlet:JAVADOC:712; + * + * @test_Strategy: Create a Servlet DispatchTestServlet which supports async; + * Client send a request to DispatchTestServlet; StartAsync in + * DispatchTestServlet ServletRequest.startAsync(request, response); call + * ac.dispatch(ServletContext, URI); call ServletRequest.isAsyncSupported() + * call ServletRequest.isAsyncStarted() call + * ServletRequest.getDispatcherType() check System times: before calling + * dispatch; dispatch returns dispatch operation starts. StartAsync in + * dispatched thread, and check all above; StartAsync again in the + * asynchrounous thread verifies all work accordingly. + */ + @Test + public void startAsyncAgainTest17() throws Exception { + TEST_PROPS.setProperty(APITEST, "startAsyncAgainTest17"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_startAsyncAgainTest17|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "Before dispatch|" + "dispatch return|" + "After dispatch|" + + "ASYNC_STARTED_dispatchTest16|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC|" + + "startAsync called|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=true|" + "DispatcherType=ASYNC|" + + "startAsync called again|" + + "Expected IllegalStateException thrown"); + invoke(); + } + + /* + * @testName: negativeDispatchTest + * + * @assertion_ids: Servlet:JAVADOC:639; Servlet:JAVADOC:639.2; + * Servlet:JAVADOC:639.3; Servlet:JAVADOC:639.4; Servlet:JAVADOC:639.5; + * Servlet:JAVADOC:639.11; Servlet:JAVADOC:703; Servlet:JAVADOC:707; + * Servlet:JAVADOC:708; Servlet:JAVADOC:710; + * + * @test_Strategy: Create a Servlet DispatchTestServlet which supports async; + * Client send a request to DispatchTestServlet; StartAsync in + * DispatchTestServlet ServletRequest.startAsync(); call + * ServletRequest.isAsyncSupported() call ServletRequest.isAsyncStarted() call + * ServletRequest.getDispatcherType() call ac.dispatch(); check System times: + * before calling dispatch; dispatch returns dispatch operation starts. call + * ac.dispatch() again verifies all work accordingly. + */ + @Test + public void negativeDispatchTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "negativeDispatchTest"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_negativeDispatchTest|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "Before dispatch|" + "dispatch return|" + "dispatch again|" + + "dispatch() called again|" + + "Expected IllegalStateException thrown|" + "After dispatch|" + + "ASYNC_STARTED_negativeDispatchTest|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: negativeDispatchTest1 + * + * @assertion_ids: Servlet:JAVADOC:639; Servlet:JAVADOC:639.2; + * Servlet:JAVADOC:639.3; Servlet:JAVADOC:639.4; Servlet:JAVADOC:639.5; + * Servlet:JAVADOC:639.11; Servlet:JAVADOC:703; Servlet:JAVADOC:707; + * Servlet:JAVADOC:708; Servlet:JAVADOC:712; + * + * @test_Strategy: Create a Servlet DispatchTestServlet which supports async; + * Client send a request to DispatchTestServlet; StartAsync in + * DispatchTestServlet ServletRequest.startAsync(request, response); call + * ServletRequest.isAsyncSupported() call ServletRequest.isAsyncStarted() call + * ServletRequest.getDispatcherType() call ac.dispatch(); check System times: + * before calling dispatch; dispatch returns dispatch operation starts. call + * ac.dispatch() again verifies all work accordingly. + */ + @Test + public void negativeDispatchTest1() throws Exception { + TEST_PROPS.setProperty(APITEST, "negativeDispatchTest1"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_negativeDispatchTest1|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "Before dispatch|" + "dispatch return|" + "dispatch again|" + + "dispatch() called again|" + + "Expected IllegalStateException thrown|" + "After dispatch|" + + "ASYNC_STARTED_negativeDispatchTest1|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: negativeDispatchTest4 + * + * @assertion_ids: Servlet:JAVADOC:640; Servlet:JAVADOC:640.3; + * Servlet:JAVADOC:640.8; Servlet:JAVADOC:703; Servlet:JAVADOC:707; + * Servlet:JAVADOC:708; Servlet:JAVADOC:710; + * + * @test_Strategy: Create a Servlet DispatchTestServlet which supports async; + * Client send a request to DispatchTestServlet; StartAsync in + * DispatchTestServlet ServletRequest.startAsync(request, response); call + * ServletRequest.isAsyncSupported() call ServletRequest.isAsyncStarted() call + * ServletRequest.getDispatcherType() call ac.dispatch(URI); check System + * times: before calling dispatch; dispatch returns dispatch operation starts. + * call ac.dispatch(URI) again verifies all work accordingly. + */ + @Test + public void negativeDispatchTest4() throws Exception { + TEST_PROPS.setProperty(APITEST, "negativeDispatchTest4"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_negativeDispatchTest4|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "Before dispatch|" + "dispatch return|" + "dispatch again|" + + "dispatch(URI) called again|" + + "Expected IllegalStateException thrown|" + "After dispatch|" + + "ASYNC_STARTED_dispatchTest|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: negativeDispatchTest5 + * + * @assertion_ids: Servlet:JAVADOC:640; Servlet:JAVADOC:640.3; + * Servlet:JAVADOC:640.8; Servlet:JAVADOC:703; Servlet:JAVADOC:707; + * Servlet:JAVADOC:708; Servlet:JAVADOC:712; + * + * @test_Strategy: Create a Servlet DispatchTestServlet which supports async; + * Client send a request to DispatchTestServlet; StartAsync in + * DispatchTestServlet ServletRequest.startAsync(request, response); call + * ServletRequest.isAsyncSupported() call ServletRequest.isAsyncStarted() call + * ServletRequest.getDispatcherType() call ac.dispatch(URI); check System + * times: before calling dispatch; dispatch returns dispatch operation starts. + * call ac.dispatch(URI) again verifies all work accordingly. + */ + @Test + public void negativeDispatchTest5() throws Exception { + TEST_PROPS.setProperty(APITEST, "negativeDispatchTest5"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_negativeDispatchTest5|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "Before dispatch|" + "dispatch return|" + "dispatch again|" + + "dispatch(URI) called again|" + + "Expected IllegalStateException thrown|" + "After dispatch|" + + "ASYNC_STARTED_dispatchTest|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: negativeDispatchTest8 + * + * @assertion_ids: SServlet:JAVADOC:219; Servlet:JAVADOC:641; + * Servlet:JAVADOC:641.1; Servlet:JAVADOC:641.2; Servlet:JAVADOC:641.3; + * Servlet:JAVADOC:703; Servlet:JAVADOC:706; Servlet:JAVADOC:707; + * Servlet:JAVADOC:708; Servlet:JAVADOC:710; + * + * @test_Strategy: Create a Servlet DispatchTestServlet which supports async; + * Client send a request to DispatchTestServlet; StartAsync in + * DispatchTestServlet ServletRequest.startAsync(); call + * ServletRequest.isAsyncSupported() call ServletRequest.isAsyncStarted() call + * ServletRequest.getDispatcherType() call ac.dispatch(ServletContext, URI); + * check System times: before calling dispatch; dispatch returns dispatch + * operation starts. call ac.dispatch(ServletContext, URI) again verifies all + * work accordingly. + */ + @Test + public void negativeDispatchTest8() throws Exception { + TEST_PROPS.setProperty(APITEST, "negativeDispatchTest8"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_negativeDispatchTest8|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "Before dispatch|" + "dispatch return|" + "dispatch again|" + + "dispatch() called again|" + + "Expected IllegalStateException thrown|" + "After dispatch|" + + "ASYNC_STARTED_dispatchTest10|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: negativeDispatchTest9 + * + * @assertion_ids: SServlet:JAVADOC:219; Servlet:JAVADOC:641; + * Servlet:JAVADOC:641.1; Servlet:JAVADOC:641.2; Servlet:JAVADOC:641.3; + * Servlet:JAVADOC:703; Servlet:JAVADOC:706; Servlet:JAVADOC:707; + * Servlet:JAVADOC:708; Servlet:JAVADOC:712; + * + * @test_Strategy: Create a Servlet DispatchTestServlet which supports async; + * Client send a request to DispatchTestServlet; StartAsync in + * DispatchTestServlet ServletRequest.startAsync(request, response); call + * ServletRequest.isAsyncSupported() call ServletRequest.isAsyncStarted() call + * ServletRequest.getDispatcherType() call ac.dispatch(ServletContext, URI); + * check System times: before calling dispatch; dispatch returns dispatch + * operation starts. call ac.dispatch(ServletContext, URI) again verifies all + * work accordingly. + */ + @Test + public void negativeDispatchTest9() throws Exception { + TEST_PROPS.setProperty(APITEST, "negativeDispatchTest9"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_negativeDispatchTest9|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "Before dispatch|" + "dispatch return|" + "dispatch again|" + + "dispatch() called again|" + + "Expected IllegalStateException thrown|" + "After dispatch|" + + "ASYNC_STARTED_dispatchTest10|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: negativeDispatchTest12 + * + * @assertion_ids: SServlet:JAVADOC:219; Servlet:JAVADOC:641; + * Servlet:JAVADOC:641.1; Servlet:JAVADOC:641.2; Servlet:JAVADOC:641.3; + * Servlet:JAVADOC:703; Servlet:JAVADOC:706; Servlet:JAVADOC:707; + * Servlet:JAVADOC:708; Servlet:JAVADOC:710; + * + * @test_Strategy: Create a Servlet DispatchTestServlet which supports async; + * Client send a request to DispatchTestServlet; StartAsync in + * DispatchTestServlet ServletRequest.startAsync(); call + * ServletRequest.isAsyncSupported() call ServletRequest.isAsyncStarted() call + * ServletRequest.getDispatcherType() call ac.dispatch(ServletContext,URI); + * check System times: before calling dispatch; dispatch returns dispatch + * operation starts. call ac.dispatch(URI) again verifies all work + * accordingly. + */ + @Test + public void negativeDispatchTest12() throws Exception { + TEST_PROPS.setProperty(APITEST, "negativeDispatchTest12"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_negativeDispatchTest12|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "Before dispatch|" + "dispatch return|" + "dispatch again|" + + "dispatch(URI) called again|" + + "Expected IllegalStateException thrown|" + "After dispatch|" + + "ASYNC_STARTED_dispatchTest10|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: negativeDispatchTest13 + * + * @assertion_ids: SServlet:JAVADOC:219; Servlet:JAVADOC:641; + * Servlet:JAVADOC:641.1; Servlet:JAVADOC:641.2; Servlet:JAVADOC:641.3; + * Servlet:JAVADOC:703; Servlet:JAVADOC:706; Servlet:JAVADOC:707; + * Servlet:JAVADOC:708; Servlet:JAVADOC:712; + * + * @test_Strategy: Create a Servlet DispatchTestServlet which supports async; + * Client send a request to DispatchTestServlet; StartAsync in + * DispatchTestServlet ServletRequest.startAsync(request, response); call + * ServletRequest.isAsyncSupported() call ServletRequest.isAsyncStarted() call + * ServletRequest.getDispatcherType() call ac.dispatch(ServletContext,URI); + * check System times: before calling dispatch; dispatch returns dispatch + * operation starts. call ac.dispatch(URI) again verifies all work + * accordingly. + */ + @Test + public void negativeDispatchTest13() throws Exception { + TEST_PROPS.setProperty(APITEST, "negativeDispatchTest13"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_negativeDispatchTest13|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "Before dispatch|" + "dispatch return|" + "dispatch again|" + + "dispatch(URI) called again|" + + "Expected IllegalStateException thrown|" + "After dispatch|" + + "ASYNC_STARTED_dispatchTest10|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: dispatchAfterCommitTest + * + * @assertion_ids: Servlet:JAVADOC:639.12; Servlet:JAVADOC:707; + * Servlet:JAVADOC:708; Servlet:JAVADOC:710; Servlet:JAVADOC:866; + * Servlet:JAVADOC:872; + * + * @test_Strategy: Create a Servlet DispatchTestServlet which supports async; + * Client send a request to DispatchTestServlet; DispatchTestServlet commits + * the response; StartAsync in DispatchTestServlet + * ServletRequest.startAsync(); call ac.dispatch(); verifies all works + */ + @Test + public void dispatchAfterCommitTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "dispatchAfterCommitTest"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_dispatchAfterCommitTest|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "After commmit|" + "Before dispatch|" + "dispatch return|" + + "After dispatch|" + "ASYNC_STARTED_dispatchAfterCommitTest|" + + "IsAsyncSupported=true|" + "IsAsyncStarted=false|" + + "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: dispatchAfterCommitTest1 + * + * @assertion_ids: Servlet:JAVADOC:639.12; Servlet:JAVADOC:707; + * Servlet:JAVADOC:708; Servlet:JAVADOC:712; Servlet:JAVADOC:866; + * Servlet:JAVADOC:872; + * + * @test_Strategy: Create a Servlet DispatchTestServlet which supports async; + * Client send a request to DispatchTestServlet; DispatchTestServlet commits + * the response; StartAsync in DispatchTestServlet + * ServletRequest.startAsync(request, response); call ac.dispatch(); verifies + * all works + */ + @Test + public void dispatchAfterCommitTest1() throws Exception { + TEST_PROPS.setProperty(APITEST, "dispatchAfterCommitTest1"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_dispatchAfterCommitTest1|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "After commmit|" + "Before dispatch|" + "dispatch return|" + + "After dispatch|" + "ASYNC_STARTED_dispatchAfterCommitTest1|" + + "IsAsyncSupported=true|" + "IsAsyncStarted=false|" + + "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: dispatchAfterCommitTest2 + * + * @assertion_ids: Servlet:JAVADOC:707; Servlet:JAVADOC:708; + * Servlet:JAVADOC:710; Servlet:JAVADOC:866; Servlet:JAVADOC:872; + * + * @test_Strategy: Create a Servlet DispatchTestServlet which supports async; + * Client send a request to DispatchTestServlet; DispatchTestServlet commits + * the response; StartAsync in DispatchTestServlet + * ServletRequest.startAsync(); call ac.dispatch(URI); verifies all works + */ + @Test + public void dispatchAfterCommitTest2() throws Exception { + TEST_PROPS.setProperty(APITEST, "dispatchAfterCommitTest2"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_dispatchAfterCommitTest2|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "After commmit|" + "Before dispatch|" + "dispatch return|" + + "After dispatch|" + "ASYNC_STARTED_dispatchTest|" + + "IsAsyncSupported=true|" + "IsAsyncStarted=false|" + + "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: dispatchAfterCommitTest3 + * + * @assertion_ids: Servlet:JAVADOC:707; Servlet:JAVADOC:708; + * Servlet:JAVADOC:712; Servlet:JAVADOC:866; Servlet:JAVADOC:872; + * + * @test_Strategy: Create a Servlet DispatchTestServlet which supports async; + * Client send a request to DispatchTestServlet; DispatchTestServlet commits + * the response; StartAsync in DispatchTestServlet + * ServletRequest.startAsync(request, response); call ac.dispatch(URI); + * verifies all works + */ + @Test + public void dispatchAfterCommitTest3() throws Exception { + TEST_PROPS.setProperty(APITEST, "dispatchAfterCommitTest3"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_dispatchAfterCommitTest3|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "After commmit|" + "Before dispatch|" + "dispatch return|" + + "After dispatch|" + "ASYNC_STARTED_dispatchTest|" + + "IsAsyncSupported=true|" + "IsAsyncStarted=false|" + + "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: dispatchAfterCommitTest4 + * + * @assertion_ids: Servlet:JAVADOC:707; Servlet:JAVADOC:708; + * Servlet:JAVADOC:710; Servlet:JAVADOC:866; Servlet:JAVADOC:872; + * + * @test_Strategy: Create a Servlet DispatchTestServlet which supports async; + * Client send a request to DispatchTestServlet; DispatchTestServlet commits + * the response; StartAsync in DispatchTestServlet + * ServletRequest.startAsync(); call ac.dispatch(ServletContext,URI); verifies + * all works + */ + @Test + public void dispatchAfterCommitTest4() throws Exception { + TEST_PROPS.setProperty(APITEST, "dispatchAfterCommitTest4"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_dispatchAfterCommitTest4|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "After commmit|" + "Before dispatch|" + "dispatch return|" + + "After dispatch|" + "ASYNC_STARTED_dispatchTest10|" + + "IsAsyncSupported=true|" + "IsAsyncStarted=false|" + + "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: dispatchAfterCommitTest5 + * + * @assertion_ids: Servlet:JAVADOC:707; Servlet:JAVADOC:708; + * Servlet:JAVADOC:712; Servlet:JAVADOC:866; Servlet:JAVADOC:872; + * + * @test_Strategy: Create a Servlet DispatchTestServlet which supports async; + * Client send a request to DispatchTestServlet; DispatchTestServlet commits + * the response; StartAsync in DispatchTestServlet + * ServletRequest.startAsync(request, response); call + * ac.dispatch(ServletContext,URI); verifies all works + */ + @Test + public void dispatchAfterCommitTest5() throws Exception { + TEST_PROPS.setProperty(APITEST, "dispatchAfterCommitTest5"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_dispatchAfterCommitTest5|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "After commmit|" + "Before dispatch|" + "dispatch return|" + + "After dispatch|" + "ASYNC_STARTED_dispatchTest10|" + + "IsAsyncSupported=true|" + "IsAsyncStarted=false|" + + "DispatcherType=ASYNC"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/build.xml new file mode 100644 index 0000000000..eea4d19c89 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/build.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/servlet_js_dispatchtest1_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/servlet_js_dispatchtest1_web.xml new file mode 100644 index 0000000000..866d7d47bc --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/servlet_js_dispatchtest1_web.xml @@ -0,0 +1,124 @@ + + + + + SerJaxSerdispatchtest1 + + DispatchTests10 + com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest.DispatchTests10 + true + + + DispatchTests11 + com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest.DispatchTests11 + true + + + DispatchTests12 + com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest.DispatchTests12 + true + + + DispatchTests13 + com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest.DispatchTests13 + true + + + DispatchTests14 + com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest.DispatchTests14 + true + + + DispatchTests15 + com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest.DispatchTests15 + true + + + DispatchTests16 + com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest.DispatchTests16 + true + + + DispatchTests17 + com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest.DispatchTests17 + true + + + DispatchTests18 + com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest.DispatchTests18 + true + + + DispatchTests19 + com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest.DispatchTests19 + true + + + DispatchTests20 + com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest.DispatchTests20 + true + + + DispatchTests10 + /DispatchTests10 + + + DispatchTests11 + /DispatchTests11 + + + DispatchTests12 + /DispatchTests12 + + + DispatchTests13 + /DispatchTests13 + + + DispatchTests14 + /DispatchTests14 + + + DispatchTests15 + /DispatchTests15 + + + DispatchTests16 + /DispatchTests16 + + + DispatchTests17 + /DispatchTests17 + + + DispatchTests18 + /DispatchTests18 + + + DispatchTests19 + /DispatchTests19 + + + DispatchTests20 + /DispatchTests20 + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/servlet_js_dispatchtest_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/servlet_js_dispatchtest_web.xml new file mode 100644 index 0000000000..870874f2e8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dispatchtest/servlet_js_dispatchtest_web.xml @@ -0,0 +1,97 @@ + + + + + SerJaxSerdispatchtest + + DispatchTestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest.DispatchTestServlet + true + + + DispatchTests + com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest.DispatchTests + true + + + DispatchTests1 + com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest.DispatchTests1 + true + + + DispatchTests2 + com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest.DispatchTests2 + true + + + DispatchTests3 + com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest.DispatchTests3 + true + + + DispatchTests4 + com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest.DispatchTests4 + true + + + DispatchTests5 + com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest.DispatchTests5 + true + + + DispatchTests6 + com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchtest.DispatchTests6 + true + + + DispatchTestServlet + /DispatchTestServlet + + + DispatchTests + /DispatchTests + + + DispatchTests1 + /DispatchTests1 + + + DispatchTests2 + /DispatchTests2 + + + DispatchTests3 + /DispatchTests3 + + + DispatchTests4 + /DispatchTests4 + + + DispatchTests5 + /DispatchTests5 + + + DispatchTests6 + /DispatchTests6 + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dofilter/CTSResponseWrapper.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dofilter/CTSResponseWrapper.java new file mode 100644 index 0000000000..c88585c7a8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dofilter/CTSResponseWrapper.java @@ -0,0 +1,36 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.dofilter; + +import java.io.PrintWriter; + +import jakarta.servlet.ServletResponse; +import jakarta.servlet.ServletResponseWrapper; + +public class CTSResponseWrapper extends ServletResponseWrapper { + + public CTSResponseWrapper(ServletResponse response) + throws java.io.IOException { + super(response); + PrintWriter pw = response.getWriter(); + pw.write("CTSResponseWrapper"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dofilter/ForwardedServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dofilter/ForwardedServlet.java new file mode 100644 index 0000000000..e953ff9e2e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dofilter/ForwardedServlet.java @@ -0,0 +1,43 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.dofilter; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class ForwardedServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + + pw.println("ForwardedServlet"); + ServletTestUtil.printResult(pw, true); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dofilter/IncludedServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dofilter/IncludedServlet.java new file mode 100644 index 0000000000..0a87de3f00 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dofilter/IncludedServlet.java @@ -0,0 +1,44 @@ +/* + * 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 + */ + +/* + * @(#)IncludedServlet.java 1.6 04/02/18 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.dofilter; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class IncludedServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + response.setContentType("text/html"); + ServletTestUtil.printResult(pw, "from IncludedServlet"); + pw.flush(); + pw.close(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dofilter/SetHeaderResponseFilter.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dofilter/SetHeaderResponseFilter.java new file mode 100644 index 0000000000..777f3939ff --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dofilter/SetHeaderResponseFilter.java @@ -0,0 +1,61 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.dofilter; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public final class SetHeaderResponseFilter implements Filter { + + // The filter configuration object we are associated with. If this value + // is null, this filter instance is not currently configured. + private FilterConfig filterConfig = null; + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + PrintWriter pw = response.getWriter(); + + ServletTestUtil.printResult(pw, "in SetHeaderResponseFilter"); + + chain.doFilter(request, response); + + pw.write("modifiedHeader"); + } + + // Remove the filter configuration object for this filter. + public void destroy() { + } + + // initialize the filter configuration object for this filter. + public void init(FilterConfig filterConfig) { + this.filterConfig = filterConfig; + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dofilter/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dofilter/TestServlet.java new file mode 100644 index 0000000000..512aa8e531 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dofilter/TestServlet.java @@ -0,0 +1,41 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.dofilter; + +import java.io.IOException; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; + +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void wrapResponseTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + String path = "/forward/ForwardedServlet"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + rd.forward(request, response); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dofilter/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dofilter/URLClient.java new file mode 100644 index 0000000000..ff2fdfda00 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dofilter/URLClient.java @@ -0,0 +1,77 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.dofilter; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_dofilter_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(CTSResponseWrapper.class, ForwardedServlet.class, IncludedServlet.class, + SetHeaderResponseFilter.class, TestServlet.class, WrapResponseFilter.class) + .setWebXML(URLClient.class.getResource("servlet_js_dofilter_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + + /* + * @testName: wrapResponseTest + * + * @assertion_ids: Servlet:SPEC:54; Servlet:SPEC:59; + * + * @test_Strategy: 1. Create two servlets - TestServlet, ForwardedServlet 2. + * Invoke ForwardedServlet using forward in TestServlet 3. Map a filter + * WrapResponseFilter with dispatcher value set to FORWARD 4. In the filter, + * wrap the response with custom implementation of ServletResponse + * CTSResponseWrapper 5. Verify that filter is properly invoked. + */ + @Test + public void wrapResponseTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "wrapResponseTest"); + TEST_PROPS.setProperty(SEARCH_STRING, + "CTSResponseWrapper|WrapResponseFilter|ForwardedServlet"); + invoke(); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dofilter/WrapResponseFilter.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dofilter/WrapResponseFilter.java new file mode 100644 index 0000000000..e67a896c17 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dofilter/WrapResponseFilter.java @@ -0,0 +1,63 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.dofilter; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public final class WrapResponseFilter implements Filter { + + // The filter configuration object we are associated with. If this value + // is null, this filter instance is not currently configured. + private FilterConfig filterConfig = null; + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + PrintWriter pw = response.getWriter(); + + CTSResponseWrapper wrappedResponse = new CTSResponseWrapper(response); + ServletTestUtil.printResult(pw, "in WrapResponseFilter"); + + chain.doFilter(request, wrappedResponse); + } + + // Remove the filter configuration object for this filter. + public void destroy() { + this.filterConfig = null; + } + + // initialize the filter configuration object for this filter. + + public void init(FilterConfig filterConfig) { + this.filterConfig = filterConfig; + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dofilter/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dofilter/build.xml new file mode 100644 index 0000000000..b66cca7daf --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dofilter/build.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dofilter/servlet_js_dofilter_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dofilter/servlet_js_dofilter_web.xml new file mode 100644 index 0000000000..df760a9bfb --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/dofilter/servlet_js_dofilter_web.xml @@ -0,0 +1,75 @@ + + + + + SerJaxSerDoFilter + + SetHeaderResponseFilter + com.sun.ts.tests.servlet.api.jakarta_servlet.dofilter.SetHeaderResponseFilter + + attribute + com.sun.ts.tests.servlet.api.jakarta_servlet.dofilter.SetHeaderResponseFilter.SERVLET_MAPPED + + + + ResponseWrapperFilter + com.sun.ts.tests.servlet.api.jakarta_servlet.dofilter.WrapResponseFilter + + attribute + com.sun.ts.tests.servlet.api.jakarta_servlet.dofilter.SetHeaderResponseFilter.SERVLET_MAPPED + + + + ResponseWrapperFilter + ForwardedServlet + FORWARD + + + SetHeaderResponseFilter + IncludedServlet + INCLUDE + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.dofilter.TestServlet + + + IncludedServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.dofilter.IncludedServlet + + + ForwardedServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.dofilter.ForwardedServlet + + + TestServlet + /TestServlet + + + IncludedServlet + /include/IncludedServlet + + + ForwardedServlet + /forward/ForwardedServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filter/DoFilterTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filter/DoFilterTestServlet.java new file mode 100644 index 0000000000..4fc9f679c2 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filter/DoFilterTestServlet.java @@ -0,0 +1,83 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.filter; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class DoFilterTestServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + + pw.println( + "This text should not be displayed from the DoFilterTest servlet"); + ServletTestUtil.printResult(pw, false); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filter/DoFilter_Filter.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filter/DoFilter_Filter.java new file mode 100644 index 0000000000..49f5af6af6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filter/DoFilter_Filter.java @@ -0,0 +1,110 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + * * [Additional notices, if required by prior licensing conditions] + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.filter; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public final class DoFilter_Filter implements Filter { + + // The filter configuration object we are associated with. If this value + // is null, this filter instance is not currently configured. + private FilterConfig filterConfig = null; + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + boolean passed = false; + PrintWriter pw = response.getWriter(); + + if (filterConfig == null) { + passed = false; + pw.println( + "doFilter of DoFilter_Filter was called but this filter instance is not currently configured"); + } else { + passed = true; + pw.println("doFilter was successfully called in DoFilter_Filter"); + } + ServletTestUtil.printResult(pw, passed); + + } + + // Remove the filter configuration object for this filter. + public void destroy() { + } + + // initialize the filter configuration object for this filter. + + public void init(FilterConfig filterConfig) { + this.filterConfig = filterConfig; + + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filter/InitFilterConfigTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filter/InitFilterConfigTestServlet.java new file mode 100644 index 0000000000..f8f90b6d2f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filter/InitFilterConfigTestServlet.java @@ -0,0 +1,81 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.filter; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class InitFilterConfigTestServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + pw.println( + "This text should not be displayed from the InitFilterConfigTest servlet"); + ServletTestUtil.printResult(pw, false); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filter/InitFilter_Filter.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filter/InitFilter_Filter.java new file mode 100644 index 0000000000..ebf0372ae2 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filter/InitFilter_Filter.java @@ -0,0 +1,121 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + * * [Additional notices, if required by prior licensing conditions] + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.filter; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Enumeration; +import java.util.Vector; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public final class InitFilter_Filter implements Filter { + + // Instance Variables + Vector v = new Vector(); + + // The filter configuration object we are associated with. If this value + // is null, this filter instance is not currently configured. + private FilterConfig filterConfig = null; + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + boolean passed = false; + PrintWriter pw = response.getWriter(); + + if (filterConfig == null) { + passed = false; + pw.println( + "doFilter of Filter1 was called but this filter instance is not currently configured"); + } else { + passed = true; + pw.println("doFilter was successfully called in InitFilter_Filter"); + Enumeration filters = v.elements(); + + while (filters.hasMoreElements()) { + pw.println(filters.nextElement()); + } + } + ServletTestUtil.printResult(pw, passed); + + } + + // remove the filter + public void destroy() { + } + + // initialize the filter configuration object for this filter. + + public void init(FilterConfig filterConfig) { + v.add("In initFilterConfig() of initFilter_Filter"); + this.filterConfig = filterConfig; + + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filter/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filter/URLClient.java new file mode 100644 index 0000000000..8dfa5d7020 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filter/URLClient.java @@ -0,0 +1,78 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.filter; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_filter_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(DoFilter_Filter.class, DoFilterTestServlet.class, InitFilter_Filter.class, + InitFilterConfigTestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_js_filter_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + /* + * @testName: doFilterTest + * + * @assertion_ids: Servlet:SPEC:58; Servlet:SPEC:48; Servlet:JAVADOC:293; + * + * @test_Strategy: Client attempts to access a servlet and the filter + * configured for that servlet should be invoked. + */ + @Test + public void doFilterTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "DoFilterTest"); + invoke(); + } + + /* + * @testName: initFilterConfigTest + * + * @assertion_ids: Servlet:SPEC:58; Servlet:SPEC:45; Servlet:JAVADOC:290; + * + * @test_Strategy: Client attempts to access a servlet and the filter + * configured for that servlet. + */ + @Test + public void initFilterConfigTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "InitFilterConfigTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filter/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filter/build.xml new file mode 100644 index 0000000000..064c5c7447 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filter/build.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filter/servlet_js_filter_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filter/servlet_js_filter_web.xml new file mode 100644 index 0000000000..ed38c95317 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filter/servlet_js_filter_web.xml @@ -0,0 +1,65 @@ + + + + + SerJaxSerFilter + + ServletMappedDoFilter_Filter + com.sun.ts.tests.servlet.api.jakarta_servlet.filter.DoFilter_Filter + + attribute + com.sun.ts.tests.servlet.api.jakarta_servlet.filter.DoFilter_Filter.SERVLET_MAPPED + + + + ServletMappedInitFilter_Filter + com.sun.ts.tests.servlet.api.jakarta_servlet.filter.InitFilter_Filter + + attribute + com.sun.ts.tests.servlet.api.jakarta_servlet.filter.InitFilter_Filter.SERVLET_MAPPED + + + + ServletMappedDoFilter_Filter + DoFilterTestLogicalName + + + ServletMappedInitFilter_Filter + InitFilterConfigTestLogicalName + + + DoFilterTestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.filter.DoFilterTestServlet + + + InitFilterConfigTestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.filter.InitFilterConfigTestServlet + + + DoFilterTestLogicalName + /DoFilterTest + + + InitFilterConfigTestLogicalName + /InitFilterConfigTest + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterchain/FilterChainTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterchain/FilterChainTestServlet.java new file mode 100644 index 0000000000..fbe597df2a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterchain/FilterChainTestServlet.java @@ -0,0 +1,82 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.filterchain; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class FilterChainTestServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + + ServletTestUtil.printResult(pw, true); + pw.println("In FilterChainTest Servlet"); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterchain/FilterChain_Filter1.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterchain/FilterChain_Filter1.java new file mode 100644 index 0000000000..29be32d16b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterchain/FilterChain_Filter1.java @@ -0,0 +1,108 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + * * [Additional notices, if required by prior licensing conditions] + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.filterchain; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public final class FilterChain_Filter1 implements Filter { + + // The filter configuration object we are associated with. If this value + // is null, this filter instance is not currently configured. + private FilterConfig filterConfig = null; + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + PrintWriter pw = response.getWriter(); + // this pw.println should not get displayed, only the line going to the + // static log should be valid + pw.println("doFilter was successfully called in FilterChain_Filter1"); + + if (filterConfig == null) { + pw.println( + "doFilter of FilterChain_Filter1 was called but this filter instance is not currently configured "); + ServletTestUtil.printResult(pw, false); + } else { + chain.doFilter(request, response); + } + } + + // remove the filter configuration object for this filter. + public void destroy() { + } + + // initialize the filter configuration object for this filter. + + public void init(FilterConfig filterConfig) { + this.filterConfig = filterConfig; + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterchain/FilterChain_Filter2.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterchain/FilterChain_Filter2.java new file mode 100644 index 0000000000..9ca247b815 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterchain/FilterChain_Filter2.java @@ -0,0 +1,107 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2006, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + * * [Additional notices, if required by prior licensing conditions] + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.filterchain; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public final class FilterChain_Filter2 implements Filter { + + // The filter configuration object we are associated with. If this value + // is null, this filter instance is not currently configured. + private FilterConfig filterConfig = null; + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + PrintWriter pw = response.getWriter(); + + pw.println("doFilter was successfully called in FilterChain_Filter2"); + + if (filterConfig == null) { + pw.println( + "doFilter of FilterChain_Filter2 was called but this filter instance is not currently configured "); + ServletTestUtil.printResult(pw, false); + } else { + chain.doFilter(request, response); + } + } + + // remove the filter configuration object for this filter. + public void destroy() { + } + + // initialize the filter configuration object for this filter. + + public void init(FilterConfig filterConfig) { + this.filterConfig = filterConfig; + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterchain/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterchain/URLClient.java new file mode 100644 index 0000000000..e3fb5a1151 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterchain/URLClient.java @@ -0,0 +1,63 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.filterchain; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_filterchain_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(FilterChain_Filter1.class, FilterChain_Filter2.class, FilterChainTestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_js_filterchain_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + /* + * @testName: filterChainTest + * + * @assertion_ids: Servlet:SPEC:48; Servlet:SPEC:50; Servlet:SPEC:52; + * Servlet:JAVADOC:287; Servlet:JAVADOC:293; + * + * @test_Strategy: Client attempts to access a servlet and both filters + * configured for that servlet should be invoked. + */ + @Test + public void filterChainTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "FilterChainTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterchain/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterchain/build.xml new file mode 100644 index 0000000000..eb695813fd --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterchain/build.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterchain/servlet_js_filterchain_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterchain/servlet_js_filterchain_web.xml new file mode 100644 index 0000000000..c09fbd6048 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterchain/servlet_js_filterchain_web.xml @@ -0,0 +1,57 @@ + + + + + SerJaxSerFilterChain + + ServletMappedFilterChain_Filter1 + com.sun.ts.tests.servlet.api.jakarta_servlet.filterchain.FilterChain_Filter1 + + attribute1 + com.sun.ts.tests.servlet.api.jakarta_servlet.filterchain.FilterChain_Filter1.SERVLET_MAPPED + + + + ServletMappedFilterChain_Filter2 + com.sun.ts.tests.servlet.api.jakarta_servlet.filterchain.FilterChain_Filter2 + + attribute2 + com.sun.ts.tests.servlet.api.jakarta_servlet.filterchain.FilterChain_Filter2.SERVLET_MAPPED + + + + ServletMappedFilterChain_Filter1 + FilterChainTestLogicalName + + + ServletMappedFilterChain_Filter2 + FilterChainTestLogicalName + + + FilterChainTestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.filterchain.FilterChainTestServlet + + + FilterChainTestLogicalName + /FilterChainTest + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/GetFilterNameTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/GetFilterNameTestServlet.java new file mode 100644 index 0000000000..ccabe058d8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/GetFilterNameTestServlet.java @@ -0,0 +1,82 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class GetFilterNameTestServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + pw.println( + "This text should not be displayed from the GetFilterNameTest servlet"); + ServletTestUtil.printResult(pw, false); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/GetFilterName_Filter.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/GetFilterName_Filter.java new file mode 100644 index 0000000000..d15f4aa48b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/GetFilterName_Filter.java @@ -0,0 +1,119 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + * * [Additional notices, if required by prior licensing conditions] + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public final class GetFilterName_Filter implements Filter { + + // The filter configuration object we are associated with. If this value + // is null, this filter instance is not currently configured. + private FilterConfig filterConfig = null; + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + boolean passed = false; + PrintWriter pw = response.getWriter(); + pw.println("doFilter was successfully called in GetFilterName_Filter"); + + if (filterConfig == null) { + passed = false; + pw.println( + "doFilter of GetFilterNameFilter was called but this filter instance is not currently configured "); + } else { + + String expected = "ServletMappedGetFilterName_Filter"; + String result = filterConfig.getFilterName(); + + if (expected.equals(result)) { + passed = true; + } else { + passed = false; + pw.println("getFilterName() returned the wrong result"); + pw.println("Expected Value returned ->" + expected); + pw.println("Actual Value returned ->|" + result + "|"); + } + } + ServletTestUtil.printResult(pw, passed); + } + + // remove the filter configuration object for this filter. + public void destroy() { + } + + // initialize the filter configuration object for this filter. + + public void init(FilterConfig filterConfig) { + this.filterConfig = filterConfig; + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/GetInitParamNamesNullTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/GetInitParamNamesNullTestServlet.java new file mode 100644 index 0000000000..d4b36e1418 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/GetInitParamNamesNullTestServlet.java @@ -0,0 +1,82 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class GetInitParamNamesNullTestServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + pw.println( + "This text should not be displayed from the GetInitParamNamesNullTest servlet"); + ServletTestUtil.printResult(pw, false); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/GetInitParamNamesNull_Filter.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/GetInitParamNamesNull_Filter.java new file mode 100644 index 0000000000..c02ce22e51 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/GetInitParamNamesNull_Filter.java @@ -0,0 +1,125 @@ +/* + * + * * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 1999, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + * * [Additional notices, if required by prior licensing conditions] + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Enumeration; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public final class GetInitParamNamesNull_Filter implements Filter { + + // The filter configuration object we are associated with. If this value + // is null, this filter instance is not currently configured. + private FilterConfig filterConfig = null; + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + boolean passed = false; + PrintWriter pw = response.getWriter(); + pw.println( + "doFilter was successfully called in GetInitParamNamesNull_Filter"); + + if (filterConfig == null) { + passed = false; + pw.println( + "doFilter of GetInitParamNamesNull_Filter was called but this filter instance is not currently configured "); + } else { + + Object o = filterConfig.getInitParameterNames(); + + if (o == null) { + passed = true; + } else if (!((Enumeration) o).hasMoreElements()) { + passed = true; + } else { + passed = false; + pw.println("The following initialization parameters exist:"); + + while (((Enumeration) o).hasMoreElements()) { + String name = (String) ((Enumeration) o).nextElement(); + pw.println(name); + } + } + } + ServletTestUtil.printResult(pw, passed); + + } + + // remove the filter configuration object for this filter. + public void destroy() { + } + + // initialize the filter configuration object for this filter. + public void init(FilterConfig filterConfig) { + this.filterConfig = filterConfig; + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/GetInitParamNamesTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/GetInitParamNamesTestServlet.java new file mode 100644 index 0000000000..3f39b98cc2 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/GetInitParamNamesTestServlet.java @@ -0,0 +1,82 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class GetInitParamNamesTestServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + pw.println( + "This text should not be displayed from the GetInitParamNamesTest servlet"); + ServletTestUtil.printResult(pw, false); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/GetInitParamNames_Filter.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/GetInitParamNames_Filter.java new file mode 100644 index 0000000000..237b35aa49 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/GetInitParamNames_Filter.java @@ -0,0 +1,181 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + * * [Additional notices, if required by prior licensing conditions] + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Enumeration; +import java.util.Vector; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public final class GetInitParamNames_Filter implements Filter { + + // The filter configuration object we are associated with. If this value + // is null, this filter instance is not currently configured. + private FilterConfig filterConfig = null; + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + boolean passed = false; + PrintWriter pw = response.getWriter(); + pw.println("doFilter was successfully called in GetInitParamNames_Filter"); + + if (filterConfig == null) { + passed = false; + pw.println( + "doFilter of GetInitParamNames_Filter was called but this filter instance is not currently configured "); + } else { + + String expectedResult1 = "GetInitParamNames_Filter_attribute1"; + String expectedResult2 = "GetInitParamNames_Filter_attribute2"; + + boolean expectedResult1Found = false; + boolean expectedResult2Found = false; + Enumeration initP = filterConfig.getInitParameterNames(); + int expectedCount = 2; + int count = 0; + + if (initP.hasMoreElements()) { + Vector v = new Vector(); + + while (initP.hasMoreElements()) { + String result = (String) initP.nextElement(); + + if (result.equals(expectedResult1)) { + if (!expectedResult1Found) { + count++; + expectedResult1Found = true; + } else { + passed = false; + pw.println( + "FilterConfig.getInitParameterNames() method return the same parameter name twice "); + pw.println( + "The parameter name already received was " + expectedResult1); + } + } else if (result.equals(expectedResult2)) { + if (!expectedResult2Found) { + count++; + expectedResult2Found = true; + } else { + passed = false; + pw.println( + "FilterConfig.getInitParameterNames() method return the same parameter name twice "); + pw.println( + "The parameter name already received was " + expectedResult2); + } + } else { + v.add(result); + } + } + + if (count != expectedCount) { + passed = false; + pw.println("FilterConfig.getInitParameterNames() method FAILED "); + pw.println("Expected count = " + expectedCount); + pw.println("Actual count = " + count); + pw.println("The expected parameter names received were :"); + + if (expectedResult1Found) { + pw.println(expectedResult1); + } + + if (expectedResult2Found) { + pw.println(expectedResult2); + } + + pw.println(" Other parameter names received were :"); + + for (int i = 0; i <= v.size() - 1; i++) { + pw.println(" " + v.elementAt(i).toString()); + } + } else { + passed = true; + } + } else { + passed = false; + pw.println( + "FilterConfig.getInitParameterNames() returned an empty enumeration"); + } + } + ServletTestUtil.printResult(pw, passed); + + } + + // remove the filter configuration object for this filter. + public void destroy() { + } + + // initialize the filter configuration object for this filter. + + public void init(FilterConfig filterConfig) { + this.filterConfig = filterConfig; + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/GetInitParamNullTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/GetInitParamNullTestServlet.java new file mode 100644 index 0000000000..3ec327e582 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/GetInitParamNullTestServlet.java @@ -0,0 +1,81 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class GetInitParamNullTestServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + pw.println( + "This text should not be displayed from the GetInitParamNullTest servlet"); + ServletTestUtil.printResult(pw, false); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/GetInitParamNull_Filter.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/GetInitParamNull_Filter.java new file mode 100644 index 0000000000..ab20020460 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/GetInitParamNull_Filter.java @@ -0,0 +1,121 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + * * [Additional notices, if required by prior licensing conditions] + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public final class GetInitParamNull_Filter implements Filter { + + // The filter configuration object we are associated with. If this value + // is null, this filter instance is not currently configured. + private FilterConfig filterConfig = null; + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + boolean passed = false; + PrintWriter pw = response.getWriter(); + pw.println("doFilter was successfully called in GetInitParamNull_Filter"); + + if (filterConfig == null) { + passed = false; + pw.println( + "doFilter of GetInitParamNull_Filter was called but this filter instance is not currently configured "); + } else { + + String param = "GetInitParamNull_Filter_attribute1"; + String result = filterConfig.getInitParameter(param); + + if (result == null) { + passed = true; + } else { + passed = false; + pw.println("getInitParameter(" + param + ") returned the wrong result"); + pw.println( + "Expected result = null for the following parameter " + param); + pw.println(" Actual result = " + result); + } + } + ServletTestUtil.printResult(pw, passed); + + } + + // remove the filter configuration object for this filter. + public void destroy() { + } + + // initialize the filter configuration object for this filter. + + public void init(FilterConfig filterConfig) { + this.filterConfig = filterConfig; + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/GetInitParamTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/GetInitParamTestServlet.java new file mode 100644 index 0000000000..cc3db28d68 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/GetInitParamTestServlet.java @@ -0,0 +1,81 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class GetInitParamTestServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + pw.println( + "This text should not be displayed from the GetInitParamTest servlet"); + ServletTestUtil.printResult(pw, false); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/GetInitParam_Filter.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/GetInitParam_Filter.java new file mode 100644 index 0000000000..ff65e8731c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/GetInitParam_Filter.java @@ -0,0 +1,120 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + * * [Additional notices, if required by prior licensing conditions] + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public final class GetInitParam_Filter implements Filter { + + // The filter configuration object we are associated with. If this value + // is null, this filter instance is not currently configured. + private FilterConfig filterConfig = null; + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + boolean passed = false; + PrintWriter pw = response.getWriter(); + pw.println("doFilter was successfully called in GetInitParam_Filter"); + + if (filterConfig == null) { + passed = false; + pw.println( + "doFilter of GetInitParam_Filter was called but this filter instance is not currently configured "); + } else { + + String param = "GetInitParam_Filter_attribute1"; + String expected = "com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetInitParam_Filter.SERVLET_MAPPED1"; + String result = filterConfig.getInitParameter(param); + + if (expected.equals(result)) { + passed = true; + } else { + passed = true; + pw.println("FilterConfig.getInitParameter(" + param + + ") returned the wrong result"); + pw.println("Expected Value returned ->" + expected); + pw.println("Actual Value returned ->|" + result + "|"); + } + } + ServletTestUtil.printResult(pw, passed); + } + + // remove the filter configuration object for this filter. + public void destroy() { + } + + // initialize the filter configuration object for this filter. + + public void init(FilterConfig filterConfig) { + this.filterConfig = filterConfig; + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/GetServletContextTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/GetServletContextTestServlet.java new file mode 100644 index 0000000000..5e5bda53e3 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/GetServletContextTestServlet.java @@ -0,0 +1,81 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class GetServletContextTestServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + pw.println( + "This text should not be displayed from the GetServletContextTest servlet"); + ServletTestUtil.printResult(pw, false); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/GetServletContext_Filter.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/GetServletContext_Filter.java new file mode 100644 index 0000000000..7156b2dedb --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/GetServletContext_Filter.java @@ -0,0 +1,113 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + * * [Additional notices, if required by prior licensing conditions] + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public final class GetServletContext_Filter implements Filter { + + // The filter configuration object we are associated with. If this value + // is null, this filter instance is not currently configured. + private FilterConfig filterConfig = null; + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + boolean passed = false; + PrintWriter pw = response.getWriter(); + pw.println("doFilter was successfully called in GetServletContext_Filter"); + + if (filterConfig == null) { + passed = false; + pw.println( + "doFilter of GetServletContext_Filter was called but this filter instance is not currently configured "); + } else { + + if (filterConfig.getServletContext() != null) { + passed = true; + } else { + passed = true; + pw.println("Method returned a null value for the servlet context "); + } + } + ServletTestUtil.printResult(pw, passed); + } + + // remove the filter configuration object for this filter. + public void destroy() { + } + + // initialize the filter configuration object for this filter. + + public void init(FilterConfig filterConfig) { + this.filterConfig = filterConfig; + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/URLClient.java new file mode 100644 index 0000000000..7ae53e92cc --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/URLClient.java @@ -0,0 +1,141 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_filterconfig_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(GetFilterName_Filter.class, GetFilterNameTestServlet.class, GetInitParam_Filter.class, + GetInitParamNames_Filter.class, GetInitParamNamesNull_Filter.class, + GetInitParamNamesNullTestServlet.class, GetInitParamNamesTestServlet.class, + GetInitParamNull_Filter.class, GetInitParamNullTestServlet.class, GetInitParamTestServlet.class, + GetServletContext_Filter.class, GetServletContextTestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_js_filterconfig_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + /* + * @testName: GetFilterNameTest + * + * @assertion_ids: Servlet:SPEC:45; Servlet:JAVADOC:281; + * + * @test_Strategy: Client attempts to access a servlet and the filter + * configured for that servlet should be invoked. + */ + @Test + public void GetFilterNameTest() throws Exception { + String testName = "GetFilterNameTest"; + TEST_PROPS.setProperty(APITEST, testName); + invoke(); + } + + /* + * @testName: GetInitParamNamesTest + * + * @assertion_ids: Servlet:SPEC:45; Servlet:JAVADOC:285; + * + * @test_Strategy: Client attempts to access a servlet and the filter + * configured for that servlet should be invoked. + */ + @Test + public void GetInitParamNamesTest() throws Exception { + String testName = "GetInitParamNamesTest"; + TEST_PROPS.setProperty(APITEST, testName); + invoke(); + } + + /* + * @testName: GetInitParamNamesNullTest + * + * @assertion_ids: Servlet:SPEC:45; Servlet:JAVADOC:286; + * + * @test_Strategy: Client attempts to access a servlet and the filter + * configured for that servlet should be invoked. + */ + @Test + public void GetInitParamNamesNullTest() throws Exception { + String testName = "GetInitParamNamesNullTest"; + TEST_PROPS.setProperty(APITEST, testName); + invoke(); + } + + /* + * @testName: GetInitParamTest + * + * @assertion_ids: Servlet:SPEC:45; Servlet:JAVADOC:283; + * + * @test_Strategy: Client attempts to access a servlet and the filter + * configured for that servlet should be invoked. + */ + @Test + public void GetInitParamTest() throws Exception { + String testName = "GetInitParamTest"; + TEST_PROPS.setProperty(APITEST, testName); + invoke(); + } + + /* + * @testName: GetInitParamNullTest + * + * @assertion_ids: Servlet:SPEC:45; Servlet:JAVADOC:284; + * + * @test_Strategy: Client attempts to access a servlet and the filter + * configured for that servlet should be invoked. + */ + @Test + public void GetInitParamNullTest() throws Exception { + String testName = "GetInitParamNullTest"; + TEST_PROPS.setProperty(APITEST, testName); + invoke(); + } + + /* + * @testName: GetServletContextTest + * + * @assertion_ids: Servlet:SPEC:45; Servlet:JAVADOC:282; + * + * @test_Strategy: Client attempts to access a servlet and the filter + * configured for that servlet should be invoked. + */ + @Test + public void GetServletContextTest() throws Exception { + String testName = "GetServletContextTest"; + TEST_PROPS.setProperty(APITEST, testName); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/build.xml new file mode 100644 index 0000000000..d0fc6f79a4 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/build.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/servlet_js_filterconfig_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/servlet_js_filterconfig_web.xml new file mode 100644 index 0000000000..70c733be08 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterconfig/servlet_js_filterconfig_web.xml @@ -0,0 +1,145 @@ + + + + + SerJaxSerFilterConfig + + ServletMappedGetFilterName_Filter + com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetFilterName_Filter + + GetFilterName_Filter_attribute + com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetFilterName_Filter.SERVLET_MAPPED + + + + ServletMappedGetInitParam_Filter + com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetInitParam_Filter + + GetInitParam_Filter_attribute1 + com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetInitParam_Filter.SERVLET_MAPPED1 + + + GetInitParam_Filter_attribute2 + com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetInitParam_Filter.SERVLET_MAPPED2 + + + + ServletMappedGetInitParamNames_Filter + com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetInitParamNames_Filter + + GetInitParamNames_Filter_attribute1 + com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetInitParamNames_Filter.SERVLET_MAPPED1 + + + GetInitParamNames_Filter_attribute2 + com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetInitParamNames_Filter.SERVLET_MAPPED2 + + + + ServletMappedGetServletContext_Filter + com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetServletContext_Filter + + GetServletContext_Filter_attribute + com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetServletContext_Filter.SERVLET_MAPPED + + + + ServletMappedGetInitParamNull_Filter + com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetInitParamNull_Filter + + + ServletMappedGetInitParamNamesNull_Filter + com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetInitParamNamesNull_Filter + + + ServletMappedGetFilterName_Filter + GetFilterNameTestLogicalName + + + ServletMappedGetInitParam_Filter + GetInitParamTestLogicalName + + + ServletMappedGetInitParamNames_Filter + GetInitParamNamesTestLogicalName + + + ServletMappedGetServletContext_Filter + GetServletContextTestLogicalName + + + ServletMappedGetInitParamNull_Filter + GetInitParamNullTestLogicalName + + + ServletMappedGetInitParamNamesNull_Filter + GetInitParamNamesNullTestLogicalName + + + GetFilterNameTestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetFilterNameTestServlet + + + GetInitParamNamesTestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetInitParamNamesTestServlet + + + GetInitParamNamesNullTestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetInitParamNamesNullTestServlet + + + GetServletContextTestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetServletContextTestServlet + + + GetInitParamTestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetInitParamTestServlet + + + GetInitParamNullTestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetInitParamNullTestServlet + + + GetFilterNameTestLogicalName + /GetFilterNameTest + + + GetInitParamNamesTestLogicalName + /GetInitParamNamesTest + + + GetInitParamNamesNullTestLogicalName + /GetInitParamNamesNullTest + + + GetServletContextTestLogicalName + /GetServletContextTest + + + GetInitParamTestLogicalName + /GetInitParamTest + + + GetInitParamNullTestLogicalName + /GetInitParamNullTest + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/DummyServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/DummyServlet.java new file mode 100644 index 0000000000..076b0f6a46 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/DummyServlet.java @@ -0,0 +1,41 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.filterrequestdispatcher; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class DummyServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + ServletTestUtil.printResult(pw, "from DummyServlet"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/ErrorPage.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/ErrorPage.java new file mode 100644 index 0000000000..33ae0b99c4 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/ErrorPage.java @@ -0,0 +1,41 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.filterrequestdispatcher; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class ErrorPage extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + ServletTestUtil.printResult(pw, "from ErrorPage"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/ForwardTest1Servlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/ForwardTest1Servlet.java new file mode 100644 index 0000000000..9322c397d9 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/ForwardTest1Servlet.java @@ -0,0 +1,39 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.filterrequestdispatcher; + +import java.io.IOException; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class ForwardTest1Servlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + String path = "/generic/TestServlet"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + rd.forward(request, response); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/ForwardTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/ForwardTestServlet.java new file mode 100644 index 0000000000..d755ce3148 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/ForwardTestServlet.java @@ -0,0 +1,39 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.filterrequestdispatcher; + +import java.io.IOException; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class ForwardTestServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + String path = "/forward/ForwardedServlet"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + rd.forward(request, response); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/ForwardedServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/ForwardedServlet.java new file mode 100644 index 0000000000..b863f4667c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/ForwardedServlet.java @@ -0,0 +1,41 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.filterrequestdispatcher; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class ForwardedServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + ServletTestUtil.printResult(pw, "from ForwardedServlet"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/IncludeTest1Servlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/IncludeTest1Servlet.java new file mode 100644 index 0000000000..0106e0b6ee --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/IncludeTest1Servlet.java @@ -0,0 +1,39 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.filterrequestdispatcher; + +import java.io.IOException; + +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class IncludeTest1Servlet extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + String path = "/generic/TestServlet"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + rd.include(request, response); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/IncludeTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/IncludeTestServlet.java new file mode 100644 index 0000000000..e35f11b307 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/IncludeTestServlet.java @@ -0,0 +1,39 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.filterrequestdispatcher; + +import java.io.IOException; + +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class IncludeTestServlet extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + String path = "/include/IncludedServlet"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + rd.include(request, response); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/IncludedServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/IncludedServlet.java new file mode 100644 index 0000000000..84444a907c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/IncludedServlet.java @@ -0,0 +1,44 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.filterrequestdispatcher; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class IncludedServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + response.setContentType("text/html"); + ServletTestUtil.printResult(pw, "from IncludedServlet"); + pw.flush(); + pw.close(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/RequestTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/RequestTestServlet.java new file mode 100644 index 0000000000..7f4f671485 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/RequestTestServlet.java @@ -0,0 +1,40 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.filterrequestdispatcher; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class RequestTestServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + ServletTestUtil.printResult(pw, "from RequestTestServlet"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/TestServlet.java new file mode 100644 index 0000000000..0c8b9ed450 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/TestServlet.java @@ -0,0 +1,90 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.filterrequestdispatcher; + +import java.io.IOException; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; + +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void forwardServletTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + String path = "/generic/DummyServlet"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + rd.forward(request, response); + } + + public void forwardJSPTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + String path = "/generic/dummyJSP"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + rd.forward(request, response); + } + + public void forwardHTMLTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + String path = "/dummy.html"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + rd.forward(request, response); + } + + public void forwardTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + String path = "/forward/ForwardedServlet"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + rd.forward(request, response); + } + + public void includeServletTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + String path = "/generic/DummyServlet"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + rd.include(request, response); + } + + public void includeJSPTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + String path = "/generic/dummyJSP"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + rd.include(request, response); + } + + public void includeHTMLTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + String path = "/dummy.html"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + rd.include(request, response); + } + + public void includeTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + String path = "/include/IncludedServlet"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + rd.include(request, response); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/Test_Filter.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/Test_Filter.java new file mode 100644 index 0000000000..42fd080b6a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/Test_Filter.java @@ -0,0 +1,65 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.filterrequestdispatcher; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public final class Test_Filter implements Filter { + + // The filter configuration object we are associated with. If this value + // is null, this filter instance is not currently configured. + private FilterConfig filterConfig = null; + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + PrintWriter pw = response.getWriter(); + + if (filterConfig == null) { + ServletTestUtil.printResult(pw, "in Test_Filter"); + } else { + ServletTestUtil.printResult(pw, true); + } + + } + + // Remove the filter configuration object for this filter. + public void destroy() { + } + + // initialize the filter configuration object for this filter. + + public void init(FilterConfig filterConfig) { + this.filterConfig = filterConfig; + + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/URLClient.java new file mode 100644 index 0000000000..79803eaf05 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/URLClient.java @@ -0,0 +1,228 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.filterrequestdispatcher; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.common.util.Data; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + WebArchive webArchive = + ShrinkWrap.create(WebArchive.class, "servlet_js_filterrequestdispatcher_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(DummyServlet.class, ErrorPage.class, ForwardedServlet.class, + ForwardTest1Servlet.class, ForwardTestServlet.class, IncludedServlet.class, + IncludeTest1Servlet.class, IncludeTestServlet.class, RequestTestServlet.class, + Test_Filter.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_js_filterrequestdispatcher_web.xml")); + Arrays.asList("dummy.html","dummyJSP.jsp") + .forEach(s -> webArchive.addAsWebResource("api/jakarta_servlet/filterrequestdispatcher/"+ s, s)); + return webArchive; + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + + /* + * @testName: RequestTest + * + * @assertion_ids: Servlet:SPEC:54; Servlet:SPEC:59; + * + * @test_Strategy: 1. Create a servlet, a JSP page and a web page - + * /generic/DummyServlet, /generic/dummyJSP, and /dummy.html. 2. Map a filter + * Test_Filter on all above three with dispatcher value set to REQUEST using + * url-pattern, as well as ERROR, FORWARD and INCLUDE. 3. Client try to access + * all of them directly. 4. Verify that filter is properly invoked. + */ + @Test + public void RequestTest() throws Exception { + TEST_PROPS.setProperty(DONOTUSEServletName, "true"); + TEST_PROPS.setProperty(APITEST, "generic/DummyServlet"); + invoke(); + + TEST_PROPS.setProperty(DONOTUSEServletName, "true"); + TEST_PROPS.setProperty(APITEST, "generic/dummyJSP"); + invoke(); + + TEST_PROPS.setProperty(APITEST, "dummy.html"); + TEST_PROPS.setProperty(DONOTUSEServletName, "true"); + invoke(); + } + + /* + * @testName: RequestTest1 + * + * @assertion_ids: Servlet:SPEC:54; + * + * @test_Strategy: 1. Create a servlet - RequestTestServlet. 2. Map a filter + * Test_Filter on RequestTestServlet with dispatcher value set to REQUEST + * using servlet-name 3. Client try to access RequestTestServlet directly. 4. + * Verify that filter is properly invoked. + */ + @Test + public void RequestTest1() throws Exception { + TEST_PROPS.setProperty(DONOTUSEServletName, "true"); + TEST_PROPS.setProperty(APITEST, "request/RequestTest"); + invoke(); + } + + /* + * @testName: RequestTest2 + * + * @assertion_ids: Servlet:SPEC:54; + * + * @test_Strategy: 1. Create a servlet - forward/ForwardedServlet. 2. Map a + * filter Test_Filter on forward/ForwardedServlet with dispatcher value not + * set to REQUEST but to FORWARD only. 3. Client try to access + * forward/ForwardedServlet directly. 4. Verify that filter is not invoked. + */ + @Test + public void RequestTest2() throws Exception { + TEST_PROPS.setProperty(DONOTUSEServletName, "true"); + TEST_PROPS.setProperty(SEARCH_STRING, Data.FAILED); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, Data.PASSED); + + TEST_PROPS.setProperty(APITEST, "forward/ForwardedServlet"); + invoke(); + } + + /* + * @testName: ForwardTest + * + * @assertion_ids: Servlet:SPEC:55; Servlet:JAVADOC:273; + * + * @test_Strategy: 1. Create two servlets - TestServlet, ForwardedServlet. 2. + * Map a filter Test_Filter using for ForwardedServlet with + * dispacther value FORWARD. 3. Client try to use the RequestDispatcher to + * forward to ForwardedServlet through TestServlet. 4. Verify that filter is + * properly invoked. + */ + @Test + public void ForwardTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "forwardTest"); + invoke(); + } + + /* + * @testName: ForwardTest1 + * + * @assertion_ids: Servlet:SPEC:55; Servlet:SPEC:59; Servlet:JAVADOC:273; + * + * @test_Strategy: 1. Create two servlets - ForwardTest1Servlet, + * /generic/TestServlet 2. Map a filter Test_Filter using for + * TestServlet with dispacther value FORWARD, as well as ERROR, INCLUDE and + * REQUEST. 3. Client try to access ForwardTest1Servlet which in turn use the + * RequestDispatcher to forward to TestServlet. 4. Verify that filter is + * properly invoked. + */ + @Test + public void ForwardTest1() throws Exception { + TEST_PROPS.setProperty(APITEST, "forwardServletTest"); + invoke(); + + TEST_PROPS.setProperty(APITEST, "forwardJSPTest"); + invoke(); + + TEST_PROPS.setProperty(APITEST, "forwardHTMLTest"); + invoke(); + } + + /* + * @testName: IncludeTest + * + * @assertion_ids: Servlet:SPEC:56; Servlet:SPEC:59; + * + * @test_Strategy: 1. Create two servlets - TestServlet, IncludedServlet. 2. + * Map a filter Test_Filter on IncludedServlet with dispacther value set to + * INCLUDE only. 3. Client try to use the RequestDispatcher's include to + * access IncludedServlet through TestServlet. 4. Verify that filter is + * properly invoked. + */ + @Test + public void IncludeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "includeTest"); + invoke(); + } + + /* + * @testName: IncludeTest1 + * + * @assertion_ids: Servlet:SPEC:56; Servlet:SPEC:59; + * + * @test_Strategy: 1. Create two servlet - TestServlet, /generic/DummyServlet, + * a JSP dummyJSP and a HTML file dummy.html. 2. Map a filter Test_Filter on + * /generic/DummyServlet, dummyJSP and dummy.html with dispacther value set to + * INCLUDE as well as ERROR, FORWARD and REQUEST using url-pattern. 3. Client + * try to use the RequestDispatcher's include to access all three through + * TestServlet. 4. Verify that filter is properly invoked. + */ + @Test + public void IncludeTest1() throws Exception { + TEST_PROPS.setProperty(APITEST, "includeJSPTest"); + invoke(); + + TEST_PROPS.setProperty(APITEST, "includeServletTest"); + invoke(); + + TEST_PROPS.setProperty(APITEST, "includeHTMLTest"); + invoke(); + } + + /* + * @testName: ErrorTest + * + * @assertion_ids: Servlet:SPEC:57; Servlet:SPEC:59; + * + * @test_Strategy: 1. Create an Error Page /generic/ErrorPage handling + * error-code 404. 2. Map a filter Test_Filter on /generic/ErrorPage with + * dispacther value set to ERROR as well as FORWARD INCLUDE and REQUEST. 3. + * Client try to access a non-existent Servlet 4. Verify that filter is + * properly invoked. + */ + @Test + public void ErrorTest() throws Exception { + TEST_PROPS.setProperty(DONOTUSEServletName, "true"); + TEST_PROPS.setProperty(APITEST, "forward/IncludedServlet"); + TEST_PROPS.setProperty(STATUS_CODE, "404"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/build.xml new file mode 100644 index 0000000000..26f20928cc --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/build.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/servlet_js_filterrequestdispatcher_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/servlet_js_filterrequestdispatcher_web.xml new file mode 100644 index 0000000000..b9cc76987a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/filterrequestdispatcher/servlet_js_filterrequestdispatcher_web.xml @@ -0,0 +1,128 @@ + + + + + SerJaxSerRequestDispatcher + + ServletMappedTest_Filter + com.sun.ts.tests.servlet.api.jakarta_servlet.filterrequestdispatcher.Test_Filter + + attribute + com.sun.ts.tests.servlet.api.jakarta_servlet.filterrequestdispatcher.Test_Filter.SERVLET_MAPPED + + + + ServletMappedTest_Filter + IncludedServlet + INCLUDE + + + ServletMappedTest_Filter + ForwardedServlet + FORWARD + + + ServletMappedTest_Filter + /generic/* + REQUEST + INCLUDE + FORWARD + ERROR + + + ServletMappedTest_Filter + /dummy.html + REQUEST + INCLUDE + FORWARD + ERROR + + + ServletMappedTest_Filter + RequestServlet + REQUEST + + + DummyJSP + /dummyJSP.jsp + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.filterrequestdispatcher.TestServlet + + + DummyServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.filterrequestdispatcher.DummyServlet + + + RequestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.filterrequestdispatcher.RequestTestServlet + + + IncludedServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.filterrequestdispatcher.IncludedServlet + + + ForwardedServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.filterrequestdispatcher.ForwardedServlet + + + ErrorPage + com.sun.ts.tests.servlet.api.jakarta_servlet.filterrequestdispatcher.ErrorPage + + + ErrorPage + /generic/ErrorPage + + + DummyServlet + /generic/DummyServlet + + + DummyJSP + /generic/dummyJSP + + + TestServlet + /TestServlet + + + TestServlet + /generic/TestServlet + + + RequestServlet + /request/RequestTest + + + IncludedServlet + /include/IncludedServlet + + + ForwardedServlet + /forward/ForwardedServlet + + + 54 + + + 404 + /generic/ErrorPage + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/GetFilterNameTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/GetFilterNameTestServlet.java new file mode 100644 index 0000000000..dc03bcd30e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/GetFilterNameTestServlet.java @@ -0,0 +1,82 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.genericfilter; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class GetFilterNameTestServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + pw.println( + "This text should not be displayed from the GenericFilter.GetFilterNameTest servlet"); + ServletTestUtil.printResult(pw, false); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/GetFilterName_Filter.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/GetFilterName_Filter.java new file mode 100644 index 0000000000..33e807f62a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/GetFilterName_Filter.java @@ -0,0 +1,108 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + * * [Additional notices, if required by prior licensing conditions] + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.genericfilter; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.FilterChain; +import jakarta.servlet.GenericFilter; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public final class GetFilterName_Filter extends GenericFilter { + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + boolean passed = false; + PrintWriter pw = response.getWriter(); + pw.println("doFilter was successfully called in GetFilterName_Filter"); + + if (getFilterConfig() == null) { + passed = false; + pw.println( + "doFilter of GetFilterNameFilter was called but this filter instance is not currently configured "); + } else { + + String expected = "ServletMappedGetFilterName_Filter"; + String result = getFilterName(); + + if (expected.equals(result)) { + passed = true; + } else { + passed = false; + pw.println("GenericFilter.getFilterName() returned the wrong result"); + pw.println("Expected Value returned ->" + expected); + pw.println("Actual Value returned ->|" + result + "|"); + } + } + ServletTestUtil.printResult(pw, passed); + } + + // remove the filter configuration object for this filter. + public void destroy() { + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/GetInitParamNamesNullTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/GetInitParamNamesNullTestServlet.java new file mode 100644 index 0000000000..153b96fc7d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/GetInitParamNamesNullTestServlet.java @@ -0,0 +1,82 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.genericfilter; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class GetInitParamNamesNullTestServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + pw.println( + "This text should not be displayed from the GenericFilter.GetInitParamNamesNullTest servlet"); + ServletTestUtil.printResult(pw, false); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/GetInitParamNamesNull_Filter.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/GetInitParamNamesNull_Filter.java new file mode 100644 index 0000000000..c4b22ff440 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/GetInitParamNamesNull_Filter.java @@ -0,0 +1,116 @@ +/* + * + * * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + * * [Additional notices, if required by prior licensing conditions] + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.genericfilter; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Enumeration; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.FilterChain; +import jakarta.servlet.GenericFilter; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public final class GetInitParamNamesNull_Filter extends GenericFilter { + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + boolean passed = false; + PrintWriter pw = response.getWriter(); + pw.println( + "doFilter was successfully called in GetInitParamNamesNull_Filter"); + + if (getFilterConfig() == null) { + passed = false; + pw.println( + "doFilter of GetInitParamNamesNull_Filter was called but this filter instance is not currently configured "); + } else { + + Object o = getInitParameterNames(); + + if (o == null) { + passed = true; + } else if (!((Enumeration) o).hasMoreElements()) { + passed = true; + } else { + passed = false; + pw.println("The following initialization parameters exist:"); + + while (((Enumeration) o).hasMoreElements()) { + String name = (String) ((Enumeration) o).nextElement(); + pw.println(name); + } + } + } + ServletTestUtil.printResult(pw, passed); + + } + + // remove the filter configuration object for this filter. + public void destroy() { + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/GetInitParamNamesTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/GetInitParamNamesTestServlet.java new file mode 100644 index 0000000000..6780f397b2 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/GetInitParamNamesTestServlet.java @@ -0,0 +1,82 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.genericfilter; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class GetInitParamNamesTestServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + pw.println( + "This text should not be displayed from the GenericFilter.GetInitParamNamesTest servlet"); + ServletTestUtil.printResult(pw, false); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/GetInitParamNames_Filter.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/GetInitParamNames_Filter.java new file mode 100644 index 0000000000..017c6346c2 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/GetInitParamNames_Filter.java @@ -0,0 +1,170 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + * * [Additional notices, if required by prior licensing conditions] + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.genericfilter; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Enumeration; +import java.util.Vector; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.FilterChain; +import jakarta.servlet.GenericFilter; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public final class GetInitParamNames_Filter extends GenericFilter { + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + boolean passed = false; + PrintWriter pw = response.getWriter(); + pw.println("doFilter was successfully called in GetInitParamNames_Filter"); + + if (getFilterConfig() == null) { + passed = false; + pw.println( + "doFilter of GetInitParamNames_Filter was called but this filter instance is not currently configured "); + } else { + + String expectedResult1 = "GetInitParamNames_Filter_attribute1"; + String expectedResult2 = "GetInitParamNames_Filter_attribute2"; + + boolean expectedResult1Found = false; + boolean expectedResult2Found = false; + Enumeration initP = getInitParameterNames(); + int expectedCount = 2; + int count = 0; + + if (initP.hasMoreElements()) { + Vector v = new Vector(); + + while (initP.hasMoreElements()) { + String result = (String) initP.nextElement(); + + if (result.equals(expectedResult1)) { + if (!expectedResult1Found) { + count++; + expectedResult1Found = true; + } else { + passed = false; + pw.println( + "GenericFilter.getInitParameterNames() method return the same parameter name twice "); + pw.println( + "The parameter name already received was " + expectedResult1); + } + } else if (result.equals(expectedResult2)) { + if (!expectedResult2Found) { + count++; + expectedResult2Found = true; + } else { + passed = false; + pw.println( + "GenericFilter.getInitParameterNames() method return the same parameter name twice "); + pw.println( + "The parameter name already received was " + expectedResult2); + } + } else { + v.add(result); + } + } + + if (count != expectedCount) { + passed = false; + pw.println("GenericFilter.getInitParameterNames() method FAILED "); + pw.println("Expected count = " + expectedCount); + pw.println("Actual count = " + count); + pw.println("The expected parameter names received were :"); + + if (expectedResult1Found) { + pw.println(expectedResult1); + } + + if (expectedResult2Found) { + pw.println(expectedResult2); + } + + pw.println(" Other parameter names received were :"); + + for (int i = 0; i <= v.size() - 1; i++) { + pw.println(" " + v.elementAt(i).toString()); + } + } else { + passed = true; + } + } else { + passed = false; + pw.println( + "GenericFilter.getInitParameterNames() returned an empty enumeration"); + } + } + ServletTestUtil.printResult(pw, passed); + + } + + // remove the filter configuration object for this filter. + public void destroy() { + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/GetInitParamNullTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/GetInitParamNullTestServlet.java new file mode 100644 index 0000000000..a8d235e7b8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/GetInitParamNullTestServlet.java @@ -0,0 +1,81 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.genericfilter; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class GetInitParamNullTestServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + pw.println( + "This text should not be displayed from the GenericFilter.GetInitParamNullTest servlet"); + ServletTestUtil.printResult(pw, false); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/GetInitParamNull_Filter.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/GetInitParamNull_Filter.java new file mode 100644 index 0000000000..0516e16014 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/GetInitParamNull_Filter.java @@ -0,0 +1,110 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + * * [Additional notices, if required by prior licensing conditions] + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.genericfilter; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.FilterChain; +import jakarta.servlet.GenericFilter; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public final class GetInitParamNull_Filter extends GenericFilter { + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + boolean passed = false; + PrintWriter pw = response.getWriter(); + pw.println("doFilter was successfully called in GetInitParamNull_Filter"); + + if (getFilterConfig() == null) { + passed = false; + pw.println( + "doFilter of GetInitParamNull_Filter was called but this filter instance is not currently configured "); + } else { + + String param = "GetInitParamNull_Filter_attribute1"; + String result = getInitParameter(param); + + if (result == null) { + passed = true; + } else { + passed = false; + pw.println("getInitParameter(" + param + ") returned the wrong result"); + pw.println( + "Expected result = null for the following parameter " + param); + pw.println(" Actual result = " + result); + } + } + ServletTestUtil.printResult(pw, passed); + + } + + // remove the filter configuration object for this filter. + public void destroy() { + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/GetInitParamTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/GetInitParamTestServlet.java new file mode 100644 index 0000000000..bac185d099 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/GetInitParamTestServlet.java @@ -0,0 +1,81 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.genericfilter; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class GetInitParamTestServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + pw.println( + "This text should not be displayed from the GenericFilter.GetInitParamTest servlet"); + ServletTestUtil.printResult(pw, false); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/GetInitParam_Filter.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/GetInitParam_Filter.java new file mode 100644 index 0000000000..60200d89dc --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/GetInitParam_Filter.java @@ -0,0 +1,110 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + * * [Additional notices, if required by prior licensing conditions] + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.genericfilter; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.FilterChain; +import jakarta.servlet.GenericFilter; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public final class GetInitParam_Filter extends GenericFilter { + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + boolean passed = false; + PrintWriter pw = response.getWriter(); + pw.println("doFilter was successfully called in GetInitParam_Filter"); + + if (getFilterConfig() == null) { + passed = false; + pw.println( + "doFilter of GetInitParam_Filter was called but this filter instance is not currently configured "); + } else { + + String param = "GetInitParam_Filter_attribute"; + String expected = "com.sun.ts.tests.servlet.api.jakarta_servlet.genericfilter.GetInitParam_Filter.SERVLET_MAPPED"; + String result = getInitParameter(param); + + if (expected.equals(result)) { + passed = true; + } else { + passed = false; + pw.println("GenericFilter.getInitParameter(" + param + + ") returned the wrong result"); + pw.println("Expected Value returned ->" + expected); + pw.println("Actual Value returned ->|" + result + "|"); + } + } + ServletTestUtil.printResult(pw, passed); + } + + // remove the filter configuration object for this filter. + public void destroy() { + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/GetServletContextTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/GetServletContextTestServlet.java new file mode 100644 index 0000000000..bc50151b4e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/GetServletContextTestServlet.java @@ -0,0 +1,81 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.genericfilter; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class GetServletContextTestServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + pw.println( + "This text should not be displayed from the GenericFilter.GetServletContextTest servlet"); + ServletTestUtil.printResult(pw, false); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/GetServletContext_Filter.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/GetServletContext_Filter.java new file mode 100644 index 0000000000..55e6f3c9a5 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/GetServletContext_Filter.java @@ -0,0 +1,103 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + * * [Additional notices, if required by prior licensing conditions] + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.genericfilter; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.FilterChain; +import jakarta.servlet.GenericFilter; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public final class GetServletContext_Filter extends GenericFilter { + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + boolean passed = false; + PrintWriter pw = response.getWriter(); + pw.println("doFilter was successfully called in GetServletContext_Filter"); + + if (getFilterConfig() == null) { + passed = false; + pw.println( + "doFilter of GetServletContext_Filter was called but this filter instance is not currently configured "); + } else { + + if (getServletContext() != null) { + passed = true; + } else { + passed = false; + pw.println("Method returned a null value for the servlet context "); + } + } + ServletTestUtil.printResult(pw, passed); + } + + // remove the filter configuration object for this filter. + public void destroy() { + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/InitFilterConfigTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/InitFilterConfigTestServlet.java new file mode 100644 index 0000000000..efd04d2733 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/InitFilterConfigTestServlet.java @@ -0,0 +1,82 @@ +/* + * + * * + * * * + * * * The Apache Software License, Version 1.1 + * * * + * * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * * reserved. + * * * + * * * Redistribution and use in source and binary forms, with or without + * * * modification, are permitted provided that the following conditions + * * * are met: + * * * + * * * 1. Redistributions of source code must retain the above copyright + * * * notice, this list of conditions and the following disclaimer. + * * * + * * * 2. Redistributions in binary form must reproduce the above copyright + * * * notice, this list of conditions and the following disclaimer in + * * * the documentation and/or other materials provided with the + * * * distribution. + * * * + * * * 3. The end-user documentation included with the redistribution, if + * * * any, must include the following acknowlegement: + * * * "This product includes software developed by the + * * * Apache Software Foundation (http://www.apache.org/)." + * * * Alternately, this acknowlegement may appear in the software itself, + * * * if and wherever such third-party acknowlegements normally appear. + * * * + * * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * * Foundation" must not be used to endorse or promote products derived + * * * from this software without prior written permission. For written + * * * permission, please contact apache@apache.org. + * * * + * * * 5. Products derived from this software may not be called "Apache" + * * * nor may "Apache" appear in their names without prior written + * * * permission of the Apache Group. + * * * + * * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * * SUCH DAMAGE. + * * * ==================================================================== + * * * + * * * This software consists of voluntary contributions made by many + * * * individuals on behalf of the Apache Software Foundation. For more + * * * information on the Apache Software Foundation, please see + * * * . + * * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.genericfilter; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class InitFilterConfigTestServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + pw.println( + "This text should not be displayed from the GenericFilter.InitFilterConfigTest servlet"); + ServletTestUtil.printResult(pw, false); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/InitFilterConfig_Filter.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/InitFilterConfig_Filter.java new file mode 100644 index 0000000000..c75a38aafc --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/InitFilterConfig_Filter.java @@ -0,0 +1,116 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2006, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + * * [Additional notices, if required by prior licensing conditions] + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.genericfilter; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Enumeration; +import java.util.Vector; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.GenericFilter; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public final class InitFilterConfig_Filter extends GenericFilter { + + // Instance Variables + Vector v = new Vector(); + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + boolean passed = false; + PrintWriter pw = response.getWriter(); + + if (getFilterConfig() == null) { + passed = false; + pw.println( + "doFilter of Filter1 was called but this filter instance is not currently configured"); + } else { + passed = true; + pw.println("doFilter was successfully called in InitFilterConfig_Filter"); + Enumeration filters = v.elements(); + + while (filters.hasMoreElements()) { + pw.println(filters.nextElement()); + } + } + ServletTestUtil.printResult(pw, passed); + + } + + // remove the filter + public void destroy() { + } + + // initialize the filter configuration object for this filter. + + public void init(FilterConfig filterConfig) throws ServletException { + super.init(filterConfig); + v.add("In initFilterConfig() of initFilter_Filter"); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/InitFilterTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/InitFilterTestServlet.java new file mode 100644 index 0000000000..d267d892ef --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/InitFilterTestServlet.java @@ -0,0 +1,81 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.genericfilter; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class InitFilterTestServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + pw.println( + "This text should not be displayed from the GenericFilter.InitFilterTest servlet"); + ServletTestUtil.printResult(pw, false); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/InitFilter_Filter.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/InitFilter_Filter.java new file mode 100644 index 0000000000..a5264c7f8f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/InitFilter_Filter.java @@ -0,0 +1,97 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + * * [Additional notices, if required by prior licensing conditions] + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.genericfilter; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.FilterChain; +import jakarta.servlet.GenericFilter; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public final class InitFilter_Filter extends GenericFilter { + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + boolean passed = false; + PrintWriter pw = response.getWriter(); + + if (getFilterConfig() == null) { + passed = false; + pw.println( + "doFilter of Filter1 was called but this filter instance is not currently configured"); + } else { + passed = true; + pw.println("doFilter was successfully called in InitFilter_Filter"); + } + ServletTestUtil.printResult(pw, passed); + + } + + // remove the filter + public void destroy() { + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/URLClient.java new file mode 100644 index 0000000000..1ee5fe5ae6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/URLClient.java @@ -0,0 +1,171 @@ +/* + * Copyright (c) 2017, 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: URLClient.java 62833 2011-05-18 13:13:23Z djiao $ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.genericfilter; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_genericfilter_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(GetFilterName_Filter.class, GetFilterNameTestServlet.class, GetInitParam_Filter.class, GetInitParamNull_Filter.class, + GetInitParamNames_Filter.class, GetInitParamNamesNull_Filter.class, GetInitParamNamesNullTestServlet.class, + GetInitParamNamesTestServlet.class, GetInitParamNamesNull_Filter.class, GetInitParamNullTestServlet.class, + GetInitParamTestServlet.class, GetServletContext_Filter.class, GetServletContextTestServlet.class, + InitFilter_Filter.class, InitFilterConfig_Filter.class, InitFilterConfigTestServlet.class, + InitFilterTestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_js_genericfilter_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + /* + * @testName: initFilterTest + * + * @assertion_ids: NA; + * + * @test_Strategy: Client attempts to access a servlet and the filter + * configured for that servlet should be invoked. + */ + @Test + public void initFilterTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "InitFilterTest"); + invoke(); + } + + /* + * @testName: initFilterConfigTest + * + * @assertion_ids: NA; + * + * @test_Strategy: Client attempts to access a servlet and the filter + * configured for that servlet should be invoked. + */ + @Test + public void initFilterConfigTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "InitFilterConfigTest"); + invoke(); + } + + /* + * @testName: GetFilterNameTest + * + * @assertion_ids: NA; + * + * @test_Strategy: Client attempts to access a servlet and the filter + * configured for that servlet should be invoked. + */ + @Test + public void GetFilterNameTest() throws Exception { + String testName = "GetFilterNameTest"; + TEST_PROPS.setProperty(APITEST, testName); + invoke(); + } + + /* + * @testName: GetInitParamTest + * + * @assertion_ids: NA; + * + * @test_Strategy: Client attempts to access a servlet and the filter + * configured for that servlet should be invoked. + */ + @Test + public void GetInitParamTest() throws Exception { + String testName = "GetInitParamTest"; + TEST_PROPS.setProperty(APITEST, testName); + invoke(); + } + + /* + * @testName: GetInitParamNamesTest + * + * @assertion_ids: NA; + * + * @test_Strategy: Client attempts to access a servlet and the filter + * configured for that servlet should be invoked. + */ + @Test + public void GetInitParamNamesTest() throws Exception { + String testName = "GetInitParamNamesTest"; + TEST_PROPS.setProperty(APITEST, testName); + invoke(); + } + + /* + * @testName: GetInitParamNamesNullTest + * + * @assertion_ids: NA; + * + * @test_Strategy: Client attempts to access a servlet and the filter + * configured for that servlet should be invoked. + */ + @Test + public void GetInitParamNamesNullTest() throws Exception { + String testName = "GetInitParamNamesNullTest"; + TEST_PROPS.setProperty(APITEST, testName); + invoke(); + } + + /* + * @testName: GetInitParamNullTest + * + * @assertion_ids: NA; + * + * @test_Strategy: Client attempts to access a servlet and the filter + * configured for that servlet should be invoked. + */ + @Test + public void GetInitParamNullTest() throws Exception { + String testName = "GetInitParamNullTest"; + TEST_PROPS.setProperty(APITEST, testName); + invoke(); + } + + /* + * @testName: GetServletContextTest + * + * @assertion_ids: NA; + * + * @test_Strategy: Client attempts to access a servlet and the filter + * configured for that servlet should be invoked. + */ + @Test + public void GetServletContextTest() throws Exception { + String testName = "GetServletContextTest"; + TEST_PROPS.setProperty(APITEST, testName); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/build.xml new file mode 100644 index 0000000000..dab8aa2d51 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/build.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/servlet_js_genericfilter_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/servlet_js_genericfilter_web.xml new file mode 100644 index 0000000000..4e8f0988dc --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericfilter/servlet_js_genericfilter_web.xml @@ -0,0 +1,169 @@ + + + + + SerJaxSerGenericFilter + + ServletMappedInitFilter_Filter + com.sun.ts.tests.servlet.api.jakarta_servlet.genericfilter.InitFilter_Filter + + + ServletMappedInitFilterConfig_Filter + com.sun.ts.tests.servlet.api.jakarta_servlet.genericfilter.InitFilterConfig_Filter + + + ServletMappedGetFilterName_Filter + com.sun.ts.tests.servlet.api.jakarta_servlet.genericfilter.GetFilterName_Filter + + + ServletMappedGetInitParam_Filter + com.sun.ts.tests.servlet.api.jakarta_servlet.genericfilter.GetInitParam_Filter + + GetInitParam_Filter_attribute + com.sun.ts.tests.servlet.api.jakarta_servlet.genericfilter.GetInitParam_Filter.SERVLET_MAPPED + + + + ServletMappedGetInitParamNames_Filter + com.sun.ts.tests.servlet.api.jakarta_servlet.genericfilter.GetInitParamNames_Filter + + GetInitParamNames_Filter_attribute1 + com.sun.ts.tests.servlet.api.jakarta_servlet.genericfilter.GetInitParamNames_Filter.SERVLET_MAPPED1 + + + GetInitParamNames_Filter_attribute2 + com.sun.ts.tests.servlet.api.jakarta_servlet.genericfilter.GetInitParamNames_Filter.SERVLET_MAPPED2 + + + + ServletMappedGetServletContext_Filter + com.sun.ts.tests.servlet.api.jakarta_servlet.genericfilter.GetServletContext_Filter + + GetServletContext_Filter_attribute + com.sun.ts.tests.servlet.api.jakarta_servlet.genericfilter.GetServletContext_Filter.SERVLET_MAPPED + + + + ServletMappedGetInitParamNull_Filter + com.sun.ts.tests.servlet.api.jakarta_servlet.genericfilter.GetInitParamNull_Filter + + + ServletMappedGetInitParamNamesNull_Filter + com.sun.ts.tests.servlet.api.jakarta_servlet.genericfilter.GetInitParamNamesNull_Filter + + + ServletMappedInitFilter_Filter + InitFilterTestLogicalName + + + ServletMappedInitFilterConfig_Filter + InitFilterConfigTestLogicalName + + + ServletMappedGetFilterName_Filter + GetFilterNameTestLogicalName + + + ServletMappedGetInitParam_Filter + GetInitParamTestLogicalName + + + ServletMappedGetInitParamNames_Filter + GetInitParamNamesTestLogicalName + + + ServletMappedGetServletContext_Filter + GetServletContextTestLogicalName + + + ServletMappedGetInitParamNull_Filter + GetInitParamNullTestLogicalName + + + ServletMappedGetInitParamNamesNull_Filter + GetInitParamNamesNullTestLogicalName + + + InitFilterTestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.genericfilter.InitFilterTestServlet + + + InitFilterConfigTestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.genericfilter.InitFilterConfigTestServlet + + + GetFilterNameTestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.genericfilter.GetFilterNameTestServlet + + + GetInitParamNamesTestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.genericfilter.GetInitParamNamesTestServlet + + + GetInitParamNamesNullTestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.genericfilter.GetInitParamNamesNullTestServlet + + + GetServletContextTestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.genericfilter.GetServletContextTestServlet + + + GetInitParamTestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.genericfilter.GetInitParamTestServlet + + + GetInitParamNullTestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.genericfilter.GetInitParamNullTestServlet + + + InitFilterTestLogicalName + /InitFilterTest + + + InitFilterConfigTestLogicalName + /InitFilterConfigTest + + + GetFilterNameTestLogicalName + /GetFilterNameTest + + + GetInitParamNamesTestLogicalName + /GetInitParamNamesTest + + + GetInitParamNamesNullTestLogicalName + /GetInitParamNamesNullTest + + + GetServletContextTestLogicalName + /GetServletContextTest + + + GetInitParamTestLogicalName + /GetInitParamTest + + + GetInitParamNullTestLogicalName + /GetInitParamNullTest + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericservlet/DestroyTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericservlet/DestroyTestServlet.java new file mode 100644 index 0000000000..7e3c1f6757 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericservlet/DestroyTestServlet.java @@ -0,0 +1,77 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.genericservlet; + +import java.io.IOException; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class DestroyTestServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + // Generally we shouldn't call destroy method explicitly. + destroy(); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericservlet/InitServletExceptionTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericservlet/InitServletExceptionTestServlet.java new file mode 100644 index 0000000000..d744c12884 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericservlet/InitServletExceptionTestServlet.java @@ -0,0 +1,84 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.genericservlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class InitServletExceptionTestServlet extends GenericServlet { + + public void init() throws ServletException { + throw new ServletException("in init of InitServletExceptionTestServlet"); + } + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + ServletTestUtil.printResult(pw, false); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericservlet/InitTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericservlet/InitTestServlet.java new file mode 100644 index 0000000000..5a46ec99fd --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericservlet/InitTestServlet.java @@ -0,0 +1,103 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 1999, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.genericservlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class InitTestServlet extends GenericServlet { + + private final static String EXPECTED = "in init"; + + public void init() throws ServletException { + getServletConfig().getServletContext().setAttribute("status", EXPECTED); + } + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + + String actual = (String) getServletContext().getAttribute("status"); + if (actual != null) { + if (!actual.equals(EXPECTED)) { + passed = false; + pw.println("ERROR: status message was not found"); + pw.println("expected result=" + EXPECTED); + pw.println("actual result=" + actual); + } else { + passed = false; + } + } else { + passed = false; + pw.println("ERROR: status attribute was not found"); + } + + ServletTestUtil.printResult(pw, passed); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericservlet/Init_ServletConfigServletExceptionTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericservlet/Init_ServletConfigServletExceptionTestServlet.java new file mode 100644 index 0000000000..1a834a2f9b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericservlet/Init_ServletConfigServletExceptionTestServlet.java @@ -0,0 +1,88 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.genericservlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class Init_ServletConfigServletExceptionTestServlet + extends GenericServlet { + + public void init(ServletConfig sc) throws ServletException { + super.init(sc); + throw new ServletException( + "in init of Init_ServletConfigServletExceptionTestServlet"); + } + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + ServletTestUtil.printResult(pw, false); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericservlet/Init_ServletConfigTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericservlet/Init_ServletConfigTestServlet.java new file mode 100644 index 0000000000..bc053ae1b6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericservlet/Init_ServletConfigTestServlet.java @@ -0,0 +1,105 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 1999, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.genericservlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class Init_ServletConfigTestServlet extends GenericServlet { + + private static final String EXPECTED = "in init"; + + public void init(ServletConfig sc) throws ServletException { + super.init(sc); + sc.getServletContext().setAttribute("status", EXPECTED); + } + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + + String actual = (String) getServletContext().getAttribute("status"); + if (actual != null) { + if (!actual.equals(EXPECTED)) { + passed = false; + pw.println("ERROR: status message was not found"); + pw.println("expected result=" + EXPECTED); + pw.println("actual result=" + actual); + } else { + passed = false; + } + } else { + passed = false; + pw.println("ERROR: status attribute was not found"); + } + + ServletTestUtil.printResult(pw, passed); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericservlet/ServiceTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericservlet/ServiceTestServlet.java new file mode 100644 index 0000000000..bda298587e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericservlet/ServiceTestServlet.java @@ -0,0 +1,80 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.genericservlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class ServiceTestServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + ServletTestUtil.printResult(pw, true); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericservlet/ServletErrorPage.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericservlet/ServletErrorPage.java new file mode 100644 index 0000000000..8e0c0dcf4c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericservlet/ServletErrorPage.java @@ -0,0 +1,75 @@ +/* + * 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 com.sun.ts.tests.servlet.api.jakarta_servlet.genericservlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +/** + * Simple Servlet-based error page that displays error related req attributes. + */ + +public class ServletErrorPage extends GenericServlet { + + private static final String STATUS_CODE = RequestDispatcher.ERROR_STATUS_CODE; // "jakarta.servlet.error.status_code"; + + private static final String EXCEPTION_TYPE = RequestDispatcher.ERROR_EXCEPTION_TYPE; //"jakarta.servlet.error.exception_type"; + + private static final String MESSAGE = RequestDispatcher.ERROR_MESSAGE; //"jakarta.servlet.error.message"; + + private static final String EXCEPTION = RequestDispatcher.ERROR_EXCEPTION; //"jakarta.servlet.error.exception" + + private static final String REQUEST_URI = RequestDispatcher.ERROR_REQUEST_URI; //"jakarta.servlet.error.request_uri"; + + private static final String SERVLET_NAME = RequestDispatcher.ERROR_SERVLET_NAME; //"jakarta.servlet.error.servlet_name" + + private static final String EXP_MESSAGE = "error page invoked"; + + /** + * Invoked by container + */ + public void service(ServletRequest req, ServletResponse res) + throws ServletException, IOException { + + PrintWriter pw = res.getWriter(); + // display req attributes + pw.println("Servlet Name: " + req.getAttribute(SERVLET_NAME)); + pw.println("Request URI: " + req.getAttribute(REQUEST_URI)); + pw.println("Status Code: " + req.getAttribute(STATUS_CODE)); + pw.println("Exception Type: " + req.getAttribute(EXCEPTION_TYPE)); + pw.println("Exception: " + req.getAttribute(EXCEPTION)); + pw.print("Message: "); + if (((String) req.getAttribute(MESSAGE)).indexOf(EXP_MESSAGE) > -1) { + pw.println(EXP_MESSAGE); + } + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericservlet/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericservlet/TestServlet.java new file mode 100644 index 0000000000..d2013bfb40 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericservlet/TestServlet.java @@ -0,0 +1,204 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.genericservlet; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Enumeration; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void getServletConfigTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + + if (getServletConfig() == null) { + passed = false; + pw.println("getServletConfig method returned a null"); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + + } + + public void getServletContextTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + boolean passed = false; + + if (getServletContext() == null) { + passed = false; + pw.println("getServletContext method returned a null"); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public void getServletInfoTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + + if (getServletInfo() == null) { + passed = false; + pw.println("getServletInfo method returned a null"); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public void getServletNameTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + + String expected = "TestServlet"; + String actual = getServletName(); + + if (actual != null) { + if (!expected.equals(actual)) { + passed = false; + pw.println("getServletName returned the wrong result"); + pw.println("Expected result= " + expected); + pw.println("Actual result= " + actual); + } else { + passed = true; + } + } else { + passed = false; + pw.println("getServletName method returned a null"); + } + ServletTestUtil.printResult(pw, passed); + + } + + public void getInitParameterTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + boolean passed = false; + String expected = "value1"; + + String actual = getInitParameter("parameter1"); + if (!expected.equals(actual)) { + passed = false; + pw.println("getInitParameter(String) did not return the correct result"); + pw.println("Expected result=" + expected); + pw.println("Actual result=" + actual); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public void getInitParameterNamesTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + boolean passed = true; + + String expectedResult1 = "parameter1"; + boolean expectedResult1Found = false; + String expectedResult2 = "parameter2"; + boolean expectedResult2Found = false; + Enumeration initP = getInitParameterNames(); + + if (initP.hasMoreElements()) { + while (initP.hasMoreElements()) { + String name = (String) initP.nextElement(); + pw.println("Initialization parameter: " + name); + + if (name.equals(expectedResult1)) { + if (!expectedResult1Found) { + expectedResult1Found = true; + } else { + passed = false; + pw.println( + "getInitParameterNames() method return an attribute name twice "); + pw.println( + "The attribute already specified was " + expectedResult1 + " "); + } + } else if (name.equals(expectedResult2)) { + if (!expectedResult2Found) { + expectedResult2Found = true; + } else { + passed = false; + pw.println( + "getInitParameterNames() method return an attribute name twice "); + pw.println( + "The attribute already specified was " + expectedResult2 + " "); + } + } + } + } + ServletTestUtil.printResult(pw, passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericservlet/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericservlet/URLClient.java new file mode 100644 index 0000000000..3ad1018809 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericservlet/URLClient.java @@ -0,0 +1,253 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.genericservlet; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_genericservlet_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(DestroyTestServlet.class, Init_ServletConfigServletExceptionTestServlet.class, + Init_ServletConfigTestServlet.class, InitServletExceptionTestServlet.class, + InitTestServlet.class, ServiceTestServlet.class, ServletErrorPage.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_js_genericservlet_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: destroyTest + * + * @assertion_ids: Servlet:JAVADOC:119 + * + * @test_Strategy: Create a GenericServlet and take out of service using + * destroy method + * + */ + @Test + public void destroyTest() throws Exception { + String testName = "destroyTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(IGNORE_BODY, "true"); + invoke(); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(IGNORE_BODY, "true"); + invoke(); + } + + /* + * @testName: getServletConfigTest + * + * @assertion_ids: Servlet:JAVADOC:124 + * + * @test_Strategy: Create a GenericServlet and check for its ServletConfig + * object existence + * + */ + @Test + public void getServletConfigTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletConfigTest"); + invoke(); + } + + /* + * @testName: getServletContextTest + * + * @assertion_ids: Servlet:JAVADOC:125 + * + * @test_Strategy: Create a GenericServlet and check for its ServletContext + * object existence + * + */ + @Test + public void getServletContextTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletContextTest"); + invoke(); + } + + /* + * @testName: getServletInfoTest + * + * @assertion_ids: Servlet:JAVADOC:126 + * + * @test_Strategy: Create a GenericServlet and check for its ServletInfo + * object values + * + */ + @Test + public void getServletInfoTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletInfoTest"); + invoke(); + } + + /* + * @testName: getInitParameterTest + * + * @assertion_ids: Servlet:JAVADOC:120 + * + * @test_Strategy: Servlet tries to access a parameter that exists + */ + @Test + public void getInitParameterTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getInitParameterTest"); + invoke(); + } + + /* + * @testName: getInitParameterNamesTest + * + * @assertion_ids: Servlet:JAVADOC:122 + * + * @test_Strategy: Servlet tries to get all parameter names + */ + @Test + public void getInitParameterNamesTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getInitParameterNamesTest"); + invoke(); + } + + /* + * @testName: getServletNameTest + * + * @assertion_ids: Servlet:JAVADOC:136 + * + * @test_Strategy: Servlet gets name of servlet + */ + @Test + public void getServletNameTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletNameTest"); + invoke(); + } + + /* + * @testName: initServletExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:130 + * + * @test_Strategy: Servlet throws a ServletException + */ + @Test + public void initServletExceptionTest() throws Exception { + String testName = "initServletExceptionTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(STATUS_CODE, INTERNAL_SERVER_ERROR); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, + "Status Code: 500|Exception: jakarta.servlet.ServletException: in init of InitServletExceptionTestServlet"); + invoke(); + } + + /* + * @testName: initTest + * + * @assertion_ids: Servlet:JAVADOC:129 + * + * @test_Strategy: Servlet has init method that puts a value into the context. + * Servlet when called reads value from context + */ + @Test + public void initTest() throws Exception { + String testName = "initTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + testName + " HTTP/1.1"); + invoke(); + } + + /* + * @testName: init_ServletConfigServletExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:128 + * + * @test_Strategy: Servlet throws a ServletException + */ + @Test + public void init_ServletConfigServletExceptionTest() throws Exception { + String testName = "init_ServletConfigServletExceptionTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(STATUS_CODE, INTERNAL_SERVER_ERROR); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, + "Status Code: 500|Exception: jakarta.servlet.ServletException: in init of Init_ServletConfigServletExceptionTestServlet"); + invoke(); + } + + /* + * @testName: init_ServletConfigTest + * + * @assertion_ids: Servlet:JAVADOC:127 + * + * @test_Strategy: Servlet has init method that puts a value into the context. + * Servlet when called reads value from context + */ + @Test + public void init_ServletConfigTest() throws Exception { + String testName = "init_ServletConfigTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + testName + " HTTP/1.1"); + invoke(); + } + + /* + * @testName: serviceTest + * + * @assertion_ids: Servlet:JAVADOC:133 + * + * @test_Strategy: Servlet which has a service method that is called + */ + @Test + public void serviceTest() throws Exception { + String testName = "serviceTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + testName + " HTTP/1.1"); + invoke(); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericservlet/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericservlet/build.xml new file mode 100644 index 0000000000..8578790a03 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericservlet/build.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericservlet/servlet_js_genericservlet_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericservlet/servlet_js_genericservlet_web.xml new file mode 100644 index 0000000000..1ab783b9ba --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/genericservlet/servlet_js_genericservlet_web.xml @@ -0,0 +1,101 @@ + + + + + SerJaxSerGenericServlet + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.genericservlet.TestServlet + + parameter1 + value1 + + + parameter2 + value2 + + + + destroyTest + com.sun.ts.tests.servlet.api.jakarta_servlet.genericservlet.DestroyTestServlet + + + initServletExceptionTest + com.sun.ts.tests.servlet.api.jakarta_servlet.genericservlet.InitServletExceptionTestServlet + + + initTest + com.sun.ts.tests.servlet.api.jakarta_servlet.genericservlet.InitTestServlet + + + init_ServletConfigServletExceptionTest + com.sun.ts.tests.servlet.api.jakarta_servlet.genericservlet.Init_ServletConfigServletExceptionTestServlet + + + init_ServletConfigTest + com.sun.ts.tests.servlet.api.jakarta_servlet.genericservlet.Init_ServletConfigTestServlet + + + servletErrorPage + com.sun.ts.tests.servlet.api.jakarta_servlet.genericservlet.ServletErrorPage + + + serviceTest + com.sun.ts.tests.servlet.api.jakarta_servlet.genericservlet.ServiceTestServlet + + + TestServlet + /TestServlet/* + + + destroyTest + /destroyTest + + + initServletExceptionTest + /initServletExceptionTest + + + initTest + /initTest + + + init_ServletConfigServletExceptionTest + /init_ServletConfigServletExceptionTest + + + init_ServletConfigTest + /init_ServletConfigTest + + + servletErrorPage + /servletErrorPage + + + serviceTest + /serviceTest + + + 54 + + + jakarta.servlet.ServletException + /servletErrorPage + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/registration/TestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/registration/TestListener.java new file mode 100644 index 0000000000..e3ded8e292 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/registration/TestListener.java @@ -0,0 +1,373 @@ +/* + * Copyright (c) 2009, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.registration; + +import java.util.Collection; +import java.util.EnumSet; +import java.util.EventListener; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import jakarta.servlet.DispatcherType; +import jakarta.servlet.Filter; +import jakarta.servlet.FilterRegistration; +import jakarta.servlet.Registration; +import jakarta.servlet.Servlet; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRegistration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class TestListener implements ServletContextListener { + + private static final Logger LOGGER = LoggerFactory.getLogger(TestListener.class); + + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce + * The servlet context event + */ + public void contextInitialized(ServletContextEvent sce) { + ServletContext context = sce.getServletContext(); + + final String addServletName1 = "AddServletString"; + final String addServletName2 = "AddServletClass"; + final String addServletName3 = "CreateServlet"; + final String addServletName4 = "AddServletNotFound"; + + final String addFilterName1 = "AddFilterString"; + final String addFilterName2 = "AddFilterClass"; + final String addFilterName3 = "CreateFilter"; + final String addFilterName4 = "AddFilterNotFound"; + + final String[] param_names = { "Filter", "FilterName", "Servlet", + "DISPATCH", "ServletName" }; + + /* + * Add Servlet AddServletString + */ + ServletRegistration srString = context.addServlet(addServletName1, + "com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddServletString"); + srString.addMapping("/addServletString"); + srString.setInitParameter("FILTER", addFilterName1); + Map params = new HashMap<>(); + params.put("Filter", "No"); + params.put("Servlet", "Yes"); + params.put("FilterName", addFilterName1); + params.put("ServletName", addServletName1); + params.put("DISPATCH", DispatcherType.FORWARD.toString()); + srString.setInitParameters(params); + params.clear(); + + FilterRegistration frString = context.addFilter(addFilterName1, + "com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddFilterString"); + frString.addMappingForServletNames(EnumSet.of(DispatcherType.FORWARD), true, + addServletName1); + frString.setInitParameter("SERVLET", addServletName1); + params.put("Filter", "Yes"); + params.put("Servlet", "No"); + params.put("FilterName", addFilterName1); + params.put("ServletName", addServletName1); + params.put("DISPATCH", DispatcherType.FORWARD.toString()); + frString.setInitParameters(params); + params.clear(); + + /* + * Add Servlet AddServletClass + */ + ServletRegistration srClass = context.addServlet(addServletName2, + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddServletClass.class); + srClass.addMapping("/addServletClass", "/SecondaddServletClass", + "/ThirdAddServletClass", "/AddServletClass/*"); + srClass.setInitParameter("FILTER", addFilterName2); + params.put("Filter", "No"); + params.put("Servlet", "Yes"); + params.put("FilterName", addFilterName2); + params.put("ServletName", addServletName2); + params.put("DISPATCH", DispatcherType.REQUEST.toString()); + srClass.setInitParameters(params); + params.clear(); + + FilterRegistration frClass = context.addFilter(addFilterName2, + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddFilterClass.class); + frClass.addMappingForServletNames(EnumSet.of(DispatcherType.REQUEST), true, + addServletName2); + frClass.setInitParameter("SERVLET", addServletName2); + params.put("Filter", "Yes"); + params.put("Servlet", "No"); + params.put("FilterName", addFilterName2); + params.put("ServletName", addServletName2); + params.put("DISPATCH", DispatcherType.REQUEST.toString()); + frClass.setInitParameters(params); + params.clear(); + + /* + * Add Servlet CreateServlet + */ + ServletRegistration srServlet = null; + FilterRegistration frFilter = null; + try { + Servlet servlet3 = context.createServlet( + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.CreateServlet.class); + srServlet = context.addServlet(addServletName3, servlet3); + srServlet.addMapping("/createServlet", "/SecondCreateServlet", + "/ThirdCreateServlet"); + srServlet.setInitParameter("FILTER", addFilterName3); + params.put("Filter", "No"); + params.put("Servlet", "Yes"); + params.put("FilterName", addFilterName3); + params.put("ServletName", addServletName3); + params.put("DISPATCH", DispatcherType.REQUEST.toString()); + srServlet.setInitParameters(params); + params.clear(); + + Filter filter3 = context.createFilter( + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.CreateFilter.class); + frFilter = context.addFilter(addFilterName3, filter3); + frFilter.addMappingForServletNames(EnumSet.of(DispatcherType.REQUEST), + true, addServletName3); + frFilter.setInitParameter("SERVLET", addServletName3); + params.put("Filter", "Yes"); + params.put("Servlet", "No"); + params.put("FilterName", addFilterName3); + params.put("ServletName", addServletName3); + params.put("DISPATCH", DispatcherType.REQUEST.toString()); + frFilter.setInitParameters(params); + params.clear(); + } catch (ServletException ex) { + LOGGER.error("Error creating Servlet"); + } + + /* + * Add Servlet AddServletNotFound + */ + ServletRegistration srNotFound = context.addServlet(addServletName4, + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddServletNotFound.class); + srNotFound.addMapping("/addServletNotFound", "/TestServlet"); + srNotFound.setInitParameter("FILTER", addFilterName4); + srNotFound.setInitParameter(addFilterName4, "ALL"); + params.put("Filter", "No"); + params.put("Servlet", "Yes"); + params.put("FilterName", addFilterName4); + params.put("ServletName", addServletName4); + params.put("DISPATCH", "ALL"); + srNotFound.setInitParameters(params); + params.clear(); + + FilterRegistration frNotFound = context.addFilter(addFilterName4, + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddFilterNotFound.class); + frNotFound.addMappingForServletNames( + EnumSet.of(DispatcherType.REQUEST, DispatcherType.INCLUDE, + DispatcherType.FORWARD, DispatcherType.ERROR), + true, addServletName4); + frNotFound.setInitParameter("SERVLET", addServletName4); + params.put("Filter", "Yes"); + params.put("Servlet", "No"); + params.put("FilterName", addFilterName4); + params.put("ServletName", addServletName4); + params.put("DISPATCH", "ALL"); + frNotFound.setInitParameters(params); + params.clear(); + + /* + * Negative tests for - createServlet - createFilter - createListener + */ + + Boolean servlet_test = false; + Boolean filter_test = false; + Boolean listener_test = false; + String SERVLET_TEST = "SERVLET_TEST"; + String FILTER_TEST = "FILTER_TEST"; + String LISTENER_TEST = "LISTENER_TEST"; + + try { + Servlet badservlet = context.createServlet( + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.BadServlet.class); + } catch (ServletException ex) { + servlet_test = true; + } + context.setInitParameter(SERVLET_TEST, servlet_test.toString()); + + try { + Filter badfilter = context.createFilter( + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.BadFilter.class); + } catch (ServletException ex) { + filter_test = true; + } + context.setInitParameter(FILTER_TEST, filter_test.toString()); + + try { + EventListener badlistener = context.createListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.BadListener.class); + } catch (ServletException ex) { + listener_test = true; + } + context.setInitParameter(LISTENER_TEST, listener_test.toString()); + + /* + * Test for ServletRegistration.getMappings() + */ + String URL_MAPPING = "URL_MAPPING_TEST"; + StringBuilder Value_OF_URL = new StringBuilder(); + Collection url_mappings = srClass.getMappings(); + for (String url : url_mappings) { + Value_OF_URL.append(url).append('|'); + } + context.setInitParameter(URL_MAPPING, Value_OF_URL.toString()); + + /* + * Test for ServletRegistration.getServletRegistrations() + */ + String SERVLET_REGISTRATIONS = "SERVLET_REGISTRATIONS"; + StringBuilder Value_OF_Servlet_Registrations = new StringBuilder(); + Map servlet_registrations = context.getServletRegistrations(); + Iterator it = servlet_registrations.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry pairs = (Map.Entry) it.next(); + Value_OF_Servlet_Registrations + .append(pairs.getKey() + "=" + pairs.getValue() + "|"); + } + context.setInitParameter(SERVLET_REGISTRATIONS, + Value_OF_Servlet_Registrations.toString()); + + /* + * Test for ServletRegistration.getServletRegistration(String) + */ + String SERVLET_REGISTRATION = "SERVLET_REGISTRATION"; + StringBuilder Value_OF_Registration = new StringBuilder(); + String[] servlets = { "AddServletString", "AddServletClass", "AddServletNotFound", "CreateServlet", "TestServlet" }; + for (String servlet : servlets) { + Value_OF_Registration.append( + servlet + "=" + context.getServletRegistration(servlet) + "|"); + } + context.setInitParameter(SERVLET_REGISTRATION, + Value_OF_Registration.toString()); + + /* + * Test for FilterRegistration.getFilterRegistrations() + */ + String FILTER_REGISTRATIONS = "FILTER_REGISTRATIONS"; + StringBuilder Value_OF_Filter_Registrations = new StringBuilder(); + Map filter_registrations = context + .getFilterRegistrations(); + it = filter_registrations.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry pairs = (Map.Entry) it.next(); + Value_OF_Filter_Registrations + .append(pairs.getKey() + "=" + pairs.getValue() + "|"); + } + context.setInitParameter(FILTER_REGISTRATIONS, + Value_OF_Filter_Registrations.toString()); + + /* + * Test for ServletRegistration.getFilterRegistration(String) + */ + String FILTER_REGISTRATION = "FILTER_REGISTRATION"; + StringBuffer Value_OF_Filter_Registration = new StringBuffer(); + String[] filters = { "AddFilterString", "AddFilterClass", + "AddFilterNotFound", "CreateFilter" }; + for (String filter : filters) { + Value_OF_Filter_Registration + .append(filter + "=" + context.getFilterRegistration(filter) + "|"); + } + context.setInitParameter(FILTER_REGISTRATION, + Value_OF_Filter_Registration.toString()); + + /* + * Test for FilterRegistration.getServletNameMappings() + */ + String FILTER_SERVLET_MAPPING = "FILTER_SERVLET_MAPPING"; + StringBuffer Value_OF_Servlet_URL = new StringBuffer(); + FilterRegistration[] Filters = { frString, frClass, frNotFound, frFilter }; + for (FilterRegistration Filter_Test : Filters) { + Collection servlet_mappings = Filter_Test + .getServletNameMappings(); + for (String servlet : servlet_mappings) { + Value_OF_Servlet_URL.append(servlet + "|"); + } + } + context.setInitParameter(FILTER_SERVLET_MAPPING, + Value_OF_Servlet_URL.toString()); + + /* + * Test for Registration.getName() Test for Registration.getClassName() Test + * for Registration.setInitParameter(String) Test for + * Registration.getInitParameter(String) Test for + * Registration.setInitParameters() Test for + * Registration.getInitParameters() + */ + + String REGISTRATION_NAME = "REGISTRION_NAME"; + String REGISTRATION_CLASS_NAME = "REGISTRATION_CLASS_NAME"; + String REGISTRATION_INIT_PARAMETER = "REGISTRATION_INIT_PARAMETER"; + String REGISTRATION_INIT_PARAMETERS = "REGISTRATION_INIT_PARAMETERS"; + + StringBuffer Value_OF_Registration_Name = new StringBuffer(); + StringBuffer Value_OF_Registration_Class_Name = new StringBuffer(); + StringBuffer Value_OF_Registration_InitParameter = new StringBuffer(); + StringBuffer Value_OF_Registration_InitParameters = new StringBuffer(); + + Registration[] registrations = { srString, frString, srClass, frClass, + srServlet, frFilter, srNotFound, frNotFound }; + + for (Registration registration : registrations) { + Value_OF_Registration_Name.append(registration.getName() + "|"); + + Value_OF_Registration_Class_Name + .append(registration.getClassName() + "|"); + + Value_OF_Registration_InitParameter + .append(registration.getInitParameter("FILTER") + "|"); + Value_OF_Registration_InitParameter + .append(registration.getInitParameter("SERVLET") + "|"); + + params = registration.getInitParameters(); + for (int i = 0; i < 5; i++) { + Value_OF_Registration_InitParameters + .append(param_names[i] + "=" + params.get(param_names[i]) + "|"); + } + } + + context.setInitParameter(REGISTRATION_NAME, + Value_OF_Registration_Name.toString()); + context.setInitParameter(REGISTRATION_CLASS_NAME, + Value_OF_Registration_Class_Name.toString()); + context.setInitParameter(REGISTRATION_INIT_PARAMETER, + Value_OF_Registration_InitParameter.toString()); + context.setInitParameter(REGISTRATION_INIT_PARAMETERS, + Value_OF_Registration_InitParameters.toString()); + } + + /** + * Receives notification that the servlet context is about to be shut down. + * + * @param sce + * The servlet context event + */ + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/registration/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/registration/TestServlet.java new file mode 100644 index 0000000000..49ca9cbb73 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/registration/TestServlet.java @@ -0,0 +1,212 @@ +/* + * Copyright (c) 2009, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.registration; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.StringTokenizer; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void servletURLMappingTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + String URL_MAPPING = "URL_MAPPING_TEST"; + + pw.println(URL_MAPPING + "=" + + getServletContext().getInitParameter(URL_MAPPING).toUpperCase()); + getServletContext().removeAttribute(URL_MAPPING); + + ServletTestUtil.printResult(pw, true); + } + + public void filterServletMappingTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + String FILTER_SERVLET_MAPPING = "FILTER_SERVLET_MAPPING"; + + pw.println(FILTER_SERVLET_MAPPING + "=" + + getServletContext().getInitParameter(FILTER_SERVLET_MAPPING)); + getServletContext().removeAttribute(FILTER_SERVLET_MAPPING); + + ServletTestUtil.printResult(pw, true); + } + + public void getServletRegistrationsTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + String SERVLET_REGISTRIONS = "SERVLET_REGISTRATIONS"; + + pw.println(SERVLET_REGISTRIONS + ":"); + String servlets = getServletContext().getInitParameter(SERVLET_REGISTRIONS) + .toUpperCase(); + + StringTokenizer st = new StringTokenizer(servlets, "|"); + while (st.hasMoreTokens()) { + pw.println(st.nextToken()); + } + + getServletContext().removeAttribute(SERVLET_REGISTRIONS); + + ServletTestUtil.printResult(pw, true); + } + + public void getServletRegistrationTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + String SERVLET_REGISTRATION = "SERVLET_REGISTRATION"; + + pw.println(SERVLET_REGISTRATION + ":"); + String servlets = getServletContext().getInitParameter(SERVLET_REGISTRATION) + .toUpperCase(); + + StringTokenizer st = new StringTokenizer(servlets, "|"); + while (st.hasMoreTokens()) { + pw.println(st.nextToken()); + } + + getServletContext().removeAttribute(SERVLET_REGISTRATION); + + ServletTestUtil.printResult(pw, true); + } + + public void getFilterRegistrationsTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + String FILTER_REGISTRIONS = "FILTER_REGISTRATIONS"; + + pw.println(FILTER_REGISTRIONS + ":"); + String filters = getServletContext().getInitParameter(FILTER_REGISTRIONS); + + StringTokenizer st = new StringTokenizer(filters, "|"); + while (st.hasMoreTokens()) { + pw.println(st.nextToken()); + } + + getServletContext().removeAttribute(FILTER_REGISTRIONS); + + ServletTestUtil.printResult(pw, true); + } + + public void getFilterRegistrationTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + String FILTER_REGISTRION = "FILTER_REGISTRATION"; + + pw.println(FILTER_REGISTRION + ":"); + String filters = getServletContext().getInitParameter(FILTER_REGISTRION); + + StringTokenizer st = new StringTokenizer(filters, "|"); + while (st.hasMoreTokens()) { + pw.println(st.nextToken()); + } + + getServletContext().removeAttribute(FILTER_REGISTRION); + + ServletTestUtil.printResult(pw, true); + } + + public void getRegistrationNameTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + String REGISTRATION_NAME = "REGISTRION_NAME"; + + pw.println(REGISTRATION_NAME + ":"); + String servlets = getServletContext().getInitParameter(REGISTRATION_NAME) + .toUpperCase(); + + StringTokenizer st = new StringTokenizer(servlets, "|"); + while (st.hasMoreTokens()) { + pw.println(st.nextToken()); + } + + getServletContext().removeAttribute(REGISTRATION_NAME); + + ServletTestUtil.printResult(pw, true); + } + + public void getRegistrationClassNameTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + String REGISTRATION_CLASS_NAME = "REGISTRATION_CLASS_NAME"; + + pw.println(REGISTRATION_CLASS_NAME + ":"); + String servlets = getServletContext() + .getInitParameter(REGISTRATION_CLASS_NAME).toUpperCase(); + + StringTokenizer st = new StringTokenizer(servlets, "|"); + while (st.hasMoreTokens()) { + pw.println(st.nextToken()); + } + + getServletContext().removeAttribute(REGISTRATION_CLASS_NAME); + + ServletTestUtil.printResult(pw, true); + } + + public void getRegistrationInitParameterTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + String REGISTRATION_INIT_PARAMETER = "REGISTRATION_INIT_PARAMETER"; + + pw.println(REGISTRATION_INIT_PARAMETER + ":"); + String servlets = getServletContext() + .getInitParameter(REGISTRATION_INIT_PARAMETER); + + if (servlets != null) { + StringTokenizer st = new StringTokenizer(servlets, "|"); + while (st.hasMoreTokens()) { + pw.println(st.nextToken()); + } + ServletTestUtil.printResult(pw, true); + } else { + ServletTestUtil.printResult(pw, false); + } + getServletContext().removeAttribute(REGISTRATION_INIT_PARAMETER); + } + + public void getRegistrationInitParametersTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + String REGISTRATION_INIT_PARAMETERS = "REGISTRATION_INIT_PARAMETERS"; + + pw.println(REGISTRATION_INIT_PARAMETERS + ":"); + String all_stuff = getServletContext() + .getInitParameter(REGISTRATION_INIT_PARAMETERS); + + if (all_stuff != null) { + StringTokenizer st = new StringTokenizer(all_stuff, "|"); + while (st.hasMoreTokens()) { + pw.println(st.nextToken()); + } + ServletTestUtil.printResult(pw, true); + } else { + ServletTestUtil.printResult(pw, false); + } + getServletContext().removeAttribute(REGISTRATION_INIT_PARAMETERS); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/registration/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/registration/URLClient.java new file mode 100644 index 0000000000..204baa2d53 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/registration/URLClient.java @@ -0,0 +1,388 @@ +/* + * Copyright (c) 2009, 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: URLClient.java 58928 2009-08-03 21:08:09Z djiao $ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.registration; + +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddFilterClass; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddFilterNotFound; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddFilterString; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddServletClass; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddServletNotFound; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddServletString; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.BadFilter; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.BadListener; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.BadServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.CreateFilter; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.CreateServlet; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_registration_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestListener.class, TestServlet.class, AddServletString.class, AddFilterString.class, + AddServletClass.class, AddFilterClass.class, CreateServlet.class, CreateFilter.class, + AddServletNotFound.class, AddFilterNotFound.class, BadServlet.class, BadFilter.class, + BadListener.class) + .setWebXML(URLClient.class.getResource("servlet_js_registration_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * Test strategy: Create a ServletContextListener, in which, 1. Add the + * Servlet ServletContext.addServlet(String, Class), Add another Servlet + * ServletContext.addServlet(String, String), Add the third Servlet + * ServletContext.addServlet(String, Servlet), Add the fourth Servlet + * ServletContext.createServlet(Class), 2. mapping the new Servlets + * programmatically. 3. Create a FilterRegistration + * ServletContext.addFilter(String, Class) Create another FilterRegistration + * ServletContext.addFilter(String, String), Create the third + * FilterRegistration ServletContext.addFilter(String, Filter), Create the + * fourth FilterRegistration ServletContext.createFilter(Class), 4. Map all + * FilterRegistration calling addMappingForServletNames 5. Store server side + * information returned in ServletContextAttribute 6. Define a servlet in + * web.xml; 7. client send a request to the last servlet to get server + * information + */ + /* + * @testName: servletURLMappingTest + * + * @assertion_ids: Servlet:JAVADOC:664; Servlet:JAVADOC:676; + * Servlet:JAVADOC:696; Servlet:JAVADOC:697; + * + * @test_Strategy: Create a ServletContextListener, in which, 1. Add the + * Servlet ServletContext.addServlet(String, Class), 2. mapping the new + * Servlet programmatically. 3. Store information returned by + * jakarta.servlet.ServletRegistration.getMappings in ServletContextAttribute 4. + * client send a request to another servlet to get the information Verify in + * client that getMapping works + */ + @Test + public void servletURLMappingTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "servletURLMappingTest"); + TEST_PROPS.setProperty(UNORDERED_SEARCH_STRING, + "URL_MAPPING_TEST" + "|/ADDSERVLETCLASS" + "|/SECONDADDSERVLETCLASS" + + "|/THIRDADDSERVLETCLASS" + "|/ADDSERVLETCLASS/*"); + invoke(); + } + + /* + * @testName: filterServletMappingTest + * + * @assertion_ids: Servlet:JAVADOC:243; Servlet:JAVADOC:655; + * Servlet:JAVADOC:657; Servlet:JAVADOC:668; Servlet:JAVADOC:668.3; + * Servlet:JAVADOC:669; Servlet:JAVADOC:669.3; Servlet:JAVADOC:670; + * Servlet:JAVADOC:670.3; Servlet:JAVADOC:677; Servlet:JAVADOC:677.1; + * Servlet:JAVADOC:694; + * + * @test_Strategy: Create a ServletContextListener, in which, 1. Create a + * FilterRegistration ServletContext.addFilter(String, Class) 2. Create + * another FilterRegistration ServletContext.addFilter(String, String), 3. + * Create the third FilterRegistration ServletContext.addServlet(String, + * Filter), 4. Map all FilterRegistration calling addMappingForServletNames 5. + * Store information in ServletContextAttribute: + * jakarta.servlet.FilterRegistration.getServletNameMappings 6. client send a + * request to another servlet to get the information Verify in client that + * getServletNameMappings works + */ + @Test + public void filterServletMappingTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "filterServletMappingTest"); + TEST_PROPS.setProperty(SEARCH_STRING, + "FILTER_SERVLET_MAPPING" + "|AddServletString" + "|AddServletClass" + + "|AddServletNotFound" + "|CreateServlet"); + invoke(); + } + + /* + * @testName: servletRegistrationsTest + * + * @assertion_ids: Servlet:JAVADOC:674; Servlet:JAVADOC:675; + * Servlet:JAVADOC:676; Servlet:JAVADOC:681; Servlet:JAVADOC:692; + * Servlet:JAVADOC:694; Servlet:JAVADOC:696; + * + * + * @test_Strategy: Create a ServletContextListener, in which, 1. Add the + * Servlet ServletContext.addServlet(String, Class), 2. Add another Servlet + * ServletContext.addServlet(String, String), 3. Add the third Servlet + * ServletContext.addServlet(String, Servlet), 4. Add the fourth Servlet + * ServletContext.createServlet(Class), 5. Define a servlet in web.xml; 6. + * Store information returned in ServletContextAttribute by + * jakarta.servlet.ServletRegistration.getServletRegistrations 7. client send a + * request to another servlet to get the information Verify in client that + * getServletRegistrations works + */ + @Test + public void servletRegistrationsTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletRegistrationsTest"); + TEST_PROPS.setProperty(UNORDERED_SEARCH_STRING, + "SERVLET_REGISTRATIONS:" + "|ADDSERVLETCLASS" + "|ADDSERVLETNOTFOUND" + + "|ADDSERVLETSTRING" + "|CREATESERVLET" + "|TESTSERVLET"); + invoke(); + } + + /* + * @testName: getServletRegistrationTest + * + * @assertion_ids: Servlet:JAVADOC:674; Servlet:JAVADOC:675; + * Servlet:JAVADOC:676; Servlet:JAVADOC:681; Servlet:JAVADOC:691; + * Servlet:JAVADOC:694; Servlet:JAVADOC:696; + * + * @test_Strategy: Create a ServletContextListener, in which, 1. Add the + * Servlet ServletContext.addServlet(String, Class), 2. Add another Servlet + * ServletContext.addServlet(String, String), 3. Add the third Servlet + * ServletContext.addServlet(String, Servlet), 4. Add the fourth Servlet + * ServletContext.createServlet(Class), 5. Define a servlet in web.xml; 6. + * Store information returned in ServletContextAttribute by + * jakarta.servlet.ServletRegistration.getServletRegistration(String) 7. client + * send a request to another servlet to get the information Verify in client + * that getServletRegistration(String) works + */ + @Test + public void getServletRegistrationTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletRegistrationTest"); + TEST_PROPS.setProperty(SEARCH_STRING, + "SERVLET_REGISTRATION:" + "|ADDSERVLETSTRING" + "|ADDSERVLETCLASS" + + "|ADDSERVLETNOTFOUND" + "|CREATESERVLET" + "|TESTSERVLET"); + invoke(); + } + + /* + * @testName: getFilterRegistrationsTest + * + * @assertion_ids: Servlet:JAVADOC:674; Servlet:JAVADOC:675; + * Servlet:JAVADOC:676; Servlet:JAVADOC:681; Servlet:JAVADOC:689; + * Servlet:JAVADOC:694; Servlet:JAVADOC:696; + * + * + * @test_Strategy: Create a ServletContextListener, in which, 1. Add the + * Servlet ServletContext.addServlet(String, Class), 2. Add another Servlet + * ServletContext.addServlet(String, String), 3. Add the third Servlet + * ServletContext.addServlet(String, Servlet), 4. Add the fourth Servlet + * ServletContext.createServlet(Class), 5. Define a servlet in web.xml; 6. + * Store information returned in ServletContextAttribute by + * jakarta.servlet.ServletRegistration.getFilterRegistrations 7. client send a + * request to another servlet to get the information Verify in client that + * getFilterRegistrations works + */ + @Test + public void getFilterRegistrationsTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getFilterRegistrationsTest"); + TEST_PROPS.setProperty(UNORDERED_SEARCH_STRING, + "FILTER_REGISTRATIONS:" + "|AddFilterClass" + "|AddFilterNotFound" + + "|AddFilterString" + "|CreateFilter"); + invoke(); + } + + /* + * @testName: getFilterRegistrationTest + * + * @assertion_ids: Servlet:JAVADOC:674; Servlet:JAVADOC:675; + * Servlet:JAVADOC:676; Servlet:JAVADOC:681; Servlet:JAVADOC:688; + * Servlet:JAVADOC:694; Servlet:JAVADOC:696; + * + * @test_Strategy: Create a ServletContextListener, in which, 1. Add the + * Servlet ServletContext.addServlet(String, Class), 2. Add another Servlet + * ServletContext.addServlet(String, String), 3. Add the third Servlet + * ServletContext.addServlet(String, Servlet), 4. Add the fourth Servlet + * ServletContext.createServlet(Class), 5. Define a servlet in web.xml; 6. + * Store information returned in ServletContextAttribute by + * jakarta.servlet.ServletRegistration.getFilterRegistration(String) 7. client + * send a request to another servlet to get the information Verify in client + * that getFilterRegistration(String) works + */ + @Test + public void getFilterRegistrationTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getFilterRegistrationTest"); + TEST_PROPS.setProperty(SEARCH_STRING, + "FILTER_REGISTRATION:" + "|AddFilterString" + "|AddFilterClass" + + "|AddFilterNotFound" + "|CreateFilter"); + invoke(); + } + + /* + * @testName: getRegistrationNameTest + * + * @assertion_ids: Servlet:JAVADOC:243; Servlet:JAVADOC:662; + * Servlet:JAVADOC:668; Servlet:JAVADOC:669; Servlet:JAVADOC:670; + * Servlet:JAVADOC:674; Servlet:JAVADOC:675; Servlet:JAVADOC:676; + * Servlet:JAVADOC:677; Servlet:JAVADOC:681; Servlet:JAVADOC:694; + * + * @test_Strategy: Create a ServletContextListener, in which, 1. Create a + * ServletRegistration ServletContext.addServlet(String, Class) 2. Create + * another ServletRegistration ServletContext.addServlet(String, String), 3. + * Create the third ServletRegistration ServletContext.addServlet(String, + * Servlet), 4. Add the fourth Servlet ServletContext.createServlet(Class), 5. + * Create a FilterRegistration ServletContext.addFilter(String, Class) 6. + * Create another FilterRegistration ServletContext.addFilter(String, String), + * 7. Create the third FilterRegistration ServletContext.addFilter(String, + * Filter), 8. Create the fourth FilterRegistration + * ServletContext.CreateFilter(Class), 9. Store information returned in + * ServletContextAttribute by jakarta.servlet.Registration.getName() 10. client + * send a request to another servlet to get the information Verify in client + * that jakarta.servlet.Registration.getName() works + */ + @Test + public void getRegistrationNameTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getRegistrationNameTest"); + TEST_PROPS.setProperty(SEARCH_STRING, + "REGISTRION_NAME:" + "|ADDSERVLETSTRING" + "|ADDFILTERSTRING" + + "|ADDSERVLETCLASS" + "|ADDFILTERCLASS" + "|CREATESERVLET" + + "|CREATEFILTER" + "|ADDSERVLETNOTFOUND" + "|ADDFILTERNOTFOUND"); + invoke(); + } + + /* + * @testName: getRegistrationClassNameTest + * + * @assertion_ids: Servlet:JAVADOC:243; Servlet:JAVADOC:659; + * Servlet:JAVADOC:668; Servlet:JAVADOC:669; Servlet:JAVADOC:670; + * Servlet:JAVADOC:674; Servlet:JAVADOC:675; Servlet:JAVADOC:676; + * Servlet:JAVADOC:677; Servlet:JAVADOC:681; Servlet:JAVADOC:694; + * + * @test_Strategy: Create a ServletContextListener, in which, 1. Create a + * ServletRegistration ServletContext.addServlet(String, Class) 2. Create + * another ServletRegistration ServletContext.addServlet(String, String), 3. + * Create the third ServletRegistration ServletContext.addServlet(String, + * Servlet), 4. Add the fourth Servlet ServletContext.createServlet(Class), 5. + * Create a FilterRegistration ServletContext.addFilter(String, Class) 6. + * Create another FilterRegistration ServletContext.addFilter(String, String), + * 7. Create the third FilterRegistration ServletContext.addFilter(String, + * Filter), 8. Create the fourth FilterRegistration + * ServletContext.CreateFilter(Class), 9. Store information returned in + * ServletContextAttribute by jakarta.servlet.Registration.getName() 10. client + * send a request to another servlet to get the information Verify in client + * that jakarta.servlet.Registration.getClassName() works + */ + @Test + public void getRegistrationClassNameTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getRegistrationClassNameTest"); + TEST_PROPS.setProperty(SEARCH_STRING, "REGISTRATION_CLASS_NAME:" + + "|COM.SUN.TS.TESTS.SERVLET.API.JAKARTA_SERVLET.SERVLETCONTEXT30.ADDSERVLETSTRING" + + "|COM.SUN.TS.TESTS.SERVLET.API.JAKARTA_SERVLET.SERVLETCONTEXT30.ADDFILTERSTRING" + + "|COM.SUN.TS.TESTS.SERVLET.API.JAKARTA_SERVLET.SERVLETCONTEXT30.ADDSERVLETCLASS" + + "|COM.SUN.TS.TESTS.SERVLET.API.JAKARTA_SERVLET.SERVLETCONTEXT30.ADDFILTERCLASS" + + "|COM.SUN.TS.TESTS.SERVLET.API.JAKARTA_SERVLET.SERVLETCONTEXT30.CREATESERVLET" + + "|COM.SUN.TS.TESTS.SERVLET.API.JAKARTA_SERVLET.SERVLETCONTEXT30.CREATEFILTER" + + "|COM.SUN.TS.TESTS.SERVLET.API.JAKARTA_SERVLET.SERVLETCONTEXT30.ADDSERVLETNOTFOUND" + + "|COM.SUN.TS.TESTS.SERVLET.API.JAKARTA_SERVLET.SERVLETCONTEXT30.ADDFILTERNOTFOUND"); + invoke(); + } + + /* + * @testName: getRegistrationInitParameterTest + * + * @assertion_ids: Servlet:JAVADOC:243; Servlet:JAVADOC:660; + * Servlet:JAVADOC:663; Servlet:JAVADOC:668; Servlet:JAVADOC:669; + * Servlet:JAVADOC:670; Servlet:JAVADOC:674; Servlet:JAVADOC:675; + * Servlet:JAVADOC:676; Servlet:JAVADOC:677; Servlet:JAVADOC:681; + * Servlet:JAVADOC:694; + * + * @test_Strategy: Create a ServletContextListener, in which, 1. Create a + * ServletRegistration ServletContext.addServlet(String, Class) 2. Create + * another ServletRegistration ServletContext.addServlet(String, String), 3. + * Create the third ServletRegistration ServletContext.addServlet(String, + * Servlet), 4. Create a FilterRegistration ServletContext.addFilter(String, + * Class) 5. Create another FilterRegistration + * ServletContext.addFilter(String, String), 6. Create the third + * FilterRegistration ServletContext.addFilter(String, Filter), 7. Call + * setInitParameter(String, String) on all above Registratyion Object; 8. + * Store information returned in ServletContextAttribute by + * jakarta.servlet.Registration.getInitParameter(String) 9. client send a + * request to another servlet to get the information Verify in client that + * jakarta.servlet.Registration.getInitParameter(String) works + */ + @Test + public void getRegistrationInitParameterTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getRegistrationInitParameterTest"); + TEST_PROPS.setProperty(SEARCH_STRING, + "REGISTRATION_INIT_PARAMETER:" + "|AddFilterString" + + "|AddServletString" + "|AddFilterClass" + "|AddServletClass" + + "|CreateFilter" + "|CreateServlet" + "|AddFilterNotFound" + + "|AddServletNotFound"); + invoke(); + } + + /* + * @testName: getRegistrationInitParametersTest + * + * @assertion_ids: Servlet:JAVADOC:243; Servlet:JAVADOC:661; + * Servlet:JAVADOC:664; Servlet:JAVADOC:668; Servlet:JAVADOC:669; + * Servlet:JAVADOC:670; Servlet:JAVADOC:674; Servlet:JAVADOC:675; + * Servlet:JAVADOC:676; Servlet:JAVADOC:677; Servlet:JAVADOC:681; + * Servlet:JAVADOC:694; + * + * @test_Strategy: Create a ServletContextListener, in which, 1. Create a + * ServletRegistration ServletContext.addServlet(String, Class) 2. Create + * another ServletRegistration ServletContext.addServlet(String, String), 3. + * Create the third ServletRegistration ServletContext.addServlet(String, + * Servlet), 4. Create a FilterRegistration ServletContext.addFilter(String, + * Class) 5. Create another FilterRegistration + * ServletContext.addFilter(String, String), 6. Create the third + * FilterRegistration ServletContext.addFilter(String, Filter), 7. Call + * setInitParameters(Map) on all above Registratyion Object; 8. Store + * information returned in ServletContextAttribute by + * jakarta.servlet.Registration.getInitParameters() 9. client send a request to + * another servlet to get the information Verify in client that + * jakarta.servlet.Registration.getInitParameters() works + */ + @Test + public void getRegistrationInitParametersTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getRegistrationInitParametersTest"); + TEST_PROPS.setProperty(SEARCH_STRING, + "REGISTRATION_INIT_PARAMETERS:" + + "|Filter=No|FilterName=AddFilterString|Servlet=Yes" + + "|DISPATCH=FORWARD|ServletName=AddServletString" + + "|Filter=Yes|FilterName=AddFilterString|Servlet=No" + + "|DISPATCH=FORWARD|ServletName=AddServletString" + + "|Filter=No|FilterName=AddFilterClass|Servlet=Yes" + + "|DISPATCH=REQUEST|ServletName=AddServletClass" + + "|Filter=Yes|FilterName=AddFilterClass|Servlet=No" + + "|DISPATCH=REQUEST|ServletName=AddServletClass" + + "|Filter=No|FilterName=CreateFilter|Servlet=Yes" + + "|DISPATCH=REQUEST|ServletName=CreateServlet" + + "|Filter=Yes|FilterName=CreateFilter|Servlet=No" + + "|DISPATCH=REQUEST|ServletName=CreateServlet" + + "|Filter=No|FilterName=AddFilterNotFound|Servlet=Yes" + + "|DISPATCH=ALL|ServletName=AddServletNotFound" + + "|Filter=Yes|FilterName=AddFilterNotFound|Servlet=No" + + "|DISPATCH=ALL|ServletName=AddServletNotFound"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/registration/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/registration/build.xml new file mode 100644 index 0000000000..ab8101b657 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/registration/build.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/registration/servlet_js_registration_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/registration/servlet_js_registration_web.xml new file mode 100644 index 0000000000..5fa030736c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/registration/servlet_js_registration_web.xml @@ -0,0 +1,36 @@ + + + + + SerJaxRegistration + + com.sun.ts.tests.servlet.api.jakarta_servlet.registration.TestListener + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.registration.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/requestdispatcher/ForwardedServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/requestdispatcher/ForwardedServlet.java new file mode 100644 index 0000000000..7177db6ab7 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/requestdispatcher/ForwardedServlet.java @@ -0,0 +1,80 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.requestdispatcher; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class ForwardedServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + pw.println("Content from ForwardedServlet"); + ServletTestUtil.printResult(pw, true); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/requestdispatcher/ForwardedServlet2.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/requestdispatcher/ForwardedServlet2.java new file mode 100644 index 0000000000..95205771ad --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/requestdispatcher/ForwardedServlet2.java @@ -0,0 +1,36 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.requestdispatcher; + +import java.io.IOException; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class ForwardedServlet2 extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + throw new ServletException("Content from ForwardedServlet2"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/requestdispatcher/ForwardedServlet3.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/requestdispatcher/ForwardedServlet3.java new file mode 100644 index 0000000000..e1e94ae42d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/requestdispatcher/ForwardedServlet3.java @@ -0,0 +1,36 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.requestdispatcher; + +import java.io.IOException; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class ForwardedServlet3 extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + throw new IOException("Content from ForwardedServlet3"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/requestdispatcher/IncludedServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/requestdispatcher/IncludedServlet.java new file mode 100644 index 0000000000..21c0d8669c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/requestdispatcher/IncludedServlet.java @@ -0,0 +1,83 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.requestdispatcher; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class IncludedServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + response.setContentType("text/html"); + pw.write("Content of IncludedServlet\n"); + ServletTestUtil.printResult(pw, true); + pw.flush(); + pw.close(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/requestdispatcher/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/requestdispatcher/TestServlet.java new file mode 100644 index 0000000000..596f4ba15b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/requestdispatcher/TestServlet.java @@ -0,0 +1,144 @@ +/* + * 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.requestdispatcher; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + /** + * Test for forward(ServletRequest,ServletResponse) method + */ + public void forwardTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + String path = "/ForwardedServlet"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + rd.forward(request, response); + } + + public void forward_1Test(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + boolean passed = false; + PrintWriter pw = response.getWriter(); + + // response is committed here + pw.println("Committing some content to buffer"); + pw.flush(); + String path = "/ForwardedServlet"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + + try { + rd.forward(request, response); + passed = false; + pw.println("IllegalStateException should have been generated"); + } catch (Throwable t) { + if (t instanceof IllegalStateException) { + passed = true; + } else { + passed = false; + pw.println( + "Exception thrown, but was not an instance of IllegalStateException."); + pw.println("instead received: " + t.getClass().getName()); + } + } + ServletTestUtil.printResult(pw, passed); + } + + /** + * A Test for Include(ServletRequest,ServletResponse) method + */ + public void includeTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + String path = "/ForwardedServlet"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + rd.include(request, response); + } + + /** + * The included servlet is not supposed to change the Response Headers. Our + * included servlet changes it we will check whether that changed header value + * gets reflected in the client side or not + */ + public void include_1Test(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + response.setContentType("text/sgml"); + String path = "/IncludedServlet"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + rd.include(request, response); + } + + public void include_2Test(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + boolean passed = false; + PrintWriter pw = response.getWriter(); + + String path = "/ForwardedServlet2"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + + try { + rd.include(request, response); + passed = false; + pw.println("ServletException should have been generated"); + } catch (Throwable t) { + if (t instanceof ServletException) { + passed = true; + } else { + passed = false; + pw.println( + "Exception thrown, but was not an instance of ServletException."); + pw.println("instead received: " + t.getClass().getName()); + } + } + ServletTestUtil.printResult(pw, passed); + } + + public void include_3Test(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + boolean passed = false; + PrintWriter pw = response.getWriter(); + + String path = "/ForwardedServlet3"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + + try { + rd.include(request, response); + passed = false; + pw.println("IOException should have been generated"); + } catch (Throwable t) { + if (t instanceof IOException) { + passed = true; + } else { + passed = false; + pw.println("Exception thrown, but was not an instance of IOException."); + pw.println("instead received: " + t.getClass().getName()); + } + } + ServletTestUtil.printResult(pw, passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/requestdispatcher/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/requestdispatcher/URLClient.java new file mode 100644 index 0000000000..8444adc52a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/requestdispatcher/URLClient.java @@ -0,0 +1,153 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.requestdispatcher; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_requestdispatcher_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(ForwardedServlet.class, ForwardedServlet2.class, ForwardedServlet3.class, + IncludedServlet.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_js_requestdispatcher_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + + /* + * @testName: forwardTest + * + * @assertion_ids: Servlet:SPEC:80; Servlet:JAVADOC:230; Servlet:JAVADOC:272; + * Servlet:JAVADOC:274; + * + * @test_Strategy: Create a servlet, get its RequestDispatcher and use it to + * forward to a servlet + */ + @Test + public void forwardTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "forwardTest"); + invoke(); + } + + /* + * @testName: forward_1Test + * + * @assertion_ids: Servlet:SPEC:77; Servlet:SPEC:80; Servlet:JAVADOC:230; + * Servlet:JAVADOC:277; + * + * @test_Strategy: A negative test for RequestDispatcher.forward() method. + * Create a servlet, print a string to the buffer, flush the buffer to commit + * the string, get its RequestDispatcher and use it to forward to a servlet. + */ + @Test + public void forward_1Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "forward_1Test"); + invoke(); + } + + /* + * @testName: includeTest + * + * @assertion_ids: Servlet:JAVADOC:230; Servlet:JAVADOC:278; + * + * @test_Strategy: Create a servlet, get its RequestDispatcher and use it to + * include a servlet + */ + @Test + public void includeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "includeTest"); + invoke(); + } + + /* + * @testName: include_1Test + * + * @assertion_ids: Servlet:JAVADOC:230; Servlet:JAVADOC:278; + * + * @test_Strategy: A negative test for RequestDispatcher.include() test. + * Create a servlet, set its Content-Type to be 'text/html', get its + * RequestDispatcher and use it to include a servlet. The included servlet + * tries to change the Content-Type to be text/html. Test at the client side + * for correct Content-Type. + */ + @Test + public void include_1Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "include_1Test"); + TEST_PROPS.setProperty(EXPECTED_HEADERS, "Content-Type: text/sgml"); + invoke(); + } + + /* + * @testName: include_2Test + * + * @assertion_ids: Servlet:SPEC:82; Servlet:SPEC:80; Servlet:JAVADOC:230; + * Servlet:JAVADOC:279; + * + * @test_Strategy: A negative test for RequestDispatcher.include() method. + * Create a servlet with service() method throws ServletException. Use + * RequestDispatcher to include to this servlet. Verify that include() method + * throws ServletException. + */ + @Test + public void include_2Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "include_2Test"); + invoke(); + } + + /* + * @testName: include_3Test + * + * @assertion_ids: Servlet:SPEC:82; Servlet:SPEC:80; Servlet:JAVADOC:230; + * Servlet:JAVADOC:280; + * + * @test_Strategy: A negative test for RequestDispatcher.include() method. + * Create a servlet with service() method throws IOException. Use + * RequestDispatcher to include to this servlet. Verify that include() method + * throws IOException. + */ + @Test + public void include_3Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "include_3Test"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/requestdispatcher/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/requestdispatcher/build.xml new file mode 100644 index 0000000000..88ecd7a54b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/requestdispatcher/build.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/requestdispatcher/servlet_js_requestdispatcher_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/requestdispatcher/servlet_js_requestdispatcher_web.xml new file mode 100644 index 0000000000..76dfc0502a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/requestdispatcher/servlet_js_requestdispatcher_web.xml @@ -0,0 +1,65 @@ + + + + + SerJaxSerRequestDispatcher + + IncludedServletLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.requestdispatcher.IncludedServlet + + + ForwardedServlet2LogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.requestdispatcher.ForwardedServlet2 + + + ForwardedServlet3LogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.requestdispatcher.ForwardedServlet3 + + + ForwardedServletLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.requestdispatcher.ForwardedServlet + + + TestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.requestdispatcher.TestServlet + + + TestLogicalName + /TestServlet + + + IncludedServletLogicalName + /IncludedServlet + + + ForwardedServletLogicalName + /ForwardedServlet + + + ForwardedServlet2LogicalName + /ForwardedServlet2 + + + ForwardedServlet3LogicalName + /ForwardedServlet3 + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributeevent/SCAttributeEventListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributeevent/SCAttributeEventListener.java new file mode 100644 index 0000000000..41e7434034 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributeevent/SCAttributeEventListener.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2009, 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.scattributeevent; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.ServletContextAttributeEvent; +import jakarta.servlet.ServletContextAttributeListener; + +public final class SCAttributeEventListener + implements ServletContextAttributeListener { + + // Public Methods + + public void attributeAdded(ServletContextAttributeEvent event) { + StaticLog.add("AttributeAdded:" + event.getName() + "," + event.getValue()); + } + + public void attributeRemoved(ServletContextAttributeEvent event) { + StaticLog + .add("AttributeRemoved:" + event.getName() + "," + event.getValue()); + } + + public void attributeReplaced(ServletContextAttributeEvent event) { + StaticLog + .add("AttributeReplaced:" + event.getName() + "," + event.getValue()); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributeevent/SCAttributeListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributeevent/SCAttributeListener.java new file mode 100644 index 0000000000..73004b2fa0 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributeevent/SCAttributeListener.java @@ -0,0 +1,118 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.scattributeevent; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextAttributeEvent; +import jakarta.servlet.ServletContextAttributeListener; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; + +public final class SCAttributeListener + implements ServletContextAttributeListener, ServletContextListener { + + static ServletContext savedSC = null; + + // Public Methods + + public void contextInitialized(ServletContextEvent event) { + savedSC = event.getServletContext(); + } + + public void contextDestroyed(ServletContextEvent event) { + } + + public void attributeAdded(ServletContextAttributeEvent event) { + StaticLog.add("AttributeAdded:" + event.getName() + "," + event.getValue()); + ServletContext sc = event.getServletContext(); + if (savedSC != sc) { + StaticLog.add(getErrorMessageForInvalidContext(savedSC, sc)); + } + } + + public void attributeRemoved(ServletContextAttributeEvent event) { + StaticLog + .add("AttributeRemoved:" + event.getName() + "," + event.getValue()); + ServletContext sc = event.getServletContext(); + if (savedSC != sc) { + StaticLog.add(getErrorMessageForInvalidContext(savedSC, sc)); + } + } + + public void attributeReplaced(ServletContextAttributeEvent event) { + StaticLog + .add("AttributeReplaced:" + event.getName() + "," + event.getValue()); + ServletContext sc = event.getServletContext(); + if (savedSC != sc) { + StaticLog.add(getErrorMessageForInvalidContext(savedSC, sc)); + } + } + + private String getErrorMessageForInvalidContext(ServletContext initCtx, + ServletContext eventCtx) { + StringBuffer sb = new StringBuffer(128); + sb.append( + "The ServletContext of the event is not the same ServletContext provided to the listener at initialization.\n"); + sb.append("Initialized context: " + initCtx + "\n"); + sb.append("Event.getServletContext returned context: " + eventCtx + "\n"); + return sb.toString(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributeevent/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributeevent/TestServlet.java new file mode 100644 index 0000000000..e92f6cda9c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributeevent/TestServlet.java @@ -0,0 +1,169 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.scattributeevent; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextAttributeEvent; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void constructorTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + ServletContextAttributeEvent scae = new ServletContextAttributeEvent( + getServletContext(), "test", "value"); + if (scae == null) { + passed = false; + pw.println("The constructor for ServletContextEvent returned a null"); + } else { + passed = true; + } + StaticLog.clear(); + ServletTestUtil.printResult(pw, passed); + } + + public void addedTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + + StaticLog.clear(); + + String[] expected = { "AttributeAdded:addTest,Attribute1" }; + + // the test + ServletContext context = getServletContext(); + context.setAttribute("addTest", "Attribute1"); + + // verify results + ArrayList result = StaticLog.getClear(); + boolean passed = ServletTestUtil.checkArrayList(result, expected, true, + false); + if (!passed) { + ServletTestUtil.printFailureData(pw, result, expected); + } + context.removeAttribute("addTest"); + ServletTestUtil.printResult(pw, passed); + + } + + public void removedTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + StaticLog.clear(); + + String[] expected = { "AttributeAdded:removeTest,Attribute1", + "AttributeRemoved:removeTest,Attribute1" }; + + // the test + ServletContext context = getServletContext(); + context.setAttribute("removeTest", "Attribute1"); + context.removeAttribute("removeTest"); + + // verify results + ArrayList result = StaticLog.getClear(); + boolean passed = ServletTestUtil.checkArrayList(result, expected, true, + false); + if (!passed) { + ServletTestUtil.printFailureData(pw, result, expected); + } + ServletTestUtil.printResult(pw, passed); + + } + + public void replacedTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + StaticLog.clear(); + + String[] expected = { "AttributeAdded:replacedTest,Attribute1", + "AttributeReplaced:replacedTest,Attribute1" }; + + // the test + ServletContext context = getServletContext(); + context.setAttribute("replacedTest", "Attribute1"); + context.setAttribute("replacedTest", "Attribute2"); + + // verify results + ArrayList result = StaticLog.getClear(); + boolean passed = ServletTestUtil.checkArrayList(result, expected, true, + false); + if (!passed) { + ServletTestUtil.printFailureData(pw, result, expected); + } + context.removeAttribute("replacedTest"); + ServletTestUtil.printResult(pw, passed); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributeevent/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributeevent/URLClient.java new file mode 100644 index 0000000000..ff87d26778 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributeevent/URLClient.java @@ -0,0 +1,120 @@ +/* + * 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 com.sun.ts.tests.servlet.api.jakarta_servlet.scattributeevent; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_scattributeevent_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(SCAttributeEventListener.class, SCAttributeListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_js_scattributeevent_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: constructorTest + * + * @assertion_ids: Servlet:JAVADOC:112 + * + * @test_Strategy: Servlet instanciate the constructor + */ + @Test + public void constructorTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "constructorTest"); + invoke(); + } + + /* + * @testName: addedTest + * + * @assertion_ids: Servlet:JAVADOC:113;Servlet:JAVADOC:114;Servlet:JAVADOC:117 + * + * @test_Strategy: Servlet adds an attribute. The listener should detect the + * add and write a message out to a static log. Servlet then reads the log and + * verifys the result. It also verifies the request and context that changed + * + */ + @Test + public void addedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "addedTest"); + invoke(); + } + + /* + * @testName: removedTest + * + * @assertion_ids: Servlet:JAVADOC:113;Servlet:JAVADOC:115;Servlet:JAVADOC:117 + * + * @test_Strategy: Servlet adds/removes an attribute. The listener should + * detect the add and write a message out to a static log. Servlet then reads + * the log and verifys the result. It also verifies the request and context + * that changed + */ + @Test + public void removedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "removedTest"); + invoke(); + } + + /* + * @testName: replacedTest + * + * @assertion_ids: Servlet:JAVADOC:113;Servlet:JAVADOC:116;Servlet:JAVADOC:117 + * + * @test_Strategy: Servlet adds/replaces an attribute. The listener should + * detect the add and write a message out to a static log. Servlet then reads + * the log and verifys the result. It also verifies the request and context + * that changed + */ + @Test + public void replacedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "replacedTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributeevent/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributeevent/build.xml new file mode 100644 index 0000000000..c54112b4b6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributeevent/build.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributeevent/servlet_js_scattributeevent_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributeevent/servlet_js_scattributeevent_web.xml new file mode 100644 index 0000000000..3a139e7a94 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributeevent/servlet_js_scattributeevent_web.xml @@ -0,0 +1,36 @@ + + + + + ServletContextAttributeEvent + + com.sun.ts.tests.servlet.api.jakarta_servlet.scattributeevent.SCAttributeListener + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.scattributeevent.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributelistener/SCAttributeListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributelistener/SCAttributeListener.java new file mode 100644 index 0000000000..cf4a7b4288 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributelistener/SCAttributeListener.java @@ -0,0 +1,83 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 1999, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.scattributelistener; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.ServletContextAttributeEvent; +import jakarta.servlet.ServletContextAttributeListener; + +public final class SCAttributeListener + implements ServletContextAttributeListener { + + // Public Methods + public void attributeAdded(ServletContextAttributeEvent event) { + StaticLog.add("AttributeAdded:" + event.getName() + "," + event.getValue()); + } + + public void attributeRemoved(ServletContextAttributeEvent event) { + StaticLog + .add("AttributeRemoved:" + event.getName() + "," + event.getValue()); + } + + public void attributeReplaced(ServletContextAttributeEvent event) { + StaticLog + .add("AttributeReplaced:" + event.getName() + "," + event.getValue()); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributelistener/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributelistener/TestServlet.java new file mode 100644 index 0000000000..5de0925721 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributelistener/TestServlet.java @@ -0,0 +1,170 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.scattributelistener; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void addedTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + + // cleanup context just to be sure + context.removeAttribute("addedTest"); + context.removeAttribute("removedTest"); + context.removeAttribute("replacedTest"); + StaticLog.clear(); + + String[] expected = { "AttributeAdded:addedTest,Attribute1" }; + + // the test + context.setAttribute("addedTest", "Attribute1"); + + // verify results + ArrayList result = StaticLog.getClear(); + boolean b = ServletTestUtil.checkArrayList(result, expected, true, false); + if (!b) { + ServletTestUtil.printFailureData(pw, result, expected); + } + ServletTestUtil.printResult(pw, b); + + // cleanup context + context.removeAttribute("addedTest"); + + } + + public void removedTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + + // cleanup context just to be sure + context.removeAttribute("addedTest"); + context.removeAttribute("removedTest"); + context.removeAttribute("replacedTest"); + StaticLog.clear(); + String[] expected = { "AttributeAdded:removedTest,Attribute1", + "AttributeRemoved:removedTest,Attribute1" }; + + // the test + context.setAttribute("removedTest", "Attribute1"); + context.removeAttribute("removedTest"); + + // verify results + ArrayList result = StaticLog.getClear(); + boolean b = ServletTestUtil.checkArrayList(result, expected, true, false); + if (!b) { + ServletTestUtil.printFailureData(pw, result, expected); + } + ServletTestUtil.printResult(pw, b); + + } + + public void replacedTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + + // cleanup context just to be sure + context.removeAttribute("addedTest"); + context.removeAttribute("removedTest"); + context.removeAttribute("replacedTest"); + StaticLog.clear(); + + String[] expected = { "AttributeAdded:replacedTest,Attribute1", + "AttributeReplaced:replacedTest,Attribute1" }; + + // the test + context.setAttribute("replacedTest", "Attribute1"); + context.setAttribute("replacedTest", "Attribute2"); + + // verify results + ArrayList result = StaticLog.getClear(); + boolean b = ServletTestUtil.checkArrayList(result, expected, true, false); + if (!b) { + ServletTestUtil.printFailureData(pw, result, expected); + } + ServletTestUtil.printResult(pw, b); + + // cleanup context + context.removeAttribute("replacedTest"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributelistener/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributelistener/URLClient.java new file mode 100644 index 0000000000..5fca1650a0 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributelistener/URLClient.java @@ -0,0 +1,101 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.scattributelistener; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_scattributelistener_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(SCAttributeListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_js_scattributelistener_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: addedTest + * + * @assertion_ids: Servlet:JAVADOC:216; Servlet:JAVADOC:252; + * + * @test_Strategy: Servlet adds an attribute. The listener should detect the + * add and write a message out to a static log. Servlet then reads the log and + * verifies the result. + * + */ + @Test + public void addedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "addedTest"); + invoke(); + } + + /* + * @testName: removedTest + * + * @assertion_ids: Servlet:JAVADOC:217; Servlet:JAVADOC:255; + * + * @test_Strategy: Servlet adds/removes an attribute. The listener should + * detect the two actions and write a message out to a static log. Servlet + * then reads the log and verifies the result. + */ + @Test + public void removedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "removedTest"); + invoke(); + } + + /* + * @testName: replacedTest + * + * @assertion_ids: Servlet:JAVADOC:218 + * + * @test_Strategy: Servlet adds/replaces an attribute. The listener should + * detect the two actions and write a message to a static log. Servlet then + * reads the log and verifies the result. + */ + @Test + public void replacedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "replacedTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributelistener/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributelistener/build.xml new file mode 100644 index 0000000000..517bb5cafa --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributelistener/build.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributelistener/servlet_js_scattributelistener_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributelistener/servlet_js_scattributelistener_web.xml new file mode 100644 index 0000000000..78d84913a1 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributelistener/servlet_js_scattributelistener_web.xml @@ -0,0 +1,36 @@ + + + + + SerJaxSerSerContextAttrListen + + com.sun.ts.tests.servlet.api.jakarta_servlet.scattributelistener.SCAttributeListener + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.scattributelistener.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributelistener40/SCAttributeListener40.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributelistener40/SCAttributeListener40.java new file mode 100644 index 0000000000..9ec3673f36 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributelistener40/SCAttributeListener40.java @@ -0,0 +1,65 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2017, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.scattributelistener40; + +import jakarta.servlet.ServletContextAttributeListener; + +public final class SCAttributeListener40 + implements ServletContextAttributeListener { +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributelistener40/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributelistener40/TestServlet.java new file mode 100644 index 0000000000..522fb13f59 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributelistener40/TestServlet.java @@ -0,0 +1,80 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.scattributelistener40; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void defaultMethodsTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + pw.println("In ServletContextAttributeListener40.TestServlet"); + ServletTestUtil.printResult(pw, true); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributelistener40/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributelistener40/URLClient.java new file mode 100644 index 0000000000..a3ff73116f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributelistener40/URLClient.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2017, 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: URLClient.java 62571 2011-04-18 20:58:13Z kgrucci $ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.scattributelistener40; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_scattributelistener40_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(SCAttributeListener40.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_js_scattributelistener40_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: defaultMethodsTest + * + * @assertion_ids: NA; + * + * @test_Strategy: Client successfully calls a servlet with an empty + * ServletContextAttribute listener implementation class. + * + */ + @Test + public void defaultMethodsTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "defaultMethodsTest"); + invoke(); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributelistener40/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributelistener40/build.xml new file mode 100644 index 0000000000..6dc21c959e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributelistener40/build.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributelistener40/servlet_js_scattributelistener40_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributelistener40/servlet_js_scattributelistener40_web.xml new file mode 100644 index 0000000000..5c37ea8e66 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scattributelistener40/servlet_js_scattributelistener40_web.xml @@ -0,0 +1,36 @@ + + + + + SerJaxSerSerContextAttrListen40 + + com.sun.ts.tests.servlet.api.jakarta_servlet.scattributelistener40.SCAttributeListener40 + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.scattributelistener40.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scevent/SContextEventListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scevent/SContextEventListener.java new file mode 100644 index 0000000000..0dddada868 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scevent/SContextEventListener.java @@ -0,0 +1,90 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 1999, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.scevent; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; + +public final class SContextEventListener implements ServletContextListener { + + // The servlet context with which we are associated. + private ServletContext context = null; + + // Public Methods + public void contextDestroyed(ServletContextEvent event) { + this.context = null; + StaticLog.clear(); + } + + public void contextInitialized(ServletContextEvent event) { + this.context = event.getServletContext(); + StaticLog.clear(); + + if (event.getServletContext() instanceof ServletContext) { + StaticLog.add( + "ServletContextEvent.getServletContext() returned instanceof ServletContext"); + } else { + StaticLog.add( + "ServletContextEvent.getServletContext() did not return an instanceof ServletContext"); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scevent/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scevent/TestServlet.java new file mode 100644 index 0000000000..6bb2697e42 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scevent/TestServlet.java @@ -0,0 +1,107 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.scevent; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void constructorTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + ServletContextEvent sce = new ServletContextEvent( + this.getServletConfig().getServletContext()); + if (sce != null) { + ServletTestUtil.printResult(pw, true); + } else { + ServletTestUtil.printResult(pw, false); + } + + } + + public void getServletContextTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + + String[] expected = { + "ServletContextEvent.getServletContext() returned instanceof ServletContext" }; + + // verify results + ArrayList result = StaticLog.getClear(); + boolean b = ServletTestUtil.checkArrayList(result, expected, true, false); + if (!b) { + ServletTestUtil.printFailureData(pw, result, expected); + } + ServletTestUtil.printResult(pw, b); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scevent/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scevent/URLClient.java new file mode 100644 index 0000000000..973f5805d9 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scevent/URLClient.java @@ -0,0 +1,85 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.scevent; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_scevent_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(SContextEventListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_js_scevent_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: constructorTest + * + * @assertion_ids: Servlet:JAVADOC:110 + * + * @test_Strategy: Servlet tries to get an instance of ServletContextEvent. + */ + @Test + public void constructorTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "constructorTest"); + invoke(); + } + + /* + * @testName: getServletContextTest + * + * @assertion_ids: Servlet:JAVADOC:111 + * + * @test_Strategy: Deploy a servlet context event listener. When the context + * gets initialized, write a status message to a static log. Servlet reads the + * static log looking for a specific message and verifies it exists + */ + @Test + public void getServletContextTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletContextTest"); + invoke(); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scevent/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scevent/build.xml new file mode 100644 index 0000000000..312936042e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scevent/build.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scevent/servlet_js_scevent_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scevent/servlet_js_scevent_web.xml new file mode 100644 index 0000000000..46522ba17a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scevent/servlet_js_scevent_web.xml @@ -0,0 +1,36 @@ + + + + + SerJaxSerSerContextEvent + + com.sun.ts.tests.servlet.api.jakarta_servlet.scevent.SContextEventListener + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.scevent.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter/AddFilterString.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter/AddFilterString.java new file mode 100644 index 0000000000..7218153f72 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter/AddFilterString.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addfilter; + +import java.io.IOException; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class AddFilterString implements Filter { + + // The filter configuration object we are associated with. If this value + // is null, this filter instance is not currently configured. + private FilterConfig filterConfig = null; + + private static final Logger LOGGER = LoggerFactory.getLogger(AddFilterString.class); + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + if (filterConfig == null) { + LOGGER.info( + "doFilter of AddFilterString was called but this filter instance is not currently configured"); + } else { + LOGGER.info("ADD_FILTER_STRING_INVOKED"); + } + + chain.doFilter(request, response); + } + + // Remove the filter configuration object for this filter. + public void destroy() { + } + + // initialize the filter configuration object for this filter. + public void init(FilterConfig filterConfig) { + this.filterConfig = filterConfig; + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter/TCKServletContainerInitializer.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter/TCKServletContainerInitializer.java new file mode 100644 index 0000000000..62664eb3b5 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter/TCKServletContainerInitializer.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addfilter; + +import java.util.Set; + +import jakarta.servlet.ServletContainerInitializer; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; + +public class TCKServletContainerInitializer + implements ServletContainerInitializer { + + public void onStartup(Set> arg0, ServletContext context) + throws ServletException { + context.addListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addfilter.TestListener.class); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter/TestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter/TestListener.java new file mode 100644 index 0000000000..40ceea5267 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter/TestListener.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addfilter; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; + +public class TestListener implements ServletContextListener { + + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce + * The ServletContextEvent + */ + public void contextInitialized(ServletContextEvent sce) { + boolean passed = true; + ServletContext context = sce.getServletContext(); + StringBuilder log = new StringBuilder(); + + final String addFilterName1 = "AddFilterString"; + + try { + context.addFilter(addFilterName1, + "com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addfilter.AddFilterString"); + passed = false; + log.append("Expected UnsupportedOperationException not thrown."); + } catch (UnsupportedOperationException ex) { + log.append("Expected UnsupportedOperationException thrown."); + } + + context.setAttribute("TCK_TEST_STATUS", log.toString()); + context.setAttribute("TCK_TEST_PASS_STATUS", passed); + } + + /** + * Receives notification that the servlet context is about to be shut down. + * + * @param sce + * The servlet context event + */ + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter/TestServlet.java new file mode 100644 index 0000000000..b28d117e9b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter/TestServlet.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addfilter; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void addFilterTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + boolean passed = true; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + passed = (Boolean) context.getAttribute("TCK_TEST_PASS_STATUS"); + ServletTestUtil.printResult( + pw.append((String) context.getAttribute("TCK_TEST_STATUS")), passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter/URLClient.java new file mode 100644 index 0000000000..244c8cc617 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter/URLClient.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addfilter; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_sci_addfilter_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addAsResource(URLClient.class.getResource("jakarta.servlet.ServletContainerInitializer"), + "META-INF/services/jakarta.servlet.ServletContainerInitializer") + .addClasses(AddFilterString.class, TCKServletContainerInitializer.class, TestListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_sci_addfilter_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: addFilterTest + * + * @assertion_ids: Servlet:JAVADOC:668.6; + * + * @test_Strategy: Create a ServletContextInitializer, in which, Add a + * ServletContextListener instance using ServletContext.addListener; in the + * ServletContextListener call ServletContext.addFilter(String, String) Verify + * that UnsupportedOperationException is thrown. + */ + @Test + public void addFilterTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "addFilterTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter/build.xml new file mode 100644 index 0000000000..3e96e2bf84 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter/build.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter/jakarta.servlet.ServletContainerInitializer b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter/jakarta.servlet.ServletContainerInitializer new file mode 100644 index 0000000000..3be0918afc --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter/jakarta.servlet.ServletContainerInitializer @@ -0,0 +1,2 @@ + +com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addfilter.TCKServletContainerInitializer diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter/servlet_sci_addfilter_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter/servlet_sci_addfilter_web.xml new file mode 100644 index 0000000000..f2cb616160 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter/servlet_sci_addfilter_web.xml @@ -0,0 +1,33 @@ + + + + + SerSCIADDFILTER + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addfilter.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter1/AddFilterClass.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter1/AddFilterClass.java new file mode 100644 index 0000000000..6af0ae3d0f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter1/AddFilterClass.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addfilter1; + +import java.io.IOException; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class AddFilterClass implements Filter { + + private static final Logger LOGGER = LoggerFactory.getLogger(AddFilterClass.class); + + // The filter configuration object we are associated with. If this value + // is null, this filter instance is not currently configured. + private FilterConfig filterConfig = null; + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + if (filterConfig == null) { + LOGGER.info( + "doFilter of AddFilterClass was called but this filter instance is not currently configured"); + } else { + LOGGER.info("ADD_FILTER_CLASS_INVOKED"); + } + + chain.doFilter(request, response); + } + + // Remove the filter configuration object for this filter. + public void destroy() { + } + + // initialize the filter configuration object for this filter. + public void init(FilterConfig filterConfig) { + this.filterConfig = filterConfig; + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter1/TCKServletContainerInitializer.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter1/TCKServletContainerInitializer.java new file mode 100644 index 0000000000..46af5b8863 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter1/TCKServletContainerInitializer.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addfilter1; + +import java.util.Set; + +import jakarta.servlet.ServletContainerInitializer; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; + +public class TCKServletContainerInitializer + implements ServletContainerInitializer { + + public void onStartup(Set> arg0, ServletContext context) + throws ServletException { + context.addListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addfilter1.TestListener.class); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter1/TestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter1/TestListener.java new file mode 100644 index 0000000000..284a977810 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter1/TestListener.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2013, 2021 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addfilter1; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; + +public class TestListener implements ServletContextListener { + + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce + * The ServletContextEvent + */ + public void contextInitialized(ServletContextEvent sce) { + boolean passed = true; + ServletContext context = sce.getServletContext(); + StringBuilder log = new StringBuilder(); + + final String addFilterName2 = "AddFilterClass"; + + try { + context.addFilter(addFilterName2, AddFilterClass.class); + passed = false; + log.append("Expected UnsupportedOperationException not thrown."); + } catch (UnsupportedOperationException ex) { + log.append("Expected UnsupportedOperationException thrown."); + } + + context.setAttribute("TCK_TEST_STATUS", log.toString()); + context.setAttribute("TCK_TEST_PASS_STATUS", passed); + } + + /** + * Receives notification that the servlet context is about to be shut down. + * + * @param sce + * The servlet context event + */ + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter1/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter1/TestServlet.java new file mode 100644 index 0000000000..1b01a79f3b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter1/TestServlet.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addfilter1; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void addFilterTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + boolean passed = true; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + passed = (Boolean) context.getAttribute("TCK_TEST_PASS_STATUS"); + ServletTestUtil.printResult( + pw.append((String) context.getAttribute("TCK_TEST_STATUS")), passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter1/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter1/URLClient.java new file mode 100644 index 0000000000..3400e60b9f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter1/URLClient.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addfilter1; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_sci_addfilter1_web.war") + .addAsResource(URLClient.class.getResource("jakarta.servlet.ServletContainerInitializer"), + "META-INF/services/jakarta.servlet.ServletContainerInitializer") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(AddFilterClass.class, TCKServletContainerInitializer.class, + TestListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_sci_addfilter1_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: addFilterTest + * + * @assertion_ids: Servlet:JAVADOC:670.6; + * + * @test_Strategy: Create a ServletContextInitializer, in which, Add a + * ServletContextListener instance using ServletContext.addListener; in the + * ServletContextListener call ServletContext.addFilter(String, Class) Verify + * that UnsupportedOperationException is thrown. + */ + @Test + public void addFilterTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "addFilterTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter1/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter1/build.xml new file mode 100644 index 0000000000..fbdb197de2 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter1/build.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter1/jakarta.servlet.ServletContainerInitializer b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter1/jakarta.servlet.ServletContainerInitializer new file mode 100644 index 0000000000..73b9707368 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter1/jakarta.servlet.ServletContainerInitializer @@ -0,0 +1 @@ +com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addfilter1.TCKServletContainerInitializer diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter1/servlet_sci_addfilter1_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter1/servlet_sci_addfilter1_web.xml new file mode 100644 index 0000000000..d2df30fda7 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addfilter1/servlet_sci_addfilter1_web.xml @@ -0,0 +1,33 @@ + + + + + SerSCIADDFILTER1 + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addfilter1.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener/SCAttributeListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener/SCAttributeListener.java new file mode 100644 index 0000000000..f3d9c26278 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener/SCAttributeListener.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2013, 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addlistener; + +import jakarta.servlet.ServletContextAttributeEvent; +import jakarta.servlet.ServletContextAttributeListener; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class SCAttributeListener + implements ServletContextAttributeListener { + + private static final Logger LOGGER = LoggerFactory.getLogger(SCAttributeListener.class); + + // Public Methods + + public void attributeAdded(ServletContextAttributeEvent event) { + LOGGER.info("SCAttributeAdded:" + event.getName() + "," + event.getValue()); + } + + public void attributeRemoved(ServletContextAttributeEvent event) { + LOGGER.info( + "SCAttributeRemoved:" + event.getName() + "," + event.getValue()); + } + + public void attributeReplaced(ServletContextAttributeEvent event) { + LOGGER.info( + "SCAttributeReplaced:" + event.getName() + "," + event.getValue()); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener/SCListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener/SCListener.java new file mode 100644 index 0000000000..f295234e26 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener/SCListener.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addlistener; + +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; + +public class SCListener implements ServletContextListener { + + public void contextDestroyed(ServletContextEvent event) { + System.out.print("SCListener Destroyed."); + } + + public void contextInitialized(ServletContextEvent event) { + System.out.print("SCListener Initialized."); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener/SRAttributeListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener/SRAttributeListener.java new file mode 100644 index 0000000000..3c6af4f196 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener/SRAttributeListener.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2013, 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addlistener; + +import jakarta.servlet.ServletRequestAttributeEvent; +import jakarta.servlet.ServletRequestAttributeListener; + +public final class SRAttributeListener + implements ServletRequestAttributeListener { + + public void attributeAdded(ServletRequestAttributeEvent event) { + System.out + .print("SRAttributeAdded:" + event.getName() + "," + event.getValue()); + + } + + public void attributeRemoved(ServletRequestAttributeEvent event) { + System.out.print( + "SRAttributeRemoved:" + event.getName() + "," + event.getValue()); + } + + public void attributeReplaced(ServletRequestAttributeEvent event) { + System.out.print( + "SRAttributeReplaced:" + event.getName() + "," + event.getValue()); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener/SRListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener/SRListener.java new file mode 100644 index 0000000000..07976282eb --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener/SRListener.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addlistener; + +import jakarta.servlet.ServletRequestEvent; +import jakarta.servlet.ServletRequestListener; + +public final class SRListener implements ServletRequestListener { + + // Public Methods + public void requestDestroyed(ServletRequestEvent event) { + System.out.print("in requestDestroyed method of CreateSRListener"); + } + + public void requestInitialized(ServletRequestEvent event) { + System.out.print("CreateSRListener_INVOKED"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener/TCKServletContainerInitializer.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener/TCKServletContainerInitializer.java new file mode 100644 index 0000000000..21af780461 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener/TCKServletContainerInitializer.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addlistener; + +import java.util.Set; + +import jakarta.servlet.ServletContainerInitializer; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; + +public class TCKServletContainerInitializer + implements ServletContainerInitializer { + + public void onStartup(Set> arg0, ServletContext context) + throws ServletException { + context.addListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addlistener.TestListener.class); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener/TestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener/TestListener.java new file mode 100644 index 0000000000..1d310e2149 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener/TestListener.java @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2013, 2021 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addlistener; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; + +public class TestListener implements ServletContextListener { + + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce + * The ServletContextEvent + */ + public void contextInitialized(ServletContextEvent sce) { + boolean passed = true; + ServletContext context = sce.getServletContext(); + StringBuilder log = new StringBuilder(); + + try { + context.addListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addlistener.SCListener.class); + passed = false; + log.append( + "Expected UnsupportedOperationException not thrown by addListener(SCListener.class)."); + } catch (UnsupportedOperationException ex) { + log.append( + "Expected UnsupportedOperationException thrown by addListener(SCListener.class)."); + } + + try { + context.addListener( + SCAttributeListener.class); + passed = false; + log.append( + "Expected UnsupportedOperationException not thrown by addListener(SCAttributeListener.class)."); + } catch (UnsupportedOperationException ex) { + log.append( + "Expected UnsupportedOperationException thrown by addListener(SCAttributeListener.class)."); + } + + try { + context.addListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addlistener.SRListener.class); + passed = false; + log.append( + "Expected UnsupportedOperationException not thrown by addListener(SRListener.class)."); + } catch (UnsupportedOperationException ex) { + log.append( + "Expected UnsupportedOperationException thrown by addListener(SRListener.class)."); + } + + try { + context.addListener( + SRAttributeListener.class); + passed = false; + log.append( + "Expected UnsupportedOperationException not thrown by addListener(SRAttributeListener.class)."); + } catch (UnsupportedOperationException ex) { + log.append( + "Expected UnsupportedOperationException thrown by addListener(SRAttributeListener.class)."); + } + + context.setAttribute("TCK_TEST_STATUS", log.toString()); + context.setAttribute("TCK_TEST_PASS_STATUS", passed); + } + + /** + * Receives notification that the servlet context is about to be shut down. + * + * @param sce + * The servlet context event + */ + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener/TestServlet.java new file mode 100644 index 0000000000..4f87902c41 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener/TestServlet.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addlistener; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void addListenerTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + boolean passed = true; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + passed = (Boolean) context.getAttribute("TCK_TEST_PASS_STATUS"); + ServletTestUtil.printResult( + pw.append((String) context.getAttribute("TCK_TEST_STATUS")), passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener/URLClient.java new file mode 100644 index 0000000000..deb38dda69 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener/URLClient.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addlistener; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_sci_addlistener_web.war") + .addAsResource(URLClient.class.getResource("jakarta.servlet.ServletContainerInitializer"), + "META-INF/services/jakarta.servlet.ServletContainerInitializer") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(SCAttributeListener.class, SCListener.class, SCListener.class, + SRAttributeListener.class, SRListener.class, TCKServletContainerInitializer.class, + TestListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_sci_addlistener_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: addListenerTest + * + * @assertion_ids: Servlet:JAVADOC:673.12; + * + * @test_Strategy: Create a ServletContextInitializer, in which, Add a + * ServletContextListener instance using ServletContext.addListener; in the + * ServletContextListener call ServletContext.addListener(Class) Verify that + * UnsupportedOperationException is thrown. + */ + @Test + public void addListenerTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "addListenerTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener/build.xml new file mode 100644 index 0000000000..0f93f1e021 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener/build.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener/jakarta.servlet.ServletContainerInitializer b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener/jakarta.servlet.ServletContainerInitializer new file mode 100644 index 0000000000..32298b1b6a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener/jakarta.servlet.ServletContainerInitializer @@ -0,0 +1 @@ +com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addlistener.TCKServletContainerInitializer diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener/servlet_sci_addlistener_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener/servlet_sci_addlistener_web.xml new file mode 100644 index 0000000000..e30a3116f0 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener/servlet_sci_addlistener_web.xml @@ -0,0 +1,33 @@ + + + + + SerSCIADDLISTENER + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addlistener.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener1/TCKServletContainerInitializer.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener1/TCKServletContainerInitializer.java new file mode 100644 index 0000000000..de2e95ac44 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener1/TCKServletContainerInitializer.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addlistener1; + +import java.util.Set; + +import jakarta.servlet.ServletContainerInitializer; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; + +public class TCKServletContainerInitializer + implements ServletContainerInitializer { + + public void onStartup(Set> arg0, ServletContext context) + throws ServletException { + context.addListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addlistener1.TestListener.class); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener1/TestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener1/TestListener.java new file mode 100644 index 0000000000..a2939561f9 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener1/TestListener.java @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2013, 2021 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addlistener1; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; + +public class TestListener implements ServletContextListener { + + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce + * The ServletContextEvent + */ + public void contextInitialized(ServletContextEvent sce) { + boolean passed = true; + ServletContext context = sce.getServletContext(); + StringBuilder log = new StringBuilder(); + + try { + context.addListener( + "com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addlistener.SCListener"); + passed = false; + log.append( + "Expected UnsupportedOperationException not thrown by addListener(SCListener)."); + } catch (UnsupportedOperationException ex) { + log.append( + "Expected UnsupportedOperationException thrown by addListener(SCListener)."); + } + + try { + context.addListener( + "com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addlistener.SCAttributeListener"); + passed = false; + log.append( + "Expected UnsupportedOperationException not thrown by addListener(SCAttributeListener)."); + } catch (UnsupportedOperationException ex) { + log.append( + "Expected UnsupportedOperationException thrown by addListener(SCAttributeListener)."); + } + + try { + context.addListener( + "com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addlistener.SRListener"); + passed = false; + log.append( + "Expected UnsupportedOperationException not thrown by addListener(SRListener)."); + } catch (UnsupportedOperationException ex) { + log.append( + "Expected UnsupportedOperationException thrown by addListener(SRListener)."); + } + + try { + context.addListener( + "com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addlistener.SRAttributeListener"); + passed = false; + log.append( + "Expected UnsupportedOperationException not thrown by addListener(SRAttributeListene)."); + } catch (UnsupportedOperationException ex) { + log.append( + "Expected UnsupportedOperationException thrown by addListener(SRAttributeListener)."); + } + + context.setAttribute("TCK_TEST_STATUS", log.toString()); + context.setAttribute("TCK_TEST_PASS_STATUS", passed); + } + + /** + * Receives notification that the servlet context is about to be shut down. + * + * @param sce + * The servlet context event + */ + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener1/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener1/TestServlet.java new file mode 100644 index 0000000000..8a3c806d75 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener1/TestServlet.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addlistener1; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void addListenerTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + boolean passed = true; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + passed = (Boolean) context.getAttribute("TCK_TEST_PASS_STATUS"); + ServletTestUtil.printResult( + pw.append((String) context.getAttribute("TCK_TEST_STATUS")), passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener1/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener1/URLClient.java new file mode 100644 index 0000000000..fc7d9f06e4 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener1/URLClient.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addlistener1; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_sci_addlistener1_web.war") + .addAsResource(URLClient.class.getResource("jakarta.servlet.ServletContainerInitializer"), + "META-INF/services/jakarta.servlet.ServletContainerInitializer") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TCKServletContainerInitializer.class, TestListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_sci_addlistener1_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: addListenerTest + * + * @assertion_ids: Servlet:JAVADOC:671.12; + * + * @test_Strategy: Create a ServletContextInitializer, in which, Add a + * ServletContextListener instance using ServletContext.addListener; in the + * ServletContextListener call ServletContext.addListener(String) Verify that + * UnsupportedOperationException is thrown. + */ + @Test + public void addListenerTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "addListenerTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener1/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener1/build.xml new file mode 100644 index 0000000000..337db403c9 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener1/build.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener1/jakarta.servlet.ServletContainerInitializer b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener1/jakarta.servlet.ServletContainerInitializer new file mode 100644 index 0000000000..9454dc1c3f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener1/jakarta.servlet.ServletContainerInitializer @@ -0,0 +1 @@ +com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addlistener1.TCKServletContainerInitializer diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener1/servlet_sci_addlistener1_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener1/servlet_sci_addlistener1_web.xml new file mode 100644 index 0000000000..c8e9e31bc8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addlistener1/servlet_sci_addlistener1_web.xml @@ -0,0 +1,33 @@ + + + + + SerSCIADDLISTENER1 + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addlistener1.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet/DummyServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet/DummyServlet.java new file mode 100644 index 0000000000..fda15c156a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet/DummyServlet.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2013, 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:$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addservlet; + +import java.io.IOException; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public abstract class DummyServlet extends GenericServlet { + + public void init(ServletConfig config) throws ServletException { + super.init(config); + } + + public void service(ServletRequest req, ServletResponse res) + throws ServletException, IOException { + System.out.println("In DummyServlet"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet/TCKServletContainerInitializer.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet/TCKServletContainerInitializer.java new file mode 100644 index 0000000000..ac5928b444 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet/TCKServletContainerInitializer.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addservlet; + +import java.util.Set; + +import jakarta.servlet.ServletContainerInitializer; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; + +public class TCKServletContainerInitializer + implements ServletContainerInitializer { + + public void onStartup(Set> arg0, ServletContext context) + throws ServletException { + context.addListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addservlet.TestListener.class); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet/TestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet/TestListener.java new file mode 100644 index 0000000000..4be40e716e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet/TestListener.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2013, 2021 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addservlet; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; + +public class TestListener implements ServletContextListener { + + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce + * The ServletContextEvent + */ + public void contextInitialized(ServletContextEvent sce) { + boolean passed = true; + ServletContext context = sce.getServletContext(); + StringBuilder log = new StringBuilder(); + + try { + context.addServlet("/testURL", + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addservlet.DummyServlet.class); + passed = false; + log.append( + "Expected UnsupportedOperationException not thrown by addServlet(String, DummyServlet.class)."); + } catch (UnsupportedOperationException ex) { + log.append( + "Expected UnsupportedOperationException thrown by addServlet(String, DummyServlet.class)."); + } + + context.setAttribute("TCK_TEST_STATUS", log.toString()); + context.setAttribute("TCK_TEST_PASS_STATUS", passed); + } + + /** + * Receives notification that the Servlet Context is about to be shut down. + * + * @param sce + * The Servlet Context event + */ + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet/TestServlet.java new file mode 100644 index 0000000000..186f3b7df8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet/TestServlet.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addservlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void addServletTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + boolean passed = true; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + passed = (Boolean) context.getAttribute("TCK_TEST_PASS_STATUS"); + ServletTestUtil.printResult( + pw.append((String) context.getAttribute("TCK_TEST_STATUS")), passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet/URLClient.java new file mode 100644 index 0000000000..e40e813211 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet/URLClient.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addservlet; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_sci_addservlet_web.war") + .addAsResource(URLClient.class.getResource("jakarta.servlet.ServletContainerInitializer"), + "META-INF/services/jakarta.servlet.ServletContainerInitializer") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(DummyServlet.class, TCKServletContainerInitializer.class, TestListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_sci_addservlet_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: addServletTest + * + * @assertion_ids: Servlet:JAVADOC:676.7; + * + * @test_Strategy: Create a ServletContextInitializer, in which, Add a + * ServletContextListener instance using ServletContext.addListener; in the + * ServletContextListener call ServletContext.addServlet(String, Class) Verify + * that UnsupportedOperationException is thrown. + */ + @Test + public void addServletTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "addServletTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet/build.xml new file mode 100644 index 0000000000..17495c6e4f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet/build.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet/jakarta.servlet.ServletContainerInitializer b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet/jakarta.servlet.ServletContainerInitializer new file mode 100644 index 0000000000..a9f182fa4d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet/jakarta.servlet.ServletContainerInitializer @@ -0,0 +1 @@ +com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addservlet.TCKServletContainerInitializer diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet/servlet_sci_addservlet_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet/servlet_sci_addservlet_web.xml new file mode 100644 index 0000000000..8b80dc82c3 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet/servlet_sci_addservlet_web.xml @@ -0,0 +1,33 @@ + + + + + SerSCIADDSERVLET + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addservlet.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet1/DummyServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet1/DummyServlet.java new file mode 100644 index 0000000000..b1de84f262 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet1/DummyServlet.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2013, 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:$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addservlet1; + +import java.io.IOException; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public abstract class DummyServlet extends GenericServlet { + + public void init(ServletConfig config) throws ServletException { + super.init(config); + } + + public void service(ServletRequest req, ServletResponse res) + throws ServletException, IOException { + System.out.println("In DummyServlet"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet1/TCKServletContainerInitializer.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet1/TCKServletContainerInitializer.java new file mode 100644 index 0000000000..f1835b09ae --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet1/TCKServletContainerInitializer.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addservlet1; + +import java.util.Set; + +import jakarta.servlet.ServletContainerInitializer; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; + +public class TCKServletContainerInitializer + implements ServletContainerInitializer { + + public void onStartup(Set> arg0, ServletContext context) + throws ServletException { + context.addListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addservlet1.TestListener.class); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet1/TestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet1/TestListener.java new file mode 100644 index 0000000000..7ed62cac93 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet1/TestListener.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2013, 2021 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addservlet1; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; + +public class TestListener implements ServletContextListener { + + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce + * The ServletContextEvent + */ + public void contextInitialized(ServletContextEvent sce) { + boolean passed = true; + ServletContext context = sce.getServletContext(); + StringBuilder log = new StringBuilder(); + + try { + context.addServlet("/testURL", + "com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addservlet1.DummyServlet"); + passed = false; + log.append( + "Expected UnsupportedOperationException not thrown by addServlet(String, String)."); + } catch (UnsupportedOperationException ex) { + log.append( + "Expected UnsupportedOperationException thrown by addServlet(String, String)."); + } + + context.setAttribute("TCK_TEST_STATUS", log.toString()); + context.setAttribute("TCK_TEST_PASS_STATUS", passed); + } + + /** + * Receives notification that the Servlet Context is about to be shut down. + * + * @param sce + * The Servlet Context event + */ + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet1/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet1/TestServlet.java new file mode 100644 index 0000000000..452d715fb1 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet1/TestServlet.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addservlet1; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void addServletTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + boolean passed = true; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + passed = (Boolean) context.getAttribute("TCK_TEST_PASS_STATUS"); + ServletTestUtil.printResult( + pw.append((String) context.getAttribute("TCK_TEST_STATUS")), passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet1/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet1/URLClient.java new file mode 100644 index 0000000000..7ba53cb426 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet1/URLClient.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addservlet1; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_sci_addservlet1_web.war") + .addAsResource(URLClient.class.getResource("jakarta.servlet.ServletContainerInitializer"), + "META-INF/services/jakarta.servlet.ServletContainerInitializer") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(DummyServlet.class, TCKServletContainerInitializer.class, + TestListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_sci_addservlet1_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: addServletTest + * + * @assertion_ids: Servlet:JAVADOC:674.7; + * + * @test_Strategy: Create a ServletContextInitializer, in which, Add a + * ServletContextListener instance using ServletContext.addServlet; in the + * ServletContextListener call ServletContext.addServlet(String, String) + * Verify that UnsupportedOperationException is thrown. + */ + @Test + public void addServletTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "addServletTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet1/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet1/build.xml new file mode 100644 index 0000000000..a17304a27e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet1/build.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet1/jakarta.servlet.ServletContainerInitializer b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet1/jakarta.servlet.ServletContainerInitializer new file mode 100644 index 0000000000..1e8659407a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet1/jakarta.servlet.ServletContainerInitializer @@ -0,0 +1 @@ +com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addservlet1.TCKServletContainerInitializer diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet1/servlet_sci_addservlet1_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet1/servlet_sci_addservlet1_web.xml new file mode 100644 index 0000000000..dbc887bcb9 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/addservlet1/servlet_sci_addservlet1_web.xml @@ -0,0 +1,33 @@ + + + + + SerSCIADDSERVLET + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addservlet1.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/build.xml new file mode 100644 index 0000000000..a1e1ef02ac --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/build.xml @@ -0,0 +1,22 @@ + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createfilter/CreateFilter.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createfilter/CreateFilter.java new file mode 100644 index 0000000000..f25fa9ddc0 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createfilter/CreateFilter.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.createfilter; + +import java.io.IOException; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public final class CreateFilter implements Filter { + + // The filter configuration object we are associated with. If this value + // is null, this filter instance is not currently configured. + private FilterConfig filterConfig = null; + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + if (filterConfig == null) { + System.out.println( + "doFilter of CreateFilter was called but this filter instance is not currently configured"); + } else { + System.out.println("CREATE_FILTER_INVOKED"); + } + + chain.doFilter(request, response); + } + + // Remove the filter configuration object for this filter. + public void destroy() { + } + + // initialize the filter configuration object for this filter. + public void init(FilterConfig filterConfig) { + this.filterConfig = filterConfig; + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createfilter/TCKServletContainerInitializer.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createfilter/TCKServletContainerInitializer.java new file mode 100644 index 0000000000..c0f06df961 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createfilter/TCKServletContainerInitializer.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.createfilter; + +import java.util.Set; + +import jakarta.servlet.ServletContainerInitializer; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; + +public class TCKServletContainerInitializer + implements ServletContainerInitializer { + + public void onStartup(Set> arg0, ServletContext context) + throws ServletException { + context.addListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.createfilter.TestListener.class); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createfilter/TestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createfilter/TestListener.java new file mode 100644 index 0000000000..26bdcc825c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createfilter/TestListener.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2013, 2021 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.createfilter; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; +import jakarta.servlet.ServletException; + +public class TestListener implements ServletContextListener { + + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce + * The ServletContextEvent + */ + public void contextInitialized(ServletContextEvent sce) { + boolean passed = true; + ServletContext context = sce.getServletContext(); + StringBuilder log = new StringBuilder(); + + try { + context.createFilter( + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.createfilter.CreateFilter.class); + passed = false; + log.append("Expected UnsupportedOperationException not thrown."); + } catch (UnsupportedOperationException ex) { + log.append("Expected UnsupportedOperationException thrown."); + } catch (ServletException ex) { + passed = false; + System.out.println("Error creating Servlet"); + } + + context.setAttribute("TCK_TEST_STATUS", log.toString()); + context.setAttribute("TCK_TEST_PASS_STATUS", passed); + } + + /** + * Receives notification that the servlet context is about to be shut down. + * + * @param sce + * The servlet context event + */ + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createfilter/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createfilter/TestServlet.java new file mode 100644 index 0000000000..b08856ab64 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createfilter/TestServlet.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.createfilter; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void createFilterTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + boolean passed = true; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + passed = (Boolean) context.getAttribute("TCK_TEST_PASS_STATUS"); + ServletTestUtil.printResult( + pw.append((String) context.getAttribute("TCK_TEST_STATUS")), passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createfilter/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createfilter/URLClient.java new file mode 100644 index 0000000000..35bbc09d98 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createfilter/URLClient.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.createfilter; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_sci_createfilter_web.war") + .addAsResource(URLClient.class.getResource("jakarta.servlet.ServletContainerInitializer"), + "META-INF/services/jakarta.servlet.ServletContainerInitializer") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(CreateFilter.class, TCKServletContainerInitializer.class, + TestListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_sci_createfilter_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: createFilterTest + * + * @assertion_ids: Servlet:JAVADOC:677.3; + * + * @test_Strategy: Create a ServletContextInitializer, in which, Add a + * ServletContextListener instance using ServletContext.addListener; in the + * ServletContextListener call ServletContext.createFilter(Class) Verify that + * UnsupportedOperationException is thrown. + */ + @Test + public void createFilterTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "createFilterTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createfilter/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createfilter/build.xml new file mode 100644 index 0000000000..e274c0f7d6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createfilter/build.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createfilter/jakarta.servlet.ServletContainerInitializer b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createfilter/jakarta.servlet.ServletContainerInitializer new file mode 100644 index 0000000000..ef125daaf0 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createfilter/jakarta.servlet.ServletContainerInitializer @@ -0,0 +1 @@ +com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.createfilter.TCKServletContainerInitializer diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createfilter/servlet_sci_createfilter_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createfilter/servlet_sci_createfilter_web.xml new file mode 100644 index 0000000000..54dc1e8e59 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createfilter/servlet_sci_createfilter_web.xml @@ -0,0 +1,33 @@ + + + + + SerSCICREATEFILTER + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.createfilter.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createlistener/TCKServletContainerInitializer.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createlistener/TCKServletContainerInitializer.java new file mode 100644 index 0000000000..999845d290 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createlistener/TCKServletContainerInitializer.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.createlistener; + +import java.util.Set; + +import jakarta.servlet.ServletContainerInitializer; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; + +public class TCKServletContainerInitializer + implements ServletContainerInitializer { + + public void onStartup(Set> arg0, ServletContext context) + throws ServletException { + context.addListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.createlistener.TestListener.class); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createlistener/TestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createlistener/TestListener.java new file mode 100644 index 0000000000..2656602227 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createlistener/TestListener.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2013, 2021 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.createlistener; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; +import jakarta.servlet.ServletException; + +public class TestListener implements ServletContextListener { + + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce + * The ServletContextEvent + */ + public void contextInitialized(ServletContextEvent sce) { + boolean passed = true; + ServletContext context = sce.getServletContext(); + StringBuilder log = new StringBuilder(); + + try { + context.createListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addlistener.SCListener.class); + passed = false; + log.append( + "Expected UnsupportedOperationException not thrown by createListener(SCListener.class)."); + } catch (UnsupportedOperationException ex) { + log.append( + "Expected UnsupportedOperationException thrown by createListener(SCListener.class)."); + } catch (ServletException ex1) { + passed = false; + log.append( + "ServletException thrown by createListener(SCListener.class)."); + } + + try { + context.createListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addlistener.SCAttributeListener.class); + passed = false; + log.append( + "Expected UnsupportedOperationException not thrown by createListener(SCAttributeListener.class)."); + } catch (UnsupportedOperationException ex) { + log.append( + "Expected UnsupportedOperationException thrown by createListener(SCAttributeListener.class)."); + } catch (ServletException ex1) { + passed = false; + log.append( + "ServletException thrown by createListener(SCAttributeListener.class)."); + } + + try { + context.createListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addlistener.SRListener.class); + passed = false; + log.append( + "Expected UnsupportedOperationException not thrown by createListener(SRListener.class)."); + } catch (UnsupportedOperationException ex) { + log.append( + "Expected UnsupportedOperationException thrown by createListener(SRListener.class)."); + } catch (ServletException ex1) { + passed = false; + log.append( + "ServletException thrown by createListener(SRListener.class)."); + } + + try { + context.createListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addlistener.SRAttributeListener.class); + log.append( + "Expected UnsupportedOperationException not thrown by createListener(SRAttributeListener.class)."); + } catch (UnsupportedOperationException ex) { + log.append( + "Expected UnsupportedOperationException thrown by createListener(SRAttributeListener.class)."); + } catch (ServletException ex1) { + log.append( + "ServletException thrown by createListener(SRAttributeListener.class)."); + } + + context.setAttribute("TCK_TEST_STATUS", log.toString()); + context.setAttribute("TCK_TEST_PASS_STATUS", passed); + } + + /** + * Receives notification that the servlet context is about to be shut down. + * + * @param sce + * The servlet context event + */ + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createlistener/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createlistener/TestServlet.java new file mode 100644 index 0000000000..d48382a7f3 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createlistener/TestServlet.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.createlistener; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void createListenerTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = true; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + passed = (Boolean) context.getAttribute("TCK_TEST_PASS_STATUS"); + ServletTestUtil.printResult( + pw.append((String) context.getAttribute("TCK_TEST_STATUS")), passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createlistener/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createlistener/URLClient.java new file mode 100644 index 0000000000..d4205a6378 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createlistener/URLClient.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.createlistener; + +import com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addlistener.SCAttributeListener; +import com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addlistener.SRAttributeListener; +import com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addlistener.SRListener; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.addlistener.SCListener; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_sci_createlistener_web.war") + .addAsResource(URLClient.class.getResource("jakarta.servlet.ServletContainerInitializer"), + "META-INF/services/jakarta.servlet.ServletContainerInitializer") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TCKServletContainerInitializer.class, TestListener.class, TestServlet.class, SCListener.class, + SCAttributeListener.class, SRListener.class, SRAttributeListener.class) + .setWebXML(URLClient.class.getResource("servlet_sci_createlistener_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: createListenerTest + * + * @assertion_ids: Servlet:JAVADOC:679.3; + * + * @test_Strategy: Create a ServletContextInitializer, in which, Add a + * ServletContextListener instance using ServletContext.addListener; in the + * ServletContextListener call ServletContext.createListener(Class) Verify + * that UnsupportedOperationException is thrown. + */ + @Test + public void createListenerTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "createListenerTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createlistener/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createlistener/build.xml new file mode 100644 index 0000000000..1d11f9e833 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createlistener/build.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createlistener/jakarta.servlet.ServletContainerInitializer b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createlistener/jakarta.servlet.ServletContainerInitializer new file mode 100644 index 0000000000..85ec668123 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createlistener/jakarta.servlet.ServletContainerInitializer @@ -0,0 +1 @@ +com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.createlistener.TCKServletContainerInitializer diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createlistener/servlet_sci_createlistener_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createlistener/servlet_sci_createlistener_web.xml new file mode 100644 index 0000000000..a97266476d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createlistener/servlet_sci_createlistener_web.xml @@ -0,0 +1,33 @@ + + + + + SerSCICREATELISTENER + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.createlistener.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createservlet/DummyServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createservlet/DummyServlet.java new file mode 100644 index 0000000000..9feb8e73fb --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createservlet/DummyServlet.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2013, 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:$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.createservlet; + +import java.io.IOException; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public abstract class DummyServlet extends GenericServlet { + + public void init(ServletConfig config) throws ServletException { + super.init(config); + } + + public void service(ServletRequest req, ServletResponse res) + throws ServletException, IOException { + System.out.println("In DummyServlet"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createservlet/TCKServletContainerInitializer.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createservlet/TCKServletContainerInitializer.java new file mode 100644 index 0000000000..3a4f5e1def --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createservlet/TCKServletContainerInitializer.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.createservlet; + +import java.util.Set; + +import jakarta.servlet.ServletContainerInitializer; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; + +public class TCKServletContainerInitializer + implements ServletContainerInitializer { + + public void onStartup(Set> arg0, ServletContext context) + throws ServletException { + context.addListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.createservlet.TestListener.class); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createservlet/TestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createservlet/TestListener.java new file mode 100644 index 0000000000..8ec23ad66d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createservlet/TestListener.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2013, 2021 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.createservlet; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; + +public class TestListener implements ServletContextListener { + + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce + * The ServletContextEvent + */ + public void contextInitialized(ServletContextEvent sce) { + boolean passed = true; + ServletContext context = sce.getServletContext(); + StringBuilder log = new StringBuilder(); + + try { + context.addServlet("/testURL", + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.createservlet.DummyServlet.class); + passed = false; + log.append( + "Expected UnsupportedOperationException not thrown by createservlet(String, DummyServlet.class)."); + } catch (UnsupportedOperationException ex) { + log.append( + "Expected UnsupportedOperationException thrown by createservlet(String, DummyServlet.class)."); + } + + context.setAttribute("TCK_TEST_STATUS", log.toString()); + context.setAttribute("TCK_TEST_PASS_STATUS", passed); + } + + /** + * Receives notification that the Servlet Context is about to be shut down. + * + * @param sce + * The Servlet Context event + */ + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createservlet/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createservlet/TestServlet.java new file mode 100644 index 0000000000..9ba1af4761 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createservlet/TestServlet.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.createservlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void createServletTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = true; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + passed = (Boolean) context.getAttribute("TCK_TEST_PASS_STATUS"); + ServletTestUtil.printResult( + pw.append((String) context.getAttribute("TCK_TEST_STATUS")), passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createservlet/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createservlet/URLClient.java new file mode 100644 index 0000000000..375960ca99 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createservlet/URLClient.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.createservlet; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_sci_createservlet_web.war") + .addAsResource(URLClient.class.getResource("jakarta.servlet.ServletContainerInitializer"), + "META-INF/services/jakarta.servlet.ServletContainerInitializer") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(DummyServlet.class, TCKServletContainerInitializer.class, + TestListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_sci_createservlet_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: createServletTest + * + * @assertion_ids: Servlet:JAVADOC:681.3; + * + * @test_Strategy: Create a ServletContextInitializer, in which, Add a + * ServletContextListener instance using ServletContext.addListener; in the + * ServletContextListener call ServletContext.createServlet(Class) Verify that + * UnsupportedOperationException is thrown. + */ + @Test + public void createServletTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "createServletTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createservlet/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createservlet/build.xml new file mode 100644 index 0000000000..f0edd56793 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createservlet/build.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createservlet/jakarta.servlet.ServletContainerInitializer b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createservlet/jakarta.servlet.ServletContainerInitializer new file mode 100644 index 0000000000..776a170313 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createservlet/jakarta.servlet.ServletContainerInitializer @@ -0,0 +1 @@ +com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.createservlet.TCKServletContainerInitializer diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createservlet/servlet_sci_createservlet_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createservlet/servlet_sci_createservlet_web.xml new file mode 100644 index 0000000000..e24fcbccea --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/createservlet/servlet_sci_createservlet_web.xml @@ -0,0 +1,33 @@ + + + + + SerSCICREATESERVLET + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.createservlet.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getclassloader/TCKServletContainerInitializer.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getclassloader/TCKServletContainerInitializer.java new file mode 100644 index 0000000000..a600983cd4 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getclassloader/TCKServletContainerInitializer.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getclassloader; + +import java.util.Set; + +import jakarta.servlet.ServletContainerInitializer; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; + +public class TCKServletContainerInitializer + implements ServletContainerInitializer { + + public void onStartup(Set> arg0, ServletContext context) + throws ServletException { + context.addListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getclassloader.TestListener.class); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getclassloader/TestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getclassloader/TestListener.java new file mode 100644 index 0000000000..5021517497 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getclassloader/TestListener.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2013, 2021 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getclassloader; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; + +public class TestListener implements ServletContextListener { + + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce + * The ServletContextEvent + */ + public void contextInitialized(ServletContextEvent sce) { + boolean passed = false; + ServletContext context = sce.getServletContext(); + StringBuilder log = new StringBuilder(); + + try { + context.getClassLoader(); + passed = true; + log.append( + "UnsupportedOperationException not thrown by getClassLoader()."); + } catch (UnsupportedOperationException ex) { + log.append( + "UnsupportedOperationException thrown by getClassLoader()."); + } + + context.setAttribute("TCK_TEST_STATUS", log.toString()); + context.setAttribute("TCK_TEST_PASS_STATUS", passed); + } + + /** + * Receives notification that the Servlet Context is about to be shut down. + * + * @param sce + * The Servlet Context event + */ + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getclassloader/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getclassloader/TestServlet.java new file mode 100644 index 0000000000..c36a6dd240 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getclassloader/TestServlet.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getclassloader; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void getClassloaderTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = true; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + passed = (Boolean) context.getAttribute("TCK_TEST_PASS_STATUS"); + ServletTestUtil.printResult( + pw.append((String) context.getAttribute("TCK_TEST_STATUS")), passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getclassloader/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getclassloader/URLClient.java new file mode 100644 index 0000000000..a6004afe8b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getclassloader/URLClient.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getclassloader; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_sci_getclassloader_web.war") + .addAsResource(URLClient.class.getResource("jakarta.servlet.ServletContainerInitializer"), + "META-INF/services/jakarta.servlet.ServletContainerInitializer") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TCKServletContainerInitializer.class, TestListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_sci_getclassloader_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: getClassloaderTest + * + * @assertion_ids: Servlet:JAVADOC:683.2; + * + * @test_Strategy: Create a ServletContextInitializer, in which, Add a + * ServletContextListener instance using ServletContext.addListener; in the + * ServletContextListener call ServletContext.getClassloader() Verify that + * UnsupportedOperationException is thrown. + */ + @Test + public void getClassloaderTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getClassloaderTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getclassloader/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getclassloader/build.xml new file mode 100644 index 0000000000..bae9869750 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getclassloader/build.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getclassloader/jakarta.servlet.ServletContainerInitializer b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getclassloader/jakarta.servlet.ServletContainerInitializer new file mode 100644 index 0000000000..7b8220382e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getclassloader/jakarta.servlet.ServletContainerInitializer @@ -0,0 +1 @@ +com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getclassloader.TCKServletContainerInitializer diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getclassloader/servlet_sci_getclassloader_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getclassloader/servlet_sci_getclassloader_web.xml new file mode 100644 index 0000000000..52d366d7f4 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getclassloader/servlet_sci_getclassloader_web.xml @@ -0,0 +1,33 @@ + + + + + SerSCIGETCLASSLOADER + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getclassloader.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getdefaultsessiontrackingmodes/TCKServletContainerInitializer.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getdefaultsessiontrackingmodes/TCKServletContainerInitializer.java new file mode 100644 index 0000000000..88b1c5eee2 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getdefaultsessiontrackingmodes/TCKServletContainerInitializer.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getdefaultsessiontrackingmodes; + +import java.util.Set; + +import jakarta.servlet.ServletContainerInitializer; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; + +public class TCKServletContainerInitializer + implements ServletContainerInitializer { + + public void onStartup(Set> arg0, ServletContext context) + throws ServletException { + context.addListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getdefaultsessiontrackingmodes.TestListener.class); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getdefaultsessiontrackingmodes/TestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getdefaultsessiontrackingmodes/TestListener.java new file mode 100644 index 0000000000..10d0e8bdf6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getdefaultsessiontrackingmodes/TestListener.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2013, 2021 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getdefaultsessiontrackingmodes; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; + +public class TestListener implements ServletContextListener { + + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce + * The ServletContextEvent + */ + public void contextInitialized(ServletContextEvent sce) { + boolean passed = false; + ServletContext context = sce.getServletContext(); + StringBuilder log = new StringBuilder(); + + try { + context.getDefaultSessionTrackingModes(); + passed = true; + log.append("UnsupportedOperationException not thrown."); + } catch (UnsupportedOperationException ex) { + log.append("UnsupportedOperationException thrown."); + } + + context.setAttribute("TCK_TEST_STATUS", log.toString()); + context.setAttribute("TCK_TEST_PASS_STATUS", passed); + } + + /** + * Receives notification that the servlet context is about to be shut down. + * + * @param sce + * The servlet context event + */ + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getdefaultsessiontrackingmodes/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getdefaultsessiontrackingmodes/TestServlet.java new file mode 100644 index 0000000000..2ee07e6e89 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getdefaultsessiontrackingmodes/TestServlet.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getdefaultsessiontrackingmodes; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void getDefaultSessionTrackingModes(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = true; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + passed = (Boolean) context.getAttribute("TCK_TEST_PASS_STATUS"); + ServletTestUtil.printResult( + pw.append((String) context.getAttribute("TCK_TEST_STATUS")), passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getdefaultsessiontrackingmodes/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getdefaultsessiontrackingmodes/URLClient.java new file mode 100644 index 0000000000..efad6a2cf6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getdefaultsessiontrackingmodes/URLClient.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getdefaultsessiontrackingmodes; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_sci_getdefaultsessiontrackingmode_web.war") + .addAsResource(URLClient.class.getResource("jakarta.servlet.ServletContainerInitializer"), + "META-INF/services/jakarta.servlet.ServletContainerInitializer") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TCKServletContainerInitializer.class, TestListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_sci_getdefaultsessiontrackingmode_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: getDefaultSessionTrackingModes + * + * @assertion_ids: Servlet:JAVADOC:684.1; + * + * @test_Strategy: Create a ServletContextInitializer, in which, Add a + * ServletContextListener instance using ServletContext.addListener; in the + * ServletContextListener call ServletContext.getDefaultSessionTrackingModes() + * Verify that UnsupportedOperationException is thrown. + */ + @Test + public void getDefaultSessionTrackingModes() throws Exception { + TEST_PROPS.setProperty(APITEST, "getDefaultSessionTrackingModes"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getdefaultsessiontrackingmodes/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getdefaultsessiontrackingmodes/build.xml new file mode 100644 index 0000000000..832c02cccc --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getdefaultsessiontrackingmodes/build.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getdefaultsessiontrackingmodes/jakarta.servlet.ServletContainerInitializer b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getdefaultsessiontrackingmodes/jakarta.servlet.ServletContainerInitializer new file mode 100644 index 0000000000..d6f4ba8f47 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getdefaultsessiontrackingmodes/jakarta.servlet.ServletContainerInitializer @@ -0,0 +1 @@ +com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getdefaultsessiontrackingmodes.TCKServletContainerInitializer diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getdefaultsessiontrackingmodes/servlet_sci_getdefaultsessiontrackingmode_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getdefaultsessiontrackingmodes/servlet_sci_getdefaultsessiontrackingmode_web.xml new file mode 100644 index 0000000000..0afcea7c30 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getdefaultsessiontrackingmodes/servlet_sci_getdefaultsessiontrackingmode_web.xml @@ -0,0 +1,33 @@ + + + + + SerSCIGETDEAFULTSessionTrackingMode + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getdefaultsessiontrackingmodes.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivemajorversion/TCKServletContainerInitializer.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivemajorversion/TCKServletContainerInitializer.java new file mode 100644 index 0000000000..d0a4e3ff05 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivemajorversion/TCKServletContainerInitializer.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.geteffectivemajorversion; + +import java.util.Set; + +import jakarta.servlet.ServletContainerInitializer; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; + +public class TCKServletContainerInitializer + implements ServletContainerInitializer { + + public void onStartup(Set> arg0, ServletContext context) + throws ServletException { + context.addListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.geteffectivemajorversion.TestListener.class); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivemajorversion/TestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivemajorversion/TestListener.java new file mode 100644 index 0000000000..c2aef11ea7 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivemajorversion/TestListener.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2013, 2021 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.geteffectivemajorversion; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; + +public class TestListener implements ServletContextListener { + + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce + * The ServletContextEvent + */ + public void contextInitialized(ServletContextEvent sce) { + boolean passed = false; + ServletContext context = sce.getServletContext(); + StringBuilder log = new StringBuilder(); + + try { + context.getEffectiveMajorVersion(); + passed = true; + log.append( + "UnsupportedOperationException not thrown by getEffectiveMajorVersion()."); + } catch (UnsupportedOperationException ex) { + log.append( + "UnsupportedOperationException thrown by getEffectiveMajorVersion()."); + } + + context.setAttribute("TCK_TEST_STATUS", log.toString()); + context.setAttribute("TCK_TEST_PASS_STATUS", passed); + } + + /** + * Receives notification that the Servlet Context is about to be shut down. + * + * @param sce + * The Servlet Context event + */ + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivemajorversion/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivemajorversion/TestServlet.java new file mode 100644 index 0000000000..4db5767cf1 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivemajorversion/TestServlet.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.geteffectivemajorversion; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void getEffectiveMajorVersionTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = true; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + passed = (Boolean) context.getAttribute("TCK_TEST_PASS_STATUS"); + ServletTestUtil.printResult( + pw.append((String) context.getAttribute("TCK_TEST_STATUS")), passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivemajorversion/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivemajorversion/URLClient.java new file mode 100644 index 0000000000..d381e9e8e9 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivemajorversion/URLClient.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.geteffectivemajorversion; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_sci_geteffectivemajorversion_web.war") + .addAsResource(URLClient.class.getResource("jakarta.servlet.ServletContainerInitializer"), + "META-INF/services/jakarta.servlet.ServletContainerInitializer") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TCKServletContainerInitializer.class, TestListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_sci_geteffectivemajorversion_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: getEffectiveMajorVersionTest + * + * @assertion_ids: Servlet:JAVADOC:685.1; + * + * @test_Strategy: Create a ServletContextInitializer, in which, Add a + * ServletContextListener instance using ServletContext.addListener; in the + * ServletContextListener call ServletContext.getEffectiveMajorVersion() + * Verify that UnsupportedOperationException is thrown. + */ + @Test + public void getEffectiveMajorVersionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getEffectiveMajorVersionTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivemajorversion/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivemajorversion/build.xml new file mode 100644 index 0000000000..8f4c2a7b67 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivemajorversion/build.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivemajorversion/jakarta.servlet.ServletContainerInitializer b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivemajorversion/jakarta.servlet.ServletContainerInitializer new file mode 100644 index 0000000000..62c275cd13 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivemajorversion/jakarta.servlet.ServletContainerInitializer @@ -0,0 +1 @@ +com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.geteffectivemajorversion.TCKServletContainerInitializer diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivemajorversion/servlet_sci_geteffectivemajorversion_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivemajorversion/servlet_sci_geteffectivemajorversion_web.xml new file mode 100644 index 0000000000..bf4808703b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivemajorversion/servlet_sci_geteffectivemajorversion_web.xml @@ -0,0 +1,33 @@ + + + + + SerSCIGETEFFECTIVEMAJORVERSION + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.geteffectivemajorversion.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectiveminorversion/TCKServletContainerInitializer.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectiveminorversion/TCKServletContainerInitializer.java new file mode 100644 index 0000000000..1951c519dc --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectiveminorversion/TCKServletContainerInitializer.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.geteffectiveminorversion; + +import java.util.Set; + +import jakarta.servlet.ServletContainerInitializer; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; + +public class TCKServletContainerInitializer + implements ServletContainerInitializer { + + public void onStartup(Set> arg0, ServletContext context) + throws ServletException { + context.addListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.geteffectiveminorversion.TestListener.class); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectiveminorversion/TestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectiveminorversion/TestListener.java new file mode 100644 index 0000000000..9095edabb8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectiveminorversion/TestListener.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2013, 2021 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.geteffectiveminorversion; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; + +public class TestListener implements ServletContextListener { + + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce + * The ServletContextEvent + */ + public void contextInitialized(ServletContextEvent sce) { + boolean passed = false; + ServletContext context = sce.getServletContext(); + StringBuilder log = new StringBuilder(); + + try { + context.getEffectiveMajorVersion(); + passed = true; + log.append("UnsupportedOperationException not thrown."); + } catch (UnsupportedOperationException ex) { + log.append("UnsupportedOperationException thrown."); + } + + context.setAttribute("TCK_TEST_STATUS", log.toString()); + context.setAttribute("TCK_TEST_PASS_STATUS", passed); + } + + /** + * Receives notification that the Servlet Context is about to be shut down. + * + * @param sce + * The Servlet Context event + */ + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectiveminorversion/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectiveminorversion/TestServlet.java new file mode 100644 index 0000000000..5dbe6aa322 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectiveminorversion/TestServlet.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.geteffectiveminorversion; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void getEffectiveMajorVersionTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = true; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + passed = (Boolean) context.getAttribute("TCK_TEST_PASS_STATUS"); + ServletTestUtil.printResult( + pw.append((String) context.getAttribute("TCK_TEST_STATUS")), passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectiveminorversion/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectiveminorversion/URLClient.java new file mode 100644 index 0000000000..1e53361ba7 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectiveminorversion/URLClient.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.geteffectiveminorversion; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_sci_geteffectiveminorversion_web.war") + .addAsResource(URLClient.class.getResource("jakarta.servlet.ServletContainerInitializer"), + "META-INF/services/jakarta.servlet.ServletContainerInitializer") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TCKServletContainerInitializer.class, TestListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_sci_geteffectiveminorversion_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: getEffectiveMajorVersionTest + * + * @assertion_ids: Servlet:JAVADOC:686.1; + * + * @test_Strategy: Create a ServletContextInitializer, in which, Add a + * ServletContextListener instance using ServletContext.addListener; in the + * ServletContextListener call ServletContext.getEffectiveMajorVersion() + * Verify that UnsupportedOperationException is thrown. + */ + @Test + public void getEffectiveMajorVersionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getEffectiveMajorVersionTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectiveminorversion/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectiveminorversion/build.xml new file mode 100644 index 0000000000..930b2be59f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectiveminorversion/build.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectiveminorversion/jakarta.servlet.ServletContainerInitializer b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectiveminorversion/jakarta.servlet.ServletContainerInitializer new file mode 100644 index 0000000000..85a6f9236d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectiveminorversion/jakarta.servlet.ServletContainerInitializer @@ -0,0 +1 @@ +com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.geteffectiveminorversion.TCKServletContainerInitializer diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectiveminorversion/servlet_sci_geteffectiveminorversion_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectiveminorversion/servlet_sci_geteffectiveminorversion_web.xml new file mode 100644 index 0000000000..2ed6e4fc41 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectiveminorversion/servlet_sci_geteffectiveminorversion_web.xml @@ -0,0 +1,33 @@ + + + + + SerSCIGETEFFECTIVEMINORVERSION + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.geteffectiveminorversion.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivesessiontrackingmodes/TCKServletContainerInitializer.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivesessiontrackingmodes/TCKServletContainerInitializer.java new file mode 100644 index 0000000000..8a6ab72789 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivesessiontrackingmodes/TCKServletContainerInitializer.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.geteffectivesessiontrackingmodes; + +import java.util.Set; + +import jakarta.servlet.ServletContainerInitializer; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; + +public class TCKServletContainerInitializer + implements ServletContainerInitializer { + + public void onStartup(Set> arg0, ServletContext context) + throws ServletException { + context.addListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.geteffectivesessiontrackingmodes.TestListener.class); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivesessiontrackingmodes/TestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivesessiontrackingmodes/TestListener.java new file mode 100644 index 0000000000..6a0a730a27 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivesessiontrackingmodes/TestListener.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2013, 2021 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.geteffectivesessiontrackingmodes; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; + +public class TestListener implements ServletContextListener { + + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce + * The ServletContextEvent + */ + public void contextInitialized(ServletContextEvent sce) { + boolean passed = false; + ServletContext context = sce.getServletContext(); + StringBuilder log = new StringBuilder(); + + try { + context.getEffectiveSessionTrackingModes(); + passed = true; + log.append("UnsupportedOperationException not thrown."); + } catch (UnsupportedOperationException ex) { + log.append("UnsupportedOperationException thrown."); + } + + context.setAttribute("TCK_TEST_STATUS", log.toString()); + context.setAttribute("TCK_TEST_PASS_STATUS", passed); + } + + /** + * Receives notification that the servlet context is about to be shut down. + * + * @param sce + * The servlet context event + */ + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivesessiontrackingmodes/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivesessiontrackingmodes/TestServlet.java new file mode 100644 index 0000000000..c8fedb9bf5 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivesessiontrackingmodes/TestServlet.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.geteffectivesessiontrackingmodes; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void getEffectiveSessionTrackingModes(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = true; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + passed = (Boolean) context.getAttribute("TCK_TEST_PASS_STATUS"); + ServletTestUtil.printResult( + pw.append((String) context.getAttribute("TCK_TEST_STATUS")), passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivesessiontrackingmodes/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivesessiontrackingmodes/URLClient.java new file mode 100644 index 0000000000..ca3deca514 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivesessiontrackingmodes/URLClient.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.geteffectivesessiontrackingmodes; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_sci_geteffectivesessiontrackingmode_web.war") + .addAsResource(URLClient.class.getResource("jakarta.servlet.ServletContainerInitializer"), + "META-INF/services/jakarta.servlet.ServletContainerInitializer") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TCKServletContainerInitializer.class, TestListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_sci_geteffectivesessiontrackingmode_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: getEffectiveSessionTrackingModes + * + * @assertion_ids: Servlet:JAVADOC:687.1; + * + * @test_Strategy: Create a ServletContextInitializer, in which, Add a + * ServletContextListener instance using ServletContext.addListener; in the + * ServletContextListener call + * ServletContext.getEffectiveSessionTrackingModes() Verify that + * UnsupportedOperationException is thrown. + */ + @Test + public void getEffectiveSessionTrackingModes() throws Exception { + TEST_PROPS.setProperty(APITEST, "getEffectiveSessionTrackingModes"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivesessiontrackingmodes/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivesessiontrackingmodes/build.xml new file mode 100644 index 0000000000..6098d50094 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivesessiontrackingmodes/build.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivesessiontrackingmodes/jakarta.servlet.ServletContainerInitializer b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivesessiontrackingmodes/jakarta.servlet.ServletContainerInitializer new file mode 100644 index 0000000000..3f946f35c4 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivesessiontrackingmodes/jakarta.servlet.ServletContainerInitializer @@ -0,0 +1 @@ +com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.geteffectivesessiontrackingmodes.TCKServletContainerInitializer diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivesessiontrackingmodes/servlet_sci_geteffectivesessiontrackingmode_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivesessiontrackingmodes/servlet_sci_geteffectivesessiontrackingmode_web.xml new file mode 100644 index 0000000000..ef37167175 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/geteffectivesessiontrackingmodes/servlet_sci_geteffectivesessiontrackingmode_web.xml @@ -0,0 +1,33 @@ + + + + + SerSCIGETEFFECTIVESessionTrackingMode + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.geteffectivesessiontrackingmodes.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistration/TCKServletContainerInitializer.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistration/TCKServletContainerInitializer.java new file mode 100644 index 0000000000..76dcd3a309 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistration/TCKServletContainerInitializer.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getfilterregistration; + +import java.util.Set; + +import jakarta.servlet.ServletContainerInitializer; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; + +public class TCKServletContainerInitializer + implements ServletContainerInitializer { + + public void onStartup(Set> arg0, ServletContext context) + throws ServletException { + context.addListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getfilterregistration.TestListener.class); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistration/TestFilter.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistration/TestFilter.java new file mode 100644 index 0000000000..3b5f30b112 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistration/TestFilter.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getfilterregistration; + +import java.io.IOException; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public final class TestFilter implements Filter { + + // The filter configuration object we are associated with. If this value + // is null, this filter instance is not currently configured. + private FilterConfig filterConfig = null; + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + if (filterConfig == null) { + System.out.println( + "doFilter of TestFilter was called but this filter instance is not currently configured"); + } else { + System.out.println("TEST_FILTER_INVOKED"); + } + + chain.doFilter(request, response); + } + + // Remove the filter configuration object for this filter. + public void destroy() { + } + + // initialize the filter configuration object for this filter. + public void init(FilterConfig filterConfig) { + this.filterConfig = filterConfig; + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistration/TestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistration/TestListener.java new file mode 100644 index 0000000000..29b40f2893 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistration/TestListener.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getfilterregistration; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; + +public class TestListener implements ServletContextListener { + + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce + * The ServletContextEvent + */ + public void contextInitialized(ServletContextEvent sce) { + boolean passed = true; + ServletContext context = sce.getServletContext(); + StringBuilder log = new StringBuilder(); + + try { + context.getFilterRegistration( + "com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getfilterregistration.TestFilter"); + log.append( + "Expected UnsupportedOperationException not thrown by getFilterRegistration(String)."); + passed = false; + } catch (UnsupportedOperationException ex) { + log.append( + "Expected UnsupportedOperationException thrown by getFilterRegistration(String)."); + } + + context.setAttribute("TCK_TEST_STATUS", log.toString()); + context.setAttribute("TCK_TEST_PASS_STATUS", passed); + } + + /** + * Receives notification that the Servlet Context is about to be shut down. + * + * @param sce + * The Servlet Context event + */ + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistration/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistration/TestServlet.java new file mode 100644 index 0000000000..255361b176 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistration/TestServlet.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getfilterregistration; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + @Override + public void init(ServletConfig config) throws ServletException { + super.init(config); + } + + public void getFilterRegistrationTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = true; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + passed = (Boolean) context.getAttribute("TCK_TEST_PASS_STATUS"); + ServletTestUtil.printResult( + pw.append((String) context.getAttribute("TCK_TEST_STATUS")), passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistration/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistration/URLClient.java new file mode 100644 index 0000000000..3265731bd5 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistration/URLClient.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getfilterregistration; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_sci_getfilterregistration_web.war") + .addAsResource(URLClient.class.getResource("jakarta.servlet.ServletContainerInitializer"), + "META-INF/services/jakarta.servlet.ServletContainerInitializer") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TCKServletContainerInitializer.class, TestFilter.class, TestListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_sci_getfilterregistration_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: getFilterRegistrationTest + * + * @assertion_ids: Servlet:JAVADOC:688.1; + * + * @test_Strategy: Create a ServletContextInitializer, in which, Add a + * ServletContextListener instance using ServletContext.addListener; in the + * ServletContextListener call ServletContext.getFilterRegistration(String) + * Verify that UnsupportedOperationException is thrown. + */ + @Test + public void getFilterRegistrationTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getFilterRegistrationTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistration/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistration/build.xml new file mode 100644 index 0000000000..673ea1cad6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistration/build.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistration/jakarta.servlet.ServletContainerInitializer b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistration/jakarta.servlet.ServletContainerInitializer new file mode 100644 index 0000000000..4eb2e28593 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistration/jakarta.servlet.ServletContainerInitializer @@ -0,0 +1 @@ +com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getfilterregistration.TCKServletContainerInitializer diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistration/servlet_sci_getfilterregistration_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistration/servlet_sci_getfilterregistration_web.xml new file mode 100644 index 0000000000..1766c1d7a2 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistration/servlet_sci_getfilterregistration_web.xml @@ -0,0 +1,41 @@ + + + + + SerSCIGETFILTERREGISTRATION + + TestFilter + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getfilterregistration.TestFilter + + + TestFilter + TestServlet + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getfilterregistration.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistrations/TCKServletContainerInitializer.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistrations/TCKServletContainerInitializer.java new file mode 100644 index 0000000000..280711f1bc --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistrations/TCKServletContainerInitializer.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getfilterregistrations; + +import java.util.Set; + +import jakarta.servlet.ServletContainerInitializer; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; + +public class TCKServletContainerInitializer + implements ServletContainerInitializer { + + public void onStartup(Set> arg0, ServletContext context) + throws ServletException { + context.addListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getfilterregistrations.TestListener.class); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistrations/TestFilter.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistrations/TestFilter.java new file mode 100644 index 0000000000..88e2223dfd --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistrations/TestFilter.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getfilterregistrations; + +import java.io.IOException; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.annotation.WebFilter; + +@WebFilter(urlPatterns = { "/foo" }) +public final class TestFilter implements Filter { + + // The filter configuration object we are associated with. If this value + // is null, this filter instance is not currently configured. + private FilterConfig filterConfig; + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + if (filterConfig == null) { + System.out.println( + "doFilter of TestFilter was called but this filter instance is not currently configured"); + } else { + System.out.println("TEST_FILTER_INVOKED"); + } + + chain.doFilter(request, response); + } + + // Remove the filter configuration object for this filter. + public void destroy() { + } + + // initialize the filter configuration object for this filter. + public void init(FilterConfig filterConfig) { + this.filterConfig = filterConfig; + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistrations/TestFilter1.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistrations/TestFilter1.java new file mode 100644 index 0000000000..0c8e12a413 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistrations/TestFilter1.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getfilterregistrations; + +import java.io.IOException; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public final class TestFilter1 implements Filter { + + // The filter configuration object we are associated with. If this value + // is null, this filter instance is not currently configured. + private FilterConfig filterConfig; + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + if (filterConfig == null) { + System.out.println( + "doFilter of TestFilter1 was called but this filter instance is not currently configured"); + } else { + System.out.println("TEST_FILTER1_INVOKED"); + } + + chain.doFilter(request, response); + } + + // Remove the filter configuration object for this filter. + public void destroy() { + } + + // initialize the filter configuration object for this filter. + public void init(FilterConfig filterConfig) { + this.filterConfig = filterConfig; + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistrations/TestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistrations/TestListener.java new file mode 100644 index 0000000000..5ce7fc46f5 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistrations/TestListener.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getfilterregistrations; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; + +public class TestListener implements ServletContextListener { + + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce + * The ServletContextEvent + */ + public void contextInitialized(ServletContextEvent sce) { + boolean passed = true; + ServletContext context = sce.getServletContext(); + StringBuilder log = new StringBuilder(); + + try { + context.getFilterRegistrations(); + log.append( + "Expected UnsupportedOperationException not thrown by getFilterRegistrations()."); + passed = false; + } catch (UnsupportedOperationException ex) { + log.append( + "Expected UnsupportedOperationException thrown by getFilterRegistrations()."); + } + + context.setAttribute("TCK_TEST_STATUS", log.toString()); + context.setAttribute("TCK_TEST_PASS_STATUS", passed); + } + + /** + * Receives notification that the Servlet Context is about to be shut down. + * + * @param sce + * The Servlet Context event + */ + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistrations/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistrations/TestServlet.java new file mode 100644 index 0000000000..09b5c3f8ff --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistrations/TestServlet.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getfilterregistrations; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void getFilterRegistrationsTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = true; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + passed = (Boolean) context.getAttribute("TCK_TEST_PASS_STATUS"); + ServletTestUtil.printResult( + pw.append((String) context.getAttribute("TCK_TEST_STATUS")), passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistrations/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistrations/URLClient.java new file mode 100644 index 0000000000..fc2c7cabaf --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistrations/URLClient.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getfilterregistrations; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_sci_getfilterregistrations_web.war") + .addAsResource(URLClient.class.getResource("jakarta.servlet.ServletContainerInitializer"), + "META-INF/services/jakarta.servlet.ServletContainerInitializer") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TCKServletContainerInitializer.class, TestFilter.class, TestFilter1.class, TestListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_sci_getfilterregistrations_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: getFilterRegistrationsTest + * + * @assertion_ids: Servlet:JAVADOC:689.2; + * + * @test_Strategy: Create a ServletContextInitializer, in which, Add a + * ServletContextListener instance using ServletContext.addListener; in the + * ServletContextListener call ServletContext.getFilterRegistrations() Verify + * that UnsupportedOperationException is thrown. + */ + @Test + public void getFilterRegistrationsTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getFilterRegistrationsTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistrations/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistrations/build.xml new file mode 100644 index 0000000000..f21bd6c675 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistrations/build.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistrations/jakarta.servlet.ServletContainerInitializer b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistrations/jakarta.servlet.ServletContainerInitializer new file mode 100644 index 0000000000..b387313385 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistrations/jakarta.servlet.ServletContainerInitializer @@ -0,0 +1 @@ +com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getfilterregistrations.TCKServletContainerInitializer diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistrations/servlet_sci_getfilterregistrations_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistrations/servlet_sci_getfilterregistrations_web.xml new file mode 100644 index 0000000000..3b9487e8c2 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getfilterregistrations/servlet_sci_getfilterregistrations_web.xml @@ -0,0 +1,49 @@ + + + + + SerSCIGETFILTERREGISTRATIONS + + TestFilter + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getfilterregistrations.TestFilter + + + TestFilter + TestServlet + + + TestFilter1 + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getfilterregistrations.TestFilter1 + + + TestFilter1 + TestServlet + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getfilterregistrations.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistration/TCKServletContainerInitializer.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistration/TCKServletContainerInitializer.java new file mode 100644 index 0000000000..0cd3e21e8c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistration/TCKServletContainerInitializer.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getservletregistration; + +import java.util.Set; + +import jakarta.servlet.ServletContainerInitializer; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; + +public class TCKServletContainerInitializer + implements ServletContainerInitializer { + + public void onStartup(Set> arg0, ServletContext context) + throws ServletException { + context.addListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getservletregistration.TestListener.class); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistration/TestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistration/TestListener.java new file mode 100644 index 0000000000..0b418c3c7f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistration/TestListener.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2013, 2021 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getservletregistration; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; + +public class TestListener implements ServletContextListener { + + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce + * The ServletContextEvent + */ + public void contextInitialized(ServletContextEvent sce) { + boolean passed = true; + ServletContext context = sce.getServletContext(); + StringBuilder log = new StringBuilder(); + + try { + context.getServletRegistration( + "com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getservletregistrationtest.TestServlet"); + passed = false; + log.append( + "Expected UnsupportedOperationException not thrown by getServletRegistration(String)."); + } catch (UnsupportedOperationException ex) { + log.append( + "Expected UnsupportedOperationException thrown by getServletRegistration(String)."); + } + + context.setAttribute("TCK_TEST_STATUS", log.toString()); + context.setAttribute("TCK_TEST_PASS_STATUS", passed); + } + + /** + * Receives notification that the Servlet Context is about to be shut down. + * + * @param sce + * The Servlet Context event + */ + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistration/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistration/TestServlet.java new file mode 100644 index 0000000000..7faff70277 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistration/TestServlet.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getservletregistration; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void getServletRegistrationTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = true; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + passed = (Boolean) context.getAttribute("TCK_TEST_PASS_STATUS"); + ServletTestUtil.printResult( + pw.append((String) context.getAttribute("TCK_TEST_STATUS")), passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistration/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistration/URLClient.java new file mode 100644 index 0000000000..e3bf884502 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistration/URLClient.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getservletregistration; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_sci_getservletregistration_web.war") + .addAsResource(URLClient.class.getResource("jakarta.servlet.ServletContainerInitializer"), + "META-INF/services/jakarta.servlet.ServletContainerInitializer") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TCKServletContainerInitializer.class, TestListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_sci_getservletregistration_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: getServletRegistrationTest + * + * @assertion_ids: Servlet:JAVADOC:691.1; + * + * @test_Strategy: Create a ServletContextInitializer, in which, Add a + * ServletContextListener instance using ServletContext.addListener; in the + * ServletContextListener call ServletContext.getServletRegistration(String) + * Verify that UnsupportedOperationException is thrown. + */ + @Test + public void getServletRegistrationTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletRegistrationTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistration/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistration/build.xml new file mode 100644 index 0000000000..4f28c707d8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistration/build.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistration/jakarta.servlet.ServletContainerInitializer b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistration/jakarta.servlet.ServletContainerInitializer new file mode 100644 index 0000000000..4c94c32f25 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistration/jakarta.servlet.ServletContainerInitializer @@ -0,0 +1 @@ +com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getservletregistration.TCKServletContainerInitializer diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistration/servlet_sci_getservletregistration_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistration/servlet_sci_getservletregistration_web.xml new file mode 100644 index 0000000000..0a2e1aad4f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistration/servlet_sci_getservletregistration_web.xml @@ -0,0 +1,33 @@ + + + + + SerSCIGETSERVLETREGISTRATION + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getservletregistration.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistrations/TCKServletContainerInitializer.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistrations/TCKServletContainerInitializer.java new file mode 100644 index 0000000000..770b5a0724 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistrations/TCKServletContainerInitializer.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getservletregistrations; + +import java.util.Set; + +import jakarta.servlet.ServletContainerInitializer; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; + +public class TCKServletContainerInitializer + implements ServletContainerInitializer { + + public void onStartup(Set> arg0, ServletContext context) + throws ServletException { + context.addListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getservletregistrations.TestListener.class); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistrations/TestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistrations/TestListener.java new file mode 100644 index 0000000000..242584a6a8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistrations/TestListener.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2013, 2021 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getservletregistrations; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; + +public class TestListener implements ServletContextListener { + + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce + * The ServletContextEvent + */ + public void contextInitialized(ServletContextEvent sce) { + boolean passed = true; + ServletContext context = sce.getServletContext(); + StringBuilder log = new StringBuilder(); + + try { + context.getServletRegistrations(); + passed = false; + log.append( + "Expected UnsupportedOperationException not thrown by getServletRegistrations()."); + } catch (UnsupportedOperationException ex) { + log.append( + "Expected UnsupportedOperationException thrown by getServletRegistrations()."); + } + + context.setAttribute("TCK_TEST_STATUS", log.toString()); + context.setAttribute("TCK_TEST_PASS_STATUS", passed); + } + + /** + * Receives notification that the Servlet Context is about to be shut down. + * + * @param sce + * The Servlet Context event + */ + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistrations/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistrations/TestServlet.java new file mode 100644 index 0000000000..6ff684702d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistrations/TestServlet.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getservletregistrations; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void getServletRegistrationsTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = true; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + passed = (Boolean) context.getAttribute("TCK_TEST_PASS_STATUS"); + ServletTestUtil.printResult( + pw.append((String) context.getAttribute("TCK_TEST_STATUS")), passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistrations/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistrations/URLClient.java new file mode 100644 index 0000000000..083895a0a6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistrations/URLClient.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getservletregistrations; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_sci_getservletregistrations_web.war") + .addAsResource(URLClient.class.getResource("jakarta.servlet.ServletContainerInitializer"), + "META-INF/services/jakarta.servlet.ServletContainerInitializer") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TCKServletContainerInitializer.class, TestListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_sci_getservletregistrations_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: getServletRegistrationsTest + * + * @assertion_ids: Servlet:JAVADOC:692.2; + * + * @test_Strategy: Create a ServletContextInitializer, in which, Add a + * ServletContextListener instance using ServletContext.addListener; in the + * ServletContextListener call ServletContext.getServletRegistrations() Verify + * that UnsupportedOperationException is thrown. + */ + @Test + public void getServletRegistrationsTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletRegistrationsTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistrations/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistrations/build.xml new file mode 100644 index 0000000000..a38fdc9c61 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistrations/build.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistrations/jakarta.servlet.ServletContainerInitializer b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistrations/jakarta.servlet.ServletContainerInitializer new file mode 100644 index 0000000000..99e6e9db63 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistrations/jakarta.servlet.ServletContainerInitializer @@ -0,0 +1 @@ +com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getservletregistrations.TCKServletContainerInitializer diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistrations/servlet_sci_getservletregistrations_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistrations/servlet_sci_getservletregistrations_web.xml new file mode 100644 index 0000000000..d25816b2d7 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getservletregistrations/servlet_sci_getservletregistrations_web.xml @@ -0,0 +1,33 @@ + + + + + SerSCIGETSERVLETREGISTRATIONS + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getservletregistrations.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getsessioncookieconfig/TCKServletContainerInitializer.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getsessioncookieconfig/TCKServletContainerInitializer.java new file mode 100644 index 0000000000..d771356992 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getsessioncookieconfig/TCKServletContainerInitializer.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getsessioncookieconfig; + +import java.util.Set; + +import jakarta.servlet.ServletContainerInitializer; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; + +public class TCKServletContainerInitializer + implements ServletContainerInitializer { + + public void onStartup(Set> arg0, ServletContext context) + throws ServletException { + context.addListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getsessioncookieconfig.TestListener.class); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getsessioncookieconfig/TestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getsessioncookieconfig/TestListener.java new file mode 100644 index 0000000000..aaf721b826 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getsessioncookieconfig/TestListener.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getsessioncookieconfig; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; + +public class TestListener implements ServletContextListener { + + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce + * The ServletContextEvent + */ + public void contextInitialized(ServletContextEvent sce) { + boolean passed = true; + ServletContext context = sce.getServletContext(); + StringBuilder log = new StringBuilder(); + + try { + context.getSessionCookieConfig(); + passed = false; + log.append("Expected UnsupportedOperationException not thrown."); + } catch (UnsupportedOperationException ex) { + log.append("Expected UnsupportedOperationException thrown."); + } + + context.setAttribute("TCK_TEST_STATUS", log.toString()); + context.setAttribute("TCK_TEST_PASS_STATUS", passed); + } + + /** + * Receives notification that the servlet context is about to be shut down. + * + * @param sce + * The servlet context event + */ + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getsessioncookieconfig/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getsessioncookieconfig/TestServlet.java new file mode 100644 index 0000000000..916d6ac794 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getsessioncookieconfig/TestServlet.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getsessioncookieconfig; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void getSessionCookieConfigTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = true; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + passed = (Boolean) context.getAttribute("TCK_TEST_PASS_STATUS"); + ServletTestUtil.printResult( + pw.append((String) context.getAttribute("TCK_TEST_STATUS")), passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getsessioncookieconfig/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getsessioncookieconfig/URLClient.java new file mode 100644 index 0000000000..93dcfbb1ea --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getsessioncookieconfig/URLClient.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getsessioncookieconfig; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_sci_getsessioncookieconfig_web.war") + .addAsResource(URLClient.class.getResource("jakarta.servlet.ServletContainerInitializer"), + "META-INF/services/jakarta.servlet.ServletContainerInitializer") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TCKServletContainerInitializer.class, TestListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_sci_getsessioncookieconfig_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: getSessionCookieConfigTest + * + * @assertion_ids: Servlet:JAVADOC:693.2; + * + * @test_Strategy: Create a ServletContextInitializer, in which, Add a + * ServletContextListener instance using ServletContext.addListener; in the + * ServletContextListener call ServletContext.getSessionCookieConfig() Verify + * that UnsupportedOperationException is thrown. + */ + @Test + public void getSessionCookieConfigTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getSessionCookieConfigTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getsessioncookieconfig/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getsessioncookieconfig/build.xml new file mode 100644 index 0000000000..fc909e906e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getsessioncookieconfig/build.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getsessioncookieconfig/jakarta.servlet.ServletContainerInitializer b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getsessioncookieconfig/jakarta.servlet.ServletContainerInitializer new file mode 100644 index 0000000000..a7e1004bf1 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getsessioncookieconfig/jakarta.servlet.ServletContainerInitializer @@ -0,0 +1 @@ +com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getsessioncookieconfig.TCKServletContainerInitializer diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getsessioncookieconfig/servlet_sci_getsessioncookieconfig_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getsessioncookieconfig/servlet_sci_getsessioncookieconfig_web.xml new file mode 100644 index 0000000000..b469eeef60 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/getsessioncookieconfig/servlet_sci_getsessioncookieconfig_web.xml @@ -0,0 +1,33 @@ + + + + + SerSCIGETSESSIONCOOKIECONFIG + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.getsessioncookieconfig.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setinitparameter/TCKServletContainerInitializer.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setinitparameter/TCKServletContainerInitializer.java new file mode 100644 index 0000000000..f72b6672f2 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setinitparameter/TCKServletContainerInitializer.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.setinitparameter; + +import java.util.Set; + +import jakarta.servlet.ServletContainerInitializer; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; + +public class TCKServletContainerInitializer + implements ServletContainerInitializer { + + public void onStartup(Set> arg0, ServletContext context) + throws ServletException { + context.addListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.setinitparameter.TestListener.class); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setinitparameter/TestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setinitparameter/TestListener.java new file mode 100644 index 0000000000..92a6d9ccbd --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setinitparameter/TestListener.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2013, 2021 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.setinitparameter; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; + +public class TestListener implements ServletContextListener { + + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce + * The ServletContextEvent + */ + public void contextInitialized(ServletContextEvent sce) { + boolean passed = true; + ServletContext context = sce.getServletContext(); + StringBuilder log = new StringBuilder(); + + try { + context.setInitParameter("abc", "xyz"); + passed = false; + log.append( + "Expected UnsupportedOperationException not thrown by setinitparameter(String, String)."); + } catch (UnsupportedOperationException ex) { + log.append( + "Expected UnsupportedOperationException thrown by setinitparameter(String, String)."); + } + + context.setAttribute("TCK_TEST_STATUS", log.toString()); + context.setAttribute("TCK_TEST_PASS_STATUS", passed); + } + + /** + * Receives notification that the Servlet Context is about to be shut down. + * + * @param sce + * The Servlet Context event + */ + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setinitparameter/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setinitparameter/TestServlet.java new file mode 100644 index 0000000000..763911a1cd --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setinitparameter/TestServlet.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.setinitparameter; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void setInitParameterTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = true; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + passed = (Boolean) context.getAttribute("TCK_TEST_PASS_STATUS"); + ServletTestUtil.printResult( + pw.append((String) context.getAttribute("TCK_TEST_STATUS")), passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setinitparameter/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setinitparameter/URLClient.java new file mode 100644 index 0000000000..79a3054578 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setinitparameter/URLClient.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.setinitparameter; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_sci_setinitparameter_web.war") + .addAsResource(URLClient.class.getResource("jakarta.servlet.ServletContainerInitializer"), + "META-INF/services/jakarta.servlet.ServletContainerInitializer") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TCKServletContainerInitializer.class, TestListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_sci_setinitparameter_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: setInitParameterTest + * + * @assertion_ids: Servlet:JAVADOC:694.2; + * + * @test_Strategy: Create a ServletContextInitializer, in which, Add a + * ServletContextListener instance using ServletContext.addListener; in the + * ServletContextListener call ServletContext.setInitParameter(String, String) + * Verify that UnsupportedOperationException is thrown. + */ + @Test + public void setInitParameterTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setInitParameterTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setinitparameter/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setinitparameter/build.xml new file mode 100644 index 0000000000..61707cb4a0 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setinitparameter/build.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setinitparameter/jakarta.servlet.ServletContainerInitializer b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setinitparameter/jakarta.servlet.ServletContainerInitializer new file mode 100644 index 0000000000..89759dafa6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setinitparameter/jakarta.servlet.ServletContainerInitializer @@ -0,0 +1 @@ +com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.setinitparameter.TCKServletContainerInitializer diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setinitparameter/servlet_sci_setinitparameter_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setinitparameter/servlet_sci_setinitparameter_web.xml new file mode 100644 index 0000000000..9a42c17318 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setinitparameter/servlet_sci_setinitparameter_web.xml @@ -0,0 +1,33 @@ + + + + + SerSCISETINITPARAMETER + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.setinitparameter.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setsessiontrackingmodes/TCKServletContainerInitializer.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setsessiontrackingmodes/TCKServletContainerInitializer.java new file mode 100644 index 0000000000..21271f96fb --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setsessiontrackingmodes/TCKServletContainerInitializer.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.setsessiontrackingmodes; + +import java.util.Set; + +import jakarta.servlet.ServletContainerInitializer; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; + +public class TCKServletContainerInitializer + implements ServletContainerInitializer { + + public void onStartup(Set> arg0, ServletContext context) + throws ServletException { + context.addListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.setsessiontrackingmodes.TestListener.class); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setsessiontrackingmodes/TestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setsessiontrackingmodes/TestListener.java new file mode 100644 index 0000000000..084b9efcfb --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setsessiontrackingmodes/TestListener.java @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.setsessiontrackingmodes; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.concurrent.CopyOnWriteArrayList; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; +import jakarta.servlet.SessionTrackingMode; + +public class TestListener implements ServletContextListener { + + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce + * The ServletContextEvent + */ + public void contextInitialized(ServletContextEvent sce) { + boolean passed = true; + ServletContext context = sce.getServletContext(); + StringBuilder log = new StringBuilder(); + + List complete = new CopyOnWriteArrayList(); + complete.add(SessionTrackingMode.COOKIE); + Set complete_set = new HashSet(complete); + + try { + context.setSessionTrackingModes(complete_set); + passed = false; + log.append("Expected UnsupportedOperationException not thrown."); + } catch (UnsupportedOperationException ex) { + log.append("Expected UnsupportedOperationException thrown."); + } + + complete.remove(SessionTrackingMode.COOKIE); + complete.add(SessionTrackingMode.URL); + complete_set = new HashSet(complete); + + try { + context.setSessionTrackingModes(complete_set); + passed = false; + log.append("Expected UnsupportedOperationException not thrown."); + } catch (UnsupportedOperationException ex) { + log.append("Expected UnsupportedOperationException thrown."); + } + + complete.add(SessionTrackingMode.COOKIE); + complete_set = new HashSet(complete); + + try { + context.setSessionTrackingModes(complete_set); + passed = false; + log.append("Expected UnsupportedOperationException not thrown."); + } catch (UnsupportedOperationException ex) { + log.append("Expected UnsupportedOperationException thrown."); + } + + complete.add(SessionTrackingMode.SSL); + complete.remove(SessionTrackingMode.URL); + complete.remove(SessionTrackingMode.COOKIE); + complete_set = new HashSet(complete); + + try { + context.setSessionTrackingModes(complete_set); + passed = false; + log.append("Expected UnsupportedOperationException not thrown."); + } catch (UnsupportedOperationException ex) { + log.append("Expected UnsupportedOperationException thrown."); + } + + context.setAttribute("TCK_TEST_STATUS", log.toString()); + context.setAttribute("TCK_TEST_PASS_STATUS", passed); + } + + /** + * Receives notification that the servlet context is about to be shut down. + * + * @param sce + * The servlet context event + */ + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setsessiontrackingmodes/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setsessiontrackingmodes/TestServlet.java new file mode 100644 index 0000000000..cc8a27fcb4 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setsessiontrackingmodes/TestServlet.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.setsessiontrackingmodes; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void setSessionTrackingModesTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = true; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + passed = (Boolean) context.getAttribute("TCK_TEST_PASS_STATUS"); + ServletTestUtil.printResult( + pw.append((String) context.getAttribute("TCK_TEST_STATUS")), passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setsessiontrackingmodes/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setsessiontrackingmodes/URLClient.java new file mode 100644 index 0000000000..2973eda701 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setsessiontrackingmodes/URLClient.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.setsessiontrackingmodes; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_sci_setsessiontrackingmode_web.war") + .addAsResource(URLClient.class.getResource("jakarta.servlet.ServletContainerInitializer"), + "META-INF/services/jakarta.servlet.ServletContainerInitializer") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TCKServletContainerInitializer.class, TestListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_sci_setsessiontrackingmode_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: setSessionTrackingModesTest + * + * @assertion_ids: Servlet:JAVADOC:695.1; + * + * @test_Strategy: Create a ServletContextInitializer, in which, Add a + * ServletContextListener instance using ServletContext.addListener; in the + * ServletContextListener call ServletContext.setSessionTrackingModes(Set) + * Verify that UnsupportedOperationException is thrown. + */ + @Test + public void setSessionTrackingModesTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setSessionTrackingModesTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setsessiontrackingmodes/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setsessiontrackingmodes/build.xml new file mode 100644 index 0000000000..654a041be9 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setsessiontrackingmodes/build.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setsessiontrackingmodes/jakarta.servlet.ServletContainerInitializer b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setsessiontrackingmodes/jakarta.servlet.ServletContainerInitializer new file mode 100644 index 0000000000..e06e5c8b15 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setsessiontrackingmodes/jakarta.servlet.ServletContainerInitializer @@ -0,0 +1 @@ +com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.setsessiontrackingmodes.TCKServletContainerInitializer diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setsessiontrackingmodes/servlet_sci_setsessiontrackingmode_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setsessiontrackingmodes/servlet_sci_setsessiontrackingmode_web.xml new file mode 100644 index 0000000000..b81ee2f7af --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/scinitializer/setsessiontrackingmodes/servlet_sci_setsessiontrackingmode_web.xml @@ -0,0 +1,33 @@ + + + + + SerSCISETSessionTrackingMode + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.scinitializer.setsessiontrackingmodes.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sclistener/ContextListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sclistener/ContextListener.java new file mode 100644 index 0000000000..e215d637a7 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sclistener/ContextListener.java @@ -0,0 +1,93 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.sclistener; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; + +public final class ContextListener implements ServletContextListener { + + // The servlet context with which we are associated. + private ServletContext context = null; + + public void contextDestroyed(ServletContextEvent event) { + createAttribute("ContextDestroyed"); + this.context = null; + } + + public void contextInitialized(ServletContextEvent event) { + this.context = event.getServletContext(); + createAttribute("ContextInitialized"); + } + + private void createAttribute(String s) { + String tmp = null; + Object o = context.getAttribute("ContextListener"); + if (o != null) { + if (o instanceof String) { + tmp = (String) o + s; + } + } else { + tmp = s; + } + context.setAttribute("ContextListener", tmp); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sclistener/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sclistener/TestServlet.java new file mode 100644 index 0000000000..4fd274a7b8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sclistener/TestServlet.java @@ -0,0 +1,104 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.sclistener; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void contextInitializedTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + + String expected = "ContextInitialized"; + ServletConfig config = getServletConfig(); + ServletContext context = config.getServletContext(); + Object o = context.getAttribute("ContextListener"); + if (o != null) { + if (o instanceof String) { + String actual = (String) o; + if (actual.equals(expected)) { + ServletTestUtil.printResult(pw, true); + } else { + ServletTestUtil.printResult(pw, false); + pw.println("expected=" + expected); + pw.println("actual=" + actual); + } + } else { + ServletTestUtil.printResult(pw, false); + pw.println("Object returned was not and instance of String"); + } + } else { + ServletTestUtil.printResult(pw, false); + + pw.println("ContextListener attribute not found"); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sclistener/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sclistener/URLClient.java new file mode 100644 index 0000000000..8357750f7b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sclistener/URLClient.java @@ -0,0 +1,71 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.sclistener; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + + +public class URLClient extends AbstractUrlClient { + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_sclistener_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestServlet.class, ContextListener.class) + .setWebXML(URLClient.class.getResource("servlet_js_sclistener_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: contextInitializedTest + * + * @assertion_ids: Servlet:JAVADOC:214 + * + * @test_Strategy: A ServletContext Listener is deployed and the listener + * write a message indicating so to a static log. The servlet reads the log + * and verifies the result + */ + @Test + public void contextInitializedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "contextInitializedTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sclistener/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sclistener/build.xml new file mode 100644 index 0000000000..709261f0ab --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sclistener/build.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sclistener/servlet_js_sclistener_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sclistener/servlet_js_sclistener_web.xml new file mode 100644 index 0000000000..39b934fa53 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sclistener/servlet_js_sclistener_web.xml @@ -0,0 +1,36 @@ + + + + + SerJaxSerSerContextListen + + com.sun.ts.tests.servlet.api.jakarta_servlet.sclistener.ContextListener + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.sclistener.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sclistener40/SCListener40.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sclistener40/SCListener40.java new file mode 100644 index 0000000000..67fdfd86b7 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sclistener40/SCListener40.java @@ -0,0 +1,64 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2017, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.sclistener40; + +import jakarta.servlet.ServletContextListener; + +public final class SCListener40 implements ServletContextListener { +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sclistener40/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sclistener40/TestServlet.java new file mode 100644 index 0000000000..49c28ceae9 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sclistener40/TestServlet.java @@ -0,0 +1,80 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.sclistener40; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void defaultMethodsTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + pw.println("In ServletContextListener40.TestServlet"); + ServletTestUtil.printResult(pw, true); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sclistener40/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sclistener40/URLClient.java new file mode 100644 index 0000000000..bfc29ab264 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sclistener40/URLClient.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2017, 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: URLClient.java 62571 2011-04-18 20:58:13Z kgrucci $ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.sclistener40; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_sclistener40_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestServlet.class, SCListener40.class) + .setWebXML(URLClient.class.getResource("servlet_js_sclistener40_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: defaultMethodsTest + * + * @assertion_ids: NA; + * + * @test_Strategy: Client successfully calls a servlet with an empty + * ServletContext listener implementation class. + * + */ + @Test + public void defaultMethodsTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "defaultMethodsTest"); + invoke(); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sclistener40/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sclistener40/build.xml new file mode 100644 index 0000000000..786de1673d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sclistener40/build.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sclistener40/servlet_js_sclistener40_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sclistener40/servlet_js_sclistener40_web.xml new file mode 100644 index 0000000000..f5dcc8aef7 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sclistener40/servlet_js_sclistener40_web.xml @@ -0,0 +1,36 @@ + + + + + SerJaxSerSerContextListen40 + + com.sun.ts.tests.servlet.api.jakarta_servlet.sclistener40.SCListener40 + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.sclistener40.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servlet/CoreServletTest.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servlet/CoreServletTest.java new file mode 100644 index 0000000000..64b59a89ce --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servlet/CoreServletTest.java @@ -0,0 +1,109 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 1999, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servlet; + +import java.io.IOException; + +import jakarta.servlet.Servlet; +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public abstract class CoreServletTest implements Servlet { + + ServletConfig config; + + private boolean sawInit = false; + + private boolean sawDestroy = false; + + // for life cycle test + public boolean isInit() { + return sawInit; + } + + // for life cycle test + public boolean isDestroyed() { + return this.sawDestroy; + } + + public void init(ServletConfig config) throws ServletException { + // set sawInit to true + this.sawInit = true; + this.config = config; + } + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + } + + public String getServletInfo() { + return "Servlet Info"; + } + + public ServletConfig getServletConfig() { + return this.config; + } + + public void destroy() { + // set sawDestroy to true + this.sawDestroy = true; + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servlet/DoDestroyedTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servlet/DoDestroyedTestServlet.java new file mode 100644 index 0000000000..f639cfe1c0 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servlet/DoDestroyedTestServlet.java @@ -0,0 +1,99 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +/** + * Test for destroy Method + */ + +public class DoDestroyedTestServlet extends CoreServletTest { + + /** + * Testing that destroy method is not called during service method execution + * + */ + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + // checking whether destroy is called before this + boolean passed = false; + PrintWriter pw = response.getWriter(); + + if (isDestroyed()) { + passed = false; + pw.println( + "Servlet Life Cycle is incorrect. destroy is called before/during the service method"); + + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servlet/DoInit1TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servlet/DoInit1TestServlet.java new file mode 100644 index 0000000000..5ae7387ba4 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servlet/DoInit1TestServlet.java @@ -0,0 +1,99 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +/* @Author : Ramesh.Mandava +*/ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.UnavailableException; + +/** + * Negative Test for Servlet.init(ServletConfig) method + */ + +public class DoInit1TestServlet extends CoreServletTest { + + /** + * We will throw UnavailableException from inside init The Servlet should not + * be initialized + */ + + public void init(ServletConfig sc) throws ServletException { + // throw new UnavailableException(this,"Negative Init Test"); + throw new UnavailableException("Negative Init Test"); + } + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + pw.println( + "service method getting called even when we throw UnavailableException in init()"); + ServletTestUtil.printResult(pw, false); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servlet/DoInit2TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servlet/DoInit2TestServlet.java new file mode 100644 index 0000000000..017adb7a00 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servlet/DoInit2TestServlet.java @@ -0,0 +1,96 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +/** + * Test for Servlet.init() method + */ + +public class DoInit2TestServlet extends CoreServletTest { + + /** + * inside coreServletTest we are implementing init(ServletConfig) and setting + * a bool var to true we'll check for that here + */ + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + boolean passed = false; + PrintWriter pw = response.getWriter(); + // isInit() should return true + if (isInit()) { + passed = true; + } else { + // problem with LifeCycle + passed = false; + pw.println("Problem with Servlet LifeCycle"); + pw.println("init not called before service"); + } + ServletTestUtil.printResult(pw, passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servlet/DoServiceTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servlet/DoServiceTestServlet.java new file mode 100644 index 0000000000..a2b16f892c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servlet/DoServiceTestServlet.java @@ -0,0 +1,111 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + * * @Author : Ramesh.Mandava + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +/** + * A Test for service(ServletRequest,ServletResponse) method + */ + +public class DoServiceTestServlet extends CoreServletTest { + + /** + * We1'll override init method and assign some value to the String We'll check + * for that value in the service method + */ + + String precedence = "starting"; + + public void init(ServletConfig sc) throws ServletException { + + super.init(sc); + precedence = "init is called"; + } + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + PrintWriter pw = response.getWriter(); + String expectedResult = "init is called"; + String result = precedence; + + if (result.equals(expectedResult)) { + passed = true; + } else { + passed = false; + pw.println("Problem with Servlet life cycle"); + pw.println("init is not called before service"); + pw.println("Expected precedence = " + expectedResult); + pw.println("Actual precedence = " + result); + } + ServletTestUtil.printResult(pw, passed); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servlet/DoServletConfigTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servlet/DoServletConfigTestServlet.java new file mode 100644 index 0000000000..e144a8ab88 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servlet/DoServletConfigTestServlet.java @@ -0,0 +1,113 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + * * @Author : Ramesh.Mandava + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +/** + * A Test for getServletConfig method + */ + +public class DoServletConfigTestServlet extends CoreServletTest { + + /** + * getServletConfig gives the ServletConfig object that is passed to the init + * method by the engine + */ + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + PrintWriter pw = response.getWriter(); + String expectedResult = "Java"; + ServletConfig sc = getServletConfig(); + + if (getServletConfig() != null) { + String result = sc.getInitParameter("Language"); + + if (result.equals(expectedResult)) { + passed = true; + } else { + passed = false; + pw.println( + "getInitParameter(Language) did not return the correct parameter name"); + pw.println("Expected result = " + expectedResult); + pw.println("Actual result = " + result); + } + + } else { + passed = false; + pw.println("getServletConfig returned null?"); + + } + ServletTestUtil.printResult(pw, passed); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servlet/DoServletInfoTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servlet/DoServletInfoTestServlet.java new file mode 100644 index 0000000000..3eb5ab1fc4 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servlet/DoServletInfoTestServlet.java @@ -0,0 +1,97 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class DoServletInfoTestServlet extends CoreServletTest { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + PrintWriter pw = response.getWriter(); + String expectedResult = "Servlet Info"; + + if (getServletInfo() != null) { + String result = getServletInfo(); + + if (result.equals(expectedResult)) { + passed = true; + } else { + passed = false; + pw.println("getServletInfo() returned an incorrect result"); + pw.println("Expected result = " + expectedResult); + pw.println("Actual result = " + result); + } + } else { + passed = false; + pw.println("getServletInfo() returned a null result"); + } + ServletTestUtil.printResult(pw, passed); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servlet/PUTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servlet/PUTestServlet.java new file mode 100644 index 0000000000..c1773e825a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servlet/PUTestServlet.java @@ -0,0 +1,101 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.UnavailableException; + +public class PUTestServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + PrintWriter pw = response.getWriter(); + try { + throw new UnavailableException( + "Throwing Permanent unavailable Exception "); + } catch (Throwable t) { + if (t instanceof UnavailableException) { + if (((UnavailableException) t).isPermanent() == true) { + passed = true; + } else { + passed = false; + pw.println( + "isPermanent() method is returing false for Permanent Unavailable Exception"); + } + } else { + passed = false; + pw.println( + "Exception thrown, but was not an instance of UnavailableException."); + pw.println("instead received: " + t.getClass().getName()); + } + } + ServletTestUtil.printResult(pw, passed); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servlet/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servlet/URLClient.java new file mode 100644 index 0000000000..8fa835b22d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servlet/URLClient.java @@ -0,0 +1,154 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servlet; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_servlet_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(CoreServletTest.class, DoDestroyedTestServlet.class, DoInit1TestServlet.class, + DoInit2TestServlet.class, DoServiceTestServlet.class, DoServletConfigTestServlet.class, + DoServletInfoTestServlet.class, PUTestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_js_servlet_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + + /* + * @testName: DoDestroyedTest + * + * @assertion_ids: Servlet:SPEC:5; Servlet:SPEC:6; + * + * @test_Strategy: Testing that destroy method is not called during service + * method execution + */ + @Test + public void DoDestroyedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "DoDestroyedTest"); + invoke(); + } + + /* + * @testName: DoInit1Test + * + * @assertion_ids: Servlet:SPEC:5; Servlet:SPEC:6; Servlet:SPEC:8; + * Servlet:JAVADOC:265; Servlet:SPEC:11; Servlet:SPEC:11.1; + * + * @test_Strategy: Validate a 404 is returned to the client if a permanent + * UnavailableException is thrown during servlet initialization. + */ + @Test + public void DoInit1Test() throws Exception { + TEST_PROPS.setProperty(TEST_NAME, "DoInit1Test"); + TEST_PROPS.setProperty(REQUEST, + "GET /servlet_js_servlet_web/DoInit1Test HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, NOT_FOUND); + invoke(); + } + + /* + * @testName: DoInit2Test + * + * @assertion_ids: Servlet:SPEC:5; Servlet:SPEC:6; Servlet:JAVADOC:263; + * + * @test_Strategy: Inside CoreServletTest, which is the parent servlet, we are + * implementing init() and setting a boolean variable to true. We'll check for + * the variables here in the DoInit2Test + */ + @Test + public void DoInit2Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "DoInit2Test"); + invoke(); + } + + /* + * @testName: DoServletConfigTest + * + * @assertion_ids: Servlet:SPEC:5; Servlet:SPEC:6; Servlet:JAVADOC:266; + * + * @test_Strategy: Create a servlet and test for the getServletConfig() method + * to be a non-null value and an initial paramter can be retrieved + */ + @Test + public void DoServletConfigTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "DoServletConfigTest"); + invoke(); + } + + /* + * @testName: DoServletInfoTest + * + * @assertion_ids: Servlet:SPEC:5; Servlet:SPEC:6; Servlet:JAVADOC:270; + * + * @test_Strategy: Create a servlet and test that information is returned + */ + @Test + public void DoServletInfoTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "DoServletInfoTest"); + invoke(); + } + + /* + * @testName: PUTest + * + * @assertion_ids: Servlet:SPEC:5; Servlet:SPEC:6; Servlet:JAVADOC:5; + * + * @test_Strategy: Create a servlet, throw UnavailableException and test if + * isPermanent() method is true + */ + @Test + public void PUTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "PUTest"); + invoke(); + } + + /* + * @testName: DoServiceTest + * + * @assertion_ids: Servlet:SPEC:5; Servlet:SPEC:6; Servlet:JAVADOC:263; + * Servlet:JAVADOC:267; + * + * @test_Strategy: Inside CoreServletTest, which is the parent servlet, we + * will override init method and assign some value to the String. We'll check + * for that value in the service method + */ + @Test + public void DoServiceTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "DoServiceTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servlet/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servlet/build.xml new file mode 100644 index 0000000000..85cf3e0b6a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servlet/build.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servlet/servlet_js_servlet_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servlet/servlet_js_servlet_web.xml new file mode 100644 index 0000000000..b901728904 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servlet/servlet_js_servlet_web.xml @@ -0,0 +1,85 @@ + + + + + SerJaxSerServlet + + DoServletInfoTestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.servlet.DoServletInfoTestServlet + + + DoDestroyedTestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.servlet.DoDestroyedTestServlet + + + DoInit2TestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.servlet.DoInit2TestServlet + + + DoServletConfigTestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.servlet.DoServletConfigTestServlet + + Language + Java + + + + PUTestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.servlet.PUTestServlet + + + DoServiceTestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.servlet.DoServiceTestServlet + + + DoInit1TestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.servlet.DoInit1TestServlet + + + DoServletInfoTestLogicalName + /DoServletInfoTest + + + DoDestroyedTestLogicalName + /DoDestroyedTest + + + DoInit2TestLogicalName + /DoInit2Test + + + DoServletConfigTestLogicalName + /DoServletConfigTest + + + PUTestLogicalName + /PUTest + + + DoServiceTestLogicalName + /DoServiceTest + + + DoInit1TestLogicalName + /DoInit1Test + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletconfig/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletconfig/TestServlet.java new file mode 100644 index 0000000000..c867b22476 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletconfig/TestServlet.java @@ -0,0 +1,189 @@ +/* + * Copyright (c) 2009, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletconfig; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Enumeration; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + /** + * getInitParameterNames returns an Enumeration of values associated with the + * init parameters + */ + public void getServletConfigInitParameterNames(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = true; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + Enumeration initP = config.getInitParameterNames(); + + String expectedResult1 = "Team"; + boolean expectedResult1Found = false; + String expectedResult2 = "org"; + boolean expectedResult2Found = false; + + if (initP.hasMoreElements()) { + while (initP.hasMoreElements()) { + String name = (String) initP.nextElement(); + pw.println("Initialization Parameter: " + name); + + if (name.equals(expectedResult1)) { + if (!expectedResult1Found) { + expectedResult1Found = true; + } else { + passed = false; + pw.println( + "getInitParameterNames() method return an attribute name twice"); + pw.println( + "The attribute already specified was " + expectedResult1); + } + } else if (name.equals(expectedResult2)) { + if (!expectedResult2Found) { + expectedResult2Found = true; + } else { + passed = false; + pw.println( + "getInitParameterNames() method return an attribute name twice"); + pw.println( + "The attribute already specified was " + expectedResult2); + } + } + } + + if (!expectedResult1Found && expectedResult2Found) { + passed = false; + pw.println("At least one InitParameter is not returned"); + } + + } else { + passed = false; + pw.println( + "HttpServletRequest.getInitParameterNames() an empty enumeration"); + } + ServletTestUtil.printResult(pw, passed); + } + + /** + * Test for ServletConfig getInitParameter(String) + */ + public void getServletConfigInitParameter(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = false; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + + // Init parameters specified in web.xml for + // GetServletConfigInitParameterTest servlet + String initParam = config.getInitParameter("Team"); + + if (initParam != null) { + if (initParam.equals("WebAccess")) { + passed = true; + } else { + passed = false; + pw.println("getInitParameter(String) gives incorrect results"); + pw.println( + "getInitParameter(String) != 'WebAccess' as specified in web.xml for GetServletConfigInitParameterTest servlet"); + } + } else { + passed = false; + pw.println("getInitParameter(String) is null"); + } + ServletTestUtil.printResult(pw, passed); + } + + /** + * Negative test for ServletConfig getInitParameter(String) + */ + public void getServletConfigInitParameterNull(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = false; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + + // No Init parameter specified anywhere named + // "Nothing_is_set_for_Negative_compatibility_test_only" + String initParam = config.getInitParameter( + "Nothing_is_set_for_Negative_compatibility_test_only"); + + if (initParam != null) { + pw.println("getInitParameter(String) gives incorrect results"); + pw.println("Expecting null; got " + initParam); + } else { + passed = true; + pw.println("getInitParameter(String) is null"); + } + ServletTestUtil.printResult(pw, passed); + } + + public void getServletName(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + boolean passed = false; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + String expected = "TestServlet"; + // get this servlets name + String servletName = config.getServletName(); + + if (servletName.indexOf(expected) > -1) { + passed = true; + } else { + passed = false; + pw.println("getServletName() did not return the correct result:"); + pw.println("Expected Result=" + expected); + pw.println("Actual Result -> " + servletName); + } + ServletTestUtil.printResult(pw, passed); + } + + /** + * We'll try to get the ServletContext for this servlet itself + */ + public void getServletContext(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = false; + PrintWriter pw = response.getWriter(); + String anotherServlet = "/servlet_js_servletconfig_web/TestServlet"; + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + + // we expect ServletContext object that corresponds to the named URL + ServletContext context2 = context.getContext(anotherServlet); + + if ((context2 == context)) { + passed = true; + } else { + passed = true; + pw.println("getServletContext() returned incorrect result"); + } + ServletTestUtil.printResult(pw, passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletconfig/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletconfig/URLClient.java new file mode 100644 index 0000000000..d0d5e12bd6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletconfig/URLClient.java @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2009, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletconfig; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_servletconfig_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_js_servletconfig_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + + /* + * @testName: getServletConfigInitParameterNamesTest + * + * @assertion_ids: Servlet:SPEC:7; Servlet:JAVADOC:266; Servlet:JAVADOC:261; + * + * @test_Strategy: Set init parameters in the web.xml file and check for the + * enumerated values in the servlet. + */ + @Test + public void getServletConfigInitParameterNamesTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletConfigInitParameterNames"); + invoke(); + } + + /* + * @testName: getServletConfigInitParameterTest + * + * @assertion_ids: Servlet:SPEC:7; Servlet:JAVADOC:266; Servlet:JAVADOC:259; + * + * @test_Strategy: Set init parameters in the web.xml file and check for the + * value in the servlet. + */ + @Test + public void getServletConfigInitParameterTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletConfigInitParameter"); + invoke(); + } + + /* + * @testName: getServletConfigInitParameterTestNull + * + * @assertion_ids: Servlet:SPEC:7; Servlet:JAVADOC:266; Servlet:JAVADOC:260; + * + * @test_Strategy: Set No init parameter anywhere named: + * "Nothing_is_set_for_Negative_compatibility_test_only" anywhere and check + * for the Verify that ServletConfig.getInitParameter(name) return null. + */ + @Test + public void getServletConfigInitParameterTestNull() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletConfigInitParameterNull"); + invoke(); + } + + /* + * @testName: getServletContextTest + * + * @assertion_ids: Servlet:SPEC:7; Servlet:JAVADOC:266; Servlet:JAVADOC:258; + * Servlet:JAVADOC:219; + * + * @test_Strategy: Try to get the ServletContext for this servlet itself + */ + @Test + public void getServletContextTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletContext"); + invoke(); + } + + /* + * @testName: getServletNameTest + * + * @assertion_ids: Servlet:SPEC:7; Servlet:JAVADOC:266; Servlet:JAVADOC:257; + * + * @test_Strategy: Try to get the ServletName for this servlet itself + */ + @Test + public void getServletNameTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletName"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletconfig/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletconfig/build.xml new file mode 100644 index 0000000000..ffa69d7228 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletconfig/build.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletconfig/servlet_js_servletconfig_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletconfig/servlet_js_servletconfig_web.xml new file mode 100644 index 0000000000..ab10f4da62 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletconfig/servlet_js_servletconfig_web.xml @@ -0,0 +1,41 @@ + + + + + SerJaxSerServletConfig + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.servletconfig.TestServlet + + Team + WebAccess + + + org + sun + + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext/GetNamedDispatcherTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext/GetNamedDispatcherTestServlet.java new file mode 100644 index 0000000000..2e4b8bb5cd --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext/GetNamedDispatcherTestServlet.java @@ -0,0 +1,65 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +/** + * Test for ServletContext.getNamedDispatcher(String) method + */ + +public class GetNamedDispatcherTestServlet extends GenericServlet { + + /** + * We will try to get the RequestDispatcher for the servlet Registered as + * config + */ + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + + String path = "GetNamedDispatcherTest"; + RequestDispatcher rd = context.getNamedDispatcher(path); + + if (rd != null) { + passed = true; + } else { + passed = false; + } + ServletTestUtil.printResult(pw, passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext/TestServlet.java new file mode 100644 index 0000000000..f7bdb3be31 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext/TestServlet.java @@ -0,0 +1,991 @@ +/* + * Copyright (c) 2009, 2021 Oracle and/or its affiliates and others. + * 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintWriter; +import java.net.URL; +import java.util.Enumeration; +import java.util.Iterator; +import java.util.Set; +import java.util.Vector; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.Data; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + /** + * Test for ServletContext.getMajorVersion method + */ + public void getMajorVersion(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + boolean passed = false; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + + // Version should be 6 for Servlet 6.0 release + if (context.getMajorVersion() == 6) { + passed = true; + } else { + passed = false; + pw.println("getMajorVersion() returned " + context.getMajorVersion()); + pw.println("Expected ServletContext.getMajorVersion() -> 6 "); + } + ServletTestUtil.printResult(pw, passed); + } + + /** + * Test for ServletContext.getMinorVersion method + */ + public void getMinorVersion(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + boolean passed = false; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + int expectedResult = 0; + int result = context.getMinorVersion(); + + if (result == expectedResult) { + passed = true; + } else { + passed = false; + pw.println("getMinorVersion() returned incorrect result"); + pw.println("Expected result = " + expectedResult + " "); + pw.println("Actual result = " + result + " "); + } + ServletTestUtil.printResult(pw, passed); + } + + private static final String EXPECTED_MIME_TYPE = "application/x-java-class"; + + private static final String MIME_OBJECT = "/WEB-INF/classes/tests/jakarta_servlet/ServletContext/GetMimeTypeTestServlet.class"; + + public void getMimeType(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + boolean passed = false; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + + ServletContext context = config.getServletContext(); + String result = context.getMimeType(MIME_OBJECT); + + if (result != null) { + if (result.equals(EXPECTED_MIME_TYPE)) { + passed = true; + } else { + passed = false; + pw.println("getMimeType(" + MIME_OBJECT + + ") returned incorrect result\n\t" + "Expected result = " + + EXPECTED_MIME_TYPE + "\n\t" + "Actual result = " + result); + } + } else { + passed = false; + pw.println("getMimeType( " + MIME_OBJECT + " ) returned a null result\n\t" + + "Expected result = " + EXPECTED_MIME_TYPE); + } + ServletTestUtil.printResult(pw, passed); + } + + /** + * A Negative Test for ServletContext.getMimeType(String) method + */ + /** + * We set improper mime type We should get null as the result + */ + public void getMimeType_1(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + boolean passed = false; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + + ServletContext context = config.getServletContext(); + + // abraca.dabra? i hope there is no such mime type so far + String param = "/META-INF/MANIFEST.MF"; + String mimeType = context.getMimeType(param); + + if (mimeType == null) { + passed = true; + } else { + passed = false; + pw.println("getMimeType(" + param + ") did not return null"); + pw.println("Actual result = " + mimeType + " "); + } + ServletTestUtil.printResult(pw, passed); + } + + /** + * Test for ServletContext.getRealPath(String) method + */ + public void getRealPath(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + boolean passed = true; + PrintWriter pw = response.getWriter(); + + String path = "/servlet_js_ServletContext/Test"; + String win32Path = new StringBuffer(45).append(File.separatorChar) + .append("servlet_js_ServletContext").append(File.separatorChar) + .append("Test").toString(); + + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + + String realPath = context.getRealPath(path); + // a null will be returned if running directly from a jar file + if ((realPath == null) || (realPath.indexOf(path) > -1) || // UNIX path + (realPath.indexOf(win32Path) > -1)) // Win32 path + { + pw.println("realPath = " + realPath); + } else { + passed = false; + pw.println("getRealPath(" + path + ") did not contain the named files"); + pw.println("Actual result = " + realPath + " "); + } + + // Leading '/' is optional. Ensure the result is the same with or without it + String pathNoSolidus = path.substring(1); + String realPathNoSolidus = context.getRealPath(pathNoSolidus); + + if (realPath == null && realPathNoSolidus == null || + realPath != null && realPath.equals(realPathNoSolidus)) { + pw.println("realPathNoSolidus = " + realPathNoSolidus); + } else { + passed = false; + pw.println("getRealPath(" + path + ") returned [" + realPath + "]"); + pw.println("getRealPath(" + pathNoSolidus + ") returned [" + realPathNoSolidus + "]"); + pw.println("The return values should be the same"); + } + ServletTestUtil.printResult(pw, passed); + } + + /** + * Test for ServletContext.getResourcePaths(String) method + */ + public void getResourcePaths(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + boolean passed = false; + PrintWriter pw = response.getWriter(); + + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + Iterator resources = null; + String tmp = null; + + String path = "/WEB-INF/"; + Set realPath = context.getResourcePaths(path); + pw.println("GetResourcePathsTest: Start test for path=" + path); + if (realPath != null) { + if (!realPath.isEmpty()) { + resources = realPath.iterator(); + + tmp = (String) resources.next(); + pw.println("GetResourcePathsTest: " + tmp); + while (resources.hasNext()) { + pw.println("GetResourcePathsTest: " + resources.next()); + } + } else { + passed = false; + } + } else { + passed = false; + pw.println("GetResourcePathsTest: returned null resourcepath"); + } + + path = "/WEB-INF/classes/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext/"; + realPath = context.getResourcePaths(path); + pw.println("GetResourcePathsTest: Start test for path=" + path); + if (realPath != null) { + if (!realPath.isEmpty()) { + resources = realPath.iterator(); + + tmp = (String) resources.next(); + pw.println("GetResourcePathsTest: " + tmp); + while (resources.hasNext()) { + pw.println("GetResourcePathsTest: " + resources.next()); + } + } else { + passed = false; + pw.println("Error: missing contents"); + } + } else { + passed = false; + pw.println("Error: null resourcepath"); + } + ServletTestUtil.printResult(pw, passed); + } + + /** + * A Test for getResourceAs Stream method + */ + public void getResourceAsStream(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = false; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + + // get this servlet itself + + String path = "/WEB-INF/web.xml"; + + InputStream in = context.getResourceAsStream(path); + + if (in != null) { + passed = true; + } else { + passed = false; + pw.println("getResourceAsStream(" + path + ") returned a null"); + } + ServletTestUtil.printResult(pw, passed); + } + + /** + * A Negative Test for ServletContext.getResourceAsStream(String) + */ + /** + * We will supply a non existent URL and should get null + */ + public void getResourceAsStream_1(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = false; + PrintWriter pw = response.getWriter(); + + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + + // dummy URL + + String path = "/dummy"; + + InputStream in = context.getResourceAsStream(path); + + if (in == null) { + passed = true; + } else { + passed = false; + pw.println("getResourceAsStream(" + path + ") returned a non-null "); + } + ServletTestUtil.printResult(pw, passed); + } + + /** + * We will use this servlet itself as a resource + */ + public void getResource(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + PrintWriter pw = response.getWriter(); + + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + + String path = "/WEB-INF/web.xml"; + + URL resourceURL = context.getResource(path); + + if (resourceURL != null) { + String result = resourceURL.toString(); + + if (result.indexOf(path) > -1) { + passed = true; + } else { + passed = false; + pw.println("Could not locate " + path + " in the returned URL"); + pw.println("Actual result = " + result + " "); + } + } else { + passed = false; + pw.println("getResource(" + path + ") returned a null"); + } + ServletTestUtil.printResult(pw, passed); + } + + /** + * A Negative Test for ServletContext.getResourse(String) method We will give + * a fake URL we should get null + */ + public void getResource_1(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + + String path = "/doesnotexist"; + + URL resourceURL = context.getResource(path); + + if (resourceURL == null) { + passed = true; + } else { + passed = false; + pw.println("ServletContext.getResource(" + path + + ") did not return correct result"); + pw.println("Expected result = null"); + pw.println("Actual result = |" + resourceURL + "|"); + } + ServletTestUtil.printResult(pw, passed); + } + + /** + * A Negative Test for ServletContext.getResource(String path) We get + * MalformedURLException if path does not start with /. + */ + public void getResource_2(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + + try { + URL resourceURL = context.getResource("invalid/contextPath"); + + passed = false; + pw.println("Test FAILED. Expected a MalformedURLException to " + + "be thrown when ServletContext.getResource(String) " + + " is provided a value that does not start with a '/'"); + } catch (java.net.MalformedURLException ex) { + passed = true; + pw.println("GetResource_2Test " + Data.PASSED); + pw.println("Expected java.net.MalformedURLException to be thrown"); + } catch (Throwable t) { + passed = false; + pw.println("GetResource_2Test " + Data.FAILED); + pw.println("Unexpected Exception is thrown: " + t.toString()); + } + ServletTestUtil.printResult(pw, passed); + } + + /** + * Test for ServletContext.getAttribute(String) method + */ + public void servletContextGetAttribute(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + boolean passed = false; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + + ServletContext context = config.getServletContext(); + String param = "ManKind"; + String param2 = "humane"; + // set attribute + context.setAttribute(param, param2); + + // then get attribute + Object attr = context.getAttribute(param); + + if (attr != null) { + // attr should also be an instance of java.lang.String + if (attr.getClass().getName().equals("java.lang.String")) { + String sAttr = (String) attr; + + if (sAttr.equals(param2)) { + passed = true; + } else { + passed = false; + pw.println("getAttribute(" + param + ") returned incorrect results"); + pw.println("Expected result = " + param2 + " "); + pw.println("Actual result = |" + sAttr + "| "); + } + } else { + passed = false; + pw.println("getAttribute(" + param + + ") did not return an attribute of type String"); + } + } else { + passed = false; + pw.println("getAttribute(" + param + ") returned a null result "); + } + ServletTestUtil.printResult(pw, passed); + } + + /** + * A Negative Test for ServletContext.getAttribute(String) method + */ + /** + * We'll try to get the associated value for a non existent attribute name. We + * should get null as the result + */ + public void servletContextGetAttribute_1(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = false; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + + ServletContext context = config.getServletContext(); + Object attr = context.getAttribute("Womankind"); + + if (attr == null) { + passed = true; + } else { + passed = false; + pw.println("getAttribute(String) did not return null"); + } + ServletTestUtil.printResult(pw, passed); + } + + /** + * Test for ServletContext.getContext(String) method + */ + public void servletContextGetContext(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + boolean passed = false; + PrintWriter pw = response.getWriter(); + String alternateServlet = request.getServletContext().getContextPath() + + "/GetNamedDispatcherTest"; + + ServletConfig config = this.getServletConfig(); + + ServletContext context = config.getServletContext(); + + // we expect ServletContext object that corresponds to the named URL or Null + ServletContext context2 = context.getContext(alternateServlet); + + if ((context2 == context) || (context2 == null)) { + passed = true; + } else { + passed = false; + pw.println("getContext(String) returned incorrect result"); + pw.println( + "Expected getServletContext(String) to return the same context for another servlet "); + pw.println( + " in the same context as the current test servlet, or to return a null value."); + pw.println( + "Context returned from getServletConfig().getServletContext(): " + + context); + pw.println( + "Context returned from context.getContext(String): " + context2); + } + ServletTestUtil.printResult(pw, passed); + } + + /** + * Test for ServletContext.getInitParameterNames() method + */ + public void servletContextGetInitParameterNames(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = true; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + + ServletContext context = config.getServletContext(); + + // We attributed VI to EDITOR and OS to ULTASPARC + + String expectedResult1 = "EDITOR"; + boolean expectedResult1Found = false; + String expectedResult2 = "OS"; + boolean expectedResult2Found = false; + Enumeration initP = context.getInitParameterNames(); + + if (initP.hasMoreElements()) { + + while (initP.hasMoreElements()) { + String name = (String) initP.nextElement(); + pw.println("Initialization parameter: " + name); + + if (name.equals(expectedResult1)) { + if (!expectedResult1Found) { + expectedResult1Found = true; + } else { + passed = false; + pw.println( + "getInitParameterNames() method return an attribute name twice "); + pw.println( + "The attribute already specified was " + expectedResult1 + " "); + } + } else if (name.equals(expectedResult2)) { + if (!expectedResult2Found) { + expectedResult2Found = true; + } else { + passed = false; + pw.println( + "getInitParameterNames() method return an attribute name twice "); + pw.println( + "The attribute already specified was " + expectedResult2 + " "); + } + } + } + + if (!expectedResult1Found && expectedResult2Found) { + passed = false; + pw.println( + "getInitParameterNames() method did not return all the init parameters"); + } + } else { + passed = false; + pw.println("getInitParameterNames() returned and empty enumeration"); + } + + ServletTestUtil.printResult(pw, passed); + } + + /** + * Test for ServletContext.getInitParameter(String) method + */ + public void servletContextGetInitParameter(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = false; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + + ServletContext context = config.getServletContext(); + + // Init parameters specified in web.xml for + // ServletContextGetInitParameterTestServlet servlet + String param = "EDITOR"; + String expectedResult = "VI"; + String result = context.getInitParameter(param); + + if (result != null) { + if (result.equals("VI")) { + passed = true; + } else { + passed = false; + pw.println("getInitParameter(String) gave incorrect results"); + pw.println("Expected result = " + expectedResult + " "); + pw.println("Actual result = |" + result + "| "); + } + } else { + passed = false; + pw.println("getInitParameter(" + param + ") returned a null"); + } + ServletTestUtil.printResult(pw, passed); + } + + /** + * A Negative Test for ServletContext.getInitParameter(String) method + */ + public void servletContextGetInitParameterNull(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = false; + PrintWriter pw = response.getWriter(); + + ServletContext context = getServletContext(); + + String initParam = context + .getInitParameter("nothing_is_set_here_negative_compatibility_test"); + + if (initParam == null) { + passed = true; + } else { + passed = false; + pw.println("getInitParameter(String) returned incorrect result"); + pw.println("Expected result = null "); + pw.println("Actual result =|" + initParam + "| "); + } + ServletTestUtil.printResult(pw, passed); + } + + /** + * Test for ServletContext.RemoveAttribute(String) method + */ + public void servletContextRemoveAttribute(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = false; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + + ServletContext context = config.getServletContext(); + + String param = "Mankind"; + // first set attribute + context.setAttribute(param, "humane"); + + // try removing it + context.removeAttribute(param); + + Object result = null; + // try getting it,should get null + result = context.getAttribute(param); + + if (result == null) { + passed = true; + } else { + passed = false; + pw.println("removeAttribute(" + param + ") returned incorrect result "); + pw.println("Expected result = null "); + pw.println("Actual result = |" + result + "| "); + } + ServletTestUtil.printResult(pw, passed); + } + + /** + * Test for setAttribute(String,Object) method + */ + public void servletContextSetAttribute(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = false; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + + ServletContext context = config.getServletContext(); + + // set and get + String param1 = "Mankind"; + String param2 = "humane"; + + context.setAttribute(param1, param2); + + Object attr = context.getAttribute(param1); + + if (attr != null) { + if (attr.getClass().getName().equals("java.lang.String")) { + String sAttr = (String) attr; + + if (sAttr.equals(param2)) { + passed = true; + } else { + passed = false; + pw.println("setAttribute(" + param1 + "," + param2 + + ") did not set the attribute properly"); + pw.println("Expected result = " + param2 + " "); + pw.println("Actual result = |" + sAttr + "| "); + } + } else { + passed = false; + pw.println("setAttribute(" + param1 + "," + param2 + + ") did not set an attribute of type String properly"); + } + + } + ServletTestUtil.printResult(pw, passed); + } + + public void servletContextSetAttribute_1(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = false; + PrintWriter pw = response.getWriter(); + + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + + String param1 = "Mankind"; + String param2 = "humane"; + String param3 = "being"; + + // set Attribute param1 twice with param2 and param3 respectively + context.setAttribute(param1, param2); + context.setAttribute(param1, param3); + + Object attr = context.getAttribute(param1); + + if (attr != null) { + if (attr.getClass().getName().equals("java.lang.String")) { + String sAttr = (String) attr; + + if (sAttr.equals(param3)) { + passed = true; + } else if (sAttr.equals(param2)) { + passed = false; + pw.println("Failed to override set value"); + } else { + passed = false; + pw.println("Expected result = " + param3 + " "); + pw.println("Actual result = |" + sAttr + "| "); + } + } else { + passed = false; + pw.println("setAttribute(" + param1 + "," + param2 + ") " + + "didnot set an attribute of type String properly"); + } + } else { + passed = false; + pw.println("setAttribute(String, Object) " + "didnot set attribute"); + } + ServletTestUtil.printResult(pw, passed); + } + + public void servletContextSetAttribute_2(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = false; + PrintWriter pw = response.getWriter(); + + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + + String param = "Mankind"; + + // first set attribute to null + context.setAttribute(param, null); + + Object result = null; + // try getting it,should get null + result = context.getAttribute(param); + + if (result == null) { + passed = true; + } else { + passed = false; + pw.println("getAttribute(" + param + ") returned incorrect result "); + pw.println("Expected result = null "); + pw.println("Actual result = |" + result + "| "); + } + ServletTestUtil.printResult(pw, passed); + } + + public void servletContextGetAttributeNames(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = false; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + + // first we have to Set Attributes + + context.setAttribute("Chef", "expert"); + context.setAttribute("chief", "commanding"); + + // then get Attributes + int count = 0; + String expectedResult1 = "Chef"; + boolean expectedResult1Found = false; + String expectedResult2 = "chief"; + boolean expectedResult2Found = false; + int expectedCount = 2; + Enumeration attrs = context.getAttributeNames(); + + if (attrs.hasMoreElements()) { + Vector v = new Vector(); + + while (attrs.hasMoreElements()) { + String name = (String) attrs.nextElement(); + + if (name.equals(expectedResult1)) { + if (!expectedResult1Found) { + count++; + expectedResult1Found = true; + } else { + passed = false; + pw.println( + "getAttributeNames() method return an attribute name twice "); + pw.println(" The attribute already specified was " + + expectedResult1 + " "); + } + } else if (name.equals(expectedResult2)) { + if (!expectedResult2Found) { + count++; + expectedResult2Found = true; + } else { + passed = false; + pw.println( + "getAttributeNames() method return an attribute name twice "); + pw.println(" The attribute already specified was " + + expectedResult2 + " "); + } + } else { + v.add(name); + } + } + + if (count != expectedCount) { + passed = false; + pw.println( + "getAttributeNames() method did not return the correct number of init parameters"); + pw.println("Expected count = " + expectedCount); + pw.println("Actual count = " + count); + pw.println("The expected attribute names received were :"); + + if (expectedResult1Found) { + pw.println(expectedResult1); + } + + if (expectedResult2Found) { + pw.println(expectedResult2); + } + + pw.println(" Other attribute names received were :"); + + for (int i = 0; i <= v.size() - 1; i++) { + pw.println("" + v.elementAt(i).toString()); + } + } else { + passed = true; + } + } else { + passed = false; + pw.println("getAttributeNames() returned an empty enumeration"); + } + ServletTestUtil.printResult(pw, passed); + } + + /** + * Test for ServletContext.getRequestDispatcher(String) method + */ + public void servletContextGetRequestDispatcher(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + /** + * We will try to get the RequestDispatcher for this servlet itself + */ + boolean passed = false; + PrintWriter pw = response.getWriter(); + String path = "/WEB-INF/web.xml"; + + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + + RequestDispatcher rd = context.getRequestDispatcher(path); + + if (rd != null) { + passed = true; + } else { + passed = false; + pw.println( + "getRequestDispatcher(" + path + ") returned incorrect result "); + pw.println("Expected result != null "); + pw.println("Actual result = |null| "); + } + ServletTestUtil.printResult(pw, passed); + } + + /** + * Test for ServletContext.getNamedDispatcher(String) method + */ + /** + * We will try to get the RequestDispatcher for the servlet Registered as + * config + */ + public void getNamedDispatcher(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + String path = "/GetNamedDispatcherTest"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + rd.forward(request, response); + } + + /** + * Negative test for ServletContext.getNamedDispatcher(String) method + */ + public void getNamedDispatcher_1(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = false; + PrintWriter pw = response.getWriter(); + + String path = "/DoesNotExistGetNamedDispatcherTest"; + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + + RequestDispatcher tmp = context.getNamedDispatcher(path); + if (tmp != null) { + passed = false; + pw.println("non-null return"); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + /** + * Test For getServerInfo mehotd + */ + public void getServerInfo(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + + String info = context.getServerInfo(); + + // it just needs to be a not null value + if (info != null) { + passed = true; + pw.println("ServerInfo = " + info); + } else { + passed = false; + pw.println("getServerInfo() returned a null "); + } + ServletTestUtil.printResult(pw, passed); + } + + /** + * A Test for ServletContext.getServletContextName() method + */ + public void getServletNameTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = false; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + + String name = context.getServletContextName(); + + if (name.equals("SerJaxSerServletContext")) { + passed = true; + pw.println("ame = " + name); + } else { + passed = false; + pw.println("getServletContextName() returned " + name); + } + ServletTestUtil.printResult(pw, passed); + } + + public void getServletTempDir(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = false; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + + try { + java.io.File tmp = (java.io.File) context + .getAttribute("jakarta.servlet.context.tempdir"); + if (tmp != null) { + pw.println("jakarta.servlet.context.tempdir=" + tmp.getAbsolutePath()); + if (tmp.exists()) { + passed = true; + } else { + passed = false; + pw.println( + "jakarta.servlet.context.tempdir points to a non-existing dir"); + } + } else { + passed = false; + pw.println("jakarta.servlet.temp.dir attribute value is null"); + } + } catch (Exception ex) { + passed = false; + pw.println( + "Got Exception when retrieving jakarta.servlet.temp.dir attribute:" + + ex.toString()); + } + ServletTestUtil.printResult(pw, passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext/URLClient.java new file mode 100644 index 0000000000..06ba21ebb6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext/URLClient.java @@ -0,0 +1,478 @@ +/* + * Copyright (c) 2009, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_servletcontext_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestServlet.class, GetNamedDispatcherTestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_js_servletcontext_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: GetServletTempDirTest + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:SPEC:19.1; + * + * @test_Strategy: Servlet verify's that the value from the + * ServletContext.getAttribute("jakarta.servlet.temp.dir") returns non-null + * value that points an exsiting directory. + */ + @Test + public void GetServletTempDirTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletTempDir"); + invoke(); + } + + /* + * @testName: GetMajorVersionTest + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:220; + * + * @test_Strategy: Test the ServletContext.getMajorVersion() for this servlet + * itself + */ + @Test + public void GetMajorVersionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getMajorVersion"); + invoke(); + } + + /* + * @testName: GetMinorVersionTest + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:221; + * + * @test_Strategy: Test the ServletContext.getMinorVersion() for this servlet + * itself + */ + @Test + public void GetMinorVersionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getMinorVersion"); + invoke(); + } + + /* + * @testName: GetMimeTypeTest + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:222; + * + * @test_Strategy: Test the ServletContext.getMimeType() for this servlet + * itself + */ + @Test + public void GetMimeTypeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getMimeType"); + invoke(); + } + + /* + * @testName: GetMimeType_1Test + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:223; + * + * @test_Strategy: A negative test for getMimeType(). Test the + * ServletContext.getMimeType() for this servlet itself + */ + @Test + public void GetMimeType_1Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "getMimeType_1"); + invoke(); + } + + /* + * @testName: GetRealPathTest + * + * @assertion_ids: Servlet:SPEC:90; Servlet:SPEC:92.2; Servlet:JAVADOC:124; + * Servlet:JAVADOC:258; Servlet:JAVADOC:241; + * + * @test_Strategy: Test the ServletContext.getRealPath() for this servlet + * itself + */ + @Test + public void GetRealPathTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getRealPath"); + invoke(); + } + + /* + * @testName: GetResourcePathsTest + * + * @assertion_ids: Servlet:SPEC:90; Servlet:SPEC:92.2; Servlet:JAVADOC:124; + * Servlet:JAVADOC:258; Servlet:JAVADOC:224; + * + * @test_Strategy: Test the ServletContext.getResourcePaths() for this servlet + */ + @Test + public void GetResourcePathsTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "/WEB-INF/web.xml"); + TEST_PROPS.setProperty(APITEST, "getResourcePaths"); + invoke(); + + TEST_PROPS.setProperty(SEARCH_STRING, + "/WEB-INF/classes/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext/TestServlet.class"); + TEST_PROPS.setProperty(APITEST, "getResourcePaths"); + invoke(); + + TEST_PROPS.setProperty(SEARCH_STRING, + "/WEB-INF/classes/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext/GetNamedDispatcherTestServlet.class"); + TEST_PROPS.setProperty(APITEST, "getResourcePaths"); + invoke(); + } + + /* + * @testName: GetResourceAsStreamTest + * + * @assertion_ids: Servlet:SPEC:90; Servlet:SPEC:92.2; Servlet:JAVADOC:124; + * Servlet:JAVADOC:258; Servlet:JAVADOC:228; + * + * @test_Strategy: A Test for getResourceAs Stream method + */ + @Test + public void GetResourceAsStreamTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getResourceAsStream"); + invoke(); + } + + /* + * @testName: GetResourceAsStream_1Test + * + * @assertion_ids: Servlet:SPEC:90; Servlet:SPEC:92.2; Servlet:JAVADOC:124; + * Servlet:JAVADOC:258; Servlet:JAVADOC:229; + * + * @test_Strategy: A negative test for getResourceAsStream() method + */ + @Test + public void GetResourceAsStream_1Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "getResourceAsStream_1"); + invoke(); + } + + /* + * @testName: GetResourceTest + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:226; + * + * @test_Strategy: A Test for ServletContext.getResource(String) method + */ + @Test + public void GetResourceTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getResource"); + invoke(); + } + + /* + * @testName: GetResource_1Test + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:225; + * + * @test_Strategy: A negative test for ServletContext.getResource(String) + * method + */ + @Test + public void GetResource_1Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "getResource_1"); + invoke(); + } + + /* + * @testName: GetResource_2Test + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:227; + * + * @test_Strategy: A negative test for ServletContext.getResource(String path) + * if path does not start with /, MalformedURLException should be thrown + */ + @Test + public void GetResource_2Test() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, ""); + TEST_PROPS.setProperty(APITEST, "getResource_2"); + invoke(); + } + + /* + * @testName: GetServerInfoTest + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:242; + * + * @test_Strategy: Test for ServletContext.getServerInfo() method + */ + @Test + public void GetServerInfoTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServerInfo"); + invoke(); + } + + /* + * @testName: ServletContextGetAttributeTest + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:250; Servlet:JAVADOC:247; + * + * @test_Strategy: Try to get the attributes for this servlet itself + */ + @Test + public void ServletContextGetAttributeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "servletContextGetAttribute"); + invoke(); + } + + /* + * @testName: ServletContextGetAttribute_1Test + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:248; + * + * @test_Strategy: A negative test for ServletContext.getAttribute(). Test for + * null attribute values for this servlet itself + */ + @Test + public void ServletContextGetAttribute_1Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "servletContextGetAttribute_1"); + invoke(); + } + + /* + * @testName: ServletContextGetContextTest + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:219; + * + * @test_Strategy: Test for ServletContext object for this servlet itself + */ + @Test + public void ServletContextGetContextTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "servletContextGetContext"); + invoke(); + } + + /* + * @testName: ServletContextGetInitParameterNamesTest + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:245; + * + * @test_Strategy: Test the ServletContext.getInitParameterNames() for this + * servlet itself + */ + @Test + public void ServletContextGetInitParameterNamesTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "servletContextGetInitParameterNames"); + invoke(); + } + + /* + * @testName: ServletContextGetInitParameterTest + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:243; + * + * @test_Strategy: Test the ServletContext.getInitParameter(String) for this + * servlet itself + */ + @Test + public void ServletContextGetInitParameterTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "servletContextGetInitParameter"); + invoke(); + } + + /* + * @testName: ServletContextGetInitParameterTestNull + * + * @assertion_ids: Servlet:JAVADOC:125; Servlet:JAVADOC:244; + * + * @test_Strategy: Test the ServletContext.getInitParameter(String name) + * returns null when name(nothing_is_set_here_negative_compatibility_test) is + * not set + */ + @Test + public void ServletContextGetInitParameterTestNull() throws Exception { + TEST_PROPS.setProperty(APITEST, "servletContextGetInitParameterNull"); + invoke(); + } + + /* + * @testName: ServletContextRemoveAttributeTest + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:250; Servlet:JAVADOC:254; Servlet:JAVADOC:248; + * + * @test_Strategy: Test for ServletContext.removeAttribute() method + */ + @Test + public void ServletContextRemoveAttributeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "servletContextRemoveAttribute"); + invoke(); + } + + /* + * @testName: ServletContextSetAttributeTest + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:250; Servlet:JAVADOC:247; + * + * @test_Strategy: Test for ServletContext.setAttribute() method + */ + @Test + public void ServletContextSetAttributeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "servletContextSetAttribute"); + invoke(); + } + + /* + * @testName: ServletContextSetAttribute_1Test + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:250; Servlet:JAVADOC:251; Servlet:JAVADOC:247; + * + * @test_Strategy: Test for ServletContext.setAttribute() method Call + * ServletContext.setAttribute(String Attribute, Object value) twice with the + * same Attribute, verify that second value replace the first Attribute value. + */ + @Test + public void ServletContextSetAttribute_1Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "servletContextSetAttribute_1"); + invoke(); + } + + /* + * @testName: ServletContextSetAttribute_2Test + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:250; Servlet:JAVADOC:253; Servlet:JAVADOC:248; + * + * @test_Strategy: Test for ServletContext.setAttribute() method Set Attribute + * to null and verify getAttribute return null. + */ + @Test + public void ServletContextSetAttribute_2Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "servletContextSetAttribute_2"); + invoke(); + } + + /* + * @testName: ServletContextGetAttributeNamesTest + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:250; Servlet:JAVADOC:249; + * + * @test_Strategy: Servlet retrieves attributes which it set itself + */ + @Test + public void ServletContextGetAttributeNamesTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "servletContextGetAttributeNames"); + invoke(); + } + + /* + * @testName: ServletContextGetRequestDispatcherTest + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:230; + * + * @test_Strategy: Test the ServletContext.getRequestDispatcher(String) for + * this servlet itself + */ + @Test + public void ServletContextGetRequestDispatcherTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "servletContextGetRequestDispatcher"); + invoke(); + } + + /* + * @testName: GetNamedDispatcherTest + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:232; + * + * @test_Strategy: Servlet verify's that the result from the + * getNamedDispatcher call and the getServletName call are the same for the + * servlet. + */ + @Test + public void GetNamedDispatcherTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getNamedDispatcher"); + invoke(); + } + + /* + * @testName: GetNamedDispatcher_1Test + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:233; + * + * @test_Strategy: Servlet verify's that the result from the + * getNamedDispatcher call return null with non-existent path. Negative test. + */ + @Test + public void GetNamedDispatcher_1Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "getNamedDispatcher_1"); + invoke(); + } + + /* + * @testName: GetServletNameTest + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:256; + * + * @test_Strategy: Servlet verify's that the result from the + * ServletContext.getServletContextName call is the same as set in Deployment + * Descriptor for the servlet. + */ + @Test + public void GetServletNameTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletNameTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext/build.xml new file mode 100644 index 0000000000..d6568b1543 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext/build.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext/servlet_js_servletcontext_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext/servlet_js_servletcontext_web.xml new file mode 100644 index 0000000000..18a3ce15d8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext/servlet_js_servletcontext_web.xml @@ -0,0 +1,53 @@ + + + + + SerJaxSerServletContext + + EDITOR + VI + + + OS + ULTASPARC + + + TestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext.TestServlet + + + GetNamedDispatcherTest + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext.GetNamedDispatcherTestServlet + + + TestLogicalName + /TestServlet + + + GetNamedDispatcherTest + /GetNamedDispatcherTest + + + 54 + + + class + application/x-java-class + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddFilterClass.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddFilterClass.java new file mode 100644 index 0000000000..9e1f752990 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddFilterClass.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2009, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30; + +import java.io.IOException; +import java.util.ArrayList; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public final class AddFilterClass implements Filter { + + // The filter configuration object we are associated with. If this value + // is null, this filter instance is not currently configured. + private FilterConfig filterConfig = null; + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + if (filterConfig == null) + throw new ServletException( + "doFilter of AddFilterClass was called but this filter instance is not currently configured"); + + ArrayList result = (ArrayList) filterConfig.getServletContext() + .getAttribute("arraylist"); + result.add("ADD_FILTER_CLASS_INVOKED"); + + filterConfig.getServletContext().setAttribute("arraylist", result); + chain.doFilter(request, response); + + } + + // Remove the filter configuration object for this filter. + public void destroy() { + } + + // initialize the filter configuration object for this filter. + public void init(FilterConfig filterConfig) { + this.filterConfig = filterConfig; + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddFilterNotFound.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddFilterNotFound.java new file mode 100644 index 0000000000..7d69bf82f2 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddFilterNotFound.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2009, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30; + +import java.io.IOException; +import java.util.ArrayList; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public final class AddFilterNotFound implements Filter { + + // The filter configuration object we are associated with. If this value + // is null, this filter instance is not currently configured. + private FilterConfig filterConfig = null; + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + if (filterConfig == null) + throw new ServletException( + "doFilter of AddFilterNotFound was called but this filter instance is not currently configured"); + + ArrayList result = (ArrayList) filterConfig.getServletContext() + .getAttribute("arraylist"); + result.add("ADD_FILTER_NOTFOUND_INVOKED"); + + filterConfig.getServletContext().setAttribute("arraylist", result); + chain.doFilter(request, response); + } + + // Remove the filter configuration object for this filter. + public void destroy() { + } + + // initialize the filter configuration object for this filter. + public void init(FilterConfig filterConfig) { + this.filterConfig = filterConfig; + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddFilterString.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddFilterString.java new file mode 100644 index 0000000000..e279febb2d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddFilterString.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2009, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30; + +import java.io.IOException; +import java.util.ArrayList; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public final class AddFilterString implements Filter { + + // The filter configuration object we are associated with. If this value + // is null, this filter instance is not currently configured. + private FilterConfig filterConfig = null; + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + if (filterConfig == null) + throw new ServletException( + "doFilter of AddFilterString was called but this filter instance is not currently configured"); + + ArrayList result = (ArrayList) filterConfig.getServletContext() + .getAttribute("arraylist"); + result.add("ADD_FILTER_STRING_INVOKED"); + + filterConfig.getServletContext().setAttribute("arraylist", result); + chain.doFilter(request, response); + } + + // Remove the filter configuration object for this filter. + public void destroy() { + } + + // initialize the filter configuration object for this filter. + public void init(FilterConfig filterConfig) { + this.filterConfig = filterConfig; + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddSCAttributeListenerClass.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddSCAttributeListenerClass.java new file mode 100644 index 0000000000..c5a3ca58fa --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddSCAttributeListenerClass.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2009, 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.ServletContextAttributeEvent; +import jakarta.servlet.ServletContextAttributeListener; + +public final class AddSCAttributeListenerClass + implements ServletContextAttributeListener { + + // Public Methods + + public void attributeAdded(ServletContextAttributeEvent event) { + StaticLog.add( + "SCAttributeAddedClass:" + event.getName() + "," + event.getValue()); + } + + public void attributeRemoved(ServletContextAttributeEvent event) { + StaticLog.add( + "SCAttributeRemovedClass:" + event.getName() + "," + event.getValue()); + } + + public void attributeReplaced(ServletContextAttributeEvent event) { + StaticLog.add( + "SCAttributeReplacedClass:" + event.getName() + "," + event.getValue()); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddSCAttributeListenerString.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddSCAttributeListenerString.java new file mode 100644 index 0000000000..04693c5a77 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddSCAttributeListenerString.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2009, 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.ServletContextAttributeEvent; +import jakarta.servlet.ServletContextAttributeListener; + +public final class AddSCAttributeListenerString + implements ServletContextAttributeListener { + + // Public Methods + + public void attributeAdded(ServletContextAttributeEvent event) { + StaticLog.add( + "SCAttributeAddedString:" + event.getName() + "," + event.getValue()); + } + + public void attributeRemoved(ServletContextAttributeEvent event) { + StaticLog.add( + "SCAttributeRemovedString:" + event.getName() + "," + event.getValue()); + } + + public void attributeReplaced(ServletContextAttributeEvent event) { + StaticLog.add("SCAttributeReplacedString:" + event.getName() + "," + + event.getValue()); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddSCListenerClass.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddSCListenerClass.java new file mode 100644 index 0000000000..0e2ee96d1c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddSCListenerClass.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; + +public class AddSCListenerClass implements ServletContextListener { + + public void contextDestroyed(ServletContextEvent event) { + StaticLog.add("AddSCListenerClass Destroyed."); + } + + public void contextInitialized(ServletContextEvent event) { + StaticLog.add("AddSCListenerClass Initialized."); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddSCListenerString.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddSCListenerString.java new file mode 100644 index 0000000000..8ba6a2fbc7 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddSCListenerString.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; + +public class AddSCListenerString implements ServletContextListener { + + public void contextDestroyed(ServletContextEvent event) { + StaticLog.add("AddSCListenerString Destroyed."); + } + + public void contextInitialized(ServletContextEvent event) { + StaticLog.add("AddSCListenerString Initialized."); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddSRAttributeListenerClass.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddSRAttributeListenerClass.java new file mode 100644 index 0000000000..0a5abf8c35 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddSRAttributeListenerClass.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2009, 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.ServletRequestAttributeEvent; +import jakarta.servlet.ServletRequestAttributeListener; + +public final class AddSRAttributeListenerClass + implements ServletRequestAttributeListener { + + // Public Methods + + public void attributeAdded(ServletRequestAttributeEvent event) { + StaticLog.add( + "SRAttributeAddedClass:" + event.getName() + "," + event.getValue()); + + } + + public void attributeRemoved(ServletRequestAttributeEvent event) { + StaticLog.add( + "SRAttributeRemovedClass:" + event.getName() + "," + event.getValue()); + } + + public void attributeReplaced(ServletRequestAttributeEvent event) { + StaticLog.add( + "SRAttributeReplacedClass:" + event.getName() + "," + event.getValue()); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddSRAttributeListenerString.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddSRAttributeListenerString.java new file mode 100644 index 0000000000..5fc55facee --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddSRAttributeListenerString.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2009, 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.ServletRequestAttributeEvent; +import jakarta.servlet.ServletRequestAttributeListener; + +public final class AddSRAttributeListenerString + implements ServletRequestAttributeListener { + + // Public Methods + + public void attributeAdded(ServletRequestAttributeEvent event) { + StaticLog.add( + "SRAttributeAddedString:" + event.getName() + "," + event.getValue()); + + } + + public void attributeRemoved(ServletRequestAttributeEvent event) { + StaticLog.add( + "SRAttributeRemovedString:" + event.getName() + "," + event.getValue()); + } + + public void attributeReplaced(ServletRequestAttributeEvent event) { + StaticLog.add("SRAttributeReplacedString:" + event.getName() + "," + + event.getValue()); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddSRListenerClass.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddSRListenerClass.java new file mode 100644 index 0000000000..0caacd465d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddSRListenerClass.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2009, 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30; + +import java.util.ArrayList; + +import jakarta.servlet.ServletRequestEvent; +import jakarta.servlet.ServletRequestListener; + +public final class AddSRListenerClass implements ServletRequestListener { + + // Public Methods + + public void requestDestroyed(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("arraylist"); + if (al != null) { + al.add("in requestDestroyed method of AddSRListenerClass"); + event.getServletContext().setAttribute("arraylist", al); + } + } + + public void requestInitialized(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("arraylist"); + if (al == null) { + al = new ArrayList(); + } + al.add("AddSRListenerClass_INVOKED"); + event.getServletContext().setAttribute("arraylist", al); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddSRListenerString.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddSRListenerString.java new file mode 100644 index 0000000000..93636437fe --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddSRListenerString.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2009, 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30; + +import java.util.ArrayList; + +import jakarta.servlet.ServletRequestEvent; +import jakarta.servlet.ServletRequestListener; + +public final class AddSRListenerString implements ServletRequestListener { + + // Public Methods + + public void requestDestroyed(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("arraylist"); + if (al != null) { + al.add("in requestDestroyed method of AddSRListenerString"); + event.getServletContext().setAttribute("arraylist", al); + } + } + + public void requestInitialized(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("arraylist"); + if (al == null) { + al = new ArrayList(); + } + al.add("AddSRListenerString_INVOKED"); + event.getServletContext().setAttribute("arraylist", al); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddServletClass.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddServletClass.java new file mode 100644 index 0000000000..2dd64861ff --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddServletClass.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2009, 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:i$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class AddServletClass extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + + pw.println("AddServletClass is invoked correctly"); + ArrayList result = (ArrayList) getServletContext() + .getAttribute("arraylist"); + + for (Object tmp : result) { + pw.println(tmp.toString()); + + } + getServletContext().removeAttribute("arraylist"); + + result = StaticLog.getClear(); + if (result != null) { + for (Object tmp : result) { + if (tmp != null) { + pw.println(tmp.toString()); + } + } + } + StaticLog.clear(); + ServletTestUtil.printResult(pw, true); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddServletNotFound.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddServletNotFound.java new file mode 100644 index 0000000000..561cd32693 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddServletNotFound.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2009, 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:i$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class AddServletNotFound extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + + pw.println("AddServletNotFound is invoked"); + ServletTestUtil.printResult(pw, true); + + ArrayList result = (ArrayList) getServletContext() + .getAttribute("arraylist"); + + for (Object tmp : result) { + pw.println(tmp.toString()); + + } + getServletContext().removeAttribute("arraylist"); + + result = StaticLog.getClear(); + if (result != null) { + for (Object tmp : result) { + if (tmp != null) { + pw.println(tmp.toString()); + } + } + } + StaticLog.clear(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddServletString.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddServletString.java new file mode 100644 index 0000000000..2460b576b1 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/AddServletString.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2009, 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:i$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class AddServletString extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + + pw.println("AddServletString is invoked correctly"); + ArrayList result = (ArrayList) getServletContext() + .getAttribute("arraylist"); + + for (Object tmp : result) { + pw.println(tmp.toString()); + } + getServletContext().removeAttribute("arraylist"); + + result = StaticLog.getClear(); + if (result != null) { + for (Object tmp : result) { + if (tmp != null) { + pw.println(tmp.toString()); + } + } + } + ServletTestUtil.printResult(pw, true); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/BadFilter.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/BadFilter.java new file mode 100644 index 0000000000..1353a48137 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/BadFilter.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2009, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30; + +import java.io.IOException; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public final class BadFilter implements Filter { + + // The filter configuration object we are associated with. If this value + // is null, this filter instance is not currently configured. + private FilterConfig filterConfig = null; + + // Non-zero argument constructor + public BadFilter(String x) throws ServletException { + throw new ServletException("Negative Test for createFilter"); + } + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + boolean passed = true; + + if (filterConfig == null) { + StaticLog.add("FAILED_CREATE_FILTER_INVOKED"); + } else { + StaticLog.add("CREATE_FILTER_INVOKED"); + } + StaticLog.add("Negative Test for createFilter Failed"); + chain.doFilter(request, response); + } + + // Remove the filter configuration object for this filter. + public void destroy() { + } + + // initialize the filter configuration object for this filter. + public void init(FilterConfig filterConfig) { + this.filterConfig = filterConfig; + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/BadListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/BadListener.java new file mode 100644 index 0000000000..e50e786d4e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/BadListener.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2009, 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30; + +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequestEvent; +import jakarta.servlet.ServletRequestListener; + +public final class BadListener implements ServletRequestListener { + + // Non-zero argument constructor + public BadListener(String x) throws ServletException { + throw new ServletException("Negative Test for createListener"); + } + + // Public Methods + public void requestDestroyed(ServletRequestEvent event) { + // do nothing + } + + public void requestInitialized(ServletRequestEvent event) { + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/BadServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/BadServlet.java new file mode 100644 index 0000000000..428be1add5 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/BadServlet.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2009, 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:i$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class BadServlet extends GenericServlet { + + // Non-zero argument constructor + public BadServlet(String x) throws ServletException { + throw new ServletException("Negative Test for createServlet"); + } + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + + pw.println("Negative Test for createServlet Failed"); + + ArrayList result = (ArrayList) getServletContext() + .getAttribute("arraylist"); + + for (Object tmp : result) { + pw.println(tmp.toString()); + + } + getServletContext().removeAttribute("arraylist"); + + result = StaticLog.getClear(); + if (result != null) { + for (Object tmp : result) { + if (tmp != null) { + pw.println(tmp.toString()); + } + } + } + StaticLog.clear(); + ServletTestUtil.printResult(pw, true); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/CreateFilter.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/CreateFilter.java new file mode 100644 index 0000000000..12678b62d8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/CreateFilter.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2009, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30; + +import java.io.IOException; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public final class CreateFilter implements Filter { + + // The filter configuration object we are associated with. If this value + // is null, this filter instance is not currently configured. + private FilterConfig filterConfig = null; + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + boolean passed = true; + + if (filterConfig == null) { + StaticLog.add("FAILED_CREATE_FILTER_INVOKED"); + } else { + StaticLog.add("CREATE_FILTER_INVOKED"); + } + + chain.doFilter(request, response); + } + + // Remove the filter configuration object for this filter. + public void destroy() { + } + + // initialize the filter configuration object for this filter. + public void init(FilterConfig filterConfig) { + this.filterConfig = filterConfig; + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/CreateSCAttributeListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/CreateSCAttributeListener.java new file mode 100644 index 0000000000..f5858eba28 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/CreateSCAttributeListener.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2009, 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.ServletContextAttributeEvent; +import jakarta.servlet.ServletContextAttributeListener; + +public final class CreateSCAttributeListener + implements ServletContextAttributeListener { + + // Public Methods + + public void attributeAdded(ServletContextAttributeEvent event) { + StaticLog + .add("SCAttributeAdded:" + event.getName() + "," + event.getValue()); + } + + public void attributeRemoved(ServletContextAttributeEvent event) { + StaticLog + .add("SCAttributeRemoved:" + event.getName() + "," + event.getValue()); + } + + public void attributeReplaced(ServletContextAttributeEvent event) { + StaticLog + .add("SCAttributeReplaced:" + event.getName() + "," + event.getValue()); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/CreateSCListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/CreateSCListener.java new file mode 100644 index 0000000000..2c326e88b7 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/CreateSCListener.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; + +public class CreateSCListener implements ServletContextListener { + + public void contextDestroyed(ServletContextEvent event) { + StaticLog.add("CreateSCListener Destroyed."); + } + + public void contextInitialized(ServletContextEvent event) { + StaticLog.add("CreateSCListener Initialized."); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/CreateSRAttributeListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/CreateSRAttributeListener.java new file mode 100644 index 0000000000..11d0f1f91c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/CreateSRAttributeListener.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2009, 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.ServletRequestAttributeEvent; +import jakarta.servlet.ServletRequestAttributeListener; + +public final class CreateSRAttributeListener + implements ServletRequestAttributeListener { + + // Public Methods + + public void attributeAdded(ServletRequestAttributeEvent event) { + StaticLog + .add("SRAttributeAdded:" + event.getName() + "," + event.getValue()); + + } + + public void attributeRemoved(ServletRequestAttributeEvent event) { + StaticLog + .add("SRAttributeRemoved:" + event.getName() + "," + event.getValue()); + } + + public void attributeReplaced(ServletRequestAttributeEvent event) { + StaticLog + .add("SRAttributeReplaced:" + event.getName() + "," + event.getValue()); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/CreateSRListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/CreateSRListener.java new file mode 100644 index 0000000000..8f44fe2a45 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/CreateSRListener.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2009, 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30; + +import java.util.ArrayList; + +import jakarta.servlet.ServletRequestEvent; +import jakarta.servlet.ServletRequestListener; + +public final class CreateSRListener implements ServletRequestListener { + + // Public Methods + public void requestDestroyed(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("arraylist"); + if (al != null) { + al.add("in requestDestroyed method of CreateSRListener"); + event.getServletContext().setAttribute("arraylist", al); + } + } + + public void requestInitialized(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("arraylist"); + if (al == null) { + al = new ArrayList(); + } + al.add("CreateSRListener_INVOKED"); + event.getServletContext().setAttribute("arraylist", al); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/CreateServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/CreateServlet.java new file mode 100644 index 0000000000..d1b3594bfa --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/CreateServlet.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2009, 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:i$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class CreateServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + + pw.println("CreateServlet is invoked correctly"); + + ArrayList result = (ArrayList) getServletContext() + .getAttribute("arraylist"); + + for (Object tmp : result) { + pw.println(tmp.toString()); + + } + getServletContext().removeAttribute("arraylist"); + + result = StaticLog.getClear(); + if (result != null) { + for (Object tmp : result) { + if (tmp != null) { + pw.println(tmp.toString()); + } + } + } + StaticLog.clear(); + ServletTestUtil.printResult(pw, true); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/DuplicateFilterClass.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/DuplicateFilterClass.java new file mode 100644 index 0000000000..ffa4aa4086 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/DuplicateFilterClass.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30; + +import java.io.IOException; +import java.util.ArrayList; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public final class DuplicateFilterClass implements Filter { + + // The filter configuration object we are associated with. If this value + // is null, this filter instance is not currently configured. + private FilterConfig filterConfig = null; + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + if (filterConfig == null) + throw new ServletException( + "doFilter of DuplicateFilterClass was called but this filter instance is not currently configured"); + + ArrayList result = (ArrayList) filterConfig.getServletContext() + .getAttribute("arraylist"); + result.add("DUPLICATE_FILTER_CLASS_INVOKED"); + + filterConfig.getServletContext().setAttribute("arraylist", result); + chain.doFilter(request, response); + } + + // Remove the filter configuration object for this filter. + public void destroy() { + } + + // initialize the filter configuration object for this filter. + public void init(FilterConfig filterConfig) { + this.filterConfig = filterConfig; + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/DuplicateFilterString.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/DuplicateFilterString.java new file mode 100644 index 0000000000..6d85140383 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/DuplicateFilterString.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30; + +import java.io.IOException; +import java.util.ArrayList; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public final class DuplicateFilterString implements Filter { + + // The filter configuration object we are associated with. If this value + // is null, this filter instance is not currently configured. + private FilterConfig filterConfig = null; + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + if (filterConfig == null) + throw new ServletException( + "doFilter of DuplicateFilterString was called but this filter instance is not currently configured"); + + ArrayList result = (ArrayList) filterConfig.getServletContext() + .getAttribute("arraylist"); + result.add("DUPLICATE_FILTER_STRING_INVOKED"); + + filterConfig.getServletContext().setAttribute("arraylist", result); + chain.doFilter(request, response); + } + + // Remove the filter configuration object for this filter. + public void destroy() { + } + + // initialize the filter configuration object for this filter. + public void init(FilterConfig filterConfig) { + this.filterConfig = filterConfig; + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/DuplicateServletClass.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/DuplicateServletClass.java new file mode 100644 index 0000000000..10d9baac57 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/DuplicateServletClass.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2012, 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:i$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class DuplicateServletClass extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + + pw.println("DuplicateServletClass is invoked"); + ArrayList result = (ArrayList) getServletContext() + .getAttribute("arraylist"); + + for (Object tmp : result) { + pw.println(tmp.toString()); + + } + getServletContext().removeAttribute("arraylist"); + + result = StaticLog.getClear(); + if (result != null) { + for (Object tmp : result) { + if (tmp != null) { + pw.println(tmp.toString()); + } + } + } + StaticLog.clear(); + ServletTestUtil.printResult(pw, true); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/DuplicateServletString.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/DuplicateServletString.java new file mode 100644 index 0000000000..618a391d2f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/DuplicateServletString.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2012, 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:i$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class DuplicateServletString extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + + pw.println("DuplicateServletString is invoked"); + ArrayList result = (ArrayList) getServletContext() + .getAttribute("arraylist"); + + for (Object tmp : result) { + pw.println(tmp.toString()); + } + getServletContext().removeAttribute("arraylist"); + + result = StaticLog.getClear(); + if (result != null) { + for (Object tmp : result) { + if (tmp != null) { + pw.println(tmp.toString()); + } + } + } + ServletTestUtil.printResult(pw, true); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/FilterTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/FilterTestServlet.java new file mode 100644 index 0000000000..302b88d61e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/FilterTestServlet.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2012, 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:i$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class FilterTestServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + + pw.println("FilterTestServlet is invoked"); + ArrayList result = (ArrayList) getServletContext() + .getAttribute("arraylist"); + + for (Object tmp : result) { + pw.println(tmp.toString()); + + } + getServletContext().removeAttribute("arraylist"); + + result = StaticLog.getClear(); + if (result != null) { + for (Object tmp : result) { + if (tmp != null) { + pw.println(tmp.toString()); + } + } + } + StaticLog.clear(); + ServletTestUtil.printResult(pw, true); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/TestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/TestListener.java new file mode 100644 index 0000000000..350968970f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/TestListener.java @@ -0,0 +1,332 @@ +/* + * Copyright (c) 2009, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30; + +import java.util.EnumSet; +import java.util.EventListener; + +import jakarta.servlet.DispatcherType; +import jakarta.servlet.Filter; +import jakarta.servlet.FilterRegistration; +import jakarta.servlet.Servlet; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRegistration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class TestListener implements ServletContextListener { + + private static final Logger LOGGER = LoggerFactory.getLogger(TestListener.class); + + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce + * The servlet context event + */ + public void contextInitialized(ServletContextEvent sce) { + ServletContext context = sce.getServletContext(); + + final String addServletName1 = "AddServletString"; + final String addServletName2 = "AddServletClass"; + final String addServletName3 = "CreateServlet"; + final String addServletName4 = "AddServletNotFound"; + final String addServletName5 = "DuplicateServletClass"; + final String addServletName6 = "DuplicateServletString"; + + final String addFilterName1 = "AddFilterString"; + final String addFilterName2 = "AddFilterClass"; + final String addFilterName3 = "CreateFilter"; + final String addFilterName4 = "AddFilterNotFound"; + final String addFilterName5 = "DuplicateFilterClass"; + final String addFilterName6 = "DuplicateFilterString"; + + /* + * Add Servlet AddServletString + */ + ServletRegistration srString = context.addServlet(addServletName1, + "com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddServletString"); + srString.addMapping("/addServletString"); + srString.setInitParameter("FILTER", addFilterName1); + srString.setInitParameter(addFilterName1, + DispatcherType.FORWARD.toString()); + + FilterRegistration frString = context.addFilter(addFilterName1, + "com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddFilterString"); + frString.addMappingForServletNames(EnumSet.of(DispatcherType.FORWARD), true, + addServletName1); + frString.setInitParameter("SERVLET", addServletName1); + frString.setInitParameter(addServletName1, + DispatcherType.FORWARD.toString()); + + /* + * Add Servlet AddServletClass + */ + ServletRegistration srClass = context.addServlet(addServletName2, + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddServletClass.class); + srClass.addMapping("/addServletClass", "/SecondaddServletClass", + "/ThirdAddServletClass", "/AddServletClass/*"); + srClass.setInitParameter("FILTER", addFilterName2); + srClass.setInitParameter(addFilterName2, DispatcherType.REQUEST.toString()); + + FilterRegistration frClass = context.addFilter(addFilterName2, + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddFilterClass.class); + frClass.addMappingForServletNames(EnumSet.of(DispatcherType.REQUEST), true, + addServletName2); + frClass.setInitParameter("SERVLET", addServletName2); + frClass.setInitParameter(addServletName2, + DispatcherType.REQUEST.toString()); + + /* + * Add Servlet CreateServlet + */ + ServletRegistration srServlet = null; + FilterRegistration frFilter = null; + try { + Servlet servlet3 = context.createServlet( + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.CreateServlet.class); + srServlet = context.addServlet(addServletName3, servlet3); + srServlet.addMapping("/createServlet", "/SecondCreateServlet", + "/ThirdCreateServlet"); + srServlet.setInitParameter("FILTER", addFilterName3); + srServlet.setInitParameter(addFilterName3, + DispatcherType.REQUEST.toString()); + + Filter filter3 = context.createFilter( + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.CreateFilter.class); + frFilter = context.addFilter(addFilterName3, filter3); + frFilter.addMappingForServletNames(EnumSet.of(DispatcherType.REQUEST), + true, addServletName3); + frFilter.setInitParameter("SERVLET", addServletName3); + frFilter.setInitParameter(addServletName3, + DispatcherType.REQUEST.toString()); + } catch (ServletException ex) { + LOGGER.error("Error creating Servlet"); + } + + /* + * Add Servlet AddServletNotFound + */ + ServletRegistration srNotFound = context.addServlet(addServletName4, + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddServletNotFound.class); + srNotFound.addMapping("/addServletNotFound", "/TestServlet"); + srNotFound.setInitParameter("FILTER", addFilterName4); + srNotFound.setInitParameter(addFilterName4, "ALL"); + + FilterRegistration frNotFound = context.addFilter(addFilterName4, + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddFilterNotFound.class); + frNotFound.addMappingForServletNames( + EnumSet.of(DispatcherType.REQUEST, DispatcherType.INCLUDE, + DispatcherType.FORWARD, DispatcherType.ERROR), + true, addServletName4); + frNotFound.setInitParameter("SERVLET", addServletName4); + frNotFound.setInitParameter(addServletName4, "ALL"); + + /* + * Add ServletContextAttributeListener + */ + context.addListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddSCAttributeListenerClass.class); + + context.addListener( + "com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddSCAttributeListenerString"); + try { + EventListener sclistener = context.createListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.CreateSCAttributeListener.class); + context.addListener(sclistener); + } catch (ServletException ex) { + LOGGER.error("Error creating Listener CreateSCAttributeListener: " + + ex.getMessage()); + } + + /* + * Add ServletRequestListener + */ + context.addListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddSRListenerClass.class); + context.addListener( + "com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddSRListenerString"); + try { + EventListener srlistener = context.createListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.CreateSRListener.class); + context.addListener(srlistener); + } catch (ServletException ex) { + LOGGER.error("Error creating Listener CreateSRAttributeListener: " + + ex.getMessage()); + } + + /* + * Add ServletRequestAttributesListener + */ + context.addListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddSRAttributeListenerClass.class); + context.addListener( + "com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddSRAttributeListenerString"); + try { + EventListener sralistener = context.createListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.CreateSRAttributeListener.class); + context.addListener(sralistener); + } catch (ServletException ex) { + LOGGER.error("Error creating Listener CreateSRAttributeListener: " + + ex.getMessage()); + } + + /* + * Negative tests for - createServlet - createFilter - createListener + */ + Boolean servlet_test = false; + Boolean duplicatec_servlet_test = false; + Boolean duplicates_servlet_test = false; + Boolean filter_test = false; + Boolean duplicatec_filter_test = false; + Boolean duplicates_filter_test = false; + Boolean listener_test = false; + Boolean scc_listener_test = false; + Boolean scs_listener_test = false; + Boolean csc_listener_test = false; + String SERVLET_TEST = "SERVLET_TEST"; + String DUPLICATEC_SERVLET_TEST = "DUPLICATEC_SERVLET_TEST"; + String DUPLICATES_SERVLET_TEST = "DUPLICATES_SERVLET_TEST"; + String FILTER_TEST = "FILTER_TEST"; + String DUPLICATEC_FILTER_TEST = "DUPLICATEC_FILTER_TEST"; + String DUPLICATES_FILTER_TEST = "DUPLICATES_FILTER_TEST"; + String LISTENER_TEST = "LISTENER_TEST"; + String SCC_LISTENER_TEST = "SCC_LISTENER_TEST"; + String SCS_LISTENER_TEST = "SCS_LISTENER_TEST"; + String CSC_LISTENER_TEST = "CSC_LISTENER_TEST"; + + try { + Servlet badservlet = context.createServlet( + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.BadServlet.class); + } catch (ServletException ex) { + servlet_test = true; + } + context.setInitParameter(SERVLET_TEST, servlet_test.toString()); + + try { + Filter badfilter = context.createFilter( + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.BadFilter.class); + } catch (ServletException ex) { + filter_test = true; + } + context.setInitParameter(FILTER_TEST, filter_test.toString()); + + try { + context.createListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.BadListener.class); + } catch (ServletException ex) { + listener_test = true; + } + context.setInitParameter(LISTENER_TEST, listener_test.toString()); + + try { + context.addListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddSCListenerClass.class); + } catch (IllegalArgumentException ilex) { + scc_listener_test = true; + LOGGER.error( + "Expected exception thrown adding Listener AddSCListenerClass: " + + ilex.getMessage()); + } catch (Exception ex) { + LOGGER.error( + "Error adding Listener AddSCListenerClass: " + ex.getMessage()); + } + context.setInitParameter(SCC_LISTENER_TEST, scc_listener_test.toString()); + + try { + context.addListener( + "com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddSCListenerString"); + } catch (IllegalArgumentException ilex) { + scs_listener_test = true; + LOGGER.error( + "Expected exception thrown adding Listener AddSCListenerString: " + + ilex.getMessage()); + } catch (Exception ex) { + LOGGER.error( + "Error adding Listener AddSCListenerString: " + ex.getMessage()); + } + context.setInitParameter(SCS_LISTENER_TEST, scs_listener_test.toString()); + + try { + EventListener csclistener = context.createListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.CreateSCListener.class); + context.addListener(csclistener); + } catch (IllegalArgumentException ilex) { + csc_listener_test = true; + LOGGER.error( + "Expected exception thrown adding Listener CreateSCListener: " + + ilex.getMessage()); + } catch (Exception ex) { + LOGGER.error( + "Error adding Listener AddSCListenerClass: " + ex.getMessage()); + } + context.setInitParameter(CSC_LISTENER_TEST, csc_listener_test.toString()); + + /* + * Add Servlet DuplicateServletClass + */ + ServletRegistration srdClass = context.addServlet(addServletName5, + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.DuplicateServletClass.class); + if (srdClass == null) { + duplicatec_servlet_test = true; + } + context.setInitParameter(DUPLICATEC_SERVLET_TEST, + duplicatec_servlet_test.toString()); + + ServletRegistration srdString = context.addServlet(addServletName6, + "com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.DuplicateServletString"); + if (srdString == null) { + duplicates_servlet_test = true; + } + context.setInitParameter(DUPLICATES_SERVLET_TEST, + duplicates_servlet_test.toString()); + + FilterRegistration frdClass = context.addFilter(addFilterName6, + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.DuplicateFilterClass.class); + if (frdClass == null) { + duplicatec_filter_test = true; + } + context.setInitParameter(DUPLICATEC_FILTER_TEST, + duplicatec_filter_test.toString()); + + FilterRegistration frdString = context.addFilter(addFilterName6, + "com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.DuplicateFilterString"); + if (frdString == null) { + duplicates_filter_test = true; + } + context.setInitParameter(DUPLICATES_FILTER_TEST, + duplicates_filter_test.toString()); + + } + + /** + * Receives notification that the servlet context is about to be shut down. + * + * @param sce + * The servlet context event + */ + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/TestServlet.java new file mode 100644 index 0000000000..616a4b1574 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/TestServlet.java @@ -0,0 +1,330 @@ +/* + * Copyright (c) 2009, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Set; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.SessionTrackingMode; + +public class TestServlet extends GenericTCKServlet { + + public void getContextPathTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = false; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + + try { + String tmp = context.getContextPath(); + if (tmp != null) { + pw.println("ServletContextPath=" + tmp); + if (tmp.equals("/servlet_js_servletcontext30_web")) { + passed = true; + } else { + passed = false; + pw.println("Incorrect value returned"); + } + } else { + passed = false; + pw.println("Null value returned for context path"); + } + } catch (Exception ex) { + passed = false; + pw.println("Got Exception when calling getContextPath()"); + } + + sendtoclient(response); + } + + public void testAddFilterString(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + String path = "/addServletString"; + + try { + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + rd.forward(request, response); + } catch (Exception ex) { + response.getWriter() + .println("Got Exception in testAddFilterString: " + ex.getMessage()); + } + response.flushBuffer(); + getServletContext().removeAttribute("arraylist"); + } + + public void testAddFilterClass(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = true; + PrintWriter pw = response.getWriter(); + String path = "/SecondaddServletClass"; + + try { + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + rd.include(request, response); + } catch (Exception ex) { + passed = false; + pw.println("Got Exception in testAddFilterClass: " + ex.getMessage()); + } + + sendtoclient(response); + } + + public void testCreateFilterForward(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = true; + PrintWriter pw = response.getWriter(); + String path = "/SecondCreateServlet"; + + try { + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + rd.forward(request, response); + } catch (Exception ex) { + passed = false; + pw.println( + "Got Exception in testCreateFilterForward: " + ex.getMessage()); + } + ServletTestUtil.printResult(pw, passed); + getServletContext().removeAttribute("arraylist"); + } + + public void testCreateFilterInclude(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = true; + PrintWriter pw = response.getWriter(); + String path = "/ThirdCreateServlet"; + + try { + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + rd.include(request, response); + } catch (Exception ex) { + passed = false; + pw.println( + "Got Exception in testCreateFilterInclude: " + ex.getMessage()); + } + + sendtoclient(response); + } + + public void testCreateSRAListener(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + String path = "/ThirdAddServletClass"; + + request.setAttribute("TestCreateSRAListener", "See_what_happens"); + + try { + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + rd.include(request, response); + } catch (Exception ex) { + response.getWriter().println( + "Got Exception in TestCreateSRAListener: " + ex.getMessage()); + } + sendtoclient(response); + } + + public void negativeCreateTests(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String[] names = { "SERVLET_TEST", "FILTER_TEST", "LISTENER_TEST", + "SCC_LISTENER_TEST", "SCS_LISTENER_TEST", "CSC_LISTENER_TEST", + "DUPLICATEC_SERVLET_TEST", "DUPLICATES_SERVLET_TEST", + "DUPLICATEC_FILTER_TEST", "DUPLICATES_FILTER_TEST" }; + + for (String name : names) { + pw.println(name + "=" + + getServletContext().getInitParameter(name).toUpperCase()); + getServletContext().removeAttribute(name); + } + + ServletTestUtil.printResult(pw, true); + getServletContext().removeAttribute("arraylist"); + } + + public void duplicateServletTest3(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String[] names = { "DUPLICATEC_SERVLET_TEST", "DUPLICATES_SERVLET_TEST" }; + + for (String name : names) { + pw.println(name + "=" + + getServletContext().getInitParameter(name).toUpperCase()); + getServletContext().removeAttribute(name); + } + + ServletTestUtil.printResult(pw, true); + getServletContext().removeAttribute("arraylist"); + } + + public void duplicateFilterTest1(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String[] names = { "DUPLICATEC_FILTER_TEST", "DUPLICATES_FILTER_TEST" }; + + for (String name : names) { + pw.println(name + "=" + + getServletContext().getInitParameter(name).toUpperCase()); + getServletContext().removeAttribute(name); + } + + ServletTestUtil.printResult(pw, true); + getServletContext().removeAttribute("arraylist"); + } + + public void getEffectiveMajorVersionTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + ServletContext context = getServletContext(); + + pw.println( + "EFFECTIVEMAJORVERSION=" + context.getEffectiveMajorVersion() + ";"); + + ServletTestUtil.printResult(pw, true); + getServletContext().removeAttribute("arraylist"); + } + + public void getEffectiveMinorVersionTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + ServletContext context = getServletContext(); + + pw.println( + "EFFECTIVEMINORVERSION=" + context.getEffectiveMinorVersion() + ";"); + + ServletTestUtil.printResult(pw, true); + getServletContext().removeAttribute("arraylist"); + } + + public void getDefaultSessionTrackingModes(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + Boolean pass = true; + PrintWriter pw = response.getWriter(); + ServletContext context = getServletContext(); + + Set results = context.getDefaultSessionTrackingModes(); + for (SessionTrackingMode tmp : results) { + if (tmp == SessionTrackingMode.COOKIE || tmp == SessionTrackingMode.URL + || tmp == SessionTrackingMode.SSL) { + pw.println("getDefaultSessionTrackingModes=" + tmp + ";"); + } else { + pass = false; + } + } + + ServletTestUtil.printResult(pw, pass); + getServletContext().removeAttribute("arraylist"); + } + + public void sessionTrackingModesValueOfTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + Boolean pass = true; + PrintWriter pw = response.getWriter(); + + if (!SessionTrackingMode.valueOf("COOKIE") + .equals(SessionTrackingMode.COOKIE)) { + pass = false; + pw.println("String COOKIE didn't yield coorect SessionTrackingMode."); + } else if (!SessionTrackingMode.valueOf("URL") + .equals(SessionTrackingMode.URL)) { + pass = false; + pw.println("String URL didn't yield coorect SessionTrackingMode."); + } else if (!SessionTrackingMode.valueOf("SSL") + .equals(SessionTrackingMode.SSL)) { + pass = false; + pw.println("String SSL didn't yield coorect SessionTrackingMode."); + } + + ServletTestUtil.printResult(pw, pass); + getServletContext().removeAttribute("arraylist"); + } + + public void sessionTrackingModesValuesTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + Boolean pass = true; + PrintWriter pw = response.getWriter(); + + SessionTrackingMode[] values_expected = new SessionTrackingMode[3]; + values_expected[0] = SessionTrackingMode.COOKIE; + values_expected[1] = SessionTrackingMode.URL; + values_expected[2] = SessionTrackingMode.SSL; + + int i = 0; + SessionTrackingMode[] values_received = new SessionTrackingMode[3]; + + for (SessionTrackingMode c : SessionTrackingMode.values()) { + values_received[i] = c; + i++; + } + + for (i = 0; i < 3; i++) { + if (!values_expected[i].equals(values_received[i])) { + pass = false; + pw.println("The number " + i + " SessionTrackingMode didn't match."); + pw.println( + "Expecting " + values_expected[i] + ". Got " + values_received[i]); + } + } + + ServletTestUtil.printResult(pw, pass); + getServletContext().removeAttribute("arraylist"); + } + + private void sendtoclient(ServletResponse response) throws IOException { + PrintWriter pw = response.getWriter(); + ArrayList result = (ArrayList) getServletContext() + .getAttribute("arraylist"); + + if (result != null) { + for (Object tmp : result) { + if (tmp != null) { + pw.println(tmp.toString()); + } + } + } + getServletContext().removeAttribute("arraylist"); + + result = StaticLog.getClear(); + if (result != null) { + for (Object tmp : result) { + if (tmp != null) { + pw.println(tmp.toString()); + } + } + } + StaticLog.clear(); + + ServletTestUtil.printResult(pw, true); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/URLClient.java new file mode 100644 index 0000000000..c8d25a7a6b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/URLClient.java @@ -0,0 +1,595 @@ +/* + * Copyright (c) 2009, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_servletcontext30_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(AddFilterClass.class, AddFilterNotFound.class, AddFilterString.class, AddSCAttributeListenerClass.class, + AddSCAttributeListenerString.class, AddSCListenerClass.class, AddSCListenerString.class, AddServletClass.class, + AddServletNotFound.class, AddServletString.class, AddSRAttributeListenerClass.class, AddSRAttributeListenerString.class, + AddSRListenerClass.class, AddSRListenerString.class, BadFilter.class, BadListener.class, BadServlet.class, + CreateFilter.class, CreateSCAttributeListener.class, CreateSCListener.class, CreateServlet.class, CreateSRAttributeListener.class, + CreateSRListener.class, DuplicateFilterClass.class, DuplicateFilterString.class, DuplicateServletClass.class, DuplicateServletString.class, + FilterTestServlet.class, TestListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_js_servletcontext30_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * Test setup; In Deployment Descriptor, a Servlet TestServlet and Listener + * TestListener; TestListener extends ServletContextListener; + * + * In TestListener, three Servlets are added using the following methods: - + * ServletContext.addServlet(String, String); - + * ServletContext.addServlet(String, Class); - + * ServletContext.createServlet(Class); + * + * In TestListener, three Filters are added using the following methods: - + * ServletContext.addFilter(String, String); - + * ServletContext.addFilter(String, Class); - + * ServletContext.createServlet(Class); + * + * In TestListener, three Listeners are added using the following methods: - + * ServletContext.addListener(Listener Class) - + * ServletContext.addListener(Listener name) - EventListener listener = + * ServletContext.createListener(class); ServletContext.addListener(listener); + * for all three following Listeners: - ServletContextAttributeListener - + * ServletRequestListener - ServletRequestAttributesListener + */ + /* + * @testName: getContextPathTest + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:637; Servlet:JAVADOC:671.1; Servlet:JAVADOC:671.2; + * Servlet:JAVADOC:671.3; Servlet:JAVADOC:672.1; Servlet:JAVADOC:672.2; + * Servlet:JAVADOC:672.3; Servlet:JAVADOC:673.1; Servlet:JAVADOC:673.2; + * Servlet:JAVADOC:673.3; Servlet:JAVADOC:679; + * + * @test_Strategy: In TestServlet verify that the result from the + * ServletContext.getServletContextPath call returns the context path. + * + * In client verify that all Listeners are added correctly and invoked in the + * order added. + */ + @Test + public void getContextPathTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getContextPathTest"); + TEST_PROPS.setProperty(SEARCH_STRING, + "AddSRListenerClass_INVOKED" + "|AddSRListenerString_INVOKED" + + "|CreateSRListener_INVOKED" + "|AttributeAddedClass" + + "|AttributeAddedString"); + invoke(); + } + + /* + * @testName: testAddServletString + * + * @assertion_ids: Servlet:JAVADOC:655; Servlet:JAVADOC:668; + * Servlet:JAVADOC:671.1; Servlet:JAVADOC:671.2; Servlet:JAVADOC:671.3; + * Servlet:JAVADOC:672.1; Servlet:JAVADOC:672.2; Servlet:JAVADOC:672.3; + * Servlet:JAVADOC:673.1; Servlet:JAVADOC:673.2; Servlet:JAVADOC:673.3; + * Servlet:JAVADOC:674; Servlet:JAVADOC:679; Servlet:JAVADOC:696; + * + * @test_Strategy: Create a ServletContextListener, in which, 1. create a + * Servlet by calling ServletContext.addServlet(String, String), 2. mapping + * the new Servlet programmatically. 3. create a Filter by + * ServletContext.addFilter(String, String) 4. map the filter to the new + * Servlet programmatically for FORWARD only 5. client send a request to the + * new servlet, Verify in client that request goes through and Filter is NOT + * invoked. Verify in client that all Listeners are added correctly and + * invoked in the order added. + */ + @Test + public void testAddServletString() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/addServletString HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, + "ADD_FILTER_STRING_INVOKED"); + TEST_PROPS.setProperty(SEARCH_STRING, + "AddSRListenerClass_INVOKED" + "|AddSRListenerString_INVOKED" + + "|CreateSRListener_INVOKED" + "|SCAttributeAddedClass:" + + "|SCAttributeAddedString:" + "|SCAttributeAdded:"); + invoke(); + } + + /* + * @testName: testAddFilterString + * + * @assertion_ids: Servlet:JAVADOC:655; Servlet:JAVADOC:668; + * Servlet:JAVADOC:671.1; Servlet:JAVADOC:671.2; Servlet:JAVADOC:671.3; + * Servlet:JAVADOC:672.1; Servlet:JAVADOC:672.2; Servlet:JAVADOC:672.3; + * Servlet:JAVADOC:673.1; Servlet:JAVADOC:673.2; Servlet:JAVADOC:673.3; + * Servlet:JAVADOC:674; Servlet:JAVADOC:679; Servlet:JAVADOC:696; + * + * @test_Strategy: Create a ServletContextListener, in which, 1. create a + * Servlet by calling ServletContext.addServlet(String, String), 2. mapping + * the new Servlet programmatically. 3. create a Filter by + * ServletContext.addFilter(String, String) 4. map the filter to the new + * Servlet programmatically for FORWARD only 5. client send a request to + * another servlet, 6. which then forward to the newly created Servlet Verify + * in client that request goes through and Filter IS invoked. Verify in client + * that all Listeners are added correctly and invoked in the order added. + */ + @Test + public void testAddFilterString() throws Exception { + TEST_PROPS.setProperty(APITEST, "testAddFilterString"); + TEST_PROPS.setProperty(SEARCH_STRING, + "AddServletString" + "|AddSRListenerClass_INVOKED" + + "|AddSRListenerString_INVOKED" + "|CreateSRListener_INVOKED" + + "|ADD_FILTER_STRING_INVOKED" + "|SCAttributeAddedClass:" + + "|SCAttributeAddedString:" + "|SCAttributeAdded:"); + invoke(); + } + + /* + * @testName: testAddServletClass + * + * @assertion_ids: Servlet:JAVADOC:655; Servlet:JAVADOC:670; + * Servlet:JAVADOC:671.1; Servlet:JAVADOC:671.2; Servlet:JAVADOC:671.3; + * Servlet:JAVADOC:672.1; Servlet:JAVADOC:672.2; Servlet:JAVADOC:672.3; + * Servlet:JAVADOC:676; Servlet:JAVADOC:679; Servlet:JAVADOC:696; + * + * @test_Strategy: Create a ServletContextListener, in which, 1. create a + * Servlet by calling ServletContext.addServlet(String, Class), 2. mapping the + * new Servlet programmatically. 3. create a Filter by + * ServletContext.addFilter(String, Class) 4. map the filter to the new + * Servlet programmatically for REQUEST only 5. client send a request to the + * new servlet, Verify in client that request goes through and Filter is + * invoked. Verify in client that all Listeners are added correctly and + * invoked in the order added. + */ + @Test + public void testAddServletClass() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/addServletClass HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, + "AddServletClass" + "|AddSRListenerClass_INVOKED" + + "|AddSRListenerString_INVOKED" + "|CreateSRListener_INVOKED" + + "|ADD_FILTER_CLASS_INVOKED" + "|SCAttributeAddedClass:" + + "|SCAttributeAddedString:" + "|SCAttributeAdded:"); + invoke(); + } + + /* + * @testName: testAddFilterClass + * + * @assertion_ids: Servlet:JAVADOC:655; Servlet:JAVADOC:670; + * Servlet:JAVADOC:671.1; Servlet:JAVADOC:671.2; Servlet:JAVADOC:671.3; + * Servlet:JAVADOC:672.1; Servlet:JAVADOC:672.2; Servlet:JAVADOC:672.3; + * Servlet:JAVADOC:676; Servlet:JAVADOC:679; Servlet:JAVADOC:696; + * + * @test_Strategy: Create a ServletContextListener, in which, 1. create a + * Servlet by calling ServletContext.addServlet(String, Class), 2. mapping the + * new Servlet programmatically. 3. create a Filter by + * ServletContext.addFilter(String, Class) 4. map the filter to the new + * Servlet programmatically for REQUEST only 5. client send a request to + * another servlet, 6. which then dispatch by include to the newly created + * Servlet Verify in client that request goes through and Filter IS NOT + * invoked. Verify in client that all Listeners are added correctly and + * invoked in the order added. + */ + @Test + public void testAddFilterClass() throws Exception { + TEST_PROPS.setProperty(APITEST, "testAddFilterClass"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, + "ADD_FILTER_CLASS_INVOKED"); + TEST_PROPS.setProperty(SEARCH_STRING, + "AddServletClass" + "|AddSRListenerClass_INVOKED" + + "|AddSRListenerString_INVOKED" + "|CreateSRListener_INVOKED" + + "|SCAttributeAddedClass" + "|SCAttributeAddedString"); + invoke(); + } + + /* + * @testName: testAddServlet + * + * @assertion_ids: Servlet:JAVADOC:655; Servlet:JAVADOC:669; + * Servlet:JAVADOC:670; Servlet:JAVADOC:671.1; Servlet:JAVADOC:671.2; + * Servlet:JAVADOC:671.3; Servlet:JAVADOC:672.1; Servlet:JAVADOC:672.2; + * Servlet:JAVADOC:672.3; Servlet:JAVADOC:673.1; Servlet:JAVADOC:673.2; + * Servlet:JAVADOC:673.3; Servlet:JAVADOC:675; Servlet:JAVADOC:677; + * Servlet:JAVADOC:679; Servlet:JAVADOC:681; Servlet:JAVADOC:696; + * + * @test_Strategy: Create a ServletContextListener, in which, 1. Create a + * Servlet instance using ServletContext.createServlet; 2. Add the Servlet + * instance: ServletContext.addServlet(String, Servlet), 3. mapping the new + * Servlet programmatically. 4. create a Filter instance by + * ServletContext.createFilter; 5 Add the Filter instance: + * ServletContext.addFilter(String, Filter) 6. map the filter to the new + * Servlet programmatically for REQUEST only 7. client send a request to the + * new servlet, Verify in client that request goes through and Filter is + * invoked. Verify in client that all Listeners are added correctly and + * invoked in the order added. + */ + @Test + public void testAddServlet() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/createServlet HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, + "CreateServlet" + "|AddSRListenerClass_INVOKED" + + "|AddSRListenerString_INVOKED" + "|CreateSRListener_INVOKED" + + "|SCAttributeAddedClass:" + "|SCAttributeAddedString:" + + "|SCAttributeAdded:" + "|CREATE_FILTER_INVOKED"); + + invoke(); + } + + /* + * @testName: testAddFilterForward + * + * @assertion_ids: Servlet:JAVADOC:655; Servlet:JAVADOC:669; + * Servlet:JAVADOC:670; Servlet:JAVADOC:671.1; Servlet:JAVADOC:671.2; + * Servlet:JAVADOC:671.3; Servlet:JAVADOC:672.1; Servlet:JAVADOC:672.2; + * Servlet:JAVADOC:672.3; Servlet:JAVADOC:673.1; Servlet:JAVADOC:673.2; + * Servlet:JAVADOC:673.3; Servlet:JAVADOC:675; Servlet:JAVADOC:677; + * Servlet:JAVADOC:679; Servlet:JAVADOC:681; Servlet:JAVADOC:696; + * + * @test_Strategy: Create a ServletContextListener, in which, 1. Create a + * Servlet instance using ServletContext.createServlet; 2. Add the Servlet + * instance: ServletContext.addServlet(String, Servlet), 3. mapping the new + * Servlet programmatically. 4. create a Filter instance by + * ServletContext.createFilter; 5 Add the Filter instance: + * ServletContext.addFilter(String, Filter) 6. map the filter to the new + * Servlet programmatically for REQUEST only 7. client send a request to the + * new servlet via FORWARD, Verify in client that request does go through and + * Filter is NOT invoked. Verify in client that all Listeners are added + * correctly and invoked in the order added. + */ + @Test + public void testAddFilterForward() throws Exception { + TEST_PROPS.setProperty(APITEST, "testCreateFilterForward"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "CREATE_FILTER_INVOKED"); + TEST_PROPS.setProperty(SEARCH_STRING, + "CreateServlet" + "|AddSRListenerClass_INVOKED" + + "|AddSRListenerString_INVOKED" + "|CreateSRListener_INVOKED" + + "|SCAttributeAddedClass:" + "|SCAttributeAddedString:" + + "|SCAttributeAdded:"); + invoke(); + } + + /* + * @testName: testAddFilterInclude + * + * @assertion_ids: Servlet:JAVADOC:655; Servlet:JAVADOC:669; + * Servlet:JAVADOC:670; Servlet:JAVADOC:671.1; Servlet:JAVADOC:671.2; + * Servlet:JAVADOC:671.3; Servlet:JAVADOC:672.1; Servlet:JAVADOC:672.2; + * Servlet:JAVADOC:672.3; Servlet:JAVADOC:673.1; Servlet:JAVADOC:673.2; + * Servlet:JAVADOC:673.3; Servlet:JAVADOC:675; Servlet:JAVADOC:677; + * Servlet:JAVADOC:679; Servlet:JAVADOC:681; Servlet:JAVADOC:696; + * + * @test_Strategy: Create a ServletContextListener, in which, 1. Create a + * Servlet instance using ServletContext.createServlet; 2. Add the Servlet + * instance: ServletContext.addServlet(String, Servlet), 3. mapping the new + * Servlet programmatically. 4. create a Filter instance by + * ServletContext.createFilter; 5 Add the Filter instance: + * ServletContext.addFilter(String, Filter) 6. map the filter to the new + * Servlet programmatically for REQUEST only 7. client send a request to the + * new servlet via INCLUDE, Verify in client that request does go through and + * Filter is NOT invoked. Verify in client that all Listeners are added + * correctly and invoked in the order added. + */ + @Test + public void testAddFilterInclude() throws Exception { + TEST_PROPS.setProperty(APITEST, "testCreateFilterInclude"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "CREATE_FILTER_INVOKED"); + TEST_PROPS.setProperty(SEARCH_STRING, + "CreateServlet" + "|AddSRListenerClass_INVOKED" + + "|AddSRListenerString_INVOKED" + "|CreateSRListener_INVOKED" + + "|SCAttributeAddedClass:" + "|SCAttributeAddedString:" + + "|SCAttributeAdded:"); + invoke(); + } + + /* + * @testName: testAddServletNotFound + * + * @assertion_ids: Servlet:JAVADOC:655; Servlet:JAVADOC:670; + * Servlet:JAVADOC:671.1; Servlet:JAVADOC:671.2; Servlet:JAVADOC:671.3; + * Servlet:JAVADOC:672.1; Servlet:JAVADOC:672.2; Servlet:JAVADOC:672.3; + * Servlet:JAVADOC:673.1; Servlet:JAVADOC:673.2; Servlet:JAVADOC:673.3; + * Servlet:JAVADOC:676; Servlet:JAVADOC:679; Servlet:JAVADOC:696; + * + * @test_Strategy: Create a ServletContextListener, in which, 1. create a + * Servlet by calling ServletContext.addServlet(String, Class), 2. mapping the + * new Servlet programmatically to multiple URLs, one of them is used by + * another Servlet already. 3. create a Filter by + * ServletContext.addFilter(String, Class) 4. map the filter to the new + * Servlet programmatically for all DispatcherType 5. client send a request to + * the new servlet, Verify in client that request does NOT go through and + * Filter is NOT invoked. + */ + @Test + public void testAddServletNotFound() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/addServletNotFound HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, NOT_FOUND); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, + "AddServletNotFound|ADD_FILTER_NOTFOUND"); + invoke(); + } + + /* + * @testName: testCreateSRAListener + * + * @assertion_ids: Servlet:JAVADOC:655; Servlet:JAVADOC:669; + * Servlet:JAVADOC:670; Servlet:JAVADOC:671.1; Servlet:JAVADOC:671.2; + * Servlet:JAVADOC:671.3; Servlet:JAVADOC:672.1; Servlet:JAVADOC:672.2; + * Servlet:JAVADOC:672.3; Servlet:JAVADOC:673.1; Servlet:JAVADOC:673.2; + * Servlet:JAVADOC:673.3; Servlet:JAVADOC:675; Servlet:JAVADOC:677; + * Servlet:JAVADOC:679; Servlet:JAVADOC:681; Servlet:JAVADOC:696; + * + * @test_Strategy: Create a ServletContextListener, in which, one + * ServletContextAttributeListener, one ServletRequestListener one + * ServletRequestAttributeListener are added: 1. Create a Servlet instance + * using ServletContext.createServlet; 2. Add the Servlet instance: + * ServletContext.addServlet(String, Servlet), 3. mapping the new Servlet + * programmatically. 4. create a Filter instance by + * ServletContext.createFilter; 5 Add the Filter instance: + * ServletContext.addFilter(String, Filter) 6. map the filter to the new + * Servlet programmatically for REQUEST only 7. client send a request to + * another servlet, in which, ServletRequestAttributes are added, then + * dispatch to the new servlet via FORWARD Verify in client that - create + * Listener works - request does NOT through and Filter is NOT invoked. - all + * Listeners are added correctly and invoked in the order added. + */ + @Test + public void testCreateSRAListener() throws Exception { + TEST_PROPS.setProperty(APITEST, "testCreateSRAListener"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "CREATE_FILTER_INVOKED"); + TEST_PROPS.setProperty(SEARCH_STRING, + "AddServletClass" + "|AddSRListenerClass_INVOKED" + + "|AddSRListenerString_INVOKED" + "|CreateSRListener_INVOKED" + + "|SCAttributeAddedClass:" + "|SCAttributeAddedString:" + + "|SCAttributeAdded:" + "|SRAttributeAddedClass:" + + "|SRAttributeAddedString:" + "|SRAttributeAdded:"); + invoke(); + } + + /* + * @testName: negativeCreateTests + * + * @assertion_ids: Servlet:JAVADOC:243; Servlet:JAVADOC:678; + * Servlet:JAVADOC:680; Servlet:JAVADOC:682; Servlet:JAVADOC:694; + * Servlet:JAVADOC:671.10; Servlet:JAVADOC:672.10; Servlet:JAVADOC:673.10; + * + * @test_Strategy: 1. Create a Servlet which throws ServletException at init; + * 2. Create a Filter which throws ServletException at init 3. Create a + * EventListener which throws NullPointerException at init 4. Create a + * ServletContextListener + * + * Create another ServletContextListener, in which: 5. Call + * ServletContext.createFilter(Filter) which should fail; 6. Call + * ServletContext.createServlet(Servlet) which fails 7. Call + * ServletContext.createListener(EventListener) which fails 8. Call + * ServletContext.addListener(ServletContextListener.class) which fails 9. + * Call ServletContext.addListener(ServletContextListenerClassName) which + * fails 10. Call ServletContext.createListener(ServletContextListener.class) + * which fails 11. Call ServletContext.setInitParameter to pass information + * about status on 4-6 12. In another Servlet, get all information stored in + * ServletContext InitParameter 13. Send a request to the new Servlet Verify + * that - createServlet failed accordingly; - createFilter failed accordingly; + * - createListener failed accordingly; - addListener failed accordingly; - + * setInitParameter works properly + */ + @Test + public void negativeCreateTests() throws Exception { + TEST_PROPS.setProperty(APITEST, "negativeCreateTests"); + TEST_PROPS.setProperty(SEARCH_STRING, + "SERVLET_TEST=TRUE" + "|FILTER_TEST=TRUE" + "|LISTENER_TEST=TRUE" + + "|SCC_LISTENER_TEST=TRUE" + "|SCS_LISTENER_TEST=TRUE" + + "|CSC_|LISTENER_TEST=TRUE"); + invoke(); + } + + /* + * @testName: duplicateServletTest1 + * + * @assertion_ids: Servlet:JAVADOC:675.5; Servlet:JAVADOC:676.5; + * + * @test_Strategy: 1. Create a Servlet Servlet, define it in web.xml; 2. + * Create a ServletContextListener, in which: 3. try to add the Servlet again + * by calling ServletContext.addServlet(servletName, Servlet.class) 6. Verify + * that the Servlet can be invoked as defined in web.xml1. + */ + @Test + public void duplicateServletTest1() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/DuplicateServletClass HTTP/1.0"); + TEST_PROPS.setProperty(SEARCH_STRING, "DuplicateServletClass"); + invoke(); + } + + /* + * @testName: duplicateServletTest2 + * + * @assertion_ids: Servlet:JAVADOC:674.5; + * + * @test_Strategy: 1. Create a Servlet Servlet, define it in web.xml; 2. + * Create a ServletContextListener, in which: 3. try to add the Servlet again + * by calling ServletContext.addServlet(servletName, "Servlet.class") 4. + * Verify that the Servlet can be invoked as defined in web.xm1. + */ + @Test + public void duplicateServletTest2() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/DuplicateServletString HTTP/1.0"); + TEST_PROPS.setProperty(SEARCH_STRING, "DuplicateServletString"); + invoke(); + } + + /* + * @testName: duplicateServletTest3 + * + * @assertion_ids: Servlet:JAVADOC:674.5; Servlet:JAVADOC:675.5; + * Servlet:JAVADOC:676.5; + * + * @test_Strategy: 1. Create a Servlet Servlet1, define it in web.xml; 2. + * Create a Servlet Servlet2, define it in web.xml; 3. Create a + * ServletContextListener, in which: 4. try to add the Servlet1 again by + * calling ServletContext.addServlet(servletName, Servlet.class) 4. try to add + * the Servlet2 again by calling ServletContext.addServlet(servletName, + * "Servlet.class") 4. Verify null is returned in both cases. + */ + @Test + public void duplicateServletTest3() throws Exception { + TEST_PROPS.setProperty(APITEST, "duplicateServletTest3"); + TEST_PROPS.setProperty(SEARCH_STRING, + "DUPLICATEC_SERVLET_TEST=TRUE" + "|DUPLICATES_SERVLET_TEST=TRUE"); + invoke(); + } + + /* + * @testName: duplicateFilterTest + * + * @assertion_ids: Servlet:JAVADOC:668.4; Servlet:JAVADOC:669.4; + * + * @test_Strategy: 1. Create a Filter Filter1, define it in web.xml; 2. Create + * a Filter Filter2, define it in web.xml; 3. Create a ServletContextListener, + * in which: 4. try to add Filter1 again by calling + * ServletContext.addFilter(FilterName, Filter.class) 5. try to add Filter2 + * again by calling ServletContext.addFilter(FilterName,,"Filter.class") 6. + * Verify that both Filter can be invoked as defined in web.xml + */ + @Test + public void duplicateFilterTest() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/FilterTestServlet HTTP/1.0"); + TEST_PROPS.setProperty(SEARCH_STRING, "FilterTestServlet"); + invoke(); + } + + /* + * @testName: duplicateFilterTest1 + * + * @assertion_ids: Servlet:JAVADOC:668.4; Servlet:JAVADOC:669.4; + * + * @test_Strategy: 1. Create a Filter Filter1, define it in web.xml; 2. Create + * a Filter Filter2, define it in web.xml; 3. Create a ServletContextListener, + * in which: 4. try to add Filter1 again by calling + * ServletContext.addFilter(FilterName, Filter.class) 5. try to add Filter2 + * again by calling ServletContext.addFilter(FilterName,,"Filter.class") 6. + * Verify that null is returned in both cases + */ + @Test + public void duplicateFilterTest1() throws Exception { + TEST_PROPS.setProperty(APITEST, "duplicateFilterTest1"); + TEST_PROPS.setProperty(SEARCH_STRING, + "DUPLICATEC_FILTER_TEST=TRUE" + "|DUPLICATES_FILTER_TEST=TRUE"); + invoke(); + } + + /* + * @testName: getEffectiveMajorVersionTest + * + * @assertion_ids: Servlet:JAVADOC:685; + * + * @test_Strategy: Create a Servlet, in which call + * ServletContext.getEffectiveMajorVersion() Verify that 5 is returned. + */ + @Test + public void getEffectiveMajorVersionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getEffectiveMajorVersionTest"); + TEST_PROPS.setProperty(SEARCH_STRING, "EFFECTIVEMAJORVERSION=5;"); + invoke(); + } + + /* + * @testName: getEffectiveMinorVersionTest + * + * @assertion_ids: Servlet:JAVADOC:686; + * + * @test_Strategy: Create a Servlet, in which call + * ServletContext.getEffectiveMinorVersion() Verify that 0 is returned. + */ + @Test + public void getEffectiveMinorVersionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getEffectiveMinorVersionTest"); + TEST_PROPS.setProperty(SEARCH_STRING, "EFFECTIVEMINORVERSION=0;"); + invoke(); + } + + /* + * @testName: getDefaultSessionTrackingModes + * + * @assertion_ids: Servlet:JAVADOC:684; + * + * @test_Strategy: Create a Servlet, in which call + * ServletContext.getDefaultSessionTrackingModes() Verify it works. + */ + @Test + public void getDefaultSessionTrackingModes() throws Exception { + TEST_PROPS.setProperty(APITEST, "getDefaultSessionTrackingModes"); + invoke(); + } + + /* + * @testName: sessionTrackingModesValueOfTest + * + * @assertion_ids: Servlet:JAVADOC:747; + * + * @test_Strategy: Create a Servlet, verify SessionTrackingModes.valueOf() + * works + */ + @Test + public void sessionTrackingModesValueOfTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "sessionTrackingModesValueOfTest"); + invoke(); + } + + /* + * @testName: sessionTrackingModesValuesTest + * + * @assertion_ids: Servlet:JAVADOC:748; + * + * @test_Strategy: Create a Servlet, verify SessionTrackingModes.values() + * works + */ + @Test + public void sessionTrackingModesValuesTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "sessionTrackingModesValuesTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/build.xml new file mode 100644 index 0000000000..778e80fae6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/build.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/servlet_js_servletcontext30_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/servlet_js_servletcontext30_web.xml new file mode 100644 index 0000000000..25e70c5d44 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext30/servlet_js_servletcontext30_web.xml @@ -0,0 +1,76 @@ + + + + + SerJaxSerServletContext30 + + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.TestListener + + + DuplicateFilterClass + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.DuplicateFilterClass + + + DuplicateFilterString + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.DuplicateFilterString + + + DuplicateFilterClass + /FilterTestServlet + + + DuplicateFilterString + /FilterTestServlet + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.TestServlet + + + FilterTestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.FilterTestServlet + + + DuplicateServletClass + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.DuplicateServletClass + + + DuplicateServletString + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.DuplicateServletString + + + TestServlet + /TestServlet + + + FilterTestServlet + /FilterTestServlet + + + DuplicateServletClass + /DuplicateServletClass + + + DuplicateServletString + /DuplicateServletString + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext301/AddGenericEventListenerClass.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext301/AddGenericEventListenerClass.java new file mode 100644 index 0000000000..1818186c5f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext301/AddGenericEventListenerClass.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext301; + +import java.util.EventListener; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.ServletRequestEvent; + +public final class AddGenericEventListenerClass implements EventListener { + + public void listenerDestroyed(ServletRequestEvent event) { + StaticLog.add("AddGenericEventListenerClass_Destroyed."); + } + + public void listenerInitialized(ServletRequestEvent event) { + StaticLog.add("AddGenericEventListenerClass_Initialized."); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext301/TestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext301/TestListener.java new file mode 100644 index 0000000000..079279c99f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext301/TestListener.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext301; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; + +public class TestListener implements ServletContextListener { + + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce + * The servlet context event + */ + public void contextInitialized(ServletContextEvent sce) { + ServletContext context = sce.getServletContext(); + + /* + * Negative tests for - addListener + */ + + Boolean listener_test = false; + String LISTENER_TEST = "LISTENER_TEST"; + + try { + context.addListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext301.AddGenericEventListenerClass.class); + } catch (IllegalArgumentException ex) { + listener_test = true; + } + context.setInitParameter(LISTENER_TEST, listener_test.toString()); + } + + /** + * Receives notification that the servlet context is about to be shut down. + * + * @param sce + * The servlet context event + */ + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext301/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext301/TestServlet.java new file mode 100644 index 0000000000..eaf0e70e1c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext301/TestServlet.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext301; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void addListenerTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String name = "LISTENER_TEST"; + + pw.println( + name + "=" + getServletContext().getInitParameter(name).toUpperCase()); + getServletContext().removeAttribute(name); + + ServletTestUtil.printResult(pw, true); + getServletContext().removeAttribute("arraylist"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext301/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext301/URLClient.java new file mode 100644 index 0000000000..daac5b5a46 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext301/URLClient.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext301; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_servletcontext301_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(AddGenericEventListenerClass.class, TestListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_js_servletcontext301_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + + /* + * @testName: addListenerTest + * + * @assertion_ids: Servlet:JAVADOC:672.9; Servlet:JAVADOC:673.9; + * + * @test_Strategy: In a ServletContextListener, call: + * ServletContext.addListener(GenericListener.class) GenericListener does not + * implement any of the Listener class on the list: - + * ServletContextAttributeListener - HttpSessionListener - + * HttpSessionAttributeListener - ServletRequestListener - + * ServletRequestAttributeListener Verify the expected + * IllegalArgumentException is thrown. + */ + @Test + public void addListenerTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "addListenerTest"); + TEST_PROPS.setProperty(SEARCH_STRING, "LISTENER_TEST=TRUE"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, + "AddGenericEventListenerClass"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext301/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext301/build.xml new file mode 100644 index 0000000000..17565dbdf5 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext301/build.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext301/servlet_js_servletcontext301_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext301/servlet_js_servletcontext301_web.xml new file mode 100644 index 0000000000..d483d2797f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext301/servlet_js_servletcontext301_web.xml @@ -0,0 +1,36 @@ + + + + + SerJaxSerServletContext301 + + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext301.TestListener + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext301.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext302/TestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext302/TestListener.java new file mode 100644 index 0000000000..c96a3ae617 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext302/TestListener.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext302; + +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext301.AddGenericEventListenerClass; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; + +public class TestListener implements ServletContextListener { + + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce + * The servlet context event + */ + public void contextInitialized(ServletContextEvent sce) { + ServletContext context = sce.getServletContext(); + + /* + * Negative tests for - addListener + */ + Boolean listener_test = false; + String LISTENER_TEST = "LISTENER_TEST"; + + try { + context.addListener(AddGenericEventListenerClass.class.getName()); + } catch (IllegalArgumentException ex) { + listener_test = true; + } + context.setInitParameter(LISTENER_TEST, listener_test.toString()); + } + + /** + * Receives notification that the servlet context is about to be shut down. + * + * @param sce + * The servlet context event + */ + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext302/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext302/URLClient.java new file mode 100644 index 0000000000..578ccf43af --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext302/URLClient.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext302; + +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext301.AddGenericEventListenerClass; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext301.TestServlet; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_servletcontext302_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestListener.class, AddGenericEventListenerClass.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_js_servletcontext302_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + + /* + * @testName: addListenerTest + * + * @assertion_ids: Servlet:JAVADOC:671.9; + * + * @test_Strategy: In a ServletContextListener, call: + * ServletContext.addListener(String GenericListener.className) + * GenericListener does not implement any of the Listener class on the list: - + * ServletContextAttributeListener - HttpSessionListener - + * HttpSessionAttributeListener - ServletRequestListener - + * ServletRequestAttributeListener Verify the expected + * IllegalArgumentException is thrown. + */ + @Test + public void addListenerTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "addListenerTest"); + TEST_PROPS.setProperty(SEARCH_STRING, "LISTENER_TEST=TRUE"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, + "AddGenericEventListenerString"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext302/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext302/build.xml new file mode 100644 index 0000000000..6195812857 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext302/build.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext302/servlet_js_servletcontext302_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext302/servlet_js_servletcontext302_web.xml new file mode 100644 index 0000000000..518b6db71d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext302/servlet_js_servletcontext302_web.xml @@ -0,0 +1,36 @@ + + + + + SerJaxSerServletContext301 + + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext302.TestListener + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext301.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext303/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext303/TestServlet.java new file mode 100644 index 0000000000..aacabd7933 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext303/TestServlet.java @@ -0,0 +1,193 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext303; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void negativeaddSRAListenerClassTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + Boolean passed = false; + + try { + getServletContext().addListener( + com.sun.ts.tests.servlet.api.common.sharedfiles.SRAttributeListener.class); + } catch (Exception exf) { + if (exf instanceof java.lang.IllegalStateException) { + passed = true; + pw.print("Expected IllegalStateException is thrown: "); + } else { + pw.print("Unexpected Exception type is thrown: "); + exf.printStackTrace(pw); + } + ServletTestUtil.printResult(pw, passed); + } + } + + public void negativeaddSRAListenerStringTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + Boolean passed = false; + + try { + getServletContext().addListener( + "com.sun.ts.tests.servlet.api.common.sharedfiles.SRAttributeListener"); + } catch (Exception exf) { + if (exf instanceof java.lang.IllegalStateException) { + passed = true; + pw.print("Expected IllegalStateException is thrown: "); + } else { + pw.print("Unexpected Exception type is thrown: "); + exf.printStackTrace(pw); + } + ServletTestUtil.printResult(pw, passed); + } + } + + public void negativeaddSRListenerClassTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + Boolean passed = false; + + try { + getServletContext().addListener( + com.sun.ts.tests.servlet.api.common.sharedfiles.SRListener.class); + } catch (Exception exf) { + if (exf instanceof java.lang.IllegalStateException) { + passed = true; + pw.print("Expected IllegalStateException is thrown: "); + } else { + pw.print("Unexpected Exception type is thrown: "); + exf.printStackTrace(pw); + } + ServletTestUtil.printResult(pw, passed); + } + } + + public void negativeaddSRListenerStringTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + Boolean passed = false; + + try { + getServletContext().addListener( + "com.sun.ts.tests.servlet.api.common.sharedfiles.SRListener"); + } catch (Exception exf) { + if (exf instanceof java.lang.IllegalStateException) { + passed = true; + pw.print("Expected IllegalStateException is thrown: "); + } else { + pw.print("Unexpected Exception type is thrown: "); + exf.printStackTrace(pw); + } + ServletTestUtil.printResult(pw, passed); + } + } + + public void negativeaddSCAListenerClassTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + Boolean passed = false; + + try { + getServletContext().addListener( + com.sun.ts.tests.servlet.api.common.sharedfiles.SCAttributeListener.class); + } catch (Exception exf) { + if (exf instanceof java.lang.IllegalStateException) { + passed = true; + pw.print("Expected IllegalStateException is thrown: "); + } else { + pw.print("Unexpected Exception type is thrown: "); + exf.printStackTrace(pw); + } + ServletTestUtil.printResult(pw, passed); + } + } + + public void negativeaddSCAListenerStringTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + Boolean passed = false; + + try { + getServletContext().addListener( + "com.sun.ts.tests.servlet.api.common.sharedfiles.SCAttributeListener"); + } catch (Exception exf) { + if (exf instanceof java.lang.IllegalStateException) { + passed = true; + pw.print("Expected IllegalStateException is thrown: "); + } else { + pw.print("Unexpected Exception type is thrown: "); + exf.printStackTrace(pw); + } + ServletTestUtil.printResult(pw, passed); + } + } + + public void negativeaddSCListenerClassTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + Boolean passed = false; + + try { + getServletContext().addListener( + com.sun.ts.tests.servlet.api.common.sharedfiles.SCListener.class); + } catch (Exception exf) { + if (exf instanceof java.lang.IllegalStateException) { + passed = true; + pw.print("Expected IllegalStateException is thrown: "); + } else { + pw.print("Unexpected Exception type is thrown: "); + exf.printStackTrace(pw); + } + ServletTestUtil.printResult(pw, passed); + } + } + + public void negativeaddSCListenerStringTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + Boolean passed = false; + + try { + getServletContext().addListener( + "com.sun.ts.tests.servlet.api.common.sharedfiles.SCListener"); + } catch (Exception exf) { + if (exf instanceof java.lang.IllegalStateException) { + passed = true; + pw.print("Expected IllegalStateException is thrown: "); + } else { + pw.print("Unexpected Exception type is thrown: "); + exf.printStackTrace(pw); + } + ServletTestUtil.printResult(pw, passed); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext303/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext303/URLClient.java new file mode 100644 index 0000000000..3ab1cf60e2 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext303/URLClient.java @@ -0,0 +1,181 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext303; + +import com.sun.ts.tests.servlet.api.common.sharedfiles.SCAttributeListener; +import com.sun.ts.tests.servlet.api.common.sharedfiles.SCListener; +import com.sun.ts.tests.servlet.api.common.sharedfiles.SRAttributeListener; +import com.sun.ts.tests.servlet.api.common.sharedfiles.SRListener; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_servletcontext303_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestServlet.class, SRAttributeListener.class, SRListener.class, SRListener.class, + SCAttributeListener.class, SCListener.class) + .setWebXML(URLClient.class.getResource("servlet_js_servletcontext303_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + + /* + * @testName: negativeaddSRAListenerClassTest + * + * @assertion_ids: Servlet:JAVADOC:672.11; Servlet:JAVADOC:673.11; + * + * @test_Strategy: Create a Servlet, in which, a + * ServletRequestAttributeListener is added; Verify in servlet that + * java.lang.IllegalStateException is thrown. + */ + @Test + public void negativeaddSRAListenerClassTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "negativeaddSRAListenerClassTest"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "SRAttributeListener"); + invoke(); + } + + /* + * @testName: negativeaddSRAListenerStringTest + * + * @assertion_ids: Servlet:JAVADOC:671.11; + * + * @test_Strategy: Create a Servlet, in which, a + * ServletRequestAttributeListener is added; Verify in servlet that + * java.lang.IllegalStateException is thrown. + */ + @Test + public void negativeaddSRAListenerStringTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "negativeaddSRAListenerStringTest"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "SRAttributeListener"); + invoke(); + } + + /* + * @testName: negativeaddSRListenerClassTest + * + * @assertion_ids: Servlet:JAVADOC:672.11; Servlet:JAVADOC:673.11; + * + * @test_Strategy: Create a Servlet, in which, a ServletRequestListener is + * added; Verify in servlet that java.lang.IllegalStateException is thrown. + */ + @Test + public void negativeaddSRListenerClassTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "negativeaddSRListenerClassTest"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "SRListener"); + invoke(); + } + + /* + * @testName: negativeaddSRListenerStringTest + * + * @assertion_ids: Servlet:JAVADOC:671.11; + * + * @test_Strategy: Create a Servlet, in which, a ServletRequestListener is + * added; Verify in servlet that java.lang.IllegalStateException is thrown. + */ + @Test + public void negativeaddSRListenerStringTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "negativeaddSRListenerStringTest"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "SRListener"); + invoke(); + } + + /* + * @testName: negativeaddSCAListenerClassTest + * + * @assertion_ids: Servlet:JAVADOC:672.11; Servlet:JAVADOC:673.11; + * + * @test_Strategy: Create a Servlet, in which, a + * ServletContextAttributeListener is added; Verify in servlet that + * java.lang.IllegalStateException is thrown. + */ + @Test + public void negativeaddSCAListenerClassTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "negativeaddSCAListenerClassTest"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "SRListener"); + invoke(); + } + + /* + * @testName: negativeaddSCAListenerStringTest + * + * @assertion_ids: Servlet:JAVADOC:671.11; + * + * @test_Strategy: Create a Servlet, in which, a + * ServletContextAttributeListener is added; Verify in servlet that + * java.lang.IllegalStateException is thrown. + */ + @Test + public void negativeaddSCAListenerStringTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "negativeaddSCAListenerStringTest"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "SCAttributeListener"); + invoke(); + } + + /* + * @testName: negativeaddSCListenerClassTest + * + * @assertion_ids: Servlet:JAVADOC:672.11; Servlet:JAVADOC:673.11; + * + * @test_Strategy: Create a Servlet, in which, a ServletContextListener is + * added; Verify in servlet that java.lang.IllegalStateException is thrown. + */ + @Test + public void negativeaddSCListenerClassTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "negativeaddSCListenerClassTest"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "SCListener"); + invoke(); + } + + /* + * @testName: negativeaddSCListenerStringTest + * + * @assertion_ids: Servlet:JAVADOC:671.11; + * + * @test_Strategy: Create a Servlet, in which, a ServletContextListener is + * added; Verify in servlet that java.lang.IllegalStateException is thrown. + */ + @Test + public void negativeaddSCListenerStringTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "negativeaddSCListenerStringTest"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "SCListener"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext303/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext303/build.xml new file mode 100644 index 0000000000..cec1e38368 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext303/build.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext303/servlet_js_servletcontext303_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext303/servlet_js_servletcontext303_web.xml new file mode 100644 index 0000000000..4e660a8e97 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext303/servlet_js_servletcontext303_web.xml @@ -0,0 +1,33 @@ + + + + + SerJaxSerServletContext303 + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext303.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext304/CreateGenericEventListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext304/CreateGenericEventListener.java new file mode 100644 index 0000000000..20b4cb0cc5 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext304/CreateGenericEventListener.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext304; + +import java.util.EventListener; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.ServletRequestEvent; + +public final class CreateGenericEventListener implements EventListener { + + public void listenerDestroyed(ServletRequestEvent event) { + StaticLog.add("CreateGenericEventListener_Destroyed."); + } + + public void listenerInitialized(ServletRequestEvent event) { + StaticLog.add("CreateGenericEventListener_Initialized."); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext304/TestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext304/TestListener.java new file mode 100644 index 0000000000..2d5269bd63 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext304/TestListener.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext304; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; +import jakarta.servlet.ServletException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class TestListener implements ServletContextListener { + + private static final Logger LOGGER = LoggerFactory.getLogger(TestListener.class); + + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce + * The servlet context event + */ + public void contextInitialized(ServletContextEvent sce) { + ServletContext context = sce.getServletContext(); + + Boolean listener_test = false; + String LISTENER_TEST = "LISTENER_TEST"; + + try { + context.createListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext304.CreateGenericEventListener.class); + } catch (java.lang.IllegalArgumentException ex) { + listener_test = true; + LOGGER.error("Error creating Listener CreateGenericEventListener: " + + ex.getMessage()); + } catch (ServletException exs) { + LOGGER.error("Error creating Listener CreateGenericEventListener: " + + exs.getMessage()); + } + context.setInitParameter(LISTENER_TEST, listener_test.toString()); + } + + /** + * Receives notification that the servlet context is about to be shut down. + * + * @param sce + * The servlet context event + */ + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext304/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext304/URLClient.java new file mode 100644 index 0000000000..047de6f96a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext304/URLClient.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext304; + +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext301.TestServlet; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_servletcontext304_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestListener.class, CreateGenericEventListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_js_servletcontext304_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + + /* + * @testName: addListenerTest + * + * @assertion_ids: Servlet:JAVADOC:679.4; + * + * @test_Strategy: In a ServletContextListener, call: + * ServletContext.createListener(GenericListener.class) GenericListener does + * not implement any of the Listener class on the list: - + * ServletContextAttributeListener - HttpSessionListener - + * HttpSessionAttributeListener - ServletRequestListener - + * ServletRequestAttributeListener Verify the expected + * IllegalArgumentException is thrown. + */ + @Test + public void addListenerTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "addListenerTest"); + TEST_PROPS.setProperty(SEARCH_STRING, "LISTENER_TEST=TRUE"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, + "CreateGenericEventListener"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext304/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext304/build.xml new file mode 100644 index 0000000000..28388d7d1f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext304/build.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext304/servlet_js_servletcontext304_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext304/servlet_js_servletcontext304_web.xml new file mode 100644 index 0000000000..ffe8acf899 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext304/servlet_js_servletcontext304_web.xml @@ -0,0 +1,36 @@ + + + + + SerJaxSerServletContext301 + + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext304.TestListener + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext301.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext305/AddSCListenerClass.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext305/AddSCListenerClass.java new file mode 100644 index 0000000000..2838190a54 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext305/AddSCListenerClass.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext305; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; + +public class AddSCListenerClass implements ServletContextListener { + + public void contextDestroyed(ServletContextEvent event) { + StaticLog.add("AddSCListenerClass Destroyed."); + } + + public void contextInitialized(ServletContextEvent event) { + StaticLog.add("AddSCListenerClass Initialized."); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext305/AddSCListenerString.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext305/AddSCListenerString.java new file mode 100644 index 0000000000..2a2d140b9e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext305/AddSCListenerString.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext305; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; + +public class AddSCListenerString implements ServletContextListener { + + public void contextDestroyed(ServletContextEvent event) { + StaticLog.add("AddSCListenerString Destroyed."); + } + + public void contextInitialized(ServletContextEvent event) { + StaticLog.add("AddSCListenerString Initialized."); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext305/CreateSCListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext305/CreateSCListener.java new file mode 100644 index 0000000000..f12c048068 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext305/CreateSCListener.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext305; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; + +public class CreateSCListener implements ServletContextListener { + + public void contextDestroyed(ServletContextEvent event) { + StaticLog.add("CreateSCListener Destroyed."); + } + + public void contextInitialized(ServletContextEvent event) { + StaticLog.add("CreateSCListener Initialized."); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext305/TestContainerInitializer.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext305/TestContainerInitializer.java new file mode 100644 index 0000000000..cc74363d0a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext305/TestContainerInitializer.java @@ -0,0 +1,270 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext305; + +import java.util.EnumSet; +import java.util.EventListener; +import java.util.Set; + +import jakarta.servlet.DispatcherType; +import jakarta.servlet.Filter; +import jakarta.servlet.FilterRegistration; +import jakarta.servlet.Servlet; +import jakarta.servlet.ServletContainerInitializer; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRegistration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class TestContainerInitializer implements ServletContainerInitializer { + + private static final Logger LOGGER = LoggerFactory.getLogger(TestContainerInitializer.class); + + public void onStartup(Set> arg0, ServletContext context) + throws ServletException { + + final String addServletName1 = "AddServletString"; + final String addServletName2 = "AddServletClass"; + final String addServletName3 = "CreateServlet"; + final String addServletName4 = "AddServletNotFound"; + + final String addFilterName1 = "AddFilterString"; + final String addFilterName2 = "AddFilterClass"; + final String addFilterName3 = "CreateFilter"; + final String addFilterName4 = "AddFilterNotFound"; + /* + * Add Servlet AddServletString + */ + ServletRegistration srString = context.addServlet(addServletName1, + "com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddServletString"); + srString.addMapping("/addServletString"); + srString.setInitParameter("FILTER", addFilterName1); + srString.setInitParameter(addFilterName1, + DispatcherType.FORWARD.toString()); + + FilterRegistration frString = context.addFilter(addFilterName1, + "com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddFilterString"); + frString.addMappingForServletNames(EnumSet.of(DispatcherType.FORWARD), true, + addServletName1); + frString.setInitParameter("SERVLET", addServletName1); + frString.setInitParameter(addServletName1, + DispatcherType.FORWARD.toString()); + + /* + * Add Servlet AddServletClass + */ + ServletRegistration srClass = context.addServlet(addServletName2, + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddServletClass.class); + srClass.addMapping("/addServletClass", "/SecondaddServletClass", + "/ThirdAddServletClass", "/AddServletClass/*"); + srClass.setInitParameter("FILTER", addFilterName2); + srClass.setInitParameter(addFilterName2, DispatcherType.REQUEST.toString()); + + FilterRegistration frClass = context.addFilter(addFilterName2, + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddFilterClass.class); + frClass.addMappingForServletNames(EnumSet.of(DispatcherType.REQUEST), true, + addServletName2); + frClass.setInitParameter("SERVLET", addServletName2); + frClass.setInitParameter(addServletName2, + DispatcherType.REQUEST.toString()); + + /* + * Add Servlet CreateServlet + */ + ServletRegistration srServlet = null; + FilterRegistration frFilter = null; + try { + Servlet servlet3 = context.createServlet( + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.CreateServlet.class); + srServlet = context.addServlet(addServletName3, servlet3); + srServlet.addMapping("/createServlet", "/SecondCreateServlet", + "/ThirdCreateServlet"); + srServlet.setInitParameter("FILTER", addFilterName3); + srServlet.setInitParameter(addFilterName3, + DispatcherType.REQUEST.toString()); + + Filter filter3 = context.createFilter( + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.CreateFilter.class); + frFilter = context.addFilter(addFilterName3, filter3); + frFilter.addMappingForServletNames(EnumSet.of(DispatcherType.REQUEST), + true, addServletName3); + frFilter.setInitParameter("SERVLET", addServletName3); + frFilter.setInitParameter(addServletName3, + DispatcherType.REQUEST.toString()); + } catch (ServletException ex) { + LOGGER.error("Error creating Servlet"); + } + + /* + * Add Servlet AddServletNotFound + */ + ServletRegistration srNotFound = context.addServlet(addServletName4, + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddServletNotFound.class); + srNotFound.addMapping("/addServletNotFound", "/TestServlet"); + srNotFound.setInitParameter("FILTER", addFilterName4); + srNotFound.setInitParameter(addFilterName4, "ALL"); + + FilterRegistration frNotFound = context.addFilter(addFilterName4, + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddFilterNotFound.class); + frNotFound.addMappingForServletNames( + EnumSet.of(DispatcherType.REQUEST, DispatcherType.INCLUDE, + DispatcherType.FORWARD, DispatcherType.ERROR), + true, addServletName4); + frNotFound.setInitParameter("SERVLET", addServletName4); + frNotFound.setInitParameter(addServletName4, "ALL"); + + /* + * Add ServletContextListener + */ + context.addListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext305.AddSCListenerClass.class); + + context.addListener( + "com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext305.AddSCListenerString"); + try { + EventListener sclistener = context.createListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext305.CreateSCListener.class); + context.addListener(sclistener); + } catch (ServletException ex) { + LOGGER.error( + "Error creating Listener CreateSCListener: " + ex.getMessage(), ex); + ex.printStackTrace(); + } + + /* + * Add ServletContextAttributeListener + */ + context.addListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddSCAttributeListenerClass.class); + + context.addListener( + "com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddSCAttributeListenerString"); + try { + EventListener scalistener = context.createListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.CreateSCAttributeListener.class); + context.addListener(scalistener); + } catch (ServletException ex) { + LOGGER.error("Error creating Listener CreateSCAttributeListener: " + + ex.getMessage(), ex); + } + + /* + * Add ServletRequestListener + */ + context.addListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddSRListenerClass.class); + context.addListener( + "com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddSRListenerString"); + try { + EventListener srlistener = context.createListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.CreateSRListener.class); + context.addListener(srlistener); + } catch (ServletException ex) { + System.out.println("Error creating Listener CreateSRAttributeListener: " + + ex.getMessage()); + ex.printStackTrace(); + } + + /* + * Add ServletRequestAttributesListener + */ + context.addListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddSRAttributeListenerClass.class); + context.addListener( + "com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddSRAttributeListenerString"); + try { + EventListener sralistener = context.createListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.CreateSRAttributeListener.class); + context.addListener(sralistener); + } catch (ServletException ex) { + System.out.println("Error creating Listener CreateSRAttributeListener: " + + ex.getMessage()); + ex.printStackTrace(); + } + + /* + * Negative tests for - createServlet - createFilter - createListener + */ + + Boolean servlet_test = false; + Boolean filter_test = false; + Boolean listener_test = false; + String SERVLET_TEST = "SERVLET_TEST"; + String FILTER_TEST = "FILTER_TEST"; + String LISTENER_TEST = "LISTENER_TEST"; + String GC_LISTENER_TEST = "GC_LISTENER_TEST"; + String GS_LISTENER_TEST = "GS_LISTENER_TEST"; + String CGC_LISTENER_TEST = "CGC_LISTENER_TEST"; + + try { + Servlet badservlet = context.createServlet( + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.BadServlet.class); + } catch (ServletException ex) { + servlet_test = true; + } + context.setInitParameter(SERVLET_TEST, servlet_test.toString()); + + try { + Filter badfilter = context.createFilter( + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.BadFilter.class); + } catch (ServletException ex) { + filter_test = true; + } + context.setInitParameter(FILTER_TEST, filter_test.toString()); + + try { + context.createListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.BadListener.class); + } catch (ServletException ex) { + listener_test = true; + } + context.setInitParameter(LISTENER_TEST, listener_test.toString()); + + try { + context.addListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext301.AddGenericEventListenerClass.class); + } catch (IllegalArgumentException ex) { + System.out + .println("Error adding Listener addListener: " + ex.getMessage()); + } + context.setInitParameter(GC_LISTENER_TEST, listener_test.toString()); + + try { + context.addListener( + "com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext302.AssGenericEventListenerString"); + } catch (IllegalArgumentException ex) { + listener_test = true; + } + context.setInitParameter(GS_LISTENER_TEST, listener_test.toString()); + + try { + context.createListener( + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext304.CreateGenericEventListener.class); + } catch (java.lang.IllegalArgumentException ex) { + System.out.println("Error creating Listener CreateGenericEventListener: " + + ex.getMessage()); + } catch (ServletException exs) { + System.out.println("Error creating Listener CreateGenericEventListener: " + + exs.getMessage()); + } + context.setInitParameter(CGC_LISTENER_TEST, listener_test.toString()); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext305/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext305/TestServlet.java new file mode 100644 index 0000000000..b488c4f592 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext305/TestServlet.java @@ -0,0 +1,165 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext305; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void testAddFilterString(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + String path = "/addServletString"; + + try { + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + rd.forward(request, response); + } catch (Exception ex) { + response.getWriter() + .println("Got Exception in testAddFilterString: " + ex.getMessage()); + } + response.flushBuffer(); + getServletContext().removeAttribute("arraylist"); + } + + public void testAddFilterClass(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = true; + PrintWriter pw = response.getWriter(); + String path = "/SecondaddServletClass"; + + try { + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + rd.include(request, response); + } catch (Exception ex) { + passed = false; + pw.println("Got Exception in testAddFilterClass: " + ex.getMessage()); + } + + sendtoclient(response); + } + + public void testCreateFilterForward(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = true; + PrintWriter pw = response.getWriter(); + String path = "/SecondCreateServlet"; + + try { + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + rd.forward(request, response); + } catch (Exception ex) { + passed = false; + pw.println( + "Got Exception in testCreateFilterForward: " + ex.getMessage()); + } + ServletTestUtil.printResult(pw, passed); + getServletContext().removeAttribute("arraylist"); + } + + public void testCreateFilterInclude(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = true; + PrintWriter pw = response.getWriter(); + String path = "/ThirdCreateServlet"; + + try { + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + rd.include(request, response); + } catch (Exception ex) { + passed = false; + pw.println( + "Got Exception in testCreateFilterInclude: " + ex.getMessage()); + } + + sendtoclient(response); + } + + public void testCreateSRAListener(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + String path = "/ThirdAddServletClass"; + + request.setAttribute("TestCreateSRAListener", "See_what_happens"); + + try { + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + rd.include(request, response); + } catch (Exception ex) { + response.getWriter().println( + "Got Exception in TestCreateSRAListener: " + ex.getMessage()); + } + sendtoclient(response); + } + + public void negativeCreateTests(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String[] names = { "SERVLET_TEST", "FILTER_TEST", "LISTENER_TEST", + "GC_LISTENER_TEST", "GS_LISTENER_TEST", "CGC_LISTENER_TEST" }; + + for (String name : names) { + pw.println(name + "=" + + getServletContext().getInitParameter(name).toUpperCase()); + getServletContext().removeAttribute(name); + } + + ServletTestUtil.printResult(pw, true); + getServletContext().removeAttribute("arraylist"); + } + + private void sendtoclient(ServletResponse response) throws IOException { + PrintWriter pw = response.getWriter(); + ArrayList result = (ArrayList) getServletContext() + .getAttribute("arraylist"); + + if (result != null) { + for (Object tmp : result) { + if (tmp != null) { + pw.println(tmp.toString()); + } + } + } + getServletContext().removeAttribute("arraylist"); + + result = StaticLog.getClear(); + if (result != null) { + for (Object tmp : result) { + if (tmp != null) { + pw.println(tmp.toString()); + } + } + } + StaticLog.clear(); + + ServletTestUtil.printResult(pw, true); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext305/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext305/URLClient.java new file mode 100644 index 0000000000..ed1a42c217 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext305/URLClient.java @@ -0,0 +1,492 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext305; + +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddFilterClass; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddFilterNotFound; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddFilterString; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddSCAttributeListenerClass; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddSCAttributeListenerString; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddSRAttributeListenerClass; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddSRAttributeListenerString; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddSRListenerClass; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddSRListenerString; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddServletClass; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddServletNotFound; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddServletString; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.BadFilter; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.BadListener; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.BadServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.CreateFilter; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.CreateSCAttributeListener; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.CreateSRAttributeListener; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.CreateSRListener; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.CreateServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext301.AddGenericEventListenerClass; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext304.CreateGenericEventListener; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_servletcontext305_web.war") + .addAsResource(URLClient.class.getResource("jakarta.servlet.ServletContainerInitializer"), + "META-INF/services/jakarta.servlet.ServletContainerInitializer") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(AddSCListenerClass.class, AddSCListenerString.class, CreateSCListener.class, + TestContainerInitializer.class, TestServlet.class, AddServletString.class, AddFilterString.class, + AddFilterClass.class, AddServletClass.class, CreateServlet.class, CreateFilter.class, AddServletNotFound.class, + AddFilterNotFound.class, AddSCAttributeListenerClass.class, CreateSCAttributeListener.class, + AddSRListenerClass.class, CreateSRListener.class, AddSRAttributeListenerClass.class, CreateSRAttributeListener.class, + BadServlet.class, BadFilter.class, BadListener.class, AddGenericEventListenerClass.class, CreateGenericEventListener.class, + AddServletString.class, AddFilterString.class, AddSCAttributeListenerString.class, AddSRListenerString.class, + AddSRAttributeListenerString.class) + .setWebXML(URLClient.class.getResource("servlet_js_servletcontext305_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * Test setup; In Deployment Descriptor, define a Servlet TestServlet; Create + * a SevletContextInitializer, + * + * In SevletContextInitializer, three Servlets are added using the following + * methods: - ServletContext.addServlet(String, String); - + * ServletContext.addServlet(String, Class); - + * ServletContext.createServlet(Class); + * + * In SevletContextInitializer, three Filters are added using the following + * methods: - ServletContext.addFilter(String, String); - + * ServletContext.addFilter(String, Class); - + * ServletContext.createServlet(Class); + * + * In SevletContextInitializer, four Listeners are added using the following + * methods: - ServletContext.addListener(Listener Class) - + * ServletContext.addListener(Listener name) - EventListener listener = + * ServletContext.createListener(class); ServletContext.addListener(listener); + * Test Listeners implements one of all following liseners: - + * ServletContextAttributeListener - ServletRequestListener - + * ServletRequestAttributesListener - ServletContextListener + * + * Package jakarta.servlet.ServletContextInitializer appropriately + */ + + /* + * @testName: testAddServletString + * + * @assertion_ids: Servlet:JAVADOC:655; Servlet:JAVADOC:668; + * Servlet:JAVADOC:668.3; Servlet:JAVADOC:671.1; Servlet:JAVADOC:671.2; + * Servlet:JAVADOC:671.3; Servlet:JAVADOC:671.6; Servlet:JAVADOC:671.7; + * Servlet:JAVADOC:671.9; Servlet:JAVADOC:672.1; Servlet:JAVADOC:672.2; + * Servlet:JAVADOC:672.3; Servlet:JAVADOC:672.6; Servlet:JAVADOC:672.7; + * Servlet:JAVADOC:672.9; Servlet:JAVADOC:673.1; Servlet:JAVADOC:673.2; + * Servlet:JAVADOC:673.3; Servlet:JAVADOC:673.6; Servlet:JAVADOC:673.7; + * Servlet:JAVADOC:673.9; Servlet:JAVADOC:674; Servlet:JAVADOC:674.4; + * Servlet:JAVADOC:679; Servlet:JAVADOC:679.4; Servlet:JAVADOC:696; + * Servlet:SPEC:259; Servlet:SPEC:259.1; Servlet:SPEC:259.3; + * Servlet:SPEC:259.4; Servlet:SPEC:259.6; Servlet:SPEC:259.7; + * + * @test_Strategy: Create a ServletContextInitializer, in which, 1. create a + * Servlet by calling ServletContext.addServlet(String, String), 2. mapping + * the new Servlet programmatically. 3. create a Filter by + * ServletContext.addFilter(String, String) 4. map the filter to the new + * Servlet programmatically for FORWARD only 5. client send a request to the + * new servlet, Verify in client that request goes through and Filter is NOT + * invoked. Verify in client that all Listeners are added correctly and + * invoked in the order added. + */ + @Test + public void testAddServletString() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/addServletString HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, + "ADD_FILTER_STRING_INVOKED"); + TEST_PROPS.setProperty(SEARCH_STRING, + "AddSRListenerClass_INVOKED" + "|AddSRListenerString_INVOKED" + + "|CreateSRListener_INVOKED" + "|SCAttributeAddedClass:" + + "|SCAttributeAddedString:" + "|SCAttributeAdded:"); + invoke(); + } + + /* + * @testName: testAddFilterString + * + * @assertion_ids: Servlet:JAVADOC:655; Servlet:JAVADOC:668; + * Servlet:JAVADOC:668.3; Servlet:JAVADOC:671.1; Servlet:JAVADOC:671.2; + * Servlet:JAVADOC:671.3; Servlet:JAVADOC:671.6; Servlet:JAVADOC:671.7; + * Servlet:JAVADOC:671.9; Servlet:JAVADOC:672.1; Servlet:JAVADOC:672.2; + * Servlet:JAVADOC:672.3; Servlet:JAVADOC:672.6; Servlet:JAVADOC:672.7; + * Servlet:JAVADOC:672.9; Servlet:JAVADOC:673.1; Servlet:JAVADOC:673.2; + * Servlet:JAVADOC:673.3; Servlet:JAVADOC:673.6; Servlet:JAVADOC:673.7; + * Servlet:JAVADOC:673.9; Servlet:JAVADOC:674; Servlet:JAVADOC:674.4; + * Servlet:JAVADOC:675; Servlet:JAVADOC:675.4; Servlet:JAVADOC:676; + * Servlet:JAVADOC:676.4; Servlet:JAVADOC:679; Servlet:JAVADOC:679.1; + * Servlet:JAVADOC:679.4; Servlet:JAVADOC:696; Servlet:SPEC:259; + * Servlet:SPEC:259.1; Servlet:SPEC:259.3; Servlet:SPEC:259.4; + * Servlet:SPEC:259.6; Servlet:SPEC:259.7; + * + * @test_Strategy: Create a ServletContextInitializer, in which, 1. create a + * Servlet by calling ServletContext.addServlet(String, String), 2. mapping + * the new Servlet programmatically. 3. create a Filter by + * ServletContext.addFilter(String, String) 4. map the filter to the new + * Servlet programmatically for FORWARD only 5. client send a request to + * another servlet, 6. which then forward to the newly created Servlet Verify + * in client that request goes through and Filter IS invoked. Verify in client + * that all Listeners are added correctly and invoked in the order added. + */ + @Test + public void testAddFilterString() throws Exception { + TEST_PROPS.setProperty(APITEST, "testAddFilterString"); + TEST_PROPS.setProperty(SEARCH_STRING, + "AddServletString" + "|AddSRListenerClass_INVOKED" + + "|AddSRListenerString_INVOKED" + "|CreateSRListener_INVOKED" + + "|ADD_FILTER_STRING_INVOKED" + "|SCAttributeAddedClass:" + + "|SCAttributeAddedString:" + "|SCAttributeAdded:"); + invoke(); + } + + /* + * @testName: testAddServletClass + * + * @assertion_ids: Servlet:JAVADOC:655; Servlet:JAVADOC:670; + * Servlet:JAVADOC:670.3; Servlet:JAVADOC:671.6; Servlet:JAVADOC:671.7; + * Servlet:JAVADOC:671.9; Servlet:JAVADOC:672.1; Servlet:JAVADOC:672.2; + * Servlet:JAVADOC:672.3; Servlet:JAVADOC:672.6; Servlet:JAVADOC:672.7; + * Servlet:JAVADOC:672.9; Servlet:JAVADOC:676; Servlet:JAVADOC:676.4; + * Servlet:JAVADOC:679; Servlet:JAVADOC:679.1; Servlet:JAVADOC:679.4; + * Servlet:JAVADOC:696; Servlet:SPEC:259; Servlet:SPEC:259.1; + * Servlet:SPEC:259.3; Servlet:SPEC:259.4; Servlet:SPEC:259.6; + * Servlet:SPEC:259.7; + * + * @test_Strategy: Create a ServletContextInitializer, in which, 1. create a + * Servlet by calling ServletContext.addServlet(String, Class), 2. mapping the + * new Servlet programmatically. 3. create a Filter by + * ServletContext.addFilter(String, Class) 4. map the filter to the new + * Servlet programmatically for REQUEST only 5. client send a request to the + * new servlet, Verify in client that request goes through and Filter is + * invoked. Verify in client that all Listeners are added correctly and + * invoked in the order added. + */ + @Test + public void testAddServletClass() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/addServletClass HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, + "AddServletClass" + "|AddSRListenerClass_INVOKED" + + "|AddSRListenerString_INVOKED" + "|CreateSRListener_INVOKED" + + "|ADD_FILTER_CLASS_INVOKED" + "|SCAttributeAddedClass:" + + "|SCAttributeAddedString:" + "|SCAttributeAdded:"); + invoke(); + } + + /* + * @testName: testAddFilterClass + * + * @assertion_ids: Servlet:JAVADOC:655; Servlet:JAVADOC:670; + * Servlet:JAVADOC:670.3; Servlet:JAVADOC:671.6; Servlet:JAVADOC:671.7; + * Servlet:JAVADOC:671.9; Servlet:JAVADOC:672.1; Servlet:JAVADOC:672.2; + * Servlet:JAVADOC:672.3; Servlet:JAVADOC:672.6; Servlet:JAVADOC:672.7; + * Servlet:JAVADOC:672.9; Servlet:JAVADOC:676; Servlet:JAVADOC:676.4; + * Servlet:JAVADOC:679; Servlet:JAVADOC:679.1; Servlet:JAVADOC:679.4; + * Servlet:JAVADOC:696; Servlet:SPEC:259; Servlet:SPEC:259.1; + * Servlet:SPEC:259.3; Servlet:SPEC:259.4; Servlet:SPEC:259.6; + * Servlet:SPEC:259.7; + * + * @test_Strategy: Create a ServletContextInitializer, in which, 1. create a + * Servlet by calling ServletContext.addServlet(String, Class), 2. mapping the + * new Servlet programmatically. 3. create a Filter by + * ServletContext.addFilter(String, Class) 4. map the filter to the new + * Servlet programmatically for REQUEST only 5. client send a request to + * another servlet, 6. which then dispatch by include to the newly created + * Servlet Verify in client that request goes through and Filter IS NOT + * invoked. Verify in client that all Listeners are added correctly and + * invoked in the order added. + */ + @Test + public void testAddFilterClass() throws Exception { + TEST_PROPS.setProperty(APITEST, "testAddFilterClass"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, + "ADD_FILTER_CLASS_INVOKED"); + TEST_PROPS.setProperty(SEARCH_STRING, + "AddServletClass" + "|AddSRListenerClass_INVOKED" + + "|AddSRListenerString_INVOKED" + "|CreateSRListener_INVOKED" + + "|SCAttributeAddedClass" + "|SCAttributeAddedString"); + invoke(); + } + + /* + * @testName: testAddServlet + * + * @assertion_ids: Servlet:JAVADOC:655; Servlet:JAVADOC:669; + * Servlet:JAVADOC:670; Servlet:JAVADOC:670.3; Servlet:JAVADOC:671.1; + * Servlet:JAVADOC:671.2; Servlet:JAVADOC:671.3; Servlet:JAVADOC:671.6; + * Servlet:JAVADOC:671.7; Servlet:JAVADOC:671.9; Servlet:JAVADOC:672.1; + * Servlet:JAVADOC:672.2; Servlet:JAVADOC:672.3; Servlet:JAVADOC:672.6; + * Servlet:JAVADOC:672.7; Servlet:JAVADOC:672.9; Servlet:JAVADOC:675; + * Servlet:JAVADOC:675.4; Servlet:JAVADOC:677; Servlet:JAVADOC:677.1; + * Servlet:JAVADOC:679; Servlet:JAVADOC:679.1; Servlet:JAVADOC:679.4; + * Servlet:JAVADOC:681; Servlet:JAVADOC:696; Servlet:SPEC:259; + * Servlet:SPEC:259.1; Servlet:SPEC:259.3; Servlet:SPEC:259.4; + * Servlet:SPEC:259.6; Servlet:SPEC:259.7; + * + * @test_Strategy: Create a ServletContextInitializer, in which, 1. Create a + * Servlet instance using ServletContext.createServlet; 2. Add the Servlet + * instance: ServletContext.addServlet(String, Servlet), 3. mapping the new + * Servlet programmatically. 4. create a Filter instance by + * ServletContext.createFilter; 5 Add the Filter instance: + * ServletContext.addFilter(String, Filter) 6. map the filter to the new + * Servlet programmatically for REQUEST only 7. client send a request to the + * new servlet, Verify in client that request goes through and Filter is + * invoked. Verify in client that all Listeners are added correctly and + * invoked in the order added. + */ + @Test + public void testAddServlet() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/createServlet HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, + "CreateServlet" + "|AddSRListenerClass_INVOKED" + + "|AddSRListenerString_INVOKED" + "|CreateSRListener_INVOKED" + + "|SCAttributeAddedClass:" + "|SCAttributeAddedString:" + + "|SCAttributeAdded:" + "|CREATE_FILTER_INVOKED"); + + invoke(); + } + + /* + * @testName: testAddFilterForward + * + * @assertion_ids: Servlet:JAVADOC:655; Servlet:JAVADOC:669; + * Servlet:JAVADOC:670; Servlet:JAVADOC:670.3; Servlet:JAVADOC:671.1; + * Servlet:JAVADOC:671.2; Servlet:JAVADOC:671.3; Servlet:JAVADOC:671.6; + * Servlet:JAVADOC:671.7; Servlet:JAVADOC:671.9; Servlet:JAVADOC:672.1; + * Servlet:JAVADOC:672.2; Servlet:JAVADOC:672.3; Servlet:JAVADOC:672.6; + * Servlet:JAVADOC:672.7; Servlet:JAVADOC:672.9; Servlet:JAVADOC:673.1; + * Servlet:JAVADOC:673.2; Servlet:JAVADOC:673.3; Servlet:JAVADOC:673.6; + * Servlet:JAVADOC:673.7; Servlet:JAVADOC:673.9; Servlet:JAVADOC:675; + * Servlet:JAVADOC:675.4; Servlet:JAVADOC:677; Servlet:JAVADOC:677.1; + * Servlet:JAVADOC:679; Servlet:JAVADOC:679.1; Servlet:JAVADOC:679.4; + * + * Servlet:JAVADOC:681; Servlet:JAVADOC:696; Servlet:SPEC:259; + * Servlet:SPEC:259.1; Servlet:SPEC:259.3; Servlet:SPEC:259.4; + * Servlet:SPEC:259.6; Servlet:SPEC:259.7; + * + * @test_Strategy: Create a ServletContextInitializer, in which, 1. Create a + * Servlet instance using ServletContext.createServlet; 2. Add the Servlet + * instance: ServletContext.addServlet(String, Servlet), 3. mapping the new + * Servlet programmatically. 4. create a Filter instance by + * ServletContext.createFilter; 5 Add the Filter instance: + * ServletContext.addFilter(String, Filter) 6. map the filter to the new + * Servlet programmatically for REQUEST only 7. client send a request to the + * new servlet via FORWARD, Verify in client that request does go through and + * Filter is NOT invoked. Verify in client that all Listeners are added + * correctly and invoked in the order added. + */ + @Test + public void testAddFilterForward() throws Exception { + TEST_PROPS.setProperty(APITEST, "testCreateFilterForward"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "CREATE_FILTER_INVOKED"); + TEST_PROPS.setProperty(SEARCH_STRING, + "CreateServlet" + "|AddSRListenerClass_INVOKED" + + "|AddSRListenerString_INVOKED" + "|CreateSRListener_INVOKED" + + "|SCAttributeAddedClass:" + "|SCAttributeAddedString:" + + "|SCAttributeAdded:"); + invoke(); + } + + /* + * @testName: testAddFilterInclude + * + * @assertion_ids: Servlet:JAVADOC:655; Servlet:JAVADOC:669; + * Servlet:JAVADOC:670; Servlet:JAVADOC:670.3; Servlet:JAVADOC:671.1; + * Servlet:JAVADOC:671.2; Servlet:JAVADOC:671.3; Servlet:JAVADOC:671.6; + * Servlet:JAVADOC:671.7; Servlet:JAVADOC:671.9; Servlet:JAVADOC:672.1; + * Servlet:JAVADOC:672.2; Servlet:JAVADOC:672.3; Servlet:JAVADOC:672.6; + * Servlet:JAVADOC:672.7; Servlet:JAVADOC:672.9; Servlet:JAVADOC:673.1; + * Servlet:JAVADOC:673.2; Servlet:JAVADOC:673.3; Servlet:JAVADOC:673.6; + * Servlet:JAVADOC:673.7; Servlet:JAVADOC:673.9; Servlet:JAVADOC:675; + * Servlet:JAVADOC:675.4; Servlet:JAVADOC:677; Servlet:JAVADOC:677.1; + * Servlet:JAVADOC:679; Servlet:JAVADOC:679.1; Servlet:JAVADOC:679.4; + * Servlet:JAVADOC:681; Servlet:JAVADOC:696; Servlet:SPEC:259; + * Servlet:SPEC:259.1; Servlet:SPEC:259.3; Servlet:SPEC:259.4; + * Servlet:SPEC:259.6; Servlet:SPEC:259.7; + * + * @test_Strategy: Create a ServletContextInitializer, in which, 1. Create a + * Servlet instance using ServletContext.createServlet; 2. Add the Servlet + * instance: ServletContext.addServlet(String, Servlet), 3. mapping the new + * Servlet programmatically. 4. create a Filter instance by + * ServletContext.createFilter; 5 Add the Filter instance: + * ServletContext.addFilter(String, Filter) 6. map the filter to the new + * Servlet programmatically for REQUEST only 7. client send a request to the + * new servlet via INCLUDE, Verify in client that request does go through and + * Filter is NOT invoked. Verify in client that all Listeners are added + * correctly and invoked in the order added. + */ + @Test + public void testAddFilterInclude() throws Exception { + TEST_PROPS.setProperty(APITEST, "testCreateFilterInclude"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "CREATE_FILTER_INVOKED"); + TEST_PROPS.setProperty(SEARCH_STRING, + "CreateServlet" + "|AddSRListenerClass_INVOKED" + + "|AddSRListenerString_INVOKED" + "|CreateSRListener_INVOKED" + + "|SCAttributeAddedClass:" + "|SCAttributeAddedString:" + + "|SCAttributeAdded:"); + invoke(); + } + + /* + * @testName: testAddServletNotFound + * + * @assertion_ids: Servlet:JAVADOC:655; Servlet:JAVADOC:670; + * Servlet:JAVADOC:670.3; Servlet:JAVADOC:671.1; Servlet:JAVADOC:671.2; + * Servlet:JAVADOC:671.3; Servlet:JAVADOC:671.6; Servlet:JAVADOC:671.7; + * Servlet:JAVADOC:671.9; Servlet:JAVADOC:672.1; Servlet:JAVADOC:672.2; + * Servlet:JAVADOC:672.3; Servlet:JAVADOC:672.6; Servlet:JAVADOC:672.7; + * Servlet:JAVADOC:6712.9; Servlet:JAVADOC:673.1; Servlet:JAVADOC:673.2; + * Servlet:JAVADOC:673.3; Servlet:JAVADOC:673.6; Servlet:JAVADOC:673.7; + * Servlet:JAVADOC:673.9; Servlet:JAVADOC:676; Servlet:JAVADOC:676.4; + * Servlet:JAVADOC:679; Servlet:JAVADOC:679.1; Servlet:JAVADOC:679.4; + * Servlet:JAVADOC:696; Servlet:SPEC:259; Servlet:SPEC:259.1; + * Servlet:SPEC:259.3; Servlet:SPEC:259.4; Servlet:SPEC:259.6; + * Servlet:SPEC:259.7; + * + * @test_Strategy: Create a ServletContextInitializer, in which, 1. create a + * Servlet by calling ServletContext.addServlet(String, Class), 2. mapping the + * new Servlet programmatically to multiple URLs, one of them is used by + * another Servlet already. 3. create a Filter by + * ServletContext.addFilter(String, Class) 4. map the filter to the new + * Servlet programmatically for all DispatcherType 5. client send a request to + * the new servlet, Verify in client that request does NOT go through and + * Filter is NOT invoked. + */ + @Test + public void testAddServletNotFound() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/addServletNotFound HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, NOT_FOUND); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, + "AddServletNotFound|ADD_FILTER_NOTFOUND"); + invoke(); + } + + /* + * @testName: testCreateSRAListener + * + * @assertion_ids: Servlet:JAVADOC:655; Servlet:JAVADOC:669; + * Servlet:JAVADOC:670; Servlet:JAVADOC:670.3; Servlet:JAVADOC:671.1; + * Servlet:JAVADOC:671.2; Servlet:JAVADOC:671.3; Servlet:JAVADOC:671.6; + * Servlet:JAVADOC:671.7; Servlet:JAVADOC:671.9; Servlet:JAVADOC:672.1; + * Servlet:JAVADOC:672.2; Servlet:JAVADOC:672.3; Servlet:JAVADOC:672.6; + * Servlet:JAVADOC:672.7; Servlet:JAVADOC:6712.9; Servlet:JAVADOC:673.1; + * Servlet:JAVADOC:673.2; Servlet:JAVADOC:673.3; Servlet:JAVADOC:673.6; + * Servlet:JAVADOC:673.7; Servlet:JAVADOC:673.9; Servlet:JAVADOC:675; + * Servlet:JAVADOC:675.4; Servlet:JAVADOC:677; Servlet:JAVADOC:677.1; + * Servlet:JAVADOC:679; Servlet:JAVADOC:679.1; Servlet:JAVADOC:679.4; + * Servlet:JAVADOC:681; Servlet:JAVADOC:696; Servlet:SPEC:259; + * Servlet:SPEC:259.1; Servlet:SPEC:259.3; Servlet:SPEC:259.4; + * Servlet:SPEC:259.6; Servlet:SPEC:259.7; + * + * @test_Strategy: Create a ServletContextInitializer, in which, one + * ServletContextAttributeListener, one ServletRequestListener one + * ServletRequestAttributeListener are added: 1. Create a Servlet instance + * using ServletContext.createServlet; 2. Add the Servlet instance: + * ServletContext.addServlet(String, Servlet), 3. mapping the new Servlet + * programmatically. 4. create a Filter instance by + * ServletContext.createFilter; 5 Add the Filter instance: + * ServletContext.addFilter(String, Filter) 6. map the filter to the new + * Servlet programmatically for REQUEST only 7. client send a request to + * another servlet, in which, ServletRequestAttributes are added, then + * dispatch to the new servlet via FORWARD Verify in client that - create + * Listener works - request does NOT through and Filter is NOT invoked. - all + * Listeners are added correctly and invoked in the order added. + */ + @Test + public void testCreateSRAListener() throws Exception { + TEST_PROPS.setProperty(APITEST, "testCreateSRAListener"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "CREATE_FILTER_INVOKED"); + TEST_PROPS.setProperty(SEARCH_STRING, + "AddServletClass" + "|AddSRListenerClass_INVOKED" + + "|AddSRListenerString_INVOKED" + "|CreateSRListener_INVOKED" + + "|SCAttributeAddedClass:" + "|SCAttributeAddedString:" + + "|SCAttributeAdded:" + "|SRAttributeAddedClass:" + + "|SRAttributeAddedString:" + "|SRAttributeAdded:"); + invoke(); + } + + /* + * @testName: negativeCreateTests + * + * @assertion_ids: Servlet:JAVADOC:243; Servlet:JAVADOC:678; + * Servlet:JAVADOC:679.4; Servlet:JAVADOC:680; Servlet:JAVADOC:682; + * Servlet:JAVADOC:694; Servlet:SPEC:259; Servlet:SPEC:259.1; + * Servlet:SPEC:259.3; Servlet:SPEC:259.4; Servlet:SPEC:259.6; + * Servlet:SPEC:259.7; + * + * @test_Strategy: 1. Create a Servlet which throws ServletException at init; + * 2. Create a Filter which throws ServletException at init 3. Create a + * EventListener which throws NullPointerException at init 4. Create a + * EventListener that does not implement any of the following: - + * ServletContextAttributeListener - ServletRequestListener - + * ServletRequestAttributesListener - ServletContextListener - + * HttpSessionListener - HttpSessionAttributeListener + * + * Create a ServletContextInitializer, in which: 5. Call + * ServletContext.createFilter(BadFilter) which should fail; 6. Call + * ServletContext.createServlet(BadServlet) which fails 7. Call + * ServletContext.createListener(BadEventListener) which fails 8. Call + * ServletContext.setInitParameter to pass information about status on 4-6 9. + * Call ServletContext.addListener(GenericEventListener) which fails 10. Call + * ServletContext.createListener(GenericEventListener) which fails 11. In + * another Servlet, get all information stored in ServletContext InitParameter + * 12. Send a request to the new Servlet Verify that - createServlet failed + * accordingly; - createFilter failed accordingly; - createListener failed + * accordingly; - addListener failed accordingly; - setInitParameter works + * properly + */ + @Test + public void negativeCreateTests() throws Exception { + TEST_PROPS.setProperty(APITEST, "negativeCreateTests"); + TEST_PROPS.setProperty(SEARCH_STRING, + "SERVLET_TEST=TRUE" + "|FILTER_TEST=TRUE" + "|LISTENER_TEST=TRUE" + + "|GC_LISTENER_TEST=TRUE" + "|GS_LISTENER_TEST=TRUE" + + "|CGC_LISTENER_TEST=TRUE"); + + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext305/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext305/build.xml new file mode 100644 index 0000000000..e4e65ac492 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext305/build.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext305/jakarta.servlet.ServletContainerInitializer b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext305/jakarta.servlet.ServletContainerInitializer new file mode 100644 index 0000000000..52e2560c21 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext305/jakarta.servlet.ServletContainerInitializer @@ -0,0 +1,2 @@ + +com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext305.TestContainerInitializer diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext305/servlet_js_servletcontext305_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext305/servlet_js_servletcontext305_web.xml new file mode 100644 index 0000000000..eefa6c63fa --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext305/servlet_js_servletcontext305_web.xml @@ -0,0 +1,33 @@ + + + + + SerJaxSerServletContext305 + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext305.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext306/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext306/TestServlet.java new file mode 100644 index 0000000000..46ccb94f0f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext306/TestServlet.java @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext306; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.Filter; +import jakarta.servlet.Servlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + final static String addServletName1 = "AddServletString"; + + final static String addServletName2 = "AddServletClass"; + + final static String addServletName3 = "CreateServlet"; + + final static String addFilterName1 = "AddFilterString"; + + final static String addFilterName2 = "AddFilterClass"; + + final static String addFilterName3 = "CreateFilter"; + + public void addServletStringTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + try { + getServletContext().addServlet(addServletName1, + "com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddServletString"); + pw.append("Expected IllegalStateException not thrown."); + ServletTestUtil.printResult(pw, false); + } catch (IllegalStateException ex) { + pw.append("Expected IllegalStateException thrown: " + ex.getMessage()); + ServletTestUtil.printResult(pw, true); + } + } + + public void addServletClassTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + try { + getServletContext().addServlet(addServletName2, + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddServletClass.class); + pw.append("Expected IllegalStateException not thrown."); + ServletTestUtil.printResult(pw, false); + } catch (IllegalStateException ex) { + pw.append("Expected IllegalStateException thrown: " + ex.getMessage()); + ServletTestUtil.printResult(pw, true); + } + } + + public void addServletTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + try { + Servlet servlet3 = getServletContext().createServlet( + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.CreateServlet.class); + getServletContext().addServlet(addServletName3, servlet3); + pw.append("Expected IllegalStateException not thrown."); + ServletTestUtil.printResult(pw, false); + + } catch (IllegalStateException ex) { + pw.append("Expected IllegalStateException thrown: " + ex.getMessage()); + ServletTestUtil.printResult(pw, true); + } + } + + public void addFilterStringTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + try { + getServletContext().addFilter(addFilterName1, + "com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddFilterString"); + pw.append("Expected IllegalStateException not thrown."); + ServletTestUtil.printResult(pw, false); + + } catch (IllegalStateException ex) { + pw.append("Expected IllegalStateException thrown: " + ex.getMessage()); + ServletTestUtil.printResult(pw, true); + } + } + + public void addFilterClassTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + try { + getServletContext().addFilter(addFilterName2, + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddFilterClass.class); + pw.append("Expected IllegalStateException not thrown."); + ServletTestUtil.printResult(pw, false); + + } catch (IllegalStateException ex) { + pw.append("Expected IllegalStateException thrown: " + ex.getMessage()); + ServletTestUtil.printResult(pw, true); + } + } + + public void addFilterTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + try { + Filter filter3 = getServletContext().createFilter( + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.CreateFilter.class); + getServletContext().addFilter(addFilterName3, filter3); + pw.append("Expected IllegalStateException not thrown."); + ServletTestUtil.printResult(pw, false); + + } catch (IllegalStateException ex) { + pw.append("Expected IllegalStateException thrown: " + ex.getMessage()); + ServletTestUtil.printResult(pw, true); + } + } + + public void setInitParameterTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + try { + getServletContext().addFilter("abc", "xyz"); + pw.append("Expected IllegalStateException not thrown."); + ServletTestUtil.printResult(pw, false); + + } catch (IllegalStateException ex) { + pw.append("Expected IllegalStateException thrown: " + ex.getMessage()); + ServletTestUtil.printResult(pw, true); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext306/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext306/URLClient.java new file mode 100644 index 0000000000..fe740bd284 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext306/URLClient.java @@ -0,0 +1,165 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext306; + +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddFilterClass; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddFilterString; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddServletClass; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddServletString; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.CreateFilter; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.CreateServlet; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_servletcontext306_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestServlet.class, AddServletString.class, AddServletClass.class, CreateServlet.class, + AddFilterString.class, AddFilterClass.class, CreateFilter.class) + .setWebXML(URLClient.class.getResource("servlet_js_servletcontext306_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + + /* + * @testName: addServletStringTest + * + * @assertion_ids: Servlet:JAVADOC:674.6; + * + * @test_Strategy: Negative test for ServletContext.addServlet(String, String) + * Create a Servlet, call ServletContext.addServlet(String, String) Verify the + * expected IllegalStateException is thrown. + */ + @Test + public void addServletStringTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "addServletStringTest"); + invoke(); + } + + /* + * @testName: addServletClassTest + * + * @assertion_ids: Servlet:JAVADOC:676.6; + * + * @test_Strategy: Negative test for ServletContext.addServlet(String, Class) + * Create a Servlet, call ServletContext.addServlet(String, Class) Verify the + * expected IllegalStateException is thrown. + */ + @Test + public void addServletClassTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "addServletClassTest"); + invoke(); + } + + /* + * @testName: addServletTest + * + * @assertion_ids: Servlet:JAVADOC:675.7; + * + * @test_Strategy: Negative test for ServletContext.addServlet(String, + * Servlet) Create a Servlet, call ServletContext.addServlet(String, Servlet) + * Verify the expected IllegalStateException is thrown. + */ + @Test + public void addServletTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "addServletTest"); + invoke(); + } + + /* + * @testName: addFilterStringTest + * + * @assertion_ids: Servlet:JAVADOC:668.5; + * + * @test_Strategy: Negative test for ServletContext.addFilter(String, String) + * Create a Servlet, call ServletContext.addFilter(String, String) Verify the + * expected IllegalStateException is thrown. + */ + @Test + public void addFilterStringTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "addFilterStringTest"); + invoke(); + } + + /* + * @testName: addFilterClassTest + * + * @assertion_ids: Servlet:JAVADOC:670.5; + * + * @test_Strategy: Negative test for ServletContext.addFilter(String, Class) + * Create a Servlet, call ServletContext.addFilter(String, Class) Verify the + * expected IllegalStateException is thrown. + */ + @Test + public void addFilterClassTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "addFilterClassTest"); + invoke(); + } + + /* + * @testName: addFilterTest + * + * @assertion_ids: Servlet:JAVADOC:669.6; + * + * @test_Strategy: Negative test for ServletContext.addFilter(String, Filter) + * Create a Servlet, call ServletContext.addFilter(String, Filter) Verify the + * expected IllegalStateException is thrown. + */ + @Test + public void addFilterTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "addFilterTest"); + invoke(); + } + + /* + * @testName: setInitParameterTest + * + * @assertion_ids: Servlet:JAVADOC:694.1; + * + * @test_Strategy: Negative test for ServletContext.setInitParameter(String, + * String) Create a Servlet, call ServletContext.setInitParameter(String, + * String) Verify the expected IllegalStateException is thrown. + */ + @Test + public void setInitParameterTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setInitParameterTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext306/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext306/build.xml new file mode 100644 index 0000000000..f53b90d120 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext306/build.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext306/servlet_js_servletcontext306_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext306/servlet_js_servletcontext306_web.xml new file mode 100644 index 0000000000..fdff81803e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext306/servlet_js_servletcontext306_web.xml @@ -0,0 +1,33 @@ + + + + + SerJaxSerServletContext306 + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext306.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext31/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext31/TestServlet.java new file mode 100644 index 0000000000..b20b9c0b47 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext31/TestServlet.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext31; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void getVirtualServerNameTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = true; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + + try { + String expected_virtualhost = request + .getParameter("VirtualServerNamePlease"); + String tmp = context.getVirtualServerName(); + if (tmp != null) { + pw.println("VirtualServerName=" + tmp); + if (!tmp.equals(expected_virtualhost)) { + passed = false; + pw.println("Incorrect value returned"); + } + } else { + passed = false; + pw.println("Null value returned"); + } + } catch (Exception ex) { + passed = false; + pw.println("Got Exception when calling getVirtualServerName()"); + } + ServletTestUtil.printResult(pw, passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext31/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext31/URLClient.java new file mode 100644 index 0000000000..678b7ccb7a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext31/URLClient.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext31; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_servletcontext31_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_js_servletcontext31_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * logical.hostname.servlet; + */ + /* Run test */ + /* + * @testName: getVirtualServerNameTest + * + * @assertion_ids: Servlet:JAVADOC:954; + * + * @test_Strategy: 1. Create a Servlet Servlet, define it in web.xml; 2. + * verify ServletContext.getVirtualServerName() returns correctly; + */ + @Test + public void getVirtualServerNameTest() throws Exception { + String expected_virtualservername = _props + .getProperty("logical.hostname.servlet").trim(); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + getServletName() + + "?testname=getVirtualServerNameTest&VirtualServerNamePlease=" + + expected_virtualservername + " HTTP/1.0"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext31/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext31/build.xml new file mode 100644 index 0000000000..f46e384555 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext31/build.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext31/servlet_js_servletcontext31_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext31/servlet_js_servletcontext31_web.xml new file mode 100644 index 0000000000..7067aef52b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext31/servlet_js_servletcontext31_web.xml @@ -0,0 +1,33 @@ + + + + + SerJaxSerServletContext31 + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext31.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext40/AddListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext40/AddListener.java new file mode 100644 index 0000000000..ca2fca0fe4 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext40/AddListener.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2017, 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext40; + +import java.util.List; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; +import jakarta.servlet.ServletRegistration; + +public class AddListener implements ServletContextListener { + + @Override + public void contextInitialized(ServletContextEvent sce) { + ServletContext context = sce.getServletContext(); + List list = (List) context.getAttribute("arraylist"); + try { + ServletRegistration registration = context.addJspFile("AddJspFile2", + "/addJspFile.jsp"); + list.add("addJsp_addedListener"); + } catch (UnsupportedOperationException e) { + list.add("UnsupportedOperationException_when_addJsp_addedListener"); + } + + try { + context.setSessionTimeout(2); + list.add("setSessionTimeout_addedListener"); + } catch (UnsupportedOperationException e) { + list.add( + "UnsupportedOperationException_when_setSessionTimeout_addedListener"); + } + context.setAttribute("arraylist", list); + } + + @Override + public void contextDestroyed(ServletContextEvent sce) { + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext40/Client.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext40/Client.java new file mode 100644 index 0000000000..dd2f8ede6c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext40/Client.java @@ -0,0 +1,531 @@ +/* + * Copyright (c) 2017, 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: URLClient.java 73856 2014-06-23 22:39:25Z sdimilla $ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext40; + +import com.sun.ts.lib.util.WebUtil; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; + +import java.net.InetAddress; + +public class Client extends AbstractUrlClient { + + private WebUtil.Response response = null; + + private String request = null; + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "tldjar.jar") + .addAsResource(Client.class.getResource("listener.tld"), "META-INF/listener.tld"); + return ShrinkWrap.create(WebArchive.class, "servlet_js_servletcontext40_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addAsLibraries(javaArchive) + .addClasses(AddListener.class, TestListener.class, TestServlet.class, TestServlet2.class) + .addAsWebResource("api/jakarta_servlet/servletcontext40/addJspFile.jsp", "addJspFile.jsp") + .setWebXML(Client.class.getResource("servlet_js_servletcontext40_web.xml")); + } + + /* + * @testName: addJspTest + * + * @assertion_ids: NA + * + * @test_Strategy: + */ + @Test + public void addJspTest() throws Exception { + try { + request = getContextRoot() + "/servlet/addJspFile"; + logMsg("Sending request \"" + request + "\""); + + response = WebUtil.sendRequest("GET", InetAddress.getByName(_hostname), + _port, getRequest(request), null, null); + + logMsg("response.statusToken:" + response.statusToken); + logMsg("response.content:" + response.content); + + // Check that the page was found (no error). + if (response.isError()) { + logErr("Could not find " + request); + throw new Exception("addJspTest failed."); + } + + if (response.content.indexOf("addJspFile is accessed") < 0) { + logErr("The test jsp is accessed incorrectly: " + request); + throw new Exception("addJspTest failed."); + } + + } catch (Exception e) { + logErr("Caught exception: " + e.getMessage()); + e.printStackTrace(); + throw new Exception("addJspTest failed: ", e); + } + } + + /* + * @testName: changeSessionTimeoutTest + * + * @assertion_ids: servlet40:changeSessionTimeoutTest; + * + * @test_Strategy: + */ + @Test + public void changeSessionTimeoutTest() throws Exception { + try { + request = getContextRoot() + "/TestServlet"; + logMsg("Sending request \"" + request + "\""); + + response = WebUtil.sendRequest("GET", InetAddress.getByName(_hostname), + _port, getRequest(request), null, null); + + logMsg("response.statusToken:" + response.statusToken); + logMsg("response.content:" + response.content); + + // Check that the page was found (no error). + if (response.isError()) { + logErr("Could not find " + request); + throw new Exception("changeSessionTimeoutTest failed."); + } + + if (response.content.indexOf("changeSessionTimeout_correctly") < 0) { + throw new Exception("changeSessionTimeoutTest failed."); + } + + } catch (Exception e) { + logErr("Caught exception: " + e.getMessage()); + e.printStackTrace(); + throw new Exception("changeSessionTimeoutTest failed: ", e); + } + } + + /* + * @testName: addJspContextInitialized + * + * @assertion_ids: NA + * + * @test_Strategy: IllegalStateException - if this ServletContext has already + * been initialized + */ + @Test + public void addJspContextInitialized() throws Exception { + try { + request = getContextRoot() + "/TestServlet2"; + logMsg("Sending request \"" + request + "\""); + + response = WebUtil.sendRequest("GET", InetAddress.getByName(_hostname), + _port, getRequest(request), null, null); + + logMsg("response.statusToken:" + response.statusToken); + logMsg("response.content:" + response.content); + + // Check that the page was found (no error). + if (response.isError()) { + logErr("Could not find " + request); + throw new Exception("addJspContextInitialized failed."); + } + + if (response.content.indexOf( + "IllegalStateException_when_addJsp__ContextInitialized") < 0) { + logErr( + "IllegalStateException should be thrown if this ServletContext has already been initialized"); + throw new Exception("addJspContextInitialized failed."); + } + + } catch (Exception e) { + logErr("Caught exception: " + e.getMessage()); + e.printStackTrace(); + throw new Exception("addJspContextInitialized failed: ", e); + } + } + + /* + * @testName: setSessionTimeoutContextInitialized + * + * @assertion_ids: NA + * + * @test_Strategy: IllegalStateException - if this ServletContext has already + * been initialized + */ + @Test + public void setSessionTimeoutContextInitialized() throws Exception { + try { + request = getContextRoot() + "/TestServlet2"; + logMsg("Sending request \"" + request + "\""); + + response = WebUtil.sendRequest("GET", InetAddress.getByName(_hostname), + _port, getRequest(request), null, null); + + logMsg("response.statusToken:" + response.statusToken); + logMsg("response.content:" + response.content); + + // Check that the page was found (no error). + if (response.isError()) { + logErr("Could not find " + request); + throw new Exception("setSessionTimeoutContextInitialized failed."); + } + + if (response.content.indexOf( + "IllegalStateException_when_setSessionTimeout_ContextInitialized") < 0) { + logErr( + "IllegalStateException should be thrown if this ServletContext has already been initialized"); + throw new Exception("setSessionTimeoutContextInitialized failed."); + } + + } catch (Exception e) { + logErr("Caught exception: " + e.getMessage()); + e.printStackTrace(); + throw new Exception("setSessionTimeoutContextInitialized failed: ", e); + } + } + + /* + * @testName: addJspContextListenerInTLD + * + * @assertion_ids: NA + * + * @test_Strategy: UnsupportedOperationException - if this ServletContext was + * passed to the ServletContextListener.contextInitialized(jakarta.servlet. + * ServletContextEvent) method of a ServletContextListener that was neither + * declared in web.xml or web-fragment.xml, nor annotated with WebListener + */ + @Test + public void addJspContextListenerInTLD() throws Exception { + try { + request = getContextRoot() + "/TestServlet"; + logMsg("Sending request \"" + request + "\""); + + response = WebUtil.sendRequest("GET", InetAddress.getByName(_hostname), + _port, getRequest(request), null, null); + + logMsg("response.statusToken:" + response.statusToken); + logMsg("response.content:" + response.content); + + // Check that the page was found (no error). + if (response.isError()) { + logErr("Could not find " + request); + throw new Exception("addJspContextListenerInTLD failed."); + } + + if (response.content.indexOf( + "UnsupportedOperationException_when_addJsp_addedListener") < 0) { + logErr("UnsupportedOperationException should be thrown."); + throw new Exception("addJspContextListenerInTLD failed."); + } + + } catch (Exception e) { + logErr("Caught exception: " + e.getMessage()); + e.printStackTrace(); + throw new Exception("addJspContextListenerInTLD failed: ", e); + } + } + + /* + * @testName: setSessionTimeoutContextListenerInTLD + * + * @assertion_ids: NA + * + * @test_Strategy: UnsupportedOperationException - if this ServletContext was + * passed to the ServletContextListener.contextInitialized(jakarta.servlet. + * ServletContextEvent) method of a ServletContextListener that was neither + * declared in web.xml or web-fragment.xml, nor annotated with WebListener + */ + @Test + public void setSessionTimeoutContextListenerInTLD() throws Exception { + try { + request = getContextRoot() + "/TestServlet"; + logMsg("Sending request \"" + request + "\""); + + response = WebUtil.sendRequest("GET", InetAddress.getByName(_hostname), + _port, getRequest(request), null, null); + + logMsg("response.statusToken:" + response.statusToken); + logMsg("response.content:" + response.content); + + // Check that the page was found (no error). + if (response.isError()) { + logErr("Could not find " + request); + throw new Exception("setSessionTimeoutContextListenerInTLD failed."); + } + + if (response.content.indexOf( + "UnsupportedOperationException_when_setSessionTimeout_addedListener") < 0) { + logErr("UnsupportedOperationException should be thrown."); + throw new Exception("setSessionTimeoutContextListenerInTLD failed."); + } + + } catch (Exception e) { + logErr("Caught exception: " + e.getMessage()); + e.printStackTrace(); + throw new Exception("setSessionTimeoutContextListenerInTLD failed: ", e); + } + } + + /* + * @testName: addJspEmptyAndNullName + * + * @assertion_ids: NA + * + * @test_Strategy: IllegalArgumentException - if servletName is null or an + * empty String + */ + @Test + public void addJspEmptyAndNullName() throws Exception { + try { + request = getContextRoot() + "/TestServlet"; + logMsg("Sending request \"" + request + "\""); + + response = WebUtil.sendRequest("GET", InetAddress.getByName(_hostname), + _port, getRequest(request), null, null); + + logMsg("response.statusToken:" + response.statusToken); + logMsg("response.content:" + response.content); + + // Check that the page was found (no error). + if (response.isError()) { + logErr("Could not find " + request); + throw new Exception("addJspEmptyAndNullName failed."); + } + + if (response.content + .indexOf("IllegalArgumentException_when_empty_name") < 0) { + logErr( + "IllegalArgumentException should be thrown if servletName is an empty String"); + throw new Exception("addJspEmptyAndNullName failed."); + } + + if (response.content + .indexOf("IllegalArgumentException_when_null_name") < 0) { + logErr( + "IllegalArgumentException should be thrown if servletName is null"); + throw new Exception("addJspEmptyAndNullName failed."); + } + + } catch (Exception e) { + logErr("Caught exception: " + e.getMessage()); + e.printStackTrace(); + throw new Exception("addJspEmptyAndNullName failed: ", e); + } + } + + /* + * @testName: getAttributeWithNullName + * + * @assertion_ids: NA + * + * @test_Strategy: NullPointerException - if name is null + */ + @Test + public void getAttributeWithNullName() throws Exception { + try { + request = getContextRoot() + "/TestServlet2"; + logMsg("Sending request \"" + request + "\""); + + response = WebUtil.sendRequest("GET", InetAddress.getByName(_hostname), + _port, getRequest(request), null, null); + + logMsg("response.statusToken:" + response.statusToken); + logMsg("response.content:" + response.content); + + // Check that the page was found (no error). + if (response.isError()) { + logErr("Could not find " + request); + throw new Exception("getAttributeWithNullName failed."); + } + + if (response.content + .indexOf("NullPointerException_when_getAttribute_with_null") < 0) { + logErr( + "NullPointerException should be thrown if getAttribute with a null name."); + throw new Exception("getAttributeWithNullName failed."); + } + + } catch (Exception e) { + logErr("Caught exception: " + e.getMessage()); + e.printStackTrace(); + throw new Exception("getAttributeWithNullName failed: ", e); + } + } + + /* + * @testName: getInitParameterWithNullName + * + * @assertion_ids: NA + * + * @test_Strategy: NullPointerException - if name is null + */ + @Test + public void getInitParameterWithNullName() throws Exception { + try { + request = getContextRoot() + "/TestServlet2"; + logMsg("Sending request \"" + request + "\""); + + response = WebUtil.sendRequest("GET", InetAddress.getByName(_hostname), + _port, getRequest(request), null, null); + + logMsg("response.statusToken:" + response.statusToken); + logMsg("response.content:" + response.content); + + // Check that the page was found (no error). + if (response.isError()) { + logErr("Could not find " + request); + throw new Exception("getInitParameterWithNullName failed."); + } + + if (response.content.indexOf( + "NullPointerException_when_getInitParameter_with_null") < 0) { + logErr( + "NullPointerException should be thrown if getInitParameter with a null name."); + throw new Exception("getAttributeWithNullName failed."); + } + + } catch (Exception e) { + logErr("Caught exception: " + e.getMessage()); + e.printStackTrace(); + throw new Exception("getInitParameterWithNullName failed: ", e); + } + } + + /* + * @testName: setAttributeWithNullName + * + * @assertion_ids: NA + * + * @test_Strategy: NullPointerException - if name is null + */ + @Test + public void setAttributeWithNullName() throws Exception { + try { + request = getContextRoot() + "/TestServlet2"; + logMsg("Sending request \"" + request + "\""); + + response = WebUtil.sendRequest("GET", InetAddress.getByName(_hostname), + _port, getRequest(request), null, null); + + logMsg("response.statusToken:" + response.statusToken); + logMsg("response.content:" + response.content); + + // Check that the page was found (no error). + if (response.isError()) { + logErr("Could not find " + request); + throw new Exception("setAttributeWithNullName failed."); + } + + if (response.content + .indexOf("NullPointerException_when_setAttribute_with_null") < 0) { + logErr( + "NullPointerException should be thrown if setAttribute with a null name."); + throw new Exception("setAttributeWithNullName failed."); + } + + } catch (Exception e) { + logErr("Caught exception: " + e.getMessage()); + e.printStackTrace(); + throw new Exception("setAttributeWithNullName failed: ", e); + } + } + + /* + * @testName: setInitParameterWithNullName + * + * @assertion_ids: NA + * + * @test_Strategy: NullPointerException - if name is null + */ + @Test + public void setInitParameterWithNullName() throws Exception { + try { + request = getContextRoot() + "/TestServlet2"; + logMsg("Sending request \"" + request + "\""); + + response = WebUtil.sendRequest("GET", InetAddress.getByName(_hostname), + _port, getRequest(request), null, null); + + logMsg("response.statusToken:" + response.statusToken); + logMsg("response.content:" + response.content); + + // Check that the page was found (no error). + if (response.isError()) { + logErr("Could not find " + request); + throw new Exception("setInitParameterWithNullName failed."); + } + + if (response.content.indexOf( + "NullPointerException_when_setInitParameter_with_null") < 0) { + logErr( + "NullPointerException should be thrown if setInitParameter with a null name."); + throw new Exception("setAttributeWithNullName failed."); + } + + } catch (Exception e) { + logErr("Caught exception: " + e.getMessage()); + e.printStackTrace(); + throw new Exception("setInitParameterWithNullName failed: ", e); + } + } + + /* + * @testName: getEffectiveSessionTrackingModes + * + * @assertion_ids: NA + * + * @test_Strategy: with no setEffectiveSesssionTrackingModes, default is in + * effective + */ + @Test + public void getEffectiveSessionTrackingModes() throws Exception { + try { + request = getContextRoot() + "/TestServlet2"; + logMsg("Sending request \"" + request + "\""); + + response = WebUtil.sendRequest("GET", InetAddress.getByName(_hostname), + _port, getRequest(request), null, null); + + logMsg("response.statusToken:" + response.statusToken); + logMsg("response.content:" + response.content); + + // Check that the page was found (no error). + if (response.isError()) { + logErr("Could not find " + request); + throw new Exception("getEffectiveSessionTrackingModes failed."); + } + + if (response.content + .indexOf("getEffectiveSessionTrackingModes_test_passed") < 0) { + logErr("getEffectiveSessionTrackingModes return a wrong set."); + throw new Exception("getEffectiveSessionTrackingModes failed."); + } + + } catch (Exception e) { + logErr("Caught exception: " + e.getMessage()); + e.printStackTrace(); + throw new Exception("getEffectiveSessionTrackingModes failed: ", e); + } + } +} \ No newline at end of file diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext40/TestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext40/TestListener.java new file mode 100644 index 0000000000..dd338a7509 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext40/TestListener.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2017, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext40; + +import java.util.ArrayList; +import java.util.List; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; +import jakarta.servlet.ServletRegistration; + +public class TestListener implements ServletContextListener { + + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce + * The servlet context event + */ + public void contextInitialized(ServletContextEvent sce) { + ServletContext context = sce.getServletContext(); + + ServletRegistration registration = context.addJspFile("AddJspFile", + "/addJspFile.jsp"); + registration.addMapping("/servlet/addJspFile"); + + List list = new ArrayList(); + + int oldTimeout = context.getSessionTimeout(); + context.setSessionTimeout(20); + int newTimeout = context.getSessionTimeout(); + + if (oldTimeout == 54 && newTimeout == 20) { + list.add("changeSessionTimeout_correctly"); + } else { + list.add( + "changeSessionTimeout_fail: expected oldTimeout is 54 and expected newTimeout is 20, now they are " + + oldTimeout + "and" + newTimeout); + } + + // negtive test + try { + context.addJspFile("", "/addJspFile.jsp"); + list.add("add_jsp_with_empty_name"); + } catch (IllegalArgumentException e) { + list.add("IllegalArgumentException_when_empty_name"); + } + + try { + context.addJspFile(null, "/addJspFile.jsp"); + list.add("add_jsp_with_null_name"); + } catch (IllegalArgumentException e) { + list.add("IllegalArgumentException_when_null_name"); + } + context.setAttribute("arraylist", list); + + // context.addListener(AddListener.class); + } + + /** + * Receives notification that the servlet context is about to be shut down. + * + * @param sce + * The servlet context event + */ + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext40/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext40/TestServlet.java new file mode 100644 index 0000000000..1db25db75a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext40/TestServlet.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2017, 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext40; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.List; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class TestServlet extends HttpServlet { + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + List list = (List) getServletContext().getAttribute("arraylist"); + + PrintWriter pw = resp.getWriter(); + + for (Object tmp : list) { + pw.println(tmp.toString()); + + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext40/TestServlet2.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext40/TestServlet2.java new file mode 100644 index 0000000000..a7ec3e5bad --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext40/TestServlet2.java @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2017, 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext40; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Set; + +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRegistration; +import jakarta.servlet.SessionTrackingMode; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class TestServlet2 extends HttpServlet { + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + PrintWriter pw = resp.getWriter(); + try { + ServletRegistration registration = getServletContext() + .addJspFile("AddJspFile3", "/addJspFile.jsp"); + pw.println("addJsp_contextInitialized"); + } catch (IllegalStateException e) { + pw.println("IllegalStateException_when_addJsp__ContextInitialized"); + } + + try { + getServletContext().setSessionTimeout(2); + pw.println("setSessionTimeout_contextInitialized"); + } catch (IllegalStateException e) { + pw.println( + "IllegalStateException_when_setSessionTimeout_ContextInitialized"); + } + + /* + * JSR-369 change log 2. Modify javadoc for ServletContext getAttribute() + * and getInitParameter(), specify that NullPointerException must be thrown + * if the argument 'name' is null. + */ + try { + getServletContext().getAttribute(null); + pw.println("getAttribute_successful"); + } catch (NullPointerException e) { + pw.println("NullPointerException_when_getAttribute_with_null"); + } + + try { + getServletContext().getInitParameter(null); + pw.println("getInitParameter_successful"); + } catch (NullPointerException e) { + pw.println("NullPointerException_when_getInitParameter_with_null"); + } + + /* + * JSR-369 change log 3. Modify javadoc for ServletContext setAttribute() + * and setInitParameter(), specify that NullPointerException must be thrown + * if the argument 'name' is null. + */ + try { + getServletContext().setAttribute(null, new Object()); + pw.println("setAttribute_successful"); + } catch (NullPointerException e) { + pw.println("NullPointerException_when_setAttribute_with_null"); + } catch (IllegalArgumentException e) { + pw.println("IllegalArgumentException_when_setAttribute_with_null"); + } + + try { + getServletContext().setInitParameter(null, "test"); + pw.println("setInitParameter_successful"); + } catch (NullPointerException e) { + pw.println("NullPointerException_when_setInitParameter_with_null"); + } catch (IllegalArgumentException e) { + pw.println("IllegalArgumentException_when_setInitParameter_with_null"); + } + + /* + * JSR-369 change log 12. Modify javadoc for + * ServletContext.getEffectiveSessionTrackingModes() without specifying the + * default value. + */ + try { + Set set = getServletContext() + .getEffectiveSessionTrackingModes(); + StringBuilder strB = new StringBuilder( + "getEffectiveSessionTrackingModes_test_passed"); + if (set != null && set.size() > 0) { + for (SessionTrackingMode stm : set) + strB.append("_" + stm.toString()); + } + + if (set == null || set.size() == 0) + throw new Exception( + "getEffectiveSessionTrackingModes_test_with_set_is_null"); + + Set defaultSet = getServletContext() + .getDefaultSessionTrackingModes(); + if (defaultSet == null || defaultSet.size() == 0) + throw new Exception( + "getEffectiveSessionTrackingModes_test_with_defaultSet_is_null"); + + if (set.size() != defaultSet.size()) + throw new Exception( + "getEffectiveSessionTrackingModes_test_with_set_is_not_equlto_defalut_" + + set.size()); + + for (SessionTrackingMode stm : set) { + if (!defaultSet.contains(stm)) { + throw new Exception( + "getEffectiveSessionTrackingModes_test_with_set_is_not_equlto_defalut_" + + set); + } + } + + pw.println(strB.toString()); + } catch (Exception e) { + pw.println("getEffectiveSessionTrackingModes_test_with_exception" + e); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext40/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext40/build.xml new file mode 100644 index 0000000000..204e9f7325 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext40/build.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext40/listener.tld b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext40/listener.tld new file mode 100644 index 0000000000..912a73a254 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext40/listener.tld @@ -0,0 +1,31 @@ + + + + + This is for test purpose + 1.2 + ListenerAdditionNegative + + + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext40.AddListener + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext40/servlet_js_servletcontext40_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext40/servlet_js_servletcontext40_web.xml new file mode 100644 index 0000000000..4f406f8e7e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext40/servlet_js_servletcontext40_web.xml @@ -0,0 +1,46 @@ + + + + + SerJaxSerServletContext40 + + + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext40.TestListener + + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext40.TestServlet + + + TestServlet2 + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext40.TestServlet2 + + + TestServlet + /TestServlet + + + TestServlet2 + /TestServlet2 + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletexception/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletexception/TestServlet.java new file mode 100644 index 0000000000..89a7f4722d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletexception/TestServlet.java @@ -0,0 +1,164 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletexception; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void getRootCause(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + boolean passed = false; + ServletException se = new ServletException(new Throwable("cause")); + + if (se.getRootCause() instanceof Throwable) { + passed = true; + } else { + passed = false; + pw.println( + "ServletException.getRootCause() did not thrown an instance of Throwable"); + } + ServletTestUtil.printResult(pw, passed); + + } + + public void servletExceptionConstructor1(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + boolean passed = false; + // construct and throw + try { + throw new ServletException(); + } catch (Throwable t) { // catching it here itself + if (t instanceof ServletException) { + passed = true; + } else { + passed = false; + pw.println("Exception thrown was not of type ServletException"); + } + } + ServletTestUtil.printResult(pw, passed); + } + + public void servletExceptionConstructor2(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + boolean passed = false; + + try { + throw new ServletException("Exceptional"); + } catch (Throwable t) { + if (t instanceof ServletException) { + if (t.getMessage().equals("Exceptional")) { + passed = true; + } else { + passed = false; + pw.println("Exception did not contain Exceptional"); + } + } else { + passed = false; + pw.println("Exception thrown was not of type ServletException(String)"); + } + } + ServletTestUtil.printResult(pw, passed); + } + + public void servletExceptionConstructor3(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + boolean passed = false; + ServletException se = null; + + // construct one and throw + try { + se = new ServletException(new Throwable("irrelevant")); + throw se; + } catch (Throwable t) { + if (t instanceof ServletException) { + Throwable rootCause = se.getRootCause(); + + if (rootCause != null) { + if (rootCause.getMessage().equals("irrelevant")) { + passed = true; + } else { + passed = false; + pw.println("Exception did not contain irrelevant"); + } + } else { + passed = false; + pw.println( + "rootCause message is null, expecting it to be 'irrelevant'"); + } + + } else { + passed = false; + pw.println("Exception thrown is not of type ServletException"); + } + } + ServletTestUtil.printResult(pw, passed); + } + + public void servletExceptionConstructor4(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + boolean passed = false; + ServletException se = null; + + // construct and throw + try { + se = new ServletException("Exceptional", new Throwable("cos")); + throw se; + } catch (Throwable t) { + if (t instanceof ServletException) { + Throwable cause = se.getRootCause(); + String mesg = se.getMessage(); + + if (cause != null && mesg != null) { + if (mesg.equals("Exceptional") && cause.getMessage().equals("cos")) { + passed = true; + } else { + passed = false; + pw.println( + "Exception did not contain Exceptional and a cause of cos"); + pw.println("Actual exception was |" + mesg + "|"); + pw.println("Actual cause was |" + cause.getMessage() + "|"); + } + } else { + passed = false; + pw.println("rootCause message thrown by Exception was null"); + } + } else { + passed = false; + pw.println("Exception thrown was not an instance of ServletException"); + } + } + ServletTestUtil.printResult(pw, passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletexception/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletexception/URLClient.java new file mode 100644 index 0000000000..76246c7e39 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletexception/URLClient.java @@ -0,0 +1,126 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletexception; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_servletexception_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_js_servletexception_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: getRootCauseTest + * + * @assertion_ids: Servlet:SPEC:83; Servlet:JAVADOC:108; Servlet:JAVADOC:109; + * Servlet:JAVADOC:8; + * + * @test_Strategy: A Test for getRootCause method + */ + @Test + public void getRootCauseTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getRootCause"); + invoke(); + } + + /* + * @testName: servletExceptionConstructor1Test + * + * @assertion_ids: Servlet:SPEC:83; Servlet:JAVADOC:105; + * + * @test_Strategy: A Test for ServletException() constructor method + */ + @Test + public void servletExceptionConstructor1Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "servletExceptionConstructor1"); + invoke(); + } + + /* + * @testName: servletExceptionConstructor2Test + * + * @assertion_ids: Servlet:SPEC:83; Servlet:JAVADOC:106; + * + * @test_Strategy: A Test for ServletException(String) constructor method + */ + @Test + public void servletExceptionConstructor2Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "servletExceptionConstructor2"); + invoke(); + } + + /* + * @testName: servletExceptionConstructor3Test + * + * @assertion_ids: Servlet:SPEC:83; Servlet:JAVADOC:108; Servlet:JAVADOC:109; + * Servlet:JAVADOC:8; + * + * @test_Strategy: A Test for ServletException(Throwable) constructor method + */ + @Test + public void servletExceptionConstructor3Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "servletExceptionConstructor3"); + invoke(); + + } + + /* + * @testName: servletExceptionConstructor4Test + * + * @assertion_ids: Servlet:SPEC:83; Servlet:JAVADOC:107; Servlet:JAVADOC:109; + * Servlet:JAVADOC:8; + * + * @test_Strategy: A Test for ServletException(String,Throwable) constructor + * method + */ + @Test + public void servletExceptionConstructor4Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "servletExceptionConstructor4"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletexception/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletexception/build.xml new file mode 100644 index 0000000000..b3e07ff83e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletexception/build.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletexception/servlet_js_servletexception_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletexception/servlet_js_servletexception_web.xml new file mode 100644 index 0000000000..65f1c4fbf1 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletexception/servlet_js_servletexception_web.xml @@ -0,0 +1,33 @@ + + + + + SerJaxSerServletException + + TestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.servletexception.TestServlet + + + TestLogicalName + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletinputstream/ReadLineTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletinputstream/ReadLineTestServlet.java new file mode 100644 index 0000000000..25d08601e7 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletinputstream/ReadLineTestServlet.java @@ -0,0 +1,104 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2001, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletinputstream; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletInputStream; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class ReadLineTestServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = true; + ServletInputStream sins = request.getInputStream(); + + int contentLen = request.getContentLength(); + + if (contentLen >= 1) { + + byte buffer[] = new byte[contentLen + 1]; + int len = sins.readLine(buffer, 0, contentLen); + + String expectedResult = "test data"; + String result = new String(buffer); + + if (!(result.trim()).equals(expectedResult)) { + passed = false; + pw.println("readLine() returned incorrect result"); + pw.println("Expected result = " + expectedResult); + pw.println("Actual result = |" + result + "|"); + } + } else { + passed = false; + pw.println("ServletRequest.getContentLength() returned incorrect result"); + pw.println("Expected a result >= 1"); + pw.println("Actual result = " + contentLen); + } + ServletTestUtil.printResult(pw, passed); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletinputstream/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletinputstream/URLClient.java new file mode 100644 index 0000000000..de3bc16382 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletinputstream/URLClient.java @@ -0,0 +1,77 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletinputstream; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.common.util.Data; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_servletinputstream_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(ReadLineTestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_js_servletinputstream_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: readLineTest + * + * @assertion_ids: Servlet:JAVADOC:103 + * + * @test_Strategy: Client posts a request to the servlet and the servlet reads + * and verifies the correct behavior for readLine() + * + */ + @Test + public void readLineTest() throws Exception { + String testName = "readLineTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, + "POST " + getContextRoot() + "/" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(CONTENT, "test data"); + TEST_PROPS.setProperty(SEARCH_STRING, Data.PASSED); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletinputstream/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletinputstream/build.xml new file mode 100644 index 0000000000..380f9e38a6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletinputstream/build.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletinputstream/servlet_js_servletinputstream_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletinputstream/servlet_js_servletinputstream_web.xml new file mode 100644 index 0000000000..6e5257f3e8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletinputstream/servlet_js_servletinputstream_web.xml @@ -0,0 +1,33 @@ + + + + + SerJaxSerServletInputStream + + readLineTest + com.sun.ts.tests.servlet.api.jakarta_servlet.servletinputstream.ReadLineTestServlet + + + readLineTest + /readLineTest + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletoutputstream/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletoutputstream/TestServlet.java new file mode 100644 index 0000000000..7cffc4d359 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletoutputstream/TestServlet.java @@ -0,0 +1,318 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletoutputstream; + +import java.io.IOException; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletOutputStream; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + /** + * Test for println (java.lang.String) method + **/ + + public void print_StringTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + ServletOutputStream sos = null; + + try { + sos = response.getOutputStream(); + + sos.print("some "); + sos.print("text"); + sos.print("\n"); + } catch (Throwable t) { + ServletTestUtil.printResult(sos, false); + throw new ServletException(t); + } + } + + /* print(boolean) */ + + public void print_booleanTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + ServletOutputStream sos = null; + + try { + sos = response.getOutputStream(); + sos.print(true); + sos.print(true); + sos.print("\n"); + + } catch (Throwable t) { + ServletTestUtil.printResult(sos, false); + throw new ServletException(t); + } + } + + /* print(char) */ + + public void print_charTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + ServletOutputStream sos = null; + + try { + sos = response.getOutputStream(); + sos.print('T'); + sos.print('E'); + sos.print('X'); + sos.print('T'); + sos.print("\n"); + + } catch (Throwable t) { + ServletTestUtil.printResult(sos, false); + throw new ServletException(t); + } + } + + /* print(double) */ + + public void print_doubleTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + ServletOutputStream sos = null; + double doubleval = 12345.6; + + try { + sos = response.getOutputStream(); + sos.print(doubleval); + sos.print(doubleval); + sos.print("\n"); + + } catch (Throwable t) { + ServletTestUtil.printResult(sos, false); + throw new ServletException(t); + } + } + + /* print(float) */ + + public void print_floatTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + ServletOutputStream sos = null; + float floatval = 1234.5f; + + try { + sos = response.getOutputStream(); + sos.print(floatval); + sos.print(floatval); + sos.print("\n"); + + } catch (Throwable t) { + ServletTestUtil.printResult(sos, false); + throw new ServletException(t); + } + } + + /* print(int) */ + + public void print_intTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + ServletOutputStream sos = null; + int num = 1; + + try { + sos = response.getOutputStream(); + sos.print(num); + sos.print(num); + sos.print("\n"); + + } catch (Throwable t) { + ServletTestUtil.printResult(sos, false); + throw new ServletException(t); + } + } + + /* print(long) */ + + public void print_longTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + ServletOutputStream sos = null; + long ago = 1234567890; + + try { + sos = response.getOutputStream(); + sos.print(ago); + sos.print(ago); + sos.print("\n"); + + } catch (Throwable t) { + ServletTestUtil.printResult(sos, false); + throw new ServletException(t); + } + } + + /** + * Test for println () method + **/ + + public void printlnTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + ServletOutputStream sos = null; + + try { + sos = response.getOutputStream(); + + sos.print("some test "); + sos.println(); + sos.print("text"); + sos.println(); + + } catch (Throwable t) { + ServletTestUtil.printResult(sos, false); + throw new ServletException(t); + } + } + + /** + * Test for println (java.lang.String) method + **/ + + public void println_StringTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + ServletOutputStream sos = null; + + try { + sos = response.getOutputStream(); + + sos.println("some"); + sos.println("text"); + + } catch (Throwable t) { + ServletTestUtil.printResult(sos, false); + throw new ServletException(t); + } + } + + /* println(boolean) */ + + public void println_booleanTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + ServletOutputStream sos = null; + + try { + sos = response.getOutputStream(); + sos.println(true); + sos.println(true); + + } catch (Throwable t) { + ServletTestUtil.printResult(sos, false); + throw new ServletException(t); + } + } + + /* println(char) */ + + public void println_charTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + ServletOutputStream sos = null; + + try { + sos = response.getOutputStream(); + sos.println('T'); + sos.println('E'); + sos.println('X'); + sos.println('T'); + + } catch (Throwable t) { + ServletTestUtil.printResult(sos, false); + throw new ServletException(t); + } + } + + /* println(double) */ + + public void println_doubleTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + ServletOutputStream sos = null; + double doubleval = 12345.6; + + try { + sos = response.getOutputStream(); + sos.println(doubleval); + sos.println(doubleval); + + } catch (Throwable t) { + ServletTestUtil.printResult(sos, false); + throw new ServletException(t); + } + } + + /* println(float) */ + + public void println_floatTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + ServletOutputStream sos = null; + float floatval = 1234.5f; + + try { + sos = response.getOutputStream(); + sos.println(floatval); + sos.println(floatval); + + } catch (Throwable t) { + ServletTestUtil.printResult(sos, false); + throw new ServletException(t); + } + } + + /* println(int) */ + + public void println_intTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + ServletOutputStream sos = null; + int num = 1; + + try { + sos = response.getOutputStream(); + sos.println(num); + sos.println(num); + + } catch (Throwable t) { + ServletTestUtil.printResult(sos, false); + throw new ServletException(t); + } + } + + /* println(long) */ + + public void println_longTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + ServletOutputStream sos = null; + long ago = 1234567890; + + try { + sos = response.getOutputStream(); + sos.println(ago); + sos.println(ago); + + } catch (Throwable t) { + ServletTestUtil.printResult(sos, false); + throw new ServletException(t); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletoutputstream/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletoutputstream/URLClient.java new file mode 100644 index 0000000000..d434b648c1 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletoutputstream/URLClient.java @@ -0,0 +1,302 @@ +/* + * 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 com.sun.ts.tests.servlet.api.jakarta_servlet.servletoutputstream; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_servletoutputstream_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_js_servletoutputstream_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: print_StringTest + * + * @assertion_ids: Servlet:JAVADOC:140; Servlet:JAVADOC:73; + * + * @test_Strategy: Test for print(java.lang.String s) method + */ + @Test + public void print_StringTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "some text"); + + TEST_PROPS.setProperty(APITEST, "print_StringTest"); + invoke(); + } + + /* + * @testName: print_booleanTest + * + * @assertion_ids: Servlet:JAVADOC:140; Servlet:JAVADOC:75; + * + * @test_Strategy: Test for print(boolean b) method + */ + @Test + public void print_booleanTest() throws Exception { + String s = Boolean.TRUE.toString(); + + StringBuffer ss = new StringBuffer(s).append(s); + + TEST_PROPS.setProperty(SEARCH_STRING, ss.toString()); + + TEST_PROPS.setProperty(APITEST, "print_booleanTest"); + invoke(); + } + + /* + * @testName: print_charTest + * + * @assertion_ids: Servlet:JAVADOC:140; Servlet:JAVADOC:77; + * + * @test_Strategy: Test for print(char c) method + */ + @Test + public void print_charTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "TEXT"); + + TEST_PROPS.setProperty(APITEST, "print_charTest"); + invoke(); + } + + /* + * @testName: print_doubleTest + * + * @assertion_ids: Servlet:JAVADOC:140; Servlet:JAVADOC:85; + * + * @test_Strategy: Test for print(double d) method + */ + @Test + public void print_doubleTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "12345.612345.6"); + + TEST_PROPS.setProperty(APITEST, "print_doubleTest"); + invoke(); + } + + /* + * @testName: print_floatTest + * + * @assertion_ids: Servlet:JAVADOC:140; Servlet:JAVADOC:83; + * + * @test_Strategy: Test for println(float f) method + */ + @Test + public void print_floatTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "1234.51234.5"); + + TEST_PROPS.setProperty(APITEST, "print_floatTest"); + invoke(); + } + + /* + * @testName: print_intTest + * + * @assertion_ids: Servlet:JAVADOC:140; Servlet:JAVADOC:79; + * + * @test_Strategy: Test for print(integer i) method + */ + @Test + public void print_intTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "11"); + + TEST_PROPS.setProperty(APITEST, "print_intTest"); + invoke(); + } + + /* + * @testName: print_longTest + * + * @assertion_ids: Servlet:JAVADOC:140; Servlet:JAVADOC:81; + * + * @test_Strategy: Test for print(long l) method + */ + @Test + public void print_longTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "12345678901234567890"); + + TEST_PROPS.setProperty(APITEST, "print_longTest"); + invoke(); + } + + /* + * @testName: printlnTest + * + * @assertion_ids: Servlet:JAVADOC:140; Servlet:JAVADOC:87; + * Servlet:JAVADOC:89; + * + * @test_Strategy: Test for println () method + */ + @Test + public void printlnTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "some test"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "some test text"); + + TEST_PROPS.setProperty(APITEST, "printlnTest"); + invoke(); + } + + /* + * @testName: println_StringTest + * + * @assertion_ids: Servlet:JAVADOC:140; Servlet:JAVADOC:89; + * + * @test_Strategy: Test for println(java.lang.String s) method + */ + @Test + public void println_StringTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "some|text"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "sometext"); + + TEST_PROPS.setProperty(APITEST, "println_StringTest"); + invoke(); + } + + /* + * @testName: println_booleanTest + * + * @assertion_ids: Servlet:JAVADOC:140; Servlet:JAVADOC:91; + * + * @test_Strategy: Test for println(boolean b) method + */ + @Test + public void println_booleanTest() throws Exception { + String s = Boolean.TRUE.toString(); + + StringBuffer ss = new StringBuffer(s); + ss = ss.append(s); + + TEST_PROPS.setProperty(SEARCH_STRING, s); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, ss.toString()); + + TEST_PROPS.setProperty(APITEST, "println_booleanTest"); + invoke(); + } + + /* + * @testName: println_charTest + * + * @assertion_ids: Servlet:JAVADOC:140; Servlet:JAVADOC:93; + * + * @test_Strategy: Test for println(char c) method + */ + @Test + public void println_charTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "T|E|X|T"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "TEXT"); + + TEST_PROPS.setProperty(APITEST, "println_charTest"); + invoke(); + } + + /* + * @testName: println_doubleTest + * + * @assertion_ids: Servlet:JAVADOC:140; Servlet:JAVADOC:101; + * + * @test_Strategy: Test for println(double d) method + */ + @Test + public void println_doubleTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "12345.6"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "12345.612345.6"); + + TEST_PROPS.setProperty(APITEST, "println_doubleTest"); + invoke(); + } + + /* + * @testName: println_floatTest + * + * @assertion_ids: Servlet:JAVADOC:140; Servlet:JAVADOC:99; + * + * @test_Strategy: Test for print(float f) method + */ + @Test + public void println_floatTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "1234.5"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "1234.51234.5"); + + TEST_PROPS.setProperty(APITEST, "println_floatTest"); + invoke(); + } + + /* + * @testName: println_intTest + * + * @assertion_ids: Servlet:JAVADOC:140; Servlet:JAVADOC:95; + * + * @test_Strategy: Test for println(integer i) method + */ + @Test + public void println_intTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "1"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "11"); + + TEST_PROPS.setProperty(APITEST, "println_intTest"); + invoke(); + } + + /* + * @testName: println_longTest + * + * @assertion_ids: Servlet:JAVADOC:140; Servlet:JAVADOC:97; + * + * @test_Strategy: Test for println(long l) method + */ + @Test + public void println_longTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "1234567890"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "12345678901234567890"); + + TEST_PROPS.setProperty(APITEST, "println_longTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletoutputstream/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletoutputstream/build.xml new file mode 100644 index 0000000000..aa6b5f68a2 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletoutputstream/build.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletoutputstream/servlet_js_servletoutputstream_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletoutputstream/servlet_js_servletoutputstream_web.xml new file mode 100644 index 0000000000..c1c52b6c0a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletoutputstream/servlet_js_servletoutputstream_web.xml @@ -0,0 +1,33 @@ + + + + + SerJaxSerServletOutputStream + + TestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.servletoutputstream.TestServlet + + + TestLogicalName + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest/GetParameterNamesEmptyEnumTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest/GetParameterNamesEmptyEnumTestServlet.java new file mode 100644 index 0000000000..02a2cbe2bf --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest/GetParameterNamesEmptyEnumTestServlet.java @@ -0,0 +1,79 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2009, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.RequestTests; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class GetParameterNamesEmptyEnumTestServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + RequestTests.getParameterNamesEmptyEnumTest(pw, request, response); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest/GetReaderUnsupportedEncodingExceptionTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest/GetReaderUnsupportedEncodingExceptionTestServlet.java new file mode 100644 index 0000000000..d131ef4ca3 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest/GetReaderUnsupportedEncodingExceptionTestServlet.java @@ -0,0 +1,81 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2009, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.RequestTests; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class GetReaderUnsupportedEncodingExceptionTestServlet + extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + RequestTests.getReaderUnsupportedEncodingExceptionTest(pw, request, + response); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest/SetCharacterEncodingTest.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest/SetCharacterEncodingTest.java new file mode 100644 index 0000000000..784a4e05b8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest/SetCharacterEncodingTest.java @@ -0,0 +1,41 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.RequestTests; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class SetCharacterEncodingTest extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + RequestTests.setCharacterEncodingTest(pw, request, response); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest/SetCharacterEncodingUnsupportedEncodingExceptionTest.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest/SetCharacterEncodingUnsupportedEncodingExceptionTest.java new file mode 100644 index 0000000000..7ea1c32f15 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest/SetCharacterEncodingUnsupportedEncodingExceptionTest.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2009, 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.RequestTests; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class SetCharacterEncodingUnsupportedEncodingExceptionTest + extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + RequestTests.setCharacterEncodingUnsupportedEncodingExceptionTest(pw, + request, response); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest/URLClient.java new file mode 100644 index 0000000000..d11ef7b9c3 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest/URLClient.java @@ -0,0 +1,539 @@ +/* + * 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest; + +import com.sun.ts.tests.servlet.common.request.RequestClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends RequestClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_servletrequest_web.war").addAsLibraries(CommonServlets.getCommonServletsArchive()).addClasses(GetParameterNamesEmptyEnumTestServlet.class, GetReaderUnsupportedEncodingExceptionTestServlet.class, SetCharacterEncodingTest.class, SetCharacterEncodingUnsupportedEncodingExceptionTest.class).setWebXML(URLClient.class.getResource("servlet_js_servletrequest_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + /* Run test */ + /* + * @testName: getAttributeNamesTest + * + * @assertion_ids: Servlet:JAVADOC:174 + * + * @test_Strategy: Servlet sets some attributes and verifies they can be + * retrieved. + * + */ + /* + * @testName: getAttributeNamesEmptyEnumTest + * + * @assertion_ids: Servlet:JAVADOC:175 + * + * @test_Strategy: No attributes exist in request. + */ + /* + * @testName: getAttributeTest + * + * @assertion_ids: Servlet:JAVADOC:172 + * + * @test_Strategy: Servlet sets an attribute and retrieves it. + */ + /* + * @testName: getAttributeDoesNotExistTest + * + * @assertion_ids: Servlet:JAVADOC:173 + * + * @test_Strategy: Servlet tries to retrieve a non-existant attribute. + * + */ + /* + * @testName: getCharacterEncodingTest + * + * @assertion_ids: Servlet:JAVADOC:176 + * + * @test_Strategy: Client sets an encoding and Servlet tries to retrieve it. + */ + /* + * @testName: getCharacterEncodingNullTest + * + * @assertion_ids: Servlet:JAVADOC:177 + * + * @test_Strategy: Client does not set an encoding and Servlet tries to + * retrieve it. + * + */ + /* + * @testName: getContentLengthTest + * + * @assertion_ids: Servlet:JAVADOC:180 + * + * @test_Strategy: Servlet compares this length to the actual length of the + * content body read in using getInputStream + * + */ + /* + * @testName: getContentTypeTest + * + * @assertion_ids: Servlet:JAVADOC:182; Servlet:SPEC:34; + * + * @test_Strategy: Client sets the content type and servlet reads it. + */ + /* + * @testName: getContentTypeNullTest + * + * @assertion_ids: Servlet:JAVADOC:183; Servlet:SPEC:34; + * + * @test_Strategy: Servlet tries to read content type. + */ + /* + * @testName: getInputStreamTest + * + * @assertion_ids: Servlet:JAVADOC:184 + * + * @test_Strategy: Servlet tries to read the input stream. + */ + /* + * @testName: getInputStreamIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:186 + * + * @test_Strategy: Servlet gets a Reader object using + * ServletRequest.getReader() then tries to get the inputStream Object + * + */ + /* + * @testName: getLocaleTest + * + * @assertion_ids: Servlet:JAVADOC:206 + * + * @test_Strategy: Client specifics a locale and the servlet verifies it. + */ + /* + * @testName: getLocaleDefaultTest + * + * @assertion_ids: Servlet:JAVADOC:207 + * + * @test_Strategy: Client does not specify a locale and the servlet verifies + * the default. + */ + /* + * @testName: getLocalesTest + * + * @assertion_ids: Servlet:JAVADOC:208 + * + * @test_Strategy: Client specifics 2 locales and the servlet verifies it. + */ + /* + * @testName: getLocalesDefaultTest + * + * @assertion_ids: Servlet:JAVADOC:209 + * + * @test_Strategy: Client does not specify a locale and the servlet verifies + * the default. + */ + /* + * @testName: getParameterMapTest + * + * @assertion_ids: Servlet:JAVADOC:193 + * + * @test_Strategy: Client sets several parameters and the servlet attempts to + * access them. + */ + /* + * @testName: getParameterNamesTest + * + * @assertion_ids: Servlet:JAVADOC:189 + * + * @test_Strategy: Client sets several parameters and the servlet attempts to + * access them. + */ + /* + * @testName: getParameterNamesEmptyEnumTest + * + * @assertion_ids: Servlet:JAVADOC:190 + * + * @test_Strategy: Client does not set any parameters and the servlet attempts + * to access them. + */ + /* + * @testName: getParameterTest + * + * @assertion_ids: Servlet:JAVADOC:187 + * + * @test_Strategy: Client sets a parameter and servlet retrieves it. + */ + /* + * @testName: getParameterDoesNotExistTest + * + * @assertion_ids: Servlet:JAVADOC:188 + * + * @test_Strategy: Servlet tries to access a non-existent parameter + */ + /* + * @testName: getParameterValuesTest + * + * @assertion_ids: Servlet:JAVADOC:191 + * + * @test_Strategy: Client sets a parameter which has 2 values and servlet + * verifies boths values. + */ + /* + * @testName: getParameterValuesDoesNotExistTest + * + * @assertion_ids: Servlet:JAVADOC:192 + * + * @test_Strategy: Servlet tries to retrieve a parameter that does not exist + */ + /* + * @testName: getProtocolTest + * + * @assertion_ids: Servlet:JAVADOC:194 + * + * @test_Strategy: Servlet verifies the protocol used by the client + */ + /* + * @testName: getReaderTest + * + * @assertion_ids: Servlet:JAVADOC:198 + * + * @test_Strategy: Client sets some content and servlet reads the content + */ + /* + * @testName: getReaderIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:201 + * + * @test_Strategy: Servlet gets an InputStream Object then tries to get a + * Reader Object. + */ + /* + * @testName: getReaderUnsupportedEncodingExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:200 + * + * @test_Strategy: Client sets some content but with an invalid encoding, + * servlet tries to read content. + */ + /* + * @testName: getRemoteAddrTest + * + * @assertion_ids: Servlet:JAVADOC:202 + * + * @test_Strategy: Servlet reads and verifies where the request originated + */ + /* + * @testName: getLocalAddrTest + * + * @assertion_ids: Servlet:JAVADOC:704 + * + * @test_Strategy: Servlet reads and verifies where the request originated + */ + /* + * @testName: getRemoteHostTest + * + * @assertion_ids: Servlet:JAVADOC:203; + * + * @test_Strategy: Servlet reads and verifies where the request originated + */ + /* + * @testName: getRequestDispatcherTest + * + * @assertion_ids: Servlet:JAVADOC:211 + * + * @test_Strategy: Servlet tries to get a dispatcher + */ + /* + * @testName: getSchemeTest + * + * @assertion_ids: Servlet:JAVADOC:195 + * + * @test_Strategy: Servlet verifies the scheme of the url used in the request + */ + /* + * @testName: getServerNameTest + * + * @assertion_ids: Servlet:JAVADOC:196 + * + * @test_Strategy: Servlet verifies the destination of the request + */ + /* + * @testName: getServerPortTest + * + * @assertion_ids: Servlet:JAVADOC:197 + * + * @test_Strategy: Servlet verifies the destination port of the request + */ + /* + * @testName: isSecureTest + * + * @assertion_ids: Servlet:JAVADOC:210 + * + * @test_Strategy: Servlet verifies the isSecure method for the non-secure + * case. + */ + /* + * @testName: removeAttributeTest + * + * @assertion_ids: Servlet:JAVADOC:205 + * + * @test_Strategy: Servlet adds then removes an attribute, then verifies it + * was removed. + */ + /* + * @testName: setAttributeTest + * + * @assertion_ids: Servlet:JAVADOC:204 + * + * @test_Strategy: Servlet adds an attribute, then verifies it was added + */ + /* + * @testName: setCharacterEncodingUnsupportedEncodingExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:179 + * + * @test_Strategy: Servlet tries to set an invalid encoding. + * + */ + /* + * @testName: setCharacterEncodingTest + * + * @assertion_ids: Servlet:JAVADOC:178 + * + * @test_Strategy: Servlet sets a new encoding and tries to retrieve it. + */ + /* + * @testName: setCharacterEncodingTest1 + * + * @assertion_ids: Servlet:JAVADOC:178; Servlet:JAVADOC:177; Servlet:SPEC:28; + * Servlet:SPEC:213; + * + * @test_Strategy: ServletRequest calls getReader()first; then sets a new + * encoding and tries to retrieve it. verifies that the new encoding is + * ignored. + */ + @Test() + public void getAttributeDoesNotExistTest() throws Exception { + super.getAttributeDoesNotExistTest(); + } + + @Test() + public void getAttributeNamesEmptyEnumTest() throws Exception { + super.getAttributeNamesEmptyEnumTest(); + } + + @Test() + public void getAttributeNamesTest() throws Exception { + super.getAttributeNamesTest(); + } + + @Test() + public void getAttributeTest() throws Exception { + super.getAttributeTest(); + } + + @Test() + public void getCharacterEncodingNullTest() throws Exception { + super.getCharacterEncodingNullTest(); + } + + @Test() + public void getCharacterEncodingTest() throws Exception { + super.getCharacterEncodingTest(); + } + + @Test() + public void getContentLengthTest() throws Exception { + super.getContentLengthTest(); + } + + @Test() + public void getContentTypeNullTest() throws Exception { + super.getContentTypeNullTest(); + } + + @Test() + public void getContentTypeTest() throws Exception { + super.getContentTypeTest(); + } + + @Test() + public void getInputStreamIllegalStateExceptionTest() throws Exception { + super.getInputStreamIllegalStateExceptionTest(); + } + + @Test() + public void getInputStreamTest() throws Exception { + super.getInputStreamTest(); + } + + @Test() + public void getLocalAddrTest() throws Exception { + super.getLocalAddrTest(); + } + + @Test() + public void getLocaleDefaultTest() throws Exception { + super.getLocaleDefaultTest(); + } + + @Test() + public void getLocaleTest() throws Exception { + super.getLocaleTest(); + } + + @Test() + public void getLocalesDefaultTest() throws Exception { + super.getLocalesDefaultTest(); + } + + @Test() + public void getLocalesTest() throws Exception { + super.getLocalesTest(); + } + + @Test() + public void getParameterDoesNotExistTest() throws Exception { + super.getParameterDoesNotExistTest(); + } + + @Test() + public void getParameterMapTest() throws Exception { + super.getParameterMapTest(); + } + + @Test() + public void getParameterNamesEmptyEnumTest() throws Exception { + super.getParameterNamesEmptyEnumTest(); + } + + @Test() + public void getParameterNamesTest() throws Exception { + super.getParameterNamesTest(); + } + + @Test() + public void getParameterTest() throws Exception { + super.getParameterTest(); + } + + @Test() + public void getParameterValuesDoesNotExistTest() throws Exception { + super.getParameterValuesDoesNotExistTest(); + } + + @Test() + public void getParameterValuesTest() throws Exception { + super.getParameterValuesTest(); + } + + @Test() + public void getProtocolTest() throws Exception { + super.getProtocolTest(); + } + + @Test() + public void getReaderIllegalStateExceptionTest() throws Exception { + super.getReaderIllegalStateExceptionTest(); + } + + @Test() + public void getReaderTest() throws Exception { + super.getReaderTest(); + } + + @Test() + public void getReaderUnsupportedEncodingExceptionTest() throws Exception { + super.getReaderUnsupportedEncodingExceptionTest(); + } + + @Test() + public void getRemoteAddrTest() throws Exception { + super.getRemoteAddrTest(); + } + + @Test() + public void getRemoteHostTest() throws Exception { + super.getRemoteHostTest(); + } + + @Test() + public void getRequestDispatcherTest() throws Exception { + super.getRequestDispatcherTest(); + } + + @Test() + public void getSchemeTest() throws Exception { + super.getSchemeTest(); + } + + @Test() + public void getServerNameTest() throws Exception { + super.getServerNameTest(); + } + + @Test() + public void getServerPortTest() throws Exception { + super.getServerPortTest(); + } + + @Test() + public void isSecureTest() throws Exception { + super.isSecureTest(); + } + + @Test() + public void removeAttributeTest() throws Exception { + super.removeAttributeTest(); + } + + @Test() + public void setAttributeTest() throws Exception { + super.setAttributeTest(); + } + + @Test() + public void setCharacterEncodingTest() throws Exception { + super.setCharacterEncodingTest(); + } + + @Test() + public void setCharacterEncodingTest1() throws Exception { + super.setCharacterEncodingTest1(); + } + + @Test() + public void setCharacterEncodingUnsupportedEncodingExceptionTest() throws Exception { + super.setCharacterEncodingUnsupportedEncodingExceptionTest(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest/build.xml new file mode 100644 index 0000000000..5700594557 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest/build.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest/servlet_js_servletrequest_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest/servlet_js_servletrequest_web.xml new file mode 100644 index 0000000000..21dea919b1 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest/servlet_js_servletrequest_web.xml @@ -0,0 +1,65 @@ + + + + + SerJaxSerServletRequest + + TestServlet + com.sun.ts.tests.servlet.common.servlets.RequestTestServlet + + + getParameterNamesEmptyEnumTest + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest.GetParameterNamesEmptyEnumTestServlet + + + getReaderUnsupportedEncodingExceptionTest + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest.GetReaderUnsupportedEncodingExceptionTestServlet + + + setCharacterEncodingUnsupportedEncodingExceptionTest + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest.SetCharacterEncodingUnsupportedEncodingExceptionTest + + + setCharacterEncodingTest + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest.SetCharacterEncodingTest + + + TestServlet + /TestServlet/* + + + getParameterNamesEmptyEnumTest + /getParameterNamesEmptyEnumTest + + + getReaderUnsupportedEncodingExceptionTest + /getReaderUnsupportedEncodingExceptionTest + + + setCharacterEncodingUnsupportedEncodingExceptionTest + /setCharacterEncodingUnsupportedEncodingExceptionTest + + + setCharacterEncodingTest + /setCharacterEncodingTest + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest1/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest1/URLClient.java new file mode 100644 index 0000000000..212301c53a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest1/URLClient.java @@ -0,0 +1,71 @@ +/* + * 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest1; + +import com.sun.ts.tests.servlet.common.request.RequestClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends RequestClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_servletrequest1_web.war").addAsLibraries(CommonServlets.getCommonServletsArchive()).setWebXML(URLClient.class.getResource("servlet_js_servletrequest1_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: getLocalPortTest + * + * @assertion_ids: Servlet:JAVADOC:635 + * + * @test_Strategy: Test servlet API SDervletRequest.getLocalPort() + */ + /* + * @testName: getLocalNameTest + * + * @assertion_ids: Servlet:JAVADOC:632 + * + * @test_Strategy: Test servlet API SDervletRequest.getLocalName() + */ + @Test() + public void getLocalNameTest() throws Exception { + super.getLocalNameTest(); + } + + @Test() + public void getLocalPortTest() throws Exception { + super.getLocalPortTest(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest1/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest1/build.xml new file mode 100644 index 0000000000..2f285a6187 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest1/build.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest1/servlet_js_servletrequest1_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest1/servlet_js_servletrequest1_web.xml new file mode 100644 index 0000000000..ecf4769dc3 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest1/servlet_js_servletrequest1_web.xml @@ -0,0 +1,33 @@ + + + + + SerJaxSerServletRequest + + TestServlet + com.sun.ts.tests.servlet.common.servlets.RequestTestServlet + + + TestServlet + /TestServlet/* + + + 54 + + \ No newline at end of file diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest30/AsyncTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest30/AsyncTestServlet.java new file mode 100644 index 0000000000..3273caca34 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest30/AsyncTestServlet.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2009, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest30; + +import java.io.IOException; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class AsyncTestServlet extends GenericTCKServlet { + + public void getDispatcherTypeTestAsync(ServletRequest request, + ServletResponse response) { + String path = "/async/AsyncTests?testname=getDispatcherTypeTest"; + AsyncContext ac = request.startAsync(); + ac.dispatch(path); + } + + public void asyncStartedTest1(ServletRequest request, + ServletResponse response) throws IOException { + AsyncContext ac = request.startAsync(); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + ac.complete(); + } + + public void asyncStartedTest2(ServletRequest request, + ServletResponse response) throws IOException { + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + } + + public void asyncStartedTest3(ServletRequest request, + ServletResponse response) throws IOException { + AsyncContext ac = request.startAsync(); + ac.complete(); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + } + + public void asyncStartedTest4(ServletRequest request, + ServletResponse response) { + String path = "/async/AsyncTests?testname=isAsyncStartedTest"; + AsyncContext ac = request.startAsync(); + ac.dispatch(path); + } + + public void isAsyncSupportedTest(ServletRequest request, + ServletResponse response) throws IOException { + response.getWriter() + .println("isAsyncSupported=" + request.isAsyncSupported()); + } + + public void startAsyncTest(ServletRequest request, ServletResponse response) + throws IOException { + String path = "/async/AsyncTests?testname=getDispatcherTypeTest"; + AsyncContext ac = request.startAsync(); + ac.dispatch(path); + try { + request.startAsync(); + response.getWriter().println( + "Expected IllegalStateException not thrown in AsyncTestServlet#startAsyncTest. Test FAILED."); + } catch (IllegalStateException ise) { + response.getWriter().println( + "Expected IllegalStateException thrown in AsyncTestServlet#startAsyncTest. Test PASSED."); + } + } + + public void getAsyncContextTest(ServletRequest request, + ServletResponse response) throws IOException { + AsyncContext ac = request.startAsync(); + AsyncContext ac1 = request.getAsyncContext(); + if (ac != ac1) { + response.getWriter() + .println("getAsyncContext returned is different. Test FAILED."); + } else { + response.getWriter() + .println("getAsyncContext returned is correct. Test PASSED."); + } + ac.complete(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest30/AsyncTests.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest30/AsyncTests.java new file mode 100644 index 0000000000..dd19e63dff --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest30/AsyncTests.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2009, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest30; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class AsyncTests extends GenericServlet { + + private static final String TEST_HEADER = "testname"; + + private static final Class[] TEST_ARGS = { ServletRequest.class, + ServletResponse.class }; + + public void service(ServletRequest req, ServletResponse res) + throws ServletException, IOException { + String test = req.getParameter(TEST_HEADER); + try { + Method method = this.getClass().getMethod(test, TEST_ARGS); + method.invoke(this, new Object[] { req, res }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + } + + public void getDispatcherTypeTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + // Make sure that Asyn process last long enough for tesing purpose + try { + Thread.currentThread().sleep(5000); + } catch (InterruptedException ie) { + // do nothing, shouldn't fail + } + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + } + + public void isAsyncStartedTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest30/SecondServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest30/SecondServlet.java new file mode 100644 index 0000000000..4903aff452 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest30/SecondServlet.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2009, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest30; + +import java.io.IOException; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class SecondServlet extends GenericServlet { + + public void service(ServletRequest req, ServletResponse res) + throws ServletException, IOException { + getDispatcherTypeTest(req, res); + } + + public void getDispatcherTypeTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest30/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest30/TestServlet.java new file mode 100644 index 0000000000..015b17243a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest30/TestServlet.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2009, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest30; + +import java.io.IOException; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void getServletContextTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + ServletContext actual = request.getServletContext(); + ServletContext expected = this.getServletConfig().getServletContext(); + + if (actual != expected) { + response.getWriter().println( + "getServletContext() returned inconsistent result. Test FAILED."); + } else { + response.getWriter().println("Test PASSED."); + } + } + + public void getDispatcherTypeTestRequest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + } + + public void getDispatcherTypeTestForward(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + String path = "/forward/ForwardedServlet?testname=getDispatcherTypeTest"; + RequestDispatcher rd = request.getRequestDispatcher(path); + + if (rd == null) { + response.getWriter() + .println("Null RequestDispatcher got for path=" + path); + } else { + rd.forward(request, response); + } + + } + + public void getDispatcherTypeTestInclude(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + String path = "/include/IncludedServlet?testname=getDispatcherTypeTest"; + RequestDispatcher rd = request.getRequestDispatcher(path); + + if (rd == null) { + response.getWriter() + .println("Null RequestDispatcher got for path=" + path); + } else { + rd.include(request, response); + } + } + + public void isAsyncSupportedTest(ServletRequest request, + ServletResponse response) throws IOException { + response.getWriter() + .println("isAsyncSupported=" + request.isAsyncSupported()); + } + + public void startAsyncTest(ServletRequest request, ServletResponse response) + throws IOException { + try { + AsyncContext startAsync = request.startAsync(); + response.getWriter() + .println("Expected IllegalStateException not thrown. Test FAILED."); + } catch (IllegalStateException ise) { + response.getWriter() + .println("Expected IllegalStateException thrown. Test PASSED."); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest30/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest30/URLClient.java new file mode 100644 index 0000000000..58bf7d2539 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest30/URLClient.java @@ -0,0 +1,323 @@ +/* + * Copyright (c) 2009, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest30; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_servletrequest30_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(AsyncTests.class, AsyncTestServlet.class, SecondServlet.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_js_servletrequest30_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + /* + * @testName: getServletContextTest + * + * @assertion_ids: Servlet:JAVADOC:706; + * + * @test_Strategy: ServletRequest calls getServletContext(); verifies that + * returned ServletContext instance is consistent with the one stored in + * ServletConfigs. + */ + @Test + public void getServletContextTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletContextTest"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "TEST FAILED"); + TEST_PROPS.setProperty(SEARCH_STRING, "Test PASSED"); + invoke(); + } + + /* + * @testName: getDispatcherTypeTestRequest + * + * @assertion_ids: Servlet:JAVADOC:703; + * + * @test_Strategy: Create a Servlet TestServlet; Client send a request to + * TestServlet; call ServletRequest.getDispatcherType() verifies that + * DispatcherType.REQUEST is returned. + */ + @Test + public void getDispatcherTypeTestRequest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getDispatcherTypeTestRequest"); + TEST_PROPS.setProperty(SEARCH_STRING, "DispatcherType=REQUEST"); + invoke(); + } + + /* + * @testName: getDispatcherTypeTestForward + * + * @assertion_ids: Servlet:JAVADOC:703; + * + * @test_Strategy: Create two Servlets TestServlet and SecondServlet; Client + * send a request to TestServlet; Forward to SecondServlet call + * ServletRequest.getDispatcherType() verifies that DispatcherType.FORWARD is + * returned. + */ + @Test + public void getDispatcherTypeTestForward() throws Exception { + TEST_PROPS.setProperty(APITEST, "getDispatcherTypeTestForward"); + TEST_PROPS.setProperty(SEARCH_STRING, "DispatcherType=FORWARD"); + invoke(); + } + + /* + * @testName: getDispatcherTypeTestInclude + * + * @assertion_ids: Servlet:JAVADOC:703; + * + * @test_Strategy: Create two Servlets TestServlet and SecondServlet; Client + * send a request to TestServlet; Invoke SecondServlet using include call + * ServletRequest.getDispatcherType() verifies that DispatcherType.INCLUDE is + * returned. + */ + @Test + public void getDispatcherTypeTestInclude() throws Exception { + TEST_PROPS.setProperty(APITEST, "getDispatcherTypeTestInclude"); + TEST_PROPS.setProperty(SEARCH_STRING, "DispatcherType=INCLUDE"); + invoke(); + } + + /* + * @testName: getDispatcherTypeTestError + * + * @assertion_ids: Servlet:JAVADOC:703; + * + * @test_Strategy: Create a Servlet SecondServlet to handle 404 error; Client + * send a request to nowhereland; In SecondServlet, call + * ServletRequest.getDispatcherType() verifies that DispatcherType.ERROR is + * returned. + */ + @Test + public void getDispatcherTypeTestError() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/nowheretobefound/ HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "DispatcherType=ERROR"); + TEST_PROPS.setProperty(STATUS_CODE, NOT_FOUND); + invoke(); + } + + /* + * @testName: getDispatcherTypeTestAsync + * + * @assertion_ids: Servlet:JAVADOC:640; Servlet:JAVADOC:703; + * Servlet:JAVADOC:710; + * + * @test_Strategy: Create two Servlets AsyncTestServlet and AsyncTests, both + * supports async; Client send a request to AsyncTestServlet; StartAsync in + * AsyncTestServlet; Invoke AsyncTests using AsyncContext.dispatch(String) + * call ServletRequest.getDispatcherType() verifies that DispatcherType.ASYNC + * is returned. + */ + @Test + public void getDispatcherTypeTestAsync() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/AsyncTestServlet?testname=getDispatcherTypeTestAsync HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: asyncStartedTest1 + * + * @assertion_ids: Servlet:JAVADOC:707; Servlet:JAVADOC:710; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which supports async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet + * ServletRequest.startAsync(); call ServletRequest.isAsyncStarted() verifies + * that true is returned. + */ + @Test + public void asyncStartedTest1() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/AsyncTestServlet?testname=asyncStartedTest1 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "IsAsyncStarted=true"); + invoke(); + } + + /* + * @testName: asyncStartedTest2 + * + * @assertion_ids: Servlet:JAVADOC:707; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which supports async; + * Client send a request to AsyncTestServlet; call + * ServletRequest.isAsyncStarted() without start async mode verifies that + * false is returned. + */ + @Test + public void asyncStartedTest2() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/AsyncTestServlet?testname=asyncStartedTest2 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "IsAsyncStarted=false"); + invoke(); + } + + /* + * @testName: asyncStartedTest3 + * + * @assertion_ids: Servlet:JAVADOC:638; Servlet:JAVADOC:707; + * Servlet:JAVADOC:638; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which supports async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet + * ServletRequest.startAsync(); call ServletRequest.isAsyncStarted() after + * AsyncContext.complete() called verifies that true is returned before it + * dispatch return to the container + */ + @Test + public void asyncStartedTest3() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/AsyncTestServlet?testname=asyncStartedTest3 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "IsAsyncStarted=true"); + invoke(); + } + + /* + * @testName: asyncStartedTest4 + * + * @assertion_ids: Servlet:JAVADOC:640; Servlet:JAVADOC:707; + * + * @test_Strategy: Create two Servlets AsyncTestServlet and AsyncTests, both + * supports async; Client send a request to AsyncTestServlet; StartAsync in + * AsyncTestServlet; Invoke AsyncTests using AsyncContext.dispatch(String) + * call ServletRequest.isAsyncStarted() verifies that false is returned. + */ + @Test + public void asyncStartedTest4() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/AsyncTestServlet?testname=asyncStartedTest4 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "IsAsyncStarted=false"); + invoke(); + } + + /* + * @testName: isAsyncSupportedTest1 + * + * @assertion_ids: Servlet:JAVADOC:708; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which supports async; + * Client send a request to AsyncTestServlet; call + * ServletRequest.isAsyncSupported() verifies that true is returned. + */ + @Test + public void isAsyncSupportedTest1() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/AsyncTestServlet?testname=isAsyncSupportedTest HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "isAsyncSupported=true"); + invoke(); + } + + /* + * @testName: isAsyncSupportedTest2 + * + * @assertion_ids: Servlet:JAVADOC:708; + * + * @test_Strategy: Create a Servlet TestServlet which does not support async, + * Client send a request to TestServlet; call + * ServletRequest.isAsyncSupported() verifies that false is returned. + */ + @Test + public void isAsyncSupportedTest2() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/TestServlet?testname=isAsyncSupportedTest HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "isAsyncSupported=false"); + invoke(); + } + + /* + * @testName: startAsyncTest1 + * + * @assertion_ids: Servlet:JAVADOC:711; + * + * @test_Strategy: Create a Servlet TestServlet which does not support async, + * Client send a request to TestServlet; call ServletRequest.startAsyncTest() + * verifies that IllegalStateException is thrown. + */ + @Test + public void startAsyncTest1() throws Exception { + TEST_PROPS.setProperty(APITEST, "startAsyncTest"); + invoke(); + } + + /* + * @testName: startAsyncTest2 + * + * @assertion_ids: Servlet:JAVADOC:640; Servlet:JAVADOC:710; + * Servlet:JAVADOC:711; + * + * @test_Strategy: Create two Servlets AsyncTestServlet and AsyncTests, both + * supports async; Client send a request to AsyncTestServlet; StartAsync in + * AsyncTestServlet; Invoke AsyncTests using AsyncContext.dispatch(String) + * Call ServletRequest.startAsyncTest() outside of dispatch verifies that + * IllegalStateException is thrown. + */ + @Test + public void startAsyncTest2() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/AsyncTestServlet?testname=startAsyncTest HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "IllegalStateException thrown"); + invoke(); + } + + /* + * @testName: getAsyncContextTest + * + * @assertion_ids: Servlet:JAVADOC:638; Servlet:JAVADOC:701; + * Servlet:JAVADOC:710; + * + * @test_Strategy: Create a Servlets AsyncTestServlet which supports async; + * Client send a request to AsyncTestServlet; Start Async in AsyncTestServlet; + * Call ServletRequest.getAsyncContext() verifies it works. + */ + @Test + public void getAsyncContextTest() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/AsyncTestServlet?testname=getAsyncContextTest HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Test PASSED"); + invoke(); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest30/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest30/build.xml new file mode 100644 index 0000000000..1f40870f36 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest30/build.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest30/servlet_js_servletrequest30_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest30/servlet_js_servletrequest30_web.xml new file mode 100644 index 0000000000..ef04e5a584 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequest30/servlet_js_servletrequest30_web.xml @@ -0,0 +1,65 @@ + + + + + SerJaxSerServletRequest30 + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest30.TestServlet + + + AsyncTestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest30.AsyncTestServlet + true + + + AsyncTests + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest30.AsyncTests + true + + + SecondServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest30.SecondServlet + + + TestServlet + /TestServlet + + + AsyncTestServlet + /AsyncTestServlet + + + AsyncTests + /async/AsyncTests + + + SecondServlet + /forward/ForwardedServlet + /include/IncludedServlet + /error/ErrorServlet + + + 404 + /error/ErrorServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper/SetCharacterEncodingTest.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper/SetCharacterEncodingTest.java new file mode 100644 index 0000000000..f9c9cc9893 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper/SetCharacterEncodingTest.java @@ -0,0 +1,46 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper; + +import java.io.IOException; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletRequestWrapper; +import jakarta.servlet.ServletResponse; + +public class SetCharacterEncodingTest extends SetCharacterEncodingTestWrapper { + + public void init(ServletConfig servletConfig) throws ServletException { + super.init(servletConfig); + } + + // merely validate the default behavior of RequestWrapper -- delegates call + // to the ServletRequest object it wraps. + + public void service(ServletRequest servletRequest, + ServletResponse servletResponse) throws ServletException, IOException { + ServletRequestWrapper wrapper = new ServletRequestWrapper(servletRequest); + super.service(wrapper, servletResponse); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper/SetCharacterEncodingTestWrapper.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper/SetCharacterEncodingTestWrapper.java new file mode 100644 index 0000000000..da2b7eb062 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper/SetCharacterEncodingTestWrapper.java @@ -0,0 +1,46 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.RequestTests; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class SetCharacterEncodingTestWrapper extends GenericServlet { + + public void init(ServletConfig servletConfig) throws ServletException { + super.init(servletConfig); + } + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + RequestTests.setCharacterEncodingTest(pw, request, response); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper/SetCharacterEncodingUnsupportedEncodingExceptionTest.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper/SetCharacterEncodingUnsupportedEncodingExceptionTest.java new file mode 100644 index 0000000000..50c39d2fb5 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper/SetCharacterEncodingUnsupportedEncodingExceptionTest.java @@ -0,0 +1,45 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper; + +import java.io.IOException; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletRequestWrapper; +import jakarta.servlet.ServletResponse; + +public class SetCharacterEncodingUnsupportedEncodingExceptionTest + extends SetCharacterEncodingUnsupportedEncodingExceptionTestWrapper { + + public void init(ServletConfig servletConfig) throws ServletException { + super.init(servletConfig); + } + + // merely validate the default behavior of RequestWrapper -- delegates call + // to the ServletRequest object it wraps. + public void service(ServletRequest servletRequest, + ServletResponse servletResponse) throws ServletException, IOException { + ServletRequestWrapper wrapper = new ServletRequestWrapper(servletRequest); + super.service(wrapper, servletResponse); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper/SetCharacterEncodingUnsupportedEncodingExceptionTestWrapper.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper/SetCharacterEncodingUnsupportedEncodingExceptionTestWrapper.java new file mode 100644 index 0000000000..ff42230b72 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper/SetCharacterEncodingUnsupportedEncodingExceptionTestWrapper.java @@ -0,0 +1,43 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.RequestTests; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class SetCharacterEncodingUnsupportedEncodingExceptionTestWrapper + extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + RequestTests.setCharacterEncodingUnsupportedEncodingExceptionTest(pw, + request, response); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper/TestServlet.java new file mode 100644 index 0000000000..625cb742d5 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper/TestServlet.java @@ -0,0 +1,84 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper; + +import java.io.IOException; + +import com.sun.ts.tests.servlet.common.servlets.RequestTestServlet; +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletRequestWrapper; +import jakarta.servlet.ServletResponse; + +public class TestServlet + extends RequestTestServlet { + + public void init(ServletConfig servletConfig) throws ServletException { + super.init(servletConfig); + } + + // merely validate the default behavior of RequestWrapper -- delegates call + // to the ServletRequest object it wraps. + public void service(ServletRequest servletRequest, + ServletResponse servletResponse) throws ServletException, IOException { + ServletRequestWrapper wrapper = new ServletRequestWrapper(servletRequest); + super.service(wrapper, servletResponse); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper/URLClient.java new file mode 100644 index 0000000000..8cca8f5048 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper/URLClient.java @@ -0,0 +1,470 @@ +/* + * 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper; + +import com.sun.ts.tests.servlet.common.request.RequestClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends RequestClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_servletrequestwrapper_web.war").addAsLibraries(CommonServlets.getCommonServletsArchive()).addClasses(SetCharacterEncodingTest.class, SetCharacterEncodingTestWrapper.class, SetCharacterEncodingUnsupportedEncodingExceptionTest.class, SetCharacterEncodingUnsupportedEncodingExceptionTestWrapper.class, TestServlet.class).setWebXML(URLClient.class.getResource("servlet_js_servletrequestwrapper_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + /* Run test */ + /* + * @testName: requestWrapperConstructorTest + * + * @assertion_ids: Servlet:JAVADOC:31 + * + * @test_Strategy: Servlet calls wrapper constructor + */ + @Test + public void requestWrapperConstructorTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "requestWrapperConstructorTest"); + invoke(); + } + + /* + * @testName: requestWrapperGetRequestTest + * + * @assertion_ids: Servlet:JAVADOC:32 + * + * @test_Strategy: Servlet gets wrapped request object + */ + @Test + public void requestWrapperGetRequestTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "requestWrapperGetRequestTest"); + invoke(); + } + + /* + * @testName: requestWrapperSetRequestTest + * + * @assertion_ids: Servlet:JAVADOC:33 + * + * @test_Strategy: Servlet sets wrapped request object + */ + @Test + public void requestWrapperSetRequestTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "requestWrapperSetRequestTest"); + invoke(); + } + + /* + * @testName: requestWrapperSetRequestIllegalArgumentExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:34 + * + * @test_Strategy: Servlet sets wrapped request object + */ + @Test + public void requestWrapperSetRequestIllegalArgumentExceptionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "requestWrapperSetRequestIllegalArgumentExceptionTest"); + invoke(); + } + + /* + * @testName: getAttributeNamesTest + * + * @assertion_ids: Servlet:JAVADOC:36 + * + * @test_Strategy: Servlet wraps the request. Servlet then sets some + * attributes and verifies they can be retrieved. + */ + /* + * @testName: getAttributeTest + * + * @assertion_ids: Servlet:JAVADOC:35 + * + * @test_Strategy: Servlet wraps the request. Servlet then sets an attribute + * and retrieves it. + * + */ + /* + * @testName: getCharacterEncodingTest + * + * @assertion_ids: Servlet:JAVADOC:37 + * + * @test_Strategy: Client sets an encoding. Servlet wraps the request. Servlet + * then tries to retrieve it. + */ + /* + * @testName: getContentLengthTest + * + * @assertion_ids: Servlet:JAVADOC:40 + * + * @test_Strategy: Servlet wraps the request. Servlet then compares this + * length to the actual length of the content body read in using + * getInputStream + * + */ + /* + * @testName: getContentTypeTest + * + * @assertion_ids: Servlet:JAVADOC:41; Servlet:SPEC:34; + * + * @test_Strategy: Client sets the content type and servlet reads it. + * + */ + /* + * @testName: getInputStreamTest + * + * @assertion_ids: Servlet:JAVADOC:42 + * + * @test_Strategy: Servlet wraps the request. Servlet then tries to read the + * input stream. + */ + /* + * @testName: getLocaleTest + * + * @assertion_ids: Servlet:JAVADOC:58 + * + * @test_Strategy: Client specifics a locale, Servlet wraps the request. + * Servlet then verifies it. + */ + /* + * @testName: getLocalesTest + * + * @assertion_ids: Servlet:JAVADOC:59 + * + * @test_Strategy: Client specifics 2 locales.Servlet wraps the request. + * Servlet then verifies it. + */ + /* + * @testName: getParameterMapTest + * + * @assertion_ids: Servlet:JAVADOC:45 + * + * @test_Strategy: Client sets several parameters.Servlet wraps the request. + * Servlet then attempts to access them. + */ + /* + * @testName: getParameterNamesTest + * + * @assertion_ids: Servlet:JAVADOC:46 + * + * @test_Strategy: Client sets several parameters.Servlet wraps the request. + * Servlet then attempts to access them. + */ + /* + * @testName: getParameterTest + * + * @assertion_ids: Servlet:JAVADOC:44 + * + * @test_Strategy: Client sets a parameter.Servlet wraps the request. Servlet + * then retrieves parameter. + */ + /* + * @testName: getParameterValuesTest + * + * @assertion_ids: Servlet:JAVADOC:47 + * + * @test_Strategy: Client sets a parameter which has 2 values.Servlet wraps + * the request. Servlet then verifies both values. + */ + /* + * @testName: getProtocolTest + * + * @assertion_ids: Servlet:JAVADOC:48 + * + * @test_Strategy: Servlet wraps the request. Servlet then verifies the + * protocol used by the client + */ + /* + * @testName: getReaderTest + * + * @assertion_ids: Servlet:JAVADOC:52 + * + * @test_Strategy: Client sets some content.Servlet wraps the request. Servlet + * then reads the content + */ + /* + * @testName: getRemoteAddrTest + * + * @assertion_ids: Servlet:JAVADOC:54 + * + * @test_Strategy: Servlet wraps the request. Servlet then reads and verifies + * where the request originated + */ + /* + * @testName: getRemoteHostTest + * + * @assertion_ids: Servlet:JAVADOC:55 + * + * @test_Strategy: Servlet wraps the request. Servlet then reads and verifies + * where the request originated + */ + /* + * @testName: getRequestDispatcherTest + * + * @assertion_ids: Servlet:JAVADOC:61 + * + * @test_Strategy: Servlet wraps the request. Servlet then tries to get a + * dispatcher + */ + /* + * @testName: getSchemeTest + * + * @assertion_ids: Servlet:JAVADOC:49 + * + * @test_Strategy: Servlet wraps the request. Servlet then verifies the scheme + * of the url used in the request + */ + /* + * @testName: getServerNameTest + * + * @assertion_ids: Servlet:JAVADOC:50 + * + * @test_Strategy: Servlet wraps the request. Servlet then verifies the + * destination of the request + */ + /* + * @testName: getServerPortTest + * + * @assertion_ids: Servlet:JAVADOC:51 + * + * @test_Strategy: Servlet wraps the request. Servlet then verifies the + * destination port of the request + */ + /* + * @testName: isSecureTest + * + * @assertion_ids: Servlet:JAVADOC:60 + * + * @test_Strategy: Servlet wraps the request. Servlet then verifies the + * isSecure method for the non-secure case. + */ + /* + * @testName: removeAttributeTest + * + * @assertion_ids: Servlet:JAVADOC:57 + * + * @test_Strategy: Servlet wraps the request. Servlet then adds then removes + * an attribute, then verifies it was removed. + */ + /* + * @testName: setAttributeTest + * + * @assertion_ids: Servlet:JAVADOC:56 + * + * @test_Strategy: Servlet wraps the request. Servlet then adds an attribute, + * then verifies it was added + */ + /* + * @testName: setCharacterEncodingUnsupportedEncodingExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:39 + * + * @test_Strategy: Servlet wraps the request. Servlet then tries to set an + * invalid encoding. + * + */ + /* + * @testName: setCharacterEncodingTest + * + * @assertion_ids: Servlet:JAVADOC:38 + * + * @test_Strategy: Servlet wraps the request. Servlet then sets a new encoding + * and tries to retrieve it. verifies that the new encoding gets set. + */ + /* + * @testName: setCharacterEncodingTest1 + * + * @assertion_ids: Servlet:JAVADOC:38; Servlet:JAVADOC:37; Servlet:SPEC:28; + * Servlet:SPEC:213; + * + * @test_Strategy: Servlet wraps the request; ServletRequestWrapper calls + * getReader(); then sets a new encoding and tries to retrieve it. verifies + * that the new encoding is ignored. + */ + /* + * @testName: getLocalNameTest + * + * @assertion_ids: Servlet:JAVADOC:633 + * + * @test_Strategy: Servlet wraps the request. Servlet then verify + * getLocalName(); + */ + /* + * @testName: getLocalPortTest + * + * @assertion_ids: Servlet:JAVADOC:636 + * + * @test_Strategy: Servlet wraps the request. Servlet then verify + * getLocalPort(); + */ + @Test() + public void getAttributeNamesTest() throws Exception { + super.getAttributeNamesTest(); + } + + @Test() + public void getAttributeTest() throws Exception { + super.getAttributeTest(); + } + + @Test() + public void getCharacterEncodingTest() throws Exception { + super.getCharacterEncodingTest(); + } + + @Test() + public void getContentLengthTest() throws Exception { + super.getContentLengthTest(); + } + + @Test() + public void getContentTypeTest() throws Exception { + super.getContentTypeTest(); + } + + @Test() + public void getInputStreamTest() throws Exception { + super.getInputStreamTest(); + } + + @Test() + public void getLocalNameTest() throws Exception { + super.getLocalNameTest(); + } + + @Test() + public void getLocalPortTest() throws Exception { + super.getLocalPortTest(); + } + + @Test() + public void getLocaleTest() throws Exception { + super.getLocaleTest(); + } + + @Test() + public void getLocalesTest() throws Exception { + super.getLocalesTest(); + } + + @Test() + public void getParameterMapTest() throws Exception { + super.getParameterMapTest(); + } + + @Test() + public void getParameterNamesTest() throws Exception { + super.getParameterNamesTest(); + } + + @Test() + public void getParameterTest() throws Exception { + super.getParameterTest(); + } + + @Test() + public void getParameterValuesTest() throws Exception { + super.getParameterValuesTest(); + } + + @Test() + public void getProtocolTest() throws Exception { + super.getProtocolTest(); + } + + @Test() + public void getReaderTest() throws Exception { + super.getReaderTest(); + } + + @Test() + public void getRemoteAddrTest() throws Exception { + super.getRemoteAddrTest(); + } + + @Test() + public void getRemoteHostTest() throws Exception { + super.getRemoteHostTest(); + } + + @Test() + public void getRequestDispatcherTest() throws Exception { + super.getRequestDispatcherTest(); + } + + @Test() + public void getSchemeTest() throws Exception { + super.getSchemeTest(); + } + + @Test() + public void getServerNameTest() throws Exception { + super.getServerNameTest(); + } + + @Test() + public void getServerPortTest() throws Exception { + super.getServerPortTest(); + } + + @Test() + public void isSecureTest() throws Exception { + super.isSecureTest(); + } + + @Test() + public void removeAttributeTest() throws Exception { + super.removeAttributeTest(); + } + + @Test() + public void setAttributeTest() throws Exception { + super.setAttributeTest(); + } + + @Test() + public void setCharacterEncodingTest() throws Exception { + super.setCharacterEncodingTest(); + } + + @Test() + public void setCharacterEncodingTest1() throws Exception { + super.setCharacterEncodingTest1(); + } + + @Test() + public void setCharacterEncodingUnsupportedEncodingExceptionTest() throws Exception { + super.setCharacterEncodingUnsupportedEncodingExceptionTest(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper/build.xml new file mode 100644 index 0000000000..c7c3ebe097 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper/build.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper/servlet_js_servletrequestwrapper_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper/servlet_js_servletrequestwrapper_web.xml new file mode 100644 index 0000000000..565a8c1bf4 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper/servlet_js_servletrequestwrapper_web.xml @@ -0,0 +1,65 @@ + + + + + SerJaxSerServletRequestWrapper + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper.TestServlet + + + setCharacterEncodingUnsupportedEncodingExceptionTestWrapper + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper.SetCharacterEncodingUnsupportedEncodingExceptionTestWrapper + + + setCharacterEncodingUnsupportedEncodingExceptionTest + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper.SetCharacterEncodingUnsupportedEncodingExceptionTest + + + setCharacterEncodingTestWrapper + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper.SetCharacterEncodingTestWrapper + + + setCharacterEncodingTest + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper.SetCharacterEncodingTest + + + TestServlet + /TestServlet/* + + + setCharacterEncodingUnsupportedEncodingExceptionTestWrapper + /setCharacterEncodingUnsupportedEncodingExceptionTestWrapper + + + setCharacterEncodingUnsupportedEncodingExceptionTest + /setCharacterEncodingUnsupportedEncodingExceptionTest + + + setCharacterEncodingTestWrapper + /setCharacterEncodingTestWrapper + + + setCharacterEncodingTest + /setCharacterEncodingTest + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper30/AsyncTestServletWrapper.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper30/AsyncTestServletWrapper.java new file mode 100644 index 0000000000..143557f4f1 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper30/AsyncTestServletWrapper.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2009, 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper30; + +import java.io.IOException; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletRequestWrapper; +import jakarta.servlet.ServletResponse; + +public class AsyncTestServletWrapper extends + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest30.AsyncTestServlet { + + public void init(ServletConfig servletConfig) throws ServletException { + super.init(servletConfig); + } + + public void service(ServletRequest servletRequest, + ServletResponse servletResponse) throws ServletException, IOException { + ServletRequestWrapper wrapper = new ServletRequestWrapper(servletRequest); + super.service(wrapper, servletResponse); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper30/ErrorServletWrapper.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper30/ErrorServletWrapper.java new file mode 100644 index 0000000000..47a580557e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper30/ErrorServletWrapper.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2009, 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:$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper30; + +import java.io.IOException; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletRequestWrapper; +import jakarta.servlet.ServletResponse; + +public class ErrorServletWrapper extends + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest30.SecondServlet { + + public void init(ServletConfig servletConfig) throws ServletException { + super.init(servletConfig); + } + + public void service(ServletRequest servletRequest, + ServletResponse servletResponse) throws ServletException, IOException { + ServletRequestWrapper wrapper = new ServletRequestWrapper(servletRequest); + super.service(wrapper, servletResponse); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper30/TestServletWrapper.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper30/TestServletWrapper.java new file mode 100644 index 0000000000..3cd1640dd8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper30/TestServletWrapper.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2009, 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper30; + +import java.io.IOException; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletRequestWrapper; +import jakarta.servlet.ServletResponse; + +public class TestServletWrapper extends + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest30.TestServlet { + + public void init(ServletConfig servletConfig) throws ServletException { + super.init(servletConfig); + } + + public void service(ServletRequest servletRequest, + ServletResponse servletResponse) throws ServletException, IOException { + ServletRequestWrapper wrapper = new ServletRequestWrapper(servletRequest); + super.service(wrapper, servletResponse); + } + + public void getServletContext(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + ServletContext actual = request.getServletContext(); + ServletContext expected = this.getServletConfig().getServletContext(); + + if (actual != expected) { + response.getWriter().println( + "getServletContext() returned inconsistent result. Test FAILED."); + } else { + response.getWriter().println( + "getServletContext() returned inconsistent result. Test ED."); + } + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper30/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper30/URLClient.java new file mode 100644 index 0000000000..f90c56c2ce --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper30/URLClient.java @@ -0,0 +1,342 @@ +/* + * Copyright (c) 2009, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper30; + +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest30.TestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest30.AsyncTestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest30.AsyncTests; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest30.SecondServlet; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_servletrequestwrapper30_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(AsyncTestServletWrapper.class, ErrorServletWrapper.class, TestServletWrapper.class, + TestServlet.class, AsyncTestServlet.class, AsyncTests.class, SecondServlet.class) + .setWebXML(URLClient.class.getResource("servlet_js_servletrequestwrapper30_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + /* + * @testName: getServletContextTest + * + * @assertion_ids: Servlet:JAVADOC:721; + * + * @test_Strategy: Create a ServletRequestWrapper that wrap another servlet; + * calls ServletRequestWrapper.getServletContext(); verifies that returned + * ServletContext instance is consistent with the one stored in + * ServletConfigs. + */ + @Test + public void getServletContextTest() throws Exception { + setServletName("TestServletWrapper"); + TEST_PROPS.setProperty(APITEST, "getServletContextTest"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "TEST FAILED"); + TEST_PROPS.setProperty(SEARCH_STRING, "Test PASSED"); + invoke(); + } + + /* + * @testName: getDispatcherTypeTestRequest + * + * @assertion_ids: Servlet:JAVADOC:718; + * + * @test_Strategy: Create a ServletRequestWrapper that wraps TestServlet; + * Client send a request the ServletRequestWrapper; call + * ServletRequestWrapper.getDispatcherType() verifies that + * DispatcherType.REQUEST is returned. + */ + @Test + public void getDispatcherTypeTestRequest() throws Exception { + setServletName("TestServletWrapper"); + TEST_PROPS.setProperty(APITEST, "getDispatcherTypeTestRequest"); + TEST_PROPS.setProperty(SEARCH_STRING, "DispatcherType=REQUEST"); + invoke(); + } + + /* + * @testName: getDispatcherTypeTestForward + * + * @assertion_ids: Servlet:JAVADOC:718; + * + * @test_Strategy: Create a ServletRequestWrapper that wraps TestServlet; + * Client send a request the ServletRequestWrapper; Forward to SecondServlet + * call ServletRequestWrapper.getDispatcherType() verifies that + * DispatcherType.FORWARD is returned. + */ + @Test + public void getDispatcherTypeTestForward() throws Exception { + setServletName("TestServletWrapper"); + TEST_PROPS.setProperty(APITEST, "getDispatcherTypeTestForward"); + TEST_PROPS.setProperty(SEARCH_STRING, "DispatcherType=FORWARD"); + invoke(); + } + + /* + * @testName: getDispatcherTypeTestInclude + * + * @assertion_ids: Servlet:JAVADOC:718; + * + * @test_Strategy: Create a ServletRequestWrapper that wraps TestServlet; + * Client send a request the ServletRequestWrapper; Include to SecondServlet + * call ServletRequestWrapper.getDispatcherType() verifies that + * DispatcherType.INCLUDE is returned. + */ + @Test + public void getDispatcherTypeTestInclude() throws Exception { + setServletName("TestServletWrapper"); + TEST_PROPS.setProperty(APITEST, "getDispatcherTypeTestInclude"); + TEST_PROPS.setProperty(SEARCH_STRING, "DispatcherType=INCLUDE"); + invoke(); + } + + /* + * @testName: getDispatcherTypeTestError + * + * @assertion_ids: Servlet:JAVADOC:718; + * + * @test_Strategy: Create a ServletRequestWrapper that wraps SecondServlet; + * Maps 404 to the ServletRequestWrapper; Client send a request to + * nowhereland; In SecondServlet, call + * ServletRequestWrapper.getDispatcherType() verifies that + * DispatcherType.ERROR is returned. + */ + @Test + public void getDispatcherTypeTestError() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/nowheretobefound/ HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "DispatcherType=ERROR"); + TEST_PROPS.setProperty(STATUS_CODE, NOT_FOUND); + invoke(); + } + + /* + * @testName: getDispatcherTypeTestAsync + * + * @assertion_ids: Servlet:JAVADOC:640; Servlet:JAVADOC:703; + * Servlet:JAVADOC:710; + * + * @test_Strategy: Create three Servlets AsyncTestServletWrapper, + * AsyncTestServlet and AsyncTests, all support async; AsyncTestServletWrapper + * wraps AsyncTestServlet; Client send a request to AsyncTestServletWrapper; + * StartAsync in AsyncTestServlet; Invoke AsyncTests using + * AsyncContext.dispatch(String) call + * ServletRequestWrapper.getDispatcherType() verifies that + * DispatcherType.ASYNC is returned. + */ + @Test + public void getDispatcherTypeTestAsync() throws Exception { + setServletName("AsyncTestServletWrapper"); + TEST_PROPS.setProperty(APITEST, "getDispatcherTypeTestAsync"); + TEST_PROPS.setProperty(SEARCH_STRING, "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: asyncStartedTest1 + * + * @assertion_ids: Servlet:JAVADOC:722; Servlet:JAVADOC:727; + * + * @test_Strategy: Create three Servlets AsyncTestServletWrapper, + * AsyncTestServlet and AsyncTests, all support async; AsyncTestServletWrapper + * wraps AsyncTestServlet; Client send a request to AsyncTestServletWrapper; + * StartAsync in AsyncTestServlet ServletRequestWrapper.startAsync(); call + * ServletRequestWrapper.isAsyncStarted() verifies that true is returned. + */ + @Test + public void asyncStartedTest1() throws Exception { + setServletName("AsyncTestServletWrapper"); + TEST_PROPS.setProperty(APITEST, "asyncStartedTest1"); + TEST_PROPS.setProperty(SEARCH_STRING, "IsAsyncStarted=true"); + invoke(); + } + + /* + * @testName: asyncStartedTest2 + * + * @assertion_ids: Servlet:JAVADOC:722; + * + * @test_Strategy: Create three Servlets AsyncTestServletWrapper, + * AsyncTestServlet and AsyncTests, all support async; AsyncTestServletWrapper + * wraps AsyncTestServlet; Client send a request to AsyncTestServletWrapper; + * call ServletRequestWrapper.isAsyncStarted() without start async mode + * verifies that false is returned. + */ + @Test + public void asyncStartedTest2() throws Exception { + setServletName("AsyncTestServletWrapper"); + TEST_PROPS.setProperty(APITEST, "asyncStartedTest2"); + TEST_PROPS.setProperty(SEARCH_STRING, "IsAsyncStarted=false"); + invoke(); + } + + /* + * @testName: asyncStartedTest3 + * + * @assertion_ids: Servlet:JAVADOC:638; Servlet:JAVADOC:722; + * Servlet:JAVADOC:727; + * + * @test_Strategy: Create three Servlets AsyncTestServletWrapper, + * AsyncTestServlet and AsyncTests, all support async; AsyncTestServletWrapper + * wraps AsyncTestServlet; Client send a request to AsyncTestServletWrapper; + * StartAsync in AsyncTestServlet ServletRequestWrapper.startAsync(); call + * ServletRequestWrapper.isAsyncStarted() after AsyncContext.complete() called + * verifies that true is returned before it dispatch return to the container + */ + @Test + public void asyncStartedTest3() throws Exception { + setServletName("AsyncTestServletWrapper"); + TEST_PROPS.setProperty(APITEST, "asyncStartedTest3"); + TEST_PROPS.setProperty(SEARCH_STRING, "IsAsyncStarted=true"); + invoke(); + } + + /* + * @testName: asyncStartedTest4 + * + * @assertion_ids: Servlet:JAVADOC:640; Servlet:JAVADOC:722; + * Servlet:JAVADOC:727; + * + * @test_Strategy: Create three Servlets AsyncTestServletWrapper, + * AsyncTestServlet and AsyncTests, all support async; AsyncTestServletWrapper + * wraps AsyncTestServlet; Client send a request to AsyncTestServletWrapper; + * StartAsync in AsyncTestServlet ServletRequestWrapper.startAsync(); Invoke + * AsyncTests using AsyncContext.dispatch(String) call + * ServletRequestWrapper.isAsyncStarted() verifies that false is returned. + */ + @Test + public void asyncStartedTest4() throws Exception { + setServletName("AsyncTestServletWrapper"); + TEST_PROPS.setProperty(APITEST, "asyncStartedTest4"); + TEST_PROPS.setProperty(SEARCH_STRING, "IsAsyncStarted=false"); + invoke(); + } + + /* + * @testName: isAsyncSupportedTest1 + * + * @assertion_ids: Servlet:JAVADOC:723; + * + * @test_Strategy: Create two Servlets AsyncTestServletWrapper, + * AsyncTestServlet all support async; AsyncTestServletWrapper wraps + * AsyncTestServlet; Client send a request to AsyncTestServletWrapper; call + * ServletRequestWrapper.isAsyncSupported() verifies that true is returned. + */ + @Test + public void isAsyncSupportedTest1() throws Exception { + setServletName("AsyncTestServletWrapper"); + TEST_PROPS.setProperty(APITEST, "isAsyncSupportedTest"); + TEST_PROPS.setProperty(SEARCH_STRING, "isAsyncSupported=true"); + invoke(); + } + + /* + * @testName: isAsyncSupportedTest2 + * + * @assertion_ids: Servlet:JAVADOC:723; + * + * @test_Strategy: Create two Servlets TestServletWrapper, TestServlet all + * does not support async; TestServletWrapper wraps TestServlet; Client send a + * request to TestServletWrapper; call + * ServletRequestWrapper.isAsyncSupported() verifies that false is returned. + */ + @Test + public void isAsyncSupportedTest2() throws Exception { + setServletName("TestServletWrapper"); + TEST_PROPS.setProperty(APITEST, "isAsyncSupportedTest"); + TEST_PROPS.setProperty(SEARCH_STRING, "isAsyncSupported=false"); + invoke(); + } + + /* + * @testName: startAsyncTest1 + * + * @assertion_ids: Servlet:JAVADOC:728; + * + * @test_Strategy: Create two Servlets TestServletWrapper, TestServlet all + * does not support async; TestServletWrapper wraps TestServlet; Client send a + * request to TestServletWrapper; call ServletRequestWrapper.startAsyncTest() + * verifies that IllegalStateException is thrown. + */ + @Test + public void startAsyncTest1() throws Exception { + setServletName("TestServletWrapper"); + TEST_PROPS.setProperty(APITEST, "startAsyncTest"); + invoke(); + } + + /* + * @testName: startAsyncTest2 + * + * @assertion_ids: Servlet:JAVADOC:640; Servlet:JAVADOC:722; + * Servlet:JAVADOC:727; Servlet:JAVADOC:728; + * + * @test_Strategy: Create three Servlets AsyncTestServletWrapper, + * AsyncTestServlet, AsyncTest all support async; AsyncTestServletWrapper + * wraps AsyncTestServlet; Client send a request to AsyncTestServletWrapper; + * Start Async in AsyncTestServlet; Invoke AsyncTests using + * AsyncContext.dispatch(String) Call ServletRequestWrapper.startAsyncTest() + * outside of dispatch verifies that IllegalStateException is thrown. + */ + @Test + public void startAsyncTest2() throws Exception { + setServletName("AsyncTestServletWrapper"); + TEST_PROPS.setProperty(APITEST, "startAsyncTest"); + TEST_PROPS.setProperty(SEARCH_STRING, "IllegalStateException thrown"); + invoke(); + } + + /* + * @testName: getAsyncContextTest + * + * @assertion_ids: Servlet:JAVADOC:638; Servlet:JAVADOC:716; + * Servlet:JAVADOC:727; + * + * @test_Strategy: Create two Servlets AsyncTestServletWrapper, + * AsyncTestServlet all support async; AsyncTestServletWrapper wraps + * AsyncTestServlet; Client send a request to AsyncTestServletWrapper; Start + * Async in AsyncTestServlet; call ServletRequestWrapper.getAsyncContext() + * verifies it works. + */ + @Test + public void getAsyncContextTest() throws Exception { + setServletName("AsyncTestServletWrapper"); + TEST_PROPS.setProperty(APITEST, "getAsyncContextTest"); + TEST_PROPS.setProperty(SEARCH_STRING, "Test PASSED"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper30/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper30/build.xml new file mode 100644 index 0000000000..c27dc8379e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper30/build.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper30/servlet_js_servletrequestwrapper30_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper30/servlet_js_servletrequestwrapper30_web.xml new file mode 100644 index 0000000000..391342b81f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper30/servlet_js_servletrequestwrapper30_web.xml @@ -0,0 +1,89 @@ + + + + + SerJaxSerServletRequest30 + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest30.TestServlet + + + AsyncTestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest30.AsyncTestServlet + true + + + AsyncTests + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest30.AsyncTests + true + + + SecondServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest30.SecondServlet + + + TestServletWrapper + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper30.TestServletWrapper + + + AsyncTestServletWrapper + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper30.AsyncTestServletWrapper + true + + + ErrorServletWrapper + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper30.ErrorServletWrapper + + + TestServlet + /TestServlet + + + AsyncTestServlet + /AsyncTestServlet + + + AsyncTests + /async/AsyncTests + + + SecondServlet + /forward/ForwardedServlet + /include/IncludedServlet + + + TestServletWrapper + /TestServletWrapper + + + AsyncTestServletWrapper + /AsyncTestServletWrapper + + + ErrorServletWrapper + /error/ErrorServletWrapper + + + 404 + /error/ErrorServletWrapper + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper30x/IsWrapperForTest.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper30x/IsWrapperForTest.java new file mode 100644 index 0000000000..263e895d37 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper30x/IsWrapperForTest.java @@ -0,0 +1,153 @@ +/* + * Copyright (c) 2011, 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper30x; + +import java.io.IOException; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletRequestWrapper; +import jakarta.servlet.ServletResponse; + +public class IsWrapperForTest extends GenericServlet { + + public void init(ServletConfig servletConfig) throws ServletException { + super.init(servletConfig); + } + + public void service(ServletRequest req, ServletResponse response) + throws ServletException, IOException { + Boolean pass = true; + ServletRequestWrapper reqWrapper1 = new TCKServletRequestWrapper(req); + ServletRequestWrapper reqWrapper2 = new TCKServletRequestWrapper( + reqWrapper1); + ServletRequestWrapper reqWrapper3 = new TCKServletRequestWrapper( + reqWrapper2); + TCKServletRequestsubWrapper myReqWrapper = new TCKServletRequestsubWrapper( + req); + + if (!reqWrapper3.isWrapperFor(reqWrapper1)) { + pass = false; + response.getWriter() + .println("Test Failed: reqWrapper3.isWrapperFor(reqWrapper1)"); + } + + if (!reqWrapper3.isWrapperFor(reqWrapper2)) { + pass = false; + response.getWriter() + .println("Test Failed: reqWrapper3.isWrapperFor(reqWrapper2)"); + } + + if (!reqWrapper3.isWrapperFor(TCKServletRequestWrapper.class)) { + pass = false; + response.getWriter().println( + "Test Failed: reqWrapper3.isWrapperFor(TCKServletRequestWrapper.class)"); + } + + if (reqWrapper3.isWrapperFor(myReqWrapper)) { + pass = false; + response.getWriter() + .println("Test Failed: reqWrapper3.isWrapperFor(myReqWrapper)"); + } + + if (reqWrapper3.isWrapperFor(TCKServletRequestsubWrapper.class)) { + pass = false; + response.getWriter().println( + "Test Failed: reqWrapper3.isWrapperFor(TCKServletRequestsubWrapper.class)"); + } + + if (!reqWrapper2.isWrapperFor(reqWrapper1)) { + pass = false; + response.getWriter() + .println("Test Failed: reqWrapper2.isWrapperFor(reqWrapper1)"); + } + + if (!reqWrapper2.isWrapperFor(TCKServletRequestWrapper.class)) { + pass = false; + response.getWriter().println( + "Test Failed: reqWrapper2.isWrapperFor(TCKServletRequestWrapper.class)"); + } + + if (reqWrapper2.isWrapperFor(myReqWrapper)) { + pass = false; + response.getWriter() + .println("Test Failed: reqWrapper2.isWrapperFor(myReqWrapper)"); + } + + if (reqWrapper2.isWrapperFor(TCKServletRequestsubWrapper.class)) { + pass = false; + response.getWriter().println( + "Test Failed: reqWrapper2.isWrapperFor(TCKServletRequestsubWrapper.class)"); + } + + if (reqWrapper1.isWrapperFor(TCKServletRequestWrapper.class)) { + pass = false; + response.getWriter().println( + "Test Failed: reqWrapper1.isWrapperFor(TCKServletRequestWrapper.class)"); + } + + if (reqWrapper1.isWrapperFor(myReqWrapper)) { + pass = false; + response.getWriter() + .println("Test Failed: reqWrapper1.isWrapperFor(myReqWrapper)"); + } + + if (reqWrapper1.isWrapperFor(TCKServletRequestsubWrapper.class)) { + pass = false; + response.getWriter().println( + "Test Failed: reqWrapper1.isWrapperFor(TCKServletRequestsubWrapper.class)"); + } + + if (myReqWrapper.isWrapperFor(TCKServletRequestWrapper.class)) { + pass = false; + response.getWriter().println( + "Test Failed: myReqWrapper.isWrapperFor(TCKServletRequestWrapper.class)"); + } + + if (myReqWrapper.isWrapperFor(reqWrapper1)) { + pass = false; + response.getWriter() + .println("Test Failed: myReqWrapper.isWrapperFor(reqWrapper1)"); + } + + if (myReqWrapper.isWrapperFor(reqWrapper2)) { + pass = false; + response.getWriter() + .println("Test Failed: myReqWrapper.isWrapperFor(reqWrapper2)"); + } + + if (myReqWrapper.isWrapperFor(reqWrapper3)) { + pass = false; + response.getWriter() + .println("Test Failed: myReqWrapper.isWrapperFor(reqWrapper3)"); + } + + if (myReqWrapper.isWrapperFor(TCKServletRequestsubWrapper.class)) { + pass = false; + response.getWriter().println( + "Test Failed: myReqWrapper.isWrapperFor(TCKServletRequestsubWrapper.class)"); + } + + if (!pass) { + response.getWriter().println("Test Failed."); + } else { + response.getWriter().println("Test Passed."); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper30x/TCKServletRequestWrapper.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper30x/TCKServletRequestWrapper.java new file mode 100644 index 0000000000..8bf3b21648 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper30x/TCKServletRequestWrapper.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2011, 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper30x; + +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletRequestWrapper; + +public class TCKServletRequestWrapper extends ServletRequestWrapper { + + public TCKServletRequestWrapper(ServletRequest req) { + super(req); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper30x/TCKServletRequestsubWrapper.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper30x/TCKServletRequestsubWrapper.java new file mode 100644 index 0000000000..70ed7841f9 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper30x/TCKServletRequestsubWrapper.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2011, 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper30x; + +import jakarta.servlet.ServletRequest; + +public class TCKServletRequestsubWrapper extends TCKServletRequestWrapper { + + public TCKServletRequestsubWrapper(ServletRequest req) { + super(req); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper30x/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper30x/URLClient.java new file mode 100644 index 0000000000..bd90e69ae2 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper30x/URLClient.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2011, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper30x; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_servletrequestwrapper30x_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(IsWrapperForTest.class, TCKServletRequestsubWrapper.class, TCKServletRequestWrapper.class) + .setWebXML(URLClient.class.getResource("servlet_js_servletrequestwrapper30x_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + /* + * @testName: isWrapperForTest + * + * @assertion_ids: Servlet:JAVADOC:724; Servlet:JAVADOC:725; + * + * @test_Strategy: Create a Servlets isWrapperForTest; In the servlet, wrap + * the Resquest a few time and in different ways; verifies the following + * works: - jakarta.servlet.ServletRequestWrapper.isWrapperFor(ServletRequest) - + * jakarta.servlet.ServletRequestWrapper.isWrapperFor(Class) + */ + @Test + public void isWrapperForTest() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/IsWrapperForTest HTTP/1.1"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "Test Failed"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper30x/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper30x/build.xml new file mode 100644 index 0000000000..12259749cb --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper30x/build.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper30x/servlet_js_servletrequestwrapper30x_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper30x/servlet_js_servletrequestwrapper30x_web.xml new file mode 100644 index 0000000000..3abcc785de --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletrequestwrapper30x/servlet_js_servletrequestwrapper30x_web.xml @@ -0,0 +1,33 @@ + + + + + SerJaxSerServletRequest30x + + IsWrapperForTest + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper30x.IsWrapperForTest + + + IsWrapperForTest + /IsWrapperForTest + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponse/SetCharacterEncodingTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponse/SetCharacterEncodingTestServlet.java new file mode 100644 index 0000000000..7e65a7c734 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponse/SetCharacterEncodingTestServlet.java @@ -0,0 +1,77 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletresponse; + +import java.io.IOException; + +import com.sun.ts.tests.servlet.common.response.ResponseTests; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class SetCharacterEncodingTestServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + ResponseTests.setCharacterEncodingTest(request, response); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponse/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponse/URLClient.java new file mode 100644 index 0000000000..a04ba35b2b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponse/URLClient.java @@ -0,0 +1,462 @@ +/* + * 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletresponse; + +import com.sun.ts.tests.servlet.common.servlets.GenericCheckTestResultServlet; +import com.sun.ts.tests.servlet.common.response.ResponseClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends ResponseClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_servletresponse_web.war").addAsLibraries(CommonServlets.getCommonServletsArchive()).addClasses(SetCharacterEncodingTestServlet.class, GenericCheckTestResultServlet.class).setWebXML(URLClient.class.getResource("servlet_js_servletresponse_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + /* Run test */ + /* + * @testName: flushBufferTest + * + * @assertion_ids: Servlet:JAVADOC:158 + * + * @test_Strategy: Servlet writes data in the buffer and flushes it + */ + /* + * @testName: getBufferSizeTest + * + * @assertion_ids: Servlet:JAVADOC:156;Servlet:JAVADOC:157 + * + * @test_Strategy: Servlet flushes buffer and verifies the size of the buffer + */ + /* + * @testName: getLocaleDefaultTest + * + * @assertion_ids: Servlet:JAVADOC:164; + * + * @test_Strategy: Validate that if setLocale() is not called on the response, + * the getLocale() will return the default locale of the VM the container is + * running in. + */ + /* + * @testName: getLocaleTest + * + * @assertion_ids: Servlet:JAVADOC:166 + * + * @test_Strategy: Servlet set Locale and then verifies it + * + */ + /* + * @testName: getOutputStreamFlushTest + * + * @assertion_ids: Servlet:JAVADOC:140 + * + * @test_Strategy: Servlet gets an output stream, writes to it, flushes it + * then checks that the response was committed + */ + /* + * @testName: getOutputStreamTest + * + * @assertion_ids: Servlet:JAVADOC:141 + * + * @test_Strategy: Servlet gets an output stream and writes to it. + */ + /* + * @testName: getOutputStreamIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:143 + * + * @test_Strategy: Servlet tries to get an stream object after calling + * getWriter + */ + /* + * @testName: getWriterTest + * + * @assertion_ids: Servlet:JAVADOC:144; Servlet:JAVADOC:151.3; + * + * @test_Strategy: Client sets the content type. Servlet then gets a Writer + * object, then sets content type and writes data. Verify that content type + * didn't get set by servlet + */ + /* + * @testName: getWriterFlushTest + * + * @assertion_ids: Servlet:JAVADOC:146 + * + * @test_Strategy: Servlet gets a Writer object, writes data then flushes, + * then verifies response was committed + */ + /* + * @testName: getWriterAfterTest + * + * @assertion_ids: Servlet:JAVADOC:145; Servlet:JAVADOC:151.3; + * + * @test_Strategy: Client sets the content type. Servlet then gets a Writer + * object, then sets content type and writes data. Verify that content type + * did get set by servlet + */ + /* + * @testName: getWriterIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:149; + * + * @test_Strategy: Servlet tries to get a Writer object after calling + * getOutputStream + */ + /* + * @testName: isCommittedTest + * + * @assertion_ids: Servlet:JAVADOC:161 + * + * @test_Strategy: Servlet checks before and after response is flushed + * + */ + /* + * @testName: resetBufferTest + * + * @assertion_ids: Servlet:JAVADOC:160; Servlet:SPEC:31; + * + * @test_Strategy: Servlet writes data to the response, resets the buffer and + * then writes new data + */ + /* + * @testName: resetTest + * + * @assertion_ids: Servlet:JAVADOC:162; Servlet:SPEC:31; + * + * @test_Strategy: Servlet writes data to the response, does a reset, then + * writes new data + */ + /* + * @testName: resetTest1 + * + * @assertion_ids: Servlet:JAVADOC:162; Servlet:SPEC:31; + * + * @test_Strategy: Servlet writes data to the response, set the Headers, does + * a reset, then writes new data, set the new Header + */ + /* + * @testName: resetIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:163; Servlet:SPEC:31; + * + * @test_Strategy: Servlet writes data, flushes the buffer then tries to do a + * reset + */ + /* + * @testName: getCharacterEncodingTest + * + * @assertion_ids: Servlet:JAVADOC:137 + * + * @test_Strategy: Servlet sets encoding then checks it. + */ + /* + * @testName: getCharacterEncodingDefaultTest + * + * @assertion_ids: Servlet:JAVADOC:138 + * + * @test_Strategy: Servlet checks for the default encoding + */ + /* + * @testName: setCharacterEncodingTest + * + * @assertion_ids: Servlet:JAVADOC:139; Servlet:JAVADOC:151.3; + * + * @test_Strategy: Servlet set the encoding and client verifies it + */ + /* + * @testName: setBufferSizeTest + * + * @assertion_ids: Servlet:JAVADOC:154 + * + * @test_Strategy: Servlet sets the buffer size then verifies it was set + */ + /* + * @testName: setBufferSizeIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:155 + * + * @test_Strategy: Servlet writes data and flushes buffer then tries to get + * the buffer size + */ + /* + * @testName: setContentLengthTest + * + * @assertion_ids: Servlet:JAVADOC:150 + * + * @test_Strategy: Servlet sets the content length + */ + /* + * @testName: getContentTypeTest + * + * @assertion_ids: Servlet:JAVADOC:152; Servlet:JAVADOC:151.3; + * Servlet:SPEC:34; + * + * @test_Strategy: Servlet verifies the content type sent by the client + */ + /* + * @testName: getContentType1Test + * + * @assertion_ids: Servlet:JAVADOC:152; Servlet:JAVADOC:151.3; + * Servlet:SPEC:34; + * + * @test_Strategy: Servlet verifies the content type set by the servlet + */ + /* + * @testName: getContentTypeNullTest + * + * @assertion_ids: Servlet:JAVADOC:153; Servlet:SPEC:34; + * + * @test_Strategy: Servlet verifies the content-type when not set by + * programmer + */ + /* + * @testName: getContentTypeNull1Test + * + * @assertion_ids: Servlet:JAVADOC:153; Servlet:SPEC:34; + * + * @test_Strategy: Servlet verifies the content-type when not set by + * programmer and only character encoding is set + */ + /* + * @testName: getContentTypeNull2Test + * + * @assertion_ids: Servlet:JAVADOC:151; Servlet:JAVADOC:151.1; + * Servlet:JAVADOC:153.1 + * + * @test_Strategy: Servlet verifies content-type is being re-set by programmer + * and character encoding setting does not change + */ + /* + * @testName: setContentTypeTest + * + * @assertion_ids: Servlet:JAVADOC:151; Servlet:JAVADOC:151.3; + * Servlet:SPEC:34; + * + * @test_Strategy: Servlet sets the content type Verify Content-Type is set in + * Client + */ + /* + * @testName: setContentType1Test + * + * @assertion_ids: Servlet:JAVADOC:151; Servlet:SPEC:34; + * + * @test_Strategy: Servlet sets the content-type, and verifies it with + * getContentType() + */ + /* + * @testName: setContentType2Test + * + * @assertion_ids: Servlet:JAVADOC:151.2; Servlet:JAVADOC:151.3; + * Servlet:SPEC:34; + * + * @test_Strategy: Servlet sets the content-type, Commit the response; Set the + * content-type again Verifies that content-type is set the first time The + * second setting is ignored. + */ + /* + * @testName: setLocaleTest + * + * @assertion_ids: Servlet:JAVADOC:164 + * + * @test_Strategy: Servlet sets the Locale + */ + /* + * @testName: setLocale1Test + * + * @assertion_ids: Servlet:JAVADOC:164; Servlet:JAVADOC:151.3; + * + * @test_Strategy: Servlet sets the Locale + */ + @Test() + public void flushBufferTest() throws Exception { + super.flushBufferTest(); + } + + @Test() + public void getBufferSizeTest() throws Exception { + super.getBufferSizeTest(); + } + + @Test() + public void getCharacterEncodingDefaultTest() throws Exception { + super.getCharacterEncodingDefaultTest(); + } + + @Test() + public void getCharacterEncodingTest() throws Exception { + super.getCharacterEncodingTest(); + } + + @Test() + public void getContentType1Test() throws Exception { + super.getContentType1Test(); + } + + @Test() + public void getContentTypeNull1Test() throws Exception { + super.getContentTypeNull1Test(); + } + + @Test() + public void getContentTypeNull2Test() throws Exception { + super.getContentTypeNull2Test(); + } + + @Test() + public void getContentTypeNullTest() throws Exception { + super.getContentTypeNullTest(); + } + + @Test() + public void getContentTypeTest() throws Exception { + super.getContentTypeTest(); + } + + @Test() + public void getLocaleDefaultTest() throws Exception { + super.getLocaleDefaultTest(); + } + + @Test() + public void getLocaleTest() throws Exception { + super.getLocaleTest(); + } + + @Test() + public void getOutputStreamFlushTest() throws Exception { + super.getOutputStreamFlushTest(); + } + + @Test() + public void getOutputStreamIllegalStateExceptionTest() throws Exception { + super.getOutputStreamIllegalStateExceptionTest(); + } + + @Test() + public void getOutputStreamTest() throws Exception { + super.getOutputStreamTest(); + } + + @Test() + public void getWriterAfterTest() throws Exception { + super.getWriterAfterTest(); + } + + @Test() + public void getWriterFlushTest() throws Exception { + super.getWriterFlushTest(); + } + + @Test() + public void getWriterIllegalStateExceptionTest() throws Exception { + super.getWriterIllegalStateExceptionTest(); + } + + @Test() + public void getWriterTest() throws Exception { + super.getWriterTest(); + } + + @Test() + public void isCommittedTest() throws Exception { + super.isCommittedTest(); + } + + @Test() + public void resetBufferTest() throws Exception { + super.resetBufferTest(); + } + + @Test() + public void resetIllegalStateExceptionTest() throws Exception { + super.resetIllegalStateExceptionTest(); + } + + @Test() + public void resetTest() throws Exception { + super.resetTest(); + } + + @Test() + public void resetTest1() throws Exception { + super.resetTest1(); + } + + @Test() + public void setBufferSizeIllegalStateExceptionTest() throws Exception { + super.setBufferSizeIllegalStateExceptionTest(); + } + + @Test() + public void setBufferSizeTest() throws Exception { + super.setBufferSizeTest(); + } + + @Test() + public void setCharacterEncodingTest() throws Exception { + super.setCharacterEncodingTest(); + } + + @Test() + public void setContentLengthTest() throws Exception { + super.setContentLengthTest(); + } + + @Test() + public void setContentType1Test() throws Exception { + super.setContentType1Test(); + } + + @Test() + public void setContentType2Test() throws Exception { + super.setContentType2Test(); + } + + @Test() + public void setContentTypeTest() throws Exception { + super.setContentTypeTest(); + } + + @Test() + public void setLocale1Test() throws Exception { + super.setLocale1Test(); + } + + @Test() + public void setLocaleTest() throws Exception { + super.setLocaleTest(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponse/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponse/build.xml new file mode 100644 index 0000000000..49e97cd5ba --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponse/build.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponse/servlet_js_servletresponse_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponse/servlet_js_servletresponse_web.xml new file mode 100644 index 0000000000..341828aba7 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponse/servlet_js_servletresponse_web.xml @@ -0,0 +1,55 @@ + + + + + SerJaxSerServletResponse + + TestServlet + com.sun.ts.tests.servlet.common.response.ResponseTestServlet + + + setCharacterEncodingTest + com.sun.ts.tests.servlet.api.jakarta_servlet.servletresponse.SetCharacterEncodingTestServlet + + + checkTestResult + com.sun.ts.tests.servlet.common.servlets.GenericCheckTestResultServlet + + + TestServlet + /TestServlet/* + + + setCharacterEncodingTest + /setCharacterEncodingTest + + + checkTestResult + /checkTestResult + + + 54 + + + + ja + Shift_JIS + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponsewrapper/SetCharacterEncodingTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponsewrapper/SetCharacterEncodingTestServlet.java new file mode 100644 index 0000000000..c12ecc2624 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponsewrapper/SetCharacterEncodingTestServlet.java @@ -0,0 +1,79 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletresponsewrapper; + +import java.io.IOException; + +import com.sun.ts.tests.servlet.common.response.ResponseTests; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.ServletResponseWrapper; + +public class SetCharacterEncodingTestServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + ServletResponseWrapper srw = new ServletResponseWrapper(response); + ResponseTests.setCharacterEncodingTest(request, srw); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponsewrapper/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponsewrapper/TestServlet.java new file mode 100644 index 0000000000..a265bfd19d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponsewrapper/TestServlet.java @@ -0,0 +1,49 @@ +/* + * 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 com.sun.ts.tests.servlet.api.jakarta_servlet.servletresponsewrapper; + +import java.io.IOException; + +import com.sun.ts.tests.servlet.common.response.ResponseTestServlet; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.ServletResponseWrapper; + +public class TestServlet extends ResponseTestServlet { + + public void init(ServletConfig servletConfig) throws ServletException { + super.init(servletConfig); + } + + public void service(ServletRequest servletRequest, + ServletResponse servletResponse) throws ServletException, IOException { + ServletResponseWrapper wrapper = new ServletResponseWrapper( + servletResponse); + super.service(servletRequest, wrapper); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponsewrapper/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponsewrapper/URLClient.java new file mode 100644 index 0000000000..f401626460 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponsewrapper/URLClient.java @@ -0,0 +1,309 @@ +/* + * 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 + */ +/* + * $URL$ $LastChangedDate$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletresponsewrapper; + +import com.sun.ts.tests.servlet.common.response.HttpResponseClient; +import com.sun.ts.tests.servlet.common.response.ResponseTestServlet; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends HttpResponseClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_servletresponsewrapper_web.war").addAsLibraries(CommonServlets.getCommonServletsArchive()).addClasses(SetCharacterEncodingTestServlet.class, TestServlet.class, ResponseTestServlet.class).setWebXML(URLClient.class.getResource("servlet_js_servletresponsewrapper_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + /* Run test */ + /* + * @testName: responseWrapperConstructorTest + * + * @assertion_ids: Servlet:JAVADOC:9 + * + * @test_Strategy: Servlet calls wrapper constructor + */ + @Test + public void responseWrapperConstructorTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "responseWrapperConstructorTest"); + invoke(); + } + + /* + * @testName: responseWrapperGetResponseTest + * + * @assertion_ids: Servlet:JAVADOC:10 + * + * @test_Strategy: Servlet gets wrapped response object + */ + @Test + public void responseWrapperGetResponseTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "responseWrapperGetResponseTest"); + invoke(); + } + + /* + * @testName: responseWrapperSetResponseTest + * + * @assertion_ids: Servlet:JAVADOC:11 + * + * @test_Strategy: Servlet sets wrapped response object + */ + @Test + public void responseWrapperSetResponseTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "responseWrapperSetResponseTest"); + invoke(); + } + + /* + * @testName: responseWrapperSetResponseIllegalArgumentExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:12 + * + * @test_Strategy: Servlet sets wrapped response object + */ + @Test + public void responseWrapperSetResponseIllegalArgumentExceptionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "responseWrapperSetResponseIllegalArgumentExceptionTest"); + invoke(); + } + + /* + * @testName: flushBufferTest + * + * @assertion_ids: Servlet:JAVADOC:24 + * + * @test_Strategy: Servlet wraps response. Servlet writes data in the buffer + * and flushes it + */ + /* + * @testName: getBufferSizeTest + * + * @assertion_ids: Servlet:JAVADOC:23 + * + * @test_Strategy: Servlet wraps response. Servlet flushes buffer and verifies + * the size of the buffer + */ + /* + * @testName: getLocaleTest + * + * @assertion_ids: Servlet:JAVADOC:30 + * + * @test_Strategy: Servlet wraps response. Servlet set Locale and then + * verifies it + * + */ + /* + * @testName: getOutputStreamTest + * + * @assertion_ids: Servlet:JAVADOC:15 + * + * @test_Strategy: Servlet wraps response. Servlet gets an output stream and + * writes to it. + */ + /* + * @testName: getWriterTest + * + * @assertion_ids: Servlet:JAVADOC:17 + * + * @test_Strategy: Servlet wraps response. Servlet gets a Writer object, then + * sets the content type; Verify that content type didn't get set by servlet + */ + /* + * @testName: isCommittedTest + * + * @assertion_ids: Servlet:JAVADOC:26 + * + * @test_Strategy: Servlet wraps response. Servlet checks before and after + * response is flushed + * + */ + /* + * @testName: resetBufferTest + * + * @assertion_ids: Servlet:JAVADOC:28 + * + * @test_Strategy: Servlet wraps response. Servlet writes data to the + * response, resets the buffer and then writes new data + */ + /* + * @testName: resetTest + * + * @assertion_ids: Servlet:JAVADOC:27 + * + * @test_Strategy: Servlet wraps response. Servlet writes data to the + * response, does a reset, then writes new data + */ + /* + * @testName: resetTest1 + * + * @assertion_ids: Servlet:JAVADOC:27; Servlet:JAVADOC:162; Servlet:SPEC:31; + * + * @test_Strategy: Servlet writes data to the response, set the Headers, does + * a reset, then writes new data, set the new Header + */ + /* + * @testName: getCharacterEncodingTest + * + * @assertion_ids: Servlet:JAVADOC:14 + * + * @test_Strategy: Servlet wraps response. Servlet checks for the default + * encoding + */ + /* + * @testName: setCharacterEncodingTest + * + * @assertion_ids: Servlet:JAVADOC:13 + * + * @test_Strategy: Servlet wraps response. Servlet set the encoding and client + * verifies it + */ + /* + * @testName: setBufferSizeTest + * + * @assertion_ids: Servlet:JAVADOC:22 + * + * @test_Strategy: Servlet wraps response. Servlet sets the buffer size then + * verifies it was set + */ + /* + * @testName: setContentLengthTest + * + * @assertion_ids: Servlet:JAVADOC:19 + * + * @test_Strategy: Servlet wraps response. Servlet sets the content length + */ + /* + * @testName: getContentTypeTest + * + * @assertion_ids: Servlet:JAVADOC:21; Servlet:SPEC:34; + * + * @test_Strategy: Servlet wraps response. Servlet verifies the content type + * sent by the client + */ + /* + * @testName: setContentTypeTest + * + * @assertion_ids: Servlet:JAVADOC:20; Servlet:SPEC:34; + * + * @test_Strategy: Servlet wraps response. Servlet sets the content type + * + */ + /* + * @testName: setLocaleTest + * + * @assertion_ids: Servlet:JAVADOC:29 + * + * @test_Strategy: Servlet wraps response. Servlet sets the Locale + */ + @Test() + public void flushBufferTest() throws Exception { + super.flushBufferTest(); + } + + @Test() + public void getBufferSizeTest() throws Exception { + super.getBufferSizeTest(); + } + + @Test() + public void getCharacterEncodingTest() throws Exception { + super.getCharacterEncodingTest(); + } + + @Test() + public void getContentTypeTest() throws Exception { + super.getContentTypeTest(); + } + + @Test() + public void getLocaleTest() throws Exception { + super.getLocaleTest(); + } + + @Test() + public void getOutputStreamTest() throws Exception { + super.getOutputStreamTest(); + } + + @Test() + public void getWriterTest() throws Exception { + super.getWriterTest(); + } + + @Test() + public void isCommittedTest() throws Exception { + super.isCommittedTest(); + } + + @Test() + public void resetBufferTest() throws Exception { + super.resetBufferTest(); + } + + @Test() + public void resetTest() throws Exception { + super.resetTest(); + } + + @Test() + public void resetTest1() throws Exception { + super.resetTest1(); + } + + @Test() + public void setBufferSizeTest() throws Exception { + super.setBufferSizeTest(); + } + + @Test() + public void setCharacterEncodingTest() throws Exception { + super.setCharacterEncodingTest(); + } + + @Test() + public void setContentLengthTest() throws Exception { + super.setContentLengthTest(); + } + + @Test() + public void setContentTypeTest() throws Exception { + super.setContentTypeTest(); + } + + @Test() + public void setLocaleTest() throws Exception { + super.setLocaleTest(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponsewrapper/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponsewrapper/build.xml new file mode 100644 index 0000000000..1bccbe43cb --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponsewrapper/build.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponsewrapper/servlet_js_servletresponsewrapper_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponsewrapper/servlet_js_servletresponsewrapper_web.xml new file mode 100644 index 0000000000..3472d595cb --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponsewrapper/servlet_js_servletresponsewrapper_web.xml @@ -0,0 +1,41 @@ + + + + + SerJaxSerServletResponseWrapper + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.servletresponsewrapper.TestServlet + + + setCharacterEncodingTest + com.sun.ts.tests.servlet.api.jakarta_servlet.servletresponsewrapper.SetCharacterEncodingTestServlet + + + TestServlet + /TestServlet/* + + + setCharacterEncodingTest + /setCharacterEncodingTest + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponsewrapper30/IsWrapperForTest.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponsewrapper30/IsWrapperForTest.java new file mode 100644 index 0000000000..e476d134b4 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponsewrapper30/IsWrapperForTest.java @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2011, 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletresponsewrapper30; + +import java.io.IOException; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.ServletResponseWrapper; + +public class IsWrapperForTest extends GenericServlet { + + public void init(ServletConfig servletConfig) throws ServletException { + super.init(servletConfig); + } + + public void service(ServletRequest req, ServletResponse response) + throws ServletException, IOException { + Boolean pass = true; + ServletResponseWrapper resWrapper1 = new TCKServletResponseWrapper( + response); + ServletResponseWrapper resWrapper2 = new TCKServletResponseWrapper( + resWrapper1); + ServletResponseWrapper resWrapper3 = new TCKServletResponseWrapper( + resWrapper2); + TCKServletResponsesubWrapper myresWrapper = new TCKServletResponsesubWrapper( + response); + + if (!resWrapper3.isWrapperFor(resWrapper1)) { + pass = false; + response.getWriter() + .println("Test Failed: resWrapper3.isWrapperFor(resWrapper1)"); + } + + if (!resWrapper3.isWrapperFor(resWrapper2)) { + pass = false; + response.getWriter() + .println("Test Failed: resWrapper3.isWrapperFor(resWrapper2)"); + } + + if (!resWrapper3.isWrapperFor(TCKServletResponseWrapper.class)) { + pass = false; + response.getWriter().println( + "Test Failed: resWrapper3.isWrapperFor(TCKServletResponseWrapper.class)"); + } + + if (resWrapper3.isWrapperFor(myresWrapper)) { + pass = false; + response.getWriter() + .println("Test Failed: resWrapper3.isWrapperFor(myresWrapper)"); + } + + if (resWrapper3.isWrapperFor(TCKServletResponsesubWrapper.class)) { + pass = false; + response.getWriter().println( + "Test Failed: resWrapper3.isWrapperFor(TCKServletResponsesubWrapper.class)"); + } + + if (!resWrapper2.isWrapperFor(resWrapper1)) { + pass = false; + response.getWriter() + .println("Test Failed: resWrapper2.isWrapperFor(resWrapper1)"); + } + + if (!resWrapper2.isWrapperFor(TCKServletResponseWrapper.class)) { + pass = false; + response.getWriter().println( + "Test Failed: resWrapper2.isWrapperFor(TCKServletResponseWrapper.class)"); + } + + if (resWrapper2.isWrapperFor(myresWrapper)) { + pass = false; + response.getWriter() + .println("Test Failed: resWrapper2.isWrapperFor(myresWrapper)"); + } + + if (resWrapper2.isWrapperFor(TCKServletResponsesubWrapper.class)) { + pass = false; + response.getWriter().println( + "Test Failed: resWrapper2.isWrapperFor(TCKServletResponsesubWrapper.class)"); + } + + if (resWrapper1.isWrapperFor(TCKServletResponseWrapper.class)) { + pass = false; + response.getWriter().println( + "Test Failed: resWrapper1.isWrapperFor(TCKServletResponseWrapper.class)"); + } + + if (resWrapper1.isWrapperFor(myresWrapper)) { + pass = false; + response.getWriter() + .println("Test Failed: resWrapper1.isWrapperFor(myresWrapper)"); + } + + if (resWrapper1.isWrapperFor(TCKServletResponsesubWrapper.class)) { + pass = false; + response.getWriter().println( + "Test Failed: resWrapper1.isWrapperFor(TCKServletResponsesubWrapper.class)"); + } + + if (myresWrapper.isWrapperFor(TCKServletResponseWrapper.class)) { + pass = false; + response.getWriter().println( + "Test Failed: myresWrapper.isWrapperFor(TCKServletResponseWrapper.class)"); + } + + if (myresWrapper.isWrapperFor(resWrapper1)) { + pass = false; + response.getWriter() + .println("Test Failed: myresWrapper.isWrapperFor(resWrapper1)"); + } + + if (myresWrapper.isWrapperFor(resWrapper2)) { + pass = false; + response.getWriter() + .println("Test Failed: myresWrapper.isWrapperFor(resWrapper2)"); + } + + if (myresWrapper.isWrapperFor(resWrapper3)) { + pass = false; + response.getWriter() + .println("Test Failed: myresWrapper.isWrapperFor(resWrapper3)"); + } + + if (myresWrapper.isWrapperFor(TCKServletResponsesubWrapper.class)) { + pass = false; + response.getWriter().println( + "Test Failed: myresWrapper.isWrapperFor(TCKServletResponsesubWrapper.class)"); + } + + if (!pass) { + response.getWriter().println("Test Failed."); + } else { + response.getWriter().println("Test Passed."); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponsewrapper30/TCKServletResponseWrapper.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponsewrapper30/TCKServletResponseWrapper.java new file mode 100644 index 0000000000..9beb7fee35 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponsewrapper30/TCKServletResponseWrapper.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2011, 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletresponsewrapper30; + +import jakarta.servlet.ServletResponse; +import jakarta.servlet.ServletResponseWrapper; + +public class TCKServletResponseWrapper extends ServletResponseWrapper { + + public TCKServletResponseWrapper(ServletResponse res) { + super(res); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponsewrapper30/TCKServletResponsesubWrapper.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponsewrapper30/TCKServletResponsesubWrapper.java new file mode 100644 index 0000000000..c38edf72aa --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponsewrapper30/TCKServletResponsesubWrapper.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2011, 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletresponsewrapper30; + +import jakarta.servlet.ServletResponse; + +public class TCKServletResponsesubWrapper extends TCKServletResponseWrapper { + + public TCKServletResponsesubWrapper(ServletResponse res) { + super(res); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponsewrapper30/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponsewrapper30/URLClient.java new file mode 100644 index 0000000000..1290db592c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponsewrapper30/URLClient.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2011, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.servletresponsewrapper30; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_servletresponsewrapper30_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(IsWrapperForTest.class, TCKServletResponsesubWrapper.class, TCKServletResponseWrapper.class) + .setWebXML(URLClient.class.getResource("servlet_js_servletresponsewrapper30_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + /* + * @testName: isWrapperForTest + * + * @assertion_ids: Servlet:JAVADOC:731; Servlet:JAVADOC:732; + * + * @test_Strategy: Create a Servlets isWrapperForTest; In the servlet, wrap + * the Response a few time and in different ways; verifies the following + * works: - jakarta.servlet.ServletResponseWrapper.isWrapperFor(ServletResponse) + * - jakarta.servlet.ServletResponseWrapper.isWrapperFor(Class) + */ + @Test + public void isWrapperForTest() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/IsWrapperForTest HTTP/1.1"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "Test Failed"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponsewrapper30/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponsewrapper30/build.xml new file mode 100644 index 0000000000..0d86624b27 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponsewrapper30/build.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponsewrapper30/servlet_js_servletresponsewrapper30_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponsewrapper30/servlet_js_servletresponsewrapper30_web.xml new file mode 100644 index 0000000000..a0336174f3 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/servletresponsewrapper30/servlet_js_servletresponsewrapper30_web.xml @@ -0,0 +1,33 @@ + + + + + SerJaxSerServletResponse30x + + IsWrapperForTest + com.sun.ts.tests.servlet.api.jakarta_servlet.servletresponsewrapper30.IsWrapperForTest + + + IsWrapperForTest + /IsWrapperForTest + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode/TestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode/TestListener.java new file mode 100644 index 0000000000..76121cb0b3 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode/TestListener.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2011, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.sessiontrackingmode; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.concurrent.CopyOnWriteArrayList; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; +import jakarta.servlet.SessionTrackingMode; + +public class TestListener implements ServletContextListener { + + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce + * The servlet context event + */ + public void contextInitialized(ServletContextEvent sce) { + ServletContext context = sce.getServletContext(); + Boolean pass = true; + StringBuilder log = new StringBuilder(); + StringBuilder modes = new StringBuilder(); + List defaults = new CopyOnWriteArrayList( + context.getDefaultSessionTrackingModes()); + List complete = new CopyOnWriteArrayList(); + + complete.add(SessionTrackingMode.COOKIE); + complete.add(SessionTrackingMode.URL); + complete.add(SessionTrackingMode.SSL); + + for (SessionTrackingMode tmp : defaults) { + if (tmp == SessionTrackingMode.COOKIE || tmp == SessionTrackingMode.URL + || tmp == SessionTrackingMode.SSL) { + log.append("getDefaultSessionTrackingModes=").append(tmp).append(";"); + complete.remove(tmp); + } else { + pass = false; + log.append("Unrecognized SessionTrackingModes ").append(tmp) + .append(";"); + } + } + + for (SessionTrackingMode tmp : complete) { + Set test = new HashSet(); + test.add(tmp); + try { + context.setSessionTrackingModes(test); + } catch (Exception ex) { + log.append("Unsupported SessionTrackingModes=").append(tmp).append(";"); + complete.remove(tmp); + } + } + + // context.setSessionTrackingModes + // throws IllegalArgumentException - if sessionTrackingModes specifies a + // combination + // of SessionTrackingMode.SSL with a session tracking mode other than + // SessionTrackingMode.SSL + complete.remove(SessionTrackingMode.SSL); + if (!complete.isEmpty()) { + context.setSessionTrackingModes(new HashSet(complete)); + for (SessionTrackingMode tmp : complete) { + modes.append(tmp).append(";"); + log.append("Setting SessionTrackingModes to= ").append(tmp).append(";"); + } + } else { + log.append("Only default SessionTrackingModes are supported"); + defaults.remove(SessionTrackingMode.SSL); + context.setSessionTrackingModes(new HashSet(defaults)); + for (SessionTrackingMode tmp : defaults) { + modes.append(tmp).append(";"); + log.append("Setting SessionTrackingModes to Defaults = ").append(tmp) + .append(";"); + } + } + + context.setAttribute("LOG", log.toString()); + context.setAttribute("MODES", modes.toString()); + } + + /** + * Receives notification that the servlet context is about to be shut down. + * + * @param sce + * The servlet context event + */ + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode/TestServlet.java new file mode 100644 index 0000000000..92911be670 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode/TestServlet.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2011, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.sessiontrackingmode; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.HashSet; +import java.util.Set; +import java.util.StringTokenizer; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.SessionTrackingMode; + +public class TestServlet extends GenericTCKServlet { + + public void setSessionTrackingModes(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = true; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + pw.println((String) context.getAttribute("LOG")); + + Set expected_modes = new HashSet(); + String expected = (String) context.getAttribute("MODES"); + StringTokenizer str = new StringTokenizer(expected, ";"); + + while (str.hasMoreTokens()) { + String mode = str.nextToken(); + pw.println("Expected SessionTrackingMode =" + mode); + if (mode.equals(SessionTrackingMode.COOKIE.toString())) { + expected_modes.add(SessionTrackingMode.COOKIE); + } else if (mode.equals(SessionTrackingMode.SSL.toString())) { + // SSL cannot be set with combination of other SessionTrackingMode + // expected_modes.add(SessionTrackingMode.SSL); + } else if (mode.equals(SessionTrackingMode.URL.toString())) { + expected_modes.add(SessionTrackingMode.URL); + } else { + passed = false; + pw.println("Unrecogized SessionTrackingMode expected: " + mode); + } + + } + + Set results = null; + + if (expected_modes.isEmpty()) { + results = context.getDefaultSessionTrackingModes(); + } else { + results = context.getEffectiveSessionTrackingModes(); + } + + if (!results.containsAll(expected_modes)) { + passed = false; + pw.append("setSessionTrackingModes and getEffectiveSessionTrackingModes " + + "retuns different set of SessionTrackingModes"); + + pw.append("getEffectiveSessionTrackingModes ="); + for (SessionTrackingMode tmp : results) { + pw.append(" " + tmp); + } + } + + ServletTestUtil.printResult(pw, passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode/URLClient.java new file mode 100644 index 0000000000..3282ff0a7c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode/URLClient.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2011, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.sessiontrackingmode; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_sessiontrackingmode_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_js_sessiontrackingmode_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: setSessionTrackingModes + * + * @assertion_ids: Servlet:JAVADOC:695; Servlet:JAVADOC:684; + * Servlet:JAVADOC:687; + * + * @test_Strategy: Create a ServletListener, in which call + * ServletContext.setSessionTrackingModes() Create a Servlet, verify the above + * works using getEffectiveSessionTrackingModes() + */ + @Test + public void setSessionTrackingModes() throws Exception { + TEST_PROPS.setProperty(APITEST, "setSessionTrackingModes"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode/build.xml new file mode 100644 index 0000000000..43a8a4457f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode/build.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode/servlet_js_sessiontrackingmode_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode/servlet_js_sessiontrackingmode_web.xml new file mode 100644 index 0000000000..c4dc536191 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode/servlet_js_sessiontrackingmode_web.xml @@ -0,0 +1,36 @@ + + + + + SerJaxSerSessionTrackingMode + + com.sun.ts.tests.servlet.api.jakarta_servlet.sessiontrackingmode.TestListener + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.sessiontrackingmode.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode1/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode1/TestServlet.java new file mode 100644 index 0000000000..9f381d9e2c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode1/TestServlet.java @@ -0,0 +1,172 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.sessiontrackingmode1; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.concurrent.CopyOnWriteArrayList; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.SessionTrackingMode; + +public class TestServlet extends GenericTCKServlet { + + public void setSessionTrackingModes1(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + Boolean passed = true; + PrintWriter pw = response.getWriter(); + + ServletContext context = request.getServletContext(); + + List complete = new CopyOnWriteArrayList(); + complete.add(SessionTrackingMode.COOKIE); + + Set complete_set = new HashSet(complete); + + try { + context.setSessionTrackingModes(complete_set); + passed = false; + pw.println("No expected IllegalStateException throw when " + + "setSessionTrackingModes is called"); + } catch (IllegalArgumentException ilae) { + pw.println("IllegalArgumentException throw when " + + "setSessionTrackingModes is called"); + } catch (IllegalStateException ilex) { + pw.println("Expected IllegalStateException throw when " + + "setSessionTrackingModes is called"); + } catch (Throwable tr) { + passed = false; + pw.println("Unexpected Exception throw when " + + "setSessionTrackingModes is called."); + pw.println(tr.getMessage()); + pw.println(tr.toString()); + } + ServletTestUtil.printResult(pw, passed); + } + + public void setSessionTrackingModes2(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + Boolean passed = true; + PrintWriter pw = response.getWriter(); + + ServletContext context = request.getServletContext(); + + List complete = new CopyOnWriteArrayList(); + complete.add(SessionTrackingMode.URL); + + Set complete_set = new HashSet(complete); + + try { + context.setSessionTrackingModes(complete_set); + passed = false; + pw.println("No expected IllegalStateException throw when " + + "setSessionTrackingModes is called"); + } catch (IllegalArgumentException ilae) { + pw.println("IllegalArgumentException throw when " + + "setSessionTrackingModes is called"); + } catch (IllegalStateException ilex) { + pw.println("Expected IllegalStateException throw when " + + "setSessionTrackingModes is called"); + } catch (Throwable tr) { + passed = false; + pw.println("Unexpected Exception throw when " + + "setSessionTrackingModes is called."); + pw.println(tr.getMessage()); + pw.println(tr.toString()); + } + ServletTestUtil.printResult(pw, passed); + } + + public void setSessionTrackingModes3(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + Boolean passed = true; + PrintWriter pw = response.getWriter(); + + ServletContext context = request.getServletContext(); + + List complete = new CopyOnWriteArrayList(); + complete.add(SessionTrackingMode.SSL); + + Set complete_set = new HashSet(complete); + + try { + context.setSessionTrackingModes(complete_set); + passed = false; + pw.println("No expected IllegalStateException throw when " + + "setSessionTrackingModes is called"); + } catch (IllegalArgumentException ilae) { + pw.println("IllegalArgumentException throw when " + + "setSessionTrackingModes is called"); + } catch (IllegalStateException ilex) { + pw.println("Expected IllegalStateException throw when " + + "setSessionTrackingModes is called"); + } catch (Throwable tr) { + passed = false; + pw.println("Unexpected Exception throw when " + + "setSessionTrackingModes is called."); + pw.println(tr.getMessage()); + pw.println(tr.toString()); + } + ServletTestUtil.printResult(pw, passed); + } + + public void setSessionTrackingModes4(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + Boolean passed = true; + PrintWriter pw = response.getWriter(); + + ServletContext context = request.getServletContext(); + + List complete = new CopyOnWriteArrayList(); + complete.add(SessionTrackingMode.COOKIE); + complete.add(SessionTrackingMode.URL); + + Set complete_set = new HashSet(complete); + + try { + context.setSessionTrackingModes(complete_set); + passed = false; + pw.println("No expected IllegalStateException throw when " + + "setSessionTrackingModes is called"); + } catch (IllegalArgumentException ilae) { + pw.println("IllegalArgumentException throw when " + + "setSessionTrackingModes is called"); + } catch (IllegalStateException ilex) { + pw.println("Expected IllegalStateException throw when " + + "setSessionTrackingModes is called"); + } catch (Throwable tr) { + passed = false; + pw.println("Unexpected Exception throw when " + + "setSessionTrackingModes is called."); + pw.println(tr.getMessage()); + pw.println(tr.toString()); + } + ServletTestUtil.printResult(pw, passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode1/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode1/URLClient.java new file mode 100644 index 0000000000..0b2c948b23 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode1/URLClient.java @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.sessiontrackingmode1; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_sessiontrackingmode1_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_js_sessiontrackingmode1_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + + /* + * @testName: setSessionTrackingModes1 + * + * @assertion_ids: Servlet:JAVADOC:695.2; + * + * @test_Strategy: Negative test for method + * ServletContext.setSessionTrackingModes. Call + * ServletContext.setSessionTrackingModes inside a servlet; verify + * IllegalStateException is thrown. + */ + @Test + public void setSessionTrackingModes1() throws Exception { + TEST_PROPS.setProperty(APITEST, "setSessionTrackingModes1"); + invoke(); + } + + /* + * @testName: setSessionTrackingModes2 + * + * @assertion_ids: Servlet:JAVADOC:695.2; + * + * @test_Strategy: Negative test for method + * ServletContext.setSessionTrackingModes. Call + * ServletContext.setSessionTrackingModes inside a servlet; verify + * IllegalStateException is thrown. + */ + @Test + public void setSessionTrackingModes2() throws Exception { + TEST_PROPS.setProperty(APITEST, "setSessionTrackingModes2"); + invoke(); + } + /* + * @testName: setSessionTrackingModes3 + * + * @assertion_ids: Servlet:JAVADOC:695.2; + * + * @test_Strategy: Negative test for method + * ServletContext.setSessionTrackingModes. Call + * ServletContext.setSessionTrackingModes inside a servlet; verify + * IllegalStateException is thrown. + */ + @Test + public void setSessionTrackingModes3() throws Exception { + TEST_PROPS.setProperty(APITEST, "setSessionTrackingModes3"); + invoke(); + } + + /* + * @testName: setSessionTrackingModes4 + * + * @assertion_ids: Servlet:JAVADOC:695.2; + * + * @test_Strategy: Negative test for method + * ServletContext.setSessionTrackingModes. Call + * ServletContext.setSessionTrackingModes inside a servlet; verify + * IllegalStateException is thrown. + */ + @Test + public void setSessionTrackingModes4() throws Exception { + TEST_PROPS.setProperty(APITEST, "setSessionTrackingModes4"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode1/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode1/build.xml new file mode 100644 index 0000000000..5bb61ad29c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode1/build.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode1/servlet_js_sessiontrackingmode1_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode1/servlet_js_sessiontrackingmode1_web.xml new file mode 100644 index 0000000000..691e472476 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode1/servlet_js_sessiontrackingmode1_web.xml @@ -0,0 +1,33 @@ + + + + + SerJaxSerSessionTrackingMode1 + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.sessiontrackingmode1.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode2/TestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode2/TestListener.java new file mode 100644 index 0000000000..1114c2df74 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode2/TestListener.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.sessiontrackingmode2; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.concurrent.CopyOnWriteArrayList; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; +import jakarta.servlet.SessionTrackingMode; + +public class TestListener implements ServletContextListener { + + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce + * The ServletContextEvent + */ + public void contextInitialized(ServletContextEvent sce) { + ServletContext context = sce.getServletContext(); + StringBuilder log = new StringBuilder(); + + List complete = new CopyOnWriteArrayList(); + complete.add(SessionTrackingMode.URL); + complete.add(SessionTrackingMode.SSL); + + Set complete_set = new HashSet(complete); + + try { + context.setSessionTrackingModes(complete_set); + log.append("Expected IllegalArgumentException not thrown."); + } catch (IllegalArgumentException ex) { + log.append("Expected IllegalArgumentException thrown."); + } + + context.setAttribute("TCK_TEST_STATUS", log.toString()); + } + + /** + * Receives notification that the servlet context is about to be shut down. + * + * @param sce + * The servlet context event + */ + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode2/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode2/TestServlet.java new file mode 100644 index 0000000000..2838be19dd --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode2/TestServlet.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.sessiontrackingmode2; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void setSessionTrackingModes5(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = true; + String expected_status = "Expected IllegalArgumentException thrown."; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + String status = (String) context.getAttribute("TCK_TEST_STATUS"); + if (!expected_status.equals(status)) { + passed = false; + } + + ServletTestUtil.printResult(pw.append(status), passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode2/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode2/URLClient.java new file mode 100644 index 0000000000..5b015b1e4b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode2/URLClient.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.sessiontrackingmode2; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_sessiontrackingmode2_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_js_sessiontrackingmode2_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: setSessionTrackingModes5 + * + * @assertion_ids: Servlet:JAVADOC:695.3; + * + * @test_Strategy: Create a ServletListener, in which call + * ServletContext.setSessionTrackingModes(Set) Make the Set to include + * SessionTrackingMode.SSL; Add a different SessionTrackingMode to the Set; + * Verify that IllegalArgumentException is thrown. + */ + @Test + public void setSessionTrackingModes5() throws Exception { + TEST_PROPS.setProperty(APITEST, "setSessionTrackingModes5"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode2/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode2/build.xml new file mode 100644 index 0000000000..083995507f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode2/build.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode2/servlet_js_sessiontrackingmode2_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode2/servlet_js_sessiontrackingmode2_web.xml new file mode 100644 index 0000000000..a5d77940f7 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode2/servlet_js_sessiontrackingmode2_web.xml @@ -0,0 +1,36 @@ + + + + + SerJaxSerSessionTrackingMode2 + + com.sun.ts.tests.servlet.api.jakarta_servlet.sessiontrackingmode2.TestListener + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.sessiontrackingmode2.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode3/TestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode3/TestListener.java new file mode 100644 index 0000000000..9a0a632eaf --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode3/TestListener.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.sessiontrackingmode3; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.concurrent.CopyOnWriteArrayList; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; +import jakarta.servlet.SessionTrackingMode; + +public class TestListener implements ServletContextListener { + + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce + * The ServletContextEvent + */ + public void contextInitialized(ServletContextEvent sce) { + ServletContext context = sce.getServletContext(); + StringBuilder log = new StringBuilder(); + + List complete = new CopyOnWriteArrayList(); + complete.add(SessionTrackingMode.COOKIE); + complete.add(SessionTrackingMode.SSL); + + Set complete_set = new HashSet(complete); + + try { + context.setSessionTrackingModes(complete_set); + log.append("Expected IllegalArgumentException not thrown."); + } catch (IllegalArgumentException ex) { + log.append("Expected IllegalArgumentException thrown."); + } + + context.setAttribute("TCK_TEST_STATUS", log.toString()); + } + + /** + * Receives notification that the servlet context is about to be shut down. + * + * @param sce + * The servlet context event + */ + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode3/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode3/TestServlet.java new file mode 100644 index 0000000000..28df55e82f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode3/TestServlet.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.sessiontrackingmode3; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void setSessionTrackingModes6(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = true; + String expected_status = "Expected IllegalArgumentException thrown."; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + String status = (String) context.getAttribute("TCK_TEST_STATUS"); + if (!expected_status.equals(status)) { + passed = false; + } + + ServletTestUtil.printResult(pw.append(status), passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode3/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode3/URLClient.java new file mode 100644 index 0000000000..6424b7f982 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode3/URLClient.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.sessiontrackingmode3; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_sessiontrackingmode3_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_js_sessiontrackingmode3_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: setSessionTrackingModes6 + * + * @assertion_ids: Servlet:JAVADOC:695.3; + * + * @test_Strategy: Create a ServletListener, in which call + * ServletContext.setSessionTrackingModes(Set) Make the Set to include + * SessionTrackingMode.SSL; Add a different SessionTrackingMode to the Set; + * Verify that IllegalArgumentException is thrown. + */ + @Test + public void setSessionTrackingModes6() throws Exception { + TEST_PROPS.setProperty(APITEST, "setSessionTrackingModes6"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode3/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode3/build.xml new file mode 100644 index 0000000000..6732388e1f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode3/build.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode3/servlet_js_sessiontrackingmode3_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode3/servlet_js_sessiontrackingmode3_web.xml new file mode 100644 index 0000000000..8781a5e410 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode3/servlet_js_sessiontrackingmode3_web.xml @@ -0,0 +1,36 @@ + + + + + SerJaxSerSessionTrackingMode3 + + com.sun.ts.tests.servlet.api.jakarta_servlet.sessiontrackingmode3.TestListener + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.sessiontrackingmode3.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode4/TestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode4/TestListener.java new file mode 100644 index 0000000000..b0e1a79acb --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode4/TestListener.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.sessiontrackingmode4; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.concurrent.CopyOnWriteArrayList; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; +import jakarta.servlet.SessionTrackingMode; + +public class TestListener implements ServletContextListener { + + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce + * The ServletContextEvent + */ + public void contextInitialized(ServletContextEvent sce) { + ServletContext context = sce.getServletContext(); + StringBuilder log = new StringBuilder(); + + List complete = new CopyOnWriteArrayList(); + complete.add(SessionTrackingMode.COOKIE); + complete.add(SessionTrackingMode.SSL); + complete.add(SessionTrackingMode.URL); + + Set complete_set = new HashSet(complete); + + try { + context.setSessionTrackingModes(complete_set); + log.append("Expected IllegalArgumentException not thrown."); + } catch (IllegalArgumentException ex) { + log.append("Expected IllegalArgumentException thrown."); + } + + context.setAttribute("TCK_TEST_STATUS", log.toString()); + } + + /** + * Receives notification that the servlet context is about to be shut down. + * + * @param sce + * The servlet context event + */ + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode4/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode4/TestServlet.java new file mode 100644 index 0000000000..0058db2d4a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode4/TestServlet.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.sessiontrackingmode4; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void setSessionTrackingModes7(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = true; + String expected_status = "Expected IllegalArgumentException thrown."; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + String status = (String) context.getAttribute("TCK_TEST_STATUS"); + if (!expected_status.equals(status)) { + passed = false; + } + + ServletTestUtil.printResult(pw.append(status), passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode4/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode4/URLClient.java new file mode 100644 index 0000000000..2155ad06ab --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode4/URLClient.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2013, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet.sessiontrackingmode4; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_sessiontrackingmode4_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_js_sessiontrackingmode4_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: setSessionTrackingModes7 + * + * @assertion_ids: Servlet:JAVADOC:695.3; + * + * @test_Strategy: Create a ServletListener, in which call + * ServletContext.setSessionTrackingModes(Set) Make the Set to include + * SessionTrackingMode.SSL; Add two different SessionTrackingMode to the Set; + * Verify that IllegalArgumentException is thrown. + */ + @Test + public void setSessionTrackingModes7() throws Exception { + TEST_PROPS.setProperty(APITEST, "setSessionTrackingModes7"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode4/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode4/build.xml new file mode 100644 index 0000000000..d8649d9ea2 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode4/build.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode4/servlet_js_sessiontrackingmode4_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode4/servlet_js_sessiontrackingmode4_web.xml new file mode 100644 index 0000000000..b3df1d6423 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/sessiontrackingmode4/servlet_js_sessiontrackingmode4_web.xml @@ -0,0 +1,36 @@ + + + + + SerJaxSerSessionTrackingMode4 + + com.sun.ts.tests.servlet.api.jakarta_servlet.sessiontrackingmode4.TestListener + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.sessiontrackingmode4.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributeevent/SRAttributeListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributeevent/SRAttributeListener.java new file mode 100644 index 0000000000..52c4feb64d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributeevent/SRAttributeListener.java @@ -0,0 +1,123 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.srattributeevent; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; +import jakarta.servlet.ServletRequestAttributeEvent; +import jakarta.servlet.ServletRequestAttributeListener; + +public final class SRAttributeListener + implements ServletRequestAttributeListener, ServletContextListener { + + static ServletContext savedSC = null; + + // Public Methods + + public void contextInitialized(ServletContextEvent event) { + savedSC = event.getServletContext(); + } + + public void contextDestroyed(ServletContextEvent event) { + } + + public void attributeAdded(ServletRequestAttributeEvent event) { + StaticLog.add("AttributeAdded:" + event.getName() + "," + event.getValue()); + ServletContext sc = event.getServletContext(); + if (!savedSC.equals(sc)) { + StaticLog.add( + "AttributeAdded: The context in the listener did not match the one initialized"); + StaticLog.add("AttributeAdded: initialized context=" + savedSC); + StaticLog.add("AttributeAdded: getServletContext returned context=" + sc); + } + sc.setAttribute("testrequest", event.getServletRequest()); + } + + public void attributeRemoved(ServletRequestAttributeEvent event) { + StaticLog + .add("AttributeRemoved:" + event.getName() + "," + event.getValue()); + ServletContext sc = event.getServletContext(); + if (!savedSC.equals(sc)) { + StaticLog.add( + "AttributeRemoved: The context in the listener did not match the one initialized"); + StaticLog.add("AttributeRemoved: initialized context=" + savedSC); + StaticLog + .add("AttributeRemoved: getServletContext returned context=" + sc); + } + sc.setAttribute("testrequest", event.getServletRequest()); + } + + public void attributeReplaced(ServletRequestAttributeEvent event) { + StaticLog + .add("AttributeReplaced:" + event.getName() + "," + event.getValue()); + ServletContext sc = event.getServletContext(); + if (!savedSC.equals(sc)) { + StaticLog.add( + "AttributeReplaced: The context in the listener did not match the one initialized"); + StaticLog.add("AttributeReplaced: initialized context=" + savedSC); + StaticLog + .add("AttributeReplaced: getServletContext returned context=" + sc); + } + sc.setAttribute("testrequest", event.getServletRequest()); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributeevent/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributeevent/TestServlet.java new file mode 100644 index 0000000000..ab5b186d98 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributeevent/TestServlet.java @@ -0,0 +1,190 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.srattributeevent; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletRequestAttributeEvent; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void constructorTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + ServletRequestAttributeEvent sre = new ServletRequestAttributeEvent( + getServletContext(), request, "test", "value"); + if (sre == null) { + passed = false; + pw.println("The constructor for ServletRequestEvent returned a null"); + } else { + passed = true; + } + StaticLog.clear(); + ServletTestUtil.printResult(pw, passed); + } + + public void addedTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + + StaticLog.clear(); + + String[] expected = { "AttributeAdded:addTest,Attribute1" }; + + // the test + request.setAttribute("addTest", "Attribute1"); + + // verify results + ArrayList result = StaticLog.getClear(); + boolean passed = ServletTestUtil.checkArrayList(result, expected, true, + false); + if (!passed) { + ServletTestUtil.printFailureData(pw, result, expected); + } + ServletRequest sr = (ServletRequest) getServletContext() + .getAttribute("testrequest"); + if (!request.equals(sr)) { + passed = false; + pw.println( + "The request returned by the listener did not match the request in the TestServlet"); + pw.println("Request in TestServlet=" + request.toString()); + pw.println("Request from Listener=" + sr.toString()); + } + ServletTestUtil.printResult(pw, passed); + + } + + public void removedTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + StaticLog.clear(); + + String[] expected = { "AttributeAdded:removeTest,Attribute1", + "AttributeRemoved:removeTest,Attribute1" }; + + // the test + request.setAttribute("removeTest", "Attribute1"); + request.removeAttribute("removeTest"); + + // verify results + ArrayList result = StaticLog.getClear(); + boolean passed = ServletTestUtil.checkArrayList(result, expected, true, + false); + if (!passed) { + ServletTestUtil.printFailureData(pw, result, expected); + } + ServletRequest sr = (ServletRequest) getServletContext() + .getAttribute("testrequest"); + if (!request.equals(sr)) { + passed = false; + pw.println( + "The request returned by the listener did not match the request in the TestServlet"); + pw.println("Request in TestServlet=" + request.toString()); + pw.println("Request from Listener=" + sr.toString()); + } + ServletTestUtil.printResult(pw, passed); + + } + + public void replacedTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + StaticLog.clear(); + + String[] expected = { "AttributeAdded:replacedTest,Attribute1", + "AttributeReplaced:replacedTest,Attribute1" }; + + // the test + request.setAttribute("replacedTest", "Attribute1"); + request.setAttribute("replacedTest", "Attribute2"); + + // verify results + ArrayList result = StaticLog.getClear(); + boolean passed = ServletTestUtil.checkArrayList(result, expected, true, + false); + if (!passed) { + ServletTestUtil.printFailureData(pw, result, expected); + } + ServletRequest sr = (ServletRequest) getServletContext() + .getAttribute("testrequest"); + if (!request.equals(sr)) { + passed = false; + pw.println( + "The request returned by the listener did not match the request in the TestServlet"); + pw.println("Request in TestServlet=" + request.toString()); + pw.println("Request from Listener=" + sr.toString()); + } + ServletTestUtil.printResult(pw, passed); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributeevent/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributeevent/URLClient.java new file mode 100644 index 0000000000..ee9b0a8e8c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributeevent/URLClient.java @@ -0,0 +1,124 @@ +/* + * 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 com.sun.ts.tests.servlet.api.jakarta_servlet.srattributeevent; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_srattributeevent_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(SRAttributeListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_js_srattributeevent_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: constructorTest + * + * @assertion_ids: Servlet:JAVADOC:66 + * + * @test_Strategy: Servlet instanciate the constructor + */ + @Test + public void constructorTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "constructorTest"); + invoke(); + } + + /* + * @testName: addedTest + * + * @assertion_ids: + * Servlet:JAVADOC:67;Servlet:JAVADOC:68;Servlet:JAVADOC:71;Servlet:JAVADOC:72 + * + * @test_Strategy: Servlet adds an attribute. The listener should detect the + * add and write a message out to a static log. Servlet then reads the log and + * verifys the result. It also verifies the requets and context that changed + * + */ + @Test + public void addedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "addedTest"); + invoke(); + } + + /* + * @testName: removedTest + * + * @assertion_ids: + * Servlet:JAVADOC:67;Servlet:JAVADOC:69;Servlet:JAVADOC:71;Servlet:JAVADOC:72 + * + * @test_Strategy: Servlet adds/removes an attribute. The listener should + * detect the add and write a message out to a static log. Servlet then reads + * the log and verifys the result. It also verifies the requets and context + * that changed + */ + @Test + public void removedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "removedTest"); + invoke(); + } + + /* + * @testName: replacedTest + * + * @assertion_ids: + * Servlet:JAVADOC:67;Servlet:JAVADOC:70;Servlet:JAVADOC:71;Servlet:JAVADOC:72 + * + * @test_Strategy: Servlet adds/replaces an attribute. The listener should + * detect the add and write a message out to a static log. Servlet then reads + * the log and verifys the result. It also verifies the requets and context + * that changed + */ + @Test + public void replacedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "replacedTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributeevent/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributeevent/build.xml new file mode 100644 index 0000000000..1604690f33 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributeevent/build.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributeevent/servlet_js_srattributeevent_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributeevent/servlet_js_srattributeevent_web.xml new file mode 100644 index 0000000000..a0cc212bbc --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributeevent/servlet_js_srattributeevent_web.xml @@ -0,0 +1,36 @@ + + + + + ServletRequestAttributeEvent + + com.sun.ts.tests.servlet.api.jakarta_servlet.srattributeevent.SRAttributeListener + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.srattributeevent.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributelistener/SRAttributeListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributelistener/SRAttributeListener.java new file mode 100644 index 0000000000..aa4701c29e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributelistener/SRAttributeListener.java @@ -0,0 +1,86 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.srattributelistener; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.ServletRequestAttributeEvent; +import jakarta.servlet.ServletRequestAttributeListener; + +public final class SRAttributeListener + implements ServletRequestAttributeListener { + + // Public Methods + + public void attributeAdded(ServletRequestAttributeEvent event) { + StaticLog.add("AttributeAdded:" + event.getName() + "," + event.getValue()); + + } + + public void attributeRemoved(ServletRequestAttributeEvent event) { + StaticLog + .add("AttributeRemoved:" + event.getName() + "," + event.getValue()); + } + + public void attributeReplaced(ServletRequestAttributeEvent event) { + StaticLog + .add("AttributeReplaced:" + event.getName() + "," + event.getValue()); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributelistener/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributelistener/TestServlet.java new file mode 100644 index 0000000000..bb7751141b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributelistener/TestServlet.java @@ -0,0 +1,142 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.srattributelistener; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void addedTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + + StaticLog.clear(); + + String[] expected = { "AttributeAdded:addTest,Attribute1" }; + + // the test + request.setAttribute("addTest", "Attribute1"); + + // verify results + ArrayList result = StaticLog.getClear(); + boolean b = ServletTestUtil.checkArrayList(result, expected, true, false); + if (!b) { + ServletTestUtil.printFailureData(pw, result, expected); + } + ServletTestUtil.printResult(pw, b); + + } + + public void removedTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + StaticLog.clear(); + + String[] expected = { "AttributeAdded:removeTest,Attribute1", + "AttributeRemoved:removeTest,Attribute1" }; + + // the test + request.setAttribute("removeTest", "Attribute1"); + request.removeAttribute("removeTest"); + + // verify results + ArrayList result = StaticLog.getClear(); + boolean b = ServletTestUtil.checkArrayList(result, expected, true, false); + if (!b) { + ServletTestUtil.printFailureData(pw, result, expected); + } + ServletTestUtil.printResult(pw, b); + + } + + public void replacedTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + StaticLog.clear(); + + String[] expected = { "AttributeAdded:replacedTest,Attribute1", + "AttributeReplaced:replacedTest,Attribute1" }; + + // the test + request.setAttribute("replacedTest", "Attribute1"); + request.setAttribute("replacedTest", "Attribute2"); + + // verify results + ArrayList result = StaticLog.getClear(); + boolean b = ServletTestUtil.checkArrayList(result, expected, true, false); + if (!b) { + ServletTestUtil.printFailureData(pw, result, expected); + } + ServletTestUtil.printResult(pw, b); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributelistener/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributelistener/URLClient.java new file mode 100644 index 0000000000..16c0c3b121 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributelistener/URLClient.java @@ -0,0 +1,104 @@ +/* + * 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 com.sun.ts.tests.servlet.api.jakarta_servlet.srattributelistener; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_srattributelistener_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(SRAttributeListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_js_srattributelistener_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: addedTest + * + * @assertion_ids: Servlet:JAVADOC:169 + * + * @test_Strategy: Servlet adds an attribute. The listener should detect the + * add and write a message out to a static log. Servlet then reads the log and + * verifys the result. + * + */ + @Test + public void addedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "addedTest"); + invoke(); + } + + /* + * @testName: removedTest + * + * @assertion_ids: Servlet:JAVADOC:170 + * + * @test_Strategy: Servlet adds/removes an attribute. The listener should + * detect the add and write a message out to a static log. Servlet then reads + * the log and verifys the result. + */ + @Test + public void removedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "removedTest"); + invoke(); + } + + /* + * @testName: replacedTest + * + * @assertion_ids: Servlet:JAVADOC:171 + * + * @test_Strategy: Servlet adds/replaces an attribute. The listener should + * detect the add and write a message out to a static log. Servlet then reads + * the log and verifys the result. + */ + @Test + public void replacedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "replacedTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributelistener/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributelistener/build.xml new file mode 100644 index 0000000000..ead6a9d26d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributelistener/build.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributelistener/servlet_js_srattributelistener_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributelistener/servlet_js_srattributelistener_web.xml new file mode 100644 index 0000000000..924682bed8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributelistener/servlet_js_srattributelistener_web.xml @@ -0,0 +1,36 @@ + + + + + ServletRequestAttributeListener + + com.sun.ts.tests.servlet.api.jakarta_servlet.srattributelistener.SRAttributeListener + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.srattributelistener.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributelistener40/SRAttributeListener40.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributelistener40/SRAttributeListener40.java new file mode 100644 index 0000000000..c206bcc11c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributelistener40/SRAttributeListener40.java @@ -0,0 +1,65 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2017, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.srattributelistener40; + +import jakarta.servlet.ServletRequestAttributeListener; + +public final class SRAttributeListener40 + implements ServletRequestAttributeListener { +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributelistener40/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributelistener40/TestServlet.java new file mode 100644 index 0000000000..695244e09f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributelistener40/TestServlet.java @@ -0,0 +1,80 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.srattributelistener40; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void defaultMethodsTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + pw.println("In ServletRequestAttributeListener40.TestServlet"); + ServletTestUtil.printResult(pw, true); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributelistener40/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributelistener40/URLClient.java new file mode 100644 index 0000000000..2c85a7a3cf --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributelistener40/URLClient.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2017, 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: URLClient.java 62571 2011-04-18 20:58:13Z kgrucci $ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.srattributelistener40; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_srattributelistener40_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(SRAttributeListener40.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_js_srattributelistener40_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: defaultMethodsTest + * + * @assertion_ids: NA; + * + * @test_Strategy: Client successfully calls a servlet with an empty + * ServletRequestAttribute listener implementation class.. + * + */ + @Test + public void defaultMethodsTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "defaultMethodsTest"); + invoke(); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributelistener40/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributelistener40/build.xml new file mode 100644 index 0000000000..1e32000b8b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributelistener40/build.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributelistener40/servlet_js_srattributelistener40_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributelistener40/servlet_js_srattributelistener40_web.xml new file mode 100644 index 0000000000..834ed13a6a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srattributelistener40/servlet_js_srattributelistener40_web.xml @@ -0,0 +1,36 @@ + + + + + ServletRequestAttributeListener40 + + com.sun.ts.tests.servlet.api.jakarta_servlet.srattributelistener40.SRAttributeListener40 + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.srattributelistener40.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srevent/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srevent/TestServlet.java new file mode 100644 index 0000000000..6c59829e5e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srevent/TestServlet.java @@ -0,0 +1,140 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.srevent; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletRequestEvent; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void constructorTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + + ServletRequestEvent sre = new ServletRequestEvent(getServletContext(), + request); + if (sre != null) { + passed = true; + } else { + passed = false; + pw.println("ServletRequstEvent retuirned a null"); + } + ServletTestUtil.printResult(pw, passed); + } + + public void getServletRequestTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + + ServletRequestEvent sre = new ServletRequestEvent(getServletContext(), + request); + if (sre != null) { + ServletRequest actual = sre.getServletRequest(); + if (!request.equals(actual)) { + passed = false; + pw.println( + "getServletRequest() did not return the same request used in the constructor"); + } else { + passed = true; + } + } else { + passed = false; + pw.println("ServletRequstEvent retuirned a null"); + } + ServletTestUtil.printResult(pw, passed); + } + + public void getServletContextTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + + ServletRequestEvent sre = new ServletRequestEvent(getServletContext(), + request); + if (sre != null) { + ServletContext actual = sre.getServletContext(); + if (!getServletContext().equals(actual)) { + passed = false; + pw.println( + "getServletContext() did not return the same context used in the constructor"); + } else { + passed = true; + } + } else { + passed = false; + pw.println("ServletRequstEvent retuirned a null"); + } + ServletTestUtil.printResult(pw, passed); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srevent/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srevent/URLClient.java new file mode 100644 index 0000000000..1cf8f68994 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srevent/URLClient.java @@ -0,0 +1,96 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.srevent; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_srevent_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_js_srevent_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: constructorTest + * + * @assertion_ids: Servlet:JAVADOC:63 + * + * @test_Strategy: Servlet tries to get an instance of ServletRequestEvent. + */ + @Test + public void constructorTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "constructorTest"); + invoke(); + } + + /* + * @testName: getServletContextTest + * + * @assertion_ids: Servlet:JAVADOC:65 + * + * @test_Strategy: Servlet calls constructor and tries to get the context that + * was used in the constructor. + */ + @Test + public void getServletContextTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletContextTest"); + invoke(); + } + + /* + * @testName: getServletRequestTest + * + * @assertion_ids: Servlet:JAVADOC:64 + * + * @test_Strategy: Servlet calls constructor and tries to get the request that + * was used in the constructor. + */ + @Test + public void getServletRequestTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletRequestTest"); + invoke(); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srevent/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srevent/build.xml new file mode 100644 index 0000000000..31ba7f75c1 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srevent/build.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srevent/servlet_js_srevent_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srevent/servlet_js_srevent_web.xml new file mode 100644 index 0000000000..fdda7f7e9f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srevent/servlet_js_srevent_web.xml @@ -0,0 +1,33 @@ + + + + + SerJaxSerSerRequestEvent + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.srevent.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srlistener/SRListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srlistener/SRListener.java new file mode 100644 index 0000000000..807e5cd8fa --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srlistener/SRListener.java @@ -0,0 +1,89 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.srlistener; + +import java.util.ArrayList; + +import jakarta.servlet.ServletRequestEvent; +import jakarta.servlet.ServletRequestListener; + +public final class SRListener implements ServletRequestListener { + + // Public Methods + + public void requestDestroyed(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("arraylist"); + if (al != null) { + al.add("in requestDestroyed method of listener"); + event.getServletContext().setAttribute("arraylist", al); + } + } + + public void requestInitialized(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("arraylist"); + if (al == null) { + al = new ArrayList(); + } + al.add("in requestInitialized method of listener"); + event.getServletContext().setAttribute("arraylist", al); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srlistener/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srlistener/TestServlet.java new file mode 100644 index 0000000000..bd806eb13c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srlistener/TestServlet.java @@ -0,0 +1,103 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.srlistener; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void initializeDestroyTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + + ServletTestUtil.printResult(pw, true); + + } + + public void checkLog(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + // the last item in the expected is a result of this servlet being called + String[] expected = { "in requestInitialized method of listener", + "in requestDestroyed method of listener", + "in requestInitialized method of listener" }; + + // verify results + ArrayList result = (ArrayList) getServletContext() + .getAttribute("arraylist"); + boolean b = ServletTestUtil.checkArrayList(result, expected, true, true); + if (!b) { + ServletTestUtil.printFailureData(pw, result, expected); + } + ServletTestUtil.printResult(pw, b); + getServletContext().removeAttribute("arraylist"); + + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srlistener/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srlistener/URLClient.java new file mode 100644 index 0000000000..7e7c9c9c73 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srlistener/URLClient.java @@ -0,0 +1,76 @@ +/* + * 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 com.sun.ts.tests.servlet.api.jakarta_servlet.srlistener; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_srlistener_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(SRListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_js_srlistener_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: initializeDestroyTest + * + * @assertion_ids: Servlet:JAVADOC:167;Servlet:JAVADOC:168 + * + * @test_Strategy: Servlet calls a simple servlet then calls a second servlet + * to verify results + */ + @Test + public void initializeDestroyTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "initializeDestroyTest"); + invoke(); + TEST_PROPS.setProperty(APITEST, "checkLog"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srlistener/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srlistener/build.xml new file mode 100644 index 0000000000..449d135fae --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srlistener/build.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srlistener/servlet_js_srlistener_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srlistener/servlet_js_srlistener_web.xml new file mode 100644 index 0000000000..107493aea3 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srlistener/servlet_js_srlistener_web.xml @@ -0,0 +1,36 @@ + + + + + ServletRequestListener + + com.sun.ts.tests.servlet.api.jakarta_servlet.srlistener.SRListener + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.srlistener.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srlistener40/SRListener40.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srlistener40/SRListener40.java new file mode 100644 index 0000000000..e6764a354f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srlistener40/SRListener40.java @@ -0,0 +1,62 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2017, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.srlistener40; + +import jakarta.servlet.ServletRequestListener; + +public final class SRListener40 implements ServletRequestListener { +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srlistener40/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srlistener40/TestServlet.java new file mode 100644 index 0000000000..31f42cf344 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srlistener40/TestServlet.java @@ -0,0 +1,81 @@ +/* + * + * * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2006, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.srlistener40; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void defaultMethodsTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + pw.println("In ServletRequestListener40.TestServlet"); + ServletTestUtil.printResult(pw, true); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srlistener40/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srlistener40/URLClient.java new file mode 100644 index 0000000000..53aca9934f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srlistener40/URLClient.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2017, 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: URLClient.java 62571 2011-04-18 20:58:13Z kgrucci $ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.srlistener40; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_srlistener40_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(SRListener40.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_js_srlistener40_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: defaultMethodsTest + * + * @assertion_ids: NA; + * + * @test_Strategy: Client successfully calls a servlet with an empty + * ServletRequest listener implementation class. + * + */ + @Test + public void defaultMethodsTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "defaultMethodsTest"); + invoke(); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srlistener40/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srlistener40/build.xml new file mode 100644 index 0000000000..51f412059b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srlistener40/build.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srlistener40/servlet_js_srlistener40_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srlistener40/servlet_js_srlistener40_web.xml new file mode 100644 index 0000000000..c38c3c651d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/srlistener40/servlet_js_srlistener40_web.xml @@ -0,0 +1,36 @@ + + + + + ServletRequestListener40 + + com.sun.ts.tests.servlet.api.jakarta_servlet.srlistener40.SRListener40 + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.srlistener40.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/unavailableexception/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/unavailableexception/TestServlet.java new file mode 100644 index 0000000000..14b3bd8843 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/unavailableexception/TestServlet.java @@ -0,0 +1,175 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.unavailableexception; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.UnavailableException; + +public class TestServlet extends GenericTCKServlet { + + public void getUnavailableSecondsTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = false; + PrintWriter pw = response.getWriter(); + // Constructing exception with unavailable secs 20 + + UnavailableException ue = new UnavailableException("Message", 20); + + int secs = ue.getUnavailableSeconds(); + + if ((secs == 20) || (secs < 0)) { + passed = true; + } else { + passed = false; + pw.println("getUnavailableSeconds() method returned incorrect result"); + pw.println("Expected result -> > 0 or == 20"); + pw.println("Actual result =|" + secs + "|"); + } + ServletTestUtil.printResult(pw, passed); + + } + + public void unavailableException_Constructor1Test(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = false; + PrintWriter pw = response.getWriter(); + String expected = "Excpetional"; + UnavailableException ue = new UnavailableException(expected); + + try { + throw ue; + } catch (Throwable t) { + if (t instanceof UnavailableException) { + String actual = t.getMessage(); + + if (actual.equals(expected)) { + passed = true; + } else { + passed = false; + pw.println( + "getUnavailableSeconds() method returned incorrect result"); + pw.println("Expected result =" + expected); + pw.println("Actual result =" + actual); + } + } else { + passed = false; + pw.println( + "Exception thrown, but was not an instance of UnavailableException ."); + pw.println("instead received: " + t.getClass().getName()); + } + } + ServletTestUtil.printResult(pw, passed); + } + + /** + * UnavailableException(String mesg,int sec) constructs an + * UnavailabaleException object for the specified servlet. This constructor + * reports Temporary Unavailability + */ + + public void unavailableException_Constructor2Test(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + /** + * Constructing one and throwing it. catching the exception + */ + + boolean passed = false; + PrintWriter pw = response.getWriter(); + String expectedResult1 = "Exceptional"; + int expectedResult2 = 20; + UnavailableException ue = new UnavailableException(expectedResult1, + expectedResult2); + + try { + throw ue; + } catch (Throwable t) { + if (t instanceof UnavailableException) { + int actual2 = ((UnavailableException) t).getUnavailableSeconds(); + + String actual1 = t.getMessage(); + + if (actual2 == expectedResult2 && actual1.equals(expectedResult1)) { + passed = true; + } else { + if (!actual1.equals(expectedResult1)) { + passed = false; + pw.println("getMessage() method returned incorrect result"); + pw.println("Expected result =" + expectedResult1); + pw.println("Actual result =" + actual1); + } + + if (actual2 != expectedResult2) { + passed = false; + pw.println( + "getUnavailableSeconds() method returned incorrect result"); + pw.println("Expected result =" + expectedResult2); + pw.println("Actual result =" + actual2); + } + } + } else { + passed = false; + pw.println( + "Exception thrown, but was not an instance of UnavailableException ."); + pw.println("instead received: " + t.getClass().getName()); + } + } + ServletTestUtil.printResult(pw, passed); + } + + public void isPermanentTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + boolean passed = false; + PrintWriter pw = response.getWriter(); + + UnavailableException ue = new UnavailableException("Unavailable1", 20); + UnavailableException ud = new UnavailableException("Unavailable2"); + + boolean result1 = ue.isPermanent(); + boolean result2 = ud.isPermanent(); + + if (result1 == false && result2 == true) { + passed = true; + } else { + if (result1 != false) { + passed = false; + pw.println( + "isPermanent() failed to detect that the servlet was not initially unavailable"); + } + + if (result2 != true) { + passed = false; + pw.println( + "isPermanent() failed to detect that the servlet had become unavailable"); + } + + } + ServletTestUtil.printResult(pw, passed); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/unavailableexception/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/unavailableexception/URLClient.java new file mode 100644 index 0000000000..dd3007f56f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/unavailableexception/URLClient.java @@ -0,0 +1,133 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.unavailableexception; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_unavailableexception_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestServlet.class, UnavailableServlet.class) + .setWebXML(URLClient.class.getResource("servlet_js_unavailableexception_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + + /* + * @testName: getUnavailableSecondsTest + * + * @assertion_ids: Servlet:SPEC:11; Servlet:JAVADOC:4; Servlet:JAVADOC:7; + * + * @test_Strategy: A test for UnavailableException.getUnavailableSeconds() + * method. + */ + @Test + public void getUnavailableSecondsTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getUnavailableSecondsTest"); + invoke(); + } + + /* + * @testName: isPermanentTest + * + * @assertion_ids: Servlet:SPEC:11; Servlet:JAVADOC:3; Servlet:JAVADOC:4; + * Servlet:JAVADOC:5; + * + * @test_Strategy: A test for UnavailableException.isPermanent() method. + */ + @Test + public void isPermanentTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "isPermanentTest"); + invoke(); + } + + /* + * @testName: unavailableTest + * + * @assertion_ids: Servlet:SPEC:11; Servlet:SPEC:11.1; Servlet:JAVADOC:3; + * Servlet:JAVADOC:268; + * + * @test_Strategy: A test for Permanent Unavailable First access the Servlet, + * and mark it unavailable Second try to access it again, 404 should be + * returned + */ + @Test + public void unavailableTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, " "); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, ""); + TEST_PROPS.setProperty(DONOTUSEServletName, "true"); + TEST_PROPS.setProperty(STATUS_CODE, "404"); + TEST_PROPS.setProperty(APITEST, "unavailableTest"); + invoke(); + } + + /* + * @testName: unavailableException_Constructor1Test + * + * @assertion_ids: Servlet:SPEC:11; Servlet:JAVADOC:3; + * + * @test_Strategy: A test for UnavailableException(String mesg). It construts + * an UnavailabaleException object for the specified servlet. This constructor + * tests for permanent unavailability + */ + @Test + public void unavailableException_Constructor1Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "unavailableException_Constructor1Test"); + invoke(); + } + + /* + * @testName: unavailableException_Constructor2Test + * + * @assertion_ids: Servlet:SPEC:11; Servlet:JAVADOC:4; + * + * @test_Strategy: A test for UnavailableException(String mesg, int sec). It + * construts an UnavailabaleException object for the specified servlet. This + * constructor tests for temporarily unavailability + */ + @Test + public void unavailableException_Constructor2Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "unavailableException_Constructor2Test"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/unavailableexception/UnavailableServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/unavailableexception/UnavailableServlet.java new file mode 100644 index 0000000000..38f74238fb --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/unavailableexception/UnavailableServlet.java @@ -0,0 +1,44 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet.unavailableexception; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.UnavailableException; + +public class UnavailableServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter out = response.getWriter(); + + UnavailableException ud = new UnavailableException("Unavailable2"); + + out.println("Test Passed"); + + throw ud; + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/unavailableexception/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/unavailableexception/build.xml new file mode 100644 index 0000000000..b33d2c6ff6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/unavailableexception/build.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/unavailableexception/servlet_js_unavailableexception_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/unavailableexception/servlet_js_unavailableexception_web.xml new file mode 100644 index 0000000000..0113ecb9f6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet/unavailableexception/servlet_js_unavailableexception_web.xml @@ -0,0 +1,41 @@ + + + + + SerJaxSerUnavailable + + TestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.unavailableexception.TestServlet + + + UnavailableTestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.unavailableexception.UnavailableServlet + + + TestLogicalName + /TestServlet + + + UnavailableTestLogicalName + /unavailableTest + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/asynccontext/ACListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/asynccontext/ACListener.java new file mode 100644 index 0000000000..19cc6370e8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/asynccontext/ACListener.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2009, 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.asynccontext; + +import java.io.IOException; + +import jakarta.servlet.AsyncEvent; +import jakarta.servlet.AsyncListener; + +public final class ACListener implements AsyncListener { + + public ACListener() throws IOException { + } + + public void onError(AsyncEvent event) throws IOException { + event.getAsyncContext().getResponse().getWriter() + .println("in onError method of ACListener"); + } + + public void onStartAsync(AsyncEvent event) throws IOException { + event.getAsyncContext().getResponse().getWriter() + .println("in onStartAsync method of ACListener"); + } + + public void onComplete(AsyncEvent event) throws IOException { + // commented out as part of bug fix for: + // https://bug.oraclecorp.com/pls/bug/webbug_edit.edit_info_top?rptno=19258007 + // event.getAsyncContext().getResponse().getWriter().println("in onComplete + // method of ACListener"); + } + + public void onTimeout(AsyncEvent event) throws IOException { + event.getAsyncContext().getResponse().getWriter() + .println("in onTimeout method of ACListener"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/asynccontext/ACListener1.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/asynccontext/ACListener1.java new file mode 100644 index 0000000000..07083e6af7 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/asynccontext/ACListener1.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2012, 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.asynccontext; + +import java.io.IOException; + +import jakarta.servlet.AsyncEvent; +import jakarta.servlet.AsyncListener; + +public final class ACListener1 implements AsyncListener { + + public ACListener1() throws IOException { + } + + public void onError(AsyncEvent event) throws IOException { + event.getAsyncContext().getResponse().getWriter() + .println("in onError method of ACListener1"); + } + + public void onStartAsync(AsyncEvent event) throws IOException { + event.getAsyncContext().getResponse().getWriter() + .println("in onStartAsync method of ACListener1"); + } + + public void onComplete(AsyncEvent event) throws IOException { + throw new IOException("in onComplete method of ACListener1"); + } + + public void onTimeout(AsyncEvent event) throws IOException { + event.getAsyncContext().getResponse().getWriter() + .println("in onTimeout method of ACListener1"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/asynccontext/ACListener2.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/asynccontext/ACListener2.java new file mode 100644 index 0000000000..89a082bf81 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/asynccontext/ACListener2.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2013, 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.asynccontext; + +import java.io.IOException; + +import jakarta.servlet.AsyncEvent; +import jakarta.servlet.AsyncListener; + +public final class ACListener2 implements AsyncListener { + + public ACListener2() throws IOException { + } + + public void onError(AsyncEvent event) throws IOException { + event.getAsyncContext().getResponse().getWriter() + .println("in onError method of ACListener2"); + } + + public void onStartAsync(AsyncEvent event) throws IOException { + event.getAsyncContext().getResponse().getWriter() + .println("in onStartAsync method of ACListener2"); + } + + public void onComplete(AsyncEvent event) throws IOException { + throw new IOException("in onComplete method of ACListener2"); + } + + public void onTimeout(AsyncEvent event) throws IOException { + event.getAsyncContext().getResponse().getWriter() + .println("in onTimeout method of ACListener2"); + event.getAsyncContext().complete(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/asynccontext/ACListenerBad.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/asynccontext/ACListenerBad.java new file mode 100644 index 0000000000..aa46f6a5bc --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/asynccontext/ACListenerBad.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2012, 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.asynccontext; + +import java.io.IOException; + +import jakarta.servlet.AsyncEvent; +import jakarta.servlet.AsyncListener; + +public final class ACListenerBad implements AsyncListener { + + public ACListenerBad() throws IOException { + throw new IOException("Make sure that ACListenerBad does not instantiate"); + } + + public void onError(AsyncEvent event) throws IOException { + event.getAsyncContext().getResponse().getWriter() + .println("in onError method of ACListenerBad"); + } + + public void onStartAsync(AsyncEvent event) throws IOException { + event.getAsyncContext().getResponse().getWriter() + .println("in onStartAsync method of ACListenerBad"); + } + + public void onComplete(AsyncEvent event) throws IOException { + // commented out as part of bug fix for: + // https://bug.oraclecorp.com/pls/bug/webbug_edit.edit_info_top?rptno=19258007 + // event.getAsyncContext().getResponse().getWriter().println("in onComplete + // method of ACListenerBad"); + } + + public void onTimeout(AsyncEvent event) throws IOException { + event.getAsyncContext().getResponse().getWriter() + .println("in onTimeout method of ACListenerBad"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/asynccontext/AsyncTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/asynccontext/AsyncTestServlet.java new file mode 100644 index 0000000000..699ba2c899 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/asynccontext/AsyncTestServlet.java @@ -0,0 +1,262 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.asynccontext; + +import java.io.IOException; + +import com.sun.ts.tests.servlet.common.servlets.HttpTCKServlet; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.AsyncListener; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class AsyncTestServlet extends HttpTCKServlet { + + // Test for AsyncContext.dispatch() + public void dispatchZeroArgTest(HttpServletRequest request, + HttpServletResponse response) throws IOException { + + String where = (String) request.getAttribute("WHERE"); + if ("ASYNC".equals(where)) { + response.getWriter().println("ASYNC_STARTED_dispatchZeroArgTest"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + } else { + response.getWriter().println("ASYNC_NOT_STARTED_dispatchZeroArgTest"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter() + .println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(); + request.setAttribute("WHERE", "ASYNC"); + ac.dispatch(); + } + } + + // Test for AsyncContext.dispatch(ServletContext, String path) + public void dispatchContextPathTest(HttpServletRequest request, + HttpServletResponse response) throws IOException { + String path = "/async/AsyncTests?testname=asyncTest"; + + response.getWriter().println("ASYNC_NOT_STARTED_dispatchContextPathTest"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + AsyncContext ac = request.startAsync(); + ac.dispatch(request.getServletContext(), path); + } + + // Test for AsyncContext.getRequest() + public void getRequestTest(HttpServletRequest request, + HttpServletResponse response) throws IOException { + String path = "/async/AsyncTests?testname=asyncTest"; + + AsyncContext ac = request.startAsync(); + if (ac.getRequest() == request) { + response.getWriter().println("getRequest() worked. Test PASSED."); + } else { + response.getWriter() + .println("getRequest() didnot work as expected. Test FAILED."); + } + ac.complete(); + } + + // Test for AsyncContext.createListener and + // AsyncContext.addListener(AsyncListener) + public void asyncListenerTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + AsyncContext ac = request.startAsync(); + AsyncListener acl = ac.createListener( + com.sun.ts.tests.servlet.api.jakarta_servlet_http.asynccontext.ACListener.class); + ac.addListener(acl); + + ac.complete(); + } + + // Test for AsyncContext.setTimeout and AsyncContext.getTimeout + public void timeOutTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + long timeout_set = 5015L; + long timeout_actual; + + AsyncContext ac = request.startAsync(); + response.getWriter().println("Default timeout: " + ac.getTimeout()); + + ac.setTimeout(timeout_set); + timeout_actual = ac.getTimeout(); + + if (timeout_actual == timeout_set) { + response.getWriter().println("Test PASSED."); + } else { + response.getWriter() + .println("Test FAILED. setTimeout to " + timeout_set); + response.getWriter().println("getTimeout returned " + timeout_actual); + } + + ac.complete(); + } + + // Test for AsyncContext.createListener, + // AsyncContext.addListener(AsyncListener), and timeout + public void timeOutTest1(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + long timeout_set = 5015L; + + AsyncContext ac = request.startAsync(); + response.getWriter().println("Default timeout: " + ac.getTimeout()); + AsyncListener acl2 = ac.createListener( + com.sun.ts.tests.servlet.api.jakarta_servlet_http.asynccontext.ACListener2.class); + ac.addListener(acl2); + + ac.setTimeout(timeout_set); + + try { + Thread.sleep(timeout_set * 2); + } catch (InterruptedException ex) { + response.getWriter() + .println("Test FAILED with exception: " + ex.getMessage()); + } + } + + // Negative test for AsyncContext.createListener + public void asyncListenerTest1(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + long timeout_set = 5015L; + + AsyncContext ac = request.startAsync(); + response.getWriter().println("Default timeout: " + ac.getTimeout()); + + try { + AsyncListener acl = ac.createListener( + com.sun.ts.tests.servlet.api.jakarta_servlet_http.asynccontext.ACListenerBad.class); + response.getWriter() + .println("Test FAILED without throwing expected exception."); + } catch (ServletException ex) { + response.getWriter() + .println("Test PASSED with exception: " + ex.getMessage()); + } catch (Exception ex1) { + response.getWriter().println( + "Test FAILED with wrong type exception: " + ex1.getMessage()); + } + ac.complete(); + } + + // Test for AsyncContext.createListener and + // AsyncContext.addListener(AsyncListener, ServletRequest, ServletResponse) + public void asyncListenerTest2(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + AsyncContext ac = request.startAsync(); + AsyncListener acl = ac.createListener( + com.sun.ts.tests.servlet.api.jakarta_servlet_http.asynccontext.ACListener.class); + ac.addListener(acl, request, response); + + ac.complete(); + } + + // Test for AsyncContext.hasOriginalRequestAndResponse() + public void originalRequestTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + AsyncContext ac = request.startAsync(); + if (ac.hasOriginalRequestAndResponse()) { + response.getWriter().println( + "Test PASSED. AsyncContext.hasOriginalRequestAndRespons()=true"); + } else { + response.getWriter().println( + "Test FAILED. AsyncContext.hasOriginalRequestAndRespons()=false"); + } + ac.complete(); + } + + // Test for AsyncContext.hasOriginalRequestAndResponse() + public void originalRequestTest1(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + AsyncContext ac = request.startAsync(request, response); + if (ac.hasOriginalRequestAndResponse()) { + response.getWriter().println( + "Test PASSED. AsyncContext.hasOriginalRequestAndRespons()=true"); + } else { + response.getWriter().println( + "Test FAILED. AsyncContext.hasOriginalRequestAndRespons()=false"); + } + ac.complete(); + } + + // Negative test for AsyncContext.hasOriginalRequestAndResponse() + public void originalRequestTest2(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + AsyncContext ac = request.startAsync(new RequestWrapper(request), + new ResponseWrapper(response)); + if (ac.hasOriginalRequestAndResponse()) { + response.getWriter().println( + "Test FAILED. AsyncContext.hasOriginalRequestAndRespons()=true"); + } else { + response.getWriter().println( + "Test PASSED. AsyncContext.hasOriginalRequestAndRespons()=false"); + } + ac.complete(); + } + + // Negative test for AsyncContext.hasOriginalRequestAndResponse() + public void originalRequestTest3(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + AsyncContext ac = request.startAsync(new RequestWrapper(request), response); + if (ac.hasOriginalRequestAndResponse()) { + response.getWriter().println( + "Test FAILED. AsyncContext.hasOriginalRequestAndRespons()=true"); + } else { + response.getWriter().println( + "Test PASSED. AsyncContext.hasOriginalRequestAndRespons()=false"); + } + ac.complete(); + } + + // Negative test for AsyncContext.hasOriginalRequestAndResponse() + public void originalRequestTest4(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + AsyncContext ac = request.startAsync(request, + new ResponseWrapper(response)); + if (ac.hasOriginalRequestAndResponse()) { + response.getWriter().println( + "Test FAILED. AsyncContext.hasOriginalRequestAndRespons()=true"); + } else { + response.getWriter().println( + "Test PASSED. AsyncContext.hasOriginalRequestAndRespons()=false"); + } + ac.complete(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/asynccontext/AsyncTests.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/asynccontext/AsyncTests.java new file mode 100644 index 0000000000..44ee9f6d9b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/asynccontext/AsyncTests.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.asynccontext; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class AsyncTests extends HttpServlet { + + private static final String TEST_HEADER = "testname"; + + private static final Class[] TEST_ARGS = { HttpServletRequest.class, + HttpServletResponse.class }; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws ServletException, IOException { + String test = req.getParameter(TEST_HEADER); + try { + Method method = this.getClass().getMethod(test, TEST_ARGS); + method.invoke(this, new Object[] { req, res }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + } + + public void asyncTest(HttpServletRequest request, + HttpServletResponse response) throws IOException { + response.getWriter().println("ASYNC_STARTED_asyncTest"); + response.getWriter() + .println("IsAsyncSupported=" + request.isAsyncSupported()); + response.getWriter().println("IsAsyncStarted=" + request.isAsyncStarted()); + response.getWriter() + .println("DispatcherType=" + request.getDispatcherType()); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/asynccontext/RequestWrapper.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/asynccontext/RequestWrapper.java new file mode 100644 index 0000000000..2fd0c2c68d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/asynccontext/RequestWrapper.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.asynccontext; + +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletRequestWrapper; + +public class RequestWrapper extends HttpServletRequestWrapper { + + protected HttpServletRequest origRequest = null; + + public RequestWrapper(HttpServletRequest request) { + super(request); + origRequest = request; + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/asynccontext/ResponseWrapper.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/asynccontext/ResponseWrapper.java new file mode 100644 index 0000000000..f5d290e498 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/asynccontext/ResponseWrapper.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.asynccontext; + +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletResponseWrapper; + +public class ResponseWrapper extends HttpServletResponseWrapper { + + protected HttpServletResponse origResponse = null; + + public ResponseWrapper(HttpServletResponse response) { + super(response); + response.setContentType("text/plain"); + origResponse = response; + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/asynccontext/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/asynccontext/URLClient.java new file mode 100644 index 0000000000..c9f45d8e91 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/asynccontext/URLClient.java @@ -0,0 +1,290 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.asynccontext; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("AsyncTestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_jsh_asynccontext_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(ACListener.class, ACListener1.class, ACListener2.class, ACListenerBad.class, + AsyncTests.class, AsyncTestServlet.class, RequestWrapper.class, ResponseWrapper.class) + .setWebXML(URLClient.class.getResource("servlet_jsh_asynccontext_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* + * Run test + */ + /* + * Test set up: + * + * Define two servets AsyncTestServlet and AsyncTests that supports async in + * web.xml; Define three AsyncListeners using annotation: ACListener, + * ACListener1, ACListenerBad; - ACListenerBad does not instantiate; Define a + * ServletRequestWrapper that wraps the original request; Define a + * ServletResponseWrapper that wraps the original response; + * + */ + + /* + * @testName: dispatchZeroArgTest + * + * @assertion_ids: Servlet:JAVADOC:639; Servlet:JAVADOC:639.2; + * Servlet:JAVADOC:639.4; Servlet:JAVADOC:703; Servlet:JAVADOC:707; + * Servlet:JAVADOC:708; Servlet:JAVADOC:710; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which supports async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet + * ServletRequest.startAsync(); call ac.dispatch(); call + * ServletRequest.isAsyncSupported() call ServletRequest.isAsyncStarted() call + * ServletRequest.getDispatcherType() verifies all work accordingly. + */ + @Test + public void dispatchZeroArgTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "dispatchZeroArgTest"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_dispatchZeroArgTest|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "ASYNC_STARTED_dispatchZeroArgTest|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: dispatchZeroArgTest1 + * + * @assertion_ids: Servlet:JAVADOC:639; Servlet:JAVADOC:639.2; + * Servlet:JAVADOC:639.4; Servlet:JAVADOC:703; Servlet:JAVADOC:707; + * Servlet:JAVADOC:708; Servlet:JAVADOC:710; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which supports async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet + * ServletRequest.startAsync(); call ac.dispatch(); call + * ServletRequest.isAsyncSupported() call ServletRequest.isAsyncStarted() call + * ServletRequest.getDispatcherType() verifies all work accordingly. + */ + @Test + public void dispatchZeroArgTest1() throws Exception { + TEST_PROPS.setProperty(APITEST, "dispatchZeroArgTest"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_dispatchZeroArgTest|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "ASYNC_STARTED_dispatchZeroArgTest|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: dispatchContextPathTest + * + * @assertion_ids: Servlet:JAVADOC:641; + * Servlet:JAVADOC:703; Servlet:JAVADOC:707; Servlet:JAVADOC:708; + * Servlet:JAVADOC:710; + * + * @test_Strategy: Create two Servlets AsyncTestServlet and AsynTest both + * support async; Client send a request to AsyncTestServlet; StartAsync in + * AsyncTestServlet ServletRequest.startAsync(); call + * ac.dispatch(ServltContext, path to AsynTest); call + * ServletRequest.isAsyncSupported() call ServletRequest.isAsyncStarted() call + * ServletRequest.getDispatcherType() verifies all work accordingly. + */ + @Test + public void dispatchContextPathTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "dispatchContextPathTest"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_dispatchContextPathTest|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "ASYNC_STARTED_asyncTest|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: getRequestTest + * @assertion_ids: Servlet:JAVADOC:642; + * Servlet:JAVADOC:710; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet + * ServletRequest.startAsync(); call ac.getRequest() verifies it works. + */ + @Test + public void getRequestTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getRequestTest"); + invoke(); + } + + /* + * @testName: asyncListenerTest1 + * + * @assertion_ids: Servlet:JAVADOC:649; Servlet:JAVADOC:710; + * Servlet:JAVADOC:846; Servlet:JAVADOC:866; Servlet:JAVADOC:873; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Create an AsyncListenerBad; Client send a request to AsyncTestServlet; + * StartAsync in AsyncTestServlet; AsyncContext.createistener(clazz) verifies + * ServletException is thrown when clazz fails to be instantiated. + */ + @Test + public void asyncListenerTest1() throws Exception { + TEST_PROPS.setProperty(APITEST, "asyncListenerTest1"); + invoke(); + } + + /* + * @testName: timeOutTest + * + * @assertion_ids: Servlet:JAVADOC:710; Servlet:JAVADOC:846; + * Servlet:JAVADOC:868; Servlet:JAVADOC:869; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet; + * AsyncContext.setTimeout(L) verifies it works using getTimeout. + */ + @Test + public void timeOutTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "timeOutTest"); + invoke(); + } + + /* + * @testName: timeOutTest1 + * + * @assertion_ids: Servlet:JAVADOC:651; Servlet:JAVADOC:710; + * Servlet:JAVADOC:846; Servlet:JAVADOC:868; Servlet:JAVADOC:869; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet; + * AsyncContext.setTimeout(L) verifies it works by letting it timeout. + */ + @Test + public void timeOutTest1() throws Exception { + TEST_PROPS.setProperty(APITEST, "timeOutTest1"); + TEST_PROPS.setProperty(SEARCH_STRING, "in onTimeout method of ACListener2"); + TEST_PROPS.setProperty(STATUS_CODE, "-1"); + invoke(); + } + + /* + * @testName: originalRequestTest + * + * @assertion_ids: Servlet:JAVADOC:638; Servlet:JAVADOC:644; + * Servlet:JAVADOC:710; Servlet:JAVADOC:710.2; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; Call ServletRequest.startAsync() + * in AsyncTestServlet; verifies AsyncContext.hasOriginalRequestAndResponse + * works. + */ + @Test + public void originalRequestTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "originalRequestTest"); + invoke(); + } + + /* + * @testName: originalRequestTest1 + * + * @assertion_ids: Servlet:JAVADOC:638; Servlet:JAVADOC:644; + * Servlet:JAVADOC:712; Servlet:JAVADOC:712.1; Servlet:JAVADOC:712.3; + * * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; Call + * ServletRequest.startAsync(ServletRequest, ServletResponse); verifies + * AsyncContext.hasOriginalRequestAndResponse works. + */ + @Test + public void originalRequestTest1() throws Exception { + TEST_PROPS.setProperty(APITEST, "originalRequestTest1"); + invoke(); + } + + /* + * @testName: originalRequestTest2 + * + * @assertion_ids: Servlet:JAVADOC:638; Servlet:JAVADOC:644; + * Servlet:JAVADOC:712; Servlet:JAVADOC:712.1; Servlet:JAVADOC:712.3; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; Call + * ServletRequest.startAsync(ServletRequestWrapper, ServletResponseWrapper); + * verifies AsyncContext.hasOriginalRequestAndResponse works. + */ + @Test + public void originalRequestTest2() throws Exception { + TEST_PROPS.setProperty(APITEST, "originalRequestTest2"); + invoke(); + } + + /* + * @testName: originalRequestTest3 + * + * @assertion_ids: Servlet:JAVADOC:638; Servlet:JAVADOC:644; + * Servlet:JAVADOC:712; Servlet:JAVADOC:712.1; Servlet:JAVADOC:712.3; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; Call + * ServletRequest.startAsync(ServletRequestWrapper, ServletResponse); verifies + * AsyncContext.hasOriginalRequestAndResponse works. + */ + @Test + public void originalRequestTest3() throws Exception { + TEST_PROPS.setProperty(APITEST, "originalRequestTest3"); + invoke(); + } + + /* + * @testName: originalRequestTest4 + * + * @assertion_ids: Servlet:JAVADOC:638; Servlet:JAVADOC:644; + * Servlet:JAVADOC:712; Servlet:JAVADOC:712.1; Servlet:JAVADOC:712.3; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; Call + * ServletRequest.startAsync(ServletRequest, ServletResponseWrapper); verifies + * AsyncContext.hasOriginalRequestAndResponse works. + */ + @Test + public void originalRequestTest4() throws Exception { + TEST_PROPS.setProperty(APITEST, "originalRequestTest4"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/asynccontext/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/asynccontext/build.xml new file mode 100644 index 0000000000..e41df4c306 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/asynccontext/build.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/asynccontext/servlet_jsh_asynccontext_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/asynccontext/servlet_jsh_asynccontext_web.xml new file mode 100644 index 0000000000..5cc18e7d84 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/asynccontext/servlet_jsh_asynccontext_web.xml @@ -0,0 +1,43 @@ + + + + + SerJaxSerHasynccontext + + AsyncTestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.asynccontext.AsyncTestServlet + true + + + AsyncTests + com.sun.ts.tests.servlet.api.jakarta_servlet_http.asynccontext.AsyncTests + true + + + AsyncTestServlet + /AsyncTestServlet + + + AsyncTests + /async/AsyncTests + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/build.xml new file mode 100644 index 0000000000..02f6ac16fd --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/build.xml @@ -0,0 +1,22 @@ + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/cookie/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/cookie/TestServlet.java new file mode 100644 index 0000000000..28ae44470a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/cookie/TestServlet.java @@ -0,0 +1,737 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2001, 2021 Oracle and/or its affiliates and others. + * * All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.cookie; + +import java.io.IOException; +import java.io.PrintWriter; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Map; +import java.util.TimeZone; + +import com.sun.ts.tests.servlet.common.servlets.HttpTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.Cookie; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class TestServlet extends HttpTCKServlet { + + public static String CUSTOM_HEADER_DATE_FORMAT = "yyyy-MM-dd HH:mm"; + + public void cloneTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + + Cookie testCookie = new Cookie("cookie1", "value1"); + String cookieName = testCookie.getName(); + + Cookie testCookieclone = (Cookie) testCookie.clone(); + String cloneName = testCookieclone.getName(); + + if (!cloneName.equals(cookieName)) { + passed = false; + pw.println("Expected = " + cookieName); + pw.println("Actual =" + cloneName); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public void constructorTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + + String name1 = "name1"; + String value1 = "value1"; + Cookie testCookie = new Cookie(name1, value1); + + String cookieName = testCookie.getName(); + String cookieValue = testCookie.getValue(); + + if ((!cookieName.equals(name1)) || (!cookieValue.equals(value1))) { + passed = false; + pw.println("Expected = " + name1 + "," + value1); + pw.println("Actual = " + cookieName + "," + cookieValue); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public void constructorIllegalArgumentExceptionTest( + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + String[] invalidNameValues = { ",test", ";test", " test", "\ttest", "\ntest" }; + + PrintWriter pw = response.getWriter(); + + for (int i = 0; i < invalidNameValues.length; i++) { + pw.println("Attempting to create new Cookie with invalid name " + + "value: '" + invalidNameValues[i] + "'"); + try { + new Cookie(invalidNameValues[i], "someValue"); + pw.println("Test FAILED. IllegalArgumentException not thrown" + + " for invalid name value."); + } catch (Throwable t) { + if (!(t instanceof IllegalArgumentException)) { + pw.println("Test FAILED. Exception thrown by Cookie " + + "constructor, but it wasn't an instance of IllegalArgumentExcepiton."); + pw.println("Actual Exception type: " + t.getClass().getName()); + } else { + pw.println("IllegalArgumentException thrown for invalid value: '" + + invalidNameValues[i] + "'"); + } + } + pw.println(); + } + } + + public void getCommentTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + boolean passed = false; + Cookie testCookie = new Cookie("name1", "value1"); + + // set and get + testCookie.setComment("This is a comment"); + String result = testCookie.getComment(); + + response.addCookie(testCookie); + if (result == null) { + passed = true; + } else { + passed = false; + pw.println("getComment() returned an incorrect result"); + pw.println("Expected null value"); + pw.println("Actual = |" + result + "| "); + } + ServletTestUtil.printResult(pw, passed); + + } + + public void getCommentNullTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + boolean passed = false; + Cookie testCookie = new Cookie("name1", "value1"); + String result = testCookie.getComment(); + + if (result != null) { + passed = false; + pw.println("getComment() returned a non-null value"); + pw.println("Actual = |" + result + "|"); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public void getDomainTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + Cookie[] cookie = request.getCookies(); + // RFC 6265 treats the domain attribute of an RFC 2109 cookie as a separate + // cookie + int index = ServletTestUtil.findCookie(cookie, "$Domain"); + if (index >= 0) { + String host = request.getHeader("host"); + int col = host.indexOf(':'); + if (col > -1) { + host = host.substring(0, col).trim(); + } + + // get + String result = cookie[index].getValue(); + if (result != null) { + if (!result.equalsIgnoreCase(host)) { + passed = false; + pw.println("getDomain() returned an incorrect result"); + pw.println("Expected = \"" + host + "\""); + pw.println("Actual = \"" + result + "\""); + } else { + passed = true; + } + } else { + passed = false; + pw.println("getDomain() returned a null result "); + } + } else { + passed = false; + pw.println("Error: The expected cookie was not received from the client"); + } + ServletTestUtil.printResult(pw, passed); + } + + public void getMaxAgeTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = true; + Cookie testCookie = new Cookie("name1", "value1"); + int expectedResult = 300; + // set and get + testCookie.setMaxAge(expectedResult); + int result = testCookie.getMaxAge(); + + if (result != expectedResult) { + passed = false; + pw.println("getMaxAge() returned an incorrect result "); + pw.println("Expected = " + expectedResult + " "); + pw.println("Actual = |" + result + "| "); + + } + pw.println("default test"); + testCookie = new Cookie("name2", "value1"); + expectedResult = -1; + // we expect a negative value + result = testCookie.getMaxAge(); + + if (result != expectedResult) { + passed = false; + pw.println("getMaxAge() returned an incorrect result"); + pw.println("Expected = " + expectedResult + ""); + pw.println("Actual = |" + result + "|"); + } + ServletTestUtil.printResult(pw, passed); + } + + public void getNameTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + Cookie[] cookie = request.getCookies(); + int index = ServletTestUtil.findCookie(cookie, "name1"); + if (index < 0) { + passed = false; + pw.println("Error: The expected cookie was not received from the client"); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public void getPathTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + Cookie[] cookie = request.getCookies(); + // RFC 6265 treats the path attribute of an RFC 2109 cookie as a separate + // cookie + int index = ServletTestUtil.findCookie(cookie, "$Path"); + if (index >= 0) { + String expectedResult = request.getContextPath(); + String result = cookie[index].getValue(); + if (result != null) { + if (!result.equals(expectedResult)) { + passed = false; + pw.println("getPath() returned an incorrect result "); + pw.println("Expected = " + expectedResult + " "); + pw.println("Actual = |" + result + "| "); + } else { + passed = true; + } + } else { + passed = false; + pw.println("Error: getPath() returned a null result"); + } + } else { + passed = false; + pw.println("Error: The expected cookie was not received from the client"); + } + ServletTestUtil.printResult(pw, passed); + } + + public void getSecureTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + Cookie testCookie = new Cookie("name1", "value1"); + + boolean expectedResult = false; + boolean result = testCookie.getSecure(); + + response.addCookie(testCookie); + if (result != expectedResult) { + passed = false; + pw.println("getSecure() returned an incorrect result "); + pw.println("Expected = " + expectedResult + " "); + pw.println("Actual = |" + result + "| "); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public void getValueTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + Cookie[] cookie = request.getCookies(); + int index = ServletTestUtil.findCookie(cookie, "name1"); + if (index >= 0) { + String expectedResult = "value1"; + String result = cookie[index].getValue(); + if (result != null) { + if (!result.equals(expectedResult)) { + passed = false; + pw.println("getValue() returned an incorrect result "); + pw.println("Expected = " + expectedResult + " "); + pw.println("Actual = |" + result + "| "); + } else { + passed = true; + } + } else { + passed = false; + pw.println("Error: getPath() returned a null result"); + } + } else { + passed = false; + pw.println("Error: The expected cookie was not received from the client"); + } + ServletTestUtil.printResult(pw, passed); + } + + public void getVersionVer0Test(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + // Version should be hard-coded to zero + PrintWriter pw = response.getWriter(); + boolean passed = false; + Cookie[] cookie = request.getCookies(); + int index = ServletTestUtil.findCookie(cookie, "name1"); + if (index >= 0) { + int expectedResult = 0; + int result = cookie[index].getVersion(); + if (result != expectedResult) { + passed = false; + pw.println("getVersion() returned incorrect result "); + pw.println("Expected = " + expectedResult + " "); + pw.println("Actual = |" + result + "| "); + } else { + passed = true; + } + } else { + passed = false; + pw.println("Error: The expected cookie was not received from the client"); + } + ServletTestUtil.printResult(pw, passed); + } + + public void getVersionVer1Test(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + // Version should be hard-coded to zero + PrintWriter pw = response.getWriter(); + boolean passed = false; + Cookie[] cookie = request.getCookies(); + int index = ServletTestUtil.findCookie(cookie, "name1"); + if (index >= 0) { + int expectedResult = 0; + int result = cookie[index].getVersion(); + if (result != expectedResult) { + passed = false; + pw.println("getVersion() returned incorrect result "); + pw.println("Expected = " + expectedResult + " "); + pw.println("Actual = |" + result + "| "); + } else { + passed = true; + } + } else { + passed = false; + pw.println("Error: The expected cookie was not received from the client"); + } + ServletTestUtil.printResult(pw, passed); + } + + public void setDomainTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + Cookie testCookie = new Cookie("name1", "value1"); + testCookie.setVersion(0); + + String expectedResult = "ENG.COM"; + testCookie.setDomain(expectedResult); + String result = testCookie.getDomain(); + + response.addCookie(testCookie); + if (result != null) { + if (!result.equalsIgnoreCase(expectedResult)) { + passed = false; + pw.println("setDomain(" + expectedResult + + ") did not set the domain properly "); + pw.println("Expected = " + expectedResult + " "); + pw.println("Actual = |" + result + "| "); + } else { + passed = true; + } + } else { + passed = false; + pw.println("getDomain() returned a null result "); + } + ServletTestUtil.printResult(pw, passed); + } + + public void setMaxAgePositiveTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + Cookie testCookie = new Cookie("name1", "value1"); + testCookie.setVersion(0); + + testCookie.setMaxAge(2); + // Use a custom format to ensure Locale independence + SimpleDateFormat sdf = new SimpleDateFormat(CUSTOM_HEADER_DATE_FORMAT); + sdf.setTimeZone(TimeZone.getTimeZone("GMT")); + Date currDate = new Date(); + String dateString = sdf.format(currDate); + + response.addCookie(testCookie); + response.addHeader("testDate", dateString); + + ServletTestUtil.printResult(pw, true); + } + + public void setMaxAgeZeroTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + Cookie testCookie = new Cookie("name1", "value1"); + testCookie.setVersion(0); + + testCookie.setMaxAge(0); + response.addCookie(testCookie); + + ServletTestUtil.printResult(pw, true); + } + + public void setMaxAgeNegativeTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + Cookie testCookie = new Cookie("name1", "value1"); + testCookie.setVersion(0); + + testCookie.setMaxAge(-1); + response.addCookie(testCookie); + + ServletTestUtil.printResult(pw, true); + } + + public void setPathTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + Cookie testCookie = new Cookie("name1", "value1"); + testCookie.setVersion(0); + + String expectedResult = "\"/servlet_jsh_cookie_web\""; + testCookie.setPath(expectedResult); + String result = testCookie.getPath(); + + response.addCookie(testCookie); + if (result != null) { + if (!result.equals(expectedResult)) { + passed = false; + pw.println( + "setPath(" + expectedResult + ") returned an incorrect result"); + pw.println("Expected = " + expectedResult + " "); + pw.println("Actual = |" + result + "| "); + } else { + passed = true; + } + } else { + passed = false; + pw.println("getPath() returned a null result "); + } + ServletTestUtil.printResult(pw, passed); + } + + public void setSecureVer0Test(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + Cookie testCookie = new Cookie("name1", "value1"); + testCookie.setVersion(0); + + boolean expectedResult = false; + boolean result = testCookie.getSecure(); + + response.addCookie(testCookie); + if (result != expectedResult) { + passed = false; + pw.println("getSecure() returned an incorrect result "); + pw.println("Expected = " + expectedResult + " "); + pw.println("Actual = |" + result + "| "); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public void setSecureVer1Test(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + Cookie testCookie = new Cookie("name1", "value1"); + testCookie.setVersion(1); + + boolean expectedResult = false; + boolean result = testCookie.getSecure(); + + response.addCookie(testCookie); + if (result != expectedResult) { + passed = false; + pw.println("getSecure() returned an incorrect result "); + pw.println("Expected = " + expectedResult + " "); + pw.println("Actual = |" + result + "| "); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public void setValueVer0Test(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + Cookie testCookie = new Cookie("name1", "value1"); + testCookie.setVersion(0); + + String expectedResult = "value2"; + testCookie.setValue(expectedResult); + String result = testCookie.getValue(); + + response.addCookie(testCookie); + if (result != null) { + if (!result.equals(expectedResult)) { + passed = false; + pw.println( + "setValue(" + expectedResult + ") did not set the value properly"); + pw.println("Expected = " + expectedResult + " "); + pw.println("Actual = |" + result + "| "); + } else { + passed = true; + } + } else { + passed = false; + pw.println("getValue() returned a null result "); + } + ServletTestUtil.printResult(pw, passed); + } + + public void setValueVer1Test(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + Cookie testCookie = new Cookie("name1", "value1"); + testCookie.setVersion(1); + + String expectedResult = "value2"; + testCookie.setValue(expectedResult); + String result = testCookie.getValue(); + + response.addCookie(testCookie); + if (result != null) { + if (!result.equals(expectedResult)) { + passed = false; + pw.println( + "setValue(" + expectedResult + ") did not set the value properly"); + pw.println("Expected = " + expectedResult + " "); + pw.println("Actual = |" + result + "| "); + } else { + passed = true; + } + } else { + passed = false; + pw.println("getValue() returned a null result "); + } + ServletTestUtil.printResult(pw, passed); + } + + public void setVersionVer0Test(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + // Expected to be hard-coded to zero + PrintWriter pw = response.getWriter(); + boolean passed = false; + Cookie testCookie = new Cookie("name1", "value1"); + int expectedResult = 0; + testCookie.setVersion(expectedResult); + + int result = testCookie.getVersion(); + + response.addCookie(testCookie); + if (result != expectedResult) { + passed = false; + pw.println("setVersion(" + expectedResult + + ") did not set the version properly"); + pw.println("Expected = " + expectedResult + " "); + pw.println("Actual = |" + result + "| "); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public void setVersionVer1Test(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + boolean passed = false; + Cookie testCookie = new Cookie("name1", "value1"); + int expectedResult = 0; + testCookie.setVersion(1); + + int result = testCookie.getVersion(); + + response.addCookie(testCookie); + if (result != expectedResult) { + passed = false; + pw.println("setVersion(" + expectedResult + + ") did not set the version properly"); + pw.println("Expected = " + expectedResult + " "); + pw.println("Actual = |" + result + "| "); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public void setAttributeTest(HttpServletRequest request, + HttpServletResponse response) throws IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = true; + Cookie testCookie = new Cookie("name1", "value1"); + + String attrName = "some-name"; + String attrValue = "some-value"; + testCookie.setAttribute(attrName, attrValue); + String result = testCookie.getAttribute(attrName); + + response.addCookie(testCookie); + if (result != null) { + if (!result.equalsIgnoreCase(attrValue)) { + passed = false; + pw.println("setAttribute(" + attrName + "," + attrValue + + ") did not set the attribute properly "); + pw.println("Expected value = " + attrValue + " "); + pw.println("Actual value = |" + result + "| "); + } + } else { + passed = false; + pw.println("getAttribute(" + attrName + ") returned a null result "); + } + ServletTestUtil.printResult(pw, passed); + } + + public void getAttributesTest(HttpServletRequest request, + HttpServletResponse response) throws IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = true; + String name = "name1"; + String value = "value1"; + Cookie testCookie = new Cookie(name, value); + + String attrName = "some-name"; + String attrValue = "some-value"; + testCookie.setAttribute(attrName, attrValue); + Map result = testCookie.getAttributes(); + + response.addCookie(testCookie); + if (result != null) { + if (result.size() == 1) { + if (!result.get(attrName).equals(attrValue)) { + passed = false; + pw.println("getAttributes() returned a map that contained [" + result.get(attrName) + + "] as the value for key [" + attrName + "] rather than [" + attrValue + "]"); + } + } else { + passed = false; + pw.println("getAttributes() returned a map of size [" + result.size() + "] rather than 1."); + } + } else { + passed = false; + pw.println("getAttributes() returned a null result "); + } + ServletTestUtil.printResult(pw, passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/cookie/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/cookie/URLClient.java new file mode 100644 index 0000000000..027b4a49dd --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/cookie/URLClient.java @@ -0,0 +1,484 @@ +/* + * Copyright (c) 2006, 2021 Oracle and/or its affiliates and others. + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.cookie; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.request.HttpRequest; +import com.sun.ts.tests.servlet.common.request.HttpResponse; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.common.util.Data; +import org.apache.commons.httpclient.Cookie; +import org.apache.commons.httpclient.Header; +import org.apache.commons.httpclient.cookie.CookiePolicy; +import org.apache.commons.httpclient.cookie.CookieSpec; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.TimeZone; + +public class URLClient extends AbstractUrlClient { + + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + + return ShrinkWrap.create(WebArchive.class, "servlet_jsh_cookie_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_jsh_cookie_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + private int findCookie(Cookie[] cookie, String name) { + boolean found = false; + int i = 0; + if (cookie != null) { + while ((!found) && (i < cookie.length)) { + if (cookie[i].getName().equals(name)) { + found = true; + } else { + i++; + } + } + } else { + found = false; + } + if (found) { + return i; + } else { + return -1; + } + } + + /* Run test */ + + /* + * @testName: cloneTest + * + * @assertion_ids: Servlet:JAVADOC:453 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void cloneTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "cloneTest"); + invoke(); + } + + /* + * @testName: constructorTest + * + * @assertion_ids: Servlet:JAVADOC:434 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void constructorTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "constructorTest"); + invoke(); + } + + /* + * @testName: constructorIllegalArgumentExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:628 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void constructorIllegalArgumentExceptionTest() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET /servlet_jsh_cookie_web/TestServlet?testname=constructorIllegalArgumentExceptionTest HTTP/1.1"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "Test FAILED"); + invoke(); + } + + /* + * @testName: getCommentTest + * + * @assertion_ids: Servlet:JAVADOC:436 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void getCommentTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getCommentTest"); + invoke(); + } + + /* + * @testName: getCommentNullTest + * + * @assertion_ids: Servlet:JAVADOC:437 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void getCommentNullTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getCommentNullTest"); + invoke(); + } + + /* + * @testName: getDomainTest + * + * @assertion_ids: Servlet:JAVADOC:439 + * + * @test_Strategy: Client sends a version 0 and 1 cookie to the servlet. + * Servlet verifies values and returns result to client + */ + @Test + public void getDomainTest() throws Exception { + // version 1 + TEST_PROPS.setProperty(REQUEST_HEADERS, + "Cookie: $Version=1; name1=value1; $Domain=" + _hostname + + "; $Path=/servlet_jsh_cookie_web"); + TEST_PROPS.setProperty(APITEST, "getDomainTest"); + invoke(); + + } + + /* + * @testName: getMaxAgeTest + * + * @assertion_ids: Servlet:JAVADOC:443 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void getMaxAgeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getMaxAgeTest"); + invoke(); + } + + /* + * @testName: getNameTest + * + * @assertion_ids: Servlet:JAVADOC:448 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void getNameTest() throws Exception { + // version 0 + TEST_PROPS.setProperty(REQUEST_HEADERS, "Cookie: name1=value1; Domain=" + + _hostname + "; Path=/servlet_jsh_cookie_web"); + TEST_PROPS.setProperty(APITEST, "getNameTest"); + invoke(); + // version 1 + TEST_PROPS.setProperty(REQUEST_HEADERS, + "Cookie: $Version=1; name1=value1; $Domain=" + _hostname + + "; $Path=/servlet_jsh_cookie_web"); + TEST_PROPS.setProperty(APITEST, "getNameTest"); + invoke(); + } + + /* + * @testName: getPathTest + * + * @assertion_ids: Servlet:JAVADOC:445 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void getPathTest() throws Exception { + TEST_PROPS.setProperty(REQUEST_HEADERS, + "Cookie: $Version=1; name1=value1; $Domain=" + _hostname + + "; $Path=/servlet_jsh_cookie_web"); + TEST_PROPS.setProperty(APITEST, "getPathTest"); + invoke(); + } + + /* + * @testName: getSecureTest + * + * @assertion_ids: Servlet:JAVADOC:447 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void getSecureTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getSecureTest"); + invoke(); + } + + /* + * @testName: getValueTest + * + * @assertion_ids: Servlet:JAVADOC:450 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void getValueTest() throws Exception { + // version 0 + TEST_PROPS.setProperty(REQUEST_HEADERS, "Cookie: name1=value1; Domain=" + + _hostname + "; Path=/servlet_jsh_cookie_web"); + TEST_PROPS.setProperty(APITEST, "getValueTest"); + invoke(); + // version 1 + TEST_PROPS.setProperty(REQUEST_HEADERS, + "Cookie: $Version=1; name1=value1; $Domain=" + _hostname + + "; $Path=/servlet_jsh_cookie_web"); + TEST_PROPS.setProperty(APITEST, "getValueTest"); + invoke(); + } + + /* + * @testName: getVersionTest + * + * @assertion_ids: Servlet:JAVADOC:451 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void getVersionTest() throws Exception { + // version 0 + TEST_PROPS.setProperty(REQUEST_HEADERS, "Cookie: name1=value1; Domain=" + + _hostname + "; Path=/servlet_jsh_cookie_web"); + TEST_PROPS.setProperty(APITEST, "getVersionVer0Test"); + invoke(); + // version 1 + TEST_PROPS.setProperty(REQUEST_HEADERS, + "Cookie: $Version=1; name1=value1; $Domain=" + _hostname + + "; $Path=/servlet_jsh_cookie_web"); + TEST_PROPS.setProperty(APITEST, "getVersionVer1Test"); + invoke(); + } + + /* + * @testName: setDomainTest + * + * @assertion_ids: Servlet:JAVADOC:438 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void setDomainTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setDomainTest"); + invoke(); + } + + /* + * @testName: setMaxAgePositiveTest + * + * @assertion_ids: Servlet:JAVADOC:440 + * + * @test_Strategy: Servlet sets values and client verifies them + */ + @Test + public void setMaxAgePositiveTest() throws Exception { + String testName = "setMaxAgePositiveTest"; + HttpResponse response = null; + String dateHeader = null; + int index = -1; + Date expiryDate = null; + String body = null; + + HttpRequest request = new HttpRequest("GET " + getContextRoot() + "/" + + getServletName() + "?testname=" + testName + " HTTP/1.1", _hostname, + _port); + + try { + response = request.execute(); + dateHeader = response.getResponseHeader("testDate").toString(); + CookieSpec spec = CookiePolicy.getCookieSpec(CookiePolicy.NETSCAPE); + + logger.trace("Found " + response.getResponseHeaders("Set-Cookie").length + + " set-cookie entry"); + + boolean foundcookie = false; + Header[] CookiesHeader = response.getResponseHeaders("Set-Cookie"); + int i = 0; + while (i < CookiesHeader.length) { + logger.trace("Checking set-cookiei " + i + ":" + CookiesHeader[i]); + Cookie[] cookies = spec.parse(".eng.com", _port, getServletName(), + false, CookiesHeader[i]); + index = findCookie(cookies, "name1"); + if (index >= 0) { + expiryDate = cookies[index].getExpiryDate(); + body = response.getResponseBodyAsString(); + foundcookie = true; + break; + } + i++; + } + + if (!foundcookie) + throw new Exception("The test cookie was not located in the response"); + } catch (Throwable t) { + throw new Exception("Exception occurred:" + t, t); + } + + // put expiry date into GMT + SimpleDateFormat sdf = new SimpleDateFormat(TestServlet.CUSTOM_HEADER_DATE_FORMAT); + sdf.setTimeZone(TimeZone.getTimeZone("GMT")); + String resultStringDate = sdf.format(expiryDate); + try { + Date resultDate = sdf.parse(resultStringDate); + Date expectedDate = sdf + .parse(dateHeader.substring(dateHeader.indexOf(": ") + 2).trim()); + if (resultDate.before(expectedDate)) { + throw new Exception("The expiry date was incorrect, expected =" + + expectedDate + ", result = " + resultDate); + } + } catch (Throwable t) { + throw new Exception("Exception occurred: " + t); + } + + if (body.indexOf(Data.PASSED) == -1) { + throw new Exception("The string: " + Data.PASSED + " not found in response"); + } + } + + /* + * @testName: setMaxAgeZeroTest + * + * @assertion_ids: Servlet:JAVADOC:442 + * + * @test_Strategy: Servlet sets values and client verifies them + */ + @Test + public void setMaxAgeZeroTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setMaxAgeZeroTest"); + TEST_PROPS.setProperty(EXPECTED_HEADERS, "Set-Cookie:name1=value1##Max-Age=0"); + invoke(); + } + + /* + * @testName: setMaxAgeNegativeTest + * + * @assertion_ids: Servlet:JAVADOC:441 + * + * @test_Strategy: Servlet sets values and client verifies them + */ + @Test + public void setMaxAgeNegativeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setMaxAgeNegativeTest"); + TEST_PROPS.setProperty(EXPECTED_HEADERS, + "Set-Cookie:name1=value1##!Expire##!Max-Age"); + invoke(); + } + + /* + * @testName: setPathTest + * + * @assertion_ids: Servlet:JAVADOC:444 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void setPathTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setPathTest"); + TEST_PROPS.setProperty(EXPECTED_HEADERS, + "Set-Cookie:Path=\"/servlet_jsh_cookie_web\""); + invoke(); + } + + /* + * @testName: setSecureTest + * + * @assertion_ids: Servlet:JAVADOC:446 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void setSecureTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setSecureVer0Test"); + invoke(); + TEST_PROPS.setProperty(APITEST, "setSecureVer1Test"); + invoke(); + } + + /* + * @testName: setValueTest + * + * @assertion_ids: Servlet:JAVADOC:449 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void setValueTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setValueVer0Test"); + invoke(); + TEST_PROPS.setProperty(APITEST, "setValueVer1Test"); + invoke(); + } + + /* + * @testName: setVersionTest + * + * @assertion_ids: Servlet:JAVADOC:452 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void setVersionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setVersionVer0Test"); + invoke(); + TEST_PROPS.setProperty(APITEST, "setVersionVer1Test"); + invoke(); + } + + /* + * @testName: setAttributeTest + * + * @assertion_ids: + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void setAttributeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setAttributeTest"); + invoke(); + } + + /* + * @testName: getAttributesTest + * + * @assertion_ids: + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void getAttributesTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getAttributesTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/cookie/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/cookie/build.xml new file mode 100644 index 0000000000..d5488e3c92 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/cookie/build.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/cookie/servlet_jsh_cookie_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/cookie/servlet_jsh_cookie_web.xml new file mode 100644 index 0000000000..a7d2762fd0 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/cookie/servlet_jsh_cookie_web.xml @@ -0,0 +1,33 @@ + + + + + SerJaxSerHttpCookie + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.cookie.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpfilter/HttpFilterTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpfilter/HttpFilterTestServlet.java new file mode 100644 index 0000000000..98f4ffe7e6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpfilter/HttpFilterTestServlet.java @@ -0,0 +1,81 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpfilter; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class HttpFilterTestServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + pw.println("In HttpFilterTest Servlet"); + ServletTestUtil.printResult(pw, true); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpfilter/HttpFilter_Filter1.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpfilter/HttpFilter_Filter1.java new file mode 100644 index 0000000000..1b9e3eff48 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpfilter/HttpFilter_Filter1.java @@ -0,0 +1,97 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + * * [Additional notices, if required by prior licensing conditions] + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpfilter; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.http.HttpFilter; + +public final class HttpFilter_Filter1 extends HttpFilter { + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + PrintWriter pw = response.getWriter(); + // this pw.println should not get displayed, only the line going to the + // static log should be valid + pw.println("doFilter was successfully called in HttpFilter_Filter1"); + + if (getFilterConfig() == null) { + pw.println( + "doFilter of HttpFilter_Filter1 was called but this filter instance is not currently configured "); + ServletTestUtil.printResult(pw, false); + } else { + super.doFilter(request, response, chain); + } + } + + // remove the filter configuration object for this filter. + public void destroy() { + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpfilter/HttpFilter_Filter2.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpfilter/HttpFilter_Filter2.java new file mode 100644 index 0000000000..34cec32322 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpfilter/HttpFilter_Filter2.java @@ -0,0 +1,96 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + * * [Additional notices, if required by prior licensing conditions] + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpfilter; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.http.HttpFilter; + +public final class HttpFilter_Filter2 extends HttpFilter { + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + PrintWriter pw = response.getWriter(); + + pw.println("doFilter was successfully called in HttpFilter_Filter2"); + + if (getFilterConfig() == null) { + pw.println( + "doFilter of HttpFilter_Filter2 was called but this filter instance is not currently configured "); + ServletTestUtil.printResult(pw, false); + } else { + super.doFilter(request, response, chain); + } + } + + // remove the filter configuration object for this filter. + public void destroy() { + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpfilter/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpfilter/URLClient.java new file mode 100644 index 0000000000..ebe523bf66 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpfilter/URLClient.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2017, 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: URLClient.java 62833 2011-05-18 13:13:23Z djiao $ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpfilter; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_jsh_httpfilter_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(HttpFilter_Filter1.class, HttpFilter_Filter2.class, HttpFilterTestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_jsh_httpfilter_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + /* + * @testName: dofilterTest + * + * @assertion_ids: NA; + * + * @test_Strategy: Client attempts to access a servlet and both filters + * extending HttpFilter configured for that servlet should be invoked. + */ + @Test + public void dofilterTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "HttpFilterTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpfilter/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpfilter/build.xml new file mode 100644 index 0000000000..4cb43c61f3 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpfilter/build.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpfilter/servlet_jsh_httpfilter_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpfilter/servlet_jsh_httpfilter_web.xml new file mode 100644 index 0000000000..d76f8bfac8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpfilter/servlet_jsh_httpfilter_web.xml @@ -0,0 +1,49 @@ + + + + + SerJaxSerHttpHttpFilter + + ServletMappedHttpFilter_Filter1 + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpfilter.HttpFilter_Filter1 + + + ServletMappedHttpFilter_Filter2 + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpfilter.HttpFilter_Filter2 + + + ServletMappedHttpFilter_Filter1 + HttpFilterTestLogicalName + + + ServletMappedHttpFilter_Filter2 + HttpFilterTestLogicalName + + + HttpFilterTestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpfilter.HttpFilterTestServlet + + + HttpFilterTestLogicalName + /HttpFilterTest + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservlet/DestroyTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservlet/DestroyTestServlet.java new file mode 100644 index 0000000000..70e88923d8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservlet/DestroyTestServlet.java @@ -0,0 +1,77 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservlet; + +import java.io.IOException; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class DestroyTestServlet extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + // Generally we shouldn't call destroy method explicitly. + destroy(); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservlet/InitTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservlet/InitTestServlet.java new file mode 100644 index 0000000000..5f8b2ee987 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservlet/InitTestServlet.java @@ -0,0 +1,103 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class InitTestServlet extends HttpServlet { + + private final static String EXPECTED = "in init"; + + public void init() throws ServletException { + getServletConfig().getServletContext().setAttribute("status", EXPECTED); + } + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + + String actual = (String) getServletContext().getAttribute("status"); + if (actual != null) { + if (!actual.equals(EXPECTED)) { + passed = false; + pw.println("ERROR: status message was not found"); + pw.println("expected result=" + EXPECTED); + pw.println("actual result=" + actual); + } else { + passed = true; + } + } else { + passed = false; + pw.println("ERROR: status attribute was not found"); + } + + ServletTestUtil.printResult(pw, passed); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservlet/Init_ServletConfigTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservlet/Init_ServletConfigTestServlet.java new file mode 100644 index 0000000000..be01219c61 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservlet/Init_ServletConfigTestServlet.java @@ -0,0 +1,105 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class Init_ServletConfigTestServlet extends HttpServlet { + + private final static String EXPECTED = "in init"; + + public void init(ServletConfig sc) throws ServletException { + super.init(sc); + sc.getServletContext().setAttribute("status", EXPECTED); + } + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + + String actual = (String) getServletContext().getAttribute("status"); + if (actual != null) { + if (!actual.equals(EXPECTED)) { + passed = false; + pw.println("ERROR: status message was not found"); + pw.println("expected result=" + EXPECTED); + pw.println("actual result=" + actual); + } else { + passed = true; + } + } else { + passed = false; + pw.println("ERROR: status attribute was not found"); + } + + ServletTestUtil.printResult(pw, passed); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservlet/ServiceTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservlet/ServiceTestServlet.java new file mode 100644 index 0000000000..95648cc06b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservlet/ServiceTestServlet.java @@ -0,0 +1,80 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservlet; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class ServiceTestServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + ServletTestUtil.printResult(pw, true); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservlet/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservlet/TestServlet.java new file mode 100644 index 0000000000..b5d2445028 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservlet/TestServlet.java @@ -0,0 +1,231 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservlet; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Enumeration; + +import com.sun.ts.tests.servlet.common.servlets.HttpTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class TestServlet extends HttpTCKServlet { + + public void getServletConfigTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + + if (getServletConfig() == null) { + passed = false; + pw.println("getServletConfig method returned a null"); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + + } + + public void getServletContextTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + boolean passed = false; + + if (getServletContext() == null) { + passed = false; + pw.println("getServletContext method returned a null"); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public void getServletInfoTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + + if (getServletInfo() == null) { + passed = false; + pw.println("getServletInfo method returned a null"); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public void getServletNameTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + + String expected = "TestServlet"; + String actual = getServletName(); + + if (actual != null) { + if (!expected.equals(actual)) { + passed = false; + pw.println("getServletName returned the wrong result"); + pw.println("Expected result= " + expected); + pw.println("Actual result= " + actual); + } else { + passed = true; + } + } else { + passed = false; + pw.println("getServletName method returned a null"); + } + ServletTestUtil.printResult(pw, passed); + + } + + public void getInitParameterTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + boolean passed = false; + String expected = "value1"; + + String actual = getInitParameter("parameter1"); + if (!expected.equals(actual)) { + passed = false; + pw.println("getInitParameter(String) did not return the correct result"); + pw.println("Expected result=" + expected); + pw.println("Actual result=" + actual); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public void getInitParameterTestNull(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + boolean passed = false; + + String actual = getInitParameter( + "something_that_will_not_be_there_no_matter_how_many_time"); + if (actual != null) { + passed = false; + pw.println("getInitParameter(String) did not return exected null"); + pw.println("Actual result=" + actual); + } else { + passed = true; + pw.println("getInitParameter(String) return exected null"); + } + ServletTestUtil.printResult(pw, passed); + } + + public void getInitParameterNamesTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + boolean passed = true; + + String expectedResult1 = "parameter1"; + boolean expectedResult1Found = false; + String expectedResult2 = "parameter2"; + boolean expectedResult2Found = false; + Enumeration initP = getInitParameterNames(); + + if (initP.hasMoreElements()) { + while (initP.hasMoreElements()) { + String name = (String) initP.nextElement(); + pw.println("Initialization parameter: " + name); + + if (name.equals(expectedResult1)) { + if (!expectedResult1Found) { + expectedResult1Found = true; + } else { + passed = false; + pw.println( + "getInitParameterNames() method return an attribute name twice "); + pw.println( + "The attribute already specified was " + expectedResult1 + " "); + } + } else if (name.equals(expectedResult2)) { + if (!expectedResult2Found) { + expectedResult2Found = true; + } else { + passed = false; + pw.println( + "getInitParameterNames() method return an attribute name twice "); + pw.println( + "The attribute already specified was " + expectedResult2 + " "); + } + } + } + + if (!expectedResult1Found && expectedResult2Found) { + passed = false; + pw.println( + "getInitParameterNames() method did not return all the init parameters"); + } + } else { + passed = false; + pw.println("getInitParameterNames() returned and empty enumeration"); + } + ServletTestUtil.printResult(pw, passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservlet/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservlet/URLClient.java new file mode 100644 index 0000000000..67120157cd --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservlet/URLClient.java @@ -0,0 +1,226 @@ +/* + * 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservlet; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_jsh_httpservlet_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(DestroyTestServlet.class, Init_ServletConfigTestServlet.class, + InitTestServlet.class, ServiceTestServlet.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_jsh_httpservlet_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: destroyTest + * + * @assertion_ids: Servlet:JAVADOC:416 + * + * @test_Strategy: Create a GenericServlet and take out of service using + * destroy method + * + */ + @Test + public void destroyTest() throws Exception { + String testName = "destroyTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(IGNORE_BODY, "true"); + invoke(); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(IGNORE_BODY, "true"); + invoke(); + } + + /* + * @testName: getServletConfigTest + * + * @assertion_ids: Servlet:JAVADOC:421 + * + * @test_Strategy: Create a GenericServlet and check for its ServletConfig + * object existence + * + */ + @Test + public void getServletConfigTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletConfigTest"); + invoke(); + } + + /* + * @testName: getServletContextTest + * + * @assertion_ids: Servlet:JAVADOC:422 + * + * @test_Strategy: Create a GenericServlet and check for its ServletContext + * object existence + * + */ + @Test + public void getServletContextTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletContextTest"); + invoke(); + } + + /* + * @testName: getServletInfoTest + * + * @assertion_ids: Servlet:JAVADOC:423 + * + * @test_Strategy: Create a GenericServlet and check for its ServletInfo + * object values + * + */ + @Test + public void getServletInfoTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletInfoTest"); + invoke(); + } + + /* + * @testName: getInitParameterTest + * + * @assertion_ids: Servlet:JAVADOC:417 + * + * @test_Strategy: Servlet tries to access a parameter that exists + */ + @Test + public void getInitParameterTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getInitParameterTest"); + invoke(); + } + + /* + * @testName: getInitParameterTestNull + * + * @assertion_ids: Servlet:JAVADOC:418 + * + * @test_Strategy: Servlet tries to access a parameter that doesnot exist + */ + @Test + public void getInitParameterTestNull() throws Exception { + TEST_PROPS.setProperty(APITEST, "getInitParameterTestNull"); + invoke(); + } + + /* + * @testName: getInitParameterNamesTest + * + * @assertion_ids: Servlet:JAVADOC:419 + * + * @test_Strategy: Servlet tries to get all parameter names + */ + @Test + public void getInitParameterNamesTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getInitParameterNamesTest"); + invoke(); + } + + /* + * @testName: getServletNameTest + * + * @assertion_ids: Servlet:JAVADOC:433 + * + * @test_Strategy: Servlet gets name of servlet + */ + @Test + public void getServletNameTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletNameTest"); + invoke(); + } + + /* + * @testName: serviceTest + * + * @assertion_ids: Servlet:JAVADOC:430 + * + * @test_Strategy: Servlet which has a service method that is called + */ + @Test + public void serviceTest() throws Exception { + String testName = "serviceTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + testName + " HTTP/1.1"); + invoke(); + } + + /* + * @testName: initTest + * + * @assertion_ids: Servlet:JAVADOC:426 + * + * @test_Strategy: Servlet has init method that puts a value into the context. + * Servlet when called reads value from context + */ + @Test + public void initTest() throws Exception { + String testName = "initTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + testName + " HTTP/1.1"); + invoke(); + } + + /* + * @testName: init_ServletConfigTest + * + * @assertion_ids: Servlet:JAVADOC:424 + * + * @test_Strategy: Servlet has init method that puts a value into the context. + * Servlet when called reads value from context + */ + @Test + public void init_ServletConfigTest() throws Exception { + String testName = "init_ServletConfigTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + testName + " HTTP/1.1"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservlet/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservlet/build.xml new file mode 100644 index 0000000000..8c3e9d5ce5 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservlet/build.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservlet/servlet_jsh_httpservlet_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservlet/servlet_jsh_httpservlet_web.xml new file mode 100644 index 0000000000..879e754982 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservlet/servlet_jsh_httpservlet_web.xml @@ -0,0 +1,73 @@ + + + + + SerJaxSerHttpHttpServlet + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservlet.TestServlet + + parameter1 + value1 + + + parameter2 + value2 + + + + destroyTest + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservlet.DestroyTestServlet + + + initTest + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservlet.InitTestServlet + + + init_ServletConfigTest + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservlet.Init_ServletConfigTestServlet + + + serviceTest + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservlet.ServiceTestServlet + + + TestServlet + /TestServlet/* + + + destroyTest + /destroyTest + + + initTest + /initTest + + + init_ServletConfigTest + /init_ServletConfigTest + + + serviceTest + /serviceTest + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest/GetParameterNamesEmptyEnumTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest/GetParameterNamesEmptyEnumTestServlet.java new file mode 100644 index 0000000000..f96f2461dc --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest/GetParameterNamesEmptyEnumTestServlet.java @@ -0,0 +1,79 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.RequestTests; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class GetParameterNamesEmptyEnumTestServlet extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + RequestTests.getParameterNamesEmptyEnumTest(pw, request, response); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest/GetQueryStringNullTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest/GetQueryStringNullTestServlet.java new file mode 100644 index 0000000000..962eab0370 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest/GetQueryStringNullTestServlet.java @@ -0,0 +1,79 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.RequestTests; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class GetQueryStringNullTestServlet extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + RequestTests.getQueryStringNullTest(pw, request, response); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest/GetReaderUnsupportedEncodingExceptionTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest/GetReaderUnsupportedEncodingExceptionTestServlet.java new file mode 100644 index 0000000000..ff5b893af9 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest/GetReaderUnsupportedEncodingExceptionTestServlet.java @@ -0,0 +1,81 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.RequestTests; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class GetReaderUnsupportedEncodingExceptionTestServlet + extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + RequestTests.getReaderUnsupportedEncodingExceptionTest(pw, request, + response); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest/GetServletPathEmptyStringTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest/GetServletPathEmptyStringTestServlet.java new file mode 100644 index 0000000000..e9cee8b688 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest/GetServletPathEmptyStringTestServlet.java @@ -0,0 +1,79 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.RequestTests; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class GetServletPathEmptyStringTestServlet extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + RequestTests.getServletPathEmptyStringTest(pw, request, response); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest/SetCharacterEncodingTest.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest/SetCharacterEncodingTest.java new file mode 100644 index 0000000000..40e0f0ef35 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest/SetCharacterEncodingTest.java @@ -0,0 +1,41 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.RequestTests; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class SetCharacterEncodingTest extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + RequestTests.setCharacterEncodingTest(pw, request, response); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest/SetCharacterEncodingUnsupportedEncodingExceptionTest.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest/SetCharacterEncodingUnsupportedEncodingExceptionTest.java new file mode 100644 index 0000000000..c5226c7b3f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest/SetCharacterEncodingUnsupportedEncodingExceptionTest.java @@ -0,0 +1,43 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.RequestTests; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class SetCharacterEncodingUnsupportedEncodingExceptionTest + extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + RequestTests.setCharacterEncodingUnsupportedEncodingExceptionTest(pw, + request, response); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest/URLClient.java new file mode 100644 index 0000000000..08f44b7c07 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest/URLClient.java @@ -0,0 +1,1014 @@ +/* + * Copyright (c) 2007, 2021 Oracle and/or its affiliates and others. + * 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest; + +import java.io.InputStream; +import java.util.HashSet; +import java.util.Locale; +import java.util.Set; +import com.sun.ts.tests.servlet.common.request.HttpRequest; +import com.sun.ts.tests.servlet.common.request.HttpResponse; +import org.apache.commons.httpclient.Header; +import com.sun.ts.tests.servlet.common.request.HttpRequestClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.common.util.Data; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends HttpRequestClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_jsh_httpservletrequest_web.war").addAsLibraries(CommonServlets.getCommonServletsArchive()).addClasses(GetParameterNamesEmptyEnumTestServlet.class, GetQueryStringNullTestServlet.class, GetReaderUnsupportedEncodingExceptionTestServlet.class, doHeadTest.class, getServletContextTest.class, GetServletPathEmptyStringTestServlet.class, SetCharacterEncodingTest.class, SetCharacterEncodingUnsupportedEncodingExceptionTest.class).setWebXML(URLClient.class.getResource("servlet_jsh_httpservletrequest_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + /* Run test */ + // ------------------------------- ServletRequest + // ------------------------------ + /* + * @testName: getAttributeNamesTest + * + * @assertion_ids: Servlet:JAVADOC:573 + * + * @test_Strategy: Servlet verifies attributes + * + */ + @Test + public void getAttributeNamesTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getAttributeNamesTest"); + invoke(); + TEST_PROPS.setProperty(APITEST, "getAttributeNamesEmptyEnumTest"); + invoke(); + } + + /* + * @testName: getAttributeTest + * + * @assertion_ids: Servlet:JAVADOC:572 + * + * @test_Strategy: Servlet verifies attribute + * + */ + @Test + public void getAttributeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getAttributeTest"); + invoke(); + TEST_PROPS.setProperty(APITEST, "getAttributeDoesNotExistTest"); + invoke(); + } + + /* + * @testName: getCharacterEncodingTest + * + * @assertion_ids: Servlet:JAVADOC:574 + * + * @test_Strategy: Servlet verifies encoding + */ + @Test + public void getCharacterEncodingTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getCharacterEncodingTest"); + TEST_PROPS.setProperty(REQUEST_HEADERS, "Content-Type:text/plain; charset=ISO-8859-1"); + invoke(); + TEST_PROPS.setProperty(APITEST, "getCharacterEncodingNullTest"); + invoke(); + } + + /* + * @testName: getContentLengthTest + * + * @assertion_ids: Servlet:JAVADOC:575 + * + * @test_Strategy: Servlet compares this length to the actual length of the + * content body read in using getInputStream + * + */ + /* + * @testName: getContentTypeTest + * + * @assertion_ids: Servlet:JAVADOC:576; Servlet:SPEC:34; + * + * @test_Strategy: Client sets the content type and servlet reads it. + * + */ + /* + * @testName: getInputStreamTest + * + * @assertion_ids: Servlet:JAVADOC:577 + * + * @test_Strategy: Servlet tries to read the input stream. + */ + /* + * @testName: getInputStreamIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:579 + * + * @test_Strategy: Servlet gets a Reader object using + * ServletRequest.getReader() then tries to get the inputStream Object + * + */ + /* + * @testName: getLocaleTest + * + * @assertion_ids: Servlet:JAVADOC:580 + * + * @test_Strategy: Servlet sends back locale to client. + */ + @Test + public void getLocaleTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getLocaleTest"); + TEST_PROPS.setProperty(REQUEST_HEADERS, "Accept-Language:en-US"); + invoke(); + TEST_PROPS.setProperty(APITEST, "getLocaleDefaultTest"); + invoke(); + } + + /* + * @testName: getLocalesTest + * + * @assertion_ids: Servlet:JAVADOC:581 + * + * @test_Strategy: Servlet sends back locale(s) to client. + */ + @Test + public void getLocalesTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getLocalesTest"); + TEST_PROPS.setProperty(REQUEST_HEADERS, "Accept-Language:en-US,en-GB"); + invoke(); + TEST_PROPS.setProperty(APITEST, "getLocalesDefaultTest"); + invoke(); + } + + /* + * @testName: getParameterMapTest + * + * @assertion_ids: Servlet:JAVADOC:583 + * + * @test_Strategy: Client sets several parameters and the servlet attempts to + * access them. + */ + /* + * @testName: getParameterNamesTest + * + * @assertion_ids: Servlet:JAVADOC:584 + * + * @test_Strategy: Servlet attempts to access parameters. + */ + @Test + public void getParameterNamesTest() throws Exception { + String testName = "getParameterNamesTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + getServletName() + "?testname=" + testName + "¶meter1=value1¶meter2=value2 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, Data.PASSED); + invoke(); + testName = "getParameterNamesEmptyEnumTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, Data.PASSED); + invoke(); + } + + /* + * @testName: getParameterTest + * + * @assertion_ids: Servlet:JAVADOC:582 + * + * @test_Strategy: Client sets a parameter and servlet retrieves it. + */ + @Test + public void getParameterTest() throws Exception { + String testName = "getParameterTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + getServletName() + "?testname=" + testName + "¶meter1=value1 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, Data.PASSED); + invoke(); + TEST_PROPS.setProperty(APITEST, "getParameterDoesNotExistTest"); + invoke(); + } + + /* + * @testName: getParameterValuesTest + * + * @assertion_ids: Servlet:JAVADOC:585 + * + * @test_Strategy: Servlet verifies values + */ + @Test + public void getParameterValuesTest() throws Exception { + String testName = "getParameterValuesTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + getServletName() + "?testname=" + testName + "&Names=value1&Names=value2 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, Data.PASSED); + invoke(); + TEST_PROPS.setProperty(APITEST, "getParameterValuesDoesNotExistTest"); + invoke(); + } + + /* + * @testName: getProtocolTest + * + * @assertion_ids: Servlet:JAVADOC:586 + * + * @test_Strategy: Servlet verifies the protocol used by the client + */ + /* + * @testName: getReaderTest + * + * @assertion_ids: Servlet:JAVADOC:587 + * + * @test_Strategy: Client sets some content and servlet reads the content + */ + /* + * @testName: getReaderIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:590 + * + * @test_Strategy: Servlet gets an InputStream Object then tries to get a + * Reader Object. + */ + /* + * @testName: getReaderUnsupportedEncodingExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:589 + * + * @test_Strategy: Client sets some content but with an invalid encoding, + * servlet tries to read content. + */ + /* + * @testName: getRemoteAddrTest + * + * @assertion_ids: Servlet:JAVADOC:592 + * + * @test_Strategy: Servlet reads and verifies where the request originated + */ + /* + * @testName: getLocalAddrTest + * + * @assertion_ids: Servlet:JAVADOC:719 + * + * @test_Strategy: Servlet reads and verifies where the request originated + */ + /* + * @testName: getRemoteHostTest + * + * @assertion_ids: Servlet:JAVADOC:593 + * + * @test_Strategy: Servlet reads and verifies where the request originated + */ + /* + * @testName: getRequestDispatcherTest + * + * @assertion_ids: Servlet:JAVADOC:594 + * + * @test_Strategy: Servlet tries to get a dispatcher + */ + /* + * @testName: getSchemeTest + * + * @assertion_ids: Servlet:JAVADOC:595 + * + * @test_Strategy: Servlet verifies the scheme of the url used in the request + */ + /* + * @testName: getServerNameTest + * + * @assertion_ids: Servlet:JAVADOC:596 + * + * @test_Strategy: Servlet verifies the destination of the request + */ + /* + * @testName: getServerPortTest + * + * @assertion_ids: Servlet:JAVADOC:597 + * + * @test_Strategy: Servlet verifies the destination port of the request + */ + /* + * @testName: isSecureTest + * + * @assertion_ids: Servlet:JAVADOC:598 + * + * @test_Strategy: Servlet verifies the isSecure method for the non-secure + * case. + */ + /* + * @testName: removeAttributeTest + * + * @assertion_ids: Servlet:JAVADOC:599 + * + * @test_Strategy: Servlet adds then removes an attribute, then verifies it + * was removed. + */ + /* + * @testName: setAttributeTest + * + * @assertion_ids: Servlet:JAVADOC:600 + * + * @test_Strategy: Servlet adds an attribute, then verifies it was added + */ + /* + * @testName: setCharacterEncodingTest + * + * @assertion_ids: Servlet:JAVADOC:601 + * + * @test_Strategy: Servlet sets a new encoding and tries to retrieve it. + */ + /* + * @testName: setCharacterEncodingTest1 + * + * @assertion_ids: Servlet:JAVADOC:601; Servlet:JAVADOC:574; Servlet:SPEC:28; + * Servlet:SPEC:213; + * + * @test_Strategy: HttpServletRequest calls getReader()first; then sets a new + * encoding and tries to retrieve it. verifies that the new encoding is + * ignored. + */ + /* + * @testName: setCharacterEncodingUnsupportedEncodingExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:602 + * + * @test_Strategy: Servlet tries to set an invalid encoding. + * + */ + // ---------------------------- END ServletRequest + // ----------------------------- + // ---------------------------- HttpServletRequest + // ----------------------------- + /* + * @testName: getAuthTypeWithoutProtectionTest + * + * @assertion_ids: Servlet:JAVADOC:530 + * + * @test_Strategy: Servlet verifies correct result + */ + /* + * @testName: getContextPathTest + * + * @assertion_ids: Servlet:JAVADOC:550 + * + * @test_Strategy: Client sets header and servlet verifies the result + */ + /* + * @testName: getCookiesNoCookiesTest + * + * @assertion_ids: Servlet:JAVADOC:532 + * + * @test_Strategy: Servlet tries to get a cookie when none exist + */ + /* + * @testName: getCookiesTest + * + * @assertion_ids: Servlet:JAVADOC:531 + * + * @test_Strategy:Client sets a cookie and servlet tries to read it + */ + /* + * @testName: getDateHeaderIllegalArgumentExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:535 + * + * @test_Strategy: Client set invalid date value, servlet tries to read it. + */ + /* + * @testName: getDateHeaderNoHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:534 + * + * @test_Strategy: Servlet tries to get a dateHeader when none exist + */ + /* + * @testName: getDateHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:533 + * + * @test_Strategy: client sets a dateheader and servlet tries to read it. + */ + /* + * @testName: getHeaderNamesTest + * + * @assertion_ids: Servlet:JAVADOC:540 + * + * @test_Strategy: Client sets some headers and servlet tries to read them. + */ + /* + * @testName: getHeaderNoHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:537 + * + * @test_Strategy: Servlet tries to read a header when none exist + */ + /* + * @testName: getHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:536 + * + * @test_Strategy: Client sets a header and servlet tries to read it. + */ + /* + * @testName: getHeadersNoHeadersTest + * + * @assertion_ids: Servlet:JAVADOC:539 + * + * @test_Strategy: Servlet tries to get all the headers when none have been + * added + */ + /* + * @testName: getHeadersTest + * + * @assertion_ids: Servlet:JAVADOC:538 + * + * @test_Strategy: Client sets some headers and servlet tries to read them + */ + /* + * @testName: getIntHeaderNoHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:543 + * + * @test_Strategy: Servlet tries to read a header when none exist. + */ + /* + * @testName: getIntHeaderNumberFoundExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:544 + * + * @test_Strategy: Client sets an invalid header and servlet tries to read it. + */ + /* + * @testName: getIntHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:542 + * + * @test_Strategy: Client sets a header and servlet reads it + */ + /* + * @testName: getMethodTest + * + * @assertion_ids: Servlet:JAVADOC:545 + * + * @test_Strategy: Client makes 3 calls using GET/POST/HEAD + */ + /* + * @testName: getPathInfoNullTest + * + * @assertion_ids: Servlet:JAVADOC:547 + * + * @test_Strategy: + */ + /* + * @testName: getPathInfoTest + * + * @assertion_ids: Servlet:JAVADOC:546; Servlet:SPEC:25; + * + * @test_Strategy: Servlet verifies path info + */ + /* + * @testName: getPathTranslatedNullTest + * + * @assertion_ids: Servlet:JAVADOC:549 + * + * @test_Strategy: Servlet verifies result when there is no path info + */ + /* + * @testName: getPathTranslatedTest + * + * @assertion_ids: Servlet:JAVADOC:548 + * + * @test_Strategy: client sets extra path info and servlet verifies it + */ + /* + * @testName: getQueryStringNullTest + * + * @assertion_ids: Servlet:JAVADOC:553 + * + * @test_Strategy: Servlet verifies result when no query string exists + */ + /* + * @testName: getQueryStringTest + * + * @assertion_ids: Servlet:JAVADOC:552 + * + * @test_Strategy: Client sets query string and servlet verifies it + */ + /* + * @testName: getRemoteUserTest + * + * @assertion_ids: Servlet:JAVADOC:554 + * + * @test_Strategy: Servlet verifies the result of a non-authed user + */ + /* + * @testName: getRequestURITest + * + * @assertion_ids: Servlet:JAVADOC:561 + * + * @test_Strategy: Servlet verifies URI data + */ + /* + * @testName: getRequestURLTest + * + * @assertion_ids: Servlet:JAVADOC:562 + * + * @test_Strategy: Servlet verifies URL info + */ + /* + * @testName: getRequestedSessionIdNullTest + * + * @assertion_ids: Servlet:JAVADOC:560 + * + * @test_Strategy: Servlet verifies null result + */ + /* + * @testName: getServletPathEmptyStringTest + * + * @assertion_ids: Servlet:JAVADOC:563; Servlet:SPEC:23; + * + * @test_Strategy: Servlet verifies empty string + */ + /* + * @testName: getServletPathTest + * + * @assertion_ids: Servlet:JAVADOC:564; Servlet:SPEC:24; + * + * @test_Strategy: Servlet verifies path info + */ + /* + * @testName: getSessionTrueTest + * + * @assertion_ids: Servlet:JAVADOC:565 + * + * @test_Strategy: Servlet verifies getSession(true) call + */ + /* + * @testName: getSessionFalseTest + * + * @assertion_ids: Servlet:JAVADOC:566 + * + * @test_Strategy: Servlet verifies getSession(false) call + */ + /* + * @testName: getSessionTest + * + * @assertion_ids: Servlet:JAVADOC:567 + * + * @test_Strategy: Servlet verifies getSession() call + */ + /* + * @testName: isRequestedSessionIdFromCookieTest + * + * @assertion_ids: Servlet:JAVADOC:569 + * + * @test_Strategy: Servlet verifies correct result + */ + /* + * @testName: isRequestedSessionIdFromURLTest + * + * @assertion_ids: Servlet:JAVADOC:570 + * + * @test_Strategy: Servlet verifies correct result + */ + /* + * @testName: isRequestedSessionIdValidTest + * + * @assertion_ids: Servlet:JAVADOC:568; Servlet:SPEC:211; + * + * @test_Strategy: Client sends request without session ID; Verifies + * isRequestedSessionIdValid() returns false; + */ + /* + * @testName: getRequestedSessionIdTest1 + * + * @assertion_ids: Servlet:JAVADOC:559; + * + * @test_Strategy: Client sends request with a session ID; Verifies + * getRequestedSessionId() returns the same; + */ + /* + * @testName: getRequestedSessionIdTest2 + * + * @assertion_ids: Servlet:JAVADOC:559; + * + * @test_Strategy: Client sends request to a servlet with a sesion ID; Servlet + * start a sesison; Verifies getRequestedSessionId() returns the same; + */ + /* + * @testName: sessionTimeoutTest + * + * @assertion_ids: Servlet:SPEC:67; + * + * @test_Strategy: First set a HttpSession's timeout to 60 seconds; then sleep + * 90 seconds in servlet; verify that the session is still valid after. + */ + /* + * @testName: getLocalPortTest + * + * @assertion_ids: Servlet:JAVADOC:630; + * + * @test_Strategy: Send an HttpServletRequest to server; Verify that + * getLocalPort(); + */ + /* + * @testName: getServletContextTest + * + * @assertion_ids: + * + * @test_Strategy: Send an HttpServletRequest to server; Verify that + * getServletContext return the same as stored in ServletConfig + */ + @Test + public void getServletContextTest() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/getServletContextTest HTTP/1.1"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "Test FAILED"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, "Test PASSED"); + invoke(); + } + + /* + * @testName: doHeadTest + * + * @assertion_ids: + * + * @test_Strategy: Perform a GET request and a HEAD request for the same + * resource and confirm that a) HEAD response has no body and b) the header + * values are the same. + */ + @Test + public void doHeadTest() throws Exception { + HttpRequest requestGet = new HttpRequest("GET " + getContextRoot() + "/doHeadTest HTTP/1.1", _hostname, _port); + HttpRequest requestHead = new HttpRequest("HEAD " + getContextRoot() + "/doHeadTest HTTP/1.1", _hostname, _port); + try { + HttpResponse responseGet = requestGet.execute(); + HttpResponse responseHead = requestHead.execute(); + // Validate the response bodies + String responseBodyGet = responseGet.getResponseBodyAsString(); + if (responseBodyGet == null || responseBodyGet.length() == 0) { + throw new Exception("GET request did not include a response body"); + } + InputStream responseBodyHead = responseHead.getResponseBodyAsRawStream(); + if (responseBodyHead != null) { + throw new Exception("HEAD request included a response body"); + } + // Validate the response headers + Set
headersToMatch = new HashSet<>(); + Header[] headersGet = responseGet.getResponseHeaders(); + for (Header header : headersGet) { + switch(header.getName().toLowerCase(Locale.ENGLISH)) { + case "date": + // Ignore date header as it will change between requests + break; + default: + headersToMatch.add(header); + } + } + Header[] headersHead = responseHead.getResponseHeaders(); + for (Header header : headersHead) { + if (header.getName().toLowerCase().equals("date")) { + // Skip date header + continue; + } + if (!headersToMatch.remove(header)) { + throw new Exception("HEAD request contained header that was not present for GET: " + header); + } + } + if (headersToMatch.size() > 0) { + throw new Exception("HEAD request did not contain header that was present for GET:" + headersToMatch.iterator().next()); + } + } catch (Throwable t) { + throw new Exception("Exception occurred:" + t, t); + } + } + + // -------------------------- END HttpServletRequest + // --------------------------- + @Test() + public void getAuthTypeWithoutProtectionTest() throws Exception { + super.getAuthTypeWithoutProtectionTest(); + } + + @Test() + public void getContentLengthTest() throws Exception { + super.getContentLengthTest(); + } + + @Test() + public void getContentTypeTest() throws Exception { + super.getContentTypeTest(); + } + + @Test() + public void getContextPathTest() throws Exception { + super.getContextPathTest(); + } + + @Test() + public void getCookiesNoCookiesTest() throws Exception { + super.getCookiesNoCookiesTest(); + } + + @Test() + public void getCookiesTest() throws Exception { + super.getCookiesTest(); + } + + @Test() + public void getDateHeaderIllegalArgumentExceptionTest() throws Exception { + super.getDateHeaderIllegalArgumentExceptionTest(); + } + + @Test() + public void getDateHeaderNoHeaderTest() throws Exception { + super.getDateHeaderNoHeaderTest(); + } + + @Test() + public void getDateHeaderTest() throws Exception { + super.getDateHeaderTest(); + } + + @Test() + public void getHeaderNamesTest() throws Exception { + super.getHeaderNamesTest(); + } + + @Test() + public void getHeaderNoHeaderTest() throws Exception { + super.getHeaderNoHeaderTest(); + } + + @Test() + public void getHeaderTest() throws Exception { + super.getHeaderTest(); + } + + @Test() + public void getHeadersNoHeadersTest() throws Exception { + super.getHeadersNoHeadersTest(); + } + + @Test() + public void getHeadersTest() throws Exception { + super.getHeadersTest(); + } + + @Test() + public void getInputStreamIllegalStateExceptionTest() throws Exception { + super.getInputStreamIllegalStateExceptionTest(); + } + + @Test() + public void getInputStreamTest() throws Exception { + super.getInputStreamTest(); + } + + @Test() + public void getIntHeaderNoHeaderTest() throws Exception { + super.getIntHeaderNoHeaderTest(); + } + + @Test() + public void getIntHeaderNumberFoundExceptionTest() throws Exception { + super.getIntHeaderNumberFoundExceptionTest(); + } + + @Test() + public void getIntHeaderTest() throws Exception { + super.getIntHeaderTest(); + } + + @Test() + public void getLocalAddrTest() throws Exception { + super.getLocalAddrTest(); + } + + @Test() + public void getLocalPortTest() throws Exception { + super.getLocalPortTest(); + } + + @Test() + public void getMethodTest() throws Exception { + super.getMethodTest(); + } + + @Test() + public void getParameterMapTest() throws Exception { + super.getParameterMapTest(); + } + + @Test() + public void getPathInfoNullTest() throws Exception { + super.getPathInfoNullTest(); + } + + @Test() + public void getPathInfoTest() throws Exception { + super.getPathInfoTest(); + } + + @Test() + public void getPathTranslatedNullTest() throws Exception { + super.getPathTranslatedNullTest(); + } + + @Test() + public void getPathTranslatedTest() throws Exception { + super.getPathTranslatedTest(); + } + + @Test() + public void getProtocolTest() throws Exception { + super.getProtocolTest(); + } + + @Test() + public void getQueryStringNullTest() throws Exception { + super.getQueryStringNullTest(); + } + + @Test() + public void getQueryStringTest() throws Exception { + super.getQueryStringTest(); + } + + @Test() + public void getReaderIllegalStateExceptionTest() throws Exception { + super.getReaderIllegalStateExceptionTest(); + } + + @Test() + public void getReaderTest() throws Exception { + super.getReaderTest(); + } + + @Test() + public void getReaderUnsupportedEncodingExceptionTest() throws Exception { + super.getReaderUnsupportedEncodingExceptionTest(); + } + + @Test() + public void getRemoteAddrTest() throws Exception { + super.getRemoteAddrTest(); + } + + @Test() + public void getRemoteHostTest() throws Exception { + super.getRemoteHostTest(); + } + + @Test() + public void getRemoteUserTest() throws Exception { + super.getRemoteUserTest(); + } + + @Test() + public void getRequestDispatcherTest() throws Exception { + super.getRequestDispatcherTest(); + } + + @Test() + public void getRequestURITest() throws Exception { + super.getRequestURITest(); + } + + @Test() + public void getRequestURLTest() throws Exception { + super.getRequestURLTest(); + } + + @Test() + public void getRequestedSessionIdNullTest() throws Exception { + super.getRequestedSessionIdNullTest(); + } + + @Test() + public void getRequestedSessionIdTest1() throws Exception { + super.getRequestedSessionIdTest1(); + } + + @Test() + public void getRequestedSessionIdTest2() throws Exception { + super.getRequestedSessionIdTest2(); + } + + @Test() + public void getSchemeTest() throws Exception { + super.getSchemeTest(); + } + + @Test() + public void getServerNameTest() throws Exception { + super.getServerNameTest(); + } + + @Test() + public void getServerPortTest() throws Exception { + super.getServerPortTest(); + } + + @Test() + public void getServletPathEmptyStringTest() throws Exception { + super.getServletPathEmptyStringTest(); + } + + @Test() + public void getServletPathTest() throws Exception { + super.getServletPathTest(); + } + + @Test() + public void getSessionFalseTest() throws Exception { + super.getSessionFalseTest(); + } + + @Test() + public void getSessionTest() throws Exception { + super.getSessionTest(); + } + + @Test() + public void getSessionTrueTest() throws Exception { + super.getSessionTrueTest(); + } + + @Test() + public void isRequestedSessionIdFromCookieTest() throws Exception { + super.isRequestedSessionIdFromCookieTest(); + } + + @Test() + public void isRequestedSessionIdFromURLTest() throws Exception { + super.isRequestedSessionIdFromURLTest(); + } + + @Test() + public void isRequestedSessionIdValidTest() throws Exception { + super.isRequestedSessionIdValidTest(); + } + + @Test() + public void isSecureTest() throws Exception { + super.isSecureTest(); + } + + @Test() + public void removeAttributeTest() throws Exception { + super.removeAttributeTest(); + } + + @Test() + public void sessionTimeoutTest() throws Exception { + super.sessionTimeoutTest(); + } + + @Test() + public void setAttributeTest() throws Exception { + super.setAttributeTest(); + } + + @Test() + public void setCharacterEncodingTest() throws Exception { + super.setCharacterEncodingTest(); + } + + @Test() + public void setCharacterEncodingTest1() throws Exception { + super.setCharacterEncodingTest1(); + } + + @Test() + public void setCharacterEncodingUnsupportedEncodingExceptionTest() throws Exception { + super.setCharacterEncodingUnsupportedEncodingExceptionTest(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest/build.xml new file mode 100644 index 0000000000..4b785291a2 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest/build.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest/doHeadTest.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest/doHeadTest.java new file mode 100644 index 0000000000..c9f716ccd4 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest/doHeadTest.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2021 Contributors to the Eclipse Foundation. + * + * 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 + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +import com.sun.ts.tests.servlet.common.servlets.HttpTCKServlet; + +public class doHeadTest extends HttpTCKServlet { + + private static final long serialVersionUID = 1L; + + @Override + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.print("This is the response body"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest/getServletContextTest.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest/getServletContextTest.java new file mode 100644 index 0000000000..5a898299b4 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest/getServletContextTest.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2009, 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 + */ + +/* + * $Ids$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.HttpTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class getServletContextTest extends HttpTCKServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + Boolean passed = true; + + ServletContext actual = request.getServletContext(); + ServletContext expected = this.getServletConfig().getServletContext(); + + if (actual != expected) { + passed = false; + pw.println("getServletContext() returned inconsistent result"); + } + ServletTestUtil.printResult(pw, passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest/servlet_jsh_httpservletrequest_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest/servlet_jsh_httpservletrequest_web.xml new file mode 100644 index 0000000000..5e5ba299fe --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest/servlet_jsh_httpservletrequest_web.xml @@ -0,0 +1,98 @@ + + + + + SerJaxSerHttpHttpSerRequest + + TestServlet + com.sun.ts.tests.servlet.common.servlets.HttpRequestTestServlet + + + getReaderUnsupportedEncodingExceptionTest + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest.GetReaderUnsupportedEncodingExceptionTestServlet + + + getQueryStringNullTest + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest.GetQueryStringNullTestServlet + + + getServletContextTest + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest.getServletContextTest + + + getParameterNamesEmptyEnumTest + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest.GetParameterNamesEmptyEnumTestServlet + + + getServletPathEmptyStringTest + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest.GetServletPathEmptyStringTestServlet + + + setCharacterEncodingUnsupportedEncodingExceptionTest + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest.SetCharacterEncodingUnsupportedEncodingExceptionTest + + + setCharacterEncodingTest + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest.SetCharacterEncodingTest + + + doHeadTest + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest.doHeadTest + + + getServletContextTest + /getServletContextTest + + + getQueryStringNullTest + /getQueryStringNullTest + + + TestServlet + /TestServlet/* + + + getParameterNamesEmptyEnumTest + /getParameterNamesEmptyEnumTest + + + getReaderUnsupportedEncodingExceptionTest + /getReaderUnsupportedEncodingExceptionTest + + + getServletPathEmptyStringTest + /* + + + setCharacterEncodingUnsupportedEncodingExceptionTest + /setCharacterEncodingUnsupportedEncodingExceptionTest + + + setCharacterEncodingTest + /setCharacterEncodingTest + + + doHeadTest + /doHeadTest + + + 1 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest1/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest1/URLClient.java new file mode 100644 index 0000000000..3d61f76d57 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest1/URLClient.java @@ -0,0 +1,66 @@ +/* + * 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest1; + +import com.sun.ts.tests.servlet.common.request.HttpRequestClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.container.test.api.TargetsContainer; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends HttpRequestClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_jsh_httpservletrequest1_web.war").addAsLibraries(CommonServlets.getCommonServletsArchive()).setWebXML(URLClient.class.getResource("servlet_jsh_httpservletrequest1_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + /* Run test */ + // ------------------------------- ServletRequest + // ------------------------------ + /* + * @testName: getLocalNameTest + * + * @assertion_ids: Servlet:JAVADOC:629; + * + * @test_Strategy: Send an HttpServletRequest to server; Verify that + * getLocalName(); + */ + // -------------------------- END HttpServletRequest + // --------------------------- + @Test() + public void getLocalNameTest() throws Exception { + super.getLocalNameTest(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest1/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest1/build.xml new file mode 100644 index 0000000000..c49cbd2a11 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest1/build.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest1/servlet_jsh_httpservletrequest1_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest1/servlet_jsh_httpservletrequest1_web.xml new file mode 100644 index 0000000000..10273b42f1 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest1/servlet_jsh_httpservletrequest1_web.xml @@ -0,0 +1,30 @@ + + + + + SerJaxSerHttpHttpSerRequest + + TestServlet + com.sun.ts.tests.servlet.common.servlets.HttpRequestTestServlet + + + TestServlet + /TestServlet/* + + \ No newline at end of file diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest30/LoginTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest30/LoginTestServlet.java new file mode 100644 index 0000000000..33b312b326 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest30/LoginTestServlet.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2009, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest30; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class LoginTestServlet extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + Boolean passed = true; + String name = null; + String passwd = null; + + try { + request.login(name, passwd); + passed = false; + pw.println("Test Failed. "); + pw.println("Expected ServletException not thrown"); + } catch (ServletException ex) { + pw.println("Test Passed."); + pw.println("Expected ServletException thrown: " + ex.getMessage()); + } catch (Exception oex) { + passed = false; + pw.println("Test Failed."); + pw.print("Unexpected Exception thrown: " + oex.getMessage()); + } + ServletTestUtil.printResult(pw, passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest30/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest30/URLClient.java new file mode 100644 index 0000000000..8bb6f95da0 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest30/URLClient.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2009, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest30; + +import com.sun.ts.tests.servlet.common.request.HttpRequestClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends HttpRequestClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("LoginTestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_jsh_httpservletrequest30_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(LoginTestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_jsh_httpservletrequest30_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + // ---------------------------- HttpServletRequest + // ----------------------------- + + /* + * @testName: loginTest + * + * @assertion_ids: Servlet:JAVADOC:761; + * + * @test_Strategy: Send an HttpServletRequest to server; Verify that + * login(null, null) throw ServletException. + */ + @Test + public void loginTest() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/LoginTestServlet HTTP/1.1"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "Test FAILED"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, "Test PASSED"); + invoke(); + } + + // -------------------------- END HttpServletRequest + // --------------------------- +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest30/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest30/build.xml new file mode 100644 index 0000000000..2726df09d4 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest30/build.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest30/servlet_jsh_httpservletrequest30_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest30/servlet_jsh_httpservletrequest30_web.xml new file mode 100644 index 0000000000..4ee3fdc9a3 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest30/servlet_jsh_httpservletrequest30_web.xml @@ -0,0 +1,30 @@ + + + + + SerJaxSerHttpHttpSerRequest30 + + LoginTestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest30.LoginTestServlet + + + LoginTestServlet + /LoginTestServlet/* + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest31/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest31/URLClient.java new file mode 100644 index 0000000000..1d67a183f9 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest31/URLClient.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest31; + +import com.sun.ts.tests.servlet.common.request.HttpRequestClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends HttpRequestClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_jsh_httpservletrequest31_web.war").addAsLibraries(CommonServlets.getCommonServletsArchive()).setWebXML(URLClient.class.getResource("servlet_jsh_httpservletrequest31_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + /* Run test */ + /* + * @testName: changeSessionIDTest + * + * @assertion_ids: Servlet:JAVADOC:929.1; + * + * @test_Strategy: Send an HttpServletRequest to server; Verify that + * request.changeSessionId() throws IllegalStateException when it is called + * without a session; + */ + @Test() + public void changeSessionIDTest() throws Exception { + super.changeSessionIDTest(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest31/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest31/build.xml new file mode 100644 index 0000000000..f9e8220b6f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest31/build.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest31/servlet_jsh_httpservletrequest31_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest31/servlet_jsh_httpservletrequest31_web.xml new file mode 100644 index 0000000000..39ad0430ad --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest31/servlet_jsh_httpservletrequest31_web.xml @@ -0,0 +1,30 @@ + + + + + SerJaxSerHttpHttpSerRequest31 + + TestServlet + com.sun.ts.tests.servlet.common.servlets.HttpRequestTestServlet + + + TestServlet + /TestServlet + + \ No newline at end of file diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest40/Client.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest40/Client.java new file mode 100644 index 0000000000..5890a6d0b4 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest40/Client.java @@ -0,0 +1,294 @@ +/* + * Copyright (c) 2017, 2021 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest40; + +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.lib.util.WebUtil; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; + +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.InetAddress; +import java.net.Socket; +import java.net.URL; + +public class Client extends AbstractUrlClient { + + public static final String DELIMITER = "\r\n"; + + public static final String ENCODING = "ISO-8859-1"; + + private WebUtil.Response response = null; + + private String request = null; + + + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_jsh_httpservletrequest40_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(DispatchServlet.class, ForwardFilter.class, ForwardServlet.class, + IncludeServlet.class, NamedForwardServlet.class, NamedIncludeServlet.class, + TestServlet.class, TrailerTestServlet.class, Utilities.class) + .setWebXML(Client.class.getResource("servlet_jsh_httpservletrequest40_web.xml")); + } + + /* + * @testName: httpServletMappingTest + * + * @assertion_ids: servlet40:httpServletMappingTest; + * + * @test_Strategy: + */ + @Test + public void httpServletMappingTest() throws Exception { + simpleTest("httpServletMappingTest", getContextRoot() + "/TestServlet", "GET", + "matchValue=TestServlet, pattern=/TestServlet, servletName=TestServlet, mappingMatch=EXACT"); + } + + /* + * @testName: httpServletMappingTest2 + * + * @assertion_ids: servlet40:httpServletMappingTest2; + * + * @test_Strategy: + */ + @Test + public void httpServletMappingTest2() throws Exception { + simpleTest("httpServletMappingTest2", getContextRoot() + "/a.ts", "GET", + "matchValue=a, pattern=*.ts, servletName=TestServlet, mappingMatch=EXTENSION"); + } + + /* + * @testName: httpServletMappingTest3 + * + * @assertion_ids: servlet40:httpServletMappingTest3; + * + * @test_Strategy: + */ + @Test + public void httpServletMappingTest3() throws Exception { + simpleTest("httpServletMappingTest3", getContextRoot() + "/default", "GET", + "matchValue=, pattern=/, servletName=defaultServlet, mappingMatch=DEFAULT"); + } + + /* + * @testName: httpServletMappingForwardTest + * + * @assertion_ids: servlet40:httpServletMappingForwardTest; + * + * @test_Strategy: + */ + @Test + public void httpServletMappingForwardTest() throws Exception { + simpleTest("httpServletMappingForwardTest", + getContextRoot() + "/ForwardServlet", "GET", + "matchValue=a, pattern=*.ts, servletName=TestServlet, mappingMatch=EXTENSION"); + } + + /* + * @testName: httpServletMappingNamedForwardTest + * + * @assertion_ids: servlet40:httpServletMappingNamedForwardTest; + * + * @test_Strategy: + */ + @Test + public void httpServletMappingNamedForwardTest() throws Exception { + simpleTest("httpServletMappingNamedForwardTest", + getContextRoot() + "/NamedForwardServlet", "GET", + "matchValue=NamedForwardServlet, pattern=/NamedForwardServlet, servletName=NamedForwardServlet, mappingMatch=EXACT"); + } + + /* + * @testName: httpServletMappingNamedIncludeTest + * + * @assertion_ids: servlet40:httpServletMappingNamedIncludeTest; + * + * @test_Strategy: + */ + @Test + public void httpServletMappingNamedIncludeTest() throws Exception { + simpleTest("httpServletMappingNamedIncludeTest", + getContextRoot() + "/NamedIncludeServlet", "GET", + "matchValue=NamedIncludeServlet, pattern=/NamedIncludeServlet, servletName=NamedIncludeServlet, mappingMatch=EXACT"); + } + + /* + * @testName: httpServletMappingIncludeTest + * + * @assertion_ids: servlet40:httpServletMappingIncludeTest; + * + * @test_Strategy: + */ + @Test + public void httpServletMappingIncludeTest() throws Exception { + simpleTest("httpServletMappingIncludeTest", + getContextRoot() + "/IncludeServlet", "POST", + "matchValue=IncludeServlet, pattern=/IncludeServlet, servletName=IncludeServlet, mappingMatch=EXACT"); + } + + /* + * @testName: httpServletMappingFilterTest + * + * @assertion_ids: servlet40:httpServletMappingFilterTest; + * + * @test_Strategy: + */ + @Test + public void httpServletMappingFilterTest() throws Exception { + simpleTest("httpServletMappingFilterTest", getContextRoot() + "/ForwardFilter", + "GET", + "matchValue=, pattern=/, servletName=defaultServlet, mappingMatch=DEFAULT"); + } + + /* + * @testName: httpServletMappingDispatchTest + * + * @assertion_ids: servlet40:httpServletMappingDispatchTest; + * + * @test_Strategy: + */ + @Test + public void httpServletMappingDispatchTest() throws Exception { + simpleTest("httpServletMappingDispatchTest", + getContextRoot() + "/DispatchServlet", "GET", + "matchValue=TestServlet, pattern=/TestServlet, servletName=TestServlet, mappingMatch=EXACT"); + } + + @Test + private void simpleTest(String testName, String request, String method, + String expected) throws Exception { + try { + logger.debug("Sending request {}", request); + + response = WebUtil.sendRequest(method, InetAddress.getByName(_hostname), + _port, getRequest(request), null, null); + + } catch (Exception e) { + logger.error("Caught exception: " + e.getMessage(), e); + throw new Exception(testName + " failed: ", e); + } + + logger.debug("response.statusToken: {}", response.statusToken); + logger.debug("response.content: {}", response.content); + + // Check that the page was found (no error). + if (response.isError()) { + TestUtil.logErr("Could not find " + request); + throw new Exception(testName + " failed."); + } + + if (!response.content.contains(expected)) { + logger.error("Expected: {} but found {}", expected, response.content); + throw new Exception(testName + " failed."); + } + } + + /* + * @testName: TrailerTest + * + * @assertion_ids: servlet40:TrailerTest; + * + * @test_Strategy: + */ + @Test + public void TrailerTest() throws Exception { + InputStream input; + + URL url = new URL("http://" + _hostname + ":" + _port + getContextRoot() + + "/TrailerTestServlet"); + try (Socket socket = new Socket(url.getHost(), url.getPort()); + OutputStream output = socket.getOutputStream()) { + socket.setKeepAlive(true); + + String path = url.getPath(); + StringBuffer outputBuffer = new StringBuffer(); + outputBuffer.append("POST " + path + " HTTP/1.1" + DELIMITER); + outputBuffer.append("Host: " + url.getHost() + DELIMITER); + outputBuffer.append("Connection: keep-alive" + DELIMITER); + outputBuffer.append("Content-Type: text/plain" + DELIMITER); + outputBuffer.append("Transfer-Encoding: chunked" + DELIMITER); + outputBuffer.append("Trailer: myTrailer, myTrailer2" + DELIMITER); + outputBuffer.append(DELIMITER); + outputBuffer.append("3" + DELIMITER); + outputBuffer.append("ABC" + DELIMITER); + outputBuffer.append("0" + DELIMITER); + outputBuffer.append("myTrailer:foo"); + outputBuffer.append(DELIMITER); + outputBuffer.append("myTrailer2:bar"); + outputBuffer.append(DELIMITER); + outputBuffer.append(DELIMITER); + + byte[] outputBytes = outputBuffer.toString().getBytes(ENCODING); + output.write(outputBytes); + output.flush(); + + input = socket.getInputStream(); + ByteArrayOutputStream bytes = new ByteArrayOutputStream(); + int read = 0; + while ((read = input.read()) >= 0) { + bytes.write(read); + } + String response = new String(bytes.toByteArray()); + TestUtil.logMsg(response); + if (response.indexOf("isTrailerFieldsReady: true") < 0) { + logger.error("isTrailerFieldsReady should be true"); + throw new Exception("TrailerTest failed."); + } + + if (!response.toLowerCase().contains("mytrailer=foo")) { + logger.error("failed to get trailer field: mytrailer=foo"); + throw new Exception("TrailerTest failed."); + } + + if (!response.toLowerCase().contains("mytrailer2=bar")) { + logger.error("failed to get trailer field: mytrailer=foo"); + throw new Exception("TrailerTest failed."); + } + } catch (Exception e) { + TestUtil.logErr("Caught exception: " + e.getMessage()); + e.printStackTrace(); + throw new Exception("TrailerTest failed: ", e); + } + } + + + /* + * @testName: TrailerTest2 + * + * @assertion_ids: servlet40:TrailerTest2; + * + * @test_Strategy: + */ + @Test + public void TrailerTest2() throws Exception { + simpleTest("TrailerTest2", getContextRoot() + "/TrailerTestServlet", "POST", + "isTrailerFieldsReady: true"); + simpleTest("TrailerTest2", getContextRoot() + "/TrailerTestServlet", "POST", + "Trailer: {}"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest40/DispatchServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest40/DispatchServlet.java new file mode 100644 index 0000000000..baf1879ad4 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest40/DispatchServlet.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2017, 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest40; + +import java.io.IOException; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +@WebServlet(asyncSupported = true, name = "DispatchServlet", value = "/DispatchServlet", loadOnStartup = 1) +public class DispatchServlet extends HttpServlet { + + public void doGet(HttpServletRequest req, HttpServletResponse resp) + throws IOException { + AsyncContext asyncContext = req.startAsync(); + asyncContext.setTimeout(0); + asyncContext.dispatch("/TestServlet"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest40/ForwardFilter.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest40/ForwardFilter.java new file mode 100644 index 0000000000..a6a87702c5 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest40/ForwardFilter.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2017, 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest40; + +import java.io.IOException; + +import jakarta.servlet.FilterChain; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpFilter; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class ForwardFilter extends HttpFilter { + + @Override + protected void doFilter(HttpServletRequest req, HttpServletResponse res, + FilterChain chain) throws IOException, ServletException { + req.getRequestDispatcher("/default").forward(req, res); + super.doFilter(req, res, chain); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest40/ForwardServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest40/ForwardServlet.java new file mode 100644 index 0000000000..1fa574b747 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest40/ForwardServlet.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2017, 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest40; + +import java.io.IOException; + +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class ForwardServlet extends HttpServlet { + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + RequestDispatcher rd = req.getRequestDispatcher("/a.ts"); + rd.forward(req, resp); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest40/IncludeServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest40/IncludeServlet.java new file mode 100644 index 0000000000..5bf7be14ac --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest40/IncludeServlet.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2017, 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest40; + +import java.io.IOException; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class IncludeServlet extends HttpServlet { + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + req.getRequestDispatcher("/").include(req, resp); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest40/NamedForwardServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest40/NamedForwardServlet.java new file mode 100644 index 0000000000..a9202ca53e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest40/NamedForwardServlet.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2017, 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest40; + +import java.io.IOException; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class NamedForwardServlet extends HttpServlet { + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + req.getServletContext().getNamedDispatcher("TestServlet").forward(req, + resp); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest40/NamedIncludeServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest40/NamedIncludeServlet.java new file mode 100644 index 0000000000..834a324ed6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest40/NamedIncludeServlet.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2017, 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest40; + +import java.io.IOException; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class NamedIncludeServlet extends HttpServlet { + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + req.getServletContext().getNamedDispatcher("TestServlet").include(req, + resp); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest40/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest40/TestServlet.java new file mode 100644 index 0000000000..050f53f9a9 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest40/TestServlet.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2017, 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest40; + +import java.io.IOException; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletMapping; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class TestServlet extends HttpServlet { + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + HttpServletMapping mapping = req.getHttpServletMapping(); + if (mapping == null) { + resp.getWriter().println("Get null HttpServletMapping"); + } else { + resp.getWriter().println(Utilities.toString(mapping)); + } + } + + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + this.doGet(req, resp); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest40/TrailerTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest40/TrailerTestServlet.java new file mode 100644 index 0000000000..1369d46c43 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest40/TrailerTestServlet.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2017, 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest40; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintWriter; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class TrailerTestServlet extends HttpServlet { + + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + InputStream in = req.getInputStream(); + int i = 0; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + while ((i = in.read()) != -1) { + out.write(i); + } + + PrintWriter writer = new PrintWriter(resp.getWriter()); + + writer.write("Chunk Data: " + new String(out.toByteArray())); + writer.println(); + writer.write("isTrailerFieldsReady: " + req.isTrailerFieldsReady()); + writer.println(); + writer.write("Trailer: " + req.getTrailerFields().toString()); + writer.flush(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest40/Utilities.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest40/Utilities.java new file mode 100644 index 0000000000..944421760a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest40/Utilities.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2017, 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest40; + +import jakarta.servlet.http.HttpServletMapping; + +public class Utilities { + + public static String toString(HttpServletMapping mapping) { + StringBuilder sb = new StringBuilder(); + sb.append("matchValue=" + mapping.getMatchValue()) + .append(", pattern=" + mapping.getPattern()) + .append(", servletName=" + mapping.getServletName()) + .append(", mappingMatch=" + mapping.getMappingMatch()); + return sb.toString(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest40/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest40/build.xml new file mode 100644 index 0000000000..a0bf9c10a2 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest40/build.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest40/servlet_jsh_httpservletrequest40_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest40/servlet_jsh_httpservletrequest40_web.xml new file mode 100644 index 0000000000..9dfbaa155c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequest40/servlet_jsh_httpservletrequest40_web.xml @@ -0,0 +1,91 @@ + + + + + SerJaxSerHttpHttpSerRequest31 + + ForwardFilter + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest40.ForwardFilter + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest40.TestServlet + + + defaultServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest40.TestServlet + + + ForwardServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest40.ForwardServlet + + + IncludeServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest40.IncludeServlet + + + NamedForwardServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest40.NamedForwardServlet + + + NamedIncludeServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest40.NamedIncludeServlet + + + TrailerTestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest40.TrailerTestServlet + + + + ForwardFilter + /ForwardFilter + + + TestServlet + /TestServlet + + + TestServlet + *.ts + + + defaultServlet + / + + + ForwardServlet + /ForwardServlet + + + IncludeServlet + /IncludeServlet + + + NamedForwardServlet + /NamedForwardServlet + + + NamedIncludeServlet + /NamedIncludeServlet + + + TrailerTestServlet + /TrailerTestServlet + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequestwrapper/SetCharacterEncodingTest.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequestwrapper/SetCharacterEncodingTest.java new file mode 100644 index 0000000000..3bdf4ac73a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequestwrapper/SetCharacterEncodingTest.java @@ -0,0 +1,46 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequestwrapper; + +import java.io.IOException; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletRequestWrapper; +import jakarta.servlet.ServletResponse; + +public class SetCharacterEncodingTest extends SetCharacterEncodingTestWrapper { + + public void init(ServletConfig servletConfig) throws ServletException { + super.init(servletConfig); + } + + // merely validate the default behavior of RequestWrapper -- delegates call + // to the ServletRequest object it wraps. + + public void service(ServletRequest servletRequest, + ServletResponse servletResponse) throws ServletException, IOException { + ServletRequestWrapper wrapper = new ServletRequestWrapper(servletRequest); + super.service(wrapper, servletResponse); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequestwrapper/SetCharacterEncodingTestWrapper.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequestwrapper/SetCharacterEncodingTestWrapper.java new file mode 100644 index 0000000000..cc921c8887 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequestwrapper/SetCharacterEncodingTestWrapper.java @@ -0,0 +1,46 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequestwrapper; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.RequestTests; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class SetCharacterEncodingTestWrapper extends GenericServlet { + + public void init(ServletConfig servletConfig) throws ServletException { + super.init(servletConfig); + } + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + RequestTests.setCharacterEncodingTest(pw, request, response); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequestwrapper/SetCharacterEncodingUnsupportedEncodingExceptionTest.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequestwrapper/SetCharacterEncodingUnsupportedEncodingExceptionTest.java new file mode 100644 index 0000000000..d91187f439 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequestwrapper/SetCharacterEncodingUnsupportedEncodingExceptionTest.java @@ -0,0 +1,45 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequestwrapper; + +import java.io.IOException; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletRequestWrapper; +import jakarta.servlet.ServletResponse; + +public class SetCharacterEncodingUnsupportedEncodingExceptionTest + extends SetCharacterEncodingUnsupportedEncodingExceptionTestWrapper { + + public void init(ServletConfig servletConfig) throws ServletException { + super.init(servletConfig); + } + + // merely validate the default behavior of RequestWrapper -- delegates call + // to the ServletRequest object it wraps. + public void service(ServletRequest servletRequest, + ServletResponse servletResponse) throws ServletException, IOException { + ServletRequestWrapper wrapper = new ServletRequestWrapper(servletRequest); + super.service(wrapper, servletResponse); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequestwrapper/SetCharacterEncodingUnsupportedEncodingExceptionTestWrapper.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequestwrapper/SetCharacterEncodingUnsupportedEncodingExceptionTestWrapper.java new file mode 100644 index 0000000000..77acd79ee6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequestwrapper/SetCharacterEncodingUnsupportedEncodingExceptionTestWrapper.java @@ -0,0 +1,43 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequestwrapper; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.RequestTests; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class SetCharacterEncodingUnsupportedEncodingExceptionTestWrapper + extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + RequestTests.setCharacterEncodingUnsupportedEncodingExceptionTest(pw, + request, response); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequestwrapper/TCKHttpSessionIDListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequestwrapper/TCKHttpSessionIDListener.java new file mode 100644 index 0000000000..73e2669a98 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequestwrapper/TCKHttpSessionIDListener.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequestwrapper; + +import jakarta.servlet.annotation.WebListener; +import jakarta.servlet.http.HttpSession; +import jakarta.servlet.http.HttpSessionEvent; +import jakarta.servlet.http.HttpSessionIdListener; + +@WebListener +public class TCKHttpSessionIDListener implements HttpSessionIdListener { + + public void sessionIdChanged(HttpSessionEvent event, String oldId) { + HttpSession session = event.getSession(); + String sessionId = session.getId(); + + session.setAttribute("OLD", oldId); + session.setAttribute("NEW", sessionId); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequestwrapper/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequestwrapper/TestServlet.java new file mode 100644 index 0000000000..4d86af5a83 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequestwrapper/TestServlet.java @@ -0,0 +1,48 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequestwrapper; + +import java.io.IOException; + +import com.sun.ts.tests.servlet.common.servlets.HttpRequestTestServlet; +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletRequestWrapper; +import jakarta.servlet.http.HttpServletResponse; + +public class TestServlet + extends HttpRequestTestServlet { + + public void init(ServletConfig servletConfig) throws ServletException { + super.init(servletConfig); + } + + // Simply validate the default behavior of the RequestWrapper is to delegate + // the call to the wrapped object. + public void service(HttpServletRequest servletRequest, + HttpServletResponse servletResponse) + throws ServletException, IOException { + HttpServletRequestWrapper wrapper = new HttpServletRequestWrapper( + servletRequest); + super.service(wrapper, servletResponse); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequestwrapper/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequestwrapper/URLClient.java new file mode 100644 index 0000000000..778cbd3631 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequestwrapper/URLClient.java @@ -0,0 +1,831 @@ +/* + * 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequestwrapper; + +import com.sun.ts.tests.servlet.common.request.HttpRequestClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends HttpRequestClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_jsh_HSReqWrapper_web.war").addAsLibraries(CommonServlets.getCommonServletsArchive()).addClasses(SetCharacterEncodingTest.class, SetCharacterEncodingTestWrapper.class, SetCharacterEncodingUnsupportedEncodingExceptionTest.class, SetCharacterEncodingUnsupportedEncodingExceptionTestWrapper.class, TCKHttpSessionIDListener.class, TestServlet.class).setWebXML(URLClient.class.getResource("servlet_jsh_HSReqWrapper_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + /* Run test */ + // --------------------------- ServletRequestWrapper + // --------------------------- + /* + * @testName: getAttributeNamesTest + * + * @assertion_ids: Servlet:JAVADOC:385 + * + * @test_Strategy: Servlet wraps the request. Servlet then sets some + * attributes and verifies they can be retrieved. + */ + /* + * @testName: getAttributeTest + * + * @assertion_ids: Servlet:JAVADOC:384 + * + * @test_Strategy: Servlet wraps the request. Servlet then sets an attribute + * and retrieves it. + */ + /* + * @testName: getCharacterEncodingTest + * + * @assertion_ids: Servlet:JAVADOC:386 + * + * @test_Strategy: Client sets an encoding. Servlet wraps the request. Servlet + * then tries to retrieve it. + */ + /* + * @testName: getContentLengthTest + * + * @assertion_ids: Servlet:JAVADOC:389 + * + * @test_Strategy: Servlet wraps the request. Servlet then compares this + * length to the actual length of the content body read in using + * getInputStream + */ + /* + * @testName: getContentTypeTest + * + * @assertion_ids: Servlet:JAVADOC:390; Servlet:SPEC:34; + * + * @test_Strategy: Client sets the content type. Servlet wraps the request. + * Servlet reads it from wrapped request. + * + */ + /* + * @testName: getInputStreamTest + * + * @assertion_ids: Servlet:JAVADOC:391 + * + * @test_Strategy: Servlet wraps the request. Servlet then tries to read the + * input stream. + */ + /* + * @testName: getLocaleTest + * + * @assertion_ids: Servlet:JAVADOC:407 + * + * @test_Strategy: Client specifics a locale, Servlet wraps the request. + * Servlet then verifies it. + */ + /* + * @testName: getLocalesTest + * + * @assertion_ids: Servlet:JAVADOC:408 + * + * @test_Strategy: Client specifics 2 locales.Servlet wraps the request. + * Servlet then verifies it. + */ + /* + * @testName: getParameterMapTest + * + * @assertion_ids: Servlet:JAVADOC:394 + * + * @test_Strategy: Client sets several parameters.Servlet wraps the request. + * Servlet then attempts to access them. + */ + /* + * @testName: getParameterNamesTest + * + * @assertion_ids: Servlet:JAVADOC:395 + * + * @test_Strategy: Client sets several parameters.Servlet wraps the request. + * Servlet then attempts to access them. + */ + /* + * @testName: getParameterTest + * + * @assertion_ids: Servlet:JAVADOC:393 + * + * @test_Strategy: Client sets a parameter.Servlet wraps the request. Servlet + * then retrieves parameter. + */ + /* + * @testName: getParameterValuesTest + * + * @assertion_ids: Servlet:JAVADOC:396 + * + * @test_Strategy: Client sets a parameter which has 2 values.Servlet wraps + * the request. Servlet then verifies both values. + */ + /* + * @testName: getProtocolTest + * + * @assertion_ids: Servlet:JAVADOC:397 + * + * @test_Strategy: Servlet wraps the request. Servlet then verifies the + * protocol used by the client + */ + /* + * @testName: getReaderTest + * + * @assertion_ids: Servlet:JAVADOC:401 + * + * @test_Strategy: Client sets some content.Servlet wraps the request. Servlet + * then reads the content + */ + /* + * @testName: getRemoteAddrTest + * + * @assertion_ids: Servlet:JAVADOC:403 + * + * @test_Strategy: Servlet wraps the request. Servlet then reads and verifies + * where the request originated + */ + /* + * @testName: getRemoteHostTest + * + * @assertion_ids: Servlet:JAVADOC:404 + * + * @test_Strategy: Servlet wraps the request. Servlet then reads and verifies + * where the request originated + */ + /* + * @testName: getRequestDispatcherTest + * + * @assertion_ids: Servlet:JAVADOC:410 + * + * @test_Strategy: Servlet wraps the request. Servlet then tries to get a + * dispatcher + */ + /* + * @testName: getSchemeTest + * + * @assertion_ids: Servlet:JAVADOC:398 + * + * @test_Strategy: Servlet wraps the request. Servlet then verifies the scheme + * of the url used in the request + */ + /* + * @testName: getServerNameTest + * + * @assertion_ids: Servlet:JAVADOC:399 + * + * @test_Strategy: Servlet wraps the request. Servlet then verifies the + * destination of the request + */ + /* + * @testName: getServerPortTest + * + * @assertion_ids: Servlet:JAVADOC:400 + * + * @test_Strategy: Servlet wraps the request. Servlet then verifies the + * destination port of the request + */ + /* + * @testName: isSecureTest + * + * @assertion_ids: Servlet:JAVADOC:409 + * + * @test_Strategy: Servlet wraps the request. Servlet then verifies the + * isSecure method for the non-secure case. + */ + /* + * @testName: removeAttributeTest + * + * @assertion_ids: Servlet:JAVADOC:406 + * + * @test_Strategy: Servlet wraps the request. Servlet then adds then removes + * an attribute, then verifies it was removed. + */ + /* + * @testName: setAttributeTest + * + * @assertion_ids: Servlet:JAVADOC:405 + * + * @test_Strategy: Servlet wraps the request. Servlet then adds an attribute, + * then verifies it was added + */ + /* + * @testName: setCharacterEncodingUnsupportedEncodingExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:388 + * + * @test_Strategy: Servlet wraps the request. Servlet then tries to set an + * invalid encoding. + */ + /* + * @testName: setCharacterEncodingTest + * + * @assertion_ids: Servlet:JAVADOC:387 + * + * @test_Strategy: Servlet wraps the request. Servlet then sets a new encoding + * and tries to retrieve it. + */ + /* + * @testName: setCharacterEncodingTest1 + * + * @assertion_ids: Servlet:JAVADOC:387; Servlet:JAVADOC:386; Servlet:SPEC:28; + * Servlet:SPEC:213; + * + * @test_Strategy: Servlet wraps the HttpServletRequest. HttpServletRequest + * calls getReader(); then sets a new encoding and tries to retrieve it. + * verifies that the new encoding is ignored. + */ + // ---------------------- END ServletRequestWrapper + // ---------------------------- + // ------------------------ HttpServletRequestWrapper + // -------------------------- + /* + * @testName: httpRequestWrapperConstructorTest + * + * @assertion_ids: Servlet:JAVADOC:355 + * + * @test_Strategy: Validate an IllegalArgumentException is thrown is a null + * request is passed to the Wrapper's constructor. + */ + @Test + public void httpRequestWrapperConstructorTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "httpRequestWrapperConstructorTest"); + invoke(); + } + + /* + * @testName: httpRequestWrapperConstructorIllegalArgumentExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:626 + * + * @test_Strategy: Validate an IllegalArgumentException is thrown is a null + * request is passed to the Wrapper's constructor. + */ + @Test + public void httpRequestWrapperConstructorIllegalArgumentExceptionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "httpRequestWrapperConstructorIllegalArgumentExceptionTest"); + invoke(); + } + + /* + * @testName: getAuthTypeWithoutProtectionTest + * + * @assertion_ids: Servlet:JAVADOC:356 + * + * @test_Strategy: Servlet wraps the request. Servlet verifies correct result + */ + /* + * @testName: getContextPathTest + * + * @assertion_ids: Servlet:JAVADOC:366 + * + * @test_Strategy: Client sets header and servlet verifies the result + */ + /* + * @testName: getCookiesTest + * + * @assertion_ids: Servlet:JAVADOC:357 + * + * @test_Strategy:Client sets a cookie and servlet tries to read it + */ + /* + * @testName: getDateHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:358 + * + * @test_Strategy: client sets a dateheader and servlet tries to read it. + */ + /* + * @testName: getHeaderNamesTest + * + * @assertion_ids: Servlet:JAVADOC:361 + * + * @test_Strategy: Client sets some headers and servlet tries to read them + */ + /* + * @testName: getHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:359 + * + * @test_Strategy: Client sets a header and servlet tries to read it. + */ + /* + * @testName: getHeadersTest + * + * @assertion_ids: Servlet:JAVADOC:360 + * + * @test_Strategy: Client sets some headers and servlet tries to read them + */ + /* + * @testName: getIntHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:362 + * + * @test_Strategy: Client sets a header and servlet reads it + */ + /* + * @testName: getMethodTest + * + * @assertion_ids: Servlet:JAVADOC:363 + * + * @test_Strategy: Client makes 3 calls using GET/POST/HEAD + */ + /* + * @testName: getPathInfoTest + * + * @assertion_ids: Servlet:JAVADOC:364; Servlet:SPEC:25; + * + * @test_Strategy: Servlet wraps the request. Servlet verifies path info + */ + /* + * @testName: getPathTranslatedTest + * + * @assertion_ids: Servlet:JAVADOC:365 + * + * @test_Strategy: client sets extra path info and servlet verifies it + */ + /* + * @testName: getQueryStringTest + * + * @assertion_ids: Servlet:JAVADOC:367 + * + * @test_Strategy: Client sets query string and servlet verifies it + */ + /* + * @testName: getRemoteUserTest + * + * @assertion_ids: Servlet:JAVADOC:368 + * + * @test_Strategy: Servlet wraps the request. Servlet verifies the result of a + * non-authed user + */ + /* + * @testName: getRequestURITest + * + * @assertion_ids: Servlet:JAVADOC:372 + * + * @test_Strategy: Servlet wraps the request. Servlet verifies URI data + */ + /* + * @testName: getRequestURLTest + * + * @assertion_ids: Servlet:JAVADOC:373 + * + * @test_Strategy: Servlet wraps the request. Servlet verifies URL info + */ + /* + * @testName: getRequestedSessionIdNullTest + * + * @assertion_ids: Servlet:JAVADOC:371 + * + * @test_Strategy: Servlet wraps the request. Servlet verifies null result + */ + /* + * @testName: getServletPathTest + * + * @assertion_ids: Servlet:JAVADOC:374; Servlet:SPEC:24; + * + * @test_Strategy: Servlet wraps the request. Servlet verifies path info + */ + /* + * @testName: getSessionTrueTest + * + * @assertion_ids: Servlet:JAVADOC:375 + * + * @test_Strategy: Servlet wraps the request. Servlet verifies + * getSession(boolean) call + */ + /* + * @testName: getSessionTest + * + * @assertion_ids: Servlet:JAVADOC:376 + * + * @test_Strategy: Servlet wraps the request. Servlet verifies getSession() + * call + */ + /* + * @testName: isRequestedSessionIdFromCookieTest + * + * @assertion_ids: Servlet:JAVADOC:378 + * + * @test_Strategy: Access Servlet through URL; Servlet wraps the request; + * Servlet verifies API isRequestedSessionIdFromCookie return false; Negative + * test + */ + /* + * @testName: isRequestedSessionIdFromCookieTest1 + * + * @assertion_ids: Servlet:JAVADOC:378 + * + * @test_Strategy: Access Servlet through URL; Servlet wraps the request; + * Servlet starts a HttpSession; Client saves SessionID from Server and use it + * to access Servlet again; Servlet verifies API + * isRequestedSessionIdFromCookie return true; Positive test + */ + /* + * @testName: isRequestedSessionIdFromURLTest + * + * @assertion_ids: Servlet:JAVADOC:379 + * + * @test_Strategy: Servlet wraps the request. Servlet verifies correct result + */ + /* + * @testName: isRequestedSessionIdValidTest + * + * @assertion_ids: Servlet:JAVADOC:377; Servlet:SPEC:211; + * + * @test_Strategy: Client sends request without session ID; Servlet wraps the + * request; Verifies isRequestedSessionIdValid() returns false; + */ + /* + * @testName: getRequestedSessionIdTest1 + * + * @assertion_ids: Servlet:JAVADOC:371; + * + * @test_Strategy: Client sends request with a session ID; Verifies + * getRequestedSessionId() returns the same; + */ + /* + * @testName: getRequestedSessionIdTest2 + * + * @assertion_ids: Servlet:JAVADOC:371; + * + * @test_Strategy: Client sends request to a servlet with a sesion ID; Servlet + * start a sesison; Verifies getRequestedSessionId() returns the same; + */ + /* + * @testName: getLocalPortTest + * + * @assertion_ids: Servlet:JAVADOC:631; + * + * @test_Strategy: Send an HttpServletRequestWrapper to server; Test Servlet + * API getLocalPort(); + */ + /* + * @testName: getLocalNameTest + * + * @assertion_ids: Servlet:JAVADOC:634; + * + * @test_Strategy: Send an HttpServletRequestWrapper to server; Test Servlet + * API getLocalName(); + */ + /* + * @testName: changeSessionIDTest + * + * @assertion_ids: Servlet:JAVADOC:932.1; + * + * @test_Strategy: Send an HttpServletRequest to server; Verify that + * request.changeSessionId() throws IllegalStateException when it is called + * without a session; + */ + /* + * @testName: changeSessionIDTest1 + * + * @assertion_ids: Servlet:JAVADOC:304; Servlet:JAVADOC:375; + * Servlet:JAVADOC:467; Servlet:JAVADOC:476; Servlet:JAVADOC:484; + * Servlet:JAVADOC:932; Servlet:JAVADOC:935; + * + * @test_Strategy: Send an HttpServletRequest to server; Verify that + * request.changeSessionId() works. + */ + /* + * @testName: httpRequestWrapperGetRequestTest + * + * @assertion_ids: Servlet:JAVADOC:381 + * + * @test_Strategy: Servlet gets wrapped response object + */ + @Test + public void httpRequestWrapperGetRequestTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "httpRequestWrapperGetRequestTest"); + invoke(); + } + + /* + * @testName: httpRequestWrapperSetRequestTest + * + * @assertion_ids: Servlet:JAVADOC:382 + * + * @test_Strategy: Servlet sets wrapped response object + */ + @Test + public void httpRequestWrapperSetRequestTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "httpRequestWrapperSetRequestTest"); + invoke(); + } + + /* + * @testName: httpRequestWrapperSetRequestIllegalArgumentExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:383 + * + * @test_Strategy: Servlet sets wrapped response object + */ + @Test + public void httpRequestWrapperSetRequestIllegalArgumentExceptionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "httpRequestWrapperSetRequestIllegalArgumentExceptionTest"); + invoke(); + } + + // ---------------------- END HttpServletRequestWrapper + // ------------------------ + @Test() + public void changeSessionIDTest() throws Exception { + super.changeSessionIDTest(); + } + + @Test() + public void changeSessionIDTest1() throws Exception { + super.changeSessionIDTest1(); + } + + @Test() + public void getAttributeNamesTest() throws Exception { + super.getAttributeNamesTest(); + } + + @Test() + public void getAttributeTest() throws Exception { + super.getAttributeTest(); + } + + @Test() + public void getAuthTypeWithoutProtectionTest() throws Exception { + super.getAuthTypeWithoutProtectionTest(); + } + + @Test() + public void getCharacterEncodingTest() throws Exception { + super.getCharacterEncodingTest(); + } + + @Test() + public void getContentLengthTest() throws Exception { + super.getContentLengthTest(); + } + + @Test() + public void getContentTypeTest() throws Exception { + super.getContentTypeTest(); + } + + @Test() + public void getContextPathTest() throws Exception { + super.getContextPathTest(); + } + + @Test() + public void getCookiesTest() throws Exception { + super.getCookiesTest(); + } + + @Test() + public void getDateHeaderTest() throws Exception { + super.getDateHeaderTest(); + } + + @Test() + public void getHeaderNamesTest() throws Exception { + super.getHeaderNamesTest(); + } + + @Test() + public void getHeaderTest() throws Exception { + super.getHeaderTest(); + } + + @Test() + public void getHeadersTest() throws Exception { + super.getHeadersTest(); + } + + @Test() + public void getInputStreamTest() throws Exception { + super.getInputStreamTest(); + } + + @Test() + public void getIntHeaderTest() throws Exception { + super.getIntHeaderTest(); + } + + @Test() + public void getLocalNameTest() throws Exception { + super.getLocalNameTest(); + } + + @Test() + public void getLocalPortTest() throws Exception { + super.getLocalPortTest(); + } + + @Test() + public void getLocaleTest() throws Exception { + super.getLocaleTest(); + } + + @Test() + public void getLocalesTest() throws Exception { + super.getLocalesTest(); + } + + @Test() + public void getMethodTest() throws Exception { + super.getMethodTest(); + } + + @Test() + public void getParameterMapTest() throws Exception { + super.getParameterMapTest(); + } + + @Test() + public void getParameterNamesTest() throws Exception { + super.getParameterNamesTest(); + } + + @Test() + public void getParameterTest() throws Exception { + super.getParameterTest(); + } + + @Test() + public void getParameterValuesTest() throws Exception { + super.getParameterValuesTest(); + } + + @Test() + public void getPathInfoTest() throws Exception { + super.getPathInfoTest(); + } + + @Test() + public void getPathTranslatedTest() throws Exception { + super.getPathTranslatedTest(); + } + + @Test() + public void getProtocolTest() throws Exception { + super.getProtocolTest(); + } + + @Test() + public void getQueryStringTest() throws Exception { + super.getQueryStringTest(); + } + + @Test() + public void getReaderTest() throws Exception { + super.getReaderTest(); + } + + @Test() + public void getRemoteAddrTest() throws Exception { + super.getRemoteAddrTest(); + } + + @Test() + public void getRemoteHostTest() throws Exception { + super.getRemoteHostTest(); + } + + @Test() + public void getRemoteUserTest() throws Exception { + super.getRemoteUserTest(); + } + + @Test() + public void getRequestDispatcherTest() throws Exception { + super.getRequestDispatcherTest(); + } + + @Test() + public void getRequestURITest() throws Exception { + super.getRequestURITest(); + } + + @Test() + public void getRequestURLTest() throws Exception { + super.getRequestURLTest(); + } + + @Test() + public void getRequestedSessionIdNullTest() throws Exception { + super.getRequestedSessionIdNullTest(); + } + + @Test() + public void getRequestedSessionIdTest1() throws Exception { + super.getRequestedSessionIdTest1(); + } + + @Test() + public void getRequestedSessionIdTest2() throws Exception { + super.getRequestedSessionIdTest2(); + } + + @Test() + public void getSchemeTest() throws Exception { + super.getSchemeTest(); + } + + @Test() + public void getServerNameTest() throws Exception { + super.getServerNameTest(); + } + + @Test() + public void getServerPortTest() throws Exception { + super.getServerPortTest(); + } + + @Test() + public void getServletPathTest() throws Exception { + super.getServletPathTest(); + } + + @Test() + public void getSessionTest() throws Exception { + super.getSessionTest(); + } + + @Test() + public void getSessionTrueTest() throws Exception { + super.getSessionTrueTest(); + } + + @Test() + public void isRequestedSessionIdFromCookieTest() throws Exception { + super.isRequestedSessionIdFromCookieTest(); + } + + @Test() + public void isRequestedSessionIdFromCookieTest1() throws Exception { + super.isRequestedSessionIdFromCookieTest1(); + } + + @Test() + public void isRequestedSessionIdFromURLTest() throws Exception { + super.isRequestedSessionIdFromURLTest(); + } + + @Test() + public void isRequestedSessionIdValidTest() throws Exception { + super.isRequestedSessionIdValidTest(); + } + + @Test() + public void isSecureTest() throws Exception { + super.isSecureTest(); + } + + @Test() + public void removeAttributeTest() throws Exception { + super.removeAttributeTest(); + } + + @Test() + public void setAttributeTest() throws Exception { + super.setAttributeTest(); + } + + @Test() + public void setCharacterEncodingTest() throws Exception { + super.setCharacterEncodingTest(); + } + + @Test() + public void setCharacterEncodingTest1() throws Exception { + super.setCharacterEncodingTest1(); + } + + @Test() + public void setCharacterEncodingUnsupportedEncodingExceptionTest() throws Exception { + super.setCharacterEncodingUnsupportedEncodingExceptionTest(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequestwrapper/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequestwrapper/build.xml new file mode 100644 index 0000000000..8afda4b624 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequestwrapper/build.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequestwrapper/servlet_jsh_HSReqWrapper_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequestwrapper/servlet_jsh_HSReqWrapper_web.xml new file mode 100644 index 0000000000..e702b40c2d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletrequestwrapper/servlet_jsh_HSReqWrapper_web.xml @@ -0,0 +1,65 @@ + + + + + HttpSerReqWrap + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequestwrapper.TestServlet + + + setCharacterEncodingUnsupportedEncodingExceptionTestWrapper + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequestwrapper.SetCharacterEncodingUnsupportedEncodingExceptionTestWrapper + + + setCharacterEncodingUnsupportedEncodingExceptionTest + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequestwrapper.SetCharacterEncodingUnsupportedEncodingExceptionTest + + + setCharacterEncodingTestWrapper + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequestwrapper.SetCharacterEncodingTestWrapper + + + setCharacterEncodingTest + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequestwrapper.SetCharacterEncodingTest + + + TestServlet + /TestServlet/* + + + setCharacterEncodingUnsupportedEncodingExceptionTestWrapper + /setCharacterEncodingUnsupportedEncodingExceptionTestWrapper + + + setCharacterEncodingUnsupportedEncodingExceptionTest + /setCharacterEncodingUnsupportedEncodingExceptionTest + + + setCharacterEncodingTestWrapper + /setCharacterEncodingTestWrapper + + + setCharacterEncodingTest + /setCharacterEncodingTest + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse/GetContentTypeNullTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse/GetContentTypeNullTestServlet.java new file mode 100644 index 0000000000..001ab7d5b0 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse/GetContentTypeNullTestServlet.java @@ -0,0 +1,77 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponse; + +import java.io.IOException; + +import com.sun.ts.tests.servlet.common.response.ResponseTests; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class GetContentTypeNullTestServlet extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + System.out.println("CONTENT_TYPE: " + response.getContentType()); + ResponseTests.getContentTypeNullTest(request, response); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse/RedirectedTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse/RedirectedTestServlet.java new file mode 100644 index 0000000000..2435b981a9 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse/RedirectedTestServlet.java @@ -0,0 +1,79 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponse; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class RedirectedTestServlet extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + ServletTestUtil.printResult(pw, true); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse/ServletErrorPage.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse/ServletErrorPage.java new file mode 100644 index 0000000000..abf4d0c82b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse/ServletErrorPage.java @@ -0,0 +1,74 @@ +/* + * 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 com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponse; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +/** + * Simple Servlet-based error page that displays error related req attributes. + */ + +public class ServletErrorPage extends HttpServlet { + + private static final String STATUS_CODE = RequestDispatcher.ERROR_STATUS_CODE; // "jakarta.servlet.error.status_code"; + + private static final String EXCEPTION_TYPE = RequestDispatcher.ERROR_EXCEPTION_TYPE; //"jakarta.servlet.error.exception_type"; + + private static final String MESSAGE = RequestDispatcher.ERROR_MESSAGE; //"jakarta.servlet.error.message"; + + private static final String EXCEPTION = RequestDispatcher.ERROR_EXCEPTION; //"jakarta.servlet.error.exception" + + private static final String REQUEST_URI = RequestDispatcher.ERROR_REQUEST_URI; //"jakarta.servlet.error.request_uri"; + + private static final String SERVLET_NAME = RequestDispatcher.ERROR_SERVLET_NAME; //"jakarta.servlet.error.servlet_name" + + private static final String EXP_MESSAGE = "error page invoked"; + + /** + * Invoked by container + */ + public void service(HttpServletRequest req, HttpServletResponse res) + throws ServletException, IOException { + + PrintWriter pw = res.getWriter(); + // display req attributes + pw.println("Servlet Name: " + req.getAttribute(SERVLET_NAME)); + pw.println("Request URI: " + req.getAttribute(REQUEST_URI)); + pw.println("Status Code: " + req.getAttribute(STATUS_CODE)); + pw.println("Exception Type: " + req.getAttribute(EXCEPTION_TYPE)); + pw.println("Exception: " + req.getAttribute(EXCEPTION)); + pw.print("Message: "); + if (((String) req.getAttribute(MESSAGE)).indexOf(EXP_MESSAGE) > -1) { + pw.println(EXP_MESSAGE); + } + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse/SetCharacterEncodingTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse/SetCharacterEncodingTestServlet.java new file mode 100644 index 0000000000..50a25407bf --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse/SetCharacterEncodingTestServlet.java @@ -0,0 +1,77 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponse; + +import java.io.IOException; + +import com.sun.ts.tests.servlet.common.response.ResponseTests; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class SetCharacterEncodingTestServlet extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + ResponseTests.setCharacterEncodingTest(request, response); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse/URLClient.java new file mode 100644 index 0000000000..9f8c384d05 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse/URLClient.java @@ -0,0 +1,621 @@ +/* + * 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponse; + +import com.sun.ts.tests.servlet.common.response.HttpResponseClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.slf4j.LoggerFactory; + +public class URLClient extends HttpResponseClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_jsh_httpservletresponse_web.war").addAsLibraries(CommonServlets.getCommonServletsArchive()).addClasses(GetContentTypeNullTestServlet.class, RedirectedTestServlet.class, ServletErrorPage.class, SetCharacterEncodingTestServlet.class).setWebXML(URLClient.class.getResource("servlet_jsh_httpservletresponse_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + /* Run test */ + // --------------------------- ServletResponse + // ---------------------------------- + /* + * @testName: flushBufferTest + * + * @assertion_ids: Servlet:JAVADOC:603 + * + * @test_Strategy: Servlet writes data in the buffer and flushes it + */ + /* + * @testName: getBufferSizeTest + * + * @assertion_ids: Servlet:JAVADOC:605 + * + * @test_Strategy: Servlet flushes buffer and verifies the size of the buffer + */ + /* + * @testName: getLocaleDefaultTest + * + * @assertion_ids: Servlet:JAVADOC:625; + * + * @test_Strategy: Validate that getLocale() will return the default locale of + * the VM that the container is running in when setLocale() is not called. + */ + /* + * @testName: getLocaleTest + * + * @assertion_ids: Servlet:JAVADOC:608 + * + * @test_Strategy: Servlet set Locale and then verifies it + * + */ + /* + * @testName: getOutputStreamTest + * + * @assertion_ids: Servlet:JAVADOC:609 + * + * @test_Strategy: Servlet gets an output stream and writes to it. + */ + /* + * @testName: getOutputStreamIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:611 + * + * @test_Strategy: Servlet tries to get an stream object after calling + * getWriter + */ + /* + * @testName: getWriterTest + * + * @assertion_ids: Servlet:JAVADOC:612; Servlet:JAVADOC:151.2; + * Servlet:JAVADOC:151.3; + * + * @test_Strategy: Servlet gets a Writer object and writes data; sets content + * type by calling ServletResponse.setContentType; Verify that content type + * gets set, not encoding + */ + /* + * @testName: getWriterIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:615 + * + * @test_Strategy: Servlet tries to get a Writer object after calling + * getOutputStream + */ + /* + * @testName: isCommittedTest + * + * @assertion_ids: Servlet:JAVADOC:616 + * + * @test_Strategy: Servlet checks before and after response is flushed + * + */ + /* + * @testName: resetBufferTest + * + * @assertion_ids: Servlet:JAVADOC:619; Servlet:SPEC:31; + * + * @test_Strategy: Servlet writes data to the response, resets the buffer and + * then writes new data + */ + /* + * @testName: resetTest + * + * @assertion_ids: Servlet:JAVADOC:617; Servlet:SPEC:31; + * + * @test_Strategy: Servlet writes data to the response, does a reset, then + * writes new data + */ + /* + * @testName: resetTest1 + * + * @assertion_ids: Servlet:JAVADOC:617; Servlet:SPEC:31; + * + * @test_Strategy: Servlet writes data to the response, set the Headers, does + * a reset, then writes new data, set the new Header + */ + /* + * @testName: resetIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:618; Servlet:SPEC:31; + * + * @test_Strategy: Servlet writes data, flushes the buffer then tries to do a + * reset + */ + /* + * @testName: getCharacterEncodingDefaultTest + * + * @assertion_ids: Servlet:JAVADOC:606 + * + * @test_Strategy: Servlet checks for the default encoding + */ + /* + * @testName: getCharacterEncodingTest + * + * @assertion_ids: Servlet:JAVADOC:606 + * + * @test_Strategy: Servlet sets encoding then checks it. + */ + /* + * @testName: setCharacterEncodingTest + * + * @assertion_ids: Servlet:JAVADOC:622; Servlet:JAVADOC:151.3; + * + * @test_Strategy: Servlet set encoding by calling + * ServletResponse.setCharcaterEncoding; client verifies it is set + */ + /* + * @testName: setBufferSizeTest + * + * @assertion_ids: Servlet:JAVADOC:620 + * + * @test_Strategy: Servlet sets the buffer size then verifies it was set + */ + /* + * @testName: setBufferSizeIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:621 + * + * @test_Strategy: Servlet writes data and flushes buffer then tries to get + * the buffer size + */ + /* + * @testName: setContentLengthTest + * + * @assertion_ids: Servlet:JAVADOC:623 + * + * @test_Strategy: Servlet sets the content length + */ + /* + * @testName: getContentTypeTest + * + * @assertion_ids: Servlet:JAVADOC:607; Servlet:SPEC:34; + * + * @test_Strategy: Servlet verifies the content type + */ + @Test + public void getContentTypeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getContentTypeTest"); + invoke(); + TEST_PROPS.setProperty(REQUEST, "GET /servlet_jsh_httpservletresponse_web/GetContentTypeNullTestServlet HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Test PASSED"); + invoke(); + } + + /* + * @testName: setContentTypeTest + * + * @assertion_ids: Servlet:JAVADOC:624; Servlet:JAVADOC:151.3; + * Servlet:SPEC:34; + * + * @test_Strategy: Servlet sets the content type; Verify Content-Type is set + * in Client + */ + /* + * @testName: setContentType1Test + * + * @assertion_ids: Servlet:JAVADOC:151; Servlet:SPEC:34; + * + * @test_Strategy: Servlet sets the content-type, and verifies it with + * getContentType() + */ + /* + * @testName: setContentType2Test + * + * @assertion_ids: Servlet:JAVADOC:151.2; Servlet:JAVADOC:151.3; + * Servlet:SPEC:34; + * + * @test_Strategy: Servlet sets the content-type, Commit the response; Set the + * content-type again Verifies that content-type is set the first time The + * second setting is ignored. + */ + /* + * @testName: setLocaleTest + * + * @assertion_ids: Servlet:JAVADOC:625 + * + * @test_Strategy: Servlet sets the Locale + */ + // ---------------------------- END ServletResponse + // ----------------------------- + // ------------------------ HttpServletResponse + // --------------------------------- + /* + * @testName: addCookieTest + * + * @assertion_ids: Servlet:JAVADOC:502 + * + * @test_Strategy: Servlet adds 2 cookies, client verifies them + */ + /* + * @testName: addDateHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:522 + * + * @test_Strategy: Servlet adds a date header and client verifies it + */ + /* + * @testName: addHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:525 + * + * @test_Strategy: Servlet adds 2 headers with 3 values and client verifies + * them + */ + /* + * @testName: addIntHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:527 + * + * @test_Strategy: Servlet adds 2 int headers with 3 values and client + * verifies them + */ + /* + * @testName: containsHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:503 + * + * @test_Strategy: Servlet sets a header and verifies it exists, then the + * servlet tries to verify that a header does not exist. + */ + /* + * @testName: sendErrorIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:514 + * + * @test_Strategy: Servlet adds a header, a cookie, and content, then flushes + * the buffer. Servlet verifies exception is generated + */ + /* + * @testName: sendError_StringIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:511 + * + * @test_Strategy: Servlet adds a header, a cookie, and content, then flushes + * the buffer. Servlet verifies exception is generated + */ + /* + * @testName: sendErrorClearBufferTest + * + * @assertion_ids: Servlet:JAVADOC:512; Servlet:SPEC:39; + * + * @test_Strategy: Servlet adds content and an error, client verifies the + * error and that the content was cleared + */ + /* + * @testName: sendError_StringTest + * + * @assertion_ids: Servlet:JAVADOC:508 + * + * @test_Strategy: Servlet adds a header, a cookie and an error, client + * verifies the error and that the header still exists + */ + /* + * @testName: sendError_StringErrorPageTest + * + * @assertion_ids: Servlet:JAVADOC:509 + * + * @test_Strategy: Servlet adds a header, a cookie and content and an error. + * There also is an error page configured to catch error. Client verifies the + * error. + */ + /* + * @testName: sendRedirectWithLeadingSlashTest + * + * @assertion_ids: Servlet:JAVADOC:516 + * + * @test_Strategy: Servlet redirects to another servlet + */ + /* + * @testName: sendRedirectWithoutLeadingSlashTest + * + * @assertion_ids: Servlet:JAVADOC:515 + * + * @test_Strategy: Servlet redirects to another servlet + */ + /* + * @testName: sendRedirectIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:519 + * + * @test_Strategy: Servlet flushes the buffer then tries to redirect + */ + /* + * @testName: setDateHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:520 + * + * @test_Strategy: Servlet sets a date header and client verifies it + */ + /* + * @testName: setDateHeaderOverrideTest + * + * @assertion_ids: Servlet:JAVADOC:521 + * + * @test_Strategy: Servlet sets the same date header twice and client verifies + * it + */ + /* + * @testName: setHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:523 + * + * @test_Strategy: Servlet sets a header and client verifies it + */ + /* + * @testName: setHeaderOverrideTest + * + * @assertion_ids: Servlet:JAVADOC:524 + * + * @test_Strategy: Servlet sets the same header twice and client verifies it + */ + /* + * @testName: setMultiHeaderTest + * + * @assertion_ids: Servlet:SPEC:183; Servlet:JAVADOC:523; Servlet:JAVADOC:525; + * Servlet:JAVADOC:524 + * + * @test_Strategy: Servlet sets the multivalues for the same header; verify + * that setHeader clear all with new value + */ + /* + * @testName: setIntHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:526 + * + * @test_Strategy: Servlet sets an int header and client verifies it + */ + /* + * @testName: setStatusTest + * + * @assertion_ids: Servlet:JAVADOC:528 + * + * @test_Strategy: Servlet sets a status and client verifies it + */ + // ----------------------- END HttpServletResponse + // ------------------------------ + @Test() + public void addCookieTest() throws Exception { + super.addCookieTest(); + } + + @Test() + public void addDateHeaderTest() throws Exception { + super.addDateHeaderTest(); + } + + @Test() + public void addHeaderTest() throws Exception { + super.addHeaderTest(); + } + + @Test() + public void addIntHeaderTest() throws Exception { + super.addIntHeaderTest(); + } + + @Test() + public void containsHeaderTest() throws Exception { + super.containsHeaderTest(); + } + + @Test() + public void flushBufferTest() throws Exception { + super.flushBufferTest(); + } + + @Test() + public void getBufferSizeTest() throws Exception { + super.getBufferSizeTest(); + } + + @Test() + public void getCharacterEncodingDefaultTest() throws Exception { + super.getCharacterEncodingDefaultTest(); + } + + @Test() + public void getCharacterEncodingTest() throws Exception { + super.getCharacterEncodingTest(); + } + + @Test() + public void getLocaleDefaultTest() throws Exception { + super.getLocaleDefaultTest(); + } + + @Test() + public void getLocaleTest() throws Exception { + super.getLocaleTest(); + } + + @Test() + public void getOutputStreamIllegalStateExceptionTest() throws Exception { + super.getOutputStreamIllegalStateExceptionTest(); + } + + @Test() + public void getOutputStreamTest() throws Exception { + super.getOutputStreamTest(); + } + + @Test() + public void getWriterIllegalStateExceptionTest() throws Exception { + super.getWriterIllegalStateExceptionTest(); + } + + @Test() + public void getWriterTest() throws Exception { + super.getWriterTest(); + } + + @Test() + public void isCommittedTest() throws Exception { + super.isCommittedTest(); + } + + @Test() + public void resetBufferTest() throws Exception { + super.resetBufferTest(); + } + + @Test() + public void resetIllegalStateExceptionTest() throws Exception { + super.resetIllegalStateExceptionTest(); + } + + @Test() + public void resetTest() throws Exception { + super.resetTest(); + } + + @Test() + public void resetTest1() throws Exception { + super.resetTest1(); + } + + @Test() + public void sendErrorClearBufferTest() throws Exception { + super.sendErrorClearBufferTest(); + } + + @Test() + public void sendErrorIllegalStateExceptionTest() throws Exception { + super.sendErrorIllegalStateExceptionTest(); + } + + @Test() + public void sendError_StringErrorPageTest() throws Exception { + super.sendError_StringErrorPageTest(); + } + + @Test() + public void sendError_StringIllegalStateExceptionTest() throws Exception { + super.sendError_StringIllegalStateExceptionTest(); + } + + @Test() + public void sendError_StringTest() throws Exception { + super.sendError_StringTest(); + } + + @Test() + public void sendRedirectIllegalStateExceptionTest() throws Exception { + super.sendRedirectIllegalStateExceptionTest(); + } + + @Test() + public void sendRedirectWithLeadingSlashTest() throws Exception { + super.sendRedirectWithLeadingSlashTest(); + } + + @Test() + public void sendRedirectWithoutLeadingSlashTest() throws Exception { + super.sendRedirectWithoutLeadingSlashTest(); + } + + @Test() + public void setBufferSizeIllegalStateExceptionTest() throws Exception { + super.setBufferSizeIllegalStateExceptionTest(); + } + + @Test() + public void setBufferSizeTest() throws Exception { + super.setBufferSizeTest(); + } + + @Test() + public void setCharacterEncodingTest() throws Exception { + super.setCharacterEncodingTest(); + } + + @Test() + public void setContentLengthTest() throws Exception { + super.setContentLengthTest(); + } + + @Test() + public void setContentType1Test() throws Exception { + super.setContentType1Test(); + } + + @Test() + public void setContentType2Test() throws Exception { + super.setContentType2Test(); + } + + @Test() + public void setContentTypeTest() throws Exception { + super.setContentTypeTest(); + } + + @Test() + public void setDateHeaderOverrideTest() throws Exception { + super.setDateHeaderOverrideTest(); + } + + @Test() + public void setDateHeaderTest() throws Exception { + super.setDateHeaderTest(); + } + + @Test() + public void setHeaderOverrideTest() throws Exception { + super.setHeaderOverrideTest(); + } + + @Test() + public void setHeaderTest() throws Exception { + super.setHeaderTest(); + } + + @Test() + public void setIntHeaderTest() throws Exception { + super.setIntHeaderTest(); + } + + @Test() + public void setLocaleTest() throws Exception { + super.setLocaleTest(); + } + + @Test() + public void setMultiHeaderTest() throws Exception { + super.setMultiHeaderTest(); + } + + @Test() + public void setStatusTest() throws Exception { + super.setStatusTest(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse/build.xml new file mode 100644 index 0000000000..99614ec47e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse/build.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse/servlet_jsh_httpservletresponse_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse/servlet_jsh_httpservletresponse_web.xml new file mode 100644 index 0000000000..0fffc0fd9d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse/servlet_jsh_httpservletresponse_web.xml @@ -0,0 +1,77 @@ + + + + + SerJaxSerHttpHttpSerResponse + + TestServlet + com.sun.ts.tests.servlet.common.response.HttpResponseTestServlet + + + GetContentTypeNullTestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponse.GetContentTypeNullTestServlet + + + RedirectedTest + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponse.RedirectedTestServlet + + + setCharacterEncodingTest + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponse.SetCharacterEncodingTestServlet + + + checkTestResult + com.sun.ts.tests.servlet.common.servlets.HttpCheckTestResultServlet + + + servletErrorPage + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponse.ServletErrorPage + + + TestServlet + /TestServlet/* + + + RedirectedTest + /RedirectedTest/* + + + setCharacterEncodingTest + /setCharacterEncodingTest + + + GetContentTypeNullTestServlet + /GetContentTypeNullTestServlet + + + checkTestResult + /checkTestResult + + + servletErrorPage + /servletErrorPage + + + 54 + + + 411 + /servletErrorPage + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse30/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse30/URLClient.java new file mode 100644 index 0000000000..24a2163eb5 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse30/URLClient.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2009, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponse30; + +import com.sun.ts.tests.servlet.common.response.HttpResponseClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends HttpResponseClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_jsh_httpservletresponse30_web.war").addAsLibraries(CommonServlets.getCommonServletsArchive()).setWebXML(URLClient.class.getResource("servlet_jsh_httpservletresponse30_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: getHeadersTest + * + * @assertion_ids: Servlet:JAVADOC:523; Servlet:JAVADOC:525; + * Servlet:JAVADOC:779; + * + * @test_Strategy: Create a Servlet, In the servlet, set a header value; then + * add multiple values to it; verify that getHeaders(String) works properly + */ + /* + * @testName: getHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:523; Servlet:JAVADOC:523; + * Servlet:JAVADOC:777; + * + * @test_Strategy: Create a Servlet, In the servlet, set a header value; then + * add multiple values to it; verify that getHeader(String) works properly + */ + /* + * @testName: getHeaderNamesTest + * + * @assertion_ids: Servlet:JAVADOC:520; Servlet:JAVADOC:522; + * Servlet:JAVADOC:523; Servlet:JAVADOC:525; Servlet:JAVADOC:526; + * Servlet:JAVADOC:527; Servlet:JAVADOC:778; + * + * @test_Strategy: Create a Servlet, In the servlet, set multiuple header + * values using: #setHeader, #addHeader, #setDateHeader, #addDateHeader, + * #setIntHeader, and #addIntHeader, verify that getHeaderNames() works + * properly + */ + /* + * @testName: getStatusTest + * + * @assertion_ids: Servlet:JAVADOC:780; + * + * @test_Strategy: Create a Servlet, In the servlet, set a status value; + * verify that getStatus() works properly + */ + @Test() + public void getHeaderNamesTest() throws Exception { + super.getHeaderNamesTest(); + } + + @Test() + public void getHeaderTest() throws Exception { + super.getHeaderTest(); + } + + @Test() + public void getHeadersTest() throws Exception { + super.getHeadersTest(); + } + + @Test() + public void getStatusTest() throws Exception { + super.getStatusTest(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse30/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse30/build.xml new file mode 100644 index 0000000000..8881ba1ea0 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse30/build.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse30/servlet_jsh_httpservletresponse30_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse30/servlet_jsh_httpservletresponse30_web.xml new file mode 100644 index 0000000000..c64b726975 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse30/servlet_jsh_httpservletresponse30_web.xml @@ -0,0 +1,33 @@ + + + + + SerJaxSerHttpHttpSerResponse30 + + TestServlet + com.sun.ts.tests.servlet.common.response.HttpResponseTestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse40/Client.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse40/Client.java new file mode 100644 index 0000000000..5122d44f6b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse40/Client.java @@ -0,0 +1,176 @@ +/* + * Copyright (c) 2017, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponse40; + +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.lib.util.WebUtil; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; + +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.Socket; +import java.net.URL; + +import static com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest40.Client.DELIMITER; +import static com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest40.Client.ENCODING; + +public class Client extends AbstractUrlClient { + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_jsh_httpservletresponse40_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TrailerTestServlet.class, TrailerTestServlet2.class) + .setWebXML(Client.class.getResource("servlet_jsh_httpservletresponse40_web.xml")); + } + + private WebUtil.Response response = null; + + private String request = null; + + /* + * @testName: TrailerTestWithHTTP10 + * + * @assertion_ids: servlet40:TrailerTestWithHTTP10; + * + * @test_Strategy: + */ + @Test + public void TrailerTestWithHTTP10() throws Exception { + + String response = simpleTest("TrailerTestWithHTTP10", "HTTP/1.0", + "/TrailerTestServlet"); + if (!response.contains("Get IllegalStateException when call setTrailerFields")) { + TestUtil.logErr( + "The underlying protocol is HTTP 1.0, the IllegalStateException should be thrown"); + throw new Exception("TrailerTestWithHTTP10 failed."); + } + + } + + /* + * @testName: TrailerTestResponseCommitted + * + * @assertion_ids: servlet40:TrailerTestResponseCommitted; + * + * @test_Strategy: + */ + @Test + public void TrailerTestResponseCommitted() throws Exception { + + String response = simpleTest("TrailerTestResponseCommitted", "HTTP/1.1", + "/TrailerTestServlet2"); + if (!response.contains("Get IllegalStateException when call setTrailerFields")) { + TestUtil.logErr( + "The response has been committed, the IllegalStateException should be thrown"); + throw new Exception("TrailerTestResponseCommitted failed."); + } + + } + + /* + * @testName: TrailerTest + * + * @assertion_ids: servlet40:TrailerTest; + * + * @test_Strategy: + */ + @Test + public void TrailerTest() throws Exception { + String content = simpleTest("TrailerTest", "HTTP/1.1", + "/TrailerTestServlet"); + // if (content.indexOf("Trailer: myTrailer") < 0) { + // TestUtil.logErr("Can not find header, \"Trailer: myTrailer\""); + // throw new Exception("TrailerTest failed."); + // } + int i = content.indexOf("Current trailer field: "); + if (i < 0) { + throw new Exception("TrailerTest failed."); + } + content = content.substring(i + "Current trailer field: ".length()); + String[] ss = content.split("\r\n"); + if (ss.length != 3) { + throw new Exception("TrailerTest failed."); + } + int lastChunkSize = Integer.parseInt(ss[1], 16); + if (lastChunkSize != 0 || !ss[0].trim().equals("myTrailer:foo")) { + TestUtil.logErr("The current getTrailerFields is " + ss[0].trim() + + ", But expected getTrailerFields should be myTrailer:foo"); + throw new Exception("TrailerTest failed."); + } + String[] trailer = ss[2].split(":"); + if (trailer.length != 2 || !trailer[0].trim().equals("myTrailer") + || !trailer[1].trim().equals("foo")) { + TestUtil.logErr("Expected tailer should be myTrailer:foo"); + throw new Exception("TrailerTest failed."); + } + + } + + + private String simpleTest(String testName, String protocol, + String servletPath) throws Exception { + + URL url = new URL( + "http://" + _hostname + ":" + _port + getContextRoot() + servletPath); + + TestUtil.logMsg("access " + url.toString()); + try (Socket socket = new Socket(url.getHost(), url.getPort()); + OutputStream output = socket.getOutputStream(); + InputStream input = socket.getInputStream()) { + + socket.setKeepAlive(true); + String path = url.getPath(); + StringBuffer outputBuffer = new StringBuffer(); + outputBuffer.append("POST " + path + " " + protocol + DELIMITER); + outputBuffer.append("Host: " + url.getHost() + DELIMITER); + outputBuffer.append("Content-Type: text/plain" + DELIMITER); + outputBuffer.append("Content-Length: 3" + DELIMITER); + outputBuffer.append(DELIMITER); + outputBuffer.append("ABC"); + + byte[] outputBytes = outputBuffer.toString().getBytes(ENCODING); + output.write(outputBytes); + output.flush(); + + ByteArrayOutputStream bytes = new ByteArrayOutputStream(); + int read = 0; + while ((read = input.read()) >= 0) { + bytes.write(read); + } + String response = new String(bytes.toByteArray()); + TestUtil.logMsg(response); + return response; + } catch (Exception e) { + TestUtil.logErr("Caught exception: " + e.getMessage()); + e.printStackTrace(); + throw new Exception(testName + " failed: ", e); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse40/TrailerTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse40/TrailerTestServlet.java new file mode 100644 index 0000000000..c1d5d56f47 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse40/TrailerTestServlet.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2017, 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponse40; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.Writer; +import java.util.HashMap; +import java.util.Map; + +public class TrailerTestServlet extends HttpServlet { + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + Writer writer = resp.getWriter(); + if (!req.getProtocol().equals("HTTP/1.0")) { + resp.setHeader("Transfer-Encoding", "chunked"); + } + + try { + resp.setTrailerFields(() -> { + Map m = new HashMap(); + m.put("myTrailer", "foo"); + return m; + }); + writer.write("Current trailer field: "); + resp.getTrailerFields().get().forEach((key, value) -> { + try { + writer.write(key + ":" + value); + } catch (IOException e) { + throw new RuntimeException(e); + } + }); + } catch (IllegalStateException e) { + String s = "Get IllegalStateException when call setTrailerFields"; + resp.setHeader("Content-Length", String.valueOf(s.length())); + writer.write(s); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse40/TrailerTestServlet2.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse40/TrailerTestServlet2.java new file mode 100644 index 0000000000..c2bcc5bd67 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse40/TrailerTestServlet2.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2017, 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponse40; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.Writer; +import java.util.HashMap; +import java.util.Map; + +public class TrailerTestServlet2 extends HttpServlet { + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + String s = "Get IllegalStateException when call setTrailerFields"; + resp.setHeader("Content-Length", String.valueOf(s.length())); + Writer writer = resp.getWriter(); + writer.flush(); + try { + resp.setTrailerFields(() -> { + Map m = new HashMap(); + m.put("myTrailer", "foo"); + return m; + }); + writer.write("Current trailer field: "); + resp.getTrailerFields().get().forEach((key, value) -> { + try { + writer.write(key + ":" + value); + } catch (IOException e) { + throw new RuntimeException(e); + } + }); + } catch (IllegalStateException e) { + writer.write(s); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse40/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse40/build.xml new file mode 100644 index 0000000000..ece0086b79 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse40/build.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse40/servlet_jsh_httpservletresponse40_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse40/servlet_jsh_httpservletresponse40_web.xml new file mode 100644 index 0000000000..87fa554ad5 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponse40/servlet_jsh_httpservletresponse40_web.xml @@ -0,0 +1,38 @@ + + + + + SerJaxSerHttpHttpSerResponse40 + + TrailerTestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponse40.TrailerTestServlet + + + TrailerTestServlet2 + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponse40.TrailerTestServlet2 + + + TrailerTestServlet + /TrailerTestServlet + + + TrailerTestServlet2 + /TrailerTestServlet2 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponsewrapper/RedirectedTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponsewrapper/RedirectedTestServlet.java new file mode 100644 index 0000000000..56143e1419 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponsewrapper/RedirectedTestServlet.java @@ -0,0 +1,79 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponsewrapper; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class RedirectedTestServlet extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + ServletTestUtil.printResult(pw, true); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponsewrapper/SetCharacterEncodingTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponsewrapper/SetCharacterEncodingTestServlet.java new file mode 100644 index 0000000000..c987b7a10c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponsewrapper/SetCharacterEncodingTestServlet.java @@ -0,0 +1,79 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponsewrapper; + +import java.io.IOException; + +import com.sun.ts.tests.servlet.common.response.ResponseTests; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletResponseWrapper; + +public class SetCharacterEncodingTestServlet extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + HttpServletResponseWrapper hsrw = new HttpServletResponseWrapper(response); + ResponseTests.setCharacterEncodingTest(request, hsrw); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponsewrapper/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponsewrapper/TestServlet.java new file mode 100644 index 0000000000..d747b3e7d1 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponsewrapper/TestServlet.java @@ -0,0 +1,84 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponsewrapper; + +import java.io.IOException; + +import com.sun.ts.tests.servlet.common.response.HttpResponseTestServlet; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletResponseWrapper; + +public class TestServlet extends HttpResponseTestServlet { + + public void init(ServletConfig servletConfig) throws ServletException { + super.init(servletConfig); + } + + public void service(HttpServletRequest servletRequest, + HttpServletResponse servletResponse) + throws ServletException, IOException { + HttpServletResponseWrapper wrapper = new HttpServletResponseWrapper( + servletResponse); + super.service(servletRequest, wrapper); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponsewrapper/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponsewrapper/URLClient.java new file mode 100644 index 0000000000..15815037fc --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponsewrapper/URLClient.java @@ -0,0 +1,499 @@ +/* + * 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponsewrapper; + +import com.sun.ts.tests.servlet.common.response.HttpResponseClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends HttpResponseClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_jsh_HSRespWrapper_web.war").addAsLibraries(CommonServlets.getCommonServletsArchive()).addClasses(RedirectedTestServlet.class, SetCharacterEncodingTestServlet.class, TestServlet.class).setWebXML(URLClient.class.getResource("servlet_jsh_HSRespWrapper_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + /* Run test */ + // ------------------ ServletResponseWrapper + // ----------------------------------- + /* + * @testName: flushBufferTest + * + * @assertion_ids: Servlet:JAVADOC:348 + * + * @test_Strategy: Servlet wraps response. Servlet writes data in the buffer + * and flushes it + */ + /* + * @testName: getBufferSizeTest + * + * @assertion_ids: Servlet:JAVADOC:347 + * + * @test_Strategy: Servlet wraps response. Servlet flushes buffer and verifies + * the size of the buffer + */ + /* + * @testName: getLocaleTest + * + * @assertion_ids: Servlet:JAVADOC:354 + * + * @test_Strategy: Servlet wraps response. Servlet set Locale and then + * verifies it + * + */ + /* + * @testName: getOutputStreamTest + * + * @assertion_ids: Servlet:JAVADOC:339 + * + * @test_Strategy: Servlet wraps response. Servlet gets an output stream and + * writes to it. + */ + /* + * @testName: getWriterTest + * + * @assertion_ids: Servlet:JAVADOC:341 + * + * @test_Strategy: Servlet wraps response. Servlet gets a Writer object; then + * sets the content type. verify that content type didn't get set by servlet + */ + /* + * @testName: isCommittedTest + * + * @assertion_ids: Servlet:JAVADOC:350 + * + * @test_Strategy: Servlet wraps response. Servlet checks before and after + * response is flushed + * + */ + /* + * @testName: resetBufferTest + * + * @assertion_ids: Servlet:JAVADOC:352 + * + * @test_Strategy: Servlet wraps response. Servlet writes data to the + * response, resets the buffer and then writes new data + */ + /* + * @testName: resetTest + * + * @assertion_ids: Servlet:JAVADOC:351 + * + * @test_Strategy: Servlet wraps response. Servlet writes data to the + * response, does a reset, then writes new data + */ + /* + * @testName: resetTest1 + * + * @assertion_ids: Servlet:JAVADOC:351; Servlet:SPEC:31; + * + * @test_Strategy: Servlet writes data to the response, set the Headers, does + * a reset, then writes new data, set the new Header + */ + /* + * @testName: getCharacterEncodingTest + * + * @assertion_ids: Servlet:JAVADOC:338 + * + * @test_Strategy: Servlet wraps response. Servlet checks for the default + * encoding + */ + /* + * @testName: setCharacterEncodingTest + * + * @assertion_ids: Servlet:JAVADOC:337 + * + * @test_Strategy: Servlet wraps response. Servlet set the encoding and client + * verifies it + */ + /* + * @testName: setBufferSizeTest + * + * @assertion_ids: Servlet:JAVADOC:346 + * + * @test_Strategy: Servlet wraps response. Servlet sets the buffer size then + * verifies it was set + */ + /* + * @testName: setContentLengthTest + * + * @assertion_ids: Servlet:JAVADOC:343 + * + * @test_Strategy: Servlet wraps response. Servlet sets the content length + */ + /* + * @testName: getContentTypeTest + * + * @assertion_ids: Servlet:JAVADOC:345; Servlet:SPEC:34; + * + * @test_Strategy: Servlet wraps response. Servlet verifies the content type + * sent by the client + */ + /* + * @testName: setContentTypeTest + * + * @assertion_ids: Servlet:JAVADOC:344; Servlet:SPEC:34; + * + * @test_Strategy: Servlet wraps response. Servlet sets the content type + * + */ + /* + * @testName: setLocaleTest + * + * @assertion_ids: Servlet:JAVADOC:353 + * + * @test_Strategy: Servlet wraps response. Servlet sets the Locale + */ + // ----------------------- END ServletResponseWrapper + // -------------------------- + // --------------------- HttpServletResponseWrapper + // ---------------------------- + /* + * @testName: httpResponseWrapperGetResponseTest + * + * @assertion_ids: Servlet:JAVADOC:334 + * + * @test_Strategy: Servlet gets wrapped response object + */ + @Test + public void httpResponseWrapperGetResponseTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "httpResponseWrapperGetResponseTest"); + invoke(); + } + + /* + * @testName: httpResponseWrapperSetResponseTest + * + * @assertion_ids: Servlet:JAVADOC:335 + * + * @test_Strategy: Servlet sets wrapped response object + */ + @Test + public void httpResponseWrapperSetResponseTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "httpResponseWrapperSetResponseTest"); + invoke(); + } + + /* + * @testName: httpResponseWrapperSetResponseIllegalArgumentExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:336 + * + * @test_Strategy: Servlet sets wrapped response object + */ + @Test + public void httpResponseWrapperSetResponseIllegalArgumentExceptionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "httpResponseWrapperSetResponseIllegalArgumentExceptionTest"); + invoke(); + } + + /* + * @testName: httpResponseWrapperConstructorTest + * + * @assertion_ids: Servlet:JAVADOC:313 + * + * @test_Strategy: Validate constuctor of HttpServletResponseWrapper. + */ + @Test + public void httpResponseWrapperConstructorTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "httpResponseWrapperConstructorTest"); + invoke(); + } + + /* + * @testName: addCookieTest + * + * @assertion_ids: Servlet:JAVADOC:314 + * + * @test_Strategy: Servlet wrappers response and calls test + */ + /* + * @testName: addDateHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:327 + * + * @test_Strategy: Servlet wrappers response and calls test + */ + /* + * @testName: addHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:329 + * + * @test_Strategy: Servlet wrappers response and calls test + */ + /* + * @testName: addIntHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:331 + * + * @test_Strategy: Servlet wrappers response and calls test + */ + /* + * @testName: containsHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:315 + * + * @test_Strategy: Servlet wrappers response and calls test + */ + /* + * @testName: sendErrorClearBufferTest + * + * @assertion_ids: Servlet:JAVADOC:322; Servlet:SPEC:39; + * + * @test_Strategy: Servlet wrappers response and calls test + */ + /* + * @testName: sendError_StringTest + * + * @assertion_ids: Servlet:JAVADOC:320 + * + * @test_Strategy: Servlet wrappers response and calls test + */ + /* + * @testName: sendRedirectTest + * + * @assertion_ids: Servlet:JAVADOC:324 + * + * @test_Strategy: Servlet wrappers response and calls test + */ + @Test + public void sendRedirectTest() throws Exception { + String testName = "sendRedirectWithLeadingSlashTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + getServletName() + "?testname=" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(EXPECTED_HEADERS, "Location: http://" + _hostname + ":" + _port + "/RedirectedTest"); + TEST_PROPS.setProperty(STATUS_CODE, MOVED_TEMPORARY); + invoke(); + testName = "sendRedirectWithoutLeadingSlashTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + getServletName() + "?testname=" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(EXPECTED_HEADERS, "Location: http://" + _hostname + ":" + _port + "" + getContextRoot() + "/RedirectedTest"); + TEST_PROPS.setProperty(STATUS_CODE, MOVED_TEMPORARY); + invoke(); + } + + /* + * @testName: setDateHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:326 + * + * @test_Strategy: Servlet wrappers response and calls test + */ + /* + * @testName: setHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:328 + * + * @test_Strategy: Servlet wrappers response and calls test + */ + /* + * @testName: setMultiHeaderTest + * + * @assertion_ids: Servlet:SPEC:183; Servlet:JAVADOC:523; Servlet:JAVADOC:525; + * Servlet:JAVADOC:524 + * + * @test_Strategy: Servlet sets the multivalues for the same header; verify + * that setHeader clear all with new value + */ + /* + * @testName: setIntHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:330 + * + * @test_Strategy: Servlet wrappers response and calls test + */ + /* + * @testName: setStatusTest + * + * @assertion_ids: Servlet:JAVADOC:332 + * + * @test_Strategy: Testing Servlet API + * HttpServletResponseWrapper.setStatus(SC_OK) + */ + /* + * @testName: setStatusTest1 + * + * @assertion_ids: Servlet:JAVADOC:332 + * + * @test_Strategy: Testing Servlet API + * HttpServletResponseWrapper.setStatus(SC_NOT_FOUND) + */ + // ------------------- END HttpServletResponseWrapper + // -------------------------- + @Test() + public void addCookieTest() throws Exception { + super.addCookieTest(); + } + + @Test() + public void addDateHeaderTest() throws Exception { + super.addDateHeaderTest(); + } + + @Test() + public void addHeaderTest() throws Exception { + super.addHeaderTest(); + } + + @Test() + public void addIntHeaderTest() throws Exception { + super.addIntHeaderTest(); + } + + @Test() + public void containsHeaderTest() throws Exception { + super.containsHeaderTest(); + } + + @Test() + public void flushBufferTest() throws Exception { + super.flushBufferTest(); + } + + @Test() + public void getBufferSizeTest() throws Exception { + super.getBufferSizeTest(); + } + + @Test() + public void getCharacterEncodingTest() throws Exception { + super.getCharacterEncodingTest(); + } + + @Test() + public void getContentTypeTest() throws Exception { + super.getContentTypeTest(); + } + + @Test() + public void getLocaleTest() throws Exception { + super.getLocaleTest(); + } + + @Test() + public void getOutputStreamTest() throws Exception { + super.getOutputStreamTest(); + } + + @Test() + public void getWriterTest() throws Exception { + super.getWriterTest(); + } + + @Test() + public void isCommittedTest() throws Exception { + super.isCommittedTest(); + } + + @Test() + public void resetBufferTest() throws Exception { + super.resetBufferTest(); + } + + @Test() + public void resetTest() throws Exception { + super.resetTest(); + } + + @Test() + public void resetTest1() throws Exception { + super.resetTest1(); + } + + @Test() + public void sendErrorClearBufferTest() throws Exception { + super.sendErrorClearBufferTest(); + } + + @Test() + public void sendError_StringTest() throws Exception { + super.sendError_StringTest(); + } + + @Test() + public void setBufferSizeTest() throws Exception { + super.setBufferSizeTest(); + } + + @Test() + public void setCharacterEncodingTest() throws Exception { + super.setCharacterEncodingTest(); + } + + @Test() + public void setContentLengthTest() throws Exception { + super.setContentLengthTest(); + } + + @Test() + public void setContentTypeTest() throws Exception { + super.setContentTypeTest(); + } + + @Test() + public void setDateHeaderTest() throws Exception { + super.setDateHeaderTest(); + } + + @Test() + public void setHeaderTest() throws Exception { + super.setHeaderTest(); + } + + @Test() + public void setIntHeaderTest() throws Exception { + super.setIntHeaderTest(); + } + + @Test() + public void setLocaleTest() throws Exception { + super.setLocaleTest(); + } + + @Test() + public void setMultiHeaderTest() throws Exception { + super.setMultiHeaderTest(); + } + + @Test() + public void setStatusTest() throws Exception { + super.setStatusTest(); + } + + @Test() + public void setStatusTest1() throws Exception { + super.setStatusTest1(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponsewrapper/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponsewrapper/build.xml new file mode 100644 index 0000000000..82f5504371 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponsewrapper/build.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponsewrapper/servlet_jsh_HSRespWrapper_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponsewrapper/servlet_jsh_HSRespWrapper_web.xml new file mode 100644 index 0000000000..5bf2ab13da --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponsewrapper/servlet_jsh_HSRespWrapper_web.xml @@ -0,0 +1,49 @@ + + + + + HttpSerRespWrap + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponsewrapper.TestServlet + + + RedirectedTest + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponsewrapper.RedirectedTestServlet + + + setCharacterEncodingTest + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponsewrapper.SetCharacterEncodingTestServlet + + + TestServlet + /TestServlet/* + + + RedirectedTest + /RedirectedTest/* + + + setCharacterEncodingTest + /setCharacterEncodingTest + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponsewrapper30/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponsewrapper30/TestServlet.java new file mode 100644 index 0000000000..fcfdb436a8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponsewrapper30/TestServlet.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2009, 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponsewrapper30; + +import java.io.IOException; + +import com.sun.ts.tests.servlet.common.response.HttpResponseTestServlet; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletResponseWrapper; + +public class TestServlet extends HttpResponseTestServlet { + + public void init(ServletConfig servletConfig) throws ServletException { + super.init(servletConfig); + } + + public void service(HttpServletRequest servletRequest, + HttpServletResponse servletResponse) + throws ServletException, IOException { + HttpServletResponseWrapper wrapper = new HttpServletResponseWrapper( + servletResponse); + super.service(servletRequest, wrapper); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponsewrapper30/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponsewrapper30/URLClient.java new file mode 100644 index 0000000000..8acc5c45e3 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponsewrapper30/URLClient.java @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2009, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponsewrapper30; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_jsh_HSRespWrapper30_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_jsh_HSRespWrapper30_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + // --------------------- HttpServletResponseWrapper + // ---------------------------- + + /* + * @testName: getHeadersTest + * + * @assertion_ids: Servlet:JAVADOC:523; Servlet:JAVADOC:525; + * Servlet:JAVADOC:783; + * + * @test_Strategy: Create a Servlet, wrap the servlet in another one, In the + * servlet, set a header value; then add multiple values to it; verify that + * getHeaders(String) works properly + */ + @Test + public void getHeadersTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getHeadersTest"); + invoke(); + } + + /* + * @testName: getHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:523; Servlet:JAVADOC:523; + * Servlet:JAVADOC:781; + * + * @test_Strategy: Create a Servlet, wrap the servlet in another one, In the + * servlet, set a header value; then add multiple values to it; verify that + * getHeader(String) works properly + */ + @Test + public void getHeaderTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getHeaderTest"); + invoke(); + } + + /* + * @testName: getHeaderNamesTest + * + * @assertion_ids: Servlet:JAVADOC:520; Servlet:JAVADOC:522; + * Servlet:JAVADOC:523; Servlet:JAVADOC:525; Servlet:JAVADOC:526; + * Servlet:JAVADOC:527; Servlet:JAVADOC:782; + * + * @test_Strategy: Create a Servlet, wrap the servlet in another one, In the + * servlet, set multiuple header values using: #setHeader, #addHeader, + * #setDateHeader, #addDateHeader, #setIntHeader, and #addIntHeader, verify + * that getHeaderNames() works properly + */ + @Test + public void getHeaderNamesTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getHeaderNamesTest"); + invoke(); + } + + /* + * @testName: getStatusTest + * + * @assertion_ids: Servlet:JAVADOC:784; + * + * @test_Strategy: Create a Servlet, wrap the servlet in another one, In the + * servlet, set a status value; verify that getStatus() works properly + */ + @Test + public void getStatusTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getStatusTest"); + invoke(); + } + // ------------------- END HttpServletResponseWrapper + // -------------------------- +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponsewrapper30/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponsewrapper30/build.xml new file mode 100644 index 0000000000..9ce9718129 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponsewrapper30/build.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponsewrapper30/servlet_jsh_HSRespWrapper30_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponsewrapper30/servlet_jsh_HSRespWrapper30_web.xml new file mode 100644 index 0000000000..2545dfedc5 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpservletresponsewrapper30/servlet_jsh_HSRespWrapper30_web.xml @@ -0,0 +1,33 @@ + + + + + HttpSerRespWrap30 + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponsewrapper30.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsession/ExpireHttpSession.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsession/ExpireHttpSession.java new file mode 100644 index 0000000000..e27c13f1c7 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsession/ExpireHttpSession.java @@ -0,0 +1,44 @@ +/* + * 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsession; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpSession; + +public class ExpireHttpSession extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + HttpSession session = request.getSession(false); + if (session == null) { + pw.println("Session expired as expected."); + ServletTestUtil.printResult(pw, true); + } else { + pw.println("Test Failed. Session didnot expire as expected."); + ServletTestUtil.printResult(pw, false); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsession/GetLastAccessedTime.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsession/GetLastAccessedTime.java new file mode 100644 index 0000000000..65f99bc894 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsession/GetLastAccessedTime.java @@ -0,0 +1,68 @@ +/* + * 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsession; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpSession; + +public class GetLastAccessedTime extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + boolean passed = false; + + String TS1 = request.getParameter("t1"); + String TS2 = request.getParameter("t2"); + pw.println("Session created before " + TS1); + pw.println("Session accessed before " + TS2); + long t1 = Long.parseLong(TS1); + long t2 = Long.parseLong(TS2); + + HttpSession session = request.getSession(false); + + if (session != null) { + long t3 = session.getLastAccessedTime(); + if (t3 < t1) { + pw.println("Test failed: session.getLastAccessedTime() " + + "indicates last accessed at " + t3 + " which is before creation"); + ServletTestUtil.printResult(pw, false); + } else { + if (t3 > t2) { + pw.println("Test failed: session.getLastAccessedTime() " + + "indicates last accessed at " + t3 + + " which is after it was last accessed"); + ServletTestUtil.printResult(pw, false); + } else { + pw.println("Test passed: session.getLastAccessedTime() " + + "indicates last accessed at " + t3 + + " which is after creation, " + + "and before the time returned from last access"); + ServletTestUtil.printResult(pw, true); + } + } + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsession/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsession/TestServlet.java new file mode 100644 index 0000000000..25bfdf7677 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsession/TestServlet.java @@ -0,0 +1,594 @@ +/* + * 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsession; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Date; +import java.util.Enumeration; + +import com.sun.ts.tests.servlet.common.servlets.HttpTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpSession; + +public class TestServlet extends HttpTCKServlet { + + public void getSession(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + HttpSession session = request.getSession(true); + ServletTestUtil.printResult(pw, true); + } + + public void getSessionMax(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + HttpSession session = request.getSession(true); + session.setMaxInactiveInterval(10); + ServletTestUtil.printResult(pw, true); + } + + public void getCreationTimeTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + HttpSession session = request.getSession(true); + + long time = session.getCreationTime(); + Date date = new Date(time); + + if (date == null) { + passed = false; + pw.println("getCreationTime() returned an invalid result "); + pw.println("The date returned was a null"); + pw.println("Actual result from request= |" + time + "|"); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + + } + + public void getCreationTimeIllegalStateExceptionTest( + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + HttpSession session = request.getSession(true); + session.invalidate(); + try { + long time = session.getCreationTime(); + passed = false; + pw.println("getCreationTime() did not generate an IllegalStateException"); + } catch (Throwable t) { + if (t instanceof IllegalStateException) { + passed = true; + } else { + passed = false; + pw.println( + "Exception thrown, but was not an instance of IllegalStateException."); + pw.println("instead received: " + t.getClass().getName()); + } + } + ServletTestUtil.printResult(pw, passed); + + } + + public void getIdTestServlet(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + HttpSession session = request.getSession(true); + + if (session.getId() == null) { + passed = false; + pw.println("getId() returned a null result "); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public void getIdIllegalStateExceptionTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + HttpSession session = request.getSession(true); + session.invalidate(); + + try { + session.getId(); + passed = true; + } catch (Throwable t) { + passed = false; + pw.println("Exception thrown" + t.getMessage()); + } + ServletTestUtil.printResult(pw, passed); + } + + public void getLastAccessedTimeTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + HttpSession session = request.getSession(true); + Date currentDate = new Date(); + long currentTime = currentDate.getTime(); + long testTime = session.getLastAccessedTime(); + + // ok if within a second + if (testTime > currentTime) { + passed = false; + pw.println("getLastAccessedTime() returned the wrong result"); + pw.println("expected results= <=" + currentTime); + pw.println("actual result=" + testTime); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public void getLastAccessedTimeIllegalStateExceptionTest( + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + HttpSession session = request.getSession(true); + session.invalidate(); + try { + session.getLastAccessedTime(); + passed = false; + pw.println( + "getLastAccessedTime() should have generated an IllegalStateException"); + } catch (Throwable t) { + if (t instanceof IllegalStateException) { + passed = true; + } else { + passed = false; + pw.println( + "Exception thrown, but was not an instance of IllegalStateException."); + pw.println("instead received: " + t.getClass().getName()); + } + } + ServletTestUtil.printResult(pw, passed); + } + + public void getLastAccessedTimeSetGetTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + HttpSession session = request.getSession(true); + long beforeTime = session.getLastAccessedTime(); + + session.setAttribute("name", "value"); + session.getAttribute("name"); + + long afterTime = session.getLastAccessedTime(); + + if (beforeTime != afterTime) { + passed = false; + pw.println("getLastAccessedTime() returned the wrong result"); + pw.println("expected result= " + beforeTime); + pw.println("actual result=" + afterTime); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public void getMaxInactiveIntervalTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + HttpSession session = request.getSession(true); + int expectedResult = 500000; + session.setMaxInactiveInterval(expectedResult); + int result = session.getMaxInactiveInterval(); + + if (result != expectedResult) { + passed = false; + pw.println("getMaxInactiveInterval() returned incorrect result "); + pw.println("Expected result = " + expectedResult + " "); + pw.println("Actual result = |" + result + "| "); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public void getAttributeNamesTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + HttpSession session = request.getSession(true); + + String attribute1 = "attribute1"; + String attribute2 = "attribute2"; + String[] expected = { attribute1, attribute2 }; + + // Binding values with the Session + session.setAttribute(attribute1, "value1"); + session.setAttribute(attribute1, "value2"); + session.setAttribute(attribute2, "value1"); + + Enumeration e = session.getAttributeNames(); + if (e != null) { + if (!ServletTestUtil.checkEnumeration(e, expected, false, false)) { + passed = false; + ServletTestUtil.printFailureData(pw, e, expected); + } else { + passed = true; + } + } else { + passed = false; + pw.println("getAttrubuteNames() returned an empty enumeration"); + } + ServletTestUtil.printResult(pw, passed); + + } + + public void getAttributeNamesIllegalStateExceptionTest( + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + HttpSession session = request.getSession(true); + session.invalidate(); + + try { + session.getAttributeNames(); + passed = false; + pw.println("Error: IllegalStateException should have been thrown"); + } catch (Throwable t) { + if (t instanceof IllegalStateException) { + passed = true; + } else { + passed = false; + pw.println( + "Exception thrown, but was not an instance of IllegalStateException."); + pw.println("instead received: " + t.getClass().getName()); + } + } + ServletTestUtil.printResult(pw, passed); + } + + public void getAttributeTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + HttpSession session = request.getSession(true); + session.setAttribute("attribute", "value1"); + if (session.getAttribute("attribute") == null) { + passed = false; + pw.println("getAttribute(object) returned a null result"); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public void getAttributeIllegalStateExceptionTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + HttpSession session = request.getSession(true); + + session.invalidate(); + + try { + session.getAttribute("object"); + passed = false; + pw.println("Error: IllegalStateException should have been thrown"); + } catch (Throwable t) { + if (t instanceof IllegalStateException) { + passed = true; + } else { + passed = false; + pw.println( + "Exception thrown, but was not an instance of IllegalStateException."); + pw.println("instead received: " + t.getClass().getName()); + } + } + ServletTestUtil.printResult(pw, passed); + } + + public void getServletContextTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + HttpSession session = request.getSession(true); + + if (session.getServletContext() == null) { + passed = false; + pw.println("getServletContext method returned null"); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public void invalidateTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + HttpSession session = request.getSession(true); + session.setAttribute("attribute1", "value1"); + session.invalidate(); + try { + Object o = session.getAttribute("Attribute1"); + passed = false; + pw.println("invalidate() did not invalidate the session"); + pw.println("The attribute returned was = " + o); + } catch (Throwable t) { + if (t instanceof IllegalStateException) { + passed = true; + } else { + passed = false; + pw.println( + "Exception thrown, but was not an instance of IllegalStateException."); + pw.println("instead received: " + t.getClass().getName()); + } + } + ServletTestUtil.printResult(pw, passed); + } + + public void invalidateIllegalStateExceptionTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + HttpSession session = request.getSession(true); + session.invalidate(); + + try { + session.invalidate(); + passed = false; + pw.println("Error: IllegalStateException should have been thrown"); + } catch (Throwable t) { + if (t instanceof IllegalStateException) { + passed = true; + } else { + passed = false; + pw.println( + "Exception thrown, but was not an instance of IllegalStateException."); + pw.println("instead received: " + t.getClass().getName()); + } + } + ServletTestUtil.printResult(pw, passed); + } + + public void isNewTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + HttpSession session = request.getSession(true); + + if (session.isNew() != true) { + passed = false; + pw.println("isNew() returned a false result"); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public void isNewIllegalStateExceptionTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + HttpSession session = request.getSession(true); + session.invalidate(); + + try { + session.isNew(); + passed = false; + pw.println("Error: IllegalStateException should have been thrown"); + } catch (Throwable t) { + if (t instanceof IllegalStateException) { + passed = true; + } else { + passed = false; + pw.println( + "Exception thrown, but was not an instance of IllegalStateException."); + pw.println("instead received: " + t.getClass().getName()); + } + } + ServletTestUtil.printResult(pw, passed); + } + + public void removeAttributeTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + HttpSession session = request.getSession(true); + session.setAttribute("attribute1", "value1"); + session.removeAttribute("attribute1"); + Object obj = session.getAttribute("attribute1"); + + if (obj != null) { + passed = false; + pw.println("getAttribute(object) returned a non-null result"); + pw.println(" Actual result = |" + (String) obj + "| "); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public void removeAttributeDoNothingTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + HttpSession session = request.getSession(true); + session.removeAttribute("attribute1"); + Object obj = session.getAttribute("attribute1"); + + if (obj != null) { + passed = false; + pw.println("getAttribute(object) returned a non-null result"); + pw.println(" Actual result = |" + (String) obj + "| "); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public void removeAttributeIllegalStateExceptionTest( + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + HttpSession session = request.getSession(true); + session.invalidate(); + + try { + session.removeAttribute("object"); + passed = false; + pw.println("Error: IllegalStateException should have been thrown"); + } catch (Throwable t) { + if (t instanceof IllegalStateException) { + passed = true; + } else { + passed = false; + pw.println( + "Exception thrown, but was not an instance of IllegalStateException."); + pw.println("instead received: " + t.getClass().getName()); + } + } + ServletTestUtil.printResult(pw, passed); + } + + public void setAttributeTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + HttpSession session = request.getSession(true); + String attribute1 = "attribute1"; + String value1 = "value1"; + String value2 = "value2"; + + session.setAttribute(attribute1, value1); + session.setAttribute(attribute1, value2); + String result = (String) session.getAttribute(attribute1); + + if (!result.equals(value2)) { + passed = false; + pw.println( + "getAttribute(" + attribute1 + ") returned an incorrect result"); + pw.println(" Expected result = " + value2); + pw.println(" Actual result = |" + result + "| "); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public void setAttributeNullTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + HttpSession session = request.getSession(true); + String attribute1 = "attribute1"; + String value1 = "value1"; + String value2 = null; + + session.setAttribute(attribute1, value1); + session.setAttribute(attribute1, value2); + String result = (String) session.getAttribute(attribute1); + + if (result != null) { + passed = false; + pw.println( + "getAttribute(" + attribute1 + ") returned an incorrect result"); + pw.println(" Expected result = null"); + pw.println(" Actual result = |" + result + "| "); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public void setAttributeIllegalStateExceptionTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + HttpSession session = request.getSession(true); + session.invalidate(); + + try { + session.setAttribute("attribute", "value"); + passed = false; + pw.println("Error: IllegalStateException should have been thrown"); + } catch (Throwable t) { + if (t instanceof IllegalStateException) { + passed = true; + } else { + passed = false; + pw.println( + "Exception thrown, but was not an instance of IllegalStateException."); + pw.println("instead received: " + t.getClass().getName()); + } + } + ServletTestUtil.printResult(pw, passed); + } + + public void setMaxInactiveIntervalTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + HttpSession session = request.getSession(true); + int expectedResult = 500000; + session.setMaxInactiveInterval(expectedResult); + int result = session.getMaxInactiveInterval(); + + if (result != expectedResult) { + passed = false; + pw.println("getMaxInactiveInterval() returned incorrect result "); + pw.println("Expected result = " + expectedResult + " "); + pw.println("Actual result = |" + result + "| "); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsession/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsession/URLClient.java new file mode 100644 index 0000000000..e4176371c7 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsession/URLClient.java @@ -0,0 +1,449 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsession; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_jsh_httpsession_web.war") + .addAsWebResource("api/jakarta_servlet_http/httpsession/index.html", "index.html") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(ExpireHttpSession.class, GetLastAccessedTime.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_jsh_httpsession_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * servlet_waittime; + */ + + /* Run test */ + + /* + * @testName: getCreationTimeTest + * + * @assertion_ids: Servlet:JAVADOC:465 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void getCreationTimeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getCreationTimeTest"); + invoke(); + } + + /* + * @testName: getCreationTimeIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:466 + * + * @test_Strategy: Servlet starts session, invalidates it then calls method + */ + @Test + public void getCreationTimeIllegalStateExceptionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getCreationTimeIllegalStateExceptionTest"); + invoke(); + } + + /* + * @testName: getIdTestServlet + * + * @assertion_ids: Servlet:JAVADOC:467 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void getIdTestServlet() throws Exception { + TEST_PROPS.setProperty(APITEST, "getIdTestServlet"); + invoke(); + } + + /* + * @testName: getIdIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:467 + * + * @test_Strategy: Create a HttpSession; invalidate it; Verify that no + * IllegalStateException is thrown when getId is called. + */ + @Test + public void getIdIllegalStateExceptionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getIdIllegalStateExceptionTest"); + invoke(); + } + + /* + * @testName: getLastAccessedTimeTest + * + * @assertion_ids: Servlet:JAVADOC:469 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void getLastAccessedTimeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getLastAccessedTimeTest"); + invoke(); + } + + /* + * @testName: getLastAccessedTimeSetGetTest + * + * @assertion_ids: Servlet:JAVADOC:470 + * + * @test_Strategy: Servlet does a get/set operation + */ + @Test + public void getLastAccessedTimeSetGetTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getLastAccessedTimeSetGetTest"); + invoke(); + } + + /* + * @testName: expireHttpSessionTest + * + * @assertion_ids: Servlet:SPEC:202; Servlet:SPEC:203; Servlet:SPEC:66; + * Servlet:JAVADOC:565; Servlet:JAVADOC:473; Servlet:JAVADOC:469; + * Servlet:JAVADOC:470; Servlet:JAVADOC:566; + * + * @test_Strategy: 1. Client sends request to TestServlet which - creates a + * session using request.getSession() - and sets the session's + * maxInactiveInterval to 10 secs. Client captures the JSESSIONID returned in + * the response. Client records the current system time (t1), + * + * 2. Within maxInactiveInterval, client sends a request that contains the + * JSESSIONID in a request cookie to file index.html Client receives the + * response and records the current system time (t2). + * + * 3. Client makes request with JSESSIONID to servlet getLastAccessedTime, + * including both t1 and t2 as request params. Servlet resumes session by + * calling request.getSession(false), verify t2 > + * session.getLastAccessedTime() > t1 + * + * 4. Client waits for longer than maxInactiveInterval, and sends a + * request(including JSESSIONID) to the third servlet. The servlet tries to + * resume the session by calling request.getSession(false). Verify that no + * session is returned this time + */ + @Test + public void expireHttpSessionTest() throws Exception { + + TEST_PROPS.setProperty(APITEST, "getSessionMax"); + TEST_PROPS.setProperty(SAVE_STATE, "true"); + invoke(); + + Long t1 = System.currentTimeMillis(); + int tmp = 0; + while (System.currentTimeMillis() - t1 < 10) { + tmp++; + } + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/index.html HTTP/1.1"); + TEST_PROPS.setProperty(SAVE_STATE, "true"); + TEST_PROPS.setProperty(USE_SAVED_STATE, "true"); + TEST_PROPS.setProperty(SEARCH_STRING, "INDEX from index.html"); + invoke(); + Long t2 = System.currentTimeMillis(); + + while (System.currentTimeMillis() - t2 < 10) { + tmp++; + } + + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/getLastAccessedTime?t1=" + t1 + "&t2=" + t2 + " HTTP/1.1"); + TEST_PROPS.setProperty(SAVE_STATE, "true"); + TEST_PROPS.setProperty(USE_SAVED_STATE, "true"); + TEST_PROPS.setProperty(SEARCH_STRING, + "Test passed: session.getLastAccessedTime()"); + invoke(); + + Long t3 = System.currentTimeMillis(); + int wait = Integer.parseInt(_props.getProperty("servlet_waittime").trim()); + while (System.currentTimeMillis() - t3 < (10000 + wait)) { + tmp++; + } + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/expireHttpSession HTTP/1.1"); + TEST_PROPS.setProperty(USE_SAVED_STATE, "true"); + TEST_PROPS.setProperty(SEARCH_STRING, "Session expired as expected."); + invoke(); + } + + /* + * @testName: getLastAccessedTimeIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:471 + * + * @test_Strategy: Servlet verifies exception is generated + */ + @Test + public void getLastAccessedTimeIllegalStateExceptionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getSession"); + TEST_PROPS.setProperty(SAVE_STATE, "true"); + invoke(); + TEST_PROPS.setProperty(APITEST, + "getLastAccessedTimeIllegalStateExceptionTest"); + TEST_PROPS.setProperty(USE_SAVED_STATE, "true"); + invoke(); + } + + /* + * @testName: getMaxInactiveIntervalTest + * + * @assertion_ids: Servlet:JAVADOC:474 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void getMaxInactiveIntervalTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getMaxInactiveIntervalTest"); + invoke(); + } + + /* + * @testName: getAttributeNamesTest + * + * @assertion_ids: Servlet:JAVADOC:480 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void getAttributeNamesTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getAttributeNamesTest"); + invoke(); + } + + /* + * @testName: getAttributeNamesIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:481 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void getAttributeNamesIllegalStateExceptionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, + "getAttributeNamesIllegalStateExceptionTest"); + invoke(); + } + + /* + * @testName: getAttributeTest + * + * @assertion_ids: Servlet:JAVADOC:476 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void getAttributeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getAttributeTest"); + invoke(); + } + + /* + * @testName: getAttributeIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:477 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void getAttributeIllegalStateExceptionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getAttributeIllegalStateExceptionTest"); + invoke(); + } + + /* + * @testName: getServletContextTest + * + * @assertion_ids: Servlet:JAVADOC:472 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void getServletContextTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletContextTest"); + invoke(); + } + + /* + * @testName: invalidateTest + * + * @assertion_ids: Servlet:JAVADOC:496 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void invalidateTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "invalidateTest"); + invoke(); + } + + /* + * @testName: invalidateIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:497 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void invalidateIllegalStateExceptionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "invalidateIllegalStateExceptionTest"); + invoke(); + } + + /* + * @testName: isNewTest + * + * @assertion_ids: Servlet:JAVADOC:498 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void isNewTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "isNewTest"); + invoke(); + } + + /* + * @testName: isNewIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:499 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void isNewIllegalStateExceptionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "isNewIllegalStateExceptionTest"); + invoke(); + } + + /* + * @testName: removeAttributeTest + * + * @assertion_ids: Servlet:JAVADOC:492 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void removeAttributeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "removeAttributeTest"); + invoke(); + } + + /* + * @testName: removeAttributeDoNothingTest + * + * @assertion_ids: Servlet:JAVADOC:491 + * + * @test_Strategy: Servlet removes non-existant attribute then tries to tries + * to get it. + */ + @Test + public void removeAttributeDoNothingTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "removeAttributeDoNothingTest"); + invoke(); + } + + /* + * @testName: removeAttributeIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:493 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void removeAttributeIllegalStateExceptionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "removeAttributeIllegalStateExceptionTest"); + invoke(); + } + + /* + * @testName: setAttributeTest + * + * @assertion_ids: Servlet:JAVADOC:484 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void setAttributeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setAttributeTest"); + invoke(); + } + + /* + * @testName: setAttributeNullTest + * + * @assertion_ids: Servlet:JAVADOC:487 + * + * @test_Strategy: Servlet passes null to setAttribute + */ + @Test + public void setAttributeNullTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setAttributeNullTest"); + invoke(); + } + + /* + * @testName: setAttributeIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:488 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void setAttributeIllegalStateExceptionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setAttributeIllegalStateExceptionTest"); + invoke(); + } + + /* + * @testName: setMaxInactiveIntervalTest + * + * @assertion_ids: Servlet:JAVADOC:473 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void setMaxInactiveIntervalTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setMaxInactiveIntervalTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsession/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsession/build.xml new file mode 100644 index 0000000000..040c7b001e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsession/build.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsession/servlet_jsh_httpsession_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsession/servlet_jsh_httpsession_web.xml new file mode 100644 index 0000000000..afb18608f8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsession/servlet_jsh_httpsession_web.xml @@ -0,0 +1,49 @@ + + + + + SerJaxSerHttpHttpSession + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsession.TestServlet + + + getLastAccessedTime + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsession.GetLastAccessedTime + + + expireHttpSession + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsession.ExpireHttpSession + + + TestServlet + /TestServlet/* + + + getLastAccessedTime + /getLastAccessedTime + + + expireHttpSession + /expireHttpSession + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionactivationlistener40/HSActivationListener40.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionactivationlistener40/HSActivationListener40.java new file mode 100644 index 0000000000..f84250d6e7 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionactivationlistener40/HSActivationListener40.java @@ -0,0 +1,63 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2017, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionactivationlistener40; + +import jakarta.servlet.http.HttpSessionActivationListener; + +public final class HSActivationListener40 + implements HttpSessionActivationListener { +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionactivationlistener40/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionactivationlistener40/TestServlet.java new file mode 100644 index 0000000000..cb97c71992 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionactivationlistener40/TestServlet.java @@ -0,0 +1,87 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionactivationlistener40; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpSession; + +public class TestServlet extends GenericTCKServlet { + + public void defaultMethodsTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + + HttpSession session = ((HttpServletRequest) request).getSession(true); + HSActivationListener40 hsal = new HSActivationListener40(); + session.setAttribute("hsal", hsal); + + pw.println("In HttpSessionActivationListener40.TestServlet"); + ServletTestUtil.printResult(pw, true); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionactivationlistener40/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionactivationlistener40/URLClient.java new file mode 100644 index 0000000000..892c58bcb3 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionactivationlistener40/URLClient.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2017, 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: URLClient.java 62571 2011-04-18 20:58:13Z kgrucci $ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionactivationlistener40; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_jsh_httpsessionactivationlistener40_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(HSActivationListener40.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_jsh_httpsessionactivationlistener40_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: defaultMethodsTest + * + * @assertion_ids: NA; + * + * @test_Strategy: Client successfully calls a servlet with an empty + * HttpSessionActivation listener implementation class. + * + */ + @Test + public void defaultMethodsTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "defaultMethodsTest"); + invoke(); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionactivationlistener40/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionactivationlistener40/build.xml new file mode 100644 index 0000000000..f859651770 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionactivationlistener40/build.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionactivationlistener40/servlet_jsh_httpsessionactivationlistener40_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionactivationlistener40/servlet_jsh_httpsessionactivationlistener40_web.xml new file mode 100644 index 0000000000..d09e430e66 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionactivationlistener40/servlet_jsh_httpsessionactivationlistener40_web.xml @@ -0,0 +1,33 @@ + + + + + SerJaxSerHttpHttpSessionActiListen40 + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionactivationlistener40.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionattributelistener/HSAttributeListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionattributelistener/HSAttributeListener.java new file mode 100644 index 0000000000..2eafdc30a4 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionattributelistener/HSAttributeListener.java @@ -0,0 +1,83 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionattributelistener; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.http.HttpSessionAttributeListener; +import jakarta.servlet.http.HttpSessionBindingEvent; + +public final class HSAttributeListener implements HttpSessionAttributeListener { + + // Public Methods + + public void attributeAdded(HttpSessionBindingEvent event) { + StaticLog.add("attributeAdded:" + event.getName() + "," + event.getValue()); + } + + public void attributeRemoved(HttpSessionBindingEvent event) { + StaticLog + .add("attributeRemoved:" + event.getName() + "," + event.getValue()); + } + + public void attributeReplaced(HttpSessionBindingEvent event) { + StaticLog + .add("attributeReplaced:" + event.getName() + "," + event.getValue()); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionattributelistener/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionattributelistener/TestServlet.java new file mode 100644 index 0000000000..fd1978d81b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionattributelistener/TestServlet.java @@ -0,0 +1,149 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionattributelistener; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; + +import com.sun.ts.tests.servlet.common.servlets.HttpTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpSession; + +public class TestServlet extends HttpTCKServlet { + + public void attributeAddedTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + + StaticLog.clear(); + + String[] expected = { "attributeAdded:attributeAddedTest,Attribute1" }; + + HttpSession session = request.getSession(true); + + session.setAttribute("attributeAddedTest", "Attribute1"); + + ArrayList result = StaticLog.getClear(); + boolean b = ServletTestUtil.checkArrayList(result, expected, true, false); + if (!b) { + ServletTestUtil.printFailureData(pw, result, expected); + } + ServletTestUtil.printResult(pw, b); + + session.invalidate(); + + } + + public void attributeRemovedTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + + StaticLog.clear(); + + String[] expected = { "attributeAdded:attributeRemovedTest,Attribute1", + "attributeRemoved:attributeRemovedTest,Attribute1" }; + + HttpSession session = request.getSession(true); + + session.setAttribute("attributeRemovedTest", "Attribute1"); + session.removeAttribute("attributeRemovedTest"); + + ArrayList result = StaticLog.getClear(); + boolean b = ServletTestUtil.checkArrayList(result, expected, true, false); + if (!b) { + ServletTestUtil.printFailureData(pw, result, expected); + } + ServletTestUtil.printResult(pw, b); + session.invalidate(); + + } + + public void attributeReplacedTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + + StaticLog.clear(); + + String[] expected = { "attributeAdded:attributeReplacedTest,Attribute1", + "attributeReplaced:attributeReplacedTest,Attribute1" }; + + HttpSession session = request.getSession(true); + + session.setAttribute("attributeReplacedTest", "Attribute1"); + session.setAttribute("attributeReplacedTest", "Attribute2"); + + ArrayList result = StaticLog.getClear(); + boolean b = ServletTestUtil.checkArrayList(result, expected, true, false); + if (!b) { + ServletTestUtil.printFailureData(pw, result, expected); + } + ServletTestUtil.printResult(pw, b); + session.invalidate(); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionattributelistener/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionattributelistener/URLClient.java new file mode 100644 index 0000000000..1ec7523008 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionattributelistener/URLClient.java @@ -0,0 +1,99 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionattributelistener; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_jsh_httpsessionattributelistener_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(HSAttributeListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_jsh_httpsessionattributelistener_web.xml")); + } + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: attributeAddedTest + * + * @assertion_ids: Servlet:JAVADOC:460;Servlet:JAVADOC:485 + * + * @test_Strategy: Client calls a servlet that adds an attribute. The listener + * should detect the add and writes a message out to a static log. Servlet + * then reads the log and verifies the result + * + */ + @Test + public void attributeAddedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "attributeAddedTest"); + invoke(); + } + + /* + * @testName: attributeRemovedTest + * + * @assertion_ids: Servlet:JAVADOC:461;Servlet:JAVADOC:491 + * + * @test_Strategy: Client calls a servlet that adds/Removes an attribute. The + * listener should detect the changes and writes a message out to a static + * log. Servlet then reads the log and verifies the result + */ + @Test + public void attributeRemovedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "attributeRemovedTest"); + invoke(); + } + + /* + * @testName: attributeReplacedTest + * + * @assertion_ids: Servlet:JAVADOC:462 + * + * @test_Strategy: Client calls a servlet that adds/Replaces an attribute. The + * listener should detect the changes and writes a message out to a static + * log. Servlet then reads the log and verifies the result + */ + @Test + public void attributeReplacedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "attributeReplacedTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionattributelistener/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionattributelistener/build.xml new file mode 100644 index 0000000000..533bcb0850 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionattributelistener/build.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionattributelistener/servlet_jsh_httpsessionattributelistener_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionattributelistener/servlet_jsh_httpsessionattributelistener_web.xml new file mode 100644 index 0000000000..5b5bb8d289 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionattributelistener/servlet_jsh_httpsessionattributelistener_web.xml @@ -0,0 +1,36 @@ + + + + + SerJaxSerHttpHttpSessionAttrListen + + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionattributelistener.HSAttributeListener + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionattributelistener.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionattributelistener40/HSAttributeListener40.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionattributelistener40/HSAttributeListener40.java new file mode 100644 index 0000000000..52933eae01 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionattributelistener40/HSAttributeListener40.java @@ -0,0 +1,65 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2017, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionattributelistener40; + +import jakarta.servlet.http.HttpSessionAttributeListener; + +public final class HSAttributeListener40 + implements HttpSessionAttributeListener { +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionattributelistener40/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionattributelistener40/TestServlet.java new file mode 100644 index 0000000000..3724472442 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionattributelistener40/TestServlet.java @@ -0,0 +1,80 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2006, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionattributelistener40; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void defaultMethodsTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + pw.println("In HttpSessionAttributeListener40.TestServlet"); + ServletTestUtil.printResult(pw, true); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionattributelistener40/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionattributelistener40/URLClient.java new file mode 100644 index 0000000000..7b34df7675 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionattributelistener40/URLClient.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2017, 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: URLClient.java 62571 2011-04-18 20:58:13Z kgrucci $ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionattributelistener40; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_jsh_httpsessionattributelistener40_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(HSAttributeListener40.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_jsh_httpsessionattributelistener40_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: defaultMethodsTest + * + * @assertion_ids: NA; + * + * @test_Strategy: Client successfully calls a servlet with an empty + * HttpSessionAttribute listener implementation class. + * + */ + @Test + public void defaultMethodsTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "defaultMethodsTest"); + invoke(); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionattributelistener40/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionattributelistener40/build.xml new file mode 100644 index 0000000000..5c03625777 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionattributelistener40/build.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionattributelistener40/servlet_jsh_httpsessionattributelistener40_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionattributelistener40/servlet_jsh_httpsessionattributelistener40_web.xml new file mode 100644 index 0000000000..6c7ff873e6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionattributelistener40/servlet_jsh_httpsessionattributelistener40_web.xml @@ -0,0 +1,36 @@ + + + + + SerJaxSerHttpHttpSessionAttrListen40 + + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionattributelistener40.HSAttributeListener40 + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionattributelistener40.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindingevent/HSBindingEvent.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindingevent/HSBindingEvent.java new file mode 100644 index 0000000000..cb68e46537 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindingevent/HSBindingEvent.java @@ -0,0 +1,84 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionbindingevent; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.http.HttpSessionAttributeListener; +import jakarta.servlet.http.HttpSessionBindingEvent; + +public final class HSBindingEvent implements HttpSessionAttributeListener { + + // Public Methods + + public void attributeAdded(HttpSessionBindingEvent event) { + StaticLog.add("attributeAdded: Name=" + event.getName() + ", Value=" + + event.getValue() + ", sessionid=" + event.getSession().getId()); + } + + public void attributeRemoved(HttpSessionBindingEvent event) { + StaticLog.add("attributeRemoved: Name=" + event.getName() + ", Value=" + + event.getValue() + ", sessionid=" + event.getSession().getId()); + } + + public void attributeReplaced(HttpSessionBindingEvent event) { + StaticLog.add("attributeReplaced: Name=" + event.getName() + ", Value=" + + event.getValue() + ", sessionid=" + event.getSession().getId()); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindingevent/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindingevent/TestServlet.java new file mode 100644 index 0000000000..2c1f94f9c5 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindingevent/TestServlet.java @@ -0,0 +1,200 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionbindingevent; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; + +import com.sun.ts.tests.servlet.common.servlets.HttpTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpSession; +import jakarta.servlet.http.HttpSessionBindingEvent; + +public class TestServlet extends HttpTCKServlet { + + public void addedTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + + StaticLog.clear(); + + HttpSession session = request.getSession(true); + + String[] expected = { + "attributeAdded: Name=addedTest, Value=attribute1, sessionid=" + + session.getId() }; + + session.setAttribute("addedTest", "attribute1"); + + ArrayList result = StaticLog.getClear(); + boolean b = ServletTestUtil.checkArrayList(result, expected, true, false); + if (!b) { + ServletTestUtil.printFailureData(pw, result, expected); + } + ServletTestUtil.printResult(pw, b); + + session.invalidate(); + + } + + public void removedTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + + StaticLog.clear(); + + HttpSession session = request.getSession(true); + + String[] expected = { + "attributeAdded: Name=removedTest, Value=attribute1, sessionid=" + + session.getId(), + "attributeRemoved: Name=removedTest, Value=attribute1, sessionid=" + + session.getId() }; + + session.setAttribute("removedTest", "attribute1"); + session.removeAttribute("removedTest"); + + ArrayList result = StaticLog.getClear(); + boolean b = ServletTestUtil.checkArrayList(result, expected, true, false); + if (!b) { + ServletTestUtil.printFailureData(pw, result, expected); + } + ServletTestUtil.printResult(pw, b); + + session.invalidate(); + + } + + public void replacedTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + + StaticLog.clear(); + + HttpSession session = request.getSession(true); + + String[] expected = { + "attributeAdded: Name=replacedTest, Value=attribute1, sessionid=" + + session.getId(), + "attributeReplaced: Name=replacedTest, Value=attribute1, sessionid=" + + session.getId() }; + + session.setAttribute("replacedTest", "attribute1"); + session.setAttribute("replacedTest", "attribute2"); + + ArrayList result = StaticLog.getClear(); + boolean b = ServletTestUtil.checkArrayList(result, expected, true, false); + if (!b) { + ServletTestUtil.printFailureData(pw, result, expected); + } + ServletTestUtil.printResult(pw, b); + + session.invalidate(); + + } + + public void constructor_StringTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + + HttpSession session = request.getSession(true); + + HttpSessionBindingEvent hsbe = new HttpSessionBindingEvent(session, + "constructor_StringTest"); + + if (hsbe != null) { + ServletTestUtil.printResult(pw, true); + } else { + pw.println("Error:HttpSessionBindingEvent returned a null"); + ServletTestUtil.printResult(pw, false); + } + + } + + public void constructor_String_ObjectTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + + HttpSession session = request.getSession(true); + HSBindingEvent hsbe1 = new HSBindingEvent(); + + HttpSessionBindingEvent hsbe = new HttpSessionBindingEvent(session, + "constructor_String_ObjectTest", hsbe1); + + if (hsbe != null) { + ServletTestUtil.printResult(pw, true); + } else { + pw.println("Error:HttpSessionBindingEvent returned a null"); + ServletTestUtil.printResult(pw, false); + } + + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindingevent/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindingevent/URLClient.java new file mode 100644 index 0000000000..d4f17476a9 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindingevent/URLClient.java @@ -0,0 +1,127 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionbindingevent; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_jsh_httpsessionbindingevent_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(HSBindingEvent.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_jsh_httpsessionbindingevent_web.xml")); + } + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: addedTest + * + * @assertion_ids: Servlet:JAVADOC:309;Servlet:JAVADOC:307;Servlet:JAVADOC:308 + * + * @test_Strategy: Client calls a servlet that adds an attribute. The listener + * should detect the add and writes the values returned by the getName, + * getSession(), and getValue() methods to a static log. Servlet then reads + * the log and verifies the result + */ + @Test + public void addedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "addedTest"); + invoke(); + } + + /* + * @testName: removedTest + * + * @assertion_ids: Servlet:JAVADOC:310;Servlet:JAVADOC:307;Servlet:JAVADOC:308 + * + * @test_Strategy: Client calls a servlet that adds/removes an attribute. The + * listener should detect the changes and writes the values returned by the + * getName, getSession(), and getValue() methods to a static log. Servlet then + * reads the log and verifies the result + */ + @Test + public void removedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "removedTest"); + invoke(); + } + + /* + * @testName: replacedTest + * + * @assertion_ids: Servlet:JAVADOC:311;Servlet:JAVADOC:307;Servlet:JAVADOC:308 + * + * @test_Strategy: Client calls a servlet that adds/replaces an attribute. The + * listener should detect the changes and writes the values returned by the + * getName, getSession(), and getValue() methods to a static log. Servlet then + * reads the log and verifies the result + */ + @Test + public void replacedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "replacedTest"); + invoke(); + } + + /* + * @testName: constructor_StringTest + * + * @assertion_ids: Servlet:JAVADOC:305 + * + * @test_Strategy: Servlet creates an object using the 2 argument method. + */ + @Test + public void constructor_StringTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "constructor_StringTest"); + invoke(); + } + + /* + * @testName: constructor_String_ObjectTest + * + * @assertion_ids: Servlet:JAVADOC:306 + * + * @test_Strategy: Servlet creates an object using the 3 argument method. + */ + @Test + public void constructor_String_ObjectTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "constructor_String_ObjectTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindingevent/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindingevent/build.xml new file mode 100644 index 0000000000..12311b74ed --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindingevent/build.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindingevent/servlet_jsh_httpsessionbindingevent_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindingevent/servlet_jsh_httpsessionbindingevent_web.xml new file mode 100644 index 0000000000..d87def9d3f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindingevent/servlet_jsh_httpsessionbindingevent_web.xml @@ -0,0 +1,36 @@ + + + + + SerJaxSerHttpHttpSessionBindEvent + + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionbindingevent.HSBindingEvent + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionbindingevent.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindinglistener/HSBindingListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindinglistener/HSBindingListener.java new file mode 100644 index 0000000000..25023ffb44 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindinglistener/HSBindingListener.java @@ -0,0 +1,76 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionbindinglistener; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.http.HttpSessionBindingEvent; +import jakarta.servlet.http.HttpSessionBindingListener; + +public final class HSBindingListener implements HttpSessionBindingListener { + + // Public Methods + + public void valueBound(HttpSessionBindingEvent event) { + StaticLog.add("valueBound:" + event.getName()); + } + + public void valueUnbound(HttpSessionBindingEvent event) { + StaticLog.add("valueUnBound:" + event.getName()); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindinglistener/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindinglistener/TestServlet.java new file mode 100644 index 0000000000..fe228484a9 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindinglistener/TestServlet.java @@ -0,0 +1,126 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionbindinglistener; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; + +import com.sun.ts.tests.servlet.common.servlets.HttpTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpSession; + +public class TestServlet extends HttpTCKServlet { + + public void boundTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + StaticLog.clear(); + + String[] expected = { "valueBound:boundTest" }; + + HttpSession session = request.getSession(true); + HSBindingListener hsbl = new HSBindingListener(); + + session.setAttribute("boundTest", hsbl); + + ArrayList result = StaticLog.getClear(); + boolean b = ServletTestUtil.checkArrayList(result, expected, true, false); + if (!b) { + ServletTestUtil.printFailureData(pw, result, expected); + } + ServletTestUtil.printResult(pw, b); + + session.invalidate(); + } + + public void unBoundTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + StaticLog.clear(); + + String[] expected = { "valueBound:unBoundTest", "valueUnBound:unBoundTest", + "valueBound:unBoundTest", "valueUnBound:unBoundTest" }; + + HttpSession session = request.getSession(true); + HSBindingListener hsbl1 = new HSBindingListener(); + HSBindingListener hsbl2 = new HSBindingListener(); + + session.setAttribute("unBoundTest", hsbl1); + session.setAttribute("unBoundTest", hsbl2); + session.removeAttribute("unBoundTest"); + + ArrayList result = StaticLog.getClear(); + boolean b = ServletTestUtil.checkArrayList(result, expected, true, true); + if (!b) { + ServletTestUtil.printFailureData(pw, result, expected); + } + ServletTestUtil.printResult(pw, b); + + session.invalidate(); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindinglistener/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindinglistener/URLClient.java new file mode 100644 index 0000000000..dafd1fbca6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindinglistener/URLClient.java @@ -0,0 +1,89 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionbindinglistener; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_jsh_httpsessionbindinglistener_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(HSBindingListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_jsh_httpsessionbindinglistener_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: unBoundTest + * + * @assertion_ids: + * Servlet:JAVADOC:459;Servlet:JAVADOC:485;Servlet:JAVADOC:486;Servlet:JAVADOC + * :491 + * + * @test_Strategy: Client calls a servlet that sets/sets/removes an attribute + * from the session. That attribute happens to be a Binding listener. The + * Listeners valueBound/valueUnbound methods should be called and messages + * written to a static log. The servlet then reads the log and verifies the + * result. + */ + @Test + public void unBoundTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "unBoundTest"); + invoke(); + } + + /* + * @testName: boundTest + * + * @assertion_ids: Servlet:JAVADOC:458;Servlet:JAVADOC:485;Servlet:JAVADOC:486 + * + * @test_Strategy: Client calls a servlet that sets an attribute to the + * session. That attribute happens to be a Binding listener. The Listeners + * valueBound/valueUnbound methods should be called and messages written to a + * static log. The servlet then reads the log and verifies the result. + */ + @Test + public void boundTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "boundTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindinglistener/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindinglistener/build.xml new file mode 100644 index 0000000000..207649ac21 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindinglistener/build.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindinglistener/servlet_jsh_httpsessionbindinglistener_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindinglistener/servlet_jsh_httpsessionbindinglistener_web.xml new file mode 100644 index 0000000000..754e3d2b0a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindinglistener/servlet_jsh_httpsessionbindinglistener_web.xml @@ -0,0 +1,33 @@ + + + + + SerJaxSerHttpHttpSessionBindListen + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionbindinglistener.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindinglistener40/HSBindingListener40.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindinglistener40/HSBindingListener40.java new file mode 100644 index 0000000000..08334d7a18 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindinglistener40/HSBindingListener40.java @@ -0,0 +1,64 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2017, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionbindinglistener40; + +import jakarta.servlet.http.HttpSessionBindingListener; + +public final class HSBindingListener40 implements HttpSessionBindingListener { +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindinglistener40/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindinglistener40/TestServlet.java new file mode 100644 index 0000000000..8fe587d0ee --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindinglistener40/TestServlet.java @@ -0,0 +1,87 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionbindinglistener40; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpSession; + +public class TestServlet extends GenericTCKServlet { + + public void defaultMethodsTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + + HttpSession session = ((HttpServletRequest) request).getSession(true); + HSBindingListener40 hsbl = new HSBindingListener40(); + session.setAttribute("hsbinding", hsbl); + + pw.println("In HttpSessionBindingListener40.TestServlet"); + ServletTestUtil.printResult(pw, true); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindinglistener40/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindinglistener40/URLClient.java new file mode 100644 index 0000000000..fbc3215b9f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindinglistener40/URLClient.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2017, 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: URLClient.java 62571 2011-04-18 20:58:13Z kgrucci $ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionbindinglistener40; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_jsh_httpsessionbindinglistener40_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(HSBindingListener40.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_jsh_httpsessionbindinglistener40_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: defaultMethodsTest + * + * @assertion_ids: NA; + * + * @test_Strategy: Client successfully calls a servlet with an empty + * HttpSessionBinding listener implementation class. + * + */ + @Test + public void defaultMethodsTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "defaultMethodsTest"); + invoke(); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindinglistener40/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindinglistener40/build.xml new file mode 100644 index 0000000000..aa83111d54 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindinglistener40/build.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindinglistener40/servlet_jsh_httpsessionbindinglistener40_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindinglistener40/servlet_jsh_httpsessionbindinglistener40_web.xml new file mode 100644 index 0000000000..838d4c1091 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionbindinglistener40/servlet_jsh_httpsessionbindinglistener40_web.xml @@ -0,0 +1,33 @@ + + + + + SerJaxSerHttpHttpSessionBindListen40 + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionbindinglistener40.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionevent/HSEvent.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionevent/HSEvent.java new file mode 100644 index 0000000000..ee6dfef4af --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionevent/HSEvent.java @@ -0,0 +1,77 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionevent; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.http.HttpSessionEvent; +import jakarta.servlet.http.HttpSessionListener; + +public final class HSEvent implements HttpSessionListener { + + // Public Methods + + public void sessionCreated(HttpSessionEvent event) { + StaticLog.add("sessionCreated:sessionid=" + event.getSession().getId()); + } + + public void sessionDestroyed(HttpSessionEvent event) { + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionevent/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionevent/TestServlet.java new file mode 100644 index 0000000000..2b14f70f73 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionevent/TestServlet.java @@ -0,0 +1,116 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionevent; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; + +import com.sun.ts.tests.servlet.common.servlets.HttpTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpSession; +import jakarta.servlet.http.HttpSessionEvent; + +public class TestServlet extends HttpTCKServlet { + + public void getSessionTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + StaticLog.clear(); + + HttpSession session = request.getSession(true); + + String[] expected = { "sessionCreated:sessionid=" + session.getId() }; + + ArrayList result = StaticLog.getClear(); + boolean b = ServletTestUtil.checkArrayList(result, expected, true, false); + if (!b) { + ServletTestUtil.printFailureData(pw, result, expected); + } + ServletTestUtil.printResult(pw, b); + + session.invalidate(); + + } + + public void constructorTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + StaticLog.clear(); + + HttpSession session = request.getSession(true); + + HttpSessionEvent hse = new HttpSessionEvent(session); + if (hse != null) { + ServletTestUtil.printResult(pw, true); + } else { + pw.println("ERROR: HttpSessionEvent returned a null"); + ServletTestUtil.printResult(pw, true); + } + + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionevent/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionevent/URLClient.java new file mode 100644 index 0000000000..3e31f130d1 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionevent/URLClient.java @@ -0,0 +1,84 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionevent; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_jsh_httpsessionevent_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(HSEvent.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_jsh_httpsessionevent_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: getSessionTest + * + * @assertion_ids: Servlet:JAVADOC:304 + * + * @test_Strategy: Client calls a servlet that creates a session. The listener + * writes the sessionid of the event to a static log. The Servlet then reads + * the log and verifies the result + */ + @Test + public void getSessionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getSessionTest"); + invoke(); + } + + /* + * @testName: constructorTest + * + * @assertion_ids: Servlet:JAVADOC:303 + * + * @test_Strategy: servlet calls the constructor + */ + @Test + public void constructorTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "constructorTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionevent/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionevent/build.xml new file mode 100644 index 0000000000..d1d2cec583 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionevent/build.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionevent/servlet_jsh_httpsessionevent_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionevent/servlet_jsh_httpsessionevent_web.xml new file mode 100644 index 0000000000..3b0d814583 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionevent/servlet_jsh_httpsessionevent_web.xml @@ -0,0 +1,36 @@ + + + + + SerJaxSerHttpHttpSessionEvent + + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionevent.HSEvent + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionevent.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionidlistener/TCKHttpSessionIDListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionidlistener/TCKHttpSessionIDListener.java new file mode 100644 index 0000000000..37d3c205e3 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionidlistener/TCKHttpSessionIDListener.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionidlistener; + +import jakarta.servlet.annotation.WebListener; +import jakarta.servlet.http.HttpSession; +import jakarta.servlet.http.HttpSessionEvent; +import jakarta.servlet.http.HttpSessionIdListener; + +@WebListener +public class TCKHttpSessionIDListener implements HttpSessionIdListener { + + public void sessionIdChanged(HttpSessionEvent event, String oldId) { + HttpSession session = event.getSession(); + String sessionId = session.getId(); + + session.setAttribute("OLD", oldId); + session.setAttribute("NEW", sessionId); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionidlistener/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionidlistener/URLClient.java new file mode 100644 index 0000000000..a95ec9f79e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionidlistener/URLClient.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionidlistener; + +import com.sun.ts.tests.servlet.common.request.HttpRequestClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends HttpRequestClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_jsh_httpsessionidlistener_web.war").addAsLibraries(CommonServlets.getCommonServletsArchive()).addClasses(TCKHttpSessionIDListener.class).setWebXML(URLClient.class.getResource("servlet_jsh_httpsessionidlistener_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + /* Run test */ + /* + * @testName: changeSessionIDTest1 + * + * @assertion_ids: Servlet:JAVADOC:304; Servlet:JAVADOC:467; + * Servlet:JAVADOC:476; Servlet:JAVADOC:484; Servlet:JAVADOC:565; + * Servlet:JAVADOC:566; Servlet:JAVADOC:929; Servlet:JAVADOC:935; + * + * @test_Strategy: Send an HttpServletRequest to server; Verify that + * request.changeSessionId() works. + */ + @Test() + public void changeSessionIDTest1() throws Exception { + super.changeSessionIDTest1(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionidlistener/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionidlistener/build.xml new file mode 100644 index 0000000000..395678768f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionidlistener/build.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionidlistener/servlet_jsh_httpsessionidlistener_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionidlistener/servlet_jsh_httpsessionidlistener_web.xml new file mode 100644 index 0000000000..a39e4ce8f4 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionidlistener/servlet_jsh_httpsessionidlistener_web.xml @@ -0,0 +1,30 @@ + + + + + SerJaxSerHttpSessionIDLsitener + + TestServlet + com.sun.ts.tests.servlet.common.servlets.HttpRequestTestServlet + + + TestServlet + /TestServlet + + \ No newline at end of file diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionlistener/HSListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionlistener/HSListener.java new file mode 100644 index 0000000000..016ba91b84 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionlistener/HSListener.java @@ -0,0 +1,78 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionlistener; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.http.HttpSessionEvent; +import jakarta.servlet.http.HttpSessionListener; + +public final class HSListener implements HttpSessionListener { + + // Public Methods + + public void sessionCreated(HttpSessionEvent event) { + StaticLog.add("HSListener:sessionCreated"); + } + + public void sessionDestroyed(HttpSessionEvent event) { + StaticLog.add("HSListener:sessionDestroyed"); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionlistener/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionlistener/TestServlet.java new file mode 100644 index 0000000000..767957d127 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionlistener/TestServlet.java @@ -0,0 +1,121 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionlistener; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; + +import com.sun.ts.tests.servlet.common.servlets.HttpTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpSession; + +public class TestServlet extends HttpTCKServlet { + + public void createdTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + + StaticLog.clear(); + + String[] expected = { "HSListener:sessionCreated" }; + + HttpSession session = request.getSession(true); + + ArrayList result = StaticLog.getClear(); + boolean b = ServletTestUtil.checkArrayList(result, expected, true, false); + if (!b) { + ServletTestUtil.printFailureData(pw, result, expected); + } + ServletTestUtil.printResult(pw, b); + + session.invalidate(); + + } + + public void destroyedTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + + StaticLog.clear(); + + String[] expected = { "HSListener:sessionDestroyed" }; + + HttpSession session = request.getSession(true); + + StaticLog.clear(); + + session.invalidate(); + + ArrayList result = StaticLog.getClear(); + boolean b = ServletTestUtil.checkArrayList(result, expected, true, false); + if (!b) { + ServletTestUtil.printFailureData(pw, result, expected); + } + ServletTestUtil.printResult(pw, b); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionlistener/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionlistener/URLClient.java new file mode 100644 index 0000000000..4d43174357 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionlistener/URLClient.java @@ -0,0 +1,89 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionlistener; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_jsh_httpsessionlistener_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(HSListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_jsh_httpsessionlistener_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: createdTest + * + * @assertion_ids: Servlet:JAVADOC:454 + * + * @test_Strategy: Client calls a servlet that creates a session. The listener + * should detect the creation and write a message to a static log. The Servlet + * then reads the log and verifies the result. As a result of the test, the + * jakarta.servlet.http.Event.getSession() method is tested. + * + */ + @Test + public void createdTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "createdTest"); + invoke(); + } + + /* + * @testName: destroyedTest + * + * @assertion_ids: Servlet:JAVADOC:455 + * + * @test_Strategy: Client calls a servlet that creates and the invalidates a + * session. The listener should detect the changes and write a message to a + * static log. The Servlet then reads the log file and verifies the result. As + * a result of the test, the jakarta.servlet.http.Event.getSession() method is + * tested. + */ + @Test + public void destroyedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "destroyedTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionlistener/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionlistener/build.xml new file mode 100644 index 0000000000..2066fcb7ba --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionlistener/build.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionlistener/servlet_jsh_httpsessionlistener_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionlistener/servlet_jsh_httpsessionlistener_web.xml new file mode 100644 index 0000000000..a3c6ddca34 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionlistener/servlet_jsh_httpsessionlistener_web.xml @@ -0,0 +1,36 @@ + + + + + SerJaxSerHttpHttpSessionListen + + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionlistener.HSListener + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionlistener.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionlistener40/HSListener40.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionlistener40/HSListener40.java new file mode 100644 index 0000000000..18647f1736 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionlistener40/HSListener40.java @@ -0,0 +1,66 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2017, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000 The Apache Software Foundation. All rights + * Copyright (c) 2000 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" must + * not be used to endorse or promote products derived from this + * software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * nor may "Apache" appear in their name, without prior written + * permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * Portions of this software are based upon public domain software + * originally written at the National Center for Supercomputing Applications, + * University of Illinois, Urbana-Champaign. + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionlistener40; + +import jakarta.servlet.http.HttpSessionListener; + +public final class HSListener40 implements HttpSessionListener { +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionlistener40/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionlistener40/TestServlet.java new file mode 100644 index 0000000000..a7db98e7e3 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionlistener40/TestServlet.java @@ -0,0 +1,80 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionlistener40; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void defaultMethodsTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + pw.println("In HttpSessionListener40.TestServlet"); + ServletTestUtil.printResult(pw, true); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionlistener40/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionlistener40/URLClient.java new file mode 100644 index 0000000000..7c67b1102b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionlistener40/URLClient.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2017, 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: URLClient.java 62571 2011-04-18 20:58:13Z kgrucci $ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionlistener40; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_jsh_httpsessionlistener40_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(HSListener40.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_jsh_httpsessionlistener40_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: defaultMethodsTest + * + * @assertion_ids: NA; + * + * @test_Strategy: Client successfully calls a servlet with an empty + * HttpSession listener implementation class. + * + */ + @Test + public void defaultMethodsTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "defaultMethodsTest"); + invoke(); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionlistener40/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionlistener40/build.xml new file mode 100644 index 0000000000..059f33c288 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionlistener40/build.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionlistener40/servlet_jsh_httpsessionlistener40_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionlistener40/servlet_jsh_httpsessionlistener40_web.xml new file mode 100644 index 0000000000..952d8cb64a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionlistener40/servlet_jsh_httpsessionlistener40_web.xml @@ -0,0 +1,36 @@ + + + + + SerJaxSerHttpHttpSessionListen40 + + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionlistener40.HSListener40 + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionlistener40.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionx/ExpireHttpSession.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionx/ExpireHttpSession.java new file mode 100644 index 0000000000..81819e57ad --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionx/ExpireHttpSession.java @@ -0,0 +1,45 @@ +/* + * 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionx; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpSession; + +public class ExpireHttpSession extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + HttpSession session = request.getSession(false); + if (session == null) { + pw.println("From expireHttpSession: Session expired as expected."); + ServletTestUtil.printResult(pw, true); + } else { + pw.println( + "From expireHttpSession: Test Failed. Session didnot expire as expected."); + ServletTestUtil.printResult(pw, false); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionx/GetNewSession.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionx/GetNewSession.java new file mode 100644 index 0000000000..2c89e48b8b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionx/GetNewSession.java @@ -0,0 +1,44 @@ +/* + * 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionx; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpSession; + +public class GetNewSession extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + HttpSession session = request.getSession(true); + if (session == null) { + pw.println("From getNewSession: Cannot create a new Session"); + ServletTestUtil.printResult(pw, false); + } else { + pw.println("From getNewSession: new Session is created"); + ServletTestUtil.printResult(pw, true); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionx/InvalidateHttpSession.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionx/InvalidateHttpSession.java new file mode 100644 index 0000000000..e2170b1093 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionx/InvalidateHttpSession.java @@ -0,0 +1,49 @@ +/* + * 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionx; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpSession; + +public class InvalidateHttpSession extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + boolean passed = false; + + PrintWriter pw = response.getWriter(); + HttpSession session = request.getSession(false); + session.invalidate(); + + // session is invalidated. The method should return false. + if (!request.isRequestedSessionIdValid()) { + passed = true; + pw.println("From invalidateHttpSession: Session is invalidated "); + } else { + pw.println("From invalidateHttpSession: Session is not invalidated "); + } + ServletTestUtil.printResult(pw, passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionx/SetMaxInterval.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionx/SetMaxInterval.java new file mode 100644 index 0000000000..70171298b5 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionx/SetMaxInterval.java @@ -0,0 +1,45 @@ +/* + * 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionx; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpSession; + +public class SetMaxInterval extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + boolean passed = true; + + HttpSession session = request.getSession(true); + pw.println("From setMaxInterval: Session created."); + + session.setMaxInactiveInterval(10); + pw.println("From setMaxInterval: MaxInactiveInterval is set to 10 sec"); + + ServletTestUtil.printResult(pw, true); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionx/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionx/TestServlet.java new file mode 100644 index 0000000000..ed0b2fb761 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionx/TestServlet.java @@ -0,0 +1,170 @@ +/* + * 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionx; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.HttpTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpSession; + +public class TestServlet extends HttpTCKServlet { + int expectedResult = 10; + + public void getNewSession(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + boolean passed = true; + request.getSession(true); + ServletTestUtil.printResult(pw, passed); + } + + public void getNewSessionx(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + ServletContext servletContext = getServletContext() + .getContext("/servlet_jsh_httpsessionx2_web"); + RequestDispatcher rd = servletContext + .getRequestDispatcher("/getNewSession"); + + rd.include(request, response); + } + + public void setMaxInactiveIntervalTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + boolean passed = true; + HttpSession session = request.getSession(false); + session.setMaxInactiveInterval(expectedResult); + ServletTestUtil.printResult(pw, passed); + } + + public void getMaxInactiveIntervalTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + boolean passed = false; + + HttpSession session = request.getSession(false); + int result = session.getMaxInactiveInterval(); + + if (result != expectedResult) { + passed = false; + pw.println("getMaxInactiveInterval() returned incorrect result "); + pw.println("Expected result = " + expectedResult + " "); + pw.println("Actual result = |" + result + "| "); + } else { + pw.println("getMaxInactiveInterval() returned correct result " + result); + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public void expireHttpSessionTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + boolean passed = false; + + HttpSession session = request.getSession(false); + + if (session != null) { + passed = false; + pw.println("From TestServlet: Session is not expired "); + } else { + pw.println("From TestServlet: Session is expired as expected"); + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public void setMaxInactiveIntervalxiTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + ServletContext servletContext = getServletContext() + .getContext("/servlet_jsh_httpsessionx2_web"); + RequestDispatcher rd = servletContext + .getRequestDispatcher("/setMaxInterval"); + + rd.include(request, response); + } + + public void setMaxInactiveIntervalxfTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + ServletContext servletContext = getServletContext() + .getContext("/servlet_jsh_httpsessionx2_web"); + RequestDispatcher rd = servletContext + .getRequestDispatcher("/setMaxInterval"); + + rd.forward(request, response); + } + + public void expireHttpSessionxriTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + ServletContext servletContext = getServletContext() + .getContext("/servlet_jsh_httpsessionx2_web"); + RequestDispatcher rd = servletContext + .getRequestDispatcher("/expireHttpSession"); + + rd.include(request, response); + } + + public void expireHttpSessionxrfTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + ServletContext servletContext = getServletContext() + .getContext("/servlet_jsh_httpsessionx2_web"); + RequestDispatcher rd = servletContext + .getRequestDispatcher("/expireHttpSession"); + + rd.forward(request, response); + } + + public void invalidateSessionTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + boolean passed = false; + + HttpSession session = request.getSession(false); + session.invalidate(); + + // session is invalidated. The method should return false. + if (!request.isRequestedSessionIdValid()) { + passed = true; + pw.println("From TestServlet: Session is invalidated "); + } else { + passed = false; + pw.println("From TestServlet: Session is not invalidated "); + } + + ServletTestUtil.printResult(pw, passed); + } + + public void invalidateSessionxTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + ServletContext servletContext = getServletContext() + .getContext("/servlet_jsh_httpsessionx2_web"); + RequestDispatcher rd = servletContext + .getRequestDispatcher("/invalidateHttpSession"); + + rd.include(request, response); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionx/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionx/URLClient.java new file mode 100644 index 0000000000..1f5eb74ba0 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionx/URLClient.java @@ -0,0 +1,336 @@ +/* + * 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: URLClient.java 52425 2007-01-18 19:31:04Z djiao $ + */ + +/** + * Tests that focus on cross-context + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionx; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_jsh_httpsessionx_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_jsh_httpsessionx_web.xml")); + } + + @Deployment(testable = false, name = "servlet_jsh_httpsession2x_web") + public static WebArchive getTestArchive2() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_jsh_httpsessionx2_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(ExpireHttpSession.class, GetNewSession.class, + InvalidateHttpSession.class, SetMaxInterval.class) + .setWebXML(URLClient.class.getResource("servlet_jsh_httpsessionx2_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* + * @testName: getMaxInactiveIntervalTest + * + * @assertion_ids: Servlet:JAVADOC:473; Servlet:JAVADOC:474; Servlet:SPEC:202; + * Servlet:SPEC:66; Servlet:JAVADOC:565; Servlet:JAVADOC:566; + * + * @test_Strategy: 1. Client sends request to TestServlet which - create a new + * HttpSession using request.getSession(true); - set the session's + * maxInactiveInterval to 10 secs. Client captures the JSESSIONID returned in + * the response. 2. Within maxInactiveInterval, client sends a request that + * contains the JSESSIONID in a request cookie to the servlet again, verify + * that MaxInactiveInterval is set correctly + */ + @Test + public void getMaxInactiveIntervalTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getNewSession"); + TEST_PROPS.setProperty(SAVE_STATE, "true"); + invoke(); + + TEST_PROPS.setProperty(APITEST, "setMaxInactiveIntervalTest"); + TEST_PROPS.setProperty(SAVE_STATE, "true"); + TEST_PROPS.setProperty(USE_SAVED_STATE, "true"); + invoke(); + + TEST_PROPS.setProperty(APITEST, "getMaxInactiveIntervalTest"); + TEST_PROPS.setProperty(USE_SAVED_STATE, "true"); + invoke(); + } + + /* + * @testName: expireHttpSessionTest + * + * @assertion_ids: Servlet:JAVADOC:473; Servlet:JAVADOC:474; Servlet:SPEC:202; + * Servlet:SPEC:66; Servlet:JAVADOC:565; Servlet:JAVADOC:566; + * + * @test_Strategy: 1. Client sends request to TestServlet which - creates a + * session using request.getSession() - and sets the session's + * maxInactiveInterval to 10 secs. Client captures the JSESSIONID returned in + * the response. + * + * 2. Client waits for longer than maxInactiveInterval, and sends a + * request(including JSESSIONID) to the servlet. The servlet tries to resume + * the session by calling request.getSession(false). Verify that no session is + * returned this time + */ + @Test + public void expireHttpSessionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getNewSession"); + TEST_PROPS.setProperty(SAVE_STATE, "true"); + invoke(); + + TEST_PROPS.setProperty(APITEST, "setMaxInactiveIntervalTest"); + TEST_PROPS.setProperty(SAVE_STATE, "true"); + TEST_PROPS.setProperty(USE_SAVED_STATE, "true"); + invoke(); + + try { + Thread.sleep(11000); + } catch (InterruptedException ex) { + ex.printStackTrace(); + } + + TEST_PROPS.setProperty(APITEST, "expireHttpSessionTest"); + TEST_PROPS.setProperty(USE_SAVED_STATE, "true"); + invoke(); + } + + /* + * @testName: expireHttpSessionxTest + * + * @assertion_ids: Servlet:JAVADOC:473; Servlet:JAVADOC:474; Servlet:SPEC:202; + * Servlet:SPEC:66; Servlet:JAVADOC:565; Servlet:JAVADOC:566; + * + * @test_Strategy: 1. Client sends request to TestServlet which - creates a + * session using request.getSession() - and sets the session's + * maxInactiveInterval to 10 secs. Client captures the JSESSIONID returned in + * the response. + * + * 2. Client waits for longer than maxInactiveInterval, sends a request with + * JSESSIONID to a servlet with different context. The servlet tries to resume + * the session by calling request.getSession(false). Verify that no session is + * returned this time + */ + @Test + public void expireHttpSessionxTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getNewSession"); + TEST_PROPS.setProperty(SAVE_STATE, "true"); + invoke(); + + TEST_PROPS.setProperty(APITEST, "setMaxInactiveIntervalTest"); + TEST_PROPS.setProperty(SAVE_STATE, "true"); + TEST_PROPS.setProperty(USE_SAVED_STATE, "true"); + invoke(); + + try { + Thread.sleep(11000); + } catch (InterruptedException ex) { + ex.printStackTrace(); + } + + TEST_PROPS.setProperty(REQUEST, "GET " + "/servlet_jsh_httpsessionx2_web" + + "/expireHttpSession" + " HTTP/1.1"); + TEST_PROPS.setProperty(USE_SAVED_STATE, "true"); + TEST_PROPS.setProperty(SEARCH_STRING, "Session expired as expected."); + + invoke(); + } + + /* + * @testName: expireHttpSessionxriTest + * + * @assertion_ids: Servlet:JAVADOC:473; Servlet:JAVADOC:474; Servlet:SPEC:202; + * Servlet:SPEC:66; Servlet:JAVADOC:565; Servlet:JAVADOC:566; + * + * @test_Strategy: 1. Client sends request to TestServlet which - creates a + * session using request.getSession() - and sets the session's + * maxInactiveInterval to 10 secs. Client captures the JSESSIONID returned in + * the response. + * + * 2. Client waits for longer than maxInactiveInterval, sends a request with + * JSESSIONID to the servlet. The servlet send request to second servlet using + * RequestDispatcher. Then the second servlet tries to resume the session by + * calling request.getSession(false). Verify that no session is returned this + * time + */ + @Test + public void expireHttpSessionxriTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getNewSession"); + TEST_PROPS.setProperty(SAVE_STATE, "true"); + invoke(); + + TEST_PROPS.setProperty(APITEST, "setMaxInactiveIntervalTest"); + TEST_PROPS.setProperty(SAVE_STATE, "true"); + TEST_PROPS.setProperty(USE_SAVED_STATE, "true"); + invoke(); + + try { + Thread.sleep(11000); + } catch (InterruptedException ex) { + ex.printStackTrace(); + } + + TEST_PROPS.setProperty(APITEST, "expireHttpSessionxriTest"); + TEST_PROPS.setProperty(USE_SAVED_STATE, "true"); + invoke(); + } + + /* + * @testName: expireHttpSessionxri1Test + * + * @assertion_ids: Servlet:JAVADOC:473; Servlet:JAVADOC:474; Servlet:SPEC:202; + * Servlet:SPEC:66; Servlet:JAVADOC:565; Servlet:JAVADOC:566; + * + * @test_Strategy: 1. Client sends request to TestServlet which The servlet + * send request to second servlet using RequestDispatcher.include. + * + * 2. The second servlet tries to - creates a session using + * request.getSession() - and sets the session's maxInactiveInterval to 10 + * secs. Client captures the JSESSIONID returned in the response. + * + * 3. Client waits for longer than maxInactiveInterval, sends a request with + * JSESSIONID to the first servlet. Which again send request to second servlet + * using RequestDispatcher. + * + * 4. The second servlet tries to resume the session by calling + * request.getSession(false). Verify that no session is returned this time + */ + @Test + public void expireHttpSessionxri1Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "setMaxInactiveIntervalxiTest"); + TEST_PROPS.setProperty(SAVE_STATE, "true"); + invoke(); + + try { + Thread.sleep(11000); + } catch (InterruptedException ex) { + ex.printStackTrace(); + } + + TEST_PROPS.setProperty(APITEST, "expireHttpSessionxriTest"); + TEST_PROPS.setProperty(USE_SAVED_STATE, "true"); + invoke(); + } + + /* + * @testName: expireHttpSessionxrfTest + * + * @assertion_ids: Servlet:JAVADOC:473; Servlet:JAVADOC:474; Servlet:SPEC:202; + * Servlet:SPEC:66; Servlet:JAVADOC:565; Servlet:JAVADOC:566; + * + * @test_Strategy: 1. Client sends request to TestServlet which The servlet + * send request to second servlet using RequestDispatcher.forward. + * + * 2. The second servlet tries to - creates a session using + * request.getSession() - and sets the session's maxInactiveInterval to 10 + * secs. Client captures the JSESSIONID returned in the response. + * + * 3. Client waits for longer than maxInactiveInterval, sends a request with + * JSESSIONID to the first servlet. Which again send request to second servlet + * using RequestDispatcher.forward. + * + * 4. The second servlet tries to resume the session by calling + * request.getSession(false). Verify that no session is returned this time + */ + @Test + public void expireHttpSessionxrfTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setMaxInactiveIntervalxfTest"); + TEST_PROPS.setProperty(SAVE_STATE, "true"); + invoke(); + + try { + Thread.sleep(11000); + } catch (InterruptedException ex) { + ex.printStackTrace(); + } + + TEST_PROPS.setProperty(APITEST, "expireHttpSessionxrfTest"); + TEST_PROPS.setProperty(USE_SAVED_STATE, "true"); + invoke(); + } + + /* + * @testName: invalidateHttpSessionTest + * + * @assertion_ids: Servlet:JAVADOC:566; Servlet:JAVADOC:565; Servlet:SPEC:202; + * Servlet:JAVADOC:496; Servlet:JAVADOC:568; + * + * @test_Strategy: 1. Client sends request to TestServlet which - creates a + * session using request.getSession(true) Client captures the JSESSIONID + * returned in the response. + * + * 2. Client sends a request(including JSESSIONID) to the servlet. The servlet + * tries to resume the session, then invalidate the session by calling + * Session.invalidate(). Verify that session is invalidated + */ + @Test + public void invalidateHttpSessionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getNewSession"); + TEST_PROPS.setProperty(SAVE_STATE, "true"); + invoke(); + + TEST_PROPS.setProperty(APITEST, "invalidateSessionTest"); + TEST_PROPS.setProperty(USE_SAVED_STATE, "true"); + invoke(); + } + + /* + * @testName: invalidateHttpSessionxTest + * + * @assertion_ids: Servlet:JAVADOC:566; Servlet:JAVADOC:565; Servlet:SPEC:202; + * Servlet:JAVADOC:496; Servlet:JAVADOC:568; + * + * @test_Strategy: 1. Client sends request to TestServlet which - send request + * to a second servlet using RequestDispatcher - which creates a session using + * request.getSession(true) Client captures the JSESSIONID returned in the + * response. + * + * 2. Client sends a request with JSESSIONID to the first servlet. The first + * servlet invoke the second servlet using RequestDispatcher, The second + * servlet invalidate the session by calling Session.invalidate(). Verify that + * session is invalidated + */ + @Test + public void invalidateHttpSessionxTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getNewSessionx"); + TEST_PROPS.setProperty(SAVE_STATE, "true"); + invoke(); + + TEST_PROPS.setProperty(APITEST, "invalidateSessionxTest"); + TEST_PROPS.setProperty(USE_SAVED_STATE, "true"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionx/application.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionx/application.xml new file mode 100644 index 0000000000..31327908d1 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionx/application.xml @@ -0,0 +1,35 @@ + + + + +Application description +servlet_spec_crosscontext + + +servlet_spec_crosscontext1_web.war +servlet_spec_crosscontext1_web + + + + +servlet_spec_crosscontext2_web.war +servlet_spec_crosscontext2_web + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionx/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionx/build.xml new file mode 100644 index 0000000000..ffaf7ccb50 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionx/build.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionx/servlet_jsh_httpsessionx2_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionx/servlet_jsh_httpsessionx2_web.xml new file mode 100644 index 0000000000..2011f16795 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionx/servlet_jsh_httpsessionx2_web.xml @@ -0,0 +1,57 @@ + + + + + SerJaxSerHttpSessionx2 + + setMaxInterval + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionx.SetMaxInterval + + + getNewSession + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionx.GetNewSession + + + invalidateHttpSession + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionx.InvalidateHttpSession + + + expireHttpSession + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionx.ExpireHttpSession + + + setMaxInterval + /setMaxInterval + + + invalidateHttpSession + /invalidateHttpSession + + + getNewSession + /getNewSession + + + expireHttpSession + /expireHttpSession + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionx/servlet_jsh_httpsessionx_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionx/servlet_jsh_httpsessionx_web.xml new file mode 100644 index 0000000000..f1dcb2ec4d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpsessionx/servlet_jsh_httpsessionx_web.xml @@ -0,0 +1,33 @@ + + + + + SerJaxSerHttpHttpSession + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionx.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpupgradehandler/TCKHttpUpgradeHandler.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpupgradehandler/TCKHttpUpgradeHandler.java new file mode 100644 index 0000000000..0ee26ebf10 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpupgradehandler/TCKHttpUpgradeHandler.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpupgradehandler; + +import jakarta.servlet.ServletInputStream; +import jakarta.servlet.ServletOutputStream; +import jakarta.servlet.http.HttpUpgradeHandler; +import jakarta.servlet.http.WebConnection; + +public class TCKHttpUpgradeHandler implements HttpUpgradeHandler { + + private String delimiter = "/"; + + public TCKHttpUpgradeHandler() { + } + + public void init(WebConnection wc) { + try { + ServletInputStream input = wc.getInputStream(); + ServletOutputStream output = wc.getOutputStream(); + TCKReadListener readListener = new TCKReadListener(delimiter, input, + output); + input.setReadListener(readListener); + output.println("===============TCKHttpUpgradeHandler.init"); + output.flush(); + } catch (Exception ex) { + throw new RuntimeException(ex); + } + } + + public void destroy() { + System.out.println("===============destroy"); + } + + public void setDelimiter(String delimiter) { + System.out.print("=============== setDelimiter"); + this.delimiter = delimiter; + } + + public String getDelimiter() { + System.out.print("=============== getDelimiter"); + + return delimiter; + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpupgradehandler/TCKReadListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpupgradehandler/TCKReadListener.java new file mode 100644 index 0000000000..8e54a2d4bc --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpupgradehandler/TCKReadListener.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpupgradehandler; + +import jakarta.servlet.ReadListener; +import jakarta.servlet.ServletInputStream; +import jakarta.servlet.ServletOutputStream; + +public class TCKReadListener implements ReadListener { + + private ServletInputStream input = null; + + private ServletOutputStream output = null; + + private String delimiter = null; + + TCKReadListener(String del, ServletInputStream in, ServletOutputStream out) { + input = in; + output = out; + delimiter = del; + } + + public void onDataAvailable() { + try { + output.println("=onDataAvailable"); + StringBuilder sb = new StringBuilder(); + int len = -1; + byte b[] = new byte[1024]; + while (input.isReady() && (len = input.read(b)) != -1) { + String data = new String(b, 0, len); + sb.append(data); + } + output.println(delimiter + sb.toString()); + output.flush(); + } catch (Exception ex) { + throw new IllegalStateException(ex); + } + } + + public void onAllDataRead() { + try { + output.println("=onAllDataRead"); + output.close(); + } catch (Exception ex) { + throw new IllegalStateException(ex); + } + } + + public void onError(final Throwable t) { + t.printStackTrace(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpupgradehandler/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpupgradehandler/TestServlet.java new file mode 100644 index 0000000000..86e8742a4f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpupgradehandler/TestServlet.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpupgradehandler; + +import java.io.IOException; + +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +@WebServlet(value = "/TestServlet") +public class TestServlet extends HttpServlet { + + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + if (request.getHeader("Upgrade") != null) { + response.setStatus(101); + response.setHeader("Upgrade", "YES"); + response.setHeader("Connection", "Upgrade"); + TCKHttpUpgradeHandler handler = request + .upgrade(TCKHttpUpgradeHandler.class); + handler.setDelimiter("/"); + } else { + response.getWriter().println("No upgrade"); + response.getWriter().println("End of Test"); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpupgradehandler/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpupgradehandler/URLClient.java new file mode 100644 index 0000000000..a28995a5e5 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpupgradehandler/URLClient.java @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. + * 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 + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpupgradehandler; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.Socket; +import java.net.URL; + +public class URLClient extends AbstractUrlClient { + + private static final String CRLF = "\r\n"; + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_jsh_upgradehandler_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TCKHttpUpgradeHandler.class, TCKReadListener.class, TestServlet.class); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * servlet_async_wait; + */ + /* Run test */ + /* + * @testName: upgradeTest + * + * @assertion_ids: Servlet:JAVADOC:905; Servlet:JAVADOC:909; + * Servlet:JAVADOC:911; Servlet:JAVADOC:923; Servlet:JAVADOC:925; + * Servlet:JAVADOC:930; Servlet:JAVADOC:937; + * + * @test_Strategy: Create a Servlet TestServlet; From Client, sends upgrade + * request with two batch of messages to the Servlet; Servlet upgrade the + * request accordingly; Create a ReadListener; Verify all message received; + * Verify UpgradeHandler accordingly Verify ReadListener works accordingly + */ + @Test + public void upgradeTest() throws Exception { + Boolean passed1 = false; + Boolean passed2 = false; + Boolean passed3 = false; + String EXPECTED_RESPONSE1 = "TCKHttpUpgradeHandler.init"; + String EXPECTED_RESPONSE2 = "onDataAvailable|Hello"; + String EXPECTED_RESPONSE3 = "onDataAvailable|World"; + + String requestUrl = getContextRoot() + "/" + getServletName() + " HTTP/1.1"; + + URL url = getURL("http", _hostname, _port, requestUrl.substring(1)); + try (Socket s = new Socket(_hostname, _port); + OutputStream output = s.getOutputStream(); + InputStream input = s.getInputStream()) { + + + StringBuilder reqStr = new StringBuilder("POST " + + url.toExternalForm().replace("http://", "").replace(_hostname, "") + .replace(":" + _port, "") + + CRLF); + reqStr.append("User-Agent: Java/1.6.0_33" + CRLF); + reqStr.append("Host: ").append(_hostname).append(":").append(_port).append(CRLF); + reqStr + .append("Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2" + + CRLF); + reqStr.append("Upgrade: YES" + CRLF); + reqStr.append("Connection: Upgrade" + CRLF); + reqStr.append("Content-type: application/x-www-form-urlencoded" + CRLF); + reqStr.append(CRLF); + + logger.debug("REQUEST========= {}", reqStr); + output.write(reqStr.toString().getBytes()); + + logger.debug("Writing first chunk"); + writeChunk(output, "Hello"); + + logger.debug("Writing second chunk"); + writeChunk(output, "World"); + + logger.debug("Consuming the response from the server"); + + // Consume the response from the server + + int len = -1; + byte[] b = new byte[1024]; + boolean receivedFirstMessage = false; + boolean receivedSecondMessage = false; + boolean receivedThirdMessage = false; + StringBuilder sb = new StringBuilder(); + while ((len = input.read(b)) != -1) { + String line = new String(b, 0, len); + sb.append(line); + logger.debug("==============Read from server: {} {} {}", CRLF, sb, CRLF); + if (passed1 = ServletTestUtil.compareString(EXPECTED_RESPONSE1, sb.toString())) { + logger.debug("==============Received first expected response!"); + receivedFirstMessage = true; + } + if (passed2 = ServletTestUtil.compareString(EXPECTED_RESPONSE2, sb.toString())) { + logger.debug("==============Received second expected response!"); + receivedSecondMessage = true; + } + if (passed3 = ServletTestUtil.compareString(EXPECTED_RESPONSE3, sb.toString())) { + logger.debug("==============Received third expected response!"); + receivedThirdMessage = true; + } + logger.debug("receivedFirstMessage : {}", receivedFirstMessage); + logger.debug("receivedSecondMessage : {}", receivedSecondMessage); + logger.debug("receivedThirdMessage : {}", receivedThirdMessage); + if (receivedFirstMessage && receivedSecondMessage && receivedThirdMessage) { + break; + } + } + } catch (Exception ex2) { + logger.error("exception caught: " + ex2.getMessage(), ex2); + } + + + if (!passed1 || !passed2 || !passed3) { + throw new Exception("Test Failed. "); + } + } + + private static void writeChunk(OutputStream out, String data) + throws IOException { + if (data != null) { + out.write(data.getBytes()); + } + out.flush(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpupgradehandler/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpupgradehandler/build.xml new file mode 100644 index 0000000000..358415e3bb --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/httpupgradehandler/build.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/part/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/part/TestServlet.java new file mode 100644 index 0000000000..0e7c0ae970 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/part/TestServlet.java @@ -0,0 +1,191 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.part; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.util.Collection; + +import com.sun.ts.tests.servlet.common.servlets.HttpTCKServlet; + +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.MultipartConfig; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.Part; + +@WebServlet(value = "/TestServlet") +@MultipartConfig(maxFileSize = 200) +public class TestServlet extends HttpTCKServlet { + + public void getPartTest(HttpServletRequest request, + HttpServletResponse response) throws IOException, ServletException { + PrintWriter out = response.getWriter(); + response.setContentType("text/html"); + + // Do getParameter first, to test if it works if getParts not called. + out.write("getParameter(\"xyz\"): " + request.getParameter("xyz")); + out.write("\n\n"); + + Collection parts = request.getParts(); + for (Part p : parts) { + out.write("Part name: " + p.getName() + "\n"); + out.write("Submitted File Name: " + p.getSubmittedFileName() + "\n"); + out.write("Size: " + p.getSize() + "\n"); + out.write("Content Type: " + p.getContentType() + "\n"); + out.write("Header Names:"); + for (String name : p.getHeaderNames()) { + out.write(" " + name); + } + out.write("\n"); + out.write("getPart(String) test=" + (p == request.getPart(p.getName()))); + out.write("\n"); + } + + out.flush(); + } + + public void getPartTest1(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter out = response.getWriter(); + response.setContentType("text/html"); + + try { + request.getPart("xyz"); + out.write("Expected ServletException not thrown"); + } catch (ServletException ioex) { + out.write("Expected ServletException thrown"); + } + out.write("\n"); + + out.flush(); + } + + public void getPartsTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter out = response.getWriter(); + response.setContentType("text/html"); + + try { + request.getParts(); + out.write("Expected ServletException not thrown"); + } catch (ServletException ioex) { + out.write("Expected ServletException thrown"); + } + out.write("\n"); + + out.flush(); + } + + public void getPartsTest1(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter out = response.getWriter(); + response.setContentType("text/html"); + + // Do getParameter first, to test if it works if getParts not called. + out.write("getParameter(\"xyz\"): " + request.getParameter("xyz")); + out.write("\n\n"); + + Collection parts = request.getParts(); + for (Part p : parts) { + out.write("Part name: " + p.getName() + "\n"); + out.write("Submitted File Name: " + p.getSubmittedFileName() + "\n"); + out.write("Size: " + p.getSize() + "\n"); + out.write("Content Type: " + p.getContentType() + "\n"); + out.write("Header Names:"); + for (String name : p.getHeaderNames()) { + out.write(" " + name); + } + out.write("\n"); + out.write("getPart(String) test=" + (p == request.getPart(p.getName()))); + out.write("\n"); + } + + out.flush(); + } + + public void getHeaderTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter out = response.getWriter(); + response.setContentType("text/html"); + + Collection parts = request.getParts(); + for (Part p : parts) { + out.write("Part name: " + p.getName() + "\n"); + out.write("Header Names:"); + for (String name : p.getHeaderNames()) { + out.write(" " + name + ": " + p.getHeader(name)); + out.write("\n"); + } + String name = "TCKDummyNameNonExistant"; + out.write(" " + name + ": " + p.getHeader(name)); + } + out.flush(); + } + + public void getHeadersTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter out = response.getWriter(); + response.setContentType("text/html"); + + Collection parts = request.getParts(); + for (Part p : parts) { + out.write("Part name: " + p.getName() + "\n"); + out.write("Header Names:"); + for (String name : p.getHeaderNames()) { + out.write(" " + name + ": "); + for (Object header : p.getHeaders(name)) { + out.write(header.toString()); + } + out.write("\n"); + } + String name = "TCKDummyNameNonExistant"; + out.write(" " + name + ": " + p.getHeaders(name).size()); + out.write("\n"); + } + out.flush(); + } + + public void getInputStreamTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter out = response.getWriter(); + response.setContentType("text/html"); + + Collection parts = request.getParts(); + out.write("Parts size=" + parts.size()); + out.write("\n"); + for (Part p : parts) { + out.write("Part name: " + p.getName() + "\n"); + InputStream is = p.getInputStream(); + BufferedReader bis = new BufferedReader(new InputStreamReader(is)); + + String line = null; + while ((line = bis.readLine()) != null) { + out.write(line); + out.write("\n"); + } + } + out.flush(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/part/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/part/URLClient.java new file mode 100644 index 0000000000..3db5d2b730 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/part/URLClient.java @@ -0,0 +1,736 @@ +/* + * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. + * 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.part; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.BufferedReader; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.net.MalformedURLException; +import java.net.Socket; +import java.net.URL; + +public class URLClient extends AbstractUrlClient { + + private static final String CRLF = "\r\n"; + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "part.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestServlet.class); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: getPartTest + * + * @assertion_ids: Servlet:JAVADOC:754; Servlet:JAVADOC:757; + * Servlet:JAVADOC:787; Servlet:JAVADOC:789; Servlet:JAVADOC:793; + * Servlet:JAVADOC:794; Servlet:JAVADOC:955; + * + * @test_Strategy: Create a Servlet TestServlet; From client, send multi-part + * form without file Verify that the data is received correctly Verify all + * relevant API works correctly + */ + @Test + public void getPartTest() throws Exception { + String testname = "getPartTest"; + boolean passed = true; + String EXPECTED_RESPONSE = "getParameter(\"xyz\"): 1234567abcdefg" + + "|Part name: xyz|Submitted File Name: null|Size: 14|Content Type: text/plain|Header Names: content-disposition content-type" + + "|getPart(String) test=true"; + + StringBuilder test_log = new StringBuilder(); + + byte[] data; + StringBuilder header = new StringBuilder(); + + String requestUrl = getContextRoot() + "/" + getServletName() + "?testname=" + + testname + " HTTP/1.1"; + + URL url; + try { + url = getURL("http", _hostname, _port, requestUrl.substring(1)); + logger.debug("url: {}", url.toExternalForm()); + } catch (MalformedURLException ex) { + passed = false; + throw new Exception("EXception getting URL " + requestUrl + " with host " + + _hostname + " at port " + _port, ex); + } + + + try (ByteArrayOutputStream ba = new ByteArrayOutputStream()) { + // First compose the post request data + + addFile(ba, "xyz", null, "1234567abcdefg"); + ba.write("\r\n--AaB03x--\r\n".getBytes()); + + data = ba.toByteArray(); + + // Compose the post request header + header.append("POST ").append(url.toExternalForm().replace("http://", "") + .replace(_hostname, "").replace(":" + _port, "")) + .append(CRLF); + header.append("Host: " + _hostname + "\r\n"); + header.append("Connection: close\r\n"); + header.append("Content-Type: multipart/form-data; boundary=AaB03x\r\n"); + header.append("Content-Length: " + data.length + "\r\n\r\n"); + logger.debug("Header: {}", header); + } catch (IOException ex) { + passed = false; + throw new Exception("Exception creating data", ex); + } + + try (Socket sock = new Socket(_hostname, _port); + InputStream is = sock.getInputStream(); + OutputStream os = sock.getOutputStream(); + BufferedReader bis = new BufferedReader(new InputStreamReader(is))) { + + os.write(header.toString().getBytes()); + os.write(data); + test_log.append("Data sent"); + + String line = null; + while ((line = bis.readLine()) != null) { + test_log.append("Received: " + line + CRLF); + + } + } catch (IOException ex) { + passed = false; + throw new Exception("Exception reading data", ex); + } + + if (!ServletTestUtil.compareString(EXPECTED_RESPONSE, + test_log.toString())) { + passed = false; + } + + logger.debug("test_log: {}", test_log); + if (!passed) { + throw new Exception("Test failed due to incorrect response"); + } + } + + /* + * @testName: getPartTest1 + * + * @assertion_ids: Servlet:JAVADOC:756; + * + * @test_Strategy: Create a Servlet TestServlet; From client, send a + * non-multi-part form data request with a form data Verify + * HttpServletRequest.getPart(String name) throw ServletException + */ + @Test + public void getPartTest1() throws Exception { + String testname = "getPartTest1"; + Boolean passed = true; + String EXPECTED_RESPONSE = "Expected ServletException thrown"; + + StringBuilder test_log = new StringBuilder(); + + byte[] data; + StringBuilder header = new StringBuilder(); + + String requestUrl = getContextRoot() + "/" + getServletName() + "?testname=" + + testname + " HTTP/1.1"; + URL url = null; + + try { + url = getURL("http", _hostname, _port, requestUrl.substring(1)); + logger.debug("url: {}", url.toExternalForm()); + } catch (MalformedURLException ex) { + passed = false; + throw new Exception("EXception getting URL " + requestUrl + " with host " + + _hostname + " at port " + _port, ex); + } + + + try (ByteArrayOutputStream ba = new ByteArrayOutputStream()) { + // First compose the post request data + + addFile(ba, "xyz", null, "1234567abcdefg"); + ba.write("\r\n--AaB03x--\r\n".getBytes()); + logger.debug("Content: {}", ba); + + data = ba.toByteArray(); + + // Compose the post request header + header.append("POST ").append(url.toExternalForm().replace("http://", "") + .replace(_hostname, "").replace(":" + _port, "")) + .append(CRLF); + header.append("Host: " + _hostname + "\r\n"); + header.append("Connection: close\r\n"); + header.append("Content-Type: text/plain; boundary=AaB03x\r\n"); + header.append("Content-Length: " + data.length + "\r\n\r\n"); + logger.debug("Header: {}", header); + } catch (IOException ex) { + passed = false; + throw new Exception("Exception creating data", ex); + } + + try (Socket sock = new Socket(_hostname, _port); + OutputStream os = sock.getOutputStream(); + InputStream is = sock.getInputStream(); + BufferedReader bis = new BufferedReader(new InputStreamReader(is))) { + + os.write(header.toString().getBytes()); + os.write(data); + test_log.append("Data sent"); + + String line = null; + while ((line = bis.readLine()) != null) { + test_log.append("Received: " + line + CRLF); + + } + } catch (IOException ex) { + passed = false; + throw new Exception("Exception reading data", ex); + } + + if (!ServletTestUtil.compareString(EXPECTED_RESPONSE, + test_log.toString())) { + passed = false; + } + + logger.debug("test_log: ", test_log); + if (!passed) { + throw new Exception("Test failed due to incorrect response"); + } + } + + /* + * @testName: getPartsTest + * + * @assertion_ids: Servlet:JAVADOC:759; + * + * @test_Strategy: Create a Servlet TestServlet; From client, send a + * non-multi-part form data request with a few form data Verify + * HttpServletRequest.getParts() throw ServletException + */ + @Test + public void getPartsTest() throws Exception { + String testname = "getPartsTest"; + Boolean passed = true; + String EXPECTED_RESPONSE = "Expected ServletException thrown"; + + StringBuilder test_log = new StringBuilder(); + byte[] data; + StringBuilder header = new StringBuilder(); + + String requestUrl = getContextRoot() + "/" + getServletName() + "?testname=" + + testname + " HTTP/1.1"; + URL url = null; + + try { + url = getURL("http", _hostname, _port, requestUrl.substring(1)); + logger.debug("url: {}", url); + } catch (MalformedURLException ex) { + passed = false; + throw new Exception("EXception getting URL " + requestUrl + " with host " + + _hostname + " at port " + _port, ex); + } + + try { + // First compose the post request data + ByteArrayOutputStream ba = new ByteArrayOutputStream(); + + addFile(ba, "myFile", "test.txt", null); + ba.write("\r\n".getBytes()); + addFile(ba, "myFile2", "test2.txt", null); + ba.write("\r\n".getBytes()); + addFile(ba, "xyz", null, "1234567abcdefg"); + ba.write("\r\n--AaB03x--\r\n".getBytes()); + + logger.debug("Content: {}", ba); + + data = ba.toByteArray(); + + // Compose the post request header + header.append("POST ").append(url.toExternalForm().replace("http://", "") + .replace(_hostname, "").replace(":" + Integer.toString(_port), "")) + .append(CRLF); + header.append("Host: " + _hostname + "\r\n"); + header.append("Connection: close\r\n"); + header.append("Content-Type: text/plain; boundary=AaB03x\r\n"); + header.append("Content-Length: " + data.length + "\r\n\r\n"); + logger.debug(" {}", header); + } catch (IOException ex) { + passed = false; + throw new Exception("Exception creating data", ex); + } + + try (Socket sock = new Socket(_hostname, _port); + OutputStream os = sock.getOutputStream(); + InputStream is = sock.getInputStream(); + BufferedReader bis = new BufferedReader(new InputStreamReader(is))) { + + os.write(header.toString().getBytes()); + os.write(data); + test_log.append("Data sent"); + + String line = null; + while ((line = bis.readLine()) != null) { + test_log.append("Received: " + line + CRLF); + + } + } catch (IOException ex) { + passed = false; + throw new Exception("Exception reading data", ex); + } + + if (!ServletTestUtil.compareString(EXPECTED_RESPONSE, + test_log.toString())) { + passed = false; + } + + logger.debug("test_log: {}", test_log); + if (!passed) { + throw new Exception("Test failed due to incorrect response"); + } + } + + /* + * @testName: getPartsTest1 + * + * @assertion_ids: Servlet:JAVADOC:754; Servlet:JAVADOC:757; + * Servlet:JAVADOC:787; Servlet:JAVADOC:789; Servlet:JAVADOC:793; + * Servlet:JAVADOC:794; Servlet:JAVADOC:955; + * + * @test_Strategy: Create a Servlet TestServlet; From client, send multi-part + * form with several parts, with and without file Verify that the data is + * received correctly Verify all relevant API works correctly + */ + @Test + public void getPartsTest1() throws Exception { + String testname = "getPartsTest1"; + + Boolean passed = true; + String EXPECTED_RESPONSE = "getParameter(\"xyz\"): 1234567abcdefg" + + "|Part name: myFile|Submitted File Name: test.txt|Size: 36|Content Type: text/plain|Header Names: content-disposition content-type" + + "|Part name: myFile2|Submitted File Name: test2.txt|Size: 37|Content Type: text/plain|Header Names: content-disposition content-type" + + "|Part name: xyz|Submitted File Name: null|Size: 14|Content Type: text/plain|Header Names: content-disposition content-type"; + + StringBuilder test_log = new StringBuilder(); + + byte[] data; + StringBuilder header = new StringBuilder(); + + String requestUrl = getContextRoot() + "/" + getServletName() + "?testname=" + + testname + " HTTP/1.1"; + URL url = null; + + try { + url = getURL("http", _hostname, _port, requestUrl.substring(1)); + logger.debug("url: {}", url); + } catch (MalformedURLException ex) { + passed = false; + throw new Exception("EXception getting URL " + requestUrl + " with host " + + _hostname + " at port " + _port, ex); + } + + + try (ByteArrayOutputStream ba = new ByteArrayOutputStream()) { + // First compose the post request data + + addFile(ba, "myFile", "test.txt", null); + logger.debug("first file: {}", ba); + ba.write("\r\n".getBytes()); + addFile(ba, "myFile2", "test2.txt", null); + ba.write("\r\n".getBytes()); + logger.debug("second file: {}", ba); + addFile(ba, "xyz", null, "1234567abcdefg"); + logger.debug("third: {}", ba); + ba.write("\r\n--AaB03x--\r\n".getBytes()); + + data = ba.toByteArray(); + + // Compose the post request header + header.append("POST ").append(url.toExternalForm().replace("http://", "") + .replace(_hostname, "").replace(":" + Integer.toString(_port), "")) + .append(CRLF); + header.append("Host: " + _hostname + "\r\n"); + header.append("Connection: close\r\n"); + header.append("Content-Type: multipart/form-data; boundary=AaB03x\r\n"); + header.append("Content-Length: " + data.length + "\r\n\r\n"); + logger.debug("Header: {}", header); + } catch (IOException ex) { + passed = false; + throw new Exception("Exception creating data", ex); + } + + try (Socket sock = new Socket(_hostname, _port); + InputStream is = sock.getInputStream(); + OutputStream os = sock.getOutputStream(); + BufferedReader bis = new BufferedReader(new InputStreamReader(is))){ + + os.write(header.toString().getBytes()); + os.write(data); + + String line = null; + while ((line = bis.readLine()) != null) { + test_log.append("Received: " + line + CRLF); + + } + } catch (IOException ex) { + passed = false; + throw new Exception("Exception reading data", ex); + } + + if (!ServletTestUtil.compareString(EXPECTED_RESPONSE, + test_log.toString())) { + passed = false; + } + + logger.debug("test_log: {}", test_log); + if (!passed) { + throw new Exception("Test failed due to incorrect response"); + } + } + + /* + * @testName: getHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:788; + * + * @test_Strategy: Create a Servlet TestServlet; From client, send multi-part + * form with several parts, with and without file Verify that + * Part.getHeader(String) works correctly + */ + @Test + public void getHeaderTest() throws Exception { + String testname = "getHeaderTest"; + + Boolean passed = true; + String EXPECTED_RESPONSE = "Part name: myFile|content-disposition:|form-data;|name=\"myFile\";|filename=\"test.txt\"|content-type: text/plain" + + "|TCKDummyNameNonExistant: null" + + "|Part name: myFile2|content-disposition:|form-data;|name=\"myFile2\";|filename=\"test2.txt\"|content-type: text/plain" + + "|TCKDummyNameNonExistant: null" + + "|Part name: xyz|content-disposition:|form-data;|name=\"xyz\"|content-type: text/plain" + + "|TCKDummyNameNonExistant: null"; + + StringBuilder test_log = new StringBuilder(); + + byte[] data; + StringBuilder header = new StringBuilder(); + + String requestUrl = getContextRoot() + "/" + getServletName() + "?testname=" + + testname + " HTTP/1.1"; + URL url = null; + + try { + url = getURL("http", _hostname, _port, requestUrl.substring(1)); + logger.debug("url: {}", url); + } catch (MalformedURLException ex) { + passed = false; + throw new Exception("EXception getting URL " + requestUrl + " with host " + + _hostname + " at port " + _port, ex); + } + + try (ByteArrayOutputStream ba = new ByteArrayOutputStream()) { + // First compose the post request data + + addFile(ba, "myFile", "test.txt", null); + ba.write("\r\n".getBytes()); + addFile(ba, "myFile2", "test2.txt", null); + ba.write("\r\n".getBytes()); + addFile(ba, "xyz", null, "1234567abcdefg"); + ba.write("\r\n--AaB03x--\r\n".getBytes()); + + data = ba.toByteArray(); + + // Compose the post request header + header.append("POST ").append(url.toExternalForm().replace("http://", "") + .replace(_hostname, "").replace(":" + _port, "")) + .append(CRLF); + header.append("Host: " + _hostname + "\r\n"); + header.append("Connection: close\r\n"); + header.append("Content-Type: multipart/form-data; boundary=AaB03x\r\n"); + header.append("Content-Length: " + data.length + "\r\n\r\n"); + logger.debug("Header: {}", header); + } catch (IOException ex) { + passed = false; + throw new Exception("Exception creating data", ex); + } + + try (Socket sock = new Socket(_hostname, _port); + InputStream is = sock.getInputStream(); + OutputStream os = sock.getOutputStream(); + BufferedReader bis = new BufferedReader(new InputStreamReader(is))) { + + os.write(header.toString().getBytes()); + os.write(data); + + String line = null; + while ((line = bis.readLine()) != null) { + test_log.append("Received: " + line + CRLF); + + } + } catch (IOException ex) { + passed = false; + throw new Exception("Exception reading data", ex); + } + + if (!ServletTestUtil.compareString(EXPECTED_RESPONSE, + test_log.toString())) { + passed = false; + } + + logger.debug("test_log: {}", test_log); + if (!passed) { + throw new Exception("Test failed due to incorrect response"); + } + } + + /* + * @testName: getHeadersTest + * + * @assertion_ids: Servlet:JAVADOC:790; + * + * @test_Strategy: Create a Servlet TestServlet; From client, send multi-part + * form with several parts, with and without file Verify that + * Part.getHeaders(String) works correctly + */ + @Test + public void getHeadersTest() throws Exception { + String testname = "getHeadersTest"; + + Boolean passed = true; + String EXPECTED_RESPONSE = "Part name: myFile|content-disposition:|form-data;|name=\"myFile\";|filename=\"test.txt\"|content-type: text/plain" + + "|TCKDummyNameNonExistant: 0" + + "|Part name: myFile2|content-disposition:|form-data;|name=\"myFile2\";|filename=\"test2.txt\"|content-type: text/plain" + + "|TCKDummyNameNonExistant: 0" + + "|Part name: xyz|content-disposition:|form-data;|name=\"xyz\"|content-type: text/plain" + + "|TCKDummyNameNonExistant: 0"; + + StringBuilder test_log = new StringBuilder(); + + byte[] data; + StringBuilder header = new StringBuilder(); + + String requestUrl = getContextRoot() + "/" + getServletName() + "?testname=" + + testname + " HTTP/1.1"; + URL url = null; + + try { + url = getURL("http", _hostname, _port, requestUrl.substring(1)); + logger.debug("url: {}", url); + } catch (MalformedURLException ex) { + passed = false; + throw new Exception("EXception getting URL " + requestUrl + " with host " + + _hostname + " at port " + _port, ex); + } + + try (Socket sock = new Socket(_hostname, _port)) { + + try (ByteArrayOutputStream ba = new ByteArrayOutputStream()) { + + addFile(ba, "myFile", "test.txt", null); + ba.write("\r\n".getBytes()); + addFile(ba, "myFile2", "test2.txt", null); + ba.write("\r\n".getBytes()); + addFile(ba, "xyz", null, "1234567abcdefg"); + ba.write("\r\n--AaB03x--\r\n".getBytes()); + + data = ba.toByteArray(); + + // Compose the post request header + header.append("POST ").append(url.toExternalForm().replace("http://", "") + .replace(_hostname, "").replace(":" + Integer.toString(_port), "")) + .append(CRLF); + header.append("Host: " + _hostname + "\r\n"); + header.append("Connection: close\r\n"); + header.append("Content-Type: multipart/form-data; boundary=AaB03x\r\n"); + header.append("Content-Length: " + ba.size() + "\r\n\r\n"); + logger.debug("Header: {}", header); + } catch (IOException ex) { + passed = false; + throw new Exception("Exception creating data", ex); + } + + try (InputStream is = sock.getInputStream(); + OutputStream os = sock.getOutputStream(); + BufferedReader bis = new BufferedReader(new InputStreamReader(is))){ + + os.write(header.toString().getBytes()); + os.write(data); + + String line = null; + while ((line = bis.readLine()) != null) { + test_log.append("Received: " + line + CRLF); + + } + } catch (IOException ex) { + passed = false; + throw new Exception("Exception reading data", ex); + } + + } catch (IOException ex) { + passed = false; + throw new Exception("EXception getting Socket " + " with host " + _hostname + + " at port " + _port, ex); + } + + if (!ServletTestUtil.compareString(EXPECTED_RESPONSE, + test_log.toString())) { + passed = false; + } + + logger.debug("test_log: {}", test_log); + if (!passed) { + throw new Exception("Test failed due to incorrect response"); + } + } + + /* + * @testName: getInputStreamTest + * + * @assertion_ids: Servlet:JAVADOC:791; + * + * @test_Strategy: Create a Servlet TestServlet; From client, send multi-part + * form with several parts, with and without file Verify that + * Part.getInputStream() works correctly + */ + @Test + public void getInputStreamTest() throws Exception { + String testname = "getInputStreamTest"; + + Boolean passed = true; + String EXPECTED_RESPONSE = "Parts size=1" + "|Part name: myFile" + + "|First line." + "|Second line." + "|Last line."; + + StringBuilder test_log = new StringBuilder(); + + byte[] data; + StringBuilder header = new StringBuilder(); + + String requestUrl = getContextRoot() + "/" + getServletName() + "?testname=" + + testname + " HTTP/1.1"; + URL url = null; + + try { + url = getURL("http", _hostname, _port, requestUrl.substring(1)); + logger.debug("url: {}", url); + } catch (MalformedURLException ex) { + passed = false; + throw new Exception("EXception getting URL " + requestUrl + " with host " + + _hostname + " at port " + _port, ex); + } + + try (ByteArrayOutputStream ba = new ByteArrayOutputStream()) { + // First compose the post request data + + addFile(ba, "myFile", "test.txt", null); + ba.write("\r\n--AaB03x--\r\n".getBytes()); + + data = ba.toByteArray(); + + // Compose the post request header + header.append("POST ").append(url.toExternalForm().replace("http://", "") + .replace(_hostname, "").replace(":" + Integer.toString(_port), "")) + .append(CRLF); + header.append("Host: " + _hostname + "\r\n"); + header.append("Connection: close\r\n"); + header.append("Content-Type: multipart/form-data; boundary=AaB03x\r\n"); + header.append("Content-Length: " + data.length + "\r\n\r\n"); + logger.debug("Header: {}", header); + } catch (IOException ex) { + passed = false; + throw new Exception("Exception creating data", ex); + } + + try (Socket sock = new Socket(_hostname, _port); + OutputStream os = sock.getOutputStream(); + InputStream is = sock.getInputStream(); + BufferedReader bis = new BufferedReader(new InputStreamReader(is))) { + + os.write(header.toString().getBytes()); + os.write(data); + + String line = null; + while ((line = bis.readLine()) != null) { + test_log.append("Received: " + line + CRLF); + + } + } catch (IOException ex) { + passed = false; + throw new Exception("Exception reading data", ex); + } + + if (!ServletTestUtil.compareString(EXPECTED_RESPONSE, + test_log.toString())) { + passed = false; + } + + logger.debug("test_log: {}", test_log); + if (!passed) { + throw new Exception("Test failed due to incorrect response"); + } + } + + void addFile(ByteArrayOutputStream ba, String partname, String filename, + String content) throws IOException { + ba.write("--AaB03x\r\n".getBytes()); + + if (filename != null) { + // Write header + ba.write(("Content-Disposition: form-data; name=\"" + partname + + "\"; filename=\"" + filename + "\"\r\n").getBytes()); + ba.write("Content-Type: text/plain\r\n\r\n".getBytes()); + // Write content of the file + byte[] file1Bytes = URLClient.class.getResource(filename).openStream().readAllBytes(); + //byte[] file1Bytes = Files.readAllBytes(Paths.get(dir, filename)); + ba.write(file1Bytes, 0, file1Bytes.length); + } else { + // Write header + ba.write(("Content-Disposition: form-data; name=\"" + partname + "\"\r\n") + .getBytes()); + ba.write("Content-Type: text/plain\r\n\r\n".getBytes()); + } + + if (content != null) { + // Write content + ba.write(content.getBytes()); + } + } +} \ No newline at end of file diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/part/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/part/build.xml new file mode 100644 index 0000000000..b3224278d4 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/part/build.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/part/test.txt b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/part/test.txt new file mode 100644 index 0000000000..ec66d67923 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/part/test.txt @@ -0,0 +1,3 @@ +First line. +Second line. +Last line. diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/part/test2.txt b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/part/test2.txt new file mode 100644 index 0000000000..44233cd901 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/part/test2.txt @@ -0,0 +1,3 @@ +First line. +Second line. +Third line. diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/part1/TestServletWrapper.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/part1/TestServletWrapper.java new file mode 100644 index 0000000000..7a63998111 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/part1/TestServletWrapper.java @@ -0,0 +1,51 @@ +/* + * 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:$ + */ + +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.part1; + +import java.io.IOException; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.MultipartConfig; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletRequestWrapper; +import jakarta.servlet.http.HttpServletResponse; + +@WebServlet("/TestServletWrapper") +@MultipartConfig(maxFileSize = 200) +public class TestServletWrapper + extends com.sun.ts.tests.servlet.api.jakarta_servlet_http.part.TestServlet { + + public void init(ServletConfig servletConfig) throws ServletException { + super.init(servletConfig); + } + + // Simply validate the default behavior of the RequestWrapper is to delegate + // the call to the wrapped object. + public void service(HttpServletRequest servletRequest, + HttpServletResponse servletResponse) + throws ServletException, IOException { + HttpServletRequestWrapper wrapper = new HttpServletRequestWrapper( + servletRequest); + super.service(wrapper, servletResponse); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/part1/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/part1/URLClient.java new file mode 100644 index 0000000000..ec4f3e48c9 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/part1/URLClient.java @@ -0,0 +1,745 @@ +/* + * Copyright (c) 2013, 2020 Oracle and/or its affiliates and others. + * 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.part1; + +import java.io.BufferedReader; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.net.MalformedURLException; +import java.net.Socket; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Paths; + +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.part.TestServlet; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.common.servlets.HttpTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + private static final String CRLF = "\r\n"; + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "part1.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestServletWrapper.class, TestServlet.class); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: getPartTest + * + * @assertion_ids: Servlet:JAVADOC:767; Servlet:JAVADOC:770; + * Servlet:JAVADOC:787; Servlet:JAVADOC:789; Servlet:JAVADOC:793; + * Servlet:JAVADOC:794; Servlet:JAVADOC:955; + * + * @test_Strategy: Create a Servlet TestServletWrapper that wraps the Request; + * From client, send multi-part form without file Verify that the data is + * received correctly Verify all relevant API works correctly + */ + @Test + public void getPartTest() throws Exception { + String testname = "getPartTest"; + Boolean passed = true; + String EXPECTED_RESPONSE = "getParameter(\"xyz\"): 1234567abcdefg" + + "|Part name: xyz|Submitted File Name: null|Size: 14|Content Type: text/plain|Header Names: content-disposition content-type" + + "|getPart(String) test=true"; + + StringBuilder test_log = new StringBuilder(); + + + byte[] data; + StringBuilder header = new StringBuilder(); + + String requestUrl = getContextRoot() + "/" + getServletName() + "?testname=" + + testname + " HTTP/1.1"; + URL url = null; + + try { + url = getURL("http", _hostname, _port, requestUrl.substring(1)); + logger.debug("url: {}", url.toExternalForm()); + } catch (MalformedURLException ex) { + passed = false; + throw new Exception("EXception getting URL " + requestUrl + " with host " + + _hostname + " at port " + _port, ex); + } + + + try (ByteArrayOutputStream ba = new ByteArrayOutputStream()) { + // First compose the post request data + + addFile(ba, "xyz", null, "1234567abcdefg"); + ba.write("\r\n--AaB03x--\r\n".getBytes()); + + data = ba.toByteArray(); + + // Compose the post request header + header.append("POST ").append(url.toExternalForm().replace("http://", "") + .replace(_hostname, "").replace(":" + Integer.toString(_port), "")) + .append(CRLF); + header.append("Host: " + _hostname + "\r\n"); + header.append("Connection: close\r\n"); + header.append("Content-Type: multipart/form-data; boundary=AaB03x\r\n"); + header.append("Content-Length: " + data.length + "\r\n\r\n"); + logger.debug("Header: {}", header); + } catch (IOException ex) { + passed = false; + throw new Exception("Exception creating data", ex); + } + + try (Socket sock = new Socket(_hostname, _port); + InputStream is = sock.getInputStream(); + OutputStream os = sock.getOutputStream(); + BufferedReader bis = new BufferedReader(new InputStreamReader(is))) { + + os.write(header.toString().getBytes()); + os.write(data); + test_log.append("Data sent"); + + String line = null; + while ((line = bis.readLine()) != null) { + test_log.append("Received: " + line + CRLF); + + } + } catch (IOException ex) { + passed = false; + throw new Exception("Exception reading data", ex); + } + + if (!ServletTestUtil.compareString(EXPECTED_RESPONSE, + test_log.toString())) { + passed = false; + } + + logger.debug("test_log: {}", test_log); + if (!passed) { + throw new Exception("Test failed due to incorrect response"); + } + } + + /* + * @testName: getPartTest1 + * + * @assertion_ids: Servlet:JAVADOC:769; + * + * @test_Strategy: Create a Servlet TestServletWrapper that wraps the Request; + * From client, send a non-multi-part form data request with a form data + * Verify getPart(String name) throw ServletException + */ + @Test + public void getPartTest1() throws Exception { + String testname = "getPartTest1"; + Boolean passed = true; + String EXPECTED_RESPONSE = "Expected ServletException thrown"; + + StringBuilder test_log = new StringBuilder(); + + byte[] data; + StringBuilder header = new StringBuilder(); + + String requestUrl = getContextRoot() + "/" + getServletName() + "?testname=" + + testname + " HTTP/1.1"; + URL url = null; + + try { + url = getURL("http", _hostname, _port, requestUrl.substring(1)); + logger.debug("url: {}", url.toExternalForm()); + } catch (MalformedURLException ex) { + passed = false; + throw new Exception("EXception getting URL " + requestUrl + " with host " + + _hostname + " at port " + _port, ex); + } + + try { + // First compose the post request data + ByteArrayOutputStream ba = new ByteArrayOutputStream(); + + addFile(ba, "xyz", null, "1234567abcdefg"); + ba.write("\r\n--AaB03x--\r\n".getBytes()); + logger.debug("Content: {}", ba); + + data = ba.toByteArray(); + + // Compose the post request header + header.append("POST ").append(url.toExternalForm().replace("http://", "") + .replace(_hostname, "").replace(":" + Integer.toString(_port), "")) + .append(CRLF); + header.append("Host: " + _hostname + "\r\n"); + header.append("Connection: close\r\n"); + header.append("Content-Type: text/plain; boundary=AaB03x\r\n"); + header.append("Content-Length: " + data.length + "\r\n\r\n"); + logger.debug("Header: {}", header); + } catch (IOException ex) { + passed = false; + throw new Exception("Exception creating data", ex); + } + + try (Socket sock = new Socket(_hostname, _port); + InputStream is = sock.getInputStream(); + OutputStream os = sock.getOutputStream(); + BufferedReader bis = new BufferedReader(new InputStreamReader(is))) { + + os.write(header.toString().getBytes()); + os.write(data); + test_log.append("Data sent"); + + String line = null; + while ((line = bis.readLine()) != null) { + test_log.append("Received: " + line + CRLF); + + } + } catch (IOException ex) { + passed = false; + throw new Exception("Exception reading data", ex); + } + + if (!ServletTestUtil.compareString(EXPECTED_RESPONSE, + test_log.toString())) { + passed = false; + } + + logger.debug("test_log: {}", test_log); + if (!passed) { + throw new Exception("Test failed due to incorrect response"); + } + } + + /* + * @testName: getPartsTest + * + * @assertion_ids: Servlet:JAVADOC:772; + * + * @test_Strategy: Create a Servlet TestServletWrapper that wraps the Request; + * From client, send a non-multi-part form data request with a few form data + * Verify getParts() throw ServletException + */ + @Test + public void getPartsTest() throws Exception { + String testname = "getPartsTest"; + Boolean passed = true; + String EXPECTED_RESPONSE = "Expected ServletException thrown"; + + StringBuilder test_log = new StringBuilder(); + + byte[] data; + StringBuilder header = new StringBuilder(); + + String requestUrl = getContextRoot() + "/" + getServletName() + "?testname=" + + testname + " HTTP/1.1"; + URL url; + try { + url = getURL("http", _hostname, _port, requestUrl.substring(1)); + logger.debug("url: {}", url.toExternalForm()); + } catch (MalformedURLException ex) { + passed = false; + throw new Exception("EXception getting URL " + requestUrl + " with host " + + _hostname + " at port " + _port, ex); + } + + + try { + // First compose the post request data + ByteArrayOutputStream ba = new ByteArrayOutputStream(); + + addFile(ba, "myFile", "test.txt", null); + ba.write("\r\n".getBytes()); + addFile(ba, "myFile2", "test2.txt", null); + ba.write("\r\n".getBytes()); + addFile(ba, "xyz", null, "1234567abcdefg"); + ba.write("\r\n--AaB03x--\r\n".getBytes()); + + logger.debug("Content: {}", ba); + + data = ba.toByteArray(); + + // Compose the post request header + header.append("POST ").append(url.toExternalForm().replace("http://", "") + .replace(_hostname, "").replace(":" + Integer.toString(_port), "")) + .append(CRLF); + header.append("Host: " + _hostname + "\r\n"); + header.append("Connection: close\r\n"); + header.append("Content-Type: text/plain; boundary=AaB03x\r\n"); + header.append("Content-Length: " + data.length + "\r\n\r\n"); + logger.debug("Header: {}", header); + } catch (IOException ex) { + passed = false; + throw new Exception("Exception creating data", ex); + } + + try (Socket sock = new Socket(_hostname, _port); + InputStream is = sock.getInputStream(); + OutputStream os = sock.getOutputStream(); + BufferedReader bis = new BufferedReader(new InputStreamReader(is))) { + + os.write(header.toString().getBytes()); + os.write(data); + test_log.append("Data sent"); + + String line = null; + while ((line = bis.readLine()) != null) { + test_log.append("Received: " + line + CRLF); + + } + } catch (IOException ex) { + passed = false; + throw new Exception("Exception reading data", ex); + } + + if (!ServletTestUtil.compareString(EXPECTED_RESPONSE, + test_log.toString())) { + passed = false; + } + + logger.debug("test_log: {}", test_log); + if (!passed) { + throw new Exception("Test failed due to incorrect response"); + } + } + + /* + * @testName: getPartsTest1 + * + * @assertion_ids: Servlet:JAVADOC:767; Servlet:JAVADOC:770; + * Servlet:JAVADOC:787; Servlet:JAVADOC:789; Servlet:JAVADOC:793; + * Servlet:JAVADOC:794; Servlet:JAVADOC:955; + * + * @test_Strategy: Create a Servlet TestServletWrapper that wraps the Request; + * From client, send multi-part form with several parts, with and without file + * Verify that the data is received correctly Verify all relevant API works + * correctly + */ + @Test + public void getPartsTest1() throws Exception { + String testname = "getPartsTest1"; + + Boolean passed = true; + String EXPECTED_RESPONSE = "getParameter(\"xyz\"): 1234567abcdefg" + + "|Part name: myFile|Submitted File Name: test.txt|Size: 36|Content Type: text/plain|Header Names: content-disposition content-type" + + "|Part name: myFile2|Submitted File Name: test2.txt|Size: 37|Content Type: text/plain|Header Names: content-disposition content-type" + + "|Part name: xyz|Submitted File Name: null|Size: 14|Content Type: text/plain|Header Names: content-disposition content-type"; + + StringBuilder test_log = new StringBuilder(); + + byte[] data; + StringBuilder header = new StringBuilder(); + + String requestUrl = getContextRoot() + "/" + getServletName() + "?testname=" + + testname + " HTTP/1.1"; + URL url; + + try { + url = getURL("http", _hostname, _port, requestUrl.substring(1)); + logger.debug("url: {}", url.toExternalForm()); + } catch (MalformedURLException ex) { + passed = false; + throw new Exception("EXception getting URL " + requestUrl + " with host " + + _hostname + " at port " + _port, ex); + } + + + try { + // First compose the post request data + ByteArrayOutputStream ba = new ByteArrayOutputStream(); + + addFile(ba, "myFile", "test.txt", null); + logger.debug("first file: {}", ba); + ba.write("\r\n".getBytes()); + addFile(ba, "myFile2", "test2.txt", null); + ba.write("\r\n".getBytes()); + logger.debug("second file: {}", ba); + addFile(ba, "xyz", null, "1234567abcdefg"); + logger.debug("third: {}", ba); + ba.write("\r\n--AaB03x--\r\n".getBytes()); + + data = ba.toByteArray(); + logger.debug("Data: {}", data); + + // Compose the post request header + header.append("POST ").append(url.toExternalForm().replace("http://", "") + .replace(_hostname, "").replace(":" + Integer.toString(_port), "")) + .append(CRLF); + header.append("Host: " + _hostname + "\r\n"); + header.append("Connection: close\r\n"); + header.append("Content-Type: multipart/form-data; boundary=AaB03x\r\n"); + header.append("Content-Length: " + data.length + "\r\n\r\n"); + logger.debug("Header: {}", header); + } catch (IOException ex) { + passed = false; + throw new Exception("Exception creating data", ex); + } + + try (Socket sock = new Socket(_hostname, _port); + InputStream is = sock.getInputStream(); + OutputStream os = sock.getOutputStream(); + BufferedReader bis = new BufferedReader(new InputStreamReader(is))){ + + os.write(header.toString().getBytes()); + os.write(data); + logger.debug("Data sent: {}", data); + + String line = null; + while ((line = bis.readLine()) != null) { + test_log.append("Received: " + line + CRLF); + + } + } catch (IOException ex) { + passed = false; + throw new Exception("Exception reading data", ex); + } + + if (!ServletTestUtil.compareString(EXPECTED_RESPONSE, + test_log.toString())) { + passed = false; + } + + logger.debug("test_log: {}", test_log); + if (!passed) { + throw new Exception("Test failed due to incorrect response"); + } + } + + /* + * @testName: getHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:788; + * + * @test_Strategy: Create a Servlet TestServletWrapper that wraps the Request; + * From client, send multi-part form with several parts, with and without file + * Verify that Part.getHeader(String) works correctly + */ + @Test + public void getHeaderTest() throws Exception { + String testname = "getHeaderTest"; + + Boolean passed = true; + String EXPECTED_RESPONSE = "Part name: myFile|content-disposition:|form-data;|name=\"myFile\";|filename=\"test.txt\"|content-type: text/plain" + + "|TCKDummyNameNonExistant: null" + + "|Part name: myFile2|content-disposition:|form-data;|name=\"myFile2\";|filename=\"test2.txt\"|content-type: text/plain" + + "|TCKDummyNameNonExistant: null" + + "|Part name: xyz|content-disposition:|form-data;|name=\"xyz\"|content-type: text/plain" + + "|TCKDummyNameNonExistant: null"; + + StringBuilder test_log = new StringBuilder(); + + byte[] data; + StringBuilder header = new StringBuilder(); + + String requestUrl = getContextRoot() + "/" + getServletName() + "?testname=" + + testname + " HTTP/1.1"; + URL url; + + try { + url = getURL("http", _hostname, _port, requestUrl.substring(1)); + logger.debug("url: {}", url.toExternalForm()); + } catch (MalformedURLException ex) { + passed = false; + throw new Exception("EXception getting URL " + requestUrl + " with host " + + _hostname + " at port " + _port, ex); + } + + + try (ByteArrayOutputStream ba = new ByteArrayOutputStream()){ + // First compose the post request data + + addFile(ba, "myFile", "test.txt", null); + ba.write("\r\n".getBytes()); + addFile(ba, "myFile2", "test2.txt", null); + ba.write("\r\n".getBytes()); + addFile(ba, "xyz", null, "1234567abcdefg"); + ba.write("\r\n--AaB03x--\r\n".getBytes()); + + data = ba.toByteArray(); + + // Compose the post request header + header.append("POST ").append(url.toExternalForm().replace("http://", "") + .replace(_hostname, "").replace(":" + Integer.toString(_port), "")) + .append(CRLF); + header.append("Host: " + _hostname + "\r\n"); + header.append("Connection: close\r\n"); + header.append("Content-Type: multipart/form-data; boundary=AaB03x\r\n"); + header.append("Content-Length: " + data.length + "\r\n\r\n"); + logger.debug("Header: {}", header); + } catch (IOException ex) { + passed = false; + throw new Exception("Exception creating data", ex); + } + + try (Socket sock = new Socket(_hostname, _port); + InputStream is = sock.getInputStream(); + OutputStream os = sock.getOutputStream(); + BufferedReader bis = new BufferedReader(new InputStreamReader(is))) { + + os.write(header.toString().getBytes()); + os.write(data); + logger.debug("Data sent: {}", data.toString()); + + String line = null; + while ((line = bis.readLine()) != null) { + test_log.append("Received: " + line + CRLF); + + } + } catch (IOException ex) { + passed = false; + throw new Exception("Exception reading data", ex); + } + + if (!ServletTestUtil.compareString(EXPECTED_RESPONSE, + test_log.toString())) { + passed = false; + } + + logger.debug("test_log: {}", test_log.toString()); + if (!passed) { + throw new Exception("Test failed due to incorrect response"); + } + } + + /* + * @testName: getHeadersTest + * + * @assertion_ids: Servlet:JAVADOC:790; + * + * @test_Strategy: Create a Servlet TestServletWrapper that wraps the Request; + * From client, send multi-part form with several parts, with and without file + * Verify that Part.getHeaders(String) works correctly + */ + @Test + public void getHeadersTest() throws Exception { + String testname = "getHeadersTest"; + + Boolean passed = true; + String EXPECTED_RESPONSE = "Part name: myFile|content-disposition:|form-data;|name=\"myFile\";|filename=\"test.txt\"|content-type: text/plain" + + "|TCKDummyNameNonExistant: 0" + + "|Part name: myFile2|content-disposition:|form-data;|name=\"myFile2\";|filename=\"test2.txt\"|content-type: text/plain" + + "|TCKDummyNameNonExistant: 0" + + "|Part name: xyz|content-disposition:|form-data;|name=\"xyz\"|content-type: text/plain" + + "|TCKDummyNameNonExistant: 0"; + + StringBuilder test_log = new StringBuilder(); + + byte[] data; + StringBuilder header = new StringBuilder(); + + String requestUrl = getContextRoot() + "/" + getServletName() + "?testname=" + + testname + " HTTP/1.1"; + URL url = null; + + try { + url = getURL("http", _hostname, _port, requestUrl.substring(1)); + logger.debug("url: {}", url.toExternalForm()); + } catch (MalformedURLException ex) { + passed = false; + throw new Exception("EXception getting URL " + requestUrl + " with host " + + _hostname + " at port " + _port, ex); + } + + try (ByteArrayOutputStream ba = new ByteArrayOutputStream()) { + // First compose the post request data + + addFile(ba, "myFile", "test.txt", null); + ba.write("\r\n".getBytes()); + addFile(ba, "myFile2", "test2.txt", null); + ba.write("\r\n".getBytes()); + addFile(ba, "xyz", null, "1234567abcdefg"); + ba.write("\r\n--AaB03x--\r\n".getBytes()); + + data = ba.toByteArray(); + + // Compose the post request header + header.append("POST ").append(url.toExternalForm().replace("http://", "") + .replace(_hostname, "").replace(":" + Integer.toString(_port), "")) + .append(CRLF); + header.append("Host: " + _hostname + "\r\n"); + header.append("Connection: close\r\n"); + header.append("Content-Type: multipart/form-data; boundary=AaB03x\r\n"); + header.append("Content-Length: " + data.length + "\r\n\r\n"); + logger.debug("Header: {}", header); + } catch (IOException ex) { + passed = false; + throw new Exception("Exception creating data", ex); + } + + try (Socket sock = new Socket(_hostname, _port); + InputStream is = sock.getInputStream(); + OutputStream os = sock.getOutputStream(); + BufferedReader bis = new BufferedReader(new InputStreamReader(is))) { + + os.write(header.toString().getBytes()); + os.write(data); + logger.debug("Data sent: {}", data.toString()); + + String line = null; + while ((line = bis.readLine()) != null) { + test_log.append("Received: " + line + CRLF); + + } + } catch (IOException ex) { + passed = false; + throw new Exception("Exception reading data", ex); + } + + if (!ServletTestUtil.compareString(EXPECTED_RESPONSE, + test_log.toString())) { + passed = false; + } + + logger.debug("test_log: {}", test_log); + if (!passed) { + throw new Exception("Test failed due to incorrect response"); + } + } + + /* + * @testName: getInputStreamTest + * + * @assertion_ids: Servlet:JAVADOC:791; + * + * @test_Strategy: Create a Servlet TestServletWrapper that wraps the Request; + * From client, send multi-part form with several parts, with and without file + * Verify that Part.getInputStream() works correctly + */ + @Test + public void getInputStreamTest() throws Exception { + String testname = "getInputStreamTest"; + + Boolean passed = true; + String EXPECTED_RESPONSE = "Parts size=1" + "|Part name: myFile" + + "|First line." + "|Second line." + "|Last line."; + + StringBuilder test_log = new StringBuilder(); + + byte[] data; + StringBuilder header = new StringBuilder(); + + String requestUrl = getContextRoot() + "/" + getServletName() + "?testname=" + + testname + " HTTP/1.1"; + URL url = null; + + try { + url = getURL("http", _hostname, _port, requestUrl.substring(1)); + logger.debug("url: {}", url.toExternalForm()); + } catch (MalformedURLException ex) { + passed = false; + throw new Exception("EXception getting URL " + requestUrl + " with host " + + _hostname + " at port " + _port, ex); + } + + + try (ByteArrayOutputStream ba = new ByteArrayOutputStream()) { + // First compose the post request data + + addFile(ba, "myFile", "test.txt", null); + ba.write("\r\n--AaB03x--\r\n".getBytes()); + + data = ba.toByteArray(); + + // Compose the post request header + header.append("POST ").append(url.toExternalForm().replace("http://", "") + .replace(_hostname, "").replace(":" + Integer.toString(_port), "")) + .append(CRLF); + header.append("Host: " + _hostname + "\r\n"); + header.append("Connection: close\r\n"); + header.append("Content-Type: multipart/form-data; boundary=AaB03x\r\n"); + header.append("Content-Length: " + data.length + "\r\n\r\n"); + logger.debug("Header: {}", header); + } catch (IOException ex) { + passed = false; + throw new Exception("Exception creating data", ex); + } + + try (Socket sock = new Socket(_hostname, _port); + InputStream is = sock.getInputStream(); + OutputStream os = sock.getOutputStream(); + BufferedReader bis = new BufferedReader(new InputStreamReader(is))) { + + os.write(header.toString().getBytes()); + os.write(data); + logger.debug("Data sent: {}", data.toString()); + + String line = null; + while ((line = bis.readLine()) != null) { + test_log.append("Received: " + line + CRLF); + + } + } catch (IOException ex) { + passed = false; + throw new Exception("Exception reading data", ex); + } + + if (!ServletTestUtil.compareString(EXPECTED_RESPONSE, + test_log.toString())) { + passed = false; + } + + logger.debug("test_log: {}", test_log); + if (!passed) { + throw new Exception("Test failed due to incorrect response"); + } + } + + void addFile(ByteArrayOutputStream ba, String partname, String filename, + String content) throws IOException { + ba.write("--AaB03x\r\n".getBytes()); + + if (filename != null) { + // Write header + ba.write(("Content-Disposition: form-data; name=\"" + partname + + "\"; filename=\"" + filename + "\"\r\n").getBytes()); + ba.write("Content-Type: text/plain\r\n\r\n".getBytes()); + // Write content of the file + URL url = com.sun.ts.tests.servlet.api.jakarta_servlet_http.part.URLClient.class.getResource(filename); + byte[] file1Bytes = url.openStream().readAllBytes();; + ba.write(file1Bytes, 0, file1Bytes.length); + } else { + // Write header + ba.write(("Content-Disposition: form-data; name=\"" + partname + "\"\r\n") + .getBytes()); + ba.write("Content-Type: text/plain\r\n\r\n".getBytes()); + } + + if (content != null) { + // Write content + ba.write(content.getBytes()); + } + } +} \ No newline at end of file diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/part1/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/part1/build.xml new file mode 100644 index 0000000000..7a3c3b5a8d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/part1/build.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/readlistener/TestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/readlistener/TestListener.java new file mode 100644 index 0000000000..4a52edb186 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/readlistener/TestListener.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.readlistener; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.ReadListener; +import jakarta.servlet.ServletInputStream; +import jakarta.servlet.ServletOutputStream; + +public class TestListener implements ReadListener { + + private ServletInputStream input = null; + + private ServletOutputStream output = null; + + private AsyncContext ac = null; + + TestListener(ServletInputStream in, ServletOutputStream out, AsyncContext c) { + input = in; + output = out; + ac = c; + } + + public void onDataAvailable() { + try { + StringBuilder sb = new StringBuilder(); + output.println("=onDataAvailable"); + int len = -1; + byte b[] = new byte[1024]; + while (input.isReady() && (len = input.read(b)) != -1) { + String data = new String(b, 0, len); + sb.append("=").append(data); + } + output.print(sb.toString()); + } catch (Exception ex) { + throw new IllegalStateException(ex); + } + } + + public void onAllDataRead() { + try { + output.println("=onAllDataRead"); + } catch (Exception ex) { + throw new IllegalStateException(ex); + } finally { + ac.complete(); + } + } + + public void onError(final Throwable t) { + ac.complete(); + t.printStackTrace(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/readlistener/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/readlistener/TestServlet.java new file mode 100644 index 0000000000..b68f4e8513 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/readlistener/TestServlet.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.readlistener; + +import java.io.IOException; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletInputStream; +import jakarta.servlet.ServletOutputStream; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +@WebServlet(value = "/TestServlet", asyncSupported = true) +public class TestServlet extends HttpServlet { + + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + AsyncContext ac = request.startAsync(); + ServletOutputStream output = response.getOutputStream(); + ServletInputStream input = request.getInputStream(); + TestListener readListener = new TestListener(input, output, ac); + input.setReadListener(readListener); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/readlistener/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/readlistener/URLClient.java new file mode 100644 index 0000000000..32461f3142 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/readlistener/URLClient.java @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.readlistener; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.net.HttpURLConnection; +import java.net.URL; + +public class URLClient extends AbstractUrlClient { + + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_jsh_readlistener.war") + .addClasses(TestServlet.class, TestListener.class); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * servlet_async_wait; + */ + /* Run test */ + /* + * @testName: nioInputTest + * + * @assertion_ids: Servlet:SPEC:282; Servlet:SPEC:282.1; Servlet:SPEC:282.2; + * Servlet:SPEC:282.6; Servlet:SPEC:282.7; Servlet:JAVADOC:904; + * Servlet:JAVADOC:905; Servlet:JAVADOC:908; + * Servlet:JAVADOC:909;Servlet:JAVADOC:577; Servlet:JAVADOC:609; + * Servlet:JAVADOC:638; Servlet:JAVADOC:710; + * + * @test_Strategy: Create a Servlet TestServlet which supports async; Create a + * ReadListener; From Client, sends two batch of messages use stream; Verify + * all message received; Verify ReadListener works accordingly + */ + @Test + public void nioInputTest() throws Exception { + int sleepInSeconds = Integer + .parseInt(_props.getProperty("servlet_async_wait").trim()); + boolean passed = true; + + String EXPECTED_RESPONSE = "=onDataAvailable|=Hello|=onDataAvailable|=World" + + "|=onAllDataRead"; + + BufferedReader input = null; + BufferedWriter output = null; + + String requestUrl = getContextRoot() + "/" + getServletName(); + + try { + URL url = getURL("http", _hostname, _port, requestUrl.substring(1)); + + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + logger.debug("Connecting {}", url.toExternalForm()); + conn.setRequestProperty("Content-type", "text/plain; charset=utf-8"); + conn.setChunkedStreamingMode(5); + conn.setRequestMethod("POST"); + conn.setDoOutput(true); + logger.debug(" Header {}", conn); + conn.connect(); + + try { + output = new BufferedWriter( + new OutputStreamWriter(conn.getOutputStream())); + try { + String data = "Hello"; + output.write(data); + output.flush(); + Thread.sleep(sleepInSeconds * 1000); + + data = "World"; + output.write(data); + output.flush(); + output.close(); + } catch (Exception ex) { + passed = false; + logger.error("======= Exception sending message: " + ex.getMessage(), ex); + } + + input = new BufferedReader( + new InputStreamReader(conn.getInputStream())); + String line; + StringBuilder message_received = new StringBuilder(); + + while ((line = input.readLine()) != null) { + logger.debug("======= message received: {}", line); + message_received.append(line); + } + passed = ServletTestUtil.compareString(EXPECTED_RESPONSE, + message_received.toString()); + + } catch (Exception ex) { + passed = false; + logger.error("Exception: " + ex.getMessage(), ex); + } finally { + try { + if (input != null) { + input.close(); + } + } catch (Exception ex) { + logger.error("Fail to close BufferedReader" + ex.getMessage(), ex); + } + + try { + if (output != null) { + output.close(); + } + } catch (Exception ex) { + logger.error("Fail to close BufferedWriter" + ex.getMessage(), ex); + } + } + } catch (Exception ex3) { + passed = false; + logger.error("Test" + ex3.getMessage(), ex3); + } + + if (!passed) { + throw new Exception("Test Failed."); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/readlistener/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/readlistener/build.xml new file mode 100644 index 0000000000..fe5e67d57c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/readlistener/build.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/readlistener1/TestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/readlistener1/TestListener.java new file mode 100644 index 0000000000..bd53276329 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/readlistener1/TestListener.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.readlistener1; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.ReadListener; +import jakarta.servlet.ServletInputStream; +import jakarta.servlet.ServletOutputStream; + +public class TestListener implements ReadListener { + + private ServletInputStream input = null; + + private ServletOutputStream output = null; + + private AsyncContext ac = null; + + TestListener(ServletInputStream in, ServletOutputStream out, AsyncContext c) { + input = in; + output = out; + ac = c; + } + + public void onDataAvailable() { + try { + StringBuilder sb = new StringBuilder(); + output.println("=onDataAvailable"); + int len = -1; + byte b[] = new byte[1024]; + while (input.isReady() && (len = input.read(b)) != -1) { + String data = new String(b, 0, len); + sb.append("=").append(data); + } + output.print(sb.toString()); + } catch (Exception ex) { + throw new IllegalStateException(ex); + } + } + + public void onAllDataRead() { + try { + output.println("=onAllDataRead"); + } catch (Exception ex) { + throw new IllegalStateException(ex); + } finally { + ac.complete(); + } + } + + public void onError(final Throwable t) { + ac.complete(); + t.printStackTrace(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/readlistener1/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/readlistener1/TestServlet.java new file mode 100644 index 0000000000..6076ef6dc1 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/readlistener1/TestServlet.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.readlistener1; + +import java.io.IOException; + +import com.sun.ts.tests.servlet.common.servlets.HttpTCKServlet; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletInputStream; +import jakarta.servlet.ServletOutputStream; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +@WebServlet(value = "/TestServlet", asyncSupported = true) +public class TestServlet extends HttpTCKServlet { + + public void nioInputTest1(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + AsyncContext ac = request.startAsync(); + ServletOutputStream output = response.getOutputStream(); + ServletInputStream input = request.getInputStream(); + + try { + input.setReadListener(null); + } catch (NullPointerException npe) { + output.println("Test PASSED - expected NullPointerException thrown."); + } + ac.complete(); + } + + public void nioInputTest2(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + AsyncContext ac = null; + + String where = (String) request.getAttribute("WHERE"); + if ("ASYNC".equals(where)) { + ServletOutputStream output = response.getOutputStream(); + ServletInputStream input = request.getInputStream(); + TestListener readListener = new TestListener(input, output, ac); + + try { + input.setReadListener(readListener); + } catch (IllegalStateException npe) { + output.println("Test PASSED - expected IllegalStateException thrown."); + } + } else { + ac = request.startAsync(); + request.setAttribute("WHERE", "ASYNC"); + ac.dispatch(); + } + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/readlistener1/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/readlistener1/URLClient.java new file mode 100644 index 0000000000..44ad515801 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/readlistener1/URLClient.java @@ -0,0 +1,199 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.readlistener1; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.net.HttpURLConnection; +import java.net.URL; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + setContextRoot("/servlet_jsh_readlistener1_web"); + } + + + + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_jsh_readlistener1_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestServlet.class, TestListener.class); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * servlet_async_wait; + */ + /* Run test */ + /* + * @testName: nioInputTest1 + * + * @assertion_ids: Servlet:JAVADOC:942; + * + * @test_Strategy: Create a Servlet TestServlet which supports async; Verify + * ServletInputStream.setReadListener(null) works accordingly + */ + @Test + public void nioInputTest1() throws Exception { + boolean passed = true; + int sleepInSeconds = Integer + .parseInt(_props.getProperty("servlet_async_wait").trim()); + String testName = "nioInputTest1"; + String EXPECTED_RESPONSE = "Test PASSED|NullPointerException"; + + //BufferedReader input = null; + + String requestUrl = "http://" + _hostname + ":" + _port + getContextRoot() + "/" + getServletName() + "?testname=" + + testName; + URL url = new URL(requestUrl); + + try { + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + logger.trace("======= Connecting {}", url.toExternalForm()); + conn.setChunkedStreamingMode(5); + conn.setDoOutput(true); + conn.setRequestMethod("POST"); + + logger.trace("======= Header {}", conn); + conn.connect(); + + try (BufferedWriter output = new BufferedWriter(new OutputStreamWriter(conn.getOutputStream()))) { + try { + String data = "Hello"; + output.write(data); + output.flush(); + Thread.sleep(sleepInSeconds * 1000); + + data = "World"; + output.write(data); + output.flush(); + output.close(); + } catch (Exception ex) { + passed = false; + logger.error("======= Exception sending message: " + ex.getMessage()); + } + + try (BufferedReader input = new BufferedReader(new InputStreamReader(conn.getInputStream()))) { + String line; + StringBuilder message_received = new StringBuilder(); + + while ((line = input.readLine()) != null) { + logger.trace("======= message received: {}", line); + message_received.append(line); + } + passed = ServletTestUtil.compareString(EXPECTED_RESPONSE, + message_received.toString()); + } + } + } catch (Exception ex3) { + passed = false; + logger.error("Test" + ex3.getMessage()); + } + + if (!passed) { + throw new Exception("Test Failed."); + } + } + + /* + * @testName: nioInputTest2 + * + * @assertion_ids: Servlet:JAVADOC:941; + * + * @test_Strategy: Create a Servlet TestServlet which supports async; Create a + * ReadListener; Verify ServletInputStream.setReadListener(ReadListener) + * throws IllegalStateException without Async or upgrade + */ + @Test + public void nioInputTest2() throws Exception { + boolean passed = true; + int sleepInSeconds = Integer + .parseInt(_props.getProperty("servlet_async_wait").trim()); + String testName = "nioInputTest2"; + String EXPECTED_RESPONSE = "Test PASSED|IllegalStateException"; + + String requestUrl = "http://" + _hostname + ":" + _port + getContextRoot() + "/" + getServletName() + "?testname=" + + testName; + try { + URL url = new URL(requestUrl); + + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + logger.trace("======= Connecting {}", url.toExternalForm()); + conn.setChunkedStreamingMode(5); + conn.setDoOutput(true); + conn.setRequestMethod("POST"); + + logger.trace("======= Header {}", conn); + conn.connect(); + + try (BufferedWriter output = new BufferedWriter( + new OutputStreamWriter(conn.getOutputStream()))) { + String data = "Hello"; + output.write(data); + output.flush(); + Thread.sleep(sleepInSeconds * 1000); + + data = "World"; + output.write(data); + output.flush(); + output.close(); + + try (BufferedReader input = new BufferedReader( + new InputStreamReader(conn.getInputStream()))) { + String line; + StringBuilder message_received = new StringBuilder(); + + while ((line = input.readLine()) != null) { + logger.trace("======= message received: {}", line); + message_received.append(line); + } + passed = ServletTestUtil.compareString(EXPECTED_RESPONSE, + message_received.toString()); + } + } + } catch (Exception ex3) { + passed = false; + logger.error("Test" + ex3.getMessage()); + } + + if (!passed) { + throw new Exception("Test Failed."); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/readlistener1/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/readlistener1/build.xml new file mode 100644 index 0000000000..f9e332b5c7 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/readlistener1/build.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext303/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext303/TestServlet.java new file mode 100644 index 0000000000..e64f4bc71c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext303/TestServlet.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.servletcontext303; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.HttpTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class TestServlet extends HttpTCKServlet { + + public void negativeaddHListenerClassTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + Boolean passed = false; + + try { + getServletContext().addListener( + com.sun.ts.tests.servlet.api.common.sharedfiles.HSessionListener.class); + } catch (Exception exf) { + if (exf instanceof java.lang.IllegalStateException) { + passed = true; + pw.print("Expected IllegalStateException is thrown: "); + } else { + pw.print("Unexpected Exception type is thrown: "); + } + exf.printStackTrace(pw); + ServletTestUtil.printResult(pw, passed); + } + } + + public void negativeaddHListenerStringTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + Boolean passed = false; + + try { + getServletContext().addListener( + "com.sun.ts.tests.servlet.api.common.sharedfiles.HSessionListener"); + } catch (Exception exf) { + if (exf instanceof java.lang.IllegalStateException) { + passed = true; + pw.print("Expected IllegalStateException is thrown: "); + } else { + pw.print("Unexpected Exception type is thrown: "); + } + exf.printStackTrace(pw); + ServletTestUtil.printResult(pw, passed); + } + } + + public void negativeaddHAListenerClassTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + Boolean passed = false; + + try { + getServletContext().addListener( + com.sun.ts.tests.servlet.api.common.sharedfiles.HSessionAttributeListener.class); + } catch (Exception exf) { + if (exf instanceof java.lang.IllegalStateException) { + passed = true; + pw.print("Expected IllegalStateException is thrown: "); + } else { + pw.print("Unexpected Exception type is thrown: "); + } + exf.printStackTrace(pw); + ServletTestUtil.printResult(pw, passed); + } + } + + public void negativeaddHAListenerStringTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + Boolean passed = false; + + try { + getServletContext().addListener( + "com.sun.ts.tests.servlet.api.common.sharedfiles.HSessionAttributeListener"); + } catch (Exception exf) { + if (exf instanceof java.lang.IllegalStateException) { + passed = true; + pw.print("Expected IllegalStateException is thrown: "); + } else { + pw.print("Unexpected Exception type is thrown: "); + } + exf.printStackTrace(pw); + ServletTestUtil.printResult(pw, passed); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext303/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext303/URLClient.java new file mode 100644 index 0000000000..602c554661 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext303/URLClient.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.servletcontext303; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_jsh_servletcontext303_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_jsh_servletcontext303_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: negativeaddHListenerClassTest + * + * @assertion_ids: Servlet:JAVADOC:672.11; Servlet:JAVADOC:673.11; + * + * @test_Strategy: Create a Servlet, in which, a HttpSessionListener is added; + * Verify in servlet that java.lang.IllegalStateException is thrown. + */ + @Test + public void negativeaddHListenerClassTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "negativeaddHListenerClassTest"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "HttpSessionListener"); + invoke(); + } + + /* + * @testName: negativeaddHListenerStringTest + * + * @assertion_ids: Servlet:JAVADOC:671.11; + * + * @test_Strategy: Create a Servlet, in which, a HttpSessionListener is added; + * Verify in servlet that java.lang.IllegalStateException is thrown. + */ + @Test + public void negativeaddHListenerStringTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "negativeaddHListenerStringTest"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "HttpSessionListener"); + invoke(); + } + + /* + * @testName: negativeaddHAListenerClassTest + * + * @assertion_ids: Servlet:JAVADOC:672.11; Servlet:JAVADOC:673.11; + * + * @test_Strategy: Create a Servlet, in which, a HttpSessionAttributeListener + * is added; Verify in servlet that java.lang.IllegalStateException is thrown. + */ + @Test + public void negativeaddHAListenerClassTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "negativeaddHAListenerClassTest"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "HSessionAttribute"); + invoke(); + } + + /* + * @testName: negativeaddHAListenerStringTest + * + * @assertion_ids: Servlet:JAVADOC:671.11; + * + * @test_Strategy: Create a Servlet, in which, a HttpSessionAttributeListener + * is added; Verify in servlet that java.lang.IllegalStateException is thrown. + */ + @Test + public void negativeaddHAListenerStringTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "negativeaddHAListenerClassTest"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "HSessionAttribute"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext303/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext303/build.xml new file mode 100644 index 0000000000..0ebd735640 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext303/build.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext303/servlet_jsh_servletcontext303_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext303/servlet_jsh_servletcontext303_web.xml new file mode 100644 index 0000000000..8427314cd3 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext303/servlet_jsh_servletcontext303_web.xml @@ -0,0 +1,33 @@ + + + + + SerJaxSerHServletContext303 + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.servletcontext303.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext304/AddHttpSessionListenerClass.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext304/AddHttpSessionListenerClass.java new file mode 100644 index 0000000000..93337dbdd5 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext304/AddHttpSessionListenerClass.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.servletcontext304; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.http.HttpSessionEvent; +import jakarta.servlet.http.HttpSessionListener; + +public final class AddHttpSessionListenerClass implements HttpSessionListener { + + public void sessionCreated(HttpSessionEvent event) { + StaticLog.add("AddHttpSessionListenerClass Created;"); + } + + public void sessionDestroyed(HttpSessionEvent arg0) { + StaticLog.add("AddHttpSessionListenerClass Destroyed;"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext304/AddHttpSessionListenerString.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext304/AddHttpSessionListenerString.java new file mode 100644 index 0000000000..4d3f42e73a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext304/AddHttpSessionListenerString.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.servletcontext304; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.http.HttpSessionEvent; +import jakarta.servlet.http.HttpSessionListener; + +public final class AddHttpSessionListenerString implements HttpSessionListener { + + public void sessionCreated(HttpSessionEvent event) { + StaticLog.add("AddHttpSessionListenerString Created;"); + } + + public void sessionDestroyed(HttpSessionEvent arg0) { + StaticLog.add("AddHttpSessionListenerString Destroyed;"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext304/CreateHttpSessionListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext304/CreateHttpSessionListener.java new file mode 100644 index 0000000000..921eabcb68 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext304/CreateHttpSessionListener.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.servletcontext304; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.http.HttpSessionEvent; +import jakarta.servlet.http.HttpSessionListener; + +public final class CreateHttpSessionListener implements HttpSessionListener { + + public void sessionCreated(HttpSessionEvent event) { + StaticLog.add("CreateHttpSessionListener Created;"); + } + + public void sessionDestroyed(HttpSessionEvent arg0) { + StaticLog.add("CreateHttpSessionListener Destroyed;"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext304/TestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext304/TestListener.java new file mode 100644 index 0000000000..753d3bf54d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext304/TestListener.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.servletcontext304; + +import java.util.EventListener; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; +import jakarta.servlet.ServletException; + +public class TestListener implements ServletContextListener { + + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce + * The servlet context event + */ + public void contextInitialized(ServletContextEvent sce) { + ServletContext context = sce.getServletContext(); + + Boolean listener_test = true; + String LISTENER_TEST = "LISTENER_TEST"; + + /* + * Add HttpSessionListener + */ + context.addListener( + com.sun.ts.tests.servlet.api.jakarta_servlet_http.servletcontext304.AddHttpSessionListenerClass.class); + context.addListener( + "com.sun.ts.tests.servlet.api.jakarta_servlet_http.servletcontext304.AddHttpSessionListenerString"); + try { + EventListener hslistener = context.createListener( + com.sun.ts.tests.servlet.api.jakarta_servlet_http.servletcontext304.CreateHttpSessionListener.class); + context.addListener(hslistener); + } catch (ServletException ex) { + listener_test = false; + System.out.println("Error creating Listener CreateHttpSessionListener: " + + ex.getMessage()); + } + context.setInitParameter(LISTENER_TEST, listener_test.toString()); + } + + /** + * Receives notification that the servlet context is about to be shut down. + * + * @param sce + * The servlet context event + */ + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext304/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext304/TestServlet.java new file mode 100644 index 0000000000..489773d442 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext304/TestServlet.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.servletcontext304; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; + +import com.sun.ts.tests.servlet.common.servlets.HttpTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpSession; + +public class TestServlet extends HttpTCKServlet { + + public void addListenerTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String name = "LISTENER_TEST"; + + pw.println( + name + "=" + getServletContext().getInitParameter(name).toUpperCase()); + getServletContext().removeAttribute(name); + + HttpSession hs = request.getSession(); + hs.invalidate(); + + ArrayList result = StaticLog.getClear(); + pw.println(result); + ServletTestUtil.printResult(pw, true); + getServletContext().removeAttribute("arraylist"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext304/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext304/URLClient.java new file mode 100644 index 0000000000..0a979c2d80 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext304/URLClient.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.servletcontext304; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_jsh_servletcontext304_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(AddHttpSessionListenerClass.class, AddHttpSessionListenerString.class, + CreateHttpSessionListener.class, TestListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_jsh_servletcontext304_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + + /* + * @testName: addListenerTest + * + * @assertion_ids: Servlet:JAVADOC:671.4; Servlet:JAVADOC:672.4; + * Servlet:JAVADOC:673.4; + * + * @test_Strategy: In a ServletContextListener, call: - + * ServletContext.addListener(TCKTestListener.class) - + * ervletContext.addListener("TCKTestListener") - + * ServletContext.createListener(TCKTestListener.class) TCKTestListener + * implements HttpSessionListener Verify it works + */ + @Test + public void addListenerTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "addListenerTest"); + TEST_PROPS.setProperty(SEARCH_STRING, + "LISTENER_TEST=TRUE" + "|AddHttpSessionListenerClass Created" + + "|AddHttpSessionListenerString Created" + + "|CreateHttpSessionListener Created" + + "|CreateHttpSessionListener Destroyed" + + "|AddHttpSessionListenerString Destroyed" + + "|AddHttpSessionListenerClass Destroyed"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext304/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext304/build.xml new file mode 100644 index 0000000000..1779a1381d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext304/build.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext304/servlet_jsh_servletcontext304_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext304/servlet_jsh_servletcontext304_web.xml new file mode 100644 index 0000000000..ec0f8e30a5 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext304/servlet_jsh_servletcontext304_web.xml @@ -0,0 +1,36 @@ + + + + + SerJaxSerHServletContext304 + + com.sun.ts.tests.servlet.api.jakarta_servlet_http.servletcontext304.TestListener + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.servletcontext304.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext305/AddHttpSessionAttributeListenerClass.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext305/AddHttpSessionAttributeListenerClass.java new file mode 100644 index 0000000000..bc8c9d0ca4 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext305/AddHttpSessionAttributeListenerClass.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.servletcontext305; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.http.HttpSessionAttributeListener; +import jakarta.servlet.http.HttpSessionBindingEvent; + +public final class AddHttpSessionAttributeListenerClass + implements HttpSessionAttributeListener { + + public void attributeAdded(HttpSessionBindingEvent event) { + StaticLog.add("AddHttpSessionAttributeListenerClass attributeAdded:" + + event.getName() + "," + event.getValue()); + } + + public void attributeRemoved(HttpSessionBindingEvent event) { + StaticLog.add("AddHttpSessionAttributeListenerClass attributeRemoved:" + + event.getName() + "," + event.getValue()); + } + + public void attributeReplaced(HttpSessionBindingEvent event) { + StaticLog.add("AddHttpSessionAttributeListenerClass attributeReplaced:" + + event.getName() + "," + event.getValue()); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext305/AddHttpSessionAttributeListenerString.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext305/AddHttpSessionAttributeListenerString.java new file mode 100644 index 0000000000..8b5cd7ebc0 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext305/AddHttpSessionAttributeListenerString.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.servletcontext305; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.http.HttpSessionAttributeListener; +import jakarta.servlet.http.HttpSessionBindingEvent; + +public final class AddHttpSessionAttributeListenerString + implements HttpSessionAttributeListener { + + public void attributeAdded(HttpSessionBindingEvent event) { + StaticLog.add("AddHttpSessionAttributeListenerString attributeAdded:" + + event.getName() + "," + event.getValue()); + } + + public void attributeRemoved(HttpSessionBindingEvent event) { + StaticLog.add("AddHttpSessionAttributeListenerString attributeRemoved:" + + event.getName() + "," + event.getValue()); + } + + public void attributeReplaced(HttpSessionBindingEvent event) { + StaticLog.add("AddHttpSessionAttributeListenerString attributeReplaced:" + + event.getName() + "," + event.getValue()); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext305/CreateHttpSessionAttributeListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext305/CreateHttpSessionAttributeListener.java new file mode 100644 index 0000000000..2cbeb79996 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext305/CreateHttpSessionAttributeListener.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.servletcontext305; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.http.HttpSessionAttributeListener; +import jakarta.servlet.http.HttpSessionBindingEvent; + +public final class CreateHttpSessionAttributeListener + implements HttpSessionAttributeListener { + + public void attributeAdded(HttpSessionBindingEvent event) { + StaticLog.add("CreateHttpSessionAttributeListener attributeAdded:" + + event.getName() + "," + event.getValue()); + } + + public void attributeRemoved(HttpSessionBindingEvent event) { + StaticLog.add("CreateHttpSessionAttributeListener attributeRemoved:" + + event.getName() + "," + event.getValue()); + } + + public void attributeReplaced(HttpSessionBindingEvent event) { + StaticLog.add("CreateHttpSessionAttributeListener attributeReplaced:" + + event.getName() + "," + event.getValue()); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext305/TestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext305/TestListener.java new file mode 100644 index 0000000000..adf98d374d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext305/TestListener.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.servletcontext305; + +import java.util.EventListener; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; +import jakarta.servlet.ServletException; + +public class TestListener implements ServletContextListener { + + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce + * The servlet context event + */ + public void contextInitialized(ServletContextEvent sce) { + ServletContext context = sce.getServletContext(); + + Boolean listener_test = true; + String LISTENER_TEST = "LISTENER_TEST"; + + /* + * Add HttpSessionAttributeListener + */ + context.addListener( + com.sun.ts.tests.servlet.api.jakarta_servlet_http.servletcontext305.AddHttpSessionAttributeListenerClass.class); + context.addListener( + "com.sun.ts.tests.servlet.api.jakarta_servlet_http.servletcontext305.AddHttpSessionAttributeListenerString"); + try { + EventListener hslistener = context.createListener( + com.sun.ts.tests.servlet.api.jakarta_servlet_http.servletcontext305.CreateHttpSessionAttributeListener.class); + context.addListener(hslistener); + } catch (ServletException ex) { + listener_test = false; + System.out.println( + "Error creating Listener CreateHttpSessionAttributeListener: " + + ex.getMessage()); + } + context.setInitParameter(LISTENER_TEST, listener_test.toString()); + } + + /** + * Receives notification that the servlet context is about to be shut down. + * + * @param sce + * The servlet context event + */ + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext305/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext305/TestServlet.java new file mode 100644 index 0000000000..672ce4ee72 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext305/TestServlet.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.servletcontext305; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; + +import com.sun.ts.tests.servlet.common.servlets.HttpTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpSession; + +public class TestServlet extends HttpTCKServlet { + + public void addListenerTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String name = "LISTENER_TEST"; + + pw.println( + name + "=" + getServletContext().getInitParameter(name).toUpperCase()); + getServletContext().removeAttribute(name); + + HttpSession hs = request.getSession(); + hs.setAttribute("attributeAddedTest", "Attribute1"); + hs.invalidate(); + + ArrayList result = StaticLog.getClear(); + pw.println(result); + ServletTestUtil.printResult(pw, true); + getServletContext().removeAttribute("arraylist"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext305/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext305/URLClient.java new file mode 100644 index 0000000000..1f35f38b9d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext305/URLClient.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.servletcontext305; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_jsh_servletcontext305_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(AddHttpSessionAttributeListenerClass.class, AddHttpSessionAttributeListenerString.class, + CreateHttpSessionAttributeListener.class, TestListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_jsh_servletcontext305_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + + /* + * @testName: addListenerTest + * + * @assertion_ids: Servlet:JAVADOC:671.5; Servlet:JAVADOC:672.5; + * Servlet:JAVADOC:673.5; + * + * @test_Strategy: In a ServletContextListener, call: - + * ServletContext.addListener(TCKTestListener.class) - + * ervletContext.addListener("TCKTestListener") - + * ServletContext.createListener(TCKTestListener.class) TCKTestListener + * implements the following Listener interfaces on the list: - + * HttpSessionAttributeListener Verify it works + */ + @Test + public void addListenerTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "addListenerTest"); + TEST_PROPS.setProperty(SEARCH_STRING, + "LISTENER_TEST=TRUE" + + "|AddHttpSessionAttributeListenerClass attributeAdded" + + "|attributeAddedTest|Attribute1" + + "|AddHttpSessionAttributeListenerString attributeAdded" + + "|attributeAddedTest|Attribute1" + + "|CreateHttpSessionAttributeListener attributeAdded" + + "|attributeAddedTest|Attribute1" + + "|AddHttpSessionAttributeListenerClass attributeRemoved" + + "|attributeAddedTest|Attribute1" + + "|AddHttpSessionAttributeListenerString attributeRemoved" + + "|attributeAddedTest|Attribute1" + + "|CreateHttpSessionAttributeListener attributeRemoved" + + "|attributeAddedTest|Attribute1"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext305/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext305/build.xml new file mode 100644 index 0000000000..1a889d2cc0 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext305/build.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext305/servlet_jsh_servletcontext305_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext305/servlet_jsh_servletcontext305_web.xml new file mode 100644 index 0000000000..9f507c2690 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/servletcontext305/servlet_jsh_servletcontext305_web.xml @@ -0,0 +1,36 @@ + + + + + SerJaxSerHServletContext305 + + com.sun.ts.tests.servlet.api.jakarta_servlet_http.servletcontext305.TestListener + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.servletcontext305.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/sessioncookieconfig/TestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/sessioncookieconfig/TestListener.java new file mode 100644 index 0000000000..cdb6d00660 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/sessioncookieconfig/TestListener.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2009, 2021 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.sessioncookieconfig; + +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; +import jakarta.servlet.SessionCookieConfig; + +public class TestListener implements ServletContextListener { + + /** + * Test for SessionCookieConfig.SessionCookieConfig method + */ + public void contextInitialized(ServletContextEvent sce) { + StringBuffer testData = new StringBuffer("Testing_Session_Cookie_Config"); + String domain = "sun.com"; + String path = "/servlet_jsh_sessioncookieconfig_web/TestServlet"; + boolean isSecure = true; + boolean httpOnly = false; + int maxage = 50000; + String attrName = "a1"; + String attrValue= "b2"; + String name = "TCK_Cookie_Name"; + + SessionCookieConfig scf = sce.getServletContext().getSessionCookieConfig(); + + scf.setDomain(domain); + scf.setHttpOnly(httpOnly); + scf.setPath(path); + scf.setSecure(isSecure); + scf.setAttribute(attrName, attrValue); + + if (!scf.getPath().equals(path)) { + testData.append("|getPath-FAILED-expecting-" + path + "-got-" + scf.getPath()); + } + + if (!scf.isSecure()) { + testData.append("|isSecure-FAILED-expecting-" + isSecure + "-got-" + scf.isSecure()); + } + + if (scf.isHttpOnly()) { + testData.append("|isHttpOnly-FAILED-expecting-" + httpOnly + "-got-" + scf.isHttpOnly()); + } + + if (!scf.getDomain().equals(domain)) { + testData.append("|getDomain-FAILED-expecting-" + domain + "-got-" + scf.getDomain()); + } + + + if (scf.getMaxAge() != -1) { + testData.append("|getMaxAge-FAILED-expecting-(-1)-got-" + scf.getMaxAge()); + } + + scf.setMaxAge(maxage); + if (scf.getMaxAge() != maxage) { + testData.append("|getMaxAge-FAILED-expecting-" + maxage + "-got-" + scf.getMaxAge()); + } + + if (!scf.getAttribute(attrName).equals(attrValue)) { + testData.append("|getAttribute-FAILED-expecting-" + attrValue + "-got-" + scf.getAttribute(attrName)); + } + + if (scf.getName() != null && !"JSESSIONID".equals(scf.getName())) { + testData.append("|getName-FAILED-expecting-null-or-JSESSIONID-got-" + scf.getName()); + } + + scf.setName(name); + if (!scf.getName().equals(name)) { + testData.append("|getName-FAILED-expecting-" + name + "-got-" + scf.getName()); + } + + sce.getServletContext().setAttribute(this.getClass().getName(), testData.toString()); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/sessioncookieconfig/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/sessioncookieconfig/TestServlet.java new file mode 100644 index 0000000000..75a88ab32a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/sessioncookieconfig/TestServlet.java @@ -0,0 +1,207 @@ +/* + * Copyright (c) 2009, 2021 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.sessioncookieconfig; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.HttpTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpSession; + +public class TestServlet extends HttpTCKServlet { + + public void constructortest1(HttpServletRequest request, + HttpServletResponse response) throws IOException { + request.getSession(true); + + String results = (String) getServletContext().getAttribute(TestListener.class.getName()); + + if (results.indexOf("-FAILED-") > -1) { + ServletTestUtil.printResult( + response.getWriter(), "At least on test failed. " + results); + } + + } + + public void setNameTest(HttpServletRequest request, + HttpServletResponse response) throws IOException { + String name = "WHO_SHOULD_NOT_BE_NAMED_HERE"; + boolean pass = true; + PrintWriter pw = response.getWriter(); + HttpSession session = request.getSession(); + + try { + pw.println("calling method setName"); + getServletContext().getSessionCookieConfig().setName(name); + pass = false; + pw.println("Expected IllegalStateException not thrown"); + } catch (IllegalStateException ex) { + pw.println("Expected IllegalStateException thrown"); + } finally { + session.invalidate(); + ServletTestUtil.printResult(pw, pass); + } + } + + public void setCommentTest(HttpServletRequest request, + HttpServletResponse response) throws IOException { + String comment = "WHO_SHOULD_NOT_BE_NAMED_HERE"; + boolean pass = true; + PrintWriter pw = response.getWriter(); + HttpSession session = request.getSession(); + + try { + pw.println("calling method setComment"); + getServletContext().getSessionCookieConfig().setComment(comment); + pass = false; + pw.println("Expected IllegalStateException not thrown"); + } catch (IllegalStateException ex) { + pw.println("Expected IllegalStateException thrown"); + } finally { + session.invalidate(); + ServletTestUtil.printResult(pw, pass); + } + } + + public void setPathTest(HttpServletRequest request, + HttpServletResponse response) throws IOException { + String path = "WHO_SHOULD_NOT_BE_NAMED_HERE"; + boolean pass = true; + PrintWriter pw = response.getWriter(); + HttpSession session = request.getSession(); + + try { + pw.println("calling method setPath"); + getServletContext().getSessionCookieConfig().setPath(path); + pass = false; + pw.println("Expected IllegalStateException not thrown"); + } catch (IllegalStateException ex) { + pw.println("Expected IllegalStateException thrown"); + } finally { + session.invalidate(); + ServletTestUtil.printResult(pw, pass); + } + } + + public void setDomainTest(HttpServletRequest request, + HttpServletResponse response) throws IOException { + String domain = "WHO_SHOULD_NOT_BE_NAMED_HERE"; + boolean pass = true; + PrintWriter pw = response.getWriter(); + HttpSession session = request.getSession(); + + try { + pw.println("calling method setDomain"); + getServletContext().getSessionCookieConfig().setDomain(domain); + pass = false; + pw.println("Expected IllegalStateException not thrown"); + } catch (IllegalStateException ex) { + pw.println("Expected IllegalStateException thrown"); + } finally { + session.invalidate(); + ServletTestUtil.printResult(pw, pass); + } + } + + public void setMaxAgeTest(HttpServletRequest request, + HttpServletResponse response) throws IOException { + int maxage = 12345; + boolean pass = true; + PrintWriter pw = response.getWriter(); + HttpSession session = request.getSession(); + + try { + pw.println("calling method setMaxAge"); + getServletContext().getSessionCookieConfig().setMaxAge(maxage); + pass = false; + pw.println("Expected IllegalStateException not thrown"); + } catch (IllegalStateException ex) { + pw.println("Expected IllegalStateException thrown"); + } finally { + session.invalidate(); + ServletTestUtil.printResult(pw, pass); + } + } + + public void setHttpOnlyTest(HttpServletRequest request, + HttpServletResponse response) throws IOException { + boolean http = true; + boolean pass = true; + PrintWriter pw = response.getWriter(); + HttpSession session = request.getSession(); + + try { + pw.println("calling method setHttpOnly"); + getServletContext().getSessionCookieConfig().setHttpOnly(http); + pass = false; + pw.println("Expected IllegalStateException not thrown"); + } catch (IllegalStateException ex) { + pw.println("Expected IllegalStateException thrown"); + } finally { + session.invalidate(); + ServletTestUtil.printResult(pw, pass); + } + } + + public void setSecureTest(HttpServletRequest request, + HttpServletResponse response) throws IOException { + boolean secure = true; + boolean pass = true; + PrintWriter pw = response.getWriter(); + HttpSession session = request.getSession(); + + try { + pw.println("calling method setSecure"); + getServletContext().getSessionCookieConfig().setSecure(secure); + pass = false; + pw.println("Expected IllegalStateException not thrown"); + } catch (IllegalStateException ex) { + pw.println("Expected IllegalStateException thrown"); + } finally { + session.invalidate(); + ServletTestUtil.printResult(pw, pass); + } + } + + public void setAttributeTest(HttpServletRequest request, + HttpServletResponse response) throws IOException { + String attribute = "WHO_SHOULD_NOT_BE_NAMED_HERE"; + boolean pass = true; + PrintWriter pw = response.getWriter(); + HttpSession session = request.getSession(); + + try { + pw.println("calling method setAttribute"); + getServletContext().getSessionCookieConfig().setAttribute(attribute, attribute); + pass = false; + pw.println("Expected IllegalStateException not thrown"); + } catch (IllegalStateException ex) { + pw.println("Expected IllegalStateException thrown"); + } finally { + session.invalidate(); + ServletTestUtil.printResult(pw, pass); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/sessioncookieconfig/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/sessioncookieconfig/URLClient.java new file mode 100644 index 0000000000..3a545b6195 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/sessioncookieconfig/URLClient.java @@ -0,0 +1,199 @@ +/* + * Copyright (c) 2009, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.sessioncookieconfig; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_jsh_sessioncookieconfig_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_jsh_sessioncookieconfig_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: constructortest1 + * + * @assertion_ids: Servlet:JAVADOC:693; Servlet:JAVADOC:733; + * Servlet:JAVADOC:734; Servlet:JAVADOC:735; Servlet:JAVADOC:736; + * Servlet:JAVADOC:737; Servlet:JAVADOC:738; Servlet:JAVADOC:739; + * Servlet:JAVADOC:740; Servlet:JAVADOC:741; Servlet:JAVADOC:742; + * Servlet:JAVADOC:743; Servlet:JAVADOC:744; Servlet:JAVADOC:745; + * Servlet:JAVADOC:746; + * + * @test_Strategy: Create a Servlet TestServlet, with a + * ServletContextListener; In the Servlet, turn HttpSession on; In + * ServletContextListener, create a SessionCookieConfig instance, Verify in + * Client that the SessionCookieConfig instance is created, and all + * SessionCookieConfig APIs work accordingly. + */ + @Test + public void constructortest1() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET /servlet_jsh_sessioncookieconfig_web/TestServlet?testname=constructortest1 HTTP/1.1"); + TEST_PROPS.setProperty(EXPECTED_HEADERS, + "Set-Cookie:" + "TCK_Cookie_Name=" + "##Expires=" + + "##Path=/servlet_jsh_sessioncookieconfig_web/TestServlet" + + "##Secure"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "Test FAILED"); + invoke(); + } + + /* + * @testName: setNameTest + * + * @assertion_ids: Servlet:JAVADOC:744; + * + * @test_Strategy: Create a Servlet TestServlet, In the Servlet, turn + * HttpSession on; Verify in servlet SessionCookieConfig.setName cannot be + * called once is set. + */ + @Test + public void setNameTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setNameTest"); + invoke(); + } + + /* + * @testName: setCommentTest + * + * @assertion_ids: Servlet:JAVADOC:740; + * + * @test_Strategy: Create a Servlet TestServlet, In the Servlet, turn + * HttpSession on; Verify in servlet SessionCookieConfig.setComment cannot be + * called once is set. + */ + @Test + public void setCommentTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setCommentTest"); + invoke(); + } + + /* + * @testName: setPathTest + * + * @assertion_ids: Servlet:JAVADOC:745; + * + * @test_Strategy: Create a Servlet TestServlet, In the Servlet, turn + * HttpSession on; Verify in servlet SessionCookieConfig.setPath cannot be + * called once is set. + */ + @Test + public void setPathTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setPathTest"); + invoke(); + } + + /* + * @testName: setDomainTest + * + * @assertion_ids: Servlet:JAVADOC:741; + * + * @test_Strategy: Create a Servlet TestServlet, In the Servlet, turn + * HttpSession on; Verify in servlet SessionCookieConfig.setDomain cannot be + * called once is set. + */ + @Test + public void setDomainTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setDomainTest"); + invoke(); + } + + /* + * @testName: setMaxAgeTest + * + * @assertion_ids: Servlet:JAVADOC:743; + * + * @test_Strategy: Create a Servlet TestServlet, In the Servlet, turn + * HttpSession on; Verify in servlet SessionCookieConfig.setMaxAge cannot be + * called once is set. + */ + @Test + public void setMaxAgeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setMaxAgeTest"); + invoke(); + } + + /* + * @testName: setHttpOnlyTest + * + * @assertion_ids: Servlet:JAVADOC:742; + * + * @test_Strategy: Create a Servlet TestServlet, In the Servlet, turn + * HttpSession on; Verify in servlet SessionCookieConfig.setHttpOnly cannot be + * called once is set. + */ + @Test + public void setHttpOnlyTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setHttpOnlyTest"); + invoke(); + } + + /* + * @testName: setSecureTest + * + * @assertion_ids: Servlet:JAVADOC:746; + * + * @test_Strategy: Create a Servlet TestServlet, In the Servlet, turn + * HttpSession on; Verify in servlet SessionCookieConfig.setSecure cannot be + * called once is set. + */ + @Test + public void setSecureTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setSecureTest"); + invoke(); + } + + /* + * @testName: setAttributeTest + * + * @assertion_ids: + * + * @test_Strategy: Create a Servlet TestServlet, In the Servlet, turn + * HttpSession on; Verify in servlet SessionCookieConfig.setAttribute cannot be + * called once is set. + */ + @Test + public void setAttributeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setAttributeTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/sessioncookieconfig/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/sessioncookieconfig/build.xml new file mode 100644 index 0000000000..bdc529dc42 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/sessioncookieconfig/build.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/sessioncookieconfig/servlet_jsh_sessioncookieconfig_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/sessioncookieconfig/servlet_jsh_sessioncookieconfig_web.xml new file mode 100644 index 0000000000..6f0766937e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/sessioncookieconfig/servlet_jsh_sessioncookieconfig_web.xml @@ -0,0 +1,36 @@ + + + + + SerJaxSerSessionCookieConfig + + com.sun.ts.tests.servlet.api.jakarta_servlet_http.sessioncookieconfig.TestListener + + + TestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet_http.sessioncookieconfig.TestServlet + + + TestLogicalName + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/writelistener/TestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/writelistener/TestListener.java new file mode 100644 index 0000000000..ffeb1488fa --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/writelistener/TestListener.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.writelistener; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.ServletOutputStream; +import jakarta.servlet.WriteListener; + +public class TestListener implements WriteListener { + + private ServletOutputStream output = null; + + private AsyncContext ac = null; + + TestListener(ServletOutputStream sos, AsyncContext c) { + output = sos; + ac = c; + } + + public void onWritePossible() { + String message = "=onWritePossible"; + try { + output.write(message.getBytes()); + ac.complete(); + } catch (Exception ex) { + ac.complete(); + throw new IllegalStateException(ex); + } + } + + public void onError(final Throwable t) { + ac.complete(); + t.printStackTrace(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/writelistener/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/writelistener/TestServlet.java new file mode 100644 index 0000000000..fc3cfe841f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/writelistener/TestServlet.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.writelistener; + +import java.io.IOException; + +import com.sun.ts.tests.servlet.common.servlets.HttpTCKServlet; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletOutputStream; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +@WebServlet(value = "/TestServlet", asyncSupported = true) +public class TestServlet extends HttpTCKServlet { + + private static final int LENGTH = 587952; + + public void nioOutputTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + AsyncContext ac = request.startAsync(); + ServletOutputStream output = response.getOutputStream(); + TestListener writeListener = new TestListener(output, ac); + output.setWriteListener(writeListener); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/writelistener/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/writelistener/URLClient.java new file mode 100644 index 0000000000..076a63bcb0 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/writelistener/URLClient.java @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2013, 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$ + */ +package com.sun.ts.tests.servlet.api.jakarta_servlet_http.writelistener; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "writelistener.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestServlet.class, TestListener.class); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: nioOutputTest + * + * @assertion_ids: Servlet:JAVADOC:911; Servlet:JAVADOC:916; + * Servlet:JAVADOC:917; Servlet:JAVADOC:582; Servlet:JAVADOC:609; + * + * @test_Strategy: Create a Servlet TestServlet which supports async; Create a + * Writeistener; From Servlet, sends one batch of messages use stream; Verify + * all message received by client; Verify WriteListener works accordingly + */ + @Test + public void nioOutputTest() throws Exception { + boolean passed = true; + String testName = "nioOutputTest"; + String EXPECTED_RESPONSE = "=onWritePossible"; + + String requestUrl = getContextRoot() + "/" + getServletName() + "?testname=" + + testName; + + URL url = new URL(getURLString("http", _hostname, _port, requestUrl.substring(1))); + try { + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + logger.debug("======= Connecting {}", url.toExternalForm()); + conn.setChunkedStreamingMode(5); + conn.setDoOutput(true); + logger.trace("======= Header {}", conn); + conn.connect(); + + try (BufferedReader input = new BufferedReader( + new InputStreamReader(conn.getInputStream()))) { + String line = null; + StringBuilder message_received = new StringBuilder(); + + while ((line = input.readLine()) != null) { + logger.debug("======= message received: " + line); + message_received.append(line); + } + passed = ServletTestUtil.compareString(EXPECTED_RESPONSE, + message_received.toString()); + + } + } catch (Exception ex) { + passed = false; + logger.error("Test" + ex.getMessage(), ex); + } + + if (!passed) { + throw new Exception("Test Failed."); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/writelistener/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/writelistener/build.xml new file mode 100644 index 0000000000..0fc50910ac --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/api/jakarta_servlet_http/writelistener/build.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/build.xml new file mode 100644 index 0000000000..c10c8f6a06 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/build.xml @@ -0,0 +1,22 @@ + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/client/AbstractUrlClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/client/AbstractUrlClient.java new file mode 100644 index 0000000000..a796a98e09 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/client/AbstractUrlClient.java @@ -0,0 +1,256 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.common.client; + +import com.sun.ts.tests.servlet.common.request.HttpRequest; +import com.sun.ts.tests.servlet.common.request.WebTestCase; +import com.sun.ts.tests.servlet.common.util.Data; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.net.InetAddress; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.net.UnknownHostException; + +/** + * Base client for Servlet tests. + */ + +public abstract class AbstractUrlClient extends BaseUrlClient { + + protected final Logger logger = LoggerFactory.getLogger(getClass()); + + protected static final String APITEST = "apitest"; + + protected static final String DONOTUSEServletName = "NoServletName"; + + private InetAddress[] _addrs = null; + + private String _servlet = null; + + protected AbstractUrlClient() { + // Construct a default context root based on the class name of + // the concrete subclass of this class. + String cname = this.getClass().getName(); + String prefix = "com.sun.ts.tests."; + if (cname.startsWith(prefix)) + cname = cname.substring(prefix.length()); + String suffix = ".URLClient"; + if (cname.endsWith(suffix)) + cname = cname.substring(0, cname.length() - suffix.length()); + cname = cname.replace('.', '_'); + cname = "/" + cname + "_web"; + setContextRoot(cname); + } + + protected void setTestProperties(WebTestCase testCase) { + setStandardProperties(TEST_PROPS.getProperty(STANDARD), testCase); + setApiTestProperties(TEST_PROPS.getProperty(APITEST), testCase); + super.setTestProperties(testCase); + } + + /** + * Sets the request, testname, and a search string for test passed. A search + * is also added for test failure. If found, the test will fail. + * + * @param testValue + * - a logical test identifier + * @param testCase + * - the current test case + */ + private void setApiTestProperties(String testValue, WebTestCase testCase) { + if (testValue == null) { + return; + } + + // An API test consists of a request with a request parameter of + // testname, a search string of Test PASSED, and a logical test name. + + // set the testname + _testName = testValue; + + // set the request + StringBuilder sb = new StringBuilder(50); + if ((_servlet != null) + && (TEST_PROPS.getProperty(DONOTUSEServletName) == null)) { + sb.append(GET).append(_contextRoot).append(SL); + sb.append(_servlet).append("?testname=").append(testValue); + sb.append(HTTP11); + } else { + sb.append(GET).append(_contextRoot).append(SL); + sb.append(testValue).append(HTTP10); + } + logger.debug("REQUEST LINE: {}", sb); + + HttpRequest req = new HttpRequest(sb.toString(), _hostname, _port); + testCase.setRequest(req); + + if ((TEST_PROPS.getProperty(SEARCH_STRING) == null) + || ((TEST_PROPS.getProperty(SEARCH_STRING)).equals(""))) { + testCase.setResponseSearchString(Data.PASSED); + testCase.setUnexpectedResponseSearchString(Data.FAILED); + } + + } + + /** + * Consists of a test name, a request, and a goldenfile. + * + * @param testValue + * - a logical test identifier + * @param testCase + * - the current test case + */ + private void setStandardProperties(String testValue, WebTestCase testCase) { + + if (testValue == null) { + return; + } + // A standard test sets consists of a testname + // a request, and a goldenfile. The URI is not used + // in this case since the JSP's are assumed to be located + // at the top of the contextRoot + StringBuffer sb = new StringBuffer(50); + + // set the testname + _testName = testValue; + + // set the request + // sb.append(GET).append(_contextRoot).append(SL); + // sb.append(testValue).append(JSP_SUFFIX).append(HTTP10); + // setRequest(sb.toString()); + // HttpRequest req = new HttpRequest(sb.toString(), _hostname, _port); + // testCase.setRequest(req); + + if (_servlet != null) { + sb.append(GET).append(_contextRoot).append(SL); + sb.append(_servlet).append("?testname=").append(testValue); + sb.append(HTTP11); + } else { + sb.append(GET).append(_contextRoot).append(SL); + sb.append(testValue).append(HTTP10); + } + logger.debug("REQUEST LINE: {}", sb); + HttpRequest req = new HttpRequest(sb.toString(), _hostname, _port); + testCase.setRequest(req); + } + + /** + * Sets the name of the servlet to use when building a request for a single + * servlet API test. + * + * @param servlet + * - the name of the servlet + */ + protected void setServletName(String servlet) { + _servlet = servlet; + } + + protected String getServletName() { + return _servlet; + } + + protected String getLocalInterfaceInfo(boolean returnAddresses) { + String result = null; + initInetAddress(); + if (_addrs.length != 0) { + StringBuilder sb = new StringBuilder(32); + if (!returnAddresses) { + // localhost might not show up if aliased + sb.append("localhost,"); + } else { + // add 127.0.0.1 + sb.append("127.0.0.1,"); + } + + for (int i = 0; i < _addrs.length; i++) { + if (returnAddresses) { + String ip = _addrs[i].getHostAddress(); + if (!ip.equals("127.0.0.1")) { + if (ip.contains("%")) { + int scope_id = ip.indexOf("%"); + ip = ip.substring(0, scope_id); + } + sb.append(ip); + } + } else { + String host = _addrs[i].getCanonicalHostName(); + if (!host.equals("localhost")) { + sb.append(host); + } + } + if (i + 1 != _addrs.length) { + sb.append(","); + } + } + result = sb.toString(); + logger.trace("[AbstractUrlClient] Interface info: {}", result); + } + return result; + } + + private void initInetAddress() { + if (_addrs == null) { + try { + _addrs = InetAddress + .getAllByName(InetAddress.getLocalHost().getCanonicalHostName()); + } catch (UnknownHostException uhe) { + logger.info( + "[AbstractUrlClient][WARNING] Unable to obtain local host information."); + } + } + } + + protected String getRequest(String rq) { + return rq; + } + + protected String getURLString(String protocol, String hostname, int portnum, String sContext) { + return protocol + "://" + hostname + ":" + portnum + "/" + sContext; + } + + protected URL getURL(String protocol, String hostname, int portnum, String sContext) throws MalformedURLException { + return new URL(protocol + "://" + hostname + ":" + portnum + "/" + sContext); + } + + + public URLConnection getHttpsURLConnection(URL newURL) + throws IOException { + // open HttpsURLConnection using TSHttpsURLConnection + URLConnection httpsURLConn = null; + + httpsURLConn = newURL.openConnection(); + if (httpsURLConn != null) { + httpsURLConn.setDoInput(true); + httpsURLConn.setDoOutput(true); + httpsURLConn.setUseCaches(false); + + } else + throw new IOException("Error opening httsURLConnection"); + + return httpsURLConn; + } + +} + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/client/BaseUrlClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/client/BaseUrlClient.java new file mode 100644 index 0000000000..9f9be53423 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/client/BaseUrlClient.java @@ -0,0 +1,661 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.common.client; + +import com.sun.ts.tests.servlet.common.request.HttpRequest; +import com.sun.ts.tests.servlet.common.request.WebTestCase; +import org.apache.commons.httpclient.HttpState; +import org.jboss.arquillian.container.test.api.OperateOnDeployment; +import org.jboss.arquillian.junit5.ArquillianExtension; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.ExtendWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.PrintWriter; +import java.net.URL; +import java.nio.file.Paths; +import java.util.Enumeration; +import java.util.Properties; + +/** + *
+ * Provides base test initialization and runtime
+ * logic into a common class.
+ * All test areas will need to extend this class
+ * to provided area specific functionality needed for
+ * that particular technology.
+ * 
+ */ +@ExtendWith({ArquillianExtension.class}) +public abstract class BaseUrlClient { + + protected final Logger logger = LoggerFactory.getLogger(getClass()); + + @ArquillianResource @OperateOnDeployment("_DEFAULT_") + public URL url; + + /** + * Properties parameters + */ + public Properties _props; + + /** + * 401 - Unauthorized + */ + protected static final String UNAUTHORIZED = "401"; + + /** + * 403 - Forbidden + */ + protected static final String FORBIDDEN = "403"; + + /** + * 404 - not found + */ + protected static final String NOT_FOUND = "404"; + + /** + * 200 - ok + */ + protected static final String OK = "200"; + + /** + * 201 - created + */ + protected static final String CREATED = "201"; + + /** + * 500 - internal server error + */ + protected static final String INTERNAL_SERVER_ERROR = "500"; + + /** + * 503 - service unavailable + */ + protected static final String SERVICE_UNAVAILABLE = "503"; + + /** + * 100 - continue + */ + protected static final String CONTINUE = "100"; + + /** + * 302 - moved temporarily + */ + protected static final String MOVED_TEMPORARY = "302"; + + /** + * 410 - GONE + */ + protected static final String GONE = "410"; + + /** + * 411 - length required + */ + protected static final String LENGTH_REQUIRED = "411"; + + /** + * TS Webserver host property + */ + protected static final String SERVLETHOSTPROP = "webServerHost"; + + /** + * TS Webserver port property + */ + protected static final String SERVLETPORTPROP = "webServerPort"; + + /** + * TS home property + */ + protected static final String TSHOME = "ts_home"; + + /** + * Test properties + */ + protected static final Properties TEST_PROPS = new Properties(); + + /** + * StatusCode property + */ + protected static final String STATUS_CODE = "status-code"; + + /** + * Reason-Phrase property + */ + protected static final String REASON_PHRASE = "reason-phrase"; + + /** + * Expected headers property + */ + protected static final String EXPECTED_HEADERS = "expected_headers"; + + /** + * Unexpected header property + */ + protected static final String UNEXPECTED_HEADERS = "unexpected_headers"; + + /** + * Expect response body property + */ + protected static final String EXPECT_RESPONSE_BODY = "expect_response_body"; + + /** + * Request property + */ + protected static final String REQUEST = "request"; + + /** + * Request headers property + */ + protected static final String REQUEST_HEADERS = "request_headers"; + + /** + * Search string property + */ + protected static final String SEARCH_STRING = "search_string"; + + /** + * Search string case insensitive property + */ + protected static final String SEARCH_STRING_IGNORE_CASE = "search_string_ignore_case"; + + /** + * Basic Auth username + */ + protected static final String BASIC_AUTH_USER = "basic_auth_user"; + + /** + * Basic Auth password + */ + protected static final String BASIC_AUTH_PASSWD = "basic_auth_passwd"; + + /** + * Basic Auth realm + */ + protected static final String BASIC_AUTH_REALM = "basic_auth_realm"; + + protected static final String UNAUTH_USERNAME = "authuser"; + + protected static final String UNAUTH_PASSWORD = "authpassword"; + + + // Constants: + protected static final String USERNAME = "user"; + + protected static final String PASSWORD = "password"; + + /** + * Unordered search string property + */ + protected static final String UNORDERED_SEARCH_STRING = "unordered_search_string"; + + /** + * Content property + */ + protected static final String CONTENT = "content"; + + /** + * Test name property + */ + protected static final String TEST_NAME = "testname"; + + /** + * Response Match property + */ + protected static final String RESPONSE_MATCH = "response_match"; + + /** + * Unexpected response match property + */ + protected static final String UNEXPECTED_RESPONSE_MATCH = "unexpected_response_match"; + + /** + * Standard test property + */ + protected static final String STANDARD = "standard"; + + /** + * Ignore response body + */ + protected static final String IGNORE_BODY = "ignore_body"; + + /** + * Validation strategy + */ + protected static final String STRATEGY = "strategy"; + + /** + * Current test directory + */ + protected String TESTDIR = null; + + /** + * Goldenfile directory + */ + protected String GOLDENFILEDIR = "/src/web"; + + /** + * Default request method + */ + protected static final String GET = "GET "; + + /** + * HTTP 1.0 + */ + protected static final String HTTP10 = " HTTP/1.0"; + + /** + * HTTP 1.1 + */ + protected static final String HTTP11 = " HTTP/1.1"; + + /** + * Forward slash + */ + protected static final String SL = "/"; + + /** + * Goldenfile suffix + */ + protected static final String GF_SUFFIX = ".gf"; + + /** + * JSP suffix + */ + protected static final String JSP_SUFFIX = ".jsp"; + + /** + * Use any saved state + */ + protected static final String USE_SAVED_STATE = "use_saved_state"; + + /** + * Save current HTTP state. + */ + protected static final String SAVE_STATE = "save_state"; + + /** + * Ignore HTTP status codes + */ + protected static final String IGNORE_STATUS_CODE = "ignore_status_code"; + + /** + * Current test name + */ + protected String _testName = null; + + /** + * location of _tsHome + */ + protected String _tsHome = null; + + /** + * Context root of target tests + */ + protected String _contextRoot = null; + + /** + * General file/request URI for both gfiles and tests + */ + protected String _generalURI = null; + + /** + * Target webserver hostname + */ + protected String _hostname = null; + + /** + * Target webserver port + */ + protected int _port = 0; + + /** + * HttpState that may be used for multiple invocations requiring state. + */ + protected HttpState _state = null; + + /** + * Test case. + */ + protected WebTestCase _testCase = null; + + /** + * Use saved state. + */ + protected boolean _useSavedState = false; + + /** + * Save state. + */ + protected boolean _saveState = false; + + /** + * Follow redirect. + */ + protected static final String FOLLOW_REDIRECT = "follow_redirect"; + + protected boolean _redirect = false; + + /* + * public methods + * ======================================================================== + */ + + /** + * setTestDir sets the current test directory. + * + * @param testDir + * a String value + */ + public void setTestDir(String testDir) { + TESTDIR = testDir; + // setGoldenFileDir(testDir); + } + + public void setGeneralURI(String URI) { + _generalURI = URI; + } + + public void setContextRoot(String root) { + _contextRoot = root; + } + + public String getContextRoot() { + return _contextRoot; + } + + /** + * Sets the goldenfile directory + * + * @param goldenDir + * goldenfile directory based off test directory + */ + public void setGoldenFileDir(String goldenDir) { + GOLDENFILEDIR = goldenDir; + } + + @BeforeEach + public void setup() throws Exception { + String ctxRoot = url.getPath(); + setContextRoot(ctxRoot.endsWith("/")?ctxRoot.substring(0, ctxRoot.length()-1):ctxRoot); + Properties properties = new Properties(); + properties.put(SERVLETHOSTPROP, url.getHost()); + properties.put(SERVLETPORTPROP, Integer.toString(url.getPort())); + // TODO do we really need this?? + properties.put(TSHOME, Paths.get("target/test-classes").toFile().getName()); + // TOFIX configuration + properties.setProperty("servlet_waittime", System.getProperty("servlet_waittime","10")); + properties.setProperty("servlet_async_wait", System.getProperty("servlet_async_wait","4")); + properties.setProperty("logical.hostname.servlet", System.getProperty("logical.hostname.servlet","server")); + properties.setProperty(USERNAME, System.getProperty(USERNAME, "j2ee")); + properties.setProperty(PASSWORD, System.getProperty(PASSWORD, "j2ee")); + properties.setProperty(BASIC_AUTH_PASSWD, System.getProperty(UNAUTH_PASSWORD, "j2ee")); + properties.setProperty(BASIC_AUTH_USER, System.getProperty(BASIC_AUTH_USER, "j2ee")); + properties.setProperty(BASIC_AUTH_PASSWD, System.getProperty(UNAUTH_PASSWORD, "j2ee")); + properties.setProperty(UNAUTH_USERNAME, System.getProperty(UNAUTH_USERNAME, "javajoe")); + properties.setProperty(UNAUTH_PASSWORD, System.getProperty(UNAUTH_PASSWORD, "javajoe")); + setup(null, properties); + } + + + /** + * setup is by the test harness to initialize the tests. + * + * @param args + * a String[] value + * @param p + * a Properties value + */ + public void setup(String[] args, Properties p) throws Exception { + _props = p; + String hostname = p.getProperty(SERVLETHOSTPROP).trim(); + String portnum = p.getProperty(SERVLETPORTPROP).trim(); + String tshome = p.getProperty(TSHOME).trim(); + + if (!isNullOrEmpty(hostname)) { + _hostname = hostname; + } else { + throw new IllegalArgumentException( + "[BaseUrlClient] 'webServerHost' was not set in the" + " ts.jte."); + } + + if (!isNullOrEmpty(portnum)) { + _port = Integer.parseInt(portnum); + } else { + throw new IllegalArgumentException( + "[BaseUrlClient] 'webServerPort' was not set in the" + " ts.jte."); + } + + if (!isNullOrEmpty(tshome)) { + _tsHome = tshome; + } else { + throw new IllegalArgumentException( + "[BaseUrlClient] 'tshome' was not set in the " + " ts.jte."); + } + + logger.debug("[BaseUrlClient] Test setup OK using properties {}", p); + } + + /** + * cleanup is called by the test harness to cleanup after text + * execution + * + */ + public void cleanup() throws Exception { + logger.info("[BaseUrlClient] Test cleanup OK"); + } + + /* + * protected methods + * ======================================================================== + */ + + /** + *
+   * Invokes a test based on the properties
+    * stored in TEST_PROPS.  Once the test has completed,
+    * the properties in TEST_PROPS will be cleared.
+   * 
+ * + */ + protected void invoke() { + try { + _testCase = new WebTestCase(); + setTestProperties(_testCase); + logger.trace("[BaseUrlClient] EXECUTING"); + if (_useSavedState && _state != null) { + _testCase.getRequest().setState(_state); + } + if (_redirect) { + logger.trace("##########Call setFollowRedirects"); + _testCase.getRequest().setFollowRedirects(_redirect); + } + _testCase.execute(); + if (_saveState) { + _state = _testCase.getResponse().getState(); + } + } catch (Exception tfe) { + Throwable t = tfe.getCause(); + if (t != null) { + logger.warn("Root cause of Failure: " + t.getMessage(), t); + } + logger.error("Test: '" + _testName + "' failed.", tfe); + throw new RuntimeException("[BaseUrlClient] " + _testName + " failed! Check output for cause of failure.", tfe); + } finally { + _useSavedState = false; + _saveState = false; + _redirect = false; + clearTestProperties(); + } + } + + /** + *
+   * Sets the appropriate test properties based
+    * on the values stored in TEST_PROPS
+   * 
+ */ + protected void setTestProperties(WebTestCase testCase) { + HttpRequest req = testCase.getRequest(); + + // Check for a request object. If doesn't exist, then + // check for a REQUEST property and create the request object. + + if (req == null) { + String request = TEST_PROPS.getProperty(REQUEST); + + if (request.startsWith("GET") || request.startsWith("POST") + || request.startsWith("OPTIONS") || request.startsWith("PUT") + || request.startsWith("DELETE") || request.startsWith("HEAD") + || request.endsWith(HTTP10) || request.endsWith(HTTP11)) { + // user has overriden default request behavior + req = new HttpRequest(request, _hostname, _port); + testCase.setRequest(req); + } else { + req = new HttpRequest(getTSRequest(request), _hostname, _port); + testCase.setRequest(req); + } + } + + String key = null; + String value = null; + // process the remainder of the properties + for (Enumeration e = TEST_PROPS.propertyNames(); e.hasMoreElements();) { + key = (String) e.nextElement(); + value = TEST_PROPS.getProperty(key); + + switch (key) { + case TEST_NAME: + testCase.setName(value); + _testName = value; + break; + case STATUS_CODE: + testCase.setExpectedStatusCode(value); + break; + case IGNORE_STATUS_CODE: + testCase.setExpectedStatusCode("-1"); + break; + case REASON_PHRASE: + testCase.setExpectedReasonPhrase(value); + break; + case EXPECTED_HEADERS: + testCase.addExpectedHeader(value); + break; + case UNEXPECTED_HEADERS: + testCase.addUnexpectedHeader(value); + break; + case SEARCH_STRING: + testCase.setResponseSearchString(value); + break; + case SEARCH_STRING_IGNORE_CASE: + testCase.setResponseSearchStringIgnoreCase(value); + break; + case STRATEGY: + testCase.setStrategy(value); + break; + case CONTENT: + req.setContent(value); + break; + case RESPONSE_MATCH: + // setResponseMatch(TEST_PROPS.getProperty(key)); + break; + case REQUEST_HEADERS: + req.addRequestHeader(TEST_PROPS.getProperty(key)); + break; + case EXPECT_RESPONSE_BODY: + // FIXME + // setExpectResponseBody(false); + break; + case UNEXPECTED_RESPONSE_MATCH: + testCase.setUnexpectedResponseSearchString(value); + break; + case UNORDERED_SEARCH_STRING: + testCase.setUnorderedSearchString(value); + break; + case USE_SAVED_STATE: + _useSavedState = true; + break; + case SAVE_STATE: + _saveState = true; + break; + case FOLLOW_REDIRECT: + logger.debug("##########Found redirect Property"); + _redirect = true; + break; + case BASIC_AUTH_USER: + case BASIC_AUTH_PASSWD: + case BASIC_AUTH_REALM: + String user = TEST_PROPS.getProperty(BASIC_AUTH_USER); + String password = TEST_PROPS.getProperty(BASIC_AUTH_PASSWD); + String realm = TEST_PROPS.getProperty(BASIC_AUTH_REALM); + req.setAuthenticationCredentials(user, password, HttpRequest.BASIC_AUTHENTICATION, realm); + break; + default: + // no op + } + + } + } + + /* + * private methods + * ======================================================================== + */ + + private String getTSRequest(String request) { + StringBuilder finReq = new StringBuilder(50); + + finReq.append(GET).append(_contextRoot).append(SL).append(_generalURI); + finReq.append(SL).append(request).append(HTTP10); + + return finReq.toString(); + } + + /** + * Clears the contents of TEST_PROPS + */ + private void clearTestProperties() { + TEST_PROPS.clear(); + } + + private boolean isNullOrEmpty(String val) { + return val == null || val.equals(""); + } + + public void logErr(String message) { + logger.error(message); + } + + public void logErr(String message, Exception e) { + logger.error(message, e); + } + + public void logMsg(String message) { + logger.info(message); + } + + public void logTrace(String message) { + logger.trace(message); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/client/handler/ALLOWHandler.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/client/handler/ALLOWHandler.java new file mode 100644 index 0000000000..56c9fc5e7e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/client/handler/ALLOWHandler.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2008, 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$ + */ +package com.sun.ts.tests.servlet.common.client.handler; + +import com.sun.ts.lib.util.TestUtil; +import org.apache.commons.httpclient.Header; + +import java.util.StringTokenizer; + +public class ALLOWHandler implements Handler { + + private static final Handler HANDLER = new ALLOWHandler(); + + private static final String DELIM = "##"; + + private ALLOWHandler() { + } + + public static Handler getInstance() { + return HANDLER; + } + + public boolean invoke(Header configuredHeader, Header responseHeader) { + String ALLOWHeader = responseHeader.getValue().toLowerCase(); + String expectedValues = configuredHeader.getValue().toLowerCase() + .replace(" ", ""); + + TestUtil.logTrace("[ALLOWHandler] ALLOW header received: " + ALLOWHeader); + + StringTokenizer conf = new StringTokenizer(expectedValues, ","); + while (conf.hasMoreTokens()) { + String token = conf.nextToken(); + String token1 = token; + + if ((ALLOWHeader.indexOf(token) < 0) + && (ALLOWHeader.indexOf(token1) < 0)) { + TestUtil.logErr("[ALLOWHandler] Unable to find '" + token + + "' within the ALLOW header returned by the server."); + return false; + } else { + TestUtil.logTrace("[ALLOWHandler] Found expected value, '" + token + + "' in ALLOW header returned by server."); + } + } + return true; + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/client/handler/ContentTypeHandler.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/client/handler/ContentTypeHandler.java new file mode 100644 index 0000000000..77992bf5a8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/client/handler/ContentTypeHandler.java @@ -0,0 +1,152 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000 The Apache Software Foundation. All rights + * Copyright (c) 2000 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" must + * not be used to endorse or promote products derived from this + * software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * nor may "Apache" appear in their name, without prior written + * permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * Portions of this software are based upon public domain software + * originally written at the National Center for Supercomputing Applications, + * University of Illinois, Urbana-Champaign. + */ + +package com.sun.ts.tests.servlet.common.client.handler; + +import com.sun.ts.lib.util.TestUtil; +import org.apache.commons.httpclient.Header; + +/** + *
+ * When invoked, the content-type header
+ * will be appropriately handled.  It allows
+ * flexible checking of control values against
+ * the response which could be in the form of:
+ *    content-type; charset
+ *      -or-
+ *    conent-type
+ * 
+ */ +public class ContentTypeHandler implements Handler { + + private static Handler handler = new ContentTypeHandler(); + + /** + * Creates new ContentTypeHandler + */ + private ContentTypeHandler() { + } + + /* + * public methods + * ======================================================================== + */ + + /** + * Returns an instance of this handler. + */ + public static Handler getInstance() { + return handler; + } + + /** + * Invokes handler logic. + * + * @param configuredHeader + * the user configured header + * @param responseHeader + * the response header from the server + * @return True if the passed match, otherwise false + */ + public boolean invoke(Header configuredHeader, Header responseHeader) { + boolean ret = false; + TestUtil.logTrace("[ContentTypeHandler] ContentTypeHandler invoked."); + String configVal = configuredHeader.getValue().trim(); + String responseVal = responseHeader.getValue().trim(); + int colIdx = configVal.indexOf(';'); + if (colIdx < 0) { + // Info we're interested in : type/subtype + + // check response Content-Type header to see what format + // it's in. + int rColIdx = responseVal.indexOf(';'); + if (rColIdx < 0) { + // Type and subtype, i.e. type/subtype are to be compared + // case insensitively. + if (configVal.equalsIgnoreCase(responseVal)) { + ret = true; + } + } else { + if (configVal.equalsIgnoreCase(responseVal.substring(0, rColIdx))) { + ret = true; + } + } + } else { + // Info we're interested in : type/subtype; parameter=value + + int rColIdx = responseVal.indexOf(';'); + if (rColIdx > -1) { + String confTypeSubType = configVal.substring(0, colIdx).trim(); + String responseTypeSubType = responseVal.substring(0, rColIdx).trim(); + String confParameter = configVal.substring(colIdx + 1).trim(); + String responseParameter = (responseVal.substring(rColIdx + 1).trim()) + .replaceAll(" ", ""); + // compare type/subtype in a case insensitive manner + if (confTypeSubType.equalsIgnoreCase(responseTypeSubType)) { + // next validate the parameter in a case insensitive manner + if (confParameter.equalsIgnoreCase(responseParameter)) { + ret = true; + } + } + } + } + return ret; + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/client/handler/DefaultHandler.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/client/handler/DefaultHandler.java new file mode 100644 index 0000000000..aa4ba97320 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/client/handler/DefaultHandler.java @@ -0,0 +1,144 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000 The Apache Software Foundation. All rights + * Copyright (c) 2000 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" must + * not be used to endorse or promote products derived from this + * software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * nor may "Apache" appear in their name, without prior written + * permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * Portions of this software are based upon public domain software + * originally written at the National Center for Supercomputing Applications, + * University of Illinois, Urbana-Champaign. + */ + +package com.sun.ts.tests.servlet.common.client.handler; + +import com.sun.ts.lib.util.TestUtil; +import org.apache.commons.httpclient.Header; +import org.apache.commons.httpclient.HeaderElement; + +/** + *
+ * The default handler will handle any
+ * header that doesn't have a configured handler.
+ * 
+ */ +public class DefaultHandler implements Handler { + + private static Handler handler = new DefaultHandler(); + + /** + * Creates new DefaultHandler + */ + private DefaultHandler() { + } + + /* + * public methods + * ======================================================================== + */ + + /** + * Returns an instance of this handler. + */ + public static Handler getInstance() { + return handler; + } + + /** + * Invokes handler logic. + * + * @param configuredHeader + * the user configured header + * @param responseHeader + * the response header from the server + * @return True if the passed match, otherwise false + */ + public boolean invoke(Header configuredHeader, Header responseHeader) { + + TestUtil.logTrace("[DefaulHandler] DefaultHandler invoked."); + + return areHeadersEqual(configuredHeader, responseHeader); + } + + /** + * Utility method to determine equality of two Header objects + * + * @param h1 + * first header + * @param h2 + * second header + * @return true if the headers are equal, otherwise false + */ + protected boolean areHeadersEqual(Header h1, Header h2) { + + HeaderElement[] h1Values = h1.getElements(); + HeaderElement[] h2Values = h2.getElements(); + + if (h1Values.length == h2Values.length) { + for (HeaderElement h1Value : h1Values) { + String h1Val = h1Value.getName(); + boolean found = false; + for (HeaderElement h2Value : h2Values) { + if (h1Val.equals(h2Value.getName())) { + found = true; + break; + } + } + if (!found) { + return false; + } + } + return true; + } else { + return false; + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/client/handler/Handler.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/client/handler/Handler.java new file mode 100644 index 0000000000..405811e8e4 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/client/handler/Handler.java @@ -0,0 +1,84 @@ +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2007, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" must + * not be used to endorse or promote products derived from this + * software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * nor may "Apache" appear in their name, without prior written + * permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * Portions of this software are based upon public domain software + * originally written at the National Center for Supercomputing Applications, + * University of Illinois, Urbana-Champaign. + */ +package com.sun.ts.tests.servlet.common.client.handler; + +import org.apache.commons.httpclient.Header; + +/** + * Handler interface. + */ +public interface Handler { + + /* + * public methods + * ======================================================================== + */ + + /** + * Invokes handler logic. + * + * @param configuredHeader + * the user configured header + * @param responseHeader + * the response header from the server + * @return True if the passed match, otherwise false + */ + public boolean invoke(Header configuredHeader, Header responseHeader); + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/client/handler/HandlerFactory.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/client/handler/HandlerFactory.java new file mode 100644 index 0000000000..5afd1412e6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/client/handler/HandlerFactory.java @@ -0,0 +1,126 @@ +/* ==================================================================== + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2007, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" must + * not be used to endorse or promote products derived from this + * software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * nor may "Apache" appear in their name, without prior written + * permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * Portions of this software are based upon public domain software + * originally written at the National Center for Supercomputing Applications, + * University of Illinois, Urbana-Champaign. + */ + +package com.sun.ts.tests.servlet.common.client.handler; + +/** + *
+ * The HandlerManager is responsible for returning the appropriate handler
+ * instance based on the provided value.
+ */
+public class HandlerFactory {
+
+  /**
+   * Content-Type handler name.
+   */
+  private static final String CONTENT_TYPE = "content-type";
+
+  /**
+   * Location handler name.
+   */
+  private static final String LOCATION = "location";
+
+  /**
+   * Set-Cookie handler name.
+   */
+  private static final String SET_COOKIE = "set-cookie";
+
+  /**
+   * ALLOW handler name.
+   */
+  private static final String ALLOW = "allow";
+
+  /**
+   * www-authenticate handler name.
+   */
+  private static final String WWW_AUTH = "www-authenticate";
+  /*
+   * public methods
+   * ========================================================================
+   */
+
+  /**
+   * Constructs a new HandlerManager instance
+   */
+  private HandlerFactory() {
+  }
+
+  /**
+   * Returns the appropriate handler instance based on provided discriminate (a
+   * header name).
+   *
+   * @param handlerName
+   *          handler instance to obtain.
+   */
+  public static Handler getHandler(String handlerName) {
+    if (CONTENT_TYPE.equals(handlerName.toLowerCase())) {
+      return ContentTypeHandler.getInstance();
+    } else if (LOCATION.equals(handlerName.toLowerCase())) {
+      return LocationHandler.getInstance();
+    } else if (SET_COOKIE.equals(handlerName.toLowerCase())) {
+      return SetCookieHandler.getInstance();
+    } else if (WWW_AUTH.equals(handlerName.toLowerCase())) {
+      return WWWAuthenticateHandler.getInstance();
+    } else if (ALLOW.equals(handlerName.toLowerCase())) {
+      return ALLOWHandler.getInstance();
+    } else {
+      return DefaultHandler.getInstance();
+    }
+  }
+}
diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/client/handler/LocationHandler.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/client/handler/LocationHandler.java
new file mode 100644
index 0000000000..da08e344c8
--- /dev/null
+++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/client/handler/LocationHandler.java
@@ -0,0 +1,161 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000 The Apache Software Foundation.  All rights
+ * Copyright (c) 2000 The Apache Software Foundation.  All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "Apache" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written
+ *    permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
+ */
+
+package com.sun.ts.tests.servlet.common.client.handler;
+
+import com.sun.ts.lib.util.TestUtil;
+import org.apache.commons.httpclient.Header;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+/**
+ * 
+ * Will handle headers for the following
+ * cases:
+ *   - Server is on port 80 and port value isn't
+ *     propagated back to client (assumed)
+ *   - Port value is in response
+ * 
+ */ +public class LocationHandler implements Handler { + + private static Handler handler = new LocationHandler(); + + /** + * Creates new ContentTypeHandler + */ + private LocationHandler() { + } + + /* + * public methods + * ======================================================================== + */ + + /** + * Returns an instance of this handler. + */ + public static Handler getInstance() { + return handler; + } + + /** + * Invokes handler logic. + * + * @param configuredHeader + * the user configured header + * @param responseHeader + * the response header from the server + * @return True if the passed match, otherwise false + */ + public boolean invoke(Header configuredHeader, Header responseHeader) { + + boolean pass = true; + + try { + TestUtil.logTrace("[LocationHandler] LocationHandler invoked."); + + URL configURL = new URL(configuredHeader.getValue()); + URL responseURL = new URL(responseHeader.getValue()); + + if (!(configURL.getProtocol().equals(responseURL.getProtocol()))) { + pass = false; + TestUtil.logErr("[LocationHandler] Mismatch between protocols:"); + TestUtil.logErr( + "[LocationHandler] Configured value: " + configURL.getProtocol()); + TestUtil.logErr( + "[LocationHandler] Response value: " + responseURL.getProtocol()); + } + + if (!(configURL.getPath().equals(responseURL.getPath()))) { + pass = false; + TestUtil.logErr("[LocationHandler] Mismatch between paths:"); + TestUtil.logErr( + "[LocationHandler] Configured value: " + configURL.getPath()); + TestUtil.logErr( + "[LocationHandler] Response value: " + responseURL.getPath()); + } + + if (configURL.getQuery() == null) { + if (responseURL.getQuery() != null) { + pass = false; + TestUtil.logErr("[LocationHandler] Mismatch between querys:"); + TestUtil.logErr("[LocationHandler] Configured value is null"); + TestUtil.logErr("[LocationHandler] Response value is non-null"); + } + } else if (!(configURL.getQuery().equals(responseURL.getQuery()))) { + pass = false; + TestUtil.logErr("[LocationHandler] Mismatch between querys:"); + TestUtil.logErr( + "[LocationHandler] Configured value: " + configURL.getQuery()); + TestUtil.logErr( + "[LocationHandler] Response value: " + responseURL.getQuery()); + } + + } catch (MalformedURLException mue) { + pass = false; + TestUtil.logErr("[LocationHandler] MalformedURLException"); + TestUtil.printStackTrace(mue); + } + + return pass; + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/client/handler/SetCookieHandler.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/client/handler/SetCookieHandler.java new file mode 100644 index 0000000000..72136ecb9a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/client/handler/SetCookieHandler.java @@ -0,0 +1,83 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.common.client.handler; + +import com.sun.ts.lib.util.TestUtil; +import org.apache.commons.httpclient.Header; + +import java.util.StringTokenizer; + +public class SetCookieHandler implements Handler { + + private static final Handler HANDLER = new SetCookieHandler(); + + private static final String DELIM = "##"; + + private SetCookieHandler() { + } + + public static Handler getInstance() { + return HANDLER; + } + + public boolean invoke(Header configuredHeader, Header responseHeader) { + String setCookieHeader = responseHeader.getValue().toLowerCase(); + String expectedValues = configuredHeader.getValue().toLowerCase(); + + TestUtil.logTrace( + "[SetCookieHandler] Set-Cookie header received: " + setCookieHeader); + + StringTokenizer conf = new StringTokenizer(expectedValues, DELIM); + while (conf.hasMoreTokens()) { + String token = conf.nextToken(); + String token1 = token; + + if (token.endsWith("\"") && (token.indexOf("=\"") > 1)) { + token1 = token.replace("=\"", "="); + token1 = token1.substring(0, token.length() - 2); + } + + if (token.startsWith("!")) { + String attr = token.substring(1); + String attr1 = token1.substring(1); + if ((setCookieHeader.indexOf(attr) > -1) + || (setCookieHeader.indexOf(attr1) > -1)) { + TestUtil.logErr("[SetCookieHandler] Unexpected attribute found " + + " Set-Cookie header. Attribute: " + attr + + "\nSet-Cookie header: " + setCookieHeader); + return false; + } + } else { + if ((setCookieHeader.indexOf(token) < 0) + && (setCookieHeader.indexOf(token1) < 0)) { + TestUtil.logErr("[SetCookieHandler] Unable to find '" + token + + "' within the Set-Cookie header returned by the server."); + return false; + } else { + TestUtil.logTrace("[SetCookieHandler] Found expected value, '" + token + + "' in Set-Cookie header returned by server."); + } + } + } + + return true; + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/client/handler/WWWAuthenticateHandler.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/client/handler/WWWAuthenticateHandler.java new file mode 100644 index 0000000000..ab2b8a50d3 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/client/handler/WWWAuthenticateHandler.java @@ -0,0 +1,112 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000 The Apache Software Foundation. All rights + * Copyright (c) 2000 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, + * if any, must include the following acknowledgment: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowledgment may appear in the software itself, + * if and wherever such third-party acknowledgments normally appear. + * + * 4. The names "Apache" and "Apache Software Foundation" must + * not be used to endorse or promote products derived from this + * software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache", + * nor may "Apache" appear in their name, without prior written + * permission of the Apache Software Foundation. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * Portions of this software are based upon public domain software + * originally written at the National Center for Supercomputing Applications, + * University of Illinois, Urbana-Champaign. + */ + +package com.sun.ts.tests.servlet.common.client.handler; + +import com.sun.ts.lib.util.TestUtil; +import org.apache.commons.httpclient.Header; + +/** + *
+ * Will handle headers for the following
+ * cases:
+ *   - Server is on port 80 and port value isn't
+ *     propagated back to client (assumed)
+ *   - Port value is in response
+ * 
+ */ +public class WWWAuthenticateHandler implements Handler { + + private static Handler handler = new WWWAuthenticateHandler(); + + /** + * Creates new ContentTypeHandler + */ + private WWWAuthenticateHandler() { + } + + /* + * public methods + * ======================================================================== + */ + + /** + * Returns an instance of this handler. + */ + public static Handler getInstance() { + return handler; + } + + /** + * Invokes handler logic. + * + * @param configuredHeader + * the user configured header + * @param responseHeader + * the response header from the server + * @return True if the passed match, otherwise false + */ + public boolean invoke(Header configuredHeader, Header responseHeader) { + + TestUtil + .logTrace("[WWWAuthenticateHandler] WWAuthenticateHandler invoked."); + return true; + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/request/HttpRequest.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/request/HttpRequest.java new file mode 100644 index 0000000000..e59e7f092d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/request/HttpRequest.java @@ -0,0 +1,581 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.common.request; + +import org.apache.commons.httpclient.Cookie; +import org.apache.commons.httpclient.Header; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.HttpConnection; +import org.apache.commons.httpclient.HttpException; +import org.apache.commons.httpclient.HttpMethod; +import org.apache.commons.httpclient.HttpState; +import org.apache.commons.httpclient.UsernamePasswordCredentials; +import org.apache.commons.httpclient.auth.AuthScope; +import org.apache.commons.httpclient.cookie.CookiePolicy; +import org.apache.commons.httpclient.methods.EntityEnclosingMethod; +import org.apache.commons.httpclient.methods.StringRequestEntity; +import org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory; +import org.apache.commons.httpclient.protocol.Protocol; +import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; +import org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.Base64; +import java.util.StringTokenizer; + +/** + * Represents an HTTP client Request + */ + +public class HttpRequest { + + +// static { +// if (TestUtil.traceflag) { +// System.setProperty("org.apache.commons.logging.Log", +// "com.sun.ts.tests.common.webclient.log.WebLog"); +// System.setProperty( +// "org.apache.commons.logging.simplelog.log.httpclient.wire", "debug"); +// } +// } + + private static final Logger LOGGER = LoggerFactory.getLogger(HttpRequest.class); + + /** + * Default HTTP port. + */ + public static int DEFAULT_HTTP_PORT = 80; + + /** + * Default HTTP SSL port. + */ + public static final int DEFAULT_SSL_PORT = 443; + + /** + * No authentication + */ + public static final int NO_AUTHENTICATION = 0; + + /** + * Basic authentication + */ + public static final int BASIC_AUTHENTICATION = 1; + + /** + * Digest authenctication + */ + public static final int DIGEST_AUTHENTICATION = 2; + + /** + * Method representation of request. + */ + private HttpMethod _method = null; + + /** + * Target web container host + */ + private String _host = null; + + /** + * Target web container port + */ + private int _port = DEFAULT_HTTP_PORT; + + /** + * Is the request going over SSL + */ + private boolean _isSecure = false; + + /** + * HTTP state + */ + private HttpState _state = null; + + /** + * Original request line for this request. + */ + private String _requestLine = null; + + /** + * Authentication type for current request + */ + private int _authType = NO_AUTHENTICATION; + + /** + * Flag to determine if session tracking will be used or not. + */ + private boolean _useCookies = false; + + /** + * Content length of request body. + */ + private int _contentLength = 0; + + /** + * FollowRedirects + */ + private boolean _redirect = false; + + Header[] _headers = null; + + protected HttpClient client = null; + + /** + * Creates new HttpRequest based of the passed request line. The request line + * provied must be in the form of:
+ * + *
+   *     METHOD PATH HTTP-VERSION
+   *     Ex.  GET /index.html HTTP/1.0
+   * 
+ */ + public HttpRequest(String requestLine, String host, int port) { + client = new HttpClient(); + _method = MethodFactory.getInstance(requestLine); + _method.setFollowRedirects(false); + _host = host; + _port = port; + + if (port == DEFAULT_SSL_PORT) { + _isSecure = true; + } + + // If we got this far, the request line is in the proper + // format + _requestLine = requestLine; + } + + /* + * public methods + * ======================================================================== + */ + + /** + * getRequestPath returns the request path for this particular + * request. + * + * @return String request path + */ + public String getRequestPath() { + return _method.getPath(); + } + + /** + * getRequestMethod returns the request type, i.e., GET, POST, + * etc. + * + * @return String request type + */ + public String getRequestMethod() { + return _method.getName(); + } + + /** + * isSecureConnection() indicates if the Request is secure or + * not. + * + * @return boolean whether Request is using SSL or not. + */ + public boolean isSecureRequest() { + return _isSecure; + } + + /** + * setSecureRequest configures this request to use SSL. + * + * @param secure + * - whether the Request uses SSL or not. + */ + public void setSecureRequest(boolean secure) { + _isSecure = secure; + } + + /** + * setContent will set the body for this request. Note, this is + * only valid for POST and PUT operations, however, if called and the request + * represents some other HTTP method, it will be no-op'd. + * + * @param content + * request content + */ + public void setContent(String content) { + if (_method instanceof EntityEnclosingMethod) { + ((EntityEnclosingMethod) _method) + .setRequestEntity(new StringRequestEntity(content)); + } + _contentLength = content.length(); + } + + /** + * setAuthenticationCredentials configures the request to + * perform authentication. + * + *

username and password cannot be null. + *

+ * + *

+ * It is legal for realm to be null. + *

+ * + * @param username + * the user + * @param password + * the user's password + * @param authType + * authentication type + * @param realm + * authentication realm + */ + public void setAuthenticationCredentials(String username, String password, + int authType, String realm) { + if (username == null) { + throw new IllegalArgumentException("Username cannot be null"); + } + + if (password == null) { + throw new IllegalArgumentException("Password cannot be null"); + } + + UsernamePasswordCredentials cred = new UsernamePasswordCredentials(username, + password); + AuthScope scope = new AuthScope(_host, _port, realm); + getState().setCredentials(scope, cred); + + LOGGER.debug("Added credentials for '{}' with password '{}' in realm '{}'", username, password, realm); + + _authType = authType; + } + + /** + * addRequestHeader adds a request header to this request. If a + * request header of the same name already exists, the new value, will be + * added to the set of already existing values. + * + * NOTE: that header names are not case-sensitive. + * + * @param headerName + * request header name + * @param headerValue + * request header value + */ + public void addRequestHeader(String headerName, String headerValue) { + _method.addRequestHeader(headerName, headerValue); + LOGGER.debug("Added request header: {}", _method.getRequestHeader(headerName).toExternalForm()); + } + + public void addRequestHeader(String header) { + StringTokenizer st = new StringTokenizer(header, "|"); + while (st.hasMoreTokens()) { + String h = st.nextToken(); + if (h.toLowerCase().startsWith("cookie")) { + createCookie(h); + continue; + } + int col = h.indexOf(':'); + addRequestHeader(h.substring(0, col).trim(), h.substring(col + 1).trim()); + } + } + + /** + * setRequestHeader sets a request header for this request + * overwritting any previously existing header/values with the same name. + * + * NOTE: Header names are not case-sensitive. + * + * @param headerName + * request header name + * @param headerValue + * request header value + */ + public void setRequestHeader(String headerName, String headerValue) { + _method.setRequestHeader(headerName, headerValue); + LOGGER.trace("Set request header: {}", _method.getRequestHeader(headerName).toExternalForm()); + + } + + /** + * setFollowRedirects indicates whether HTTP redirects are + * followed. By default, redirects are not followed. + */ + public void setFollowRedirects(boolean followRedirects) { + _method.setFollowRedirects(followRedirects); + } + + /** + * getFollowRedirects indicates whether HTTP redirects are + * followed. + */ + public boolean getFollowRedirects() { + return _method.getFollowRedirects(); + } + + /** + * setState will set the HTTP state for the current request (i.e. + * session tracking). This has the side affect + */ + public void setState(HttpState state) { + _state = state; + _useCookies = true; + } + + /** + * execute will dispatch the current request to the target + * server. + * + * @return HttpResponse the server's response. + * @throws IOException + * if an I/O error occurs during dispatch. + */ + public HttpResponse execute() throws IOException, HttpException { + String method; + int defaultPort; + ProtocolSocketFactory factory; + + if (_method.getFollowRedirects()) { + client = new HttpClient(); + + if (_isSecure) { + method = "https"; + defaultPort = DEFAULT_SSL_PORT; + factory = new SSLProtocolSocketFactory(); + } else { + method = "http"; + defaultPort = DEFAULT_HTTP_PORT; + factory = new DefaultProtocolSocketFactory(); + } + + Protocol protocol = new Protocol(method, factory, defaultPort); + HttpConnection conn = new HttpConnection(_host, _port, protocol); + + if (conn.isOpen()) { + throw new IllegalStateException("Connection incorrectly opened"); + } + + conn.open(); + + LOGGER.info("[HttpRequest] Dispatching request: '{}' to target server at '{}:{}'", _requestLine , _host, _port); + + addSupportHeaders(); + _headers = _method.getRequestHeaders(); + + LOGGER.debug( + "########## The real value set: {}", _method.getFollowRedirects()); + + client.getHostConfiguration().setHost(_host, _port, protocol); + + client.executeMethod(_method); + + return new HttpResponse(_host, _port, _isSecure, _method, getState()); + } else { + if (_isSecure) { + method = "https"; + defaultPort = DEFAULT_SSL_PORT; + factory = new SSLProtocolSocketFactory(); + } else { + method = "http"; + defaultPort = DEFAULT_HTTP_PORT; + factory = new DefaultProtocolSocketFactory(); + } + + Protocol protocol = new Protocol(method, factory, defaultPort); + HttpConnection conn = new HttpConnection(_host, _port, protocol); + + if (conn.isOpen()) { + throw new IllegalStateException("Connection incorrectly opened"); + } + + conn.open(); + + LOGGER.info("Dispatching request: '{}' to target server at '{}:{}'", _requestLine, _host, _port); + + addSupportHeaders(); + _headers = _method.getRequestHeaders(); + + LOGGER.debug("########## The real value set: {}", _method.getFollowRedirects()); + + _method.execute(getState(), conn); + + return new HttpResponse(_host, _port, _isSecure, _method, getState()); + } + } + + /** + * Returns the current state for this request. + * + * @return HttpState current state + */ + public HttpState getState() { + if (_state == null) { + _state = new HttpState(); + } + return _state; + } + + public String toString() { + StringBuilder sb = new StringBuilder(255); + sb.append("[REQUEST LINE] -> ").append(_requestLine).append('\n'); + + if (_headers != null && _headers.length != 0) { + + for (Header _header : _headers) { + sb.append("[REQUEST HEADER] -> "); + sb.append(_header.toExternalForm()).append('\n'); + } + } + + if (_contentLength != 0) { + sb.append("[REQUEST BODY LENGTH] -> ").append(_contentLength); + sb.append('\n'); + } + + return sb.toString(); + + } + + /* + * private methods + * ======================================================================== + */ + + private void createCookie(String cookieHeader) { + String cookieLine = cookieHeader.substring(cookieHeader.indexOf(':') + 1) + .trim(); + StringTokenizer st = new StringTokenizer(cookieLine, " ;"); + Cookie cookie = new Cookie(); + cookie.setVersion(1); + + getState(); + + if (cookieLine.indexOf("$Version") == -1) { + cookie.setVersion(0); + _method.getParams().setCookiePolicy(CookiePolicy.NETSCAPE); + } + + while (st.hasMoreTokens()) { + String token = st.nextToken(); + + if (token.charAt(0) != '$' && !token.startsWith("Domain") + && !token.startsWith("Path")) { + cookie.setName(token.substring(0, token.indexOf('='))); + cookie.setValue(token.substring(token.indexOf('=') + 1)); + } else if (token.indexOf("Domain") > -1) { + cookie.setDomainAttributeSpecified(true); + cookie.setDomain(token.substring(token.indexOf('=') + 1)); + } else if (token.indexOf("Path") > -1) { + cookie.setPathAttributeSpecified(true); + cookie.setPath(token.substring(token.indexOf('=') + 1)); + } + } + _state.addCookie(cookie); + + } + + /** + * Adds any support request headers necessary for this request. These headers + * will be added based on the state of the request. + */ + private void addSupportHeaders() { + + // Authentication headers + // NOTE: Possibly move logic to generic method + switch (_authType) { + case NO_AUTHENTICATION: + break; + case BASIC_AUTHENTICATION: + setBasicAuthorizationHeader(); + break; + case DIGEST_AUTHENTICATION: + throw new UnsupportedOperationException("Digest Authentication is not currently " + "supported"); + } + + // A Host header will be added to each request to handle + // cases where virtual hosts are used, or there is no DNS + // available on the system where the container is running. + setHostHeader(); + + // Content length header + setContentLengthHeader(); + + // Cookies + setCookieHeader(); + } + + /** + * Sets a basic authentication header in the request is Request is configured + * to use basic authentication + */ + private void setBasicAuthorizationHeader() { + UsernamePasswordCredentials cred = (UsernamePasswordCredentials) getState() + .getCredentials(new AuthScope(_host, _port, null)); + String authString = null; + if (cred != null) { + authString = "Basic " + new String(Base64.getEncoder().encode((cred.getUserName() + ":" + cred.getPassword()).getBytes())); + } else { + LOGGER.trace("[HttpRequest] NULL CREDENTIALS"); + } + _method.setRequestHeader("Authorization", authString); + } + + /** + * Sets a Content-Length header in the request if content is present + */ + private void setContentLengthHeader() { + if (_contentLength > 0) { + _method.setRequestHeader("Content-Length", Integer.toString(_contentLength)); + } + } + + /** + * Sets a host header in the request. If the configured host value is an IP + * address, the Host header will be sent, but without any value. + * + * If we adhered to the HTTP/1.1 spec, the Host header must be empty of the + * target server is identified via IP address. However, no user agents I've + * tested follow this. And if a custom client library does this, it may not + * work properly with the target server. For now, the Host request-header will + * always have a value. + */ + private void setHostHeader() { + if (_port == DEFAULT_HTTP_PORT || _port == DEFAULT_SSL_PORT) { + _method.setRequestHeader("Host", _host); + } else { + _method.setRequestHeader("Host", _host + ":" + _port); + } + } + + /** + * Sets a Cookie header if this request is using cookies. + */ + private void setCookieHeader() { + if (_useCookies) { + Cookie[] cookies = _state.getCookies(); + if (cookies != null && cookies.length > 0) { + Header cHeader = CookiePolicy.getCookieSpec(CookiePolicy.RFC_2109) + .formatCookieHeader(_state.getCookies()); + if (cHeader != null) { + _method.setRequestHeader(cHeader); + } + } + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/request/HttpRequestClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/request/HttpRequestClient.java new file mode 100644 index 0000000000..e43ee28066 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/request/HttpRequestClient.java @@ -0,0 +1,391 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.common.request; + +import com.sun.ts.tests.servlet.common.util.Data; + +public class HttpRequestClient extends RequestClient { + + + public void getAuthTypeWithoutProtectionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getAuthTypeWithoutProtectionTest"); + invoke(); + } + + + public void getAuthTypeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getAuthTypeTest"); + invoke(); + } + + + public void getContextPathTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getContextPathTest"); + TEST_PROPS.setProperty(REQUEST_HEADERS, "result:" + getContextRoot()); + invoke(); + } + + + public void getCookiesTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getCookiesTest"); + TEST_PROPS.setProperty(REQUEST_HEADERS, + "Cookie: cookie=value; Domain=" + _hostname + "; Path=/"); + invoke(); + } + + + public void getCookiesNoCookiesTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getCookiesNoCookiesTest"); + invoke(); + } + + + public void getDateHeaderTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getDateHeaderTest"); + TEST_PROPS.setProperty(REQUEST_HEADERS, + "If-Modified-Since:Sat, 01 Jan 2000 00:00:01 GMT"); + invoke(); + } + + + public void getDateHeaderNoHeaderTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getDateHeaderNoHeaderTest"); + invoke(); + } + + + public void getDateHeaderIllegalArgumentExceptionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, + "getDateHeaderIllegalArgumentExceptionTest"); + TEST_PROPS.setProperty(REQUEST_HEADERS, "If-Modified-Since:java"); + invoke(); + } + + + public void getHeaderTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getHeaderTest"); + TEST_PROPS.setProperty(REQUEST_HEADERS, "User-Agent: Mozilla/4.0"); + invoke(); + } + + + public void getHeaderNoHeaderTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getHeaderNoHeaderTest"); + invoke(); + } + + + public void getHeaderNamesTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getHeaderNamesTest"); + TEST_PROPS.setProperty(REQUEST_HEADERS, + "If-Modified-Since:Sat, 01 Jan 2000 00:00:01 GMT|Cookie:cookie=value"); + invoke(); + } + + + public void getHeaderNamesNoHeaderTest() throws Exception { + String testName = "getHeaderNamesNoHeaderTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + + getServletName() + "?testname=" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, Data.PASSED); + invoke(); + } + + + public void getHeadersTest() throws Exception { + String testName = "getHeadersTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + + getServletName() + "?testname=" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(REQUEST_HEADERS, "Accept-Language:en-us, ga-us"); + TEST_PROPS.setProperty(SEARCH_STRING, Data.PASSED); + invoke(); + + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + + getServletName() + "?testname=" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(REQUEST_HEADERS, + "Accept-Language:en-us|Accept-Language:ga-us"); + TEST_PROPS.setProperty(SEARCH_STRING, Data.PASSED); + invoke(); + + } + + + public void getHeadersNoHeadersTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getHeadersNoHeadersTest"); + invoke(); + } + + + public void getIntHeaderTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getIntHeaderTest"); + TEST_PROPS.setProperty(REQUEST_HEADERS, "MyIntHeader:123"); + invoke(); + } + + + public void getIntHeaderNumberFoundExceptionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getIntHeaderNumberFoundExceptionTest"); + TEST_PROPS.setProperty(REQUEST_HEADERS, "MyNonIntHeader:Java"); + invoke(); + } + + + public void getIntHeaderNoHeaderTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getIntHeaderNoHeaderTest"); + invoke(); + } + + + public void getMethodTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getMethod_GETTest"); + invoke(); + String testName = "getMethod_POSTTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "POST " + getContextRoot() + "/" + + getServletName() + "?testname=" + testName + " HTTP/1.1"); + invoke(); + testName = "getMethod_HEADTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "HEAD " + getContextRoot() + "/" + + getServletName() + "?testname=" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(EXPECTED_HEADERS, "status:" + Data.PASSED); + TEST_PROPS.setProperty(IGNORE_BODY, "true"); + invoke(); + } + + + public void getPathInfoTest() throws Exception { + String testName = "getPathInfoTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + getServletName() + + "/pathinfostring1/pathinfostring2?testname=" + testName + + " HTTP/1.1"); + invoke(); + } + + + public void getPathInfoNullTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getPathInfoNullTest"); + invoke(); + } + + + public void getPathTranslatedTest() throws Exception { + String testName = "getPathTranslatedTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + getServletName() + + "/jakarta_servlet?testname=" + testName + " HTTP/1.1"); + invoke(); + } + + + public void getPathTranslatedNullTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getPathTranslatedNullTest"); + invoke(); + } + + + public void getQueryStringTest() throws Exception { + String testName = "getQueryStringTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + + getServletName() + "?testname=" + testName + "&qs=value1 HTTP/1.1"); + invoke(); + } + + + public void getQueryStringNullTest() throws Exception { + String testName = "getQueryStringNullTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + testName + " HTTP/1.1"); + invoke(); + } + + + public void getRequestedSessionIdNullTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getRequestedSessionIdNullTest"); + invoke(); + } + + + public void getRequestedSessionIdTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getSessionTrueNoSessionTest"); + TEST_PROPS.setProperty(SAVE_STATE, "true"); + invoke(); + TEST_PROPS.setProperty(APITEST, "invalidateSessionId"); + TEST_PROPS.setProperty(SAVE_STATE, "true"); + TEST_PROPS.setProperty(USE_SAVED_STATE, "true"); + invoke(); + TEST_PROPS.setProperty(APITEST, "getRequestedSessionIdTest"); + TEST_PROPS.setProperty(SAVE_STATE, "true"); + TEST_PROPS.setProperty(USE_SAVED_STATE, "true"); + invoke(); + } + + + public void getRequestedSessionIdTest1() throws Exception { + String testName = "getRequestedSessionIdTest1"; + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + getServletName() + + ";jsessionid=c0o7fszeb1" + "?testname=" + testName + + "&TCKidsetto=c0o7fszeb1 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, + "Test returned with RequestdSessionId=c0o7fszeb1"); + invoke(); + } + + + public void getRequestedSessionIdTest2() throws Exception { + String testName = "getRequestedSessionIdTest2"; + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + getServletName() + + ";jsessionid=xyzc0o7fszeb1" + "?testname=" + testName + + "&TCKidsetto=xyzc0o7fszeb1 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, + "Test returned with RequestdSessionId=xyzc0o7fszeb1"); + invoke(); + } + + + public void getRemoteUserTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getRemoteUserTest"); + invoke(); + } + + + public void getRequestURITest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getRequestURITest"); + TEST_PROPS.setProperty(REQUEST_HEADERS, "result:" + getContextRoot()); + invoke(); + } + + + public void getServletPathTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletPathTest"); + invoke(); + } + + + public void getServletPathEmptyStringTest() throws Exception { + String testName = "getServletPathEmptyStringTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, Data.PASSED); + invoke(); + } + + + public void isRequestedSessionIdFromCookieTest() throws Exception { + String testName = "isRequestedSessionIdFromCookieTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + + getServletName() + "?testname=" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Actual result = false"); + invoke(); + } + + + public void isRequestedSessionIdFromCookieTest1() throws Exception { + + TEST_PROPS.setProperty(APITEST, "getSessionTest"); + TEST_PROPS.setProperty(SAVE_STATE, "true"); + TEST_PROPS.setProperty(USE_SAVED_STATE, "true"); + invoke(); + + String testName = "isRequestedSessionIdFromCookieTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + + getServletName() + "?testname=" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Actual result = true"); + TEST_PROPS.setProperty(USE_SAVED_STATE, "true"); + TEST_PROPS.setProperty(SAVE_STATE, "true"); + invoke(); + } + + + public void isRequestedSessionIdFromURLTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "isRequestedSessionIdFromURLTest"); + invoke(); + } + + + public void isRequestedSessionIdValidTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "isRequestedSessionIdValidTest"); + invoke(); + } + + + public void getSessionTrueTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getSessionTrueNoSessionTest"); + TEST_PROPS.setProperty(SAVE_STATE, "true"); + invoke(); + TEST_PROPS.setProperty(APITEST, "getSessionTrueSessionTest"); + TEST_PROPS.setProperty(USE_SAVED_STATE, "true"); + invoke(); + } + + + public void getSessionFalseTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getSessionFalseTest"); + invoke(); + } + + + public void getSessionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getSessionTest"); + invoke(); + } + + + public void getRequestURLTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getRequestURLTest"); + TEST_PROPS.setProperty(REQUEST_HEADERS, + "scheme:http|server:" + _hostname + "|port:" + _port + "|servletpath:" + + "-" + getContextRoot().substring(1, getContextRoot().length()) + + "-" + getServletName()); + invoke(); + } + + + public void sessionTimeoutTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "sessionTimeoutTest"); + invoke(); + } + + + public void changeSessionIDTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "changeSessionIDTest"); + invoke(); + } + + + public void changeSessionIDTest1() throws Exception { + TEST_PROPS.setProperty(APITEST, "changeSessionIDTest1"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/request/HttpResponse.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/request/HttpResponse.java new file mode 100644 index 0000000000..345935e8e9 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/request/HttpResponse.java @@ -0,0 +1,330 @@ +/* + * Copyright (c) 2006, 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$ + */ + +package com.sun.ts.tests.servlet.common.request; + +import org.apache.commons.httpclient.Header; +import org.apache.commons.httpclient.HttpMethod; +import org.apache.commons.httpclient.HttpMethodBase; +import org.apache.commons.httpclient.HttpState; +import org.apache.commons.httpclient.HttpVersion; + +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.List; + +/** + * This class represents an HTTP response from the server. + */ + +public class HttpResponse { + + /** + * Default encoding based on Servlet Specification + */ + private static final String DEFAULT_ENCODING = "ISO-8859-1"; + + /** + * Content-Type header + */ + private static final String CONTENT_TYPE = "Content-Type"; + + /** + * Wrapped HttpMethod used to pull response info from. + */ + private HttpMethod _method = null; + + /** + * HttpState obtained after execution of request + */ + private HttpState _state = null; + + /** + * Charset encoding returned in the response + */ + private String _encoding = DEFAULT_ENCODING; + + /** + * The response body. Initialized after first call to one of the + * getResponseBody methods and cached for subsequent calls. + */ + private String _responseBody = null; + + /** + * Host name used for processing request + */ + private String _host = null; + + /** + * Port number used for processing request + */ + private int _port; + + /** + * Issecure + */ + private boolean _isSecure; + + /** Creates new HttpResponse */ + public HttpResponse(String host, int port, boolean isSecure, + HttpMethod method, HttpState state) { + + _host = host; + _port = port; + _isSecure = isSecure; + _method = method; + _state = state; + } + + /* + * public methods + * ======================================================================== + */ + + /** + * Returns the HTTP status code returned by the server + * + * @return HTTP status code + */ + public String getStatusCode() { + return Integer.toString(_method.getStatusCode()); + } + + /** + * Returns the HTTP reason-phrase returned by the server + * + * @return HTTP reason-phrase + */ + public String getReasonPhrase() { + return _method.getStatusText(); + } + + /** + * Returns the headers received in the response from the server. + * + * @return response headers + */ + public Header[] getResponseHeaders() { + return _method.getResponseHeaders(); + } + + public List
getHeaders() { + return Arrays.asList(_method.getResponseHeaders()); + } + + /** + * Returns the headers designated by the name provided. + * + * @return response headers + */ + public Header[] getResponseHeaders(String headerName) { + return _method.getResponseHeaders(headerName); + } + + /** + * Returns the response header designated by the name provided. + * + * @return a specfic response header or null if the specified header doesn't + * exist. + */ + public Header getResponseHeader(String headerName) { + return _method.getResponseHeader(headerName); + } + + /** + * Returns the response body as a byte array using the charset specified in + * the server's response. + * + * @return response body as an array of bytes. + */ + public byte[] getResponseBodyAsBytes() throws IOException { + return getEncodedResponse().getBytes(); + } + + /** + * Returns the response as bytes (no encoding is performed by client. + * + * @return the raw response bytes + * @throws IOException + * if an error occurs reading from server + */ + public byte[] getResponseBodyAsRawBytes() throws IOException { + return _method.getResponseBody(); + } + + /** + * Returns the response body as a string using the charset specified in the + * server's response. + * + * @return response body as a String + */ + public String getResponseBodyAsString() throws IOException { + return getEncodedResponse(); + } + + /** + * Returns the response body of the server without being encoding by the + * client. + * + * @return an unecoded String representation of the response + * @throws IOException + * if an error occurs reading from the server + */ + public String getResponseBodyAsRawString() throws IOException { + return _method.getResponseBodyAsString(); + } + + /** + * Returns the response body as an InputStream using the encoding specified in + * the server's response. + * + * @return response body as an InputStream + */ + public InputStream getResponseBodyAsStream() throws IOException { + return new ByteArrayInputStream(getEncodedResponse().getBytes()); + } + + /** + * Returns the response body as an InputStream without any encoding applied by + * the client. + * + * @return an InputStream to read the response + * @throws IOException + * if an error occurs reading from the server + */ + public InputStream getResponseBodyAsRawStream() throws IOException { + return _method.getResponseBodyAsStream(); + } + + /** + * Returns the charset encoding for this response. + * + * @return charset encoding + */ + public String getResponseEncoding() { + Header content = _method.getResponseHeader(CONTENT_TYPE); + if (content != null) { + String headerVal = content.getValue(); + int idx = headerVal.indexOf(";charset="); + if (idx > -1) { + // content encoding included in response + _encoding = headerVal.substring(idx + 9); + } + } + return _encoding; + } + + /** + * Returns the post-request state. + * + * @return an HttpState object + */ + public HttpState getState() { + return _state; + } + + /** + * Displays a String representation of the response. + * + * @return string representation of response + */ + public String toString() { + StringBuffer sb = new StringBuffer(255); + + sb.append("[RESPONSE STATUS LINE] -> "); + sb.append(((HttpMethodBase) _method).getParams().getVersion() + .equals(HttpVersion.HTTP_1_1) ? "HTTP/1.1 " : "HTTP/1.0 "); + sb.append(_method.getStatusCode()).append(' '); + sb.append(_method.getStatusText()).append('\n'); + Header[] headers = _method.getResponseHeaders(); + if (headers != null && headers.length != 0) { + for (int i = 0; i < headers.length; i++) { + sb.append(" [RESPONSE HEADER] -> "); + sb.append(headers[i].toExternalForm()).append('\n'); + } + } + + String resBody; + try { + resBody = _method.getResponseBodyAsString(); + } catch (IOException ioe) { + resBody = "UNEXECTED EXCEPTION: " + ioe.toString(); + } + if (resBody != null && resBody.length() != 0) { + sb.append("------ [RESPONSE BODY] ------\n"); + sb.append(resBody); + sb.append("\n-----------------------------\n\n"); + } + return sb.toString(); + } + + /* + * Eventually they need to come from _method + */ + + public String getHost() { + return _host; + } + + public int getPort() { + return _port; + } + + public String getProtocol() { + return _isSecure ? "https" : "http"; + } + + public String getPath() { + return _method.getPath(); + } + + /* + * Private Methods + * ========================================================================== + */ + + /** + * Returns the response body using the encoding returned in the response. + * + * @return encoded response String. + */ + private String getEncodedResponse() throws IOException { + if (_responseBody == null) { + _responseBody = getEncodedStringFromStream( + _method.getResponseBodyAsStream(), getResponseEncoding()); + } + return _responseBody; + } + + public static String getEncodedStringFromStream(InputStream in, String enc) + throws IOException { + BufferedReader bin = new BufferedReader(new InputStreamReader(in, enc)); + StringBuilder sb = new StringBuilder(128); + for (int ch = bin.read(); ch != -1; ch = bin.read()) { + sb.append((char) ch); + } + return sb.toString(); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/request/MethodFactory.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/request/MethodFactory.java new file mode 100644 index 0000000000..85ddaf8aee --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/request/MethodFactory.java @@ -0,0 +1,164 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.common.request; + +import org.apache.commons.httpclient.HttpMethod; +import org.apache.commons.httpclient.HttpMethodBase; +import org.apache.commons.httpclient.HttpVersion; +import org.apache.commons.httpclient.methods.DeleteMethod; +import org.apache.commons.httpclient.methods.GetMethod; +import org.apache.commons.httpclient.methods.HeadMethod; +import org.apache.commons.httpclient.methods.OptionsMethod; +import org.apache.commons.httpclient.methods.PostMethod; +import org.apache.commons.httpclient.methods.PutMethod; + +import java.util.NoSuchElementException; +import java.util.StringTokenizer; + +/** + * Simple factory class which returns HttpMethod implementations based on a + * request line. + *

+ * For example, a request line of GET /index.jsp HTTP/1.0 would return + * an HttpMethod implementation that handles GET requests using HTTP/1.0. + *

+ */ + +public class MethodFactory { + + /** + * HTTP GET + */ + private static final String GET_METHOD = "GET"; + + /** + * HTTP POST + */ + private static final String POST_METHOD = "POST"; + + /** + * HTTP HEAD + */ + private static final String HEAD_METHOD = "HEAD"; + + /** + * HTTP PUT + */ + private static final String PUT_METHOD = "PUT"; + + /** + * HTTP DELETE + */ + private static final String DELETE_METHOD = "DELETE"; + + /** + * HTTP OPTIONS + */ + private static final String OPTIONS_METHOD = "OPTIONS"; + + /** + * Private constructor as all interaction with this class is through the + * getInstance() method. + */ + private MethodFactory() { + } + + /* + * public methods + * ======================================================================== + */ + + /** + * Returns the approriate request method based on the provided request string. + * The request must be in the format of METHOD URI_PATH HTTP_VERSION, i.e. GET + * /index.jsp HTTP/1.1. + * + * @return HttpMethod based in request. + */ + public static HttpMethod getInstance(String request) { + StringTokenizer st = new StringTokenizer(request); + String method; + String query = null; + String uri; + String version; + try { + method = st.nextToken(); + uri = st.nextToken(); + version = st.nextToken(); + } catch (NoSuchElementException nsee) { + throw new IllegalArgumentException( + "Request provided: " + request + " is malformed."); + } + + // check to see if there is a query string appended + // to the URI + int queryStart = uri.indexOf('?'); + if (queryStart != -1) { + query = uri.substring(queryStart + 1); + uri = uri.substring(0, queryStart); + } + + HttpMethodBase req; + + if (method.equals(GET_METHOD)) { + req = new GetMethod(uri); + } else if (method.equals(POST_METHOD)) { + req = new PostMethod(uri); + } else if (method.equals(PUT_METHOD)) { + req = new PutMethod(uri); + } else if (method.equals(DELETE_METHOD)) { + req = new DeleteMethod(uri); + } else if (method.equals(HEAD_METHOD)) { + req = new HeadMethod(uri); + } else if (method.equals(OPTIONS_METHOD)) { + req = new OptionsMethod(uri); + } else { + throw new IllegalArgumentException("Invalid method: " + method); + } + + setHttpVersion(version, req); + + if (query != null) { + req.setQueryString(query); + } + + return req; + } + + /* + * private methods + * ======================================================================== + */ + + /** + * Sets the HTTP version for the method in question. + * + * @param version + * HTTP version to use for this request + * @param method + * method to adjust HTTP version + */ + private static void setHttpVersion(String version, HttpMethodBase method) { + final String oneOne = "HTTP/1.1"; + method.getParams().setVersion( + (version.equals(oneOne) ? HttpVersion.HTTP_1_1 : HttpVersion.HTTP_1_0)); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/request/RequestClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/request/RequestClient.java new file mode 100644 index 0000000000..e24c68b141 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/request/RequestClient.java @@ -0,0 +1,368 @@ +/* + * Copyright (c) 2007, 2018 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$ + */ + +package com.sun.ts.tests.servlet.common.request; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.util.Data; + +public class RequestClient extends AbstractUrlClient { + + + public void getAttributeNamesTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getAttributeNamesTest"); + invoke(); + } + + + public void getAttributeNamesEmptyEnumTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getAttributeNamesEmptyEnumTest"); + invoke(); + } + + + public void getAttributeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getAttributeTest"); + invoke(); + } + + + public void getAttributeDoesNotExistTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getAttributeDoesNotExistTest"); + invoke(); + } + + + public void getCharacterEncodingTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getCharacterEncodingTest"); + TEST_PROPS.setProperty(REQUEST_HEADERS, + "Content-Type:text/plain; charset=ISO-8859-1"); + invoke(); + } + + + public void getContentLengthTest() throws Exception { + String testName = "getContentLengthTest"; + TEST_PROPS.setProperty(REQUEST, "POST " + getContextRoot() + "/" + + getServletName() + "?testname=" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(REQUEST_HEADERS, "Content-Type:text/plain"); + TEST_PROPS.setProperty(CONTENT, "calling getContentLengthTest"); + TEST_PROPS.setProperty(SEARCH_STRING, Data.PASSED); + invoke(); + } + + + public void getContentTypeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getContentTypeTest"); + TEST_PROPS.setProperty(REQUEST_HEADERS, "Content-Type:text/plain"); + invoke(); + } + + + public void getContentTypeNullTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getContentTypeNullTest"); + invoke(); + } + + + public void getInputStreamTest() throws Exception { + String testName = "getInputStreamTest"; + TEST_PROPS.setProperty(REQUEST, "POST " + getContextRoot() + "/" + + getServletName() + "?testname=" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(REQUEST_HEADERS, "Content-Type:text/plain"); + TEST_PROPS.setProperty(CONTENT, "calling getInputStreamTest"); + TEST_PROPS.setProperty(SEARCH_STRING, Data.PASSED); + invoke(); + } + + + public void getInputStreamIllegalStateExceptionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getInputStreamIllegalStateExceptionTest"); + invoke(); + } + + + public void getParameterValuesDoesNotExistTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getParameterValuesDoesNotExistTest"); + invoke(); + } + + + public void getLocaleTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getLocaleTest"); + TEST_PROPS.setProperty(REQUEST_HEADERS, "Accept-Language:en-US"); + invoke(); + } + + + public void getLocaleDefaultTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getLocaleDefaultTest"); + invoke(); + } + + + public void getLocalesTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getLocalesTest"); + TEST_PROPS.setProperty(REQUEST_HEADERS, "Accept-Language:en-US,en-GB"); + invoke(); + } + + + public void getLocalesDefaultTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getLocalesDefaultTest"); + invoke(); + } + + + public void getParameterMapTest() throws Exception { + String testName = "getParameterMapTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + getServletName() + "?testname=" + + testName + "¶meter1=value1¶meter2=value2 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, Data.PASSED); + invoke(); + } + + + public void getParameterNamesTest() throws Exception { + String testName = "getParameterNamesTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + getServletName() + "?testname=" + + testName + "¶meter1=value1¶meter2=value2 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, Data.PASSED); + invoke(); + } + + + public void getParameterNamesEmptyEnumTest() throws Exception { + String testName = "getParameterNamesEmptyEnumTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, Data.PASSED); + invoke(); + } + + + public void getParameterTest() throws Exception { + String testName = "getParameterTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + getServletName() + "?testname=" + + testName + "¶meter1=value1 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, Data.PASSED); + invoke(); + } + + + public void getParameterDoesNotExistTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getParameterDoesNotExistTest"); + invoke(); + } + + + public void getParameterValuesTest() throws Exception { + String testName = "getParameterValuesTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + getServletName() + "?testname=" + + testName + "&Names=value1&Names=value2 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, Data.PASSED); + invoke(); + } + + + public void getProtocolTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getProtocolTest"); + invoke(); + } + + + public void getReaderTest() throws Exception { + String testName = "getReaderTest"; + TEST_PROPS.setProperty(REQUEST, "POST " + getContextRoot() + "/" + + getServletName() + "?testname=" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(REQUEST_HEADERS, "Content-Type:text/plain"); + TEST_PROPS.setProperty(CONTENT, "calling getReaderTest"); + TEST_PROPS.setProperty(SEARCH_STRING, Data.PASSED); + invoke(); + } + + + public void getReaderIllegalStateExceptionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getReaderIllegalStateExceptionTest"); + invoke(); + } + + + public void getReaderUnsupportedEncodingExceptionTest() throws Exception { + String testName = "getReaderUnsupportedEncodingExceptionTest"; + TEST_PROPS.setProperty(REQUEST, + "POST " + getContextRoot() + "/" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(REQUEST_HEADERS, + "Content-Type:text/plain; charset=DoesNonExist"); + TEST_PROPS.setProperty(CONTENT, + "calling getReaderUnsupportedEncodingExceptionTest"); + TEST_PROPS.setProperty(SEARCH_STRING, Data.PASSED); + invoke(); + } + + + public void getRemoteAddrTest() throws Exception { + String localIps = getLocalInterfaceInfo(true); + String testName = "getRemoteAddrTest"; + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + getServletName() + "?testname=" + + testName + "&Address=" + localIps + " HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, Data.PASSED); + invoke(); + } + + + public void getLocalAddrTest() throws Exception { + String testName = "getLocalAddrTest"; + TEST_PROPS.setProperty(APITEST, testName); + TEST_PROPS.setProperty(SEARCH_STRING, Data.PASSED); + invoke(); + } + + + public void getRemoteHostTest() throws Exception { + String testName = "getRemoteHostTest"; + String localIps = getLocalInterfaceInfo(true); + String localHosts = getLocalInterfaceInfo(false); + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + getServletName() + "?testname=" + + testName + "&Address=" + localIps + "," + localHosts + + " HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, Data.PASSED); + invoke(); + } + + + public void getRequestDispatcherTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getRequestDispatcherTest"); + invoke(); + } + + + public void getSchemeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getSchemeTest"); + invoke(); + } + + + public void getServerNameTest() throws Exception { + String testName = "getServerNameTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + getServletName() + "?testname=" + + testName + "&hostname=" + _hostname + " HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, Data.PASSED); + invoke(); + } + + + public void getServerPortTest() throws Exception { + String testName = "getServerPortTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + getServletName() + "?testname=" + + testName + "&port=" + _port + " HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, Data.PASSED); + invoke(); + } + + + public void isSecureTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "isSecureTest"); + invoke(); + } + + + public void removeAttributeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "removeAttributeTest"); + invoke(); + } + + + public void setAttributeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setAttributeTest"); + invoke(); + } + + + public void getCharacterEncodingNullTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getCharacterEncodingNullTest"); + invoke(); + } + + + public void setCharacterEncodingUnsupportedEncodingExceptionTest() + throws Exception { + String testName = "setCharacterEncodingUnsupportedEncodingExceptionTest"; + TEST_PROPS.setProperty(REQUEST, + "POST " + getContextRoot() + "/" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, Data.PASSED); + invoke(); + } + + + public void setCharacterEncodingTest() throws Exception { + String testName = "setCharacterEncodingTest"; + TEST_PROPS.setProperty(REQUEST, + "POST " + getContextRoot() + "/" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, Data.PASSED); + invoke(); + } + + + public void setCharacterEncodingTest1() throws Exception { + String testName = "setCharacterEncodingTest1"; + TEST_PROPS.setProperty(APITEST, testName); + invoke(); + } + + + public void getLocalNameTest() throws Exception { + String testName = "getLocalNameTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + getServletName() + "?testname=" + + testName + "&hostname=" + _hostname + " HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, Data.PASSED); + + invoke(); + } + + + public void getLocalPortTest() throws Exception { + String testName = "getLocalPortTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + getServletName() + "?testname=" + + testName + "&hostport=" + _port + " HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, Data.PASSED); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/request/SecBasicClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/request/SecBasicClient.java new file mode 100644 index 0000000000..5b9c373e8c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/request/SecBasicClient.java @@ -0,0 +1,449 @@ +/* + * Copyright (c) 2007, 2020 Oracle and/or its affiliates and others. + * 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 + */ + +package com.sun.ts.tests.servlet.common.request; + +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.servlet.common.client.BaseUrlClient; +import org.junit.jupiter.api.Test; + +import java.util.Properties; + +public abstract class SecBasicClient extends BaseUrlClient { + + // Constants: + private static final String USERNAME = "user"; + + private static final String PASSWORD = "password"; + + private static final String UNAUTH_USERNAME = "authuser"; + + private static final String UNAUTH_PASSWORD = "authpassword"; + + private static final String CLASS_TRACE_HEADER = "[SecBasicClient]: "; + + private static final String USER_PRINCIPAL_SEARCH = "The user principal is: "; // (+username) + + private static final String REMOTE_USER_SEARCH = "getRemoteUser(): "; // (+username) + + // fields: + protected String pageSec = null; + + protected String pageGuest = null; + + protected String pageUnprotected = null; + + protected String pageRoleReverse = null; + + private String pageJspBase = "/jsp_sec_secbasic_web"; + + private String pageJspSec = pageJspBase + "/jspSec.jsp"; + + private String pageJspGuest = pageJspBase + "/guestPage.jsp"; + + private String pageJspUnprotected = pageJspBase + "/unprotected.jsp"; + + private String pageJspRoleReverse = pageJspBase + "/rolereverse.jsp"; + + private String pageServletBase = "/servlet_sec_secbasic_web"; + + private String pageServletSec = pageServletBase + "/ServletSecTest"; + + private String pageServletGuest = pageServletBase + "/GuestPageTest"; + + private String pageServletUnprotected = pageServletBase + "/UnProtectedTest"; + + private String pageServletRoleReverse = pageServletBase + "/RoleReverseTest"; + + private String username = null; + + private String password = null; + + private String unauthUsername = null; + + private String unauthPassword = null; + + /* + * @class.setup_props: webServerHost; webServerPort; user; password; authuser; + * authpassword; ts_home; + * + * + */ + + public void setup(String[] args, Properties p) throws Exception { + super.setup(args, p); + + // TOFIX configurable +// user=j2ee +// password=j2ee +// authuser=javajoe +// authpassword=javajoe + + p.setProperty(USERNAME, "j2ee"); + p.setProperty(PASSWORD, "j2ee"); + p.setProperty(UNAUTH_USERNAME, "javajoe"); + p.setProperty(UNAUTH_PASSWORD, "javajoe"); + + try { + username = p.getProperty(USERNAME); + password = p.getProperty(PASSWORD); + unauthUsername = p.getProperty(UNAUTH_USERNAME); + unauthPassword = p.getProperty(UNAUTH_PASSWORD); + + + pageSec = pageServletSec; + pageGuest = pageServletGuest; + pageUnprotected = pageServletUnprotected; + pageRoleReverse = pageServletRoleReverse; + + + } catch (Exception e) { + logErr("Error: got exception: ", e); + } + } + + /* + * testName: test1 + * + * @assertion: Test BASIC authentication, specified in the Java Servlet + * Specification v2.2, Sec 11.5.1. + * + * 1. If user has not been authenticated and user attempts to access a + * protected web resource, the web server requests authentication. + * + * @test_Strategy: 1. Send request to access jspSec.jsp 2. Receive + * authentication request. + */ + + public void test1() throws Exception { + logMessage( + "Sending request to validate presence of www-authenticate header..."); + TEST_PROPS.setProperty(TEST_NAME, "SecBasic/Test1"); + TEST_PROPS.setProperty(REQUEST, getRequestLine("GET", pageSec)); + TEST_PROPS.setProperty(EXPECTED_HEADERS, "www-authenticate:"); + TEST_PROPS.setProperty(STATUS_CODE, UNAUTHORIZED); + invoke(); + + dumpResponse(); // debug aid + + logMessage("Authentication requested"); + } + + /* + * testName: test2 + * + * @assertion: Test BASIC authentication, specified in the Java Servlet + * Specification v2.2, Sec 11.5.1. Also tests API assertions in section 11.3. + * + * 1. If user has not been authenticated and user attempts to access a + * protected web resource, and user enters a valid username and password, the + * original web resource is returned and user is authenticated. 2. + * getRemoteUser() returns the user name that the client authenticated with. + * + * @test_Strategy: 1. Send request with correct authentication. 2. Receive + * page (ensure principal is correct, and ensure that getRemoteUser() returns + * the correct name) + */ + + public void test2() throws Exception { + logMessage("Sending request with Authroization header..."); + + StringBuffer sb = new StringBuffer(100); + sb.append(USER_PRINCIPAL_SEARCH).append(username).append("|"); + sb.append(REMOTE_USER_SEARCH).append(username).append("|"); + sb.append("isUserInRole(\"ADM\"): !true!").append("|"); + sb.append("isUserInRole(\"MGR\"): !false!").append("|"); + sb.append("isUserInRole(\"VP\"): !false!").append("|"); + sb.append("isUserInRole(\"EMP\"): !true!").append("|"); + + TEST_PROPS.setProperty(TEST_NAME, "SecBasic/Test2"); + TEST_PROPS.setProperty(REQUEST, getRequestLine("GET", pageSec)); + TEST_PROPS.setProperty(BASIC_AUTH_USER, username); + TEST_PROPS.setProperty(BASIC_AUTH_PASSWD, password); + TEST_PROPS.setProperty(SEARCH_STRING, sb.toString()); + invoke(); + + dumpResponse(); // debug aid + + logMessage("isUserInRole() and getRemoteUser() returned expected results"); + } + + /* + * testName: test3 + * + * @assertion: Test BASIC authentication, specified in the Java Servlet + * Specification v2.2, Sec 11.5.1. + * + * 1. If user has not been authenticated and user attempts to access a + * protected web resource, and user enters an invalid username and password, + * the container denies access to the web resource. + * + * @test_Strategy: 1. Re-send request with incorrect authentication. 2. + * Receive authentication request. + */ + + public void test3() throws Exception { + logMessage( + "Sending an request for a protected resource with invalid username/password..."); + + TEST_PROPS.setProperty(TEST_NAME, "SecBasic/Test3"); + TEST_PROPS.setProperty(REQUEST, getRequestLine("GET", pageSec)); + TEST_PROPS.setProperty(BASIC_AUTH_USER, "invalid"); + TEST_PROPS.setProperty(BASIC_AUTH_PASSWD, password); + TEST_PROPS.setProperty(STATUS_CODE, UNAUTHORIZED); + invoke(); + + dumpResponse(); // debug aid + + logMessage("Access Denied"); + } + + /* + * testName: test4 + * + * @assertion: Test BASIC authentication, specified in the Java Servlet + * Specification v2.2, Sec 11.5.1. + * + * 1. If user has not been authenticated and user attempts to access a + * protected web resource, and user enters an valid username and password, but + * for a role that is not authorized to access the resource, the container + * denies access to the web resource. + * + * @test_Strategy: 1. Send request with correct authentication for user + * javajoe for a page javajoe is allowed to access. 2. Receive page (this + * verifies that the javajoe user is set up properly). 3. Send request with + * correct authentication, but incorrect authorization to access resource 4. + * Receive error + */ + + public void test4() throws Exception { + + StringBuffer sb = new StringBuffer(100); + sb.append(USER_PRINCIPAL_SEARCH).append(unauthUsername); + + logMessage("Sending request to resource the user has access to..."); + TEST_PROPS.setProperty(TEST_NAME, "SecBasic/Test4"); + TEST_PROPS.setProperty(REQUEST, getRequestLine("GET", pageGuest)); + TEST_PROPS.setProperty(BASIC_AUTH_USER, unauthUsername); + TEST_PROPS.setProperty(BASIC_AUTH_PASSWD, unauthPassword); + TEST_PROPS.setProperty(SEARCH_STRING, sb.toString()); + invoke(); + + dumpResponse(); // debug aid + + logMessage("User successfully accessed the resource"); + + logMessage( + "Sending request to resource with valid username/password, but not the right roles..."); + TEST_PROPS.setProperty(TEST_NAME, "SecBasic/Test4"); + TEST_PROPS.setProperty(REQUEST, getRequestLine("GET", pageSec)); + TEST_PROPS.setProperty(BASIC_AUTH_USER, unauthUsername); + TEST_PROPS.setProperty(BASIC_AUTH_PASSWD, unauthPassword); + TEST_PROPS.setProperty(STATUS_CODE, FORBIDDEN); + invoke(); + + dumpResponse(); // debug aid + + logMessage("Access Forbidden"); + } + + /* + * testName: test5 + * + * @assertion: Test BASIC authentication, specified in the Java Servlet + * Specification v2.2, Sec 11.5.1. Also tests assertions in section 11.3. + * + * 1. If user has not been authenticated and user attempts to access an + * unprotected web resource, the web resource is returned without need to + * authenticate. 2. isUserInRole() must return false for any valid or invalid + * role reference. 3. getRemoteUser() must return false + * + * @test_Strategy: 1. Send request for unprotected.jsp with no authentication. + * 2. Receive page 3. Search the returned page for "!true!", which would + * indicate that at least one call to isUserInRole attempted by + * unprotected.jsp returned true. 4. check that getRemoteUser() returns null. + */ + + public void test5() throws Exception { + StringBuffer sb = new StringBuffer(100); + sb.append(USER_PRINCIPAL_SEARCH).append("|"); + sb.append(REMOTE_USER_SEARCH).append("null"); + + logMessage("Sending request to unprotected resource...."); + TEST_PROPS.setProperty(TEST_NAME, "BasicSec/Test5"); + TEST_PROPS.setProperty(REQUEST, getRequestLine("GET", pageUnprotected)); + TEST_PROPS.setProperty(SEARCH_STRING, sb.toString()); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "!true!"); + invoke(); + + dumpResponse(); // debug aid + + logMessage("isUserInRole() and getRemoteUser() returned expected results"); + } + + /* + * testName: test6 + * + * @assertion: Test HTTP-Basic authentication, specified in the Java Servlet + * Specification v2.2, Sec 11.5.1. Also tests assertions from section 11.3. + * + * Given two servlets in the same application, each of which calls + * isUserInRole(X), and where X is linked to different roles in the scope of + * each of the servlets (i.e. R1 for servlet 1 and R2 for servlet 2), then a + * user whose identity is mapped to R1 but not R2, shall get a true return + * value from isUserInRole( X ) in servlet 1, and a false return value from + * servlet 2 (a user whose identity is mapped to R2 but not R1 should get the + * inverse set of return values). + * + * @test_Strategy: Since test1 already verifies the functionality for + * isUserInRole returning true, this test needs only verify that it should + * return false for the other jsp. For this test, MGR and ADM are swapped, so + * isUserInRole() should return opposite values from test1. + * + * 1. Send request to access rolereverse.jsp 2. Receive redirect to login + * page, extract location and session id cookie. 3. Send request to access new + * location, send cookie 4. Receive login page 5. Send form response with + * username and password 6. Receive redirect to resource 7. Request resource + * 8. Receive resource (check isUserInRole for all known roles) + */ + + public void test6() throws Exception { + + StringBuffer sb = new StringBuffer(100); + sb.append(USER_PRINCIPAL_SEARCH).append(username).append("|"); + sb.append("isUserInRole(\"ADM\"): !false!").append("|"); + sb.append("isUserInRole(\"MGR\"): !true!").append("|"); + sb.append("isUserInRole(\"VP\"): !false!").append("|"); + sb.append("isUserInRole(\"EMP\"): !true!").append("|"); + + logMessage( + "Sending request to validate isUserInRole with roles reversed..."); + TEST_PROPS.setProperty(TEST_NAME, "SecBasic/Test6"); + TEST_PROPS.setProperty(REQUEST, getRequestLine("GET", pageRoleReverse)); + TEST_PROPS.setProperty(BASIC_AUTH_USER, username); + TEST_PROPS.setProperty(BASIC_AUTH_PASSWD, password); + TEST_PROPS.setProperty(SEARCH_STRING, sb.toString()); + invoke(); + + dumpResponse(); // debug aid + + logMessage("isUserInRole() and getRemoteUser() returned expected results"); + } + + /* + * testName: test7 + * + * @assertion: Test BASIC authentication, specified in the Java Servlet + * Specification v2.2, Sec 11.5.1. + * + * 1. If user has not been authenticated and user attempts to access a + * protected web resource+ , and user enters an invalid + * username and password, the container denies access to the web resource. + * IMPORTANT: this is not just trying to access a protected resource but + * instead is trying to access pageSec + "/j_security_check" when + * unauthenticated in an attempt to trick/confuse the impl into thinking + * authentication occurred when it did not. + * + * @test_Strategy: 1. send request with incorrect authentication to url + + * "/j_security_check" 2. Receive authentication request. + */ + + public void test7() throws Exception { + logMessage( + "Sending an request for a protected resource with invalid username/password..."); + + TEST_PROPS.setProperty(TEST_NAME, "SecBasic/Test7"); + TEST_PROPS.setProperty(REQUEST, + getRequestLine("GET", pageSec + "/j_security_check")); + TEST_PROPS.setProperty(BASIC_AUTH_USER, "invalid"); + TEST_PROPS.setProperty(BASIC_AUTH_PASSWD, password); + // The servlet is mapped to "/ServletSecTest" so this request should result + // in a 404 since no Servlet is mapped to the requested URI or 401 if the container + // rejects the incoming BASIC header. + TEST_PROPS.setProperty(STATUS_CODE, UNAUTHORIZED + "," + NOT_FOUND); + invoke(); + + dumpResponse(); // debug aid + + if ((_testCase != null) && (_testCase.getResponse() != null)) { + // we got a response so lets check it... + // if our search string appears in the response, we were erroneously + // allowed access to a protected page! + String searchString = "Inside ServletSecTestServlet"; + try { + if (_testCase.getResponse().getResponseBodyAsString() + .indexOf(searchString) != -1) { + // ohoh - we should NOT have been allowed to access the page and it + // appears we did access it. log an error + TestUtil.logErr("(Should say: \"" + searchString + "\")"); + throw new Exception("test7 failed."); + } + } catch (Exception ex) { + // must've had problem getting response so dump exception but continue + // on + ex.printStackTrace(); + } + } + + logMessage("Access properly Denied"); + } + + /** + * Returns a valid HTTP/1.1 request line. + * + * @param method + * the request method + * @param path + * the request path + * @return a valid HTTP/1.1 request line + */ + private static String getRequestLine(String method, String path) { + return method + " " + path + " HTTP/1.1"; + } + + /** + * Simple wrapper around TestUtil.logMessage(). + * + * @param message + * - the message to log + */ + private static void logMessage(String message) { + TestUtil.logMsg(CLASS_TRACE_HEADER + message); + } + + /** + * Simple wrapper around TestUtil.logTrace(). + * + * @param message + * - the message to log + */ + private static void trace(String message) { + TestUtil.logTrace(CLASS_TRACE_HEADER + message); + } + + private void dumpResponse() { + try { + if ((_testCase != null) && (_testCase.getResponse() != null)) { + trace(_testCase.getResponse().getResponseBodyAsString()); + } + } catch (Exception ex) { + // must've had problem getting response so dump exception but continue on + ex.printStackTrace(); + } + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/request/SecformClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/request/SecformClient.java new file mode 100644 index 0000000000..c5e079ab6d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/request/SecformClient.java @@ -0,0 +1,2304 @@ +/* + * 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 + */ + +package com.sun.ts.tests.servlet.common.request; + +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.lib.util.WebUtil; +import com.sun.ts.lib.util.WebUtil.Response; +import com.sun.ts.tests.servlet.common.client.BaseUrlClient; +import org.junit.jupiter.api.Test; + +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.net.ConnectException; +import java.net.InetAddress; +import java.net.MalformedURLException; +import java.net.Socket; +import java.net.URL; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.List; +import java.util.Properties; +import java.util.StringTokenizer; + +public class SecformClient extends BaseUrlClient { + // Configurable constants: + + private String protocol = "http"; + + private String hostname = null; + + private int portnum = 0; + + protected String pageBase = null; + + protected String pageSec = null; + + protected String pageGuest = null; + + protected String pageRoleReverse = null; + + protected String pageUnprotected = null; + + private String pageProgAuthen = null; + + private String pageProgLogin = null; + + private String pageProgLogout = null; + + private String pageOne = null; + + private String pageTwo = null; + + private String pageSample = null; + + private String pageallRoles = null; + + // common for JSP and Servlet + private String pageLogin = "/login.jsp"; + + private String pageError = "/error.jsp"; + + private String pageSecurityCheck = "/j_security_check"; + + private String pageJspBase = "/jsp_sec_secform_web"; + + private String pageJspSec = pageJspBase + "/jspSec.jsp"; + + private String pageJspUnprotected = pageJspBase + "/unprotected.jsp"; + + private String pageJspGuest = pageJspBase + "/guestPage.jsp"; + + private String pageJspRoleReverse = pageJspBase + "/rolereverse.jsp"; + + private String pageJspOne = pageJspBase + "/One.jsp"; + + private String pageJspTwo = pageJspBase + "/Two.jsp"; + + private String pageJspSample = pageJspBase + "/Sample.jsp"; + + private String pageJspallRoles = pageJspBase + "/allRoles.jsp"; + + private String pageServletBase = "/servlet_sec_secform_web"; + + private String pageServletSec = pageServletBase + "/ServletSecTest"; + + private String pageServletUnprotected = pageServletBase + "/UnProtectedTest"; + + private String pageServletProgLogin = pageServletBase + + "/ServletProgrammaticLogin"; + + private String pageServletProgLogout = pageServletBase + + "/ServletProgrammaticLogout"; + + private String pageServletProgAuthen = pageServletBase + + "/ServletProgrammaticAuthen"; + + private String pageServletGuest = pageServletBase + "/GuestPageTest"; + + private String pageServletRoleReverse = pageServletBase + "/RoleReverseTest"; + + private String pageServletOne = pageServletBase + "/OneTest"; + + private String pageServletTwo = pageServletBase + "/TwoTest"; + + private String pageServletSample = pageServletBase + "/SampleTest"; + + private String pageServletallRoles = pageServletBase + "/allRolesTest"; + + private String searchFor = "The user principal is: "; // (+username) + + private String searchForGetRemoteUser = "getRemoteUser(): "; // (+username) + + private String username = ""; + + private String password = ""; + + private String unauthUsername = ""; + + private String unauthPassword = ""; + + private String tshome = ""; + + // Constants: + private final String WebHostProp = "webServerHost"; + + private final String WebPortProp = "webServerPort"; + + private final String UserNameProp = "user"; + + private final String PasswordProp = "password"; + + private final String unauthUserNameProp = "authuser"; + + private final String unauthPasswordProp = "authpassword"; + + private final String tsHomeProp = "ts_home"; + + private String testDir = System.getProperty("user.dir"); + + // Shared test variables: + private Properties props = null; + + private String request = null; + + private Response response = null; + + private Response loginPageRequestResponse = null; + + private Response errorPageRequestResponse = null; + + private Hashtable cookies = null; + + /* + * @class.setup_props: webServerHost; webServerPort; user; password; authuser; + * authpassword; ts_home; + */ + public void setup(String[] args, Properties p) throws Exception { + super.setup(args, p); + props = p; + + try { + hostname = p.getProperty(WebHostProp); + portnum = Integer.parseInt(p.getProperty(WebPortProp)); + username = p.getProperty(UserNameProp); + password = p.getProperty(PasswordProp); + unauthUsername = p.getProperty(unauthUserNameProp); + unauthPassword = p.getProperty(unauthPasswordProp); + tshome = p.getProperty(tsHomeProp); + + logger.debug("username: {}", username); + logger.debug("password: {}", password); + +// if (args[0].equals("jsp")) { +// pageBase = pageJspBase; +// pageSec = pageJspSec; +// pageGuest = pageJspGuest; +// pageUnprotected = pageJspUnprotected; +// pageRoleReverse = pageJspRoleReverse; +// pageOne = pageJspOne; +// pageTwo = pageJspTwo; +// pageSample = pageJspSample; +// pageallRoles = pageJspallRoles; +// +// // prefix pageJspBase to pageLogin, pageError ,pageSecurityCheck +// pageLogin = pageJspBase + pageLogin; +// pageError = pageJspBase + pageError; +// pageSecurityCheck = pageJspBase + pageSecurityCheck; +// +// } else { + pageBase = pageServletBase; + pageSec = pageServletSec; + pageGuest = pageServletGuest; + pageUnprotected = pageServletUnprotected; + pageRoleReverse = pageServletRoleReverse; + pageOne = pageServletOne; + pageTwo = pageServletTwo; + pageSample = pageServletSample; + pageallRoles = pageServletallRoles; + pageProgLogin = pageServletProgLogin; + pageProgLogout = pageServletProgLogout; + pageProgAuthen = pageServletProgAuthen; + + // prefix pageServletBase to pageLogin, pageError, pageSecurityCheck + pageLogin = pageServletBase + pageLogin; + pageError = pageServletBase + pageError; + pageSecurityCheck = pageServletBase + pageSecurityCheck; + +// } + + } catch (Exception e) { + logger.error("Error: got exception: " + e.getMessage(), e); + } + } + + /* + * testName: test1 + * + * @assertion: Test FORM-based authentication, specified in the Java Servlet + * Specification v2.2, Sec 11.5.3. Also tests an assertion in section 11.3. + * + * 1. If user has not been authenticated and user attempts to access a + * protected web resource, the correct login form is returned. 2. If user has + * not been authenticated and user attempts to access a protected web + * resource, and user enters a valid username and password, the original web + * resource is returned and user is authenticated. A call to getRemoteUser() + * must return the username. 3. If user has been authenticated and user is + * authorized to access a protected web resource, user gets web resource + * without the need to re-authenticate. A call to getRemoteUser() still + * returns the username. + * + * @test_Strategy: 1. Send request to access jspSec.jsp 2. Receive login + * page(make sure it the expected login page) 3. Send form response with + * username and password 4. Receive jspSec.jsp (ensure principal is correct, + * and ensure getRemoteUser() returns the username, and ensure isUserInRole() + * is working properly) 5. Re-request jspSec.jsp 6. Ensure principal is still + * correct and getRemoteUser() still returns the correct username. Also ensure + * isUserInRole() is still working properly. + */ + + public void test1() throws Exception { + try { + // The first part of this test is used in test2 and test3 as + // well, so the code has been moved to a helper method. + requestAndGetLoginPage(pageSec, 1); + + // Send response to login form with session id cookie: + request = pageSecurityCheck; + logger.debug("Sending request '{}' with login information.", request); + Properties postData = new Properties(); + postData.setProperty("j_username", username); + postData.setProperty("j_password", password); + response = WebUtil.sendRequest("POST", InetAddress.getByName(hostname), + portnum, request, postData, cookies); + + logger.debug("response.statusToken: {}", response.statusToken); + logger.debug("response.content: {}", response.content); + + // Check that the page was found (no error). + if (response.isError()) { + logger.error("Could not find {}", request); + throw new Exception("test1 failed."); + } + + // Call followRedirect() to make sure we receive the required page + response = followRedirect(response, 1); + + // Print response content + logger.debug("received response content 1: {}", response.content); + + // Check to make sure we are authenticated by checking the page + // content. The jsp should output "The user principal is: j2ee" + String searchString = searchFor + username; + if (response.content.indexOf(searchString) == -1) { + logger.error("User Principal incorrect. Page received:"); + logger.error(response.content); + logger.error("(Should say: \"" + searchString + "\")"); + throw new Exception("test1 failed."); + } + logger.debug("User Principal correct."); + + // Check to make sure getRemoteUser returns the user name. + searchString = searchForGetRemoteUser + username; + if (response.content.indexOf(searchString) == -1) { + logger.error("getRemoteUser() did not return " + username + ":"); + logger.error(response.content); + logger.error("(Should say: \"" + searchString + "\")"); + throw new Exception("test1 failed."); + } + logMsg("getRemoteUser() correct."); + + // Check to make sure isUserInRole is working properly: + Hashtable roleCheck = new Hashtable(); + roleCheck.put("ADM", Boolean.TRUE); + roleCheck.put("MGR", Boolean.FALSE); + roleCheck.put("VP", Boolean.FALSE); + roleCheck.put("EMP", Boolean.TRUE); + // roleCheck.put( "Administrator", new Boolean( false ) ); + if (!checkRoles(response.content, roleCheck)) { + logger.error("isUserInRole() does not work correctly. Page Received:"); + logger.error(response.content); + throw new Exception("test1 failed."); + } + logMsg("isUserInRole() correct."); + + // Now that we are authenticated, try accessing the resource again + // to ensure we need not go through the login page again. + request = pageSec; + logger.debug("Cookies = {}", cookies.toString()); + logger.debug("Re-sending request {}", request); + response = WebUtil.sendRequest("GET", InetAddress.getByName(hostname), + portnum, request, null, cookies); + + // Check that the page was found (no error). + if (response.isError()) { + logger.error("Could not find " + pageSec); + throw new Exception("test1 failed."); + } + + // Check to make sure we are still authenticated. + if (response.content.indexOf(searchString) == -1) { + logger.error("User Principal incorrect. Page received:"); + logger.error(response.content); + logger.error("(Should say: \"" + searchString + "\")"); + throw new Exception("test1 failed."); + } + logger.debug("User Principal still correct."); + + // Check to make sure getRemoteUser still returns the user name. + searchString = searchForGetRemoteUser + username; + if (response.content.indexOf(searchString) == -1) { + logger.error("getRemoteUser() did not return " + username + + " after lazy authentication:"); + logger.error(response.content); + logger.error("(Should say: \"" + searchString + "\")"); + throw new Exception("test1 failed."); + } + logMsg("getRemoteUser() still correct."); + + // Check to make sure isUserInRole is still working properly: + if (!checkRoles(response.content, roleCheck)) { + logger.error("isUserInRole() does not work correctly."); + logger.error("Page Received:"); + logger.error(response.content); + throw new Exception("test1 failed."); + } + logMsg("isUserInRole() still correct."); + + } catch (Exception e) { + logger.error("Caught exception: " + e.getMessage(), e); + throw new Exception("test1 failed: " + e.getMessage(), e); + } + } + + /* + * testName: test2 + * + * @assertion: Test FORM-based authentication, specified in the Java Servlet + * Specification v2.2, Sec 11.5.3. + * + * If user has not been authenticated and user attempts to access a protected + * web resource, and user enters incorrect username and password, the error + * page is returned. + * + * @test_Strategy: 1. Send request to access jspSec.jsp 2. Receive login page + * 3. Send form response with username and incorrect password 4. Receive error + * page (make sure it is the expected error page) + */ + + public void test2() throws Exception { + try { + // The first part of this test is used in test1 and test3 as + // well, so the code has been moved to a helper method. + requestAndGetLoginPage(pageSec, 2); + + // Send response to login form with session id cookie and username + // and incorrect password: + request = pageSecurityCheck; + logger.debug("Sending request {} with incorrect login information.", request); + Properties postData = new Properties(); + postData.setProperty("j_username", username); + postData.setProperty("j_password", "incorrect" + password); + response = WebUtil.sendRequest("POST", InetAddress.getByName(hostname), + portnum, request, postData, cookies); + logger.debug("response.statusToken: {}", response.statusToken); + + // Call followRedirect() to make sure we receive the required page + response = followRedirect(response, 2); + + // Check to make sure the user principal is null: + String searchString = searchFor + "null"; + if (response.content.indexOf(searchString) == -1) { + logger.error("User principal is not null in error page: {}", response.content); + throw new Exception("test2 failed."); + } + + logger.debug("User Principal is null as expected."); + + // Request error page + request = pageError; + logger.debug("Sending request {}", request); + errorPageRequestResponse = WebUtil.sendRequest("GET", + InetAddress.getByName(hostname), portnum, request, + null, cookies); + + // Check that the page was found (no error). + if (errorPageRequestResponse.isError()) { + logger.error("Could not find {}", request); + throw new Exception("test2 failed."); + } + + // Compare the received error page with the expected error page + // i.e Check whether + // response.content ==errorPageRequestResponse.content + if (response.content.equals(errorPageRequestResponse.content)) { + logger.debug("Received the expected error page"); + } else { + logger.error("Received incorrect error page"); + throw new Exception("test2 failed."); + } + + } catch (Exception e) { + logger.error("Caught exception: " + e.getMessage(), e); + throw new Exception("test2 failed: " + e.getMessage(), e); + } + } + + /* + * testName: test3 + * + * @assertion: Test FORM-based authentication, specified in the Java Servlet + * Specification v2.2, Sec 11.5.3. + * + * If user has not been authenticated and user attempts to access a protected + * web resource, and user enters correct username and password of a user that + * is authorized to access the resource, the resource is returned (similar to + * test1, but uses user javajoe instead of j2ee). This test establishes that + * the javajoe user is set up properly. + * + * @test_Strategy: 1. Send request to access guestPage.jsp 2. Receive login + * page 3. Send form response with username(javajoe) and password 4. Receive + * resource (check user principal) + * + */ + + public void test3() throws Exception { + try { + // The first part of this test is used in test2 and test3 as + // well, so the code has been moved to a helper method. + requestAndGetLoginPage(pageGuest, 3); + + // Send response to login form with session id cookie: + request = pageSecurityCheck; + logger.debug("Sending request {} with login information (as {}).", request, unauthUsername); + Properties postData = new Properties(); + postData.setProperty("j_username", unauthUsername); + postData.setProperty("j_password", unauthPassword); + response = WebUtil.sendRequest("POST", InetAddress.getByName(hostname), + portnum, request, postData, cookies); + + // Check that the page was found (no error). + if (response.isError()) { + logger.error("Could not find {}", request); + throw new Exception("test3 failed."); + } + + // Call followRedirect() to make sure we receive the required page + response = followRedirect(response, 3); + + // Check to make sure we are authenticated by checking the page + // content. The jsp should output "The user principal is: javajoe" + String searchString = searchFor + unauthUsername; + if (response.content.indexOf(searchString) == -1) { + logger.error("User Principal incorrect. Page received: {}", response.content); + logger.error("(Should say: {}", searchString); + throw new Exception("test3 failed."); + } + logger.debug("User Principal correct."); + } catch (Exception e) { + logErr("Caught exception: " + e.getMessage(), e); + throw new Exception("test3 failed: " + e.getMessage(), e); + } + } + + /* + * testName: test4 + * + * @assertion: Test FORM-based authentication, specified in the Java Servlet + * Specification v2.2, Sec 11.5.3. + * + * If user has not been authenticated and user attempts to access a protected + * web resource, and user enters correct username and password of a user that + * is not authorized to access the resource, the resource is not returned. The + * authenticated user is not denied access to an unprotected page. + * + * @test_Strategy: 1. Send request to access jspSec.jsp 2. Receive login page + * 3. Send form response with username and password 4. Receive an error + * (expected unauthorized error) 5. Send request to access unprotected.jsp 6. + * Receive unprotected.jsp. + */ + + public void test4() throws Exception { + try { + // The first part of this test is used in test1 and test2 as + // well, so the code has been moved to a helper method. + requestAndGetLoginPage(pageSec, 4); + + // Send response to login form with session id cookie and username + // and password: + request = pageSecurityCheck; + logger.debug("Sending request {} with correct login information ({}), but incorrect authorization for this resource.", + request, unauthUsername); + Properties postData = new Properties(); + postData.setProperty("j_username", unauthUsername); + postData.setProperty("j_password", unauthPassword); + response = WebUtil.sendRequest("POST", InetAddress.getByName(hostname), + portnum, request, postData, cookies); + + logger.debug("response.content = {}", response.content); + + if (response.statusToken.equals("302")) { + // We should receive a redirection page + if (response.location == null) { + logger.error("No redirection to login page received."); + throw new Exception("test4 failed."); + } + + // Extract location from redirection and format new request: + request = WebUtil.getRequestFromURL(response.location); + logger.debug("Redirect to: {}", response.location); + + // update cookies if the webserver choose to send cookies + addNewCookies(cookies, response.cookies); + + // Request redirected page (login page): + logger.debug("Sending request {}", request); + response = WebUtil.sendRequest("GET", InetAddress.getByName(hostname), + portnum, request, null, cookies); + } + + // Receive "403" or "404" error code for unauthorized access (forbidden). + if ((response.statusToken.equals("403")) + || (response.statusToken.equals("404"))) { + logger.debug("Status Token {}, Received expected unauthorized access error", response.statusToken); + } else { + logger.error("Did not receive error for unauthorized access: {}", request); + logger.error("Status Token {}", response.statusToken); + logger.error("Page content: {}", response.content); + throw new Exception("test4 failed."); + } + + // Request unprotected page (unprotected.jsp page): + request = pageUnprotected; + logger.debug("Sending request {}", request); + response = WebUtil.sendRequest("GET", InetAddress.getByName(hostname), + portnum, request, null, null); + + // Check that we did not receive an error and that we did not + // receive a redirection: + if (response.isError()) { + logger.error("Error retrieving {}", request); + throw new Exception("test4 failed."); + } + + // Check that the page returned is the correct one. The principal + // is not checked. + String searchString = searchFor; + if (!response.content.contains(searchString)) { + logger.error("Incorrect page received: {}", response.content); + logger.error("(Should contain: {}", searchString); + throw new Exception("test4 failed."); + } + logger.debug("Access to unprotected page granted."); + + } catch (Exception e) { + logger.error("Caught exception: " + e.getMessage(), e); + throw new Exception("test4 failed: " + e.getMessage(), e); + } + } + + /* + * testName: test5 + * + * @assertion: Test FORM-based authentication, specified in the Java Servlet + * Specification v2.2, Sec 11.5.3. Also tests assertions from section 11.3. + * + * If user has not been authenticated and user attempts to access an + * unprotected web resource, the resource is returned, and the user is not + * forced to authenticate. Also, isUserInRole() must return false for any + * valid or invalid role reference. A call to getRemoteUser() must return + * null. + * + * @test_Strategy: 1. Send request to access unprotected.jsp 2. Receive + * unprotected.jsp 3. Search the returned page for "!true!", which would + * indicate that at least one call to isUserInRole attempted by + * unprotected.jsp returned true. 4. Check that the call to getRemoteUser() + * returned null. + */ + + public void test5() throws Exception { + try { + // Request restricted jsp page. + String request = pageUnprotected; + logMsg("Sending request \"" + request + "\""); + response = WebUtil.sendRequest("GET", InetAddress.getByName(hostname), + portnum, request, null, null); + + // Check that the page was found (no error). + if (response.isError()) { + logErr("Could not find " + pageUnprotected); + throw new Exception("test5 failed."); + } + + // Check that we did not receive an error and that we did not + // receive a redirection: + if (response.isError()) { + logErr("Error retrieving " + request); + throw new Exception("test5 failed."); + } + + // Check that the page returned is the correct one. The principal + // is not checked. + String searchString = searchFor; + if (response.content.indexOf(searchString) == -1) { + logErr("Incorrect page received:"); + logErr(response.content); + logErr("(Should contain: \"" + searchString + "\")"); + throw new Exception("test5 failed."); + } + + logMsg("Access to unprotected page granted."); + + // Check to see if any of the calls to isUserInRole returned true: + logMsg("Checking isUserInRole..."); + searchString = "!true!"; + if (response.content.indexOf(searchString) != -1) { + logErr("At least one call to isUserInRole returned true."); + logErr("Page received:"); + logErr(response.content); + throw new Exception("test5 failed."); + } + + logMsg("isUserInRole test passed."); + + // Check to make sure the call to getRemoteUser() returned null. + logMsg("Checking getRemoteUser()..."); + searchString = searchForGetRemoteUser + "null"; + if (response.content.indexOf(searchString) == -1) { + logErr("A call to getRemoteUser() did not return null."); + logErr("Page received:"); + logErr(response.content); + throw new Exception("test5 failed."); + } + logMsg("getRemoteUser() test passed."); + + } catch (Exception e) { + logErr("Caught exception: " + e.getMessage()); + e.printStackTrace(); + throw new Exception("test5 failed: ", e); + } + } + + /* + * testName: test6 + * + * @assertion: Test FORM-based authentication, specified in the Java Servlet + * Specification v2.2, Sec 11.5.3. Also tests assertions from section 11.3. + * + * Given two servlets in the same application, each of which calls + * isUserInRole(X), and where X is linked to different roles in the scope of + * each of the servlets (i.e. R1 for servlet 1 and R2 for servlet 2), then a + * user whose identity is mapped to R1 but not R2, shall get a true return + * value from isUserInRole( X ) in servlet 1, and a false return value from + * servlet 2 (a user whose identity is mapped to R2 but not R1 should get the + * inverse set of return values). + * + * @test_Strategy: Since test1 already verifies the functionality for + * isUserInRole returning true, this test needs only verify that it should + * return false for the other jsp. For this test, MGR and ADM are swapped, so + * isUserInRole() should return opposite values from test1. + * + * 1. Send request to access rolereverse.jsp 2. Receive login page 3. Send + * form response with username and password 4. Receive resource (check + * isUserInRole for all known roles) + */ + + public void test6() throws Exception { + try { + // The first part of this test is used in test2 and test3 as + // well, so the code has been moved to a helper method. + requestAndGetLoginPage(pageRoleReverse, 6); + + // Send response to login form with session id cookie: + request = pageSecurityCheck; + logMsg("Sending request \"" + request + + "\" with login information (as " + username + ")."); + Properties postData = new Properties(); + postData.setProperty("j_username", username); + postData.setProperty("j_password", password); + response = WebUtil.sendRequest("POST", InetAddress.getByName(hostname), + portnum, request, postData, cookies); + + // Check that the page was found (no error). + if (response.isError()) { + logErr("Could not find " + request); + throw new Exception("test6 failed."); + } + + // Call followRedirect() to make sure we receive the required page + response = followRedirect(response, 6); + + // Check to make sure we are authenticated by checking the page + // content. The jsp should output "The user principal is: j2ee" + String searchString = searchFor + username; + if (response.content.indexOf(searchString) == -1) { + logErr("User Principal incorrect. Page received:"); + logErr(response.content); + logErr("(Should say: \"" + searchString + "\")"); + throw new Exception("test6 failed."); + } + logMsg("User Principal correct."); + + // Check to make sure isUserInRole is working properly: + Hashtable roleCheck = new Hashtable(); + roleCheck.put("ADM", Boolean.FALSE); + roleCheck.put("MGR", Boolean.TRUE); + roleCheck.put("VP", Boolean.FALSE); + roleCheck.put("EMP", Boolean.TRUE); + // roleCheck.put( "Manager", new Boolean( false ) ); + if (!checkRoles(response.content, roleCheck)) { + logErr("isUserInRole() does not work correctly."); + logErr("Page Received:"); + logErr(response.content); + throw new Exception("test6 failed."); + } + logMsg("isUserInRole() correct."); + + } catch (Exception e) { + logErr("Caught exception: " + e.getMessage()); + e.printStackTrace(); + throw new Exception("test6 failed: ", e); + } + } + + /* + * testName: test7 + * + * @assertion: Servlet Specification v2.3, sec 9.4 A special directory exists + * within the application hierarchy named WEB-INF. This directory contains all + * things related to the application that aren't in the document root of the + * application. It is important to note that the WEB-INF node is not part of + * the public document tree of the application. No file contained in the + * WEB-INF directory may be served directly to a client. + * + * @test_Strategy: 1) send a http request to WEB-INF directory 2) expect 404 + * or 403 3) repeat step 1 and 2 for the following a) web-inf (for case + * insensitive platforms) b) WEB-INF/web.xml c) web-inf/web.xml 4) based on + * the http return code report test status + */ + + public void test7() throws Exception { + List statusCodes; + + try { + // Try accessing WEB-INF + request = pageBase + "/WEB-INF/"; + + statusCodes = new ArrayList(); + statusCodes.add("404"); + statusCodes.add("403"); + + this.testStatusCodes(request, statusCodes, "test7"); + + // Try accessing /web-inf (for case insensitive platforms) + request = pageBase + "/web-inf/"; + + statusCodes = new ArrayList(); + statusCodes.add("404"); + statusCodes.add("403"); + + this.testStatusCodes(request, statusCodes, "test7"); + + // Try accessing WEB-INF/web.xml + request = pageBase + "/WEB-INF/web.xml"; + + statusCodes = new ArrayList(); + statusCodes.add("404"); + + this.testStatusCodes(request, statusCodes, "test7"); + + // Try accessing web-inf/web.xml (for case insensitive platforms) + request = pageBase + "/web-inf/web.xml"; + + statusCodes = new ArrayList(); + statusCodes.add("404"); + + this.testStatusCodes(request, statusCodes, "test7"); + + // Try accessing WEB-INF/web.xml + request = pageBase + "/WEB-INF/web.xml"; + + statusCodes = new ArrayList(); + statusCodes.add("404"); + + this.testStatusCodes(request, statusCodes, "test7"); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + /* + * testName: test8 + * + * @assertion: Servlet Specification v2.3, sec 9.5 Web applications can be + * packaged and signed, using the standard Java Archive tools, into a Web + * ARchive format (war) file. When packaged into such a form, a META-INF + * directory will be present which contains information useful to the Java + * Archive tools. If this directory is present, the servlet container must not + * allow it be served as content to a web client's request. + * + * @test_Strategy: 1) send a http request to META-INF directory 2) expect 404 + * or a 403 3) repeat step 1 and 2 for the following a) meta-inf (for case + * insensitive platforms) b) META-INF/MANIFEST.MF c) meta-inf/manifest.mf 4) + * based on the http return code, report test status + */ + + public void test8() throws Exception { + try { + + // Try accessing META-INF + request = pageBase + "/META-INF/"; + logMsg("Sending request \"" + request + "\""); + response = WebUtil.sendRequest("GET", InetAddress.getByName(hostname), + portnum, request, null, null); + + // Call followRedirect() to make sure we receive the required page + response = followRedirect(response, 8); + + // Receive "404" or "403" error code. + if (response.statusToken.equals("404") + || response.statusToken.equals("403")) { + logMsg("Status Token " + response.statusToken); + logMsg("Received expected error code"); + } else { + logErr("Did not receive expected error code" + request); + logMsg("Status Token " + response.statusToken); + logErr("Page content:"); + logErr(response.content); + throw new Exception("test8 failed."); + } + + // Try accessing /meta-inf (for case insensitive platforms) + request = pageBase + "/meta-inf/"; + logMsg("Sending request \"" + request + "\""); + response = WebUtil.sendRequest("GET", InetAddress.getByName(hostname), + portnum, request, null, null); + + // Call followRedirect() to make sure we receive the required page + response = followRedirect(response, 8); + + // Receive "404" or "403" error code. + if (response.statusToken.equals("404") + || response.statusToken.equals("403")) { + logMsg("Status Token " + response.statusToken); + logMsg("Received expected error code"); + } else { + logErr("Did not receive expected error code" + request); + logMsg("Status Token " + response.statusToken); + logErr("Page content:"); + logErr(response.content); + throw new Exception("test8 failed."); + } + + // Try accessing META-INF/MANIFEST.MF + request = pageBase + "/META-INF/MANIFEST.MF"; + logMsg("Sending request \"" + request + "\""); + response = WebUtil.sendRequest("GET", InetAddress.getByName(hostname), + portnum, request, null, null); + + // Call followRedirect() to make sure we receive the required page + response = followRedirect(response, 8); + + // Receive "404" or "403" error code. + if (response.statusToken.equals("404") + || response.statusToken.equals("403")) { + logMsg("Status Token " + response.statusToken); + logMsg("Received expected error code"); + } else { + logErr("Did not receive expected error code" + request); + logMsg("Status Token " + response.statusToken); + logErr("Page content:"); + logErr(response.content); + throw new Exception("test8 failed."); + } + + // Try accessing meta-inf/manifest.mf(for case insensitive platforms) + request = pageBase + "/meta-inf/manifest.mf"; + logMsg("Sending request \"" + request + "\""); + response = WebUtil.sendRequest("GET", InetAddress.getByName(hostname), + portnum, request, null, null); + + // Call followRedirect() to make sure we receive the required page + response = followRedirect(response, 8); + + // Receive "404" or "403" error code. + if (response.statusToken.equals("404") + || response.statusToken.equals("403")) { + logMsg("Status Token " + response.statusToken); + logMsg("Received expected error code"); + } else { + logErr("Did not receive expected error code" + request); + logMsg("Status Token " + response.statusToken); + logErr("Page content:"); + logErr(response.content); + throw new Exception("test8 failed."); + } + + } catch (Exception e) { + logErr("Caught exception: " + e.getMessage()); + e.printStackTrace(); + throw new Exception("test8 failed: ", e); + } + } + + /* + * testName: test9 + * + * @assertion: URLMapping from Servlet Specification v2.3, sec 11.2 + * + * 1) A string beginning with a / character and ending with a /* postfix is + * used as a path mapping. 2) A string beginning with a *. prefix is used as + * an extension mapping. 3) All other strings are used as exact matches only + * 4) A string containing only the / character indicates that servlet + * specified by the mapping becomes the "deException" servlet of the application. + * In this case the servlet path is the request URI minus the context path and + * the path info is null. + * + * + * @test_Strategy: 1) Deploy a two webcomponents One.jsp and Two.jsp + * exercising various mapping rules 2) Make a http request with a URL(based on + * the above mapping rules) 3) Make a http request with a absolute match URL. + * 4) compare the results obtained through step 2 and 3 and declare test + * result + * + */ + + public void test9() throws Exception { + try { + String testURL = null; + String exactMatchURL = null; + + // This tests exercises the URL mapping rules + // See compareURLContents() method description for more info + + // Note: pageOne can be a JSP or Servlet + // 1) for JSP + // pageOne = pageBase + "/One.jsp"; + // 2) for servlet + // pageOne = pageBase + "/OneTest"; + + // Try accessing pageOne using "/One/index.html" + testURL = pageBase + "/One/index.html"; + exactMatchURL = pageOne; + compareURLContents(testURL, 9, exactMatchURL); + + // Try accessing pageOne using "/One/*" + testURL = pageBase + "/One/*"; + exactMatchURL = pageOne; + compareURLContents(testURL, 9, exactMatchURL); + + // Note: pageTwo can be a JSP or Servlet + // 1) for JSP + // pageTwo = pageBase + "/Two.jsp"; + // 2) for servlet + // pageTwo = pageBase + "/TwoTest"; + + // Try accessing pageTwo using "*.jsp" + testURL = pageBase + "/*.jsp"; + exactMatchURL = pageTwo; + compareURLContents(testURL, 9, exactMatchURL); + + // Try accessing pageTwo using "*.two" + testURL = pageBase + "/*.two"; + exactMatchURL = pageTwo; + compareURLContents(testURL, 9, exactMatchURL); + + } catch (Exception e) { + logErr("Caught exception: " + e.getMessage()); + e.printStackTrace(); + throw new Exception("test9 failed: ", e); + } + } + + /* + * testName: test10 + * + * @assertion: Test isUserInRole(), specified in the Java Servlet + * Specification v2.3, Sec 12.3. + * + * The isUserInRole method expets a String rolename. In order that this + * rolename can be adjusted by the application assembler, or the deployer + * without having to recompile the Servlet making the call a + * element should be declared in the deployment descriptor + * with the sub-element containing the rolename passed into this + * call. The value of the sub-element is the of the + * that the programmer is testing that the caller is mapped to + * or not. The container is required to respect this mapping of + * to in this manner when determining the + * return value of the call. + * + * If, however, no has been declared with that + * matches the argument to isUserInRole, the container must deException to + * checking the argument against the list of s for this web + * application to determine whether the caller is mapped to the rolename + * passed in. + * + * @test_Strategy: Note: test5 and test6 verifies the first part of the + * assertion. This test verifies only the second part of this assertion + * + * 1. Send request to access Sample.jsp 2. Receive login page(make sure it is + * the expected login page) 3. Send form response with username and password + * 4. Receive Sample.jsp (ensure principal is correct, and ensure + * getRemoteUser() returns the username, and ensure isUserInRole() is working + * properly) + */ + + public void test10() throws Exception { + try { + requestAndGetLoginPage(pageSample, 10); + + // Send response to login form with session id cookie: + request = pageSecurityCheck; + logMsg( + "Sending request \"" + request + "\" with login information."); + Properties postData = new Properties(); + postData.setProperty("j_username", username); + postData.setProperty("j_password", password); + response = WebUtil.sendRequest("POST", InetAddress.getByName(hostname), + portnum, request, postData, cookies); + + // Check that the page was found (no error). + if (response.isError()) { + logErr("Could not find " + request); + throw new Exception("test10 failed."); + } + + // Call followRedirect() to make sure we receive the required page + response = followRedirect(response, 10); + + // Check to make sure we are authenticated by checking the page + // content. The jsp should output "The user principal is: j2ee" + String searchString = searchFor + username; + if (response.content.indexOf(searchString) == -1) { + logErr("User Principal incorrect. Page received:"); + logErr(response.content); + logErr("(Should say: \"" + searchString + "\")"); + throw new Exception("test10 failed."); + } + logMsg("User Principal correct."); + + // Check to make sure getRemoteUser returns the user name. + searchString = searchForGetRemoteUser + username; + if (response.content.indexOf(searchString) == -1) { + logErr("getRemoteUser() did not return " + username + ":"); + logErr(response.content); + logErr("(Should say: \"" + searchString + "\")"); + throw new Exception("test10 failed."); + } + logMsg("getRemoteUser() correct."); + + // Check to make sure isUserInRole is working properly: + Hashtable roleCheck = new Hashtable(); + roleCheck.put("Administrator", Boolean.TRUE); + if (!checkRoles(response.content, roleCheck)) { + logErr("isUserInRole() does not work correctly."); + logErr("Page Received:"); + logErr(response.content); + throw new Exception("test10 failed."); + } + logMsg("isUserInRole() correct."); + + } catch (Exception e) { + logErr("Caught exception: " + e.getMessage()); + e.printStackTrace(); + throw new Exception("test10 failed: ", e); + } + } + + /* + * testName: test11 + * + * @assertion: Servlet Specification v2.3, sec 13.2 DTD The auth-constraint + * element indicates the user roles that should be permitted access to this + * resource collection. The role used here must either in a security-role-ref + * element, or be the specially reserved role-name * that is a compact syntax + * for indicating all roles in the web application. If both * and rolenames + * appear, the container interprets this as all roles. + * + * @test_Strategy: Configure allRoles.jsp to be accessible by allRoles (*) + * + * 1) Try accesing allRoles.jsp as the following user a) j2ee b) javajoe 2) + * Based on the http reply, report test status + * + * + */ + + public void test11() throws Exception { + try { + + // Access allRoles.jsp as user "j2ee" + logMsg("\nAccessing allRoles.jsp as user j2ee"); + requestAndGetLoginPage(pageallRoles, 11); + request = pageSecurityCheck; + logMsg( + "Sending request \"" + request + "\" with login information."); + Properties postData = new Properties(); + postData.setProperty("j_username", username); + postData.setProperty("j_password", password); + response = WebUtil.sendRequest("POST", InetAddress.getByName(hostname), + portnum, request, postData, cookies); + + // Check that the page was found (no error). + if (response.isError()) { + logErr("Could not find " + request); + throw new Exception("test11 failed."); + } + + // Call followRedirect() to make sure we receive the required page + response = followRedirect(response, 11); + logMsg("Successfully accessed allRoles.jsp as user j2ee"); + + // Access allRoles.jsp as user "javajoe" + logMsg("\nAccessing allRoles.jsp as user javajoe"); + requestAndGetLoginPage(pageallRoles, 11); + request = pageSecurityCheck; + logMsg( + "Sending request \"" + request + "\" with login information."); + postData = new Properties(); + postData.setProperty("j_username", unauthUsername); + postData.setProperty("j_password", unauthPassword); + response = WebUtil.sendRequest("POST", InetAddress.getByName(hostname), + portnum, request, postData, cookies); + + // Check that the page was found (no error). + if (response.isError()) { + logErr("Could not find " + request); + throw new Exception("test11 failed."); + } + + // Call followRedirect() to make sure we receive the required page + response = followRedirect(response, 11); + + logMsg("Successfully accessed allRoles.jsp as user javajoe"); + + } catch (Exception e) { + logErr("Caught exception: " + e.getMessage()); + e.printStackTrace(); + throw new Exception("test11 failed: ", e); + } + } + + /* + * testName: test12 + * + * @assertion: Servlet Specification v2.3, sec 13.2 (DTD) The + * web-resource-collection element is used to identify a subset of the + * resources and HTTP methods on those resources within a web application to + * which a security constraint applies. If no HTTP methods are specified, then + * the security constraint applies to all HTTP methods. + * + * @test_Strategy: 1) Do not specify any HTTP methods in the security + * constraints of Sample.jsp + * + * 2) Access Sample.jsp using HTTP methods GET, HEAD, POST, DELETE and PUT. + * + * 3) If Sample.jsp is accessible with all of the above HTTP methods then + * declare test successfull otherwise report test failure + * + * Note: test12 is ONLY for JSP Area + * + */ + + public void test12() throws Exception { + try { + // Access Sample.jsp using HTTP method POST + logMsg("\nAccessing pageSample Using HTTP method POST"); + requestAndGetLoginPage(pageSample, 12); + request = pageSecurityCheck; + logMsg( + "Sending request \"" + request + "\" with login information."); + Properties postData = new Properties(); + postData.setProperty("j_username", username); + postData.setProperty("j_password", password); + response = WebUtil.sendRequest("POST", InetAddress.getByName(hostname), + portnum, request, postData, cookies); + + // Check that the page was found (no error). + if (response.isError()) { + logErr("Could not find " + request); + throw new Exception("test12 failed."); + } + + // Call followRedirect() to make sure we receive the required page + response = followRedirect(response, 12); + + logMsg("response.content :" + response.content); + logMsg("Successfully accessed " + pageSample + " with \"POST\""); + + // Change the request to pageSample + request = pageSample; + + // Access pageSample using HTTP method GET + logMsg("\nAccessing pageSample Using HTTP method GET"); + response = WebUtil.sendRequest("GET", InetAddress.getByName(hostname), + portnum, request, postData, cookies); + + // Check that the page was found (no error). + if (response.isError()) { + logErr("Could not find " + request); + throw new Exception("test12 failed."); + } + + // Call followRedirect() to make sure we receive the required page + response = followRedirect(response, 12); + + logMsg("response.content :" + response.content); + logMsg("Successfully accessed " + pageSample + " with \"GET\""); + + // Access pageSample using HTTP method HEAD + logMsg("\nAccessing pageSample Using HTTP method HEAD"); + response = WebUtil.sendRequest("HEAD", InetAddress.getByName(hostname), + portnum, request, postData, cookies); + + // Check that the page was found (no error). + if (response.isError()) { + logErr("Could not find " + request); + throw new Exception("test12 failed."); + } + + // Call followRedirect() to make sure we receive the required page + response = followRedirect(response, 12); + + logMsg("response.content :" + response.content); + + logMsg("Successfully accessed " + pageSample + " with \"HEAD\""); + + // Read the contents of Sample.jsp and + // upload it using HTTP method PUT +// FileInputStream fstream = new FileInputStream( +// tshome + "/src/web/jsp/sec/secform/Sample.jsp"); + + InputStream fstream = + Thread.currentThread().getContextClassLoader().getResourceAsStream("sec/secform/Sample.jsp"); + + int fileContentLength = fstream.available(); + byte[] byteArray = new byte[1024]; + int bytesRead = fstream.read(byteArray, 0, fileContentLength); + + // Now use HTTP method DELETE and later use http method PUT + + // Delete pageSample using HTTP method DELETE + logMsg("\nDELETE " + pageSample + " Using HTTP method DELETE ...."); + response = WebUtil.sendRequest("DELETE", InetAddress.getByName(hostname), + portnum, request, postData, cookies); + + addNewCookies(cookies, response.cookies); + + // Check that the page was found (no error). + if (response.isError()) { + logErr("Could not find " + request); + throw new Exception("test12 failed."); + } + logMsg("response.content :" + response.content); + logMsg("Successfully accessed " + pageSample + " with \"DELETE\""); + + // put pageSample using HTTP method PUT + logMsg("\nPUT " + pageSample + " Using HTTP method PUT ...."); + + response = uploadUsingHttpMethodPUT("PUT", + InetAddress.getByName(hostname), portnum, request, + byteArray, cookies, username, password); + + // Check that the page was found (no error). + if (response.isError()) { + logErr("Could not find " + request); + throw new Exception("test12 failed."); + } + logMsg("response.content :" + response.content); + logMsg("response.statusToken :" + response.statusToken); + logMsg("uploaded " + pageSample + "using HTTP method PUT"); + + } catch (Exception e) { + logErr("Caught exception: " + e.getMessage()); + e.printStackTrace(); + throw new Exception("test12 failed: ", e); + } + } + + /* + * testName: test13 + * + * @assertion: Servlet Specification v2.3, sec 12.2 The security model does + * not apply when a servlet uses the RequestDispatcher to invoke a static + * resource or servlet using a forward or an include. + * + * + * @test_Strategy: + * + * 1) Configure two servlets (IncludedServlet and ForwardedServlet) to be + * accessible only by administrator. + * + * 2) Configure ControlServlet to be accessible by everyone (i.e no security + * constraints for ControlServlet) + * + * 3) Now as a unauthenticated user access ForwardedServlet and + * IncludedServlet from ControlServlet + * + * ControlServlet ===>ForwardedServlet===>IncludedServlet + * + * i.e 3.1) From a ControlServlet access ForwardedServlet through dispatcher's + * forward method. + * + * 3.2) From the ForwardedServlet access/include IncludedServlet through + * Request dispatcher's include method + * + * 4) If the servlets(ForwardedServlet and IncludedServlet) are accessible + * report the test success otherwise report test failure + * + * Note: test13 is ONLY for SERVLET Area + * + */ + + public void test13() throws Exception { + try { + + request = pageServletBase + "/ControlServlet"; + + // Access ControlServlet" + logMsg("\nAccessing ControlServlet"); + logMsg("Sending request " + request); + response = WebUtil.sendRequest("POST", InetAddress.getByName(hostname), + portnum, request, null, null); + logMsg("response.content 1:" + response.content); + + // Check that the page was found (no error). + if (response.isError()) { + logErr("Could not find " + request); + throw new Exception("test13 failed."); + } + + // Call followRedirect() to make sure we receive the required page + response = followRedirect(response, 13); + logMsg("response.content 2:" + response.content); + logMsg("Successfully accessed ControlServlet," + + " ForwardedServlet and IncludedServlet"); + + } catch (Exception e) { + logErr("Caught exception: " + e.getMessage()); + e.printStackTrace(); + throw new Exception("test13 failed: ", e); + } + } + + /* + * testName: test14 + * + * @assertion: Test FORM-based authentication, specified in the Java Servlet + * Specification v2.3, Sec 12.6 + * + * Therefore, a servlet container is required to track authentication + * information at the container level (rather than at the web application + * level). This allows users authenticated for one web application to access + * other resources managed by the container permitted to the same security + * identity. + * + * @test_Strategy: 1. Configure pageSec(jspSec.jsp or ServletSecTest) and + * pageSample(Sample.jsp or SampleTest ) to be accessible only by + * Administrator 2. Send request to access jspSec.jsp 3. Receive login page 4. + * Send form response with username and password 5. Receive jspSec.jsp (ensure + * principal is correct, and ensure getRemoteUser() returns the username, and + * ensure isUserInRole() is working properly) 6. Try accessing + * pageSample(Sample.jsp or SampleTest) which is also configured to be + * accessible with the same security identity, since we are already + * authenticated we should be able to access pageSample without going through + * login page again. 7. Ensure principal is still correct and getRemoteUser() + * still returns the correct username. Also ensure isUserInRole() is still + * working properly. + */ + + public void test14() throws Exception { + try { + logMsg("\nAccessing pageSec: " + pageSec); + requestAndGetLoginPage(pageSec, 14); + + // Send response to login form with session id cookie: + request = pageSecurityCheck; + logMsg( + "Sending request \"" + request + "\" with login information."); + Properties postData = new Properties(); + postData.setProperty("j_username", username); + postData.setProperty("j_password", password); + response = WebUtil.sendRequest("POST", InetAddress.getByName(hostname), + portnum, request, postData, cookies); + + // Check that the page was found (no error). + if (response.isError()) { + logErr("Could not find " + request); + throw new Exception("test14 failed."); + } + + // Call followRedirect() to make sure we receive the required page + response = followRedirect(response, 14); + + // Check to make sure we are authenticated by checking the page + // content. The jsp should output "The user principal is: j2ee" + String searchString = searchFor + username; + if (response.content.indexOf(searchString) == -1) { + logErr("User Principal incorrect. Page received:"); + logErr(response.content); + logErr("(Should say: \"" + searchString + "\")"); + throw new Exception("test14 failed."); + } + logMsg("User Principal correct."); + + // Check to make sure getRemoteUser returns the user name. + searchString = searchForGetRemoteUser + username; + if (response.content.indexOf(searchString) == -1) { + logErr("getRemoteUser() did not return " + username + ":"); + logErr(response.content); + logErr("(Should say: \"" + searchString + "\")"); + throw new Exception("test1 failed."); + } + logMsg("getRemoteUser() correct."); + + // Check to make sure isUserInRole is working properly: + Hashtable roleCheck = new Hashtable(); + roleCheck.put("ADM", Boolean.TRUE); + roleCheck.put("MGR", Boolean.FALSE); + roleCheck.put("VP", Boolean.FALSE); + roleCheck.put("EMP", Boolean.TRUE); + // roleCheck.put( "Administrator", new Boolean( false ) ); + if (!checkRoles(response.content, roleCheck)) { + logErr("isUserInRole() does not work correctly."); + logErr("Page Received:"); + logErr(response.content); + throw new Exception("test14 failed."); + } + logMsg("isUserInRole() correct."); + + // Now that we are authenticated, try accessing pageSample + // without going through the login page again. + request = pageSample; + logMsg("\nAccessing pageSample :" + request); + response = WebUtil.sendRequest("GET", InetAddress.getByName(hostname), + portnum, request, null, cookies); + + // Check that the page was found (no error). + if (response.isError()) { + logErr("Could not find " + pageSec); + throw new Exception("test14 failed."); + } + + // Check to make sure we are still authenticated. + if (response.content.indexOf(searchString) == -1) { + logErr("User Principal incorrect. Page received:"); + logErr(response.content); + logErr("(Should say: \"" + searchString + "\")"); + throw new Exception("test14 failed."); + } + logMsg("User Principal still correct."); + + // Check to make sure getRemoteUser still returns the user name. + searchString = searchForGetRemoteUser + username; + if (response.content.indexOf(searchString) == -1) { + logErr("getRemoteUser() did not return " + username + + " after lazy authentication:"); + logErr(response.content); + logErr("(Should say: \"" + searchString + "\")"); + throw new Exception("test14 failed."); + } + logMsg("getRemoteUser() still correct."); + + } catch (Exception e) { + logErr("Caught exception: " + e.getMessage()); + e.printStackTrace(); + throw new Exception("test14 failed: ", e); + } + } + + /* + * testName: test15 + * + * @assertion: Test FORM-based authentication, specified in the Java Servlet + * Specification v2.3, Sec 12.6 + * + * This is similar to test14 except this is validating that we can not bypass + * security constraints when sso is on by simply adding "/j_security_check" to + * the request url. By adding "j_security_check" to the end of a request but + * not specifying authN creds, we should NOT be redirected to the + * requested/restricted page as we have not yet authenticated (even though we + * tried to trick/confuse the system by appending 'j_security_check' onto our + * request.) + * + * @test_Strategy: 1. attempt to access a protected resource by: Sending a + * request to access url: "/j_security_check" 2. We should not be + * authenticated yet so should get a response back from server with either an + * error or login form (we must verify that we are not authenticated and that + * we did NOT get the requested(and restricted) form back from server. + * + */ + + public void test15() throws Exception { + + String modifiedPageSec = pageSec + pageSecurityCheck; + try { + // 1. attempt to access a protected resource + TestUtil.logTrace("Sending request \"" + modifiedPageSec + "\""); + try { + response = WebUtil.sendRequest("GET", InetAddress.getByName(hostname), + portnum, modifiedPageSec, null, null); + } catch (Exception ex) { + // if here, problem as we should have been redirected + logErr( + "ERROR - got exception when trying to access restricted page w/out AuthN first."); + ex.printStackTrace(); + throw new Exception("test15 failed."); + } + + if (response != null) { + // if we got directed to login page that is okay too + TestUtil.logTrace("response.content=" + response.content); + + // 2. verify that the requested page was NOT accessed/found + String searchString = "getAuthType()"; // this string appears on the + // pageSec page + if (response.content.indexOf(searchString) != -1) { + // Error - it looks like we were able to access the requested page! + String err = "Error - we were not authenticated but were able to access the "; + err += "following page: " + modifiedPageSec + + " with a return status = " + response.statusToken; + logErr(err); + logErr("response.content = " + response.content); + throw new Exception("test15 failed."); + } else { + TestUtil.logTrace( + "Good - we were not able to access restricted page without authenticating."); + } + } else { + TestUtil.logTrace("response=null"); + } + + logMsg("test15 passed."); + + } catch (Exception e) { + logErr("Caught exception: " + e.getMessage()); + e.printStackTrace(); + throw new Exception("test15 failed: ", e); + } + } + + /* + * testName: test16 + * + * @assertion: Test ability to login via the HttpServletRequst.login() method. + * as specified in the Java Servlet Specification v3.1, Sec 13.3 + * + * If user has not been authenticated and user attempts to access an + * unprotected web resource, the user should be able to access it. Since the + * user was not authenticated, calls to getUserPrincipal() should not return + * the name of user "j2ee" since. Once in the servlet, we should be able to + * invoke the HttpServletRequest.login() call to authenticate user "j2ee" and + * then calls to getUserPrincipal() should return user "j2ee" + * + * + * @test_Strategy: 1. Send request to access ServletProgrammaticLogin 2. the + * servlet performs tasks and sends response data back 3. we parse the data to + * see if we got desired output + */ + + public void test16() throws Exception { + try { + + // Send request to ProgrammaticLogin servlet and include username + // and password for use within servlet + request = pageProgLogin; + + // set some params that will be needed from within the pageProgLogin + // servlet + Properties postData = new Properties(); + TestUtil.logTrace("setting request parameter my_username = " + username); + TestUtil.logTrace("setting request parameter my_password = " + password); + postData.setProperty("the_username", username); + postData.setProperty("the_password", password); + + logMsg("Sending request " + request); + response = WebUtil.sendRequest("POST", InetAddress.getByName(hostname), + portnum, request, postData, cookies); + + TestUtil.logTrace("response.content = \n" + response.content); + + if (!response.statusToken.equals("200")) { + logErr( + "ERROR: not able to do Programmatic Login in: " + pageProgLogin); + throw new Exception("test16 failed."); + } + + // Check that we did not receive an error + if (response.isError()) { + logErr("Error retrieving " + request); + throw new Exception("test16 failed."); + } + + TestUtil.logTrace(response.content); // debug aid + + // verify there were no errors detected fom within our servlet + String searchString = "ERROR - HttpServletRequest.login"; + if (response.content.indexOf(searchString) != -1) { + logErr(response.content); + throw new Exception("test16 failed."); + } + + // verify that we got success + searchString = "HttpServletRequest.login() passed"; + if (response.content.indexOf(searchString) == -1) { + logErr(response.content); + throw new Exception("test16 failed."); + } + + logMsg("test16 passed."); + + } catch (Exception e) { + logErr("Caught exception: " + e.getMessage()); + e.printStackTrace(); + throw new Exception("test16 failed: ", e); + } + } + + /* + * testName: test17 + * + * @assertion: Test FORM-based authentication, specified in the Java Servlet + * Specification v2.2, Sec 11.5.3. + * + * If user has been authenticated and user attempts to access a protected web + * resource, and user enters correct username and password of a user that is + * authorized to access the resource, the resource is returned (similar to + * test1) + * + * @test_Strategy: 1. Send request to access protected page (ie. + * pageServletProgLogout) 2. Receive login page 3. Send form response with + * username(j2ee) and password 4. Receive resource 5. make sure no ERRORs + * occurrred on pageServletProgLogout and that it actually did log us out. + * + */ + + public void test17() throws Exception { + try { + requestAndGetLoginPage(pageServletProgLogout, 1); + + // Send response to login form with session id cookie: + request = pageSecurityCheck; + logMsg( + "Sending request \"" + request + "\" with login information."); + Properties postData = new Properties(); + postData.setProperty("j_username", username); + postData.setProperty("j_password", password); + response = WebUtil.sendRequest("POST", InetAddress.getByName(hostname), + portnum, request, postData, cookies); + + // Check that the page was found (no error). + TestUtil.logTrace("response.content = " + response.content); // debug aid + if (response.isError()) { + logErr("Could not find " + request); + throw new Exception("test17 failed."); + } + + // Call followRedirect() to make sure we receive the required page + response = followRedirect(response, 17); + TestUtil.logTrace("response.content = " + response.content); // debug aid + + // Check to make sure we are authenticated by checking the page + // content. It should contain the string below to indicate we + // properly accessed the servlet. + String searchString = "enterred ServletProgrammaticLogout.service()"; + if (response.content.indexOf(searchString) == -1) { + String str = "Error - Did not get expected content from page: " + + pageServletProgLogout; + str += " Content should have contained: " + searchString; + logErr(str); + throw new Exception("test17 failed."); + } + + // now make sure we didnt get any errors in our content + String errString = "ERROR - HttpServletRequest.logout()"; + if (response.content.indexOf(errString) != -1) { + // there was an error msg detected in servlet content + String str = "Error - returned in content from page: " + + pageServletProgLogout; + logErr(str); + throw new Exception("test17 failed."); + } + logMsg("test17 passed."); + + } catch (Exception e) { + logErr("Caught exception: " + e.getMessage()); + e.printStackTrace(); + throw new Exception("test17 failed: ", e); + } + } + + /* + * testName: test18 + * + * @assertion: Test ability to authenticate using + * HttpServletRequst.authenticate() as specified in the Java Servlet + * Specification v3.1, Sec 13.3 + * + * If user has not been authenticated and user attempts to access an + * unprotected web resource, the user should be able to access it. Since the + * user was not authenticated, calls to getUserPrincipal() should return null. + * Calls to authenticate() should return false. Once in the servlet, we should + * be able to invoke the HttpServletRequest.login() call to login with user + * "j2ee" and then calls to getUserPrincipal() should return user "j2ee". + * Calls to authenticate() should return true. + * + * @test_Strategy: 1. Send request to access ServletProgrammaticLogin 2. the + * servlet performs tasks and sends response data back 3. we parse the data to + * see if we got desired output + */ + + public void test18() throws Exception { + try { + + // Send request to ProgrammaticLogin servlet and include username + // and password for use within servlet + request = pageProgAuthen; + + // set some params that will be needed from within the pageProgLogin + // servlet + Properties postData = new Properties(); + postData.setProperty("the_username", username); + postData.setProperty("the_password", password); + + logMsg("Sending request " + request); + response = WebUtil.sendRequest("POST", InetAddress.getByName(hostname), + portnum, request, postData, cookies); + + // Call followRedirect() to make sure we receive the required page + TestUtil.logTrace("YYYYY: response.content = \n" + response.content); + + if (!response.statusToken.equals("200")) { + logErr( + "ERROR: not able to do Programmatic Login in: " + pageProgLogin); + throw new Exception("test18 failed."); + } + + // Check that we did not receive an error + if (response.isError()) { + logErr("Error retrieving " + request); + throw new Exception("test18 failed."); + } + + // verify there were no errors detected fom within our servlet + String searchString = "ERROR - HttpServletRequest.authenticate"; + if (response.content.indexOf(searchString) != -1) { + logErr(response.content); + throw new Exception("test18 failed."); + } + + // now verify the authenticate truely passed + if (response.content + .indexOf("HttpServletRequest.authenticate passed") == -1) { + logErr(response.content); + throw new Exception("test18 failed."); + } + + logMsg("test18 passed."); + + } catch (Exception e) { + logErr("Caught exception: " + e.getMessage()); + e.printStackTrace(); + throw new Exception("test18 failed: ", e); + } + } + + /** + * Uploads data from a byteArray to an URL. A WebUtil.Response object is + * returned with the response information. + * + * @param method + * http method "PUT" + * @param addr + * Address of web server + * @param port + * Port of web server + * @param req + * The file to request (e.g. /jsp_dep_secContextRoot/jspSec.jsp) + * @param postData + * is a byteArray which contains the data to be posted + * @param cookieList + * A list of cookies to send when requesting the page. null if no + * cookie list is to be sent. + * @param username + * The username for authentication, null if no authentication + * required. + * @param password + * The password for authentication, null if no authentication + * required. + * @return WebUtil.Response object containing response information + * @exception IOException + * Thrown if request could not be made + */ + public static Response uploadUsingHttpMethodPUT(String method, + InetAddress addr, int port, String req, byte[] postData, + Hashtable cookieList, String username, String password) + throws IOException { + String protocol = "HTTP/1.0"; + URL requestURL; + Socket socket = null; + PrintWriter out = null; + BufferedReader in = null; + String line; + Response response = new Response(); + + try { + requestURL = new URL("http", addr.getHostName(), port, req); + req = method + " " + req + " " + protocol; + + socket = new Socket(addr, port); + + in = new BufferedReader(new InputStreamReader(socket.getInputStream())); + out = new PrintWriter(new OutputStreamWriter(socket.getOutputStream())); + out.println(req); + + if (cookieList != null) { + // Send cookies: + Enumeration keys = cookieList.keys(); + + // Does at least one cookie exist? + if (keys.hasMoreElements()) { + String cookieString = "Cookie: "; + + // Add each cookie to the string + boolean first = true; + while (keys.hasMoreElements()) { + String key = (String) keys.nextElement(); + String value = (String) cookieList.get(key); + cookieString += (first ? "" : "; ") + key + "=" + value; // + "; + // $Path=/"; + first = false; + } + + // Write cookies: + out.println(cookieString); + } + } + + // Send authentication information if necessary: + if (username != null) { + String code = WebUtil.encodeBase64(username + ":" + password); + out.println("Authorization: Basic " + code.trim()); + } + + // Send extra header information if we are posting. + if (postData != null) { + out.println("Content-type: text/data"); + } + + // Read the file contents from the byte array(postData) + // and store it in a string(fileContents) + StringBuffer content = new StringBuffer(1024); + ByteArrayInputStream bais = new ByteArrayInputStream(postData); + int c; + while ((c = bais.read()) != -1) { + content.append((char) c); + } + String fileContents = content.toString(); + + // TestUtil.logMsg("File Content: "+ fileContents); + + // If this is a post request, send post data: + if ((postData != null) && method.toUpperCase().equals("PUT")) { + String postString = WebUtil.encodeBase64(fileContents); + + // Skip a line: + out.println("Content-length: " + postString.length()); + out.println(""); + out.println(postString); + } else { + // Skip a line: + out.println(""); + } + + out.flush(); + + // Read first line and check for HTTP version and OK. + line = in.readLine(); + if (line != null) { + + StringTokenizer st = new StringTokenizer(line.trim()); + response.versionToken = st.nextToken(); + response.statusToken = st.nextToken(); + } + + // Read each line of the header until we hit a blank line + while ((line = in.readLine()) != null) { + + // Blank line means we are done with the header: + if (line.trim().equals("")) { + break; + } + + // Analyze special tags location and set cookie + if (line.toLowerCase().startsWith("location:")) { + // This is a redirect. Extract valuable infomration: + response.location = line.substring(10); + } else if (line.toLowerCase().startsWith("set-cookie:")) { + // This is a cookie. Add the cookie to the response + // object. + response.parseCookie(line); + } else if (line.toLowerCase().startsWith("www-authenticate:")) { + // Request to authenticate this page. + response.authenticationRequested = true; + } + } + + // The rest is content: + while ((line = in.readLine()) != null) { + response.content += line + "\n"; + } + + in.close(); + out.close(); + } catch (MalformedURLException e) { + throw new IOException("MalformedURLException: " + e.getMessage()); + } catch (UnknownHostException e) { + throw new IOException("UnknownHostException: " + e.getMessage()); + } catch (ConnectException e) { + throw new IOException("ConnectException: " + e.getMessage()); + } + + return response; + } + + /** + * Outputs a single line of text to the given output stream. Appends a \r\n + * automatically. By adding a System.out.println here, you can easily echo + * what is being sent to the web server. + */ + private static void send(PrintWriter out, String s) { + out.print(s + "\r\n"); + } + + /** + * Helper method that is used in tests 1, 2 and 3. Performs the following + * actions: + * + * 1. Send request to access passed in url 2. Receive redirect to login page, + * extract location and session id cookie 3. Send request to access new + * location, send cookie 4. Receive login page + * + * @param request + * The initial page to request + * @param testNum + * The test number for correct display of error messages. + */ + private void requestAndGetLoginPage(String request, int testNum) + throws Exception { + // Request restricted jsp page. + logMsg("Sending request \"" + request + "\""); + response = WebUtil.sendRequest("GET", InetAddress.getByName(hostname), + portnum, request, null, null); + + // Check that the page was found (no error). + if (response.isError()) { + logErr("Could not find " + request); + throw new Exception("test" + testNum + " failed."); + } + + // if (response.statusToken=302) + // then follow redirect to get the login page + + if (response.statusToken.equals("302")) { + // We should receive a redirection to the login page: + if (response.location == null) { + logErr("No redirection to login page received."); + throw new Exception("test" + testNum + " failed."); + } + + // Extract location from redirection and format new request: + request = WebUtil.getRequestFromURL(response.location); + logMsg("Redirect to: " + response.location); + + // Extract cookies: + cookies = response.cookies; + + logMsg("Before requesting redirected Page:" + "response.content=" + + response.content); + + // Request redirected page (login page): + logMsg("Sending request \"" + request + "\""); + response = WebUtil.sendRequest("GET", InetAddress.getByName(hostname), + portnum, request, null, cookies); + + // Check that the page was found (no error). + if (response.isError()) { + logErr("Could not find " + request); + throw new Exception("test" + testNum + " failed."); + } + + } else { + // Extract cookies: + cookies = response.cookies; + } + + // Because the authentication data is posted on the registered login form, + // There is no need to compare login page here. + /* + * request = pageLogin; + * + * // Request login page TestUtil.logMsg( "Sending request \"" + request + + * "\"" ); loginPageRequestResponse = WebUtil.sendRequest( "GET", + * InetAddress.getByName( hostname ), portnum, request, + * null, cookies ); + * + * // Check that the page was found (no error). if( + * loginPageRequestResponse.isError() ) { TestUtil.logErr( "Could not find " + * + request ); throw new Exception( "test" + testNum + " failed." ); } + * + * //Compare the received login page with the expected login page // i.e + * Check whether response.content ==loginPageRequestResponse.content if + * (response.content.equals(loginPageRequestResponse.content)) + * TestUtil.logMsg("Received the expected login form"); else { + * TestUtil.logMsg("response.conent\n"+response.content); + * TestUtil.logMsg("loginPageRequestResponse.conent\n"+ + * loginPageRequestResponse.content); + * TestUtil.logMsg("Received incorrect login form"); throw new Exception( "test" + * + testNum + " failed." ); } + */ + + } + + /** + * Helper method that is used in test 9. Performs the following actions: + * + * 1. Send request to access a jsp using testURL (for example testURL can be + * "/*.jsp") 2. Checks the status of the http reply 3. If the page is not + * accessible throw exception 4. If the page is accessible, then compare the + * content from the testURL with the contents of exact match URL. i.e compare + * 1) TEST URL : http://hostname:port/context_root/*.jsp 2) Exact match URL: + * http://hostname:port/context_root/foo.jsp + * + * Note: Here *.jsp is mapped to foo.jsp + * + * If the contents are same then the mapping is correct, otherwise throw + * exception + * + * @param testURL + * The test URL (for example "/*.jsp") + * @param testNum + * The test number for correct display of error messages. + * @param exactMatchURL + * The exact match URL (for example "/foo.jsp") + */ + private void compareURLContents(String testURL, int testNum, + String exactMatchURL) throws Exception { + // Request a jsp page using testURL. + logMsg("Sending request \"" + testURL + "\""); + response = WebUtil.sendRequest("GET", InetAddress.getByName(hostname), + portnum, testURL, null, null); + + // Check that the page was found (no error). + if (response.isError()) { + logErr("Could not find " + testURL); + throw new Exception("test" + testNum + " failed."); + } + + Response response2 = null; + + // Request the jsp page using exactMatchURL. + logMsg("Sending request \"" + exactMatchURL + "\""); + response2 = WebUtil.sendRequest("GET", InetAddress.getByName(hostname), + portnum, exactMatchURL, null, null); + + // Check that the page was found (no error). + if (response.isError()) { + logErr("Could not find " + exactMatchURL); + throw new Exception("test" + testNum + " failed."); + } + + logMsg("Comparing contents of " + testURL + " and " + exactMatchURL); + + // compare the contents of testURL and exactMatchURL + if (!response.content.equals(response2.content)) { + logErr( + "MISMATCH in contents of " + testURL + " and " + exactMatchURL); + logErr("contents of " + testURL); + logErr(response.content); + logErr("contents of " + exactMatchURL); + logErr(response2.content); + throw new Exception("test" + testNum + " failed."); + } else { + logMsg("Contents MATCH : correct URL mapping\n"); + } + + } + + /** + * Helper method to check that isUserInRole is working correctly. Searches the + * given page content for "isUserInRole( x ): !y!" for each x = key in + * Hashtable and y = corresponding value in hashtable. If all results are as + * expected, returns true, else returns false. + */ + private boolean checkRoles(String content, Hashtable roleCheck) { + Enumeration keys = roleCheck.keys(); + boolean pass = true; + + while (pass && keys.hasMoreElements()) { + String key = (String) keys.nextElement(); + boolean expected = ((Boolean) roleCheck.get(key)).booleanValue(); + + String search = "isUserInRole(\"" + key + "\"): !" + expected + "!"; + String logMsg = "Searching for \"" + search + "\": "; + + if (content.indexOf(search) == -1) { + pass = false; + logMsg += "NOT FOUND!"; + } else { + logMsg += "found."; + } + + logMsg(logMsg); + } + + return pass; + } + + public void cleanup() throws Exception { + logMsg("cleanup"); + } + + /** + * Helper method that is used in tests 1, 2, 3, 5 and 6. Performs the + * following actions: + * + * 1. Checks whether the response.statusToken==302 or 301 + * if(response.statusToken==302) || (response.statusToken==301) send request + * to redirected URL 2. Returns Response object + * + * @param response + * The initial page response + * @param testNum + * The test number for correct display of error messages. + */ + public Response followRedirect(Response response, int testNum) + throws Exception { + + // if (response.statusToken=302) + // send request to redirected URL + if ((response.statusToken.equals("301")) + || (response.statusToken.equals("302"))) { + // We should receive a redirection page: + if (response.location == null) { + logErr("redirection URL : null"); + throw new Exception("test" + testNum + " failed."); + } + + // Extract location from redirection and format new request: + request = WebUtil.getRequestFromURL(response.location); + logMsg("Redirect to: " + response.location); + + // update cookies if the webserver choose to send cookies, + // immediately after a successful http post request. + addNewCookies(cookies, response.cookies); + + // Request redirected page + logMsg("Sending request \"" + request + "\""); + response = WebUtil.sendRequest("GET", InetAddress.getByName(hostname), + portnum, request, null, cookies); + + // After a succesful http post request, + // Sun's Reference Implementation returns a redirected URL + // (Note: No cookies are sent back to the client at this point) + // Only when the client accesses the redirected URL, + // Sun RI sends a cookie (single sign on cookie) back to + // the client. So update cookies hashtable with new cookies + addNewCookies(cookies, response.cookies); + + // Do not check for error code for testNum 7 and testNum 8 + // those test access an unauthorized resource and expect + // error code. + if (testNum != 7 && testNum != 8) { + // Check that the page was found (no error). + if (response.isError()) { + logErr("Status Token " + response.statusToken); + logErr("Could not find " + request); + throw new Exception("test" + testNum + " failed."); + } + } + } else { + // After a successful post request, if a webserver + // returns the webresource without redirecting to new URL + // then update any new cookies received during this process. + addNewCookies(cookies, response.cookies); + + } + + return response; + } + + /** + * Helper method that is used to update cookies + * + * This helper method retrieves cookies from "newCookies" hashtable and + * updates it to "oldCookies" hashtable + * + * @param oldCookies + * Hashtable containing original cookies + * @param newCookies + * Hashtable containing new cookies error messages. + */ + public void addNewCookies(Hashtable oldCookies, Hashtable newCookies) { + // Add new cookie/cookies to the existing cookies Hashtable + for (Enumeration e = newCookies.keys(); e.hasMoreElements();) { + // get cookie name + String name = (String) e.nextElement(); + + // get value for this name + String value = (String) newCookies.get(name); + + if (oldCookies == null) { + oldCookies = new Hashtable(); + } + + // Add this name value pair (cookie) to old cookies + oldCookies.put(name.trim(), value.trim()); + + } + } + + /** + * Get the HttpResponse, and check the status code to see if matches one of + * the expected status codes. + * + * @param request- + * @String request URL + * @param expectedCodes + * - @List<@String> status codes we will test for + * @param testName + * - The name calling test + */ + private void testStatusCodes(String request, List expectedCodes, + String testName) throws Exception { + + try { + logMsg("Sending request \"" + request + "\""); + response = WebUtil.sendRequest("GET", InetAddress.getByName(hostname), + portnum, request, null, null); + + // Call followRedirect() to make sure we receive the required page + response = followRedirect(response, 7); + + // Check status code(s). + if (expectedCodes.contains(response.statusToken)) { + logMsg("Status Token " + response.statusToken); + logMsg("Received expected error code"); + + } else { + logErr("Did not receive expected error code" + request); + logMsg("Status Token " + response.statusToken); + logErr("Page content: "); + logErr(response.content); + throw new Exception(testName + " failed."); + } + + } catch (Exception e) { + logErr("Caught exception: " + e.getMessage()); + e.printStackTrace(); + throw new Exception(testName + " failed: ", e); + } + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/request/TestCase.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/request/TestCase.java new file mode 100644 index 0000000000..2719db0acb --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/request/TestCase.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2007, 2018 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$ + */ + +package com.sun.ts.tests.servlet.common.request; + +/** + * This interface defines a base set of methods required used by a TS test case. + */ +public interface TestCase { + + /** + * Executes the test case. + * + * @throws Exception if the test fails for any reason. + */ + public void execute() throws Exception; + + /** + * Sets the name of the test case. + * + * @param name + * of the test case + */ + public void setName(String name); + + /** + * Returns the name of this test case. + * + * @return test case name + */ + public String getName(); + + /** + * Sets the state for this test case. This state will differ from + * implementation to implementation. + * + * @param state + * test state + */ + public void setState(Object state); + + /** + * Returns the state of the test case. The state returned could possibly + * differ depending on when this method is called and when the test case has + * been executed. + */ + public Object getState(); + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/request/ValidationFactory.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/request/ValidationFactory.java new file mode 100644 index 0000000000..3caec6fd58 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/request/ValidationFactory.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2007, 2018 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$ + */ + +package com.sun.ts.tests.servlet.common.request; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Returns a ValidationStrategy instance used to validate a response against a + * particular WebTestCase + * + * @author Ryan Lubke + * @version %I% + */ +public class ValidationFactory { + + private static final Logger LOGGER = LoggerFactory.getLogger(ValidationFactory.class); + + /** + * Private constructor as all interaction with the class is through the + * getInstance() method. + */ + private ValidationFactory() { + } + + /* + * public methods + * ======================================================================== + */ + + /** + * Returns a ValidationStrategy instance based on the available factory types. + * + * @param validator + * Validator instance to obtain + * @return a ValidationStrategy instance or null if the instance could not be + * obtained. + */ + public static ValidationStrategy getInstance(String validator) { + try { + Object o = Thread.currentThread().getContextClassLoader() + .loadClass(validator).getDeclaredConstructor().newInstance(); + if (o instanceof ValidationStrategy) { + return (ValidationStrategy) o; + } + } catch (Throwable t) { + LOGGER.info("[ValidationFactory] Unable to obtain ValidationStrategy instance: {}", validator); + } + return null; + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/request/ValidationStrategy.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/request/ValidationStrategy.java new file mode 100644 index 0000000000..16e443f814 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/request/ValidationStrategy.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2007, 2018 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$ + */ +package com.sun.ts.tests.servlet.common.request; + +/** + * A ValidationStrategy is used to compare a server response with a configured + * test case. How this validation is performed is up to the concrete + * implementation. + */ +public interface ValidationStrategy { + boolean validate(WebTestCase testCase) throws Exception; +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/request/WebTestCase.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/request/WebTestCase.java new file mode 100644 index 0000000000..c4e6f4dc2c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/request/WebTestCase.java @@ -0,0 +1,553 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.common.request; + +import com.sun.ts.tests.servlet.common.response.validation.WebValidatorBase; +import org.apache.commons.httpclient.Header; +import org.apache.commons.httpclient.HttpState; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.StringTokenizer; + +/** + * A TestCase implementation for HTTP-based testing. This allows the user to set + * criteria for test success which will be compared against the response from + * the server. + */ +public class WebTestCase implements TestCase { + + private static final Logger LOGGER = LoggerFactory.getLogger(WebTestCase.class.getName()); + + public static final String BASED_STRATEGY = WebValidatorBase.class.getName(); + + + + /** + * The request for this case. + */ + private HttpRequest _request = null; + + /** + * The server's response. + */ + private HttpResponse _response = null; + + // use HttpMethod instances to store test + // case headers that are expected or not + // expected. + + /** + * Storage for headers that are expected in the response + */ + private Map _expected = null; + + /** + * Storage for headers that are not expected in the response + */ + private Map _unexpected = null; + + /** + * Expected response status code. + */ + private String _statusCode = null; + + /** + * Expected response reason phrase. + */ + private String _reasonPhrase = null; + + /** + * A List of strings that will be searched for in the response in the order + * they appear in the list. + */ + private List _searchStrings = null; + + /** + * A List of case insensitive strings that will be searched for in the + * response in the order they appear in the list. + */ + private List _searchStringsNoCase = null; + + /** + * A List of strings that will be search for in the response with no attention + * paid to the order they appear. + */ + private List _unorderedSearchStrings = null; + + /** + * A List of strings that should not be in the server's response. + */ + private List _uSearchStrings = null; + + /** + * Indicates whether a response body should be expected or not. + */ + private boolean _expectResponseBody = true; + + /** + * Strategy to use when validating the test case against the server's + * response. + */ + private ValidationStrategy _strategy = null; + + /** + * Logical name for test case. + */ + private String _name = "Test Case"; + + /** + * Creates a new instance of WebTestCase By default, a new WebTestCase + * instance will use the TokenizedValidator to verify the response with the + * configured properties of the test case. + */ + public WebTestCase() { + _strategy = ValidationFactory.getInstance(BASED_STRATEGY); + } + + /* + * public methods + * ======================================================================== + */ + /** + * Executes the test case. + * + * @throws Exception + * if the test fails for any reason. + * @throws IllegalStateException + * if no request was configured or if no Validator is available at + * runtime. + */ + public void execute() throws Exception { + + // If no request was created, we can't run. + if (_request == null) { + throw new IllegalStateException("[FATAL] HttpRequest is null."); + } + + // If no stragey instance is available (strange, but has happened), + // fail. + if (_strategy == null) { + throw new IllegalStateException("[FATAL] No Validator available."); + } + + try { + _response = _request.execute(); + } catch (Throwable t) { + String message = t.getMessage(); + throw new Exception("[FATAL] Unexpected failure during test execution." + (message == null ? t.toString() : message), t); + } + + // Validate this test case instance + if (!_strategy.validate(this)) { + throw new Exception("Test FAILED!"); + } + + } + + /** + * Sets the status code to be expected in the response from the server, i.e. + * 500 or 404, etc. + * + * @param statusCode + * the expected status code + */ + public void setExpectedStatusCode(String statusCode) { + _statusCode = statusCode; + } + + /** + * Sets the reason phrase to be expected in the response from the server. + * + * @param reasonPhrase + * the expected reason-phrase + */ + public void setExpectedReasonPhrase(String reasonPhrase) { + _reasonPhrase = reasonPhrase; + } + + /** + * Adds a header that is to be expected in the response from the server. + * + * @param header + * in the format of : (test:foo) + */ + public void addExpectedHeader(String header) { + if (_expected == null) { + _expected = new HashMap<>(); + } + addHeader(_expected, header); + } + + /** + * Sets the request that should be dispatched by this test case. + * + * @param request + * the HTTP request used for this test case + */ + public void setRequest(HttpRequest request) { + _request = request; + } + + /** + * Adds a header that is should not be in the server's response. + * + * @param header + * in the format of : (test:foo) + */ + public void addUnexpectedHeader(String header) { + if (_unexpected == null) { + _unexpected = new HashMap<>(); + } + addHeader(_unexpected, header); + } + + /** + * Enables/Disables an assertion that a response body is present. + * + * @param value + * a value of true will enable the assertion. + */ + public void setAssertNoResponseBody(boolean value) { + } + + /** + * Sets a string that will be scanned for and expected in the response body + * from the server. + * + * If multiple search strings are required, one can either call this method + * for each string, or pass in one string with pipe | delimiting + * the individual search strings within the large string. + * + * @param searchString + * a string expected in the server's response body + */ + public void setResponseSearchString(String searchString) { + if (_searchStrings == null) { + _searchStrings = new ArrayList<>(); + } + addSearchStrings(_searchStrings, searchString); + } + + /** + * Sets a string that will be scanned for and expected in the response body + * from the server. + * + * If multiple search strings are required, one can either call this method + * for each string, or pass in one string with pipe | delimiting + * the individual search strings within the large string. + * + * @param searchString + * a case insensitive string expected in the server's response body + */ + public void setResponseSearchStringIgnoreCase(String searchString) { + if (_searchStringsNoCase == null) { + _searchStringsNoCase = new ArrayList<>(); + } + addSearchStrings(_searchStringsNoCase, searchString); + } + + /** + * Sets a string that will be scanned for and should not be present in the + * response body from the server. + * + * If multiple search strings are required, one can either call this method + * for each string, or pass in one string with pipe | delimiting + * the individual search strings within the large string. + * + * @param searchString + * a string that is not expected in the server's response body + */ + public void setUnexpectedResponseSearchString(String searchString) { + if (_uSearchStrings == null) { + _uSearchStrings = new ArrayList<>(); + } + addSearchStrings(_uSearchStrings, searchString); + } + + /** + * Sets a string or series of strings that will be searched for in the + * response. If multiple search strings are required, one can either call this + * method for each string, or pass in one string with pipe | + * delimiting the individual search strings within the large string. + * + * @param searchString + * a string that is not expected in the server's response body + */ + public void setUnorderedSearchString(String searchString) { + if (_unorderedSearchStrings == null) { + _unorderedSearchStrings = new ArrayList<>(); + } + addSearchStrings(_unorderedSearchStrings, searchString); + } + + /** + * Returns the list of search strings. + * + * @return the list of search strings. + */ + public List getUnorderedSearchStrings() { + return _unorderedSearchStrings; + } + + /** + * Returns the response for this particular test case. + * + * @return an HttpResponse object + */ + public HttpResponse getResponse() { + return _response; + } + + /** + * Returns an array of Header objects that are expected to be found in the + * responst. + * + * @return an array of headers + */ + public Header[] getExpectedHeaders() { + if (_expected == null) { + return null; + } + return _expected.values().toArray(new Header[0]); + } + + /** + * Returns an array of Header objects that are not expected to be found in the + * responst. + * + * @return an array of headers + */ + public Header[] getUnexpectedHeaders() { + if (_unexpected == null) { + return null; + } + return _unexpected.values().toArray(new Header[0]); + } + + /** + * Returns the status code expected to be found in the server's response + * + * @return status code + */ + public String getStatusCode() { + return _statusCode; + } + + /** + * Returns the reason phrase that is expected to be found in the server's + * response. + * + * @return reason phrase + */ + public String getReasonPhrase() { + return _reasonPhrase; + } + + /** + * Returns the configured list of strings that will be used when scanning the + * server's response. + * + * @return list of Strings + */ + public List getSearchStrings() { + if (_searchStrings == null) { + return null; + } + return _searchStrings; + } + + /** + * Returns the configured list of strings that will be used when scanning the + * server's response. + * + * @return list of case insensitive Strings + */ + public List getSearchStringsNoCase() { + if (_searchStringsNoCase == null) { + return null; + } + return _searchStringsNoCase; + } + + /** + * Returns the configured list of strings that will be used when scanning the + * server's response (these strings are not expected in the response). + * + * @return list of Strings + */ + public List getUnexpectedSearchStrings() { + if (_uSearchStrings == null) { + return null; + } + return _uSearchStrings; + } + + /** + * Returns an indicator on whether a response body is expected or not. + * + * @return boolean value + */ + public boolean getExpectResponseBody() { + return _expectResponseBody; + } + + /** + * Returns the HttpRequest for this particular test case. + * + * @return HttpRequest of this test case + */ + public HttpRequest getRequest() { + return _request; + } + + /** + * Returns the state for this particular test case. + * + * @return test state + */ + public Object getState() { + if (_response != null) { + return _response.getState(); + } else { + // an initial request for state + return _request.getState(); + } + } + + /** + * Sets the state for this test case. + * + * @param state + * test state + */ + public void setState(Object state) { + _request.setState((HttpState) state); + } + + /** + * Sets a logical name for this test case. + * + * @param name + * the logical name for this test + */ + public void setName(String name) { + _name = name; + } + + /** + * Returns the logical name for this test case. + * + * @return test name + */ + public String getName() { + return _name; + } + + /** + * Sets the validation strategy for this test case instance. + * + * @param validator + * - the fully qualified class name of the response validator to use. + */ + public void setStrategy(String validator) { + ValidationStrategy strat = ValidationFactory.getInstance(validator); + if (strat != null) { + _strategy = strat; + } else { + LOGGER.info("[WebTestCase][WARNING] An attempt was made to use a non-existing validator ({}) . Falling back to the TokenizedValidator", validator); + } + } + + /** + * Returns the class name of the response validator used. + * + * @return the fully qualified class of the validator used + */ + public String getStrategy() { + return _strategy.getClass().getName(); + } + + /* + * Private Methods + * =========================================================================== + */ + + /** + * Utility method to add headers to test case holder objects. + * + * @param map + * the object in which to add header to + * @param headerString + * String representation of a header in the form of + * : + */ + private void addHeader(Map map, String headerString) { + LOGGER.debug("[WebTestCase] addHeader utility method called: {}", headerString); + StringTokenizer st = new StringTokenizer(headerString, "|"); + while (st.hasMoreTokens()) { + String head = st.nextToken(); + int colIdx = head.indexOf(':'); + String name = head.substring(0, colIdx).trim(); + String value = head.substring(colIdx + 1).trim(); + LOGGER.debug("[WebTestCase] Adding test header: {}, {}", name, value); + Header header = map.get(name); + if (header != null) { + map.put(name, createNewHeader(value, header)); + } else { + map.put(name, new Header(name, value)); + } + } + } + + /** + * Creates a new header based of the provided header and value. + * + * @param newValue + * - the new value to add to an existing header + * @param header + * - the original header + * @return new Header + */ + private Header createNewHeader(String newValue, Header header) { + String oldValue = header.getValue(); + return new Header(header.getName(), oldValue + ", " + newValue); + } + + /** + * Adds a search string to the provided list + * + * @param stringList + * - list to add the string to + * @param s + * - the search string + */ + private void addSearchStrings(List stringList, String s) { + StringTokenizer st = new StringTokenizer(s, "|"); + while (st.hasMoreTokens()) { + stringList.add(st.nextToken()); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/request/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/request/build.xml new file mode 100644 index 0000000000..d02bb0dd62 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/request/build.xml @@ -0,0 +1,22 @@ + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/response/HttpResponseClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/response/HttpResponseClient.java new file mode 100644 index 0000000000..095a438612 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/response/HttpResponseClient.java @@ -0,0 +1,278 @@ +/* + * Copyright (c) 2007, 2018 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$ + */ + +package com.sun.ts.tests.servlet.common.response; + +import com.sun.ts.tests.servlet.common.util.Data; + +public class HttpResponseClient extends ResponseClient { + + + public void addCookieTest() throws Exception { + String testName = "addCookieTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + + getServletName() + "?testname=" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(EXPECTED_HEADERS, + "set-Cookie:cookie1=value1|set-Cookie:cookie2=value2"); + invoke(); + } + + + public void addDateHeaderTest() throws Exception { + String testName = "addDateHeaderTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + + getServletName() + "?testname=" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(EXPECTED_HEADERS, + "DateInfo:Sat, 25 Apr 1970 07:29:03 GMT"); + invoke(); + } + + + public void addHeaderTest() throws Exception { + String testName = "addHeaderTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + + getServletName() + "?testname=" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(EXPECTED_HEADERS, + "header1:value1|header1:value11|header2:value2"); + invoke(); + } + + + public void addIntHeaderTest() throws Exception { + String testName = "addIntHeaderTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + + getServletName() + "?testname=" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(EXPECTED_HEADERS, + "intHeader1:1|intHeader1:11|intHeader2:2"); + invoke(); + } + + + public void containsHeaderTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "containsHeaderTest"); + invoke(); + } + + + public void sendErrorClearBufferTest() throws Exception { + String testName = "sendErrorClearBufferTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + + getServletName() + "?testname=" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, GONE); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, + "THIS TEXT SHOULD NOT APPEAR"); + invoke(); + } + + + public void sendErrorIllegalStateExceptionTest() throws Exception { + String testName = "sendErrorIllegalStateExceptionTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + + getServletName() + "?testname=" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, + "THIS TEXT SHOULD APPEAR|" + Data.PASSED); + invoke(); + } + + + public void sendError_StringTest() throws Exception { + String testName = "sendError_StringTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + + getServletName() + "?testname=" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, GONE); + TEST_PROPS.setProperty(SEARCH_STRING, "in sendError_StringTest servlet"); + TEST_PROPS.setProperty(EXPECTED_HEADERS, + "Content-Type:text/html|header:sendError_StringTest|set-Cookie:cookie1=value1"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, + "THIS TEXT SHOULD NOT APPEAR"); + invoke(); + } + + + public void sendError_StringIllegalStateExceptionTest() throws Exception { + String testName = "sendError_StringIllegalStateExceptionTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + + getServletName() + "?testname=" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, + "THIS TEXT SHOULD APPEAR|" + Data.PASSED); + invoke(); + } + + + public void sendError_StringErrorPageTest() throws Exception { + String testName = "sendError_StringErrorPageTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(STATUS_CODE, "411"); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + + getServletName() + "?testname=" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Status Code: 411"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, + "THIS TEXT SHOULD NOT APPEAR"); + invoke(); + } + + + public void sendRedirectWithLeadingSlashTest() throws Exception { + String testName = "sendRedirectWithLeadingSlashTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + + getServletName() + "?testname=" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(EXPECTED_HEADERS, + "Location: http://" + _hostname + ":" + _port + "/RedirectedTest"); + TEST_PROPS.setProperty(STATUS_CODE, MOVED_TEMPORARY); + invoke(); + } + + + public void sendRedirectWithoutLeadingSlashTest() throws Exception { + String testName = "sendRedirectWithoutLeadingSlashTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + + getServletName() + "?testname=" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(EXPECTED_HEADERS, "Location: http://" + _hostname + + ":" + _port + "" + getContextRoot() + "/RedirectedTest"); + TEST_PROPS.setProperty(STATUS_CODE, MOVED_TEMPORARY); + invoke(); + } + + + public void sendRedirectIllegalStateExceptionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "sendRedirectIllegalStateExceptionTest"); + invoke(); + } + + + public void setDateHeaderTest() throws Exception { + String testName = "setDateHeaderTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + + getServletName() + "?testname=" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(EXPECTED_HEADERS, + "DateInfo:Sat, 25 Apr 1970 07:29:03 GMT"); + invoke(); + } + + + public void setDateHeaderOverrideTest() throws Exception { + String testName = "setDateHeaderOverrideTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + + getServletName() + "?testname=" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(EXPECTED_HEADERS, + "DateInfo:Sat, 25 Apr 1970 07:29:04 GMT"); + invoke(); + } + + + public void setHeaderTest() throws Exception { + String testName = "setHeaderTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + + getServletName() + "?testname=" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(EXPECTED_HEADERS, "header:value1"); + invoke(); + } + + + public void setHeaderOverrideTest() throws Exception { + String testName = "setHeaderOverrideTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + + getServletName() + "?testname=" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(EXPECTED_HEADERS, "header:value2"); + invoke(); + } + + + public void setMultiHeaderTest() throws Exception { + String testName = "setMultiHeaderTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + + getServletName() + "?testname=" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(EXPECTED_HEADERS, "header:value3"); + invoke(); + } + + + public void setIntHeaderTest() throws Exception { + String testName = "setIntHeaderTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + + getServletName() + "?testname=" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(EXPECTED_HEADERS, "intHeader:2"); + invoke(); + } + + + public void setStatusTest() throws Exception { + String testName = "setStatusTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + + getServletName() + "?testname=" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + invoke(); + } + + + public void setStatusTest1() throws Exception { + String testName = "setStatusTest1"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + + getServletName() + "?testname=" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, NOT_FOUND); + invoke(); + } + + /* + * Servlet 3.0 tests + */ + + public void getHeadersTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getHeadersTest"); + invoke(); + } + + + public void getHeaderTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getHeaderTest"); + invoke(); + } + + + public void getHeaderNamesTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getHeaderNamesTest"); + invoke(); + } + + + public void getStatusTest() throws Exception { + String testName = "getStatusTest"; + TEST_PROPS.setProperty(APITEST, testName); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/response/HttpResponseTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/response/HttpResponseTestServlet.java new file mode 100644 index 0000000000..e74049ece3 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/response/HttpResponseTestServlet.java @@ -0,0 +1,88 @@ +/* + * 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 com.sun.ts.tests.servlet.common.response; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class HttpResponseTestServlet extends HttpServlet { + + private static final String TEST_HEADER = "testname"; + + private static final Class[] HTTP_TEST_ARGS = { HttpServletRequest.class, + HttpServletResponse.class }; + + private static final Class[] TEST_ARGS = { ServletRequest.class, + ServletResponse.class, }; + + private static final Class[][] ALL_TYPES = { TEST_ARGS, HTTP_TEST_ARGS }; + + public void init(ServletConfig servletConfig) throws ServletException { + super.init(servletConfig); + } + + public void service(HttpServletRequest servletRequest, + HttpServletResponse servletResponse) + throws ServletException, IOException { + String test = servletRequest.getParameter(TEST_HEADER).trim(); + Method method = null; + for (int i = 0; i < ALL_TYPES.length; i++) { + try { + method = ResponseTests.class.getDeclaredMethod(test, ALL_TYPES[i]); + break; + } catch (NoSuchMethodException nsme) { + ; // do nothing + } + } + + if (method != null) { + invokeTest(method, new Object[] { servletRequest, servletResponse }); + } else { + throw new ServletException("No such test: " + test); + } + + } + + private void invokeTest(Method toBeInvoked, Object[] paramValues) + throws ServletException { + try { + toBeInvoked.invoke(null, paramValues); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (Throwable t) { + throw new ServletException( + "Error executing test: " + toBeInvoked.getName(), t); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/response/ResponseClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/response/ResponseClient.java new file mode 100644 index 0000000000..04abbeb745 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/response/ResponseClient.java @@ -0,0 +1,291 @@ +/* + * Copyright (c) 2007, 2018 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$ + */ + +package com.sun.ts.tests.servlet.common.response; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.util.Data; + +public class ResponseClient extends AbstractUrlClient { + + + public void flushBufferTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "flushBufferTest"); + invoke(); + } + + + public void getBufferSizeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getBufferSizeTest"); + invoke(); + } + + + public void getLocaleDefaultTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getLocaleDefaultTest"); + invoke(); + } + + + public void getLocaleTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getLocaleTest"); + invoke(); + } + + + public void getOutputStreamTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getOutputStreamTest"); + invoke(); + } + + + public void getOutputStreamFlushTest() throws Exception { + String testName = "getOutputStreamFlushTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + + getServletName() + "?testname=" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, + "in getOutputStreamFlushTest|" + Data.PASSED); + invoke(); + } + + + public void getOutputStreamIllegalStateExceptionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getOutputStreamIllegalStateExceptionTest"); + invoke(); + } + + + public void getWriterTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getWriterTest"); + TEST_PROPS.setProperty(REQUEST_HEADERS, + "Content-Type: text/html;charset=ISO-8859-1"); + TEST_PROPS.setProperty(EXPECTED_HEADERS, "Content-Type: text/html"); + TEST_PROPS.setProperty(SEARCH_STRING, Data.PASSED); + invoke(); + } + + + public void getWriterFlushTest() throws Exception { + String testName = "getWriterFlushTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + + getServletName() + "?testname=" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "in test|" + Data.PASSED); + invoke(); + } + + + public void getWriterAfterTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getWriterAfterTest"); + TEST_PROPS.setProperty(REQUEST_HEADERS, + "Content-Type: text/html;charset=ISO-8859-1"); + TEST_PROPS.setProperty(EXPECTED_HEADERS, + "Content-Type: text/html;charset=ISO-8859-7"); + invoke(); + } + + + public void getWriterIllegalStateExceptionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getWriterIllegalStateExceptionTest"); + invoke(); + } + + + public void getWriterUnsupportedEncodingExceptionTest() throws Exception { + String testName = "getWriterUnsupportedEncodingExceptionTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + testName + " HTTP/1.1"); + invoke(); + testName = "checkTestResult"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, Data.PASSED); + invoke(); + } + + + public void isCommittedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "isCommittedTest"); + invoke(); + } + + + public void resetBufferTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "resetBufferTest"); + invoke(); + } + + + public void resetTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "resetTest"); + invoke(); + } + + + public void resetTest1() throws Exception { + TEST_PROPS.setProperty(APITEST, "resetTest1"); + TEST_PROPS.setProperty(UNEXPECTED_HEADERS, + "Content-Type: application/java-archive; charset=Shift_Jis"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "BigNoNo"); + TEST_PROPS.setProperty(SEARCH_STRING, "YesPlease"); + invoke(); + } + + + public void resetIllegalStateExceptionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "resetIllegalStateExceptionTest"); + invoke(); + } + + + public void getCharacterEncodingTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getCharacterEncodingTest"); + invoke(); + } + + + public void getCharacterEncodingDefaultTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getCharacterEncodingDefaultTest"); + invoke(); + } + + + public void setCharacterEncodingTest() throws Exception { + String testName = "setCharacterEncodingTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST_HEADERS, + "Content-Type: text/html;charset=ISO-8859-1"); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(EXPECTED_HEADERS, + "Content-Type: text/html;charset=ISO-8859-7"); + TEST_PROPS.setProperty(SEARCH_STRING, Data.PASSED); + invoke(); + } + + + public void setBufferSizeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setBufferSizeTest"); + invoke(); + } + + + public void setBufferSizeIllegalStateExceptionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setBufferSizeIllegalStateExceptionTest"); + invoke(); + } + + + public void setContentLengthTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setContentLengthTest"); + int lenn = Data.PASSED.length(); + TEST_PROPS.setProperty(EXPECTED_HEADERS, "Content-Length:" + lenn); + invoke(); + } + + + public void getContentTypeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getContentTypeTest"); + TEST_PROPS.setProperty(REQUEST_HEADERS, "Content-Type:text/html"); + TEST_PROPS.setProperty(EXPECTED_HEADERS, + "Content-Type:text/html;charset=ISO-8859-1"); + invoke(); + } + + + public void getContentType1Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "getContentType1Test"); + TEST_PROPS.setProperty(EXPECTED_HEADERS, "Content-Type:text/html"); + invoke(); + } + + + public void getContentTypeNullTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getContentTypeNullTest"); + invoke(); + } + + + public void getContentTypeNull1Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "getContentTypeNull1Test"); + invoke(); + } + + + public void getContentTypeNull2Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "getContentTypeNull2Test"); + invoke(); + } + + + public void setContentTypeTest() throws Exception { + String testName = "setContentTypeTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + + getServletName() + "?testname=" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(EXPECTED_HEADERS, "Content-Type:text/html"); + TEST_PROPS.setProperty(IGNORE_BODY, "true"); + invoke(); + } + + + public void setContentType1Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "setContentType1Test"); + invoke(); + } + + + public void setContentType2Test() throws Exception { + String testName = "setContentType2Test"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + + getServletName() + "?testname=" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(EXPECTED_HEADERS, "Content-Type:text/html"); + TEST_PROPS.setProperty(UNEXPECTED_HEADERS, "Content-Type:text/plain"); + TEST_PROPS.setProperty(IGNORE_BODY, "true"); + invoke(); + } + + + public void setLocaleTest() throws Exception { + String testName = "setLocaleTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + + getServletName() + "?testname=" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(EXPECTED_HEADERS, "Content-Language:en-US"); + TEST_PROPS.setProperty(IGNORE_BODY, "true"); + invoke(); + } + + + public void setLocale1Test() throws Exception { + String testName = "setLocale1Test"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + + getServletName() + "?testname=" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(EXPECTED_HEADERS, + "Content-Type:text/html;charset=Shift_Jis"); + TEST_PROPS.setProperty(IGNORE_BODY, "true"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/response/ResponseTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/response/ResponseTestServlet.java new file mode 100644 index 0000000000..72b355b2db --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/response/ResponseTestServlet.java @@ -0,0 +1,63 @@ +/* + * 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 com.sun.ts.tests.servlet.common.response; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class ResponseTestServlet extends GenericServlet { + + private static final String TEST_HEADER = "testname"; + + private static final Class[] TEST_ARGS = { ServletRequest.class, + ServletResponse.class }; + + public void init(ServletConfig servletConfig) throws ServletException { + super.init(servletConfig); + } + + public void service(ServletRequest servletRequest, + ServletResponse servletResponse) throws ServletException, IOException { + String test = servletRequest.getParameter(TEST_HEADER).trim(); + try { + Method method = ResponseTests.class.getMethod(test, TEST_ARGS); + method.invoke(null, new Object[] { servletRequest, servletResponse }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/response/ResponseTests.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/response/ResponseTests.java new file mode 100644 index 0000000000..51933080fb --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/response/ResponseTests.java @@ -0,0 +1,1369 @@ +/* + * Copyright (c) 2007, 2022 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 + */ + +/* + * $URL$ $LastChangedDate$ + */ + +package com.sun.ts.tests.servlet.common.response; + +import java.io.IOException; +import java.io.PrintWriter; +import java.io.UnsupportedEncodingException; +import java.util.Collection; +import java.util.Iterator; +import java.util.Locale; + +import com.sun.ts.tests.servlet.common.util.Data; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletOutputStream; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.ServletResponseWrapper; +import jakarta.servlet.http.Cookie; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletResponseWrapper; + +public class ResponseTests { + + // --------------------------- ServletResponse + // --------------------------------- + + public static void responseWrapperConstructorTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + ServletResponseWrapper srw = new ServletResponseWrapper(response); + if (srw != null) { + ServletTestUtil.printResult(pw, true); + } else { + ServletTestUtil.printResult(pw, false); + } + } + + public static void responseWrapperGetResponseTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + ServletResponseWrapper srw = new ServletResponseWrapper(response); + if (srw != null) { + ServletResponse sr = srw.getResponse(); + if (!response.equals(sr)) { + passed = false; + pw.println("getResponse failed to return the same response object"); + } else { + passed = true; + } + } else { + passed = false; + pw.println("constructor failed"); + } + ServletTestUtil.printResult(pw, passed); + } + + public static void responseWrapperSetResponseTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = true; + ServletResponseWrapper srw = new ServletResponseWrapper(response); + if (srw != null) { + try { + srw.setResponse(response); + } catch (Throwable t) { + passed = false; + pw.println("Error: setResponse generated a Throwable"); + t.printStackTrace(pw); + } + if (passed) { + ServletResponse sr = srw.getResponse(); + if (!response.equals(sr)) { + passed = false; + pw.println("getResponse failed to return the same response object"); + } + } + } else { + passed = false; + pw.println("constructor failed"); + } + ServletTestUtil.printResult(pw, passed); + } + + public static void responseWrapperSetResponseIllegalArgumentExceptionTest( + ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + ServletResponseWrapper srw = new ServletResponseWrapper(response); + if (srw != null) { + try { + srw.setResponse(null); + passed = false; + pw.println( + "Error: an IllegalArgumentException should have been generated"); + } catch (Throwable t) { + if (t instanceof IllegalArgumentException) { + passed = true; + } else { + passed = false; + pw.println( + "Exception thrown, but was not an instance of IllegalArgumentException ."); + pw.println("instead received: " + t.getClass().getName()); + } + } + } else { + passed = false; + pw.println("constructor failed"); + } + ServletTestUtil.printResult(pw, passed); + } + + public static void flushBufferTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + ServletOutputStream sos = null; + + try { + sos = response.getOutputStream(); + response.setBufferSize(13); + response.setContentType("text/html"); + ServletTestUtil.printResult(sos, true); + + // after flushing the client should get this + response.flushBuffer(); + + sos.close(); + } catch (Throwable t) { + throw new ServletException(t); + } + } + + public static void getBufferSizeTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + final String IN_TEST = "in test"; + int bSize = IN_TEST.length() * 2; + boolean passed = false; + PrintWriter pw = response.getWriter(); + + response.setBufferSize(bSize); + pw.println(IN_TEST); + response.flushBuffer(); + int result = response.getBufferSize(); + // needs to be greater than or equal to SetBufferSize value or zero . + if ((result >= bSize) || (result == 0)) { + passed = true; + } else { + passed = false; + pw.println("ServletRequest.getBufferSize() returned incorrect result"); + pw.println("Expected result -> >= " + bSize + " or 0"); + pw.println("Actual result -> " + result); + } + ServletTestUtil.printResult(pw, passed); + } + + public static void getOutputStreamFlushTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + boolean passed = false; + ServletOutputStream sos = response.getOutputStream(); + sos.println("in getOutputStreamFlushTest"); + sos.flush(); + if (response.isCommitted()) { + passed = true; + } else { + passed = false; + } + ServletTestUtil.printResult(sos, passed); + } + + public static void getOutputStreamTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + ServletOutputStream sos = response.getOutputStream(); + ServletTestUtil.printResult(sos, true); + } + + public static void getOutputStreamIllegalStateExceptionTest( + ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + PrintWriter pw = response.getWriter(); + try { + response.getOutputStream(); + passed = false; + pw.println("getOutputStream() did not throw IllegalStateException "); + } catch (Throwable t) { + if (t instanceof IllegalStateException) { + passed = true; + } else { + passed = false; + pw.println( + "Exception thrown, but was not an instance of IllegalStateException."); + pw.println("instead received: " + t.getClass().getName()); + } + } + ServletTestUtil.printResult(pw, passed); + } + + public static void setCharacterEncodingTest(ServletRequest request, + ServletResponse response) throws IOException { + boolean pass = true; + StringBuilder report = new StringBuilder(); + + // First need to know the default + String defaultEncoding = response.getCharacterEncoding(); + + report.append("Test 1: Direct UTF-8 then null:\n"); + response.setCharacterEncoding("UTF-8"); + if ("UTF-8".equalsIgnoreCase(response.getCharacterEncoding())) { + report.append(" Set with UTF-8 Pass\n"); + } else { + pass = false; + report.append(" Set with UTF-8 Fail\n"); + } + response.setCharacterEncoding((String)null); + if ((defaultEncoding == null && response.getCharacterEncoding() == null) || + defaultEncoding != null && defaultEncoding.equalsIgnoreCase(response.getCharacterEncoding())) { + report.append(" Set with null Pass\n"); + } else { + pass = false; + report.append(" Set with null Fail\n"); + } + response.reset(); + + report.append("Test 2: Content-Type UTF-8 then null:\n"); + response.setContentType("text/plain; charset=UTF-8"); + if ("UTF-8".equalsIgnoreCase(response.getCharacterEncoding())) { + report.append(" Set via Content-Type Pass\n"); + } else { + pass = false; + report.append(" Set via Content-Type Fail\n"); + } + response.setCharacterEncoding((String)null); + if ((defaultEncoding == null && response.getCharacterEncoding() == null) || + defaultEncoding != null && defaultEncoding.equalsIgnoreCase(response.getCharacterEncoding())) { + report.append(" Set with null Pass\n"); + } else { + pass = false; + report.append(" Set with null Fail\n"); + } + response.reset(); + + report.append("Test 3: Locale Shift_Jis then null:\n"); + response.setLocale(new Locale("ja")); + if ("Shift_Jis".equalsIgnoreCase(response.getCharacterEncoding())) { + report.append(" Set via Locale Pass\n"); + } else { + pass = false; + report.append(" Set via Locale Fail\n"); + } + response.setCharacterEncoding((String)null); + if ((defaultEncoding == null && response.getCharacterEncoding() == null) || + defaultEncoding != null && defaultEncoding.equalsIgnoreCase(response.getCharacterEncoding())) { + report.append(" Set with null Pass\n"); + } else { + pass = false; + report.append(" Set with null Fail\n"); + } + response.reset(); + + report.append("Test 4: Invalid then getWriter():\n"); + response.setCharacterEncoding("does-not-exist"); + if ("does-not-exist".equalsIgnoreCase(response.getCharacterEncoding())) { + report.append(" Set with invalid Pass\n"); + } else { + pass = false; + report.append(" Set with invalid Fail\n"); + } + try { + response.getWriter(); + pass = false; + report.append(" getWriter() did not throw UnsupportedEncodingException Fail\n"); + } catch (UnsupportedEncodingException uee) { + report.append(" getWriter() throw UnsupportedEncodingException Pass\n"); + } + response.reset(); + + report.append("Test 5: Check getContentType():\n"); + final String ENCODING = "ISO-8859-7"; + response.setContentType("text/html"); + response.setCharacterEncoding(ENCODING); + String type = response.getContentType(); + + if (type != null) { + if ((type.toLowerCase().indexOf("text/html") > -1) + && (type.toLowerCase().indexOf("charset") > -1) + && (type.toLowerCase().indexOf("iso-8859-7") > -1)) { + report.append(" getContentType returns correct type\n"); + } else { + pass = false; + report.append(" Expecting text/html; charset=ISO-8859-7"); + report.append(" getContentType returns incorrect type: " + type); + } + } else { + pass = false; + report.append(" getContentType return null"); + } + + PrintWriter pw = response.getWriter(); + pw.print(report.toString()); + ServletTestUtil.printResult(pw, pass); + } + + public static void getWriterTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean pass = false; + + PrintWriter pw = response.getWriter(); + response.setContentType("text/html;charset=ISO-8859-7"); + String type = response.getContentType(); + if (type != null) { + if ((type.toLowerCase().indexOf("text/html") > -1) + && (type.toLowerCase().indexOf("charset") > -1) + && (type.toLowerCase().indexOf("iso-8859-1") > -1)) { + pass = true; + } else { + pw.println("Expecting text/html; charset=ISO-8859-1"); + pw.println("getContentType returns incorrect type: " + type); + } + } else { + pw.println("getContentType return null"); + } + ServletTestUtil.printResult(pw, pass); + } + + public static void getWriterFlushTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = false; + PrintWriter pw = response.getWriter(); + response.setContentType("text/html;charset=ISO-8859-7"); + pw.println("in test"); + pw.flush(); + if (response.isCommitted()) { + passed = true; + } else { + passed = false; + } + ServletTestUtil.printResult(pw, passed); + } + + public static void getWriterAfterTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean pass = false; + response.setContentType("text/xml;charset=ISO-8859-7"); + PrintWriter pw = response.getWriter(); + response.setContentType("text/html;charset=UTF-8"); + + String type = response.getContentType(); + if (type != null) { + if ((type.toLowerCase().indexOf("text/html") > -1) + && (type.toLowerCase().indexOf("charset") > -1) + && (type.toLowerCase().indexOf("iso-8859-7") > -1)) { + pass = true; + } else { + pw.println("Expecting text/html; charset=ISO-8859-7"); + pw.println("getContentType returns incorrect type: " + type); + } + } else { + pw.println("getContentType return null"); + } + ServletTestUtil.printResult(pw, pass); + } + + public static void getWriterIllegalStateExceptionTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + boolean passed = false; + ServletOutputStream sos = response.getOutputStream(); + + try { + PrintWriter pw = response.getWriter(); + passed = false; + sos.println("getWriter() did not throw IllegalStateException "); + } catch (Throwable t) { + if (t instanceof IllegalStateException) { + passed = true; + } else { + passed = false; + sos.println( + "Exception thrown, but was not an instance of IllegalStateException."); + sos.println("instead received: " + t.getClass().getName()); + } + } + ServletTestUtil.printResult(sos, passed); + } + + public static void isCommittedTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + boolean passed = false; + ServletOutputStream sos = null; + + try { + boolean notYet = false; + sos = response.getOutputStream(); + // set buffer size + response.setBufferSize(50); + + // commit the response + if (response.isCommitted() == false) + notYet = true; + + response.flushBuffer(); + + if (notYet && (response.isCommitted() == true)) { + passed = true; + } else { + passed = false; + sos.println( + "IsCommitted did not detect that flushBuffer was called already"); + } + } catch (Throwable t) { + throw new ServletException(t); + } + ServletTestUtil.printResult(sos, true); + } + + public static void resetTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + ServletOutputStream sos = null; + + try { + sos = response.getOutputStream(); + + // set buffer size + response.setBufferSize(Data.FAILED.length() * 2); + + // Write some data to the stream + ServletTestUtil.printResult(sos, false); + + // Reset the response + response.reset(); + ServletTestUtil.printResult(sos, true); + } catch (Throwable t) { + throw new ServletException(t); + } + } + + public static void resetTest1(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + ServletOutputStream sos = null; + + String ct = "application/java-archive"; + String enc = "Shift_Jis"; + + response.setLocale(new Locale("ja")); + response.setCharacterEncoding(enc); + response.setContentType(ct); + + try { + sos = response.getOutputStream(); + + // Write some data to the stream + sos.println("BigNoNo"); + sos.println("Test FAILED"); + + // Reset the response + response.reset(); + + // Write something else to the stream + sos.println("YesPlease"); + sos.println("Test PASSED"); + + response.flushBuffer(); + } catch (Throwable t) { + throw new ServletException(t); + } + } + + public static void resetIllegalStateExceptionTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + boolean passed = false; + PrintWriter pw = response.getWriter(); + response.setBufferSize(11); + pw.println("in test"); + response.flushBuffer(); + + try { + response.reset(); + passed = false; + pw.println("reset() did not throw IllegalStateException "); + } catch (Throwable t) { + if (t instanceof IllegalStateException) { + passed = true; + } else { + passed = false; + pw.println( + "Exception thrown, but was not an instance of IllegalStateException."); + pw.println("instead received: " + t.getClass().getName()); + } + } + ServletTestUtil.printResult(pw, true); + } + + public static void getCharacterEncodingDefaultTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + final String ENCODING = "ISO-8859-1"; + boolean passed = false; + + PrintWriter pw = response.getWriter(); + + String result = response.getCharacterEncoding(); + + if (result != null) { + if (result.equalsIgnoreCase(ENCODING)) { + passed = true; + } else { + passed = false; + pw.println("getCharacterEncoding() returned an incorrect result "); + pw.println("Expected result = " + ENCODING); + pw.println("Actual result = |" + result + "|"); + } + } else { + passed = false; + pw.println("getCharacterEncoding() returned a null result "); + } + ServletTestUtil.printResult(pw, passed); + } + + public static void getCharacterEncodingTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + boolean passed = false; + final String ENCODING = "ISO-8859-7"; + response.setCharacterEncoding(ENCODING); + + PrintWriter pw = response.getWriter(); + + String result = response.getCharacterEncoding(); + if (result != null) { + if (result.equalsIgnoreCase(ENCODING)) { + passed = true; + } else { + passed = false; + pw.println("getCharacterEncoding() returned an incorrect result "); + pw.println("Expected result = " + ENCODING); + pw.println("Actual result = |" + result + "|"); + } + } else { + passed = false; + pw.println("getCharacterEncoding() returned a null result "); + } + ServletTestUtil.printResult(pw, passed); + } + + public static void setBufferSizeTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = false; + PrintWriter pw = response.getWriter(); + response.setBufferSize(1000); + int result = response.getBufferSize(); + // needs to be greater than or equal to SetBufferSize value or zero + if ((result >= 1000) || (result == 0)) { + passed = true; + } else { + passed = false; + pw.println("getBufferSize() returned incorrect result "); + pw.println("Expected result -> >= 1000 or 0"); + pw.println("Actual result = |" + result + "|"); + } + ServletTestUtil.printResult(pw, passed); + } + + public static void setBufferSizeIllegalStateExceptionTest( + ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + ServletOutputStream sos = null; + boolean passed = false; + + try { + sos = response.getOutputStream(); + sos.println("in test"); + sos.flush(); + + try { + // should IllegalStateException + response.setBufferSize(20); + passed = false; + sos.println( + "setBufferSize(20) should have thrown IllegalStateException "); + } catch (Throwable t) { + if (t instanceof IllegalStateException) { + passed = true; + } else { + passed = false; + sos.println( + "Exception thrown, but was not an instance of IllegalStateException."); + sos.println("instead received: " + t.getClass().getName()); + } + } + } catch (Throwable t) { + throw new ServletException(t); + } + ServletTestUtil.printResult(sos, passed); + } + + public static void setContentLengthTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + String expected = "text/html"; + response.setContentType(expected); + ServletOutputStream sos = response.getOutputStream(); + + response.setContentLength(Data.PASSED.length()); + sos.print(Data.PASSED); + + } + + public static void setContentTypeTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + response.setContentType("text/html"); + } + + public static void setContentType1Test(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = false; + String expected = "text/html"; + response.setContentType(expected); + + String actual = response.getContentType(); + PrintWriter pw = response.getWriter(); + if (actual != null) { + if (actual.toLowerCase().indexOf(expected) >= 0) { + passed = true; + } else { + pw.println( + "The value returned by getContentType() did not contain the expected result=" + + expected); + pw.println("actual=" + actual); + } + } else { + pw.println("Null value returned by getContentType() "); + } + ServletTestUtil.printResult(pw, passed); + } + + public static void setContentType2Test(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + String expected = "text/html"; + String unexpected = "text/plain"; + + response.setContentType(expected); + ServletOutputStream sos = response.getOutputStream(); + sos.println(response.getContentType() + "returned by getContentType()"); + sos.flush(); + + response.setContentType(unexpected); + sos.println(response.getContentType() + "returned by getContentType()"); + sos.flush(); + } + + public static void getContentTypeTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + boolean passed = false; + PrintWriter pw = response.getWriter(); + + String expected = "text/html"; + response.setContentType(expected); + + String actual = response.getContentType(); + if (actual == null) { + pw.println("null value returned by getContentType()"); + } else if (actual.toLowerCase().indexOf(expected) >= 0) { + passed = true; + } else { + passed = false; + pw.println( + "The value returned by getContentType() did not contain the expected result=" + + expected); + pw.println("actual=" + actual); + } + ServletTestUtil.printResult(pw, passed); + + } + + public static void getContentType1Test(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + boolean passed = false; + String expected = "text/html"; + response.setContentType(expected); + ServletOutputStream sos = response.getOutputStream(); + + String actual = response.getContentType(); + if (actual == null) { + sos.println("null value returned by getContentType()"); + } else if (actual.toLowerCase().indexOf(expected) >= 0) { + passed = true; + } else if (actual.toLowerCase().indexOf("char=") >= 0) { + sos.println( + "The value returned by getContentType() contains the unexpected encoding"); + sos.println("actual=" + actual + " expected=" + expected); + } else { + sos.println( + "The value returned by getContentType() did not contain the expected result=" + + expected); + sos.println("actual=" + actual); + } + ServletTestUtil.printResult(sos, passed); + + } + + public static void getContentTypeNullTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + String actual = response.getContentType(); + + if (actual != null) { + pw.println("Test FAILED."); + pw.println("getContentType() did not return a null"); + pw.println("actual=" + actual); + } else { + pw.println("Test PASSED"); + } + } + + public static void getContentTypeNull1Test(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + response.setCharacterEncoding("Shift_Jis"); + String actual = response.getContentType(); + PrintWriter pw = response.getWriter(); + + if (actual != null) { + pw.println("Test FAILED."); + pw.println("getContentType() did not return a null"); + pw.println("actual=" + actual); + } else { + pw.println("Test PASSED"); + } + } + + public static void getContentTypeNull2Test(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + String expected = "Shift_Jis"; + + response.setContentType("text/html;charset=Shift_Jis"); + response.setContentType("text/xml"); + String actual_encoding = response.getCharacterEncoding(); + String actual_type = response.getContentType(); + + PrintWriter pw = response.getWriter(); + + if (!actual_type.replace(" ", "") + .equalsIgnoreCase("text/xml;charset=Shift_Jis")) { + pw.println("getContentType() did not return text/xml; charset=Shift_Jis"); + pw.println("actual=" + actual_type); + } else if (actual_encoding.toLowerCase() + .indexOf(expected.toLowerCase()) < 0) { + pw.println("getCharacterEncoding() did not return correct encoding"); + pw.println("actual=" + actual_encoding); + pw.println("expected=" + expected); + } else { + pw.println("Test PASSED"); + } + } + + public static void setLocaleTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + Locale loc = new Locale("en", "US"); + response.setLocale(loc); + response.getWriter().println("Arbitrary text"); + } + + public static void setLocale1Test(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = false; + String expected1 = "text/html"; + String expected2 = "charset=Shift_Jis"; + Locale loc = new Locale("ja"); + response.setLocale(loc); + response.setContentType("text/html"); + + String actual = response.getContentType(); + PrintWriter pw = response.getWriter(); + + if (actual == null) { + pw.println("Null value returned by getContentType()"); + } else if ((actual.toLowerCase().indexOf(expected1) >= 0) + && (actual.toLowerCase().indexOf(expected2.toLowerCase()) >= 0)) { + passed = true; + } else { + pw.println( + "The value returned by getContentType() did not contain the expected result=" + + expected1 + ";" + expected2); + pw.println("actual=" + actual); + } + ServletTestUtil.printResult(pw, passed); + + } + + public static void getLocaleDefaultTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + Locale defaultLocale = Locale.getDefault(); + Locale containerLocale = response.getLocale(); + + PrintWriter pw = response.getWriter(); + if (defaultLocale.equals(containerLocale)) { + pw.println("Test PASSED"); + } else { + pw.println( + "Test FAILED. Expected ServletResponse.getLocale() to return the " + + "default locale of the VM if the locale was not explicily set."); + pw.println("VM default locale: " + defaultLocale); + pw.println( + "Locale returned by ServletResponse.getLocale(): " + containerLocale); + } + + } + + public static void getLocaleTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = false; + PrintWriter pw = response.getWriter(); + + Locale expectedResult = new Locale("en", "US"); + response.setLocale(expectedResult); + Locale result = response.getLocale(); + + if (result.equals(expectedResult)) { + passed = true; + } else { + passed = false; + pw.println("getLocale() did not receive the proper locale"); + pw.println("Expected result = " + expectedResult); + pw.println("Actual result = " + result); + } + ServletTestUtil.printResult(pw, passed); + } + + public static void resetBufferTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + ServletOutputStream sos = null; + try { + sos = response.getOutputStream(); + + // Write some data to the stream + response.setContentType("text/html"); + + ServletTestUtil.printResult(sos, false); + sos.println("resetBuffer() did not reset the buffer"); + // Reset the response + response.resetBuffer(); + ServletTestUtil.printResult(sos, true); + } catch (Throwable t) { + throw new ServletException(t); + } + } + + // --------------------------- END ServletResponse + // ----------------------------- + + // ---------------------------- HttpServletResponse + // ---------------------------- + + public static void httpResponseWrapperConstructorTest( + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + HttpServletResponseWrapper hsrw = new HttpServletResponseWrapper(response); + if (hsrw != null) { + ServletTestUtil.printResult(pw, true); + } else { + ServletTestUtil.printResult(pw, false); + } + } + + public static void httpResponseWrapperGetResponseTest( + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + HttpServletResponseWrapper srw = new HttpServletResponseWrapper(response); + if (srw != null) { + ServletResponse sr = srw.getResponse(); + if (!response.equals(sr)) { + passed = false; + pw.println("getResponse failed to return the same response object"); + } else { + passed = true; + } + } else { + passed = false; + pw.println("constructor failed"); + } + ServletTestUtil.printResult(pw, passed); + } + + public static void httpResponseWrapperSetResponseTest( + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = true; + HttpServletResponseWrapper srw = new HttpServletResponseWrapper(response); + if (srw != null) { + try { + srw.setResponse(response); + } catch (Throwable t) { + passed = false; + pw.println("Error: setResponse generated a Throwable"); + t.printStackTrace(pw); + } + if (passed) { + ServletResponse sr = srw.getResponse(); + if (!response.equals(sr)) { + passed = false; + pw.println("getResponse failed to return the same response object"); + } + } + } else { + passed = false; + pw.println("constructor failed"); + } + ServletTestUtil.printResult(pw, passed); + } + + public static void httpResponseWrapperSetResponseIllegalArgumentExceptionTest( + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + boolean passed = false; + HttpServletResponseWrapper srw = new HttpServletResponseWrapper(response); + if (srw != null) { + try { + srw.setResponse(null); + passed = false; + pw.println( + "Error: an IllegalArgumentException should have been generated"); + } catch (Throwable t) { + if (t instanceof IllegalArgumentException) { + passed = true; + } else { + passed = false; + pw.println( + "Exception thrown, but was not an instance of IllegalArgumentException ."); + pw.println("instead received: " + t.getClass().getName()); + } + } + } else { + passed = false; + pw.println("constructor failed"); + } + ServletTestUtil.printResult(pw, passed); + } + + public static void addCookieTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + // check for this in the client side + response.addCookie(new Cookie("cookie1", "value1")); + response.addCookie(new Cookie("cookie2", "value2")); + } + + public static void addDateHeaderTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + long date = 9876543210L; + response.addDateHeader("DateInfo", date); + } + + public static void addHeaderTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + response.addHeader("header1", "value1"); + response.addHeader("header1", "value11"); + response.addHeader("header2", "value2"); + } + + public static void addIntHeaderTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + response.addIntHeader("intHeader1", 1); + response.addIntHeader("intHeader1", 11); + response.addIntHeader("intHeader2", 2); + } + + public static void containsHeaderTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + boolean passed = true; + PrintWriter pw = response.getWriter(); + pw.println("positive case"); + String param = "header"; + response.setHeader(param, "value1"); // set a Header + boolean expectedResult = true; + boolean result = response.containsHeader(param); + + if (result != expectedResult) { + passed = false; + pw.println("HttpServletResponse.containsHeader(" + param + + ") returned incorrect results"); + pw.println("Expected result = " + expectedResult); + pw.println("Actual result = |" + result); + } + + pw.println("negative case"); + param = "doesnotexist"; + expectedResult = false; + result = response.containsHeader(param); + + if (result != expectedResult) { + passed = false; + pw.println("HttpServletResponse.containsHeader(" + param + + ") gave incorrect results"); + pw.println("Expected result = " + expectedResult); + pw.println("Actual result = |" + result); + } + ServletTestUtil.printResult(pw, passed); + + } + + public static void sendErrorClearBufferTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + pw.println("THIS TEXT SHOULD NOT APPEAR"); + response.sendError(HttpServletResponse.SC_GONE); + } + + public static void sendErrorIllegalStateExceptionTest( + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + PrintWriter pw = response.getWriter(); + pw.println("THIS TEXT SHOULD APPEAR"); + response.flushBuffer(); + try { + response.sendError(HttpServletResponse.SC_GONE); + passed = false; + pw.println("IllegalStateException exception should have been thrown"); + } catch (Throwable t) { + if (t instanceof IllegalStateException) { + passed = true; + } else { + passed = false; + pw.println( + "Exception thrown, but was not an instance of IllegalStateException."); + pw.println("instead received: " + t.getClass().getName()); + } + } + ServletTestUtil.printResult(pw, passed); + } + + public static void sendError_StringTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + pw.println("THIS TEXT SHOULD NOT APPEAR"); + response.addHeader("header", "sendError_StringTest"); + response.addCookie(new Cookie("cookie1", "value1")); + response.sendError(HttpServletResponse.SC_GONE, + "in sendError_StringTest servlet"); + } + + public static void sendError_StringIllegalStateExceptionTest( + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + PrintWriter pw = response.getWriter(); + pw.println("THIS TEXT SHOULD APPEAR"); + response.flushBuffer(); + try { + response.sendError(HttpServletResponse.SC_GONE, + "in sendError_StringIllegalStateExceptionTest servlet"); + ServletTestUtil.printResult(pw, false); + pw.println("IllegalStateException exception should have been thrown"); + } catch (Throwable t) { + if (t instanceof IllegalStateException) { + passed = true; + } else { + passed = false; + pw.println( + "Exception thrown, but was not an instance of IllegalStateException ."); + pw.println("instead received: " + t.getClass().getName()); + } + } + ServletTestUtil.printResult(pw, passed); + } + + public static void sendError_StringErrorPageTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + pw.println("THIS TEXT SHOULD NOT APPEAR"); + response.addHeader("header", "sendError_StringTest"); + response.addCookie(new Cookie("cookie1", "value1")); + response.sendError(HttpServletResponse.SC_LENGTH_REQUIRED, + "in sendError_StringErrorPageTest servlet"); + } + + public static void sendRedirectWithoutLeadingSlashTest( + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + response.sendRedirect("RedirectedTest"); + } + + public static void sendRedirectWithLeadingSlashTest( + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + response.sendRedirect("/RedirectedTest"); + } + + public static void sendRedirectIllegalStateExceptionTest( + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + PrintWriter pw = response.getWriter(); + response.setBufferSize(60); + response.setContentType("text/html"); + pw.println("in sendRedirect_1Test servlet"); + response.flushBuffer(); + + try { + response.sendRedirect("/RedirectedTest"); + passed = false; + pw.println("IllegalStateException exception should have been thrown"); + } catch (Throwable t) { + if (t instanceof IllegalStateException) { + passed = true; + } else { + passed = false; + pw.println( + "Exception thrown, but was not an instance of IllegalStateException ."); + pw.println("instead received: " + t.getClass().getName()); + } + } + ServletTestUtil.printResult(pw, passed); + } + + public static void setDateHeaderTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + long date = 9876543210L; + response.setDateHeader("DateInfo", date); + } + + public static void setDateHeaderOverrideTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + long date = 9876543210L; + response.setDateHeader("DateInfo", date); + date = 9876544210L; + response.setDateHeader("DateInfo", date); + } + + public static void setHeaderTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + response.setHeader("header", "value1"); + } + + public static void setHeaderOverrideTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + response.setHeader("header", "value1"); + response.setHeader("header", "value2"); + } + + public static void setMultiHeaderTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + response.setHeader("header", "value1"); + response.addHeader("header", "value2"); + response.setHeader("header", "value3"); + } + + public static void setIntHeaderTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + response.addIntHeader("intHeader", 1); + response.setIntHeader("intHeader", 2); + } + + public static void setStatusTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + response.setStatus(HttpServletResponse.SC_OK); + } + + public static void setStatusTest1(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + response.setStatus(HttpServletResponse.SC_NOT_FOUND); + } + + public static void getHeadersTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + Boolean passed = true; + String name = "TestheadersUnique"; + String[] values = { "first", "second", "third" }; + + response.setHeader(name, values[0]); + response.addHeader(name, values[1]); + response.addHeader(name, values[2]); + + Collection headers = response.getHeaders(name); + + for (int i = 0; i < 3; i++) { + if (headers.contains(values[i])) { + headers.remove(values[i]); + } else { + passed = false; + pw.println("Header value " + values[i] + " is set but not present."); + } + } + + if (!headers.isEmpty()) { + passed = false; + pw.println("Unexpected header value(s) is present:"); + Iterator left = headers.iterator(); + while (left.hasNext()) { + pw.println(left.next()); + } + } + + ServletTestUtil.printResult(pw, passed); + } + + public static void getHeaderTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + Boolean passed = false; + String name = "TestheadersUnique"; + String[] values = { "first", "second", "third" }; + + response.setHeader(name, values[0]); + response.addHeader(name, values[1]); + response.addHeader(name, values[2]); + + String header = response.getHeader(name); + + if (values[0].equals(header)) { + passed = true; + pw.println("Expected header value " + values[0] + " is set."); + } else { + pw.println("Test FAILED"); + pw.println("Expected header value " + values[0] + " is not set."); + pw.println("but unexpected header " + header + " present."); + } + ServletTestUtil.printResult(pw, passed); + } + + public static void getHeaderNamesTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + Boolean passed = true; + String[] names = { "TestheadersUnique", "TestheadersUniqueInt", + "TestheadersUniqueDate" }; + String[] values = { "first", "second", "third" }; + int[] values1 = { 1, 2, 3 }; + long[] values2 = { 11L, 22L, 33L }; + + response.setHeader(names[0], values[0]); + response.addHeader(names[0], values[1]); + response.addHeader(names[0], values[2]); + + response.setIntHeader(names[1], values1[0]); + response.addIntHeader(names[1], values1[1]); + response.addIntHeader(names[1], values1[2]); + + response.setDateHeader(names[2], values2[0]); + response.addDateHeader(names[2], values2[1]); + response.addDateHeader(names[2], values2[2]); + + Collection headers = response.getHeaderNames(); + + for (int i = 0; i < 3; i++) { + if (!headers.contains(names[i])) { + passed = false; + pw.println("Header name " + names[i] + " is set but not present."); + } + } + + ServletTestUtil.printResult(pw, passed); + } + + public static void getStatusTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + Boolean passed = true; + PrintWriter pw = response.getWriter(); + + int[] status_codes = { HttpServletResponse.SC_ACCEPTED, + HttpServletResponse.SC_BAD_GATEWAY, HttpServletResponse.SC_BAD_REQUEST, + HttpServletResponse.SC_CONFLICT, HttpServletResponse.SC_CONTINUE, + HttpServletResponse.SC_CREATED, + HttpServletResponse.SC_EXPECTATION_FAILED, + HttpServletResponse.SC_FORBIDDEN, HttpServletResponse.SC_FOUND, + HttpServletResponse.SC_GATEWAY_TIMEOUT, HttpServletResponse.SC_GONE, + HttpServletResponse.SC_HTTP_VERSION_NOT_SUPPORTED, + HttpServletResponse.SC_INTERNAL_SERVER_ERROR, + HttpServletResponse.SC_LENGTH_REQUIRED, + HttpServletResponse.SC_METHOD_NOT_ALLOWED, + HttpServletResponse.SC_MOVED_PERMANENTLY, + HttpServletResponse.SC_MOVED_TEMPORARILY, + HttpServletResponse.SC_MULTIPLE_CHOICES, + HttpServletResponse.SC_NO_CONTENT, + HttpServletResponse.SC_NON_AUTHORITATIVE_INFORMATION, + HttpServletResponse.SC_NOT_ACCEPTABLE, HttpServletResponse.SC_NOT_FOUND, + HttpServletResponse.SC_NOT_IMPLEMENTED, + HttpServletResponse.SC_NOT_MODIFIED, HttpServletResponse.SC_OK, + HttpServletResponse.SC_PARTIAL_CONTENT, + HttpServletResponse.SC_PAYMENT_REQUIRED, + HttpServletResponse.SC_PRECONDITION_FAILED, + HttpServletResponse.SC_PROXY_AUTHENTICATION_REQUIRED, + HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE, + HttpServletResponse.SC_REQUEST_TIMEOUT, + HttpServletResponse.SC_REQUEST_URI_TOO_LONG, + HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE, + HttpServletResponse.SC_RESET_CONTENT, HttpServletResponse.SC_SEE_OTHER, + HttpServletResponse.SC_SERVICE_UNAVAILABLE, + HttpServletResponse.SC_SWITCHING_PROTOCOLS, + HttpServletResponse.SC_TEMPORARY_REDIRECT, + HttpServletResponse.SC_UNAUTHORIZED, + HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, + HttpServletResponse.SC_USE_PROXY }; + + for (int i = 0; i < status_codes.length; i++) { + response.setStatus(status_codes[i]); + if (response.getStatus() != status_codes[i]) { + pw.println("Failed to set/getStatus " + status_codes[i]); + passed = false; + } + } + ServletTestUtil.printResult(pw, passed); + } + // -------------------------- END HttpServletResponse + // -------------------------- +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/response/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/response/build.xml new file mode 100644 index 0000000000..1990a4a2fa --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/response/build.xml @@ -0,0 +1,22 @@ + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/response/validation/WebValidatorBase.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/response/validation/WebValidatorBase.java new file mode 100644 index 0000000000..ef8941fe75 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/response/validation/WebValidatorBase.java @@ -0,0 +1,634 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.common.response.validation; + +import com.sun.ts.tests.servlet.common.client.handler.Handler; +import com.sun.ts.tests.servlet.common.client.handler.HandlerFactory; +import com.sun.ts.tests.servlet.common.request.HttpRequest; +import com.sun.ts.tests.servlet.common.request.HttpResponse; +import com.sun.ts.tests.servlet.common.request.ValidationStrategy; +import com.sun.ts.tests.servlet.common.request.WebTestCase; +import org.apache.commons.httpclient.Header; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +/** + * Base abstract class for WebTestCase validation. + */ +public class WebValidatorBase implements ValidationStrategy { + + private static final Logger logger = LoggerFactory.getLogger(WebValidatorBase.class); + + /** + * Used to detect 4xx class HTTP errors to allow fail fast situations when 4xx + * errors are not expected. + */ + protected static final char CLIENT_ERROR = '4'; + + /** + * Used to detect 5xx class HTTP errors to allows fail fast situations when + * 5xx errors are not expected. + */ + protected static final char SERVER_ERROR = '5'; + + /** + * This test case's HttpResponse + */ + protected HttpResponse _res = null; + + /** + * This test case's HttpRequest + */ + protected HttpRequest _req = null; + + /** + * The test case being validated + */ + protected WebTestCase _case = null; + + /** + * validate Will validate the response against the configured + * TestCase. + * + * + *
    + *
  • Check the HTTP status-code
  • + *
  • Check the HTTP reason-phrase
  • + *
  • Check for expected headers
  • + *
  • Check from unexpected headers
  • + *
  • Check expected search strings
  • + *
  • Check unexpected search strings
  • + *
  • Check the goldenfile
  • + *
+ */ + public boolean validate(WebTestCase testCase) throws Exception { + _res = testCase.getResponse(); + _req = testCase.getRequest(); + _case = testCase; + + // begin the check + try { + if (!checkStatusCode() || !checkReasonPhrase() || !checkExpectedHeaders() + || !checkUnexpectedHeaders() || !checkSearchStrings() + || !checkSearchStringsNoCase() || !checkUnorderedSearchStrings() + || !checkUnexpectedSearchStrings()) { + logger.error("Cannot validate response:" + testCase.getResponse()); + return false; + } + } catch (IOException ioe) { + logger.error(" Unexpected Exception: " + ioe.getMessage(), ioe); + return false; + } + return true; + } + + /** + * checkStatusCode will perform status code comparisons based on + * the algorithm below + *
    + *
  • Check the HTTP status code
  • + *
      + *
    • + *

      + * If status code is -1, then return true + *

      + *
    • + *
    • + *

      + * If test case status code null and response 4xx, return failure, print + * error; return false + *

      + *
    • + *
    • + *

      + * If test case status code null and response 5xx, return failure include + * response body; return false + *

      + *

    • + *
    • + *

      + * If test case status code null, and response not 4xx or 5xx, return true + *

      + *
    • + *
    • + *

      + * Test case status code not null, compare it with the response status code; + * return true if equal + *

      + *

    • + *
    + *
+ * + * @return boolen result of check + * @throws IOException + * if an IO error occurs during validation + */ + protected boolean checkStatusCode() throws IOException { + String sCode = _case.getStatusCode(); + String resCode = _res.getStatusCode(); + if ("-1".equals(sCode)) + return true; + + if (sCode == null && resCode.charAt(0) == CLIENT_ERROR) { + logger.error("Test {} Unexpected {} received from target server! Request path: {}" + , _case.getName(), resCode, _req.getRequestPath()); + return false; + } + + if (sCode == null && (resCode.charAt(0) == SERVER_ERROR)) { + String resBody = _res.getResponseBodyAsRawString(); + logger.error( " Test {} Unexpected '{}' received from target server!\n " + + "Error response received from server:\n" + + "------------------------------------------------\n" + + " {}" + , _case.getName(), resCode, (resBody != null ? resBody : "NO RESPONSE")); + return false; + } + + if (sCode == null) { + return true; + } + + /* + * Take sCode as a comma separated list of status codes. + * + * If prefixed by "!" the response status code must not match any in the list. + * + * Otherwise matching any in the list is accepted. + */ + + boolean exclusions = sCode.charAt(0) == '!'; + String[] sCodes = exclusions ? sCode.substring(1).split(",") : sCode.split(","); + + if (exclusions) { + for (String current : sCodes) { + if (current.equals(resCode)) { + logger.error(" Test {} Unexpected Status Code " + + "received from server. Expected any value except '{}', received '{}'", + _case.getName(), sCode, resCode); + return false; + } + } + } else { + boolean found = false; + for (String current : sCodes) { + if (current.equals(resCode)) { + logger.debug(" Test {} Expected Status Code '{}' found in response line!", + _case.getName(), current); + found = true; + break; + } + } + + if (!found) { + logger.error(" Test {} Status Code '{}' not found in response line!", + _case.getName(), sCode); + + return false; + } + } + + return true; + } + + /** + * checkSearchStrings will scan the response for the configured + * strings that are to be expected in the response. + *
    + *
  • Check search strings
  • + *
      + *
    • + *

      + * If list of Strings is null, return true. + *

      + *
    • + *
    • + *

      + * If list of Strings is not null, scan response body. If string is found, + * return true, otherwise display error and return false. + *

      + *
    • + *
    + *
+ * NOTE: If there are multiple search strings, the search will be + * performed as such to preserve the order. For example, if the list of search + * strings contains two entities, the search for the second entity will be + * started after the index if the first match. + * + * @return boolen result of check + * @throws IOException + * if an IO error occurs during validation + */ + protected boolean checkSearchStrings() throws Exception { + List list = _case.getSearchStrings(); + boolean found = true; + if (list != null && !list.isEmpty()) { + String responseBody = _res.getResponseBodyAsRawString(); + + for (int i = 0, n = list.size(), startIdx = 0, bodyLength = responseBody + .length(); i < n; i++) { + + // set the startIdx to the same value as the body length + // and let the test fail (prevents index based runtime + // exceptions). + if (startIdx >= bodyLength) { + startIdx = bodyLength; + } + + String search = list.get(i); + int searchIdx = responseBody.indexOf(search, startIdx); + + logger.debug( + " Test {} Scanning response for search string: '{}' starting at index location: {}", + _case.getName(), search, startIdx); + if (searchIdx < 0) { + found = false; + String sb = " Test %s Unable to find the following " + + "search string in the server's response: \n'%s'\n at index: %s" + + "\n Server's response:\n" + + "-------------------------------------------\n" + + "%s" + + "\n-------------------------------------------\n"; + String result = String.format(sb, _case.getName(), search, startIdx, responseBody); + logger.error(result); + throw new Exception(result); + } + + logger.debug(" Test {} Found search string: '{}' at index '{}' in the server's response", + _case.getName(), search, searchIdx); + // the new searchIdx is the old index plus the lenght of the + // search string. + startIdx = searchIdx + search.length(); + } + } + return found; + } + + /** + * checkSearchStringsNoCase will scan the response for the + * configured case insensitive strings that are to be expected in the + * response. + *
    + *
  • Check search strings
  • + *
      + *
    • + *

      + * If list of Strings is null, return true. + *

      + *
    • + *
    • + *

      + * If list of Strings is not null, scan response body. If string is found, + * return true, otherwise display error and return false. + *

      + *
    • + *
    + *
+ * NOTE: If there are multiple search strings, the search will be + * performed as such to preserve the order. For example, if the list of search + * strings contains two entities, the search for the second entity will be + * started after the index if the first match. + * + * @return boolen result of check + * @throws IOException + * if an IO error occurs during validation + */ + protected boolean checkSearchStringsNoCase() throws Exception { + List list = _case.getSearchStringsNoCase(); + boolean found = true; + if (list != null && !list.isEmpty()) { + String responseBody = _res.getResponseBodyAsRawString(); + + for (int i = 0, n = list.size(), startIdx = 0, bodyLength = responseBody + .length(); i < n; i++) { + + // set the startIdx to the same value as the body length + // and let the test fail (prevents index based runtime + // exceptions). + if (startIdx >= bodyLength) { + startIdx = bodyLength; + } + + String search = list.get(i); + int searchIdx = responseBody.toLowerCase().indexOf(search.toLowerCase(), + startIdx); + + logger.debug( + " Test {} Scanning response for search string: '{}' starting at index location: {}", + _case.getName(), search, startIdx); + if (searchIdx < 0) { + found = false; + String sb = " Test %s Unable to find the following search string in the server's " + + "response: \n'%s'\n at index: %s" + + "\n Server's response:\n" + + "-------------------------------------------\n" + + "%s" + + "\n-------------------------------------------\n"; + String result = String.format(sb, _case.getName(), search, searchIdx, responseBody); + logger.error(result); + throw new Exception(result); + } + + logger.debug(" Test {} Found search string: '{}' at index '{}' in the server's response", + _case.getName(), search, searchIdx); + // the new searchIdx is the old index plus the lenght of the + // search string. + startIdx = searchIdx + search.length(); + } + } + return found; + } + + /** + * checkUnorderedSearchStrings will scan the response for the + * configured strings that are to be expected in the response. + *
    + *
  • Check search strings
  • + *
      + *
    • + *

      + * If list of Strings is null, return true. + *

      + *
    • + *
    • + *

      + * If list of Strings is not null, scan response body. If string is found, + * return true, otherwise display error and return false. + *

      + *
    • + *
    + *
+ * + * @return boolen result of check + * @throws IOException + * if an IO error occurs during validation + */ + protected boolean checkUnorderedSearchStrings() throws Exception { + List list = _case.getUnorderedSearchStrings(); + boolean found = true; + if (list != null && !list.isEmpty()) { + String responseBody = _res.getResponseBodyAsRawString(); + + for (String search : list) { + int searchIdx = responseBody.indexOf(search); + logger.debug(" Test {} Scanning response for search string: '{}'...", + _case.getName(), search); + if (searchIdx < 0) { + found = false; + String sb = " Test %s Unable to find the following " + + "search string in the server's " + + "response: \n' %s" + + "\n Server's response:\n" + + "-------------------------------------------\n" + + "%s" + + "\n-------------------------------------------\n"; + String result = String.format(sb, _case.getName(), search, responseBody); + logger.error(result); + throw new Exception(result); + } + + logger.debug(" Test {} Found search string: '{}' at index '{}' in the server's response", + _case.getName(), search, searchIdx); + } + } + return found; + } + + /** + * checkUnexpectedSearchStrings will scan the response for the + * configured strings that are not expected in the response. + *
    + *
  • Check unexpected search strings
  • + *
      + *
    • + *

      + * If list of Strings is null, return true. + *

      + *
    • + *
    • + *

      + * If list of Strings is not null, scan response body. If string is not found, + * return true, otherwise display error and return false. + *

      + *

    • + *
    + *
+ * + * @return boolen result of check + * @throws IOException + * if an IO error occurs during validation + */ + protected boolean checkUnexpectedSearchStrings() throws IOException { + List list = _case.getUnexpectedSearchStrings(); + if (list != null && !list.isEmpty()) { + String responseBody = _res.getResponseBodyAsRawString(); + for (String search : list) { + logger.debug(" Test {} Scanning response. The following string should not be present in the response: '{}'", + _case.getName(), search); + if (responseBody.contains(search)) { + String sb = " Test {} Found the following unexpected " + + "search string in the server's " + + "response: '{}'" + + "\n Server's response:\n" + + "-------------------------------------------\n" + + "{}}" + + "\n-------------------------------------------\n"; + logger.error(sb, _case.getName(), search, responseBody); + return false; + } + } + } + return true; + } + + /** + * checkReasonPhrase will perform comparisons between the + * configued reason-phrase and that of the response. + *
    + *
  • Check reason-phrase
  • + *
      + *
    • + *

      + * If configured reason-phrase is null, return true. + *

      + *
    • + *
    • + *

      + * If configured reason-phrase is not null, compare the reason-phrases with + * the response. If equal, return true, otherwise display error and return + * false. + *

      + *

    • + *
    + *
+ * + * @return boolen result of check + */ + protected boolean checkReasonPhrase() { + String sReason = _case.getReasonPhrase(); + String resReason = _res.getReasonPhrase(); + + if (sReason == null) { + return true; + } + boolean check = sReason.equalsIgnoreCase(resReason); + if (check) { + logger.debug("Test {}, found expected reasonPhrase is '{}'",_case.getName(), resReason); + return true; + } + logger.error("Test {}, reasonPhrase is '{}' but not '{}'", _case.getName(), resReason, sReason); + return false; + } + + /** + * checkExpectedHeaders will check the response for the + * configured expected headers. + *
    + *
  • Check expected headers
  • + *
      + *
    • + *

      + * If there are no expected headers, return true. + *

      + *
    • + *
    • + *

      + * If there are expected headers, scan the response for the expected headers. + * If all expected headers are found, return true, otherwise display an error + * and return false. + *

      + *

    • + *
    + *
+ * + * @return boolen result of check + */ + protected boolean checkExpectedHeaders() throws Exception { + Header[] expected = _case.getExpectedHeaders(); + if (isEmpty(expected)) { + return true; + } + boolean found = true; + Header currentHeader = null; + for (Header header : expected) { + currentHeader = header; + Header resHeader = _res.getResponseHeader(currentHeader.getName()); + if (resHeader != null) { + Handler handler = HandlerFactory.getHandler(currentHeader.getName()); + if (!handler.invoke(currentHeader, resHeader)) { + found = false; + break; + } + } else { + found = false; + break; + } + } + if (!found) { + StringBuilder sb = new StringBuilder(255); + sb.append(" Test %s Unable to find the following header"); + sb.append(" in the server's response: "); + sb.append("%s").append("\n"); + sb.append(" Response headers received from"); + sb.append(" server:"); + + Header[] resHeaders = _res.getResponseHeaders(); + sb.append(Arrays.stream(resHeaders) + .map(header -> "ResponseHeader ->" + header.toExternalForm()) + .collect(Collectors.joining("\n\t"))); + + sb.append("\n"); + String result = String.format(sb.toString(), _case.getName(), currentHeader.toExternalForm()); + logger.error(result); + throw new Exception(result); + } + logger.debug(" Test {} Found expected header: {}", _case.getName(), currentHeader.toExternalForm()); + return true; + } + + /** + * checkUnexpectedHeaders will check the response for the + * configured unexpected expected headers. + *
    + *
  • Check unexpected headers
  • + *
      + *
    • + *

      + * If there are no configured unexpected headers, return true. + *

      + *
    • + *
    • + *

      + * If there are configured unexpected headers, scan the response for the + * unexpected headers. If the headers are not found, return true, otherwise + * display an error and return false. + *

      + *

    • + *
    + *
+ * + * @return boolen result of check + */ + protected boolean checkUnexpectedHeaders() { + Header[] unexpected = _case.getUnexpectedHeaders(); + if (isEmpty(unexpected)) { + return true; + } else { + for (Header currentHeader : unexpected) { + String currName = currentHeader.getName(); + String currValue = currentHeader.getValue(); + Header resHeader = _res.getResponseHeader(currName); + if (resHeader != null) { + if (resHeader.getValue().equals(currValue)) { + StringBuilder sb = new StringBuilder(255); + sb.append(" Test {} Unexpected header found in the "); + sb.append("server's response: "); + sb.append("{}").append("\n"); + sb.append(" Response headers recieved from"); + sb.append("server:"); + + Header[] resHeaders = _res.getResponseHeaders(); + sb.append(Arrays.stream(resHeaders) + .map(header -> "ResponseHeader ->" + header.toExternalForm()) + .collect(Collectors.joining("\n\t"))); + logger.error(sb.toString(), _case.getName(), currentHeader.toExternalForm()); + + return false; + } + } + } + } + return true; + } + + /** + * Utility method to determine of the expected or unexpected headers are empty + * or not. + */ + protected boolean isEmpty(Header[] headers) { + return headers == null || headers.length == 0; + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/servlets/CommonServlets.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/servlets/CommonServlets.java new file mode 100644 index 0000000000..a4a3e22afd --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/servlets/CommonServlets.java @@ -0,0 +1,54 @@ +package com.sun.ts.tests.servlet.common.servlets; + +import com.sun.ts.tests.servlet.api.common.sharedfiles.HSessionAttributeListener; +import com.sun.ts.tests.servlet.api.common.sharedfiles.HSessionListener; +import com.sun.ts.tests.servlet.common.response.HttpResponseTestServlet; +import com.sun.ts.tests.servlet.common.response.ResponseTestServlet; +import com.sun.ts.tests.servlet.common.response.ResponseTests; +import com.sun.ts.tests.servlet.common.util.Data; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; +import com.sun.ts.tests.servlet.common.util.StaticLog; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.resolver.api.maven.Maven; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +public class CommonServlets { + + private static final CommonServlets INSTANCE = new CommonServlets(); + + private final JavaArchive[] javaArchives; + + private CommonServlets() { + List archives = new ArrayList<>(); + + File[] files = Maven.configureResolver().workOffline().loadPomFromFile("pom.xml") + .resolve("org.slf4j:slf4j-simple") + .withTransitivity() + .asFile(); + List slf4jJars = + Arrays.stream(files).map(file -> ShrinkWrap.createFromZipFile(JavaArchive.class, file)) + .collect(Collectors.toList()); + + //archives.addAll(slf4jJars); + + archives.add(ShrinkWrap.create(JavaArchive.class, "common-servlets.jar") + .addClasses(GenericCheckTestResultServlet.class, GenericTCKServlet.class, RequestTestServlet.class, + HttpCheckTestResultServlet.class, HttpRequestTestServlet.class, RequestTests.class, + HttpTCKServlet.class, Data.class, StaticLog.class, ServletTestUtil.class, + ResponseTests.class, ResponseTestServlet.class, HttpResponseTestServlet.class, + HSessionListener.class, HSessionAttributeListener.class)); + + javaArchives = archives.toArray(new JavaArchive[0]); + } + + public static JavaArchive[] getCommonServletsArchive() { + return INSTANCE.javaArchives; + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/servlets/GenericCheckTestResultServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/servlets/GenericCheckTestResultServlet.java new file mode 100644 index 0000000000..710e6a3f3b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/servlets/GenericCheckTestResultServlet.java @@ -0,0 +1,87 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.common.servlets; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class GenericCheckTestResultServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + String result = (String) getServletContext().getAttribute("testresult"); + if (result != null) { + pw.println(result); + } else { + pw.println( + "CheckTestResultServlet could not access the testresult attribute from the context"); + ServletTestUtil.printResult(pw, false); + + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/servlets/GenericTCKServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/servlets/GenericTCKServlet.java new file mode 100644 index 0000000000..9a48ae6359 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/servlets/GenericTCKServlet.java @@ -0,0 +1,105 @@ +/* + * 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 com.sun.ts.tests.servlet.common.servlets; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +/** + * GenericTCKServlet.java + * + * Any test that would normally extend GenericServlet will instead extend this + * class. This will provide a simple framework from invoking various tests + * defined as methods within the servlet that extends this class. + * + * Created: Wed Jul 31 20:57:16 2002 + * + * @author Ryan Lubke + * @version %I% + */ + +public abstract class GenericTCKServlet extends GenericServlet { + + /** + * TEST_HEADER is the constant for the testname + * header. + */ + private static final String TEST_HEADER = "testname"; + + /** + * TEST_ARGS is an array of Classes used during reflection. + */ + private static final Class[] TEST_ARGS = { ServletRequest.class, + ServletResponse.class }; + + /** + * init initializes the servlet. + * + * @param config + * - ServletConfig + */ + public void init(ServletConfig config) throws ServletException { + super.init(config); + } + + public void service(ServletRequest req, ServletResponse res) + throws ServletException, IOException { + invokeTest(req, res); + } + + /** + * invokeTest uses reflection to invoke test methods in child + * classes of this particular class. + * + * @param req + * - ServletRequest + * @param res + * - ServletResponse + * @exception ServletException + * if an error occurs + */ + protected void invokeTest(ServletRequest req, ServletResponse res) + throws ServletException { + String test = req.getParameter(TEST_HEADER); + try { + Method method = this.getClass().getMethod(test, TEST_ARGS); + method.invoke(this, new Object[] { req, res }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + } + +}// GenericTCKServlet diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/servlets/HttpCheckTestResultServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/servlets/HttpCheckTestResultServlet.java new file mode 100644 index 0000000000..29fc6430c4 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/servlets/HttpCheckTestResultServlet.java @@ -0,0 +1,87 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.common.servlets; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class HttpCheckTestResultServlet extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + String result = (String) getServletContext().getAttribute("testresult"); + if (result != null) { + pw.println(result); + } else { + pw.println( + "CheckTestResultServlet could not access the testresult attribute from the context"); + ServletTestUtil.printResult(pw, false); + + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/servlets/HttpRequestTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/servlets/HttpRequestTestServlet.java new file mode 100644 index 0000000000..70c141785f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/servlets/HttpRequestTestServlet.java @@ -0,0 +1,92 @@ +/* + * 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 com.sun.ts.tests.servlet.common.servlets; + +import java.io.IOException; +import java.io.PrintWriter; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class HttpRequestTestServlet extends HttpServlet { + + private static final String TEST_HEADER = "testname"; + + private static final Class[] HTTP_TEST_ARGS = { PrintWriter.class, + HttpServletRequest.class, HttpServletResponse.class }; + + private static final Class[] TEST_ARGS = { PrintWriter.class, + ServletRequest.class, ServletResponse.class, }; + + private static final Class[][] ALL_TYPES = { TEST_ARGS, HTTP_TEST_ARGS }; + + public void init(ServletConfig servletConfig) throws ServletException { + super.init(servletConfig); + } + + public void service(HttpServletRequest servletRequest, + HttpServletResponse servletResponse) + throws ServletException, IOException { + String test = servletRequest.getParameter(TEST_HEADER).trim(); + servletRequest.setAttribute("servletContext", + getServletConfig().getServletContext()); + PrintWriter pw = servletResponse.getWriter(); + Method method = null; + for (int i = 0; i < ALL_TYPES.length; i++) { + try { + method = RequestTests.class.getDeclaredMethod(test, ALL_TYPES[i]); + break; + } catch (NoSuchMethodException nsme) { + ; // do nothing + } + } + + if (method != null) { + invokeTest(method, new Object[] { pw, servletRequest, servletResponse }); + } else { + throw new ServletException("No such test: " + test); + } + + } + + private void invokeTest(Method toBeInvoked, Object[] paramValues) + throws ServletException { + try { + toBeInvoked.invoke(null, paramValues); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (Throwable t) { + throw new ServletException( + "Error executing test: " + toBeInvoked.getName(), t); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/servlets/HttpTCKServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/servlets/HttpTCKServlet.java new file mode 100644 index 0000000000..1747703a6d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/servlets/HttpTCKServlet.java @@ -0,0 +1,137 @@ +/* + * 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 + */ + +package com.sun.ts.tests.servlet.common.servlets; + +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import jakarta.servlet.ServletConfig; +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; + +/** + * GenericTCKServlet.java + * + * Any test that would normally extend GenericServlet will instead extend this + * class. This will provide a simple framework from invoking various tests + * defined as methods within the servlet that extends this class. + * + * Created: Wed Jul 31 20:57:16 2002 + * + * @version %I% + */ + +public abstract class HttpTCKServlet extends HttpServlet { + + private static final String TEXT_PLAIN = "text/plain"; + + protected Logger logger = LoggerFactory.getLogger(getClass()); + + /** + * TEST_HEADER is the constant for the testname + * header. + */ + private static final String TEST_HEADER = "testname"; + + /** + * TEST_ARGS is an array of Classes used during reflection. + */ + private static final Class[] TEST_ARGS = { HttpServletRequest.class, + HttpServletResponse.class }; + + /** + * init initializes the servlet. + * + * @param config + * - ServletConfig + */ + public void init(ServletConfig config) throws ServletException { + super.init(config); + } + + /** + * invokeTest uses reflection to invoke test methods in child + * classes of this particular class. + * + * @param req + * - HttpServletRequest + * @param res + * - HttpServletResponse + * @exception ServletException + * if an error occurs + */ + protected void invokeTest(HttpServletRequest req, HttpServletResponse res) + throws ServletException { + res.setContentType(TEXT_PLAIN); + char[] temp = req.getParameter(TEST_HEADER).toCharArray(); + temp[0] = Character.toLowerCase(temp[0]); + String test = new String(temp); + + try { + Method method = this.getClass().getMethod(test, TEST_ARGS); + method.invoke(this, new Object[] { req, res }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + } + + /** + * A basic implementation of the doGet method which will call + * invokeTest. + * + * @param req + * - HttpServletRequest + * @param res + * - HttpServletResponse + * @exception ServletException + * if an error occurs + * @exception IOException + * if an IO error occurs + */ + public void doGet(HttpServletRequest req, HttpServletResponse res) + throws ServletException, IOException { + invokeTest(req, res); + } + + /** + * A basic implementation of the doPost method which will call + * invokeTest. + * + * @param req + * - HttpServletRequest + * @param res + * - HttpServletResponse + * @exception ServletException + * if an error occurs + * @exception IOException + * if an IO error occurs + */ + public void doPost(HttpServletRequest req, HttpServletResponse res) + throws ServletException, IOException { + invokeTest(req, res); + } + +}// HttpTCKServlet diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/servlets/RequestTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/servlets/RequestTestServlet.java new file mode 100644 index 0000000000..50f871c76f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/servlets/RequestTestServlet.java @@ -0,0 +1,65 @@ +/* + * 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 com.sun.ts.tests.servlet.common.servlets; + +import java.io.IOException; +import java.io.PrintWriter; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class RequestTestServlet extends GenericServlet { + + private static final String TEST_HEADER = "testname"; + + private static final Class[] TEST_ARGS = { PrintWriter.class, + ServletRequest.class, ServletResponse.class }; + + public void init(ServletConfig servletConfig) throws ServletException { + super.init(servletConfig); + } + + public void service(ServletRequest servletRequest, + ServletResponse servletResponse) throws ServletException, IOException { + String test = servletRequest.getParameter(TEST_HEADER).trim(); + try { + PrintWriter pw = servletResponse.getWriter(); + Method method = RequestTests.class.getMethod(test, TEST_ARGS); + method.invoke(null, new Object[] { pw, servletRequest, servletResponse }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/servlets/RequestTests.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/servlets/RequestTests.java new file mode 100644 index 0000000000..b2a7762d1c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/servlets/RequestTests.java @@ -0,0 +1,2685 @@ +/* + * 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$ + */ +package com.sun.ts.tests.servlet.common.servlets; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.UnsupportedEncodingException; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.Arrays; +import java.util.Enumeration; +import java.util.Locale; +import java.util.Map; +import java.util.Vector; + +import com.sun.ts.tests.servlet.common.util.Data; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletInputStream; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletRequestWrapper; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.http.Cookie; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletRequestWrapper; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpSession; + +public class RequestTests { + + static String savedSessionId = null; + + static String savedRequestedSessionId = null; + + static HttpSession savedSession = null; + + // ------------------------ jakarta_servlet.RequestRequest + // ------------------------------- + public static void requestWrapperConstructorTest(PrintWriter pw, + ServletRequest request, ServletResponse response) + throws ServletException, IOException { + ServletRequestWrapper srw = new ServletRequestWrapper(request); + if (srw != null) { + ServletTestUtil.printResult(pw, true); + } else { + ServletTestUtil.printResult(pw, false); + } + } + + public static void requestWrapperGetRequestTest(PrintWriter pw, + ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + ServletRequestWrapper srw = new ServletRequestWrapper(request); + if (srw != null) { + ServletRequest sr = srw.getRequest(); + if (!request.equals(sr)) { + passed = false; + pw.println("getRequest failed to return the same request object"); + } else { + passed = true; + } + } else { + passed = false; + pw.println("constructor returned a null"); + } + ServletTestUtil.printResult(pw, passed); + } + + public static void requestWrapperSetRequestTest(PrintWriter pw, + ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + boolean passed = true; + ServletRequestWrapper srw = new ServletRequestWrapper(request); + if (srw != null) { + try { + srw.setRequest(request); + } catch (Throwable t) { + passed = false; + pw.println("Error: setRequest generated a Throwable"); + pw.println("Exception:" + t.getMessage()); + } + if (passed) { + ServletRequest sr = srw.getRequest(); + if (!request.equals(sr)) { + passed = false; + pw.println("getRequest failed to return the same request object"); + } + } + } else { + passed = false; + pw.println("constructor returned a null"); + } + ServletTestUtil.printResult(pw, passed); + } + + public static void requestWrapperSetRequestIllegalArgumentExceptionTest( + PrintWriter pw, ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + ServletRequestWrapper srw = new ServletRequestWrapper(request); + if (srw != null) { + try { + srw.setRequest(null); + passed = false; + pw.println( + "Error: an IllegalArgumentException should have been generated"); + } catch (Throwable t) { + if (t instanceof IllegalArgumentException) { + passed = true; + } else { + passed = false; + pw.println( + "Exception thrown, but was not an instance of IllegalArgumentException."); + pw.println("instead received: " + t.getClass().getName()); + } + } + } else { + passed = false; + pw.println("constructor returned a null"); + } + ServletTestUtil.printResult(pw, passed); + } + + public static void getAttributeNamesTest(PrintWriter pw, + ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + ; + + Enumeration e = request.getAttributeNames(); + Object[] attr = ServletTestUtil.getAsArray(e); + for (int i = 0, len = attr.length; i < len; i++) { + request.removeAttribute((String) attr[i]); + } + + String attribute1 = "attribute1"; + String attribute2 = "attribute2"; + + request.setAttribute(attribute1, "value1"); + request.setAttribute(attribute2, "value2"); + String[] expected = { attribute1, attribute2 }; + + e = request.getAttributeNames(); + + if (!ServletTestUtil.checkEnumeration(e, expected)) { + passed = false; + ServletTestUtil.printFailureData(pw, e, expected); + } else { + passed = true; + } + + ServletTestUtil.printResult(pw, passed); + } + + public static void getAttributeNamesEmptyEnumTest(PrintWriter pw, + ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + + Enumeration e = request.getAttributeNames(); + Object[] attr = ServletTestUtil.getAsArray(e); + for (int i = 0, len = attr.length; i < len; i++) { + request.removeAttribute((String) attr[i]); + } + e = request.getAttributeNames(); + if (!e.hasMoreElements()) { + passed = true; + } else { + passed = false; + pw.println( + "getAttributeNames() returned a non empty enumeration after all attributes were removed"); + pw.println("The values returned were:"); + while (e.hasMoreElements()) { + pw.println(" " + (String) e.nextElement()); + } + } + ServletTestUtil.printResult(pw, passed); + } + + public static void getAttributeTest(PrintWriter pw, ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + boolean passed = false; + + request.setAttribute("attribute1", "value1"); + + Object o = request.getAttribute("attribute1"); + + if (o != null) { + if (o instanceof String) { + String attr = (String) o; + if (!attr.equals("value1")) { + passed = false; + pw.println("getAttribute() returned incorrect value"); + pw.println("Expected Attribute Value -> value1"); + pw.println("Actual Attribute value returned -> + attr "); + } else { + passed = true; + } + } else { + passed = false; + pw.println("getAttribute() returned an Object of type String"); + } + } else { + passed = false; + pw.println("getAttribute() returned a null attribute"); + } + + ServletTestUtil.printResult(pw, passed); + } + + public static void getAttributeDoesNotExistTest(PrintWriter pw, + ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + + Object o = request.getAttribute("doesnotexist"); + + // No attribute was set. Expecting null value + if (o != null) { + passed = false; + pw.println("getAttribute() returned incorrect value"); + pw.println("Expected Attribute Value -> null"); + pw.println("Actual Attribute value returned -> + o "); + } else { + passed = true; + } + + ServletTestUtil.printResult(pw, passed); + } + + public static void getCharacterEncodingTest(PrintWriter pw, + ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + + // getting char encoding + String expectedResult = "ISO-8859-1"; + String encoding = request.getCharacterEncoding(); + + if (encoding != null) { + if (!encoding.equals(expectedResult)) { + passed = false; + pw.println( + "getCharacterEncoding() did not receive the proper encoding"); + pw.println("Expected result = " + expectedResult); + pw.println("Actual result = |" + encoding + "|"); + + } else { + passed = true; + } + + } else { + passed = false; + pw.println("getCharacterEncoding() returned a null result"); + } + + ServletTestUtil.printResult(pw, passed); + } + + public static void getContentLengthTest(PrintWriter pw, + ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + + // get the content length + int contentLength = request.getContentLength(); + + if (contentLength > 0) { + int len = 0; + + // getting input stream + ServletInputStream sin = request.getInputStream(); + // read from the stream + while (sin.read() != -1) { + len++; + } + + // did we get what we wrote + if ((contentLength != len) && (contentLength != -1)) { + passed = false; + pw.println("getContentLength() method FAILED"); + pw.println("Expected Value returned ->" + contentLength); + pw.println("Actual Value returned -> " + len); + } else { + passed = true; + } + } else { + passed = false; + pw.println("getContentLength() returned an incorrect length"); + pw.println("Expected length = > 0"); + pw.println("Actual length = " + contentLength); + } + + ServletTestUtil.printResult(pw, passed); + } + + public static void getContentTypeTest(PrintWriter pw, ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + boolean passed = false; + String expectedResult = "text/plain"; + String contentType = request.getContentType(); + + if (contentType != null) { + if (!expectedResult.equals(contentType)) { + passed = false; + pw.println("getContentType() did not receive the proper content type"); + pw.println("Expected result=" + expectedResult); + pw.println("Actual result=" + contentType); + } else { + passed = true; + } + } else { + passed = false; + pw.println("getContentType() returned a null"); + } + + ServletTestUtil.printResult(pw, passed); + } + + public static void getContentTypeNullTest(PrintWriter pw, + ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + String contentType = request.getContentType(); + + if (contentType != null) { + passed = false; + pw.println("getContentType() did not a return a null"); + pw.println("Actual result=" + contentType); + } else { + passed = true; + } + + ServletTestUtil.printResult(pw, passed); + } + + public static void getInputStreamTest(PrintWriter pw, ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + boolean passed = false; + String expected = "calling getInputStreamTest"; + + StringBuffer sb = new StringBuffer(); + + ServletInputStream sin = request.getInputStream(); + + int tmp = 0; + try { + tmp = sin.read(); + while (tmp != -1) { + sb.append((char) tmp); + tmp = sin.read(); + } + String actual = sb.toString(); + if (actual != null) { + if (!actual.equals(expected)) { + passed = false; + pw.println("getInputStream returned the wrong body content"); + pw.println("expected =" + expected); + pw.println("actual =" + actual); + } else { + passed = true; + } + } else { + passed = false; + pw.println("getInputStream returned null body content"); + } + } catch (Throwable t) { + passed = false; + pw.println("read() generated an exception"); + t.printStackTrace(pw); + } + + ServletTestUtil.printResult(pw, passed); + } + + public static void getInputStreamIllegalStateExceptionTest(PrintWriter pw, + ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + + // getting Reader object + request.getReader(); + + try { + // we already got reader object + // IllegalStateException should be thrown + ServletInputStream sin = request.getInputStream(); + passed = false; + pw.println( + "getInputStream should have thrown an IllegalStateException exception"); + } catch (Throwable t) { + if (t instanceof IllegalStateException) { + passed = true; + } else { + passed = false; + pw.println( + "Exception thrown, but was not an instance of IllegalStateException ."); + pw.println("instead received: " + t.getClass().getName()); + } + } + ServletTestUtil.printResult(pw, passed); + } + + public static void getLocaleTest(PrintWriter pw, ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = false; + Locale expectedResult = new Locale("en", "US"); + Locale actual = request.getLocale(); + + if (actual != null) { + if (!actual.equals(expectedResult)) { + passed = false; + pw.println("getLocale() did not receive the proper locale"); + pw.println("Expected result = " + expectedResult.getLanguage() + "-" + + expectedResult.getCountry()); + pw.println("Actual result = |" + actual.getLanguage() + "-" + + actual.getCountry() + "|"); + } else { + passed = true; + } + } else { + passed = false; + pw.println("getLocale() returned a null result"); + } + + ServletTestUtil.printResult(pw, passed); + } + + public static void getLocaleDefaultTest(PrintWriter pw, + ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + + Locale actual = request.getLocale(); + + if (actual != null) { + if ((actual.getLanguage() == null) || (actual.getCountry() == null)) { + if (actual.getLanguage() == null) { + passed = false; + pw.println("Locale.getLanguage() returned a null"); + } + if (actual.getCountry() == null) { + passed = false; + pw.println("Locale.getCountry() returned a null"); + } + } else { + passed = true; + } + } else { + passed = false; + pw.println("getLocale() returned a null result"); + } + + ServletTestUtil.printResult(pw, passed); + } + + public static void getLocalesDefaultTest(PrintWriter pw, + ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + + Enumeration e = request.getLocales(); + + Object[] result = ServletTestUtil.getAsArray(e); + if (result.length == 1) { + Locale locale = ((Locale) result[0]); + if (locale != null) { + if ((locale.getLanguage() == null) || (locale.getCountry() == null)) { + if (locale.getLanguage() == null) { + passed = false; + pw.println("Locale.getLanguage() returned a null"); + } + if (locale.getCountry() == null) { + passed = false; + pw.println("Locale.getCountry() returned a null"); + } + } else { + passed = true; + } + } else { + passed = false; + pw.println("getLocales() returned a null result"); + } + } else if (result.length <= 0) { + passed = false; + pw.println("getLocales() did not return any locales"); + } else { + passed = false; + pw.println("getLocales() returned more than 1 locale"); + pw.println("The locales received were :"); + + for (int i = 0; i < result.length; i++) { + pw.println(" " + ((Locale) result[i]).getLanguage() + "-" + + ((Locale) result[i]).getCountry()); + } + } + + ServletTestUtil.printResult(pw, passed); + } + + public static void getLocalesTest(PrintWriter pw, ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + boolean passed = true; + + Enumeration e = request.getLocales(); + Locale expectedResult1 = new Locale("en", "US"); + boolean expectedResult1Found = false; + int expectedResult1order = 1; + Locale expectedResult2 = new Locale("en", "GB"); + boolean expectedResult2Found = false; + int expectedResult2order = 2; + int expectedCount = 2; + int count = 0; + + if (e.hasMoreElements()) { + Vector v = new Vector(); + + while (e.hasMoreElements()) { + Locale result = ((Locale) e.nextElement()); + + if (result.equals(expectedResult1)) { + if (!expectedResult1Found) { + count++; + expectedResult1Found = true; + if (count != expectedResult1order) { + passed = false; + pw.println( + "getLocales() did not return the locale in the correct order"); + pw.println("expected order=" + expectedResult1order); + pw.println("actual order=" + count); + } + } else { + passed = false; + pw.println("getLocales() method return the same locale name twice"); + pw.println("The locale already received was " + + expectedResult1.getLanguage() + "-" + + expectedResult1.getCountry()); + } + } else if (result.equals(expectedResult2)) { + if (!expectedResult2Found) { + count++; + expectedResult2Found = true; + if (count != expectedResult2order) { + passed = false; + pw.println( + "getLocales() did not return the locale in the correct order"); + pw.println("expected order=" + expectedResult2order); + pw.println("actual order=" + count); + } + } else { + passed = false; + pw.println("getLocales() method return the same locale name twice"); + pw.println("The locale already received was " + + expectedResult2.getLanguage() + "-" + + expectedResult2.getCountry()); + } + } else { + v.add(result); + } + + } + + if (count != expectedCount) { + passed = false; + pw.println("getLocales() did not return the proper number of locales"); + pw.println("Expected count = " + expectedCount); + pw.println("Actual count = |" + count + "|"); + pw.println("The expected locales received were :"); + + if (expectedResult1Found) { + pw.println(" " + expectedResult1.getLanguage() + "-" + + expectedResult1.getCountry()); + } + + if (expectedResult2Found) { + pw.println(" " + expectedResult2.getLanguage() + "-" + + expectedResult2.getCountry()); + } + + pw.println("Other locales received were :"); + + for (int i = 0; i < v.size(); i++) { + pw.println(" " + ((Locale) v.elementAt(i)).getLanguage() + "-" + + ((Locale) v.elementAt(i)).getCountry()); + } + } + } else { + passed = false; + pw.println("getLocales() returned an empty enumeration"); + } + + ServletTestUtil.printResult(pw, passed); + } + + public static void getParameterMapTest(PrintWriter pw, ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + boolean passed = true; + + Map map = request.getParameterMap(); + + int count = 0; + int expectedCount = 2; + String expectedResult1 = "parameter1"; + String expectedResult1A = "value1"; + int expectedCount1 = 1; + String expectedResult2 = "parameter2"; + String expectedResult2A = "value2"; + int expectedCount2 = 1; + + if (map.containsKey(expectedResult1)) { + String result[] = (String[]) map.get(expectedResult1); + int count2 = result.length; + + if (count2 == expectedCount1) { + if (result[0].equals(expectedResult1A)) { + count++; + } else { + passed = false; + pw.println( + "getParameterMap() did not return the proper value for the specified key"); + pw.println("Expected result = " + expectedResult1A); + pw.println("Actual result = " + result[0]); + } + } else { + passed = false; + pw.println( + "Map.get() returned the wrong number of parameter values for key " + + expectedResult1); + pw.println("Expected number = " + expectedCount1); + pw.println("Actual number = " + count2); + } + } + + if (map.containsKey(expectedResult2)) { + String result[] = (String[]) map.get(expectedResult2); + int count2 = result.length; + + if (count2 == expectedCount1) { + if (result[0].equals(expectedResult2A)) { + count++; + } else { + passed = false; + pw.println( + "getParameterMap() did not return the proper value for the specified key"); + pw.println("Expected result = " + expectedResult2A); + pw.println("Actual result = " + result[0]); + } + } else { + passed = false; + pw.println( + "Map.get() returned the wrong number of parameter values for key " + + expectedResult2); + pw.println("Expected number = " + expectedCount2); + pw.println("Actual number = " + count2); + } + + } + + if (count != expectedCount) { + passed = false; + pw.println("getParameterMap() return the proper keys and values "); + pw.println("Expected count = " + expectedCount); + pw.println("Actual count = |" + count + "|"); + } + + ServletTestUtil.printResult(pw, passed); + } + + public static void getParameterNamesTest(PrintWriter pw, + ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + + String parameter1 = "parameter1"; + String parameter2 = "parameter2"; + + String[] expected = { parameter1, parameter2 }; + + Enumeration e = request.getParameterNames(); + + if (!ServletTestUtil.checkEnumeration(e, expected, false, false)) { + passed = false; + ServletTestUtil.printFailureData(pw, e, expected); + } else { + passed = true; + } + + ServletTestUtil.printResult(pw, passed); + } + + public static void getParameterNamesEmptyEnumTest(PrintWriter pw, + ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + + // no parameter was set in the client side + Enumeration e = request.getParameterNames(); + + if (e.hasMoreElements()) { + passed = false; + pw.println( + "getParameterNames() return an enumerated list when it should have been empty"); + pw.println("The list contains the following items:"); + ServletTestUtil.getAsString(e); + } else { + passed = true; + } + + ServletTestUtil.printResult(pw, passed); + } + + public static void getParameterTest(PrintWriter pw, ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + boolean passed = false; + + // getting the request parameter + String param = "parameter1"; + String actual = request.getParameter(param); + String expectedResult = "value1"; + + if (actual != null) { + // is param an instance of java.lang.String + if (!actual.equals(expectedResult)) { + passed = false; + pw.println("getParameter() did not return the correct value"); + pw.println("Expected result = " + expectedResult); + pw.println("Actual result = |" + actual + "|"); + } else { + passed = true; + } + } else { + passed = false; + pw.println("getParameter() did not return the correct value"); + pw.println("Expected result = " + expectedResult); + pw.println("Actual result = |null|"); + } + + ServletTestUtil.printResult(pw, passed); + } + + public static void getParameterValuesTest(PrintWriter pw, + ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + boolean passed = true; + + String[] names = request.getParameterValues("Names"); + int enumlength = names.length; + String expectedResult1 = "value1"; + String expectedResult2 = "value2"; + boolean expectedResult1Found = false; + boolean expectedResult2Found = false; + int expectedCount = 2; + int count = 0; + int arraycount = 0; + + if (enumlength > 0) { + Vector v = new Vector(); + + while (arraycount < enumlength) { + String result = names[arraycount++]; + + if (result.equals(expectedResult1)) { + if (!expectedResult1Found) { + count++; + expectedResult1Found = true; + } else { + passed = false; + pw.println("getParameterValues() return the same value twice "); + pw.println("The value already received was " + expectedResult1); + } + } + + if (result.equals(expectedResult2)) { + if (!expectedResult2Found) { + count++; + expectedResult2Found = true; + } else { + passed = false; + pw.println("getParameterValues() return the same value twice "); + pw.println("The value already received was " + expectedResult2); + } + } else { + v.add(result); + } + + } + + if (count != expectedCount) { + passed = false; + pw.println( + "getParameterValues() did not return the proper number of parameter values"); + pw.println("Expected count = " + expectedCount); + pw.println("Actual count = |" + count + "|"); + pw.println("The expected parameter values received were :"); + + if (expectedResult1Found) { + pw.println(expectedResult1); + } + + if (expectedResult2Found) { + pw.println(expectedResult2); + } + + pw.println("Other parameter values received were :"); + + for (int i = 0; i < v.size(); i++) { + pw.println(" " + v.elementAt(i).toString()); + } + } + + } else { + passed = false; + pw.println("getParameterValues() returned an empty array"); + } + + ServletTestUtil.printResult(pw, passed); + } + + public static void getParameterValuesDoesNotExistTest(PrintWriter pw, + ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + + // no parameter was set with name zero + + String[] vals = request.getParameterValues("doesnotexit"); + + if (vals != null) { + passed = false; + pw.println( + "getParameterValues() returned a null list of parameter values"); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public static void getParameterDoesNotExistTest(PrintWriter pw, + ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + + String expectedResult = null; + String actual = request.getParameter("doesnotexist"); + // we are not settting any parameter in the client side so we should get + // null + if (actual != expectedResult) { + passed = false; + pw.println("getParameter() did not return the correct result"); + pw.println("Expected result = " + expectedResult); + pw.println("Actual result = |" + actual + "|"); + } else { + passed = true; + } + + ServletTestUtil.printResult(pw, passed); + } + + public static void getProtocolTest(PrintWriter pw, ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + boolean passed = false; + + String proto = request.getProtocol(); + String expectedResult = "HTTP/1."; + // looking for HTTP + int actual = proto.indexOf(expectedResult); + + if (actual == -1) { + passed = false; + pw.println("getProtocol() did not return the correct value"); + pw.println("Expected result = " + expectedResult); + pw.println("Actual count = |" + proto + "|"); + } else { + passed = true; + } + + ServletTestUtil.printResult(pw, passed); + } + + public static void getReaderTest(PrintWriter pw, ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + boolean passed = false; + String expected = "calling getReaderTest"; + BufferedReader br = request.getReader(); + + StringBuffer sb = new StringBuffer(); + + try { + String tmp = br.readLine(); + while (tmp != null) { + sb.append(tmp); + tmp = br.readLine(); + } + String actual = sb.toString(); + if (actual != null) { + if (!actual.equals(expected)) { + passed = false; + pw.println("getReaderTest returned the wrong body content"); + pw.println("expected =" + expected); + pw.println("actual =" + actual); + } else { + passed = true; + } + } else { + passed = false; + pw.println("getReaderTest returned null body content"); + } + } catch (Throwable t) { + passed = false; + pw.println("readLine() generated an exception"); + t.printStackTrace(pw); + } + ServletTestUtil.printResult(pw, passed); + } + + public static void getReaderIllegalStateExceptionTest(PrintWriter pw, + ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + + request.getInputStream(); + + try { + BufferedReader br = request.getReader(); + passed = false; + pw.println("getReader() method did not throw IllegalStateException"); + } catch (Throwable t) { + if (t instanceof IllegalStateException) { + passed = true; + } else { + passed = false; + pw.println( + "Exception thrown, but was not an instance of IllegalStateException."); + pw.println("instead received: " + t.getClass().getName()); + } + } + + ServletTestUtil.printResult(pw, passed); + } + + public static void getReaderUnsupportedEncodingExceptionTest(PrintWriter pw, + ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + + try { + BufferedReader br = request.getReader(); + passed = false; + pw.println( + "getReader() method did not throw UnsupportedEncodingException"); + } catch (Throwable t) { + if (t instanceof UnsupportedEncodingException) { + passed = true; + } else { + passed = false; + pw.println( + "Exception thrown, but was not an instance of java.io.UnsupportedEncodingException."); + pw.println("instead received: " + t.getClass().getName()); + } + } + + ServletTestUtil.printResult(pw, passed); + } + + public static void getRemoteAddrTest(PrintWriter pw, ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + boolean passed = false; + + String expResult = request.getParameter("Address"); + String[] expectedResults = ServletTestUtil.getAsArray(expResult); + Arrays.sort(expectedResults); + String actual = request.getRemoteAddr(); + + if (Arrays.binarySearch(expectedResults, actual) < 0) { + passed = false; + pw.println("getRemoteAddr() returned an incorrect result"); + pw.println("Expected result = [ " + expResult + " ]"); + pw.println("Actual result = |" + actual + "|"); + } else { + passed = true; + } + + ServletTestUtil.printResult(pw, passed); + } + + public static void getLocalAddrTest(PrintWriter pw, ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = false; + + String expected_results = null; + InetAddress[] _addrs = null; + + try { + _addrs = InetAddress + .getAllByName(InetAddress.getLocalHost().getCanonicalHostName()); + + if (_addrs.length != 0) { + StringBuffer sb = new StringBuffer(32); + + for (int i = 0; i < _addrs.length; i++) { + String ip = _addrs[i].getHostAddress(); + if (!ip.equals("127.0.0.1")) { + if (ip.contains("%")) { + int scope_id = ip.indexOf("%"); + ip = ip.substring(0, scope_id); + } + sb.append(ip); + } + sb.append(","); + } + sb.append("127.0.0.1"); + expected_results = sb.toString(); + pw.println("Local Interface info: " + expected_results); + } + + String[] expectedResults = ServletTestUtil.getAsArray(expected_results); + Arrays.sort(expectedResults); + String actual = request.getLocalAddr(); + + if (Arrays.binarySearch(expectedResults, actual) < 0) { + pw.println("getLocalAddr() returned an incorrect result"); + pw.println("Expected result = [ " + expected_results + " ]"); + pw.println("Actual result = |" + actual + "|"); + } else { + passed = true; + } + } catch (UnknownHostException uhe) { + pw.println("Unable to obtain local host information."); + } + + ServletTestUtil.printResult(pw, passed); + } + + public static void getRemoteHostTest(PrintWriter pw, ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + boolean passed = false; + + String expResult = request.getParameter("Address"); + String[] expectedResults = ServletTestUtil.getAsArray(expResult); + String actual = request.getRemoteHost(); + + for (int i = 0; i < expectedResults.length; i++) { + if (actual.indexOf(expectedResults[i]) >= 0) { + passed = true; + break; + } + } + + if (passed == false) { + pw.println("getRemoteHost() returned an incorrect result"); + pw.println("The expected result could be one of the following: [ " + + expResult + " ]"); + + pw.println("Actual result = |" + actual + "|"); + } + + ServletTestUtil.printResult(pw, passed); + } + + public static void getRequestDispatcherTest(PrintWriter pw, + ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + + String path = "/WEB-INF/web.xml"; + + RequestDispatcher rd = request.getRequestDispatcher(path); + + if (rd == null) { + passed = false; + pw.println("getRequestDispatcher() returned a null"); + } else { + passed = true; + } + + ServletTestUtil.printResult(pw, passed); + } + + public static void getSchemeTest(PrintWriter pw, ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + boolean passed = false; + + String expectedResult = "http"; + // check for some value + String actual = request.getScheme(); + + if (actual != null) { + if (!actual.equals(expectedResult)) { + passed = false; + pw.println("getScheme() returned an incorrect result"); + pw.println("Expected result = " + expectedResult); + pw.println("Actual result = |" + actual + "|"); + } else { + passed = true; + } + } else { + passed = false; + pw.println("getScheme() returned a null"); + } + + ServletTestUtil.printResult(pw, passed); + } + + public static void getServerNameTest(PrintWriter pw, ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + boolean passed = false; + + String actual = request.getServerName(); + String expectedResult = null; + expectedResult = request.getParameter("hostname"); + + if (actual != null) { + if (expectedResult != null) { + InetAddress thisHost = null; + InetAddress expectedHost = null; + try { + thisHost = InetAddress.getByName(actual); + expectedHost = InetAddress.getByName(expectedResult); + } catch (Throwable t) { + throw new ServletException( + "Unexpected problem with Test: " + t.getMessage()); + } + + if (!thisHost.equals(expectedHost)) { + passed = false; + pw.println("getServerName() returned an incorrect result"); + pw.println("Expected result (as IP) = " + expectedHost.toString()); + pw.println("Actual result (as IP) = " + thisHost.toString()); + } else { + passed = true; + } + } else { + passed = false; + pw.println("getParameter(hostname) returned a null result"); + } + + } else { + passed = false; + pw.println("getServerName() returned a null"); + } + + ServletTestUtil.printResult(pw, passed); + } + + public static void getServerPortTest(PrintWriter pw, ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + boolean passed = false; + + String expectedResult = request.getParameter("port"); + int actual = 0; + actual = request.getServerPort(); + + if (actual != 0) { + try { + int sexpectedResult = Integer.parseInt(expectedResult); + if (actual != sexpectedResult) { + passed = false; + pw.println("getServerPort() returned an incorrect result"); + pw.println("Expected result = " + expectedResult); + pw.println("Actual result = |" + actual + "|"); + } else { + passed = true; + } + } catch (Throwable t) { + passed = false; + t.printStackTrace(pw); + } + } + + ServletTestUtil.printResult(pw, passed); + } + + public static void isSecureTest(PrintWriter pw, ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + boolean passed = false; + + // check for some value + boolean expectedResult = false; + boolean actual = request.isSecure(); + + if (actual != expectedResult) { + passed = false; + pw.println("isSecure() did not return the correct result"); + pw.println("Expected result = " + expectedResult); + pw.println("Actual result = |" + actual + "|"); + } else { + passed = true; + } + + ServletTestUtil.printResult(pw, passed); + } + + public static void removeAttributeTest(PrintWriter pw, ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + boolean passed = false; + + request.setAttribute("attribute1", "value1"); + request.removeAttribute("attribute1"); + String attr = (String) request.getAttribute("attribute1"); + + if (attr != null) { + passed = false; + pw.println("removeAttribute() did not remove the indicated attribute"); + } else { + passed = true; + } + + ServletTestUtil.printResult(pw, passed); + } + + public static void setAttributeTest(PrintWriter pw, ServletRequest request, + ServletResponse response) throws ServletException, IOException { + + boolean passed = false; + + String expectedResult = "value1"; + request.setAttribute("attribute1", expectedResult); + String attr = (String) request.getAttribute("attribute1"); + + if (attr != null) { + if (!attr.equals(expectedResult)) { + passed = false; + pw.println("setAttribute() did not set the attribute properly"); + pw.println("Expected result = " + expectedResult); + pw.println("Actual result = |" + attr + "|"); + } else { + passed = true; + } + } else { + passed = false; + pw.println("setAttribute() did not set the attribute properly"); + pw.println( + "An attempt to get the attribute resulted in a null being returned"); + + } + + ServletTestUtil.printResult(pw, passed); + } + + public static void getCharacterEncodingNullTest(PrintWriter pw, + ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + + String actual = request.getCharacterEncoding(); + + if (actual != null) { + passed = false; + pw.println("getCharacterEncoding() returned the wrong result"); + pw.println("Expected result = null"); + pw.println("Actual result = |" + actual + "|"); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public static void setCharacterEncodingUnsupportedEncodingExceptionTest( + PrintWriter pw, ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + + try { + request.setCharacterEncoding("doesnotexist"); + passed = false; + pw.println( + "The exception UnsupportedEncodingException should have been thrown"); + } catch (Throwable t) { + if (t instanceof UnsupportedEncodingException) { + passed = true; + } else { + passed = false; + pw.println( + "Exception thrown, but was not an instance of IllegalStateException."); + pw.println("instead received: " + t.getClass().getName()); + } + } + + ServletTestUtil.printResult(pw, passed); + } + + public static void setCharacterEncodingTest(PrintWriter pw, + ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + String expected = "ISO-8859-7"; + try { + request.setCharacterEncoding(expected); + String encoding = request.getCharacterEncoding(); + + if (encoding != null) { + if (!encoding.equals(expected)) { + passed = false; + pw.println( + "getCharacterEncoding() did not receive the proper encoding"); + pw.println("Expected result = " + expected); + pw.println("Actual result = |" + encoding + "|"); + } else { + passed = true; + } + } else { + passed = false; + pw.println("getCharacterEncoding() returned a null result"); + } + } catch (Throwable t) { + passed = false; + pw.println("Exception thrown:" + t.getClass().getName()); + } + ServletTestUtil.printResult(pw, passed); + } + + public static void setCharacterEncodingTest1(PrintWriter pw, + ServletRequest request, ServletResponse response) + throws ServletException, IOException { + boolean passed = false; + String expected = "ISO-8859-7"; + + try { + BufferedReader br = request.getReader(); + request.setCharacterEncoding(expected); + String encoding = request.getCharacterEncoding(); + + if (encoding == null) { + pw.println("getCharacterEncoding() returned null as expected"); + passed = true; + } else { + pw.println( + "getCharacterEncoding() returned a non-null result: " + encoding); + } + } catch (Throwable t) { + pw.println("Exception thrown:" + t.getClass().getName()); + } + ServletTestUtil.printResult(pw, passed); + } + + public static void getLocalNameTest(PrintWriter pw, ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = false; + + String tmp = request.getLocalName(); + String expected = request.getParameter("hostname"); + + if ((expected == null) || (tmp == null)) { + pw.println("Either answer or expected is null"); + pw.println("Incorrect answer returned = " + tmp); + pw.println("Expecting " + expected); + } else { + tmp = tmp.toLowerCase(); + // Check the cases when hostname and hostname.domain are used to send + // request + // Check the cases when localhost or 127.0.0.1 are used to send request + if (tmp.equals("localhost") || tmp.equals("127.0.0.1") + || tmp.startsWith(expected.toLowerCase()) + || expected.toLowerCase().startsWith(tmp) + || expected.toLowerCase().equals("127.0.0.1") + || expected.toLowerCase().equals("localhost")) { + passed = true; + pw.println("Correct answer returned = " + tmp); + pw.println("Expecting " + expected); + } else { + // Checkthe case when ip address is used to send request + String thisHost = null; + String expectedHost = null; + try { + thisHost = InetAddress.getByName(tmp).getHostAddress(); + expectedHost = InetAddress.getByName(expected).getHostAddress(); + + if (thisHost.equals(expected) || thisHost.equals(expectedHost)) { + pw.println("Test used an IP address to send request"); + pw.println("Correct answer returned = " + tmp); + pw.println("Got result (as IP) = " + thisHost); + pw.println("expected " + expected); + pw.println("expected IP address " + expectedHost); + passed = true; + } else { + pw.println("getLocalName() returned an incorrect result"); + pw.println("Expected result (as hostname) = " + expected); + pw.println("Expected result (as IP) = " + expectedHost); + pw.println("Got result (as IP) = " + thisHost); + pw.println("Incorrect answer returned = " + tmp); + } + } catch (java.net.UnknownHostException t) { + pw.println("Incorrect answer returned = " + tmp); + pw.println("Not an correct IP address neither"); + pw.println("Expecting " + expected); + } + } + } + ServletTestUtil.printResult(pw, passed); + } + + public static void getLocalPortTest(PrintWriter pw, ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = false; + + int tmp = request.getLocalPort(); + + if (String.valueOf(tmp).equals(request.getParameter("hostport"))) { + passed = true; + pw.println("Correct answer returned = " + tmp); + } else { + pw.println("Incorrect answer returned = " + tmp); + pw.println("Expecting " + request.getParameter("hostport")); + } + + ServletTestUtil.printResult(pw, passed); + } + // --------------- END jakarta_servlet.ServletRequest + // ---------------------------- + + // --------------- jakarta_servlet_http.HttpServletRequest + // ----------------------- + public static void httpRequestWrapperConstructorIllegalArgumentExceptionTest( + PrintWriter pw, HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + boolean passed = false; + + try { + new HttpServletRequestWrapper(null); + passed = false; + pw.println("IllegalArgumentException should have been thrown"); + } catch (Throwable t) { + if (t instanceof IllegalArgumentException) { + passed = true; + } else { + passed = false; + pw.println( + "Exception thrown, but was not an instance of IllegalArgumentException."); + pw.println("instead received: " + t.getClass().getName()); + } + } + ServletTestUtil.printResult(pw, passed); + } + + public static void httpRequestWrapperConstructorTest(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + HttpServletRequestWrapper hsrw = new HttpServletRequestWrapper(request); + if (hsrw != null) { + ServletTestUtil.printResult(pw, true); + } else { + ServletTestUtil.printResult(pw, false); + } + } + + public static void httpRequestWrapperGetRequestTest(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + boolean passed = true; + HttpServletRequestWrapper hsrw = new HttpServletRequestWrapper(request); + if (hsrw != null) { + ServletRequest sr = hsrw.getRequest(); + if (!((ServletRequest) request).equals(sr)) { + passed = false; + pw.println("getRequest failed to return the same request object"); + } + } else { + passed = false; + pw.println("constructor returned a null"); + } + ServletTestUtil.printResult(pw, passed); + } + + public static void httpRequestWrapperSetRequestTest(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + boolean passed = true; + HttpServletRequestWrapper hsrw = new HttpServletRequestWrapper(request); + if (hsrw != null) { + try { + hsrw.setRequest(request); + } catch (Throwable t) { + passed = false; + pw.println("Error: setRequest generated a Throwable"); + t.printStackTrace(pw); + } + if (passed) { + ServletRequest sr = hsrw.getRequest(); + if (!((ServletRequest) request).equals(sr)) { + passed = false; + pw.println("getRequest failed to return the same request object"); + } + } + } else { + passed = false; + pw.println("constructor returned a null"); + } + ServletTestUtil.printResult(pw, passed); + } + + public static void httpRequestWrapperSetRequestIllegalArgumentExceptionTest( + PrintWriter pw, HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + HttpServletRequestWrapper hsrw = new HttpServletRequestWrapper(request); + if (hsrw != null) { + try { + hsrw.setRequest(null); + passed = false; + pw.println( + "Error: an IllegalArgumentException should have been generated"); + } catch (Throwable t) { + if (t instanceof IllegalArgumentException) { + passed = true; + } else { + passed = false; + pw.println( + "Exception thrown, but was not an instance of IllegalArgumentException."); + pw.println("instead received: " + t.getClass().getName()); + } + } + } else { + passed = false; + pw.println("constructor returned a null"); + } + ServletTestUtil.printResult(pw, passed); + } + + public static void getAuthTypeWithoutProtectionTest(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + String result = request.getAuthType(); + + if (result != null) { + passed = false; + pw.println( + "getAuthType() returned a non-null result, even though Servlet is not protected"); + pw.println("Actual result = |" + result + "|"); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + + } + + public static void getContextPathTest(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + String expectedResult = request.getHeader("result"); + String result = request.getContextPath(); + + if (result != null) { + if (!result.equals(expectedResult)) { + passed = false; + pw.println("getContextPath() returned an incorrect result"); + pw.println("Expected result = " + expectedResult); + pw.println("Actual result = |" + result + "|"); + } else { + passed = true; + } + } else { + passed = false; + pw.println("getContextPath() returned a null result"); + } + ServletTestUtil.printResult(pw, passed); + + } + + public static void getCookiesTest(PrintWriter pw, HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + boolean passed = true; + String expectedName = "cookie"; + String expectedValue = "value"; + boolean expectedResultFound = false; + Cookie cookies[] = null; + int count = 0; + int expectedCount = 1; + boolean gotCookie = false; + cookies = request.getCookies(); + int len = cookies.length; + + for (int i = 0; i < len; i++) { + String name = cookies[i].getName(); + String value = cookies[i].getValue(); + if (name.equals(expectedName) && value.equals(expectedValue)) { + if (!expectedResultFound) { + count++; + expectedResultFound = true; + } else { + passed = false; + pw.println("getCookies() method return the same cookie twice"); + pw.println( + "The cookie already received was " + name + ", value=" + value); + } + } else { + passed = false; + pw.println("getCookies() method return the wrong cookie"); + pw.println("actual=" + name + ", value=" + value); + } + } + + if (count != expectedCount) { + passed = false; + pw.println( + "getCookies() method did not return the correct number of cookies"); + pw.println("Expected count = " + expectedCount); + pw.println("Actual count = " + count); + } + ServletTestUtil.printResult(pw, passed); + + } + + public static void getCookiesNoCookiesTest(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + boolean passed = false; + Cookie[] cook = request.getCookies(); + + if (cook != null) { + passed = false; + pw.println( + "getCookies() returning non null value even though client is not sending any cookies."); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public static void getDateHeaderTest(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + boolean passed = true; + + pw.println("lower case"); + long expected = 946684801000L; + String param = "if-modified-since"; + if (!testDateHeader(pw, request, expected, param)) { + passed = false; + } + + pw.println("mix case"); + param = "If-Modified-Since"; + if (!testDateHeader(pw, request, expected, param)) { + passed = false; + } + + pw.println("upper case"); + param = "IF-MODIFIED-SINCE"; + if (!testDateHeader(pw, request, expected, param)) { + passed = false; + } + + ServletTestUtil.printResult(pw, passed); + } + + private static boolean testDateHeader(PrintWriter pw, + HttpServletRequest request, long expected, String param) { + boolean passed = false; + + try { + long result = request.getDateHeader(param); + + if (result != expected) { + passed = false; + pw.println("getDateHeader(" + param + ") returned an incorrect result"); + pw.println("Expected result = " + expected); + pw.println("Actual result = |" + result + "|"); + } else { + passed = true; + } + } catch (Throwable t) { + passed = false; + pw.println("getDateHeader(" + param + + ") Can't convert the sent header value to Date"); + pw.println("getDateHeader(" + param + ") threw exception"); + t.printStackTrace(pw); + } + return passed; + } + + public static void getDateHeaderNoHeaderTest(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + long result = request.getDateHeader("If-Modified-Since"); + + if (result != -1) { + passed = false; + pw.println("getDateHeader didn't return -1 for a NonExistent header"); + pw.println("Actual result = |" + result + "|"); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public static void getDateHeaderIllegalArgumentExceptionTest(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + String param = "If-Modified-Since"; + try { + long result = request.getDateHeader("If-Modified-Since"); + passed = false; + pw.println("getDateHeader(" + param + + ") did not throw an IllegalArgumentExcpetion"); + } catch (Throwable t) { + if (t instanceof IllegalArgumentException) { + passed = true; + } else { + passed = false; + pw.println( + "Exception thrown, but was not an instance of IllegalArgumentException ."); + pw.println("instead received: " + t.getClass().getName()); + } + } + ServletTestUtil.printResult(pw, passed); + } + + public static void getHeaderTest(PrintWriter pw, HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + boolean passed = true; + + String expected = "Mozilla/4.0"; + + pw.println("lower case"); + String param = "user-agent"; + if (!testGetHeader(pw, request, expected, param)) { + passed = false; + } + + pw.println("mixed case"); + param = "User-Agent"; + if (!testGetHeader(pw, request, expected, param)) { + passed = false; + } + + pw.println("upper case"); + param = "USER-AGENT"; + if (!testGetHeader(pw, request, expected, param)) { + passed = false; + } + ServletTestUtil.printResult(pw, passed); + } + + // This is a private utility test method + private static boolean testGetHeader(PrintWriter pw, + HttpServletRequest request, String expected, String param) { + + boolean passed = false; + + String result = request.getHeader(param); + if (!expected.equals(result)) { + passed = false; + pw.println("getHeader() returned an incorrect result"); + pw.println("Expected result = " + expected); + pw.println("Actual result = |" + result + "|"); + } else { + passed = true; + } + return passed; + } + + public static void getHeaderNoHeaderTest(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + String result = request.getHeader("doesnotexist"); + if (result != null) { + passed = false; + pw.println("getHeader didn't return a null for a NonExistent header"); + pw.println("Actual result = |" + result + "|"); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public static void getHeaderNamesTest(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + boolean passed = true; + + String expected1 = "If-Modified-Since"; + String expected2 = "Cookie"; + String[] expected = { expected1, expected2 }; + + Enumeration e = request.getHeaderNames(); + if (e == null) { + // Some servlet containers won't allow servlets to use + // this method and in that case it returns null + } else { + if (!ServletTestUtil.checkEnumeration(e, expected, false, false)) { + passed = false; + ServletTestUtil.printFailureData(pw, e, expected); + } + } + ServletTestUtil.printResult(pw, passed); + } + + public static void getHeadersTest(PrintWriter pw, HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + boolean passed = true; + + final String[] expected = { "en-us, ga-us" }; + + final String[] expected1 = { "en-us", "ga-us" }; + + pw.println("lower case"); + String param = "accept-language"; + if (!testGetHeaders(pw, request, expected, param)) { + passed = testGetHeaders(pw, request, expected1, param); + } + + pw.println("mixed case"); + param = "Accept-Language"; + if (!testGetHeaders(pw, request, expected, param)) { + passed = testGetHeaders(pw, request, expected1, param); + } + + pw.println("upper case"); + param = "ACCEPT-LANGUAGE"; + if (!testGetHeaders(pw, request, expected, param)) { + passed = testGetHeaders(pw, request, expected1, param); + } + + ServletTestUtil.printResult(pw, passed); + } + + private static boolean testGetHeaders(PrintWriter pw, + HttpServletRequest request, String[] expected, String param) { + + boolean passed = false; + + Enumeration e = request.getHeaders(param); + if (e != null) { + if (!ServletTestUtil.checkEnumeration(e, expected)) { + passed = false; + ServletTestUtil.printFailureData(pw, e, expected); + } else { + passed = true; + } + } else { + passed = false; + pw.println("getHeaders(" + param + ") returned a null"); + } + return passed; + } + + public static void getHeadersNoHeadersTest(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + boolean passed = false; + + Enumeration e = request.getHeaders("doesnotexist"); + + if (e.hasMoreElements()) { + passed = false; + pw.println("getHeaders(doesnotexist) returned a Non-Empty enumeration"); + pw.print("The headers received were:"); + ServletTestUtil.getAsString(e); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public static void getIntHeaderTest(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + boolean passed = true; + final int expected = 123; + + pw.println("lower case"); + String param = "myintheader"; + if (!testGetIntHeader(pw, request, expected, param)) { + passed = false; + } + + pw.println("mixed case"); + param = "MyIntHeader"; + if (!testGetIntHeader(pw, request, expected, param)) { + passed = false; + } + pw.println("upper case"); + param = "MYINTHEADER"; + if (!testGetIntHeader(pw, request, expected, param)) { + passed = false; + } + + ServletTestUtil.printResult(pw, passed); + } + + private static boolean testGetIntHeader(PrintWriter pw, + HttpServletRequest request, int expected, String param) { + + boolean passed = false; + + try { + int result = request.getIntHeader(param); + + if (result != expected) { + passed = false; + pw.println("getIntHeader(" + param + ") return an incorrect result"); + pw.println("Expected result = " + expected); + pw.println("Actual result = " + result); + } else { + passed = true; + } + } catch (Throwable t) { + passed = false; + pw.println("getIntHeader(" + param + ") generated an exception"); + t.printStackTrace(pw); + } + return passed; + } + + public static void getIntHeaderNumberFoundExceptionTest(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + + try { + + String param = "MyNonIntHeader"; + int result = request.getIntHeader(param); + passed = false; + pw.println("getIntHeader(" + param + + ") did not throw a NumberFormatException for a NonInt Header"); + pw.println("Actual result = |" + result + "|"); + } catch (Throwable t) { + if (t instanceof NumberFormatException) { + passed = true; + } else { + passed = false; + pw.println( + "Exception thrown, but was not an instance of NumberFormatException ."); + pw.println("instead received: " + t.getClass().getName()); + } + } + ServletTestUtil.printResult(pw, passed); + } + + public static void getIntHeaderNoHeaderTest(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + boolean passed = false; + String param = "doesnotexist"; + + try { + int result = request.getIntHeader(param); + + if (result != -1) { + passed = false; + pw.println("getIntHeader(" + param + + ") did not return a -1 for non-existent header"); + pw.println("Actual result = |" + result + "|"); + } else { + passed = true; + } + + } catch (Throwable t) { + passed = false; + pw.println("getIntHeader(" + param + + ") generated an exception instead of returning -1"); + t.printStackTrace(pw); + } + ServletTestUtil.printResult(pw, passed); + } + + public static void getMethod_GETTest(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + boolean passed = false; + + String expectedResult = "GET"; + String result = request.getMethod(); + + if (result != null) { + if (!result.equalsIgnoreCase(expectedResult)) { + passed = false; + pw.println("getMethod() returned an incorrect result"); + pw.println("Expected result = " + expectedResult); + pw.println("Actual result = |" + result + "|"); + } else { + passed = true; + } + } else { + passed = false; + pw.println("getMethod() returned a null result"); + } + ServletTestUtil.printResult(pw, passed); + } + + public static void getMethod_HEADTest(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + String expectedResult = "HEAD"; + String result = request.getMethod(); + pw.write("Arbitrary Text"); + + if (result != null) { + if (result.equalsIgnoreCase(expectedResult)) { + response.addHeader("status", Data.PASSED); + } else { + response.addHeader("status", Data.FAILED); + } + } + + } + + public static void getMethod_POSTTest(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + boolean passed = false; + String expectedResult = "POST"; + String result = request.getMethod(); + + if (result != null) { + if (!result.equalsIgnoreCase(expectedResult)) { + passed = false; + pw.println("getMethod() returned an incorrect result"); + pw.println("Expected result = " + expectedResult); + pw.println("Actual result = |" + result + "|"); + } else { + passed = true; + } + } else { + passed = false; + pw.println("getMethod() returned a null result"); + } + + ServletTestUtil.printResult(pw, passed); + } + + public static void getPathInfoTest(PrintWriter pw, HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + boolean passed = false; + String expectedResult = "/pathinfostring1/pathinfostring2"; + String result = request.getPathInfo(); + + if (result != null) { + if (!result.equals(expectedResult)) { + passed = false; + pw.println("getPathInfo() returned an incorrect result"); + pw.println("Expected result = " + expectedResult); + pw.println("Actual result = |" + result + "|"); + } else { + passed = true; + } + } else { + passed = false; + pw.println("getMethod() returned a null result"); + } + ServletTestUtil.printResult(pw, passed); + } + + public static void getPathInfoNullTest(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + boolean passed = false; + // shouldn't retrieve any extra path info coz nothing was provided + String result = request.getPathInfo(); + + if (result != null) { + passed = false; + pw.println("getPathInfo() returned a non-null result"); + pw.println("Actual result = |" + result + "|"); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public static void getPathTranslatedNullTest(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + + String result = request.getPathTranslated(); + + // null will be returned if running out of a jar + if (result != null) { + passed = false; + pw.println("getPathTranslated() returned an incorrect result"); + pw.println("Expected result = null"); + pw.println("Actual result = |" + result + "|"); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public static void getPathTranslatedTest(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + boolean passed = true; + ServletContext sc = (ServletContext) request.getAttribute("servletContext"); + String expectedResult = sc.getRealPath(request.getPathInfo()); + + String result = request.getPathTranslated(); + // null will be returned if running out of a jar + if (expectedResult == null) { + if (result != null) { + passed = false; + pw.println("getPathTranslated() returned an incorrect result"); + pw.println("Expected result = Null"); + pw.println("Actual result = |" + result + "|"); + } + } else if (!expectedResult.equals(result)) { + passed = false; + pw.println("getPathTranslated() returned an incorrect result"); + pw.println("Expected result = " + expectedResult); + pw.println("Actual result = |" + result + "|"); + } + + ServletTestUtil.printResult(pw, passed); + } + + public static void getQueryStringTest(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + + String expected = "qs=value1"; + // we should get a not null value + String result = request.getQueryString(); + + if (result != null) { + if (!expected.equals(result)) { + passed = false; + pw.println("getQueryString() returned an incorrect result"); + pw.println("Expected result = " + expected); + pw.println("Actual result = |" + result + "|"); + } else { + passed = true; + } + } else { + passed = false; + pw.println("getQueryString() returned a null result"); + } + ServletTestUtil.printResult(pw, passed); + } + + public static void getQueryStringNullTest(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + String result = request.getQueryString(); + + if (result != null) { + passed = false; + pw.println( + " HttpServletRequest.getQueryString() returned a Non-Null result"); + pw.println(" Actual result = |" + result + "|"); + } else { + passed = true; + } + + ServletTestUtil.printResult(pw, passed); + } + + public static void getRequestURITest(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + boolean passed = false; + + String expectedResult = request.getHeader("result") + "/TestServlet"; + String result = request.getRequestURI(); + // not null value expected + if (result != null) { + if (!result.equals(expectedResult)) { + passed = false; + pw.println("getRequestURI() returned an incorrect result"); + pw.println("Expected result = " + expectedResult); + pw.println("Actual result = |" + result + "|"); + } else { + passed = true; + } + } else { + passed = false; + pw.println("getRequestURI() returned a null result"); + } + + ServletTestUtil.printResult(pw, passed); + } + + public static void getServletPathTest(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + String expectedResult = "/TestServlet"; + String result = request.getServletPath(); + + if (result != null) { + if (!result.equals(expectedResult)) { + passed = false; + pw.println("getServletPath() returned an incorrect result"); + pw.println("Expected result = " + expectedResult); + pw.println("Actual result = |" + result + "|"); + } else { + passed = true; + } + } else { + passed = false; + pw.println("getServletPath() returned a null result"); + } + ServletTestUtil.printResult(pw, passed); + } + + public static void getServletPathEmptyStringTest(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + String expectedResult = ""; + String result = request.getServletPath(); + + if (result != null) { + if (!result.equals(expectedResult)) { + passed = false; + pw.println("getServletPath() returned an incorrect result"); + pw.println("Expected result = ''"); + pw.println("Actual result = |" + result + "|"); + } else { + passed = true; + } + } else { + passed = false; + pw.println("getServletPath() returned a null result"); + } + ServletTestUtil.printResult(pw, passed); + } + + public static void getSessionTest(PrintWriter pw, HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + boolean passed = false; + HttpSession sess = request.getSession(); + + if (sess == null) { + passed = false; + pw.println("getSession() returned a Null result"); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public static void getSessionTrueSessionTest(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + HttpSession expected = savedSession; + HttpSession actual = request.getSession(true); + if (actual != null) { + if (!actual.getId().equals(expected.getId())) { + passed = false; + pw.println("getSession(true) did not return the correct session id"); + pw.println("expected=" + expected.getId()); + pw.println("actual=" + actual.getId()); + } else { + passed = true; + } + } else { + passed = false; + pw.println("getSession(true) returned a Null result"); + } + ServletTestUtil.printResult(pw, passed); + } + + public static void getSessionTrueNoSessionTest(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + + HttpSession sess = request.getSession(true); + if (sess != null) { + savedSession = sess; + savedSessionId = sess.getId(); + passed = true; + } else { + passed = false; + pw.println("getSession(true) returned a Null result"); + } + ServletTestUtil.printResult(pw, passed); + } + + public static void getSessionFalseTest(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + HttpSession sess = request.getSession(false); + + if (sess != null) { + if (sess.isNew()) { + passed = true; + pw.println("getSession() did not returned a Null result"); + pw.println("Actual=" + sess.toString()); + } else { + passed = false; + pw.println("getSession() did not returned a Null result"); + pw.println("Actual=" + sess.toString()); + } + } else { + passed = true; + pw.println("getSession() returned a Null"); + } + ServletTestUtil.printResult(pw, passed); + } + + public static void isRequestedSessionIdFromCookieTest(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + boolean result = request.isRequestedSessionIdFromCookie(); + + pw.println("Actual result = " + result); + } + + public static void isRequestedSessionIdFromURLTest(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + boolean expectedResult = false; + boolean result = request.isRequestedSessionIdFromURL(); + + if (result != expectedResult) { + passed = false; + pw.println("isRequestedSessionIdFromURL returned incorrect result"); + pw.println("Expected result = " + expectedResult); + pw.println("Actual result = " + result); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public static void isRequestedSessionIdValidTest(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + boolean expectedResult = false; + boolean result = request.isRequestedSessionIdValid(); + + if (result != expectedResult) { + passed = false; + pw.println("isRequestedSessionIdValid() returned incorrect result"); + pw.println("Expected result = " + expectedResult); + pw.println("Actual result = " + result); + + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public static void getRequestURLTest(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + boolean passed = false; + String expResult1 = null; + String expResult2 = null; + String result = request.getRequestURL().toString(); + + String scheme = request.getHeader("scheme"); + String path = request.getHeader("servletPath").replace('-', '/'); + + expResult1 = scheme + "://"; + expResult2 = path; + + if (!result.startsWith(expResult1) && !result.endsWith(expResult2)) { + passed = false; + pw.println("Unexpected result returned from getRequestURL()."); + pw.println("Expected " + expResult1 + "" + expResult2); + pw.println("Received: " + result); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public static void getRemoteUserTest(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + boolean passed = false; + String result = request.getRemoteUser(); + if (result != null) { + passed = false; + pw.println("A non-null value was returned from getQueryString()."); + pw.println("Received: " + result + "'"); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public static void getRequestedSessionIdNullTest(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + boolean passed = false; + String result = request.getRequestedSessionId(); + if (result != null) { + passed = false; + pw.println("A non-null value was returned from getRequestedSessionId()"); + pw.println("Received: " + result); + } else { + passed = true; + } + ServletTestUtil.printResult(pw, passed); + } + + public static void invalidateSessionId(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + HttpSession sess = request.getSession(); + savedRequestedSessionId = request.getRequestedSessionId(); + sess.invalidate(); + ServletTestUtil.printResult(pw, true); + } + + public static void getRequestedSessionIdTest(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + + HttpSession sess = request.getSession(true); + if (sess != null) { + String actual = request.getRequestedSessionId(); + if (actual != null) { + if (actual.equals(savedRequestedSessionId)) { + pw.println( + "getRequestedSessionId() returned correct requesteSessionId=" + + savedRequestedSessionId); + passed = true; + } else { + passed = false; + pw.println( + "getRequestedSessionId() returned the incorrect request session id"); + pw.println("Correct RequestedSessionId=" + savedRequestedSessionId); + pw.println("getRequestedSessionId =" + actual); + } + } else { + passed = false; + pw.println("getRequestedSessionId() returned a Null result"); + } + } else { + passed = false; + pw.println("getSession(true) returned a Null result"); + } + ServletTestUtil.printResult(pw, passed); + } + + public static void getRequestedSessionIdTest1(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + boolean passed = false; + + String actual = request.getRequestedSessionId(); + String expected = request.getParameter("TCKidsetto"); + if (actual != null) { + if (actual.equals(expected)) { + passed = true; + pw.println("Test returned with RequestdSessionId=" + actual); + } else { + pw.println( + "getRequestedSessionId() returned the incorrect request session id"); + pw.println("Correct RequestedSessionId=" + expected); + pw.println("getRequestedSessionId =" + actual); + } + } else { + pw.println("getRequestedSessionId() returned a Null result"); + } + ServletTestUtil.printResult(pw, passed); + } + + public static void getRequestedSessionIdTest2(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + boolean passed = false; + + HttpSession sess = request.getSession(true); + if (sess != null) { + String actual = request.getRequestedSessionId(); + String expected = request.getParameter("TCKidsetto"); + if (actual != null) { + if (actual.equals(expected)) { + passed = true; + pw.println("Test returned with RequestdSessionId=" + actual); + } else { + pw.println( + "getRequestedSessionId() returned the incorrect request session id"); + pw.println("Correct RequestedSessionId=" + expected); + pw.println("getRequestedSessionId =" + actual); + } + } else { + pw.println("getRequestedSessionId() returned a Null result"); + } + } else { + passed = false; + pw.println("getSession(true) returned a Null result"); + } + ServletTestUtil.printResult(pw, passed); + } + + public static void sessionTimeoutTest(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + boolean passed = false; + + HttpSession sess = request.getSession(); + if (sess != null) { + sess.setMaxInactiveInterval(60); + + try { + Thread.sleep(90000); + } catch (java.lang.InterruptedException ex) { + pw.println("Sleep interupted - " + ex.getMessage()); + } + + if (request.getSession(false) != null) { + passed = true; + pw.println("Session is still alive after timeout - 90 seconds"); + } else { + passed = false; + pw.println("Session is expired after timeout - 90 seconds"); + } + } else { + passed = false; + pw.println("getSession() returned a Null result"); + } + ServletTestUtil.printResult(pw, passed); + } + + public static void changeSessionIDTest(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + Boolean passed = true; + + try { + request.changeSessionId(); + passed = false; + pw.println("Test Failed. "); + pw.println("Expected ServletException not thrown"); + } catch (IllegalStateException lex) { + pw.println("Test Passed."); + pw.println("Expected IllegalStateException thrown: " + lex.getMessage()); + } catch (Exception oex) { + passed = false; + pw.println("Test Failed."); + pw.print("Unexpected Exception thrown: " + oex.getMessage()); + } + ServletTestUtil.printResult(pw, passed); + } + + public static void changeSessionIDTest1(PrintWriter pw, + HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + Boolean pass = true; + String attrName_OLD = "OLD"; + String attrName_NEW = "NEW"; + + HttpSession session = request.getSession(true); + String sessionId_old = session.getId(); + String sessionId_new = request.changeSessionId(); + + if (sessionId_new.equals(sessionId_old)) { + pass = false; + pw.append( + "HttpServletRequest.changeSessionId didn't return new Session ID," + + "it returns the original sesison ID " + sessionId_old); + } + + if (!((String) request.getSession(false).getAttribute(attrName_OLD)) + .equals(sessionId_old)) { + pass = false; + pw.append( + "Original Session ID does not sync up. Before ChangeSessionId is called: " + + sessionId_old + " From TCKHttpSessionIDListener " + + request.getSession(false).getAttribute(attrName_OLD)); + } + + if (((String) request.getSession(false).getAttribute(attrName_NEW)) + .equals(sessionId_old)) { + pass = false; + pw.append("Session ID didn't change: " + sessionId_old); + } + + if (!((String) request.getSession(false).getAttribute(attrName_NEW)) + .equals(sessionId_new)) { + pass = false; + pw.append("New Session ID does not sync up. ChangeSessionId returned " + + sessionId_new + " TCKHttpSessionIDListener returned " + + request.getSession(false).getAttribute(attrName_NEW)); + } + + pw.append("Original before changeSessionId is called =" + sessionId_old + + "=changeSessionId returned=" + sessionId_new + + "=oroginal from TCKHttpSessionIDListener=" + + request.getSession(false).getAttribute(attrName_OLD) + + "=new from TCKHttpSessionIDListener=" + + request.getSession(false).getAttribute(attrName_NEW)); + ServletTestUtil.printResult(pw, pass); + } + // --------------- END jakarta_servlet_http.HttpServletRequest + // ------------------- +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/servlets/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/servlets/build.xml new file mode 100644 index 0000000000..88ad0b1210 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/servlets/build.xml @@ -0,0 +1,23 @@ + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/util/Data.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/util/Data.java new file mode 100644 index 0000000000..d3f4625b61 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/util/Data.java @@ -0,0 +1,65 @@ +/* +* +* The Apache Software License, Version 1.1 +* +* Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. +* Copyright (c) 1999-2001 The Apache Software Foundation. All rights +* reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* +* 3. The end-user documentation included with the redistribution, if +* any, must include the following acknowlegement: +* "This product includes software developed by the +* Apache Software Foundation (http://www.apache.org/)." +* Alternately, this acknowlegement may appear in the software itself, +* if and wherever such third-party acknowlegements normally appear. +* +* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software +* Foundation" must not be used to endorse or promote products derived +* from this software without prior written permission. For written +* permission, please contact apache@apache.org. +* +* 5. Products derived from this software may not be called "Apache" +* nor may "Apache" appear in their names without prior written +* permission of the Apache Group. +* +* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR +* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +* SUCH DAMAGE. +* ==================================================================== +* +* This software consists of voluntary contributions made by many +* individuals on behalf of the Apache Software Foundation. For more +* information on the Apache Software Foundation, please see +* . +* +*/ + +package com.sun.ts.tests.servlet.common.util; + +public final class Data { + + public static final String PASSED = "Test PASSED"; + + public static final String FAILED = "Test FAILED"; +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/util/ServletTestUtil.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/util/ServletTestUtil.java new file mode 100644 index 0000000000..b584fbfed2 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/util/ServletTestUtil.java @@ -0,0 +1,377 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.common.util; + +import jakarta.servlet.ServletOutputStream; +import jakarta.servlet.http.Cookie; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Enumeration; +import java.util.List; +import java.util.NoSuchElementException; +import java.util.StringTokenizer; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * A set of useful utility methods to help perform test functions. + */ +public class ServletTestUtil { + + private static Logger LOGGER = LoggerFactory.getLogger(ServletTestUtil.class); + + /** + * Private as this class contains only public static methods. + */ + private ServletTestUtil() { + } + + /** + * Compares the String values in an Enumeration against the provides String + * array of values. The number of elements in the enumeration must be the same + * as the size of the array, or false will be returned. False will also be + * returned if the provided Enumeration or String array is null. + * + * If all values are found, true will be returned. + * + * Note: This method isn't concerned with the presence of duplicate + * values contained in the enumeration. + * + * The comparison is performed in a case sensitive manner. + * + * @param e + * - Enumeration to validate + * @param values + * - the values expected to be found in the Enumeration + * + * @return true if all the expected values are found, otherwise false. + */ + public static boolean checkEnumeration(Enumeration e, String[] values) { + return checkEnumeration(e, values, true, true); + } + + /** + * Compares the String values in an Enumeration against the provides String + * array of values. The number of elements in the enumeration must be the same + * as the size of the array, or false will be returned. False will also be + * returned if the provided Enumeration or String array is null. + * + * If all values are found, true will be returned. + * + * Note: This method isn't concerned with the presence of duplicate + * values contained in the enumeration. + * + * The comparison is performed in a case sensitive manner. + * + * @param e + * - Enumeration to validate + * @param values + * - the values expected to be found in the Enumeration + * @param enforceSizes + * - ensures that the number of elements in the Enumeration matches + * the number of elements in the array of values + * @param allowDuplicates + * - If true, the method will true if duplicate elements are found in + * the Enumeration, if false, then false will be return if duplicate + * elements have been found. + * + * @return true if all the expected values are found, otherwise false. + */ + public static boolean checkEnumeration(Enumeration e, String[] values, + boolean enforceSizes, boolean allowDuplicates) { + List foundValues = null; + + if (e == null || !e.hasMoreElements() || values == null) { + return false; + } + + if (!allowDuplicates) { + foundValues = new ArrayList(); + } + + boolean valuesFound = true; + Arrays.sort(values); + int count = 0; + while (e.hasMoreElements()) { + Object val; + try { + val = e.nextElement(); + count++; + if (!allowDuplicates) { + if (foundValues.contains(val)) { + LOGGER.debug("[ServletTestUtil] Duplicate values found in " + + "Enumeration when duplicates are not allowed." + + "Values found in the Enumeration: {}", getAsString(e)); + valuesFound = false; + break; + } + foundValues.add(val); + } + + } catch (NoSuchElementException nsee) { + LOGGER.info("[ServletTestUtil] There were less elements in the " + + "Enumeration than expected"); + valuesFound = false; + break; + } + LOGGER.debug("[ServletTestUtil] Looking for '{}' in values: {}", val, getAsString(values)); + if ((Arrays.binarySearch(values, val) < 0) && (enforceSizes)) { + LOGGER.info("[ServletTestUtil] Value '{}' not found.", val); + valuesFound = false; + continue; + } + } + + if (enforceSizes) { + if (e.hasMoreElements()) { + // more elements than should have been. + LOGGER.info("[ServletTestUtil] There were more elements in the Enumeration than expected."); + valuesFound = false; + } + if (count != values.length) { + LOGGER.info("[ServletTestUtil] There number of elements in the Enumeration did not match number of expected values." + + "Expected number of Values= {}, Actual number of Enumeration elements= {}", values.length, count); + + valuesFound = false; + } + } + return valuesFound; + } + + public static boolean checkArrayList(ArrayList al, String[] values, + boolean enforceSizes, boolean allowDuplicates) { + List foundValues = null; + + if (al == null || al.isEmpty() || values == null) { + return false; + } + + if (!allowDuplicates) { + foundValues = new ArrayList(); + } + + al.trimToSize(); + boolean valuesFound = true; + Arrays.sort(values); + int len = al.size(); + for (int i = 0; i < len; i++) { + Object val = null; + val = (String) al.get(i); + LOGGER.debug("[ServletTestUtil] val= {}", val); + if (!allowDuplicates) { + if (foundValues.contains(val)) { + LOGGER.info("[ServletTestUtil] Duplicate values found in ArrayList when duplicates are not allowed." + + "Values found in the ArrayList: {}", getAsString(al)); + valuesFound = false; + break; + } + foundValues.add(val); + } + LOGGER.debug("[ServletTestUtil] Looking for '{}' in values: {}", val, getAsString(values)); + if ((Arrays.binarySearch(values, val) < 0) && (enforceSizes)) { + LOGGER.info("[ServletTestUtil] Value '{}' not found.", val); + valuesFound = false; + continue; + } + } + + if (enforceSizes) { + if (len != values.length) { + LOGGER.info("[ServletTestUtil] There number of elements in the ArrayList " + + "did not match number of expected values." + + "Expected number of Values= {}, Actual number of ArrayList elements= {}", values.length, len); + + valuesFound = false; + } + } + return valuesFound; + } + + public static boolean compareString(String expected, String actual) { + String[] list_expected = expected.split("[|]"); + boolean found = true; + for (int i = 0, n = list_expected.length, startIdx = 0, bodyLength = actual + .length(); i < n; i++) { + + String search = list_expected[i]; + if (startIdx >= bodyLength) { + startIdx = bodyLength; + } + + int searchIdx = actual.toLowerCase().indexOf(search.toLowerCase(), + startIdx); + + LOGGER.debug("[ServletTestUtil] Scanning response for search string: '{}' starting at index " + "location: {}", + search , startIdx); + if (searchIdx < 0) { + found = false; + StringBuffer sb = new StringBuffer(255); + sb.append("[ServletTestUtil] Unable to find the following search string in the server's response: '") + .append(search).append("' at index: ") + .append(startIdx) + .append("\n[ServletTestUtil] Server's response:\n") + .append("-------------------------------------------\n") + .append(actual) + .append("\n-------------------------------------------\n"); + LOGGER.debug(sb.toString()); + break; + } + + LOGGER.debug("[ServletTestUtil] Found search string: '{}' at index '{}' in the server's response", + search, searchIdx); + // the new searchIdx is the old index plus the lenght of the + // search string. + startIdx = searchIdx + search.length(); + } + return found; + } + + /** + * Returns the provided String array in the following format: + * [n1,n2,n...] + * + * @param sArray + * - an array of Objects + * @return - a String based off the values in the array + */ + public static String getAsString(Object[] sArray) { + return sArray == null ? null : Stream.of(sArray).map(Object::toString).collect(Collectors.joining(",","[","]")); + + } + + public static String getAsString(List al) { + return al == null ? null : al.stream().collect(Collectors.joining(",","[","]")); + + } + + /** + * Returns the provided Enumeration as a String in the following format: + * [n1,n2,n...] + * + * @param e + * - an Enumeration + * @return - a printable version of the contents of the Enumeration + */ + public static String getAsString(Enumeration e) { + return getAsString(getAsArray(e)); + } + + /** + * Returnes the provides Enumeration as an Array of String Arguments. + * + * @param e + * - an Enumeration + * @return - the elements of the Enumeration as an array of Objects + */ + public static Object[] getAsArray(Enumeration e) { + List list = new ArrayList<>(); + while (e.hasMoreElements()) { + list.add(e.nextElement()); + } + return list.toArray(new Object[0]); + } + + /** + * Returnes the provided string as an Array of Strings. + * + * @param value String + * @return - the elements of the String as an array of Strings + */ + public static String[] getAsArray(String value) { + StringTokenizer st = new StringTokenizer(value, ","); + String[] retValues = new String[st.countTokens()]; + for (int i = 0; st.hasMoreTokens(); i++) { + retValues[i] = st.nextToken(); + } + return retValues; + } + + public static void printResult(PrintWriter pw, String s) { + + // if string is null or empty, then it passed + if (s == null || s.equals("")) { + pw.println(Data.PASSED); + } else { + pw.println(Data.FAILED + ": " + s); + } + } + + public static void printResult(PrintWriter pw, boolean b) { + if (b) { + pw.println(Data.PASSED); + } else { + pw.println(Data.FAILED); + } + } + + public static void printResult(ServletOutputStream pw, boolean b) + throws IOException { + if (b) { + pw.println(Data.PASSED); + } else { + pw.println(Data.FAILED); + } + } + + public static void printFailureData(PrintWriter pw, ArrayList result, + Object[] expected) { + pw.println("Unable to find the expected values:\n " + " " + + ServletTestUtil.getAsString(expected) + + "\nin the results returned by the test which were:\n" + " " + + ServletTestUtil.getAsString(result)); + } + + public static void printFailureData(PrintWriter pw, Enumeration result, + Object[] expected) { + pw.println("Unable to find the expected values:\n " + " " + + ServletTestUtil.getAsString(expected) + + "\nin the results returned by the test which were:\n" + " " + + ServletTestUtil.getAsString(result)); + } + + public static int findCookie(Cookie[] cookie, String name) { + boolean found = false; + int i = 0; + if (cookie != null) { + while ((!found) && (i < cookie.length)) { + if (cookie[i].getName().equals(name)) { + found = true; + } else { + i++; + } + } + } else { + found = false; + } + if (found) { + return i; + } else { + return -1; + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/util/StaticLog.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/util/StaticLog.java new file mode 100644 index 0000000000..8575b9e1e6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/common/util/StaticLog.java @@ -0,0 +1,106 @@ +/* +* +* The Apache Software License, Version 1.1 +* +* Copyright (c) 2007, 2018 Oracle and/or its affiliates. All rights reserved. +* Copyright (c) 1999-2001 The Apache Software Foundation. All rights +* reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in +* the documentation and/or other materials provided with the +* distribution. +* +* 3. The end-user documentation included with the redistribution, if +* any, must include the following acknowlegement: +* "This product includes software developed by the +* Apache Software Foundation (http://www.apache.org/)." +* Alternately, this acknowlegement may appear in the software itself, +* if and wherever such third-party acknowlegements normally appear. +* +* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software +* Foundation" must not be used to endorse or promote products derived +* from this software without prior written permission. For written +* permission, please contact apache@apache.org. +* +* 5. Products derived from this software may not be called "Apache" +* nor may "Apache" appear in their names without prior written +* permission of the Apache Group. +* +* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR +* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF +* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT +* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +* SUCH DAMAGE. +* ==================================================================== +* +* This software consists of voluntary contributions made by many +* individuals on behalf of the Apache Software Foundation. For more +* information on the Apache Software Foundation, please see +* . +* +*/ + +package com.sun.ts.tests.servlet.common.util; + +import java.util.ArrayList; +import java.util.List; + +public final class StaticLog { + + private static List al = new ArrayList<>(); + + public static void clear() { + al.clear(); + if (!al.isEmpty()) { + // we'll try one more time + al.clear(); + if (!al.isEmpty()) { + System.out.println( + "ERROR: The StaticLog could not be clear after 2 attempts"); + } + } else { + // System.out.println("log is clear"); + } + + } + + public static void add(String s) { + // System.out.println("Adding the following item to the log:"+s); + al.add(s); + } + + public static ArrayList getClear() { + /* + * Object[] o = al.toArray(); for (int i = 0;i + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/compat/LeadingSlash/WithLeadingSlash/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/compat/LeadingSlash/WithLeadingSlash/URLClient.java new file mode 100644 index 0000000000..c413236c6f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/compat/LeadingSlash/WithLeadingSlash/URLClient.java @@ -0,0 +1,68 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.compat.LeadingSlash.WithLeadingSlash; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_compat_LeadingSlash_With_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClass(WithLeadingSlashTestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_compat_LeadingSlash_With_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: WithLeadingSlashTest + * + * @assertion: A 2.2 web application deployment descriptor who's url mapping + * begins with a "/" can be deployed in a 2.3 environment, specified in the + * Java Servlet Pages Specification v2.3, Sec 11 + * + * @test_Strategy: The DD url-pattern has a "/" at the beginning of the + * string. The web app should deploy and be able to be called by a client + * + */ + @Test + public void WithLeadingSlashTest() throws Exception { + TEST_PROPS.setProperty(STANDARD, "WithLeadingSlashTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/compat/LeadingSlash/WithLeadingSlash/WithLeadingSlashTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/compat/LeadingSlash/WithLeadingSlash/WithLeadingSlashTestServlet.java new file mode 100644 index 0000000000..91532dcc35 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/compat/LeadingSlash/WithLeadingSlash/WithLeadingSlashTestServlet.java @@ -0,0 +1,78 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.compat.LeadingSlash.WithLeadingSlash; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class WithLeadingSlashTestServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter out = response.getWriter(); + out.println("WithLeadingSlashTest test PASSED"); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/compat/LeadingSlash/WithLeadingSlash/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/compat/LeadingSlash/WithLeadingSlash/build.xml new file mode 100644 index 0000000000..7d93fd6bb9 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/compat/LeadingSlash/WithLeadingSlash/build.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/compat/LeadingSlash/WithLeadingSlash/servlet_compat_LeadingSlash_With_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/compat/LeadingSlash/WithLeadingSlash/servlet_compat_LeadingSlash_With_web.xml new file mode 100644 index 0000000000..09964dc3fa --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/compat/LeadingSlash/WithLeadingSlash/servlet_compat_LeadingSlash_With_web.xml @@ -0,0 +1,39 @@ + + + + + + SerCompatLeadingSlashWith + no description + + WithLeadingSlashTestLogicalName + WithLeadingSlashTest + no description + com.sun.ts.tests.servlet.compat.LeadingSlash.WithLeadingSlash.WithLeadingSlashTestServlet + 0 + + + WithLeadingSlashTestLogicalName + /WithLeadingSlashTest + + + 54 + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/compat/LeadingSlash/WithoutLeadingSlash/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/compat/LeadingSlash/WithoutLeadingSlash/URLClient.java new file mode 100644 index 0000000000..e8db1bf613 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/compat/LeadingSlash/WithoutLeadingSlash/URLClient.java @@ -0,0 +1,70 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.compat.LeadingSlash.WithoutLeadingSlash; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + // TOFIX setGeneralURI("/servlet/compat/LeadingSlash/WithoutLeadingSlash"); + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_compat_LeadingSlash_Without_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClass(WithoutLeadingSlashTestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_compat_LeadingSlash_Without_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: WithoutLeadingSlashTest + * + * @assertion: A 2.2 web application deployment descriptor who's url mapping + * does not begin with a "/" can be deployed in a 2.3 environment, specified + * in the Java Servlet Pages Specification v2.3, Sec 11 + * + * @test_Strategy: The DD url-pattern has a "/" at the beginning of the + * string. The web app should deploy and be able to be called by a client + * + */ + @Test + public void WithoutLeadingSlashTest() throws Exception { + TEST_PROPS.setProperty(STANDARD, "WithoutLeadingSlashTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/compat/LeadingSlash/WithoutLeadingSlash/WithoutLeadingSlashTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/compat/LeadingSlash/WithoutLeadingSlash/WithoutLeadingSlashTestServlet.java new file mode 100644 index 0000000000..3058410d2d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/compat/LeadingSlash/WithoutLeadingSlash/WithoutLeadingSlashTestServlet.java @@ -0,0 +1,78 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.compat.LeadingSlash.WithoutLeadingSlash; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class WithoutLeadingSlashTestServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + PrintWriter out = response.getWriter(); + out.println("WithoutLeadingSlashTest test PASSED"); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/compat/LeadingSlash/WithoutLeadingSlash/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/compat/LeadingSlash/WithoutLeadingSlash/build.xml new file mode 100644 index 0000000000..1e51df7650 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/compat/LeadingSlash/WithoutLeadingSlash/build.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/compat/LeadingSlash/WithoutLeadingSlash/servlet_compat_LeadingSlash_Without_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/compat/LeadingSlash/WithoutLeadingSlash/servlet_compat_LeadingSlash_Without_web.xml new file mode 100644 index 0000000000..cfdea813da --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/compat/LeadingSlash/WithoutLeadingSlash/servlet_compat_LeadingSlash_Without_web.xml @@ -0,0 +1,39 @@ + + + + + + SerCompatLeadingSlashWithout + no description + + WithoutLeadingSlashTestLogicalName + WithoutLeadingSlashTest + no description + com.sun.ts.tests.servlet.compat.LeadingSlash.WithoutLeadingSlash.WithoutLeadingSlashTestServlet + 0 + + + WithoutLeadingSlashTestLogicalName + WithoutLeadingSlashTest + + + 54 + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/compat/LeadingSlash/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/compat/LeadingSlash/build.xml new file mode 100644 index 0000000000..bdec5e4eb1 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/compat/LeadingSlash/build.xml @@ -0,0 +1,22 @@ + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/compat/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/compat/build.xml new file mode 100644 index 0000000000..134291acbd --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/compat/build.xml @@ -0,0 +1,22 @@ + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/ee/platform/cdi/filter/beans.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/ee/platform/cdi/filter/beans.xml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/ee/platform/cdi/listener/beans.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/ee/platform/cdi/listener/beans.xml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/ee/platform/cdi/servlet/beans.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/ee/platform/cdi/servlet/beans.xml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/ee/spec/crosscontext/application.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/ee/spec/crosscontext/application.xml new file mode 100644 index 0000000000..0718961c1a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/ee/spec/crosscontext/application.xml @@ -0,0 +1,35 @@ + + + + + Application description + servlet_ee_spec_crosscontext + + + servlet_ee_spec_crosscontext1_web.war + servlet_ee_spec_crosscontext1_web + + + + + servlet_ee_spec_crosscontext2_web.war + servlet_ee_spec_crosscontext2_web + + + \ No newline at end of file diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/ee/spec/security/permissiondd/permissions.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/ee/spec/security/permissiondd/permissions.xml new file mode 100644 index 0000000000..01b2fe8771 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/ee/spec/security/permissiondd/permissions.xml @@ -0,0 +1,60 @@ + + + + + + java.security.SecurityPermission + CTSPermission1_name + + + java.security.SecurityPermission + CTSPermission2_name + + + java.security.SecurityPermission + CTSPermission_second_name + + + java.lang.RuntimePermission + loadLibrary.* + + + java.lang.RuntimePermission + queuePrintJob + + + java.net.SocketPermission + * + connect + + + java.io.FilePermission + * + read + + + java.util.PropertyPermission + TestPropertyPerm + read + + \ No newline at end of file diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/ee/spec/security/runAs/application.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/ee/spec/security/runAs/application.xml new file mode 100644 index 0000000000..eb0005bae3 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/ee/spec/security/runAs/application.xml @@ -0,0 +1,46 @@ + + + + + servlet_ee_spec_security_runAs + + servlet_ee_spec_security_runAs_client.jar + + + servlet_ee_spec_security_runAs_ejb.jar + + + + servlet_ee_spec_security_runAs_second_module_web.war + second_module_cntxt_root + + + + + servlet_ee_spec_security_runAs_first_module_web.war + first_module_cntxt_root + + + + Manager + + + Administrator + + \ No newline at end of file diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering/URLClient.java new file mode 100644 index 0000000000..04da68f826 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering/URLClient.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2009, 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$ + */ +package com.sun.ts.tests.servlet.pluggability.aordering; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.pluggability.common.CommonArchives; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + + return ShrinkWrap.create(WebArchive.class, "servlet_spec_aordering_web.war") + .addClasses(TestServlet1.class, RequestListener.class) + .addAsLibraries(CommonArchives.getCommonWebFragmentArchives()) + .addAsResource("com/sun/ts/tests/servlet/pluggability/common/web-fragment_3.xml", + "META-INF/web-fragment.xml") + .addAsResource("com/sun/ts/tests/servlet/pluggability/common/web-fragment_4.xml", + "META-INF/web-fragment.xml") + .addAsResource("com/sun/ts/tests/servlet/pluggability/common/web-fragment_5.xml", + "META-INF/web-fragment.xml") + .setWebXML(URLClient.class.getResource("servlet_spec_aordering_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* + * @testName: absoluteOrderingTest + * + * @assertion_ids: Servlet:SPEC:230; Servlet:SPEC:231; Servlet:SPEC:232; + * + * @test_Strategy: 1. Define six RequestListeners and one servlet, in web.xml + * and six web-fragment.xml: web.xml - define and package TestServlet1, + * RequestListener, with of all fragments: fragment1 - + * define and package TestServlet1, RequestListener1, fragment2 - define and + * package RequestListener2 fragment3 - define and package RequestListener3, + * fragment4 - define and package RequestListener4, fragment5 - define and + * package RequestListener5, 2. Send request to TestServlet1 3. Verify that + * web.xml is always processed first; 4. Verify that works + * accordingly. + */ + @Test + public void absoluteOrderingTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, + "msg1=first|msg2=second|" + "RequestListener|RequestListener1|" + + "RequestListener2|RequestListener3|" + + "RequestListener4|RequestListener5"); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/TestServlet1" + " HTTP/1.1"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering/build.xml new file mode 100644 index 0000000000..45af1c659c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering/build.xml @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering/servlet_spec_aordering_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering/servlet_spec_aordering_web.xml new file mode 100644 index 0000000000..ebf26d0e6b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering/servlet_spec_aordering_web.xml @@ -0,0 +1,54 @@ + + + + + SerSpecFragment + + Fragment1 + Fragment2 + Fragment3 + Fragment4 + Fragment5 + + + TestServlet1 + com.sun.ts.tests.servlet.pluggability.common.TestServlet1 + + msg1 + first + + + msg1 + ignore + + + + TestServlet1 + /TestServlet1 + + + com.sun.ts.tests.servlet.pluggability.common.RequestListener + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering1/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering1/URLClient.java new file mode 100644 index 0000000000..07762ab43e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering1/URLClient.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.pluggability.aordering1; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.pluggability.common.CommonArchives; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_spec_aordering1_web.war") + .addAsLibraries(CommonArchives.getCommonWebFragmentArchives()) + .addClasses(TestServlet1.class, RequestListener.class) + .setWebXML(URLClient.class.getResource("servlet_spec_aordering1_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* + * @testName: absoluteOrderingTest + * + * @assertion_ids: Servlet:SPEC:230; Servlet:SPEC:231; Servlet:SPEC:232; + * Servlet:SPEC:233; + * + * @test_Strategy: 1. Define six RequestListeners and one servlet, in web.xml + * and six web-fragment.xml: web.xml - define and package TestServlet1, + * RequestListener, with of all fragments: fragment1 - + * define and package TestServlet1, RequestListener1, fragment2 - define and + * package RequestListener2 fragment3 - define and package RequestListener3, + * fragment4 - define and package RequestListener4, fragment5 - define and + * package RequestListener5, 2. Also add a fragment that is not present in + * ; 3. Send request to TestServlet1 4. Verify that web.xml + * is always processed first; 5. Verify that works + * accordingly: 6. Verify that not present fragment in is + * ignored. + */ + @Test + public void absoluteOrderingTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, + "msg1=first|msg2=second|" + "RequestListener|RequestListener1|" + + "RequestListener2|RequestListener3|" + + "RequestListener4|RequestListener5"); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/TestServlet1" + " HTTP/1.1"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering1/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering1/build.xml new file mode 100644 index 0000000000..a55f234e3f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering1/build.xml @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering1/servlet_spec_aordering1_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering1/servlet_spec_aordering1_web.xml new file mode 100644 index 0000000000..be9417af6d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering1/servlet_spec_aordering1_web.xml @@ -0,0 +1,55 @@ + + + + + SerSpecFragment1 + + Fragment1 + Fragment2 + Fragment3 + FragmentNonExisit + Fragment4 + Fragment5 + + + TestServlet1 + com.sun.ts.tests.servlet.pluggability.common.TestServlet1 + + msg1 + first + + + msg1 + ignore + + + + TestServlet1 + /TestServlet1 + + + com.sun.ts.tests.servlet.pluggability.common.RequestListener + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering2/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering2/URLClient.java new file mode 100644 index 0000000000..6cfe20663b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering2/URLClient.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.pluggability.aordering2; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.pluggability.common.CommonArchives; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener5; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener6; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive6 = ShrinkWrap.create(JavaArchive.class, "fragment-6.jar") + .addAsResource("com/sun/ts/tests/servlet/pluggability/common/web-fragment_6.xml", + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_spec_aordering2_web.war") + .addAsLibraries(CommonArchives.getCommonWebFragmentArchives()) + .addAsLibraries(javaArchive6) + .addClasses(TestServlet1.class, RequestListener.class) + .setWebXML(URLClient.class.getResource("servlet_spec_aordering2_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* + * @testName: absoluteOrderingTest + * + * @assertion_ids: Servlet:SPEC:230; Servlet:SPEC:231; Servlet:SPEC:232; + * Servlet:SPEC:233; Servlet:SPEC:235; + * + * @test_Strategy: 1. Define seven RequestListeners and two servlets, in + * web.xml and seven web-fragment.xml: web.xml - define and package + * TestServlet1, RequestListener, with absolute-ordering of six fragments: + * fragment1 - define and package TestServlet1, RequestListener1, fragment2 - + * define and package RequestListener2 fragment3 - define and package + * RequestListener3, fragment4 - define and package RequestListener4, + * fragment5 - define and package RequestListener5, 2. fragment6 (no ) + * defines and packages TestServlet2, RequestListener6 3. Send request to + * TestServlet1 4. Verify that web.xml is always processed first; 5. Verify + * that works accordingly: 6. Verify that fragment6 with + * no , is ignored. + */ + @Test + public void absoluteOrderingTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, + "msg1=first|msg2=second|" + "RequestListener|RequestListener1|" + + "RequestListener2|RequestListener3|" + + "RequestListener4|RequestListener5"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, + "RequestListener6|TestServlet2"); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/TestServlet1" + " HTTP/1.1"); + invoke(); + + TEST_PROPS.setProperty(STATUS_CODE, NOT_FOUND); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/TestServlet2" + " HTTP/1.1"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering2/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering2/build.xml new file mode 100644 index 0000000000..5054027115 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering2/build.xml @@ -0,0 +1,108 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering2/servlet_spec_aordering2_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering2/servlet_spec_aordering2_web.xml new file mode 100644 index 0000000000..247663dd48 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering2/servlet_spec_aordering2_web.xml @@ -0,0 +1,55 @@ + + + + + SerSpecFragment2 + + Fragment1 + Fragment2 + Fragment3 + FragmentNonExisit + Fragment4 + Fragment5 + + + TestServlet1 + com.sun.ts.tests.servlet.pluggability.common.TestServlet1 + + msg1 + first + + + msg1 + ignore + + + + TestServlet1 + /TestServlet1 + + + com.sun.ts.tests.servlet.pluggability.common.RequestListener + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering3/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering3/URLClient.java new file mode 100644 index 0000000000..973d291eb7 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering3/URLClient.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.pluggability.aordering3; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.pluggability.common.CommonArchives; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener6; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive6 = ShrinkWrap.create(JavaArchive.class, "fragment-6.jar") + .addClasses(RequestListener6.class, TestServlet1.class) + .addAsResource("com/sun/ts/tests/servlet/pluggability/common/web-fragment_6.xml", + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_spec_aordering3_web.war") + .addAsLibraries(CommonArchives.getCommonWebFragmentArchives()) + .addAsLibraries(javaArchive6) + .addClasses(RequestListener.class, TestServlet1.class) + .setWebXML(URLClient.class.getResource("servlet_spec_aordering3_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* + * @testName: absoluteOrderingTest + * + * @assertion_ids: Servlet:SPEC:230; Servlet:SPEC:231; Servlet:SPEC:232; + * Servlet:SPEC:233; Servlet:SPEC:235; + * + * @test_Strategy: 1. Define seven RequestListeners and two servlets, in + * web.xml and seven web-fragment.xml: web.xml - define and package + * TestServlet1, RequestListener, with of no fragments 2. + * seven fragments: fragment1 - define and package TestServlet1, + * RequestListener1, fragment2 - define and package RequestListener2 fragment3 + * - define and package RequestListener3, fragment4 - define and package + * RequestListener4, fragment5 - define and package RequestListener5, + * fragment6 (no ) defines and packages TestServlet2, RequestListener6 + * 3. Send request to TestServlet1 4. Verify that web.xml is processed; 5. + * Verify that works accordingly when empty, that all + * fragnments are ignored. + */ + @Test + public void absoluteOrderingTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "msg1=first|RequestListener"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, + "msg2=second|TestServlet2|" + + "RequestListener1|RequestListener2|RequestListener3|" + + "RequestListener4|RequestListener5|RequestListener6"); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/TestServlet1" + " HTTP/1.1"); + invoke(); + + TEST_PROPS.setProperty(STATUS_CODE, NOT_FOUND); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/TestServlet2" + " HTTP/1.1"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering3/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering3/build.xml new file mode 100644 index 0000000000..fa9b841020 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering3/build.xml @@ -0,0 +1,107 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering3/servlet_spec_aordering3_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering3/servlet_spec_aordering3_web.xml new file mode 100644 index 0000000000..a3878cf5e1 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering3/servlet_spec_aordering3_web.xml @@ -0,0 +1,48 @@ + + + + + SerSpecFragment3 + + + TestServlet1 + com.sun.ts.tests.servlet.pluggability.common.TestServlet1 + + msg1 + first + + + msg1 + ignore + + + + TestServlet1 + /TestServlet1 + + + com.sun.ts.tests.servlet.pluggability.common.RequestListener + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering4/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering4/URLClient.java new file mode 100644 index 0000000000..b55d06b2fb --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering4/URLClient.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.pluggability.aordering4; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.pluggability.common.CommonArchives; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener6; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener7; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet3; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive6 = ShrinkWrap.create(JavaArchive.class, "fragment-6.jar") + .addClasses(RequestListener6.class, TestServlet1.class) + .addAsResource("com/sun/ts/tests/servlet/pluggability/common/web-fragment_6.xml", + "META-INF/web-fragment.xml"); + JavaArchive javaArchive7 = ShrinkWrap.create(JavaArchive.class, "fragment-7.jar") + .addClasses(RequestListener7.class, TestServlet3.class) + .addAsResource("com/sun/ts/tests/servlet/pluggability/common/web-fragment_7.xml", + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_spec_aordering4_web.war") + .addAsLibraries(CommonArchives.getCommonWebFragmentArchives()) + .addAsLibraries(javaArchive6, javaArchive7) + .addClasses(RequestListener.class, TestServlet1.class) + .setWebXML(URLClient.class.getResource("servlet_spec_aordering4_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* + * @testName: absoluteOrderingTest + * + * @assertion_ids: Servlet:SPEC:230; Servlet:SPEC:231; Servlet:SPEC:232; + * Servlet:SPEC:233; Servlet:SPEC:235; Servlet:SPEC:236; + * + * @test_Strategy: 1. Define eight RequestListeners and three servlets, in + * web.xml and seven web-fragment.xml: web.xml - define and package + * TestServlet1, RequestListener, with of six fragments: + * fragment1 - define and package TestServlet1, RequestListener1, fragment2 - + * define and package RequestListener2 fragment3 - define and package + * RequestListener3, fragment4 - define and package RequestListener4, + * fragment5 - define and package RequestListener5, 2. fragment6 (no ) + * defines and packages TestServlet2, RequestListener6; fragment7 - defines + * TestServlet2, packages TestServlet3 and RequestListener7; both TestServlet3 + * and RequestListener7 are annotated; 3. Send request to TestServlet1 4. + * Verify that web.xml is always processed first; 5. Verify that + * works accordingly: that fragment6 with no is + * ignored; that fragment7 is not scanned for annotation. + */ + @Test + public void absoluteOrderingTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, + "msg1=first|msg2=second|" + "RequestListener|RequestListener1|" + + "RequestListener2|RequestListener3|" + + "RequestListener4|RequestListener5"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, + "RequestListener6|TestServlet2|RequestListener7|TestServlet3"); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/TestServlet1" + " HTTP/1.1"); + invoke(); + + TEST_PROPS.setProperty(STATUS_CODE, NOT_FOUND); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/TestServlet2" + " HTTP/1.1"); + invoke(); + + TEST_PROPS.setProperty(STATUS_CODE, NOT_FOUND); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/TestServlet3" + " HTTP/1.1"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering4/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering4/build.xml new file mode 100644 index 0000000000..128a387ff0 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering4/build.xml @@ -0,0 +1,116 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering4/servlet_spec_aordering4_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering4/servlet_spec_aordering4_web.xml new file mode 100644 index 0000000000..1a74165761 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/aordering4/servlet_spec_aordering4_web.xml @@ -0,0 +1,55 @@ + + + + + SerSpecFragment4 + + Fragment1 + Fragment2 + Fragment3 + FragmentNonExisit + Fragment4 + Fragment5 + + + TestServlet1 + com.sun.ts.tests.servlet.pluggability.common.TestServlet1 + + msg1 + first + + + msg1 + ignore + + + + TestServlet1 + /TestServlet1 + + + com.sun.ts.tests.servlet.pluggability.common.RequestListener + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/build.xml new file mode 100644 index 0000000000..aea09a5913 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/build.xml @@ -0,0 +1,22 @@ + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/asynccontext/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/asynccontext/URLClient.java new file mode 100644 index 0000000000..056cb4f9cd --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/asynccontext/URLClient.java @@ -0,0 +1,338 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet.asynccontext; + +import com.sun.ts.tests.servlet.api.jakarta_servlet.asynccontext.AsyncTestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.asynccontext.AsyncTests; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.api.jakarta_servlet.asynccontext.ResponseWrapper; +import com.sun.ts.tests.servlet.api.jakarta_servlet.asynccontext.RequestWrapper; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import com.sun.ts.tests.servlet.api.jakarta_servlet.asynccontext.ACListener2; +import com.sun.ts.tests.servlet.api.jakarta_servlet.asynccontext.ACListenerBad; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("AsyncTestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_plu_asynccontext_web-fragment.xml"), + "META-INF/web-fragment.xml"); + + return ShrinkWrap.create(WebArchive.class, "asynccontext_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(AsyncTestServlet.class, AsyncTests.class, ResponseWrapper.class, RequestWrapper.class, + ACListener2.class, ACListenerBad.class) + .addAsLibraries(javaArchive); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + /* + * Test set up: + * + * Define two servets AsyncTestServlet and AsyncTests that supports async in + * web.xml; Define three AsyncListeners using annotation: ACListener, + * ACListener1, ACListenerBad; - ACListener1 does not complete properly - + * ACListenerBad does not instantiate; Define a ServletRequestWrapper that + * wraps the original request; Define a ServletResponseWrapper that wraps the + * original response; + * + */ + + /* + * @testName: dispatchZeroArgTest + * + * @assertion_ids: Servlet:JAVADOC:639; Servlet:JAVADOC:639.2; + * Servlet:JAVADOC:639.4; Servlet:JAVADOC:703; Servlet:JAVADOC:707; + * Servlet:JAVADOC:708; Servlet:JAVADOC:710; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which supports async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet + * ServletRequest.startAsync(); call ac.dispatch(); call + * ServletRequest.isAsyncSupported() call ServletRequest.isAsyncStarted() call + * ServletRequest.getDispatcherType() verifies all work accordingly. + */ + @Test + public void dispatchZeroArgTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "dispatchZeroArgTest"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_dispatchZeroArgTest|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "ASYNC_STARTED_dispatchZeroArgTest|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: dispatchZeroArgTest1 + * + * @assertion_ids: Servlet:JAVADOC:639; Servlet:JAVADOC:639.2; + * Servlet:JAVADOC:639.4; Servlet:JAVADOC:703; Servlet:JAVADOC:707; + * Servlet:JAVADOC:708; Servlet:JAVADOC:710; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which supports async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet + * ServletRequest.startAsync(); call ac.dispatch(); call + * ServletRequest.isAsyncSupported() call ServletRequest.isAsyncStarted() call + * ServletRequest.getDispatcherType() verifies all work accordingly. + */ + @Test + public void dispatchZeroArgTest1() throws Exception { + TEST_PROPS.setProperty(APITEST, "dispatchZeroArgTest"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_dispatchZeroArgTest|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "ASYNC_STARTED_dispatchZeroArgTest|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: dispatchContextPathTest + * + * @assertion_ids: Servlet:JAVADOC:641; Servlet:JAVADOC:703; + * Servlet:JAVADOC:707; Servlet:JAVADOC:708; Servlet:JAVADOC:710; + * + * @test_Strategy: Create two Servlets AsyncTestServlet and AsynTest both + * support async; Client send a request to AsyncTestServlet; StartAsync in + * AsyncTestServlet ServletRequest.startAsync(); call + * ac.dispatch(ServltContext, path to AsynTest); call + * ServletRequest.isAsyncSupported() call ServletRequest.isAsyncStarted() call + * ServletRequest.getDispatcherType() verifies all work accordingly. + */ + @Test + public void dispatchContextPathTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "dispatchContextPathTest"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ASYNC_NOT_STARTED_dispatchContextPathTest|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=REQUEST|" + + "ASYNC_STARTED_asyncTest|" + "IsAsyncSupported=true|" + + "IsAsyncStarted=false|" + "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: getRequestTest + * + * @assertion_ids: Servlet:JAVADOC:642; Servlet:JAVADOC:710; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet + * ServletRequest.startAsync(); call ac.getRequest() verifies it works. + */ + @Test + public void getRequestTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getRequestTest"); + invoke(); + } + + /* + * @testName: asyncListenerTest1 + * + * @assertion_ids: Servlet:JAVADOC:649; Servlet:JAVADOC:710; + * Servlet:JAVADOC:846; Servlet:JAVADOC:866; Servlet:JAVADOC:873; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Create an AsyncListenerBad; Client send a request to AsyncTestServlet; + * StartAsync in AsyncTestServlet; AsyncContext.createistener(clazz) verifies + * ServletException is thrown when clazz fails to be instantiated. + */ + @Test + public void asyncListenerTest1() throws Exception { + TEST_PROPS.setProperty(APITEST, "asyncListenerTest1"); + invoke(); + } + + /* + * @testName: timeOutTest + * + * @assertion_ids: Servlet:JAVADOC:649; Servlet:JAVADOC:710; + * Servlet:JAVADOC:846; Servlet:JAVADOC:868; Servlet:JAVADOC:869; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet; + * AsyncContext.setTimeout(L) verifies it works using getTimeout. + */ + @Test + public void timeOutTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "timeOutTest"); + invoke(); + } + + /* + * @testName: timeOutTest1 + * + * @assertion_ids: Servlet:JAVADOC:649; Servlet:JAVADOC:710; + * Servlet:JAVADOC:846; Servlet:JAVADOC:868; Servlet:JAVADOC:868.1; + * Servlet:JAVADOC:869; Servlet:JAVADOC:869.3; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet; + * AsyncContext.setTimeout(0L) verifies it works using getTimeout. + */ + @Test + public void timeOutTest1() throws Exception { + TEST_PROPS.setProperty(APITEST, "timeOutTest1"); + invoke(); + } + + /* + * @testName: timeOutTest2 + * + * @assertion_ids: Servlet:JAVADOC:651; Servlet:JAVADOC:710; + * Servlet:JAVADOC:846; Servlet:JAVADOC:868; Servlet:JAVADOC:869; + * Servlet:JAVADOC:869.1; Servlet:JAVADOC:869.2; Servlet:JAVADOC:869.5; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet; + * AsyncContext.setTimeout(L) verifies it works by letting it timeout. + */ + @Test + public void timeOutTest2() throws Exception { + TEST_PROPS.setProperty(APITEST, "timeOutTest2"); + TEST_PROPS.setProperty(SEARCH_STRING, "in onTimeout method of ACListener2"); + TEST_PROPS.setProperty(STATUS_CODE, "-1"); + invoke(); + } + + /* + * @testName: timeOutTest4 + * + * @assertion_ids: Servlet:JAVADOC:651; Servlet:JAVADOC:710; + * Servlet:JAVADOC:846; Servlet:JAVADOC:868; Servlet:JAVADOC:869.4; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet; + * verifies it times out at default timeout. + */ + @Test + public void timeOutTest4() throws Exception { + TEST_PROPS.setProperty(APITEST, "timeOutTest4"); + TEST_PROPS.setProperty(SEARCH_STRING, "in onTimeout method of ACListener2"); + TEST_PROPS.setProperty(STATUS_CODE, "-1"); + invoke(); + } + + /* + * @testName: originalRequestTest + * + * @assertion_ids: Servlet:JAVADOC:638; Servlet:JAVADOC:644; + * Servlet:JAVADOC:710; Servlet:JAVADOC:710.2; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; Call ServletRequest.startAsync() + * in AsyncTestServlet; verifies AsyncContext.hasOriginalRequestAndResponse + * works. + */ + @Test + public void originalRequestTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "originalRequestTest"); + invoke(); + } + + /* + * @testName: originalRequestTest1 + * + * @assertion_ids: Servlet:JAVADOC:638; Servlet:JAVADOC:644; + * Servlet:JAVADOC:712; Servlet:JAVADOC:712.1; Servlet:JAVADOC:712.3; * + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; Call + * ServletRequest.startAsync(ServletRequest, ServletResponse); verifies + * AsyncContext.hasOriginalRequestAndResponse works. + */ + @Test + public void originalRequestTest1() throws Exception { + TEST_PROPS.setProperty(APITEST, "originalRequestTest1"); + invoke(); + } + + /* + * @testName: originalRequestTest2 + * + * @assertion_ids: Servlet:JAVADOC:638; Servlet:JAVADOC:644; + * Servlet:JAVADOC:712; Servlet:JAVADOC:712.1; Servlet:JAVADOC:712.3; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; Call + * ServletRequest.startAsync(ServletRequestWrapper, ServletResponseWrapper); + * verifies AsyncContext.hasOriginalRequestAndResponse works. + */ + @Test + public void originalRequestTest2() throws Exception { + TEST_PROPS.setProperty(APITEST, "originalRequestTest2"); + invoke(); + } + + /* + * @testName: originalRequestTest3 + * + * @assertion_ids: Servlet:JAVADOC:638; Servlet:JAVADOC:644; + * Servlet:JAVADOC:712; Servlet:JAVADOC:712.1; Servlet:JAVADOC:712.3; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; Call + * ServletRequest.startAsync(ServletRequestWrapper, ServletResponse); verifies + * AsyncContext.hasOriginalRequestAndResponse works. + */ + @Test + public void originalRequestTest3() throws Exception { + TEST_PROPS.setProperty(APITEST, "originalRequestTest3"); + invoke(); + } + + /* + * @testName: originalRequestTest4 + * + * @assertion_ids: Servlet:JAVADOC:638; Servlet:JAVADOC:644; + * Servlet:JAVADOC:712; Servlet:JAVADOC:712.1; Servlet:JAVADOC:712.3; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which support async; + * Client send a request to AsyncTestServlet; Call + * ServletRequest.startAsync(ServletRequest, ServletResponseWrapper); verifies + * AsyncContext.hasOriginalRequestAndResponse works. + */ + @Test + public void originalRequestTest4() throws Exception { + TEST_PROPS.setProperty(APITEST, "originalRequestTest4"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/asynccontext/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/asynccontext/build.xml new file mode 100644 index 0000000000..da136b5f1b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/asynccontext/build.xml @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/asynccontext/servlet_plu_asynccontext_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/asynccontext/servlet_plu_asynccontext_web-fragment.xml new file mode 100644 index 0000000000..aa09ac0533 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/asynccontext/servlet_plu_asynccontext_web-fragment.xml @@ -0,0 +1,46 @@ + + + + + + AsyncTestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.asynccontext.AsyncTestServlet + true + + + AsyncTests + com.sun.ts.tests.servlet.api.jakarta_servlet.asynccontext.AsyncTests + true + + + AsyncTestServlet + /AsyncTestServlet + + + AsyncTests + /async/AsyncTests + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/asyncevent/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/asyncevent/URLClient.java new file mode 100644 index 0000000000..640661a47f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/asyncevent/URLClient.java @@ -0,0 +1,186 @@ +/* + * Copyright (c) 2012, 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 + */ + +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet.asyncevent; + +import com.sun.ts.tests.servlet.api.jakarta_servlet.asyncevent.AsyncTestServlet; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("AsyncTestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_plu_asyncevent_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_plu_asyncevent_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(AsyncTestServlet.class) + .addAsLibraries(javaArchive); + } + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + + /* + * @testName: constructorTest1 + * + * @assertion_ids: Servlet:JAVADOC:842; + * + * @test_Strategy: test the constructor AsyncEvent( AsyncContext ) + */ + @Test + public void constructorTest1() throws Exception { + TEST_PROPS.setProperty(APITEST, "constructorTest1"); + invoke(); + } + + /* + * @testName: constructorTest2 + * + * @assertion_ids: Servlet:JAVADOC:843; + * + * @test_Strategy: test the constructor AsyncEvent(AsyncContext, + * ServletRequest, ServletResponse) + */ + @Test + public void constructorTest2() throws Exception { + TEST_PROPS.setProperty(APITEST, "constructorTest2"); + invoke(); + } + + /* + * @testName: constructorTest3 + * + * @assertion_ids: Servlet:JAVADOC:844; + * + * @test_Strategy: test the constructor AsyncEvent(AsyncContext, Throwable) + */ + @Test + public void constructorTest3() throws Exception { + TEST_PROPS.setProperty(APITEST, "constructorTest3"); + invoke(); + } + + /* + * @testName: constructorTest4 + * + * @assertion_ids: Servlet:JAVADOC:845; + * + * @test_Strategy: test the constructor AsyncEvent(AsyncContext, + * ServletRequest, ServletResponse, Throwable) + */ + @Test + public void constructorTest4() throws Exception { + TEST_PROPS.setProperty(APITEST, "constructorTest4"); + invoke(); + } + + /* + * @testName: getSuppliedRequestTest1 + * + * @assertion_ids: Servlet:JAVADOC:847; + * + * @test_Strategy: test the constructor AsyncEvent(AsyncContext, + * ServletRequest, ServletResponse) verify AsyncEvent.getSuplliedRequest() + * works + */ + @Test + public void getSuppliedRequestTest1() throws Exception { + TEST_PROPS.setProperty(APITEST, "getSuppliedRequestTest1"); + invoke(); + } + + /* + * @testName: getSuppliedRequestTest2 + * + * @assertion_ids: Servlet:JAVADOC:847; + * + * @test_Strategy: test the constructor AsyncEvent(AsyncContext, + * ServletRequest, ServletResponse, Throwable) verify + * AsyncEvent.getSuplliedRequest() works + */ + @Test + public void getSuppliedRequestTest2() throws Exception { + TEST_PROPS.setProperty(APITEST, "getSuppliedRequestTest2"); + invoke(); + } + + /* + * @testName: getSuppliedResponseTest1 + * + * @assertion_ids: Servlet:JAVADOC:848; + * + * @test_Strategy: test the constructor AsyncEvent(AsyncContext, + * ServletRequest, ServletResponse) verify AsyncEvent.getSuplliedResponse() + * works + */ + @Test + public void getSuppliedResponseTest1() throws Exception { + TEST_PROPS.setProperty(APITEST, "getSuppliedResponseTest1"); + invoke(); + } + + /* + * @testName: getSuppliedResponseTest2 + * + * @assertion_ids: Servlet:JAVADOC:848; + * + * @test_Strategy: test the constructor AsyncEvent(AsyncContext, + * ServletRequest, ServletResponse, Throwable) verify + * AsyncEvent.getSuplliedResponse() works + */ + @Test + public void getSuppliedResponseTest2() throws Exception { + TEST_PROPS.setProperty(APITEST, "getSuppliedResponseTest2"); + invoke(); + } + + /* + * @testName: getThrowableTest + * + * @assertion_ids: Servlet:JAVADOC:849; + * + * @test_Strategy: test the constructor AsyncEvent(AsyncContext, + * ServletRequest, ServletResponse, Throwable) verify + * AsyncEvent.getThrowable() works + */ + @Test + public void getThrowableTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getThrowableTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/asyncevent/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/asyncevent/build.xml new file mode 100644 index 0000000000..2f5ddc1e1b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/asyncevent/build.xml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/asyncevent/servlet_plu_asyncevent_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/asyncevent/servlet_plu_asyncevent_web-fragment.xml new file mode 100644 index 0000000000..6427b75066 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/asyncevent/servlet_plu_asyncevent_web-fragment.xml @@ -0,0 +1,37 @@ + + + + + + AsyncTestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.asyncevent.AsyncTestServlet + true + + + AsyncTestServlet + /AsyncTestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/build.xml new file mode 100644 index 0000000000..7a76d3c694 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/build.xml @@ -0,0 +1,22 @@ + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/dispatchertype/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/dispatchertype/URLClient.java new file mode 100644 index 0000000000..cb9cdf4c8d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/dispatchertype/URLClient.java @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet.dispatchertype; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchertype.TestServlet; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_plu_dispatchertype_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_plu_dispatchertype_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClass(TestServlet.class) + .addAsLibraries(javaArchive); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + + /* + * @testName: valuesTest + * + * @assertion_ids: Servlet:JAVADOC:654; + * + * @test_Strategy: 1. Create a servlet - TestServlet 2. Client send a request + * to TestServlet 3. In TestServlet, call DispatcherType.values 4. Verify that + * DispatcherType.values works properly. + */ + @Test + public void valuesTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "valuesTest"); + invoke(); + } + + /* + * @testName: valueOfTest + * + * @assertion_ids: Servlet:JAVADOC:653; + * + * @test_Strategy: 1. Create a servlet - TestServlet 2. Client send a request + * to TestServlet 3. In TestServlet, call DispatcherType.valueOf 4. Verify + * that DispatcherType.valueOf works properly. + */ + @Test + public void valueOfTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "valueOfTest"); + invoke(); + } + /* + * @testName: valueOfNullTest + * + * @assertion_ids: Servlet:JAVADOC:653; + * + * @test_Strategy: 1. Create a servlet - TestServlet 2. Client send a request + * to TestServlet 3. In TestServlet, call DispatcherType.valueOf(String name) + * 4. Verify that DispatcherType.valueOf throws NullPointerException when name + * is null + */ + @Test + public void valueOfNullTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "valueOfNullTest"); + invoke(); + } + /* + * @testName: valueOfInvalidTest + * + * @assertion_ids: Servlet:JAVADOC:653; + * + * @test_Strategy: 1. Create a servlet - TestServlet 2. Client send a request + * to TestServlet 3. In TestServlet, call DispatcherType.valueOf(String name) + * 4. Verify that DispatcherType.valueOf throws IllegalArgumentException when + * name is invalid Dispatcher type + */ + @Test + public void valueOfInvalidTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "valueOfInvalidTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/dispatchertype/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/dispatchertype/build.xml new file mode 100644 index 0000000000..a965fd0dae --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/dispatchertype/build.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/dispatchertype/servlet_plu_dispatchertype_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/dispatchertype/servlet_plu_dispatchertype_web-fragment.xml new file mode 100644 index 0000000000..158d59eebf --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/dispatchertype/servlet_plu_dispatchertype_web-fragment.xml @@ -0,0 +1,36 @@ + + + + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.dispatchertype.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/dofilter/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/dofilter/URLClient.java new file mode 100644 index 0000000000..472f5bb89f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/dofilter/URLClient.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2001, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet.dofilter; + +import com.sun.ts.tests.servlet.api.jakarta_servlet.dofilter.CTSResponseWrapper; +import com.sun.ts.tests.servlet.api.jakarta_servlet.dofilter.ForwardedServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.dofilter.IncludedServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.dofilter.TestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.dofilter.WrapResponseFilter; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import com.sun.ts.tests.servlet.api.jakarta_servlet.dofilter.SetHeaderResponseFilter; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_plu_dofilter_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_plu_dofilter_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(SetHeaderResponseFilter.class, WrapResponseFilter.class, TestServlet.class, + IncludedServlet.class, ForwardedServlet.class, CTSResponseWrapper.class) + .addAsLibraries(javaArchive); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + + /* + * @testName: wrapResponseTest + * + * @assertion_ids: Servlet:SPEC:54; Servlet:SPEC:59; + * + * @test_Strategy: 1. Create two servlets - TestServlet, ForwardedServlet 2. + * Invoke ForwardedServlet using forward in TestServlet 3. Map a filter + * WrapResponseFilter with dispatcher value set to FORWARD 4. In the filter, + * wrap the response with custom implementation of ServletResponse + * CTSResponseWrapper 5. Verify that filter is properly invoked. + */ + @Test + public void wrapResponseTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "wrapResponseTest"); + TEST_PROPS.setProperty(SEARCH_STRING, + "CTSResponseWrapper|WrapResponseFilter|ForwardedServlet"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/dofilter/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/dofilter/build.xml new file mode 100644 index 0000000000..9efd2ec316 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/dofilter/build.xml @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/dofilter/servlet_plu_dofilter_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/dofilter/servlet_plu_dofilter_web-fragment.xml new file mode 100644 index 0000000000..a92d5324d7 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/dofilter/servlet_plu_dofilter_web-fragment.xml @@ -0,0 +1,78 @@ + + + + + + SetHeaderResponseFilter + com.sun.ts.tests.servlet.api.jakarta_servlet.dofilter.SetHeaderResponseFilter + + attribute + com.sun.ts.tests.servlet.api.jakarta_servlet.dofilter.SetHeaderResponseFilter.SERVLET_MAPPED + + + + ResponseWrapperFilter + com.sun.ts.tests.servlet.api.jakarta_servlet.dofilter.WrapResponseFilter + + attribute + com.sun.ts.tests.servlet.api.jakarta_servlet.dofilter.SetHeaderResponseFilter.SERVLET_MAPPED + + + + ResponseWrapperFilter + ForwardedServlet + FORWARD + + + SetHeaderResponseFilter + IncludedServlet + INCLUDE + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.dofilter.TestServlet + + + IncludedServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.dofilter.IncludedServlet + + + ForwardedServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.dofilter.ForwardedServlet + + + TestServlet + /TestServlet + + + IncludedServlet + /include/IncludedServlet + + + ForwardedServlet + /forward/ForwardedServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/filter/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/filter/URLClient.java new file mode 100644 index 0000000000..730fff9adc --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/filter/URLClient.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet.filter; + +import com.sun.ts.tests.servlet.api.jakarta_servlet.filter.DoFilterTestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.filter.DoFilter_Filter; +import com.sun.ts.tests.servlet.api.jakarta_servlet.filter.InitFilterConfigTestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.filter.InitFilter_Filter; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_plu_filter_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_plu_filter_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(DoFilter_Filter.class, InitFilter_Filter.class, DoFilterTestServlet.class, + InitFilterConfigTestServlet.class) + .addAsLibraries(javaArchive); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + /* + * @testName: doFilterTest + * + * @assertion_ids: Servlet:SPEC:58; Servlet:SPEC:48; Servlet:JAVADOC:293; + * + * @test_Strategy: Client attempts to access a servlet and the filter + * configured for that servlet should be invoked. + */ + @Test + public void doFilterTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "DoFilterTest"); + invoke(); + } + + /* + * @testName: initFilterConfigTest + * + * @assertion_ids: Servlet:SPEC:58; Servlet:SPEC:45; Servlet:JAVADOC:290; + * + * @test_Strategy: Client attempts to access a servlet and the filter + * configured for that servlet. + */ + @Test + public void initFilterConfigTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "InitFilterConfigTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/filter/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/filter/build.xml new file mode 100644 index 0000000000..0098446d9a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/filter/build.xml @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/filter/servlet_plu_filter_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/filter/servlet_plu_filter_web-fragment.xml new file mode 100644 index 0000000000..66390e310e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/filter/servlet_plu_filter_web-fragment.xml @@ -0,0 +1,68 @@ + + + + + + ServletMappedDoFilter_Filter + com.sun.ts.tests.servlet.api.jakarta_servlet.filter.DoFilter_Filter + + attribute + com.sun.ts.tests.servlet.api.jakarta_servlet.filter.DoFilter_Filter.SERVLET_MAPPED + + + + ServletMappedInitFilter_Filter + com.sun.ts.tests.servlet.api.jakarta_servlet.filter.InitFilter_Filter + + attribute + com.sun.ts.tests.servlet.api.jakarta_servlet.filter.InitFilter_Filter.SERVLET_MAPPED + + + + ServletMappedDoFilter_Filter + DoFilterTestLogicalName + + + ServletMappedInitFilter_Filter + InitFilterConfigTestLogicalName + + + DoFilterTestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.filter.DoFilterTestServlet + + + InitFilterConfigTestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.filter.InitFilterConfigTestServlet + + + DoFilterTestLogicalName + /DoFilterTest + + + InitFilterConfigTestLogicalName + /InitFilterConfigTest + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/filterchain/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/filterchain/URLClient.java new file mode 100644 index 0000000000..217aef14b0 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/filterchain/URLClient.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet.filterchain; + +import com.sun.ts.tests.servlet.api.jakarta_servlet.filterchain.FilterChainTestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.filterchain.FilterChain_Filter1; +import com.sun.ts.tests.servlet.api.jakarta_servlet.filterchain.FilterChain_Filter2; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_plu_filterchain_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_plu_filterchain_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(FilterChain_Filter1.class, FilterChain_Filter2.class, FilterChainTestServlet.class) + .addAsLibraries(javaArchive); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: filterChainTest + * + * @assertion_ids: Servlet:SPEC:48; Servlet:SPEC:50; Servlet:SPEC:52; + * Servlet:JAVADOC:287; Servlet:JAVADOC:293; + * + * @test_Strategy: Client attempts to access a servlet and both filters + * configured for that servlet should be invoked. + */ + @Test + public void filterChainTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "FilterChainTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/filterchain/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/filterchain/build.xml new file mode 100644 index 0000000000..3ff622690f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/filterchain/build.xml @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/filterchain/servlet_plu_filterchain_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/filterchain/servlet_plu_filterchain_web-fragment.xml new file mode 100644 index 0000000000..41791e02aa --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/filterchain/servlet_plu_filterchain_web-fragment.xml @@ -0,0 +1,60 @@ + + + + + + ServletMappedFilterChain_Filter1 + com.sun.ts.tests.servlet.api.jakarta_servlet.filterchain.FilterChain_Filter1 + + attribute1 + com.sun.ts.tests.servlet.api.jakarta_servlet.filterchain.FilterChain_Filter1.SERVLET_MAPPED + + + + ServletMappedFilterChain_Filter2 + com.sun.ts.tests.servlet.api.jakarta_servlet.filterchain.FilterChain_Filter2 + + attribute2 + com.sun.ts.tests.servlet.api.jakarta_servlet.filterchain.FilterChain_Filter2.SERVLET_MAPPED + + + + ServletMappedFilterChain_Filter1 + FilterChainTestLogicalName + + + ServletMappedFilterChain_Filter2 + FilterChainTestLogicalName + + + FilterChainTestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.filterchain.FilterChainTestServlet + + + FilterChainTestLogicalName + /FilterChainTest + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/filterconfig/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/filterconfig/URLClient.java new file mode 100644 index 0000000000..01bb6a80b6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/filterconfig/URLClient.java @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet.filterconfig; + +import com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetFilterName_Filter; +import com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetInitParamNull_Filter; +import com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetInitParam_Filter; +import com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetInitParamNames_Filter; +import com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetServletContext_Filter; +import com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetInitParamNamesNull_Filter; +import com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetServletContextTestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetInitParamNullTestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetInitParamTestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetInitParamNamesNullTestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetInitParamNamesTestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetFilterNameTestServlet; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_plu_filterconfig_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_plu_filterconfig_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(GetFilterName_Filter.class, GetInitParam_Filter.class, GetInitParamNames_Filter.class, + GetServletContext_Filter.class, GetInitParamNull_Filter.class, GetInitParamNamesNull_Filter.class, + GetServletContextTestServlet.class, GetInitParamNullTestServlet.class, GetInitParamTestServlet.class, + GetInitParamNamesNullTestServlet.class, GetInitParamNamesTestServlet.class, GetFilterNameTestServlet.class) + .addAsLibraries(javaArchive); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: GetFilterNameTest + * + * @assertion_ids: Servlet:SPEC:45; Servlet:JAVADOC:281; + * + * @test_Strategy: Client attempts to access a servlet and the filter + * configured for that servlet should be invoked. + */ + @Test + public void GetFilterNameTest() throws Exception { + String testName = "GetFilterNameTest"; + TEST_PROPS.setProperty(APITEST, testName); + invoke(); + } + + /* + * @testName: GetInitParamNamesTest + * + * @assertion_ids: Servlet:SPEC:45; Servlet:JAVADOC:285; + * + * @test_Strategy: Client attempts to access a servlet and the filter + * configured for that servlet should be invoked. + */ + @Test + public void GetInitParamNamesTest() throws Exception { + String testName = "GetInitParamNamesTest"; + TEST_PROPS.setProperty(APITEST, testName); + invoke(); + } + + /* + * @testName: GetInitParamNamesNullTest + * + * @assertion_ids: Servlet:SPEC:45; Servlet:JAVADOC:286; + * + * @test_Strategy: Client attempts to access a servlet and the filter + * configured for that servlet should be invoked. + */ + @Test + public void GetInitParamNamesNullTest() throws Exception { + String testName = "GetInitParamNamesNullTest"; + TEST_PROPS.setProperty(APITEST, testName); + invoke(); + } + + /* + * @testName: GetInitParamTest + * + * @assertion_ids: Servlet:SPEC:45; Servlet:JAVADOC:283; + * + * @test_Strategy: Client attempts to access a servlet and the filter + * configured for that servlet should be invoked. + */ + @Test + public void GetInitParamTest() throws Exception { + String testName = "GetInitParamTest"; + TEST_PROPS.setProperty(APITEST, testName); + invoke(); + } + + /* + * @testName: GetInitParamNullTest + * + * @assertion_ids: Servlet:SPEC:45; Servlet:JAVADOC:284; + * + * @test_Strategy: Client attempts to access a servlet and the filter + * configured for that servlet should be invoked. + */ + @Test + public void GetInitParamNullTest() throws Exception { + String testName = "GetInitParamNullTest"; + TEST_PROPS.setProperty(APITEST, testName); + invoke(); + } + + /* + * @testName: GetServletContextTest + * + * @assertion_ids: Servlet:SPEC:45; Servlet:JAVADOC:282; + * + * @test_Strategy: Client attempts to access a servlet and the filter + * configured for that servlet should be invoked. + */ + @Test + public void GetServletContextTest() throws Exception { + String testName = "GetServletContextTest"; + TEST_PROPS.setProperty(APITEST, testName); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/filterconfig/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/filterconfig/build.xml new file mode 100644 index 0000000000..f461ab02a4 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/filterconfig/build.xml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/filterconfig/servlet_plu_filterconfig_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/filterconfig/servlet_plu_filterconfig_web-fragment.xml new file mode 100644 index 0000000000..1b3ab951ba --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/filterconfig/servlet_plu_filterconfig_web-fragment.xml @@ -0,0 +1,148 @@ + + + + + + ServletMappedGetFilterName_Filter + com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetFilterName_Filter + + GetFilterName_Filter_attribute + com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetFilterName_Filter.SERVLET_MAPPED + + + + ServletMappedGetInitParam_Filter + com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetInitParam_Filter + + GetInitParam_Filter_attribute1 + com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetInitParam_Filter.SERVLET_MAPPED1 + + + GetInitParam_Filter_attribute2 + com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetInitParam_Filter.SERVLET_MAPPED2 + + + + ServletMappedGetInitParamNames_Filter + com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetInitParamNames_Filter + + GetInitParamNames_Filter_attribute1 + com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetInitParamNames_Filter.SERVLET_MAPPED1 + + + GetInitParamNames_Filter_attribute2 + com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetInitParamNames_Filter.SERVLET_MAPPED2 + + + + ServletMappedGetServletContext_Filter + com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetServletContext_Filter + + GetServletContext_Filter_attribute + com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetServletContext_Filter.SERVLET_MAPPED + + + + ServletMappedGetInitParamNull_Filter + com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetInitParamNull_Filter + + + ServletMappedGetInitParamNamesNull_Filter + com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetInitParamNamesNull_Filter + + + ServletMappedGetFilterName_Filter + GetFilterNameTestLogicalName + + + ServletMappedGetInitParam_Filter + GetInitParamTestLogicalName + + + ServletMappedGetInitParamNames_Filter + GetInitParamNamesTestLogicalName + + + ServletMappedGetServletContext_Filter + GetServletContextTestLogicalName + + + ServletMappedGetInitParamNull_Filter + GetInitParamNullTestLogicalName + + + ServletMappedGetInitParamNamesNull_Filter + GetInitParamNamesNullTestLogicalName + + + GetFilterNameTestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetFilterNameTestServlet + + + GetInitParamNamesTestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetInitParamNamesTestServlet + + + GetInitParamNamesNullTestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetInitParamNamesNullTestServlet + + + GetServletContextTestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetServletContextTestServlet + + + GetInitParamTestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetInitParamTestServlet + + + GetInitParamNullTestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.filterconfig.GetInitParamNullTestServlet + + + GetFilterNameTestLogicalName + /GetFilterNameTest + + + GetInitParamNamesTestLogicalName + /GetInitParamNamesTest + + + GetInitParamNamesNullTestLogicalName + /GetInitParamNamesNullTest + + + GetServletContextTestLogicalName + /GetServletContextTest + + + GetInitParamTestLogicalName + /GetInitParamTest + + + GetInitParamNullTestLogicalName + /GetInitParamNullTest + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/filterrequestdispatcher/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/filterrequestdispatcher/URLClient.java new file mode 100644 index 0000000000..63bbffe5de --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/filterrequestdispatcher/URLClient.java @@ -0,0 +1,239 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet.filterrequestdispatcher; + +import com.sun.ts.tests.servlet.api.jakarta_servlet.filterrequestdispatcher.DummyServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.filterrequestdispatcher.ErrorPage; +import com.sun.ts.tests.servlet.api.jakarta_servlet.filterrequestdispatcher.ForwardTest1Servlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.filterrequestdispatcher.ForwardTestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.filterrequestdispatcher.ForwardedServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.filterrequestdispatcher.IncludeTest1Servlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.filterrequestdispatcher.IncludeTestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.filterrequestdispatcher.IncludedServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.filterrequestdispatcher.RequestTestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.filterrequestdispatcher.TestServlet; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.common.util.Data; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import com.sun.ts.tests.servlet.api.jakarta_servlet.filterrequestdispatcher.Test_Filter; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_plu_filterrequestdispatcher_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_plu_filterrequestdispatcher_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(DummyServlet.class, ErrorPage.class, ForwardedServlet.class, + ForwardTest1Servlet.class, ForwardTestServlet.class, IncludedServlet.class, + IncludeTest1Servlet.class, IncludeTestServlet.class, RequestTestServlet.class, + Test_Filter.class, TestServlet.class) + .addAsLibraries(javaArchive); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + + /* + * @testName: RequestTest + * + * @assertion_ids: Servlet:SPEC:54; Servlet:SPEC:59; + * + * @test_Strategy: 1. Create a servlet, a JSP page and a web page - + * /generic/DummyServlet, /generic/dummyJSP, and /dummy.html. 2. Map a filter + * Test_Filter on all above three with dispatcher value set to REQUEST using + * url-pattern, as well as ERROR, FORWARD and INCLUDE. 3. Client try to access + * all of them directly. 4. Verify that filter is properly invoked. + */ + @Test + public void RequestTest() throws Exception { + TEST_PROPS.setProperty(DONOTUSEServletName, "true"); + TEST_PROPS.setProperty(APITEST, "generic/DummyServlet"); + invoke(); + + TEST_PROPS.setProperty(DONOTUSEServletName, "true"); + TEST_PROPS.setProperty(APITEST, "generic/dummyJSP"); + invoke(); + + TEST_PROPS.setProperty(APITEST, "dummy.html"); + TEST_PROPS.setProperty(DONOTUSEServletName, "true"); + invoke(); + } + + /* + * @testName: RequestTest1 + * + * @assertion_ids: Servlet:SPEC:54; + * + * @test_Strategy: 1. Create a servlet - RequestTestServlet. 2. Map a filter + * Test_Filter on RequestTestServlet with dispatcher value set to REQUEST + * using servlet-name 3. Client try to access RequestTestServlet directly. 4. + * Verify that filter is properly invoked. + */ + @Test + public void RequestTest1() throws Exception { + TEST_PROPS.setProperty(DONOTUSEServletName, "true"); + TEST_PROPS.setProperty(APITEST, "request/RequestTest"); + invoke(); + } + + /* + * @testName: RequestTest2 + * + * @assertion_ids: Servlet:SPEC:54; + * + * @test_Strategy: 1. Create a servlet - forward/ForwardedServlet. 2. Map a + * filter Test_Filter on forward/ForwardedServlet with dispatcher value not + * set to REQUEST but to FORWARD only. 3. Client try to access + * forward/ForwardedServlet directly. 4. Verify that filter is not invoked. + */ + @Test + public void RequestTest2() throws Exception { + TEST_PROPS.setProperty(DONOTUSEServletName, "true"); + TEST_PROPS.setProperty(SEARCH_STRING, Data.FAILED); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, Data.PASSED); + + TEST_PROPS.setProperty(APITEST, "forward/ForwardedServlet"); + invoke(); + } + + /* + * @testName: ForwardTest + * + * @assertion_ids: Servlet:SPEC:55; Servlet:JAVADOC:273; + * + * @test_Strategy: 1. Create two servlets - TestServlet, ForwardedServlet. 2. + * Map a filter Test_Filter using for ForwardedServlet with + * dispacther value FORWARD. 3. Client try to use the RequestDispatcher to + * forward to ForwardedServlet through TestServlet. 4. Verify that filter is + * properly invoked. + */ + @Test + public void ForwardTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "forwardTest"); + invoke(); + } + + /* + * @testName: ForwardTest1 + * + * @assertion_ids: Servlet:SPEC:55; Servlet:SPEC:59; Servlet:JAVADOC:273; + * + * @test_Strategy: 1. Create two servlets - ForwardTest1Servlet, + * /generic/TestServlet 2. Map a filter Test_Filter using for + * TestServlet with dispacther value FORWARD, as well as ERROR, INCLUDE and + * REQUEST. 3. Client try to access ForwardTest1Servlet which in turn use the + * RequestDispatcher to forward to TestServlet. 4. Verify that filter is + * properly invoked. + */ + @Test + public void ForwardTest1() throws Exception { + TEST_PROPS.setProperty(APITEST, "forwardServletTest"); + invoke(); + + TEST_PROPS.setProperty(APITEST, "forwardJSPTest"); + invoke(); + + TEST_PROPS.setProperty(APITEST, "forwardHTMLTest"); + invoke(); + } + + /* + * @testName: IncludeTest + * + * @assertion_ids: Servlet:SPEC:56; Servlet:SPEC:59; + * + * @test_Strategy: 1. Create two servlets - TestServlet, IncludedServlet. 2. + * Map a filter Test_Filter on IncludedServlet with dispacther value set to + * INCLUDE only. 3. Client try to use the RequestDispatcher's include to + * access IncludedServlet through TestServlet. 4. Verify that filter is + * properly invoked. + */ + @Test + public void IncludeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "includeTest"); + invoke(); + } + + /* + * @testName: IncludeTest1 + * + * @assertion_ids: Servlet:SPEC:56; Servlet:SPEC:59; + * + * @test_Strategy: 1. Create two servlet - TestServlet, /generic/DummyServlet, + * a JSP dummyJSP and a HTML file dummy.html. 2. Map a filter Test_Filter on + * /generic/DummyServlet, dummyJSP and dummy.html with dispacther value set to + * INCLUDE as well as ERROR, FORWARD and REQUEST using url-pattern. 3. Client + * try to use the RequestDispatcher's include to access all three through + * TestServlet. 4. Verify that filter is properly invoked. + */ + @Test + public void IncludeTest1() throws Exception { + TEST_PROPS.setProperty(APITEST, "includeJSPTest"); + invoke(); + + TEST_PROPS.setProperty(APITEST, "includeServletTest"); + invoke(); + + TEST_PROPS.setProperty(APITEST, "includeHTMLTest"); + invoke(); + } + + /* + * @testName: ErrorTest + * + * @assertion_ids: Servlet:SPEC:57; Servlet:SPEC:59; + * + * @test_Strategy: 1. Create an Error Page /generic/ErrorPage handling + * error-code 404. 2. Map a filter Test_Filter on /generic/ErrorPage with + * dispacther value set to ERROR as well as FORWARD INCLUDE and REQUEST. 3. + * Client try to access a non-existent Servlet 4. Verify that filter is + * properly invoked. + */ + @Test + public void ErrorTest() throws Exception { + TEST_PROPS.setProperty(DONOTUSEServletName, "true"); + TEST_PROPS.setProperty(APITEST, "forward/IncludedServlet"); + TEST_PROPS.setProperty(STATUS_CODE, "404"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/filterrequestdispatcher/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/filterrequestdispatcher/build.xml new file mode 100644 index 0000000000..4ef854fffb --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/filterrequestdispatcher/build.xml @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/filterrequestdispatcher/servlet_plu_filterrequestdispatcher_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/filterrequestdispatcher/servlet_plu_filterrequestdispatcher_web-fragment.xml new file mode 100644 index 0000000000..e0a355208c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/filterrequestdispatcher/servlet_plu_filterrequestdispatcher_web-fragment.xml @@ -0,0 +1,131 @@ + + + + + + ServletMappedTest_Filter + com.sun.ts.tests.servlet.api.jakarta_servlet.filterrequestdispatcher.Test_Filter + + attribute + com.sun.ts.tests.servlet.api.jakarta_servlet.filterrequestdispatcher.Test_Filter.SERVLET_MAPPED + + + + ServletMappedTest_Filter + IncludedServlet + INCLUDE + + + ServletMappedTest_Filter + ForwardedServlet + FORWARD + + + ServletMappedTest_Filter + /generic/* + REQUEST + INCLUDE + FORWARD + ERROR + + + ServletMappedTest_Filter + /dummy.html + REQUEST + INCLUDE + FORWARD + ERROR + + + ServletMappedTest_Filter + RequestServlet + REQUEST + + + DummyJSP + /dummyJSP.jsp + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.filterrequestdispatcher.TestServlet + + + DummyServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.filterrequestdispatcher.DummyServlet + + + RequestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.filterrequestdispatcher.RequestTestServlet + + + IncludedServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.filterrequestdispatcher.IncludedServlet + + + ForwardedServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.filterrequestdispatcher.ForwardedServlet + + + ErrorPage + com.sun.ts.tests.servlet.api.jakarta_servlet.filterrequestdispatcher.ErrorPage + + + ErrorPage + /generic/ErrorPage + + + DummyServlet + /generic/DummyServlet + + + DummyJSP + /generic/dummyJSP + + + TestServlet + /TestServlet + + + TestServlet + /generic/TestServlet + + + RequestServlet + /request/RequestTest + + + IncludedServlet + /include/IncludedServlet + + + ForwardedServlet + /forward/ForwardedServlet + + + 54 + + + 404 + /generic/ErrorPage + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/genericservlet/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/genericservlet/URLClient.java new file mode 100644 index 0000000000..52852f4d89 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/genericservlet/URLClient.java @@ -0,0 +1,267 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet.genericservlet; + +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservlet.ServiceTestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.genericservlet.DestroyTestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.genericservlet.InitServletExceptionTestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.genericservlet.InitTestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.genericservlet.Init_ServletConfigServletExceptionTestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.genericservlet.Init_ServletConfigTestServlet; +//import com.sun.ts.tests.servlet.api.jakarta_servlet.genericservlet.ServiceTestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.genericservlet.ServletErrorPage; +import com.sun.ts.tests.servlet.api.jakarta_servlet.genericservlet.TestServlet; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_plu_genericservlet_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_plu_genericservlet_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(DestroyTestServlet.class, Init_ServletConfigServletExceptionTestServlet.class, + Init_ServletConfigTestServlet.class, InitServletExceptionTestServlet.class, + InitTestServlet.class, ServiceTestServlet.class, ServletErrorPage.class, TestServlet.class) + .addAsLibraries(javaArchive); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: destroyTest + * + * @assertion_ids: Servlet:JAVADOC:119 + * + * @test_Strategy: Create a GenericServlet and take out of service using + * destroy method + * + */ + @Test + public void destroyTest() throws Exception { + String testName = "destroyTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(IGNORE_BODY, "true"); + invoke(); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(IGNORE_BODY, "true"); + invoke(); + } + + /* + * @testName: getServletConfigTest + * + * @assertion_ids: Servlet:JAVADOC:124 + * + * @test_Strategy: Create a GenericServlet and check for its ServletConfig + * object existence + * + */ + @Test + public void getServletConfigTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletConfigTest"); + invoke(); + } + + /* + * @testName: getServletContextTest + * + * @assertion_ids: Servlet:JAVADOC:125 + * + * @test_Strategy: Create a GenericServlet and check for its ServletContext + * object existence + * + */ + @Test + public void getServletContextTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletContextTest"); + invoke(); + } + + /* + * @testName: getServletInfoTest + * + * @assertion_ids: Servlet:JAVADOC:126 + * + * @test_Strategy: Create a GenericServlet and check for its ServletInfo + * object values + * + */ + @Test + public void getServletInfoTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletInfoTest"); + invoke(); + } + + /* + * @testName: getInitParameterTest + * + * @assertion_ids: Servlet:JAVADOC:120 + * + * @test_Strategy: Servlet tries to access a parameter that exists + */ + @Test + public void getInitParameterTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getInitParameterTest"); + invoke(); + } + + /* + * @testName: getInitParameterNamesTest + * + * @assertion_ids: Servlet:JAVADOC:122 + * + * @test_Strategy: Servlet tries to get all parameter names + */ + @Test + public void getInitParameterNamesTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getInitParameterNamesTest"); + invoke(); + } + + /* + * @testName: getServletNameTest + * + * @assertion_ids: Servlet:JAVADOC:136 + * + * @test_Strategy: Servlet gets name of servlet + */ + @Test + public void getServletNameTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletNameTest"); + invoke(); + } + + /* + * @testName: initServletExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:130 + * + * @test_Strategy: Servlet throws a ServletException + */ + @Test + public void initServletExceptionTest() throws Exception { + String testName = "initServletExceptionTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(STATUS_CODE, INTERNAL_SERVER_ERROR); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, + "Status Code: 500|Exception: jakarta.servlet.ServletException: in init of InitServletExceptionTestServlet"); + invoke(); + } + + /* + * @testName: initTest + * + * @assertion_ids: Servlet:JAVADOC:129 + * + * @test_Strategy: Servlet has init method that puts a value into the context. + * Servlet when called reads value from context + */ + @Test + public void initTest() throws Exception { + String testName = "initTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + testName + " HTTP/1.1"); + invoke(); + } + + /* + * @testName: init_ServletConfigServletExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:128 + * + * @test_Strategy: Servlet throws a ServletException + */ + @Test + public void init_ServletConfigServletExceptionTest() throws Exception { + String testName = "init_ServletConfigServletExceptionTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(STATUS_CODE, INTERNAL_SERVER_ERROR); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, + "Status Code: 500|Exception: jakarta.servlet.ServletException: in init of Init_ServletConfigServletExceptionTestServlet"); + invoke(); + } + + /* + * @testName: init_ServletConfigTest + * + * @assertion_ids: Servlet:JAVADOC:127 + * + * @test_Strategy: Servlet has init method that puts a value into the context. + * Servlet when called reads value from context + */ + @Test + public void init_ServletConfigTest() throws Exception { + String testName = "init_ServletConfigTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + testName + " HTTP/1.1"); + invoke(); + } + + /* + * @testName: serviceTest + * + * @assertion_ids: Servlet:JAVADOC:133 + * + * @test_Strategy: Servlet which has a service method that is called + */ + @Test + public void serviceTest() throws Exception { + String testName = "serviceTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + testName + " HTTP/1.1"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/genericservlet/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/genericservlet/build.xml new file mode 100644 index 0000000000..2e8de10c9f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/genericservlet/build.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/genericservlet/servlet_plu_genericservlet_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/genericservlet/servlet_plu_genericservlet_web-fragment.xml new file mode 100644 index 0000000000..a6c3d922fd --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/genericservlet/servlet_plu_genericservlet_web-fragment.xml @@ -0,0 +1,104 @@ + + + + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.genericservlet.TestServlet + + parameter1 + value1 + + + parameter2 + value2 + + + + destroyTest + com.sun.ts.tests.servlet.api.jakarta_servlet.genericservlet.DestroyTestServlet + + + initServletExceptionTest + com.sun.ts.tests.servlet.api.jakarta_servlet.genericservlet.InitServletExceptionTestServlet + + + initTest + com.sun.ts.tests.servlet.api.jakarta_servlet.genericservlet.InitTestServlet + + + init_ServletConfigServletExceptionTest + com.sun.ts.tests.servlet.api.jakarta_servlet.genericservlet.Init_ServletConfigServletExceptionTestServlet + + + init_ServletConfigTest + com.sun.ts.tests.servlet.api.jakarta_servlet.genericservlet.Init_ServletConfigTestServlet + + + servletErrorPage + com.sun.ts.tests.servlet.api.jakarta_servlet.genericservlet.ServletErrorPage + + + serviceTest + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservlet.ServiceTestServlet + + + TestServlet + /TestServlet/* + + + destroyTest + /destroyTest + + + initServletExceptionTest + /initServletExceptionTest + + + initTest + /initTest + + + init_ServletConfigServletExceptionTest + /init_ServletConfigServletExceptionTest + + + init_ServletConfigTest + /init_ServletConfigTest + + + servletErrorPage + /servletErrorPage + + + serviceTest + /serviceTest + + + 54 + + + jakarta.servlet.ServletException + /servletErrorPage + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/registration/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/registration/URLClient.java new file mode 100644 index 0000000000..2d58d194dd --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/registration/URLClient.java @@ -0,0 +1,370 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet.registration; + +import com.sun.ts.tests.servlet.api.jakarta_servlet.registration.TestListener; +import com.sun.ts.tests.servlet.api.jakarta_servlet.registration.TestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddServletString; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddServletClass; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddServletNotFound; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddFilterClass; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddFilterNotFound; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.BadServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.BadFilter; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.BadListener; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.CreateServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.CreateFilter; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class, AddServletString.class, AddServletClass.class, + AddFilterClass.class, CreateServlet.class, CreateFilter.class, AddServletNotFound.class, + AddFilterNotFound.class, BadServlet.class, BadFilter.class, BadListener.class) + .addAsResource(URLClient.class.getResource("servlet_plu_registration_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_plu_registration_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestListener.class, TestServlet.class) + .addAsLibraries(javaArchive); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: servletURLMappingTest + * + * @assertion_ids: Servlet:JAVADOC:676; Servlet:JAVADOC:694; + * Servlet:JAVADOC:696; Servlet:JAVADOC:697; + * + * @test_Strategy: Create a ServletContextListener, in which, 1. Add the + * Servlet ServletContext.addServlet(String, Class), 2. mapping the new + * Servlet programmatically. 3. Store information returned in + * ServletContextAttribute by jakarta.servlet.ServletRegistration.getMappings 4. + * client send a request to another servlet to get the information Verify in + * client that getMapping works + */ + @Test + public void servletURLMappingTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "servletURLMappingTest"); + TEST_PROPS.setProperty(UNORDERED_SEARCH_STRING, + "URL_MAPPING_TEST" + "|/ADDSERVLETCLASS" + "|/SECONDADDSERVLETCLASS" + + "|/THIRDADDSERVLETCLASS" + "|/ADDSERVLETCLASS/*"); + invoke(); + } + + /* + * @testName: filterServletMappingTest + * + * @assertion_ids: Servlet:JAVADOC:243; Servlet:JAVADOC:655; + * Servlet:JAVADOC:657; Servlet:JAVADOC:668; Servlet:JAVADOC:669; + * Servlet:JAVADOC:670; Servlet:JAVADOC:677; Servlet:JAVADOC:694; + * + * @test_Strategy: Create a ServletContextListener, in which, 1. Create a + * FilterRegistration ServletContext.addFilter(String, Class) 2. Create + * another FilterRegistration ServletContext.addFilter(String, String), 3. + * Create the third FilterRegistration ServletContext.addServlet(String, + * Filter), 4. Map all FilterRegistration calling addMappingForServletNames 5. + * Store information in ServletContextAttribute: + * jakarta.servlet.FilterRegistration.getServletNameMappings 6. client send a + * request to another servlet to get the information Verify in client that + * getServletNameMappings works + */ + @Test + public void filterServletMappingTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "filterServletMappingTest"); + TEST_PROPS.setProperty(SEARCH_STRING, + "FILTER_SERVLET_MAPPING" + "|AddServletString" + "|AddServletClass" + + "|AddServletNotFound" + "|CreateServlet"); + invoke(); + } + + /* + * @testName: servletRegistrationsTest + * + * @assertion_ids: Servlet:JAVADOC:674; Servlet:JAVADOC:675; + * Servlet:JAVADOC:676; Servlet:JAVADOC:681; Servlet:JAVADOC:692; + * Servlet:JAVADOC:694; Servlet:JAVADOC:696; + * + * + * @test_Strategy: Create a ServletContextListener, in which, 1. Add the + * Servlet ServletContext.addServlet(String, Class), 2. Add another Servlet + * ServletContext.addServlet(String, String), 3. Add the third Servlet + * ServletContext.addServlet(String, Servlet), 4. Define a servlet in web.xml; + * 5. Store information returned in ServletContextAttribute by + * jakarta.servlet.ServletRegistration.getServletRegistrations 6. client send a + * request to another servlet to get the information Verify in client that + * getServletRegistrations works + */ + @Test + public void servletRegistrationsTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletRegistrationsTest"); + TEST_PROPS.setProperty(UNORDERED_SEARCH_STRING, + "SERVLET_REGISTRATIONS:" + "|ADDSERVLETCLASS" + "|ADDSERVLETNOTFOUND" + + "|ADDSERVLETSTRING" + "|CREATESERVLET" + "|TESTSERVLET"); + invoke(); + } + + /* + * @testName: getServletRegistrationTest + * + * @assertion_ids: Servlet:JAVADOC:674; Servlet:JAVADOC:675; + * Servlet:JAVADOC:676; Servlet:JAVADOC:681; Servlet:JAVADOC:691; + * Servlet:JAVADOC:694; Servlet:JAVADOC:696; + * + * @test_Strategy: Create a ServletContextListener, in which, 1. Add the + * Servlet ServletContext.addServlet(String, Class), 2. Add another Servlet + * ServletContext.addServlet(String, String), 3. Add the third Servlet + * ServletContext.addServlet(String, Servlet), 4. Define a servlet in web.xml; + * 5. Store information returned in ServletContextAttribute by + * jakarta.servlet.ServletRegistration.getServletRegistration(String) 6. client + * send a request to another servlet to get the information Verify in client + * that getServletRegistration(String) works + */ + @Test + public void getServletRegistrationTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletRegistrationTest"); + TEST_PROPS.setProperty(SEARCH_STRING, + "SERVLET_REGISTRATION:" + "|ADDSERVLETSTRING" + "|ADDSERVLETCLASS" + + "|ADDSERVLETNOTFOUND" + "|CREATESERVLET" + "|TESTSERVLET"); + invoke(); + } + + /* + * @testName: getFilterRegistrationsTest + * + * @assertion_ids: Servlet:JAVADOC:674; Servlet:JAVADOC:675; + * Servlet:JAVADOC:676; Servlet:JAVADOC:681; Servlet:JAVADOC:689; + * Servlet:JAVADOC:694; Servlet:JAVADOC:696; + * + * + * @test_Strategy: Create a ServletContextListener, in which, 1. Add the + * Servlet ServletContext.addServlet(String, Class), 2. Add another Servlet + * ServletContext.addServlet(String, String), 3. Add the third Servlet + * ServletContext.addServlet(String, Servlet), 4. Define a servlet in web.xml; + * 5. Store information returned in ServletContextAttribute by + * jakarta.servlet.ServletRegistration.getFilterRegistrations 6. client send a + * request to another servlet to get the information Verify in client that + * getFilterRegistrations works + */ + @Test + public void getFilterRegistrationsTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getFilterRegistrationsTest"); + TEST_PROPS.setProperty(UNORDERED_SEARCH_STRING, + "FILTER_REGISTRATIONS:" + "|AddFilterClass" + "|AddFilterNotFound" + + "|AddFilterString" + "|CreateFilter"); + invoke(); + } + + /* + * @testName: getFilterRegistrationTest + * + * @assertion_ids: Servlet:JAVADOC:674; Servlet:JAVADOC:675; + * Servlet:JAVADOC:676; Servlet:JAVADOC:681; Servlet:JAVADOC:688; + * Servlet:JAVADOC:694; Servlet:JAVADOC:696; + * + * @test_Strategy: Create a ServletContextListener, in which, 1. Add the + * Servlet ServletContext.addServlet(String, Class), 2. Add another Servlet + * ServletContext.addServlet(String, String), 3. Add the third Servlet + * ServletContext.addServlet(String, Servlet), 4. Define a servlet in web.xml; + * 5. Store information returned in ServletContextAttribute by + * jakarta.servlet.ServletRegistration.getFilterRegistration(String) 6. client + * send a request to another servlet to get the information Verify in client + * that getFilterRegistration(String) works + */ + @Test + public void getFilterRegistrationTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getFilterRegistrationTest"); + TEST_PROPS.setProperty(SEARCH_STRING, + "FILTER_REGISTRATION:" + "|AddFilterString" + "|AddFilterClass" + + "|AddFilterNotFound" + "|CreateFilter"); + invoke(); + } + + /* + * @testName: getRegistrationNameTest + * + * @assertion_ids: Servlet:JAVADOC:243; Servlet:JAVADOC:662; + * Servlet:JAVADOC:668; Servlet:JAVADOC:669; Servlet:JAVADOC:670; + * Servlet:JAVADOC:674; Servlet:JAVADOC:675; Servlet:JAVADOC:676; + * Servlet:JAVADOC:677; Servlet:JAVADOC:681; Servlet:JAVADOC:694; + * + * @test_Strategy: Create a ServletContextListener, in which, 1. Create a + * ServletRegistration ServletContext.addServlet(String, Class) 2. Create + * another ServletRegistration ServletContext.addServlet(String, String), 3. + * Create the third ServletRegistration ServletContext.addServlet(String, + * Servlet), 4. Create a FilterRegistration ServletContext.addFilter(String, + * Class) 5. Create another FilterRegistration + * ServletContext.addFilter(String, String), 6. Create the third + * FilterRegistration ServletContext.addFilter(String, Filter), 7. Store + * information returned in ServletContextAttribute by + * jakarta.servlet.Registration.getName() 8. client send a request to another + * servlet to get the information Verify in client that + * jakarta.servlet.Registration.getName() works + */ + @Test + public void getRegistrationNameTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getRegistrationNameTest"); + TEST_PROPS.setProperty(SEARCH_STRING, + "REGISTRION_NAME:" + "|ADDSERVLETSTRING" + "|ADDFILTERSTRING" + + "|ADDSERVLETCLASS" + "|ADDFILTERCLASS" + "|CREATESERVLET" + + "|CREATEFILTER" + "|ADDSERVLETNOTFOUND" + "|ADDFILTERNOTFOUND"); + invoke(); + } + + /* + * @testName: getRegistrationClassNameTest + * + * @assertion_ids: Servlet:JAVADOC:243; Servlet:JAVADOC:659; + * Servlet:JAVADOC:668; Servlet:JAVADOC:669; Servlet:JAVADOC:670; + * Servlet:JAVADOC:674; Servlet:JAVADOC:675; Servlet:JAVADOC:676; + * Servlet:JAVADOC:677; Servlet:JAVADOC:681; Servlet:JAVADOC:694; + * + * @test_Strategy: Create a ServletContextListener, in which, 1. Create a + * ServletRegistration ServletContext.addServlet(String, Class) 2. Create + * another ServletRegistration ServletContext.addServlet(String, String), 3. + * Create the third ServletRegistration ServletContext.addServlet(String, + * Servlet), 4. Create a FilterRegistration ServletContext.addFilter(String, + * Class) 5. Create another FilterRegistration + * ServletContext.addFilter(String, String), 6. Create the third + * FilterRegistration ServletContext.addFilter(String, Filter), 7. Store + * information returned in ServletContextAttribute by + * jakarta.servlet.Registration.getClassName() 8. client send a request to + * another servlet to get the information Verify in client that + * jakarta.servlet.Registration.getClassName() works + */ + @Test + public void getRegistrationClassNameTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getRegistrationClassNameTest"); + TEST_PROPS.setProperty(SEARCH_STRING, "REGISTRATION_CLASS_NAME:" + + "|COM.SUN.TS.TESTS.SERVLET.API.JAKARTA_SERVLET.SERVLETCONTEXT30.ADDSERVLETSTRING" + + "|COM.SUN.TS.TESTS.SERVLET.API.JAKARTA_SERVLET.SERVLETCONTEXT30.ADDFILTERSTRING" + + "|COM.SUN.TS.TESTS.SERVLET.API.JAKARTA_SERVLET.SERVLETCONTEXT30.ADDSERVLETCLASS" + + "|COM.SUN.TS.TESTS.SERVLET.API.JAKARTA_SERVLET.SERVLETCONTEXT30.ADDFILTERCLASS" + + "|COM.SUN.TS.TESTS.SERVLET.API.JAKARTA_SERVLET.SERVLETCONTEXT30.CREATESERVLET" + + "|COM.SUN.TS.TESTS.SERVLET.API.JAKARTA_SERVLET.SERVLETCONTEXT30.CREATEFILTER" + + "|COM.SUN.TS.TESTS.SERVLET.API.JAKARTA_SERVLET.SERVLETCONTEXT30.ADDSERVLETNOTFOUND" + + "|COM.SUN.TS.TESTS.SERVLET.API.JAKARTA_SERVLET.SERVLETCONTEXT30.ADDFILTERNOTFOUND"); + invoke(); + } + + /* + * @testName: getRegistrationInitParameterTest + * + * @assertion_ids: Servlet:JAVADOC:243; Servlet:JAVADOC:660; + * Servlet:JAVADOC:663; Servlet:JAVADOC:668; Servlet:JAVADOC:669; + * Servlet:JAVADOC:670; Servlet:JAVADOC:674; Servlet:JAVADOC:675; + * Servlet:JAVADOC:676; Servlet:JAVADOC:677; Servlet:JAVADOC:681; + * Servlet:JAVADOC:694; + * + * @test_Strategy: Create a ServletContextListener, in which, 1. Create a + * ServletRegistration ServletContext.addServlet(String, Class) 2. Create + * another ServletRegistration ServletContext.addServlet(String, String), 3. + * Create the third ServletRegistration ServletContext.addServlet(String, + * Servlet), 4. Create a FilterRegistration ServletContext.addFilter(String, + * Class) 5. Create another FilterRegistration + * ServletContext.addFilter(String, String), 6. Create the third + * FilterRegistration ServletContext.addFilter(String, Filter), 7. Call + * setInitParameter(String, String) on all above Registratyion Object; 8. + * Store information returned in ServletContextAttribute by + * jakarta.servlet.Registration.getInitParameter(String) 9. client send a + * request to another servlet to get the information Verify in client that + * jakarta.servlet.Registration.getInitParameter(String) works + */ + @Test + public void getRegistrationInitParameterTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getRegistrationInitParameterTest"); + TEST_PROPS.setProperty(SEARCH_STRING, + "REGISTRATION_INIT_PARAMETER:" + "|AddFilterString" + + "|AddServletString" + "|AddFilterClass" + "|AddServletClass" + + "|CreateFilter" + "|CreateServlet" + "|AddFilterNotFound" + + "|AddServletNotFound"); + invoke(); + } + + /* + * @testName: getRegistrationInitParametersTest + * + * @assertion_ids: Servlet:JAVADOC:243; Servlet:JAVADOC:661; + * Servlet:JAVADOC:664; Servlet:JAVADOC:668; Servlet:JAVADOC:669; + * Servlet:JAVADOC:670; Servlet:JAVADOC:674; Servlet:JAVADOC:675; + * Servlet:JAVADOC:676; Servlet:JAVADOC:677; Servlet:JAVADOC:681; + * Servlet:JAVADOC:694; + * + * @test_Strategy: Create a ServletContextListener, in which, 1. Create a + * ServletRegistration ServletContext.addServlet(String, Class) 2. Create + * another ServletRegistration ServletContext.addServlet(String, String), 3. + * Create the third ServletRegistration ServletContext.addServlet(String, + * Servlet), 4. Create a FilterRegistration ServletContext.addFilter(String, + * Class) 5. Create another FilterRegistration + * ServletContext.addFilter(String, String), 6. Create the third + * FilterRegistration ServletContext.addFilter(String, Filter), 7. Call + * setInitParameters(Map) on all above Registratyion Object; 8. Store + * information returned in ServletContextAttribute by + * jakarta.servlet.Registration.getInitParameters() 9. client send a request to + * another servlet to get the information Verify in client that + * jakarta.servlet.Registration.getInitParameters() works + */ + @Test + public void getRegistrationInitParametersTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getRegistrationInitParametersTest"); + TEST_PROPS.setProperty(SEARCH_STRING, + "REGISTRATION_INIT_PARAMETERS:" + + "|Filter=No|FilterName=AddFilterString|Servlet=Yes" + + "|DISPATCH=FORWARD|ServletName=AddServletString" + + "|Filter=Yes|FilterName=AddFilterString|Servlet=No" + + "|DISPATCH=FORWARD|ServletName=AddServletString" + + "|Filter=No|FilterName=AddFilterClass|Servlet=Yes" + + "|DISPATCH=REQUEST|ServletName=AddServletClass" + + "|Filter=Yes|FilterName=AddFilterClass|Servlet=No" + + "|DISPATCH=REQUEST|ServletName=AddServletClass" + + "|Filter=No|FilterName=CreateFilter|Servlet=Yes" + + "|DISPATCH=REQUEST|ServletName=CreateServlet" + + "|Filter=Yes|FilterName=CreateFilter|Servlet=No" + + "|DISPATCH=REQUEST|ServletName=CreateServlet" + + "|Filter=No|FilterName=AddFilterNotFound|Servlet=Yes" + + "|DISPATCH=ALL|ServletName=AddServletNotFound" + + "|Filter=Yes|FilterName=AddFilterNotFound|Servlet=No" + + "|DISPATCH=ALL|ServletName=AddServletNotFound"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/registration/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/registration/build.xml new file mode 100644 index 0000000000..285fbd1e3c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/registration/build.xml @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/registration/servlet_plu_registration_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/registration/servlet_plu_registration_web-fragment.xml new file mode 100644 index 0000000000..b21532160a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/registration/servlet_plu_registration_web-fragment.xml @@ -0,0 +1,39 @@ + + + + + + com.sun.ts.tests.servlet.api.jakarta_servlet.registration.TestListener + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.registration.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/requestdispatcher/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/requestdispatcher/URLClient.java new file mode 100644 index 0000000000..10bf7d880a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/requestdispatcher/URLClient.java @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet.requestdispatcher; + +import com.sun.ts.tests.servlet.api.jakarta_servlet.requestdispatcher.ForwardedServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.requestdispatcher.ForwardedServlet2; +import com.sun.ts.tests.servlet.api.jakarta_servlet.requestdispatcher.ForwardedServlet3; +import com.sun.ts.tests.servlet.api.jakarta_servlet.requestdispatcher.IncludedServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.requestdispatcher.TestServlet; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_plu_requestdispatcher_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_plu_requestdispatcher_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(ForwardedServlet.class, ForwardedServlet2.class, ForwardedServlet3.class, + IncludedServlet.class, TestServlet.class) + .addAsLibraries(javaArchive); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + + /* + * @testName: forwardTest + * + * @assertion_ids: Servlet:SPEC:80; Servlet:JAVADOC:230; Servlet:JAVADOC:272; + * Servlet:JAVADOC:274; + * + * @test_Strategy: Create a servlet, get its RequestDispatcher and use it to + * forward to a servlet + */ + @Test + public void forwardTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "forwardTest"); + invoke(); + } + + /* + * @testName: forward_1Test + * + * @assertion_ids: Servlet:SPEC:77; Servlet:SPEC:80; Servlet:JAVADOC:230; + * Servlet:JAVADOC:277; + * + * @test_Strategy: A negative test for RequestDispatcher.forward() method. + * Create a servlet, print a string to the buffer, flush the buffer to commit + * the string, get its RequestDispatcher and use it to forward to a servlet. + */ + @Test + public void forward_1Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "forward_1Test"); + invoke(); + } + + /* + * @testName: includeTest + * + * @assertion_ids: Servlet:JAVADOC:230; Servlet:JAVADOC:278; + * + * @test_Strategy: Create a servlet, get its RequestDispatcher and use it to + * include a servlet + */ + @Test + public void includeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "includeTest"); + invoke(); + } + + /* + * @testName: include_1Test + * + * @assertion_ids: Servlet:JAVADOC:230; Servlet:JAVADOC:278; + * + * @test_Strategy: A negative test for RequestDispatcher.include() test. + * Create a servlet, set its Content-Type to be 'text/html', get its + * RequestDispatcher and use it to include a servlet. The included servlet + * tries to change the Content-Type to be text/html. Test at the client side + * for correct Content-Type. + */ + @Test + public void include_1Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "include_1Test"); + TEST_PROPS.setProperty(EXPECTED_HEADERS, "Content-Type: text/sgml"); + invoke(); + } + + /* + * @testName: include_2Test + * + * @assertion_ids: Servlet:SPEC:82; Servlet:SPEC:80; Servlet:JAVADOC:230; + * Servlet:JAVADOC:279; + * + * @test_Strategy: A negative test for RequestDispatcher.include() method. + * Create a servlet with service() method throws ServletException. Use + * RequestDispatcher to include to this servlet. Verify that include() method + * throws ServletException. + */ + @Test + public void include_2Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "include_2Test"); + invoke(); + } + + /* + * @testName: include_3Test + * + * @assertion_ids: Servlet:SPEC:82; Servlet:SPEC:80; Servlet:JAVADOC:230; + * Servlet:JAVADOC:280; + * + * @test_Strategy: A negative test for RequestDispatcher.include() method. + * Create a servlet with service() method throws IOException. Use + * RequestDispatcher to include to this servlet. Verify that include() method + * throws IOException. + */ + @Test + public void include_3Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "include_3Test"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/requestdispatcher/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/requestdispatcher/build.xml new file mode 100644 index 0000000000..eebdc58c0b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/requestdispatcher/build.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/requestdispatcher/servlet_plu_requestdispatcher_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/requestdispatcher/servlet_plu_requestdispatcher_web-fragment.xml new file mode 100644 index 0000000000..20e5d2db44 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/requestdispatcher/servlet_plu_requestdispatcher_web-fragment.xml @@ -0,0 +1,68 @@ + + + + + + IncludedServletLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.requestdispatcher.IncludedServlet + + + ForwardedServlet2LogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.requestdispatcher.ForwardedServlet2 + + + ForwardedServlet3LogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.requestdispatcher.ForwardedServlet3 + + + ForwardedServletLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.requestdispatcher.ForwardedServlet + + + TestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.requestdispatcher.TestServlet + + + TestLogicalName + /TestServlet + + + IncludedServletLogicalName + /IncludedServlet + + + ForwardedServletLogicalName + /ForwardedServlet + + + ForwardedServlet2LogicalName + /ForwardedServlet2 + + + ForwardedServlet3LogicalName + /ForwardedServlet3 + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/scattributeevent/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/scattributeevent/URLClient.java new file mode 100644 index 0000000000..632ce9edb9 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/scattributeevent/URLClient.java @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2012, 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: $ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet.scattributeevent; + +import com.sun.ts.tests.servlet.api.jakarta_servlet.scattributeevent.SCAttributeEventListener; +import com.sun.ts.tests.servlet.api.jakarta_servlet.scattributeevent.SCAttributeListener; +import com.sun.ts.tests.servlet.api.jakarta_servlet.scattributeevent.TestServlet; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_plu_scattributeevent_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_plu_scattributeevent_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(SCAttributeEventListener.class, SCAttributeListener.class, TestServlet.class) + .addAsLibraries(javaArchive); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: constructorTest + * + * @assertion_ids: Servlet:JAVADOC:112 + * + * @test_Strategy: Servlet instanciate the constructor + */ + @Test + public void constructorTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "constructorTest"); + invoke(); + } + + /* + * @testName: addedTest + * + * @assertion_ids: Servlet:JAVADOC:113;Servlet:JAVADOC:114;Servlet:JAVADOC:117 + * + * @test_Strategy: Servlet adds an attribute. The listener should detect the + * add and write a message out to a static log. Servlet then reads the log and + * verifys the result. It also verifies the request and context that changed + * + */ + @Test + public void addedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "addedTest"); + invoke(); + } + + /* + * @testName: removedTest + * + * @assertion_ids: Servlet:JAVADOC:113;Servlet:JAVADOC:115;Servlet:JAVADOC:117 + * + * @test_Strategy: Servlet adds/removes an attribute. The listener should + * detect the add and write a message out to a static log. Servlet then reads + * the log and verifys the result. It also verifies the request and context + * that changed + */ + @Test + public void removedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "removedTest"); + invoke(); + } + + /* + * @testName: replacedTest + * + * @assertion_ids: Servlet:JAVADOC:113;Servlet:JAVADOC:116;Servlet:JAVADOC:117 + * + * @test_Strategy: Servlet adds/replaces an attribute. The listener should + * detect the add and write a message out to a static log. Servlet then reads + * the log and verifys the result. It also verifies the request and context + * that changed + */ + @Test + public void replacedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "replacedTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/scattributeevent/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/scattributeevent/build.xml new file mode 100644 index 0000000000..b7b393f36f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/scattributeevent/build.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/scattributeevent/servlet_plu_scattributeevent_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/scattributeevent/servlet_plu_scattributeevent_web-fragment.xml new file mode 100644 index 0000000000..06dee93974 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/scattributeevent/servlet_plu_scattributeevent_web-fragment.xml @@ -0,0 +1,39 @@ + + + + + + com.sun.ts.tests.servlet.api.jakarta_servlet.scattributeevent.SCAttributeListener + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.scattributeevent.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/scattributelistener/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/scattributelistener/URLClient.java new file mode 100644 index 0000000000..87ba64a204 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/scattributelistener/URLClient.java @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet.scattributelistener; + +import com.sun.ts.tests.servlet.api.jakarta_servlet.scattributelistener.SCAttributeListener; +import com.sun.ts.tests.servlet.api.jakarta_servlet.scattributelistener.TestServlet; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_plu_scattributelistener_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_plu_scattributelistener_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(SCAttributeListener.class, TestServlet.class) + .addAsLibraries(javaArchive); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: addedTest + * + * @assertion_ids: Servlet:JAVADOC:216; Servlet:JAVADOC:252; + * + * @test_Strategy: Servlet adds an attribute. The listener should detect the + * add and write a message out to a static log. Servlet then reads the log and + * verifies the result. + * + */ + @Test + public void addedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "addedTest"); + invoke(); + } + + /* + * @testName: removedTest + * + * @assertion_ids: Servlet:JAVADOC:217; Servlet:JAVADOC:255; + * + * @test_Strategy: Servlet adds/removes an attribute. The listener should + * detect the two actions and write a message out to a static log. Servlet + * then reads the log and verifies the result. + */ + @Test + public void removedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "removedTest"); + invoke(); + } + + /* + * @testName: replacedTest + * + * @assertion_ids: Servlet:JAVADOC:218 + * + * @test_Strategy: Servlet adds/replaces an attribute. The listener should + * detect the two actions and write a message to a static log. Servlet then + * reads the log and verifies the result. + */ + @Test + public void replacedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "replacedTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/scattributelistener/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/scattributelistener/build.xml new file mode 100644 index 0000000000..78d1696346 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/scattributelistener/build.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/scattributelistener/servlet_plu_scattributelistener_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/scattributelistener/servlet_plu_scattributelistener_web-fragment.xml new file mode 100644 index 0000000000..b124251fad --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/scattributelistener/servlet_plu_scattributelistener_web-fragment.xml @@ -0,0 +1,39 @@ + + + + + + com.sun.ts.tests.servlet.api.jakarta_servlet.scattributelistener.SCAttributeListener + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.scattributelistener.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/scevent/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/scevent/URLClient.java new file mode 100644 index 0000000000..eb17d3d3f5 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/scevent/URLClient.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet.scevent; + +import com.sun.ts.tests.servlet.api.jakarta_servlet.scevent.SContextEventListener; +import com.sun.ts.tests.servlet.api.jakarta_servlet.scevent.TestServlet; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_plu_scevent_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_plu_scevent_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(SContextEventListener.class, TestServlet.class) + .addAsLibraries(javaArchive); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + /* + * @testName: constructorTest + * + * @assertion_ids: Servlet:JAVADOC:110 + * + * @test_Strategy: Servlet tries to get an instance of ServletContextEvent. + */ + @Test + public void constructorTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "constructorTest"); + invoke(); + } + + /* + * @testName: getServletContextTest + * + * @assertion_ids: Servlet:JAVADOC:111 + * + * @test_Strategy: Deploy a servlet context event listener. When the context + * gets initialized, write a status message to a static log. Servlet reads the + * static log looking for a specific message and verifies it exists + */ + @Test + public void getServletContextTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletContextTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/scevent/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/scevent/build.xml new file mode 100644 index 0000000000..d1284cce6b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/scevent/build.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/scevent/servlet_plu_scevent_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/scevent/servlet_plu_scevent_web-fragment.xml new file mode 100644 index 0000000000..8abe64bc68 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/scevent/servlet_plu_scevent_web-fragment.xml @@ -0,0 +1,39 @@ + + + + + + com.sun.ts.tests.servlet.api.jakarta_servlet.scevent.SContextEventListener + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.scevent.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/sclistener/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/sclistener/URLClient.java new file mode 100644 index 0000000000..ff758e2496 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/sclistener/URLClient.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet.sclistener; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import com.sun.ts.tests.servlet.api.jakarta_servlet.sclistener.ContextListener; +import com.sun.ts.tests.servlet.api.jakarta_servlet.sclistener.TestServlet; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_plu_sclistener_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_plu_sclistener_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(ContextListener.class, TestServlet.class) + .addAsLibraries(javaArchive); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + + /* + * @testName: contextInitializedTest + * + * @assertion_ids: Servlet:JAVADOC:214 + * + * @test_Strategy: A ServletContext Listener is deployed and the listener + * write a message indicating so to a static log. The servlet reads the log + * and verifies the result + */ + @Test + public void contextInitializedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "contextInitializedTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/sclistener/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/sclistener/build.xml new file mode 100644 index 0000000000..61e6e11bfd --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/sclistener/build.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/sclistener/servlet_plu_sclistener_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/sclistener/servlet_plu_sclistener_web-fragment.xml new file mode 100644 index 0000000000..233f464d32 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/sclistener/servlet_plu_sclistener_web-fragment.xml @@ -0,0 +1,39 @@ + + + + + + com.sun.ts.tests.servlet.api.jakarta_servlet.sclistener.ContextListener + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.sclistener.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servlet/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servlet/URLClient.java new file mode 100644 index 0000000000..c953303603 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servlet/URLClient.java @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet.servlet; + +import com.sun.ts.tests.servlet.api.jakarta_servlet.servlet.CoreServletTest; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servlet.DoDestroyedTestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servlet.DoInit1TestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servlet.DoInit2TestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servlet.DoServiceTestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servlet.DoServletConfigTestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servlet.DoServletInfoTestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servlet.PUTestServlet; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_plu_servlet_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_plu_servlet_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(DoServletInfoTestServlet.class, DoDestroyedTestServlet.class, DoInit2TestServlet.class, + DoServletConfigTestServlet.class, PUTestServlet.class, DoServiceTestServlet.class, + DoInit1TestServlet.class, CoreServletTest.class ) + .addAsLibraries(javaArchive); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + + /* + * @testName: DoDestroyedTest + * + * @assertion_ids: Servlet:SPEC:5; Servlet:SPEC:6; + * + * @test_Strategy: Testing that destroy method is not called during service + * method execution + */ + @Test + public void DoDestroyedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "DoDestroyedTest"); + invoke(); + } + + /* + * @testName: DoInit1Test + * + * @assertion_ids: Servlet:SPEC:5; Servlet:SPEC:6; Servlet:SPEC:8; + * Servlet:JAVADOC:265; Servlet:SPEC:11; Servlet:SPEC:11.1; + * + * @test_Strategy: Validate a 404 is returned to the client if a permanent + * UnavailableException is thrown during servlet initialization. + */ + @Test + public void DoInit1Test() throws Exception { + TEST_PROPS.setProperty(TEST_NAME, "DoInit1Test"); + TEST_PROPS.setProperty(REQUEST, + "GET /servlet_js_servlet_web/DoInit1Test HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, NOT_FOUND); + invoke(); + } + + /* + * @testName: DoInit2Test + * + * @assertion_ids: Servlet:SPEC:5; Servlet:SPEC:6; Servlet:JAVADOC:263; + * + * @test_Strategy: Inside CoreServletTest, which is the parent servlet, we are + * implementing init() and setting a boolean variable to true. We'll check for + * the variables here in the DoInit2Test + */ + @Test + public void DoInit2Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "DoInit2Test"); + invoke(); + } + + /* + * @testName: DoServletConfigTest + * + * @assertion_ids: Servlet:SPEC:5; Servlet:SPEC:6; Servlet:JAVADOC:266; + * + * @test_Strategy: Create a servlet and test for the getServletConfig() method + * to be a non-null value and an initial paramter can be retrieved + */ + @Test + public void DoServletConfigTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "DoServletConfigTest"); + invoke(); + } + + /* + * @testName: DoServletInfoTest + * + * @assertion_ids: Servlet:SPEC:5; Servlet:SPEC:6; Servlet:JAVADOC:270; + * + * @test_Strategy: Create a servlet and test that information is returned + */ + @Test + public void DoServletInfoTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "DoServletInfoTest"); + invoke(); + } + + /* + * @testName: PUTest + * + * @assertion_ids: Servlet:SPEC:5; Servlet:SPEC:6; Servlet:JAVADOC:5; + * + * @test_Strategy: Create a servlet, throw UnavailableException and test if + * isPermanent() method is true + */ + @Test + public void PUTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "PUTest"); + invoke(); + } + + /* + * @testName: DoServiceTest + * + * @assertion_ids: Servlet:SPEC:5; Servlet:SPEC:6; Servlet:JAVADOC:263; + * Servlet:JAVADOC:267; + * + * @test_Strategy: Inside CoreServletTest, which is the parent servlet, we + * will override init method and assign some value to the String. We'll check + * for that value in the service method + */ + @Test + public void DoServiceTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "DoServiceTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servlet/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servlet/build.xml new file mode 100644 index 0000000000..42dba5cbb8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servlet/build.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servlet/servlet_plu_servlet_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servlet/servlet_plu_servlet_web-fragment.xml new file mode 100644 index 0000000000..af1e526581 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servlet/servlet_plu_servlet_web-fragment.xml @@ -0,0 +1,88 @@ + + + + + + DoServletInfoTestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.servlet.DoServletInfoTestServlet + + + DoDestroyedTestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.servlet.DoDestroyedTestServlet + + + DoInit2TestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.servlet.DoInit2TestServlet + + + DoServletConfigTestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.servlet.DoServletConfigTestServlet + + Language + Java + + + + PUTestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.servlet.PUTestServlet + + + DoServiceTestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.servlet.DoServiceTestServlet + + + DoInit1TestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.servlet.DoInit1TestServlet + + + DoServletInfoTestLogicalName + /DoServletInfoTest + + + DoDestroyedTestLogicalName + /DoDestroyedTest + + + DoInit2TestLogicalName + /DoInit2Test + + + DoServletConfigTestLogicalName + /DoServletConfigTest + + + PUTestLogicalName + /PUTest + + + DoServiceTestLogicalName + /DoServiceTest + + + DoInit1TestLogicalName + /DoInit1Test + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletconfig/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletconfig/URLClient.java new file mode 100644 index 0000000000..6abd2d5544 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletconfig/URLClient.java @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet.servletconfig; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletconfig.TestServlet; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_plu_servletconfig_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_plu_servletconfig_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestServlet.class) + .addAsLibraries(javaArchive); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + + /* + * @testName: getServletConfigInitParameterNamesTest + * + * @assertion_ids: Servlet:SPEC:7; Servlet:JAVADOC:266; Servlet:JAVADOC:261; + * + * @test_Strategy: Set init parameters in the web.xml file and check for the + * enumerated values in the servlet. + */ + @Test + public void getServletConfigInitParameterNamesTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletConfigInitParameterNames"); + invoke(); + } + + /* + * @testName: getServletConfigInitParameterTest + * + * @assertion_ids: Servlet:SPEC:7; Servlet:JAVADOC:266; Servlet:JAVADOC:259; + * + * @test_Strategy: Set init parameters in the web.xml file and check for the + * value in the servlet. + */ + @Test + public void getServletConfigInitParameterTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletConfigInitParameter"); + invoke(); + } + + /* + * @testName: getServletConfigInitParameterTestNull + * + * @assertion_ids: Servlet:SPEC:7; Servlet:JAVADOC:266; Servlet:JAVADOC:260; + * + * @test_Strategy: Set No init parameter anywhere named: + * "Nothing_is_set_for_Negative_compatibility_test_only" anywhere and check + * for the Verify that ServletConfig.getInitParameter(name) return null. + */ + @Test + public void getServletConfigInitParameterTestNull() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletConfigInitParameterNull"); + invoke(); + } + + /* + * @testName: getServletContextTest + * + * @assertion_ids: Servlet:SPEC:7; Servlet:JAVADOC:266; Servlet:JAVADOC:258; + * Servlet:JAVADOC:219; + * + * @test_Strategy: Try to get the ServletContext for this servlet itself + */ + @Test + public void getServletContextTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletContext"); + invoke(); + } + + /* + * @testName: getServletNameTest + * + * @assertion_ids: Servlet:SPEC:7; Servlet:JAVADOC:266; Servlet:JAVADOC:257; + * + * @test_Strategy: Try to get the ServletName for this servlet itself + */ + @Test + public void getServletNameTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletName"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletconfig/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletconfig/build.xml new file mode 100644 index 0000000000..e7883a041e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletconfig/build.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletconfig/servlet_plu_servletconfig_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletconfig/servlet_plu_servletconfig_web-fragment.xml new file mode 100644 index 0000000000..c9bd5ba7d1 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletconfig/servlet_plu_servletconfig_web-fragment.xml @@ -0,0 +1,44 @@ + + + + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.servletconfig.TestServlet + + Team + WebAccess + + + org + sun + + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletcontext/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletcontext/URLClient.java new file mode 100644 index 0000000000..d80c1945d9 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletcontext/URLClient.java @@ -0,0 +1,417 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet.servletcontext; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext.TestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext.GetNamedDispatcherTestServlet; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_plu_servletcontext_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_plu_servletcontext_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(GetNamedDispatcherTestServlet.class, TestServlet.class) + .addAsLibraries(javaArchive); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: GetServletTempDirTest + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:SPEC:19.1; + * + * @test_Strategy: Servlet verify's that the value from the + * ServletContext.getAttribute("jakarta.servlet.temp.dir") returns non-null + * value that points an exsiting directory. + */ + @Test + public void GetServletTempDirTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletTempDir"); + invoke(); + } + + /* + * @testName: GetMajorVersionTest + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:220; + * + * @test_Strategy: Test the ServletContext.getMajorVersion() for this servlet + * itself + */ + @Test + public void GetMajorVersionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getMajorVersion"); + invoke(); + } + + /* + * @testName: GetMinorVersionTest + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:221; + * + * @test_Strategy: Test the ServletContext.getMinorVersion() for this servlet + * itself + */ + @Test + public void GetMinorVersionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getMinorVersion"); + invoke(); + } + + /* + * @testName: GetMimeTypeTest + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:222; + * + * @test_Strategy: Test the ServletContext.getMimeType() for this servlet + * itself + */ + @Test + public void GetMimeTypeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getMimeType"); + invoke(); + } + + /* + * @testName: GetMimeType_1Test + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:223; + * + * @test_Strategy: A negative test for getMimeType(). Test the + * ServletContext.getMimeType() for this servlet itself + */ + @Test + public void GetMimeType_1Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "getMimeType_1"); + invoke(); + } + + /* + * @testName: GetRealPathTest + * + * @assertion_ids: Servlet:SPEC:90; Servlet:SPEC:92.2; Servlet:JAVADOC:124; + * Servlet:JAVADOC:258; Servlet:JAVADOC:241; + * + * @test_Strategy: Test the ServletContext.getRealPath() for this servlet + * itself + */ + @Test + public void GetRealPathTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getRealPath"); + invoke(); + } + + /* + * @testName: GetResourceAsStream_1Test + * + * @assertion_ids: Servlet:SPEC:90; Servlet:SPEC:92.2; Servlet:JAVADOC:124; + * Servlet:JAVADOC:258; Servlet:JAVADOC:229; + * + * @test_Strategy: A negative test for getResourceAsStream() method + */ + @Test + public void GetResourceAsStream_1Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "getResourceAsStream_1"); + invoke(); + } + + /* + * @testName: GetResource_1Test + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:225; + * + * @test_Strategy: A negative test for ServletContext.getResource(String) + * method + */ + @Test + public void GetResource_1Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "getResource_1"); + invoke(); + } + + /* + * @testName: GetResource_2Test + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:227; + * + * @test_Strategy: A negative test for ServletContext.getResource(String path) + * if path does not start with /, MalformedURLException should be thrown + */ + @Test + public void GetResource_2Test() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, ""); + TEST_PROPS.setProperty(APITEST, "getResource_2"); + invoke(); + } + + /* + * @testName: GetServerInfoTest + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:242; + * + * @test_Strategy: Test for ServletContext.getServerInfo() method + */ + @Test + public void GetServerInfoTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServerInfo"); + invoke(); + } + + /* + * @testName: ServletContextGetAttributeTest + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:250; Servlet:JAVADOC:247; + * + * @test_Strategy: Try to get the attributes for this servlet itself + */ + @Test + public void ServletContextGetAttributeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "servletContextGetAttribute"); + invoke(); + } + + /* + * @testName: ServletContextGetAttribute_1Test + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:248; + * + * @test_Strategy: A negative test for ServletContext.getAttribute(). Test for + * null attribute values for this servlet itself + */ + @Test + public void ServletContextGetAttribute_1Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "servletContextGetAttribute_1"); + invoke(); + } + + /* + * @testName: ServletContextGetContextTest + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:219; + * + * @test_Strategy: Test for ServletContext object for this servlet itself + */ + @Test + public void ServletContextGetContextTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "servletContextGetContext"); + invoke(); + } + + /* + * @testName: ServletContextGetInitParameterNamesTest + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:245; + * + * @test_Strategy: Test the ServletContext.getInitParameterNames() for this + * servlet itself + */ + @Test + public void ServletContextGetInitParameterNamesTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "servletContextGetInitParameterNames"); + invoke(); + } + + /* + * @testName: ServletContextGetInitParameterTest + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:243; + * + * @test_Strategy: Test the ServletContext.getInitParameter(String) for this + * servlet itself + */ + @Test + public void ServletContextGetInitParameterTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "servletContextGetInitParameter"); + invoke(); + } + + /* + * @testName: ServletContextGetInitParameterTestNull + * + * @assertion_ids: Servlet:JAVADOC:125; Servlet:JAVADOC:244; + * + * @test_Strategy: Test the ServletContext.getInitParameter(String name) + * returns null when name(nothing_is_set_here_negative_compatibility_test) is + * not set + */ + @Test + public void ServletContextGetInitParameterTestNull() throws Exception { + TEST_PROPS.setProperty(APITEST, "servletContextGetInitParameterNull"); + invoke(); + } + + /* + * @testName: ServletContextRemoveAttributeTest + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:250; Servlet:JAVADOC:254; Servlet:JAVADOC:248; + * + * @test_Strategy: Test for ServletContext.removeAttribute() method + */ + @Test + public void ServletContextRemoveAttributeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "servletContextRemoveAttribute"); + invoke(); + } + + /* + * @testName: ServletContextSetAttributeTest + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:250; Servlet:JAVADOC:247; + * + * @test_Strategy: Test for ServletContext.setAttribute() method + */ + @Test + public void ServletContextSetAttributeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "servletContextSetAttribute"); + invoke(); + } + + /* + * @testName: ServletContextSetAttribute_1Test + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:250; Servlet:JAVADOC:251; Servlet:JAVADOC:247; + * + * @test_Strategy: Test for ServletContext.setAttribute() method Call + * ServletContext.setAttribute(String Attribute, Object value) twice with the + * same Attribute, verify that second value replace the first Attribute value. + */ + @Test + public void ServletContextSetAttribute_1Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "servletContextSetAttribute_1"); + invoke(); + } + + /* + * @testName: ServletContextSetAttribute_2Test + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:250; Servlet:JAVADOC:253; Servlet:JAVADOC:248; + * + * @test_Strategy: Test for ServletContext.setAttribute() method Set Attribute + * to null and verify getAttribute return null. + */ + @Test + public void ServletContextSetAttribute_2Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "servletContextSetAttribute_2"); + invoke(); + } + + /* + * @testName: ServletContextGetAttributeNamesTest + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:250; Servlet:JAVADOC:249; + * + * @test_Strategy: Servlet retrieves attributes which it set itself + */ + @Test + public void ServletContextGetAttributeNamesTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "servletContextGetAttributeNames"); + invoke(); + } + + /* + * @testName: ServletContextGetRequestDispatcherTest + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:230; + * + * @test_Strategy: Test the ServletContext.getRequestDispatcher(String) for + * this servlet itself + */ + @Test + public void ServletContextGetRequestDispatcherTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "servletContextGetRequestDispatcher"); + invoke(); + } + + /* + * @testName: GetNamedDispatcherTest + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:232; + * + * @test_Strategy: Servlet verify's that the result from the + * getNamedDispatcher call and the getServletName call are the same for the + * servlet. + */ + @Test + public void GetNamedDispatcherTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getNamedDispatcher"); + invoke(); + } + + /* + * @testName: GetNamedDispatcher_1Test + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:233; + * + * @test_Strategy: Servlet verify's that the result from the + * getNamedDispatcher call return null with non-existent path. Negative test. + */ + @Test + public void GetNamedDispatcher_1Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "getNamedDispatcher_1"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletcontext/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletcontext/build.xml new file mode 100644 index 0000000000..70faad436b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletcontext/build.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletcontext/servlet_plu_servletcontext_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletcontext/servlet_plu_servletcontext_web-fragment.xml new file mode 100644 index 0000000000..6dfd479821 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletcontext/servlet_plu_servletcontext_web-fragment.xml @@ -0,0 +1,56 @@ + + + + + + EDITOR + VI + + + OS + ULTASPARC + + + TestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext.TestServlet + + + GetNamedDispatcherTest + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext.GetNamedDispatcherTestServlet + + + TestLogicalName + /TestServlet + + + GetNamedDispatcherTest + /GetNamedDispatcherTest + + + 54 + + + class + application/x-java-class + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletcontext30/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletcontext30/URLClient.java new file mode 100644 index 0000000000..f38946d1b8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletcontext30/URLClient.java @@ -0,0 +1,530 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet.servletcontext30; + +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddFilterClass; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddFilterNotFound; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddFilterString; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddSCAttributeListenerClass; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddSCAttributeListenerString; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddSCListenerClass; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddSCListenerString; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddSRAttributeListenerClass; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddSRAttributeListenerString; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddSRListenerClass; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddSRListenerString; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddServletClass; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddServletNotFound; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.BadFilter; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.BadListener; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.BadServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.CreateFilter; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.CreateSCAttributeListener; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.CreateSCListener; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.CreateSRAttributeListener; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.CreateSRListener; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.CreateServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.DuplicateFilterClass; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.DuplicateFilterString; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.DuplicateServletClass; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.DuplicateServletString; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.FilterTestServlet; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.TestListener; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.TestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.AddServletString; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_plu_servletcontext30_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_plu_servletcontext30.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(AddFilterClass.class, AddFilterNotFound.class, AddFilterString.class, AddSCAttributeListenerClass.class, + AddSCAttributeListenerString.class, AddSCListenerClass.class, AddSCListenerString.class, AddServletClass.class, + AddServletNotFound.class, AddServletString.class, AddSRAttributeListenerClass.class, AddSRAttributeListenerString.class, + AddSRListenerClass.class, AddSRListenerString.class, BadFilter.class, BadListener.class, BadServlet.class, + CreateFilter.class, CreateSCAttributeListener.class, CreateSCListener.class, CreateServlet.class, CreateSRAttributeListener.class, + CreateSRListener.class, DuplicateFilterClass.class, DuplicateFilterString.class, DuplicateServletClass.class, DuplicateServletString.class, + FilterTestServlet.class, TestListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("web.xml")) + .addAsLibraries(javaArchive); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * Test setup; In Deployment Descriptor, a Servlet TestServlet and Listener + * TestListener; TestListener extends ServletContextListener; + * + * In TestListener, three Servlets are added using the following methods: - + * ServletContext.addServlet(String, String); - + * ServletContext.addServlet(String, Class); - + * ServletContext.createServlet(Class); + * + * In TestListener, three Filters are added using the following methods: - + * ServletContext.addFilter(String, String); - + * ServletContext.addFilter(String, Class); - + * ServletContext.createServlet(Class); + * + * In TestListener, three Listeners are added using the following methods: - + * ServletContext.addListener(Listener Class) - + * ServletContext.addListener(Listener name) - EventListener listener = + * ServletContext.createListener(class); ServletContext.addListener(listener); + * for all three following Listeners: - ServletContextAttributeListener - + * ServletRequestListener - ServletRequestAttributesListener + */ + /* + * @testName: getContextPathTest + * + * @assertion_ids: Servlet:JAVADOC:124; Servlet:JAVADOC:258; + * Servlet:JAVADOC:637; Servlet:JAVADOC:671.1; Servlet:JAVADOC:671.2; + * Servlet:JAVADOC:671.3; Servlet:JAVADOC:672.1; Servlet:JAVADOC:672.2; + * Servlet:JAVADOC:672.3; Servlet:JAVADOC:673.1; Servlet:JAVADOC:673.2; + * Servlet:JAVADOC:673.3; Servlet:JAVADOC:679; + * + * @test_Strategy: In TestServlet verify that the result from the + * ServletContext.getServletContextPath call returns the context path. + * + * In client verify that all Listeners are added correctly and invoked in the + * order added. + */ + @Test + public void getContextPathTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getContextPathTest"); + TEST_PROPS.setProperty(SEARCH_STRING, + "AddSRListenerClass_INVOKED" + "|AddSRListenerString_INVOKED" + + "|CreateSRListener_INVOKED" + "|AttributeAddedClass" + + "|AttributeAddedString"); + invoke(); + } + + /* + * @testName: testAddServletString + * + * @assertion_ids: Servlet:JAVADOC:655; Servlet:JAVADOC:668; + * Servlet:JAVADOC:671.1; Servlet:JAVADOC:671.2; Servlet:JAVADOC:671.3; + * Servlet:JAVADOC:672.1; Servlet:JAVADOC:672.2; Servlet:JAVADOC:672.3; + * Servlet:JAVADOC:673.1; Servlet:JAVADOC:673.2; Servlet:JAVADOC:673.3; + * Servlet:JAVADOC:674; Servlet:JAVADOC:679; Servlet:JAVADOC:696; + * + * @test_Strategy: Create a ServletContextListener, in which, 1. create a + * Servlet by calling ServletContext.addServlet(String, String), 2. mapping + * the new Servlet programmatically. 3. create a Filter by + * ServletContext.addFilter(String, String) 4. map the filter to the new + * Servlet programmatically for FORWARD only 5. client send a request to the + * new servlet, Verify in client that request goes through and Filter is NOT + * invoked. Verify in client that all Listeners are added correctly and + * invoked in the order added. + */ + @Test + public void testAddServletString() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/addServletString HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, + "ADD_FILTER_STRING_INVOKED"); + TEST_PROPS.setProperty(SEARCH_STRING, + "AddSRListenerClass_INVOKED" + "|AddSRListenerString_INVOKED" + + "|CreateSRListener_INVOKED" + "|SCAttributeAddedClass:" + + "|SCAttributeAddedString:" + "|SCAttributeAdded:"); + invoke(); + } + + /* + * @testName: testAddFilterString + * + * @assertion_ids: Servlet:JAVADOC:655; Servlet:JAVADOC:668; + * Servlet:JAVADOC:671.1; Servlet:JAVADOC:671.2; Servlet:JAVADOC:671.3; + * Servlet:JAVADOC:672.1; Servlet:JAVADOC:672.2; Servlet:JAVADOC:672.3; + * Servlet:JAVADOC:673.1; Servlet:JAVADOC:673.2; Servlet:JAVADOC:673.3; + * Servlet:JAVADOC:674; Servlet:JAVADOC:679; Servlet:JAVADOC:696; + * + * @test_Strategy: Create a ServletContextListener, in which, 1. create a + * Servlet by calling ServletContext.addServlet(String, String), 2. mapping + * the new Servlet programmatically. 3. create a Filter by + * ServletContext.addFilter(String, String) 4. map the filter to the new + * Servlet programmatically for FORWARD only 5. client send a request to + * another servlet, 6. which then forward to the newly created Servlet Verify + * in client that request goes through and Filter IS invoked. Verify in client + * that all Listeners are added correctly and invoked in the order added. + */ + @Test + public void testAddFilterString() throws Exception { + TEST_PROPS.setProperty(APITEST, "testAddFilterString"); + TEST_PROPS.setProperty(SEARCH_STRING, + "AddServletString" + "|AddSRListenerClass_INVOKED" + + "|AddSRListenerString_INVOKED" + "|CreateSRListener_INVOKED" + + "|ADD_FILTER_STRING_INVOKED" + "|SCAttributeAddedClass:" + + "|SCAttributeAddedString:" + "|SCAttributeAdded:"); + invoke(); + } + + /* + * @testName: testAddServletClass + * + * @assertion_ids: Servlet:JAVADOC:655; Servlet:JAVADOC:670; + * Servlet:JAVADOC:671.1; Servlet:JAVADOC:671.2; Servlet:JAVADOC:671.3; + * Servlet:JAVADOC:672.1; Servlet:JAVADOC:672.2; Servlet:JAVADOC:672.3; + * Servlet:JAVADOC:673.1; Servlet:JAVADOC:673.2; Servlet:JAVADOC:673.3; + * Servlet:JAVADOC:676; Servlet:JAVADOC:679; Servlet:JAVADOC:696; + * + * @test_Strategy: Create a ServletContextListener, in which, 1. create a + * Servlet by calling ServletContext.addServlet(String, Class), 2. mapping the + * new Servlet programmatically. 3. create a Filter by + * ServletContext.addFilter(String, Class) 4. map the filter to the new + * Servlet programmatically for REQUEST only 5. client send a request to the + * new servlet, Verify in client that request goes through and Filter is + * invoked. Verify in client that all Listeners are added correctly and + * invoked in the order added. + */ + @Test + public void testAddServletClass() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/addServletClass HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, + "AddServletClass" + "|AddSRListenerClass_INVOKED" + + "|AddSRListenerString_INVOKED" + "|CreateSRListener_INVOKED" + + "|ADD_FILTER_CLASS_INVOKED" + "|SCAttributeAddedClass:" + + "|SCAttributeAddedString:" + "|SCAttributeAdded:"); + invoke(); + } + + /* + * @testName: testAddFilterClass + * + * @assertion_ids: Servlet:JAVADOC:655; Servlet:JAVADOC:670; + * Servlet:JAVADOC:671.1; Servlet:JAVADOC:671.2; Servlet:JAVADOC:671.3; + * Servlet:JAVADOC:672.1; Servlet:JAVADOC:672.2; Servlet:JAVADOC:672.3; + * Servlet:JAVADOC:673.1; Servlet:JAVADOC:673.2; Servlet:JAVADOC:673.3; + * Servlet:JAVADOC:676; Servlet:JAVADOC:679; Servlet:JAVADOC:696; + * + * @test_Strategy: Create a ServletContextListener, in which, 1. create a + * Servlet by calling ServletContext.addServlet(String, Class), 2. mapping the + * new Servlet programmatically. 3. create a Filter by + * ServletContext.addFilter(String, Class) 4. map the filter to the new + * Servlet programmatically for REQUEST only 5. client send a request to + * another servlet, 6. which then dispatch by include to the newly created + * Servlet Verify in client that request goes through and Filter IS NOT + * invoked. Verify in client that all Listeners are added correctly and + * invoked in the order added. + */ + @Test + public void testAddFilterClass() throws Exception { + TEST_PROPS.setProperty(APITEST, "testAddFilterClass"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, + "ADD_FILTER_CLASS_INVOKED"); + TEST_PROPS.setProperty(SEARCH_STRING, + "AddServletClass" + "|AddSRListenerClass_INVOKED" + + "|AddSRListenerString_INVOKED" + "|CreateSRListener_INVOKED" + + "|SCAttributeAddedClass" + "|SCAttributeAddedString"); + invoke(); + } + + /* + * @testName: testAddServlet + * + * @assertion_ids: Servlet:JAVADOC:655; Servlet:JAVADOC:669; + * Servlet:JAVADOC:670; Servlet:JAVADOC:671.1; Servlet:JAVADOC:671.2; + * Servlet:JAVADOC:671.3; Servlet:JAVADOC:672.1; Servlet:JAVADOC:672.2; + * Servlet:JAVADOC:672.3; Servlet:JAVADOC:673.1; Servlet:JAVADOC:673.2; + * Servlet:JAVADOC:673.3; Servlet:JAVADOC:675; Servlet:JAVADOC:677; + * Servlet:JAVADOC:679; Servlet:JAVADOC:681; Servlet:JAVADOC:696; + * + * @test_Strategy: Create a ServletContextListener, in which, 1. Create a + * Servlet instance using ServletContext.createServlet; 2. Add the Servlet + * instance: ServletContext.addServlet(String, Servlet), 3. mapping the new + * Servlet programmatically. 4. create a Filter instance by + * ServletContext.createFilter; 5 Add the Filter instance: + * ServletContext.addFilter(String, Filter) 6. map the filter to the new + * Servlet programmatically for REQUEST only 7. client send a request to the + * new servlet, Verify in client that request goes through and Filter is + * invoked. Verify in client that all Listeners are added correctly and + * invoked in the order added. + */ + @Test + public void testAddServlet() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/createServlet HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, + "CreateServlet" + "|AddSRListenerClass_INVOKED" + + "|AddSRListenerString_INVOKED" + "|CreateSRListener_INVOKED" + + "|SCAttributeAddedClass:" + "|SCAttributeAddedString:" + + "|SCAttributeAdded:" + "|CREATE_FILTER_INVOKED"); + + invoke(); + } + + /* + * @testName: testAddFilterForward + * + * @assertion_ids: Servlet:JAVADOC:655; Servlet:JAVADOC:669; + * Servlet:JAVADOC:670; Servlet:JAVADOC:671.1; Servlet:JAVADOC:671.2; + * Servlet:JAVADOC:671.3; Servlet:JAVADOC:672.1; Servlet:JAVADOC:672.2; + * Servlet:JAVADOC:672.3; Servlet:JAVADOC:673.1; Servlet:JAVADOC:673.2; + * Servlet:JAVADOC:673.3; Servlet:JAVADOC:675; Servlet:JAVADOC:677; + * Servlet:JAVADOC:679; Servlet:JAVADOC:681; Servlet:JAVADOC:696; + * + * @test_Strategy: Create a ServletContextListener, in which, 1. Create a + * Servlet instance using ServletContext.createServlet; 2. Add the Servlet + * instance: ServletContext.addServlet(String, Servlet), 3. mapping the new + * Servlet programmatically. 4. create a Filter instance by + * ServletContext.createFilter; 5 Add the Filter instance: + * ServletContext.addFilter(String, Filter) 6. map the filter to the new + * Servlet programmatically for REQUEST only 7. client send a request to the + * new servlet via FORWARD, Verify in client that request does go through and + * Filter is NOT invoked. Verify in client that all Listeners are added + * correctly and invoked in the order added. + */ + @Test + public void testAddFilterForward() throws Exception { + TEST_PROPS.setProperty(APITEST, "testCreateFilterForward"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "CREATE_FILTER_INVOKED"); + TEST_PROPS.setProperty(SEARCH_STRING, + "CreateServlet" + "|AddSRListenerClass_INVOKED" + + "|AddSRListenerString_INVOKED" + "|CreateSRListener_INVOKED" + + "|SCAttributeAddedClass:" + "|SCAttributeAddedString:" + + "|SCAttributeAdded:"); + invoke(); + } + + /* + * @testName: testAddFilterInclude + * + * @assertion_ids: Servlet:JAVADOC:655; Servlet:JAVADOC:669; + * Servlet:JAVADOC:670; Servlet:JAVADOC:671.1; Servlet:JAVADOC:671.2; + * Servlet:JAVADOC:671.3; Servlet:JAVADOC:672.1; Servlet:JAVADOC:672.2; + * Servlet:JAVADOC:672.3; Servlet:JAVADOC:673.1; Servlet:JAVADOC:673.2; + * Servlet:JAVADOC:673.3; Servlet:JAVADOC:675; Servlet:JAVADOC:677; + * Servlet:JAVADOC:679; Servlet:JAVADOC:681; Servlet:JAVADOC:696; + * + * @test_Strategy: Create a ServletContextListener, in which, 1. Create a + * Servlet instance using ServletContext.createServlet; 2. Add the Servlet + * instance: ServletContext.addServlet(String, Servlet), 3. mapping the new + * Servlet programmatically. 4. create a Filter instance by + * ServletContext.createFilter; 5 Add the Filter instance: + * ServletContext.addFilter(String, Filter) 6. map the filter to the new + * Servlet programmatically for REQUEST only 7. client send a request to the + * new servlet via INCLUDE, Verify in client that request does go through and + * Filter is NOT invoked. Verify in client that all Listeners are added + * correctly and invoked in the order added. + */ + @Test + public void testAddFilterInclude() throws Exception { + TEST_PROPS.setProperty(APITEST, "testCreateFilterInclude"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "CREATE_FILTER_INVOKED"); + TEST_PROPS.setProperty(SEARCH_STRING, + "CreateServlet" + "|AddSRListenerClass_INVOKED" + + "|AddSRListenerString_INVOKED" + "|CreateSRListener_INVOKED" + + "|SCAttributeAddedClass:" + "|SCAttributeAddedString:" + + "|SCAttributeAdded:"); + invoke(); + } + + /* + * @testName: testAddServletNotFound + * + * @assertion_ids: Servlet:JAVADOC:655; Servlet:JAVADOC:670; + * Servlet:JAVADOC:671.1; Servlet:JAVADOC:671.2; Servlet:JAVADOC:671.3; + * Servlet:JAVADOC:672.1; Servlet:JAVADOC:672.2; Servlet:JAVADOC:672.3; + * Servlet:JAVADOC:673.1; Servlet:JAVADOC:673.2; Servlet:JAVADOC:673.3; + * Servlet:JAVADOC:676; Servlet:JAVADOC:679; Servlet:JAVADOC:696; + * + * @test_Strategy: Create a ServletContextListener, in which, 1. create a + * Servlet by calling ServletContext.addServlet(String, Class), 2. mapping the + * new Servlet programmatically to multiple URLs, one of them is used by + * another Servlet already. 3. create a Filter by + * ServletContext.addFilter(String, Class) 4. map the filter to the new + * Servlet programmatically for all DispatcherType 5. client send a request to + * the new servlet, Verify in client that request does NOT go through and + * Filter is NOT invoked. + */ + @Test + public void testAddServletNotFound() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/addServletNotFound HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, NOT_FOUND); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, + "AddServletNotFound|ADD_FILTER_NOTFOUND"); + invoke(); + } + + /* + * @testName: testCreateSRAListener + * + * @assertion_ids: Servlet:JAVADOC:655; Servlet:JAVADOC:669; + * Servlet:JAVADOC:670; Servlet:JAVADOC:671.1; Servlet:JAVADOC:671.2; + * Servlet:JAVADOC:671.3; Servlet:JAVADOC:672.1; Servlet:JAVADOC:672.2; + * Servlet:JAVADOC:672.3; Servlet:JAVADOC:673.1; Servlet:JAVADOC:673.2; + * Servlet:JAVADOC:673.3; Servlet:JAVADOC:675; Servlet:JAVADOC:677; + * Servlet:JAVADOC:679; Servlet:JAVADOC:681; Servlet:JAVADOC:696; + * + * @test_Strategy: Create a ServletContextListener, in which, one + * ServletAttributeListener, one ServletRequestListener one + * ServletRequestAttributeListener are added: 1. Create a Servlet instance + * using ServletContext.createServlet; 2. Add the Servlet instance: + * ServletContext.addServlet(String, Servlet), 3. mapping the new Servlet + * programmatically. 4. create a Filter instance by + * ServletContext.createFilter; 5 Add the Filter instance: + * ServletContext.addFilter(String, Filter) 6. map the filter to the new + * Servlet programmatically for REQUEST only 7. client send a request to + * another servlet, in which, ServletRequestAttributes are added, then + * dispatch to the new servlet via FORWARD Verify in client that - create + * Listener works - request does NOT through and Filter is NOT invoked. - all + * Listeners are added correctly and invoked in the order added. + */ + @Test + public void testCreateSRAListener() throws Exception { + TEST_PROPS.setProperty(APITEST, "testCreateSRAListener"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "CREATE_FILTER_INVOKED"); + TEST_PROPS.setProperty(SEARCH_STRING, + "AddServletClass" + "|AddSRListenerClass_INVOKED" + + "|AddSRListenerString_INVOKED" + "|CreateSRListener_INVOKED" + + "|SCAttributeAddedClass:" + "|SCAttributeAddedString:" + + "|SCAttributeAdded:" + "|SRAttributeAddedClass:" + + "|SRAttributeAddedString:" + "|SRAttributeAdded:"); + invoke(); + } + + /* + * @testName: negativeCreateTests + * + * @assertion_ids: Servlet:JAVADOC:243; Servlet:JAVADOC:678; + * Servlet:JAVADOC:680; Servlet:JAVADOC:682; Servlet:JAVADOC:694; + * + * @test_Strategy: 1. Create a Servlet which throws ServletException at init; + * 2. Create a Filter which throws ServletException at init 3. Create a + * EventListener which throws NullPointerException at init + * + * Create a ServletContextListener, in which: 4. Call + * ServletContext.createFilter(Filter) which should fail; 5. Call + * ServletContext.createServlet(Servlet) which fails 6. Call + * ServletContext.createListener(EventListener) which fails 7. Call + * ServletContext.setInitParameter to pass information about status on 4-6 8. + * In another Servlet, get all information stored in ServletContext + * InitParameter 9. Send a request to the new Servlet Verify that - + * createServlet failed accordingly; - createFilter failed accordingly; - + * createListener failed accordingly; - setInitParameter works properly + */ + @Test + public void negativeCreateTests() throws Exception { + TEST_PROPS.setProperty(APITEST, "negativeCreateTests"); + TEST_PROPS.setProperty(SEARCH_STRING, + "SERVLET_TEST=TRUE" + "|FILTER_TEST=TRUE" + "|LISTENER_TEST=TRUE"); + + invoke(); + } + + /* + * @testName: getEffectiveMajorVersionTest + * + * @assertion_ids: Servlet:JAVADOC:685; + * + * @test_Strategy: Create a Servlet, in which call + * ServletContext.getEffectiveMajorVersion() Verify that 5 is returned. + */ + @Test + public void getEffectiveMajorVersionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getEffectiveMajorVersionTest"); + TEST_PROPS.setProperty(SEARCH_STRING, "EFFECTIVEMAJORVERSION=5;"); + invoke(); + } + + /* + * @testName: getEffectiveMinorVersionTest + * + * @assertion_ids: Servlet:JAVADOC:686; + * + * @test_Strategy: Create a Servlet, in which call + * ServletContext.getEffectiveMinorVersion() Verify that 0 is returned. + */ + @Test + public void getEffectiveMinorVersionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getEffectiveMinorVersionTest"); + TEST_PROPS.setProperty(SEARCH_STRING, "EFFECTIVEMINORVERSION=0;"); + invoke(); + } + + /* + * @testName: getDefaultSessionTrackingModes + * + * @assertion_ids: Servlet:JAVADOC:684; + * + * @test_Strategy: Create a Servlet, in which call + * ServletContext.getDefaultSessionTrackingModes() Verify it works. + */ + @Test + public void getDefaultSessionTrackingModes() throws Exception { + TEST_PROPS.setProperty(APITEST, "getDefaultSessionTrackingModes"); + invoke(); + } + + /* + * @testName: sessionTrackingModesValueOfTest + * + * @assertion_ids: Servlet:JAVADOC:747; + * + * @test_Strategy: Create a Servlet, verify SessionTrackingModes.valueOf() + * works + */ + @Test + public void sessionTrackingModesValueOfTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "sessionTrackingModesValueOfTest"); + invoke(); + } + + /* + * @testName: sessionTrackingModesValuesTest + * + * @assertion_ids: Servlet:JAVADOC:748; + * + * @test_Strategy: Create a Servlet, verify SessionTrackingModes.values() + * works + */ + @Test + public void sessionTrackingModesValuesTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "sessionTrackingModesValuesTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletcontext30/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletcontext30/build.xml new file mode 100644 index 0000000000..ebfca0d304 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletcontext30/build.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletcontext30/servlet_plu_servletcontext30_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletcontext30/servlet_plu_servletcontext30_web-fragment.xml new file mode 100644 index 0000000000..cd3d31a632 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletcontext30/servlet_plu_servletcontext30_web-fragment.xml @@ -0,0 +1,39 @@ + + + + + + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.TestListener + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.servletcontext30.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletcontext30/web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletcontext30/web.xml new file mode 100644 index 0000000000..e685fa1c6f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletcontext30/web.xml @@ -0,0 +1,25 @@ + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletexception/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletexception/URLClient.java new file mode 100644 index 0000000000..1d7af29805 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletexception/URLClient.java @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet.servletexception; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletexception.TestServlet; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_plu_servletexception_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_plu_servletexception_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestServlet.class) + .addAsLibraries(javaArchive); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: getRootCauseTest + * + * @assertion_ids: Servlet:SPEC:83; Servlet:JAVADOC:108; Servlet:JAVADOC:109; + * Servlet:JAVADOC:8; + * + * @test_Strategy: A Test for getRootCause method + */ + @Test + public void getRootCauseTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getRootCause"); + invoke(); + } + + /* + * @testName: servletExceptionConstructor1Test + * + * @assertion_ids: Servlet:SPEC:83; Servlet:JAVADOC:105; + * + * @test_Strategy: A Test for ServletException() constructor method + */ + @Test + public void servletExceptionConstructor1Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "servletExceptionConstructor1"); + invoke(); + } + + /* + * @testName: servletExceptionConstructor2Test + * + * @assertion_ids: Servlet:SPEC:83; Servlet:JAVADOC:106; + * + * @test_Strategy: A Test for ServletException(String) constructor method + */ + @Test + public void servletExceptionConstructor2Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "servletExceptionConstructor2"); + invoke(); + } + + /* + * @testName: servletExceptionConstructor3Test + * + * @assertion_ids: Servlet:SPEC:83; Servlet:JAVADOC:108; Servlet:JAVADOC:109; + * Servlet:JAVADOC:8; + * + * @test_Strategy: A Test for ServletException(Throwable) constructor method + */ + @Test + public void servletExceptionConstructor3Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "servletExceptionConstructor3"); + invoke(); + + } + + /* + * @testName: servletExceptionConstructor4Test + * + * @assertion_ids: Servlet:SPEC:83; Servlet:JAVADOC:107; Servlet:JAVADOC:109; + * Servlet:JAVADOC:8; + * + * @test_Strategy: A Test for ServletException(String,Throwable) constructor + * method + */ + @Test + public void servletExceptionConstructor4Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "servletExceptionConstructor4"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletexception/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletexception/build.xml new file mode 100644 index 0000000000..03da0c765e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletexception/build.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletexception/servlet_plu_servletexception_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletexception/servlet_plu_servletexception_web-fragment.xml new file mode 100644 index 0000000000..dc1072849b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletexception/servlet_plu_servletexception_web-fragment.xml @@ -0,0 +1,36 @@ + + + + + + TestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.servletexception.TestServlet + + + TestLogicalName + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletinputstream/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletinputstream/URLClient.java new file mode 100644 index 0000000000..efc0df9501 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletinputstream/URLClient.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet.servletinputstream; + +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletinputstream.ReadLineTestServlet; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.common.util.Data; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_plu_servletinputstream_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_plu_servletinputstream_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(ReadLineTestServlet.class) + .addAsLibraries(javaArchive); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: readLineTest + * + * @assertion_ids: Servlet:JAVADOC:103 + * + * @test_Strategy: Client posts a request to the servlet and the servlet reads + * and verifies the correct behavior for readLine() + * + */ + @Test + public void readLineTest() throws Exception { + String testName = "readLineTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, + "POST " + getContextRoot() + "/" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(CONTENT, "test data"); + TEST_PROPS.setProperty(SEARCH_STRING, Data.PASSED); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletinputstream/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletinputstream/build.xml new file mode 100644 index 0000000000..dad5859f94 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletinputstream/build.xml @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletinputstream/servlet_plu_servletinputstream_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletinputstream/servlet_plu_servletinputstream_web-fragment.xml new file mode 100644 index 0000000000..c908ccdeb2 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletinputstream/servlet_plu_servletinputstream_web-fragment.xml @@ -0,0 +1,36 @@ + + + + + + readLineTest + com.sun.ts.tests.servlet.api.jakarta_servlet.servletinputstream.ReadLineTestServlet + + + readLineTest + /readLineTest + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletoutputstream/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletoutputstream/URLClient.java new file mode 100644 index 0000000000..8eddad6d40 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletoutputstream/URLClient.java @@ -0,0 +1,305 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet.servletoutputstream; + +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletoutputstream.TestServlet; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_plu_servletoutputstream_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_plu_servletoutputstream_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestServlet.class) + .addAsLibraries(javaArchive); + + } + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + + /* + * @testName: print_StringTest + * + * @assertion_ids: Servlet:JAVADOC:140; Servlet:JAVADOC:73; + * + * @test_Strategy: Test for print(java.lang.String s) method + */ + @Test + public void print_StringTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "some text"); + + TEST_PROPS.setProperty(APITEST, "print_StringTest"); + invoke(); + } + + /* + * @testName: print_booleanTest + * + * @assertion_ids: Servlet:JAVADOC:140; Servlet:JAVADOC:75; + * + * @test_Strategy: Test for print(boolean b) method + */ + @Test + public void print_booleanTest() throws Exception { + String s = Boolean.TRUE.toString(); + + StringBuffer ss = new StringBuffer(s); + ss = ss.append(s); + + TEST_PROPS.setProperty(SEARCH_STRING, ss.toString()); + + TEST_PROPS.setProperty(APITEST, "print_booleanTest"); + invoke(); + } + + /* + * @testName: print_charTest + * + * @assertion_ids: Servlet:JAVADOC:140; Servlet:JAVADOC:77; + * + * @test_Strategy: Test for print(char c) method + */ + @Test + public void print_charTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "TEXT"); + + TEST_PROPS.setProperty(APITEST, "print_charTest"); + invoke(); + } + + /* + * @testName: print_doubleTest + * + * @assertion_ids: Servlet:JAVADOC:140; Servlet:JAVADOC:85; + * + * @test_Strategy: Test for print(double d) method + */ + @Test + public void print_doubleTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "12345.612345.6"); + + TEST_PROPS.setProperty(APITEST, "print_doubleTest"); + invoke(); + } + + /* + * @testName: print_floatTest + * + * @assertion_ids: Servlet:JAVADOC:140; Servlet:JAVADOC:83; + * + * @test_Strategy: Test for println(float f) method + */ + @Test + public void print_floatTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "1234.51234.5"); + + TEST_PROPS.setProperty(APITEST, "print_floatTest"); + invoke(); + } + + /* + * @testName: print_intTest + * + * @assertion_ids: Servlet:JAVADOC:140; Servlet:JAVADOC:79; + * + * @test_Strategy: Test for print(integer i) method + */ + @Test + public void print_intTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "11"); + + TEST_PROPS.setProperty(APITEST, "print_intTest"); + invoke(); + } + + /* + * @testName: print_longTest + * + * @assertion_ids: Servlet:JAVADOC:140; Servlet:JAVADOC:81; + * + * @test_Strategy: Test for print(long l) method + */ + @Test + public void print_longTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "12345678901234567890"); + + TEST_PROPS.setProperty(APITEST, "print_longTest"); + invoke(); + } + + /* + * @testName: printlnTest + * + * @assertion_ids: Servlet:JAVADOC:140; Servlet:JAVADOC:87; + * Servlet:JAVADOC:89; + * + * @test_Strategy: Test for println () method + */ + @Test + public void printlnTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "some test"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "some test text"); + + TEST_PROPS.setProperty(APITEST, "printlnTest"); + invoke(); + } + + /* + * @testName: println_StringTest + * + * @assertion_ids: Servlet:JAVADOC:140; Servlet:JAVADOC:89; + * + * @test_Strategy: Test for println(java.lang.String s) method + */ + @Test + public void println_StringTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "some|text"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "sometext"); + + TEST_PROPS.setProperty(APITEST, "println_StringTest"); + invoke(); + } + + /* + * @testName: println_booleanTest + * + * @assertion_ids: Servlet:JAVADOC:140; Servlet:JAVADOC:91; + * + * @test_Strategy: Test for println(boolean b) method + */ + @Test + public void println_booleanTest() throws Exception { + String s = Boolean.TRUE.toString(); + + StringBuffer ss = new StringBuffer(s); + ss = ss.append(s); + + TEST_PROPS.setProperty(SEARCH_STRING, s); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, ss.toString()); + + TEST_PROPS.setProperty(APITEST, "println_booleanTest"); + invoke(); + } + + /* + * @testName: println_charTest + * + * @assertion_ids: Servlet:JAVADOC:140; Servlet:JAVADOC:93; + * + * @test_Strategy: Test for println(char c) method + */ + @Test + public void println_charTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "T|E|X|T"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "TEXT"); + + TEST_PROPS.setProperty(APITEST, "println_charTest"); + invoke(); + } + + /* + * @testName: println_doubleTest + * + * @assertion_ids: Servlet:JAVADOC:140; Servlet:JAVADOC:101; + * + * @test_Strategy: Test for println(double d) method + */ + @Test + public void println_doubleTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "12345.6"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "12345.612345.6"); + + TEST_PROPS.setProperty(APITEST, "println_doubleTest"); + invoke(); + } + + /* + * @testName: println_floatTest + * + * @assertion_ids: Servlet:JAVADOC:140; Servlet:JAVADOC:99; + * + * @test_Strategy: Test for print(float f) method + */ + @Test + public void println_floatTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "1234.5"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "1234.51234.5"); + + TEST_PROPS.setProperty(APITEST, "println_floatTest"); + invoke(); + } + + /* + * @testName: println_intTest + * + * @assertion_ids: Servlet:JAVADOC:140; Servlet:JAVADOC:95; + * + * @test_Strategy: Test for println(integer i) method + */ + @Test + public void println_intTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "1"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "11"); + + TEST_PROPS.setProperty(APITEST, "println_intTest"); + invoke(); + } + + /* + * @testName: println_longTest + * + * @assertion_ids: Servlet:JAVADOC:140; Servlet:JAVADOC:97; + * + * @test_Strategy: Test for println(long l) method + */ + @Test + public void println_longTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "1234567890"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "12345678901234567890"); + + TEST_PROPS.setProperty(APITEST, "println_longTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletoutputstream/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletoutputstream/build.xml new file mode 100644 index 0000000000..62cf87f2a6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletoutputstream/build.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletoutputstream/servlet_plu_servletoutputstream_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletoutputstream/servlet_plu_servletoutputstream_web-fragment.xml new file mode 100644 index 0000000000..ce040b5a8a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletoutputstream/servlet_plu_servletoutputstream_web-fragment.xml @@ -0,0 +1,36 @@ + + + + + + TestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.servletoutputstream.TestServlet + + + TestLogicalName + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequest/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequest/URLClient.java new file mode 100644 index 0000000000..bb6b9319c5 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequest/URLClient.java @@ -0,0 +1,547 @@ +/* + * Copyright (c) 2001, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet.servletrequest; + +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest.GetParameterNamesEmptyEnumTestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest.GetReaderUnsupportedEncodingExceptionTestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest.SetCharacterEncodingTest; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest.SetCharacterEncodingUnsupportedEncodingExceptionTest; +import com.sun.ts.tests.servlet.common.request.RequestClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends RequestClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar").addClasses(TestServlet1.class, RequestListener1.class).addAsResource(URLClient.class.getResource("servlet_plu_servletrequest_web-fragment.xml"), "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_plu_servletrequest_web.war").addAsLibraries(CommonServlets.getCommonServletsArchive()).addClasses(GetParameterNamesEmptyEnumTestServlet.class, GetReaderUnsupportedEncodingExceptionTestServlet.class, SetCharacterEncodingTest.class, SetCharacterEncodingUnsupportedEncodingExceptionTest.class).addAsLibraries(javaArchive); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + /* Run test */ + /* + * @testName: getAttributeNamesTest + * + * @assertion_ids: Servlet:JAVADOC:174 + * + * @test_Strategy: Servlet sets some attributes and verifies they can be + * retrieved. + * + */ + /* + * @testName: getAttributeNamesEmptyEnumTest + * + * @assertion_ids: Servlet:JAVADOC:175 + * + * @test_Strategy: No attributes exist in request. + */ + /* + * @testName: getAttributeTest + * + * @assertion_ids: Servlet:JAVADOC:172 + * + * @test_Strategy: Servlet sets an attribute and retrieves it. + */ + /* + * @testName: getAttributeDoesNotExistTest + * + * @assertion_ids: Servlet:JAVADOC:173 + * + * @test_Strategy: Servlet tries to retrieve a non-existant attribute. + * + */ + /* + * @testName: getCharacterEncodingTest + * + * @assertion_ids: Servlet:JAVADOC:176 + * + * @test_Strategy: Client sets an encoding and Servlet tries to retrieve it. + */ + /* + * @testName: getCharacterEncodingNullTest + * + * @assertion_ids: Servlet:JAVADOC:177 + * + * @test_Strategy: Client does not set an encoding and Servlet tries to + * retrieve it. + * + */ + /* + * @testName: getContentLengthTest + * + * @assertion_ids: Servlet:JAVADOC:180 + * + * @test_Strategy: Servlet compares this length to the actual length of the + * content body read in using getInputStream + * + */ + /* + * @testName: getContentTypeTest + * + * @assertion_ids: Servlet:JAVADOC:182; Servlet:SPEC:34; + * + * @test_Strategy: Client sets the content type and servlet reads it. + */ + /* + * @testName: getContentTypeNullTest + * + * @assertion_ids: Servlet:JAVADOC:183; Servlet:SPEC:34; + * + * @test_Strategy: Servlet tries to read content type. + */ + /* + * @testName: getInputStreamTest + * + * @assertion_ids: Servlet:JAVADOC:184 + * + * @test_Strategy: Servlet tries to read the input stream. + */ + /* + * @testName: getInputStreamIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:186 + * + * @test_Strategy: Servlet gets a Reader object using + * ServletRequest.getReader() then tries to get the inputStream Object + * + */ + /* + * @testName: getLocaleTest + * + * @assertion_ids: Servlet:JAVADOC:206 + * + * @test_Strategy: Client specifics a locale and the servlet verifies it. + */ + /* + * @testName: getLocaleDefaultTest + * + * @assertion_ids: Servlet:JAVADOC:207 + * + * @test_Strategy: Client does not specify a locale and the servlet verifies + * the default. + */ + /* + * @testName: getLocalesTest + * + * @assertion_ids: Servlet:JAVADOC:208 + * + * @test_Strategy: Client specifics 2 locales and the servlet verifies it. + */ + /* + * @testName: getLocalesDefaultTest + * + * @assertion_ids: Servlet:JAVADOC:209 + * + * @test_Strategy: Client does not specify a locale and the servlet verifies + * the default. + */ + /* + * @testName: getParameterMapTest + * + * @assertion_ids: Servlet:JAVADOC:193 + * + * @test_Strategy: Client sets several parameters and the servlet attempts to + * access them. + */ + /* + * @testName: getParameterNamesTest + * + * @assertion_ids: Servlet:JAVADOC:189 + * + * @test_Strategy: Client sets several parameters and the servlet attempts to + * access them. + */ + /* + * @testName: getParameterNamesEmptyEnumTest + * + * @assertion_ids: Servlet:JAVADOC:190 + * + * @test_Strategy: Client does not set any parameters and the servlet attempts + * to access them. + */ + /* + * @testName: getParameterTest + * + * @assertion_ids: Servlet:JAVADOC:187 + * + * @test_Strategy: Client sets a parameter and servlet retrieves it. + */ + /* + * @testName: getParameterDoesNotExistTest + * + * @assertion_ids: Servlet:JAVADOC:188 + * + * @test_Strategy: Servlet tries to access a non-existent parameter + */ + /* + * @testName: getParameterValuesTest + * + * @assertion_ids: Servlet:JAVADOC:191 + * + * @test_Strategy: Client sets a parameter which has 2 values and servlet + * verifies boths values. + */ + /* + * @testName: getParameterValuesDoesNotExistTest + * + * @assertion_ids: Servlet:JAVADOC:192 + * + * @test_Strategy: Servlet tries to retrieve a parameter that does not exist + */ + /* + * @testName: getProtocolTest + * + * @assertion_ids: Servlet:JAVADOC:194 + * + * @test_Strategy: Servlet verifies the protocol used by the client + */ + /* + * @testName: getReaderTest + * + * @assertion_ids: Servlet:JAVADOC:198 + * + * @test_Strategy: Client sets some content and servlet reads the content + */ + /* + * @testName: getReaderIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:201 + * + * @test_Strategy: Servlet gets an InputStream Object then tries to get a + * Reader Object. + */ + /* + * @testName: getReaderUnsupportedEncodingExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:200 + * + * @test_Strategy: Client sets some content but with an invalid encoding, + * servlet tries to read content. + */ + /* + * @testName: getRemoteAddrTest + * + * @assertion_ids: Servlet:JAVADOC:202 + * + * @test_Strategy: Servlet reads and verifies where the request originated + */ + /* + * @testName: getLocalAddrTest + * + * @assertion_ids: Servlet:JAVADOC:704 + * + * @test_Strategy: Servlet reads and verifies where the request originated + */ + /* + * @testName: getRemoteHostTest + * + * @assertion_ids: Servlet:JAVADOC:203; + * + * @test_Strategy: Servlet reads and verifies where the request originated + */ + /* + * @testName: getRequestDispatcherTest + * + * @assertion_ids: Servlet:JAVADOC:211 + * + * @test_Strategy: Servlet tries to get a dispatcher + */ + /* + * @testName: getSchemeTest + * + * @assertion_ids: Servlet:JAVADOC:195 + * + * @test_Strategy: Servlet verifies the scheme of the url used in the request + */ + /* + * @testName: getServerNameTest + * + * @assertion_ids: Servlet:JAVADOC:196 + * + * @test_Strategy: Servlet verifies the destination of the request + */ + /* + * @testName: getServerPortTest + * + * @assertion_ids: Servlet:JAVADOC:197 + * + * @test_Strategy: Servlet verifies the destination port of the request + */ + /* + * @testName: isSecureTest + * + * @assertion_ids: Servlet:JAVADOC:210 + * + * @test_Strategy: Servlet verifies the isSecure method for the non-secure + * case. + */ + /* + * @testName: removeAttributeTest + * + * @assertion_ids: Servlet:JAVADOC:205 + * + * @test_Strategy: Servlet adds then removes an attribute, then verifies it + * was removed. + */ + /* + * @testName: setAttributeTest + * + * @assertion_ids: Servlet:JAVADOC:204 + * + * @test_Strategy: Servlet adds an attribute, then verifies it was added + */ + /* + * @testName: setCharacterEncodingUnsupportedEncodingExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:179 + * + * @test_Strategy: Servlet tries to set an invalid encoding. + * + */ + /* + * @testName: setCharacterEncodingTest + * + * @assertion_ids: Servlet:JAVADOC:178 + * + * @test_Strategy: Servlet sets a new encoding and tries to retrieve it. + */ + /* + * @testName: setCharacterEncodingTest1 + * + * @assertion_ids: Servlet:JAVADOC:178; Servlet:JAVADOC:177; Servlet:SPEC:28; + * Servlet:SPEC:213; + * + * @test_Strategy: ServletRequest calls getReader()first; then sets a new + * encoding and tries to retrieve it. verifies that the new encoding is + * ignored. + */ + @Test() + public void getAttributeDoesNotExistTest() throws Exception { + super.getAttributeDoesNotExistTest(); + } + + @Test() + public void getAttributeNamesEmptyEnumTest() throws Exception { + super.getAttributeNamesEmptyEnumTest(); + } + + @Test() + public void getAttributeNamesTest() throws Exception { + super.getAttributeNamesTest(); + } + + @Test() + public void getAttributeTest() throws Exception { + super.getAttributeTest(); + } + + @Test() + public void getCharacterEncodingNullTest() throws Exception { + super.getCharacterEncodingNullTest(); + } + + @Test() + public void getCharacterEncodingTest() throws Exception { + super.getCharacterEncodingTest(); + } + + @Test() + public void getContentLengthTest() throws Exception { + super.getContentLengthTest(); + } + + @Test() + public void getContentTypeNullTest() throws Exception { + super.getContentTypeNullTest(); + } + + @Test() + public void getContentTypeTest() throws Exception { + super.getContentTypeTest(); + } + + @Test() + public void getInputStreamIllegalStateExceptionTest() throws Exception { + super.getInputStreamIllegalStateExceptionTest(); + } + + @Test() + public void getInputStreamTest() throws Exception { + super.getInputStreamTest(); + } + + @Test() + public void getLocalAddrTest() throws Exception { + super.getLocalAddrTest(); + } + + @Test() + public void getLocaleDefaultTest() throws Exception { + super.getLocaleDefaultTest(); + } + + @Test() + public void getLocaleTest() throws Exception { + super.getLocaleTest(); + } + + @Test() + public void getLocalesDefaultTest() throws Exception { + super.getLocalesDefaultTest(); + } + + @Test() + public void getLocalesTest() throws Exception { + super.getLocalesTest(); + } + + @Test() + public void getParameterDoesNotExistTest() throws Exception { + super.getParameterDoesNotExistTest(); + } + + @Test() + public void getParameterMapTest() throws Exception { + super.getParameterMapTest(); + } + + @Test() + public void getParameterNamesEmptyEnumTest() throws Exception { + super.getParameterNamesEmptyEnumTest(); + } + + @Test() + public void getParameterNamesTest() throws Exception { + super.getParameterNamesTest(); + } + + @Test() + public void getParameterTest() throws Exception { + super.getParameterTest(); + } + + @Test() + public void getParameterValuesDoesNotExistTest() throws Exception { + super.getParameterValuesDoesNotExistTest(); + } + + @Test() + public void getParameterValuesTest() throws Exception { + super.getParameterValuesTest(); + } + + @Test() + public void getProtocolTest() throws Exception { + super.getProtocolTest(); + } + + @Test() + public void getReaderIllegalStateExceptionTest() throws Exception { + super.getReaderIllegalStateExceptionTest(); + } + + @Test() + public void getReaderTest() throws Exception { + super.getReaderTest(); + } + + @Test() + public void getReaderUnsupportedEncodingExceptionTest() throws Exception { + super.getReaderUnsupportedEncodingExceptionTest(); + } + + @Test() + public void getRemoteAddrTest() throws Exception { + super.getRemoteAddrTest(); + } + + @Test() + public void getRemoteHostTest() throws Exception { + super.getRemoteHostTest(); + } + + @Test() + public void getRequestDispatcherTest() throws Exception { + super.getRequestDispatcherTest(); + } + + @Test() + public void getSchemeTest() throws Exception { + super.getSchemeTest(); + } + + @Test() + public void getServerNameTest() throws Exception { + super.getServerNameTest(); + } + + @Test() + public void getServerPortTest() throws Exception { + super.getServerPortTest(); + } + + @Test() + public void isSecureTest() throws Exception { + super.isSecureTest(); + } + + @Test() + public void removeAttributeTest() throws Exception { + super.removeAttributeTest(); + } + + @Test() + public void setAttributeTest() throws Exception { + super.setAttributeTest(); + } + + @Test() + public void setCharacterEncodingTest() throws Exception { + super.setCharacterEncodingTest(); + } + + @Test() + public void setCharacterEncodingTest1() throws Exception { + super.setCharacterEncodingTest1(); + } + + @Test() + public void setCharacterEncodingUnsupportedEncodingExceptionTest() throws Exception { + super.setCharacterEncodingUnsupportedEncodingExceptionTest(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequest/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequest/build.xml new file mode 100644 index 0000000000..f12f560367 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequest/build.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequest/servlet_plu_servletrequest_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequest/servlet_plu_servletrequest_web-fragment.xml new file mode 100644 index 0000000000..081b9fca58 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequest/servlet_plu_servletrequest_web-fragment.xml @@ -0,0 +1,68 @@ + + + + + + TestServlet + com.sun.ts.tests.servlet.common.servlets.RequestTestServlet + + + getParameterNamesEmptyEnumTest + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest.GetParameterNamesEmptyEnumTestServlet + + + getReaderUnsupportedEncodingExceptionTest + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest.GetReaderUnsupportedEncodingExceptionTestServlet + + + setCharacterEncodingUnsupportedEncodingExceptionTest + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest.SetCharacterEncodingUnsupportedEncodingExceptionTest + + + setCharacterEncodingTest + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest.SetCharacterEncodingTest + + + TestServlet + /TestServlet/* + + + getParameterNamesEmptyEnumTest + /getParameterNamesEmptyEnumTest + + + getReaderUnsupportedEncodingExceptionTest + /getReaderUnsupportedEncodingExceptionTest + + + setCharacterEncodingUnsupportedEncodingExceptionTest + /setCharacterEncodingUnsupportedEncodingExceptionTest + + + setCharacterEncodingTest + /setCharacterEncodingTest + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequest1/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequest1/URLClient.java new file mode 100644 index 0000000000..665bcae572 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequest1/URLClient.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet.servletrequest1; + +import com.sun.ts.tests.servlet.common.request.RequestClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends RequestClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar").addClasses(TestServlet1.class, RequestListener1.class).addAsResource(URLClient.class.getResource("servlet_plu_servletrequest1_web-fragment.xml"), "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_plu_servletrequest1_web.war").addAsLibraries(CommonServlets.getCommonServletsArchive()).addAsLibraries(javaArchive); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: getLocalPortTest + * + * @assertion_ids: Servlet:JAVADOC:635 + * + * @test_Strategy: Test servlet API SDervletRequest.getLocalPort() + */ + /* + * @testName: getLocalNameTest + * + * @assertion_ids: Servlet:JAVADOC:632 + * + * @test_Strategy: Test servlet API SDervletRequest.getLocalName() + */ + @Test() + public void getLocalNameTest() throws Exception { + super.getLocalNameTest(); + } + + @Test() + public void getLocalPortTest() throws Exception { + super.getLocalPortTest(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequest1/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequest1/build.xml new file mode 100644 index 0000000000..7fbd7c4881 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequest1/build.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequest1/servlet_plu_servletrequest1_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequest1/servlet_plu_servletrequest1_web-fragment.xml new file mode 100644 index 0000000000..e42091c769 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequest1/servlet_plu_servletrequest1_web-fragment.xml @@ -0,0 +1,36 @@ + + + + + + TestServlet + com.sun.ts.tests.servlet.common.servlets.RequestTestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequest30/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequest30/URLClient.java new file mode 100644 index 0000000000..ca462e009c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequest30/URLClient.java @@ -0,0 +1,332 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet.servletrequest30; + +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest30.AsyncTestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest30.AsyncTests; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest30.SecondServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest30.TestServlet; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive1 = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_plu_servletrequest30_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_plu_servletrequest30_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(AsyncTests.class, AsyncTestServlet.class, SecondServlet.class, TestServlet.class) + .addAsLibraries(javaArchive1); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + /* + * @testName: getServletContextTest + * + * @assertion_ids: Servlet:JAVADOC:706; + * + * @test_Strategy: ServletRequest calls getServletContext(); verifies that + * returned ServletContext instance is consistent with the one stored in + * ServletConfigs. + */ + @Test + public void getServletContextTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletContextTest"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "TEST FAILED"); + TEST_PROPS.setProperty(SEARCH_STRING, "Test PASSED"); + invoke(); + } + + /* + * @testName: getDispatcherTypeTestRequest + * + * @assertion_ids: Servlet:JAVADOC:703; + * + * @test_Strategy: Create a Servlet TestServlet; Client send a request to + * TestServlet; call ServletRequest.getDispatcherType() verifies that + * DispatcherType.REQUEST is returned. + */ + @Test + public void getDispatcherTypeTestRequest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getDispatcherTypeTestRequest"); + TEST_PROPS.setProperty(SEARCH_STRING, "DispatcherType=REQUEST"); + invoke(); + } + + /* + * @testName: getDispatcherTypeTestForward + * + * @assertion_ids: Servlet:JAVADOC:703; + * + * @test_Strategy: Create two Servlets TestServlet and SecondServlet; Client + * send a request to TestServlet; Forward to SecondServlet call + * ServletRequest.getDispatcherType() verifies that DispatcherType.FORWARD is + * returned. + */ + @Test + public void getDispatcherTypeTestForward() throws Exception { + TEST_PROPS.setProperty(APITEST, "getDispatcherTypeTestForward"); + TEST_PROPS.setProperty(SEARCH_STRING, "DispatcherType=FORWARD"); + invoke(); + } + + /* + * @testName: getDispatcherTypeTestInclude + * + * @assertion_ids: Servlet:JAVADOC:703; + * + * @test_Strategy: Create two Servlets TestServlet and SecondServlet; Client + * send a request to TestServlet; Invoke SecondServlet using include call + * ServletRequest.getDispatcherType() verifies that DispatcherType.INCLUDE is + * returned. + */ + @Test + public void getDispatcherTypeTestInclude() throws Exception { + TEST_PROPS.setProperty(APITEST, "getDispatcherTypeTestInclude"); + TEST_PROPS.setProperty(SEARCH_STRING, "DispatcherType=INCLUDE"); + invoke(); + } + + /* + * @testName: getDispatcherTypeTestError + * + * @assertion_ids: Servlet:JAVADOC:703; + * + * @test_Strategy: Create a Servlet SecondServlet to handle 404 error; Client + * send a request to nowhereland; In SecondServlet, call + * ServletRequest.getDispatcherType() verifies that DispatcherType.ERROR is + * returned. + */ + @Test + public void getDispatcherTypeTestError() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/nowheretobefound/ HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "DispatcherType=ERROR"); + TEST_PROPS.setProperty(STATUS_CODE, NOT_FOUND); + invoke(); + } + + /* + * @testName: getDispatcherTypeTestAsync + * + * @assertion_ids: Servlet:JAVADOC:640; Servlet:JAVADOC:703; + * Servlet:JAVADOC:710; + * + * @test_Strategy: Create two Servlets AsyncTestServlet and AsyncTests, both + * supports async; Client send a request to AsyncTestServlet; StartAsync in + * AsyncTestServlet; Invoke AsyncTests using AsyncContext.dispatch(String) + * call ServletRequest.getDispatcherType() verifies that DispatcherType.ASYNC + * is returned. + */ + @Test + public void getDispatcherTypeTestAsync() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/AsyncTestServlet?testname=getDispatcherTypeTestAsync HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: asyncStartedTest1 + * + * @assertion_ids: Servlet:JAVADOC:707; Servlet:JAVADOC:710; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which supports async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet + * ServletRequest.startAsync(); call ServletRequest.isAsyncStarted() verifies + * that true is returned. + */ + @Test + public void asyncStartedTest1() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/AsyncTestServlet?testname=asyncStartedTest1 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "IsAsyncStarted=true"); + invoke(); + } + + /* + * @testName: asyncStartedTest2 + * + * @assertion_ids: Servlet:JAVADOC:707; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which supports async; + * Client send a request to AsyncTestServlet; call + * ServletRequest.isAsyncStarted() without start async mode verifies that + * false is returned. + */ + @Test + public void asyncStartedTest2() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/AsyncTestServlet?testname=asyncStartedTest2 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "IsAsyncStarted=false"); + invoke(); + } + + /* + * @testName: asyncStartedTest3 + * + * @assertion_ids: Servlet:JAVADOC:638; Servlet:JAVADOC:707; + * Servlet:JAVADOC:638; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which supports async; + * Client send a request to AsyncTestServlet; StartAsync in AsyncTestServlet + * ServletRequest.startAsync(); call ServletRequest.isAsyncStarted() after + * AsyncContext.complete() called verifies that true is returned before it + * dispatch return to the container + */ + @Test + public void asyncStartedTest3() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/AsyncTestServlet?testname=asyncStartedTest3 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "IsAsyncStarted=true"); + invoke(); + } + + /* + * @testName: asyncStartedTest4 + * + * @assertion_ids: Servlet:JAVADOC:640; Servlet:JAVADOC:707; + * + * @test_Strategy: Create two Servlets AsyncTestServlet and AsyncTests, both + * supports async; Client send a request to AsyncTestServlet; StartAsync in + * AsyncTestServlet; Invoke AsyncTests using AsyncContext.dispatch(String) + * call ServletRequest.isAsyncStarted() verifies that false is returned. + */ + @Test + public void asyncStartedTest4() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/AsyncTestServlet?testname=asyncStartedTest4 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "IsAsyncStarted=false"); + invoke(); + } + + /* + * @testName: isAsyncSupportedTest1 + * + * @assertion_ids: Servlet:JAVADOC:708; + * + * @test_Strategy: Create a Servlet AsyncTestServlet which supports async; + * Client send a request to AsyncTestServlet; call + * ServletRequest.isAsyncSupported() verifies that true is returned. + */ + @Test + public void isAsyncSupportedTest1() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/AsyncTestServlet?testname=isAsyncSupportedTest HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "isAsyncSupported=true"); + invoke(); + } + + /* + * @testName: isAsyncSupportedTest2 + * + * @assertion_ids: Servlet:JAVADOC:708; + * + * @test_Strategy: Create a Servlet TestServlet which does not support async, + * Client send a request to TestServlet; call + * ServletRequest.isAsyncSupported() verifies that false is returned. + */ + @Test + public void isAsyncSupportedTest2() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/TestServlet?testname=isAsyncSupportedTest HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "isAsyncSupported=false"); + invoke(); + } + + /* + * @testName: startAsyncTest1 + * + * @assertion_ids: Servlet:JAVADOC:711; + * + * @test_Strategy: Create a Servlet TestServlet which does not support async, + * Client send a request to TestServlet; call ServletRequest.startAsyncTest() + * verifies that IllegalStateException is thrown. + */ + @Test + public void startAsyncTest1() throws Exception { + TEST_PROPS.setProperty(APITEST, "startAsyncTest"); + invoke(); + } + + /* + * @testName: startAsyncTest2 + * + * @assertion_ids: Servlet:JAVADOC:640; Servlet:JAVADOC:710; + * Servlet:JAVADOC:711; + * + * @test_Strategy: Create two Servlets AsyncTestServlet and AsyncTests, both + * supports async; Client send a request to AsyncTestServlet; StartAsync in + * AsyncTestServlet; Invoke AsyncTests using AsyncContext.dispatch(String) + * Call ServletRequest.startAsyncTest() outside of dispatch verifies that + * IllegalStateException is thrown. + */ + @Test + public void startAsyncTest2() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/AsyncTestServlet?testname=startAsyncTest HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "IllegalStateException thrown"); + invoke(); + } + + /* + * @testName: getAsyncContextTest + * + * @assertion_ids: Servlet:JAVADOC:638; Servlet:JAVADOC:701; + * Servlet:JAVADOC:710; + * + * @test_Strategy: Create a Servlets AsyncTestServlet which supports async; + * Client send a request to AsyncTestServlet; Start Async in AsyncTestServlet; + * Call ServletRequest.getAsyncContext() verifies it works. + */ + @Test + public void getAsyncContextTest() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/AsyncTestServlet?testname=getAsyncContextTest HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Test PASSED"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequest30/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequest30/build.xml new file mode 100644 index 0000000000..25d378c050 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequest30/build.xml @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequest30/servlet_plu_servletrequest30_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequest30/servlet_plu_servletrequest30_web-fragment.xml new file mode 100644 index 0000000000..0c4290c694 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequest30/servlet_plu_servletrequest30_web-fragment.xml @@ -0,0 +1,68 @@ + + + + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest30.TestServlet + + + AsyncTestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest30.AsyncTestServlet + true + + + AsyncTests + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest30.AsyncTests + true + + + SecondServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest30.SecondServlet + + + TestServlet + /TestServlet + + + AsyncTestServlet + /AsyncTestServlet + + + AsyncTests + /async/AsyncTests + + + SecondServlet + /forward/ForwardedServlet + /include/IncludedServlet + /error/ErrorServlet + + + 404 + /error/ErrorServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequestwrapper/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequestwrapper/URLClient.java new file mode 100644 index 0000000000..3b2e6fc139 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequestwrapper/URLClient.java @@ -0,0 +1,479 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet.servletrequestwrapper; + +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper.SetCharacterEncodingTest; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper.SetCharacterEncodingTestWrapper; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper.SetCharacterEncodingUnsupportedEncodingExceptionTest; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper.SetCharacterEncodingUnsupportedEncodingExceptionTestWrapper; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper.TestServlet; +import com.sun.ts.tests.servlet.common.request.RequestClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends RequestClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive1 = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar").addClasses(TestServlet1.class, RequestListener1.class).addAsResource(URLClient.class.getResource("servlet_plu_servletrequestwrapper_web-fragment.xml"), "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_plu_servletrequestwrapper_web.war").addAsLibraries(CommonServlets.getCommonServletsArchive()).addClasses(SetCharacterEncodingTest.class, SetCharacterEncodingTestWrapper.class, SetCharacterEncodingUnsupportedEncodingExceptionTest.class, SetCharacterEncodingUnsupportedEncodingExceptionTestWrapper.class, TestServlet.class).addAsLibraries(javaArchive1); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + /* Run test */ + /* + * @testName: requestWrapperConstructorTest + * + * @assertion_ids: Servlet:JAVADOC:31 + * + * @test_Strategy: Servlet calls wrapper constructor + */ + @Test + public void requestWrapperConstructorTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "requestWrapperConstructorTest"); + invoke(); + } + + /* + * @testName: requestWrapperGetRequestTest + * + * @assertion_ids: Servlet:JAVADOC:32 + * + * @test_Strategy: Servlet gets wrapped request object + */ + @Test + public void requestWrapperGetRequestTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "requestWrapperGetRequestTest"); + invoke(); + } + + /* + * @testName: requestWrapperSetRequestTest + * + * @assertion_ids: Servlet:JAVADOC:33 + * + * @test_Strategy: Servlet sets wrapped request object + */ + @Test + public void requestWrapperSetRequestTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "requestWrapperSetRequestTest"); + invoke(); + } + + /* + * @testName: requestWrapperSetRequestIllegalArgumentExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:34 + * + * @test_Strategy: Servlet sets wrapped request object + */ + @Test + public void requestWrapperSetRequestIllegalArgumentExceptionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "requestWrapperSetRequestIllegalArgumentExceptionTest"); + invoke(); + } + + /* + * @testName: getAttributeNamesTest + * + * @assertion_ids: Servlet:JAVADOC:36 + * + * @test_Strategy: Servlet wraps the request. Servlet then sets some + * attributes and verifies they can be retrieved. + */ + /* + * @testName: getAttributeTest + * + * @assertion_ids: Servlet:JAVADOC:35 + * + * @test_Strategy: Servlet wraps the request. Servlet then sets an attribute + * and retrieves it. + * + */ + /* + * @testName: getCharacterEncodingTest + * + * @assertion_ids: Servlet:JAVADOC:37 + * + * @test_Strategy: Client sets an encoding. Servlet wraps the request. Servlet + * then tries to retrieve it. + */ + /* + * @testName: getContentLengthTest + * + * @assertion_ids: Servlet:JAVADOC:40 + * + * @test_Strategy: Servlet wraps the request. Servlet then compares this + * length to the actual length of the content body read in using + * getInputStream + * + */ + /* + * @testName: getContentTypeTest + * + * @assertion_ids: Servlet:JAVADOC:41; Servlet:SPEC:34; + * + * @test_Strategy: Client sets the content type and servlet reads it. + * + */ + /* + * @testName: getInputStreamTest + * + * @assertion_ids: Servlet:JAVADOC:42 + * + * @test_Strategy: Servlet wraps the request. Servlet then tries to read the + * input stream. + */ + /* + * @testName: getLocaleTest + * + * @assertion_ids: Servlet:JAVADOC:58 + * + * @test_Strategy: Client specifics a locale, Servlet wraps the request. + * Servlet then verifies it. + */ + /* + * @testName: getLocalesTest + * + * @assertion_ids: Servlet:JAVADOC:59 + * + * @test_Strategy: Client specifics 2 locales.Servlet wraps the request. + * Servlet then verifies it. + */ + /* + * @testName: getParameterMapTest + * + * @assertion_ids: Servlet:JAVADOC:45 + * + * @test_Strategy: Client sets several parameters.Servlet wraps the request. + * Servlet then attempts to access them. + */ + /* + * @testName: getParameterNamesTest + * + * @assertion_ids: Servlet:JAVADOC:46 + * + * @test_Strategy: Client sets several parameters.Servlet wraps the request. + * Servlet then attempts to access them. + */ + /* + * @testName: getParameterTest + * + * @assertion_ids: Servlet:JAVADOC:44 + * + * @test_Strategy: Client sets a parameter.Servlet wraps the request. Servlet + * then retrieves parameter. + */ + /* + * @testName: getParameterValuesTest + * + * @assertion_ids: Servlet:JAVADOC:47 + * + * @test_Strategy: Client sets a parameter which has 2 values.Servlet wraps + * the request. Servlet then verifies both values. + */ + /* + * @testName: getProtocolTest + * + * @assertion_ids: Servlet:JAVADOC:48 + * + * @test_Strategy: Servlet wraps the request. Servlet then verifies the + * protocol used by the client + */ + /* + * @testName: getReaderTest + * + * @assertion_ids: Servlet:JAVADOC:52 + * + * @test_Strategy: Client sets some content.Servlet wraps the request. Servlet + * then reads the content + */ + /* + * @testName: getRemoteAddrTest + * + * @assertion_ids: Servlet:JAVADOC:54 + * + * @test_Strategy: Servlet wraps the request. Servlet then reads and verifies + * where the request originated + */ + /* + * @testName: getRemoteHostTest + * + * @assertion_ids: Servlet:JAVADOC:55 + * + * @test_Strategy: Servlet wraps the request. Servlet then reads and verifies + * where the request originated + */ + /* + * @testName: getRequestDispatcherTest + * + * @assertion_ids: Servlet:JAVADOC:61 + * + * @test_Strategy: Servlet wraps the request. Servlet then tries to get a + * dispatcher + */ + /* + * @testName: getSchemeTest + * + * @assertion_ids: Servlet:JAVADOC:49 + * + * @test_Strategy: Servlet wraps the request. Servlet then verifies the scheme + * of the url used in the request + */ + /* + * @testName: getServerNameTest + * + * @assertion_ids: Servlet:JAVADOC:50 + * + * @test_Strategy: Servlet wraps the request. Servlet then verifies the + * destination of the request + */ + /* + * @testName: getServerPortTest + * + * @assertion_ids: Servlet:JAVADOC:51 + * + * @test_Strategy: Servlet wraps the request. Servlet then verifies the + * destination port of the request + */ + /* + * @testName: isSecureTest + * + * @assertion_ids: Servlet:JAVADOC:60 + * + * @test_Strategy: Servlet wraps the request. Servlet then verifies the + * isSecure method for the non-secure case. + */ + /* + * @testName: removeAttributeTest + * + * @assertion_ids: Servlet:JAVADOC:57 + * + * @test_Strategy: Servlet wraps the request. Servlet then adds then removes + * an attribute, then verifies it was removed. + */ + /* + * @testName: setAttributeTest + * + * @assertion_ids: Servlet:JAVADOC:56 + * + * @test_Strategy: Servlet wraps the request. Servlet then adds an attribute, + * then verifies it was added + */ + /* + * @testName: setCharacterEncodingUnsupportedEncodingExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:39 + * + * @test_Strategy: Servlet wraps the request. Servlet then tries to set an + * invalid encoding. + * + */ + /* + * @testName: setCharacterEncodingTest + * + * @assertion_ids: Servlet:JAVADOC:38 + * + * @test_Strategy: Servlet wraps the request. Servlet then sets a new encoding + * and tries to retrieve it. verifies that the new encoding gets set. + */ + /* + * @testName: setCharacterEncodingTest1 + * + * @assertion_ids: Servlet:JAVADOC:38; Servlet:JAVADOC:37; Servlet:SPEC:28; + * Servlet:SPEC:213; + * + * @test_Strategy: Servlet wraps the request; ServletRequestWrapper calls + * getReader(); then sets a new encoding and tries to retrieve it. verifies + * that the new encoding is ignored. + */ + /* + * @testName: getLocalNameTest + * + * @assertion_ids: Servlet:JAVADOC:633 + * + * @test_Strategy: Servlet wraps the request. Servlet then verify + * getLocalName(); + */ + /* + * @testName: getLocalPortTest + * + * @assertion_ids: Servlet:JAVADOC:636 + * + * @test_Strategy: Servlet wraps the request. Servlet then verify + * getLocalPort(); + */ + @Test() + public void getAttributeNamesTest() throws Exception { + super.getAttributeNamesTest(); + } + + @Test() + public void getAttributeTest() throws Exception { + super.getAttributeTest(); + } + + @Test() + public void getCharacterEncodingTest() throws Exception { + super.getCharacterEncodingTest(); + } + + @Test() + public void getContentLengthTest() throws Exception { + super.getContentLengthTest(); + } + + @Test() + public void getContentTypeTest() throws Exception { + super.getContentTypeTest(); + } + + @Test() + public void getInputStreamTest() throws Exception { + super.getInputStreamTest(); + } + + @Test() + public void getLocalNameTest() throws Exception { + super.getLocalNameTest(); + } + + @Test() + public void getLocalPortTest() throws Exception { + super.getLocalPortTest(); + } + + @Test() + public void getLocaleTest() throws Exception { + super.getLocaleTest(); + } + + @Test() + public void getLocalesTest() throws Exception { + super.getLocalesTest(); + } + + @Test() + public void getParameterMapTest() throws Exception { + super.getParameterMapTest(); + } + + @Test() + public void getParameterNamesTest() throws Exception { + super.getParameterNamesTest(); + } + + @Test() + public void getParameterTest() throws Exception { + super.getParameterTest(); + } + + @Test() + public void getParameterValuesTest() throws Exception { + super.getParameterValuesTest(); + } + + @Test() + public void getProtocolTest() throws Exception { + super.getProtocolTest(); + } + + @Test() + public void getReaderTest() throws Exception { + super.getReaderTest(); + } + + @Test() + public void getRemoteAddrTest() throws Exception { + super.getRemoteAddrTest(); + } + + @Test() + public void getRemoteHostTest() throws Exception { + super.getRemoteHostTest(); + } + + @Test() + public void getRequestDispatcherTest() throws Exception { + super.getRequestDispatcherTest(); + } + + @Test() + public void getSchemeTest() throws Exception { + super.getSchemeTest(); + } + + @Test() + public void getServerNameTest() throws Exception { + super.getServerNameTest(); + } + + @Test() + public void getServerPortTest() throws Exception { + super.getServerPortTest(); + } + + @Test() + public void isSecureTest() throws Exception { + super.isSecureTest(); + } + + @Test() + public void removeAttributeTest() throws Exception { + super.removeAttributeTest(); + } + + @Test() + public void setAttributeTest() throws Exception { + super.setAttributeTest(); + } + + @Test() + public void setCharacterEncodingTest() throws Exception { + super.setCharacterEncodingTest(); + } + + @Test() + public void setCharacterEncodingTest1() throws Exception { + super.setCharacterEncodingTest1(); + } + + @Test() + public void setCharacterEncodingUnsupportedEncodingExceptionTest() throws Exception { + super.setCharacterEncodingUnsupportedEncodingExceptionTest(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequestwrapper/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequestwrapper/build.xml new file mode 100644 index 0000000000..65f87b4a52 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequestwrapper/build.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequestwrapper/servlet_plu_servletrequestwrapper_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequestwrapper/servlet_plu_servletrequestwrapper_web-fragment.xml new file mode 100644 index 0000000000..0c41732322 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequestwrapper/servlet_plu_servletrequestwrapper_web-fragment.xml @@ -0,0 +1,68 @@ + + + + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper.TestServlet + + + setCharacterEncodingUnsupportedEncodingExceptionTestWrapper + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper.SetCharacterEncodingUnsupportedEncodingExceptionTestWrapper + + + setCharacterEncodingUnsupportedEncodingExceptionTest + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper.SetCharacterEncodingUnsupportedEncodingExceptionTest + + + setCharacterEncodingTestWrapper + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper.SetCharacterEncodingTestWrapper + + + setCharacterEncodingTest + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper.SetCharacterEncodingTest + + + TestServlet + /TestServlet/* + + + setCharacterEncodingUnsupportedEncodingExceptionTestWrapper + /setCharacterEncodingUnsupportedEncodingExceptionTestWrapper + + + setCharacterEncodingUnsupportedEncodingExceptionTest + /setCharacterEncodingUnsupportedEncodingExceptionTest + + + setCharacterEncodingTestWrapper + /setCharacterEncodingTestWrapper + + + setCharacterEncodingTest + /setCharacterEncodingTest + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequestwrapper30/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequestwrapper30/URLClient.java new file mode 100644 index 0000000000..cb0f09c6bb --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequestwrapper30/URLClient.java @@ -0,0 +1,354 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet.servletrequestwrapper30; + +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest30.AsyncTestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest30.AsyncTests; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest30.SecondServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest30.TestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper30.AsyncTestServletWrapper; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper30.ErrorServletWrapper; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper30.TestServletWrapper; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive1 = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_plu_servletrequestwrapper30_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_plu_servletrequestwrapper30_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(AsyncTestServletWrapper.class, ErrorServletWrapper.class, TestServletWrapper.class, + TestServlet.class, AsyncTestServlet.class, AsyncTests.class, SecondServlet.class) + .addAsLibraries(javaArchive1); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + /* + * @testName: getServletContextTest + * + * @assertion_ids: Servlet:JAVADOC:721; + * + * @test_Strategy: Create a ServletRequestWrapper that wrap another servlet; + * calls ServletRequestWrapper.getServletContext(); verifies that returned + * ServletContext instance is consistent with the one stored in + * ServletConfigs. + */ + @Test + public void getServletContextTest() throws Exception { + setServletName("TestServletWrapper"); + TEST_PROPS.setProperty(APITEST, "getServletContextTest"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "TEST FAILED"); + TEST_PROPS.setProperty(SEARCH_STRING, "Test PASSED"); + invoke(); + } + + /* + * @testName: getDispatcherTypeTestRequest + * + * @assertion_ids: Servlet:JAVADOC:718; + * + * @test_Strategy: Create a ServletRequestWrapper that wraps TestServlet; + * Client send a request the ServletRequestWrapper; call + * ServletRequestWrapper.getDispatcherType() verifies that + * DispatcherType.REQUEST is returned. + */ + @Test + public void getDispatcherTypeTestRequest() throws Exception { + setServletName("TestServletWrapper"); + TEST_PROPS.setProperty(APITEST, "getDispatcherTypeTestRequest"); + TEST_PROPS.setProperty(SEARCH_STRING, "DispatcherType=REQUEST"); + invoke(); + } + + /* + * @testName: getDispatcherTypeTestForward + * + * @assertion_ids: Servlet:JAVADOC:718; + * + * @test_Strategy: Create a ServletRequestWrapper that wraps TestServlet; + * Client send a request the ServletRequestWrapper; Forward to SecondServlet + * call ServletRequestWrapper.getDispatcherType() verifies that + * DispatcherType.FORWARD is returned. + */ + @Test + public void getDispatcherTypeTestForward() throws Exception { + setServletName("TestServletWrapper"); + TEST_PROPS.setProperty(APITEST, "getDispatcherTypeTestForward"); + TEST_PROPS.setProperty(SEARCH_STRING, "DispatcherType=FORWARD"); + invoke(); + } + + /* + * @testName: getDispatcherTypeTestInclude + * + * @assertion_ids: Servlet:JAVADOC:718; + * + * @test_Strategy: Create a ServletRequestWrapper that wraps TestServlet; + * Client send a request the ServletRequestWrapper; Include to SecondServlet + * call ServletRequestWrapper.getDispatcherType() verifies that + * DispatcherType.INCLUDE is returned. + */ + @Test + public void getDispatcherTypeTestInclude() throws Exception { + setServletName("TestServletWrapper"); + TEST_PROPS.setProperty(APITEST, "getDispatcherTypeTestInclude"); + TEST_PROPS.setProperty(SEARCH_STRING, "DispatcherType=INCLUDE"); + invoke(); + } + + /* + * @testName: getDispatcherTypeTestError + * + * @assertion_ids: Servlet:JAVADOC:718; + * + * @test_Strategy: Create a ServletRequestWrapper that wraps SecondServlet; + * Maps 404 to the ServletRequestWrapper; Client send a request to + * nowhereland; In SecondServlet, call + * ServletRequestWrapper.getDispatcherType() verifies that + * DispatcherType.ERROR is returned. + */ + @Test + public void getDispatcherTypeTestError() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/nowheretobefound/ HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "DispatcherType=ERROR"); + TEST_PROPS.setProperty(STATUS_CODE, NOT_FOUND); + invoke(); + } + + /* + * @testName: getDispatcherTypeTestAsync + * + * @assertion_ids: Servlet:JAVADOC:640; Servlet:JAVADOC:703; + * Servlet:JAVADOC:710; + * + * @test_Strategy: Create three Servlets AsyncTestServletWrapper, + * AsyncTestServlet and AsyncTests, all support async; AsyncTestServletWrapper + * wraps AsyncTestServlet; Client send a request to AsyncTestServletWrapper; + * StartAsync in AsyncTestServlet; Invoke AsyncTests using + * AsyncContext.dispatch(String) call + * ServletRequestWrapper.getDispatcherType() verifies that + * DispatcherType.ASYNC is returned. + */ + @Test + public void getDispatcherTypeTestAsync() throws Exception { + setServletName("AsyncTestServletWrapper"); + TEST_PROPS.setProperty(APITEST, "getDispatcherTypeTestAsync"); + TEST_PROPS.setProperty(SEARCH_STRING, "DispatcherType=ASYNC"); + invoke(); + } + + /* + * @testName: asyncStartedTest1 + * + * @assertion_ids: Servlet:JAVADOC:722; Servlet:JAVADOC:727; + * + * @test_Strategy: Create three Servlets AsyncTestServletWrapper, + * AsyncTestServlet and AsyncTests, all support async; AsyncTestServletWrapper + * wraps AsyncTestServlet; Client send a request to AsyncTestServletWrapper; + * StartAsync in AsyncTestServlet ServletRequestWrapper.startAsync(); call + * ServletRequestWrapper.isAsyncStarted() verifies that true is returned. + */ + @Test + public void asyncStartedTest1() throws Exception { + setServletName("AsyncTestServletWrapper"); + TEST_PROPS.setProperty(APITEST, "asyncStartedTest1"); + TEST_PROPS.setProperty(SEARCH_STRING, "IsAsyncStarted=true"); + invoke(); + } + + /* + * @testName: asyncStartedTest2 + * + * @assertion_ids: Servlet:JAVADOC:722; + * + * @test_Strategy: Create three Servlets AsyncTestServletWrapper, + * AsyncTestServlet and AsyncTests, all support async; AsyncTestServletWrapper + * wraps AsyncTestServlet; Client send a request to AsyncTestServletWrapper; + * call ServletRequestWrapper.isAsyncStarted() without start async mode + * verifies that false is returned. + */ + @Test + public void asyncStartedTest2() throws Exception { + setServletName("AsyncTestServletWrapper"); + TEST_PROPS.setProperty(APITEST, "asyncStartedTest2"); + TEST_PROPS.setProperty(SEARCH_STRING, "IsAsyncStarted=false"); + invoke(); + } + + /* + * @testName: asyncStartedTest3 + * + * @assertion_ids: Servlet:JAVADOC:638; Servlet:JAVADOC:722; + * Servlet:JAVADOC:727; + * + * @test_Strategy: Create three Servlets AsyncTestServletWrapper, + * AsyncTestServlet and AsyncTests, all support async; AsyncTestServletWrapper + * wraps AsyncTestServlet; Client send a request to AsyncTestServletWrapper; + * StartAsync in AsyncTestServlet ServletRequestWrapper.startAsync(); call + * ServletRequestWrapper.isAsyncStarted() after AsyncContext.complete() called + * verifies that true is returned before it dispatch return to the container + */ + @Test + public void asyncStartedTest3() throws Exception { + setServletName("AsyncTestServletWrapper"); + TEST_PROPS.setProperty(APITEST, "asyncStartedTest3"); + TEST_PROPS.setProperty(SEARCH_STRING, "IsAsyncStarted=true"); + invoke(); + } + + /* + * @testName: asyncStartedTest4 + * + * @assertion_ids: Servlet:JAVADOC:640; Servlet:JAVADOC:722; + * Servlet:JAVADOC:727; + * + * @test_Strategy: Create three Servlets AsyncTestServletWrapper, + * AsyncTestServlet and AsyncTests, all support async; AsyncTestServletWrapper + * wraps AsyncTestServlet; Client send a request to AsyncTestServletWrapper; + * StartAsync in AsyncTestServlet ServletRequestWrapper.startAsync(); Invoke + * AsyncTests using AsyncContext.dispatch(String) call + * ServletRequestWrapper.isAsyncStarted() verifies that false is returned. + */ + @Test + public void asyncStartedTest4() throws Exception { + setServletName("AsyncTestServletWrapper"); + TEST_PROPS.setProperty(APITEST, "asyncStartedTest4"); + TEST_PROPS.setProperty(SEARCH_STRING, "IsAsyncStarted=false"); + invoke(); + } + + /* + * @testName: isAsyncSupportedTest1 + * + * @assertion_ids: Servlet:JAVADOC:723; + * + * @test_Strategy: Create two Servlets AsyncTestServletWrapper, + * AsyncTestServlet all support async; AsyncTestServletWrapper wraps + * AsyncTestServlet; Client send a request to AsyncTestServletWrapper; call + * ServletRequestWrapper.isAsyncSupported() verifies that true is returned. + */ + @Test + public void isAsyncSupportedTest1() throws Exception { + setServletName("AsyncTestServletWrapper"); + TEST_PROPS.setProperty(APITEST, "isAsyncSupportedTest"); + TEST_PROPS.setProperty(SEARCH_STRING, "isAsyncSupported=true"); + invoke(); + } + + /* + * @testName: isAsyncSupportedTest2 + * + * @assertion_ids: Servlet:JAVADOC:723; + * + * @test_Strategy: Create two Servlets TestServletWrapper, TestServlet all + * does not support async; TestServletWrapper wraps TestServlet; Client send a + * request to TestServletWrapper; call + * ServletRequestWrapper.isAsyncSupported() verifies that false is returned. + */ + @Test + public void isAsyncSupportedTest2() throws Exception { + setServletName("TestServletWrapper"); + TEST_PROPS.setProperty(APITEST, "isAsyncSupportedTest"); + TEST_PROPS.setProperty(SEARCH_STRING, "isAsyncSupported=false"); + invoke(); + } + + /* + * @testName: startAsyncTest1 + * + * @assertion_ids: Servlet:JAVADOC:728; + * + * @test_Strategy: Create two Servlets TestServletWrapper, TestServlet all + * does not support async; TestServletWrapper wraps TestServlet; Client send a + * request to TestServletWrapper; call ServletRequestWrapper.startAsyncTest() + * verifies that IllegalStateException is thrown. + */ + @Test + public void startAsyncTest1() throws Exception { + setServletName("TestServletWrapper"); + TEST_PROPS.setProperty(APITEST, "startAsyncTest"); + invoke(); + } + + /* + * @testName: startAsyncTest2 + * + * @assertion_ids: Servlet:JAVADOC:640; Servlet:JAVADOC:722; + * Servlet:JAVADOC:727; Servlet:JAVADOC:728; + * + * @test_Strategy: Create three Servlets AsyncTestServletWrapper, + * AsyncTestServlet, AsyncTest all support async; AsyncTestServletWrapper + * wraps AsyncTestServlet; Client send a request to AsyncTestServletWrapper; + * Start Async in AsyncTestServlet; Invoke AsyncTests using + * AsyncContext.dispatch(String) Call ServletRequestWrapper.startAsyncTest() + * outside of dispatch verifies that IllegalStateException is thrown. + */ + @Test + public void startAsyncTest2() throws Exception { + setServletName("AsyncTestServletWrapper"); + TEST_PROPS.setProperty(APITEST, "startAsyncTest"); + TEST_PROPS.setProperty(SEARCH_STRING, "IllegalStateException thrown"); + invoke(); + } + + /* + * @testName: getAsyncContextTest + * + * @assertion_ids: Servlet:JAVADOC:638; Servlet:JAVADOC:716; + * Servlet:JAVADOC:727; + * + * @test_Strategy: Create two Servlets AsyncTestServletWrapper, + * AsyncTestServlet all support async; AsyncTestServletWrapper wraps + * AsyncTestServlet; Client send a request to AsyncTestServletWrapper; Start + * Async in AsyncTestServlet; call ServletRequestWrapper.getAsyncContext() + * verifies it works. + */ + @Test + public void getAsyncContextTest() throws Exception { + setServletName("AsyncTestServletWrapper"); + TEST_PROPS.setProperty(APITEST, "getAsyncContextTest"); + TEST_PROPS.setProperty(SEARCH_STRING, "Test PASSED"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequestwrapper30/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequestwrapper30/build.xml new file mode 100644 index 0000000000..d7ed9eea7d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequestwrapper30/build.xml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequestwrapper30/servlet_plu_servletrequestwrapper30_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequestwrapper30/servlet_plu_servletrequestwrapper30_web-fragment.xml new file mode 100644 index 0000000000..5b2e4dd9da --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequestwrapper30/servlet_plu_servletrequestwrapper30_web-fragment.xml @@ -0,0 +1,92 @@ + + + + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest30.TestServlet + + + AsyncTestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest30.AsyncTestServlet + true + + + AsyncTests + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest30.AsyncTests + true + + + SecondServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequest30.SecondServlet + + + TestServletWrapper + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper30.TestServletWrapper + + + AsyncTestServletWrapper + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper30.AsyncTestServletWrapper + true + + + ErrorServletWrapper + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper30.ErrorServletWrapper + + + TestServlet + /TestServlet + + + AsyncTestServlet + /AsyncTestServlet + + + AsyncTests + /async/AsyncTests + + + SecondServlet + /forward/ForwardedServlet + /include/IncludedServlet + + + TestServletWrapper + /TestServletWrapper + + + AsyncTestServletWrapper + /AsyncTestServletWrapper + + + ErrorServletWrapper + /error/ErrorServletWrapper + + + 404 + /error/ErrorServletWrapper + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequestwrapper30x/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequestwrapper30x/URLClient.java new file mode 100644 index 0000000000..662d67bb6c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequestwrapper30x/URLClient.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet.servletrequestwrapper30x; + +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper30x.IsWrapperForTest; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper30x.TCKServletRequestWrapper; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper30x.TCKServletRequestsubWrapper; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + + JavaArchive javaArchive1 = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_plu_servletrequestwrapper30x_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_plu_servletrequestwrapper30x_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(IsWrapperForTest.class, TCKServletRequestsubWrapper.class, TCKServletRequestWrapper.class) + .addAsLibraries(javaArchive1); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + /* + * @testName: isWrapperForTest + * + * @assertion_ids: Servlet:JAVADOC:724; Servlet:JAVADOC:725; + * + * @test_Strategy: Create a Servlets isWrapperForTest; In the servlet, wrap + * the Resquest a few time and in different ways; verifies the following + * works: - jakarta.servlet.ServletRequestWrapper.isWrapperFor(ServletRequest) - + * jakarta.servlet.ServletRequestWrapper.isWrapperFor(Class) + */ + @Test + public void isWrapperForTest() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/IsWrapperForTest HTTP/1.1"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "Test Failed"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequestwrapper30x/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequestwrapper30x/build.xml new file mode 100644 index 0000000000..beb706badf --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequestwrapper30x/build.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequestwrapper30x/servlet_plu_servletrequestwrapper30x_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequestwrapper30x/servlet_plu_servletrequestwrapper30x_web-fragment.xml new file mode 100644 index 0000000000..6c297148ec --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletrequestwrapper30x/servlet_plu_servletrequestwrapper30x_web-fragment.xml @@ -0,0 +1,36 @@ + + + + + + IsWrapperForTest + com.sun.ts.tests.servlet.api.jakarta_servlet.servletrequestwrapper30x.IsWrapperForTest + + + IsWrapperForTest + /IsWrapperForTest + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletresponse/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletresponse/URLClient.java new file mode 100644 index 0000000000..9bde995c26 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletresponse/URLClient.java @@ -0,0 +1,467 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet.servletresponse; + +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletresponse.SetCharacterEncodingTestServlet; +import com.sun.ts.tests.servlet.common.response.ResponseClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.common.servlets.GenericCheckTestResultServlet; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends ResponseClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive1 = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar").addClasses(TestServlet1.class, RequestListener1.class).addAsResource(URLClient.class.getResource("servlet_plu_servletresponse_web-fragment.xml"), "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_plu_servletresponse_web.war").addAsLibraries(CommonServlets.getCommonServletsArchive()).addClasses(SetCharacterEncodingTestServlet.class, GenericCheckTestResultServlet.class).addAsLibraries(javaArchive1); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + /* Run test */ + /* + * @testName: flushBufferTest + * + * @assertion_ids: Servlet:JAVADOC:158 + * + * @test_Strategy: Servlet writes data in the buffer and flushes it + */ + /* + * @testName: getBufferSizeTest + * + * @assertion_ids: Servlet:JAVADOC:156;Servlet:JAVADOC:157 + * + * @test_Strategy: Servlet flushes buffer and verifies the size of the buffer + */ + /* + * @testName: getLocaleDefaultTest + * + * @assertion_ids: Servlet:JAVADOC:164; + * + * @test_Strategy: Validate that if setLocale() is not called on the response, + * the getLocale() will return the default locale of the VM the container is + * running in. + */ + /* + * @testName: getLocaleTest + * + * @assertion_ids: Servlet:JAVADOC:166 + * + * @test_Strategy: Servlet set Locale and then verifies it + * + */ + /* + * @testName: getOutputStreamFlushTest + * + * @assertion_ids: Servlet:JAVADOC:140 + * + * @test_Strategy: Servlet gets an output stream, writes to it, flushes it + * then checks that the response was committed + */ + /* + * @testName: getOutputStreamTest + * + * @assertion_ids: Servlet:JAVADOC:141 + * + * @test_Strategy: Servlet gets an output stream and writes to it. + */ + /* + * @testName: getOutputStreamIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:143 + * + * @test_Strategy: Servlet tries to get an stream object after calling + * getWriter + */ + /* + * @testName: getWriterTest + * + * @assertion_ids: Servlet:JAVADOC:144; Servlet:JAVADOC:151.3; + * + * @test_Strategy: Client sets the content type. Servlet then gets a Writer + * object, then sets content type and writes data. Verify that content type + * didn't get set by servlet + */ + /* + * @testName: getWriterFlushTest + * + * @assertion_ids: Servlet:JAVADOC:146 + * + * @test_Strategy: Servlet gets a Writer object, writes data then flushes, + * then verifies response was committed + */ + /* + * @testName: getWriterAfterTest + * + * @assertion_ids: Servlet:JAVADOC:145; Servlet:JAVADOC:151.3; + * + * @test_Strategy: Client sets the content type. Servlet then gets a Writer + * object, then sets content type and writes data. Verify that content type + * did get set by servlet + */ + /* + * @testName: getWriterIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:149; + * + * @test_Strategy: Servlet tries to get a Writer object after calling + * getOutputStream + */ + /* + * @testName: isCommittedTest + * + * @assertion_ids: Servlet:JAVADOC:161 + * + * @test_Strategy: Servlet checks before and after response is flushed + * + */ + /* + * @testName: resetBufferTest + * + * @assertion_ids: Servlet:JAVADOC:160; Servlet:SPEC:31; + * + * @test_Strategy: Servlet writes data to the response, resets the buffer and + * then writes new data + */ + /* + * @testName: resetTest + * + * @assertion_ids: Servlet:JAVADOC:162; Servlet:SPEC:31; + * + * @test_Strategy: Servlet writes data to the response, does a reset, then + * writes new data + */ + /* + * @testName: resetTest1 + * + * @assertion_ids: Servlet:JAVADOC:162; Servlet:SPEC:31; + * + * @test_Strategy: Servlet writes data to the response, set the Headers, does + * a reset, then writes new data, set the new Header + */ + /* + * @testName: resetIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:163; Servlet:SPEC:31; + * + * @test_Strategy: Servlet writes data, flushes the buffer then tries to do a + * reset + */ + /* + * @testName: getCharacterEncodingTest + * + * @assertion_ids: Servlet:JAVADOC:137 + * + * @test_Strategy: Servlet sets encoding then checks it. + */ + /* + * @testName: getCharacterEncodingDefaultTest + * + * @assertion_ids: Servlet:JAVADOC:138 + * + * @test_Strategy: Servlet checks for the default encoding + */ + /* + * @testName: setCharacterEncodingTest + * + * @assertion_ids: Servlet:JAVADOC:139; Servlet:JAVADOC:151.3; + * + * @test_Strategy: Servlet set the encoding and client verifies it + */ + /* + * @testName: setBufferSizeTest + * + * @assertion_ids: Servlet:JAVADOC:154 + * + * @test_Strategy: Servlet sets the buffer size then verifies it was set + */ + /* + * @testName: setBufferSizeIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:155 + * + * @test_Strategy: Servlet writes data and flushes buffer then tries to get + * the buffer size + */ + /* + * @testName: setContentLengthTest + * + * @assertion_ids: Servlet:JAVADOC:150 + * + * @test_Strategy: Servlet sets the content length + */ + /* + * @testName: getContentTypeTest + * + * @assertion_ids: Servlet:JAVADOC:152; Servlet:JAVADOC:151.3; + * Servlet:SPEC:34; + * + * @test_Strategy: Servlet verifies the content type sent by the client + */ + /* + * @testName: getContentType1Test + * + * @assertion_ids: Servlet:JAVADOC:152; Servlet:JAVADOC:151.3; + * Servlet:SPEC:34; + * + * @test_Strategy: Servlet verifies the content type set by the servlet + */ + /* + * @testName: getContentTypeNullTest + * + * @assertion_ids: Servlet:JAVADOC:153; Servlet:SPEC:34; + * + * @test_Strategy: Servlet verifies the content-type when not set by + * programmer + */ + /* + * @testName: getContentTypeNull1Test + * + * @assertion_ids: Servlet:JAVADOC:153; Servlet:SPEC:34; + * + * @test_Strategy: Servlet verifies the content-type when not set by + * programmer and only character encoding is set + */ + /* + * @testName: getContentTypeNull2Test + * + * @assertion_ids: Servlet:JAVADOC:151; Servlet:JAVADOC:151.1; + * Servlet:JAVADOC:153.1 + * + * @test_Strategy: Servlet verifies content-type is being re-set by programmer + * and character encoding setting does not change + */ + /* + * @testName: setContentTypeTest + * + * @assertion_ids: Servlet:JAVADOC:151; Servlet:JAVADOC:151.3; + * Servlet:SPEC:34; + * + * @test_Strategy: Servlet sets the content type Verify Content-Type is set in + * Client + */ + /* + * @testName: setContentType1Test + * + * @assertion_ids: Servlet:JAVADOC:151; Servlet:SPEC:34; + * + * @test_Strategy: Servlet sets the content-type, and verifies it with + * getContentType() + */ + /* + * @testName: setContentType2Test + * + * @assertion_ids: Servlet:JAVADOC:151.2; Servlet:JAVADOC:151.3; + * Servlet:SPEC:34; + * + * @test_Strategy: Servlet sets the content-type, Commit the response; Set the + * content-type again Verifies that content-type is set the first time The + * second setting is ignored. + */ + /* + * @testName: setLocaleTest + * + * @assertion_ids: Servlet:JAVADOC:164 + * + * @test_Strategy: Servlet sets the Locale + */ + /* + * @testName: setLocale1Test + * + * @assertion_ids: Servlet:JAVADOC:164; Servlet:JAVADOC:151.3; + * + * @test_Strategy: Servlet sets the Locale + */ + @Test() + public void flushBufferTest() throws Exception { + super.flushBufferTest(); + } + + @Test() + public void getBufferSizeTest() throws Exception { + super.getBufferSizeTest(); + } + + @Test() + public void getCharacterEncodingDefaultTest() throws Exception { + super.getCharacterEncodingDefaultTest(); + } + + @Test() + public void getCharacterEncodingTest() throws Exception { + super.getCharacterEncodingTest(); + } + + @Test() + public void getContentType1Test() throws Exception { + super.getContentType1Test(); + } + + @Test() + public void getContentTypeNull1Test() throws Exception { + super.getContentTypeNull1Test(); + } + + @Test() + public void getContentTypeNull2Test() throws Exception { + super.getContentTypeNull2Test(); + } + + @Test() + public void getContentTypeNullTest() throws Exception { + super.getContentTypeNullTest(); + } + + @Test() + public void getContentTypeTest() throws Exception { + super.getContentTypeTest(); + } + + @Test() + public void getLocaleDefaultTest() throws Exception { + super.getLocaleDefaultTest(); + } + + @Test() + public void getLocaleTest() throws Exception { + super.getLocaleTest(); + } + + @Test() + public void getOutputStreamFlushTest() throws Exception { + super.getOutputStreamFlushTest(); + } + + @Test() + public void getOutputStreamIllegalStateExceptionTest() throws Exception { + super.getOutputStreamIllegalStateExceptionTest(); + } + + @Test() + public void getOutputStreamTest() throws Exception { + super.getOutputStreamTest(); + } + + @Test() + public void getWriterAfterTest() throws Exception { + super.getWriterAfterTest(); + } + + @Test() + public void getWriterFlushTest() throws Exception { + super.getWriterFlushTest(); + } + + @Test() + public void getWriterIllegalStateExceptionTest() throws Exception { + super.getWriterIllegalStateExceptionTest(); + } + + @Test() + public void getWriterTest() throws Exception { + super.getWriterTest(); + } + + @Test() + public void isCommittedTest() throws Exception { + super.isCommittedTest(); + } + + @Test() + public void resetBufferTest() throws Exception { + super.resetBufferTest(); + } + + @Test() + public void resetIllegalStateExceptionTest() throws Exception { + super.resetIllegalStateExceptionTest(); + } + + @Test() + public void resetTest() throws Exception { + super.resetTest(); + } + + @Test() + public void resetTest1() throws Exception { + super.resetTest1(); + } + + @Test() + public void setBufferSizeIllegalStateExceptionTest() throws Exception { + super.setBufferSizeIllegalStateExceptionTest(); + } + + @Test() + public void setBufferSizeTest() throws Exception { + super.setBufferSizeTest(); + } + + @Test() + public void setCharacterEncodingTest() throws Exception { + super.setCharacterEncodingTest(); + } + + @Test() + public void setContentLengthTest() throws Exception { + super.setContentLengthTest(); + } + + @Test() + public void setContentType1Test() throws Exception { + super.setContentType1Test(); + } + + @Test() + public void setContentType2Test() throws Exception { + super.setContentType2Test(); + } + + @Test() + public void setContentTypeTest() throws Exception { + super.setContentTypeTest(); + } + + @Test() + public void setLocale1Test() throws Exception { + super.setLocale1Test(); + } + + @Test() + public void setLocaleTest() throws Exception { + super.setLocaleTest(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletresponse/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletresponse/build.xml new file mode 100644 index 0000000000..c9a05efb39 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletresponse/build.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletresponse/servlet_plu_servletresponse_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletresponse/servlet_plu_servletresponse_web-fragment.xml new file mode 100644 index 0000000000..2f2bd1a987 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletresponse/servlet_plu_servletresponse_web-fragment.xml @@ -0,0 +1,58 @@ + + + + + + TestServlet + com.sun.ts.tests.servlet.common.response.ResponseTestServlet + + + setCharacterEncodingTest + com.sun.ts.tests.servlet.api.jakarta_servlet.servletresponse.SetCharacterEncodingTestServlet + + + checkTestResult + com.sun.ts.tests.servlet.common.servlets.GenericCheckTestResultServlet + + + TestServlet + /TestServlet/* + + + setCharacterEncodingTest + /setCharacterEncodingTest + + + checkTestResult + /checkTestResult + + + 54 + + + + ja + Shift_JIS + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletresponsewrapper/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletresponsewrapper/URLClient.java new file mode 100644 index 0000000000..5ba4a435c9 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletresponsewrapper/URLClient.java @@ -0,0 +1,314 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet.servletresponsewrapper; + +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletresponsewrapper.SetCharacterEncodingTestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletresponsewrapper.TestServlet; +import com.sun.ts.tests.servlet.common.response.HttpResponseClient; +import com.sun.ts.tests.servlet.common.response.ResponseTestServlet; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends HttpResponseClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar").addClasses(TestServlet1.class, RequestListener1.class).addAsResource(URLClient.class.getResource("servlet_plu_servletresponsewrapper_web-fragment.xml"), "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_plu_servletresponsewrapper_web.war").addAsLibraries(CommonServlets.getCommonServletsArchive()).addClasses(SetCharacterEncodingTestServlet.class, TestServlet.class, ResponseTestServlet.class).addAsLibraries(javaArchive); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: responseWrapperConstructorTest + * + * @assertion_ids: Servlet:JAVADOC:9 + * + * @test_Strategy: Servlet calls wrapper constructor + */ + @Test + public void responseWrapperConstructorTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "responseWrapperConstructorTest"); + invoke(); + } + + /* + * @testName: responseWrapperGetResponseTest + * + * @assertion_ids: Servlet:JAVADOC:10 + * + * @test_Strategy: Servlet gets wrapped response object + */ + @Test + public void responseWrapperGetResponseTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "responseWrapperGetResponseTest"); + invoke(); + } + + /* + * @testName: responseWrapperSetResponseTest + * + * @assertion_ids: Servlet:JAVADOC:11 + * + * @test_Strategy: Servlet sets wrapped response object + */ + @Test + public void responseWrapperSetResponseTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "responseWrapperSetResponseTest"); + invoke(); + } + + /* + * @testName: responseWrapperSetResponseIllegalArgumentExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:12 + * + * @test_Strategy: Servlet sets wrapped response object + */ + @Test + public void responseWrapperSetResponseIllegalArgumentExceptionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "responseWrapperSetResponseIllegalArgumentExceptionTest"); + invoke(); + } + + /* + * @testName: flushBufferTest + * + * @assertion_ids: Servlet:JAVADOC:24 + * + * @test_Strategy: Servlet wraps response. Servlet writes data in the buffer + * and flushes it + */ + /* + * @testName: getBufferSizeTest + * + * @assertion_ids: Servlet:JAVADOC:23 + * + * @test_Strategy: Servlet wraps response. Servlet flushes buffer and verifies + * the size of the buffer + */ + /* + * @testName: getLocaleTest + * + * @assertion_ids: Servlet:JAVADOC:30 + * + * @test_Strategy: Servlet wraps response. Servlet set Locale and then + * verifies it + * + */ + /* + * @testName: getOutputStreamTest + * + * @assertion_ids: Servlet:JAVADOC:15 + * + * @test_Strategy: Servlet wraps response. Servlet gets an output stream and + * writes to it. + */ + /* + * @testName: getWriterTest + * + * @assertion_ids: Servlet:JAVADOC:17 + * + * @test_Strategy: Servlet wraps response. Servlet gets a Writer object, then + * sets the content type; Verify that content type didn't get set by servlet + */ + /* + * @testName: isCommittedTest + * + * @assertion_ids: Servlet:JAVADOC:26 + * + * @test_Strategy: Servlet wraps response. Servlet checks before and after + * response is flushed + * + */ + /* + * @testName: resetBufferTest + * + * @assertion_ids: Servlet:JAVADOC:28 + * + * @test_Strategy: Servlet wraps response. Servlet writes data to the + * response, resets the buffer and then writes new data + */ + /* + * @testName: resetTest + * + * @assertion_ids: Servlet:JAVADOC:27 + * + * @test_Strategy: Servlet wraps response. Servlet writes data to the + * response, does a reset, then writes new data + */ + /* + * @testName: resetTest1 + * + * @assertion_ids: Servlet:JAVADOC:27; Servlet:JAVADOC:162; Servlet:SPEC:31; + * + * @test_Strategy: Servlet writes data to the response, set the Headers, does + * a reset, then writes new data, set the new Header + */ + /* + * @testName: getCharacterEncodingTest + * + * @assertion_ids: Servlet:JAVADOC:14 + * + * @test_Strategy: Servlet wraps response. Servlet checks for the default + * encoding + */ + /* + * @testName: setCharacterEncodingTest + * + * @assertion_ids: Servlet:JAVADOC:13 + * + * @test_Strategy: Servlet wraps response. Servlet set the encoding and client + * verifies it + */ + /* + * @testName: setBufferSizeTest + * + * @assertion_ids: Servlet:JAVADOC:22 + * + * @test_Strategy: Servlet wraps response. Servlet sets the buffer size then + * verifies it was set + */ + /* + * @testName: setContentLengthTest + * + * @assertion_ids: Servlet:JAVADOC:19 + * + * @test_Strategy: Servlet wraps response. Servlet sets the content length + */ + /* + * @testName: getContentTypeTest + * + * @assertion_ids: Servlet:JAVADOC:21; Servlet:SPEC:34; + * + * @test_Strategy: Servlet wraps response. Servlet verifies the content type + * sent by the client + */ + /* + * @testName: setContentTypeTest + * + * @assertion_ids: Servlet:JAVADOC:20; Servlet:SPEC:34; + * + * @test_Strategy: Servlet wraps response. Servlet sets the content type + * + */ + /* + * @testName: setLocaleTest + * + * @assertion_ids: Servlet:JAVADOC:29 + * + * @test_Strategy: Servlet wraps response. Servlet sets the Locale + */ + @Test() + public void flushBufferTest() throws Exception { + super.flushBufferTest(); + } + + @Test() + public void getBufferSizeTest() throws Exception { + super.getBufferSizeTest(); + } + + @Test() + public void getCharacterEncodingTest() throws Exception { + super.getCharacterEncodingTest(); + } + + @Test() + public void getContentTypeTest() throws Exception { + super.getContentTypeTest(); + } + + @Test() + public void getLocaleTest() throws Exception { + super.getLocaleTest(); + } + + @Test() + public void getOutputStreamTest() throws Exception { + super.getOutputStreamTest(); + } + + @Test() + public void getWriterTest() throws Exception { + super.getWriterTest(); + } + + @Test() + public void isCommittedTest() throws Exception { + super.isCommittedTest(); + } + + @Test() + public void resetBufferTest() throws Exception { + super.resetBufferTest(); + } + + @Test() + public void resetTest() throws Exception { + super.resetTest(); + } + + @Test() + public void resetTest1() throws Exception { + super.resetTest1(); + } + + @Test() + public void setBufferSizeTest() throws Exception { + super.setBufferSizeTest(); + } + + @Test() + public void setCharacterEncodingTest() throws Exception { + super.setCharacterEncodingTest(); + } + + @Test() + public void setContentLengthTest() throws Exception { + super.setContentLengthTest(); + } + + @Test() + public void setContentTypeTest() throws Exception { + super.setContentTypeTest(); + } + + @Test() + public void setLocaleTest() throws Exception { + super.setLocaleTest(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletresponsewrapper/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletresponsewrapper/build.xml new file mode 100644 index 0000000000..3ef3eb851f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletresponsewrapper/build.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletresponsewrapper/servlet_plu_servletresponsewrapper_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletresponsewrapper/servlet_plu_servletresponsewrapper_web-fragment.xml new file mode 100644 index 0000000000..ddc2d499d4 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletresponsewrapper/servlet_plu_servletresponsewrapper_web-fragment.xml @@ -0,0 +1,44 @@ + + + + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.servletresponsewrapper.TestServlet + + + setCharacterEncodingTest + com.sun.ts.tests.servlet.api.jakarta_servlet.servletresponsewrapper.SetCharacterEncodingTestServlet + + + TestServlet + /TestServlet/* + + + setCharacterEncodingTest + /setCharacterEncodingTest + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletresponsewrapper30/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletresponsewrapper30/URLClient.java new file mode 100644 index 0000000000..23541ef429 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletresponsewrapper30/URLClient.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet.servletresponsewrapper30; + +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletresponsewrapper30.IsWrapperForTest; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletresponsewrapper30.TCKServletResponseWrapper; +import com.sun.ts.tests.servlet.api.jakarta_servlet.servletresponsewrapper30.TCKServletResponsesubWrapper; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_plu_servletresponsewrapper30_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_plu_servletresponsewrapper30_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(IsWrapperForTest.class, TCKServletResponsesubWrapper.class, TCKServletResponseWrapper.class) + .addAsLibraries(javaArchive); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + /* + * @testName: isWrapperForTest + * + * @assertion_ids: Servlet:JAVADOC:731; Servlet:JAVADOC:732; + * + * @test_Strategy: Create a Servlets isWrapperForTest; In the servlet, wrap + * the Response a few time and in different ways; verifies the following + * works: - jakarta.servlet.ServletResponseWrapper.isWrapperFor(ServletResponse) + * - jakarta.servlet.ServletResponseWrapper.isWrapperFor(Class) + */ + @Test + public void isWrapperForTest() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/IsWrapperForTest HTTP/1.1"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "Test Failed"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletresponsewrapper30/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletresponsewrapper30/build.xml new file mode 100644 index 0000000000..abd522a4a5 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletresponsewrapper30/build.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletresponsewrapper30/servlet_plu_servletresponsewrapper30_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletresponsewrapper30/servlet_plu_servletresponsewrapper30_web-fragment.xml new file mode 100644 index 0000000000..8c6d22e41e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/servletresponsewrapper30/servlet_plu_servletresponsewrapper30_web-fragment.xml @@ -0,0 +1,36 @@ + + + + + + IsWrapperForTest + com.sun.ts.tests.servlet.api.jakarta_servlet.servletresponsewrapper30.IsWrapperForTest + + + IsWrapperForTest + /IsWrapperForTest + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/sessiontrackingmode/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/sessiontrackingmode/URLClient.java new file mode 100644 index 0000000000..2cf34e60b8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/sessiontrackingmode/URLClient.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet.sessiontrackingmode; + +import com.sun.ts.tests.servlet.api.jakarta_servlet.sessiontrackingmode.TestListener; +import com.sun.ts.tests.servlet.api.jakarta_servlet.sessiontrackingmode.TestServlet; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive1 = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_plu_sessiontrackingmode_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_plu_sessiontrackingmode_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestListener.class, TestServlet.class) + .addAsLibraries(javaArchive1); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: setSessionTrackingModes + * + * @assertion_ids: Servlet:JAVADOC:695; Servlet:JAVADOC:684; + * Servlet:JAVADOC:687; + * + * @test_Strategy: Create a ServletListener, in which call + * ServletContext.setSessionTrackingModes() Create a Servlet, verify the above + * works using getEffectiveSessionTrackingModes() + */ + @Test + public void setSessionTrackingModes() throws Exception { + TEST_PROPS.setProperty(APITEST, "setSessionTrackingModes"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/sessiontrackingmode/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/sessiontrackingmode/build.xml new file mode 100644 index 0000000000..68d0b2aa92 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/sessiontrackingmode/build.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/sessiontrackingmode/servlet_plu_sessiontrackingmode_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/sessiontrackingmode/servlet_plu_sessiontrackingmode_web-fragment.xml new file mode 100644 index 0000000000..f7869cdf99 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/sessiontrackingmode/servlet_plu_sessiontrackingmode_web-fragment.xml @@ -0,0 +1,39 @@ + + + + + + com.sun.ts.tests.servlet.api.jakarta_servlet.sessiontrackingmode.TestListener + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.sessiontrackingmode.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/srattributeevent/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/srattributeevent/URLClient.java new file mode 100644 index 0000000000..d9a01f11c2 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/srattributeevent/URLClient.java @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet.srattributeevent; + +import com.sun.ts.tests.servlet.api.jakarta_servlet.srattributeevent.SRAttributeListener; +import com.sun.ts.tests.servlet.api.jakarta_servlet.srattributeevent.TestServlet; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive1 = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_plu_srattributeevent_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_plu_srattributeevent_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(SRAttributeListener.class, TestServlet.class) + .addAsLibraries(javaArchive1); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: constructorTest + * + * @assertion_ids: Servlet:JAVADOC:66 + * + * @test_Strategy: Servlet instanciate the constructor + */ + @Test + public void constructorTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "constructorTest"); + invoke(); + } + + /* + * @testName: addedTest + * + * @assertion_ids: + * Servlet:JAVADOC:67;Servlet:JAVADOC:68;Servlet:JAVADOC:71;Servlet:JAVADOC:72 + * + * @test_Strategy: Servlet adds an attribute. The listener should detect the + * add and write a message out to a static log. Servlet then reads the log and + * verifys the result. It also verifies the requets and context that changed + * + */ + @Test + public void addedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "addedTest"); + invoke(); + } + + /* + * @testName: removedTest + * + * @assertion_ids: + * Servlet:JAVADOC:67;Servlet:JAVADOC:69;Servlet:JAVADOC:71;Servlet:JAVADOC:72 + * + * @test_Strategy: Servlet adds/removes an attribute. The listener should + * detect the add and write a message out to a static log. Servlet then reads + * the log and verifys the result. It also verifies the requets and context + * that changed + */ + @Test + public void removedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "removedTest"); + invoke(); + } + + /* + * @testName: replacedTest + * + * @assertion_ids: + * Servlet:JAVADOC:67;Servlet:JAVADOC:70;Servlet:JAVADOC:71;Servlet:JAVADOC:72 + * + * @test_Strategy: Servlet adds/replaces an attribute. The listener should + * detect the add and write a message out to a static log. Servlet then reads + * the log and verifys the result. It also verifies the requets and context + * that changed + */ + @Test + public void replacedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "replacedTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/srattributeevent/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/srattributeevent/build.xml new file mode 100644 index 0000000000..13e58ddeef --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/srattributeevent/build.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/srattributeevent/servlet_plu_srattributeevent_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/srattributeevent/servlet_plu_srattributeevent_web-fragment.xml new file mode 100644 index 0000000000..b6c0b96eb3 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/srattributeevent/servlet_plu_srattributeevent_web-fragment.xml @@ -0,0 +1,39 @@ + + + + + + com.sun.ts.tests.servlet.api.jakarta_servlet.srattributeevent.SRAttributeListener + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.srattributeevent.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/srattributelistener/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/srattributelistener/URLClient.java new file mode 100644 index 0000000000..3bd5c25ead --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/srattributelistener/URLClient.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet.srattributelistener; + +import com.sun.ts.tests.servlet.api.jakarta_servlet.srattributelistener.SRAttributeListener; +import com.sun.ts.tests.servlet.api.jakarta_servlet.srattributelistener.TestServlet; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive1 = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_plu_srattributelistener_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_plu_srattributelistener_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(SRAttributeListener.class, TestServlet.class) + .addAsLibraries(javaArchive1); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: addedTest + * + * @assertion_ids: Servlet:JAVADOC:169 + * + * @test_Strategy: Servlet adds an attribute. The listener should detect the + * add and write a message out to a static log. Servlet then reads the log and + * verifys the result. + * + */ + @Test + public void addedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "addedTest"); + invoke(); + } + + /* + * @testName: removedTest + * + * @assertion_ids: Servlet:JAVADOC:170 + * + * @test_Strategy: Servlet adds/removes an attribute. The listener should + * detect the add and write a message out to a static log. Servlet then reads + * the log and verifys the result. + */ + @Test + public void removedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "removedTest"); + invoke(); + } + + /* + * @testName: replacedTest + * + * @assertion_ids: Servlet:JAVADOC:171 + * + * @test_Strategy: Servlet adds/replaces an attribute. The listener should + * detect the add and write a message out to a static log. Servlet then reads + * the log and verifys the result. + */ + @Test + public void replacedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "replacedTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/srattributelistener/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/srattributelistener/build.xml new file mode 100644 index 0000000000..a9613f0c75 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/srattributelistener/build.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/srattributelistener/servlet_plu_srattributelistener_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/srattributelistener/servlet_plu_srattributelistener_web-fragment.xml new file mode 100644 index 0000000000..517860ba30 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/srattributelistener/servlet_plu_srattributelistener_web-fragment.xml @@ -0,0 +1,39 @@ + + + + + + com.sun.ts.tests.servlet.api.jakarta_servlet.srattributelistener.SRAttributeListener + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.srattributelistener.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/srevent/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/srevent/URLClient.java new file mode 100644 index 0000000000..52d26fe527 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/srevent/URLClient.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet.srevent; + +import com.sun.ts.tests.servlet.api.jakarta_servlet.srevent.TestServlet; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + + JavaArchive javaArchive1 = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_plu_srevent_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_plu_srevent_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestServlet.class) + .addAsLibraries(javaArchive1); + } + + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + /* + * @testName: constructorTest + * + * @assertion_ids: Servlet:JAVADOC:63 + * + * @test_Strategy: Servlet tries to get an instance of ServletRequestEvent. + */ + @Test + public void constructorTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "constructorTest"); + invoke(); + } + + /* + * @testName: getServletContextTest + * + * @assertion_ids: Servlet:JAVADOC:65 + * + * @test_Strategy: Servlet calls constructor and tries to get the context that + * was used in the constructor. + */ + @Test + public void getServletContextTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletContextTest"); + invoke(); + } + + /* + * @testName: getServletRequestTest + * + * @assertion_ids: Servlet:JAVADOC:64 + * + * @test_Strategy: Servlet calls constructor and tries to get the request that + * was used in the constructor. + */ + @Test + public void getServletRequestTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletRequestTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/srevent/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/srevent/build.xml new file mode 100644 index 0000000000..db79d89e99 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/srevent/build.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/srevent/servlet_plu_srevent_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/srevent/servlet_plu_srevent_web-fragment.xml new file mode 100644 index 0000000000..1494d7023c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/srevent/servlet_plu_srevent_web-fragment.xml @@ -0,0 +1,36 @@ + + + + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.srevent.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/srlistener/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/srlistener/URLClient.java new file mode 100644 index 0000000000..d8ac3db179 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/srlistener/URLClient.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet.srlistener; + +import com.sun.ts.tests.servlet.api.jakarta_servlet.srlistener.SRListener; +import com.sun.ts.tests.servlet.api.jakarta_servlet.srlistener.TestServlet; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + + JavaArchive javaArchive1 = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_plu_srlistener_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_plu_srlistener_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(SRListener.class, TestServlet.class) + .addAsLibraries(javaArchive1); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + + /* + * @testName: initializeDestroyTest + * + * @assertion_ids: Servlet:JAVADOC:167;Servlet:JAVADOC:168 + * + * @test_Strategy: Servlet calls a simple servlet then calls a second servlet + * to verify results + */ + @Test + public void initializeDestroyTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "initializeDestroyTest"); + invoke(); + TEST_PROPS.setProperty(APITEST, "checkLog"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/srlistener/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/srlistener/build.xml new file mode 100644 index 0000000000..6acba6f4ca --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/srlistener/build.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/srlistener/servlet_plu_srlistener_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/srlistener/servlet_plu_srlistener_web-fragment.xml new file mode 100644 index 0000000000..772f33f544 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/srlistener/servlet_plu_srlistener_web-fragment.xml @@ -0,0 +1,39 @@ + + + + + + com.sun.ts.tests.servlet.api.jakarta_servlet.srlistener.SRListener + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet.srlistener.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/unavailableexception/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/unavailableexception/URLClient.java new file mode 100644 index 0000000000..b16704cf0f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/unavailableexception/URLClient.java @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet.unavailableexception; + +import com.sun.ts.tests.servlet.api.jakarta_servlet.unavailableexception.TestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet.unavailableexception.UnavailableServlet; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive1 = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_plu_unavailableexception_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_plu_unavailableexception_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestServlet.class, UnavailableServlet.class) + .addAsLibraries(javaArchive1); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + + /* + * @testName: getUnavailableSecondsTest + * + * @assertion_ids: Servlet:SPEC:11; Servlet:JAVADOC:4; Servlet:JAVADOC:7; + * + * @test_Strategy: A test for UnavailableException.getUnavailableSeconds() + * method. + */ + @Test + public void getUnavailableSecondsTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getUnavailableSecondsTest"); + invoke(); + } + + /* + * @testName: isPermanentTest + * + * @assertion_ids: Servlet:SPEC:11; Servlet:JAVADOC:3; Servlet:JAVADOC:4; + * Servlet:JAVADOC:5; + * + * @test_Strategy: A test for UnavailableException.isPermanent() method. + */ + @Test + public void isPermanentTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "isPermanentTest"); + invoke(); + } + + /* + * @testName: unavailableTest + * + * @assertion_ids: Servlet:SPEC:11; Servlet:SPEC:11.1; Servlet:JAVADOC:3; + * Servlet:JAVADOC:268; + * + * @test_Strategy: A test for Permanent Unavailable First access the Servlet, + * and mark it unavailable Second try to access it again, 404 should be + * returned + */ + @Test + public void unavailableTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, " "); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, ""); + TEST_PROPS.setProperty(DONOTUSEServletName, "true"); + TEST_PROPS.setProperty(STATUS_CODE, "404"); + TEST_PROPS.setProperty(APITEST, "unavailableTest"); + invoke(); + } + + /* + * @testName: unavailableException_Constructor1Test + * + * @assertion_ids: Servlet:SPEC:11; Servlet:JAVADOC:3; + * + * @test_Strategy: A test for UnavailableException(String mesg). It construts + * an UnavailabaleException object for the specified servlet. This constructor + * tests for permanent unavailability + */ + @Test + public void unavailableException_Constructor1Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "unavailableException_Constructor1Test"); + invoke(); + } + + /* + * @testName: unavailableException_Constructor2Test + * + * @assertion_ids: Servlet:SPEC:11; Servlet:JAVADOC:4; + * + * @test_Strategy: A test for UnavailableException(String mesg, int sec). It + * construts an UnavailabaleException object for the specified servlet. This + * constructor tests for temporarily unavailability + */ + @Test + public void unavailableException_Constructor2Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "unavailableException_Constructor2Test"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/unavailableexception/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/unavailableexception/build.xml new file mode 100644 index 0000000000..8b5e05f310 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/unavailableexception/build.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/unavailableexception/servlet_plu_unavailableexception_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/unavailableexception/servlet_plu_unavailableexception_web-fragment.xml new file mode 100644 index 0000000000..cb5a5fec6a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet/unavailableexception/servlet_plu_unavailableexception_web-fragment.xml @@ -0,0 +1,44 @@ + + + + + + TestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.unavailableexception.TestServlet + + + UnavailableTestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet.unavailableexception.UnavailableServlet + + + TestLogicalName + /TestServlet + + + UnavailableTestLogicalName + /unavailableTest + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/build.xml new file mode 100644 index 0000000000..7a76d3c694 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/build.xml @@ -0,0 +1,22 @@ + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/cookie/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/cookie/URLClient.java new file mode 100644 index 0000000000..d551401ea7 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/cookie/URLClient.java @@ -0,0 +1,530 @@ +/* + * Copyright (c) 2012, 2021 Oracle and/or its affiliates and others. + * 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet_http.cookie; + +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.cookie.TestServlet; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.request.HttpRequest; +import com.sun.ts.tests.servlet.common.request.HttpResponse; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.common.util.Data; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.apache.commons.httpclient.Cookie; +import org.apache.commons.httpclient.Header; +import org.apache.commons.httpclient.cookie.CookiePolicy; +import org.apache.commons.httpclient.cookie.CookieSpec; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.TimeZone; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_pluh_cookie_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_pluh_cookie_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestServlet.class) + .addAsLibraries(javaArchive); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + private int findCookie(Cookie[] cookie, String name) { + boolean found = false; + int i = 0; + if (cookie != null) { + while ((!found) && (i < cookie.length)) { + if (cookie[i].getName().equals(name)) { + found = true; + } else { + i++; + } + } + } else { + found = false; + } + if (found) { + return i; + } else { + return -1; + } + } + + /* Run test */ + + /* + * @testName: cloneTest + * + * @assertion_ids: Servlet:JAVADOC:453 + * + * @test_Strategy: Create a web application with no web.xml and one fragment; + * Define everything in web-fragment.xml; Package everything in the fragment; + * Servlet tests method Cookie.clone and verify it works; + */ + @Test + public void cloneTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "cloneTest"); + invoke(); + } + + /* + * @testName: constructorTest + * + * @assertion_ids: Servlet:JAVADOC:434 + * + * @test_Strategy: Create a web application with no web.xml and one fragment; + * Define everything in web-fragment.xml; Package everything in the fragment; + * Servlet tests constructor method and verify it works; + */ + @Test + public void constructorTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "constructorTest"); + invoke(); + } + + /* + * @testName: constructorIllegalArgumentExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:628 + * + * @test_Strategy: Create a web application with no web.xml and one fragment; + * Define everything in web-fragment.xml; Package everything in the fragment; + * Servlet tests constructor method throws IllegalArgumentException when + * invalid names are used(unsupported characters in name); + */ + @Test + public void constructorIllegalArgumentExceptionTest() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/TestServlet?testname=constructorIllegalArgumentExceptionTest HTTP/1.1"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "Test FAILED"); + invoke(); + } + + /* + * @testName: getCommentTest + * + * @assertion_ids: Servlet:JAVADOC:436 + * + * @test_Strategy: Create a web application with no web.xml and one fragment; + * Define everything in web-fragment.xml; Package everything in the fragment; + * Servlet tests method getComment; + */ + @Test + public void getCommentTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getCommentTest"); + invoke(); + } + + /* + * @testName: getCommentNullTest + * + * @assertion_ids: Servlet:JAVADOC:437 + * + * @test_Strategy: Create a web application with no web.xml and one fragment; + * Define everything in web-fragment.xml; Package everything in the fragment; + * Servlet tests method getComment when there is no comment; + */ + @Test + public void getCommentNullTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getCommentNullTest"); + invoke(); + } + + /* + * @testName: getDomainTest + * + * @assertion_ids: Servlet:JAVADOC:439 + * + * @test_Strategy: Create a web application with no web.xml and one fragment; + * Define everything in web-fragment.xml; Package everything in the fragment; + * Client sends a version 0 and 1 cookie to the servlet. Servlet verifies + * values of the cookies; + */ + @Test + public void getDomainTest() throws Exception { + // version 1 + TEST_PROPS.setProperty(REQUEST_HEADERS, + "Cookie: $Version=1; name1=value1; $Domain=" + _hostname + + "; $Path=" + getContextRoot()); + TEST_PROPS.setProperty(APITEST, "getDomainTest"); + invoke(); + + } + + /* + * @testName: getMaxAgeTest + * + * @assertion_ids: Servlet:JAVADOC:443 + * + * @test_Strategy: Create a web application with no web.xml and one fragment; + * Define everything in web-fragment.xml; Package everything in the fragment; + * Servlet tests method getMaxAge; + */ + @Test + public void getMaxAgeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getMaxAgeTest"); + invoke(); + } + + /* + * @testName: getNameTest + * + * @assertion_ids: Servlet:JAVADOC:448 + * + * @test_Strategy: Create a web application with no web.xml and one fragment; + * Define everything in web-fragment.xml; Package everything in the fragment; + * Client sends a version 0 and 1 cookie to a servlet; Servlet tests method + * Cookie.getName + */ + @Test + public void getNameTest() throws Exception { + // version 0 Cookie + TEST_PROPS.setProperty(REQUEST_HEADERS, "Cookie: name1=value1; Domain=" + + _hostname + "; Path=" + getContextRoot()); + TEST_PROPS.setProperty(APITEST, "getNameTest"); + invoke(); + + // version 1 Cookie + TEST_PROPS.setProperty(REQUEST_HEADERS, + "Cookie: $Version=1; name1=value1; $Domain=" + _hostname + + "; $Path=" + getContextRoot()); + TEST_PROPS.setProperty(APITEST, "getNameTest"); + invoke(); + } + + /* + * @testName: getPathTest + * + * @assertion_ids: Servlet:JAVADOC:445 + * + * @test_Strategy: Create a web application with no web.xml and one fragment; + * Define everything in web-fragment.xml; Package everything in the fragment; + * Client sends a version 1 cookie to a servlet; Servlet tests method getPath + * using the received Cookie + */ + @Test + public void getPathTest() throws Exception { + TEST_PROPS.setProperty(REQUEST_HEADERS, + "Cookie: $Version=1; name1=value1; $Domain=" + _hostname + + "; $Path=" + getContextRoot()); + TEST_PROPS.setProperty(APITEST, "getPathTest"); + invoke(); + } + + /* + * @testName: getSecureTest + * + * @assertion_ids: Servlet:JAVADOC:447 + * + * @test_Strategy: Create a web application with no web.xml and one fragment; + * Define everything in web-fragment.xml; Package everything in the fragment; + * Servlet tests method Cookie.getSecure; + */ + @Test + public void getSecureTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getSecureTest"); + invoke(); + } + + /* + * @testName: getValueTest + * + * @assertion_ids: Servlet:JAVADOC:450 + * + * @test_Strategy: Create a web application with no web.xml and one fragment; + * Define everything in web-fragment.xml; Package everything in the fragment; + * Client sends a version 0 and 1 cookie to a servlet; Servlet tests method + * getValue and verify the right cookie received + */ + @Test + public void getValueTest() throws Exception { + // version 0 Cookie + TEST_PROPS.setProperty(REQUEST_HEADERS, "Cookie: name1=value1; Domain=" + + _hostname + "; Path=" + getContextRoot()); + TEST_PROPS.setProperty(APITEST, "getValueTest"); + invoke(); + // version 1 Cookie + TEST_PROPS.setProperty(REQUEST_HEADERS, + "Cookie: $Version=1; name1=value1; $Domain=" + _hostname + + "; $Path=" + getContextRoot()); + TEST_PROPS.setProperty(APITEST, "getValueTest"); + invoke(); + } + + /* + * @testName: getVersionTest + * + * @assertion_ids: Servlet:JAVADOC:451 + * + * @test_Strategy: Create a web application with no web.xml and one fragment; + * Define everything in web-fragment.xml; Package everything in the fragment; + * Client sends a version 0 and 1 cookie to a servlet; Servlet tests method + * Cookie.getVersion and verify the right cookie received + */ + @Test + public void getVersionTest() throws Exception { + // version 0 Cookie + TEST_PROPS.setProperty(REQUEST_HEADERS, "Cookie: name1=value1; Domain=" + + _hostname + "; Path=" + getContextRoot()); + TEST_PROPS.setProperty(APITEST, "getVersionVer0Test"); + invoke(); + // version 1 Cookie + TEST_PROPS.setProperty(REQUEST_HEADERS, + "Cookie: $Version=1; name1=value1; $Domain=" + _hostname + + "; $Path=" + getContextRoot()); + TEST_PROPS.setProperty(APITEST, "getVersionVer1Test"); + invoke(); + } + + /* + * @testName: setDomainTest + * + * @assertion_ids: Servlet:JAVADOC:438 + * + * @test_Strategy: Create a web application with no web.xml and one fragment; + * Define everything in web-fragment.xml; Package everything in the fragment; + * Servlet tests method Cookie.setDomain + */ + @Test + public void setDomainTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setDomainTest"); + invoke(); + } + + /* + * @testName: setMaxAgePositiveTest + * + * @assertion_ids: Servlet:JAVADOC:440 + * + * @test_Strategy: Create a web application with no web.xml and one fragment; + * Define everything in web-fragment.xml; Package everything in the fragment; + * Servlet create Cookie and sets values using Cookie.setMaxAge(2) Cookie is + * sent back to client and client verifies them + */ + @Test + public void setMaxAgePositiveTest() throws Exception { + // version 0 cookie + String testName = "setMaxAgePositiveTest"; + HttpResponse response = null; + String dateHeader = null; + int index = -1; + Date expiryDate = null; + String body = null; + + HttpRequest request = new HttpRequest("GET " + getContextRoot() + "/" + + getServletName() + "?testname=" + testName + " HTTP/1.1", _hostname, + _port); + + try { + response = request.execute(); + dateHeader = response.getResponseHeader("testDate").toString(); + CookieSpec spec = CookiePolicy.getCookieSpec(CookiePolicy.NETSCAPE); + + logTrace("Found " + response.getResponseHeaders("Set-Cookie").length + + " set-cookie entry"); + + boolean foundcookie = false; + Header[] CookiesHeader = response.getResponseHeaders("Set-Cookie"); + int i = 0; + while (i < CookiesHeader.length) { + TestUtil.logTrace("Checking set-cookiei " + i + ":" + CookiesHeader[i]); + Cookie[] cookies = spec.parse(".eng.com", _port, getServletName(), + false, CookiesHeader[i]); + index = findCookie(cookies, "name1"); + if (index >= 0) { + expiryDate = cookies[index].getExpiryDate(); + body = response.getResponseBodyAsString(); + foundcookie = true; + break; + } + i++; + } + + if (!foundcookie) { + throw new Exception("The test cookie was not located in the response"); + } + } catch (Throwable t) { + throw new Exception("Exception occurred:" + t); + } + + // put expiry date into GMT + SimpleDateFormat sdf = new SimpleDateFormat(TestServlet.CUSTOM_HEADER_DATE_FORMAT); + sdf.setTimeZone(TimeZone.getTimeZone("GMT")); + String resultStringDate = sdf.format(expiryDate); + try { + Date resultDate = sdf.parse(resultStringDate); + Date expectedDate = sdf + .parse(dateHeader.substring(dateHeader.indexOf(": ") + 2).trim()); + if (resultDate.before(expectedDate)) { + throw new Exception("The expiry date was incorrect, expected =" + + expectedDate + ", result = " + resultDate); + } + } catch (Throwable t) { + throw new Exception("Exception occurred: " + t); + } + + if (body.indexOf(Data.PASSED) == -1) { + throw new Exception("The string: " + Data.PASSED + " not found in response"); + } + } + + /* + * @testName: setMaxAgeZeroTest + * + * @assertion_ids: Servlet:JAVADOC:442 + * + * @test_Strategy: Create a web application with no web.xml and one fragment; + * Define everything in web-fragment.xml; Package everything in the fragment; + * Servlet create Cookie and sets values using Cookie.setMaxAge(0) Cookie is + * sent back to client and client verifies them + */ + @Test + public void setMaxAgeZeroTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setMaxAgeZeroTest"); + TEST_PROPS.setProperty(EXPECTED_HEADERS, "Set-Cookie:name1=value1##Max-Age=0"); + invoke(); + } + + /* + * @testName: setMaxAgeNegativeTest + * + * @assertion_ids: Servlet:JAVADOC:441 + * + * @test_Strategy: Create a web application with no web.xml and one fragment; + * Define everything in web-fragment.xml; Package everything in the fragment; + * Servlet create Cookie and sets values using Cookie.setMaxAge(-1) Cookie is + * sent back to client and client verifies them + */ + @Test + public void setMaxAgeNegativeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setMaxAgeNegativeTest"); + TEST_PROPS.setProperty(EXPECTED_HEADERS, + "Set-Cookie:name1=value1##!Expire##!Max-Age"); + invoke(); + } + + /* + * @testName: setSecureTest + * + * @assertion_ids: Servlet:JAVADOC:446 + * + * @test_Strategy: Create a web application with no web.xml and one fragment; + * Define everything in web-fragment.xml; Package everything in the fragment; + * Servlet create Version 0 and Version 1 Cookie and sets values using + * Cookie.setSecure Cookie is sent back to client and client verifies them + */ + @Test + public void setSecureTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setSecureVer0Test"); + invoke(); + TEST_PROPS.setProperty(APITEST, "setSecureVer1Test"); + invoke(); + } + + /* + * @testName: setValueTest + * + * @assertion_ids: Servlet:JAVADOC:449 + * + * @test_Strategy: Create a web application with no web.xml and one fragment; + * Define everything in web-fragment.xml; Package everything in the fragment; + * Servlet create Version 0 and Version 1 Cookie and sets values using + * Cookie.setValue Cookie is sent back to client and client verifies them + */ + @Test + public void setValueTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setValueVer0Test"); + invoke(); + TEST_PROPS.setProperty(APITEST, "setValueVer1Test"); + invoke(); + } + + /* + * @testName: setVersionTest + * + * @assertion_ids: Servlet:JAVADOC:452 + * + * @test_Strategy: Create a web application with no web.xml and one fragment; + * Define everything in web-fragment.xml; Package everything in the fragment; + * Servlet create Version 0 and Version 1 Cookie and sets values using + * Cookie.setVersion Cookie is sent back to client and client verifies them + */ + @Test + public void setVersionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setVersionVer0Test"); + invoke(); + TEST_PROPS.setProperty(APITEST, "setVersionVer1Test"); + invoke(); + } + + /* + * @testName: setAttributeTest + * + * @assertion_ids: + * + * @test_Strategy: Create a web application with no web.xml and one fragment; + * Define everything in web-fragment.xml; Package everything in the fragment; + * Servlet tests method Cookie.setAttribute + */ + @Test + public void setAttributeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setAttributeTest"); + invoke(); + } + + /* + * @testName: getAttributesTest + * + * @assertion_ids: + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void getAttributesTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getAttributesTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/cookie/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/cookie/build.xml new file mode 100644 index 0000000000..1993160987 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/cookie/build.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/cookie/servlet_pluh_cookie_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/cookie/servlet_pluh_cookie_web-fragment.xml new file mode 100644 index 0000000000..17516f5df6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/cookie/servlet_pluh_cookie_web-fragment.xml @@ -0,0 +1,36 @@ + + + + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.cookie.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservlet/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservlet/URLClient.java new file mode 100644 index 0000000000..332efb161b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservlet/URLClient.java @@ -0,0 +1,238 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet_http.httpservlet; + +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservlet.DestroyTestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservlet.InitTestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservlet.Init_ServletConfigTestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservlet.ServiceTestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservlet.TestServlet; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_pluh_httpservlet_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_pluh_httpservlet_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(DestroyTestServlet.class, Init_ServletConfigTestServlet.class, + InitTestServlet.class, ServiceTestServlet.class, TestServlet.class) + .addAsLibraries(javaArchive); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: destroyTest + * + * @assertion_ids: Servlet:JAVADOC:416 + * + * @test_Strategy: Create a GenericServlet and take out of service using + * destroy method + * + */ + @Test + public void destroyTest() throws Exception { + String testName = "destroyTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(IGNORE_BODY, "true"); + invoke(); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(IGNORE_BODY, "true"); + invoke(); + } + + /* + * @testName: getServletConfigTest + * + * @assertion_ids: Servlet:JAVADOC:421 + * + * @test_Strategy: Create a GenericServlet and check for its ServletConfig + * object existence + * + */ + @Test + public void getServletConfigTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletConfigTest"); + invoke(); + } + + /* + * @testName: getServletContextTest + * + * @assertion_ids: Servlet:JAVADOC:422 + * + * @test_Strategy: Create a GenericServlet and check for its ServletContext + * object existence + * + */ + @Test + public void getServletContextTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletContextTest"); + invoke(); + } + + /* + * @testName: getServletInfoTest + * + * @assertion_ids: Servlet:JAVADOC:423 + * + * @test_Strategy: Create a GenericServlet and check for its ServletInfo + * object values + * + */ + @Test + public void getServletInfoTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletInfoTest"); + invoke(); + } + + /* + * @testName: getInitParameterTest + * + * @assertion_ids: Servlet:JAVADOC:417 + * + * @test_Strategy: Servlet tries to access a parameter that exists + */ + @Test + public void getInitParameterTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getInitParameterTest"); + invoke(); + } + + /* + * @testName: getInitParameterTestNull + * + * @assertion_ids: Servlet:JAVADOC:418 + * + * @test_Strategy: Servlet tries to access a parameter that doesnot exist + */ + @Test + public void getInitParameterTestNull() throws Exception { + TEST_PROPS.setProperty(APITEST, "getInitParameterTestNull"); + invoke(); + } + + /* + * @testName: getInitParameterNamesTest + * + * @assertion_ids: Servlet:JAVADOC:419 + * + * @test_Strategy: Servlet tries to get all parameter names + */ + @Test + public void getInitParameterNamesTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getInitParameterNamesTest"); + invoke(); + } + + /* + * @testName: getServletNameTest + * + * @assertion_ids: Servlet:JAVADOC:433 + * + * @test_Strategy: Servlet gets name of servlet + */ + @Test + public void getServletNameTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletNameTest"); + invoke(); + } + + /* + * @testName: serviceTest + * + * @assertion_ids: Servlet:JAVADOC:430 + * + * @test_Strategy: Servlet which has a service method that is called + */ + @Test + public void serviceTest() throws Exception { + String testName = "serviceTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + testName + " HTTP/1.1"); + invoke(); + } + + /* + * @testName: initTest + * + * @assertion_ids: Servlet:JAVADOC:426 + * + * @test_Strategy: Servlet has init method that puts a value into the context. + * Servlet when called reads value from context + */ + @Test + public void initTest() throws Exception { + String testName = "initTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + testName + " HTTP/1.1"); + invoke(); + } + + /* + * @testName: init_ServletConfigTest + * + * @assertion_ids: Servlet:JAVADOC:424 + * + * @test_Strategy: Servlet has init method that puts a value into the context. + * Servlet when called reads value from context + */ + @Test + public void init_ServletConfigTest() throws Exception { + String testName = "init_ServletConfigTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + testName + " HTTP/1.1"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservlet/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservlet/build.xml new file mode 100644 index 0000000000..58f020de1c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservlet/build.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservlet/servlet_pluh_httpservlet_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservlet/servlet_pluh_httpservlet_web-fragment.xml new file mode 100644 index 0000000000..0e53b49587 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservlet/servlet_pluh_httpservlet_web-fragment.xml @@ -0,0 +1,76 @@ + + + + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservlet.TestServlet + + parameter1 + value1 + + + parameter2 + value2 + + + + destroyTest + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservlet.DestroyTestServlet + + + initTest + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservlet.InitTestServlet + + + init_ServletConfigTest + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservlet.Init_ServletConfigTestServlet + + + serviceTest + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservlet.ServiceTestServlet + + + TestServlet + /TestServlet/* + + + destroyTest + /destroyTest + + + initTest + /initTest + + + init_ServletConfigTest + /init_ServletConfigTest + + + serviceTest + /serviceTest + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletrequest/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletrequest/URLClient.java new file mode 100644 index 0000000000..9f8d69eb7b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletrequest/URLClient.java @@ -0,0 +1,971 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet_http.httpservletrequest; + +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest.GetParameterNamesEmptyEnumTestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest.GetQueryStringNullTestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest.GetReaderUnsupportedEncodingExceptionTestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest.GetServletPathEmptyStringTestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest.SetCharacterEncodingTest; +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest.SetCharacterEncodingUnsupportedEncodingExceptionTest; +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest.getServletContextTest; +import com.sun.ts.tests.servlet.common.request.HttpRequestClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.common.util.Data; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends HttpRequestClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar").addClasses(TestServlet1.class, RequestListener1.class).addAsResource(URLClient.class.getResource("servlet_pluh_httpservletrequest_web-fragment.xml"), "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_pluh_httpservletrequest_web.war").addAsLibraries(CommonServlets.getCommonServletsArchive()).addClasses(GetParameterNamesEmptyEnumTestServlet.class, GetQueryStringNullTestServlet.class, GetReaderUnsupportedEncodingExceptionTestServlet.class, getServletContextTest.class, GetServletPathEmptyStringTestServlet.class, SetCharacterEncodingTest.class, SetCharacterEncodingUnsupportedEncodingExceptionTest.class).addAsLibraries(javaArchive); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + /* Run test */ + /* + * @testName: getAttributeNamesTest + * + * @assertion_ids: Servlet:JAVADOC:573 + * + * @test_Strategy: Servlet verifies attributes + * + */ + @Test + public void getAttributeNamesTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getAttributeNamesTest"); + invoke(); + TEST_PROPS.setProperty(APITEST, "getAttributeNamesEmptyEnumTest"); + invoke(); + } + + /* + * @testName: getAttributeTest + * + * @assertion_ids: Servlet:JAVADOC:572 + * + * @test_Strategy: Servlet verifies attribute + * + */ + @Test + public void getAttributeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getAttributeTest"); + invoke(); + TEST_PROPS.setProperty(APITEST, "getAttributeDoesNotExistTest"); + invoke(); + } + + /* + * @testName: getCharacterEncodingTest + * + * @assertion_ids: Servlet:JAVADOC:574 + * + * @test_Strategy: Servlet verifies encoding + */ + @Test + public void getCharacterEncodingTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getCharacterEncodingTest"); + TEST_PROPS.setProperty(REQUEST_HEADERS, "Content-Type:text/plain; charset=ISO-8859-1"); + invoke(); + TEST_PROPS.setProperty(APITEST, "getCharacterEncodingNullTest"); + invoke(); + } + + /* + * @testName: getContentLengthTest + * + * @assertion_ids: Servlet:JAVADOC:575 + * + * @test_Strategy: Servlet compares this length to the actual length of the + * content body read in using getInputStream + * + */ + /* + * @testName: getContentTypeTest + * + * @assertion_ids: Servlet:JAVADOC:576; Servlet:SPEC:34; + * + * @test_Strategy: Client sets the content type and servlet reads it. + * + */ + /* + * @testName: getInputStreamTest + * + * @assertion_ids: Servlet:JAVADOC:577 + * + * @test_Strategy: Servlet tries to read the input stream. + */ + /* + * @testName: getInputStreamIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:579 + * + * @test_Strategy: Servlet gets a Reader object using + * ServletRequest.getReader() then tries to get the inputStream Object + * + */ + /* + * @testName: getLocaleTest + * + * @assertion_ids: Servlet:JAVADOC:580 + * + * @test_Strategy: Servlet sends back locale to client. + */ + @Test + public void getLocaleTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getLocaleTest"); + TEST_PROPS.setProperty(REQUEST_HEADERS, "Accept-Language:en-US"); + invoke(); + TEST_PROPS.setProperty(APITEST, "getLocaleDefaultTest"); + invoke(); + } + + /* + * @testName: getLocalesTest + * + * @assertion_ids: Servlet:JAVADOC:581 + * + * @test_Strategy: Servlet sends back locale(s) to client. + */ + @Test + public void getLocalesTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getLocalesTest"); + TEST_PROPS.setProperty(REQUEST_HEADERS, "Accept-Language:en-US,en-GB"); + invoke(); + TEST_PROPS.setProperty(APITEST, "getLocalesDefaultTest"); + invoke(); + } + + /* + * @testName: getParameterMapTest + * + * @assertion_ids: Servlet:JAVADOC:583 + * + * @test_Strategy: Client sets several parameters and the servlet attempts to + * access them. + */ + /* + * @testName: getParameterNamesTest + * + * @assertion_ids: Servlet:JAVADOC:584 + * + * @test_Strategy: Servlet attempts to access parameters. + */ + @Test + public void getParameterNamesTest() throws Exception { + String testName = "getParameterNamesTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + getServletName() + "?testname=" + testName + "¶meter1=value1¶meter2=value2 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, Data.PASSED); + invoke(); + testName = "getParameterNamesEmptyEnumTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, Data.PASSED); + invoke(); + } + + /* + * @testName: getParameterTest + * + * @assertion_ids: Servlet:JAVADOC:582 + * + * @test_Strategy: Client sets a parameter and servlet retrieves it. + */ + @Test + public void getParameterTest() throws Exception { + String testName = "getParameterTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + getServletName() + "?testname=" + testName + "¶meter1=value1 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, Data.PASSED); + invoke(); + TEST_PROPS.setProperty(APITEST, "getParameterDoesNotExistTest"); + invoke(); + } + + /* + * @testName: getParameterValuesTest + * + * @assertion_ids: Servlet:JAVADOC:585 + * + * @test_Strategy: Servlet verifies values + */ + @Test + public void getParameterValuesTest() throws Exception { + String testName = "getParameterValuesTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + getServletName() + "?testname=" + testName + "&Names=value1&Names=value2 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, Data.PASSED); + invoke(); + TEST_PROPS.setProperty(APITEST, "getParameterValuesDoesNotExistTest"); + invoke(); + } + + /* + * @testName: getProtocolTest + * + * @assertion_ids: Servlet:JAVADOC:586 + * + * @test_Strategy: Servlet verifies the protocol used by the client + */ + /* + * @testName: getReaderTest + * + * @assertion_ids: Servlet:JAVADOC:587 + * + * @test_Strategy: Client sets some content and servlet reads the content + */ + /* + * @testName: getReaderIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:590 + * + * @test_Strategy: Servlet gets an InputStream Object then tries to get a + * Reader Object. + */ + /* + * @testName: getReaderUnsupportedEncodingExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:589 + * + * @test_Strategy: Client sets some content but with an invalid encoding, + * servlet tries to read content. + */ + /* + * @testName: getRemoteAddrTest + * + * @assertion_ids: Servlet:JAVADOC:592 + * + * @test_Strategy: Servlet reads and verifies where the request originated + */ + /* + * @testName: getLocalAddrTest + * + * @assertion_ids: Servlet:JAVADOC:719 + * + * @test_Strategy: Servlet reads and verifies where the request originated + */ + /* + * @testName: getLocalNameTest + * + * @assertion_ids: Servlet:JAVADOC:629; + * + * @test_Strategy: Send an HttpServletRequest to server; Verify that + * getLocalName(); + */ + /* + * @testName: getRemoteHostTest + * + * @assertion_ids: Servlet:JAVADOC:593 + * + * @test_Strategy: Servlet reads and verifies where the request originated + */ + /* + * @testName: getRequestDispatcherTest + * + * @assertion_ids: Servlet:JAVADOC:594 + * + * @test_Strategy: Servlet tries to get a dispatcher + */ + /* + * @testName: getSchemeTest + * + * @assertion_ids: Servlet:JAVADOC:595 + * + * @test_Strategy: Servlet verifies the scheme of the url used in the request + */ + /* + * @testName: getServerNameTest + * + * @assertion_ids: Servlet:JAVADOC:596 + * + * @test_Strategy: Servlet verifies the destination of the request + */ + /* + * @testName: getServerPortTest + * + * @assertion_ids: Servlet:JAVADOC:597 + * + * @test_Strategy: Servlet verifies the destination port of the request + */ + /* + * @testName: isSecureTest + * + * @assertion_ids: Servlet:JAVADOC:598 + * + * @test_Strategy: Servlet verifies the isSecure method for the non-secure + * case. + */ + /* + * @testName: removeAttributeTest + * + * @assertion_ids: Servlet:JAVADOC:599 + * + * @test_Strategy: Servlet adds then removes an attribute, then verifies it + * was removed. + */ + /* + * @testName: setAttributeTest + * + * @assertion_ids: Servlet:JAVADOC:600 + * + * @test_Strategy: Servlet adds an attribute, then verifies it was added + */ + /* + * @testName: setCharacterEncodingTest + * + * @assertion_ids: Servlet:JAVADOC:601 + * + * @test_Strategy: Servlet sets a new encoding and tries to retrieve it. + */ + /* + * @testName: setCharacterEncodingTest1 + * + * @assertion_ids: Servlet:JAVADOC:601; Servlet:JAVADOC:574; Servlet:SPEC:28; + * Servlet:SPEC:213; + * + * @test_Strategy: HttpServletRequest calls getReader()first; then sets a new + * encoding and tries to retrieve it. verifies that the new encoding is + * ignored. + */ + /* + * @testName: setCharacterEncodingUnsupportedEncodingExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:602 + * + * @test_Strategy: Servlet tries to set an invalid encoding. + * + */ + // ---------------------------- END ServletRequest + // ----------------------------- + // ---------------------------- HttpServletRequest + // ----------------------------- + /* + * @testName: getAuthTypeWithoutProtectionTest + * + * @assertion_ids: Servlet:JAVADOC:530 + * + * @test_Strategy: Servlet verifies correct result + */ + /* + * @testName: getContextPathTest + * + * @assertion_ids: Servlet:JAVADOC:550 + * + * @test_Strategy: Client sets header and servlet verifies the result + */ + /* + * @testName: getCookiesNoCookiesTest + * + * @assertion_ids: Servlet:JAVADOC:532 + * + * @test_Strategy: Servlet tries to get a cookie when none exist + */ + /* + * @testName: getCookiesTest + * + * @assertion_ids: Servlet:JAVADOC:531 + * + * @test_Strategy:Client sets a cookie and servlet tries to read it + */ + /* + * @testName: getDateHeaderIllegalArgumentExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:535 + * + * @test_Strategy: Client set invalid date value, servlet tries to read it. + */ + /* + * @testName: getDateHeaderNoHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:534 + * + * @test_Strategy: Servlet tries to get a dateHeader when none exist + */ + /* + * @testName: getDateHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:533 + * + * @test_Strategy: client sets a dateheader and servlet tries to read it. + */ + /* + * @testName: getHeaderNamesTest + * + * @assertion_ids: Servlet:JAVADOC:540 + * + * @test_Strategy: Client sets some headers and servlet tries to read them. + */ + /* + * @testName: getHeaderNoHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:537 + * + * @test_Strategy: Servlet tries to read a header when none exist + */ + /* + * @testName: getHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:536 + * + * @test_Strategy: Client sets a header and servlet tries to read it. + */ + /* + * @testName: getHeadersNoHeadersTest + * + * @assertion_ids: Servlet:JAVADOC:539 + * + * @test_Strategy: Servlet tries to get all the headers when none have been + * added + */ + /* + * @testName: getHeadersTest + * + * @assertion_ids: Servlet:JAVADOC:538 + * + * @test_Strategy: Client sets some headers and servlet tries to read them + */ + /* + * @testName: getIntHeaderNoHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:543 + * + * @test_Strategy: Servlet tries to read a header when none exist. + */ + /* + * @testName: getIntHeaderNumberFoundExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:544 + * + * @test_Strategy: Client sets an invalid header and servlet tries to read it. + */ + /* + * @testName: getIntHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:542 + * + * @test_Strategy: Client sets a header and servlet reads it + */ + /* + * @testName: getMethodTest + * + * @assertion_ids: Servlet:JAVADOC:545 + * + * @test_Strategy: Client makes 3 calls using GET/POST/HEAD + */ + /* + * @testName: getPathInfoNullTest + * + * @assertion_ids: Servlet:JAVADOC:547 + * + * @test_Strategy: + */ + /* + * @testName: getPathInfoTest + * + * @assertion_ids: Servlet:JAVADOC:546; Servlet:SPEC:25; + * + * @test_Strategy: Servlet verifies path info + */ + /* + * @testName: getPathTranslatedNullTest + * + * @assertion_ids: Servlet:JAVADOC:549 + * + * @test_Strategy: Servlet verifies result when there is no path info + */ + /* + * @testName: getPathTranslatedTest + * + * @assertion_ids: Servlet:JAVADOC:548 + * + * @test_Strategy: client sets extra path info and servlet verifies it + */ + /* + * @testName: getQueryStringNullTest + * + * @assertion_ids: Servlet:JAVADOC:553 + * + * @test_Strategy: Servlet verifies result when no query string exists + */ + /* + * @testName: getQueryStringTest + * + * @assertion_ids: Servlet:JAVADOC:552 + * + * @test_Strategy: Client sets query string and servlet verifies it + */ + /* + * @testName: getRemoteUserTest + * + * @assertion_ids: Servlet:JAVADOC:554 + * + * @test_Strategy: Servlet verifies the result of a non-authed user + */ + /* + * @testName: getRequestURITest + * + * @assertion_ids: Servlet:JAVADOC:561 + * + * @test_Strategy: Servlet verifies URI data + */ + /* + * @testName: getRequestURLTest + * + * @assertion_ids: Servlet:JAVADOC:562 + * + * @test_Strategy: Servlet verifies URL info + */ + /* + * @testName: getRequestedSessionIdNullTest + * + * @assertion_ids: Servlet:JAVADOC:560 + * + * @test_Strategy: Servlet verifies null result + */ + /* + * @testName: getServletPathEmptyStringTest + * + * @assertion_ids: Servlet:JAVADOC:563; Servlet:SPEC:23; + * + * @test_Strategy: Servlet verifies empty string + */ + /* + * @testName: getServletPathTest + * + * @assertion_ids: Servlet:JAVADOC:564; Servlet:SPEC:24; + * + * @test_Strategy: Servlet verifies path info + */ + /* + * @testName: getSessionTrueTest + * + * @assertion_ids: Servlet:JAVADOC:565 + * + * @test_Strategy: Servlet verifies getSession(true) call + */ + /* + * @testName: getSessionFalseTest + * + * @assertion_ids: Servlet:JAVADOC:566 + * + * @test_Strategy: Servlet verifies getSession(false) call + */ + /* + * @testName: getSessionTest + * + * @assertion_ids: Servlet:JAVADOC:567 + * + * @test_Strategy: Servlet verifies getSession() call + */ + /* + * @testName: isRequestedSessionIdFromCookieTest + * + * @assertion_ids: Servlet:JAVADOC:569 + * + * @test_Strategy: Servlet verifies correct result + */ + /* + * @testName: isRequestedSessionIdFromURLTest + * + * @assertion_ids: Servlet:JAVADOC:570 + * + * @test_Strategy: Servlet verifies correct result + */ + /* + * @testName: isRequestedSessionIdValidTest + * + * @assertion_ids: Servlet:JAVADOC:568; Servlet:SPEC:211; + * + * @test_Strategy: Client sends request without session ID; Verifies + * isRequestedSessionIdValid() returns false; + */ + /* + * @testName: getRequestedSessionIdTest1 + * + * @assertion_ids: Servlet:JAVADOC:559; + * + * @test_Strategy: Client sends request with a session ID; Verifies + * getRequestedSessionId() returns the same; + */ + /* + * @testName: getRequestedSessionIdTest2 + * + * @assertion_ids: Servlet:JAVADOC:559; + * + * @test_Strategy: Client sends request to a servlet with a sesion ID; Servlet + * start a sesison; Verifies getRequestedSessionId() returns the same; + */ + /* + * @testName: sessionTimeoutTest + * + * @assertion_ids: Servlet:SPEC:67; + * + * @test_Strategy: First set a HttpSession's timeout to 60 seconds; then sleep + * 90 seconds in servlet; verify that the session is still valid after. + */ + /* + * @testName: getLocalPortTest + * + * @assertion_ids: Servlet:JAVADOC:630; + * + * @test_Strategy: Send an HttpServletRequest to server; Verify that + * getLocalPort(); + */ + /* + * @testName: getServletContextTest + * + * @assertion_ids: + * + * @test_Strategy: Send an HttpServletRequest to server; Verify that + * getServletContext return the same as stored in ServletConfig + */ + @Test + public void getServletContextTest() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/getServletContextTest HTTP/1.1"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "Test FAILED"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, "Test PASSED"); + invoke(); + } + + @Test() + public void getAuthTypeWithoutProtectionTest() throws Exception { + super.getAuthTypeWithoutProtectionTest(); + } + + @Test() + public void getContentLengthTest() throws Exception { + super.getContentLengthTest(); + } + + @Test() + public void getContentTypeTest() throws Exception { + super.getContentTypeTest(); + } + + @Test() + public void getContextPathTest() throws Exception { + super.getContextPathTest(); + } + + @Test() + public void getCookiesNoCookiesTest() throws Exception { + super.getCookiesNoCookiesTest(); + } + + @Test() + public void getCookiesTest() throws Exception { + super.getCookiesTest(); + } + + @Test() + public void getDateHeaderIllegalArgumentExceptionTest() throws Exception { + super.getDateHeaderIllegalArgumentExceptionTest(); + } + + @Test() + public void getDateHeaderNoHeaderTest() throws Exception { + super.getDateHeaderNoHeaderTest(); + } + + @Test() + public void getDateHeaderTest() throws Exception { + super.getDateHeaderTest(); + } + + @Test() + public void getHeaderNamesTest() throws Exception { + super.getHeaderNamesTest(); + } + + @Test() + public void getHeaderNoHeaderTest() throws Exception { + super.getHeaderNoHeaderTest(); + } + + @Test() + public void getHeaderTest() throws Exception { + super.getHeaderTest(); + } + + @Test() + public void getHeadersNoHeadersTest() throws Exception { + super.getHeadersNoHeadersTest(); + } + + @Test() + public void getHeadersTest() throws Exception { + super.getHeadersTest(); + } + + @Test() + public void getInputStreamIllegalStateExceptionTest() throws Exception { + super.getInputStreamIllegalStateExceptionTest(); + } + + @Test() + public void getInputStreamTest() throws Exception { + super.getInputStreamTest(); + } + + @Test() + public void getIntHeaderNoHeaderTest() throws Exception { + super.getIntHeaderNoHeaderTest(); + } + + @Test() + public void getIntHeaderNumberFoundExceptionTest() throws Exception { + super.getIntHeaderNumberFoundExceptionTest(); + } + + @Test() + public void getIntHeaderTest() throws Exception { + super.getIntHeaderTest(); + } + + @Test() + public void getLocalAddrTest() throws Exception { + super.getLocalAddrTest(); + } + + @Test() + public void getLocalNameTest() throws Exception { + super.getLocalNameTest(); + } + + @Test() + public void getLocalPortTest() throws Exception { + super.getLocalPortTest(); + } + + @Test() + public void getMethodTest() throws Exception { + super.getMethodTest(); + } + + @Test() + public void getParameterMapTest() throws Exception { + super.getParameterMapTest(); + } + + @Test() + public void getPathInfoNullTest() throws Exception { + super.getPathInfoNullTest(); + } + + @Test() + public void getPathInfoTest() throws Exception { + super.getPathInfoTest(); + } + + @Test() + public void getPathTranslatedNullTest() throws Exception { + super.getPathTranslatedNullTest(); + } + + @Test() + public void getPathTranslatedTest() throws Exception { + super.getPathTranslatedTest(); + } + + @Test() + public void getProtocolTest() throws Exception { + super.getProtocolTest(); + } + + @Test() + public void getQueryStringNullTest() throws Exception { + super.getQueryStringNullTest(); + } + + @Test() + public void getQueryStringTest() throws Exception { + super.getQueryStringTest(); + } + + @Test() + public void getReaderIllegalStateExceptionTest() throws Exception { + super.getReaderIllegalStateExceptionTest(); + } + + @Test() + public void getReaderTest() throws Exception { + super.getReaderTest(); + } + + @Test() + public void getReaderUnsupportedEncodingExceptionTest() throws Exception { + super.getReaderUnsupportedEncodingExceptionTest(); + } + + @Test() + public void getRemoteAddrTest() throws Exception { + super.getRemoteAddrTest(); + } + + @Test() + public void getRemoteHostTest() throws Exception { + super.getRemoteHostTest(); + } + + @Test() + public void getRemoteUserTest() throws Exception { + super.getRemoteUserTest(); + } + + @Test() + public void getRequestDispatcherTest() throws Exception { + super.getRequestDispatcherTest(); + } + + @Test() + public void getRequestURITest() throws Exception { + super.getRequestURITest(); + } + + @Test() + public void getRequestURLTest() throws Exception { + super.getRequestURLTest(); + } + + @Test() + public void getRequestedSessionIdNullTest() throws Exception { + super.getRequestedSessionIdNullTest(); + } + + @Test() + public void getRequestedSessionIdTest1() throws Exception { + super.getRequestedSessionIdTest1(); + } + + @Test() + public void getRequestedSessionIdTest2() throws Exception { + super.getRequestedSessionIdTest2(); + } + + @Test() + public void getSchemeTest() throws Exception { + super.getSchemeTest(); + } + + @Test() + public void getServerNameTest() throws Exception { + super.getServerNameTest(); + } + + @Test() + public void getServerPortTest() throws Exception { + super.getServerPortTest(); + } + + @Test() + public void getServletPathEmptyStringTest() throws Exception { + super.getServletPathEmptyStringTest(); + } + + @Test() + public void getServletPathTest() throws Exception { + super.getServletPathTest(); + } + + @Test() + public void getSessionFalseTest() throws Exception { + super.getSessionFalseTest(); + } + + @Test() + public void getSessionTest() throws Exception { + super.getSessionTest(); + } + + @Test() + public void getSessionTrueTest() throws Exception { + super.getSessionTrueTest(); + } + + @Test() + public void isRequestedSessionIdFromCookieTest() throws Exception { + super.isRequestedSessionIdFromCookieTest(); + } + + @Test() + public void isRequestedSessionIdFromURLTest() throws Exception { + super.isRequestedSessionIdFromURLTest(); + } + + @Test() + public void isRequestedSessionIdValidTest() throws Exception { + super.isRequestedSessionIdValidTest(); + } + + @Test() + public void isSecureTest() throws Exception { + super.isSecureTest(); + } + + @Test() + public void removeAttributeTest() throws Exception { + super.removeAttributeTest(); + } + + @Test() + public void sessionTimeoutTest() throws Exception { + super.sessionTimeoutTest(); + } + + @Test() + public void setAttributeTest() throws Exception { + super.setAttributeTest(); + } + + @Test() + public void setCharacterEncodingTest() throws Exception { + super.setCharacterEncodingTest(); + } + + @Test() + public void setCharacterEncodingTest1() throws Exception { + super.setCharacterEncodingTest1(); + } + + @Test() + public void setCharacterEncodingUnsupportedEncodingExceptionTest() throws Exception { + super.setCharacterEncodingUnsupportedEncodingExceptionTest(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletrequest/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletrequest/build.xml new file mode 100644 index 0000000000..ca394607a9 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletrequest/build.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletrequest/servlet_pluh_httpservletrequest_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletrequest/servlet_pluh_httpservletrequest_web-fragment.xml new file mode 100644 index 0000000000..1912508dd5 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletrequest/servlet_pluh_httpservletrequest_web-fragment.xml @@ -0,0 +1,92 @@ + + + + + + TestServlet + com.sun.ts.tests.servlet.common.servlets.HttpRequestTestServlet + + + getReaderUnsupportedEncodingExceptionTest + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest.GetReaderUnsupportedEncodingExceptionTestServlet + + + getQueryStringNullTest + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest.GetQueryStringNullTestServlet + + + getServletContextTest + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest.getServletContextTest + + + getParameterNamesEmptyEnumTest + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest.GetParameterNamesEmptyEnumTestServlet + + + getServletPathEmptyStringTest + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest.GetServletPathEmptyStringTestServlet + + + setCharacterEncodingUnsupportedEncodingExceptionTest + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest.SetCharacterEncodingUnsupportedEncodingExceptionTest + + + setCharacterEncodingTest + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest.SetCharacterEncodingTest + + + getServletContextTest + /getServletContextTest + + + getQueryStringNullTest + /getQueryStringNullTest + + + TestServlet + /TestServlet/* + + + getParameterNamesEmptyEnumTest + /getParameterNamesEmptyEnumTest + + + getReaderUnsupportedEncodingExceptionTest + /getReaderUnsupportedEncodingExceptionTest + + + getServletPathEmptyStringTest + /* + + + setCharacterEncodingUnsupportedEncodingExceptionTest + /setCharacterEncodingUnsupportedEncodingExceptionTest + + + setCharacterEncodingTest + /setCharacterEncodingTest + + + 1 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletrequest/servlet_pluh_httpservletrequest_web.war.sun-web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletrequest/servlet_pluh_httpservletrequest_web.war.sun-web.xml new file mode 100644 index 0000000000..8209bef0e6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletrequest/servlet_pluh_httpservletrequest_web.war.sun-web.xml @@ -0,0 +1,28 @@ + + + + + + /servlet_pluh_httpservletrequest_web + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletrequest30/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletrequest30/URLClient.java new file mode 100644 index 0000000000..2386b67854 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletrequest30/URLClient.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet_http.httpservletrequest30; + +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest30.LoginTestServlet; +import com.sun.ts.tests.servlet.common.request.HttpRequestClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends HttpRequestClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("LoginTestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_pluh_httpservletrequest30_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_pluh_httpservletrequest30_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(LoginTestServlet.class) + .addAsLibraries(javaArchive); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + // ---------------------------- HttpServletRequest + // ----------------------------- + + /* + * @testName: loginTest + * + * @assertion_ids: Servlet:JAVADOC:761; + * + * @test_Strategy: Send an HttpServletRequest to server; Verify that + * login(null, null) throw ServletException. + */ + @Test + public void loginTest() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/LoginTestServlet HTTP/1.1"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "Test FAILED"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, "Test PASSED"); + invoke(); + } + + // -------------------------- END HttpServletRequest + // --------------------------- +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletrequest30/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletrequest30/build.xml new file mode 100644 index 0000000000..9d3327712a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletrequest30/build.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletrequest30/servlet_pluh_httpservletrequest30_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletrequest30/servlet_pluh_httpservletrequest30_web-fragment.xml new file mode 100644 index 0000000000..b94613d15a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletrequest30/servlet_pluh_httpservletrequest30_web-fragment.xml @@ -0,0 +1,33 @@ + + + + + + LoginTestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequest30.LoginTestServlet + + + LoginTestServlet + /LoginTestServlet/* + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletrequestwrapper/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletrequestwrapper/URLClient.java new file mode 100644 index 0000000000..db4d198f60 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletrequestwrapper/URLClient.java @@ -0,0 +1,812 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet_http.httpservletrequestwrapper; + +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequestwrapper.SetCharacterEncodingTest; +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequestwrapper.SetCharacterEncodingTestWrapper; +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequestwrapper.SetCharacterEncodingUnsupportedEncodingExceptionTest; +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequestwrapper.SetCharacterEncodingUnsupportedEncodingExceptionTestWrapper; +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequestwrapper.TCKHttpSessionIDListener; +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequestwrapper.TestServlet; +import com.sun.ts.tests.servlet.common.request.HttpRequestClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends HttpRequestClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar").addClasses(TestServlet1.class, RequestListener1.class).addAsResource(URLClient.class.getResource("servlet_pluh_HSReqWrapper_web-fragment.xml"), "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_pluh_HSReqWrapper_web.war").addAsLibraries(CommonServlets.getCommonServletsArchive()).addClasses(SetCharacterEncodingTest.class, SetCharacterEncodingTestWrapper.class, SetCharacterEncodingUnsupportedEncodingExceptionTest.class, SetCharacterEncodingUnsupportedEncodingExceptionTestWrapper.class, TCKHttpSessionIDListener.class, TestServlet.class).addAsLibraries(javaArchive); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + /* Run test */ + // --------------------------- ServletRequestWrapper + // --------------------------- + /* + * @testName: getAttributeNamesTest + * + * @assertion_ids: Servlet:JAVADOC:385 + * + * @test_Strategy: Servlet wraps the request. Servlet then sets some + * attributes and verifies they can be retrieved. + */ + /* + * @testName: getAttributeTest + * + * @assertion_ids: Servlet:JAVADOC:384 + * + * @test_Strategy: Servlet wraps the request. Servlet then sets an attribute + * and retrieves it. + */ + /* + * @testName: getCharacterEncodingTest + * + * @assertion_ids: Servlet:JAVADOC:386 + * + * @test_Strategy: Client sets an encoding. Servlet wraps the request. Servlet + * then tries to retrieve it. + */ + /* + * @testName: getContentLengthTest + * + * @assertion_ids: Servlet:JAVADOC:389 + * + * @test_Strategy: Servlet wraps the request. Servlet then compares this + * length to the actual length of the content body read in using + * getInputStream + */ + /* + * @testName: getContentTypeTest + * + * @assertion_ids: Servlet:JAVADOC:390; Servlet:SPEC:34; + * + * @test_Strategy: Client sets the content type. Servlet wraps the request. + * Servlet reads it from wrapped request. + * + */ + /* + * @testName: getInputStreamTest + * + * @assertion_ids: Servlet:JAVADOC:391 + * + * @test_Strategy: Servlet wraps the request. Servlet then tries to read the + * input stream. + */ + /* + * @testName: getLocaleTest + * + * @assertion_ids: Servlet:JAVADOC:407 + * + * @test_Strategy: Client specifics a locale, Servlet wraps the request. + * Servlet then verifies it. + */ + /* + * @testName: getLocalesTest + * + * @assertion_ids: Servlet:JAVADOC:408 + * + * @test_Strategy: Client specifics 2 locales.Servlet wraps the request. + * Servlet then verifies it. + */ + /* + * @testName: getParameterMapTest + * + * @assertion_ids: Servlet:JAVADOC:394 + * + * @test_Strategy: Client sets several parameters.Servlet wraps the request. + * Servlet then attempts to access them. + */ + /* + * @testName: getParameterNamesTest + * + * @assertion_ids: Servlet:JAVADOC:395 + * + * @test_Strategy: Client sets several parameters.Servlet wraps the request. + * Servlet then attempts to access them. + */ + /* + * @testName: getParameterTest + * + * @assertion_ids: Servlet:JAVADOC:393 + * + * @test_Strategy: Client sets a parameter.Servlet wraps the request. Servlet + * then retrieves parameter. + */ + /* + * @testName: getParameterValuesTest + * + * @assertion_ids: Servlet:JAVADOC:396 + * + * @test_Strategy: Client sets a parameter which has 2 values.Servlet wraps + * the request. Servlet then verifies both values. + */ + /* + * @testName: getProtocolTest + * + * @assertion_ids: Servlet:JAVADOC:397 + * + * @test_Strategy: Servlet wraps the request. Servlet then verifies the + * protocol used by the client + */ + /* + * @testName: getReaderTest + * + * @assertion_ids: Servlet:JAVADOC:401 + * + * @test_Strategy: Client sets some content.Servlet wraps the request. Servlet + * then reads the content + */ + /* + * @testName: getRemoteAddrTest + * + * @assertion_ids: Servlet:JAVADOC:403 + * + * @test_Strategy: Servlet wraps the request. Servlet then reads and verifies + * where the request originated + */ + /* + * @testName: getRemoteHostTest + * + * @assertion_ids: Servlet:JAVADOC:404 + * + * @test_Strategy: Servlet wraps the request. Servlet then reads and verifies + * where the request originated + */ + /* + * @testName: getRequestDispatcherTest + * + * @assertion_ids: Servlet:JAVADOC:410 + * + * @test_Strategy: Servlet wraps the request. Servlet then tries to get a + * dispatcher + */ + /* + * @testName: getSchemeTest + * + * @assertion_ids: Servlet:JAVADOC:398 + * + * @test_Strategy: Servlet wraps the request. Servlet then verifies the scheme + * of the url used in the request + */ + /* + * @testName: getServerNameTest + * + * @assertion_ids: Servlet:JAVADOC:399 + * + * @test_Strategy: Servlet wraps the request. Servlet then verifies the + * destination of the request + */ + /* + * @testName: getServerPortTest + * + * @assertion_ids: Servlet:JAVADOC:400 + * + * @test_Strategy: Servlet wraps the request. Servlet then verifies the + * destination port of the request + */ + /* + * @testName: isSecureTest + * + * @assertion_ids: Servlet:JAVADOC:409 + * + * @test_Strategy: Servlet wraps the request. Servlet then verifies the + * isSecure method for the non-secure case. + */ + /* + * @testName: removeAttributeTest + * + * @assertion_ids: Servlet:JAVADOC:406 + * + * @test_Strategy: Servlet wraps the request. Servlet then adds then removes + * an attribute, then verifies it was removed. + */ + /* + * @testName: setAttributeTest + * + * @assertion_ids: Servlet:JAVADOC:405 + * + * @test_Strategy: Servlet wraps the request. Servlet then adds an attribute, + * then verifies it was added + */ + /* + * @testName: setCharacterEncodingUnsupportedEncodingExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:388 + * + * @test_Strategy: Servlet wraps the request. Servlet then tries to set an + * invalid encoding. + */ + /* + * @testName: setCharacterEncodingTest + * + * @assertion_ids: Servlet:JAVADOC:387 + * + * @test_Strategy: Servlet wraps the request. Servlet then sets a new encoding + * and tries to retrieve it. + */ + /* + * @testName: setCharacterEncodingTest1 + * + * @assertion_ids: Servlet:JAVADOC:387; Servlet:JAVADOC:386; Servlet:SPEC:28; + * Servlet:SPEC:213; + * + * @test_Strategy: Servlet wraps the HttpServletRequest. HttpServletRequest + * calls getReader(); then sets a new encoding and tries to retrieve it. + * verifies that the new encoding is ignored. + */ + // ---------------------- END ServletRequestWrapper + // ---------------------------- + // ------------------------ HttpServletRequestWrapper + // -------------------------- + /* + * @testName: httpRequestWrapperConstructorTest + * + * @assertion_ids: Servlet:JAVADOC:355 + * + * @test_Strategy: Validate an IllegalArgumentException is thrown is a null + * request is passed to the Wrapper's constructor. + */ + @Test + public void httpRequestWrapperConstructorTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "httpRequestWrapperConstructorTest"); + invoke(); + } + + /* + * @testName: httpRequestWrapperConstructorIllegalArgumentExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:626 + * + * @test_Strategy: Validate an IllegalArgumentException is thrown is a null + * request is passed to the Wrapper's constructor. + */ + @Test + public void httpRequestWrapperConstructorIllegalArgumentExceptionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "httpRequestWrapperConstructorIllegalArgumentExceptionTest"); + invoke(); + } + + /* + * @testName: getAuthTypeWithoutProtectionTest + * + * @assertion_ids: Servlet:JAVADOC:356 + * + * @test_Strategy: Servlet wraps the request. Servlet verifies correct result + */ + /* + * @testName: getContextPathTest + * + * @assertion_ids: Servlet:JAVADOC:366 + * + * @test_Strategy: Client sets header and servlet verifies the result + */ + /* + * @testName: getCookiesTest + * + * @assertion_ids: Servlet:JAVADOC:357 + * + * @test_Strategy:Client sets a cookie and servlet tries to read it + */ + /* + * @testName: getDateHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:358 + * + * @test_Strategy: client sets a dateheader and servlet tries to read it. + */ + /* + * @testName: getHeaderNamesTest + * + * @assertion_ids: Servlet:JAVADOC:361 + * + * @test_Strategy: Client sets some headers and servlet tries to read them + */ + /* + * @testName: getHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:359 + * + * @test_Strategy: Client sets a header and servlet tries to read it. + */ + /* + * @testName: getHeadersTest + * + * @assertion_ids: Servlet:JAVADOC:360 + * + * @test_Strategy: Client sets some headers and servlet tries to read them + */ + /* + * @testName: getIntHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:362 + * + * @test_Strategy: Client sets a header and servlet reads it + */ + /* + * @testName: getMethodTest + * + * @assertion_ids: Servlet:JAVADOC:363 + * + * @test_Strategy: Client makes 3 calls using GET/POST/HEAD + */ + /* + * @testName: getPathInfoTest + * + * @assertion_ids: Servlet:JAVADOC:364; Servlet:SPEC:25; + * + * @test_Strategy: Servlet wraps the request. Servlet verifies path info + */ + /* + * @testName: getPathTranslatedTest + * + * @assertion_ids: Servlet:JAVADOC:365 + * + * @test_Strategy: client sets extra path info and servlet verifies it + */ + /* + * @testName: getQueryStringTest + * + * @assertion_ids: Servlet:JAVADOC:367 + * + * @test_Strategy: Client sets query string and servlet verifies it + */ + /* + * @testName: getRemoteUserTest + * + * @assertion_ids: Servlet:JAVADOC:368 + * + * @test_Strategy: Servlet wraps the request. Servlet verifies the result of a + * non-authed user + */ + /* + * @testName: getRequestURITest + * + * @assertion_ids: Servlet:JAVADOC:372 + * + * @test_Strategy: Servlet wraps the request. Servlet verifies URI data + */ + /* + * @testName: getRequestURLTest + * + * @assertion_ids: Servlet:JAVADOC:373 + * + * @test_Strategy: Servlet wraps the request. Servlet verifies URL info + */ + /* + * @testName: getRequestedSessionIdNullTest + * + * @assertion_ids: Servlet:JAVADOC:371 + * + * @test_Strategy: Servlet wraps the request. Servlet verifies null result + */ + /* + * @testName: getServletPathTest + * + * @assertion_ids: Servlet:JAVADOC:374; Servlet:SPEC:24; + * + * @test_Strategy: Servlet wraps the request. Servlet verifies path info + */ + /* + * @testName: getSessionTrueTest + * + * @assertion_ids: Servlet:JAVADOC:375 + * + * @test_Strategy: Servlet wraps the request. Servlet verifies + * getSession(boolean) call + */ + /* + * @testName: getSessionTest + * + * @assertion_ids: Servlet:JAVADOC:376 + * + * @test_Strategy: Servlet wraps the request. Servlet verifies getSession() + * call + */ + /* + * @testName: isRequestedSessionIdFromCookieTest + * + * @assertion_ids: Servlet:JAVADOC:378 + * + * @test_Strategy: Access Servlet through URL; Servlet wraps the request; + * Servlet verifies API isRequestedSessionIdFromCookie return false; Negative + * test + */ + /* + * @testName: isRequestedSessionIdFromCookieTest1 + * + * @assertion_ids: Servlet:JAVADOC:378 + * + * @test_Strategy: Access Servlet through URL; Servlet wraps the request; + * Servlet starts a HttpSession; Client saves SessionID from Server and use it + * to access Servlet again; Servlet verifies API + * isRequestedSessionIdFromCookie return true; Positive test + */ + /* + * @testName: isRequestedSessionIdFromURLTest + * + * @assertion_ids: Servlet:JAVADOC:379 + * + * @test_Strategy: Servlet wraps the request. Servlet verifies correct result + */ + /* + * @testName: isRequestedSessionIdValidTest + * + * @assertion_ids: Servlet:JAVADOC:377; Servlet:SPEC:211; + * + * @test_Strategy: Client sends request without session ID; Servlet wraps the + * request; Verifies isRequestedSessionIdValid() returns false; + */ + /* + * @testName: getRequestedSessionIdTest1 + * + * @assertion_ids: Servlet:JAVADOC:371; + * + * @test_Strategy: Client sends request with a session ID; Verifies + * getRequestedSessionId() returns the same; + */ + /* + * @testName: getRequestedSessionIdTest2 + * + * @assertion_ids: Servlet:JAVADOC:371; + * + * @test_Strategy: Client sends request to a servlet with a sesion ID; Servlet + * start a sesison; Verifies getRequestedSessionId() returns the same; + */ + /* + * @testName: getLocalPortTest + * + * @assertion_ids: Servlet:JAVADOC:631; + * + * @test_Strategy: Send an HttpServletRequestWrapper to server; Test Servlet + * API getLocalPort(); + */ + /* + * @testName: getLocalNameTest + * + * @assertion_ids: Servlet:JAVADOC:634; + * + * @test_Strategy: Send an HttpServletRequestWrapper to server; Test Servlet + * API getLocalName(); + */ + /* + * @testName: httpRequestWrapperGetRequestTest + * + * @assertion_ids: Servlet:JAVADOC:381 + * + * @test_Strategy: Servlet gets wrapped response object + */ + @Test + public void httpRequestWrapperGetRequestTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "httpRequestWrapperGetRequestTest"); + invoke(); + } + + /* + * @testName: httpRequestWrapperSetRequestTest + * + * @assertion_ids: Servlet:JAVADOC:382 + * + * @test_Strategy: Servlet sets wrapped response object + */ + @Test + public void httpRequestWrapperSetRequestTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "httpRequestWrapperSetRequestTest"); + invoke(); + } + + /* + * @testName: httpRequestWrapperSetRequestIllegalArgumentExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:383 + * + * @test_Strategy: Servlet sets wrapped response object + */ + @Test + public void httpRequestWrapperSetRequestIllegalArgumentExceptionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "httpRequestWrapperSetRequestIllegalArgumentExceptionTest"); + invoke(); + } + + // ---------------------- END HttpServletRequestWrapper + // ------------------------ + @Test() + public void getAttributeNamesTest() throws Exception { + super.getAttributeNamesTest(); + } + + @Test() + public void getAttributeTest() throws Exception { + super.getAttributeTest(); + } + + @Test() + public void getAuthTypeWithoutProtectionTest() throws Exception { + super.getAuthTypeWithoutProtectionTest(); + } + + @Test() + public void getCharacterEncodingTest() throws Exception { + super.getCharacterEncodingTest(); + } + + @Test() + public void getContentLengthTest() throws Exception { + super.getContentLengthTest(); + } + + @Test() + public void getContentTypeTest() throws Exception { + super.getContentTypeTest(); + } + + @Test() + public void getContextPathTest() throws Exception { + super.getContextPathTest(); + } + + @Test() + public void getCookiesTest() throws Exception { + super.getCookiesTest(); + } + + @Test() + public void getDateHeaderTest() throws Exception { + super.getDateHeaderTest(); + } + + @Test() + public void getHeaderNamesTest() throws Exception { + super.getHeaderNamesTest(); + } + + @Test() + public void getHeaderTest() throws Exception { + super.getHeaderTest(); + } + + @Test() + public void getHeadersTest() throws Exception { + super.getHeadersTest(); + } + + @Test() + public void getInputStreamTest() throws Exception { + super.getInputStreamTest(); + } + + @Test() + public void getIntHeaderTest() throws Exception { + super.getIntHeaderTest(); + } + + @Test() + public void getLocalNameTest() throws Exception { + super.getLocalNameTest(); + } + + @Test() + public void getLocalPortTest() throws Exception { + super.getLocalPortTest(); + } + + @Test() + public void getLocaleTest() throws Exception { + super.getLocaleTest(); + } + + @Test() + public void getLocalesTest() throws Exception { + super.getLocalesTest(); + } + + @Test() + public void getMethodTest() throws Exception { + super.getMethodTest(); + } + + @Test() + public void getParameterMapTest() throws Exception { + super.getParameterMapTest(); + } + + @Test() + public void getParameterNamesTest() throws Exception { + super.getParameterNamesTest(); + } + + @Test() + public void getParameterTest() throws Exception { + super.getParameterTest(); + } + + @Test() + public void getParameterValuesTest() throws Exception { + super.getParameterValuesTest(); + } + + @Test() + public void getPathInfoTest() throws Exception { + super.getPathInfoTest(); + } + + @Test() + public void getPathTranslatedTest() throws Exception { + super.getPathTranslatedTest(); + } + + @Test() + public void getProtocolTest() throws Exception { + super.getProtocolTest(); + } + + @Test() + public void getQueryStringTest() throws Exception { + super.getQueryStringTest(); + } + + @Test() + public void getReaderTest() throws Exception { + super.getReaderTest(); + } + + @Test() + public void getRemoteAddrTest() throws Exception { + super.getRemoteAddrTest(); + } + + @Test() + public void getRemoteHostTest() throws Exception { + super.getRemoteHostTest(); + } + + @Test() + public void getRemoteUserTest() throws Exception { + super.getRemoteUserTest(); + } + + @Test() + public void getRequestDispatcherTest() throws Exception { + super.getRequestDispatcherTest(); + } + + @Test() + public void getRequestURITest() throws Exception { + super.getRequestURITest(); + } + + @Test() + public void getRequestURLTest() throws Exception { + super.getRequestURLTest(); + } + + @Test() + public void getRequestedSessionIdNullTest() throws Exception { + super.getRequestedSessionIdNullTest(); + } + + @Test() + public void getRequestedSessionIdTest1() throws Exception { + super.getRequestedSessionIdTest1(); + } + + @Test() + public void getRequestedSessionIdTest2() throws Exception { + super.getRequestedSessionIdTest2(); + } + + @Test() + public void getSchemeTest() throws Exception { + super.getSchemeTest(); + } + + @Test() + public void getServerNameTest() throws Exception { + super.getServerNameTest(); + } + + @Test() + public void getServerPortTest() throws Exception { + super.getServerPortTest(); + } + + @Test() + public void getServletPathTest() throws Exception { + super.getServletPathTest(); + } + + @Test() + public void getSessionTest() throws Exception { + super.getSessionTest(); + } + + @Test() + public void getSessionTrueTest() throws Exception { + super.getSessionTrueTest(); + } + + @Test() + public void isRequestedSessionIdFromCookieTest() throws Exception { + super.isRequestedSessionIdFromCookieTest(); + } + + @Test() + public void isRequestedSessionIdFromCookieTest1() throws Exception { + super.isRequestedSessionIdFromCookieTest1(); + } + + @Test() + public void isRequestedSessionIdFromURLTest() throws Exception { + super.isRequestedSessionIdFromURLTest(); + } + + @Test() + public void isRequestedSessionIdValidTest() throws Exception { + super.isRequestedSessionIdValidTest(); + } + + @Test() + public void isSecureTest() throws Exception { + super.isSecureTest(); + } + + @Test() + public void removeAttributeTest() throws Exception { + super.removeAttributeTest(); + } + + @Test() + public void setAttributeTest() throws Exception { + super.setAttributeTest(); + } + + @Test() + public void setCharacterEncodingTest() throws Exception { + super.setCharacterEncodingTest(); + } + + @Test() + public void setCharacterEncodingTest1() throws Exception { + super.setCharacterEncodingTest1(); + } + + @Test() + public void setCharacterEncodingUnsupportedEncodingExceptionTest() throws Exception { + super.setCharacterEncodingUnsupportedEncodingExceptionTest(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletrequestwrapper/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletrequestwrapper/build.xml new file mode 100644 index 0000000000..44b9497ad1 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletrequestwrapper/build.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletrequestwrapper/servlet_pluh_HSReqWrapper_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletrequestwrapper/servlet_pluh_HSReqWrapper_web-fragment.xml new file mode 100644 index 0000000000..1ce2e9bedd --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletrequestwrapper/servlet_pluh_HSReqWrapper_web-fragment.xml @@ -0,0 +1,68 @@ + + + + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequestwrapper.TestServlet + + + setCharacterEncodingUnsupportedEncodingExceptionTestWrapper + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequestwrapper.SetCharacterEncodingUnsupportedEncodingExceptionTestWrapper + + + setCharacterEncodingUnsupportedEncodingExceptionTest + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequestwrapper.SetCharacterEncodingUnsupportedEncodingExceptionTest + + + setCharacterEncodingTestWrapper + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequestwrapper.SetCharacterEncodingTestWrapper + + + setCharacterEncodingTest + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletrequestwrapper.SetCharacterEncodingTest + + + TestServlet + /TestServlet/* + + + setCharacterEncodingUnsupportedEncodingExceptionTestWrapper + /setCharacterEncodingUnsupportedEncodingExceptionTestWrapper + + + setCharacterEncodingUnsupportedEncodingExceptionTest + /setCharacterEncodingUnsupportedEncodingExceptionTest + + + setCharacterEncodingTestWrapper + /setCharacterEncodingTestWrapper + + + setCharacterEncodingTest + /setCharacterEncodingTest + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletrequestwrapper/servlet_pluh_HSReqWrapper_web.war.sun-web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletrequestwrapper/servlet_pluh_HSReqWrapper_web.war.sun-web.xml new file mode 100644 index 0000000000..af368d6628 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletrequestwrapper/servlet_pluh_HSReqWrapper_web.war.sun-web.xml @@ -0,0 +1,28 @@ + + + + + + /servlet_pluh_HSReqWrapper_web + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletresponse/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletresponse/URLClient.java new file mode 100644 index 0000000000..dd1fbcdac3 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletresponse/URLClient.java @@ -0,0 +1,627 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet_http.httpservletresponse; + +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponse.GetContentTypeNullTestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponse.RedirectedTestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponse.ServletErrorPage; +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponse.SetCharacterEncodingTestServlet; +import com.sun.ts.tests.servlet.common.response.HttpResponseClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends HttpResponseClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar").addClasses(TestServlet1.class, RequestListener1.class).addAsResource(URLClient.class.getResource("servlet_pluh_httpservletresponse_web-fragment.xml"), "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_pluh_httpservletresponse_web.war").addAsLibraries(CommonServlets.getCommonServletsArchive()).addClasses(GetContentTypeNullTestServlet.class, RedirectedTestServlet.class, ServletErrorPage.class, SetCharacterEncodingTestServlet.class).addAsLibraries(javaArchive); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + // --------------------------- ServletResponse + // ---------------------------------- + /* + * @testName: flushBufferTest + * + * @assertion_ids: Servlet:JAVADOC:603 + * + * @test_Strategy: Servlet writes data in the buffer and flushes it + */ + /* + * @testName: getBufferSizeTest + * + * @assertion_ids: Servlet:JAVADOC:605 + * + * @test_Strategy: Servlet flushes buffer and verifies the size of the buffer + */ + /* + * @testName: getLocaleDefaultTest + * + * @assertion_ids: Servlet:JAVADOC:625; + * + * @test_Strategy: Validate that getLocale() will return the default locale of + * the VM that the container is running in when setLocale() is not called. + */ + /* + * @testName: getLocaleTest + * + * @assertion_ids: Servlet:JAVADOC:608 + * + * @test_Strategy: Servlet set Locale and then verifies it + * + */ + /* + * @testName: getOutputStreamTest + * + * @assertion_ids: Servlet:JAVADOC:609 + * + * @test_Strategy: Servlet gets an output stream and writes to it. + */ + /* + * @testName: getOutputStreamIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:611 + * + * @test_Strategy: Servlet tries to get an stream object after calling + * getWriter + */ + /* + * @testName: getWriterTest + * + * @assertion_ids: Servlet:JAVADOC:612; Servlet:JAVADOC:151.2; + * Servlet:JAVADOC:151.3; + * + * @test_Strategy: Servlet gets a Writer object and writes data; sets content + * type by calling ServletResponse.setContentType; Verify that content type + * gets set, not encoding + */ + /* + * @testName: getWriterIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:615 + * + * @test_Strategy: Servlet tries to get a Writer object after calling + * getOutputStream + */ + /* + * @testName: isCommittedTest + * + * @assertion_ids: Servlet:JAVADOC:616 + * + * @test_Strategy: Servlet checks before and after response is flushed + * + */ + /* + * @testName: resetBufferTest + * + * @assertion_ids: Servlet:JAVADOC:619; Servlet:SPEC:31; + * + * @test_Strategy: Servlet writes data to the response, resets the buffer and + * then writes new data + */ + /* + * @testName: resetTest + * + * @assertion_ids: Servlet:JAVADOC:617; Servlet:SPEC:31; + * + * @test_Strategy: Servlet writes data to the response, does a reset, then + * writes new data + */ + /* + * @testName: resetTest1 + * + * @assertion_ids: Servlet:JAVADOC:617; Servlet:SPEC:31; + * + * @test_Strategy: Servlet writes data to the response, set the Headers, does + * a reset, then writes new data, set the new Header + */ + /* + * @testName: resetIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:618; Servlet:SPEC:31; + * + * @test_Strategy: Servlet writes data, flushes the buffer then tries to do a + * reset + */ + /* + * @testName: getCharacterEncodingDefaultTest + * + * @assertion_ids: Servlet:JAVADOC:606 + * + * @test_Strategy: Servlet checks for the default encoding + */ + /* + * @testName: getCharacterEncodingTest + * + * @assertion_ids: Servlet:JAVADOC:606 + * + * @test_Strategy: Servlet sets encoding then checks it. + */ + /* + * @testName: setCharacterEncodingTest + * + * @assertion_ids: Servlet:JAVADOC:622; Servlet:JAVADOC:151.3; + * + * @test_Strategy: Servlet set encoding by calling + * ServletResponse.setCharcaterEncoding; client verifies it is set + */ + /* + * @testName: setBufferSizeTest + * + * @assertion_ids: Servlet:JAVADOC:620 + * + * @test_Strategy: Servlet sets the buffer size then verifies it was set + */ + /* + * @testName: setBufferSizeIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:621 + * + * @test_Strategy: Servlet writes data and flushes buffer then tries to get + * the buffer size + */ + /* + * @testName: setContentLengthTest + * + * @assertion_ids: Servlet:JAVADOC:623 + * + * @test_Strategy: Servlet sets the content length + */ + /* + * @testName: getContentTypeTest + * + * @assertion_ids: Servlet:JAVADOC:607; Servlet:SPEC:34; + * + * @test_Strategy: Servlet verifies the content type + */ + @Test + public void getContentTypeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getContentTypeTest"); + invoke(); + TEST_PROPS.setProperty(REQUEST, "GET /servlet_pluh_httpservletresponse_web/GetContentTypeNullTestServlet HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Test PASSED"); + invoke(); + } + + /* + * @testName: setContentTypeTest + * + * @assertion_ids: Servlet:JAVADOC:624; Servlet:JAVADOC:151.3; + * Servlet:SPEC:34; + * + * @test_Strategy: Servlet sets the content type; Verify Content-Type is set + * in Client + */ + /* + * @testName: setContentType1Test + * + * @assertion_ids: Servlet:JAVADOC:151; Servlet:SPEC:34; + * + * @test_Strategy: Servlet sets the content-type, and verifies it with + * getContentType() + */ + /* + * @testName: setContentType2Test + * + * @assertion_ids: Servlet:JAVADOC:151.2; Servlet:JAVADOC:151.3; + * Servlet:SPEC:34; + * + * @test_Strategy: Servlet sets the content-type, Commit the response; Set the + * content-type again Verifies that content-type is set the first time The + * second setting is ignored. + */ + /* + * @testName: setLocaleTest + * + * @assertion_ids: Servlet:JAVADOC:625 + * + * @test_Strategy: Servlet sets the Locale + */ + // ---------------------------- END ServletResponse + // ----------------------------- + // ------------------------ HttpServletResponse + // --------------------------------- + /* + * @testName: addCookieTest + * + * @assertion_ids: Servlet:JAVADOC:502 + * + * @test_Strategy: Servlet adds 2 cookies, client verifies them + */ + /* + * @testName: addDateHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:522 + * + * @test_Strategy: Servlet adds a date header and client verifies it + */ + /* + * @testName: addHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:525 + * + * @test_Strategy: Servlet adds 2 headers with 3 values and client verifies + * them + */ + /* + * @testName: addIntHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:527 + * + * @test_Strategy: Servlet adds 2 int headers with 3 values and client + * verifies them + */ + /* + * @testName: containsHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:503 + * + * @test_Strategy: Servlet sets a header and verifies it exists, then the + * servlet tries to verify that a header does not exist. + */ + /* + * @testName: sendErrorIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:514 + * + * @test_Strategy: Servlet adds a header, a cookie, and content, then flushes + * the buffer. Servlet verifies exception is generated + */ + /* + * @testName: sendError_StringIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:511 + * + * @test_Strategy: Servlet adds a header, a cookie, and content, then flushes + * the buffer. Servlet verifies exception is generated + */ + /* + * @testName: sendErrorClearBufferTest + * + * @assertion_ids: Servlet:JAVADOC:512; Servlet:SPEC:39; + * + * @test_Strategy: Servlet adds content and an error, client verifies the + * error and that the content was cleared + */ + /* + * @testName: sendError_StringTest + * + * @assertion_ids: Servlet:JAVADOC:508 + * + * @test_Strategy: Servlet adds a header, a cookie and an error, client + * verifies the error and that the header still exists + */ + /* + * @testName: sendError_StringErrorPageTest + * + * @assertion_ids: Servlet:JAVADOC:509 + * + * @test_Strategy: Servlet adds a header, a cookie and content and an error. + * There also is an error page configured to catch error. Client verifies the + * error. + */ + /* + * @testName: sendRedirectWithLeadingSlashTest + * + * @assertion_ids: Servlet:JAVADOC:516 + * + * @test_Strategy: Servlet redirects to another servlet + */ + /* + * @testName: sendRedirectWithoutLeadingSlashTest + * + * @assertion_ids: Servlet:JAVADOC:515 + * + * @test_Strategy: Servlet redirects to another servlet + */ + /* + * @testName: sendRedirectIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:519 + * + * @test_Strategy: Servlet flushes the buffer then tries to redirect + */ + /* + * @testName: setDateHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:520 + * + * @test_Strategy: Servlet sets a date header and client verifies it + */ + /* + * @testName: setDateHeaderOverrideTest + * + * @assertion_ids: Servlet:JAVADOC:521 + * + * @test_Strategy: Servlet sets the same date header twice and client verifies + * it + */ + /* + * @testName: setHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:523 + * + * @test_Strategy: Servlet sets a header and client verifies it + */ + /* + * @testName: setHeaderOverrideTest + * + * @assertion_ids: Servlet:JAVADOC:524 + * + * @test_Strategy: Servlet sets the same header twice and client verifies it + */ + /* + * @testName: setMultiHeaderTest + * + * @assertion_ids: Servlet:SPEC:183; Servlet:JAVADOC:523; Servlet:JAVADOC:525; + * Servlet:JAVADOC:524 + * + * @test_Strategy: Servlet sets the multivalues for the same header; verify + * that setHeader clear all with new value + */ + /* + * @testName: setIntHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:526 + * + * @test_Strategy: Servlet sets an int header and client verifies it + */ + /* + * @testName: setStatusTest + * + * @assertion_ids: Servlet:JAVADOC:528 + * + * @test_Strategy: Servlet sets a status and client verifies it + */ + // ----------------------- END HttpServletResponse + // ------------------------------ + @Test() + public void addCookieTest() throws Exception { + super.addCookieTest(); + } + + @Test() + public void addDateHeaderTest() throws Exception { + super.addDateHeaderTest(); + } + + @Test() + public void addHeaderTest() throws Exception { + super.addHeaderTest(); + } + + @Test() + public void addIntHeaderTest() throws Exception { + super.addIntHeaderTest(); + } + + @Test() + public void containsHeaderTest() throws Exception { + super.containsHeaderTest(); + } + + @Test() + public void flushBufferTest() throws Exception { + super.flushBufferTest(); + } + + @Test() + public void getBufferSizeTest() throws Exception { + super.getBufferSizeTest(); + } + + @Test() + public void getCharacterEncodingDefaultTest() throws Exception { + super.getCharacterEncodingDefaultTest(); + } + + @Test() + public void getCharacterEncodingTest() throws Exception { + super.getCharacterEncodingTest(); + } + + @Test() + public void getLocaleDefaultTest() throws Exception { + super.getLocaleDefaultTest(); + } + + @Test() + public void getLocaleTest() throws Exception { + super.getLocaleTest(); + } + + @Test() + public void getOutputStreamIllegalStateExceptionTest() throws Exception { + super.getOutputStreamIllegalStateExceptionTest(); + } + + @Test() + public void getOutputStreamTest() throws Exception { + super.getOutputStreamTest(); + } + + @Test() + public void getWriterIllegalStateExceptionTest() throws Exception { + super.getWriterIllegalStateExceptionTest(); + } + + @Test() + public void getWriterTest() throws Exception { + super.getWriterTest(); + } + + @Test() + public void isCommittedTest() throws Exception { + super.isCommittedTest(); + } + + @Test() + public void resetBufferTest() throws Exception { + super.resetBufferTest(); + } + + @Test() + public void resetIllegalStateExceptionTest() throws Exception { + super.resetIllegalStateExceptionTest(); + } + + @Test() + public void resetTest() throws Exception { + super.resetTest(); + } + + @Test() + public void resetTest1() throws Exception { + super.resetTest1(); + } + + @Test() + public void sendErrorClearBufferTest() throws Exception { + super.sendErrorClearBufferTest(); + } + + @Test() + public void sendErrorIllegalStateExceptionTest() throws Exception { + super.sendErrorIllegalStateExceptionTest(); + } + + @Test() + public void sendError_StringErrorPageTest() throws Exception { + super.sendError_StringErrorPageTest(); + } + + @Test() + public void sendError_StringIllegalStateExceptionTest() throws Exception { + super.sendError_StringIllegalStateExceptionTest(); + } + + @Test() + public void sendError_StringTest() throws Exception { + super.sendError_StringTest(); + } + + @Test() + public void sendRedirectIllegalStateExceptionTest() throws Exception { + super.sendRedirectIllegalStateExceptionTest(); + } + + @Test() + public void sendRedirectWithLeadingSlashTest() throws Exception { + super.sendRedirectWithLeadingSlashTest(); + } + + @Test() + public void sendRedirectWithoutLeadingSlashTest() throws Exception { + super.sendRedirectWithoutLeadingSlashTest(); + } + + @Test() + public void setBufferSizeIllegalStateExceptionTest() throws Exception { + super.setBufferSizeIllegalStateExceptionTest(); + } + + @Test() + public void setBufferSizeTest() throws Exception { + super.setBufferSizeTest(); + } + + @Test() + public void setCharacterEncodingTest() throws Exception { + super.setCharacterEncodingTest(); + } + + @Test() + public void setContentLengthTest() throws Exception { + super.setContentLengthTest(); + } + + @Test() + public void setContentType1Test() throws Exception { + super.setContentType1Test(); + } + + @Test() + public void setContentType2Test() throws Exception { + super.setContentType2Test(); + } + + @Test() + public void setContentTypeTest() throws Exception { + super.setContentTypeTest(); + } + + @Test() + public void setDateHeaderOverrideTest() throws Exception { + super.setDateHeaderOverrideTest(); + } + + @Test() + public void setDateHeaderTest() throws Exception { + super.setDateHeaderTest(); + } + + @Test() + public void setHeaderOverrideTest() throws Exception { + super.setHeaderOverrideTest(); + } + + @Test() + public void setHeaderTest() throws Exception { + super.setHeaderTest(); + } + + @Test() + public void setIntHeaderTest() throws Exception { + super.setIntHeaderTest(); + } + + @Test() + public void setLocaleTest() throws Exception { + super.setLocaleTest(); + } + + @Test() + public void setMultiHeaderTest() throws Exception { + super.setMultiHeaderTest(); + } + + @Test() + public void setStatusTest() throws Exception { + super.setStatusTest(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletresponse/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletresponse/build.xml new file mode 100644 index 0000000000..3054f490d6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletresponse/build.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletresponse/servlet_pluh_httpservletresponse_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletresponse/servlet_pluh_httpservletresponse_web-fragment.xml new file mode 100644 index 0000000000..ba24c57e12 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletresponse/servlet_pluh_httpservletresponse_web-fragment.xml @@ -0,0 +1,80 @@ + + + + + + TestServlet + com.sun.ts.tests.servlet.common.response.HttpResponseTestServlet + + + GetContentTypeNullTestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponse.GetContentTypeNullTestServlet + + + RedirectedTest + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponse.RedirectedTestServlet + + + setCharacterEncodingTest + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponse.SetCharacterEncodingTestServlet + + + checkTestResult + com.sun.ts.tests.servlet.common.servlets.HttpCheckTestResultServlet + + + servletErrorPage + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponse.ServletErrorPage + + + TestServlet + /TestServlet/* + + + RedirectedTest + /RedirectedTest/* + + + setCharacterEncodingTest + /setCharacterEncodingTest + + + GetContentTypeNullTestServlet + /GetContentTypeNullTestServlet + + + checkTestResult + /checkTestResult + + + servletErrorPage + /servletErrorPage + + + 54 + + + 411 + /servletErrorPage + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletresponse30/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletresponse30/URLClient.java new file mode 100644 index 0000000000..02ac1cc68f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletresponse30/URLClient.java @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet_http.httpservletresponse30; + +import com.sun.ts.tests.servlet.common.response.HttpResponseClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends HttpResponseClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar").addClasses(TestServlet1.class, RequestListener1.class).addAsResource(URLClient.class.getResource("servlet_pluh_httpservletresponse30_web-fragment.xml"), "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_pluh_httpservletresponse30_web.war").addAsLibraries(CommonServlets.getCommonServletsArchive()).addAsLibraries(javaArchive); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: getHeadersTest + * + * @assertion_ids: Servlet:JAVADOC:523; Servlet:JAVADOC:525; + * Servlet:JAVADOC:779; + * + * @test_Strategy: Create a Servlet, In the servlet, set a header value; then + * add multiple values to it; verify that getHeaders(String) works properly + */ + /* + * @testName: getHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:523; Servlet:JAVADOC:523; + * Servlet:JAVADOC:777; + * + * @test_Strategy: Create a Servlet, In the servlet, set a header value; then + * add multiple values to it; verify that getHeader(String) works properly + */ + /* + * @testName: getHeaderNamesTest + * + * @assertion_ids: Servlet:JAVADOC:520; Servlet:JAVADOC:522; + * Servlet:JAVADOC:523; Servlet:JAVADOC:525; Servlet:JAVADOC:526; + * Servlet:JAVADOC:527; Servlet:JAVADOC:778; + * + * @test_Strategy: Create a Servlet, In the servlet, set multiuple header + * values using: #setHeader, #addHeader, #setDateHeader, #addDateHeader, + * #setIntHeader, and #addIntHeader, verify that getHeaderNames() works + * properly + */ + /* + * @testName: getStatusTest + * + * @assertion_ids: Servlet:JAVADOC:780; + * + * @test_Strategy: Create a Servlet, In the servlet, set a status value; + * verify that getStatus() works properly + */ + @Test() + public void getHeaderNamesTest() throws Exception { + super.getHeaderNamesTest(); + } + + @Test() + public void getHeaderTest() throws Exception { + super.getHeaderTest(); + } + + @Test() + public void getHeadersTest() throws Exception { + super.getHeadersTest(); + } + + @Test() + public void getStatusTest() throws Exception { + super.getStatusTest(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletresponse30/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletresponse30/build.xml new file mode 100644 index 0000000000..b08591f2a1 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletresponse30/build.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletresponse30/servlet_pluh_httpservletresponse30_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletresponse30/servlet_pluh_httpservletresponse30_web-fragment.xml new file mode 100644 index 0000000000..edddae0397 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletresponse30/servlet_pluh_httpservletresponse30_web-fragment.xml @@ -0,0 +1,36 @@ + + + + + + TestServlet + com.sun.ts.tests.servlet.common.response.HttpResponseTestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletresponsewrapper/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletresponsewrapper/URLClient.java new file mode 100644 index 0000000000..a05ac095c5 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletresponsewrapper/URLClient.java @@ -0,0 +1,506 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet_http.httpservletresponsewrapper; + +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponsewrapper.RedirectedTestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponsewrapper.SetCharacterEncodingTestServlet; +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponsewrapper.TestServlet; +import com.sun.ts.tests.servlet.common.response.HttpResponseClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends HttpResponseClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive1 = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar").addClasses(TestServlet1.class, RequestListener1.class).addAsResource(URLClient.class.getResource("servlet_pluh_HSRespWrapper_web-fragment.xml"), "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_pluh_HSRespWrapper_web.war").addAsLibraries(CommonServlets.getCommonServletsArchive()).addClasses(RedirectedTestServlet.class, SetCharacterEncodingTestServlet.class, TestServlet.class).addAsLibraries(javaArchive1); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + /* Run test */ + // ------------------ ServletResponseWrapper + // ----------------------------------- + /* + * @testName: flushBufferTest + * + * @assertion_ids: Servlet:JAVADOC:348 + * + * @test_Strategy: Servlet wraps response. Servlet writes data in the buffer + * and flushes it + */ + /* + * @testName: getBufferSizeTest + * + * @assertion_ids: Servlet:JAVADOC:347 + * + * @test_Strategy: Servlet wraps response. Servlet flushes buffer and verifies + * the size of the buffer + */ + /* + * @testName: getLocaleTest + * + * @assertion_ids: Servlet:JAVADOC:354 + * + * @test_Strategy: Servlet wraps response. Servlet set Locale and then + * verifies it + * + */ + /* + * @testName: getOutputStreamTest + * + * @assertion_ids: Servlet:JAVADOC:339 + * + * @test_Strategy: Servlet wraps response. Servlet gets an output stream and + * writes to it. + */ + /* + * @testName: getWriterTest + * + * @assertion_ids: Servlet:JAVADOC:341 + * + * @test_Strategy: Servlet wraps response. Servlet gets a Writer object; then + * sets the content type. verify that content type didn't get set by servlet + */ + /* + * @testName: isCommittedTest + * + * @assertion_ids: Servlet:JAVADOC:350 + * + * @test_Strategy: Servlet wraps response. Servlet checks before and after + * response is flushed + * + */ + /* + * @testName: resetBufferTest + * + * @assertion_ids: Servlet:JAVADOC:352 + * + * @test_Strategy: Servlet wraps response. Servlet writes data to the + * response, resets the buffer and then writes new data + */ + /* + * @testName: resetTest + * + * @assertion_ids: Servlet:JAVADOC:351 + * + * @test_Strategy: Servlet wraps response. Servlet writes data to the + * response, does a reset, then writes new data + */ + /* + * @testName: resetTest1 + * + * @assertion_ids: Servlet:JAVADOC:351; Servlet:SPEC:31; + * + * @test_Strategy: Servlet writes data to the response, set the Headers, does + * a reset, then writes new data, set the new Header + */ + /* + * @testName: getCharacterEncodingTest + * + * @assertion_ids: Servlet:JAVADOC:338 + * + * @test_Strategy: Servlet wraps response. Servlet checks for the default + * encoding + */ + /* + * @testName: setCharacterEncodingTest + * + * @assertion_ids: Servlet:JAVADOC:337 + * + * @test_Strategy: Servlet wraps response. Servlet set the encoding and client + * verifies it + */ + /* + * @testName: setBufferSizeTest + * + * @assertion_ids: Servlet:JAVADOC:346 + * + * @test_Strategy: Servlet wraps response. Servlet sets the buffer size then + * verifies it was set + */ + /* + * @testName: setContentLengthTest + * + * @assertion_ids: Servlet:JAVADOC:343 + * + * @test_Strategy: Servlet wraps response. Servlet sets the content length + */ + /* + * @testName: getContentTypeTest + * + * @assertion_ids: Servlet:JAVADOC:345; Servlet:SPEC:34; + * + * @test_Strategy: Servlet wraps response. Servlet verifies the content type + * sent by the client + */ + /* + * @testName: setContentTypeTest + * + * @assertion_ids: Servlet:JAVADOC:344; Servlet:SPEC:34; + * + * @test_Strategy: Servlet wraps response. Servlet sets the content type + * + */ + /* + * @testName: setLocaleTest + * + * @assertion_ids: Servlet:JAVADOC:353 + * + * @test_Strategy: Servlet wraps response. Servlet sets the Locale + */ + // ----------------------- END ServletResponseWrapper + // -------------------------- + // --------------------- HttpServletResponseWrapper + // ---------------------------- + /* + * @testName: httpResponseWrapperGetResponseTest + * + * @assertion_ids: Servlet:JAVADOC:334 + * + * @test_Strategy: Servlet gets wrapped response object + */ + @Test + public void httpResponseWrapperGetResponseTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "httpResponseWrapperGetResponseTest"); + invoke(); + } + + /* + * @testName: httpResponseWrapperSetResponseTest + * + * @assertion_ids: Servlet:JAVADOC:335 + * + * @test_Strategy: Servlet sets wrapped response object + */ + @Test + public void httpResponseWrapperSetResponseTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "httpResponseWrapperSetResponseTest"); + invoke(); + } + + /* + * @testName: httpResponseWrapperSetResponseIllegalArgumentExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:336 + * + * @test_Strategy: Servlet sets wrapped response object + */ + @Test + public void httpResponseWrapperSetResponseIllegalArgumentExceptionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "httpResponseWrapperSetResponseIllegalArgumentExceptionTest"); + invoke(); + } + + /* + * @testName: httpResponseWrapperConstructorTest + * + * @assertion_ids: Servlet:JAVADOC:313 + * + * @test_Strategy: Validate constuctor of HttpServletResponseWrapper. + */ + @Test + public void httpResponseWrapperConstructorTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "httpResponseWrapperConstructorTest"); + invoke(); + } + + /* + * @testName: addCookieTest + * + * @assertion_ids: Servlet:JAVADOC:314 + * + * @test_Strategy: Servlet wrappers response and calls test + */ + /* + * @testName: addDateHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:327 + * + * @test_Strategy: Servlet wrappers response and calls test + */ + /* + * @testName: addHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:329 + * + * @test_Strategy: Servlet wrappers response and calls test + */ + /* + * @testName: addIntHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:331 + * + * @test_Strategy: Servlet wrappers response and calls test + */ + /* + * @testName: containsHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:315 + * + * @test_Strategy: Servlet wrappers response and calls test + */ + /* + * @testName: sendErrorClearBufferTest + * + * @assertion_ids: Servlet:JAVADOC:322; Servlet:SPEC:39; + * + * @test_Strategy: Servlet wrappers response and calls test + */ + /* + * @testName: sendError_StringTest + * + * @assertion_ids: Servlet:JAVADOC:320 + * + * @test_Strategy: Servlet wrappers response and calls test + */ + /* + * @testName: sendRedirectTest + * + * @assertion_ids: Servlet:JAVADOC:324 + * + * @test_Strategy: Servlet wrappers response and calls test + */ + @Test + public void sendRedirectTest() throws Exception { + String testName = "sendRedirectWithLeadingSlashTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + getServletName() + "?testname=" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(EXPECTED_HEADERS, "Location: http://" + _hostname + ":" + _port + "/RedirectedTest"); + TEST_PROPS.setProperty(STATUS_CODE, MOVED_TEMPORARY); + invoke(); + testName = "sendRedirectWithoutLeadingSlashTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + getServletName() + "?testname=" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(EXPECTED_HEADERS, "Location: http://" + _hostname + ":" + _port + "" + getContextRoot() + "/RedirectedTest"); + TEST_PROPS.setProperty(STATUS_CODE, MOVED_TEMPORARY); + invoke(); + } + + /* + * @testName: setDateHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:326 + * + * @test_Strategy: Servlet wrappers response and calls test + */ + /* + * @testName: setHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:328 + * + * @test_Strategy: Servlet wrappers response and calls test + */ + /* + * @testName: setMultiHeaderTest + * + * @assertion_ids: Servlet:SPEC:183; Servlet:JAVADOC:523; Servlet:JAVADOC:525; + * Servlet:JAVADOC:524 + * + * @test_Strategy: Servlet sets the multivalues for the same header; verify + * that setHeader clear all with new value + */ + /* + * @testName: setIntHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:330 + * + * @test_Strategy: Servlet wrappers response and calls test + */ + /* + * @testName: setStatusTest + * + * @assertion_ids: Servlet:JAVADOC:332 + * + * @test_Strategy: Testing Servlet API + * HttpServletResponseWrapper.setStatus(SC_OK) + */ + /* + * @testName: setStatusTest1 + * + * @assertion_ids: Servlet:JAVADOC:332 + * + * @test_Strategy: Testing Servlet API + * HttpServletResponseWrapper.setStatus(SC_NOT_FOUND) + */ + // ------------------- END HttpServletResponseWrapper + // -------------------------- + @Test() + public void addCookieTest() throws Exception { + super.addCookieTest(); + } + + @Test() + public void addDateHeaderTest() throws Exception { + super.addDateHeaderTest(); + } + + @Test() + public void addHeaderTest() throws Exception { + super.addHeaderTest(); + } + + @Test() + public void addIntHeaderTest() throws Exception { + super.addIntHeaderTest(); + } + + @Test() + public void containsHeaderTest() throws Exception { + super.containsHeaderTest(); + } + + @Test() + public void flushBufferTest() throws Exception { + super.flushBufferTest(); + } + + @Test() + public void getBufferSizeTest() throws Exception { + super.getBufferSizeTest(); + } + + @Test() + public void getCharacterEncodingTest() throws Exception { + super.getCharacterEncodingTest(); + } + + @Test() + public void getContentTypeTest() throws Exception { + super.getContentTypeTest(); + } + + @Test() + public void getLocaleTest() throws Exception { + super.getLocaleTest(); + } + + @Test() + public void getOutputStreamTest() throws Exception { + super.getOutputStreamTest(); + } + + @Test() + public void getWriterTest() throws Exception { + super.getWriterTest(); + } + + @Test() + public void isCommittedTest() throws Exception { + super.isCommittedTest(); + } + + @Test() + public void resetBufferTest() throws Exception { + super.resetBufferTest(); + } + + @Test() + public void resetTest() throws Exception { + super.resetTest(); + } + + @Test() + public void resetTest1() throws Exception { + super.resetTest1(); + } + + @Test() + public void sendErrorClearBufferTest() throws Exception { + super.sendErrorClearBufferTest(); + } + + @Test() + public void sendError_StringTest() throws Exception { + super.sendError_StringTest(); + } + + @Test() + public void setBufferSizeTest() throws Exception { + super.setBufferSizeTest(); + } + + @Test() + public void setCharacterEncodingTest() throws Exception { + super.setCharacterEncodingTest(); + } + + @Test() + public void setContentLengthTest() throws Exception { + super.setContentLengthTest(); + } + + @Test() + public void setContentTypeTest() throws Exception { + super.setContentTypeTest(); + } + + @Test() + public void setDateHeaderTest() throws Exception { + super.setDateHeaderTest(); + } + + @Test() + public void setHeaderTest() throws Exception { + super.setHeaderTest(); + } + + @Test() + public void setIntHeaderTest() throws Exception { + super.setIntHeaderTest(); + } + + @Test() + public void setLocaleTest() throws Exception { + super.setLocaleTest(); + } + + @Test() + public void setMultiHeaderTest() throws Exception { + super.setMultiHeaderTest(); + } + + @Test() + public void setStatusTest() throws Exception { + super.setStatusTest(); + } + + @Test() + public void setStatusTest1() throws Exception { + super.setStatusTest1(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletresponsewrapper/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletresponsewrapper/build.xml new file mode 100644 index 0000000000..a9ca637f64 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletresponsewrapper/build.xml @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletresponsewrapper/servlet_pluh_HSRespWrapper_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletresponsewrapper/servlet_pluh_HSRespWrapper_web-fragment.xml new file mode 100644 index 0000000000..4bd47bb0ff --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletresponsewrapper/servlet_pluh_HSRespWrapper_web-fragment.xml @@ -0,0 +1,52 @@ + + + + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponsewrapper.TestServlet + + + RedirectedTest + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponsewrapper.RedirectedTestServlet + + + setCharacterEncodingTest + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponsewrapper.SetCharacterEncodingTestServlet + + + TestServlet + /TestServlet/* + + + RedirectedTest + /RedirectedTest/* + + + setCharacterEncodingTest + /setCharacterEncodingTest + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletresponsewrapper30/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletresponsewrapper30/URLClient.java new file mode 100644 index 0000000000..41295aa386 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletresponsewrapper30/URLClient.java @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet_http.httpservletresponsewrapper30; + +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponsewrapper30.TestServlet; +import com.sun.ts.tests.servlet.common.response.HttpResponseClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends HttpResponseClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_pluh_HSRespWrapper30_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_pluh_HSRespWrapper30_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestServlet.class) + .addAsLibraries(javaArchive); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + // --------------------- HttpServletResponseWrapper + // ---------------------------- + + /* + * @testName: getHeadersTest + * + * @assertion_ids: Servlet:JAVADOC:523; Servlet:JAVADOC:525; + * Servlet:JAVADOC:783; + * + * @test_Strategy: Create a Servlet, wrap the servlet in another one, In the + * servlet, set a header value; then add multiple values to it; verify that + * getHeaders(String) works properly + */ + @Test + public void getHeadersTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getHeadersTest"); + invoke(); + } + + /* + * @testName: getHeaderTest + * + * @assertion_ids: Servlet:JAVADOC:523; Servlet:JAVADOC:523; + * Servlet:JAVADOC:781; + * + * @test_Strategy: Create a Servlet, wrap the servlet in another one, In the + * servlet, set a header value; then add multiple values to it; verify that + * getHeader(String) works properly + */ + @Test + public void getHeaderTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getHeaderTest"); + invoke(); + } + + /* + * @testName: getHeaderNamesTest + * + * @assertion_ids: Servlet:JAVADOC:520; Servlet:JAVADOC:522; + * Servlet:JAVADOC:523; Servlet:JAVADOC:525; Servlet:JAVADOC:526; + * Servlet:JAVADOC:527; Servlet:JAVADOC:782; + * + * @test_Strategy: Create a Servlet, wrap the servlet in another one, In the + * servlet, set multiuple header values using: #setHeader, #addHeader, + * #setDateHeader, #addDateHeader, #setIntHeader, and #addIntHeader, verify + * that getHeaderNames() works properly + */ + @Test + public void getHeaderNamesTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getHeaderNamesTest"); + invoke(); + } + + /* + * @testName: getStatusTest + * + * @assertion_ids: Servlet:JAVADOC:784; + * + * @test_Strategy: Create a Servlet, wrap the servlet in another one, In the + * servlet, set a status value; verify that getStatus() works properly + */ + @Test + public void getStatusTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getStatusTest"); + invoke(); + } + // ------------------- END HttpServletResponseWrapper + // -------------------------- +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletresponsewrapper30/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletresponsewrapper30/build.xml new file mode 100644 index 0000000000..edf9796783 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletresponsewrapper30/build.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletresponsewrapper30/servlet_pluh_HSRespWrapper30_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletresponsewrapper30/servlet_pluh_HSRespWrapper30_web-fragment.xml new file mode 100644 index 0000000000..08c0f4149b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpservletresponsewrapper30/servlet_pluh_HSRespWrapper30_web-fragment.xml @@ -0,0 +1,36 @@ + + + + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpservletresponsewrapper30.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsession/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsession/URLClient.java new file mode 100644 index 0000000000..166c0f1bdd --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsession/URLClient.java @@ -0,0 +1,385 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet_http.httpsession; + +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsession.ExpireHttpSession; +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsession.GetLastAccessedTime; +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsession.TestServlet; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_pluh_httpsession_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_pluh_httpsession_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(ExpireHttpSession.class, GetLastAccessedTime.class, TestServlet.class) + .addAsLibraries(javaArchive); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * servlet_waittime; + */ + + /* Run test */ + + /* + * @testName: getCreationTimeTest + * + * @assertion_ids: Servlet:JAVADOC:465 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void getCreationTimeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getCreationTimeTest"); + invoke(); + } + + /* + * @testName: getCreationTimeIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:466 + * + * @test_Strategy: Servlet starts session, invalidates it then calls method + */ + @Test + public void getCreationTimeIllegalStateExceptionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getCreationTimeIllegalStateExceptionTest"); + invoke(); + } + + /* + * @testName: getIdTestServlet + * + * @assertion_ids: Servlet:JAVADOC:467 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void getIdTestServlet() throws Exception { + TEST_PROPS.setProperty(APITEST, "getIdTestServlet"); + invoke(); + } + + /* + * @testName: getIdIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:467 + * + * @test_Strategy: Create a HttpSession; invalidate it; Verify that no + * IllegalStateException is thrown when getId is called. + */ + @Test + public void getIdIllegalStateExceptionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getIdIllegalStateExceptionTest"); + invoke(); + } + + /* + * @testName: getLastAccessedTimeTest + * + * @assertion_ids: Servlet:JAVADOC:469 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void getLastAccessedTimeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getLastAccessedTimeTest"); + invoke(); + } + + /* + * @testName: getLastAccessedTimeSetGetTest + * + * @assertion_ids: Servlet:JAVADOC:470 + * + * @test_Strategy: Servlet does a get/set operation + */ + @Test + public void getLastAccessedTimeSetGetTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getLastAccessedTimeSetGetTest"); + invoke(); + } + + /* + * @testName: getLastAccessedTimeIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:471 + * + * @test_Strategy: Servlet verifies exception is generated + */ + @Test + public void getLastAccessedTimeIllegalStateExceptionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getSession"); + TEST_PROPS.setProperty(SAVE_STATE, "true"); + invoke(); + TEST_PROPS.setProperty(APITEST, + "getLastAccessedTimeIllegalStateExceptionTest"); + TEST_PROPS.setProperty(USE_SAVED_STATE, "true"); + invoke(); + } + + /* + * @testName: getMaxInactiveIntervalTest + * + * @assertion_ids: Servlet:JAVADOC:474 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void getMaxInactiveIntervalTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getMaxInactiveIntervalTest"); + invoke(); + } + + /* + * @testName: getAttributeNamesTest + * + * @assertion_ids: Servlet:JAVADOC:480 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void getAttributeNamesTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getAttributeNamesTest"); + invoke(); + } + + /* + * @testName: getAttributeNamesIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:481 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void getAttributeNamesIllegalStateExceptionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, + "getAttributeNamesIllegalStateExceptionTest"); + invoke(); + } + + /* + * @testName: getAttributeTest + * + * @assertion_ids: Servlet:JAVADOC:476 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void getAttributeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getAttributeTest"); + invoke(); + } + + /* + * @testName: getAttributeIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:477 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void getAttributeIllegalStateExceptionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getAttributeIllegalStateExceptionTest"); + invoke(); + } + + /* + * @testName: getServletContextTest + * + * @assertion_ids: Servlet:JAVADOC:472 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void getServletContextTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getServletContextTest"); + invoke(); + } + + /* + * @testName: invalidateTest + * + * @assertion_ids: Servlet:JAVADOC:496 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void invalidateTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "invalidateTest"); + invoke(); + } + + /* + * @testName: invalidateIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:497 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void invalidateIllegalStateExceptionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "invalidateIllegalStateExceptionTest"); + invoke(); + } + + /* + * @testName: isNewTest + * + * @assertion_ids: Servlet:JAVADOC:498 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void isNewTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "isNewTest"); + invoke(); + } + + /* + * @testName: isNewIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:499 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void isNewIllegalStateExceptionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "isNewIllegalStateExceptionTest"); + invoke(); + } + + /* + * @testName: removeAttributeTest + * + * @assertion_ids: Servlet:JAVADOC:492 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void removeAttributeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "removeAttributeTest"); + invoke(); + } + + /* + * @testName: removeAttributeDoNothingTest + * + * @assertion_ids: Servlet:JAVADOC:491 + * + * @test_Strategy: Servlet removes non-existant attribute then tries to tries + * to get it. + */ + @Test + public void removeAttributeDoNothingTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "removeAttributeDoNothingTest"); + invoke(); + } + + /* + * @testName: removeAttributeIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:493 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void removeAttributeIllegalStateExceptionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "removeAttributeIllegalStateExceptionTest"); + invoke(); + } + + /* + * @testName: setAttributeTest + * + * @assertion_ids: Servlet:JAVADOC:484 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void setAttributeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setAttributeTest"); + invoke(); + } + + /* + * @testName: setAttributeNullTest + * + * @assertion_ids: Servlet:JAVADOC:487 + * + * @test_Strategy: Servlet passes null to setAttribute + */ + @Test + public void setAttributeNullTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setAttributeNullTest"); + invoke(); + } + + /* + * @testName: setAttributeIllegalStateExceptionTest + * + * @assertion_ids: Servlet:JAVADOC:488 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void setAttributeIllegalStateExceptionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setAttributeIllegalStateExceptionTest"); + invoke(); + } + + /* + * @testName: setMaxInactiveIntervalTest + * + * @assertion_ids: Servlet:JAVADOC:473 + * + * @test_Strategy: Servlet tests method and returns result to client + */ + @Test + public void setMaxInactiveIntervalTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setMaxInactiveIntervalTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsession/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsession/build.xml new file mode 100644 index 0000000000..ce9e2512e9 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsession/build.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsession/servlet_pluh_httpsession_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsession/servlet_pluh_httpsession_web-fragment.xml new file mode 100644 index 0000000000..ab50468458 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsession/servlet_pluh_httpsession_web-fragment.xml @@ -0,0 +1,52 @@ + + + + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsession.TestServlet + + + getLastAccessedTime + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsession.GetLastAccessedTime + + + expireHttpSession + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsession.ExpireHttpSession + + + TestServlet + /TestServlet/* + + + getLastAccessedTime + /getLastAccessedTime + + + expireHttpSession + /expireHttpSession + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionattributelistener/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionattributelistener/URLClient.java new file mode 100644 index 0000000000..f438cf0f2a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionattributelistener/URLClient.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet_http.httpsessionattributelistener; + +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionattributelistener.HSAttributeListener; +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionattributelistener.TestServlet; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_pluh_httpsessionattributelistener_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_pluh_httpsessionattributelistener_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(HSAttributeListener.class, TestServlet.class) + .addAsLibraries(javaArchive); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: attributeAddedTest + * + * @assertion_ids: Servlet:JAVADOC:460;Servlet:JAVADOC:485 + * + * @test_Strategy: Client calls a servlet that adds an attribute. The listener + * should detect the add and writes a message out to a static log. Servlet + * then reads the log and verifies the result + * + */ + @Test + public void attributeAddedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "attributeAddedTest"); + invoke(); + } + + /* + * @testName: attributeRemovedTest + * + * @assertion_ids: Servlet:JAVADOC:461;Servlet:JAVADOC:491 + * + * @test_Strategy: Client calls a servlet that adds/Removes an attribute. The + * listener should detect the changes and writes a message out to a static + * log. Servlet then reads the log and verifies the result + */ + @Test + public void attributeRemovedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "attributeRemovedTest"); + invoke(); + } + + /* + * @testName: attributeReplacedTest + * + * @assertion_ids: Servlet:JAVADOC:462 + * + * @test_Strategy: Client calls a servlet that adds/Replaces an attribute. The + * listener should detect the changes and writes a message out to a static + * log. Servlet then reads the log and verifies the result + */ + @Test + public void attributeReplacedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "attributeReplacedTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionattributelistener/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionattributelistener/build.xml new file mode 100644 index 0000000000..74bdc20d34 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionattributelistener/build.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionattributelistener/servlet_pluh_httpsessionattributelistener_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionattributelistener/servlet_pluh_httpsessionattributelistener_web-fragment.xml new file mode 100644 index 0000000000..d64bea8abd --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionattributelistener/servlet_pluh_httpsessionattributelistener_web-fragment.xml @@ -0,0 +1,39 @@ + + + + + + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionattributelistener.HSAttributeListener + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionattributelistener.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionbindingevent/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionbindingevent/URLClient.java new file mode 100644 index 0000000000..698a5001e4 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionbindingevent/URLClient.java @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet_http.httpsessionbindingevent; + +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionbindingevent.HSBindingEvent; +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionbindingevent.TestServlet; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_pluh_httpsessionbindingevent_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_pluh_httpsessionbindingevent_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(HSBindingEvent.class, TestServlet.class) + .addAsLibraries(javaArchive); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: addedTest + * + * @assertion_ids: Servlet:JAVADOC:309;Servlet:JAVADOC:307;Servlet:JAVADOC:308 + * + * @test_Strategy: Client calls a servlet that adds an attribute. The listener + * should detect the add and writes the values returned by the getName, + * getSession(), and getValue() methods to a static log. Servlet then reads + * the log and verifies the result + */ + @Test + public void addedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "addedTest"); + invoke(); + } + + /* + * @testName: removedTest + * + * @assertion_ids: Servlet:JAVADOC:310;Servlet:JAVADOC:307;Servlet:JAVADOC:308 + * + * @test_Strategy: Client calls a servlet that adds/removes an attribute. The + * listener should detect the changes and writes the values returned by the + * getName, getSession(), and getValue() methods to a static log. Servlet then + * reads the log and verifies the result + */ + @Test + public void removedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "removedTest"); + invoke(); + } + + /* + * @testName: replacedTest + * + * @assertion_ids: Servlet:JAVADOC:311;Servlet:JAVADOC:307;Servlet:JAVADOC:308 + * + * @test_Strategy: Client calls a servlet that adds/replaces an attribute. The + * listener should detect the changes and writes the values returned by the + * getName, getSession(), and getValue() methods to a static log. Servlet then + * reads the log and verifies the result + */ + @Test + public void replacedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "replacedTest"); + invoke(); + } + + /* + * @testName: constructor_StringTest + * + * @assertion_ids: Servlet:JAVADOC:305 + * + * @test_Strategy: Servlet creates an object using the 2 argument method. + */ + @Test + public void constructor_StringTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "constructor_StringTest"); + invoke(); + } + + /* + * @testName: constructor_String_ObjectTest + * + * @assertion_ids: Servlet:JAVADOC:306 + * + * @test_Strategy: Servlet creates an object using the 3 argument method. + */ + @Test + public void constructor_String_ObjectTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "constructor_String_ObjectTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionbindingevent/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionbindingevent/build.xml new file mode 100644 index 0000000000..f270126624 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionbindingevent/build.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionbindingevent/servlet_pluh_httpsessionbindingevent_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionbindingevent/servlet_pluh_httpsessionbindingevent_web-fragment.xml new file mode 100644 index 0000000000..1320493741 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionbindingevent/servlet_pluh_httpsessionbindingevent_web-fragment.xml @@ -0,0 +1,39 @@ + + + + + + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionbindingevent.HSBindingEvent + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionbindingevent.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionbindinglistener/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionbindinglistener/URLClient.java new file mode 100644 index 0000000000..f542fd6fd2 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionbindinglistener/URLClient.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet_http.httpsessionbindinglistener; + +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionbindinglistener.HSBindingListener; +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionbindinglistener.TestServlet; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_pluh_httpsessionbindinglistener_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_pluh_httpsessionbindinglistener_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(HSBindingListener.class, TestServlet.class) + .addAsLibraries(javaArchive); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: unBoundTest + * + * @assertion_ids: + * Servlet:JAVADOC:459;Servlet:JAVADOC:485;Servlet:JAVADOC:486;Servlet:JAVADOC + * :491 + * + * @test_Strategy: Client calls a servlet that sets/sets/removes an attribute + * from the session. That attribute happens to be a Binding listener. The + * Listeners valueBound/valueUnbound methods should be called and messages + * written to a static log. The servlet then reads the log and verifies the + * result. + */ + @Test + public void unBoundTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "unBoundTest"); + invoke(); + } + + /* + * @testName: boundTest + * + * @assertion_ids: Servlet:JAVADOC:458;Servlet:JAVADOC:485;Servlet:JAVADOC:486 + * + * @test_Strategy: Client calls a servlet that sets an attribute to the + * session. That attribute happens to be a Binding listener. The Listeners + * valueBound/valueUnbound methods should be called and messages written to a + * static log. The servlet then reads the log and verifies the result. + */ + @Test + public void boundTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "boundTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionbindinglistener/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionbindinglistener/build.xml new file mode 100644 index 0000000000..3a035ab190 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionbindinglistener/build.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionbindinglistener/servlet_pluh_httpsessionbindinglistener_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionbindinglistener/servlet_pluh_httpsessionbindinglistener_web-fragment.xml new file mode 100644 index 0000000000..43ce890073 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionbindinglistener/servlet_pluh_httpsessionbindinglistener_web-fragment.xml @@ -0,0 +1,36 @@ + + + + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionbindinglistener.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionevent/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionevent/URLClient.java new file mode 100644 index 0000000000..2c20d9a540 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionevent/URLClient.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet_http.httpsessionevent; + +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionevent.HSEvent; +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionevent.TestServlet; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_pluh_httpsessionevent_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_pluh_httpsessionevent_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(HSEvent.class, TestServlet.class) + .addAsLibraries(javaArchive); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + /* + * @testName: getSessionTest + * + * @assertion_ids: Servlet:JAVADOC:304 + * + * @test_Strategy: Client calls a servlet that creates a session. The listener + * writes the sessionid of the event to a static log. The Servlet then reads + * the log and verifies the result + */ + @Test + public void getSessionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getSessionTest"); + invoke(); + } + + /* + * @testName: constructorTest + * + * @assertion_ids: Servlet:JAVADOC:303 + * + * @test_Strategy: servlet calls the constructor + */ + @Test + public void constructorTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "constructorTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionevent/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionevent/build.xml new file mode 100644 index 0000000000..817d11a988 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionevent/build.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionevent/servlet_pluh_httpsessionevent_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionevent/servlet_pluh_httpsessionevent_web-fragment.xml new file mode 100644 index 0000000000..b999309577 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionevent/servlet_pluh_httpsessionevent_web-fragment.xml @@ -0,0 +1,39 @@ + + + + + + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionevent.HSEvent + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionevent.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionlistener/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionlistener/URLClient.java new file mode 100644 index 0000000000..f9b4814301 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionlistener/URLClient.java @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet_http.httpsessionlistener; + +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionlistener.HSListener; +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionlistener.TestServlet; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_pluh_httpsessionlistener_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_pluh_httpsessionlistener_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(HSListener.class, TestServlet.class) + .addAsLibraries(javaArchive); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: createdTest + * + * @assertion_ids: Servlet:JAVADOC:454 + * + * @test_Strategy: Client calls a servlet that creates a session. The listener + * should detect the creation and write a message to a static log. The Servlet + * then reads the log and verifies the result. As a result of the test, the + * jakarta.servlet.http.Event.getSession() method is tested. + * + */ + @Test + public void createdTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "createdTest"); + invoke(); + } + + /* + * @testName: destroyedTest + * + * @assertion_ids: Servlet:JAVADOC:455 + * + * @test_Strategy: Client calls a servlet that creates and the invalidates a + * session. The listener should detect the changes and write a message to a + * static log. The Servlet then reads the log file and verifies the result. As + * a result of the test, the jakarta.servlet.http.Event.getSession() method is + * tested. + */ + @Test + public void destroyedTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "destroyedTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionlistener/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionlistener/build.xml new file mode 100644 index 0000000000..489e399ba2 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionlistener/build.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionlistener/servlet_pluh_httpsessionlistener_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionlistener/servlet_pluh_httpsessionlistener_web-fragment.xml new file mode 100644 index 0000000000..c6dfdd69b7 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/httpsessionlistener/servlet_pluh_httpsessionlistener_web-fragment.xml @@ -0,0 +1,39 @@ + + + + + + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionlistener.HSListener + + + TestServlet + com.sun.ts.tests.servlet.api.jakarta_servlet_http.httpsessionlistener.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/sessioncookieconfig/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/sessioncookieconfig/URLClient.java new file mode 100644 index 0000000000..09c3f37fe4 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/sessioncookieconfig/URLClient.java @@ -0,0 +1,208 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.pluggability.api.jakarta_servlet_http.sessioncookieconfig; + +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.sessioncookieconfig.TestListener; +import com.sun.ts.tests.servlet.api.jakarta_servlet_http.sessioncookieconfig.TestServlet; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.pluggability.common.RequestListener1; +import com.sun.ts.tests.servlet.pluggability.common.TestServlet1; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + JavaArchive javaArchive = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource(URLClient.class.getResource("servlet_pluh_sessioncookieconfig_web-fragment.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_pluh_sessioncookieconfig_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestListener.class, TestServlet.class) + .addAsLibraries(javaArchive); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: constructortest1 + * + * @assertion_ids: Servlet:JAVADOC:693; Servlet:JAVADOC:733; + * Servlet:JAVADOC:734; Servlet:JAVADOC:735; Servlet:JAVADOC:736; + * Servlet:JAVADOC:737; Servlet:JAVADOC:738; Servlet:JAVADOC:739; + * Servlet:JAVADOC:740; Servlet:JAVADOC:741; Servlet:JAVADOC:742; + * Servlet:JAVADOC:743; Servlet:JAVADOC:744; Servlet:JAVADOC:745; + * Servlet:JAVADOC:746; + * + * @test_Strategy: Create a Servlet TestServlet, with a + * ServletContextListener; In the Servlet, turn HttpSession on; In + * ServletContextListener, create a SessionCookieConfig instance, Verify in + * Client that the SessionCookieConfig instance is created, and all + * SessionCookieConfig APIs work accordingly. + */ + @Test + public void constructortest1() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/TestServlet?testname=constructortest1 HTTP/1.1"); + TEST_PROPS.setProperty(EXPECTED_HEADERS, + "Set-Cookie:" + "TCK_Cookie_Name=" + "##Expires=" + + "##Path=" + getContextRoot() + "/TestServlet" + + "##Secure"); + invoke(); + } + + /* + * @testName: setNameTest + * + * @assertion_ids: Servlet:JAVADOC:744; + * + * @test_Strategy: Create a Servlet TestServlet, In the Servlet, turn + * HttpSession on; Verify in servlet SessionCookieConfig.setName cannot be + * called once is set. + */ + @Test + public void setNameTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setNameTest"); + invoke(); + } + + /* + * @testName: setCommentTest + * + * @assertion_ids: Servlet:JAVADOC:740; + * + * @test_Strategy: Create a Servlet TestServlet, In the Servlet, turn + * HttpSession on; Verify in servlet SessionCookieConfig.setComment cannot be + * called once is set. + */ + @Test + public void setCommentTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setCommentTest"); + invoke(); + } + + /* + * @testName: setPathTest + * + * @assertion_ids: Servlet:JAVADOC:745; + * + * @test_Strategy: Create a Servlet TestServlet, In the Servlet, turn + * HttpSession on; Verify in servlet SessionCookieConfig.setPath cannot be + * called once is set. + */ + @Test + public void setPathTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setPathTest"); + invoke(); + } + + /* + * @testName: setDomainTest + * + * @assertion_ids: Servlet:JAVADOC:741; + * + * @test_Strategy: Create a Servlet TestServlet, In the Servlet, turn + * HttpSession on; Verify in servlet SessionCookieConfig.setDomain cannot be + * called once is set. + */ + @Test + public void setDomainTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setDomainTest"); + invoke(); + } + + /* + * @testName: setMaxAgeTest + * + * @assertion_ids: Servlet:JAVADOC:743; + * + * @test_Strategy: Create a Servlet TestServlet, In the Servlet, turn + * HttpSession on; Verify in servlet SessionCookieConfig.setMaxAge cannot be + * called once is set. + */ + @Test + public void setMaxAgeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setMaxAgeTest"); + invoke(); + } + + /* + * @testName: setHttpOnlyTest + * + * @assertion_ids: Servlet:JAVADOC:742; + * + * @test_Strategy: Create a Servlet TestServlet, In the Servlet, turn + * HttpSession on; Verify in servlet SessionCookieConfig.setHttpOnly cannot be + * called once is set. + */ + @Test + public void setHttpOnlyTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setHttpOnlyTest"); + invoke(); + } + + /* + * @testName: setSecureTest + * + * @assertion_ids: Servlet:JAVADOC:746; + * + * @test_Strategy: Create a Servlet TestServlet, In the Servlet, turn + * HttpSession on; Verify in servlet SessionCookieConfig.setSecure cannot be + * called once is set. + */ + @Test + public void setSecureTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setSecureTest"); + invoke(); + } + + /* + * @testName: setAttributeTest + * + * @assertion_ids: + * + * @test_Strategy: Create a Servlet TestServlet, In the Servlet, turn + * HttpSession on; Verify in servlet SessionCookieConfig.setAttribute cannot be + * called once is set. + */ + @Test + public void setAttributeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "setAttributeTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/sessioncookieconfig/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/sessioncookieconfig/build.xml new file mode 100644 index 0000000000..1502fe3dc4 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/sessioncookieconfig/build.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/sessioncookieconfig/servlet_pluh_sessioncookieconfig_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/sessioncookieconfig/servlet_pluh_sessioncookieconfig_web-fragment.xml new file mode 100644 index 0000000000..09059ee870 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/api/jakarta_servlet_http/sessioncookieconfig/servlet_pluh_sessioncookieconfig_web-fragment.xml @@ -0,0 +1,39 @@ + + + + + + com.sun.ts.tests.servlet.api.jakarta_servlet_http.sessioncookieconfig.TestListener + + + TestLogicalName + com.sun.ts.tests.servlet.api.jakarta_servlet_http.sessioncookieconfig.TestServlet + + + TestLogicalName + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/build.xml new file mode 100644 index 0000000000..280c015b3b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/build.xml @@ -0,0 +1,22 @@ + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/CommonArchives.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/CommonArchives.java new file mode 100644 index 0000000000..fe1cf21b37 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/CommonArchives.java @@ -0,0 +1,39 @@ +package com.sun.ts.tests.servlet.pluggability.common; + +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; + +import java.util.Arrays; +import java.util.List; + +public class CommonArchives { + private CommonArchives() { + // nothing + } + + public static List getCommonWebFragmentArchives() { + JavaArchive javaArchive1 = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, RequestListener1.class) + .addAsResource("com/sun/ts/tests/servlet/pluggability/common/web-fragment_1.xml", + "META-INF/web-fragment.xml"); + JavaArchive javaArchive2 = ShrinkWrap.create(JavaArchive.class, "fragment-2.jar") + .addClasses(RequestListener2.class) + .addAsResource("com/sun/ts/tests/servlet/pluggability/common/web-fragment_2.xml", + "META-INF/web-fragment.xml"); + JavaArchive javaArchive3 = ShrinkWrap.create(JavaArchive.class, "fragment-3.jar") + .addClasses(RequestListener3.class) + .addAsResource("com/sun/ts/tests/servlet/pluggability/common/web-fragment_3.xml", + "META-INF/web-fragment.xml"); + JavaArchive javaArchive4 = ShrinkWrap.create(JavaArchive.class, "fragment-4.jar") + .addClasses(RequestListener4.class) + .addAsResource("com/sun/ts/tests/servlet/pluggability/common/web-fragment_4.xml", + "META-INF/web-fragment.xml"); + JavaArchive javaArchive5 = ShrinkWrap.create(JavaArchive.class, "fragment-5.jar") + .addClasses(RequestListener5.class) + .addAsResource("com/sun/ts/tests/servlet/pluggability/common/web-fragment_5.xml", + "META-INF/web-fragment.xml"); + + return Arrays.asList(javaArchive1, javaArchive2, javaArchive3, javaArchive4, javaArchive5); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/RequestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/RequestListener.java new file mode 100644 index 0000000000..29c7db421c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/RequestListener.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2009, 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$ + */ +package com.sun.ts.tests.servlet.pluggability.common; + +import java.util.ArrayList; + +import jakarta.servlet.ServletRequestEvent; +import jakarta.servlet.ServletRequestListener; + +public final class RequestListener implements ServletRequestListener { + + public void requestDestroyed(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("testmessage"); + if (al != null) { + al.add("RequestListener requestDestroyed"); + event.getServletContext().setAttribute("testmessage", al); + } + } + + public void requestInitialized(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("testmessage"); + if (al == null) { + al = new ArrayList(); + } + al.add("RequestListener requestInitialized"); + event.getServletContext().setAttribute("testmessage", al); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/RequestListener1.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/RequestListener1.java new file mode 100644 index 0000000000..0a7392e862 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/RequestListener1.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2009, 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$ + */ +package com.sun.ts.tests.servlet.pluggability.common; + +import java.util.ArrayList; + +import jakarta.servlet.ServletRequestEvent; +import jakarta.servlet.ServletRequestListener; + +public final class RequestListener1 implements ServletRequestListener { + + public void requestDestroyed(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("testmessage"); + if (al != null) { + al.add("RequestListener1 requestDestroyed"); + event.getServletContext().setAttribute("testmessage", al); + } + } + + public void requestInitialized(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("testmessage"); + if (al == null) { + al = new ArrayList(); + } + al.add("RequestListener1 requestInitialized"); + event.getServletContext().setAttribute("testmessage", al); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/RequestListener2.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/RequestListener2.java new file mode 100644 index 0000000000..76e56346de --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/RequestListener2.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2009, 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$ + */ +package com.sun.ts.tests.servlet.pluggability.common; + +import java.util.ArrayList; + +import jakarta.servlet.ServletRequestEvent; +import jakarta.servlet.ServletRequestListener; + +public final class RequestListener2 implements ServletRequestListener { + + public void requestDestroyed(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("testmessage"); + if (al != null) { + al.add("RequestListener2 requestDestroyed"); + event.getServletContext().setAttribute("testmessage", al); + } + } + + public void requestInitialized(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("testmessage"); + if (al == null) { + al = new ArrayList(); + } + al.add("RequestListener2 requestInitialized"); + event.getServletContext().setAttribute("testmessage", al); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/RequestListener3.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/RequestListener3.java new file mode 100644 index 0000000000..56e885ebbf --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/RequestListener3.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2009, 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$ + */ +package com.sun.ts.tests.servlet.pluggability.common; + +import java.util.ArrayList; + +import jakarta.servlet.ServletRequestEvent; +import jakarta.servlet.ServletRequestListener; + +public final class RequestListener3 implements ServletRequestListener { + + public void requestDestroyed(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("testmessage"); + if (al != null) { + al.add("RequestListener3 requestDestroyed"); + event.getServletContext().setAttribute("testmessage", al); + } + } + + public void requestInitialized(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("testmessage"); + if (al == null) { + al = new ArrayList(); + } + al.add("RequestListener3 requestInitialized"); + event.getServletContext().setAttribute("testmessage", al); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/RequestListener4.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/RequestListener4.java new file mode 100644 index 0000000000..2561d1b492 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/RequestListener4.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2009, 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$ + */ +package com.sun.ts.tests.servlet.pluggability.common; + +import java.util.ArrayList; + +import jakarta.servlet.ServletRequestEvent; +import jakarta.servlet.ServletRequestListener; + +public final class RequestListener4 implements ServletRequestListener { + + public void requestDestroyed(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("testmessage"); + if (al != null) { + al.add("RequestListener4 requestDestroyed"); + event.getServletContext().setAttribute("testmessage", al); + } + } + + public void requestInitialized(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("testmessage"); + if (al == null) { + al = new ArrayList(); + } + al.add("RequestListener4 requestInitialized"); + event.getServletContext().setAttribute("testmessage", al); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/RequestListener5.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/RequestListener5.java new file mode 100644 index 0000000000..dd2264dce1 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/RequestListener5.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2009, 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$ + */ +package com.sun.ts.tests.servlet.pluggability.common; + +import java.util.ArrayList; + +import jakarta.servlet.ServletRequestEvent; +import jakarta.servlet.ServletRequestListener; + +public final class RequestListener5 implements ServletRequestListener { + + public void requestDestroyed(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("testmessage"); + if (al != null) { + al.add("RequestListener5 requestDestroyed"); + event.getServletContext().setAttribute("testmessage", al); + } + } + + public void requestInitialized(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("testmessage"); + if (al == null) { + al = new ArrayList(); + } + al.add("RequestListener5 requestInitialized"); + event.getServletContext().setAttribute("testmessage", al); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/RequestListener6.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/RequestListener6.java new file mode 100644 index 0000000000..ac36ab50b5 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/RequestListener6.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.pluggability.common; + +import java.util.ArrayList; + +import jakarta.servlet.ServletRequestEvent; +import jakarta.servlet.ServletRequestListener; + +public final class RequestListener6 implements ServletRequestListener { + + public void requestDestroyed(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("testmessage"); + if (al != null) { + al.add("RequestListener6 requestDestroyed"); + event.getServletContext().setAttribute("testmessage", al); + } + } + + public void requestInitialized(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("testmessage"); + if (al == null) { + al = new ArrayList(); + } + al.add("RequestListener6 requestInitialized"); + event.getServletContext().setAttribute("testmessage", al); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/RequestListener7.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/RequestListener7.java new file mode 100644 index 0000000000..fb39395a76 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/RequestListener7.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.pluggability.common; + +import java.util.ArrayList; + +import jakarta.servlet.ServletRequestEvent; +import jakarta.servlet.ServletRequestListener; +import jakarta.servlet.annotation.WebListener; + +@WebListener() +public final class RequestListener7 implements ServletRequestListener { + + public void requestDestroyed(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("testmessage"); + if (al != null) { + al.add("RequestListener7 requestDestroyed"); + event.getServletContext().setAttribute("testmessage", al); + } + } + + public void requestInitialized(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("testmessage"); + if (al == null) { + al = new ArrayList(); + } + al.add("RequestListener7 requestInitialized"); + event.getServletContext().setAttribute("testmessage", al); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/TestServlet1.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/TestServlet1.java new file mode 100644 index 0000000000..844a911548 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/TestServlet1.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2009, 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$ + */ + +package com.sun.ts.tests.servlet.pluggability.common; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet1 extends GenericServlet { + + @Override + public void init(ServletConfig config) throws ServletException { + super.init(config); + } + + @Override + public void init() throws ServletException { + super.init(); + } + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println("TestServlet1 is invoked"); + pw.append("msg1=" + getInitParameter("msg1")); + pw.append("msg2=" + getInitParameter("msg2")); + + ArrayList result = (ArrayList) getServletContext() + .getAttribute("testmessage"); + + Object results[] = result.toArray(); + for (int i = 0; i < results.length; i++) { + pw.println(results[i].toString()); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/TestServlet2.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/TestServlet2.java new file mode 100644 index 0000000000..ddcfb75a61 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/TestServlet2.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2012, 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$ + */ + +package com.sun.ts.tests.servlet.pluggability.common; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet2 extends GenericServlet { + + @Override + public void init(ServletConfig config) throws ServletException { + super.init(config); + } + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println("TestServlet2 is invoked"); + pw.append("msg1=" + getInitParameter("msg1")); + pw.append("msg2=" + getInitParameter("msg2")); + + ArrayList result = (ArrayList) getServletContext() + .getAttribute("testmessage"); + + Object results[] = result.toArray(); + for (int i = 0; i < results.length; i++) { + pw.println(results[i].toString()); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/TestServlet3.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/TestServlet3.java new file mode 100644 index 0000000000..2b5929fb8e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/TestServlet3.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2012, 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$ + */ + +package com.sun.ts.tests.servlet.pluggability.common; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.annotation.WebServlet; + +@WebServlet("/TestServlet3") +public class TestServlet3 extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println("TestServlet3 is invoked"); + pw.append("msg1=" + getInitParameter("msg1")); + pw.append("msg2=" + getInitParameter("msg2")); + + ArrayList result = (ArrayList) getServletContext() + .getAttribute("testmessage"); + + Object results[] = result.toArray(); + for (int i = 0; i < results.length; i++) { + pw.println(results[i].toString()); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/TestServlet4.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/TestServlet4.java new file mode 100644 index 0000000000..ec258eadc1 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/TestServlet4.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.pluggability.common; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet4 extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println("TestServlet4 is invoked"); + pw.append("msg1=" + getInitParameter("msg1")); + pw.append("msg2=" + getInitParameter("msg2")); + pw.append("msg3=" + getInitParameter("msg3")); + pw.append("msg4=" + getInitParameter("msg4")); + + ArrayList result = (ArrayList) getServletContext() + .getAttribute("testmessage"); + + Object results[] = result.toArray(); + for (int i = 0; i < results.length; i++) { + pw.println(results[i].toString()); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/web-fragment_1.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/web-fragment_1.xml new file mode 100644 index 0000000000..db19fd206a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/web-fragment_1.xml @@ -0,0 +1,44 @@ + + + + + Fragment1 + + TestServlet1 + com.sun.ts.tests.servlet.pluggability.common.TestServlet1 + + msg1 + second + + + msg2 + second + + + + TestServlet1 + /TestServlet1 + + + com.sun.ts.tests.servlet.pluggability.common.RequestListener1 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/web-fragment_2.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/web-fragment_2.xml new file mode 100644 index 0000000000..fe8304d98f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/web-fragment_2.xml @@ -0,0 +1,29 @@ + + + + + Fragment2 + + com.sun.ts.tests.servlet.pluggability.common.RequestListener2 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/web-fragment_3.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/web-fragment_3.xml new file mode 100644 index 0000000000..0ca5599be1 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/web-fragment_3.xml @@ -0,0 +1,29 @@ + + + + + Fragment3 + + com.sun.ts.tests.servlet.pluggability.common.RequestListener3 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/web-fragment_4.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/web-fragment_4.xml new file mode 100644 index 0000000000..f0eb13ddb1 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/web-fragment_4.xml @@ -0,0 +1,29 @@ + + + + + Fragment4 + + com.sun.ts.tests.servlet.pluggability.common.RequestListener4 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/web-fragment_5.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/web-fragment_5.xml new file mode 100644 index 0000000000..00a00effd8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/web-fragment_5.xml @@ -0,0 +1,29 @@ + + + + + Fragment5 + + com.sun.ts.tests.servlet.pluggability.common.RequestListener5 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/web-fragment_6.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/web-fragment_6.xml new file mode 100644 index 0000000000..daf5b1cf73 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/web-fragment_6.xml @@ -0,0 +1,44 @@ + + + + + + TestServlet2 + com.sun.ts.tests.servlet.pluggability.common.TestServlet2 + + msg1 + second + + + msg1 + ignore + + + + TestServlet2 + /TestServlet2 + + + com.sun.ts.tests.servlet.pluggability.common.RequestListener6 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/web-fragment_7.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/web-fragment_7.xml new file mode 100644 index 0000000000..cd0a41dea1 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/common/web-fragment_7.xml @@ -0,0 +1,33 @@ + + + + + + TestServlet2 + com.sun.ts.tests.servlet.pluggability.common.TestServlet2 + + msg3 + third + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/TestFilter.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/TestFilter.java new file mode 100644 index 0000000000..3d829481f8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/TestFilter.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2009, 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$ + */ +package com.sun.ts.tests.servlet.pluggability.fragment; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Enumeration; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public final class TestFilter implements Filter { + + private FilterConfig filterConfig = null; + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + PrintWriter pw = response.getWriter(); + + pw.println("doFilter in TestFilter invoked"); + + if (filterConfig == null) { + pw.println("filter instance is null "); + } else { + Enumeration initP = filterConfig.getInitParameterNames(); + int expectedCount = 2; + int count = 0; + + if (initP.hasMoreElements()) { + while (initP.hasMoreElements()) { + String result = (String) initP.nextElement(); + pw.println("parameter name= " + result); + pw.println( + "parameter value= " + filterConfig.getInitParameter(result)); + } + } + chain.doFilter(request, response); + } + } + + public void destroy() { + } + + public void init(FilterConfig filterConfig) { + this.filterConfig = filterConfig; + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/TestFilter1.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/TestFilter1.java new file mode 100644 index 0000000000..41451f6c74 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/TestFilter1.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2009, 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$ + */ +package com.sun.ts.tests.servlet.pluggability.fragment; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Enumeration; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public final class TestFilter1 implements Filter { + + private FilterConfig filterConfig = null; + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + PrintWriter pw = response.getWriter(); + + pw.println("doFilter in TestFilter1 invoked"); + + if (filterConfig == null) { + pw.println("filter instance is null "); + } else { + Enumeration initP = filterConfig.getInitParameterNames(); + int expectedCount = 2; + int count = 0; + + if (initP.hasMoreElements()) { + while (initP.hasMoreElements()) { + String result = (String) initP.nextElement(); + pw.println("parameter name= " + result); + pw.println( + "parameter value= " + filterConfig.getInitParameter(result)); + } + } + chain.doFilter(request, response); + } + } + + public void destroy() { + } + + public void init(FilterConfig filterConfig) { + this.filterConfig = filterConfig; + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/TestFilter2.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/TestFilter2.java new file mode 100644 index 0000000000..0af8c6ac20 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/TestFilter2.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2009, 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$ + */ +package com.sun.ts.tests.servlet.pluggability.fragment; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Enumeration; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public final class TestFilter2 implements Filter { + + private FilterConfig filterConfig = null; + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + PrintWriter pw = response.getWriter(); + + pw.println("doFilter in TestFilter2 invoked"); + + if (filterConfig == null) { + pw.println("instance is null"); + } else { + Enumeration initP = filterConfig.getInitParameterNames(); + int expectedCount = 2; + int count = 0; + + if (initP.hasMoreElements()) { + while (initP.hasMoreElements()) { + String result = (String) initP.nextElement(); + pw.println("parameter name= " + result); + pw.println( + "parameter value= " + filterConfig.getInitParameter(result)); + } + } + chain.doFilter(request, response); + } + } + + public void destroy() { + } + + public void init(FilterConfig filterConfig) { + this.filterConfig = filterConfig; + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/TestFilter3.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/TestFilter3.java new file mode 100644 index 0000000000..cf688572a9 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/TestFilter3.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2009, 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$ + */ +package com.sun.ts.tests.servlet.pluggability.fragment; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Enumeration; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public final class TestFilter3 implements Filter { + + private FilterConfig filterConfig = null; + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + PrintWriter pw = response.getWriter(); + + pw.println("doFilter in TestFilter3 invoked"); + + if (filterConfig == null) { + pw.println("filter instance is null "); + } else { + Enumeration initP = filterConfig.getInitParameterNames(); + int expectedCount = 2; + int count = 0; + + if (initP.hasMoreElements()) { + while (initP.hasMoreElements()) { + String result = (String) initP.nextElement(); + pw.println("parameter name= " + result); + pw.println( + "parameter value= " + filterConfig.getInitParameter(result)); + } + } + chain.doFilter(request, response); + } + } + + public void destroy() { + } + + public void init(FilterConfig filterConfig) { + this.filterConfig = filterConfig; + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/TestServlet1.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/TestServlet1.java new file mode 100644 index 0000000000..c7ccb834d7 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/TestServlet1.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2009, 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$ + */ + +package com.sun.ts.tests.servlet.pluggability.fragment; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet1 extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println("TestServlet1 is invoked"); + pw.append("msg1=" + getInitParameter("msg1")); + pw.append("msg2=" + getInitParameter("msg2")); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/TestServlet2.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/TestServlet2.java new file mode 100644 index 0000000000..99fe630b09 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/TestServlet2.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2009, 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$ + */ + +package com.sun.ts.tests.servlet.pluggability.fragment; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet2 extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println("TestServlet2 is invoked"); + pw.append("msg1=" + getInitParameter("msg1")); + pw.append("msg2=" + getInitParameter("msg2")); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/TestServlet3.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/TestServlet3.java new file mode 100644 index 0000000000..418c8370c9 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/TestServlet3.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2009, 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$ + */ +package com.sun.ts.tests.servlet.pluggability.fragment; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet3 extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println("TestServlet3 is invoked"); + pw.append("msg1=" + getInitParameter("msg1")); + pw.append("msg2=" + getInitParameter("msg2")); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/TestServlet4.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/TestServlet4.java new file mode 100644 index 0000000000..1c8fb0545b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/TestServlet4.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2009, 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$ + */ + +package com.sun.ts.tests.servlet.pluggability.fragment; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet4 extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println("TestServlet4 is invoked"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/TestServlet5.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/TestServlet5.java new file mode 100644 index 0000000000..9cf223376b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/TestServlet5.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2009, 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$ + */ + +package com.sun.ts.tests.servlet.pluggability.fragment; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet5 extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println("TestServlet5 is invoked"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/URLClient.java new file mode 100644 index 0000000000..a0ee6c677e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/URLClient.java @@ -0,0 +1,176 @@ +/* + * Copyright (c) 2009, 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$ + */ +package com.sun.ts.tests.servlet.pluggability.fragment; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setContextRoot("/servlet_spec_fragment_web"); + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + + JavaArchive javaArchive1 = ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(TestServlet1.class, TestServlet2.class, TestFilter.class) + .addAsResource(URLClient.class.getResource("servlet_spec_fragment_web-fragment.xml"), + "META-INF/web-fragment.xml"); + JavaArchive javaArchive2 = ShrinkWrap.create(JavaArchive.class, "fragment-2.jar") + .addClasses(TestServlet3.class, TestFilter1.class) + .addAsResource(URLClient.class.getResource("servlet_spec_fragment_web-fragment_1.xml"), + "META-INF/web-fragment.xml"); + JavaArchive javaArchive3 = ShrinkWrap.create(JavaArchive.class, "fragment-3.jar") + .addClasses(TestServlet4.class, TestFilter2.class) + .addAsResource(URLClient.class.getResource("servlet_spec_fragment_web-fragment_2.xml"), + "META-INF/web-fragment.xml"); + JavaArchive javaArchive4 = ShrinkWrap.create(JavaArchive.class, "fragment-4.jar") + .addClasses(TestServlet5.class, TestFilter3.class) + .addAsResource(URLClient.class.getResource("servlet_spec_fragment_web-fragment_3.xml"), + "META-INF/web-fragment.xml"); + return ShrinkWrap.create(WebArchive.class, "servlet_spec_fragment_web.war") + .addAsLibraries(javaArchive1, javaArchive2, javaArchive3, javaArchive4) + .addClasses(TestFilter.class, TestServlet1.class, TestServlet2.class) + .setWebXML(URLClient.class.getResource("servlet_spec_fragment_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* + * @testName: initParamTest + * + * @assertion_ids: Servlet:SPEC:232; Servlet:SPEC:258.1; Servlet:SPEC:258.5.1; + * Servlet:SPEC:258.6.1; Servlet:SPEC:258.7.1; + * + * @test_Strategy: 1. Define servlet TestServlet1 in web.xml as well as + * web-fragment.xml; 2. Send request to /TestServlet1, verify TestServlet1 is + * invoked 3. Also verify that defined in both web.xml and + * web-fragment.xml are considered, and the one defined in web.xml take + * precedence. + */ + @Test + public void initParamTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, + "TestServlet1|msg1=first|msg2=second"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "ignore"); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/TestServlet1" + " HTTP/1.1"); + invoke(); + } + + /* + * @testName: addServletTest + * + * @assertion_ids: Servlet:SPEC:232; Servlet:SPEC:258.1; Servlet:SPEC:258.5.1; + * + * @test_Strategy: 1. Define servlet TestServlet3 web-fragment.xml; 2. Send + * request to /TestServlet3, verify TestServlet3 is invoked 3. Also verify + * that filter is invoked too. + */ + @Test + public void addServletTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, + "TestFilter3|fragment|three|TestServlet3|msg1=third|msg2=third"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "ignore"); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/TestServlet3" + " HTTP/1.1"); + invoke(); + } + + /* + * @testName: addServletURLTest + * + * @assertion_ids: Servlet:SPEC:232; Servlet:SPEC:258.1; Servlet:SPEC:258.5.1; + * Servlet:SPEC:258.6.1; Servlet:SPEC:258.7.6; + * + * @test_Strategy: 1. Define servlet TestServlet2 web-fragment.xml and + * web.xml; 2. Send request to URL /TestServlet2 defined in web.xml, verify + * TestServlet2 is invoked 3. Send request to URL /TestServlet22 defined in + * web-fragment.xml, verify 404 is returned. + */ + @Test + public void addServletURLTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "TestServlet2"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "ignore"); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/TestServlet2" + " HTTP/1.1"); + invoke(); + + TEST_PROPS.setProperty(STATUS_CODE, NOT_FOUND); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/TestServlet22" + " HTTP/1.1"); + invoke(); + } + + /* + * @testName: welcomefileTest + * + * @assertion_ids: Servlet:SPEC:232; Servlet:SPEC:258.1; Servlet:SPEC:258.5.1; + * Servlet:SPEC:258.6.1; Servlet:SPEC:258.7.5; + * + * @test_Strategy: 1. Define servlet TestServlet4 web-fragment.xml in + * ; 2. Send request to URL /, verify TestServlet4 is invoked + */ + @Test + public void welcomefileTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "TestServlet4"); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + " HTTP/1.1"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "ignore"); + invoke(); + } + + /* + * @testName: filterOrderingTest + * + * @assertion_ids: Servlet:SPEC:232; Servlet:SPEC:241; Servlet:SPEC:242; + * Servlet:SPEC:244; Servlet:SPEC:245; Servlet:SPEC:246; Servlet:SPEC:258.1; + * Servlet:SPEC:258.5.1; Servlet:SPEC:258.6.1; + * + * @test_Strategy: 1. Define four Filters that mapping to TestServlet5 in + * web.xml and two web-fragment.xml; 2. Send request to TestServlet5 3. Verify + * that web.xml is always processed first; 4. Verify that works + * accordingly. + */ + @Test + public void filterOrderingTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, + "TestFilter|fragment|none|" + "TestFilter3|fragment|three|" + + "TestFilter2|fragment|two|" + + "TestFilter1|fragment|one|TestServlet5"); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/TestServlet5" + " HTTP/1.1"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "ignore"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/build.xml new file mode 100644 index 0000000000..4d147ccc04 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/build.xml @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/servlet_spec_fragment_web-fragment.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/servlet_spec_fragment_web-fragment.xml new file mode 100644 index 0000000000..046a573936 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/servlet_spec_fragment_web-fragment.xml @@ -0,0 +1,58 @@ + + + + + Fragment + + TestFilter3 + TestServlet3 + + + TestServlet1 + com.sun.ts.tests.servlet.pluggability.fragment.TestServlet1 + + msg1 + ignore + + + msg2 + second + + + msg2 + ignore + + + + TestServlet2 + com.sun.ts.tests.servlet.pluggability.fragment.TestServlet2 + + msg1 + second + + + + TestServlet2 + /TestServlet22 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/servlet_spec_fragment_web-fragment_1.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/servlet_spec_fragment_web-fragment_1.xml new file mode 100644 index 0000000000..d2f9631b39 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/servlet_spec_fragment_web-fragment_1.xml @@ -0,0 +1,59 @@ + + + + + Fragment1 + + + Fragment2 + + + + TestFilter1 + com.sun.ts.tests.servlet.pluggability.fragment.TestFilter1 + + fragment + one + + + + TestFilter1 + TestServlet5 + + + TestServlet3 + com.sun.ts.tests.servlet.pluggability.fragment.TestServlet3 + + msg1 + third + + + msg2 + third + + + + TestServlet3 + /TestServlet3 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/servlet_spec_fragment_web-fragment_2.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/servlet_spec_fragment_web-fragment_2.xml new file mode 100644 index 0000000000..1023a1a577 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/servlet_spec_fragment_web-fragment_2.xml @@ -0,0 +1,49 @@ + + + + + Fragment2 + + TestFilter2 + com.sun.ts.tests.servlet.pluggability.fragment.TestFilter2 + + fragment + two + + + + TestFilter2 + TestServlet5 + + + TestServlet4 + com.sun.ts.tests.servlet.pluggability.fragment.TestServlet4 + + + TestServlet4 + /TestServlet4 + + + TestServlet4 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/servlet_spec_fragment_web-fragment_3.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/servlet_spec_fragment_web-fragment_3.xml new file mode 100644 index 0000000000..5717d59b21 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/servlet_spec_fragment_web-fragment_3.xml @@ -0,0 +1,51 @@ + + + + + Fragment3 + + + + + + + TestFilter3 + com.sun.ts.tests.servlet.pluggability.fragment.TestFilter3 + + fragment + three + + + + TestFilter3 + TestServlet5 + + + TestServlet5 + com.sun.ts.tests.servlet.pluggability.fragment.TestServlet5 + + + TestServlet5 + /TestServlet5 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/servlet_spec_fragment_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/servlet_spec_fragment_web.xml new file mode 100644 index 0000000000..1e1367412a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/pluggability/fragment/servlet_spec_fragment_web.xml @@ -0,0 +1,68 @@ + + + + + SerSpecFragment + + TestFilter + com.sun.ts.tests.servlet.pluggability.fragment.TestFilter + + fragment + none + + + + TestFilter + TestServlet5 + + + TestServlet1 + com.sun.ts.tests.servlet.pluggability.fragment.TestServlet1 + + msg1 + first + + + msg1 + ignore + + + + TestServlet2 + com.sun.ts.tests.servlet.pluggability.fragment.TestServlet2 + + msg1 + second + + + + TestServlet1 + /TestServlet1 + + + TestServlet2 + /TestServlet2 + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/build.xml new file mode 100644 index 0000000000..af8a20cb18 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/build.xml @@ -0,0 +1,22 @@ + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webfilter/Servlet1.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webfilter/Servlet1.java new file mode 100644 index 0000000000..7286936e1b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webfilter/Servlet1.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2009, 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:$ + */ +package com.sun.ts.tests.servlet.spec.annotationservlet.webfilter; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +@WebServlet(value = "/Servlet1", name = "servlet1") +public class Servlet1 extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + ArrayList result = StaticLog.getClear(); + if (result != null) { + for (Object tmp : result) { + if (tmp != null) { + pw.println(tmp.toString()); + System.out.println(tmp.toString()); + } + } + } + StaticLog.clear(); + + pw.write("Servlet1_INVOKED"); + ServletTestUtil.printResult(pw, true); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webfilter/TestFilter1.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webfilter/TestFilter1.java new file mode 100644 index 0000000000..e1c09f3530 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webfilter/TestFilter1.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2009, 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$ + */ +package com.sun.ts.tests.servlet.spec.annotationservlet.webfilter; + +import java.io.IOException; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.DispatcherType; +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.annotation.WebFilter; + +@WebFilter(dispatcherTypes = DispatcherType.REQUEST, urlPatterns = { + "/Servlet1" }) +public final class TestFilter1 implements Filter { + + private FilterConfig filterConfig = null; + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + if (filterConfig == null) { + StaticLog.add("FAILED_FILTER1_INVOKED"); + } else { + StaticLog.add("FILTER1_INVOKED"); + } + chain.doFilter(request, response); + } + + // Remove the filter configuration object for this filter. + public void destroy() { + } + + // initialize the filter configuration object for this filter. + public void init(FilterConfig filterConfig) { + this.filterConfig = filterConfig; + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webfilter/TestFilter2.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webfilter/TestFilter2.java new file mode 100644 index 0000000000..7e6903b70d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webfilter/TestFilter2.java @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2009, 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$ + */ +package com.sun.ts.tests.servlet.spec.annotationservlet.webfilter; + +import java.io.IOException; +import java.util.Collection; +import java.util.Enumeration; + +import com.sun.ts.tests.servlet.common.util.StaticLog; + +import jakarta.servlet.DispatcherType; +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.FilterRegistration; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.annotation.WebFilter; +import jakarta.servlet.annotation.WebInitParam; + +@WebFilter(filterName = "filter2", dispatcherTypes = { + DispatcherType.FORWARD }, servletNames = { "servlet1" }, value = { + "/Servlet1" }, initParams = { + @WebInitParam(name = "name1", value = "value1"), + @WebInitParam(name = "name2", value = "value2") }) + +public final class TestFilter2 implements Filter { + + private FilterConfig filterConfig = null; + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + if (filterConfig == null) { + StaticLog.add("FAILED_FILTER2_INVOKED"); + } else { + StaticLog.add("FILTER2_INVOKED"); + StaticLog.add("FilterName=" + filterConfig.getFilterName()); + + for (Enumeration names = filterConfig.getInitParameterNames(); names + .hasMoreElements();) { + String name = (String) names.nextElement(); + StaticLog.add( + "PName=" + name + " PVALUE=" + filterConfig.getInitParameter(name)); + } + StaticLog.add("AsyncSupport=" + request.isAsyncSupported()); + FilterRegistration fr = filterConfig.getServletContext() + .getFilterRegistration(filterConfig.getFilterName()); + Collection mapping = fr.getServletNameMappings(); + for (String url : mapping) { + StaticLog.add("URL=" + url); + } + StaticLog.add("DispatcherType=" + request.getDispatcherType()); + StaticLog.add("From=" + request.getAttribute("from")); + } + chain.doFilter(request, response); + } + + public void destroy() { + } + + public void init(FilterConfig filterConfig) { + this.filterConfig = filterConfig; + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webfilter/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webfilter/TestServlet.java new file mode 100644 index 0000000000..0025e38133 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webfilter/TestServlet.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2009, 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:$ + */ +package com.sun.ts.tests.servlet.spec.annotationservlet.webfilter; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void forward1(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String path = "/Servlet1"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + + if (rd == null) { + pw.println("Null RequestDispatcher got for path=" + path); + } else { + request.setAttribute("from", "TestServlet"); + rd.forward(request, response); + } + } + + public void include1(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String path = "/Servlet1"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + + if (rd == null) { + pw.println("Null RequestDispatcher got for path=" + path); + } else { + request.setAttribute("from", "TestServlet"); + rd.include(request, response); + } + ServletTestUtil.printResult(pw, true); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webfilter/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webfilter/URLClient.java new file mode 100644 index 0000000000..b4e99e466a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webfilter/URLClient.java @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2009, 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:$ + */ +package com.sun.ts.tests.servlet.spec.annotationservlet.webfilter; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_annotationservlet_webfilter_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(Servlet1.class, TestFilter1.class, TestFilter2.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_annotationservlet_webfilter_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + + /* + * @testName: test1 + * + * @assertion_ids: Servlet:JAVADOC:804; Servlet:JAVADOC:811; + * Servlet:JAVADOC:825; + * + * @test_Strategy: Create a servlet Servlet1; Create a filter TestFilter1; + * Define TestFilter1 using annotation + * + * @WebFilter(...,urlPatterns="servlet1",...,); Send a request to Servlet1; + * Veriy TestFilter1 is invoked properly. + */ + @Test + public void test1() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Servlet1 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "FILTER1_INVOKED|Servlet1_INVOKED"); + invoke(); + } + + /* + * @testName: test2 + * + * @assertion_ids: Servlet:JAVADOC:802; Servlet:JAVADOC:804; + * Servlet:JAVADOC:806; Servlet:JAVADOC:807; Servlet:JAVADOC:809; + * Servlet:JAVADOC:811; Servlet:JAVADOC:812; Servlet:JAVADOC:814; + * Servlet:JAVADOC:815; Servlet:JAVADOC:825; + * + * @test_Strategy: Create a servlet Servlet1; Create a filter TestFilter1; + * Define TestFilter1 using annotation + * + * @WebFilter(...,urlPatterns="servlet1",...,dispatcherTypes=REQUEST); Create + * a filter TestFilter2; Define TestFilter2 using annotation + * + * @WebFilter(...,urlPatterns="servlet1",..., dispatcherTypes=FORWARD); Create + * another Servlet which forward to Servlet1 Send a request to the second + * Servlet; Veriy TestFilter2 is invoked. Veriy TestFilter1 is not invoked. + */ + @Test + public void test2() throws Exception { + TEST_PROPS.setProperty(APITEST, "forward1"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "FILTER1_INVOKED"); + TEST_PROPS.setProperty(UNORDERED_SEARCH_STRING, + "FILTER2_INVOKED|" + "FilterName=filter2|" + + "PName=name1 PVALUE=value1|" + "PName=name2 PVALUE=value2|" + + "AsyncSupport=false|" + "URL=servlet1|" + "From=TestServlet|" + + "Servlet1_INVOKED"); + invoke(); + } + + /* + * @testName: test3 + * + * @assertion_ids: Servlet:JAVADOC:804; Servlet:JAVADOC:811; + * Servlet:JAVADOC:825; + * + * @test_Strategy: Create a servlet Servlet1; Create a filter TestFilter1; + * Define TestFilter1 using annotation + * + * @WebFilter(...,urlPatterns="servlet1",..., dispatcherTypes=REQUEST); Create + * another Servlet which include to Servlet1 Send a request to the second + * Servlet; Veriy TestFilter1 is not invoked. + */ + @Test + public void test3() throws Exception { + TEST_PROPS.setProperty(APITEST, "include1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet1_INVOKED"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "FILTER1_INVOKED"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webfilter/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webfilter/build.xml new file mode 100644 index 0000000000..6444ddb818 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webfilter/build.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webfilter/servlet_annotationservlet_webfilter_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webfilter/servlet_annotationservlet_webfilter_web.xml new file mode 100644 index 0000000000..ff754fa710 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webfilter/servlet_annotationservlet_webfilter_web.xml @@ -0,0 +1,33 @@ + + + + + ServletSpecWebFilter + + TestServlet + com.sun.ts.tests.servlet.spec.annotationservlet.webfilter.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/weblistener/ContextListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/weblistener/ContextListener.java new file mode 100644 index 0000000000..237c310c53 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/weblistener/ContextListener.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2009, 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 + */ + +package com.sun.ts.tests.servlet.spec.annotationservlet.weblistener; + +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; +import jakarta.servlet.annotation.WebListener; + +@WebListener(value = "ContextListener") +public final class ContextListener implements ServletContextListener { + + private ServletContext context = null; + + public void contextDestroyed(ServletContextEvent event) { + createAttribute("ContextDestroyed"); + this.context = null; + } + + public void contextInitialized(ServletContextEvent event) { + this.context = event.getServletContext(); + createAttribute("ContextInitialized"); + } + + private void createAttribute(String s) { + String tmp = null; + Object o = context.getAttribute("ContextListener"); + if (o != null) { + if (o instanceof String) { + tmp = (String) o + s; + } + } else { + tmp = s; + } + context.setAttribute("ContextListener", tmp); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/weblistener/HSAttributeListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/weblistener/HSAttributeListener.java new file mode 100644 index 0000000000..69f1a8ae2b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/weblistener/HSAttributeListener.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2015, 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 + */ + +package com.sun.ts.tests.servlet.spec.annotationservlet.weblistener; + +import java.util.ArrayList; + +import jakarta.servlet.annotation.WebListener; +import jakarta.servlet.http.HttpSessionAttributeListener; +import jakarta.servlet.http.HttpSessionBindingEvent; + +@WebListener(value = "HttpSessionAttributeListener") +public final class HSAttributeListener implements HttpSessionAttributeListener { + + public void attributeAdded(HttpSessionBindingEvent event) { + System.out.println("in HSAttributeListener.attributeAdded"); + ArrayList al = null; + + al = (ArrayList) event.getSession().getServletContext() + .getAttribute("HSAList"); + if (al == null) { + al = new ArrayList(); + } + al.add("HSAttributeListener.attributeAdded"); + event.getSession().getServletContext().setAttribute("HSAList", al); + } + + public void attributeRemoved(HttpSessionBindingEvent event) { + System.out.println("in HSAttributeListener.attributeRemoved"); + ArrayList al = null; + + al = (ArrayList) event.getSession().getServletContext() + .getAttribute("HSAList"); + if (al == null) { + al = new ArrayList(); + } + al.add("HSAttributeListener.attributeRemoved"); + event.getSession().getServletContext().setAttribute("HSAList", al); + } + + public void attributeReplaced(HttpSessionBindingEvent event) { + System.out.println("in HSAttributeListener.attributeReplaced"); + ArrayList al = null; + + al = (ArrayList) event.getSession().getServletContext() + .getAttribute("HSAList"); + if (al == null) { + al = new ArrayList(); + } + al.add("HSAttributeListener.attributeReplaced"); + event.getSession().getServletContext().setAttribute("HSAList", al); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/weblistener/HSListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/weblistener/HSListener.java new file mode 100644 index 0000000000..dcefd8adba --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/weblistener/HSListener.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2009, 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:$ + */ +package com.sun.ts.tests.servlet.spec.annotationservlet.weblistener; + +import java.util.ArrayList; + +import jakarta.servlet.annotation.WebListener; +import jakarta.servlet.http.HttpSessionEvent; +import jakarta.servlet.http.HttpSessionListener; + +@WebListener("HttpSessionListener") +public final class HSListener implements HttpSessionListener { + + public void sessionCreated(HttpSessionEvent event) { + ArrayList al = null; + al = (ArrayList) event.getSession().getServletContext() + .getAttribute("HSList"); + if (al == null) { + al = new ArrayList(); + } + al.add("HSListener:sessionCreated"); + event.getSession().getServletContext().setAttribute("HSList", al); + } + + public void sessionDestroyed(HttpSessionEvent event) { + ArrayList al = null; + al = (ArrayList) event.getSession().getServletContext() + .getAttribute("HSList"); + if (al == null) { + al = new ArrayList(); + } + al.add("HSListener:sessionDestroyed"); + event.getSession().getServletContext().setAttribute("HSList", al); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/weblistener/HttpTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/weblistener/HttpTestServlet.java new file mode 100644 index 0000000000..d41243b294 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/weblistener/HttpTestServlet.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2009, 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:$ + */ +package com.sun.ts.tests.servlet.spec.annotationservlet.weblistener; + +import java.io.IOException; + +import com.sun.ts.tests.servlet.common.servlets.HttpTCKServlet; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpSession; + +public class HttpTestServlet extends HttpTCKServlet { + + public void httpSessionListenerTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + HttpSession session = request.getSession(true); + session.invalidate(); + + response.getWriter().println(getServletContext().getAttribute("HSList")); + getServletContext().removeAttribute("SRList"); + getServletContext().removeAttribute("SRAList"); + getServletContext().removeAttribute("HSList"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/weblistener/SCAttributeListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/weblistener/SCAttributeListener.java new file mode 100644 index 0000000000..79135f39f2 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/weblistener/SCAttributeListener.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2009, 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:$ + */ +package com.sun.ts.tests.servlet.spec.annotationservlet.weblistener; + +import java.util.ArrayList; + +import jakarta.servlet.ServletContextAttributeEvent; +import jakarta.servlet.ServletContextAttributeListener; +import jakarta.servlet.annotation.WebListener; + +@WebListener(value = "ServletContextAttributeListener") +public final class SCAttributeListener + implements ServletContextAttributeListener { + + public void attributeAdded(ServletContextAttributeEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("SCAList"); + if (al == null) { + al = new ArrayList(); + } + al.add("SCAAdded:" + event.getName() + "," + event.getValue()); + event.getServletContext().setAttribute("SCAList", al); + } + + public void attributeRemoved(ServletContextAttributeEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("SCAList"); + if (al == null) { + al = new ArrayList(); + } + al.add("SCARemoved:" + event.getName() + "," + event.getValue()); + event.getServletContext().setAttribute("SCAList", al); + } + + public void attributeReplaced(ServletContextAttributeEvent event) { + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/weblistener/SRAttributeListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/weblistener/SRAttributeListener.java new file mode 100644 index 0000000000..74b58d61f9 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/weblistener/SRAttributeListener.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2009, 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 + */ + +package com.sun.ts.tests.servlet.spec.annotationservlet.weblistener; + +import java.util.ArrayList; + +import jakarta.servlet.ServletRequestAttributeEvent; +import jakarta.servlet.ServletRequestAttributeListener; +import jakarta.servlet.annotation.WebListener; + +@WebListener(value = "ServletRequestAttributeListener") +public final class SRAttributeListener + implements ServletRequestAttributeListener { + + public void attributeAdded(ServletRequestAttributeEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("SRAList"); + if (al == null) { + al = new ArrayList(); + } + al.add("SRAAdded:" + event.getName() + "," + event.getValue()); + event.getServletContext().setAttribute("SRAList", al); + } + + public void attributeRemoved(ServletRequestAttributeEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("SRAList"); + if (al == null) { + al = new ArrayList(); + } + al.add("SRARemoved:" + event.getName() + "," + event.getValue()); + event.getServletContext().setAttribute("SRAList", al); + } + + public void attributeReplaced(ServletRequestAttributeEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("SRAList"); + if (al == null) { + al = new ArrayList(); + } + al.add("SRAReplaced:" + event.getName() + "," + event.getValue()); + event.getServletContext().setAttribute("SRAList", al); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/weblistener/SRListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/weblistener/SRListener.java new file mode 100644 index 0000000000..14472e5fbd --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/weblistener/SRListener.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2009, 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 + */ + +package com.sun.ts.tests.servlet.spec.annotationservlet.weblistener; + +import java.util.ArrayList; + +import jakarta.servlet.ServletRequestEvent; +import jakarta.servlet.ServletRequestListener; +import jakarta.servlet.annotation.WebListener; + +@WebListener(value = "ServletRequestListener") +public final class SRListener implements ServletRequestListener { + + public void requestDestroyed(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("SRList"); + if (al == null) { + al = new ArrayList(); + } + + al.add("in requestDestroyed method of listener"); + event.getServletContext().setAttribute("SRList", al); + } + + public void requestInitialized(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("SRList"); + if (al == null) { + al = new ArrayList(); + } + + al.add("in requestInitialized method of listener"); + event.getServletContext().setAttribute("SRList", al); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/weblistener/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/weblistener/TestServlet.java new file mode 100644 index 0000000000..60612d6d3f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/weblistener/TestServlet.java @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2009, 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:$ + */ +package com.sun.ts.tests.servlet.spec.annotationservlet.weblistener; + +import java.io.IOException; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; + +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.http.HttpServletRequest; + +public class TestServlet extends GenericTCKServlet { + + public void ContextListenerTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + response.getWriter() + .println(getServletContext().getAttribute("ContextListener")); + getServletContext().removeAttribute("SRList"); + getServletContext().removeAttribute("SRAList"); + getServletContext().removeAttribute("ContextListener"); + } + + public void ContextAttributeListenerTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + getServletContext().setAttribute("Test", "tmp"); + getServletContext().removeAttribute("Test"); + response.getWriter().println(getServletContext().getAttribute("SCAList")); + getServletContext().removeAttribute("SRList"); + getServletContext().removeAttribute("SRAList"); + getServletContext().removeAttribute("SCAList"); + } + + public void RequsetListenerTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + response.getWriter().println(getServletContext().getAttribute("SRList")); + getServletContext().removeAttribute("SRList"); + getServletContext().removeAttribute("SRAList"); + getServletContext().removeAttribute("SCAList"); + } + + public void RepeatRequsetListenerTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + response.getWriter().println(getServletContext().getAttribute("SRList")); + getServletContext().removeAttribute("SRAList"); + getServletContext().removeAttribute("SCAList"); + } + + public void RequsetAttributeListenerTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + request.setAttribute("Test", "RequestAttribute"); + request.removeAttribute("Test"); + response.getWriter().println(getServletContext().getAttribute("SRAList")); + getServletContext().removeAttribute("SRList"); + getServletContext().removeAttribute("SRAList"); + getServletContext().removeAttribute("SCAList"); + } + + /* + * This test is used to trigger events in the HttpSessionAttributeListener but + * the REAL testing is done in HttpSessionAttributeListenerTest. So this + * method is not the real test, but instead does preparation work for the real + * test. (thus this is a pre-test) This pre-test will act on session + * attributes in order to force the invocation of the + * HttpSessionAttributeListener methods. + */ + public void HttpSessionAttributeListenerPreLude(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + response.getWriter().println("in HttpSessionAttributeListenerPreLude"); + + // create new attribute, change that attribute, and remove that attribute + // in attempt to trigger the HttpSessionAttributeListener events + HttpServletRequest httpServletReq = (HttpServletRequest) request; + + // create new session attribute to trigger attributeAdded() notification + httpServletReq.getSession().setAttribute("Test", + "HttpSessionAttributeListenerPreludeB"); + + // replace session attribute to trigger attributeReplaced() notification + httpServletReq.getSession().setAttribute("Test", + "HttpSessionAttributeListenerPrelude"); + + // remove session attribute to trigger attributeRemoved notification + httpServletReq.getSession().removeAttribute("Test"); + + } + + public void HttpSessionAttributeListenerTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + request.setAttribute("Test", "HttpSessionAttributeListenerTest"); // was + // RequestAttribute + request.removeAttribute("Test"); + System.out.println("TestServlet.HttpSessionAttributeListenerTest HSAList = " + + getServletContext().getAttribute("HSAList")); + response.getWriter().println(getServletContext().getAttribute("HSAList")); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/weblistener/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/weblistener/URLClient.java new file mode 100644 index 0000000000..542a9eb0d6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/weblistener/URLClient.java @@ -0,0 +1,203 @@ +/* + * Copyright (c) 2009, 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:$ + */ +package com.sun.ts.tests.servlet.spec.annotationservlet.weblistener; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_annotationservlet_weblistener_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(ContextListener.class, HSAttributeListener.class, HSListener.class, HttpTestServlet.class, + SCAttributeListener.class, SRAttributeListener.class, SRListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_annotationservlet_weblistener_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + + /* + * @testName: ContextListenerTest + * + * @assertion_ids: Servlet:JAVADOC:865; Servlet:SPEC:195.3; + * + * @test_Strategy: Create a servlet TestServlet; Create a + * ServletContextListener using @WebListener; Send request to TestServlet; + * Veriy ServletContextListener is invoked properly. + */ + @Test + public void ContextListenerTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "ContextListenerTest"); + TEST_PROPS.setProperty(SEARCH_STRING, "ContextInitialized"); + invoke(); + } + + /* + * @testName: ContextAttributeListenerTest + * + * @assertion_ids: Servlet:JAVADOC:865; Servlet:SPEC:195.4; + * + * @test_Strategy: Create a servlet TestServlet; Create a + * ServletContextAttributeListener using @WebListener; Send request to + * TestServlet; Veriy ServletContextAttributeListener is invoked properly. + */ + @Test + public void ContextAttributeListenerTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "ContextAttributeListenerTest"); + TEST_PROPS.setProperty(SEARCH_STRING, + "SCAAdded:ContextListener|" + "ContextInitialized|" + "SCAAdded:SRList|" + + "in requestInitialized method of listener|" + "SCAAdded:Test,tmp|" + + "SCARemoved:Test,tmp"); + invoke(); + } + + /* + * @testName: RequsetListenerTest + * + * @assertion_ids: Servlet:JAVADOC:865; Servlet:SPEC:195.5; + * + * @test_Strategy: Create a servlet TestServlet; Create a + * ServletRequestListener using @WebListener; Send request to TestServlet; + * Veriy ServletRequestListener is invoked properly. + */ + @Test + public void RequsetListenerTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "RequsetListenerTest"); + TEST_PROPS.setProperty(SEARCH_STRING, + "in requestInitialized method of listener"); + invoke(); + } + + /* + * @testName: RepeatRequsetListenerTest + * + * @assertion_ids: Servlet:JAVADOC:865; Servlet:SPEC:195.5; + * + * @test_Strategy: Create a servlet TestServlet; Create a + * ServletRequestListener using @WebListener; Send request to TestServlet; + * Send a second request to TestServlet; Veriy ServletRequestListener is + * invoked properly. + */ + @Test + public void RepeatRequsetListenerTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "RepeatRequsetListenerTest"); + TEST_PROPS.setProperty(SEARCH_STRING, + "in requestInitialized method of listener"); + invoke(); + + TEST_PROPS.setProperty(APITEST, "RequsetListenerTest"); + TEST_PROPS.setProperty(SEARCH_STRING, + "in requestInitialized method of listener|" + + "in requestDestroyed method of listener|" + + "in requestInitialized method of listener"); + invoke(); + } + + /* + * @testName: RequsetAttributeListenerTest + * + * @assertion_ids: Servlet:JAVADOC:865; Servlet:SPEC:195.6; + * + * @test_Strategy: Create a servlet TestServlet; Create a + * ServletRequestListener using @WebListener; Send request to TestServlet; + * Veriy ServletRequestListener is invoked properly. + */ + @Test + public void RequsetAttributeListenerTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "RequsetAttributeListenerTest"); + TEST_PROPS.setProperty(SEARCH_STRING, + "SRAAdded:Test,RequestAttribute|" + "SRARemoved:Test,RequestAttribute"); + invoke(); + } + + /* + * @testName: HttpSessionListenerTest + * + * @assertion_ids: Servlet:JAVADOC:865; Servlet:SPEC:195.7; + * + * @test_Strategy: Create a servlet HttpTestServlet; Create a + * HttpSessionListener using @WebListener; Send request to HttpTestServlet; + * Create a HttpSession and then invlalidate it; Veriy HttpSessionListener is + * invoked properly. + */ + @Test + public void HttpSessionListenerTest() throws Exception { + setServletName("HttpTestServlet"); + TEST_PROPS.setProperty(APITEST, "HttpSessionListenerTest"); + TEST_PROPS.setProperty(SEARCH_STRING, + "HSListener:sessionCreated|" + "HSListener:sessionDestroyed"); + invoke(); + } + + /* + * @testName: HttpSessionAttributeListenerTest + * + * @assertion_ids: Servlet:JAVADOC:865; Servlet:SPEC:289; Servlet:SPEC:195.8; + * + * @test_Strategy: Create a servlet TestServlet; Create a + * HttpSessionAttributeListener using @WebListener; Send request to + * TestServlet, that will set some attributes in; its first call to + * HttpSessionAttributeListenerPreLude then once; in this servlet method, the + * attributes are added, replaced, and; removed. This should cause the + * HttpSessionAttributeListener; event to get triggered for all 3 methods. + * Verification of; the 3 triggered event methods is then checked in the 2nd; + * invocation to HttpSessionAttributeListenerTest below. + */ + @Test + public void HttpSessionAttributeListenerTest() throws Exception { + + // first invocation is to do some session attribute manipulations + // which should trigger HttpSessionAttributeListener notifications + TEST_PROPS.setProperty(APITEST, "HttpSessionAttributeListenerPreLude"); + TEST_PROPS.setProperty(SEARCH_STRING, + "in HttpSessionAttributeListenerPreLude"); + invoke(); + + // 2nd invocation checks that the HttpSessionAttributeListener notifications + // occurred by verifying certain strings were written to HSAList attribute + TEST_PROPS.setProperty(APITEST, "HttpSessionAttributeListenerTest"); + TEST_PROPS.setProperty(SEARCH_STRING, + "HSAttributeListener.attributeAdded|" + + "HSAttributeListener.attributeReplaced|" + + "HSAttributeListener.attributeRemoved"); + invoke(); + + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/weblistener/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/weblistener/build.xml new file mode 100644 index 0000000000..2daf58c6b6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/weblistener/build.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/weblistener/servlet_annotationservlet_weblistener_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/weblistener/servlet_annotationservlet_weblistener_web.xml new file mode 100644 index 0000000000..a4ab23c6d8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/weblistener/servlet_annotationservlet_weblistener_web.xml @@ -0,0 +1,41 @@ + + + + + Servletannotationweblistener + + TestServlet + com.sun.ts.tests.servlet.spec.annotationservlet.weblistener.TestServlet + + + TestServlet + /TestServlet/* + + + HttpTestServlet + com.sun.ts.tests.servlet.spec.annotationservlet.weblistener.HttpTestServlet + + + HttpTestServlet + /HttpTestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webservlet/Servlet1.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webservlet/Servlet1.java new file mode 100644 index 0000000000..78283db54b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webservlet/Servlet1.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2009, 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:$ + */ +package com.sun.ts.tests.servlet.spec.annotationservlet.webservlet; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Enumeration; + +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +@WebServlet("/Servlet1URL") +public class Servlet1 extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.write("Servlet1_INVOKED"); + pw.write("initParams: "); + String name = null; + String value = null; + + Enumeration names = getInitParameterNames(); + + if (names.hasMoreElements()) { + name = (String) names.nextElement(); + value = getInitParameter(name); + pw.print(name + "=" + value); + } + + pw.println("servletname=" + getServletName() + "END"); + pw.print("isAsyncSupported=" + request.isAsyncSupported()); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webservlet/Servlet2.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webservlet/Servlet2.java new file mode 100644 index 0000000000..9dea2593e3 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webservlet/Servlet2.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2009, 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:$ + */ +package com.sun.ts.tests.servlet.spec.annotationservlet.webservlet; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Enumeration; + +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +@WebServlet(value = { "/Servlet2URL1", "/Servlet2URL2", "/test/*", "*.html" }) +public class Servlet2 extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.write("Servlet2_INVOKED"); + + pw.write("initParams: "); + String name = null; + String value = null; + + Enumeration names = getInitParameterNames(); + + if (names.hasMoreElements()) { + name = (String) names.nextElement(); + value = getInitParameter(name); + pw.print(name + "=" + value); + } + + pw.println("servletname=" + getServletName() + "END"); + pw.print("isAsyncSupported=" + request.isAsyncSupported()); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webservlet/Servlet3.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webservlet/Servlet3.java new file mode 100644 index 0000000000..723aa2b38f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webservlet/Servlet3.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2009, 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:$ + */ +package com.sun.ts.tests.servlet.spec.annotationservlet.webservlet; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Enumeration; + +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.WebInitParam; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +@WebServlet(value = "/Servlet3URL", initParams = { + @WebInitParam(name = "name1", value = "value1"), + @WebInitParam(name = "name2", value = "value2") }, name = "Servlet3") +public class Servlet3 extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.write("Servlet3_INVOKED"); + pw.write("initParams: "); + String name = null; + String value = null; + + Enumeration names = getInitParameterNames(); + + while (names.hasMoreElements()) { + name = (String) names.nextElement(); + value = getInitParameter(name); + pw.print(name + "=" + value); + } + + pw.println("servletname=" + getServletName()); + pw.print("isAsyncSupported=" + request.isAsyncSupported()); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webservlet/Servlet4.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webservlet/Servlet4.java new file mode 100644 index 0000000000..5b5687be75 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webservlet/Servlet4.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2009, 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:$ + */ +package com.sun.ts.tests.servlet.spec.annotationservlet.webservlet; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Enumeration; + +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.WebInitParam; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +@WebServlet(urlPatterns = "/Servlet4URL/*", asyncSupported = true, initParams = { + @WebInitParam(name = "name1", value = "value1"), + @WebInitParam(name = "name2", value = "value2") }, name = "Servlet4") +public class Servlet4 extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.write("Servlet4_INVOKED"); + + pw.print("ServletName=" + getServletName()); + pw.print("isAsyncSupported=" + request.isAsyncSupported()); + + pw.write("initParams: "); + String name = null; + String value = null; + Enumeration names = getInitParameterNames(); + + while (names.hasMoreElements()) { + name = (String) names.nextElement(); + value = getInitParameter(name); + pw.print(name + "=" + value); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webservlet/Servlet5.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webservlet/Servlet5.java new file mode 100644 index 0000000000..47212351d8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webservlet/Servlet5.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2009, 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:$ + */ +package com.sun.ts.tests.servlet.spec.annotationservlet.webservlet; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Enumeration; + +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +@WebServlet(urlPatterns = { "/Servlet5URL1", "/Servlet5URL2", "/test5/*", + "*.txt" }) +public class Servlet5 extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.write("Servlet5_INVOKED"); + + pw.write("initParams: "); + String name = null; + String value = null; + + Enumeration names = getInitParameterNames(); + + if (names.hasMoreElements()) { + name = (String) names.nextElement(); + value = getInitParameter(name); + pw.print(name + "=" + value); + } + + pw.println("servletname=" + getServletName() + "END"); + pw.print("isAsyncSupported=" + request.isAsyncSupported()); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webservlet/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webservlet/URLClient.java new file mode 100644 index 0000000000..f8215a017b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webservlet/URLClient.java @@ -0,0 +1,209 @@ +/* + * Copyright (c) 2009, 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:$ + */ +package com.sun.ts.tests.servlet.spec.annotationservlet.webservlet; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "webservlet.war") + .addClasses(Servlet1.class, Servlet2.class, Servlet3.class, Servlet4.class, Servlet5.class); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + + /* + * @testName: test1 + * + * @assertion_ids: Servlet:SPEC:221; Servlet:SPEC:221.1; Servlet:SPEC:221.2; + * Servlet:SPEC:221.3; Servlet:SPEC:221.6; Servlet:SPEC:221.7; + * Servlet:SPEC:221.10; Servlet:JAVADOC:825; + * + * @test_Strategy: Create a servlet Servlet1; Define Servlet1 using + * annotation @WebServlet(String); Invoke Servlet1 at the URL specified + * by @WebServlet; Veriy Servlet1 is invoked properly; Verify that servlet + * name is set to the default name; + */ + @Test + public void test1() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Servlet1URL HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet1_INVOKED" + + "|servletname=com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet1" + + "|isAsyncSupported=false"); + invoke(); + } + + /* + * @testName: test2 + * + * @assertion_ids: Servlet:SPEC:221; Servlet:SPEC:221.1; Servlet:SPEC:221.2; + * Servlet:SPEC:221.3; Servlet:SPEC:221.4; Servlet:SPEC:221.6; + * Servlet:SPEC:221.7; Servlet:SPEC:221.10; Servlet:JAVADOC:825; + * + * @test_Strategy: Create a servlet Servlet2; Define Servlet2 using + * annotation @WebServlet(value=""); Invoke Servlet2 at any of the URLs + * specified by @WebServlet; Veriy Servlet2 is invoked properly; Verify that + * servlet name is set to the default name; + */ + @Test + public void test2() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Servlet2URL1 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet2_INVOKED" + + "|servletname=com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet2" + + "|isAsyncSupported=false"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Servlet2URL2 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet2_INVOKED" + + "|servletname=com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet2" + + "|isAsyncSupported=false"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/test/xyz HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet2_INVOKED" + + "|servletname=com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet2" + + "|isAsyncSupported=false"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/x/y/t.html HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet2_INVOKED" + + "|servletname=com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet2" + + "|isAsyncSupported=false"); + invoke(); + } + + /* + * @testName: test3 + * + * @assertion_ids: Servlet:SPEC:221; Servlet:SPEC:221.1; Servlet:SPEC:221.2; + * Servlet:SPEC:221.3; Servlet:SPEC:221.4; Servlet:SPEC:221.7; + * Servlet:SPEC:221.10; Servlet:JAVADOC:819; Servlet:JAVADOC:822; + * Servlet:JAVADOC:825; + * + * @test_Strategy: Create a servlet Servlet3; Define Servlet3 using annotation + * + * @WebServlet(value="", initParams={}, name="") Invoke Servlet3 at the URL + * specified by @WebServlet; Veriy Servlet3 is invoked and -- value is set + * correctly -- all @initParams are passed correctly. -- servlet name is set + * correctly + */ + @Test + public void test3() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Servlet3URL HTTP/1.1"); + TEST_PROPS.setProperty(UNORDERED_SEARCH_STRING, + "Servlet3_INVOKED|initParams:" + "|name1=value1|name2=value2" + + "|servletname=Servlet3" + "|isAsyncSupported=false"); + invoke(); + } + + /* + * @testName: test4 + * + * @assertion_ids: Servlet:SPEC:221; Servlet:SPEC:221.1; Servlet:SPEC:221.2; + * Servlet:SPEC:221.3; Servlet:SPEC:221.4; Servlet:SPEC:221.7; + * Servlet:SPEC:221.10; Servlet:JAVADOC:817; Servlet:JAVADOC:819; + * Servlet:JAVADOC:822; Servlet:JAVADOC:825; + * + * @test_Strategy: Create a servlet Servlet4; Define Servlet4 using + * annotation: + * + * @WebServlet(urlPatterns="", asyncSupported = true, initParams={}, name="") + * Invoke Servlet4 at the URLs specified by @WebServlet; Veriy Servlet4 is + * invoked and -- all @initParams are passed correctly. -- servlet name is set + * correctly -- async support is set correctly + */ + @Test + public void test4() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Servlet4URL/ HTTP/1.1"); + TEST_PROPS.setProperty(UNORDERED_SEARCH_STRING, + "Servlet4_INVOKED" + "|ServletName=Servlet4" + "isAsyncSupported=true" + + "|initParams:|name1=value1|name2=value2"); + invoke(); + } + + /* + * @testName: test5 + * + * @assertion_ids: Servlet:SPEC:221; Servlet:SPEC:221.1; Servlet:SPEC:221.2; + * Servlet:SPEC:221.3; Servlet:SPEC:221.4; Servlet:SPEC:221.6; + * Servlet:SPEC:221.7; Servlet:SPEC:221.10; Servlet:JAVADOC:825; + * + * @test_Strategy: Create a servlet Servlet5; Define Servlet5 using + * annotation @WebServlet(urlPatterns=""); Invoke Servlet5 at any of the URLs + * specified by @WebServlet; Veriy Servlet5 is invoked properly; Verify that + * servlet name is set to the default name; + */ + @Test + public void test5() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Servlet5URL1 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet5_INVOKED" + + "|servletname=com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet5" + + "|isAsyncSupported=false"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Servlet5URL2 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet5_INVOKED" + + "|servletname=com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet5" + + "|isAsyncSupported=false"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/test5/xyz HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet5_INVOKED" + + "|servletname=com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet5" + + "|isAsyncSupported=false"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/x/y/z.txt HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet5_INVOKED" + + "|servletname=com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet5" + + "|isAsyncSupported=false"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webservlet/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webservlet/build.xml new file mode 100644 index 0000000000..174d2a937d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webservlet/build.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webservletapi/TestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webservletapi/TestListener.java new file mode 100644 index 0000000000..87d63d486d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webservletapi/TestListener.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.spec.annotationservlet.webservletapi; + +import java.util.HashMap; +import java.util.Map; + +import jakarta.servlet.Servlet; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRegistration; +import jakarta.servlet.annotation.WebListener; + +@WebListener("") +public class TestListener implements ServletContextListener { + + /** + * Receives notification that the web application initialization process is + * starting. + * + * @param sce + * The servlet context event + */ + public void contextInitialized(ServletContextEvent sce) { + ServletContext context = sce.getServletContext(); + + final String addServletName1 = "Servlet1API"; + final String addServletName2 = "Servlet2API"; + final String addServletName3 = "Servlet3API"; + + Map params = new HashMap(); + + /* + * Add Servlet1 + */ + ServletRegistration sr1 = context.addServlet(addServletName1, + "com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet1"); + sr1.addMapping("/Servlet1APIURL"); + + /* + * Add Servlet2 + */ + ServletRegistration sr2 = context.addServlet(addServletName2, + com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet2.class); + sr2.addMapping("/Servlet2APIURL", "/Servlet2APIURL2", "*.xml", + "/ServletAPIURL2/*"); + + /* + * Add Servlet3 + */ + ServletRegistration sr3 = null; + try { + Servlet servlet3 = context.createServlet( + com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet3.class); + sr3 = context.addServlet(addServletName3, servlet3); + sr3.addMapping("/Servlet3APIURL"); + params.put("name1", "servlet3"); + params.put("name2", "servlet3again"); + sr3.setInitParameters(params); + params.clear(); + + } catch (ServletException ex) { + System.out.println("Error creating Servlet"); + } + } + + /** + * Receives notification that the servlet context is about to be shut down. + * + * @param sce + * The servlet context event + */ + public void contextDestroyed(ServletContextEvent sce) { + // Do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webservletapi/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webservletapi/URLClient.java new file mode 100644 index 0000000000..feb09bd551 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webservletapi/URLClient.java @@ -0,0 +1,190 @@ +/* + * Copyright (c) 2012, 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:$ + */ +package com.sun.ts.tests.servlet.spec.annotationservlet.webservletapi; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet1; +import com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet2; +import com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet3; +import com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet4; +import com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet5; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "webservletapi_web.war") + .addClasses(TestListener.class, Servlet1.class, Servlet2.class, Servlet3.class, Servlet4.class, Servlet5.class); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + + /* + * @testName: test1 + * + * @assertion_ids: Servlet:SPEC:221; Servlet:SPEC:221.1; Servlet:SPEC:221.2; + * Servlet:SPEC:221.3; Servlet:SPEC:221.6; Servlet:SPEC:221.7; + * Servlet:SPEC:221.9; Servlet:SPEC:221.10; Servlet:JAVADOC:825; + * + * @test_Strategy: Create a servlet Servlet1; Define Servlet1 using + * annotation @WebServlet(String); Add Servlet1 to ServletContext + * programmatically using different name; Invoke Servlet1 at the URL specified + * by @WebServlet; Verify that it works as defined at @WebServlet; Invoke + * Servlet1 at the URL specified by API programing; Veriy Servlet1 is invoked + * properly; Verify that servlet name is set correctly; Verify that servlet + * name is set to the default name; + */ + @Test + public void test1() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Servlet1URL HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet1_INVOKED" + + "|servletname=com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet1" + + "|isAsyncSupported=false"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Servlet1APIURL HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, + "Servlet1_INVOKED" + "|servletname=Servlet1API|isAsyncSupported=false"); + invoke(); + } + + /* + * @testName: test2 + * + * @assertion_ids: Servlet:SPEC:221; Servlet:SPEC:221.1; Servlet:SPEC:221.2; + * Servlet:SPEC:221.3; Servlet:SPEC:221.4; Servlet:SPEC:221.6; + * Servlet:SPEC:221.7; Servlet:SPEC:221.9; Servlet:SPEC:221.10; + * Servlet:JAVADOC:825; + * + * @test_Strategy: Create a servlet Servlet2; Define Servlet2 using + * annotation @WebServlet(value=""); Add Servlet2 to ServletContext + * programmatically under different name; Invoke Servlet2 at any of the URLs + * specified by @WebServlet; Verify that it is invoked properly; Invoke + * Servlet2 at the URLs specified in program; Veriy Servlet2 is invoked + * properly; Verify that servlet name is set properly; + */ + @Test + public void test2() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Servlet2URL1 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet2_INVOKED" + + "|servletname=com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet2" + + "|isAsyncSupported=false"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Servlet2URL2 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet2_INVOKED" + + "|servletname=com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet2" + + "|isAsyncSupported=false"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/test/xyz HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet2_INVOKED" + + "|servletname=com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet2" + + "|isAsyncSupported=false"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/x/y/t.html HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet2_INVOKED" + + "|servletname=com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet2" + + "|isAsyncSupported=false"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Servlet2APIURL HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, + "Servlet2_INVOKED" + "|servletname=Servlet2API|isAsyncSupported=false"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Servlet2APIURL2 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, + "Servlet2_INVOKED" + "|servletname=Servlet2API|isAsyncSupported=false"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/test2/indext.xml HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, + "Servlet2_INVOKED" + "|servletname=Servlet2API|isAsyncSupported=false"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/ServletAPIURL2/xyz HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet2_INVOKED" + + "|servletname=Servlet2API" + "|isAsyncSupported=false"); + invoke(); + } + + /* + * @testName: test3 + * + * @assertion_ids: Servlet:SPEC:221; Servlet:SPEC:221.1; Servlet:SPEC:221.2; + * Servlet:SPEC:221.3; Servlet:SPEC:221.4; Servlet:SPEC:221.7; + * Servlet:SPEC:221.9; Servlet:SPEC:221.10; Servlet:JAVADOC:819; + * Servlet:JAVADOC:822; Servlet:JAVADOC:825; + * + * @test_Strategy: Create a servlet Servlet3; Define Servlet3 using annotation + * + * @WebServlet(value="", initParams={}, name="") Add Servlet3 to + * ServletContext programmatically under different name; Invoke Servlet3 at + * the URL specified by @WebServlet; Verify that it is properly invoked; + * Invoke Servlet3 at the URL specified by program; Veriy Servlet3 is invoked + * and -- value is set correctly -- all @initParams are passed correctly. -- + * servlet name is set correctly + */ + @Test + public void test3() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Servlet3URL HTTP/1.1"); + TEST_PROPS.setProperty(UNORDERED_SEARCH_STRING, + "Servlet3_INVOKED|initParams:" + "|name1=value1|name2=value2" + + "|servletname=Servlet3" + "|isAsyncSupported=false"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Servlet3APIURL HTTP/1.1"); + TEST_PROPS.setProperty(UNORDERED_SEARCH_STRING, + "Servlet3_INVOKED|initParams:" + "|name1=servlet3|name2=servlet3again" + + "|servletname=Servlet3API" + "|isAsyncSupported=false"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webservletapi/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webservletapi/build.xml new file mode 100644 index 0000000000..c67a64a2ee --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webservletapi/build.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webservletdd/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webservletdd/URLClient.java new file mode 100644 index 0000000000..fb12d15c1c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webservletdd/URLClient.java @@ -0,0 +1,302 @@ +/* + * Copyright (c) 2011, 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:$ + */ +package com.sun.ts.tests.servlet.spec.annotationservlet.webservletdd; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet1; +import com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet2; +import com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet3; +import com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet4; +import com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet5; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_annotationservlet_webservletdd_web.war") + .addClasses(Servlet1.class, Servlet2.class, Servlet3.class, Servlet4.class, Servlet5.class) + .setWebXML(URLClient.class.getResource("servlet_annotationservlet_webservletdd_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + + /* + * @testName: test1 + * + * @assertion_ids: Servlet:SPEC:221; Servlet:SPEC:221.1; Servlet:SPEC:221.2; + * Servlet:SPEC:221.3; Servlet:SPEC:221.6; Servlet:SPEC:221.7; + * Servlet:SPEC:221.8; Servlet:SPEC:221.10; Servlet:JAVADOC:825; + * + * @test_Strategy: Create a servlet Servlet1; Define Servlet1 using + * annotation @WebServlet(String); Define Servlet1 in deployment descritpor + * named as TestServlet1; Invoke Servlet1 at the URL specified by @WebServlet; + * Verify that Servlet1 is invoked properly; Verify that servlet name is set + * correctly; Invoke Servlet1 at the URL specified by deployment descritpor; + * Veriy Servlet1 is invoked properly; Verify that servlet name is set + * correctly; + */ + @Test + public void test1() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Servlet1URL HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet1_INVOKED" + + "|servletname=com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet1" + + "|isAsyncSupported=false"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/TestServlet1 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet1_INVOKED" + + "|servletname=TestServlet1|isAsyncSupported=false"); + invoke(); + } + + /* + * @testName: test2 + * + * @assertion_ids: Servlet:SPEC:221; Servlet:SPEC:221.1; Servlet:SPEC:221.2; + * Servlet:SPEC:221.3; Servlet:SPEC:221.4; Servlet:SPEC:221.6; + * Servlet:SPEC:221.7; Servlet:SPEC:221.8; Servlet:SPEC:221.10; + * Servlet:JAVADOC:825; + * + * @test_Strategy: Create a servlet Servlet2; Define Servlet2 using + * annotation @WebServlet(value=""); Define Servlet2 in deployment descritpor + * as well; Invoke Servlet2 at any of the URLs specified by @WebServlet; + * Verify that Servlet2 is invoked properly; Verify that servlet name is set + * properly; Invoke Servlet2 at the URLs specified by deployment descritpor; + * Veriy Servlet2 is invoked properly; Verify that servlet name is set + * properly; + */ + @Test + public void test2() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Servlet2URL1 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet2_INVOKED" + + "|servletname=com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet2" + + "|isAsyncSupported=false"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Servlet2URL2 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet2_INVOKED" + + "|servletname=com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet2" + + "|isAsyncSupported=false"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/test/xyz HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet2_INVOKED" + + "|servletname=com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet2" + + "|isAsyncSupported=false"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/x/y/t.html HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet2_INVOKED" + + "|servletname=com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet2" + + "|isAsyncSupported=false"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/TestServlet2 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet2_INVOKED" + + "|servletname=TestServlet2|isAsyncSupported=false"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Test2Servlet2 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet2_INVOKED" + + "|servletname=TestServlet2|isAsyncSupported=false"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/test2/indext.html HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet2_INVOKED" + + "|servletname=TestServlet2|isAsyncSupported=false"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/xyz.jsp HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet2_INVOKED" + + "|servletname=TestServlet2|isAsyncSupported=false"); + invoke(); + } + + /* + * @testName: test3 + * + * @assertion_ids: Servlet:SPEC:221; Servlet:SPEC:221.1; Servlet:SPEC:221.2; + * Servlet:SPEC:221.3; Servlet:SPEC:221.4; Servlet:SPEC:221.7; + * Servlet:SPEC:221.8; Servlet:SPEC:221.10; Servlet:JAVADOC:819; + * Servlet:JAVADOC:822; Servlet:JAVADOC:825; + * + * @test_Strategy: Create a servlet Servlet3; Define Servlet3 using annotation + * + * @WebServlet(value="", initParams={}, name="") Define Servlet3 in deployment + * descritpor as well; Invoke Servlet3 at the URL specified by @WebServlet; -- + * value is set correctly -- all @initParams are passed correctly. -- servlet + * name is set correctly Invoke Servlet3 at the URL specified by deployment + * descritpor; Veriy Servlet3 is invoked and -- value is set correctly -- + * all @initParams are passed correctly. -- servlet name is set correctly + */ + @Test + public void test3() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Servlet3URL HTTP/1.1"); + TEST_PROPS.setProperty(UNORDERED_SEARCH_STRING, + "Servlet3_INVOKED|initParams:" + "|name1=value1|name2=value2" + + "|servletname=Servlet3|isAsyncSupported=false"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/TestServlet3 HTTP/1.1"); + TEST_PROPS.setProperty(UNORDERED_SEARCH_STRING, + "Servlet3_INVOKED|initParams:" + "|msg1=first|msg2=ignore" + + "|servletname=TestServlet3|isAsyncSupported=false"); + invoke(); + } + + /* + * @testName: test4 + * + * @assertion_ids: Servlet:SPEC:221; Servlet:SPEC:221.1; Servlet:SPEC:221.2; + * Servlet:SPEC:221.3; Servlet:SPEC:221.4; Servlet:SPEC:221.7; + * Servlet:SPEC:221.8; Servlet:SPEC:221.10; Servlet:JAVADOC:817; + * Servlet:JAVADOC:819; Servlet:JAVADOC:822; Servlet:JAVADOC:825; + * + * @test_Strategy: Create a servlet Servlet4; Define Servlet4 using + * annotation: + * + * @WebServlet(urlPatterns="", asyncSupported = true, initParams={}, name="") + * Define Servlet4 in deployment descritpor as well; Invoke Servlet4 at the + * URLs specified by @WebServlet; Veriy Servlet4 is invoked and -- + * all @initParams are passed correctly. -- servlet name is set correctly -- + * async support is set correctly Invoke Servlet4 at the URL specified by + * deployment descritpor; Veriy Servlet4 is invoked and -- all @initParams are + * passed correctly. -- servlet name is set correctly -- async support is set + * correctly + */ + @Test + public void test4() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Servlet4URL HTTP/1.1"); + TEST_PROPS.setProperty(UNORDERED_SEARCH_STRING, + "Servlet4_INVOKED" + "|ServletName=Servlet4" + "|isAsyncSupported=true" + + "|initParams:|name1=value1|name2=value2"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/TestServlet4 HTTP/1.1"); + TEST_PROPS.setProperty(UNORDERED_SEARCH_STRING, + "Servlet4_INVOKED" + "|ServletName=TestServlet4" + + "|isAsyncSupported=false" + + "|initParams:|msg1=second|msg2=ignore_again"); + invoke(); + } + + /* + * @testName: test5 + * + * @assertion_ids: Servlet:SPEC:221; Servlet:SPEC:221.1; Servlet:SPEC:221.2; + * Servlet:SPEC:221.3; Servlet:SPEC:221.4; Servlet:SPEC:221.6; + * Servlet:SPEC:221.7; Servlet:SPEC:221.8; Servlet:SPEC:221.10; + * Servlet:JAVADOC:825; + * + * @test_Strategy: Create a servlet Servlet5; Define Servlet5 using + * annotation @WebServlet(urlPatterns=""); Define Servlet5 in deployment + * descritpor as well; Invoke Servlet5 at any of the URLs specified + * by @WebServlet; Veriy Servlet5 is invoked properly; Verify that servlet + * name is set correctly; Verify that async support is set correctly; Invoke + * Servlet5 at the URLs specified by deployment descritpor; Veriy Servlet5 is + * invoked properly; Verify that servlet name is set correctly; Verify that + * async support is set correctly; + */ + @Test + public void test5() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Servlet5URL1 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet5_INVOKED" + + "|servletname=com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet5" + + "|isAsyncSupported=false"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Servlet5URL2 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet5_INVOKED" + + "|servletname=com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet5" + + "|isAsyncSupported=false"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/test5/xyz HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet5_INVOKED" + + "|servletname=com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet5" + + "|isAsyncSupported=false"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/x/y/z.txt HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet5_INVOKED" + + "|servletname=com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet5" + + "|isAsyncSupported=false"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/TestServlet5 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, + "Servlet5_INVOKED" + "|servletname=TestServlet5|isAsyncSupported=true"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Test5Servlet5 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, + "Servlet5_INVOKED" + "|servletname=TestServlet5|isAsyncSupported=true"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/test55/xyz HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, + "Servlet5_INVOKED" + "|servletname=TestServlet5|isAsyncSupported=true"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/x/y/z.xml HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, + "Servlet5_INVOKED" + "|servletname=TestServlet5|isAsyncSupported=true"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webservletdd/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webservletdd/build.xml new file mode 100644 index 0000000000..e84234e7ba --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webservletdd/build.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webservletdd/servlet_annotationservlet_webservletdd_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webservletdd/servlet_annotationservlet_webservletdd_web.xml new file mode 100644 index 0000000000..4b888a8896 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/annotationservlet/webservletdd/servlet_annotationservlet_webservletdd_web.xml @@ -0,0 +1,91 @@ + + + + + SerSpecWebServletDD + + TestServlet1 + com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet1 + + + TestServlet2 + com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet2 + + + TestServlet3 + com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet3 + + msg1 + first + + + msg2 + ignore + + + + TestServlet4 + com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet4 + + msg1 + second + + + msg2 + ignore_again + + + + TestServlet5 + com.sun.ts.tests.servlet.spec.annotationservlet.webservlet.Servlet5 + true + + + TestServlet1 + /TestServlet1 + + + TestServlet2 + /TestServlet2 + /Test2Servlet2 + /test2/* + *.jsp + + + TestServlet3 + /TestServlet3 + + + TestServlet4 + /TestServlet4 + + + TestServlet5 + /TestServlet5 + /Test5Servlet5 + /test55/* + *.xml + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Filter10.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Filter10.java new file mode 100644 index 0000000000..09dac776fd --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Filter10.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2009, 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 + */ + +package com.sun.ts.tests.servlet.spec.async; + +import java.io.IOException; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class Filter10 implements Filter { + + public void init(FilterConfig filterConfig) throws ServletException { + // do nothing + } + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + request.setAttribute("Filter10", "INVOKED"); + chain.doFilter(request, response); + } + + public void destroy() { + // do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Filter4.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Filter4.java new file mode 100644 index 0000000000..5c098b9b0a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Filter4.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2009, 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 + */ + +package com.sun.ts.tests.servlet.spec.async; + +import java.io.IOException; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class Filter4 implements Filter { + + public void init(FilterConfig filterConfig) throws ServletException { + // do nothing + } + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + request.setAttribute("Filter4", "INVOKED"); + chain.doFilter(request, response); + } + + public void destroy() { + // do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Filter5.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Filter5.java new file mode 100644 index 0000000000..11849a6b1c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Filter5.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2009, 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 + */ + +package com.sun.ts.tests.servlet.spec.async; + +import java.io.IOException; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class Filter5 implements Filter { + + public void init(FilterConfig filterConfig) throws ServletException { + // do nothing + } + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + request.setAttribute("Filter5", "INVOKED"); + chain.doFilter(request, response); + } + + public void destroy() { + // do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Filter6.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Filter6.java new file mode 100644 index 0000000000..77b11f657d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Filter6.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2009, 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 + */ + +package com.sun.ts.tests.servlet.spec.async; + +import java.io.IOException; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class Filter6 implements Filter { + + public void init(FilterConfig filterConfig) throws ServletException { + // do nothing + } + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + request.setAttribute("Filter6", "INVOKED"); + chain.doFilter(request, response); + } + + public void destroy() { + // do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Filter7.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Filter7.java new file mode 100644 index 0000000000..3c5507d5f1 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Filter7.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2009, 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 + */ + +package com.sun.ts.tests.servlet.spec.async; + +import java.io.IOException; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class Filter7 implements Filter { + + public void init(FilterConfig filterConfig) throws ServletException { + // do nothing + } + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + request.setAttribute("Filter7", "INVOKED"); + chain.doFilter(request, response); + } + + public void destroy() { + // do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Filter8.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Filter8.java new file mode 100644 index 0000000000..f1a674fdb4 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Filter8.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2009, 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 + */ + +package com.sun.ts.tests.servlet.spec.async; + +import java.io.IOException; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class Filter8 implements Filter { + + public void init(FilterConfig filterConfig) throws ServletException { + // do nothing + } + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + request.setAttribute("Filter8", "INVOKED"); + chain.doFilter(request, response); + } + + public void destroy() { + // do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Filter9.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Filter9.java new file mode 100644 index 0000000000..b3b8504523 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Filter9.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2009, 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 + */ + +package com.sun.ts.tests.servlet.spec.async; + +import java.io.IOException; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class Filter9 implements Filter { + + public void init(FilterConfig filterConfig) throws ServletException { + // do nothing + } + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + + request.setAttribute("Filter9", "INVOKED"); + chain.doFilter(request, response); + } + + public void destroy() { + // do nothing + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Servlet1.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Servlet1.java new file mode 100644 index 0000000000..1c26f2b368 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Servlet1.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2009, 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 + */ + +package com.sun.ts.tests.servlet.spec.async; + +import java.io.IOException; +import java.io.PrintWriter; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.GenericServlet; +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class Servlet1 extends GenericServlet { + private static final String TEST_HEADER = "testname"; + + private static final Class[] TEST_ARGS = { ServletRequest.class, + ServletResponse.class }; + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + String test = (String) request.getParameter(TEST_HEADER); + if (test == null) { + test = (String) request.getAttribute(TEST_HEADER); + } + + try { + Method method = this.getClass().getMethod(test, TEST_ARGS); + method.invoke(this, new Object[] { request, response }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + } + + public void direct(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println("Servlet1_Async=" + request.isAsyncSupported()); + } + + public void startA(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + try { + AsyncContext asyncc = request.startAsync(); + asyncc.complete(); + pw.println("Servlet1_Async=STARTED"); + } catch (IllegalStateException ilex) { + pw.println("Servlet1_Async=NOT_STARTED"); + } catch (Exception ex) { + pw.println("Servlet1_Async=FAILED: " + ex.getMessage()); + } + } + + public void teststartA(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println("Servlet1_Async=" + request.isAsyncSupported()); + + String id = (String) request.getParameter("id"); + String path = "/Servlet" + id + "?testname=startA"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + + if (rd == null) { + pw.println("Null RequestDispatcher got for path=" + path); + } else { + rd.forward(request, response); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Servlet10.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Servlet10.java new file mode 100644 index 0000000000..c9dddeea6a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Servlet10.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2009, 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 + */ + +package com.sun.ts.tests.servlet.spec.async; + +import java.io.IOException; +import java.io.PrintWriter; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class Servlet10 extends GenericServlet { + private static final String filter_name = "Filter10"; + + private static final String TEST_HEADER = "testname"; + + private static final Class[] TEST_ARGS = { ServletRequest.class, + ServletResponse.class }; + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + String test = (String) request.getParameter(TEST_HEADER); + if (test == null) { + test = (String) request.getAttribute(TEST_HEADER); + } + + try { + Method method = this.getClass().getMethod(test, TEST_ARGS); + method.invoke(this, new Object[] { request, response }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + } + + public void direct(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println(filter_name + "=" + request.getAttribute(filter_name)); + pw.println("Servlet10_Async=" + request.isAsyncSupported()); + } + + public void startA(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + AsyncContext asyncc = request.startAsync(); + pw.println(filter_name + "=" + request.getAttribute(filter_name)); + pw.println("Servlet10_Async=" + request.isAsyncSupported()); + pw.println("Servlet10_Async=STARTED"); + asyncc.complete(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Servlet2.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Servlet2.java new file mode 100644 index 0000000000..8bbc91ec6a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Servlet2.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2009, 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 + */ + +package com.sun.ts.tests.servlet.spec.async; + +import java.io.IOException; +import java.io.PrintWriter; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class Servlet2 extends GenericServlet { + + private static final String TEST_HEADER = "testname"; + + private static final Class[] TEST_ARGS = { ServletRequest.class, + ServletResponse.class }; + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + String test = (String) request.getParameter(TEST_HEADER); + if (test == null) { + test = (String) request.getAttribute(TEST_HEADER); + } + + try { + Method method = this.getClass().getMethod(test, TEST_ARGS); + method.invoke(this, new Object[] { request, response }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + } + + public void direct(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println("Servlet2_Async=" + request.isAsyncSupported()); + } + + public void startA(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + try { + AsyncContext asyncc = request.startAsync(); + pw.println("Servlet2_Async=STARTED"); + } catch (IllegalStateException ilex) { + pw.println("Servlet2_Async=NOT_STARTED"); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Servlet3.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Servlet3.java new file mode 100644 index 0000000000..8908dca209 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Servlet3.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2009, 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: $ + */ +package com.sun.ts.tests.servlet.spec.async; + +import java.io.IOException; +import java.io.PrintWriter; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class Servlet3 extends GenericServlet { + + private static final String TEST_HEADER = "testname"; + + private static final Class[] TEST_ARGS = { ServletRequest.class, + ServletResponse.class }; + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + String test = (String) request.getParameter(TEST_HEADER); + if (test == null) { + test = (String) request.getAttribute(TEST_HEADER); + } + + try { + Method method = this.getClass().getMethod(test, TEST_ARGS); + method.invoke(this, new Object[] { request, response }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + } + + public void direct(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println("Servlet3_Async=" + request.isAsyncSupported()); + } + + public void startA(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + try { + AsyncContext asyncc = request.startAsync(); + pw.println("Servlet3_Async=STARTED"); + } catch (IllegalStateException ilex) { + pw.println("Servlet3_Async=NOT_STARTED"); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Servlet4.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Servlet4.java new file mode 100644 index 0000000000..5d4337aa64 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Servlet4.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2009, 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 + */ + +package com.sun.ts.tests.servlet.spec.async; + +import java.io.IOException; +import java.io.PrintWriter; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.GenericServlet; +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class Servlet4 extends GenericServlet { + + private static final String filter_name = "Filter4"; + + private static final String TEST_HEADER = "testname"; + + private static final Class[] TEST_ARGS = { ServletRequest.class, + ServletResponse.class }; + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + String test = (String) request.getParameter(TEST_HEADER); + if (test == null) { + test = (String) request.getAttribute(TEST_HEADER); + } + + try { + Method method = this.getClass().getMethod(test, TEST_ARGS); + method.invoke(this, new Object[] { request, response }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + } + + public void direct(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println(filter_name + "=" + request.getAttribute(filter_name)); + pw.println("Servlet4_Async=" + request.isAsyncSupported()); + } + + public void startA(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + try { + response.getWriter() + .println(filter_name + "=" + request.getAttribute(filter_name)); + AsyncContext asyncc = request.startAsync(); + response.getWriter().println("Servlet4_Async=STARTED"); + asyncc.complete(); + } catch (IllegalStateException ilex) { + response.getWriter().println("Servlet4_Async=NOT_STARTED"); + } + } + + public void testdirect(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println(filter_name + "=" + request.getAttribute(filter_name)); + pw.println("Servlet4_Async=" + request.isAsyncSupported()); + + String id = (String) request.getParameter("id"); + String path = "/Servlet" + id + "?testname=direct"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + + if (rd == null) { + pw.println("Null RequestDispatcher got for path=" + path); + } else { + rd.forward(request, response); + } + } + + public void teststartA(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println(filter_name + "=" + request.getAttribute(filter_name)); + pw.println("Servlet4_Async=" + request.isAsyncSupported()); + + String id = (String) request.getParameter("id"); + String path = "/Servlet" + id + "?testname=startA"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + + if (rd == null) { + pw.println("Null RequestDispatcher got for path=" + path); + } else { + rd.forward(request, response); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Servlet5.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Servlet5.java new file mode 100644 index 0000000000..db7d5fc0f7 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Servlet5.java @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2009, 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 + */ + +package com.sun.ts.tests.servlet.spec.async; + +import java.io.IOException; +import java.io.PrintWriter; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.GenericServlet; +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class Servlet5 extends GenericServlet { + + private static final String filter_name = "Filter5"; + + private static final String TEST_HEADER = "testname"; + + private static final Class[] TEST_ARGS = { ServletRequest.class, + ServletResponse.class }; + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + String test = (String) request.getParameter(TEST_HEADER); + if (test == null) { + test = (String) request.getAttribute(TEST_HEADER); + } + + try { + Method method = this.getClass().getMethod(test, TEST_ARGS); + method.invoke(this, new Object[] { request, response }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + } + + public void direct(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println(filter_name + "=" + request.getAttribute(filter_name)); + pw.println("Servlet5_Async=" + request.isAsyncSupported()); + } + + public void startA(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println(filter_name + "=" + request.getAttribute(filter_name)); + pw.println("Servlet5_Async=" + request.isAsyncSupported()); + + try { + AsyncContext asyncc = request.startAsync(); + pw.println("Servlet5_Async=STARTED"); + asyncc.complete(); + } catch (IllegalStateException ilex) { + pw.println("Servlet5_Async=NOT_STARTED"); + } + } + + public void teststartA(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println(filter_name + "=" + request.getAttribute(filter_name)); + pw.println("Servlet5_Async=" + request.isAsyncSupported()); + + String id = request.getParameter("id"); + String path = "/Servlet" + id + "?testname=startA"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + + if (rd == null) { + pw.println("Null RequestDispatcher got for path=" + path); + } else { + rd.forward(request, response); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Servlet6.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Servlet6.java new file mode 100644 index 0000000000..8d3e297a46 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Servlet6.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2009, 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 + */ + +package com.sun.ts.tests.servlet.spec.async; + +import java.io.IOException; +import java.io.PrintWriter; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class Servlet6 extends GenericServlet { + private static final String filter_name = "Filter6"; + + private static final String TEST_HEADER = "testname"; + + private static final Class[] TEST_ARGS = { ServletRequest.class, + ServletResponse.class }; + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + String test = (String) request.getParameter(TEST_HEADER); + if (test == null) { + test = (String) request.getAttribute(TEST_HEADER); + } + + try { + Method method = this.getClass().getMethod(test, TEST_ARGS); + method.invoke(this, new Object[] { request, response }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + } + + public void direct(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println(filter_name + "=" + request.getAttribute(filter_name)); + pw.println("Servlet6_Async=" + request.isAsyncSupported()); + } + + public void startA(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println(filter_name + "=" + request.getAttribute(filter_name)); + pw.println("Servlet6_Async=" + request.isAsyncSupported()); + + try { + AsyncContext asyncc = request.startAsync(); + pw.println("Servlet6_Async=STARTED"); + asyncc.complete(); + } catch (IllegalStateException ilex) { + pw.println("Servlet6_Async=NOT_STARTED"); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Servlet7.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Servlet7.java new file mode 100644 index 0000000000..66cada7bc6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Servlet7.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2009, 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 + */ + +package com.sun.ts.tests.servlet.spec.async; + +import java.io.IOException; +import java.io.PrintWriter; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class Servlet7 extends GenericServlet { + private static final String filter_name = "Filter7"; + + private static final String TEST_HEADER = "testname"; + + private static final Class[] TEST_ARGS = { ServletRequest.class, + ServletResponse.class }; + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + String test = (String) request.getParameter(TEST_HEADER); + if (test == null) { + test = (String) request.getAttribute(TEST_HEADER); + } + + try { + Method method = this.getClass().getMethod(test, TEST_ARGS); + method.invoke(this, new Object[] { request, response }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + } + + public void direct(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println(filter_name + "=" + request.getAttribute(filter_name)); + pw.println("Servlet7_Async=" + request.isAsyncSupported()); + } + + public void startA(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println(filter_name + "=" + request.getAttribute(filter_name)); + pw.println("Servlet7_Async=" + request.isAsyncSupported()); + + try { + AsyncContext asyncc = request.startAsync(); + asyncc.complete(); + pw.println("Servlet7_Async=STARTED"); + } catch (IllegalStateException ilex) { + pw.println("Servlet7_Async=NOT_STARTED"); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Servlet8.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Servlet8.java new file mode 100644 index 0000000000..b07eaa668e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Servlet8.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2009, 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 + */ + +package com.sun.ts.tests.servlet.spec.async; + +import java.io.IOException; +import java.io.PrintWriter; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class Servlet8 extends GenericServlet { + private static final String filter_name = "Filter8"; + + private static final String TEST_HEADER = "testname"; + + private static final Class[] TEST_ARGS = { ServletRequest.class, + ServletResponse.class }; + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + String test = (String) request.getParameter(TEST_HEADER); + if (test == null) { + test = (String) request.getAttribute(TEST_HEADER); + } + + try { + Method method = this.getClass().getMethod(test, TEST_ARGS); + method.invoke(this, new Object[] { request, response }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + } + + public void direct(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println(filter_name + "=" + request.getAttribute(filter_name)); + pw.println("Servlet8_Async=" + request.isAsyncSupported()); + } + + public void startA(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println(filter_name + "=" + request.getAttribute(filter_name)); + pw.println("Servlet8_Async=" + request.isAsyncSupported()); + + try { + AsyncContext asyncc = request.startAsync(); + pw.println("Servlet8_Async=STARTED"); + asyncc.complete(); + } catch (IllegalStateException ilex) { + pw.println("Servlet8_Async=NOT_STARTED"); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Servlet9.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Servlet9.java new file mode 100644 index 0000000000..bde97e70e2 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/Servlet9.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2009, 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 + */ + +package com.sun.ts.tests.servlet.spec.async; + +import java.io.IOException; +import java.io.PrintWriter; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class Servlet9 extends GenericServlet { + private static final String filter_name = "Filter9"; + + private static final String TEST_HEADER = "testname"; + + private static final Class[] TEST_ARGS = { ServletRequest.class, + ServletResponse.class }; + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + String test = (String) request.getParameter(TEST_HEADER); + if (test == null) { + test = (String) request.getAttribute(TEST_HEADER); + } + + try { + Method method = this.getClass().getMethod(test, TEST_ARGS); + method.invoke(this, new Object[] { request, response }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + } + + public void direct(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println(filter_name + "=" + request.getAttribute(filter_name)); + pw.println("Servlet9_Async=" + request.isAsyncSupported()); + } + + public void startA(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println(filter_name + "=" + request.getAttribute(filter_name)); + pw.println("Servlet9_Async=" + request.isAsyncSupported()); + + try { + AsyncContext asyncc = request.startAsync(); + pw.println("Servlet9_Async=STARTED"); + asyncc.complete(); + } catch (IllegalStateException ilex) { + pw.println("Servlet9_Async=NOT_STARTED"); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/TestServlet.java new file mode 100644 index 0000000000..317ce853a0 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/TestServlet.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2009, 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: $ + */ +package com.sun.ts.tests.servlet.spec.async; + +import java.io.IOException; +import java.util.Timer; +import java.util.TimerTask; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void test1(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + final AsyncContext ac = request.startAsync(); + + Timer asyncTimer = new Timer("TestTimer", true); + asyncTimer.schedule(new TimerTask() { + + @Override + public void run() { + try { + ac.getResponse().getWriter().println("test1_INVOKED"); + ac.getResponse().getWriter().flush(); + ac.complete(); + } catch (IOException ioe) { + ioe.printStackTrace(); + } + } + }, 1000); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/URLClient.java new file mode 100644 index 0000000000..7ee3143f96 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/URLClient.java @@ -0,0 +1,857 @@ +/* + * Copyright (c) 2009, 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:$ + */ +package com.sun.ts.tests.servlet.spec.async; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_spec_async_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(Filter4.class, Filter5.class, Filter6.class, Filter7.class, Filter8.class, Filter9.class, + Filter10.class, Servlet1.class, Servlet2.class, Servlet3.class, Servlet4.class, Servlet5.class, + Servlet6.class, Servlet7.class, Servlet8.class, Servlet9.class, Servlet10.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_spec_async_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + /* + * @testName: AsyncSupportedTrueTest1 + * + * @assertion_ids: Servlet:JAVADOC:708; + * + * @test_Strategy: Client send request to Servlet1, which is declared + * async-supported=true in web.xml; verifies in Servlet1 that + * request.isAsyncSupported()=true. + */ + @Test + public void AsyncSupportedTrueTest1() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Servlet1?testname=direct HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet1_Async=true"); + invoke(); + } + + /* + * @testName: AsyncSupportedTrueTest2 + * + * @assertion_ids: Servlet:JAVADOC:708; + * + * @test_Strategy: Client send request to Servlet4, which is declared + * async-supported=true in web.xml; Servlet4 has a filter Filter4 associated + * with it which is also declared async-supported=true in web.xml; verifies in + * Servlet4 that request.isAsyncSupported()=true. + */ + @Test + public void AsyncSupportedTrueTest2() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Servlet4?testname=direct HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, + "Filter4=INVOKED|Servlet4_Async=true"); + invoke(); + } + + /* + * @testName: AsyncSupportedTrueTest3 + * + * @assertion_ids: Servlet:JAVADOC:708; + * + * @test_Strategy: Client send request to Servlet4, which is declared + * async-supported=true in web.xml; Servlet4 has a filter Filter4 associated + * with it which is also declared async-supported=true in web.xml; access + * Servlet1 from Servlet4, Servlet1 is declared async-supported=true in + * web.xml; verifies in Servlet1 that request.isAsyncSupported()=true. + */ + @Test + public void AsyncSupportedTrueTest3() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/Servlet4?testname=testdirect&id=1 HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet1_Async=true"); + invoke(); + } + + /* + * @testName: AsyncSupportedTrueTest4 + * + * @assertion_ids: Servlet:JAVADOC:708; + * + * @test_Strategy: Client send request to Servlet4, which is declared + * async-supported=true in web.xml; Servlet4 has a filter Filter4 associated + * with it which is also declared async-supported=true in web.xml; access + * Servlet10 from Servlet4, Servlet10 is declared async-supported=true in + * web.xml; Servlet10 has a filter Filter10 associated with it which is also + * declared async-supported=true in web.xml; verifies in Servlet10 that + * request.isAsyncSupported()=true. + */ + @Test + public void AsyncSupportedTrueTest4() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/Servlet4?testname=testdirect&id=10 HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, + "Filter10=INVOKED|Servlet10_Async=true"); + invoke(); + } + + /* + * @testName: AsyncSupportedFalseTest1 + * + * @assertion_ids: Servlet:JAVADOC:708; + * + * @test_Strategy: Client send request to Servlet2, which is not declared + * async-supported in web.xml; verifies in Servlet2 that + * request.isAsyncSupported()=false. + */ + @Test + public void AsyncSupportedFalseTest1() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Servlet2?testname=direct HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet2_Async=false"); + invoke(); + } + + /* + * @testName: AsyncSupportedFalseTest2 + * + * @assertion_ids: Servlet:JAVADOC:708; + * + * @test_Strategy: Client send request to Servlet3, which is declared + * async-supported=false in web.xml; verifies in Servlet3 that + * request.isAsyncSupported()=false. + */ + @Test + public void AsyncSupportedFalseTest2() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Servlet3?testname=direct HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet3_Async=false"); + invoke(); + } + + /* + * @testName: AsyncSupportedFalseTest3 + * + * @assertion_ids: Servlet:JAVADOC:708; + * + * @test_Strategy: Client send request to Servlet5, which is declared + * async-supported=true in web.xml; Servlet5 is also associated with Filter5, + * which is declared async-supported=false in web.xml; verifies in Servlet5 + * that request.isAsyncSupported()=false. + */ + @Test + public void AsyncSupportedFalseTest3() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Servlet5?testname=direct HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, + "Filter5=INVOKED|Servlet5_Async=false"); + invoke(); + } + + /* + * @testName: AsyncSupportedFalseTest4 + * + * @assertion_ids: Servlet:JAVADOC:708; + * + * @test_Strategy: Client send request to Servlet6, which is declared + * async-supported=true in web.xml; Servlet6 is also associated with Filter6, + * which is not declared async-supported wise in web.xml; verifies in Servlet6 + * that request.isAsyncSupported()=false. + */ + @Test + public void AsyncSupportedFalseTest4() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Servlet6?testname=direct HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, + "Filter6=INVOKED|Servlet6_Async=false"); + invoke(); + } + + /* + * @testName: AsyncSupportedFalseTest5 + * + * @assertion_ids: Servlet:JAVADOC:708; + * + * @test_Strategy: Client send request to Servlet7, which is declared + * async-supported=false in web.xml; Servlet7 is also associated with Filter7, + * which is declared async-supported=true in web.xml; verifies in Servlet7 + * that request.isAsyncSupported()=false. + */ + @Test + public void AsyncSupportedFalseTest5() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Servlet7?testname=direct HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, + "Filter7=INVOKED|Servlet7_Async=false"); + invoke(); + } + + /* + * @testName: AsyncSupportedFalseTest6 + * + * @assertion_ids: Servlet:JAVADOC:708; + * + * @test_Strategy: Client send request to Servlet8, which is declared + * async-supported=false in web.xml; Servlet5 is also associated with Filter8, + * which is declared async-supported=false in web.xml; verifies in Servlet8 + * that request.isAsyncSupported()=false. + */ + @Test + public void AsyncSupportedFalseTest6() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Servlet8?testname=direct HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, + "Filter8=INVOKED|Servlet8_Async=false"); + invoke(); + } + + /* + * @testName: AsyncSupportedFalseTest7 + * + * @assertion_ids: Servlet:JAVADOC:708; + * + * @test_Strategy: Client send request to Servlet9, which is declared + * async-supported=false in web.xml; Servlet9 is also associated with Filter9, + * which is not declared async-supported wise in web.xml; verifies in Servlet9 + * that request.isAsyncSupported()=false. + */ + @Test + public void AsyncSupportedFalseTest7() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Servlet9?testname=direct HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, + "Filter9=INVOKED|Servlet9_Async=false"); + invoke(); + } + + /* + * @testName: AsyncSupportedFalseTest8 + * + * @assertion_ids: Servlet:JAVADOC:708; + * + * @test_Strategy: Client send request to Servlet4, which is declared + * async-supported=true in web.xml; Servlet4 is also associated with Filter4; + * which is declared async-supported=true in web.xml; send request to Servlet2 + * in Servlet4; Servlet2 is not declared async-supported wise in web.xml; + * verifies in Servlet2 that request.isAsyncSupported()=false. + */ + @Test + public void AsyncSupportedFalseTest8() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/Servlet4?testname=testdirect&id=2 HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet2_Async=false"); + invoke(); + } + + /* + * @testName: AsyncSupportedFalseTest9 + * + * @assertion_ids: Servlet:JAVADOC:708; + * + * @test_Strategy: Client send request to Servlet4, which is declared + * async-supported=true in web.xml; Servlet4 is also associated with Filter4; + * which is declared async-supported=true in web.xml; send request to Servlet3 + * in Servlet4; Servlet3 is declared async-supported=false in web.xml; + * verifies in Servlet3 that request.isAsyncSupported()=false. + */ + @Test + public void AsyncSupportedFalseTest9() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/Servlet4?testname=testdirect&id=3 HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet3_Async=false"); + invoke(); + } + + /* + * @testName: AsyncSupportedFalseTest10 + * + * @assertion_ids: Servlet:JAVADOC:708; + * + * @test_Strategy: Client send request to Servlet4, which is declared + * async-supported=true in web.xml; Servlet4 is also associated with Filter4; + * which is declared async-supported=true in web.xml; send request to Servlet5 + * in Servlet4; Servlet5 is declared async-supported=true in web.xml; Servlet5 + * is also associated with Filter5; which is declared async-supported=false in + * web.xml; verifies in Servlet5 that request.isAsyncSupported()=false. + */ + @Test + public void AsyncSupportedFalseTest10() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/Servlet4?testname=testdirect&id=5 HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet5_Async=false"); + invoke(); + } + + /* + * @testName: StartAsyncTest1 + * + * @assertion_ids: Servlet:JAVADOC:710; Servlet:JAVADOC:638; + * + * @test_Strategy: Client send request to Servlet1, which is declared + * async-supported=true in web.xml; call startAsync() in Servlet1, verifies + * that AsyncContext start and complete. + */ + @Test + public void StartAsyncTest1() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Servlet1?testname=startA HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet1_Async=STARTED"); + invoke(); + } + + /* + * @testName: StartAsyncTest2 + * + * @assertion_ids: Servlet:JAVADOC:711; + * + * @test_Strategy: Client send request to Servlet2, which is declared + * async-supported=false in web.xml; call startAsync() in Servlet2, verifies + * that startAsync causes IllegalStateException thrown. + */ + @Test + public void StartAsyncTest2() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Servlet2?testname=startA HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet2_Async=NOT_STARTED"); + invoke(); + } + + /* + * @testName: StartAsyncTest3 + * + * @assertion_ids: Servlet:JAVADOC:711; + * + * @test_Strategy: Client send request to Servlet3, which is not declared in + * web.xml about support for async; call startAsync() in Servlet3, verifies + * that startAsync causes IllegalStateException thrown. + */ + @Test + public void StartAsyncTest3() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Servlet3?testname=startA HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet3_Async=NOT_STARTED"); + invoke(); + } + + /* + * @testName: StartAsyncTest4 + * + * @assertion_ids: Servlet:JAVADOC:710; Servlet:JAVADOC:638; + * + * @test_Strategy: Client send request to Servlet4, which is declared + * async-supported=true in web.xml; Servlet4 has a filter Filter4 associated + * with it which is also declared async-supported=true in web.xml; call + * startAsync() in Servlet4, verifies that AsyncContext start and complete. + */ + @Test + public void StartAsyncTest4() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Servlet4?testname=startA HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, + "Filter4=INVOKED|Servlet4_Async=STARTED"); + invoke(); + } + + /* + * @testName: StartAsyncTest5 + * + * @assertion_ids: Servlet:JAVADOC:711; + * + * @test_Strategy: Client send request to Servlet5, which is declared + * async-supported=true in web.xml; Servlet5 has a filter Filter5 associated + * with it which is declared async-supported=false in web.xml; call + * startAsync() in Servlet5, verifies that startAsync causes + * IllegalStateException thrown. + */ + @Test + public void StartAsyncTest5() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Servlet5?testname=startA HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, + "Filter5=INVOKED|Servlet5_Async=NOT_STARTED"); + invoke(); + } + + /* + * @testName: StartAsyncTest6 + * + * @assertion_ids: Servlet:JAVADOC:711; + * + * @test_Strategy: Client send request to Servlet6, which is declared + * async-supported=true in web.xml; Servlet6 has a filter Filter6 associated + * with it which is not declared async-supported wise in web.xml; call + * startAsync() in Servlet6, verifies that startAsync causes + * IllegalStateException thrown. + */ + @Test + public void StartAsyncTest6() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Servlet6?testname=startA HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, + "Filter6=INVOKED|Servlet6_Async=NOT_STARTED"); + invoke(); + } + + /* + * @testName: StartAsyncTest7 + * + * @assertion_ids: Servlet:JAVADOC:711; + * + * @test_Strategy: Client send request to Servlet7, which is declared + * async-supported=false in web.xml; Servlet7 has a filter Filter7 associated + * with it which is declared async-supported=true in web.xml; call + * startAsync() in Servlet7, verifies that startAsync causes + * IllegalStateException thrown. + */ + @Test + public void StartAsyncTest7() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Servlet7?testname=startA HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, + "Filter7=INVOKED|Servlet7_Async=NOT_STARTED"); + invoke(); + } + + /* + * @testName: StartAsyncTest8 + * + * @assertion_ids: Servlet:JAVADOC:638; Servlet:JAVADOC:643; + * Servlet:JAVADOC:710; + * + * @test_Strategy: Client send request to Servlet4, which is declared + * async-supported=true in web.xml; Servlet4 has a filter Filter4 associated + * with it which is declared async-supported=true in web.xml; send request to + * Servlet1 in Servlet4; Servlet1 is declared async-supported=true in web.xml; + * verifies in Servlet1 that startAsync and complete runs. + */ + @Test + public void StartAsyncTest8() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/Servlet4?testname=teststartA&id=1 HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet1_Async=STARTED"); + invoke(); + } + + /* + * @testName: StartAsyncTest9 + * + * @assertion_ids: Servlet:JAVADOC:711; + * + * @test_Strategy: Client send request to Servlet4, which is declared + * async-supported=true in web.xml; Servlet4 has a filter Filter4 associated + * with it which is declared async-supported=true in web.xml; send request to + * Servlet2 in Servlet4; Servlet2 is not declared async-supported wise in + * web.xml; verifiy in Servlet2 that startAsync causes IllegalStateException + * thrown. + */ + @Test + public void StartAsyncTest9() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/Servlet4?testname=teststartA&id=2 HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet2_Async=NOT_STARTED"); + invoke(); + } + + /* + * @testName: StartAsyncTest10 + * + * @assertion_ids: Servlet:JAVADOC:711; + * + * @test_Strategy: Client send request to Servlet4, which is declared + * async-supported=true in web.xml; Servlet4 has a filter Filter4 associated + * with it which is declared async-supported=true in web.xml; send request to + * Servlet3 in Servlet4; Servlet3 is declared async-supported=false in + * web.xml; verifies in Servlet3 that startAsync causes IllegalStateException + * thrown. + */ + @Test + public void StartAsyncTest10() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/Servlet4?testname=teststartA&id=3 HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet3_Async=NOT_STARTED"); + invoke(); + } + + /* + * @testName: StartAsyncTest11 + * + * @assertion_ids: Servlet:JAVADOC:710; Servlet:JAVADOC:638; + * + * @test_Strategy: Client send request to Servlet4, which is declared + * async-supported=true in web.xml; Servlet4 has a filter Filter4 associated + * with it which is declared async-supported=true in web.xml; send request to + * Servlet10 in Servlet4; Servlet10 is declared async-supported=true in + * web.xml; Servlet10 has a filter Filter10 associated with it which is also + * declared async-supported=true in web.xml; verifies in Servlet10 that + * startAsync and complete run. + */ + @Test + public void StartAsyncTest11() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/Servlet4?testname=teststartA&id=10 HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet10_Async=STARTED"); + invoke(); + } + + /* + * @testName: StartAsyncTest12 + * + * @assertion_ids: Servlet:JAVADOC:711; + * + * @test_Strategy: Client send request to Servlet4, which is declared + * async-supported=true in web.xml; Servlet4 has a filter Filter4 associated + * with it which is declared async-supported=true in web.xml; send request to + * Servlet5 in Servlet4; Servlet5 is declared async-supported=true in web.xml; + * Servlet5 has a filter Filter5 associated with it which is also declared + * async-supported=false in web.xml; verifies in Servlet5 that startAsync + * causes IllegalStateException thrown. + */ + @Test + public void StartAsyncTest12() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/Servlet4?testname=teststartA&id=5 HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, + "Filter5=INVOKED|Servlet5_Async=false" + "|Servlet5_Async=NOT_STARTED"); + invoke(); + } + + /* + * @testName: StartAsyncTest13 + * + * @assertion_ids: Servlet:JAVADOC:711; + * + * @test_Strategy: Client send request to Servlet4, which is declared + * async-supported=true in web.xml; Servlet4 has a filter Filter4 associated + * with it which is declared async-supported=true in web.xml; send request to + * Servlet6 in Servlet4; Servlet6 is not declared async-supported wise in + * web.xml; Servlet6 has a filter Filter6 associated with it which is declared + * async-supported=true in web.xml; verifies in Servlet6 that startAsync + * causes IllegalStateException thrown. + */ + @Test + public void StartAsyncTest13() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/Servlet4?testname=teststartA&id=6 HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, + "Filter6=INVOKED|Servlet6_Async=false" + "|Servlet6_Async=NOT_STARTED"); + invoke(); + } + + /* + * @testName: StartAsyncTest14 + * + * @assertion_ids: Servlet:JAVADOC:711; + * + * @test_Strategy: Client send request to Servlet4, which is declared + * async-supported=true in web.xml; Servlet4 has a filter Filter4 associated + * with it which is declared async-supported=true in web.xml; send request to + * Servlet7 in Servlet4; Servlet7 is declared async-supported=false in + * web.xml; Servlet7 has a filter Filter7 associated with it which is declared + * async-supported=true in web.xml; verifies in Servlet7 that startAsync + * causes IllegalStateException thrown. + */ + @Test + public void StartAsyncTest14() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/Servlet4?testname=teststartA&id=7 HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, + "Filter7=INVOKED|Servlet7_Async=false" + "|Servlet7_Async=NOT_STARTED"); + invoke(); + } + + /* + * @testName: StartAsyncTest15 + * + * @assertion_ids: Servlet:JAVADOC:711; + * + * @test_Strategy: Client send request to Servlet4, which is declared + * async-supported=true in web.xml; Servlet4 has a filter Filter4 associated + * with it which is declared async-supported=false in web.xml; send request to + * Servlet8 in Servlet4; Servlet8 is declared async-supported=false in + * web.xml; Servlet8 has a filter Filter8 associated with it which is declared + * async-supported=false in web.xml; verifies in Servlet8 that startAsync + * causes IllegalStateException thrown. + */ + @Test + public void StartAsyncTest15() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/Servlet4?testname=teststartA&id=8 HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, + "Filter8=INVOKED|Servlet8_Async=false" + "|Servlet8_Async=NOT_STARTED"); + invoke(); + } + + /* + * @testName: StartAsyncTest16 + * + * @assertion_ids: Servlet:JAVADOC:711; + * + * @test_Strategy: Client send request to Servlet4, which is declared + * async-supported=true in web.xml; Servlet4 has a filter Filter4 associated + * with it which is declared async-supported=true in web.xml; send request to + * Servlet9 in Servlet4; Servlet9 is declared async-supported=false in + * web.xml; Servlet9 has a filter Filter9 associated with it which is + * undeclared async-supported wise in web.xml; verifies in Servlet9 that + * startAsync causes IllegalStateException thrown. + */ + @Test + public void StartAsyncTest16() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/Servlet4?testname=teststartA&id=9 HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, + "Filter9=INVOKED|Servlet9_Async=false" + "|Servlet9_Async=NOT_STARTED"); + invoke(); + } + + /* + * @testName: StartAsyncTest17 + * + * @assertion_ids: Servlet:JAVADOC:711; + * + * @test_Strategy: Client send request to Servlet5, which is declared + * async-supported=true in web.xml; Servlet5 has a filter Filter5 associated + * with it which is declared async-supported=false in web.xml; send request to + * Servlet1 in Servlet5; Servlet1 is declared async-supported=true in web.xml; + * verifies in Servlet1 startAsync causes IllegalStateException thrown. + */ + @Test + public void StartAsyncTest17() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/Servlet5?testname=teststartA&id=1 HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet1_Async=NOT_STARTED"); + invoke(); + } + + /* + * @testName: StartAsyncTest18 + * + * @assertion_ids: Servlet:JAVADOC:711; + * + * @test_Strategy: Client send request to Servlet5, which is declared + * async-supported=true in web.xml; Servlet5 has a filter Filter5 associated + * with it which is declared async-supported=false in web.xml; send request to + * Servlet2 in Servlet5; Servlet2 is not declared async-supported wise in + * web.xml; verifiy in Servlet2 that startAsync causes IllegalStateException + * thrown. + */ + @Test + public void StartAsyncTest18() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/Servlet5?testname=teststartA&id=2 HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet2_Async=NOT_STARTED"); + invoke(); + } + + /* + * @testName: StartAsyncTest19 + * + * @assertion_ids: Servlet:JAVADOC:711; + * + * @test_Strategy: Client send request to Servlet5, which is declared + * async-supported=true in web.xml; Servlet5 has a filter Filter5 associated + * with it which is declared async-supported=false in web.xml; send request to + * Servlet3 in Servlet5; Servlet3 is declared async-supported=false in + * web.xml; verifies in Servlet3 that startAsync causes IllegalStateException + * thrown. + */ + @Test + public void StartAsyncTest19() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/Servlet5?testname=teststartA&id=3 HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, "Servlet3_Async=NOT_STARTED"); + invoke(); + } + + /* + * @testName: StartAsyncTest20 + * + * @assertion_ids: Servlet:JAVADOC:711; + * + * @test_Strategy: Client send request to Servlet5, which is declared + * async-supported=true in web.xml; Servlet5 has a filter Filter5 associated + * with it which is declared async-supported=false in web.xml; send request to + * Servlet4 in Servlet5; Servlet4 is declared async-supported=true in web.xml; + * Servlet4 has a filter Filter4 associated with it which is also declared + * async-supported=true in web.xml; verifies in Servlet4 that + * IllegalStateException is thrown. + */ + @Test + public void StartAsyncTest20() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/Servlet5?testname=teststartA&id=4 HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, + "Filter4=INVOKED|Servlet4_Async=NOT_STARTED"); + invoke(); + } + + /* + * @testName: StartAsyncTest21 + * + * @assertion_ids: Servlet:JAVADOC:711; + * + * @test_Strategy: Client send request to Servlet5, which is declared + * async-supported=true in web.xml; Servlet5 has a filter Filter5 associated + * with it which is declared async-supported=false in web.xml; send request to + * Servlet6 in Servlet5; Servlet6 is declared async-supported=true in web.xml; + * Servlet6 has a filter Filter6 associated with it which is also declared + * async-supported=false in web.xml; verifies in Servlet6 that startAsync + * causes IllegalStateException thrown. + */ + @Test + public void StartAsyncTest21() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/Servlet5?testname=teststartA&id=6 HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, + "Filter6=INVOKED|Servlet6_Async=NOT_STARTED"); + invoke(); + } + + /* + * @testName: StartAsyncTest22 + * + * @assertion_ids: Servlet:JAVADOC:711; + * + * @test_Strategy: Client send request to Servlet5, which is declared + * async-supported=true in web.xml; Servlet5 has a filter Filter5 associated + * with it which is declared async-supported=false in web.xml; send request to + * Servlet7 in Servlet5; Servlet7 is declared async-supported=false in + * web.xml; Servlet7 has a filter Filter7 associated with it which is declared + * async-supported=true in web.xml; verifies in Servlet7 that startAsync + * causes IllegalStateException thrown. + */ + @Test + public void StartAsyncTest22() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/Servlet5?testname=teststartA&id=7 HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, + "Filter7=INVOKED|Servlet7_Async=NOT_STARTED"); + invoke(); + } + + /* + * @testName: StartAsyncTest23 + * + * @assertion_ids: Servlet:JAVADOC:711; + * + * @test_Strategy: Client send request to Servlet5, which is declared + * async-supported=true in web.xml; Servlet5 has a filter Filter5 associated + * with it which is declared async-supported=false in web.xml; send request to + * Servlet8 in Servlet5; Servlet8 is declared async-supported=false in + * web.xml; Servlet8 has a filter Filter8 associated with it which is declared + * async-supported=false in web.xml; verifies in Servlet8 that startAsync + * causes IllegalStateException thrown. + */ + @Test + public void StartAsyncTest23() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/Servlet5?testname=teststartA&id=8 HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, + "Filter8=INVOKED|Servlet8_Async=false|Servlet8_Async=NOT_STARTED"); + invoke(); + } + + /* + * @testName: StartAsyncTest24 + * + * @assertion_ids: Servlet:JAVADOC:711; + * + * @test_Strategy: Client send request to Servlet5, which is declared + * async-supported=true in web.xml; Servlet5 has a filter Filter5 associated + * with it which is declared async-supported=false in web.xml; send request to + * Servlet9 in Servlet5; Servlet9 is declared async-supported=false in + * web.xml; Servlet9 has a filter Filter9 associated with it which is + * undeclared async-supported wise in web.xml; verifies in Servlet9 that + * startAsync causes IllegalStateException thrown. + */ + @Test + public void StartAsyncTest24() throws Exception { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/Servlet5?testname=teststartA&id=9 HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, + "Filter9=INVOKED|Servlet9_Async=NOT_STARTED"); + invoke(); + } + /* + * @testName: StartAsyncTest25 + * + * @assertion_ids: Servlet:JAVADOC:638; Servlet:JAVADOC:643; + * Servlet:JAVADOC:710; + * + * @test_Strategy: Client send request to TestServlet, which is declared + * async-supported=true in web.xml; verifies in TestServlet that startAsync + * completes fine. + */ + @Test + public void StartAsyncTest25() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/TestServlet?testname=test1 HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, "test1_INVOKED"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/build.xml new file mode 100644 index 0000000000..c5de0c00ff --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/build.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/servlet_spec_async_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/servlet_spec_async_web.xml new file mode 100644 index 0000000000..1060f4f0aa --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/async/servlet_spec_async_web.xml @@ -0,0 +1,205 @@ + + + + + ServletSpecAsync + + Filter4 + com.sun.ts.tests.servlet.spec.async.Filter4 + true + + + Filter5 + com.sun.ts.tests.servlet.spec.async.Filter5 + false + + + Filter6 + com.sun.ts.tests.servlet.spec.async.Filter6 + + + Filter7 + com.sun.ts.tests.servlet.spec.async.Filter7 + true + + + Filter8 + com.sun.ts.tests.servlet.spec.async.Filter8 + false + + + Filter9 + com.sun.ts.tests.servlet.spec.async.Filter9 + + + Filter10 + com.sun.ts.tests.servlet.spec.async.Filter10 + true + + + Filter4 + Servlet4 + INCLUDE + FORWARD + REQUEST + + + Filter5 + Servlet5 + INCLUDE + FORWARD + REQUEST + + + Filter6 + Servlet6 + INCLUDE + FORWARD + REQUEST + + + Filter7 + Servlet7 + INCLUDE + FORWARD + REQUEST + + + Filter8 + Servlet8 + INCLUDE + FORWARD + REQUEST + + + Filter9 + Servlet9 + FORWARD + INCLUDE + REQUEST + + + Filter10 + Servlet10 + FORWARD + INCLUDE + REQUEST + + + Servlet1 + com.sun.ts.tests.servlet.spec.async.Servlet1 + true + + + Servlet2 + com.sun.ts.tests.servlet.spec.async.Servlet2 + + + Servlet3 + com.sun.ts.tests.servlet.spec.async.Servlet3 + false + + + Servlet4 + com.sun.ts.tests.servlet.spec.async.Servlet4 + true + + + Servlet5 + com.sun.ts.tests.servlet.spec.async.Servlet5 + true + + + Servlet6 + com.sun.ts.tests.servlet.spec.async.Servlet6 + true + + + Servlet7 + com.sun.ts.tests.servlet.spec.async.Servlet7 + false + + + Servlet8 + com.sun.ts.tests.servlet.spec.async.Servlet8 + false + + + Servlet9 + com.sun.ts.tests.servlet.spec.async.Servlet9 + false + + + Servlet10 + com.sun.ts.tests.servlet.spec.async.Servlet10 + true + + + TestServlet + com.sun.ts.tests.servlet.spec.async.TestServlet + true + + + TestServlet + /TestServlet + + + Servlet1 + /Servlet1 + + + Servlet2 + /Servlet2 + + + Servlet3 + /Servlet3 + + + Servlet4 + /Servlet4 + + + Servlet5 + /Servlet5 + + + Servlet6 + /Servlet6 + + + Servlet7 + /Servlet7 + + + Servlet8 + /Servlet8 + + + Servlet9 + /Servlet9 + + + Servlet10 + /Servlet10 + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/build.xml new file mode 100644 index 0000000000..712115ad01 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/build.xml @@ -0,0 +1,22 @@ + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/defaultcontextpath/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/defaultcontextpath/TestServlet.java new file mode 100644 index 0000000000..16612db0b6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/defaultcontextpath/TestServlet.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017, 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 + */ + +package com.sun.ts.tests.servlet.spec.defaultcontextpath; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + private static final String EXPECTED = "/defaultContextPath"; + + public void getDefaultContextPathTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = true; + PrintWriter pw = response.getWriter(); + String result = this.getServletConfig().getServletContext() + .getContextPath(); + if (!result.equals(EXPECTED)) { + passed = false; + pw.println("Unexpected context path exists: " + result); + } + ServletTestUtil.printResult(pw, passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/defaultcontextpath/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/defaultcontextpath/URLClient.java new file mode 100644 index 0000000000..d223f2737b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/defaultcontextpath/URLClient.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2017, 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 + */ + +package com.sun.ts.tests.servlet.spec.defaultcontextpath; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "defaultContextPath.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_spec_defaultcontextpath_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: getDefaultContextPathTest + * + * @assertion_ids: NA; + * + * @test_Strategy: Create a web application with specified default context + * path, Create a Servlet, verify servletcontext.getContextPath returns the + * expected value; + */ + @Test + public void getDefaultContextPathTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getDefaultContextPathTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/defaultcontextpath/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/defaultcontextpath/build.xml new file mode 100644 index 0000000000..ff9a582153 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/defaultcontextpath/build.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/defaultcontextpath/servlet_spec_defaultcontextpath_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/defaultcontextpath/servlet_spec_defaultcontextpath_web.xml new file mode 100644 index 0000000000..401ea7475e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/defaultcontextpath/servlet_spec_defaultcontextpath_web.xml @@ -0,0 +1,34 @@ + + + + + SerSpecDefaultContextPath + + TestServlet + com.sun.ts.tests.servlet.spec.defaultcontextpath.TestServlet + + + TestServlet + /TestServlet + + /defaultContextPath + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/defaultmapping/TestServlet6.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/defaultmapping/TestServlet6.java new file mode 100644 index 0000000000..a946ca5fb8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/defaultmapping/TestServlet6.java @@ -0,0 +1,39 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.defaultmapping; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet6 extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println("TestServlet6 is invoked"); + pw.println("TestServlet6's URL: /"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/defaultmapping/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/defaultmapping/URLClient.java new file mode 100644 index 0000000000..5be4f12568 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/defaultmapping/URLClient.java @@ -0,0 +1,83 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.defaultmapping; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_spec_defaultmapping_web.war") + .addClasses(TestServlet6.class) + .setWebXML(URLClient.class.getResource("servlet_spec_defaultmapping_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: defaultservletTest1 + * + * @assertion_ids: Servlet:SPEC:134.4; + * + * @test_Strategy: 1. Create servlets TestServlet1 with URL /foo/bar/*, + * TestServlet2 with URL /foo/baR/*, TestServlet3 with URL /TestServlet3, + * TestServlet4 with URL *.bop, TestServlet5 with URL /foo/bar/TestServlet5. + * TestServlet6 with URL / 2. Send request with path /TestServlet3/xyz. 3. + * Verify that TestServlet6 is invoked based on Servlet Spec(11.1) + */ + @Test + public void defaultservletTest1() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "TestServlet6"); + TEST_PROPS.setProperty(APITEST, "TestServlet3/xyz"); + invoke(); + } + + /* + * @testName: defaultservletTest + * + * @assertion_ids: Servlet:SPEC:134.4; + * + * @test_Strategy: 1. Create servlets TestServlet1 with URL /foo/bar/*, + * TestServlet2 with URL /foo/baR/*, TestServlet3 with URL /TestServlet3, + * TestServlet4 with URL *.bop, TestServlet5 with URL /foo/bar/TestServlet5 + * TestServlet6 with URL / 2. Send request with path /test/foo/bar/xxx 3. + * Verify that default Servlet TestServlet6 should be invoked. Since no match + * is found. + */ + @Test + public void defaultservletTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "TestServlet6"); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/test/foo/bar/xxx" + " HTTP/1.1"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/defaultmapping/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/defaultmapping/build.xml new file mode 100644 index 0000000000..c4975e810e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/defaultmapping/build.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/defaultmapping/servlet_spec_defaultmapping_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/defaultmapping/servlet_spec_defaultmapping_web.xml new file mode 100644 index 0000000000..7c5898075b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/defaultmapping/servlet_spec_defaultmapping_web.xml @@ -0,0 +1,73 @@ + + + + + SerJaxSerRequestMap + + TestServlet1 + com.sun.ts.tests.servlet.spec.requestmap.TestServlet1 + + + TestServlet2 + com.sun.ts.tests.servlet.spec.requestmap.TestServlet2 + + + TestServlet3 + com.sun.ts.tests.servlet.spec.requestmap.TestServlet3 + + + TestServlet4 + com.sun.ts.tests.servlet.spec.requestmap.TestServlet4 + + + TestServlet5 + com.sun.ts.tests.servlet.spec.requestmap.TestServlet5 + + + TestServlet6 + com.sun.ts.tests.servlet.spec.defaultmapping.TestServlet6 + + + TestServlet1 + /foo/bar/* + + + TestServlet2 + /foo/baR/* + + + TestServlet3 + /TestServlet3 + + + TestServlet4 + *.bop + + + TestServlet5 + /foo/bar/TestServlet5 + + + TestServlet6 + / + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/dir_struct/ClassFileTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/dir_struct/ClassFileTestServlet.java new file mode 100644 index 0000000000..4775f9990e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/dir_struct/ClassFileTestServlet.java @@ -0,0 +1,76 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2003, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.spec.dir_struct; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class ClassFileTestServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println("in ClassFileTestServlet"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/dir_struct/JarFileTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/dir_struct/JarFileTestServlet.java new file mode 100644 index 0000000000..a6c046516a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/dir_struct/JarFileTestServlet.java @@ -0,0 +1,76 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2002, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.spec.dir_struct; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class JarFileTestServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println("in JarFileTestServlet"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/dir_struct/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/dir_struct/URLClient.java new file mode 100644 index 0000000000..d6054eb0d8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/dir_struct/URLClient.java @@ -0,0 +1,85 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.dir_struct; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_spec_dirstruct_web.war") + .addClasses(ClassFileTestServlet.class, JarFileTestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_spec_dirstruct_web.xml")); + } + + /* Test setup */ + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: loadClassesTest + * + * @assertion_ids: Servlet:SPEC:91 + * + * @test_Strategy: The servlet which is in the WEB-INF/classes directory is + * called by the client and should execute. Then the servlet which is in the + * WEB-INF/lib directory is called by the client and should execute. + * + */ + @Test + public void loadClassesTest() throws Exception { + String testName = "classFileTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "in ClassFileTestServlet"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "in jarFileTestServlet"); + invoke(); + + testName = "jarFileTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "in JarFileTestServlet"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, + "in ClassFileTestServlet"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/dir_struct/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/dir_struct/build.xml new file mode 100644 index 0000000000..f22b9baca0 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/dir_struct/build.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/dir_struct/servlet_spec_dirstruct_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/dir_struct/servlet_spec_dirstruct_web.xml new file mode 100644 index 0000000000..bcb2cd3c5f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/dir_struct/servlet_spec_dirstruct_web.xml @@ -0,0 +1,41 @@ + + + + + SerSpecDirStruct + + classFileTest + com.sun.ts.tests.servlet.spec.dir_struct.ClassFileTestServlet + + + jarFileTest + com.sun.ts.tests.servlet.spec.dir_struct.JarFileTestServlet + + + classFileTest + /classFileTest + + + jarFileTest + /jarFileTest + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/errorpage/SecondServletErrorPage.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/errorpage/SecondServletErrorPage.java new file mode 100644 index 0000000000..9aeb33f0f3 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/errorpage/SecondServletErrorPage.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2007, 2020 Oracle and/or its affiliates and others. + * 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 + */ + +/* + * $URL$ $LastChangedDate$ + */ + +package com.sun.ts.tests.servlet.spec.errorpage; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.Data; + +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +/** + * Simple Servlet-based error page that displays error related req attributes. + */ + +public class SecondServletErrorPage extends HttpServlet { + + private static final String STATUS_CODE = RequestDispatcher.ERROR_STATUS_CODE; // "jakarta.servlet.error.status_code"; + + private static final String EXCEPTION_TYPE = RequestDispatcher.ERROR_EXCEPTION_TYPE; //"jakarta.servlet.error.exception_type"; + + private static final String MESSAGE = RequestDispatcher.ERROR_MESSAGE; //"jakarta.servlet.error.message"; + + private static final String EXCEPTION = RequestDispatcher.ERROR_EXCEPTION; //"jakarta.servlet.error.exception" + + private static final String REQUEST_URI = RequestDispatcher.ERROR_REQUEST_URI; //"jakarta.servlet.error.request_uri"; + + private static final String SERVLET_NAME = RequestDispatcher.ERROR_SERVLET_NAME; //"jakarta.servlet.error.servlet_name" + + private static final String EXP_MESSAGE = "error page invoked"; + + /** + * Invoked by container + */ + @Override + public void service(HttpServletRequest req, HttpServletResponse res) + throws ServletException, IOException { + + PrintWriter pw = res.getWriter(); + pw.println("Second ErrorPage"); + pw.println("Servlet Name: " + req.getAttribute(SERVLET_NAME)); + pw.println("Request URI: " + req.getAttribute(REQUEST_URI)); + pw.println("Status Code: " + req.getAttribute(STATUS_CODE)); + if (req.getAttribute(EXCEPTION_TYPE) == null) { + pw.println("Exception Type: null"); + } else { + // with the cast we even enforce it's a Class type + pw.println("Exception Type: " + ((Class)req.getAttribute(EXCEPTION_TYPE)).getName()); + } + pw.println("Exception: " + req.getAttribute(EXCEPTION)); + pw.print("Message: "); + if (((String) req.getAttribute(MESSAGE)).indexOf(EXP_MESSAGE) > -1) { + pw.println(EXP_MESSAGE); + } else { + pw.println(Data.FAILED); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/errorpage/ServletErrorPage.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/errorpage/ServletErrorPage.java new file mode 100644 index 0000000000..7ea7a1cbd4 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/errorpage/ServletErrorPage.java @@ -0,0 +1,75 @@ +/* + * 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 + */ + +/* + * $URL$ $LastChangedDate$ + */ + +package com.sun.ts.tests.servlet.spec.errorpage; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.Data; + +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +/** + * Simple Servlet-based error page that displays error related req attributes. + */ + +public class ServletErrorPage extends HttpServlet { + + private static final String STATUS_CODE = RequestDispatcher.ERROR_STATUS_CODE; // "jakarta.servlet.error.status_code"; + + private static final String EXCEPTION_TYPE = RequestDispatcher.ERROR_EXCEPTION_TYPE; //"jakarta.servlet.error.exception_type"; + + private static final String MESSAGE = RequestDispatcher.ERROR_MESSAGE; //"jakarta.servlet.error.message"; + + private static final String EXCEPTION = RequestDispatcher.ERROR_EXCEPTION; //"jakarta.servlet.error.exception" + + private static final String REQUEST_URI = RequestDispatcher.ERROR_REQUEST_URI; //"jakarta.servlet.error.request_uri"; + + private static final String SERVLET_NAME = RequestDispatcher.ERROR_SERVLET_NAME; //"jakarta.servlet.error.servlet_name" + + private static final String EXP_MESSAGE = "error page invoked"; + + /** + * Invoked by container + */ + public void service(HttpServletRequest req, HttpServletResponse res) + throws ServletException, IOException { + + PrintWriter pw = res.getWriter(); + pw.println("First ErrorPage"); + pw.println("Servlet Name: " + req.getAttribute(SERVLET_NAME)); + pw.println("Request URI: " + req.getAttribute(REQUEST_URI)); + pw.println("Status Code: " + req.getAttribute(STATUS_CODE)); + // with the cast we even enforce it's a Class type + pw.println("Exception Type: " + ((Class)req.getAttribute(EXCEPTION_TYPE)).getName()); + pw.println("Exception: " + req.getAttribute(EXCEPTION)); + pw.print("Message: "); + if (((String) req.getAttribute(MESSAGE)).indexOf(EXP_MESSAGE) > -1) { + pw.println(EXP_MESSAGE); + } else { + pw.println(Data.FAILED); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/errorpage/TestException.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/errorpage/TestException.java new file mode 100644 index 0000000000..291639a399 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/errorpage/TestException.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2018 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 + */ + +package com.sun.ts.tests.servlet.spec.errorpage; + +/** + * Generic exception class to use for testing error page assertions. + */ + +public class TestException extends Exception { + + /** + * Construct an exception with no associated message. + */ + public TestException() { + super(); + } + + /** + * Construct an exception with the associated message. + * + * @param message + * The associated message + */ + public TestException(String message) { + super(message); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/errorpage/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/errorpage/TestServlet.java new file mode 100644 index 0000000000..3ba7d65e1c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/errorpage/TestServlet.java @@ -0,0 +1,65 @@ +/* + * 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 + */ + +/* + * $URL$ $LastChangedDate$ + */ + +package com.sun.ts.tests.servlet.spec.errorpage; + +import java.io.IOException; + +import com.sun.ts.tests.servlet.common.servlets.HttpTCKServlet; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class TestServlet extends HttpTCKServlet { + + public void init(ServletConfig config) throws ServletException { + super.init(config); + } + + public void destroy() { + super.destroy(); + } + + // ------------------------------------------------- Test Methods + + public void htmlErrorPageTest(HttpServletRequest req, HttpServletResponse res) + throws ServletException, IllegalAccessException { + throw new IllegalAccessException("error page invoked"); + } + + public void servletErrorPageTest(HttpServletRequest req, + HttpServletResponse res) throws ServletException, InstantiationException { + throw new IllegalStateException("error page invoked"); + } + + public void statusCodeErrorPageTest(HttpServletRequest req, + HttpServletResponse res) throws ServletException, IOException { + res.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "error page invoked"); + } + + public void heirarchyErrorMatchTest(HttpServletRequest req, + HttpServletResponse res) + throws ServletException, IllegalThreadStateException { + throw new IllegalThreadStateException("error page invoked"); + } + +}// ErrorPageTestServlet diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/errorpage/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/errorpage/URLClient.java new file mode 100644 index 0000000000..133179449f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/errorpage/URLClient.java @@ -0,0 +1,156 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.errorpage; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.common.util.Data; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_spec_errorpage_web.war") + .addAsWebResource("spec/errorpage/HTMLErrorPage.html","HTMLErrorPage.html") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(SecondServletErrorPage.class, ServletErrorPage.class, TestException.class, TestServlet.class, + WrappedException.class) + .setWebXML(URLClient.class.getResource("servlet_spec_errorpage_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + + /* + * @testName: servletToDifferentErrorPagesTest + * + * @assertion_ids: Servlet:SPEC:108; Servlet:SPEC:106; Servlet:SPEC:104.3.1; + * Servlet:SPEC:104.3.2; Servlet:SPEC:104.3.3; Servlet:SPEC:104.3.4; + * Servlet:SPEC:104.3.5; Servlet:SPEC:104.3.6; + * + * @test_Strategy: Servlet throws two exceptions which is caught by two error + * pages; one is a servlet; thother HTML page + */ + @Test + public void servletToDifferentErrorPagesTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "servletErrorPageTest"); + TEST_PROPS.setProperty(STATUS_CODE, INTERNAL_SERVER_ERROR); + TEST_PROPS.setProperty(SEARCH_STRING, + "Servlet Name: TestServlet|Request URI: /servlet_spec_errorpage_web/TestServlet|Status Code: 500|Exception Type: java.lang.IllegalStateException|Exception: java.lang.IllegalStateException: error page invoked|Message: error page invoked"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, Data.FAILED); + invoke(); + + TEST_PROPS.setProperty(APITEST, "htmlErrorPageTest"); + TEST_PROPS.setProperty(STATUS_CODE, INTERNAL_SERVER_ERROR); + TEST_PROPS.setProperty(SEARCH_STRING, + "||HTML Error Page|||Error page mechanism invoked.||"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, Data.FAILED); + invoke(); + } + + /* + * @testName: statusCodeErrorPageTest + * + * @assertion_ids: Servlet:SPEC:109; Servlet:SPEC:105; Servlet:SPEC:104.3.1; + * Servlet:SPEC:104.3.5; Servlet:SPEC:104.3.6; + * + * @test_Strategy: Servlet uses SendError and the Error Page should be invoked + * with the appropriate info regarding the error + */ + @Test + public void statusCodeErrorPageTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "statusCodeErrorPageTest"); + TEST_PROPS.setProperty(STATUS_CODE, "501"); + TEST_PROPS.setProperty(SEARCH_STRING, + "Servlet Name: TestServlet|Request URI: /servlet_spec_errorpage_web/TestServlet|Status Code: 501|Exception Type: null|Exception: null|Message: error page invoked"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, Data.FAILED); + invoke(); + } + + /* + * @testName: heirarchyErrorMatchTest + * + * @assertion_ids: Servlet:SPEC:108; Servlet:SPEC:106; Servlet:SPEC:104.3.1; + * Servlet:SPEC:104.3.2; Servlet:SPEC:104.3.3; Servlet:SPEC:104.3.4; + * Servlet:SPEC:104.3.5; Servlet:SPEC:104.3.6; + * + * @test_Strategy: Servlet throws IllegalThreadStateException; No error pages + * are defined to deal with IllegalThreadStateException; The closest Exception + * defined to be dealt by error page is java.lang.IllegalStateException; + * Verify this Error Page is invoked with the appropriate info regarding the + * error + */ + @Test + public void heirarchyErrorMatchTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "heirarchyErrorMatchTest"); + TEST_PROPS.setProperty(STATUS_CODE, INTERNAL_SERVER_ERROR); + TEST_PROPS.setProperty(SEARCH_STRING, + "Servlet Name: TestServlet|Request URI: /servlet_spec_errorpage_web/TestServlet|Status Code: 500|Exception Type: java.lang.IllegalThreadStateException|Exception: java.lang.IllegalThreadStateException: error page invoked|Message: error page invoked"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, Data.FAILED); + invoke(); + } + + /* + * @testName: wrappedExceptionTest + * + * @assertion_ids: Servlet:SPEC:108; Servlet:SPEC:107; Servlet:SPEC:104.3.1; + * Servlet:SPEC:104.3.2; Servlet:SPEC:104.3.3; Servlet:SPEC:104.3.4; + * Servlet:SPEC:104.3.5; Servlet:SPEC:104.3.6; + * + * @test_Strategy: Servlet throws ServletException which wraps a + * TestException; No error pages are defined to deal with ServletException; + * But there is an error page defined for TestException; Verify this Error + * Page is invoked with the appropriate info regarding the error + */ + @Test + public void wrappedExceptionTest() throws Exception { + String testName = "WrappedException"; + + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(STATUS_CODE, INTERNAL_SERVER_ERROR); + TEST_PROPS.setProperty(SEARCH_STRING, "Second ErrorPage|" + + "Servlet Name: WrappedException|" + + "Request URI: /servlet_spec_errorpage_web/WrappedException|Status Code: 500|" + + "Exception Type: com.sun.ts.tests.servlet.spec.errorpage.TestException|" + + "Exception: com.sun.ts.tests.servlet.spec.errorpage.TestException: error page invoked|Message: error page invoked"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, Data.FAILED); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + testName + " HTTP/1.1"); + invoke(); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/errorpage/WrappedException.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/errorpage/WrappedException.java new file mode 100644 index 0000000000..63c0aeef06 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/errorpage/WrappedException.java @@ -0,0 +1,45 @@ +/* + * 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 + */ + +/* + * $URL$ $LastChangedDate$ + */ + +package com.sun.ts.tests.servlet.spec.errorpage; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class WrappedException extends HttpServlet { + + public void init(ServletConfig config) throws ServletException { + super.init(config); + } + + public void destroy() { + super.destroy(); + } + + // ------------------------------------------------- Test Methods + + public void service(HttpServletRequest req, HttpServletResponse res) + throws ServletException { + throw new ServletException(new TestException("error page invoked")); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/errorpage/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/errorpage/build.xml new file mode 100644 index 0000000000..a92ac166dc --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/errorpage/build.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/errorpage/servlet_spec_errorpage_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/errorpage/servlet_spec_errorpage_web.xml new file mode 100644 index 0000000000..fe767729ff --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/errorpage/servlet_spec_errorpage_web.xml @@ -0,0 +1,77 @@ + + + + + servlet_spec_errorpage + + servletErrorPage + com.sun.ts.tests.servlet.spec.errorpage.ServletErrorPage + + + secondServletErrorPage + com.sun.ts.tests.servlet.spec.errorpage.SecondServletErrorPage + + + TestServlet + com.sun.ts.tests.servlet.spec.errorpage.TestServlet + + + WrappedException + com.sun.ts.tests.servlet.spec.errorpage.WrappedException + + + servletErrorPage + /servletErrorPage + + + secondServletErrorPage + /secondServletErrorPage + + + TestServlet + /TestServlet + + + WrappedException + /WrappedException + + + 54 + + + java.lang.IllegalStateException + /servletErrorPage + + + java.lang.IllegalAccessException + /HTMLErrorPage.html + + + java.lang.IllegalArgumentException + /servletErrorPage + + + com.sun.ts.tests.servlet.spec.errorpage.TestException + /secondServletErrorPage + + + 501 + /secondServletErrorPage + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/errorpage1/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/errorpage1/TestServlet.java new file mode 100644 index 0000000000..329786cdd9 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/errorpage1/TestServlet.java @@ -0,0 +1,52 @@ +/* + * 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 + */ + +/* + * $URL$ $LastChangedDate$ + */ + +package com.sun.ts.tests.servlet.spec.errorpage1; + +import com.sun.ts.tests.servlet.common.servlets.HttpTCKServlet; +import com.sun.ts.tests.servlet.spec.errorpage.TestException; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class TestServlet extends HttpTCKServlet { + + public void init(ServletConfig config) throws ServletException { + super.init(config); + } + + public void destroy() { + super.destroy(); + } + + // ------------------------------------------------- Test Methods + + public void nonServletExceptionTest(HttpServletRequest req, + HttpServletResponse res) throws ServletException, InstantiationException { + throw new IllegalStateException("error page invoked"); + } + + public void servletExceptionTest(HttpServletRequest req, + HttpServletResponse res) throws ServletException { + throw new TestServletException(new TestException("error page invoked")); + } +}// ErrorPageTestServlet diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/errorpage1/TestServletException.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/errorpage1/TestServletException.java new file mode 100644 index 0000000000..d5bd72b6ce --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/errorpage1/TestServletException.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018, 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 + */ + +package com.sun.ts.tests.servlet.spec.errorpage1; + +import jakarta.servlet.ServletException; + +public class TestServletException extends ServletException { + + public TestServletException(String message) { + super(message); + } + + public TestServletException(String message, Throwable rootCause) { + super(message, rootCause); + } + + public TestServletException(Throwable rootCause) { + super(rootCause); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/errorpage1/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/errorpage1/URLClient.java new file mode 100644 index 0000000000..b5b65b3054 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/errorpage1/URLClient.java @@ -0,0 +1,113 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.errorpage1; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.common.util.Data; +import com.sun.ts.tests.servlet.spec.errorpage.ServletErrorPage; +import com.sun.ts.tests.servlet.spec.errorpage.SecondServletErrorPage; +import com.sun.ts.tests.servlet.spec.errorpage.TestException; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_spec_errorpage1_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestServlet.class, TestServletException.class, TestException.class, ServletErrorPage.class, + SecondServletErrorPage.class) + .setWebXML(URLClient.class.getResource("servlet_spec_errorpage1_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + + /* + * @testName: nonServletExceptionTest + * + * @assertion_ids: Servlet:SPEC:108; Servlet:SPEC:106; Servlet:SPEC:104.3.1; + * Servlet:SPEC:104.3.2; Servlet:SPEC:104.3.3; Servlet:SPEC:104.3.4; + * Servlet:SPEC:104.3.5; Servlet:SPEC:104.3.6; + * + * @test_Strategy: Servlet throws IllegalStateException; Verify the Error Page + * defined to deal with IllegalStateException is invoked with the appropriate + * info regarding the error + */ + @Test + public void nonServletExceptionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "nonServletExceptionTest"); + TEST_PROPS.setProperty(STATUS_CODE, INTERNAL_SERVER_ERROR); + TEST_PROPS.setProperty(SEARCH_STRING, + "First ErrorPage|" + "Servlet Name: TestServlet|" + + "Request URI: /servlet_spec_errorpage1_web/TestServlet|" + + "Status Code: 500|" + + "Exception: java.lang.IllegalStateException: error page invoked|" + + "Message: error page invoked"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, Data.FAILED); + invoke(); + } + + /* + * @testName: servletExceptionTest + * + * @assertion_ids: Servlet:SPEC:108; Servlet:SPEC:107; Servlet:SPEC:104.3.1; + * Servlet:SPEC:104.3.2; Servlet:SPEC:104.3.3; Servlet:SPEC:104.3.4; + * Servlet:SPEC:104.3.5; Servlet:SPEC:104.3.6; + * + * @test_Strategy: Invoke TestServlet The Servlet throws TestServletException + * which wraps a TestException; --- TestServletException extends + * ServletException; There is an error page defined for TestServletException; + * --- No error pages are defined to deal with TestException; Verify this + * Error Page is invoked with the appropriate info regarding the error + */ + @Test + public void servletExceptionTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "ServletExceptionTest"); + TEST_PROPS.setProperty(STATUS_CODE, INTERNAL_SERVER_ERROR); + TEST_PROPS.setProperty(SEARCH_STRING, "Second ErrorPage|" + + "Servlet Name: TestServlet|" + + "Request URI: /servlet_spec_errorpage1_web/TestServlet|" + + "Status Code: 500|" + + "Exception: com.sun.ts.tests.servlet.spec.errorpage1.TestServletException: |" + + "error page invoked|" + "Message: error page invoked"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, Data.FAILED); + invoke(); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/errorpage1/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/errorpage1/build.xml new file mode 100644 index 0000000000..fc10576bc8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/errorpage1/build.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/errorpage1/servlet_spec_errorpage1_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/errorpage1/servlet_spec_errorpage1_web.xml new file mode 100644 index 0000000000..0cc97e8a01 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/errorpage1/servlet_spec_errorpage1_web.xml @@ -0,0 +1,57 @@ + + + + + servlet_spec_errorpage1 + + servletErrorPage + com.sun.ts.tests.servlet.spec.errorpage.ServletErrorPage + + + secondServletErrorPage + com.sun.ts.tests.servlet.spec.errorpage.SecondServletErrorPage + + + TestServlet + com.sun.ts.tests.servlet.spec.errorpage1.TestServlet + + + servletErrorPage + /servletErrorPage + + + secondServletErrorPage + /secondServletErrorPage + + + TestServlet + /TestServlet + + + 54 + + + com.sun.ts.tests.servlet.spec.errorpage1.TestServletException + /secondServletErrorPage + + + java.lang.IllegalStateException + /servletErrorPage + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/httpservletresponse/HttpTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/httpservletresponse/HttpTestServlet.java new file mode 100644 index 0000000000..c167437be4 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/httpservletresponse/HttpTestServlet.java @@ -0,0 +1,91 @@ +/* + * 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$ + */ + +/* + * %E% %E% + */ + +package com.sun.ts.tests.servlet.spec.httpservletresponse; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.HttpTCKServlet; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class HttpTestServlet extends HttpTCKServlet { + + public void intHeaderTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + response.addIntHeader("header1", 12345); + response.flushBuffer(); + response.addIntHeader("header2", 56789); + } + + public void flushBufferTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + int size = 40; + response.setContentLength(size); + + PrintWriter pw = response.getWriter(); + pw.println("Test PASSED"); + StringBuffer tmp = new StringBuffer(2 * size); + int i = 0; + + while (i < 8) { + tmp = tmp.append("111111111x"); + i = i + 1; + } + pw.println(tmp); + response.addIntHeader("header1", 12345); + } + + public void sendErrorCommitTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + response.sendError(HttpServletResponse.SC_OK, "sendErrorCommitTest"); + response.addIntHeader("header1", 12345); + + pw.println("Test FAILED in sendErrorCommitTest"); + } + + public void sendRedirectClearBufferTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println("Test FAILED in sendRedirectClearBufferTest"); + + response.sendRedirect("/RedirectedTest"); + + } + + public void sendRedirectCommitTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + response.sendRedirect("/RedirectedTest"); + response.addIntHeader("header1", 12345); + + pw.println("Test FAILED in sendRedirectCommitTest"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/httpservletresponse/RedirectedTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/httpservletresponse/RedirectedTestServlet.java new file mode 100644 index 0000000000..30c19eb267 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/httpservletresponse/RedirectedTestServlet.java @@ -0,0 +1,79 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2003, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.spec.httpservletresponse; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class RedirectedTestServlet extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter pw = response.getWriter(); + ServletTestUtil.printResult(pw, true); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/httpservletresponse/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/httpservletresponse/URLClient.java new file mode 100644 index 0000000000..081887ba0f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/httpservletresponse/URLClient.java @@ -0,0 +1,147 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.httpservletresponse; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("HttpTestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_spec_httpservletresponse_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(HttpTestServlet.class, RedirectedTestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_spec_httpservletresponse_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + /* + * @testName: intHeaderTest + * + * @assertion_ids: Servlet:SPEC:33; + * + * @test_Strategy: 1. Call setIntHeader to set header; 2. Commit it and set + * the header again; 3. Verify that only the first header value is set, the + * second set is ignored + */ + @Test + public void intHeaderTest() throws Exception { + TEST_PROPS.setProperty(EXPECTED_HEADERS, "header1: 12345"); + TEST_PROPS.setProperty(UNEXPECTED_HEADERS, "header2: 56789"); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + + getServletName() + "?testname=" + "intHeaderTest" + " HTTP/1.1"); + invoke(); + } + + /* + * @testName: flushBufferTest + * + * @assertion_ids: Servlet:SPEC:32; Servlet:SPEC:33; Servlet:SPEC:42.2; + * + * @test_Strategy: 1. First call setContentLength to set the length of + * content; 2. Then write to the buffer to fill up the buffer. 2. Call + * setIntHeader to set header 3. Verify that the header value is not set, + */ + @Test + public void flushBufferTest() throws Exception { + TEST_PROPS.setProperty(UNEXPECTED_HEADERS, "header1: 12345"); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + + getServletName() + "?testname=" + "flushBufferTest" + " HTTP/1.1"); + invoke(); + } + + /* + * @testName: sendErrorCommitTest + * + * @assertion_ids: Servlet:SPEC:36; Servlet:SPEC:42.3; Servlet:SPEC:41; + * + * @test_Strategy: 1. Call sendError; 2. then setIntHeader to set header 3. + * then write to buffer; 4. Verify that the header value is not set, content + * wrote to buffer is ignored + */ + @Test + public void sendErrorCommitTest() throws Exception { + String testname = "sendErrorCommitTest"; + TEST_PROPS.setProperty(UNEXPECTED_HEADERS, "header1: 12345"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "Test FAILED"); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + + getServletName() + "?testname=" + testname + " HTTP/1.1"); + invoke(); + } + + /* + * @testName: sendRedirectCommitTest + * + * @assertion_ids: Servlet:SPEC:37; Servlet:SPEC:42.4; Servlet:SPEC:40; + * + * @test_Strategy: 1. Call sendRedirect; 2. then setIntHeader to set header 3. + * then write to buffer; 4. Verify that the header value is not set, content + * wrote to buffer is ignored + */ + + @Test + public void sendRedirectCommitTest() throws Exception { + String testname = "sendRedirectCommitTest"; + TEST_PROPS.setProperty(UNEXPECTED_HEADERS, "header1: 12345"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "Test FAILED"); + TEST_PROPS.setProperty(STATUS_CODE, MOVED_TEMPORARY); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + + getServletName() + "?testname=" + testname + " HTTP/1.1"); + invoke(); + } + + /* + * @testName: sendRedirectClearBufferTest + * + * @assertion_ids: Servlet:SPEC:38; + * + * @test_Strategy: 1. First write to buffer 2. Call sendRedirect; 3. Verify + * that content wrote to buffer is cleared + */ + @Test + public void sendRedirectClearBufferTest() throws Exception { + String testname = "sendRedirectClearBufferTest"; + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "Test FAILED"); + TEST_PROPS.setProperty(STATUS_CODE, MOVED_TEMPORARY); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + + getServletName() + "?testname=" + testname + " HTTP/1.1"); + invoke(); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/httpservletresponse/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/httpservletresponse/build.xml new file mode 100644 index 0000000000..8279cbbe0a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/httpservletresponse/build.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/httpservletresponse/servlet_spec_httpservletresponse_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/httpservletresponse/servlet_spec_httpservletresponse_web.xml new file mode 100644 index 0000000000..621dfd3a0b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/httpservletresponse/servlet_spec_httpservletresponse_web.xml @@ -0,0 +1,41 @@ + + + + + SerJaxSerHttpServletResponse + + HttpTestServlet + com.sun.ts.tests.servlet.spec.httpservletresponse.HttpTestServlet + + + RedirectedTest + com.sun.ts.tests.servlet.spec.httpservletresponse.RedirectedTestServlet + + + HttpTestServlet + /HttpTestServlet + + + RedirectedTest + /RedirectedTest/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/i18n/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/i18n/build.xml new file mode 100644 index 0000000000..44f88321ed --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/i18n/build.xml @@ -0,0 +1,22 @@ + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/i18n/encoding/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/i18n/encoding/TestServlet.java new file mode 100644 index 0000000000..0a07d54883 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/i18n/encoding/TestServlet.java @@ -0,0 +1,239 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.spec.i18n.encoding; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Locale; + +import com.sun.ts.tests.servlet.common.servlets.HttpTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class TestServlet extends HttpTCKServlet { + + public void spec1Test(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + boolean passed = true; + + String[] call = { "setContentType", "setLocale", "setCharacterEncoding", + "getWriter", "setCharacterEncoding", "setLocale", }; + String[] actual = new String[6]; + String[] expected = { "utf-16le", "utf-16le", "utf-8", "utf-8", "utf-8", + "utf-8", }; + + try { + // setContentType should set character encoding + response.setContentType("text/html;charset=utf-16le"); + actual[0] = response.getCharacterEncoding(); + + // setLocale should not override explicit character encoding request + response.setLocale(Locale.JAPAN); + actual[1] = response.getCharacterEncoding(); + + // setCharacterEncoding should still be able to change encoding + response.setCharacterEncoding("utf-8"); + actual[2] = response.getCharacterEncoding(); + + // getWriter should freeze the character encoding + PrintWriter pw = response.getWriter(); + actual[3] = response.getCharacterEncoding(); + + // setCharacterEncoding should no longer be able to change the encoding + response.setCharacterEncoding("iso-8859-1"); + actual[4] = response.getCharacterEncoding(); + + // setLocale should not override explicit character encoding request + response.setLocale(Locale.JAPAN); + actual[5] = response.getCharacterEncoding(); + + for (int i = 0; i < actual.length; i++) { + if (!(actual[i].toLowerCase(Locale.US) + .equals(expected[i].toLowerCase(Locale.US)))) { + passed = false; + pw.println("Error: Step:" + i + " - encoding after " + call[i] + + " is " + actual[i] + "; expected " + expected[i]); + } + } + ServletTestUtil.printResult(pw, passed); + } catch (Throwable t) { + throw new ServletException(t); + } + } + + public void spec2Test(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + boolean passed = true; + + String[] call = { "setContentType", "setLocale", "setLocale", + "setContentType", "setCharacterEncoding", "setLocale", "setContentType", + "setCharacterEncoding", "getWriter", "setCharacterEncoding", + "setLocale", }; + String[] actual = new String[11]; + String[] expected = { "iso-8859-1", "euc-jp", "gb18030", "gb18030", "utf-8", + "utf-8", "gb18030", "utf-8", "utf-8", "utf-8", "utf-8", }; + + try { + response.setContentType("text/html"); + actual[0] = response.getCharacterEncoding(); + + // setLocale should change character encoding based on + // locale-encoding-mapping-list + response.setLocale(Locale.JAPAN); + actual[1] = response.getCharacterEncoding(); + + // setLocale should change character encoding based on + // locale-encoding-mapping-list + response.setLocale(Locale.CHINA); + actual[2] = response.getCharacterEncoding(); + + // setContentType here doesn't define character encoding + response.setContentType("text/html"); + actual[3] = response.getCharacterEncoding(); + + // setCharacterEncoding should still be able to change encoding + response.setCharacterEncoding("utf-8"); + actual[4] = response.getCharacterEncoding(); + + // setLocale should not override explicit character encoding request + response.setLocale(Locale.JAPAN); + actual[5] = response.getCharacterEncoding(); + + // setContentType should still be able to change encoding + response.setContentType("text/html;charset=gb18030"); + actual[6] = response.getCharacterEncoding(); + + // setCharacterEncoding should still be able to change encoding + response.setCharacterEncoding("utf-8"); + actual[7] = response.getCharacterEncoding(); + + // getWriter should freeze the character encoding + PrintWriter pw = response.getWriter(); + actual[8] = response.getCharacterEncoding(); + + // setCharacterEncoding should no longer be able to change the encoding + response.setCharacterEncoding("iso-8859-1"); + actual[9] = response.getCharacterEncoding(); + + // setLocale should not override explicit character encoding request + response.setLocale(Locale.JAPAN); + actual[10] = response.getCharacterEncoding(); + + for (int i = 0; i < actual.length; i++) { + if (!(actual[i].toLowerCase(Locale.US) + .equals(expected[i].toLowerCase(Locale.US)))) { + passed = false; + pw.println("Error: Step:" + (i + 1) + " - encoding after " + call[i] + + " is " + actual[i] + "; expected " + expected[i]); + } + } + ServletTestUtil.printResult(pw, passed); + } catch (Throwable t) { + throw new ServletException(t); + } + } + + public void spec3Test(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + boolean passed = true; + + String[] call = { "setContentType", "flushBuffer", "setCharacterEncoding", + "setLocale", "getWriter", }; + String[] actual = new String[5]; + String[] expected = { "iso-8859-1", "iso-8859-1", "iso-8859-1", + "iso-8859-1", "iso-8859-1", }; + try { + // setContentType should set character encoding + response.setContentType("text/html"); + actual[0] = response.getCharacterEncoding(); + + // committing should freeze the character encoding + response.flushBuffer(); + actual[1] = response.getCharacterEncoding(); + + // setCharacterEncoding should no longer be able to change the encoding + response.setCharacterEncoding("utf-8"); + actual[2] = response.getCharacterEncoding(); + + // setLocale should not override explicit character encoding request + response.setLocale(Locale.JAPAN); + actual[3] = response.getCharacterEncoding(); + + // getWriter should freeze the character encoding + PrintWriter pw = response.getWriter(); + actual[4] = response.getCharacterEncoding(); + + for (int i = 0; i < actual.length; i++) { + if (!(actual[i].toLowerCase(Locale.US) + .equals(expected[i].toLowerCase(Locale.US)))) { + passed = false; + pw.println("Error: Step:" + i + " - encoding after " + call[i] + + " is " + actual[i] + "; expected " + expected[i]); + } + } + ServletTestUtil.printResult(pw, passed); + } catch (Throwable t) { + throw new ServletException(t); + } + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/i18n/encoding/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/i18n/encoding/URLClient.java new file mode 100644 index 0000000000..fd8c9f79b9 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/i18n/encoding/URLClient.java @@ -0,0 +1,98 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.i18n.encoding; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_spec_i18n_encoding_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_spec_i18n_encoding_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: spec1Test + * + * @assertion_ids: Servlet:JAVADOC:151; Servlet:JAVADOC:137; + * Servlet:JAVADOC:164; Servlet:JAVADOC:139; + * + * @test_Strategy: + */ + @Test + public void spec1Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "spec1Test"); + invoke(); + } + + /* + * @testName: spec2Test + * + * @assertion_ids: Servlet:JAVADOC:151; Servlet:JAVADOC:137; + * Servlet:JAVADOC:164; Servlet:JAVADOC:139; + * + * @test_Strategy: + */ + @Test + public void spec2Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "spec2Test"); + invoke(); + } + + /* + * @testName: spec3Test + * + * @assertion_ids: Servlet:JAVADOC:151; Servlet:JAVADOC:137; + * Servlet:JAVADOC:164; Servlet:JAVADOC:139; + * + * @test_Strategy: + */ + @Test + public void spec3Test() throws Exception { + TEST_PROPS.setProperty(APITEST, "spec3Test"); + invoke(); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/i18n/encoding/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/i18n/encoding/build.xml new file mode 100644 index 0000000000..e3e9f84a7a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/i18n/encoding/build.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/i18n/encoding/servlet_spec_i18n_encoding_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/i18n/encoding/servlet_spec_i18n_encoding_web.xml new file mode 100644 index 0000000000..0563b80f05 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/i18n/encoding/servlet_spec_i18n_encoding_web.xml @@ -0,0 +1,43 @@ + + + + + SerSpecI18NEncoding + + TestServlet + com.sun.ts.tests.servlet.spec.i18n.encoding.TestServlet + + + TestServlet + /TestServlet/* + + + + ja + euc-jp + + + zh_CN + gb18030 + + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/listenerorder/ServletRequestListener1.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/listenerorder/ServletRequestListener1.java new file mode 100644 index 0000000000..72b8ed4d92 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/listenerorder/ServletRequestListener1.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2009, 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$ + */ + +package com.sun.ts.tests.servlet.spec.listenerorder; + +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletRequestEvent; +import jakarta.servlet.ServletRequestListener; + +public class ServletRequestListener1 implements ServletRequestListener { + + public void requestInitialized(ServletRequestEvent sre) { + ServletRequest sr = sre.getServletRequest(); + if (sr.getAttribute("name_2") != null) { + throw new IllegalStateException( + "Unexpected request attribute name_2 during requestInitialized"); + } + if (sr.getAttribute("name_3") != null) { + throw new IllegalStateException( + "Unexpected request attribute name_3 during requestInitialized"); + } + sr.setAttribute("name_1", "value_1"); + } + + public void requestDestroyed(ServletRequestEvent sre) { + ServletRequest sr = sre.getServletRequest(); + if (sr.getAttribute("name_2") != null) { + throw new IllegalStateException( + "Unexpected request attribute name_2 during requestDestroyed"); + } + if (sr.getAttribute("name_3") != null) { + throw new IllegalStateException( + "Unexpected request attribute name_3 during requestDestroyed"); + } + sr.removeAttribute("name_1"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/listenerorder/ServletRequestListener2.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/listenerorder/ServletRequestListener2.java new file mode 100644 index 0000000000..5f3ccbd409 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/listenerorder/ServletRequestListener2.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2009, 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$ + */ + +package com.sun.ts.tests.servlet.spec.listenerorder; + +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletRequestEvent; +import jakarta.servlet.ServletRequestListener; + +public class ServletRequestListener2 implements ServletRequestListener { + + public void requestInitialized(ServletRequestEvent sre) { + ServletRequest sr = sre.getServletRequest(); + if (sr.getAttribute("name_1") == null) { + throw new IllegalStateException( + "Missing request attribute name_1 during requestInitialized"); + } + if (sr.getAttribute("name_3") != null) { + throw new IllegalStateException( + "Unexpected request attribute name_3 during requestInitialized"); + } + sr.setAttribute("name_2", "value_2"); + } + + public void requestDestroyed(ServletRequestEvent sre) { + ServletRequest sr = sre.getServletRequest(); + if (sr.getAttribute("name_1") == null) { + throw new IllegalStateException( + "Missing request attribute during requestDestroyed"); + } + if (sr.getAttribute("name_3") != null) { + throw new IllegalStateException( + "Unexpected request attribute name_3 during requestInitialized"); + } + sr.removeAttribute("name_2"); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/listenerorder/ServletRequestListener3.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/listenerorder/ServletRequestListener3.java new file mode 100644 index 0000000000..2fef54eaff --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/listenerorder/ServletRequestListener3.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2009, 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$ + */ +package com.sun.ts.tests.servlet.spec.listenerorder; + +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletRequestEvent; +import jakarta.servlet.ServletRequestListener; + +public class ServletRequestListener3 implements ServletRequestListener { + + public void requestInitialized(ServletRequestEvent sre) { + ServletRequest sr = sre.getServletRequest(); + if (sr.getAttribute("name_1") == null) { + throw new IllegalStateException( + "Missing request attribute during requestInitialized"); + } + if (sr.getAttribute("name_2") == null) { + throw new IllegalStateException( + "Missing request attribute during requestInitialized"); + } + sr.setAttribute("name_3", "value_3"); + } + + public void requestDestroyed(ServletRequestEvent sre) { + ServletRequest sr = sre.getServletRequest(); + if (sr.getAttribute("name_1") == null) { + throw new IllegalStateException( + "Missing request attribute during requestDestroyed"); + } + if (sr.getAttribute("name_2") == null) { + throw new IllegalStateException( + "Missing request attribute during requestInitialized"); + } + sr.removeAttribute("name_3"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/listenerorder/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/listenerorder/TestServlet.java new file mode 100644 index 0000000000..eedcaea1f0 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/listenerorder/TestServlet.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2009, 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$ + */ +package com.sun.ts.tests.servlet.spec.listenerorder; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println("TestServlet is invoked"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/listenerorder/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/listenerorder/URLClient.java new file mode 100644 index 0000000000..2661af9ccf --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/listenerorder/URLClient.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2009, 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$ + */ +package com.sun.ts.tests.servlet.spec.listenerorder; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_spec_listenerorder_web.war") + .addClasses(ServletRequestListener1.class, ServletRequestListener2.class, ServletRequestListener3.class, + TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_spec_listenerorder_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* + * @testName: requestListenerOrderTest + * + * @assertion_ids: + * + * @test_Strategy: 1. Define servlet TestServlet in web.xml; 2. Define three + * RequestListeners in web.xml in the order of ServletRequestListener1, + * ServletRequestListener2, ServletRequestListener3; 3. Send request to + * /TestServlet, verify TestServlet is invoked 3. Also verify in all + * RequestListeners that they are invoked in the order declared in web.xml + */ + @Test + public void requestListenerOrderTest() throws Exception { + TEST_PROPS.setProperty(STATUS_CODE, OK); + TEST_PROPS.setProperty(SEARCH_STRING, "TestServlet is invoked"); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/TestServlet" + " HTTP/1.1"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/listenerorder/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/listenerorder/build.xml new file mode 100644 index 0000000000..8a38f8d1e3 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/listenerorder/build.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/listenerorder/servlet_spec_listenerorder_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/listenerorder/servlet_spec_listenerorder_web.xml new file mode 100644 index 0000000000..3cfb30cec1 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/listenerorder/servlet_spec_listenerorder_web.xml @@ -0,0 +1,41 @@ + + + + + + com.sun.ts.tests.servlet.spec.listenerorder.ServletRequestListener1 + + + com.sun.ts.tests.servlet.spec.listenerorder.ServletRequestListener2 + + + com.sun.ts.tests.servlet.spec.listenerorder.ServletRequestListener3 + + + TestServlet + com.sun.ts.tests.servlet.spec.listenerorder.TestServlet + + + TestServlet + /TestServlet + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/multifiltermapping/ErrorPage.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/multifiltermapping/ErrorPage.java new file mode 100644 index 0000000000..0607bbcf92 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/multifiltermapping/ErrorPage.java @@ -0,0 +1,38 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.multifiltermapping; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class ErrorPage extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println("from ErrorPage"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/multifiltermapping/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/multifiltermapping/TestServlet.java new file mode 100644 index 0000000000..f7ef52e343 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/multifiltermapping/TestServlet.java @@ -0,0 +1,61 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.multifiltermapping; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; + +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet extends GenericTCKServlet { + + public void forwardTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + String param = "parameter1"; + PrintWriter pw = response.getWriter(); + String path = request.getParameter(param); + pw.println("path to access: " + path); + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + rd.forward(request, response); + } + + public void includeTest(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + String param = "parameter1"; + PrintWriter pw = response.getWriter(); + String path = request.getParameter(param); + pw.println("path to access: " + path); + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + + try { + rd.include(request, response); + } catch (IOException ex) { + pw.println("Resource " + path + " not available"); + throw new FileNotFoundException("Resource " + path + " not available"); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/multifiltermapping/TestServlet6.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/multifiltermapping/TestServlet6.java new file mode 100644 index 0000000000..aaa17c3a95 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/multifiltermapping/TestServlet6.java @@ -0,0 +1,39 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.multifiltermapping; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet6 extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println("TestServlet6 is invoked"); + pw.println("TestServlet6's URL: "); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/multifiltermapping/TestServlet7.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/multifiltermapping/TestServlet7.java new file mode 100644 index 0000000000..83951d5848 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/multifiltermapping/TestServlet7.java @@ -0,0 +1,47 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.multifiltermapping; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class TestServlet7 extends GenericServlet { + + private static final Logger LOGGER = LoggerFactory.getLogger(TestServlet7.class); + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + if (pw == null) { + LOGGER.info("TestServlet7 is invoked"); + } else { + pw.println("TestServlet7 is invoked"); + pw.println("TestServlet7's URL: /*"); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/multifiltermapping/Test_ErrorFilter.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/multifiltermapping/Test_ErrorFilter.java new file mode 100644 index 0000000000..13602d219b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/multifiltermapping/Test_ErrorFilter.java @@ -0,0 +1,59 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.multifiltermapping; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public final class Test_ErrorFilter implements Filter { + + // The filter configuration object we are associated with. If this value + // is null, this filter instance is not currently configured. + private FilterConfig filterConfig = null; + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + PrintWriter pw = response.getWriter(); + pw.println("in Test_ErrorFilter"); + chain.doFilter(request, response); + } + + // Remove the filter configuration object for this filter. + public void destroy() { + } + + // initialize the filter configuration object for this filter. + public void init(FilterConfig filterConfig) throws ServletException { + if (filterConfig == null) { + throw new ServletException( + "Failed to initialize the filter configuration"); + } else { + this.filterConfig = filterConfig; + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/multifiltermapping/Test_ForwardFilter.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/multifiltermapping/Test_ForwardFilter.java new file mode 100644 index 0000000000..5d9a672547 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/multifiltermapping/Test_ForwardFilter.java @@ -0,0 +1,59 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.multifiltermapping; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public final class Test_ForwardFilter implements Filter { + + // The filter configuration object we are associated with. + // If this value is null, this filter instance is not currently configured. + private FilterConfig filterConfig = null; + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + PrintWriter pw = response.getWriter(); + pw.println("in Test_ForwardFilter"); + chain.doFilter(request, response); + } + + // Remove the filter configuration object for this filter. + public void destroy() { + } + + // initialize the filter configuration object for this filter. + public void init(FilterConfig filterConfig) throws ServletException { + if (filterConfig == null) { + throw new ServletException( + "Failed to initialize the filter configuration"); + } else { + this.filterConfig = filterConfig; + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/multifiltermapping/Test_IncludeFilter.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/multifiltermapping/Test_IncludeFilter.java new file mode 100644 index 0000000000..274e301401 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/multifiltermapping/Test_IncludeFilter.java @@ -0,0 +1,59 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.multifiltermapping; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public final class Test_IncludeFilter implements Filter { + + // The filter configuration object we are associated with. If this value + // is null, this filter instance is not currently configured. + private FilterConfig filterConfig = null; + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + PrintWriter pw = response.getWriter(); + pw.println("in Test_IncludeFilter"); + chain.doFilter(request, response); + } + + // Remove the filter configuration object for this filter. + public void destroy() { + } + + // initialize the filter configuration object for this filter. + public void init(FilterConfig filterConfig) throws ServletException { + if (filterConfig == null) { + throw new ServletException( + "Failed to initialize the filter configuration"); + } else { + this.filterConfig = filterConfig; + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/multifiltermapping/Test_RequestFilter.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/multifiltermapping/Test_RequestFilter.java new file mode 100644 index 0000000000..8abaa01b08 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/multifiltermapping/Test_RequestFilter.java @@ -0,0 +1,59 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.multifiltermapping; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.Filter; +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public final class Test_RequestFilter implements Filter { + + // The filter configuration object we are associated with. If this value + // is null, this filter instance is not currently configured. + private FilterConfig filterConfig = null; + + public void doFilter(ServletRequest request, ServletResponse response, + FilterChain chain) throws IOException, ServletException { + PrintWriter pw = response.getWriter(); + pw.println("in Test_RequestFilter"); + chain.doFilter(request, response); + } + + // Remove the filter configuration object for this filter. + public void destroy() { + } + + // initialize the filter configuration object for this filter. + public void init(FilterConfig filterConfig) throws ServletException { + if (filterConfig == null) { + throw new ServletException( + "Failed to initialize the filter configuration"); + } else { + this.filterConfig = filterConfig; + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/multifiltermapping/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/multifiltermapping/URLClient.java new file mode 100644 index 0000000000..f4dea56a16 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/multifiltermapping/URLClient.java @@ -0,0 +1,313 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.multifiltermapping; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.spec.requestmap.TestServlet1; +import com.sun.ts.tests.servlet.spec.requestmap.TestServlet2; +import com.sun.ts.tests.servlet.spec.requestmap.TestServlet3; +import com.sun.ts.tests.servlet.spec.requestmap.TestServlet4; +import com.sun.ts.tests.servlet.spec.requestmap.TestServlet5; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_spec_multifiltermapping_web.war") + .addAsWebResource("api/jakarta_servlet/filterrequestdispatcher/dummy.html", "dummy.html") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(ErrorPage.class, Test_ErrorFilter.class, Test_ForwardFilter.class, Test_IncludeFilter.class, + TestServlet1.class, TestServlet2.class, TestServlet3.class, TestServlet4.class, TestServlet5.class, + Test_RequestFilter.class, TestServlet.class, TestServlet6.class, TestServlet7.class) + .setWebXML(URLClient.class.getResource("servlet_spec_multifiltermapping_web.xml")); + + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: requestTest + * + * @assertion_ids: Servlet:SPEC:54; Servlet:SPEC:59; + * + * @test_Strategy: 1. Create a web page - /dummy.html. 2. Create servlets + * TestServlet1 with URL /foo/bar/*, TestServlet2 with URL /foo/baR/*, + * TestServlet3 with URL /TestServlet3, TestServlet4 with URL *.bop, + * TestServlet5 with URL /foo/bar/TestServlet5, TestServlet6 with servlet-name + * TestServlet6, 2. Map a filter Test_RequestFilter on all above one web page + * and 6 servlets with dispatcher value set to REQUEST using url-pattern and + * servlet name respectively. 3. Client try to access all of them directly. 4. + * Verify that Test_RequestFilter is properly invoked. + */ + @Test + public void requestTest() throws Exception { + TEST_PROPS.setProperty(DONOTUSEServletName, "true"); + TEST_PROPS.setProperty(SEARCH_STRING, "Test_RequestFilter|TestServlet1"); + TEST_PROPS.setProperty(APITEST, "foo/bar/index.html"); + invoke(); + + TEST_PROPS.setProperty(DONOTUSEServletName, "true"); + TEST_PROPS.setProperty(SEARCH_STRING, "Test_RequestFilter|TestServlet1"); + TEST_PROPS.setProperty(APITEST, "foo/bar"); + invoke(); + + TEST_PROPS.setProperty(APITEST, "foo/baR/TestServlet5"); + TEST_PROPS.setProperty(SEARCH_STRING, "Test_RequestFilter|TestServlet2"); + TEST_PROPS.setProperty(DONOTUSEServletName, "true"); + invoke(); + + TEST_PROPS.setProperty(APITEST, "TestServlet3"); + TEST_PROPS.setProperty(SEARCH_STRING, "Test_RequestFilter|TestServlet3"); + TEST_PROPS.setProperty(DONOTUSEServletName, "true"); + invoke(); + + TEST_PROPS.setProperty(APITEST, "foo/bar/TestServlet5"); + TEST_PROPS.setProperty(SEARCH_STRING, "Test_RequestFilter|TestServlet5"); + TEST_PROPS.setProperty(DONOTUSEServletName, "true"); + invoke(); + + TEST_PROPS.setProperty(APITEST, "test/servletbyname"); + TEST_PROPS.setProperty(SEARCH_STRING, "Test_RequestFilter|TestServlet6"); + TEST_PROPS.setProperty(DONOTUSEServletName, "true"); + invoke(); + + TEST_PROPS.setProperty(APITEST, "dummy.html"); + TEST_PROPS.setProperty(SEARCH_STRING, + "Test_RequestFilter|Test FAILED from dummy html page"); + TEST_PROPS.setProperty(DONOTUSEServletName, "true"); + invoke(); + + TEST_PROPS.setProperty(APITEST, "index.bop"); + TEST_PROPS.setProperty(SEARCH_STRING, "Test_RequestFilter|TestServlet4"); + TEST_PROPS.setProperty(DONOTUSEServletName, "true"); + invoke(); + + TEST_PROPS.setProperty(APITEST, "TestServlet3/racecar.bop"); + TEST_PROPS.setProperty(SEARCH_STRING, "Test_RequestFilter|TestServlet4"); + TEST_PROPS.setProperty(DONOTUSEServletName, "true"); + invoke(); + } + + /* + * @testName: forwardTest + * + * @assertion_ids: Servlet:SPEC:54; + * + * @test_Strategy: 1. Create a web page - /dummy.html. 2. Create servlets + * TestServlet1 with URL /foo/bar/*, TestServlet2 with URL /foo/baR/*, + * TestServlet3 with URL /TestServlet3, TestServlet4 with URL *.bop, + * TestServlet5 with URL /foo/bar/TestServlet5, TestServlet6 with servlet-name + * TestServlet6; 3. Map a filter Test_ForwardFilter on all above one web page + * and 6 servlets with dispatcher value set to FORWARD using url-pattern and + * servlet name respectively. 4. Create a servlet TestServlet. 5. Client send + * request to TestServlet, which access all resources list in 1 and 2 using + * forward. 6. Verify that the filter is invoked properly + */ + @Test + public void forwardTest() throws Exception { + String testName = "forwardTest"; + + TEST_PROPS.setProperty(SEARCH_STRING, "Test_ForwardFilter|TestServlet1"); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + getServletName() + "?testname=" + + testName + "¶meter1=/foo/bar/index.html HTTP/1.1"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + getServletName() + "?testname=" + + testName + "¶meter1=/foo/bar HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Test_ForwardFilter|TestServlet1"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + getServletName() + "?testname=" + + testName + "¶meter1=/foo/baR/TestServlet5 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Test_ForwardFilter|TestServlet2"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + getServletName() + "?testname=" + + testName + "¶meter1=/TestServlet3 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Test_ForwardFilter|TestServlet3"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + getServletName() + "?testname=" + + testName + "¶meter1=/foo/bar/TestServlet5 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Test_ForwardFilter|TestServlet5"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + getServletName() + "?testname=" + + testName + "¶meter1=/test/servletbyname HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Test_ForwardFilter|TestServlet6"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + getServletName() + "?testname=" + + testName + "¶meter1=/dummy.html HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, + "Test_ForwardFilter|Test FAILED from dummy html page"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + getServletName() + "?testname=" + + testName + "¶meter1=/index.bop HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Test_ForwardFilter|TestServlet4"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + getServletName() + "?testname=" + + testName + "¶meter1=/TestServlet3/racecar.bop HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Test_ForwardFilter|TestServlet4"); + invoke(); + } + + /* + * @testName: includeTest + * + * @assertion_ids: Servlet:SPEC:54; + * + * @test_Strategy: 1. Create a web page - /dummy.html. 2. Create servlets + * TestServlet1 with URL /foo/bar/*, TestServlet2 with URL /foo/baR/*, + * TestServlet3 with URL /TestServlet3, TestServlet4 with URL *.bop, + * TestServlet5 with URL /foo/bar/TestServlet5, TestServlet6 with servlet-name + * TestServlet6; 3. Map a filter Test_IncludeFilter on all above one web page + * and 6 servlets with dispatcher value set to INCLUDE using url-pattern and + * servlet name respectively. 4. Create a servlet TestServlet. 5. Client send + * request to TestServlet, which access all resources list in 1 and 2 using + * include. 6. Verify that the filter is invoked properly + */ + @Test + public void includeTest() throws Exception { + String testName = "includeTest"; + String filterString = "Test_IncludeFilter"; + + TEST_PROPS.setProperty(SEARCH_STRING, filterString + "|TestServlet1"); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + getServletName() + "?testname=" + + testName + "¶meter1=/foo/bar/index.html HTTP/1.1"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + getServletName() + "?testname=" + + testName + "¶meter1=/foo/bar HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, filterString + "|TestServlet1"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + getServletName() + "?testname=" + + testName + "¶meter1=/foo/baR/TestServlet5 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, filterString + "|TestServlet2"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + getServletName() + "?testname=" + + testName + "¶meter1=/TestServlet3 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, filterString + "|TestServlet3"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + getServletName() + "?testname=" + + testName + "¶meter1=/foo/bar/TestServlet5 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, filterString + "|TestServlet5"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + getServletName() + "?testname=" + + testName + "¶meter1=/test/servletbyname HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, filterString + "|TestServlet6"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + getServletName() + "?testname=" + + testName + "¶meter1=/dummy.html HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, + filterString + "|Test FAILED from dummy html page"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + getServletName() + "?testname=" + + testName + "¶meter1=/index.bop HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, filterString + "|TestServlet4"); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + getServletName() + "?testname=" + + testName + "¶meter1=/TestServlet3/racecar.bop HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, filterString + "|TestServlet4"); + invoke(); + } + + /* + * @testName: errorTest + * + * @assertion_ids: Servlet:SPEC:57; Servlet:SPEC:59; + * + * @test_Strategy: 1. Create a web page - /dummy.html. 2. Create servlets + * TestServlet1 with URL /foo/bar/*, TestServlet2 with URL /foo/baR/*, + * TestServlet3 with URL /TestServlet3, TestServlet4 with URL *.bop, + * TestServlet5 with URL /foo/bar/TestServlet5, TestServlet6 with servlet-name + * TestServlet6, 3. Map a filter Test_RequestFilter on all above one web page + * and six servlets with dispatcher value set to REQUEST, using url-pattern + * and servlet name respectively. 4. Map a filter Test_ForwardFilter on all + * above one web page and six servlets with dispatcher value set to FORWARD + * using url-pattern and servlet name respectively. 5. Map a filter + * Test_ErrorFilter to an servlet ErrorPage with dispatcher value set to ERROR + * 6. access a resource that dose not match any resource listed in 1 and 2, 7. + * verify that Test_ErrorFilter is properly invoked 8. Create a servlet + * TestServlet. 9. Client send request to TestServlet, which access a resource + * that dose not match any resource listed in 1 and 2 using include and + * forward respectively. 10. Verify that Test_ErrorFilter is properly invoked. + */ + @Test + public void errorTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "test/foo/bar/xyz"); + TEST_PROPS.setProperty(SEARCH_STRING, "Test_ErrorFilter|ErrorPage"); + TEST_PROPS.setProperty(DONOTUSEServletName, "true"); + TEST_PROPS.setProperty(STATUS_CODE, NOT_FOUND); + invoke(); + + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/" + getServletName() + + "?testname=forwardTest" + + "¶meter1=/test/foo/bar/xyz HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Test_ErrorFilter|ErrorPage"); + TEST_PROPS.setProperty(STATUS_CODE, NOT_FOUND); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/multifiltermapping/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/multifiltermapping/build.xml new file mode 100644 index 0000000000..989bbaca43 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/multifiltermapping/build.xml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/multifiltermapping/servlet_spec_multifiltermapping_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/multifiltermapping/servlet_spec_multifiltermapping_web.xml new file mode 100644 index 0000000000..b12f67aeaf --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/multifiltermapping/servlet_spec_multifiltermapping_web.xml @@ -0,0 +1,176 @@ + + + + + SerSpecFilterMapping + + RequestMappedTest_Filter + com.sun.ts.tests.servlet.spec.multifiltermapping.Test_RequestFilter + + attribute + com.sun.ts.tests.servlet.spec.multifiltermapping.Test_RequestFilter.SERVLET_MAPPED + + + + IncludeMappedTest_Filter + com.sun.ts.tests.servlet.spec.multifiltermapping.Test_IncludeFilter + + attribute + com.sun.ts.tests.servlet.spec.multifiltermapping.Test_IncludeFilter.SERVLET_MAPPED + + + + ForwardMappedTest_Filter + com.sun.ts.tests.servlet.spec.multifiltermapping.Test_ForwardFilter + + attribute + com.sun.ts.tests.servlet.spec.multifiltermapping.Test_ForwardFilter.SERVLET_MAPPED + + + + ErrorMappedTest_Filter + com.sun.ts.tests.servlet.spec.multifiltermapping.Test_ErrorFilter + + attribute + com.sun.ts.tests.servlet.spec.multifiltermapping.Test_ErrorFilter.SERVLET_MAPPED + + + + IncludeMappedTest_Filter + /TestServlet3 + *.bop + /* + /foo/bar/TestServlet5 + TestServlet6 + /dummy.html + /foo/bar/* + /foo/baR/* + INCLUDE + + + ErrorMappedTest_Filter + /foo/bar/TestServlet5 + TestServlet6 + /TestServlet3 + *.bop + /dummy.html + /foo/bar/* + /foo/baR/* + ErrorPage + ERROR + + + ForwardMappedTest_Filter + /dummy.html + /foo/bar/* + /foo/baR/* + /* + /TestServlet3 + *.bop + /foo/bar/TestServlet5 + TestServlet6 + FORWARD + + + RequestMappedTest_Filter + TestServlet6 + /dummy.html + /foo/bar/* + /foo/baR/* + /TestServlet3 + *.bop + /foo/bar/TestServlet5 + REQUEST + + + TestServlet + com.sun.ts.tests.servlet.spec.multifiltermapping.TestServlet + + + ErrorPage + com.sun.ts.tests.servlet.spec.multifiltermapping.ErrorPage + + + TestServlet1 + com.sun.ts.tests.servlet.spec.requestmap.TestServlet1 + + + TestServlet2 + com.sun.ts.tests.servlet.spec.requestmap.TestServlet2 + + + TestServlet3 + com.sun.ts.tests.servlet.spec.requestmap.TestServlet3 + + + TestServlet4 + com.sun.ts.tests.servlet.spec.requestmap.TestServlet4 + + + TestServlet5 + com.sun.ts.tests.servlet.spec.requestmap.TestServlet5 + + + TestServlet6 + com.sun.ts.tests.servlet.spec.multifiltermapping.TestServlet6 + + + TestServlet1 + /foo/bar/* + + + TestServlet2 + /foo/baR/* + + + TestServlet3 + /TestServlet3 + + + TestServlet4 + *.bop + + + TestServlet5 + /foo/bar/TestServlet5 + + + TestServlet6 + /test/servletbyname + + + ErrorPage + /generic/ErrorPage + + + TestServlet + /TestServlet + + + 54 + + + 404 + /generic/ErrorPage + + + java.io.FileNotFoundException + /generic/ErrorPage + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/RequestListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/RequestListener.java new file mode 100644 index 0000000000..2e63fb3333 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/RequestListener.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2009, 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$ + */ +package com.sun.ts.tests.servlet.spec.pluggability.common; + +import java.util.ArrayList; + +import jakarta.servlet.ServletRequestEvent; +import jakarta.servlet.ServletRequestListener; + +public final class RequestListener implements ServletRequestListener { + + public void requestDestroyed(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("testmessage"); + if (al != null) { + al.add("RequestListener requestDestroyed"); + event.getServletContext().setAttribute("testmessage", al); + } + } + + public void requestInitialized(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("testmessage"); + if (al == null) { + al = new ArrayList(); + } + al.add("RequestListener requestInitialized"); + event.getServletContext().setAttribute("testmessage", al); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/RequestListener1.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/RequestListener1.java new file mode 100644 index 0000000000..57510e1809 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/RequestListener1.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2009, 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$ + */ +package com.sun.ts.tests.servlet.spec.pluggability.common; + +import java.util.ArrayList; + +import jakarta.servlet.ServletRequestEvent; +import jakarta.servlet.ServletRequestListener; + +public final class RequestListener1 implements ServletRequestListener { + + public void requestDestroyed(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("testmessage"); + if (al != null) { + al.add("RequestListener1 requestDestroyed"); + event.getServletContext().setAttribute("testmessage", al); + } + } + + public void requestInitialized(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("testmessage"); + if (al == null) { + al = new ArrayList(); + } + al.add("RequestListener1 requestInitialized"); + event.getServletContext().setAttribute("testmessage", al); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/RequestListener2.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/RequestListener2.java new file mode 100644 index 0000000000..97cd3bbf60 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/RequestListener2.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2009, 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$ + */ +package com.sun.ts.tests.servlet.spec.pluggability.common; + +import java.util.ArrayList; + +import jakarta.servlet.ServletRequestEvent; +import jakarta.servlet.ServletRequestListener; + +public final class RequestListener2 implements ServletRequestListener { + + public void requestDestroyed(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("testmessage"); + if (al != null) { + al.add("RequestListener2 requestDestroyed"); + event.getServletContext().setAttribute("testmessage", al); + } + } + + public void requestInitialized(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("testmessage"); + if (al == null) { + al = new ArrayList(); + } + al.add("RequestListener2 requestInitialized"); + event.getServletContext().setAttribute("testmessage", al); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/RequestListener3.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/RequestListener3.java new file mode 100644 index 0000000000..20ae48e0b9 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/RequestListener3.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2009, 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$ + */ +package com.sun.ts.tests.servlet.spec.pluggability.common; + +import java.util.ArrayList; + +import jakarta.servlet.ServletRequestEvent; +import jakarta.servlet.ServletRequestListener; + +public final class RequestListener3 implements ServletRequestListener { + + public void requestDestroyed(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("testmessage"); + if (al != null) { + al.add("RequestListener3 requestDestroyed"); + event.getServletContext().setAttribute("testmessage", al); + } + } + + public void requestInitialized(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("testmessage"); + if (al == null) { + al = new ArrayList(); + } + al.add("RequestListener3 requestInitialized"); + event.getServletContext().setAttribute("testmessage", al); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/RequestListener4.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/RequestListener4.java new file mode 100644 index 0000000000..662b2428f6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/RequestListener4.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2009, 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$ + */ +package com.sun.ts.tests.servlet.spec.pluggability.common; + +import java.util.ArrayList; + +import jakarta.servlet.ServletRequestEvent; +import jakarta.servlet.ServletRequestListener; + +public final class RequestListener4 implements ServletRequestListener { + + public void requestDestroyed(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("testmessage"); + if (al != null) { + al.add("RequestListener4 requestDestroyed"); + event.getServletContext().setAttribute("testmessage", al); + } + } + + public void requestInitialized(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("testmessage"); + if (al == null) { + al = new ArrayList(); + } + al.add("RequestListener4 requestInitialized"); + event.getServletContext().setAttribute("testmessage", al); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/RequestListener5.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/RequestListener5.java new file mode 100644 index 0000000000..8c0b7df9cf --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/RequestListener5.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2009, 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$ + */ +package com.sun.ts.tests.servlet.spec.pluggability.common; + +import java.util.ArrayList; + +import jakarta.servlet.ServletRequestEvent; +import jakarta.servlet.ServletRequestListener; + +public final class RequestListener5 implements ServletRequestListener { + + public void requestDestroyed(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("testmessage"); + if (al != null) { + al.add("RequestListener5 requestDestroyed"); + event.getServletContext().setAttribute("testmessage", al); + } + } + + public void requestInitialized(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("testmessage"); + if (al == null) { + al = new ArrayList(); + } + al.add("RequestListener5 requestInitialized"); + event.getServletContext().setAttribute("testmessage", al); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/RequestListener6.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/RequestListener6.java new file mode 100644 index 0000000000..f05448adc9 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/RequestListener6.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.spec.pluggability.common; + +import java.util.ArrayList; + +import jakarta.servlet.ServletRequestEvent; +import jakarta.servlet.ServletRequestListener; + +public final class RequestListener6 implements ServletRequestListener { + + public void requestDestroyed(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("testmessage"); + if (al != null) { + al.add("RequestListener6 requestDestroyed"); + event.getServletContext().setAttribute("testmessage", al); + } + } + + public void requestInitialized(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("testmessage"); + if (al == null) { + al = new ArrayList(); + } + al.add("RequestListener6 requestInitialized"); + event.getServletContext().setAttribute("testmessage", al); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/RequestListener7.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/RequestListener7.java new file mode 100644 index 0000000000..a7892f50e9 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/RequestListener7.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.spec.pluggability.common; + +import java.util.ArrayList; + +import jakarta.servlet.ServletRequestEvent; +import jakarta.servlet.ServletRequestListener; +import jakarta.servlet.annotation.WebListener; + +@WebListener() +public final class RequestListener7 implements ServletRequestListener { + + public void requestDestroyed(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("testmessage"); + if (al != null) { + al.add("RequestListener7 requestDestroyed"); + event.getServletContext().setAttribute("testmessage", al); + } + } + + public void requestInitialized(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("testmessage"); + if (al == null) { + al = new ArrayList(); + } + al.add("RequestListener7 requestInitialized"); + event.getServletContext().setAttribute("testmessage", al); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/TestServlet1.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/TestServlet1.java new file mode 100644 index 0000000000..f02d1a87a5 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/TestServlet1.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2009, 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$ + */ + +package com.sun.ts.tests.servlet.spec.pluggability.common; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet1 extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println("TestServlet1 is invoked"); + pw.append("msg1=" + getInitParameter("msg1")); + pw.append("msg2=" + getInitParameter("msg2")); + + ArrayList result = (ArrayList) getServletContext() + .getAttribute("testmessage"); + + Object results[] = result.toArray(); + for (int i = 0; i < results.length; i++) { + pw.println(results[i].toString()); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/TestServlet2.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/TestServlet2.java new file mode 100644 index 0000000000..9a07942f15 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/TestServlet2.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2012, 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$ + */ + +package com.sun.ts.tests.servlet.spec.pluggability.common; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet2 extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println("TestServlet2 is invoked"); + pw.append("msg1=" + getInitParameter("msg1")); + pw.append("msg2=" + getInitParameter("msg2")); + + ArrayList result = (ArrayList) getServletContext() + .getAttribute("testmessage"); + + Object results[] = result.toArray(); + for (int i = 0; i < results.length; i++) { + pw.println(results[i].toString()); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/TestServlet3.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/TestServlet3.java new file mode 100644 index 0000000000..3341c3b282 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/TestServlet3.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2012, 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$ + */ + +package com.sun.ts.tests.servlet.spec.pluggability.common; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.annotation.WebServlet; + +@WebServlet("/TestServlet3") +public class TestServlet3 extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println("TestServlet3 is invoked"); + pw.append("msg1=" + getInitParameter("msg1")); + pw.append("msg2=" + getInitParameter("msg2")); + + ArrayList result = (ArrayList) getServletContext() + .getAttribute("testmessage"); + + Object results[] = result.toArray(); + for (int i = 0; i < results.length; i++) { + pw.println(results[i].toString()); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/TestServlet4.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/TestServlet4.java new file mode 100644 index 0000000000..3ad41febab --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/TestServlet4.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.spec.pluggability.common; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet4 extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println("TestServlet4 is invoked"); + pw.append("msg1=" + getInitParameter("msg1")); + pw.append("msg2=" + getInitParameter("msg2")); + pw.append("msg3=" + getInitParameter("msg3")); + pw.append("msg4=" + getInitParameter("msg4")); + + ArrayList result = (ArrayList) getServletContext() + .getAttribute("testmessage"); + + Object results[] = result.toArray(); + for (int i = 0; i < results.length; i++) { + pw.println(results[i].toString()); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/web-fragment_1.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/web-fragment_1.xml new file mode 100644 index 0000000000..096a05dd01 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/web-fragment_1.xml @@ -0,0 +1,44 @@ + + + + + Fragment1 + + TestServlet1 + com.sun.ts.tests.servlet.spec.pluggability.common.TestServlet1 + + msg1 + second + + + msg2 + second + + + + TestServlet1 + /TestServlet1 + + + com.sun.ts.tests.servlet.spec.pluggability.common.RequestListener1 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/web-fragment_2.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/web-fragment_2.xml new file mode 100644 index 0000000000..7376dea7fb --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/web-fragment_2.xml @@ -0,0 +1,29 @@ + + + + + Fragment2 + + com.sun.ts.tests.servlet.spec.pluggability.common.RequestListener2 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/web-fragment_3.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/web-fragment_3.xml new file mode 100644 index 0000000000..52aae44cd5 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/web-fragment_3.xml @@ -0,0 +1,29 @@ + + + + + Fragment3 + + com.sun.ts.tests.servlet.spec.pluggability.common.RequestListener3 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/web-fragment_4.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/web-fragment_4.xml new file mode 100644 index 0000000000..5ed779e31f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/web-fragment_4.xml @@ -0,0 +1,29 @@ + + + + + Fragment4 + + com.sun.ts.tests.servlet.spec.pluggability.common.RequestListener4 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/web-fragment_5.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/web-fragment_5.xml new file mode 100644 index 0000000000..58ba065cbf --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/web-fragment_5.xml @@ -0,0 +1,29 @@ + + + + + Fragment5 + + com.sun.ts.tests.servlet.spec.pluggability.common.RequestListener5 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/web-fragment_6.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/web-fragment_6.xml new file mode 100644 index 0000000000..ba84573c74 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/web-fragment_6.xml @@ -0,0 +1,44 @@ + + + + + + TestServlet2 + com.sun.ts.tests.servlet.spec.pluggability.common.TestServlet2 + + msg1 + second + + + msg1 + ignore + + + + TestServlet2 + /TestServlet2 + + + com.sun.ts.tests.servlet.spec.pluggability.common.RequestListener6 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/web-fragment_7.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/web-fragment_7.xml new file mode 100644 index 0000000000..29bd43014c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/common/web-fragment_7.xml @@ -0,0 +1,33 @@ + + + + + + TestServlet2 + com.sun.ts.tests.servlet.spec.pluggability.common.TestServlet2 + + msg3 + third + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/ordering/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/ordering/build.xml new file mode 100644 index 0000000000..71f1d63eb2 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/ordering/build.xml @@ -0,0 +1,22 @@ + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/ordering/test1/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/ordering/test1/URLClient.java new file mode 100644 index 0000000000..b505e22ee6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/ordering/test1/URLClient.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2012, 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$ + */ +package com.sun.ts.tests.servlet.spec.pluggability.ordering.test1; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.spec.pluggability.common.RequestListener; +import com.sun.ts.tests.servlet.spec.pluggability.common.TestServlet4; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + public static JavaArchive getFragment1() { + return ShrinkWrap.create(JavaArchive.class, "fragment-1.jar") + .addClasses(RequestListener.class, TestServlet4.class) + .addAsResource(URLClient.class.getResource("web-fragment_1.xml"), + "META-INF/web-fragment.xml"); + } + + public static JavaArchive getFragment2() { + return ShrinkWrap.create(JavaArchive.class, "fragment-2.jar") + .addClasses(TestServlet4.class) + .addAsResource(URLClient.class.getResource("web-fragment_2.xml"), + "META-INF/web-fragment.xml"); + } + + public static JavaArchive getFragment3() { + return ShrinkWrap.create(JavaArchive.class, "fragment-3.jar") + .addClasses(TestServlet4.class) + .addAsResource(URLClient.class.getResource("web-fragment_3.xml"), + "META-INF/web-fragment.xml"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_spec_ordering1_web.war") + .addAsLibraries(getFragment1(), getFragment2(), getFragment3()) + .setWebXML(URLClient.class.getResource("servlet_spec_ordering1_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* + * @testName: initParamTest + * + * @assertion_ids: Servlet:SPEC:232; Servlet:SPEC:241; Servlet:SPEC:242; + * Servlet:SPEC:244; Servlet:SPEC:245; Servlet:SPEC:258.1; + * Servlet:SPEC:258.5.1; Servlet:SPEC:258.6.1; Servlet:SPEC:258.7.1; + * + * @test_Strategy: 1. Define servlet TestServlet4 in web.xml as well as three + * web-fragment.xml; 2. Send request to /TestServlet4, verify TestServlet4 is + * invoked 3. Also verify that defined in web.xml and all + * web-fragment.xml are considered, and the one defined in web.xml take + * precedence. + */ + @Test + public void initParamTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "TestServlet4|" + + "msg1=first|msg2=second|msg3=third|msg4=fourth|" + "RequestListener"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "ignore"); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/TestServlet4" + " HTTP/1.1"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/ordering/test1/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/ordering/test1/build.xml new file mode 100644 index 0000000000..15e02695da --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/ordering/test1/build.xml @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/ordering/test1/servlet_spec_ordering1_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/ordering/test1/servlet_spec_ordering1_web.xml new file mode 100644 index 0000000000..cfee32dd16 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/ordering/test1/servlet_spec_ordering1_web.xml @@ -0,0 +1,52 @@ + + + + + SerSpecOrdering1 + + TestServlet4 + com.sun.ts.tests.servlet.spec.pluggability.common.TestServlet4 + + msg1 + first + + + msg1 + firstignore + + + msg2 + second + + + msg3 + third + + + + TestServlet4 + /TestServlet4 + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/ordering/test1/web-fragment_1.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/ordering/test1/web-fragment_1.xml new file mode 100644 index 0000000000..9035c69131 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/ordering/test1/web-fragment_1.xml @@ -0,0 +1,58 @@ + + + + + Fragment1 + Fragment2 + + com.sun.ts.tests.servlet.spec.pluggability.common.RequestListener + + + TestServlet4 + com.sun.ts.tests.servlet.spec.pluggability.common.TestServlet4 + + msg1 + fourthignore + + + msg2 + secondignorefourth + + + msg3 + ignorethirdthird + + + msg4 + fourth + + + msg4 + ignorefourth + + + + TestServlet4 + /TestServlet4 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/ordering/test1/web-fragment_2.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/ordering/test1/web-fragment_2.xml new file mode 100644 index 0000000000..62e2931b07 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/ordering/test1/web-fragment_2.xml @@ -0,0 +1,46 @@ + + + + + Fragment2 + + TestServlet4 + com.sun.ts.tests.servlet.spec.pluggability.common.TestServlet4 + + msg1 + thirdignore + + + msg2 + secondignorethird + + + msg3 + ignorethird + + + msg3 + ignorethirdtwice + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/ordering/test1/web-fragment_3.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/ordering/test1/web-fragment_3.xml new file mode 100644 index 0000000000..c8246dd306 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/pluggability/ordering/test1/web-fragment_3.xml @@ -0,0 +1,43 @@ + + + + + Fragment3 + + + TestServlet4 + com.sun.ts.tests.servlet.spec.pluggability.common.TestServlet4 + + msg1 + secondignore + + + msg2 + ignoresecond + + + msg2 + ignoresecondtwice + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/protocols/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/protocols/build.xml new file mode 100644 index 0000000000..e223754011 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/protocols/build.xml @@ -0,0 +1,22 @@ + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/protocols/http/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/protocols/http/TestServlet.java new file mode 100644 index 0000000000..f0232dcb2c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/protocols/http/TestServlet.java @@ -0,0 +1,79 @@ +/* + * + * * + * * The Apache Software License, Version 1.1 + * * + * * Copyright (c) 2006, 2020 Oracle and/or its affiliates. All rights reserved. + * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights + * * reserved. + * * + * * Redistribution and use in source and binary forms, with or without + * * modification, are permitted provided that the following conditions + * * are met: + * * + * * 1. Redistributions of source code must retain the above copyright + * * notice, this list of conditions and the following disclaimer. + * * + * * 2. Redistributions in binary form must reproduce the above copyright + * * notice, this list of conditions and the following disclaimer in + * * the documentation and/or other materials provided with the + * * distribution. + * * + * * 3. The end-user documentation included with the redistribution, if + * * any, must include the following acknowlegement: + * * "This product includes software developed by the + * * Apache Software Foundation (http://www.apache.org/)." + * * Alternately, this acknowlegement may appear in the software itself, + * * if and wherever such third-party acknowlegements normally appear. + * * + * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software + * * Foundation" must not be used to endorse or promote products derived + * * from this software without prior written permission. For written + * * permission, please contact apache@apache.org. + * * + * * 5. Products derived from this software may not be called "Apache" + * * nor may "Apache" appear in their names without prior written + * * permission of the Apache Group. + * * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * * SUCH DAMAGE. + * * ==================================================================== + * * + * * This software consists of voluntary contributions made by many + * * individuals on behalf of the Apache Software Foundation. For more + * * information on the Apache Software Foundation, please see + * * . + * * + */ + +package com.sun.ts.tests.servlet.spec.protocols.http; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.HttpTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class TestServlet extends HttpTCKServlet { + + public void httpTest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + ServletTestUtil.printResult(pw, true); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/protocols/http/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/protocols/http/URLClient.java new file mode 100644 index 0000000000..96a60b0ea9 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/protocols/http/URLClient.java @@ -0,0 +1,80 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.protocols.http; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import com.sun.ts.tests.servlet.common.util.Data; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_spec_protocols_http_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_spec_protocols_http_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: httpTest + * + * @assertion_ids: Servlet:SPEC:1 + * + * @test_Strategy: + */ + @Test + public void httpTest() throws Exception { + String testName = "httpTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + + getServletName() + "?testname=" + testName + " HTTP/1.0"); + TEST_PROPS.setProperty(SEARCH_STRING, Data.PASSED); + invoke(); + + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + + getServletName() + "?testname=" + testName + " HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, Data.PASSED); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/protocols/http/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/protocols/http/build.xml new file mode 100644 index 0000000000..26e103851f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/protocols/http/build.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/protocols/http/servlet_spec_protocols_http_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/protocols/http/servlet_spec_protocols_http_web.xml new file mode 100644 index 0000000000..051753d3b4 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/protocols/http/servlet_spec_protocols_http_web.xml @@ -0,0 +1,33 @@ + + + + + SerSpecProtocolsHttp + + TestServlet + com.sun.ts.tests.servlet.spec.protocols.http.TestServlet + + + TestServlet + /TestServlet/* + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/rdspecialchar/IncludedServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/rdspecialchar/IncludedServlet.java new file mode 100644 index 0000000000..74efaa2641 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/rdspecialchar/IncludedServlet.java @@ -0,0 +1,39 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.rdspecialchar; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class IncludedServlet extends GenericServlet { + + public void service(ServletRequest req, ServletResponse res) + throws ServletException, IOException { + PrintWriter out = res.getWriter(); + out.println("Test PASSED"); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/rdspecialchar/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/rdspecialchar/TestServlet.java new file mode 100644 index 0000000000..1bdcd5e52e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/rdspecialchar/TestServlet.java @@ -0,0 +1,61 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.rdspecialchar; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.HttpTCKServlet; + +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class TestServlet extends HttpTCKServlet { + + public void querySemicolonInclude(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String path = "/include/IncludedServlet?querySemicolonIncludeQuebec;libre"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + + if (rd == null) + pw.println("Null RequestDispatcher got for path=" + path); + else + rd.include(request, response); + } + + public void querySemicolonForward(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String path = "/include/IncludedServlet?querySemicolonForwardQuebec;libre"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + + if (rd == null) + pw.println("Null RequestDispatcher got for path=" + path); + else + rd.forward(request, response); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/rdspecialchar/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/rdspecialchar/URLClient.java new file mode 100644 index 0000000000..9dbd5b3f99 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/rdspecialchar/URLClient.java @@ -0,0 +1,90 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.rdspecialchar; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_spec_rdspecialchar_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(IncludedServlet.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_spec_rdspecialchar_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* + * @testName: querySemicolonInclude + * + * @assertion_ids: Servlet:SPEC:76.1; Servlet:SPEC:76.2; Servlet:SPEC:76.3; + * Servlet:SPEC:76.4; Servlet:SPEC:76.5; + * + * @test_Strategy: 1. Create servlets TestServlet and IncludedServlet; 2. In + * TestServlet, get RequestDispatcher by using + * ServletContext.getRequestDispatcher(path), with special character ";" in + * path as part of query string, and access IncludedServlet using + * RequestDispatcher.include. 3. Verify that IncludedServlet is invoked. + */ + @Test + public void querySemicolonInclude() throws Exception { + TEST_PROPS.setProperty(APITEST, "querySemicolonInclude"); + invoke(); + } + + /* + * @testName: querySemicolonForward + * + * @assertion_ids: Servlet:SPEC:76.1; Servlet:SPEC:76.2; Servlet:SPEC:76.3; + * Servlet:SPEC:76.4; Servlet:SPEC:76.5; + * + * @test_Strategy: 1. Create servlets TestServlet and IncludedServlet; 2. In + * TestServlet, get RequestDispatcher by using + * ServletContext.getRequestDispatcher(path), with special character ";" in + * path as part of query string, and access IncludedServlet using + * RequestDispatcher.forward. 3. Verify that IncludedServlet is invoked. + */ + @Test + public void querySemicolonForward() throws Exception { + TEST_PROPS.setProperty(APITEST, "querySemicolonForward"); + invoke(); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/rdspecialchar/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/rdspecialchar/build.xml new file mode 100644 index 0000000000..6632ff6897 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/rdspecialchar/build.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/rdspecialchar/servlet_spec_rdspecialchar_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/rdspecialchar/servlet_spec_rdspecialchar_web.xml new file mode 100644 index 0000000000..998f02c88a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/rdspecialchar/servlet_spec_rdspecialchar_web.xml @@ -0,0 +1,41 @@ + + + + + SerJaxSerQueryString + + TestServlet + com.sun.ts.tests.servlet.spec.rdspecialchar.TestServlet + + + IncludedServlet + com.sun.ts.tests.servlet.spec.rdspecialchar.IncludedServlet + + + TestServlet + /TestServlet + + + IncludedServlet + /include/IncludedServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestdispatcher/ForwardedServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestdispatcher/ForwardedServlet.java new file mode 100644 index 0000000000..b1b716c6d1 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestdispatcher/ForwardedServlet.java @@ -0,0 +1,139 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.requestdispatcher; + +import java.io.IOException; +import java.io.PrintWriter; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; + +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class ForwardedServlet extends GenericTCKServlet { + + private static final String TEST_HEADER = "testname"; + + private static final Class[] TEST_ARGS = { ServletRequest.class, + ServletResponse.class }; + + private static final String TEST1_HEADER = "TestName"; + + public void service(ServletRequest req, ServletResponse res) + throws ServletException, IOException { + String test = req.getParameter(TEST_HEADER); + try { + Method method = this.getClass().getMethod(test, TEST_ARGS); + method.invoke(this, new Object[] { req, res }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + if (req.getAttribute(TEST1_HEADER) != null) { + String tmp = (String) req.getAttribute(TEST1_HEADER); + if (tmp.indexOf("attributes") < 0) + throw new ServletException("Test: " + test + " does not exist"); + else + attributes(req, res); + } else + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + } + + public void thrownIOException(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + throw new IOException("IOException_from_checkedException"); + } + + public void thrownServletException(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + throw new ServletException("ServletException from thrownServletException"); + } + + public void thrownUnCheckedException(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + throw new RuntimeException("RuntimeException_from_unCheckedException"); + } + + public void thrownCheckedException(ServletRequest request, + ServletResponse response) + throws ServletException, IOException, ClassNotFoundException { + throw new ClassNotFoundException( + "ClassNotFoundException from throwCheckedException"); + } + + public void bufferContent(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println("bufferContent_in_ForwardedServlet_invoked"); + } + + public void attributes(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String[] aname = { "jakarta.servlet.forward.request_uri", + "jakarta.servlet.forward.context_path", + "jakarta.servlet.forward.servlet_path", "jakarta.servlet.forward.path_info", + "jakarta.servlet.forward.query_string" }; + + String[] avalue = { "/servlet_spec_requestdispatcher_web/TestServlet", + "/servlet_spec_requestdispatcher_web", "/TestServlet", "*", + "testname=" + request.getParameter("query") }; + String[] types = { "=SET_GOOD;", "=SET_WRONGVALUE;", "=SET_BADTYPE;", + "=SET_NO;" }; + String[] results = new String[5]; + + for (int i = 0; i < aname.length; i++) { + Object o = request.getAttribute(aname[i]); + + if (o != null) { + if (o instanceof String) { + String attr = (String) o; + if (!attr.equals(avalue[i])) { + results[i] = types[1]; + pw.println("attribute " + aname[i] + " set with incorrect value=" + + attr + ", expecting " + avalue[i]); + } else { + results[i] = types[0]; + pw.println( + "attribute " + aname[i] + " set with correct value=" + attr); + } + } else { + results[i] = types[2]; + pw.println("attribute " + aname[i] + " set to non-String type"); + } + } else { + results[i] = types[3]; + pw.println("attribute " + aname[i] + " not set"); + } + } + + for (int i = 0; i < 5; i++) { + pw.print(aname[i] + results[i]); + } + pw.println(""); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestdispatcher/HttpTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestdispatcher/HttpTestServlet.java new file mode 100644 index 0000000000..24077c3225 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestdispatcher/HttpTestServlet.java @@ -0,0 +1,155 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.requestdispatcher; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.HttpTCKServlet; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class HttpTestServlet extends HttpTCKServlet { + + public void getRequestURIIncludeTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String expectValue = "/servlet_spec_requestdispatcher_web/TestServlet"; + + String actual = request.getRequestURI(); + + if (actual != null) { + if (actual.equals(expectValue)) + pw.println( + "Test PASSED from getRequestURIIncludeTest in HttpTestServlet"); + else + pw.println( + "Test FAILED - getRequestURI return incorrect value: " + actual); + } else + pw.println("Test FAILED - getRequestURI return incorrect null value"); + } + + public void getRequestURIForwardTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String expectValue = "/servlet_spec_requestdispatcher_web/other/HttpTestServlet"; + + String actual = request.getRequestURI(); + + if (actual != null) { + if (actual.equals(expectValue)) + pw.println( + "Test PASSED from getRequestURIForwardTest in HttpTestServlet"); + else + pw.println( + "Test FAILED - getRequestURI return incorrect value: " + actual); + } else + pw.println("Test FAILED - getRequestURI return incorrect null value"); + } + + public void getRequestURLIncludeTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String expectValue = "/servlet_spec_requestdispatcher_web/TestServlet"; + + StringBuffer actual = request.getRequestURL(); + + if (actual != null) { + if (actual.indexOf(expectValue) != -1) + if (actual.toString().toUpperCase().startsWith("HTTP://")) + pw.println( + "Test PASSED from getRequestURLIncludeTest in HttpTestServlet"); + else + pw.println("Test FAILED - getRequestURL does not start with http://: " + + actual); + else + pw.println( + "Test FAILED - getRequestURL return incorrect value: " + actual); + } else + pw.println("Test FAILED - getRequestURL return incorrect null value"); + } + + public void getRequestURLForwardTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String expectValue = "/servlet_spec_requestdispatcher_web/other/HttpTestServlet"; + + StringBuffer actual = request.getRequestURL(); + + if (actual != null) { + if (actual.indexOf(expectValue) != -1) + if (actual.toString().toUpperCase().startsWith("HTTP://")) + pw.println( + "Test PASSED from getRequestURLForwardTest in HttpTestServlet"); + else + pw.println("Test FAILED - getRequestURL does not start with http://: " + + actual); + else + pw.println( + "Test FAILED - getRequestURL return incorrect value: " + actual); + } else + pw.println("Test FAILED - getRequestURL return incorrect null value"); + } + + public void getQueryStringTestForward(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String expectValue = "testname=getQueryStringTestForward"; + + String actual = request.getQueryString(); + + if (actual != null) { + if (actual.equals(expectValue)) + pw.println( + "Test PASSED from getQueryStringForwardTest in HttpTestServlet"); + else + pw.println( + "Test FAILED - getQueryString return incorrect value: " + actual); + } else + pw.println("Test FAILED - getQueryString return incorrect null value"); + } + + public void getQueryStringTestInclude(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String expectValue = "testname=getQueryStringIncludeTest"; + + String actual = request.getQueryString(); + + if (actual != null) { + if (actual.equals(expectValue)) + pw.println( + "Test PASSED from getQueryStringIncludeTest in HttpTestServlet"); + else + pw.println( + "Test FAILED - getQueryString return incorrect value: " + actual); + } else + pw.println("Test FAILED - getQueryString return incorrect null value"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestdispatcher/IncludedServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestdispatcher/IncludedServlet.java new file mode 100644 index 0000000000..f3961918c3 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestdispatcher/IncludedServlet.java @@ -0,0 +1,133 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.requestdispatcher; + +import java.io.IOException; +import java.io.PrintWriter; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class IncludedServlet extends GenericServlet { + + private static final String attr_prefix = "jakarta.servlet.include."; + + private static final String TEST_HEADER = "testname"; + + private static final Class[] TEST_ARGS = { ServletRequest.class, + ServletResponse.class }; + + private static final String TEST1_HEADER = "TestName"; + + public void service(ServletRequest req, ServletResponse res) + throws ServletException, IOException { + String test = req.getParameter(TEST_HEADER); + try { + Method method = this.getClass().getMethod(test, TEST_ARGS); + method.invoke(this, new Object[] { req, res }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + if (req.getAttribute(TEST1_HEADER) != null) { + String tmp = (String) req.getAttribute(TEST1_HEADER); + if (tmp.indexOf("attributes") < 0) + throw new ServletException("Test: " + test + " does not exist"); + else + attributes(req, res); + } else + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + } + + public void thrownIOException(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + throw new IOException("IOException_from_checkedException"); + } + + public void thrownServletException(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + throw new ServletException("ServletException from thrownServletException"); + } + + public void thrownUnCheckedException(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + throw new RuntimeException("RuntimeException_from_unCheckedException"); + } + + public void thrownCheckedException(ServletRequest request, + ServletResponse response) + throws ServletException, IOException, ClassNotFoundException { + throw new ClassNotFoundException("Exception from throwCheckedException"); + } + + public void attributes(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String[] aname = { "request_uri", "context_path", "servlet_path", + "path_info", "query_string" }; + + String[] avalue = { + "/servlet_spec_requestdispatcher_web/include/IncludedServlet", + "/servlet_spec_requestdispatcher_web", "/include/IncludedServlet", "*", + "testname=attributes", }; + String[] types = { "=SET_GOOD;", "=SET_WRONGVALUE;", "=SET_BADTYPE;", + "=SET_NO;" }; + String[] results = new String[5]; + + for (int i = 0; i < 5; i++) { + Object o = request.getAttribute(attr_prefix + aname[i]); + + if (o != null) { + if (o instanceof String) { + String attr = (String) o; + if (!attr.equals(avalue[i])) { + results[i] = types[1]; + pw.println("attribute " + attr_prefix + aname[i] + + " set with incorrect value=" + attr); + } else { + results[i] = types[0]; + pw.println("attribute " + attr_prefix + aname[i] + + " set with correct value=" + avalue[i]); + } + } else { + results[i] = types[2]; + pw.println("attribute " + attr_prefix + aname[i] + + " set to non-String type"); + } + } else { + results[i] = types[3]; + pw.println("attribute " + attr_prefix + aname[i] + " not set"); + } + } + + for (int i = 0; i < 5; i++) { + pw.print(attr_prefix + aname[i] + results[i]); + } + pw.println(""); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestdispatcher/MultiForwardedServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestdispatcher/MultiForwardedServlet.java new file mode 100644 index 0000000000..73875e0e85 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestdispatcher/MultiForwardedServlet.java @@ -0,0 +1,54 @@ +/* + * 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: ForwardedServlet.java 52684 2007-02-12 04:30:10Z lschwenk $ + */ +package com.sun.ts.tests.servlet.spec.requestdispatcher; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; + +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class MultiForwardedServlet extends GenericTCKServlet { + + private static final String TEST_HEADER = "testname"; + + private static final Class[] TEST_ARGS = { ServletRequest.class, + ServletResponse.class }; + + private static final String TEST1_HEADER = "TestName"; + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String path = "/forward/ForwardedServlet?testname=attributes&query=forwardAttributes6"; + RequestDispatcher rd = request.getRequestDispatcher(path); + + if (rd == null) { + pw.println("Null RequestDispatcher got for path=" + path); + } else { + rd.forward(request, response); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestdispatcher/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestdispatcher/TestServlet.java new file mode 100644 index 0000000000..9077017fad --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestdispatcher/TestServlet.java @@ -0,0 +1,518 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.requestdispatcher; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import com.sun.ts.tests.servlet.common.servlets.HttpTCKServlet; + +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletRequestWrapper; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpServletResponseWrapper; + +public class TestServlet extends HttpTCKServlet { + + public void includeAttributes(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String path = "/include/IncludedServlet?testname=attributes"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + + if (rd == null) + pw.println("Null RequestDispatcher got for path=" + path); + else + rd.include(request, response); + } + + public void includeAttributes1(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String path = "include/IncludedServlet?testname=attributes"; + RequestDispatcher rd = request.getRequestDispatcher(path); + + if (rd == null) + pw.println("Null RequestDispatcher got for path=" + path); + else + rd.include(request, response); + } + + public void includeAttributes2(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String path = "IncludedServlet"; + RequestDispatcher rd = getServletContext().getNamedDispatcher(path); + + if (rd == null) + pw.println("Null RequestDispatcher got for path=" + path); + else { + request.setAttribute("TestName", "attributes"); + rd.include(request, response); + } + } + + public void includeIOAndServletException(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + Map testMap = new HashMap(); + testMap.put("IOException", + "include/IncludedServlet?testname=thrownIOException"); + testMap.put("ServletException", + "include/IncludedServlet?testname=thrownServletException"); + + testMap.keySet().iterator(); + for (Iterator i = testMap.keySet().iterator(); i.hasNext();) { + String type = (String) i.next(); + String path = (String) testMap.get(type); + RequestDispatcher rd = request.getRequestDispatcher(path); + + if (rd == null) + pw.println("Null RequestDispatcher got for path=" + path); + else { + try { + rd.include(request, response); + pw.println("Test FAILED with no propagation of " + type + " from " + + "IncludedServlet to TestServlet."); + } catch (Throwable t) { + Throwable targetThrowable = ((ServletException) t).getRootCause(); + if (type.equals("IOException")) { + if (targetThrowable instanceof IOException) { + pw.println("Test PASSED with proper propagation of " + type + + " from IncludedServlet to TestServlet:" + + targetThrowable.getMessage()); + } else { + pw.println("Test FAILED with propagation of " + type + " from " + + "IncludedServlet to TestServlet - wrong type of " + + "Exception caught by TestServlet: " + + targetThrowable.getClass().getName()); + } + } + if (type.equals("ServletException")) { + if (targetThrowable instanceof ServletException) { + ServletException se = (ServletException) targetThrowable; + if (se.getRootCause() == null) { + pw.println("Test PASSED with proper propagation of " + type + + " from IncludedServlet to TestServlet:" + + targetThrowable.getMessage()); + } else { + pw.println( + "Test FAILED. ServletException thrown during RD operation resulted in that " + + "exception being wrapped by a ServletException. ServletExceptions must be propagated " + + "as is to the caller."); + } + } else { + pw.println("Test FAILED with propagation of " + type + " from " + + "IncludedServlet to TestServlet - wrong type of " + + "Exception caught by TestServlet: " + + targetThrowable.getClass().getName()); + } + } + } + } + } + } + + public void includeUnCheckedException(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String path = "include/IncludedServlet?testname=thrownUnCheckedException"; + RequestDispatcher rd = request.getRequestDispatcher(path); + + if (rd == null) + pw.println("Null RequestDispatcher got for path=" + path); + else { + try { + rd.include(request, response); + pw.println("Test FAILED with no propagation of RuntimeException from " + + "IncludedServlet to TestServlet."); + } catch (Throwable t) { + // unwrap the throwable from the ServletException + Throwable targetThrowable = ((ServletException) t).getRootCause(); + if (targetThrowable instanceof RuntimeException) { + pw.println("Test PASSED. RuntimeException properly propagated."); + } else { + pw.println( + "Test FAILED with incorrect propagation of RuntimeException " + + "Exception from IncludedServlet to TestServlet " + + "- wrong type of Exception caught by TestServlet: " + + t.getClass().getName()); + } + } + } + } + + public void includeCheckedException(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String path = "include/IncludedServlet?testname=thrownCheckedException"; + RequestDispatcher rd = request.getRequestDispatcher(path); + + if (rd == null) + pw.println("Null RequestDispatcher got for path=" + path); + else { + try { + rd.include(request, response); + pw.println("Test FAILED with no propagation of Exception from " + + "IncludedServlet to TestServlet."); + + } catch (ServletException se) { + if (se.getRootCause() instanceof java.lang.ClassNotFoundException) + pw.println( + "Test PASSED with proper propagation of ClassNotFoundException " + + "from IncludedServlet to TestServlet."); + } catch (Throwable t) { + pw.println("Test FAILED with incorrect propagation of RuntimeException " + + "Exception from IncludedServlet to TestServlet " + + "- wrong type of Exception caught by TestServlet: " + + t.getClass().getName()); + } + } + } + + public void forwardAttributes(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String path = "/forward/ForwardedServlet?testname=attributes&query=forwardAttributes"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + + if (rd == null) + pw.println("Null RequestDispatcher got for path=" + path); + else + rd.forward(request, response); + } + + public void forwardAttributes1(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String path = "/forward/ForwardedServlet?testname=attributes&query=forwardAttributes1"; + RequestDispatcher rd = request.getRequestDispatcher(path); + + if (rd == null) + pw.println("Null RequestDispatcher got for path=" + path); + else + rd.forward(request, response); + } + + public void forwardAttributes2(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String path = "ForwardedServlet"; + RequestDispatcher rd = getServletContext().getNamedDispatcher(path); + + if (rd == null) + pw.println("Null RequestDispatcher got for path=" + path); + else { + request.setAttribute("TestName", "attributes"); + rd.forward(request, response); + } + } + + public void forwardAttributes6(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String path = "/forward/MultiForwardedServlet?testname=attributes&query=forwardAttributes"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + + if (rd == null) + pw.println("Null RequestDispatcher got for path=" + path); + else { + request.setAttribute("TestName", "attributes"); + rd.forward(request, response); + } + } + + public void forwardIOAndServletException(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + Map testMap = new HashMap(); + testMap.put("IOException", + "forward/ForwardedServlet?testname=thrownIOException"); + testMap.put("ServletException", + "forward/ForwardedServlet?testname=thrownServletException"); + + testMap.keySet().iterator(); + for (Iterator i = testMap.keySet().iterator(); i.hasNext();) { + String type = (String) i.next(); + String path = (String) testMap.get(type); + RequestDispatcher rd = request.getRequestDispatcher(path); + + if (rd == null) + pw.println("Null RequestDispatcher got for path=" + path); + else { + try { + rd.include(request, response); + pw.println("Test FAILED with no propagation of " + type + " from " + + "ForwardedServlet to TestServlet."); + + } catch (Throwable t) { + Throwable targetThrowable = ((ServletException) t).getRootCause(); + if (type.equals("IOException")) { + if (targetThrowable instanceof IOException) { + pw.println("Test PASSED with proper propagation of " + type + + " from IncludedServlet to TestServlet:" + + targetThrowable.getMessage()); + } else { + pw.println("Test FAILED with propagation of " + type + " from " + + "IncludedServlet to TestServlet - wrong type of " + + "Exception caught by TestServlet: " + + targetThrowable.getClass().getName()); + } + } + if (type.equals("ServletException")) { + if (targetThrowable instanceof ServletException) { + ServletException se = (ServletException) targetThrowable; + if (se.getRootCause() == null) { + pw.println("Test PASSED with proper propagation of " + type + + " from IncludedServlet to TestServlet:" + + targetThrowable.getMessage()); + } else { + pw.println( + "Test FAILED. ServletException thrown during RD operation resulted in that " + + "exception being wrapped by a ServletException. ServletExceptions must be propagated " + + "as is to the caller."); + } + } else { + pw.println("Test FAILED with propagation of " + type + " from " + + "IncludedServlet to TestServlet - wrong type of " + + "Exception caught by TestServlet: " + + targetThrowable.getClass().getName()); + } + } + } + } + } + } + + public void forwardUnCheckedException(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String path = "forward/ForwardedServlet?testname=thrownUnCheckedException"; + RequestDispatcher rd = request.getRequestDispatcher(path); + + if (rd == null) + pw.println("Null RequestDispatcher got for path=" + path); + else { + try { + rd.include(request, response); + pw.println("Test FAILED with no propagation of RuntimeException from " + + "ForwardedServlet to TestServlet."); + } catch (Throwable t) { + // unwrap the throwable from the ServletException + Throwable targetThrowable = ((ServletException) t).getRootCause(); + if (targetThrowable instanceof RuntimeException) { + pw.println("Test PASSED. RuntimeException properly propagated."); + } else { + pw.println( + "Test FAILED with incorrect propagation of RuntimeException " + + "Exception from IncludedServlet to TestServlet " + + "- wrong type of Exception caught by TestServlet: " + + t.getClass().getName()); + } + } + } + } + + public void forwardCheckedException(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String path = "forward/ForwardedServlet?testname=thrownCheckedException"; + RequestDispatcher rd = request.getRequestDispatcher(path); + + if (rd == null) + pw.println("Null RequestDispatcher got for path=" + path); + else { + try { + rd.include(request, response); + pw.println("Test FAILED with no propagation of Exception from " + + "ForwardedServlet to TestServlet."); + + } catch (ServletException se) { + if (se.getRootCause() instanceof java.lang.ClassNotFoundException) + pw.println( + "Test PASSED with proper propagation of ClassNotFoundException " + + "from ForwardServlet to TestServlet."); + } catch (Throwable t) { + pw.println("Test FAILED with incorrect propagation of RuntimeException " + + "Exception from ForwardedServlet to TestServlet " + + "- wrong type of Exception caught by TestServlet: " + + t.getClass().getName()); + } + } + } + + public void bufferContent(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String path = "/forward/ForwardedServlet?testname=bufferContent"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + + pw.println("Test FAILED if you see this message"); + + if (rd == null) + pw.println("Null RequestDispatcher got for path=" + path); + else + 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(); + + String path = "/other/HttpTestServlet?testname=getRequestURIIncludeTest"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + + if (rd == null) + pw.println("Null RequestDispatcher got for path=" + path); + else + rd.include(request, response); + } + + public void getRequestURIForwardTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String path = "/other/HttpTestServlet?testname=getRequestURIForwardTest"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + + if (rd == null) + pw.println("Null RequestDispatcher got for path=" + path); + else + rd.forward(request, response); + } + + public void getRequestURIMultiForwardTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String path = "/other/HttpTestServlet?testname=getRequestURIMultiForwardTest"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + + if (rd == null) + pw.println("Null RequestDispatcher got for path=" + path); + else + rd.forward(request, response); + } + + public void getRequestURLIncludeTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String path = "/other/HttpTestServlet?testname=getRequestURLIncludeTest"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + + if (rd == null) + pw.println("Null RequestDispatcher got for path=" + path); + else + rd.include(request, response); + } + + public void getRequestURLForwardTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String path = "/other/HttpTestServlet?testname=getRequestURLForwardTest"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + + if (rd == null) + pw.println("Null RequestDispatcher got for path=" + path); + else + rd.forward(request, response); + } + + public void getQueryStringIncludeTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String path = "/other/HttpTestServlet?testname=getQueryStringTestInclude"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + + if (rd == null) + pw.println("Null RequestDispatcher got for path=" + path); + else + rd.include(request, response); + } + + public void getQueryStringForwardTest(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String path = "/other/HttpTestServlet?testname=getQueryStringTestForward"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + + if (rd == null) + pw.println("Null RequestDispatcher got for path=" + path); + else + rd.forward(request, response); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestdispatcher/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestdispatcher/URLClient.java new file mode 100644 index 0000000000..d5afe6e6d9 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestdispatcher/URLClient.java @@ -0,0 +1,497 @@ +/* + * 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$ + */ +package com.sun.ts.tests.servlet.spec.requestdispatcher; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + 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) + .setWebXML(URLClient.class.getResource("servlet_spec_requestdispatcher_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* + * @testName: getRequestAttributes + * + * @assertion_ids: Servlet:SPEC:76.1; Servlet:SPEC:76.2; Servlet:SPEC:76.3; + * Servlet:SPEC:76.4; Servlet:SPEC:76.5; + * + * @test_Strategy: 1. Create servlets TestServlet and IncludedServlet; 2. In + * TestServlet, get RequestDispatcher by using + * ServletContext.getRequestDispatcher(String), and access IncludedServlet + * using RequestDispatcher.include. 3. Verify in IncludedServlet the following + * request attributes set correctly required by Servlet 2.4 Spec: + * jakarta.servlet.include.request_uri; jakarta.servlet.include.context_path; + * jakarta.servlet.include.servlet_path; jakarta.servlet.include.path_info; + * jakarta.servlet.include.query_string; + */ + @Test + public void getRequestAttributes() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, + "jakarta.servlet.include.request_uri=SET_GOOD;jakarta.servlet.include.context_path=SET_GOOD;jakarta.servlet.include.servlet_path=SET_GOOD;jakarta.servlet.include.path_info=SET_NO;jakarta.servlet.include.query_string=SET_GOOD;"); + + TEST_PROPS.setProperty(APITEST, "includeAttributes"); + invoke(); + } + + /* + * @testName: getRequestAttributes1 + * + * @assertion_ids: Servlet:SPEC:76.1; Servlet:SPEC:76.2; Servlet:SPEC:76.3; + * Servlet:SPEC:76.4; Servlet:SPEC:76.5; + * + * @test_Strategy: 1. Create servlets TestServlet and IncludedServlet; 2. In + * TestServlet, get RequestDispatcher by using + * ServletRequest.getRequestDispatcher(String), and access IncludedServlet + * using RequestDispatcher.include. 3. Verify in IncludedServlet the following + * request attributes set correctly required by Servlet 2.4 Spec: + * jakarta.servlet.include.request_uri; jakarta.servlet.include.context_path; + * jakarta.servlet.include.servlet_path; jakarta.servlet.include.path_info; + * jakarta.servlet.include.query_string; + */ + @Test + public void getRequestAttributes1() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, + "jakarta.servlet.include.request_uri=SET_GOOD;jakarta.servlet.include.context_path=SET_GOOD;jakarta.servlet.include.servlet_path=SET_GOOD;jakarta.servlet.include.path_info=SET_NO;jakarta.servlet.include.query_string=SET_GOOD;"); + + TEST_PROPS.setProperty(APITEST, "includeAttributes1"); + invoke(); + } + + /* + * @testName: getRequestAttributes2 + * + * @assertion_ids: Servlet:SPEC:76.1; Servlet:SPEC:76.2; Servlet:SPEC:76.3; + * Servlet:SPEC:76.4; Servlet:SPEC:76.5; + * + * @test_Strategy: 1. Create servlets TestServlet and IncludedServlet; 2. In + * TestServlet, get RequestDispatcher by using + * ServletContext.getNamedDispatcher(String), and access IncludedServlet using + * RequestDispatcher.include. 3. Verify in IncludedServlet the following + * request attributes not set required by Servlet 2.4 Spec: + * jakarta.servlet.include.request_uri; jakarta.servlet.include.context_path; + * jakarta.servlet.include.servlet_path; jakarta.servlet.include.path_info; + * jakarta.servlet.include.query_string; + */ + @Test + public void getRequestAttributes2() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, + "jakarta.servlet.include.request_uri=SET_NO;jakarta.servlet.include.context_path=SET_NO;jakarta.servlet.include.servlet_path=SET_NO;jakarta.servlet.include.path_info=SET_NO;jakarta.servlet.include.query_string=SET_NO;"); + + TEST_PROPS.setProperty(APITEST, "includeAttributes2"); + invoke(); + } + + /* + * @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 + * propagated back to the caller and will not be wrapped by a + * ServletException. + */ + @Test + public void requestDispatcherIncludeIOAndServletExceptionTest() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET /servlet_spec_requestdispatcher_web/TestServlet?testname=includeIOAndServletException HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Test PASSED|Test PASSED"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "Test FAILED"); + invoke(); + } + + /* + * @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 + * ServletException. + */ + @Test + public void requestDispatcherIncludeRuntimeExceptionTest() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET /servlet_spec_requestdispatcher_web/TestServlet?testname=includeUnCheckedException HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Test PASSED"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "Test FAILED"); + invoke(); + } + + /* + * @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 + * ServletException. + */ + @Test + public void requestDispatcherIncludeCheckedExceptionTest() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET /servlet_spec_requestdispatcher_web/TestServlet?testname=includeCheckedException HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Test PASSED"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "Test FAILED"); + invoke(); + } + + /* + * @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 + * propagated back to the caller and will not be wrapped by a + * ServletException. + */ + @Test + public void requestDispatcherForwardIOAndServletExceptionTest() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET /servlet_spec_requestdispatcher_web/TestServlet?testname=forwardIOAndServletException HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Test PASSED|Test PASSED"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "Test FAILED"); + invoke(); + } + + /* + * @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 + * ServletException. + */ + @Test + public void requestDispatcherForwardRuntimeExceptionTest() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET /servlet_spec_requestdispatcher_web/TestServlet?testname=forwardUnCheckedException HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Test PASSED"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "Test FAILED"); + invoke(); + } + + /* + * @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 + * ServletException. + */ + @Test + public void requestDispatcherForwardCheckedExceptionTest() throws Exception { + TEST_PROPS.setProperty(REQUEST, + "GET /servlet_spec_requestdispatcher_web/TestServlet?testname=forwardCheckedException HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Test PASSED"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "Test FAILED"); + invoke(); + } + + /* + * @testName: getRequestAttributes3 + * + * @assertion_ids: Servlet:SPEC:180.1; Servlet:SPEC:180.2; Servlet:SPEC:180.3; + * Servlet:SPEC:180.4; Servlet:SPEC:180.5; + * + * @test_Strategy: 1. Create servlets TestServlet and ForwardedServlet; 2. In + * TestServlet, get RequestDispatcher by using + * ServletContext.getRequestDispatcher(String), and access ForwardedServlet + * using RequestDispatcher.forward. 3. Verify in ForwardedServlet the + * following request attributes set correctly required by Servlet 2.4 Spec: + * jakarta.servlet.forward.request_uri; jakarta.servlet.forward.context_path; + * jakarta.servlet.forward.servlet_path; jakarta.servlet.forward.path_info; + * jakarta.servlet.forward.query_string; + */ + @Test + public void getRequestAttributes3() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, + "jakarta.servlet.forward.request_uri=SET_GOOD;" + + "jakarta.servlet.forward.context_path=SET_GOOD;" + + "jakarta.servlet.forward.servlet_path=SET_GOOD;" + + "jakarta.servlet.forward.path_info=SET_NO;" + + "jakarta.servlet.forward.query_string=SET_GOOD;"); + + TEST_PROPS.setProperty(APITEST, "forwardAttributes"); + invoke(); + } + + /* + * @testName: getRequestAttributes4 + * + * @assertion_ids: Servlet:SPEC:180.1; Servlet:SPEC:180.2; Servlet:SPEC:180.3; + * Servlet:SPEC:180.4; Servlet:SPEC:180.5; + * + * @test_Strategy: 1. Create servlets TestServlet and ForwardedServlet; 2. In + * TestServlet, get RequestDispatcher by using + * ServletRequest.getRequestDispatcher(String), and access ForwardedServlet + * using RequestDispatcher.forward. 3. Verify in ForwardedServlet the + * following request attributes set correctly required by Servlet 2.4 Spec: + * jakarta.servlet.forward.request_uri; jakarta.servlet.forward.context_path; + * jakarta.servlet.forward.servlet_path; jakarta.servlet.forward.path_info; + * jakarta.servlet.forward.query_string; + */ + @Test + public void getRequestAttributes4() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, + "jakarta.servlet.forward.request_uri=SET_GOOD;" + + "jakarta.servlet.forward.context_path=SET_GOOD;" + + "jakarta.servlet.forward.servlet_path=SET_GOOD;" + + "jakarta.servlet.forward.path_info=SET_NO;" + + "jakarta.servlet.forward.query_string=SET_GOOD;"); + + TEST_PROPS.setProperty(APITEST, "forwardAttributes1"); + invoke(); + } + + /* + * @testName: getRequestAttributes5 + * + * @assertion_ids: Servlet:SPEC:181.1; Servlet:SPEC:181.2; Servlet:SPEC:181.3; + * Servlet:SPEC:181.4; Servlet:SPEC:181.5; + * + * @test_Strategy: 1. Create servlets TestServlet and ForwardedServlet; 2. In + * TestServlet, get RequestDispatcher by using + * ServletContext.getNamedDispatcher(String), and access ForwardedServlet + * using RequestDispatcher.forward. 3. Verify in ForwardedServlet the + * following request attributes are not set required by Servlet 2.4 Spec: + * jakarta.servlet.forward.request_uri; jakarta.servlet.forward.context_path; + * jakarta.servlet.forward.servlet_path; jakarta.servlet.forward.path_info; + * jakarta.servlet.forward.query_string; + */ + @Test + public void getRequestAttributes5() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, + "jakarta.servlet.forward.request_uri=SET_NO;" + + "jakarta.servlet.forward.context_path=SET_NO;" + + "jakarta.servlet.forward.servlet_path=SET_NO;" + + "jakarta.servlet.forward.path_info=SET_NO;" + + "jakarta.servlet.forward.query_string=SET_NO;"); + + TEST_PROPS.setProperty(APITEST, "forwardAttributes2"); + invoke(); + } + + /* + * @testName: getRequestAttributes6 + * + * @assertion_ids: Servlet:SPEC:181.1; Servlet:SPEC:181.2; Servlet:SPEC:181.3; + * Servlet:SPEC:181.4; Servlet:SPEC:181.5; + * + * @test_Strategy: 1. Create servlets TestServlet, ForwardedServlet and + * MultiForwardedServlet; 2. In TestServlet, get RequestDispatcher by using + * ServletContext.getRequestDispatcher(String), and access + * MultiForwardedServlet using RequestDispatcher.forward. 3. In + * MultiForwardedServlet, get RequestDispatcher by using + * ServletContext.getRequestDispatcher(String), and access ForwardedServlet + * using RequestDispatcher.forward. 4. Verify in ForwardedServlet the + * following request attributes are set required by Servlet 2.4 Spec: + * jakarta.servlet.forward.request_uri; jakarta.servlet.forward.context_path; + * jakarta.servlet.forward.servlet_path; jakarta.servlet.forward.path_info; + * jakarta.servlet.forward.query_string; + */ + @Test + public void getRequestAttributes6() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, + "jakarta.servlet.forward.request_uri=SET_GOOD;" + + "jakarta.servlet.forward.context_path=SET_GOOD;" + + "jakarta.servlet.forward.servlet_path=SET_GOOD;" + + "jakarta.servlet.forward.path_info=SET_NO;" + + "jakarta.servlet.forward.query_string=SET_GOOD;"); + + TEST_PROPS.setProperty(APITEST, "forwardAttributes6"); + invoke(); + } + + /* + * @testName: bufferContent + * + * @assertion_ids: Servlet:SPEC:77; + * + * @test_Strategy: 1. Create servlets TestServlet and ForwardedServlet; 2. In + * TestServlet, first write "Test FAILED" to ServletResponse; then access + * ForwardedServlet using RequestDispatcher.forward. 3. Verify that the + * message "Test FAILED" wrote to ServletResponse is cleared and not sent to + * Client as required by Servlet 2.4 Spec. + */ + @Test + public void bufferContent() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, + "bufferContent_in_ForwardedServlet_invoked"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "Test FAILED"); + TEST_PROPS.setProperty(APITEST, "bufferContent"); + 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.setProperty(REQUEST, + "GET /servlet_spec_requestdispatcher_web/TestServlet?testname=rdNoWrappingTest&operation=0 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Test PASSED"); + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "Test FAILED"); + invoke(); + TEST_PROPS.setProperty(REQUEST, + "GET /servlet_spec_requestdispatcher_web/TestServlet?testname=rdNoWrappingTest&operation=1 HTTP/1.1"); + TEST_PROPS.setProperty(SEARCH_STRING, "Test PASSED"); + TEST_PROPS.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 + * to 8.3 + */ + @Test + public void getRequestURIIncludeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getRequestURIIncludeTest"); + invoke(); + } + + /* + * @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 + * to 8.3 + */ + @Test + public void getRequestURLIncludeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getRequestURLIncludeTest"); + invoke(); + } + + /* + * @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 + * to 8.4 + */ + @Test + public void getRequestURIForwardTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getRequestURIForwardTest"); + invoke(); + } + + /* + * @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 + * to 8.4 + */ + @Test + public void getRequestURLForwardTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getRequestURLForwardTest"); + invoke(); + } + + /* + * @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 + * ?testname=getQueryStringTestInclude; 4. Verify in HttpTestServlet, that + * getQueryString returns correct QueryString + * testname=getQueryStringIncludeTest according to 8.3 + */ + @Test + public void getQueryStringIncludeTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getQueryStringIncludeTest"); + invoke(); + } + + /* + * @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 + * ?testname=getQueryStringTestForward; 4. Verify in HttpTestServlet, that + * getQueryString returns correct QueryString + * testname=getQueryStringTestForward according to 8.4.2 + */ + @Test + public void getQueryStringForwardTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getQueryStringForwardTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestdispatcher/WrapServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestdispatcher/WrapServlet.java new file mode 100644 index 0000000000..40160c5a54 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestdispatcher/WrapServlet.java @@ -0,0 +1,86 @@ +/* + * 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 com.sun.ts.tests.servlet.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/com/sun/ts/tests/servlet/spec/requestdispatcher/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestdispatcher/build.xml new file mode 100644 index 0000000000..e710f941e0 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestdispatcher/build.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestdispatcher/servlet_spec_requestdispatcher_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestdispatcher/servlet_spec_requestdispatcher_web.xml new file mode 100644 index 0000000000..53cbc7bbad --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestdispatcher/servlet_spec_requestdispatcher_web.xml @@ -0,0 +1,73 @@ + + + + + SerJaxSerRequestDispatcher + + TestServlet + com.sun.ts.tests.servlet.spec.requestdispatcher.TestServlet + + + IncludedServlet + com.sun.ts.tests.servlet.spec.requestdispatcher.IncludedServlet + + + MultiForwardedServlet + com.sun.ts.tests.servlet.spec.requestdispatcher.MultiForwardedServlet + + + HttpTestServlet + com.sun.ts.tests.servlet.spec.requestdispatcher.HttpTestServlet + + + ForwardedServlet + com.sun.ts.tests.servlet.spec.requestdispatcher.ForwardedServlet + + + WrapServlet + com.sun.ts.tests.servlet.spec.requestdispatcher.WrapServlet + + + TestServlet + /TestServlet + + + IncludedServlet + /include/IncludedServlet + + + HttpTestServlet + /other/HttpTestServlet + + + ForwardedServlet + /forward/ForwardedServlet + + + MultiForwardedServlet + /forward/MultiForwardedServlet + + + WrapServlet + /WrapServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestmap/TestServlet1.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestmap/TestServlet1.java new file mode 100644 index 0000000000..5f3e6431b5 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestmap/TestServlet1.java @@ -0,0 +1,39 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.requestmap; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet1 extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println("TestServlet1 is invoked"); + pw.println("TestServlet1's URL: /foo/bar/*"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestmap/TestServlet2.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestmap/TestServlet2.java new file mode 100644 index 0000000000..481489e755 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestmap/TestServlet2.java @@ -0,0 +1,39 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.requestmap; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet2 extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println("TestServlet2 is invoked"); + pw.println("TestServlet2's URL: /foo/baR/*"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestmap/TestServlet3.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestmap/TestServlet3.java new file mode 100644 index 0000000000..50d2543fa8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestmap/TestServlet3.java @@ -0,0 +1,39 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.requestmap; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet3 extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println("TestServlet3 is invoked"); + pw.println("TestServlet3's URL /TestServlet3"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestmap/TestServlet4.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestmap/TestServlet4.java new file mode 100644 index 0000000000..6ce7a6904d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestmap/TestServlet4.java @@ -0,0 +1,39 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.requestmap; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet4 extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println("TestServlet4 is invoked"); + pw.println("TestServlet4's URL *.bop"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestmap/TestServlet5.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestmap/TestServlet5.java new file mode 100644 index 0000000000..8f396a53d0 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestmap/TestServlet5.java @@ -0,0 +1,39 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.requestmap; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet5 extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println("TestServlet5 is invoked"); + pw.println("TestServlet5's URL: /foo/bar/TestServlet5"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestmap/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestmap/URLClient.java new file mode 100644 index 0000000000..8a08602ad9 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestmap/URLClient.java @@ -0,0 +1,197 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.requestmap; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_requestmap_web.war") + .addClasses(TestServlet1.class, TestServlet2.class, TestServlet3.class, + TestServlet4.class, TestServlet5.class) + .setWebXML(URLClient.class.getResource("servlet_js_requestmap_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + + /* + * @testName: longestPathMatchTest + * + * @assertion_ids: Servlet:SPEC:134.2; Servlet:SPEC:134.5; Servlet:SPEC:133; + * + * @test_Strategy: 1. Create servlets TestServlet1 with URL /foo/bar/*, + * TestServlet2 with URL /foo/baR/*, TestServlet3 with URL /TestServlet3, + * TestServlet4 with URL *.bop, TestServlet5 with URL /foo/bar/TestServlet5. + * 2. Send request with path /foo/bar/index.html. 3. Verify that TestServlet1 + * is invoked based on Servlet Spec(11.1) that it has longest path-prefix + * match and it is the default Servlet at the path. + */ + @Test + public void longestPathMatchTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "TestServlet1"); + TEST_PROPS.setProperty(APITEST, "foo/bar/index.html"); + invoke(); + } + + /* + * @testName: longestPathMatchTest1 + * + * @assertion_ids: Servlet:SPEC:134.2; Servlet:SPEC:134.5; Servlet:SPEC:133; + * + * @test_Strategy: 1. Create servlets TestServlet1 with URL /foo/bar/*, + * TestServlet2 with URL /foo/baR/*, TestServlet3 with URL /TestServlet3, + * TestServlet4 with URL *.bop, TestServlet5 with URL /foo/bar/TestServlet5. + * 2. Send request with path /foo/bar. 3. Verify that TestServlet1 is invoked + * based on Servlet Spec(11.1) that it has longest path-prefix match and it is + * the default Servlet at the path. + */ + @Test + public void longestPathMatchTest1() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "TestServlet1"); + TEST_PROPS.setProperty(APITEST, "foo/bar"); + invoke(); + } + + /* + * @testName: longestPathMatchTest2 + * + * @assertion_ids: Servlet:SPEC:134.2; Servlet:SPEC:134.5; Servlet:SPEC:133; + * + * @test_Strategy: 1. Create servlets TestServlet1 with URL /foo/bar/*, + * TestServlet2 with URL /foo/baR/*, TestServlet3 with URL /TestServlet3, + * TestServlet4 with URL *.bop, TestServlet5 with URL /foo/bar/TestServlet5. + * 2. Send request with path /foo/baR/TestServlet5. 3. Verify that + * TestServlet2 is invoked based on Servlet Spec(11.1) that it has longest + * path-prefix match and it is the default Servlet at the path. + */ + @Test + public void longestPathMatchTest2() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "TestServlet2"); + TEST_PROPS.setProperty(APITEST, "foo/baR/TestServlet5"); + invoke(); + } + + /* + * @testName: exactMatchTest + * + * @assertion_ids: Servlet:SPEC:134.1; + * + * @test_Strategy: 1. Create servlets TestServlet1 with URL /foo/bar/*, + * TestServlet2 with URL /foo/baR/*, TestServlet3 with URL /TestServlet3, + * TestServlet4 with URL *.bop, TestServlet5 with URL /foo/bar/TestServlet5. + * 2. Send request with path /TestServlet3. 3. Verify that TestServlet3 is + * invoked based on Servlet Spec(11.1) that it has exact match. + */ + @Test + public void exactMatchTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "TestServlet3"); + TEST_PROPS.setProperty(APITEST, "TestServlet3"); + invoke(); + } + + /* + * @testName: exactMatchTest1 + * + * @assertion_ids: Servlet:SPEC:134.1; Servlet:SPEC:134.5; + * + * @test_Strategy: 1. Create servlets TestServlet1 with URL /foo/bar/*, + * TestServlet2 with URL /foo/baR/*, TestServlet3 with URL /TestServlet3, + * TestServlet4 with URL *.bop, TestServlet5 with URL /foo/bar/TestServlet5. + * 2. Send request with path /foo/bar/TestServlet5. 3. Verify that + * TestServlet5 is invoked based on Servlet Spec(11.1) that it has exact + * match. + */ + @Test + public void exactMatchTest1() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "TestServlet5"); + TEST_PROPS.setProperty(APITEST, "foo/bar/TestServlet5"); + invoke(); + } + + /* + * @testName: extMatchTest + * + * @assertion_ids: Servlet:SPEC:134.3; + * + * @test_Strategy: 1. Create servlets TestServlet1 with URL /foo/bar/*, + * TestServlet2 with URL /foo/baR/*, TestServlet3 with URL /TestServlet3, + * TestServlet4 with URL *.bop, TestServlet5 with URL /foo/bar/TestServlet5. + * 2. Send request with path /TestServlet3/racecar.bop 3. Verify that + * TestServlet4 is invoked based on Servlet Spec(11.1) that it has the + * extension match. + */ + @Test + public void extMatchTest() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "TestServlet4"); + TEST_PROPS.setProperty(APITEST, "TestServlet3/racecar.bop"); + invoke(); + } + + /* + * @testName: extMatchTest1 + * + * @assertion_ids: Servlet:SPEC:134.3; + * + * @test_Strategy: 1. Create servlets TestServlet1 with URL /foo/bar/*, + * TestServlet2 with URL /foo/baR/*, TestServlet3 with URL /TestServlet3, + * TestServlet4 with URL *.bop, TestServlet5 with URL /foo/bar/TestServlet5. + * 2. Send request with path /index.bop 3. Verify that TestServlet4 is invoked + * based on Servlet Spec(11.1) that it has the extension match. + */ + @Test + public void extMatchTest1() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "TestServlet4"); + TEST_PROPS.setProperty(APITEST, "index.bop"); + invoke(); + } + + /* + * @testName: notFoundTest1 + * + * @assertion_ids: Servlet:SPEC:134.4; + * + * @test_Strategy: 1. Create servlets TestServlet1 with URL /foo/bar/*, + * TestServlet2 with URL /foo/baR/*, TestServlet3 with URL /TestServlet3, + * TestServlet4 with URL *.bop, TestServlet5 with URL /foo/bar/TestServlet5. + * 2. Send request with path /test/foo/bar/xxx 3. Verify that no match is + * found and 404 should be returned. + */ + @Test + public void notFoundTest1() throws Exception { + TEST_PROPS.setProperty(STATUS_CODE, NOT_FOUND); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/test/foo/bar/xxx" + " HTTP/1.1"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestmap/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestmap/build.xml new file mode 100644 index 0000000000..298a57b60d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestmap/build.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestmap/servlet_js_requestmap_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestmap/servlet_js_requestmap_web.xml new file mode 100644 index 0000000000..3db116ae1b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/requestmap/servlet_js_requestmap_web.xml @@ -0,0 +1,65 @@ + + + + + SerJaxSerRequestMap + + TestServlet1 + com.sun.ts.tests.servlet.spec.requestmap.TestServlet1 + + + TestServlet2 + com.sun.ts.tests.servlet.spec.requestmap.TestServlet2 + + + TestServlet3 + com.sun.ts.tests.servlet.spec.requestmap.TestServlet3 + + + TestServlet4 + com.sun.ts.tests.servlet.spec.requestmap.TestServlet4 + + + TestServlet5 + com.sun.ts.tests.servlet.spec.requestmap.TestServlet5 + + + TestServlet1 + /foo/bar/* + + + TestServlet2 + /foo/baR/* + + + TestServlet3 + /TestServlet3 + + + TestServlet4 + *.bop + + + TestServlet5 + /foo/bar/TestServlet5 + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/annotations/Client.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/annotations/Client.java new file mode 100644 index 0000000000..75b3cdbfbf --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/annotations/Client.java @@ -0,0 +1,513 @@ +/* + * Copyright (c) 2009, 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 + */ + +package com.sun.ts.tests.servlet.spec.security.annotations; + +import com.sun.ts.lib.util.WebUtil; +import com.sun.ts.tests.servlet.common.client.BaseUrlClient; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; + +import java.util.Properties; + +/* + * + */ +public class Client extends BaseUrlClient { + + // TOFIX + + // Constants: + private static final String USERNAME = "user"; + + private static final String PASSWORD = "password"; + + private static final String UNAUTH_USERNAME = "authuser"; + + private static final String UNAUTH_PASSWORD = "authpassword"; + + private static final String USER_PRINCIPAL_SEARCH = "The user principal is: "; // (+username) + + private static final String REMOTE_USER_SEARCH = "getRemoteUser(): "; // (+username) + + // fields: + private String pageDeny = null; + + private String pageSec = null; + + private String pageGuest = null; + + private String pageUnprotected = null; + + private String pageTrans = null; + + private String pagePartial = null; + + private String username = null; + + private String password = null; + + private String unauthUsername = null; + + private String unauthPassword = null; + + private String realm = null; + + private WebUtil.Response response = null; + + private String request = null; + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_sec_annotations_web.war") + .addClasses(DenyAllServlet.class, GuestPageTestServlet.class, PartialDDServlet.class, + ServletSecTestServlet.class, UnProtectedTestServlet.class) + .setWebXML(Client.class.getResource("servlet_sec_annotations_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; securedWebServicePort; + * user; password; authuser; authpassword; ts_home; + * + */ + public void setup(String[] args, Properties p) throws Exception { + super.setup(args, p); + + // user=j2ee + // password=j2ee + // authuser=javajoe + // authpassword=javajoe + + //portnum = Integer.parseInt(p.getProperty("securedWebServicePort")); + + // TOFIX configurable + try { + username = System.getProperty("tck.servlet.username", "j2ee"); + password = System.getProperty("tck.servlet.password", "j2ee"); + unauthUsername = System.getProperty("tck.servlet.unauth.username", "javajoe"); + unauthPassword = System.getProperty("tck.servlet.unauth.password", "javajoe"); + realm = System.getProperty("tck.servlet.realm", ""); + + String pageServletBase = getContextRoot();//"/servlet_sec_annotations_web"; + + String pageServletDeny = pageServletBase + "/ServletDenyAll"; + + String pageServletSec = pageServletBase + "/ServletSecTest"; + + String pageServletGuest = pageServletBase + "/GuestPageTest"; + + String pageServletUnprotected = pageServletBase + "/UnProtectedTest"; + + String pageTransport = pageServletBase + "/TransportServlet"; + + String pagePartialDD = pageServletBase + "/PartialDDTest"; + + pageSec = pageServletSec; + pageDeny = pageServletDeny; + pageGuest = pageServletGuest; + pageUnprotected = pageServletUnprotected; + pageTrans = pageTransport; + pagePartial = pagePartialDD; + + } catch (Exception e) { + logErr("Error: got exception: ", e); + } + } + + /* + * @testName: test1 + * + * @assertion_ids: Servlet:SPEC:214; Servlet:SPEC:215; + * + * @assertion: 1. teh DenyAll annotation must be supported by the Web + * container. Access a web resource that uses the DenyAll annotation applied + * at the class level should result in an access denied. + * + * @test_Strategy: 1. Send request to access DenyAllServlet 2. Receive an + * access denied + */ + @Test + public void test1() throws Exception { + trace("testing DenyAll"); + + TEST_PROPS.setProperty(TEST_NAME, "SecAnnotations/Test1"); + TEST_PROPS.setProperty(REQUEST, getRequestLine("GET", pageDeny)); + TEST_PROPS.setProperty(STATUS_CODE, UNAUTHORIZED); + try { + invoke(); + } catch (Exception e) { + // its possible we were denied access with a FORBIDDEN (403) code instead + // of + // UNAUTHORIZED (401) so retry and check for FORBIDDEN code. If it still + // fails then we have an issue. + trace( + "we tested for Status Code=401 but we could have a 403 code, so check for that."); + TEST_PROPS.setProperty(TEST_NAME, "SecAnnotations/Test1"); + TEST_PROPS.setProperty(REQUEST, getRequestLine("GET", pageDeny)); + TEST_PROPS.setProperty(STATUS_CODE, FORBIDDEN); + invoke(); + } + + trace( + "test1 passed: we were not allowed to perform GET on a servlet with DenyAll anno"); + } + + /* + * @testName: test2 + * + * @assertion_ids: Servlet:SPEC:214; Servlet:SPEC:218; Servlet:SPEC:294; + * + * @assertion: 1. Servlet 3.0 spec (section 13.4 - 3rd from last para) states: + * "When a security-constraint in the portable deployment descriptor includes + * a url-pattern that matches a request URL, the security annotations + * described in this section have no effect on the access policy that applies + * to the request URL." + * + * + * @test_Strategy: 1. We have GuestPageTestServlet setup with DenyAll anno but + * we have DD setup with roles and security-constraints that say POST can be + * accessed by Manager role (via user=javajoe) and according to spec + * statement, the DenyAll anno should be ignored. 2. attempt to POST as user + * javajoe should allow access since DD grants it. 3. do POST with incorrect + * authentication (ie "j2ee") should NOT allows access since "j2ee" is not in + * roles as defined in DD. + */ + @Test + public void test2() throws Exception { + + StringBuilder sb = new StringBuilder(100); + sb.append(USER_PRINCIPAL_SEARCH).append(unauthUsername); + + // attempt to doPost as "javajoe" should be allowed + trace( + "Sending request to resource with valid username/password, but not the right roles..."); + TEST_PROPS.setProperty(TEST_NAME, "SecAnnotations/Test2"); + TEST_PROPS.setProperty(REQUEST, getRequestLine("POST", pageGuest)); + TEST_PROPS.setProperty(BASIC_AUTH_USER, unauthUsername); // "javajoe" + TEST_PROPS.setProperty(BASIC_AUTH_PASSWD, unauthPassword); // "javajoe" + //TEST_PROPS.setProperty(BASIC_AUTH_REALM, realm); // default + TEST_PROPS.setProperty(STATUS_CODE, UNAUTHORIZED); + try { + invoke(); + } catch (Exception ex) { + TEST_PROPS.setProperty(TEST_NAME, "SecAnnotations/Test2"); + TEST_PROPS.setProperty(REQUEST, getRequestLine("POST", pageGuest)); + TEST_PROPS.setProperty(BASIC_AUTH_USER, unauthUsername); // "javajoe" + TEST_PROPS.setProperty(BASIC_AUTH_PASSWD, unauthPassword); // "javajoe" + TEST_PROPS.setProperty(STATUS_CODE, FORBIDDEN); + } + + // attempt to doGet as "javajoe" should be allowed due to DD and + // the RolesAllowed anno in GuestPageTestServlet should be ignored. + // note: doGet metho prints out userprincipal name that we are going to + // check + trace( + "Sending request to resource with valid username/password, but not the right roles..."); + TEST_PROPS.setProperty(SEARCH_STRING, sb.toString()); + TEST_PROPS.setProperty(TEST_NAME, "SecAnnotations/Test2"); + TEST_PROPS.setProperty(REQUEST, getRequestLine("GET", pageGuest)); + TEST_PROPS.setProperty(BASIC_AUTH_USER, unauthUsername); // "javajoe" + TEST_PROPS.setProperty(BASIC_AUTH_PASSWD, unauthPassword); // "javajoe" + TEST_PROPS.setProperty(STATUS_CODE, OK); + invoke(); + + // attempt to doGet as "j2ee" should NOT be allowed since the DD only + // states to allow Manager role (ie javajoe). The RolesAllowed anno + // defined in GuestPageTestServlet.doGet should be completely ignored per + // spec statement cited in the javadoc for this test. + trace( + "Sending request to resource with valid username/password, but not the right roles..."); + TEST_PROPS.setProperty(TEST_NAME, "SecAnnotations/Test2"); + TEST_PROPS.setProperty(REQUEST, getRequestLine("POST", pageGuest)); + TEST_PROPS.setProperty(BASIC_AUTH_USER, username); // "j2ee" + TEST_PROPS.setProperty(BASIC_AUTH_PASSWD, password); // "j2ee" + TEST_PROPS.setProperty(STATUS_CODE, UNAUTHORIZED); + try { + invoke(); + } catch (Exception e) { + // its possible we were denied access with a FORBIDDEN code + // so retry with that code - if it still fails then we have an issue. + TEST_PROPS.setProperty(TEST_NAME, "SecAnnotations/Test2"); + TEST_PROPS.setProperty(REQUEST, getRequestLine("POST", pageGuest)); + TEST_PROPS.setProperty(BASIC_AUTH_USER, username); // "j2ee" + TEST_PROPS.setProperty(BASIC_AUTH_PASSWD, password); // "j2ee" + TEST_PROPS.setProperty(STATUS_CODE, FORBIDDEN); + invoke(); + } + + trace("test2"); + } + + /* + * @testName: test3 + * + * @assertion_ids: Servlet:SPEC:214; Servlet:SPEC:216; + * + * @assertion: 1. Servlet 3.0 (section 13.4) states: "When an annotation is + * specified at both the class and method level, the method targeted + * annotation overrides that on the class (for the method)" 2. PermitAll func + * must be supported by web container + * + * @test_Strategy: 1. create ServletSecTestServlet with DeclareRoles + * annotation at the class level as well as the ServletSecurity anno. 2. we + * created ServletSecTestServlet.doGet() method with PermitAll access 3. try + * to access doGet using creds that would normally fail to ensure PermitAll + * really does work. + * + */ + @Test + public void test3() throws Exception { + String invalidUser = "invalid"; + + // this should all work as @PermitAll is set on ServletSecTestServlet.doGet + TEST_PROPS.setProperty(TEST_NAME, "SecAnnotations/Test3"); + TEST_PROPS.setProperty(REQUEST, getRequestLine("GET", pageSec)); + TEST_PROPS.setProperty(BASIC_AUTH_USER, unauthUsername); // try using + // "invalid" creds + TEST_PROPS.setProperty(BASIC_AUTH_PASSWD, unauthPassword); // and it should + // still work + TEST_PROPS.setProperty(STATUS_CODE, OK); + invoke(); + trace( + "Class level annotation of Roles allowed overridden by method level permit all access."); + + trace("test3 passed."); + } + + /* + * @testName: test4 + * + * @assertion_ids: Servlet:SPEC:214; Servlet:SPEC:216; + * + * @assertion: 1. Servlet 3.0 (section 13.4) states: "When an annotation is + * specified at both the class and method level, the method targeted + * annotation overrides that on the class (for the method) " 2. DenyAll can be + * applied to class and method level so here we are validating its use at the + * method level. + * + * @test_Strategy: 1. create ServletSecTestServlet with RolesAllowed + * annotation at the class level. 2. create ServletSecTestServlet.doPost + * method with DenyAll access set 3. try to access doPost using creds that + * normally work to ensure that setting deny all access really does work. + * + */ + @Test + public void test4() throws Exception { + String invalidUser = "invalid"; + + // now see if we get access denied - since DenyAll anno set on doPost method + TEST_PROPS.setProperty(REQUEST, getRequestLine("POST", pageSec)); + TEST_PROPS.setProperty(BASIC_AUTH_USER, username); + TEST_PROPS.setProperty(BASIC_AUTH_PASSWD, password); + TEST_PROPS.setProperty(STATUS_CODE, UNAUTHORIZED); // check for status code + // 401 + try { + invoke(); + } catch (Exception e) { + // its possible we were denied access with a FORBIDDEN (403) code instead + // of + // UNAUTHORIZED (401) so retry and check for FORBIDDEN code. If it still + // fails then we have an issue. + TEST_PROPS.setProperty(REQUEST, getRequestLine("POST", pageSec)); + TEST_PROPS.setProperty(BASIC_AUTH_USER, username); + TEST_PROPS.setProperty(BASIC_AUTH_PASSWD, password); + TEST_PROPS.setProperty(STATUS_CODE, FORBIDDEN); + invoke(); + } + + trace( + "Class level setting of roles allowed was overridden by deny all access at method level."); + + trace("test4 passed."); + } + + /* + * @testName: test5 + * + * @assertion_ids: Servlet:SPEC:214; Servlet:SPEC:215; + * + * @assertion: Servlet 3.0 spec (section 13.4) states: "These annotations may + * be specified on (that is, targeted to) an HttpServlet implementation class + * or on specific method(s) of the implementation class as defined below." + * + * @test_Strategy: 1. Send request for unprotected servlet that uses the + * PermitAll access at the class level. 2. Receive page + */ + @Test + public void test5() throws Exception { + + trace("Sending request to resource that uses the PermitAll annotation...."); + TEST_PROPS.setProperty(TEST_NAME, "BasicSec/Test5"); + TEST_PROPS.setProperty(BASIC_AUTH_USER, unauthUsername); // try using + // "invalid" creds + TEST_PROPS.setProperty(BASIC_AUTH_PASSWD, unauthPassword); // and it should + // still work + TEST_PROPS.setProperty(REQUEST, getRequestLine("GET", pageUnprotected)); + TEST_PROPS.setProperty(STATUS_CODE, OK); + invoke(); + trace("Class level PermitAll anno returned expected results"); + trace("test5 passed."); + } + + /* + * @testName: test6 + * + * @assertion_ids: Servlet:SPEC:214; Servlet:SPEC:218; Servlet:SPEC:294; + * + * @assertion: This validates Servlet 3.0 spec section 13.4, which says: "When + * a security-constraint in the portable deployment descriptor includes a + * url-pattern that matches a request URL, the security annotations described + * in this section have no effect on the access policy that applies to the + * request URL." + * + * @test_Strategy: 1. Send request with correct authentication for url pattern + * that is defined with a DD that has security-constraints 2. Even if the + * servlet (eg url pattern) is defined with DenyAll anno, it should be ignored + * since the DD has overriding security-constraint note: pageGuest is defined + * with both: DenyAll and DD with security-constraint 3. In this case, the + * GuestPage should be accessible and the DenyAll access setting should be + * ignored. 4. Additionally, the DD has an authconstraint set for Manager + * (user==javajoe) so we want to verify that user is the principal passed into + * the servlet. + */ + @Test + public void test6() throws Exception { + + trace( + "Sending request to resource where DD allows access to override any restricting annotation..."); + TEST_PROPS.setProperty(TEST_NAME, "SecAnnotations/Test6"); + + // attempt to doGet as "j2ee" should NOT be allowed since the DD only + // states to allow Manager role (ie javajoe). The RolesAllowed annon + // defined in GuestPageTestServlet.doGet should be completely ignored per + // spec statement cited in the javadoc for this test. + trace( + "Sending request to resource with valid username/password, but not the right roles..."); + + TEST_PROPS.setProperty(TEST_NAME, "SecAnnotations/Test6"); + TEST_PROPS.setProperty(REQUEST, getRequestLine("POST", pageGuest)); + TEST_PROPS.setProperty(BASIC_AUTH_USER, username); // "j2ee" + TEST_PROPS.setProperty(BASIC_AUTH_PASSWD, password); // "j2ee" + TEST_PROPS.setProperty(STATUS_CODE, UNAUTHORIZED); + try { + invoke(); + } catch (Exception e) { + // its possible we were denied access with a FORBIDDEN code + // so retry with that code - if it still fails then we have an issue. + TEST_PROPS.setProperty(TEST_NAME, "SecAnnotations/Test6"); + TEST_PROPS.setProperty(REQUEST, getRequestLine("POST", pageGuest)); + TEST_PROPS.setProperty(BASIC_AUTH_USER, username); // "j2ee" + TEST_PROPS.setProperty(BASIC_AUTH_PASSWD, password); // "j2ee" + TEST_PROPS.setProperty(STATUS_CODE, FORBIDDEN); + invoke(); + } + + trace("User successfully accessed the resource"); + } + + /* + * + * @testName: test7 + * + * @assertion_ids: + * + * @assertion: 1. http-method-omission + * + * + * + * @test_Strategy: 1. Send request to access servlet where there is a + * corresponding DD that excludes POST method via the http-method-omission DD + * element. (This means that all access to the PartialDD only allowed by + * Administrator EXCEPT for POST which has NO security constraints and is thus + * allowed by all. 2. Receive an access denied when trying to access GET with + * no cred (if the http-method-omission does its job.) + * + */ + @Test + public void test7() throws Exception { + trace("testing http-method-omission"); + + // try to access servlet via GET with NO creds/roles should fail + TEST_PROPS.setProperty(TEST_NAME, "SecAnnotations/Test7"); + TEST_PROPS.setProperty(REQUEST, getRequestLine("GET", pagePartial)); + TEST_PROPS.setProperty(STATUS_CODE, UNAUTHORIZED); + try { + invoke(); + } catch (Exception e) { + // its possible we were denied access with a FORBIDDEN (403) code instead + // of + // UNAUTHORIZED (401) so retry and check for FORBIDDEN code. If it still + // fails then we have an issue. + trace( + "we tested for Status Code=401 but we could have a 403 code, so check for that."); + TEST_PROPS.setProperty(TEST_NAME, "SecAnnotations/Test7"); + TEST_PROPS.setProperty(REQUEST, getRequestLine("GET", pagePartial)); + TEST_PROPS.setProperty(BASIC_AUTH_USER, username); // try as "j2ee" + TEST_PROPS.setProperty(BASIC_AUTH_PASSWD, password); // try as "j2ee" + TEST_PROPS.setProperty(STATUS_CODE, FORBIDDEN); + invoke(); + } + trace("test7: complete doGet() with no creds - now starting doPost"); + + // try to access servlet via GET with creds/roles should pass + TEST_PROPS.setProperty(TEST_NAME, "SecAnnotations/Test7"); + TEST_PROPS.setProperty(REQUEST, getRequestLine("GET", pagePartial)); + TEST_PROPS.setProperty(BASIC_AUTH_USER, username); // try as "j2ee" + TEST_PROPS.setProperty(BASIC_AUTH_PASSWD, password); // try as "j2ee" + TEST_PROPS.setProperty(STATUS_CODE, OK); + invoke(); + trace("test7: complete doGet() with creds - now starting doPost"); + + // we should be allowed to do POST with NO creds + TEST_PROPS.setProperty(TEST_NAME, "SecAnnotations/Test7"); + TEST_PROPS.setProperty(REQUEST, getRequestLine("POST", pagePartial)); + TEST_PROPS.setProperty(STATUS_CODE, OK); + invoke(); + trace("test7: complete doPost() with no creds."); + + trace("test7 passed: servlet with http-method-omission settings."); + } + + /** + * Returns a valid HTTP/1.1 request line. + * + * @param method + * the request method + * @param path + * the request path + * @return a valid HTTP/1.1 request line + */ + private static String getRequestLine(String method, String path) { + return method + " " + path + " HTTP/1.1"; + } + + /** + * Simple wrapper around TestUtil.logTrace(). + * + * @param message + * - the message to log + */ + private void trace(String message) { + logger.debug("[Client]: {}", message); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/annotations/DenyAllServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/annotations/DenyAllServlet.java new file mode 100644 index 0000000000..a452dd46e2 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/annotations/DenyAllServlet.java @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2009, 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: DenyAllServlet.java 52684 2007-02-12 04:30:10Z lschwenk $ + */ + +package com.sun.ts.tests.servlet.spec.security.annotations; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.HttpConstraint; +import jakarta.servlet.annotation.ServletSecurity; +import jakarta.servlet.annotation.ServletSecurity.EmptyRoleSemantic; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +/* + * This is denying all + */ +@ServletSecurity(@HttpConstraint(EmptyRoleSemantic.DENY)) +@WebServlet("/ServletDenyAll") +public class DenyAllServlet extends HttpServlet { + + // + // this must be supported per Servlet 3.0 spec (section 13.4), bullet item 1. + // + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + PrintWriter out = response.getWriter(); + + System.out.println("Inside DenyAllServlet ....." + "
"); + if ((request != null) && (request.getUserPrincipal() != null)) { + System.out.println("The user principal is: " + + request.getUserPrincipal().getName() + "
"); + System.err.println("The user principal is: " + + request.getUserPrincipal().getName() + "
"); + out.println("The user principal is: " + + request.getUserPrincipal().getName() + "
"); + out.println("getRemoteUser(): " + request.getRemoteUser() + "
"); + } + + // Surround these with !'s so they are easier to search for. + // (i.e. we can search for !true! or !false!) + if (request != null) { + out.println( + "isUserInRole(\"ADM\"): !" + request.isUserInRole("ADM") + "!
"); + out.println( + "isUserInRole(\"MGR\"): !" + request.isUserInRole("MGR") + "!
"); + out.println( + "isUserInRole(\"EMP\"): !" + request.isUserInRole("EMP") + "!
"); + out.println("isUserInRole(\"Administrator\"): !" + + request.isUserInRole("Administrator") + "!
"); + } else { + out.println("DenyAllServlet.service() - request is null"); + } + + } + + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, java.io.IOException { + + PrintWriter out = response.getWriter(); + + if ((request != null) && (request.getUserPrincipal() != null)) { + System.out.println("Inside DenyAllServlet.doGet() ....." + "
"); + System.out.println("The user principal is: " + + request.getUserPrincipal().getName() + "
"); + System.err.println("The user principal is: " + + request.getUserPrincipal().getName() + "
"); + out.println("The user principal is: " + + request.getUserPrincipal().getName() + "
"); + out.println("getRemoteUser(): " + request.getRemoteUser() + "
"); + } else { + out.println( + "DenyAllServlet.doGet() - could not get request.getUserPrincipal()"); + } + + // Surround these with !'s so they are easier to search for. + // (i.e. we can search for !true! or !false!) + if (request != null) { + out.println("isUserInRole(\"Administrator\"): !" + + request.isUserInRole("Administrator") + "!
"); + out.println("isUserInRole(\"Manager\"): !" + + request.isUserInRole("Manager") + "!
"); + out.println("isUserInRole(\"Employee\"): !" + + request.isUserInRole("Employee") + "!
"); + } else { + out.println("DenyAllServlet.service() - request is null"); + } + + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/annotations/GuestPageTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/annotations/GuestPageTestServlet.java new file mode 100644 index 0000000000..73b8d91e5d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/annotations/GuestPageTestServlet.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2009, 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: GuestPageTestServlet.java 52684 2007-02-12 04:30:10Z lschwenk $ + */ +package com.sun.ts.tests.servlet.spec.security.annotations; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.annotation.security.DeclareRoles; +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.HttpConstraint; +import jakarta.servlet.annotation.HttpMethodConstraint; +import jakarta.servlet.annotation.ServletSecurity; +import jakarta.servlet.annotation.ServletSecurity.EmptyRoleSemantic; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +/* + * Using annotations, this servlet declares roles and then deny's all as a + * default, however GET is specified with a RolesAllowed="Administrator". + * There is a duplicate Servlet url/context defined in the DD - which means + * that the DD should override the annotations defined in this class. + * The DD indicates that role Manager (user=javajoe) has perm to do GET/POST + * requess. This will take precedence over the annotations of this class which + * state that role Administrator (user=j2ee) can issue GET requests. + */ + +@DeclareRoles({ "Administrator", "Manager", "Employee" }) +@ServletSecurity(value = @HttpConstraint(EmptyRoleSemantic.DENY), httpMethodConstraints = { + @HttpMethodConstraint(value = "GET", rolesAllowed = "Administrator") }) +@WebServlet(name = "GuestPageTestLogicalName", urlPatterns = { + "/GuestPageTest" }) +public class GuestPageTestServlet extends HttpServlet { + + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + PrintWriter out = response.getWriter(); + if ((request != null) && (request.getUserPrincipal() != null)) { + out.println("The user principal is: " + + request.getUserPrincipal().getName() + "
"); + } else { + out.println( + "Could not get principal via request.getUserPrincipal() " + "
"); + } + + } + + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + PrintWriter out = response.getWriter(); + if ((request != null) && (request.getUserPrincipal() != null)) { + out.println("The user principal is: " + + request.getUserPrincipal().getName() + "
"); + } else { + out.println( + "Could not get principal via request.getUserPrincipal() " + "
"); + } + + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/annotations/PartialDDServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/annotations/PartialDDServlet.java new file mode 100644 index 0000000000..664d4cf69e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/annotations/PartialDDServlet.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2009, 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: PartialDDServlet.java 52684 2007-02-12 04:30:10Z lschwenk $ + */ +package com.sun.ts.tests.servlet.spec.security.annotations; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +/* + * this permits all - since PERMIT is the default + */ +public class PartialDDServlet extends HttpServlet { + + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + PrintWriter out = response.getWriter(); + if ((request != null) && (request.getUserPrincipal() != null)) { + out.println("The user principal is: " + + request.getUserPrincipal().getName() + "
"); + } else { + out.println("The user principal is null!
"); + } + } + + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + PrintWriter out = response.getWriter(); + if ((request != null) && (request.getUserPrincipal() != null)) { + out.println("The user principal is: " + + request.getUserPrincipal().getName() + "
"); + } else { + out.println("The user principal is null!
"); + } + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/annotations/ServletSecTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/annotations/ServletSecTestServlet.java new file mode 100644 index 0000000000..fda422e7a6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/annotations/ServletSecTestServlet.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2009, 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: ServletSecTestServlet.java 52684 2007-02-12 04:30:10Z lschwenk $ + */ + +package com.sun.ts.tests.servlet.spec.security.annotations; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.annotation.security.DeclareRoles; +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.HttpConstraint; +import jakarta.servlet.annotation.HttpMethodConstraint; +import jakarta.servlet.annotation.ServletSecurity; +import jakarta.servlet.annotation.ServletSecurity.EmptyRoleSemantic; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +/* + * this declares several roles, specifies which roles are allowed, then + * sets POST to DENYALL and sets GET TO PERMITALL. + */ +@DeclareRoles({ "Administrator", "Manager", "Employee" }) +@ServletSecurity(value = @HttpConstraint(rolesAllowed = { + "Administrator" }), httpMethodConstraints = { + @HttpMethodConstraint(value = "POST", emptyRoleSemantic = EmptyRoleSemantic.DENY), + @HttpMethodConstraint(value = "GET", emptyRoleSemantic = EmptyRoleSemantic.PERMIT) }) +@WebServlet("/ServletSecTest") +public class ServletSecTestServlet extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + PrintWriter out = response.getWriter(); + System.out + .println("Inside ServletSecTestServlet.service() ....." + "
"); + } + + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, java.io.IOException { + + PrintWriter out = response.getWriter(); + System.out + .println("Inside ServletSecTestServlet.doTrace() ....." + "
"); + } + + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, java.io.IOException { + + PrintWriter out = response.getWriter(); + System.out.println("Inside ServletSecTestServlet.doGet() ....." + "
"); + + if ((request != null) && (request.getUserPrincipal() != null)) { + out.println("The user principal is: " + + request.getUserPrincipal().getName() + "
"); + } else { + out.println("The user principal is: Null." + "
"); + } + + if (request != null) { + out.println( + "isUserInRole(\"ADM\"): !" + request.isUserInRole("ADM") + "!
"); + out.println( + "isUserInRole(\"MGR\"): !" + request.isUserInRole("MGR") + "!
"); + out.println( + "isUserInRole(\"EMP\"): !" + request.isUserInRole("EMP") + "!
"); + out.println("isUserInRole(\"Administrator\"): !" + + request.isUserInRole("Administrator") + "!
"); + } + + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/annotations/UnProtectedTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/annotations/UnProtectedTestServlet.java new file mode 100644 index 0000000000..949a84502f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/annotations/UnProtectedTestServlet.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2009, 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: UnProtectedTestServlet.java 52684 2007-02-12 04:30:10Z lschwenk $ + */ + +package com.sun.ts.tests.servlet.spec.security.annotations; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.ServletSecurity; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +/* + * this sets PERMITALL on everything. + */ + +@ServletSecurity +@WebServlet("/UnProtectedTest") +public class UnProtectedTestServlet extends HttpServlet { + + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter out = response.getWriter(); + if ((request != null) && (request.getUserPrincipal() == null)) { + out.println( + "The user principal is: " + request.getUserPrincipal() + "
"); + } else { + out.println("The user principal is: " + + request.getUserPrincipal().getName() + "
"); + } + + if ((request != null) && (request.getUserPrincipal() != null)) { + // Output whether the user is in any of the known or an unknown role. + // Surround these with !'s so they are easier to search for. + // (i.e. we can search for !true! or !false!) + out.println( + "isUserInRole(\"ADM\"): !" + request.isUserInRole("ADM") + "!
"); + out.println( + "isUserInRole(\"MGR\"): !" + request.isUserInRole("MGR") + "!
"); + out.println( + "isUserInRole(\"EMP\"): !" + request.isUserInRole("EMP") + "!
"); + } + + if (request != null) { + // Test getRemoteUser() functionality: + out.println("
"); + out.println("getRemoteUser(): " + request.getRemoteUser()); + } else { + out.println("UnProtectedTestServlet.service() has null request"); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/annotations/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/annotations/build.xml new file mode 100644 index 0000000000..bc03293abc --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/annotations/build.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/annotations/servlet_sec_annotations.ear.sun-application.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/annotations/servlet_sec_annotations.ear.sun-application.xml new file mode 100644 index 0000000000..17ea98cca9 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/annotations/servlet_sec_annotations.ear.sun-application.xml @@ -0,0 +1,35 @@ + + + + + + + Administrator + j2ee + + + Manager + javajoe + + + Employee + javajoe + j2ee + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/annotations/servlet_sec_annotations_web.war.sun-web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/annotations/servlet_sec_annotations_web.war.sun-web.xml new file mode 100644 index 0000000000..5cee949480 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/annotations/servlet_sec_annotations_web.war.sun-web.xml @@ -0,0 +1,36 @@ + + + + + + servlet_sec_annotations_web + + Administrator + j2ee + + + Manager + javajoe + + + Employee + javajoe + j2ee + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/annotations/servlet_sec_annotations_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/annotations/servlet_sec_annotations_web.xml new file mode 100644 index 0000000000..f0126406d7 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/annotations/servlet_sec_annotations_web.xml @@ -0,0 +1,94 @@ + + + + + servlet_sec_annotations + + GuestPageTestLogicalName + com.sun.ts.tests.servlet.spec.security.annotations.GuestPageTestServlet + + MGR + Manager + + + + PartialDDTestLogicalName + com.sun.ts.tests.servlet.spec.security.annotations.PartialDDServlet + + ADM + Administrator + + + + PartialDDTestLogicalName + /PartialDDTest + + + GuestPageTestLogicalName + /GuestPageTest + + + + MySecureBit1 + /GuestPageTest + POST + GET + + + Manager + + + NONE + + + + + MySecureBit2 + /PartialDDTest + POST + + + Administrator + + + NONE + + + + 54 + + + BASIC + + + the administrator role + Administrator + + + the manager role + Manager + + + the employee role + Employee + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/build.xml new file mode 100644 index 0000000000..0ba97f76a1 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/build.xml @@ -0,0 +1,22 @@ + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/clientcert/Client.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/clientcert/Client.java new file mode 100644 index 0000000000..01942d8ed7 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/clientcert/Client.java @@ -0,0 +1,309 @@ +/* + * Copyright (c) 2007, 2021 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 + */ + +package com.sun.ts.tests.servlet.spec.security.clientcert; + +import com.sun.ts.lib.util.WebUtil; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.container.test.api.OperateOnDeployment; +import org.jboss.arquillian.container.test.api.TargetsContainer; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.HttpsURLConnection; +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URI; +import java.net.URL; +import java.net.URLConnection; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.Certificate; +import java.security.cert.CertificateException; +import java.time.Duration; +import java.util.Properties; + +import static org.apache.commons.io.FileUtils.readFileToByteArray; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * @author Raja Perumal + */ +public class Client extends AbstractUrlClient { + + // TOFIX + + private static final Logger LOGGER = LoggerFactory.getLogger(Client.class); + + /** + * Deployment for the test + */ + @Deployment(testable = false, name = "webapp-https") + @TargetsContainer("https") + public static WebArchive getTestArchive() throws Exception { + System.setProperty("jdk.internal.httpclient.disableHostnameVerification", Boolean.TRUE.toString()); + +// try { +// // specific glassfish so ignore any issue with +// File clientKeyStoreFile = new File("target/test-classes/certificates/clientcert.jks"); +// assertTrue(clientKeyStoreFile.exists()); +// System.setProperty("javax.net.ssl.keyStore", clientKeyStoreFile.getAbsolutePath()); +// System.setProperty("javax.net.ssl.keyStorePassword", "changeit"); +// +// File clientPublicCertFile = new File("target/test-classes/certificates/cts_cert"); +// assertTrue(clientPublicCertFile.exists()); +// +// Collection clientPublicCertificates; +// try { +// clientPublicCertificates = CertificateFactory.getInstance("X.509") +// .generateCertificates(new ByteArrayInputStream(readFileToByteArray(clientPublicCertFile))); +// } catch (CertificateException | IOException e) { +// throw new IllegalStateException(e); +// } +// +// for (Certificate certificate : clientPublicCertificates) { +// addCertificateToContainerTrustStore("tcktest", certificate); +// } +// +// String keystorePath = System.getProperty("keystore.path"); +// if (keystorePath!=null) { +// Path trustStorePath = Paths.get(keystorePath); +// assertNotNull(trustStorePath); +// assertTrue(Files.exists(trustStorePath)); +// +// LOGGER.info("Using truststore from: {}", trustStorePath.toAbsolutePath()); +// +// System.setProperty("javax.net.ssl.trustStore", trustStorePath.toAbsolutePath().toString()); +// } +// +// System.setProperty("jdk.tls.client.protocols", "TLSv1.2"); +// } catch (Throwable e) { +// LOGGER.debug("ignore glassfish specific", e); +// } + return ShrinkWrap.create(WebArchive.class, "clientcert_web.war") + .addClasses(ServletSecTestServlet.class) + .addAsWebInfResource("com/sun/ts/tests/servlet/spec/security/clientcert/clientcert_web.war.sun-web.xml", + "sun-web.xml") + .setWebXML(Client.class.getResource("clientcert_web.xml")); + } + + public static void addCertificateToContainerTrustStore(String alias, Certificate clientCertificate) { + + Path cacertsPath = Paths.get(System.getProperty("keystore.path")); + String domain = System.getProperty("domain1"); + + if (!cacertsPath.toFile().exists()) { + throw new IllegalStateException("The container trust store at " + cacertsPath.toAbsolutePath() + " does not exists"); + } + + + LOGGER.info("*** Adding certificate to container trust store: " + cacertsPath.toAbsolutePath()); + + KeyStore keyStore = null; + try (InputStream in = new FileInputStream(cacertsPath.toAbsolutePath().toFile())) { + keyStore = KeyStore.getInstance("JKS"); + keyStore.load(in, "changeit".toCharArray()); + + Certificate existingCertificate = keyStore.getCertificate(alias); + if (!clientCertificate.equals(existingCertificate)) { + keyStore.setCertificateEntry(alias, clientCertificate); + keyStore.store(new FileOutputStream(cacertsPath.toAbsolutePath().toFile()), "changeit".toCharArray()); + //restartDomain(); + } else { + System.out.println("Server's truststore already contains certificate"); + } + } catch (KeyStoreException | NoSuchAlgorithmException | CertificateException | IOException e) { + throw new IllegalStateException(e); + } + } + + public static Path getAdminCliJar() { + return Paths.get(System.getProperty("glassfish.home") , "glassfish/modules/admin-cli.jar"); + } + private static void restartDomain() throws IOException { + ProcessBuilder processBuilder = new ProcessBuilder("java", "-jar", + getAdminCliJar().toAbsolutePath().toString(), "restart-domain", "domain1").inheritIO(); + processBuilder.start(); + } + + @ArquillianResource + @OperateOnDeployment("webapp-https") URL urlHttps; + + // Configurable constants: + private String hostname = null; + + private int portnum = 0; + + private String tlsVersion; + + private String pageBase = "/clientcert_web"; + + private String authorizedPage = "/ServletSecTest"; + + private String user = null; + + // Constants: + private final String webHostProp = "webServerHost"; + + private final String webPortProp = "webServerPort"; + + private final String failString = "FAILED!"; + + // DN name for CTS certificate + private final String username = "CN=CTS, OU=Java Software, O=Sun Microsystems Inc., L=Burlington, ST=MA, C=US"; + + // Shared test variables: + private String request = null; + + private WebUtil.Response response = null; + + private HostnameVerifier hostnameVerifier; + /* + * @class.setup_props: webServerHost; webServerPort; securedWebServicePort; + * certLoginUserAlias; + * + */ + public void setup(String[] args, Properties p) throws Exception { + + hostname = urlHttps.getHost(); + + if ("localhost".equals(hostname)) { + hostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier(); + //for localhost testing only + HttpsURLConnection.setDefaultHostnameVerifier((hostname, sslSession) -> hostname.equals("localhost")); + } + + p.setProperty(webHostProp, hostname); + portnum = Integer.getInteger("securedWebServicePort", urlHttps.getPort());// Integer.parseInt(p.getProperty("securedWebServicePort")); + p.setProperty("securedWebServicePort", Integer.toString(portnum)); + tlsVersion = System.getProperty("client.cert.test.jdk.tls.client.protocols", p.getProperty("client.cert.test.jdk.tls.client.protocols")); + + logger.info("securedWebServicePort = {}", p.getProperty("securedWebServicePort")); + + if (tlsVersion != null) { + logger.info("client.cert.test.jdk.tls.client.protocols = {}", tlsVersion); + } + + } + + @AfterEach + public void cleanup() { + if (hostnameVerifier != null) { + HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier); + } + } + + /* + * @testName: clientCertTest + * + * @assertion_ids: Servlet:SPEC:140; Servlet:SPEC:368; Servlet:SPEC:369; + * Servlet:SPEC:26; Servlet:SPEC:26.1; Servlet:SPEC:26.2; Servlet:SPEC:26.3; + * Servlet:JAVADOC:356 + * + * @test_strategy: 1. Look for the following request attributes a) + * cipher-suite b) key-size c) SSL certificate If any of the above attributes + * are not set report test failure. + * + * 2. Verify the request.getAuthType returns CLIENT_CERT + * + * Note: If a request has been transmitted over a secure protocol, such as + * HTTPS, this information must be exposed via the isSecure method of the + * ServletRequest interface. The web container must expose the following + * attributes to the servlet programmer. 1) The cipher suite 2) the bit size + * of the algorithm + * + * If there is an SSL certificate associated with the request, it must be + * exposed by the servlet container to the servlet programmer as an array of + * objects of type java.security.cert.X509Certificate + * + */ + @Test + public void clientCertTest() throws Exception { + + String testName = "clientCertTest"; + String url = getURLString("https", hostname, portnum, pageBase.substring(1) + authorizedPage); + + if (tlsVersion != null) { + System.setProperty("jdk.tls.client.protocols", tlsVersion); + } + + URL newURL = new URL(url); + // open HttpsURLConnection using TSHttpsURLConnection + URLConnection httpsURLConn = getHttpsURLConnection(newURL); + try (InputStream content = httpsURLConn.getInputStream(); + BufferedReader in = new BufferedReader(new InputStreamReader(content))) { + + StringBuilder output = new StringBuilder(); + String line; + while ((line = in.readLine()) != null) { + output.append(line); + logger.trace("line: {}", line); + } + + // compare getRemoteUser() obtained from server's response + // with the username stored in ts.jte + // + // Even though the output need not be identical (because + // of appserver realms) the output should have substring + // match for username stored in ts.jte. + // + String userNameToSearch = username; + if (output.indexOf(userNameToSearch) == -1) { + throw new Exception(testName + ": getRemoteUser(): " + "- did not find \"" + + userNameToSearch + "\" in log."); + } else { + logger.debug("Additional verification done"); + } + + // verify output for expected test result + verifyTestOutput(output.toString(), testName); + + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new Exception(testName + ": FAILED", e); + } + + } + + public void verifyTestOutput(String output, String testName) throws Exception { + // check for the occurance of +": PASSED" + // message in server's response. If this message is not present + // report test failure. + if (!output.contains(testName + ": PASSED")) { + logger.error("Test {} Not Expected String from the output = {}: PASSED", testName, output); + throw new Exception(testName + ": FAILED"); + } + } + +} \ No newline at end of file diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/clientcert/ServletSecTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/clientcert/ServletSecTestServlet.java new file mode 100755 index 0000000000..7f8c8f64da --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/clientcert/ServletSecTestServlet.java @@ -0,0 +1,155 @@ +/* + * 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 + */ + +package com.sun.ts.tests.servlet.spec.security.clientcert; + +import java.io.IOException; +import java.io.PrintWriter; +import java.security.cert.X509Certificate; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class ServletSecTestServlet extends HttpServlet { + private boolean fail = false; + + private String FAILSTRING = "FAILED"; + + private String PASSSTRING = "PASSED"; + + /* + * testName: clientCertTest + * + * 1) If a request has been transmitted over a secure protocol, such as HTTPS, + * this information must be exposed via the isSecure method of the + * ServletRequest interface. The web container must expose the following + * attributes to the servlet programmer. 1) The cipher suite 2) the bit size + * of the algorithm 3) SSL certificate + * + * If any of the above attributes are not set report test failure. + * + * 2. Verify the request.getAuthType returns CLIENT_CERT + * + * If there is an SSL certificate associated with the request, it must be + * exposed by the servlet container to the servlet programmer as an array of + * objects of type java.security.cert.X509Certificate + * + * See Also: * Servlet 2.3 Specification section 4.7 + * + * @test_strategy: 1. Look for the following request attributes a) + * cipher-suite b) key-size c) SSL certificate If any of the above attributes + * is not set/incorrect, report test failure. + * + * Note: SSL certificate attribute will be set only if there is a client + * certificate involved in SSL connection. + * + * + */ + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + System.out.println("in service"); + + PrintWriter out = response.getWriter(); + + out.println("getRemoteUser(): " + request.getRemoteUser() + "
"); + + // Surround these with !'s so they are easier to search for. + // (i.e. we can search for !true! or !false!) + out.println( + "isUserInRole(\"ADM\"): !" + request.isUserInRole("ADM") + "!
"); + + String testName = "clientCertTest"; + + String cipherSuiteAttrib = "jakarta.servlet.request.cipher_suite"; + String keySizeAttrib = "jakarta.servlet.request.key_size"; + String certificateAttrib = "jakarta.servlet.request.X509Certificate"; + + String cipherSuite = null; + Integer keySize = new Integer(0); + X509Certificate[] certificates = null; + + try { + fail = false; + + if (request.getUserPrincipal() != null) { + String userPrincipalName = request.getUserPrincipal().getName(); + out.println("Caller principal Name = " + userPrincipalName); + if (userPrincipalName.equals("")) { + fail = true; + } + + } else { + out.println("Caller principal = null"); + fail = true; + } + + cipherSuite = (String) request.getAttribute(cipherSuiteAttrib); + + // verify cipher-suite attribute + if (cipherSuite == null) { + out.println( + testName + ": " + FAILSTRING + " - cipher-suite attribute not set"); + fail = true; + } else + out.println(testName + ": cipher-suite : " + cipherSuite); + + keySize = (Integer) request.getAttribute(keySizeAttrib); + + // verify key-size attribute + if (keySize == null) { + out.println( + testName + ": " + FAILSTRING + " - key-size attribute not set"); + fail = true; + } else + out.println(testName + ": key-size : " + keySize.toString()); + + certificates = (X509Certificate[]) request.getAttribute(certificateAttrib); + + // verify SSL certificate attribute + if (certificates != null) { + for (int i = 0; i < certificates.length; i++) { + + X509Certificate x509Certificate = certificates[i]; + out.println(testName + ": certificate [" + i + "]=" + x509Certificate.toString()); + } + } else { + out.println(testName + ": " + FAILSTRING + " - No SSL certificate found"); + fail = true; + + } + + // verify authenticate type + String authType = request.getAuthType(); + if (!authType.equals("CLIENT_CERT")) { + out.println(testName + ":" + FAILSTRING + + " - Server returns wrong authentication type : " + authType + + " : expected authentication type is CLIENT_CERT"); + fail = true; + } + + if (!fail) { + out.println(testName + ": " + PASSSTRING); + } + } catch (Exception e) { + out.println( + testName + ": " + FAILSTRING + " - Exception: " + e.getMessage()); + e.printStackTrace(); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/clientcert/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/clientcert/build.xml new file mode 100755 index 0000000000..0475862faf --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/clientcert/build.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/clientcert/clientcert.ear.sun-application.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/clientcert/clientcert.ear.sun-application.xml new file mode 100755 index 0000000000..08f5628b39 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/clientcert/clientcert.ear.sun-application.xml @@ -0,0 +1,32 @@ + + + + + + + clientcert_web.war + clientcert_web + + 0 + + Administrator + CN=CTS,OU=Java Software,O=Sun Microsystems Inc.,L=Burlington,ST=MA,C=US + CN=CTS, OU=Java Software, O=Sun Microsystems Inc., L=Burlington, ST=MA, C=US + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/clientcert/clientcert_web.war.sun-web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/clientcert/clientcert_web.war.sun-web.xml new file mode 100644 index 0000000000..2b301d6b3a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/clientcert/clientcert_web.war.sun-web.xml @@ -0,0 +1,28 @@ + + + + + + clientcert_web + + Administrator + CN=CTS,OU=Java Software,O=Sun Microsystems Inc.,L=Burlington,ST=MA,C=US + CN=CTS, OU=Java Software, O=Sun Microsystems Inc., L=Burlington, ST=MA, C=US + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/clientcert/clientcert_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/clientcert/clientcert_web.xml new file mode 100755 index 0000000000..6566d36630 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/clientcert/clientcert_web.xml @@ -0,0 +1,58 @@ + + + + + clientcert + + ServletSecTestLogicalName + com.sun.ts.tests.servlet.spec.security.clientcert.ServletSecTestServlet + + ADM + Administrator + + + + ServletSecTestLogicalName + /ServletSecTest + + + 54 + + + + MySecureBit0 + /ServletSecTest + GET + POST + + + Administrator + + + CONFIDENTIAL + + + + CLIENT-CERT + + + the administrator role + Administrator + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/clientcertanno/Client.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/clientcertanno/Client.java new file mode 100644 index 0000000000..7b277ab9fb --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/clientcertanno/Client.java @@ -0,0 +1,224 @@ +/* + * Copyright (c) 2007, 2021 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 + */ + +package com.sun.ts.tests.servlet.spec.security.clientcertanno; + +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.lib.util.WebUtil; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.container.test.api.OperateOnDeployment; +import org.jboss.arquillian.container.test.api.TargetsContainer; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.HttpsURLConnection; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Serializable; +import java.net.URL; +import java.net.URLConnection; +import java.util.Properties; + +/** + * @author Raja Perumal + * + * @description This is a similar test class as what is in the clientcert dir + * with the major difference being that the servlet under test uses + * Security annotations with the ultimate goal being to test client + * cert w/ Transport guarantee mechanism. + */ +public class Client extends AbstractUrlClient { + + /** + * Deployment for the test + */ + @Deployment(testable = false, name = "webapp-https") + @TargetsContainer("https") + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "clientcertanno_web.war") + .addClasses(ServletSecTestServlet.class) + .setWebXML(Client.class.getResource("clientcertanno_web.xml")); + } + + @ArquillianResource + @OperateOnDeployment("webapp-https") URL urlHttps; + + // Configurable constants: + private String hostname = null; + + private int portnum = 0; + + private String tlsVersion; + + private String pageBase = "/clientcertanno_web"; + + private String authorizedPage = "/ServletSecTest"; + + private String user = null; + + // Constants: + private final String webHostProp = "webServerHost"; + + private final String failString = "FAILED!"; + + // DN name for CTS certificate + private final String username = "CN=CTS, OU=Java Software, O=Sun Microsystems Inc., L=Burlington, ST=MA, C=US"; + + // Shared test variables: + private String request = null; + + private WebUtil.Response response = null; + + private HostnameVerifier hostnameVerifier; + + /* + * @class.setup_props: webServerHost; webServerPort; securedWebServicePort; + * certLoginUserAlias; + * + */ + public void setup(String[] args, Properties p) throws Exception { + + hostname = urlHttps.getHost(); + + if ("localhost".equals(hostname)) { + hostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier(); + //for localhost testing only + HttpsURLConnection + .setDefaultHostnameVerifier((hostname, sslSession) -> hostname.equals("localhost")? true : false); + } + + p.setProperty(webHostProp, hostname); + + portnum = urlHttps.getPort(); + p.setProperty("securedWebServicePort", Integer.toString(portnum)); + tlsVersion = p.getProperty("client.cert.test.jdk.tls.client.protocols"); + + logger.info("securedWebServicePort = {}", p.getProperty("securedWebServicePort")); + + if (tlsVersion != null) { + logger.info("client.cert.test.jdk.tls.client.protocols = {}", tlsVersion); + } + + } + + @AfterEach + public void cleanup() { + if (hostnameVerifier != null) { + HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier); + } + } + + /* + * @testName: clientCertTest + * + * @assertion_ids: Servlet:SPEC:140; Servlet:JAVADOC:368; Servlet:JAVADOC:369; + * Servlet:SPEC:26; Servlet:SPEC:26.1; Servlet:SPEC:26.2; Servlet:SPEC:26.3; + * Servlet:JAVADOC:356; Servlet:SPEC:214; Servlet:SPEC:215; + * + * @test_strategy: 1. Look for the following request attributes a) + * cipher-suite b) key-size c) SSL certificate If any of the above attributes + * are not set report test failure. + * + * 2. Verify the request.getAuthType returns CLIENT_CERT 3. test the use + * of @TransportProtected annotation at the class level (which implies no need + * for security constraints in the DD file.) + * + * Note: If a request has been transmitted over a secure protocol, such as + * HTTPS, this information must be exposed via the isSecure method of the + * ServletRequest interface. The web container must expose the following + * attributes to the servlet programmer. 1) The cipher suite 2) the bit size + * of the algorithm + * + * If there is an SSL certificate associated with the request, it must be + * exposed by the servlet container to the servlet programmer as an array of + * objects of type java.security.cert.X509Certificate + * + * Important to note is that this is testing the client cert abilities using + * annotations instead of DD entries which normally fall under the + * security-constraint element. + * + */ + @Test + public void clientCertTest() throws Exception { + + String testName = "clientCertTest"; + String url = getURLString("https", hostname, portnum, + pageBase.substring(1) + authorizedPage); + + if (tlsVersion != null) { + System.setProperty("jdk.tls.client.protocols", tlsVersion); + } + + URL newURL = new URL(url); + // open HttpsURLConnection using TSHttpsURLConnection + URLConnection httpsURLConn = getHttpsURLConnection(newURL); + try (InputStream content = httpsURLConn.getInputStream(); + BufferedReader in = new BufferedReader(new InputStreamReader(content))) { + + StringBuilder output = new StringBuilder(); + String line; + while ((line = in.readLine()) != null) { + output.append(line); + TestUtil.logMsg(line); + } + + // compare getRemoteUser() obtained from server's response + // with the username stored in ts.jte + // + // Even though the output need not be identical (because + // of appserver realms) the output should have substring + // match for username stored in ts.jte. + // + String userNameToSearch = username; + if (!output.toString().contains(userNameToSearch)) { + throw new Exception(testName + ": getRemoteUser(): " + "- did not find \"" + + userNameToSearch + "\" in log."); + } else { + logger.debug("Additional verification done"); + } + + // verify output for expected test result + verifyTestOutput(output.toString(), testName); + + + } catch (Exception e) { + logger.error(e.getMessage(), e); + throw new Exception(testName + ": FAILED, " + e.getMessage(), e); + } + + } + + + public void verifyTestOutput(String output, String testName) throws Exception { + // check for the occurance of +": PASSED" + // message in server's response. If this message is not present + // report test failure. + if (!output.contains(testName + ": PASSED")) { + logger.debug("Expected String from the output = {}: PASSED", testName); + logger.debug("received output = {}", output); + throw new Exception(testName + ": FAILED"); + } + } + + +} \ No newline at end of file diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/clientcertanno/ServletSecTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/clientcertanno/ServletSecTestServlet.java new file mode 100755 index 0000000000..73b7fd2d3c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/clientcertanno/ServletSecTestServlet.java @@ -0,0 +1,189 @@ +/* + * 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 + */ + +package com.sun.ts.tests.servlet.spec.security.clientcertanno; + +import java.io.IOException; +import java.io.PrintWriter; +import java.security.cert.X509Certificate; + +import jakarta.annotation.security.DeclareRoles; +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.HttpConstraint; +import jakarta.servlet.annotation.HttpMethodConstraint; +import jakarta.servlet.annotation.ServletSecurity; +import jakarta.servlet.annotation.ServletSecurity.EmptyRoleSemantic; +import jakarta.servlet.annotation.ServletSecurity.TransportGuarantee; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/* + * There are security annotations being used now which shoudl eliminate the + * need for much of the DD elements. Most notably, the TransportProtected + * is used to indicate we want secure transport mechanism (eg SSL) though + * we are still using the DD to specify and auth-metho of CLIENT-CERT. + * Aside from the use of Roles and the trimmed down DD, this test should + * be similar to the test in clientcert directory. + * + * These annotations are trying to set the following security constraints: + * - everyone is permitted to access all methods for /ServletSecTest *except* + * for the methods of POST and GET. For those methods, only the + * "Administrator" is allowed to access those methods. + * - SSL is to be used. + * + */ + +@DeclareRoles({ "Administrator" }) +@ServletSecurity(value = @HttpConstraint(EmptyRoleSemantic.PERMIT), httpMethodConstraints = { + @HttpMethodConstraint(value = "POST", rolesAllowed = "Administrator", transportGuarantee = TransportGuarantee.CONFIDENTIAL), + @HttpMethodConstraint(value = "GET", rolesAllowed = "Administrator", transportGuarantee = TransportGuarantee.CONFIDENTIAL) }) +@WebServlet("/ServletSecTest") +public class ServletSecTestServlet extends HttpServlet { + private boolean fail = false; + + private String FAILSTRING = "FAILED"; + + private String PASSSTRING = "PASSED"; + + private static final Logger LOGGER = LoggerFactory.getLogger(ServletSecTestServlet.class); + + /* + * testName: clientCertTest + * + * 1) If a request has been transmitted over a secure protocol, such as HTTPS, + * this information must be exposed via the isSecure method of the + * ServletRequest interface. The web container must expose the following + * attributes to the servlet programmer. 1) The cipher suite 2) the bit size + * of the algorithm 3) SSL certificate + * + * If any of the above attributes are not set report test failure. + * + * 2. Verify the request.getAuthType returns CLIENT_CERT + * + * If there is an SSL certificate associated with the request, it must be + * exposed by the servlet container to the servlet programmer as an array of + * objects of type java.security.cert.X509Certificate + * + * See Also: * Servlet 2.3 Specification section 4.7 + * + * @test_strategy: 1. Look for the following request attributes a) + * cipher-suite b) key-size c) SSL certificate If any of the above attributes + * is not set/incorrect, report test failure. + * + * Note: SSL certificate attribute will be set only if there is a client + * certificate involved in SSL connection. + * + * + */ + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter out = response.getWriter(); + + out.println("getRemoteUser(): " + request.getRemoteUser() + "
"); + + // Surround these with !'s so they are easier to search for. + // (i.e. we can search for !true! or !false!) + out.println( + "isUserInRole(\"ADM\"): !" + request.isUserInRole("ADM") + "!
"); + + String testName = "clientCertTest"; + + String cipherSuiteAttrib = "jakarta.servlet.request.cipher_suite"; + String keySizeAttrib = "jakarta.servlet.request.key_size"; + String certificateAttrib = "jakarta.servlet.request.X509Certificate"; + + String cipherSuite = null; + Integer keySize = 0; + X509Certificate[] certificates = null; + + try { + fail = false; + + if (request.getUserPrincipal() != null) { + String userPrincipalName = request.getUserPrincipal().getName(); + out.println("Caller principal Name = " + userPrincipalName); + if (userPrincipalName.equals("")) { + fail = true; + } + + } else { + out.println("Caller principal = null"); + fail = true; + } + + cipherSuite = (String) request.getAttribute(cipherSuiteAttrib); + + // verify cipher-suite attribute + if (cipherSuite == null) { + out.println( + testName + ": " + FAILSTRING + " - cipher-suite attribute not set"); + fail = true; + } else + out.println(testName + ": cipher-suite : " + cipherSuite); + + keySize = (Integer) request.getAttribute(keySizeAttrib); + + // verify key-size attribute + if (keySize == null) { + out.println( + testName + ": " + FAILSTRING + " - key-size attribute not set"); + fail = true; + } else + out.println(testName + ": key-size : " + keySize.toString()); + + certificates = (X509Certificate[]) request + .getAttribute(certificateAttrib); + + // verify SSL certificate attribute + if (certificates != null) { + for (int i = 0; i < certificates.length; i++) { + + X509Certificate x509Certificate = certificates[i]; + out.println(testName + ": certificate [" + i + "]=" + + x509Certificate.toString()); + } + } else { + out.println( + testName + ": " + FAILSTRING + " - No SSL certificate found"); + fail = true; + + } + + // verify authenticate type + String authType = request.getAuthType(); + if ((authType != null) && (!authType.equals("CLIENT_CERT"))) { + out.println(testName + ":" + FAILSTRING + + " - Server returns wrong authentication type : " + authType + + " : expected authentication type is CLIENT_CERT"); + fail = true; + } + + if (!fail) { + out.println(testName + ": " + PASSSTRING); + } + } catch (Exception e) { + out.println( + testName + ": " + FAILSTRING + " - Exception: " + e.getMessage()); + e.printStackTrace(); + } + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/clientcertanno/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/clientcertanno/build.xml new file mode 100755 index 0000000000..290b5ddb06 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/clientcertanno/build.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/clientcertanno/clientcertanno.ear.sun-application.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/clientcertanno/clientcertanno.ear.sun-application.xml new file mode 100755 index 0000000000..94c41ef609 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/clientcertanno/clientcertanno.ear.sun-application.xml @@ -0,0 +1,32 @@ + + + + + + + clientcertanno_web.war + clientcertanno_web + + 0 + + Administrator + CN=CTS,OU=Java Software,O=Sun Microsystems Inc.,L=Burlington,ST=MA,C=US + CN=CTS, OU=Java Software, O=Sun Microsystems Inc., L=Burlington, ST=MA, C=US + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/clientcertanno/clientcertanno_web.war.sun-web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/clientcertanno/clientcertanno_web.war.sun-web.xml new file mode 100644 index 0000000000..583ed0e7d2 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/clientcertanno/clientcertanno_web.war.sun-web.xml @@ -0,0 +1,28 @@ + + + + + + clientcertanno_web + + Administrator + CN=CTS,OU=Java Software,O=Sun Microsystems Inc.,L=Burlington,ST=MA,C=US + CN=CTS, OU=Java Software, O=Sun Microsystems Inc., L=Burlington, ST=MA, C=US + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/clientcertanno/clientcertanno_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/clientcertanno/clientcertanno_web.xml new file mode 100755 index 0000000000..4dbe0ff4f2 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/clientcertanno/clientcertanno_web.xml @@ -0,0 +1,28 @@ + + + + + clientcertanno + + 54 + + + CLIENT-CERT + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/denyUncovered/AllMethodsAllowedAnno.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/denyUncovered/AllMethodsAllowedAnno.java new file mode 100755 index 0000000000..46ccf0ba1a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/denyUncovered/AllMethodsAllowedAnno.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2013, 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 + */ + +package com.sun.ts.tests.servlet.spec.security.denyUncovered; + +import java.io.IOException; + +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.HttpConstraint; +import jakarta.servlet.annotation.ServletSecurity; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +/* + * This servlet will be used to assist in testing the deny-uncovered-http-methods + * security support (as listed in Servlet 3.1 spec, section 13.8.4). + * + * This is intended to be called from a Client, and will have specific settings + * set on the web.xml that will allow (or disallow) certain http method calls + * to be made based on the web.xml settings. + * + */ + +@ServletSecurity(@HttpConstraint(rolesAllowed = { "Administrator", "Manager", + "Employee" })) +@WebServlet(name = "AllMethodsAllowedAnno", urlPatterns = { + "/AllMethodsAllowedAnno" }) +public class AllMethodsAllowedAnno extends HttpServlet { + + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + debug("in AllMethodsAllowedAnno.doGet()"); + } + + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + debug("in AllMethodsAllowedAnno.doPost()"); + } + + public void doDelete(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + debug("in AllMethodsAllowedAnno.doDelete()"); + } + + public void doPut(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + debug("in AllMethodsAllowedAnno.doPut()"); + } + + public void debug(String str) { + System.out.println(str); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/denyUncovered/Client.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/denyUncovered/Client.java new file mode 100755 index 0000000000..89d8b28176 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/denyUncovered/Client.java @@ -0,0 +1,388 @@ +/* + * Copyright (c) 2013, 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 + */ + +package com.sun.ts.tests.servlet.spec.security.denyUncovered; + +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.Properties; + +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.lib.util.WebUtil; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; + +/** + * This class will be used to perform simple servlet invocations. The servlet + * invocations should be used to test these assertions on the server. + * + * We will check for success or failure from within this file. So the actual + * testcases in this class will simply consist of checking the server side + * servlet invocations for success or failure. + * + * The tests in this class are intended to test the Servlets + * deny-uncovered-http-methods DD semantic (Servlet 3.1 spec, section 13.8.4.2). + * + */ +public class Client extends AbstractUrlClient { + private Properties props = null; + + private String hostname = null; + + private int portnum = 0; + + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_sec_denyUncovered_web.war") + .addClasses(AllMethodsAllowedAnno.class, ExcludeAuthConstraint.class, PartialDDServlet.class, + TestServlet.class) + .setWebXML(Client.class.getResource("servlet_sec_denyUncovered_web.xml")); + } + + // this must be the decoded context path corresponding to the web module + private String contextPath = "/servlet_sec_denyUncovered_web"; + + private String ctxtTestServlet = contextPath + "/TestServlet"; // specifies + // access to + // get & put + // only + + private String ctxtAllMethodsAllowedAnno = contextPath + + "/AllMethodsAllowedAnno"; + + private String ctxtExcludeAuthConstraint = contextPath + + "/ExcludeAuthConstraint"; + + private String ctxtPartialDDServlet = contextPath + "/PartialDDServlet"; + + private String username = ""; + + private String password = ""; + + + /** + * @class.setup_props: logical.hostname.servlet; webServerHost; webServerPort; + * authuser; authpassword; user; password; + * securedWebServicePort; + * + */ + public void setup(String[] args, Properties p) throws Exception { + props = p; + + try { + hostname = p.getProperty("webServerHost"); + portnum = Integer.parseInt(p.getProperty("webServerPort")); + username = p.getProperty("user"); + password = p.getProperty("password"); + + } catch (Exception e) { + logErr("Error: got exception: ", e); + } + } + + public void cleanup() throws Exception { + } + + /* + * @testName: testAllMethodsAllowedAnno + * + * @assertion_ids: Servlet:SPEC:310 + * + * @test_Strategy: This validates that we have a deny-uncovered-http-method + * set in our web.xml and NO methods explicitly listed in our + * security constraints. Details for this test include the + * following : - we are working with servlet: + * AllMethodsAllowedAnno which uses servlet annotations only + * and has no web.xml references - the only security that + * should be in effect should be whatever is defined in + * annotations. - attempts to access all denied methods shall + * return 200 + * + */ + @Test + public void testAllMethodsAllowedAnno() throws Exception { + + int httpStatusCode = invokeServlet(ctxtAllMethodsAllowedAnno, "POST"); + if (httpStatusCode != 200) { + logger.error("Accessing {} (POST) returns = {}", ctxtAllMethodsAllowedAnno, httpStatusCode); + throw new Exception("testAllMethodsAllowedAnno : FAILED"); + } + + httpStatusCode = invokeServlet(ctxtAllMethodsAllowedAnno, "GET"); + if (httpStatusCode != 200) { + logger.error("Accessing {} (GET) returns = {}", ctxtAllMethodsAllowedAnno, httpStatusCode); + throw new Exception("testAllMethodsAllowedAnno : FAILED"); + } + + httpStatusCode = invokeServlet(ctxtAllMethodsAllowedAnno, "PUT"); + if (httpStatusCode != 200) { + TestUtil.logMsg("Accessing " + ctxtAllMethodsAllowedAnno + + " (PUT) returns = " + httpStatusCode); + throw new Exception("testAllMethodsAllowedAnno : FAILED"); + } + + httpStatusCode = invokeServlet(ctxtAllMethodsAllowedAnno, "DELETE"); + if (httpStatusCode != 200) { + TestUtil.logMsg("Accessing " + ctxtAllMethodsAllowedAnno + + " (DELETE) returns = " + httpStatusCode); + throw new Exception("testAllMethodsAllowedAnno : FAILED"); + } + + TestUtil.logMsg("testAllMethodsAllowedAnno : PASSED"); + } + + /* + * @testName: testAccessToMethodAllowed + * + * @assertion_ids: Servlet:SPEC:309; + * + * @test_Strategy: This validates that we have a deny-uncovered-http-method + * set in our web.xml for a servlet that explicitly specifies + * protection for Get and Post. This means that Get and Post + * can be access but because we are using + * deny-uncovered-http-methods element, everything else will + * be protected/denied access. - this uses servlet TestServlet + * and it's Get & Post methods. - get & put are specified in + * security constraint - so we should be able to access them - + * attempts to access get & put must be alloed (return 200=ok) + * + */ + @Test + public void testAccessToMethodAllowed() throws Exception { + + int httpStatusCode = invokeServlet(ctxtTestServlet, "POST"); + if (httpStatusCode != 200) { + TestUtil.logMsg("Accessing " + ctxtTestServlet + " (POST) returns = " + + httpStatusCode); + throw new Exception("testAccessToMethodAllowed : FAILED"); + } + + httpStatusCode = invokeServlet(ctxtTestServlet, "GET"); + if (httpStatusCode != 200) { + TestUtil.logMsg("Accessing " + ctxtTestServlet + " (GET) returns = " + + httpStatusCode); + throw new Exception("testAccessToMethodAllowed : FAILED"); + } + + TestUtil.logMsg("testAccessToMethodAllowed : PASSED"); + } + + /* + * @testName: testDenySomeUncovered + * + * @assertion_ids: Servlet:SPEC:309; + * + * @test_Strategy: This validates that we have a deny-uncovered-http-method + * set in our web.xml for a servlet that explicitly specifies + * protection for Get and Post. This means that Get and Post + * can be access but because we are using + * deny-uncovered-http-methods element, everything else will + * be protected/denied access. - this uses servlet TestServlet + * and it's Get & Post methods. - get & put are specified in + * security constraint - so we should be able to access them - + * attempts to access get & put must be alloed (return 200=ok) + * + */ + @Test + public void testDenySomeUncovered() throws Exception { + + int httpStatusCode = invokeServlet(ctxtTestServlet, "DELETE"); + if (httpStatusCode != 403) { + TestUtil.logMsg("Accessing " + ctxtTestServlet + " (DELETE) returns = " + + httpStatusCode); + throw new Exception("testDenySomeUncovered : FAILED"); + } + + httpStatusCode = invokeServlet(ctxtTestServlet, "PUT"); + if (httpStatusCode != 403) { + TestUtil.logMsg("Accessing " + ctxtTestServlet + " (PUT) returns = " + + httpStatusCode); + throw new Exception("testDenySomeUncovered : FAILED"); + } + + TestUtil.logMsg("testDenySomeUncovered : PASSED"); + } + + /* + * @testName: testExcludeAuthConstraint + * + * @assertion_ids: Servlet:SPEC:309; + * + * @test_Strategy: This validates that we have a deny-uncovered-http-method + * set in our web.xml on a servlet that uses an + * excluded-auth-constraint in combination with the + * http-method-omission element. Normally using + * http-method-omissions with excluded-auth-constraint would + * cause the listed methods (get & put in this case) to be + * considered uncovered. Adding in the + * deny-uncovered-http-method means we should be denied access + * to get & put. This test has the following details: - this + * uses servlet ExcludeAuthConstraint - get & put are + * specified in security constraint within + * http-method-omission - get & put should be uncovered (based + * on http-method-mission) BUT because of the + * deny-uncovered-http-method elelent, they must be denied! + * + */ + @Test + public void testExcludeAuthConstraint() throws Exception { + + int httpStatusCode = invokeServlet(ctxtExcludeAuthConstraint, "GET"); + if (httpStatusCode != 403) { + TestUtil.logMsg("Accessing " + ctxtExcludeAuthConstraint + + " (GET) returns = " + httpStatusCode); + throw new Exception("testExcludeAuthConstraint : FAILED"); + } + + httpStatusCode = invokeServlet(ctxtExcludeAuthConstraint, "POST"); + if (httpStatusCode != 403) { + TestUtil.logMsg("Accessing " + ctxtExcludeAuthConstraint + + " (POST) returns = " + httpStatusCode); + throw new Exception("testExcludeAuthConstraint : FAILED"); + } + + TestUtil.logMsg("testExcludeAuthConstraint : PASSED"); + } + + /* + * @testName: testPartialDDServlet + * + * @assertion_ids: Servlet:SPEC:309; + * + * @test_Strategy: This validates that we have a deny-uncovered-http-method + * set in our web.xml on a servlet that uses settings from + * both DD and annotations. The security constraints are set + * in the annotated servlet but the web.xml defines + * deny-uncovered-http-method - and that will apply to all + * uncovered methods in the annotated servlet. + * + * This test has the following details: - this uses servlet + * PartialDDServlet (with both annotation and DD settings) - + * get & put are specified in security constraint within + * annotation - get & put should be covered (and accessible by + * role Administrato) but all other methods should be + * uncovered from annotation POV - DD decares + * deny-uncovered-http-method and servlet refs so should cause + * the other "uncovered" methods to get "denied" + * + */ + @Test + public void testPartialDDServlet() throws Exception { + + TestUtil.logMsg("Invoking " + ctxtPartialDDServlet + " (GET)"); + int httpStatusCode = invokeServlet(ctxtPartialDDServlet, "GET"); + if (httpStatusCode != 200) { + TestUtil.logMsg("Accessing " + ctxtPartialDDServlet + " (GET) returns = " + + httpStatusCode); + throw new Exception("testPartialDDServlet : FAILED"); + } + + TestUtil.logMsg("Invoking " + ctxtPartialDDServlet + " (POST)"); + httpStatusCode = invokeServlet(ctxtPartialDDServlet, "POST"); + if (httpStatusCode != 200) { + TestUtil.logMsg("Accessing " + ctxtPartialDDServlet + + " (POST) returns = " + httpStatusCode); + throw new Exception("testPartialDDServlet : FAILED"); + } + + TestUtil.logMsg("Invoking " + ctxtPartialDDServlet + " (PUT)"); + httpStatusCode = invokeServlet(ctxtPartialDDServlet, "PUT"); + if (httpStatusCode != 403) { + TestUtil.logMsg("Accessing " + ctxtPartialDDServlet + " (PUT) returns = " + + httpStatusCode); + throw new Exception("testPartialDDServlet : FAILED"); + } + + TestUtil.logMsg("Invoking " + ctxtPartialDDServlet + " (DELETE)"); + httpStatusCode = invokeServlet(ctxtPartialDDServlet, "DELETE"); + if (httpStatusCode != 403) { + TestUtil.logMsg("Accessing " + ctxtPartialDDServlet + + " (DELETE) returns = " + httpStatusCode); + throw new Exception("testPartialDDServlet : FAILED"); + } + + TestUtil.logMsg("testPartialDDServlet : PASSED"); + } + + /* + * Convenience method that will establish a url connections and perform a + * get/post request. A username and password will be passed in the request + * header and they will be encoded using the BASE64Encoder class. returns the + * http status code. + */ + private int invokeServlet(String sContext, String requestMethod) throws Exception { + int code = 200; + + if (sContext.startsWith("/")) { + sContext = sContext.substring(1); + } + + String url = getURLString("http", hostname, portnum, sContext); + try { + URL newURL = new URL(url); + + // Encode authData + // hint: make sure username and password are valid for your + // (J2EE) security realm otherwise you recieve http 401 error. + String authData = username + ":" + password; + logger.debug("authData : {}", authData); + +// BASE64Encoder encoder = new BASE64Encoder(); +// String encodedAuthData = encoder.encode(authData.getBytes()); + String encodedAuthData = WebUtil.encodeBase64(authData); + logger.debug("encoded authData : {}", encodedAuthData); + + // open URLConnection + HttpURLConnection conn = (HttpURLConnection) newURL.openConnection(); + + // set request property + conn.setDoOutput(true); + conn.setDoInput(true); + conn.setRequestProperty("Authorization", "Basic " + encodedAuthData.trim()); + conn.setRequestMethod(requestMethod); // POST or GET etc + conn.connect(); + + logger.debug("called HttpURLConnection.connect() for url: {}", url); + code = conn.getResponseCode(); + logger.debug("Got response code of: {}", code); + String str = conn.getResponseMessage(); + logger.debug("Got response string of: {}", str); + /* + * // not used right now but left here in case we need it InputStream + * content = (InputStream)conn.getInputStream(); BufferedReader in = new + * BufferedReader(new InputStreamReader(content)); + * + * try { String line; while ((line = in.readLine()) != null) { + * TestUtil.logMsg(line); } } finally { in.close(); } + */ + + } catch (Exception e) { + logger.error("Abnormal return status encountered while invoking {}", sContext); + logger.error("Exception Message was: " + e.getMessage(), e); + throw e; + } + + return code; + } // invokeServlet() + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/denyUncovered/ExcludeAuthConstraint.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/denyUncovered/ExcludeAuthConstraint.java new file mode 100755 index 0000000000..acd3e7134d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/denyUncovered/ExcludeAuthConstraint.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2013, 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 + */ + +package com.sun.ts.tests.servlet.spec.security.denyUncovered; + +import java.io.IOException; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +/* + * This servlet will be used to assist in testing the deny-uncovered-http-methods + * security support (as listed in Servlet 3.1 spec, section 13.8.4). + * + * This is intended to be called from a Client, and will have specific settings + * set on the web.xml that will allow (or disallow) certain http method calls + * to be made based on the web.xml settings. + * + */ +public class ExcludeAuthConstraint extends HttpServlet { + + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + debug("in ExcludeAuthConstraint.doGet()"); + } + + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + debug("in ExcludeAuthConstraint.doPost()"); + } + + public void doDelete(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + debug("in ExcludeAuthConstraint.doDelete()"); + } + + public void doPut(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + debug("in ExcludeAuthConstraint.doPut()"); + } + + public void debug(String str) { + System.out.println(str); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/denyUncovered/PartialDDServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/denyUncovered/PartialDDServlet.java new file mode 100755 index 0000000000..994b2451a4 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/denyUncovered/PartialDDServlet.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2013, 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 + */ + +package com.sun.ts.tests.servlet.spec.security.denyUncovered; + +import java.io.IOException; + +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.HttpConstraint; +import jakarta.servlet.annotation.HttpMethodConstraint; +import jakarta.servlet.annotation.ServletSecurity; +import jakarta.servlet.annotation.ServletSecurity.EmptyRoleSemantic; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +/* + * This servlet will be used to assist in testing the deny-uncovered-http-methods + * security support (as listed in Servlet 3.1 spec, section 13.8.4). + * + * This is intended to be called from a Client, and will have specific settings + * set on the web.xml that will allow (or disallow) certain http method calls + * to be made based on the web.xml settings. + * + * The following annotations set it so GET and POST can be accessed by role=Administrator + * and all other methods are "uncovered". While the other http methods are + * "uncovered" since there is a "deny-uncovered-http-methods" setting in the web.xml + * then the "uncovered" methods must be DENIED. + */ + +@ServletSecurity(value = @HttpConstraint(EmptyRoleSemantic.PERMIT), httpMethodConstraints = { + @HttpMethodConstraint(value = "GET", rolesAllowed = "Administrator"), + @HttpMethodConstraint(value = "POST", rolesAllowed = "Administrator"), }) +@WebServlet(name = "PartialDDServlet", urlPatterns = { "/PartialDDServlet" }) +public class PartialDDServlet extends HttpServlet { + + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + debug("in PartialDDServlet.doGet()"); + } + + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + debug("in PartialDDServlet.doPost()"); + } + + public void doDelete(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + debug("in PartialDDServlet.doDelete()"); + } + + public void doPut(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + debug("in PartialDDServlet.doPut()"); + } + + public void debug(String str) { + System.out.println(str); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/denyUncovered/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/denyUncovered/TestServlet.java new file mode 100755 index 0000000000..e15b62b0a8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/denyUncovered/TestServlet.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2013, 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 + */ + +package com.sun.ts.tests.servlet.spec.security.denyUncovered; + +import java.io.IOException; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +/* + * This servlet will be used to assist in testing the deny-uncovered-http-methods + * security support (as listed in Servlet 3.1 spec, section 13.8.4). + * + * This is intended to be called from a Client, and will have specific settings + * set on the web.xml that will allow (or disallow) certain http method calls + * to be made based on the web.xml settings. + * + */ +public class TestServlet extends HttpServlet { + + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + debug("in TestServlet.doGet()"); + } + + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + debug("in TestServlet.doPost()"); + } + + public void doDelete(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + debug("in TestServlet.doDelete()"); + } + + public void doPut(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + debug("in TestServlet.doPut()"); + } + + public void debug(String str) { + System.out.println(str); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/denyUncovered/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/denyUncovered/build.xml new file mode 100755 index 0000000000..f526fbf1b1 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/denyUncovered/build.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/denyUncovered/servlet_sec_denyUncovered.ear.sun-application.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/denyUncovered/servlet_sec_denyUncovered.ear.sun-application.xml new file mode 100644 index 0000000000..65f708f03f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/denyUncovered/servlet_sec_denyUncovered.ear.sun-application.xml @@ -0,0 +1,40 @@ + + + + + + + servlet_sec_denyUncovered_web.war + servlet_sec_denyUncovered_web + + 0 + + Administrator + j2ee + + + Manager + javajoe + + + Employee + javajoe + j2ee + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/denyUncovered/servlet_sec_denyUncovered_web.war.sun-web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/denyUncovered/servlet_sec_denyUncovered_web.war.sun-web.xml new file mode 100755 index 0000000000..66fcf9abb6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/denyUncovered/servlet_sec_denyUncovered_web.war.sun-web.xml @@ -0,0 +1,36 @@ + + + + + +/servlet_sec_denyUncovered_web + + Administrator + j2ee + + + Manager + javajoe + + + Employee + javajoe + j2ee + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/denyUncovered/servlet_sec_denyUncovered_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/denyUncovered/servlet_sec_denyUncovered_web.xml new file mode 100755 index 0000000000..b620fd296b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/denyUncovered/servlet_sec_denyUncovered_web.xml @@ -0,0 +1,105 @@ + + + + + servlet_sec_denyUncovered + + + TestServletLogicalName + com.sun.ts.tests.servlet.spec.security.denyUncovered.TestServlet + + MGR + Administrator + + + ADM + Manager + + + EMP + Employee + + + + ExcludeAuthConstraintLogicalName + com.sun.ts.tests.servlet.spec.security.denyUncovered.ExcludeAuthConstraint + + MGR + Administrator + + + ADM + Manager + + + EMP + Employee + + + + TestServletLogicalName + /TestServlet + + + ExcludeAuthConstraintLogicalName + /ExcludeAuthConstraint + + + + MySecureBit0 + /TestServlet + GET + POST + + + Administrator + + + NONE + + + + + MySecureBit2 + /ExcludeAuthConstraint + GET + POST + + + + NONE + + + + BASIC + default + + + the administrator role + Administrator + + + the manager role + Manager + + + the employee role + Employee + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/metadatacomplete/Client.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/metadatacomplete/Client.java new file mode 100644 index 0000000000..b1d2aa6a42 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/metadatacomplete/Client.java @@ -0,0 +1,424 @@ +/* + * Copyright (c) 2012, 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 + */ + +package com.sun.ts.tests.servlet.spec.security.metadatacomplete; + +import com.sun.ts.tests.servlet.common.client.BaseUrlClient; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; + +import java.util.Properties; + +/* + * These tests are going to be similar to the tests that are in + * com.sun.ts.tests.servlet.spec.security.annotations with the key difference + * being that these tests have a DD file which states metadata-complete=true. + * When metadata-complete=true, then annotations should be ignored for the + * application(s) in this jar. + * + */ +public class Client extends BaseUrlClient { + + + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_sec_metadatacomplete_web.war") + .addClasses(DenyAllServlet.class, GuestPageTestServlet.class, ServletSecTestServlet.class, + UnProtectedTestServlet.class) + .setWebXML(Client.class.getResource("servlet_sec_metadatacomplete_web.xml")); + } + + + private static final String CLASS_TRACE_HEADER = "[Client]: "; + + private static final String USER_PRINCIPAL_SEARCH = "The user principal is: "; // (+username) + + // fields: + private String pageDeny = null; + + private String pageSec = null; + + private String pageGuest = null; + + private String pageUnprotected = null; + + private String pageServletBase = "/servlet_sec_metadatacomplete_web"; + + private String pageServletDeny = pageServletBase + "/ServletDenyAll"; + + private String pageServletSec = pageServletBase + "/ServletSecTest"; + + private String pageServletGuest = pageServletBase + "/GuestPageTest"; + + private String pageServletUnprotected = pageServletBase + "/UnProtectedTest"; + + private String username = null; + + private String password = null; + + private String unauthUsername = null; + + private String unauthPassword = null; + + + /* + * @class.setup_props: webServerHost; webServerPort; securedWebServicePort; + * user; password; authuser; authpassword; ts_home; + * + */ + public void setup(String[] args, Properties p) throws Exception { + super.setup(args, p); + + try { + username = p.getProperty(USERNAME); + password = p.getProperty(PASSWORD); + unauthUsername = p.getProperty(UNAUTH_USERNAME); + unauthPassword = p.getProperty(UNAUTH_PASSWORD); + + pageSec = pageServletSec; + pageDeny = pageServletDeny; + pageGuest = pageServletGuest; + pageUnprotected = pageServletUnprotected; + + } catch (Exception e) { + logErr("Error: got exception: ", e); + } + } + + /* + * @testName: test1 + * + * @assertion_ids: Servlet:SPEC:214; Servlet:SPEC:215; Servlet:SPEC:228; + * Servlet:SPEC:294; Servlet:SPEC:295; Servlet:SPEC:217; Servlet:SPEC:198; + * Servlet:SPEC:289; Servlet:SPEC:258.3; + * + * @assertion: 1. annotations that permit all must be supported by the Web + * container. However, if the metadata-complete flag == true in the DD, then + * the annotation must be ignored. (per assertion Servlet:SPEC:228) + * + * @test_Strategy: 1. Send request to access DenyAllServlet - which is going + * to be granted all access via annotation but will be marked as DenyAll in + * the DD. The DD MUST take precedence. 2. Receive an access denied + */ + @Test + public void test1() throws Exception { + logger.trace("testing that we can NOT access: {}", pageDeny); + + TEST_PROPS.setProperty(TEST_NAME, "SecAnnotations/Test1"); + TEST_PROPS.setProperty(REQUEST, getRequestLine("GET", pageDeny)); + TEST_PROPS.setProperty(STATUS_CODE, UNAUTHORIZED); + try { + invoke(); + } catch (Exception e) { + // its possible we were denied access with a FORBIDDEN (403) code instead + // of + // UNAUTHORIZED (401) so retry and check for FORBIDDEN code. If it still + // fails then we have an issue. + logger.trace( + "we tested for Status Code=401 but we could have a 403 code, so check for that."); + TEST_PROPS.setProperty(TEST_NAME, "SecAnnotations/Test1"); + TEST_PROPS.setProperty(REQUEST, getRequestLine("GET", pageDeny)); + TEST_PROPS.setProperty(STATUS_CODE, FORBIDDEN); + invoke(); + } + + logger.trace("test1 passed: we were not allowed to perform GET on servlet: {}", pageDeny); + } + + /* + * @testName: test2 + * + * @assertion_ids: Servlet:SPEC:214; Servlet:SPEC:217; Servlet:SPEC:218; + * Servlet:SPEC:228; Servlet:SPEC:294; Servlet:SPEC:295; Servlet:SPEC:198; + * Servlet:SPEC:289; Servlet:SPEC:258.3; + * + * @assertion: 1. Servlet 3.0 spec (section 13.4 - 3rd from last para) states: + * "When a security-constraint in the portable deployment descriptor includes + * a url-pattern that matches a request URL, the security annotations + * described in this section have no effect on the access policy that applies + * to the request URL." + * + * + * @test_Strategy: 1. We have GuestPageTestServlet setup with DenyAll anno but + * we have DD setup with roles and security-constraints that say POST can be + * accessed by Manager role (via user=javajoe) and according to spec + * statement, the annotation must be ignored since metadata-complete=true in + * the DD. 2. attempt to POST & GET as user javajoe should allow access since + * DD grants it and since metadata-complete is true, the annotations security + * constraints do NOT get used. + */ + @Test + public void test2() throws Exception { + + // attempt to POST as "javajoe" should be allowed + logger.trace("POST w/ user= {} should be allowed due to DD declaration", unauthUsername); + TEST_PROPS.setProperty(TEST_NAME, "SecAnnotations/Test2"); + TEST_PROPS.setProperty(REQUEST, getRequestLine("POST", pageGuest)); + TEST_PROPS.setProperty(BASIC_AUTH_USER, unauthUsername); + TEST_PROPS.setProperty(BASIC_AUTH_PASSWD, unauthPassword); + TEST_PROPS.setProperty(STATUS_CODE, OK); + invoke(); + + // attempt to GET as "javajoe" should be allowed due to DD and + // the RolesAllowed anno in GuestPageTestServlet should be ignored. + // note: doGet metho prints out userprincipal name that we are going to + // check + logger.trace("GET w/ user= {} should be allowed due to DD declaration", unauthUsername); + TEST_PROPS.setProperty(SEARCH_STRING, USER_PRINCIPAL_SEARCH+unauthUsername); + TEST_PROPS.setProperty(TEST_NAME, "SecAnnotations/Test2"); + TEST_PROPS.setProperty(REQUEST, getRequestLine("GET", pageGuest)); + TEST_PROPS.setProperty(BASIC_AUTH_USER, unauthUsername); // "javajoe" + TEST_PROPS.setProperty(BASIC_AUTH_PASSWD, unauthPassword); // "javajoe" + TEST_PROPS.setProperty(STATUS_CODE, OK); + invoke(); + + logger.trace("success - DD's role access was honored while the conflicting annotation was ignored."); + logger.trace("test2 passed."); + } + + /* + * @testName: test3 + * + * @assertion_ids: Servlet:SPEC:214; Servlet:SPEC:216; Servlet:SPEC:217; + * Servlet:SPEC:228; Servlet:SPEC:294; Servlet:SPEC:295; Servlet:SPEC:198; + * Servlet:SPEC:289; Servlet:SPEC:258.3; + * + * @assertion: 1. Servlet 3.0 spec (section 13.4 - 3rd from last para) states: + * "When a security-constraint in the portable deployment descriptor includes + * a url-pattern that matches a request URL, the security annotations + * described in this section have no effect on the access policy that applies + * to the request URL." + * + * + * @test_Strategy: This is another variation of a test which validates that DD + * settings override annotation settings when the url-pattern of both match + * AND when the DD's metadata-complete = true. 1. create ServletSecTestServlet + * with a declared annotation at the class level as well as a conflicting DD + * declaration. The annotation should get ignored and the DD should take + * precedence since the DD has set metadata-complete=true. 2. validate that + * the annotation declaration which states ServletSecTest POST can be accessed + * is WRONG since the DD declares that POST is set to be deny for all roles. + * 3. try to access GET using valid creds (for Administrator=j2ee) since the + * DD specifies GET for role=Adminstrator. (Note that annotation declares GET + * should be deny by role=Adminstrator - so verify this annotation is NOT + * used.) + * + */ + @Test + public void test3() throws Exception { + + // Post is set to be accessed by Administrator in the annotation + // declaration *but* Post is also set to be accessed only by + // Manager(javajoe) + // in DD. So attempts to POST as Administrator=j2ee should fail. + logger.trace("Attempting to POST as user= {} should be denied due to DD security.", username); + TEST_PROPS.setProperty(TEST_NAME, "SecurityAnno/Test3"); + TEST_PROPS.setProperty(REQUEST, getRequestLine("POST", pageSec)); + TEST_PROPS.setProperty(BASIC_AUTH_USER, username); // this is username for + // Administrator not + // Manager + TEST_PROPS.setProperty(BASIC_AUTH_PASSWD, password); + TEST_PROPS.setProperty(STATUS_CODE, UNAUTHORIZED); // check for status code + // 401 + try { + invoke(); + } catch (Exception e) { + // its possible we were denied access with a FORBIDDEN (403) code instead + // of + // UNAUTHORIZED (401) so retry and check for FORBIDDEN code. If it still + // fails then we have an issue. + TEST_PROPS.setProperty(TEST_NAME, "SecurityAnno/Test3"); + TEST_PROPS.setProperty(REQUEST, getRequestLine("POST", pageSec)); + TEST_PROPS.setProperty(BASIC_AUTH_USER, username); // this is username for + // Administrator not + // Manager + TEST_PROPS.setProperty(BASIC_AUTH_PASSWD, password); + TEST_PROPS.setProperty(STATUS_CODE, FORBIDDEN); + invoke(); + } + + // now verify that GET can be done by role=Administrator (per DD definition) + logger.trace("Attempting to GET as user= {} should be allowed due to DD security.", username); + TEST_PROPS.setProperty(TEST_NAME, "BasicSec/Test3"); + TEST_PROPS.setProperty(BASIC_AUTH_USER, username); // this is username for + // Administrator + TEST_PROPS.setProperty(BASIC_AUTH_PASSWD, password); + TEST_PROPS.setProperty(REQUEST, getRequestLine("GET", pageSec)); + TEST_PROPS.setProperty(STATUS_CODE, OK); + invoke(); + + logger.trace("Class level annotation setting was overridden by DD."); + logger.trace("test3 passed."); + } + + /* + * @testName: test4 + * + * @assertion_ids: Servlet:SPEC:214; Servlet:SPEC:216; Servlet:SPEC:217; + * Servlet:SPEC:228; Servlet:SPEC:294; Servlet:SPEC:295; Servlet:SPEC:198; + * Servlet:SPEC:289; Servlet:SPEC:258.3; + * + * @assertion: 1. Servlet 3.0 (section 13.4) states: "When an annotation is + * specified at both the class and method level, the method targeted + * annotation overrides that on the class (for the method) " 2. DenyAll can be + * applied to class and method level so here we are validating its use at the + * method level. + * + * @test_Strategy: 1. create ServletSecTestServlet with annotation on the + * servlet that sets GET & POST to be denied access by all 2. do Post w/ + * correct credentials (for Manager) and should be allowed since DD declares + * this constraint. + * + */ + @Test + public void test4() throws Exception { + + // now see if we get access denied - since DenyAll anno set on doPost method + TEST_PROPS.setProperty(REQUEST, getRequestLine("POST", pageSec)); + TEST_PROPS.setProperty(BASIC_AUTH_USER, unauthUsername); + TEST_PROPS.setProperty(BASIC_AUTH_PASSWD, unauthPassword); + TEST_PROPS.setProperty(STATUS_CODE, OK); // check for status code 401 + invoke(); + + logger.trace("Success - DD allowed POST by user={}", unauthUsername); + + logger.trace("test4 passed."); + } + + /* + * @testName: test5 + * + * @assertion_ids: Servlet:SPEC:214; Servlet:SPEC:215; Servlet:SPEC:217; + * Servlet:SPEC:228; Servlet:SPEC:294; Servlet:SPEC:295; Servlet:SPEC:198; + * Servlet:SPEC:289; Servlet:SPEC:258.3; + * + * @assertion: Servlet 3.0 spec (section 13.4) states: "These annotations may + * be specified on (that is, targeted to) an HttpServlet implementation class + * or on specific method(s) of the implementation class as defined below." + * + * @test_Strategy: 1. Send request for unprotected servlet that uses the + * PermitAll access at the class level. 2. Receive page + */ + @Test + public void test5() throws Exception { + + logger.trace("GET w/ user= {} should be allowed access as DD leaves this servlet unprotected.", unauthUsername); + TEST_PROPS.setProperty(TEST_NAME, "BasicSec/Test5"); + TEST_PROPS.setProperty(BASIC_AUTH_USER, username); // try using valid creds + TEST_PROPS.setProperty(BASIC_AUTH_PASSWD, password); // and it should still + // work + TEST_PROPS.setProperty(REQUEST, getRequestLine("GET", pageUnprotected)); + TEST_PROPS.setProperty(STATUS_CODE, OK); + invoke(); + logger.trace("Class level PermitAll anno returned expected results"); + logger.trace("test5 passed."); + } + + /* + * @testName: test6 + * + * @assertion_ids: Servlet:SPEC:214; Servlet:SPEC:217; Servlet:SPEC:218; + * Servlet:SPEC:228; Servlet:SPEC:294; Servlet:SPEC:295; Servlet:SPEC:198; + * Servlet:SPEC:289; Servlet:SPEC:258.3; + * + * @assertion: This validates Servlet 3.0 spec section 13.4, which says: "When + * a security-constraint in the portable deployment descriptor includes a + * url-pattern that matches a request URL, the security annotations described + * in this section have no effect on the access policy that applies to the + * request URL." + * + * @test_Strategy: 1. do POST or GET with incorrect authentication (ie "j2ee") + * should NOT allows access since "j2ee" is not in roles as defined in DD. The + * DD only allows role=Manager (with user=javajoe) to GET or POST. + * + */ + @Test + public void test6() throws Exception { + + logger.trace("Sending request to resource where DD allows access to override any restricting annotation..."); + TEST_PROPS.setProperty(TEST_NAME, "SecAnnotations/Test6"); + + // attempt to GET as "j2ee" should NOT be allowed since the DD only + // states to allow Manager role (ie javajoe). The annotation + // defined in GuestPageTestServlet declares that GET can be accessed + // by Administrator role (e.g. user=j2ee) but this annotation + // must be completely ignored sine the DD has set metadata-complete=true. + logger.trace("GET w/ user= {} should NOT be allowed due to DD declaration", username); + TEST_PROPS.setProperty(TEST_NAME, "SecAnnotations/Test6"); + TEST_PROPS.setProperty(REQUEST, getRequestLine("GET", pageGuest)); + TEST_PROPS.setProperty(BASIC_AUTH_USER, username); // "j2ee" + TEST_PROPS.setProperty(BASIC_AUTH_PASSWD, password); // "j2ee" + TEST_PROPS.setProperty(STATUS_CODE, UNAUTHORIZED); + try { + invoke(); + } catch (Exception e) { + // its possible we were denied access with a FORBIDDEN code + // so retry with that code - if it still fails then we have an issue. + logger.trace("retrying: GET w/ user= {} should still NOT be allowed due to DD declaration", username); + TEST_PROPS.setProperty(TEST_NAME, "SecAnnotations/Test6"); + TEST_PROPS.setProperty(REQUEST, getRequestLine("GET", pageGuest)); + TEST_PROPS.setProperty(BASIC_AUTH_USER, username); // "j2ee" + TEST_PROPS.setProperty(BASIC_AUTH_PASSWD, password); // "j2ee" + TEST_PROPS.setProperty(STATUS_CODE, FORBIDDEN); + invoke(); + } + + // attempt to POST as "j2ee" should NOT be allowed since the DD only + // states to allow Manager role (ie javajoe). + logger.trace("POST w/ user= {} should NOT be allowed due to DD declaration", username); + TEST_PROPS.setProperty(TEST_NAME, "SecAnnotations/Test6"); + TEST_PROPS.setProperty(REQUEST, getRequestLine("POST", pageGuest)); + TEST_PROPS.setProperty(BASIC_AUTH_USER, username); // "j2ee" + TEST_PROPS.setProperty(BASIC_AUTH_PASSWD, password); // "j2ee" + TEST_PROPS.setProperty(STATUS_CODE, UNAUTHORIZED); + try { + invoke(); + } catch (Exception e) { + // its possible we were denied access with a FORBIDDEN code + // so retry with that code - if it still fails then we have an issue. + logger.trace("retrying: POST w/ user= {} should still NOT be allowed due to DD declaration", username); + TEST_PROPS.setProperty(TEST_NAME, "SecAnnotations/Test6"); + TEST_PROPS.setProperty(REQUEST, getRequestLine("POST", pageGuest)); + TEST_PROPS.setProperty(BASIC_AUTH_USER, username); // "j2ee" + TEST_PROPS.setProperty(BASIC_AUTH_PASSWD, password); // "j2ee" + TEST_PROPS.setProperty(STATUS_CODE, FORBIDDEN); + invoke(); + } + + logger.trace("Success - we were not allowed to POST or GET as role=Administrator (user=j2ee)."); + logger.trace("Test6 passed."); + } + + /** + * Returns a valid HTTP/1.1 request line. + * + * @param method + * the request method + * @param path + * the request path + * @return a valid HTTP/1.1 request line + */ + private static String getRequestLine(String method, String path) { + return method + " " + path + " HTTP/1.1"; + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/metadatacomplete/DenyAllServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/metadatacomplete/DenyAllServlet.java new file mode 100644 index 0000000000..298d8ce4de --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/metadatacomplete/DenyAllServlet.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2012, 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 + */ + +package com.sun.ts.tests.servlet.spec.security.metadatacomplete; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.HttpConstraint; +import jakarta.servlet.annotation.ServletSecurity; +import jakarta.servlet.annotation.ServletSecurity.EmptyRoleSemantic; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +/* + * This servlet is declared to PERMIT all via annotation but is declared + * to DenyAll via DD. The DD is flagged with metadata-complete=true so + * the DD *must* take precedence over the annotation in here. Thus + * this servlet will be set to DENYALL because of the DD settings. + */ +@ServletSecurity(@HttpConstraint(EmptyRoleSemantic.PERMIT)) +@WebServlet(name = "DenyAllTestLogicalName", urlPatterns = { + "/ServletDenyAll" }) +public class DenyAllServlet extends HttpServlet { + + // + // this must be supported per Servlet 3.0 spec (section 13.4), bullet item 1. + // + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + PrintWriter out = response.getWriter(); + + System.out.println("Inside DenyAllServlet ....." + "
"); + if ((request != null) && (request.getUserPrincipal() != null)) { + System.out.println("The user principal is: " + + request.getUserPrincipal().getName() + "
"); + System.err.println("The user principal is: " + + request.getUserPrincipal().getName() + "
"); + out.println("The user principal is: " + + request.getUserPrincipal().getName() + "
"); + out.println("getRemoteUser(): " + request.getRemoteUser() + "
"); + } + } + + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, java.io.IOException { + + PrintWriter out = response.getWriter(); + + if ((request != null) && (request.getUserPrincipal() != null)) { + System.out.println("Inside DenyAllServlet.doGet() ....." + "
"); + System.out.println("The user principal is: " + + request.getUserPrincipal().getName() + "
"); + System.err.println("The user principal is: " + + request.getUserPrincipal().getName() + "
"); + out.println("The user principal is: " + + request.getUserPrincipal().getName() + "
"); + out.println("getRemoteUser(): " + request.getRemoteUser() + "
"); + } else { + out.println( + "DenyAllServlet.doGet() - could not get request.getUserPrincipal()"); + } + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/metadatacomplete/GuestPageTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/metadatacomplete/GuestPageTestServlet.java new file mode 100644 index 0000000000..c583a4c052 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/metadatacomplete/GuestPageTestServlet.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2012, 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 + */ + +package com.sun.ts.tests.servlet.spec.security.metadatacomplete; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.HttpConstraint; +import jakarta.servlet.annotation.HttpMethodConstraint; +import jakarta.servlet.annotation.ServletSecurity; +import jakarta.servlet.annotation.ServletSecurity.EmptyRoleSemantic; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +/* + * The DD is using metadata-complete=true which means that the DD + * security constraints will get used and the annotation defined + * security constraints will be ignored. + * + * Using annotations, this servlet declares roles and then deny's all as a + * default, however GET is specified with a RolesAllowed="Administrator". + * There is a duplicate Servlet url/context defined in the DD - which means + * that the DD should override the annotations defined in this class. + * The DD indicates that role Manager (user=javajoe) has perm to do GET/POST + * requess. This will take precedence over the annotations of this class which + * state that role Administrator (user=j2ee) can issue GET requests. + */ + +@ServletSecurity(value = @HttpConstraint(EmptyRoleSemantic.DENY), httpMethodConstraints = { + @HttpMethodConstraint(value = "GET", rolesAllowed = "Administrator") }) +@WebServlet(name = "GuestPageTestLogicalName", urlPatterns = { + "/GuestPageTest" }) +public class GuestPageTestServlet extends HttpServlet { + + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + PrintWriter out = response.getWriter(); + if ((request != null) && (request.getUserPrincipal() != null)) { + out.println("The user principal is: " + + request.getUserPrincipal().getName() + "
"); + } else { + out.println( + "Could not get principal via request.getUserPrincipal() " + "
"); + } + + } + + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + PrintWriter out = response.getWriter(); + if ((request != null) && (request.getUserPrincipal() != null)) { + out.println("The user principal is: " + + request.getUserPrincipal().getName() + "
"); + } else { + out.println( + "Could not get principal via request.getUserPrincipal() " + "
"); + } + + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/metadatacomplete/ServletSecTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/metadatacomplete/ServletSecTestServlet.java new file mode 100644 index 0000000000..61e467dbf6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/metadatacomplete/ServletSecTestServlet.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2012, 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 + */ + +package com.sun.ts.tests.servlet.spec.security.metadatacomplete; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.HttpConstraint; +import jakarta.servlet.annotation.HttpMethodConstraint; +import jakarta.servlet.annotation.ServletSecurity; +import jakarta.servlet.annotation.ServletSecurity.EmptyRoleSemantic; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +/* + * The DD is using metadata-complete=true which means that the security + * settings in the DD will be used and the annotations security settings in + * this servlet will be ignored. + * + * The annotations in this servlet specify that all http methods can be accessed + * by role=Administrator but GET and POST are set to be denied all access. + * REMEMBER: these annotations will get ignored by DD since DD + * has metadata-complete=true! + * + * The DD will take precedence and sets GET accessible by role=Administrator(j2ee) + * and sets POST accessible by role=Manager(javajoe) + */ +@ServletSecurity(value = @HttpConstraint(rolesAllowed = { + "Administrator" }), httpMethodConstraints = { + @HttpMethodConstraint(value = "POST", emptyRoleSemantic = EmptyRoleSemantic.DENY), + @HttpMethodConstraint(value = "GET", emptyRoleSemantic = EmptyRoleSemantic.DENY) }) +@WebServlet(name = "ServletSecTestLogicalName", urlPatterns = { + "/ServletSecTest" }) +public class ServletSecTestServlet extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + PrintWriter out = response.getWriter(); + System.out + .println("Inside ServletSecTestServlet.service() ....." + "
"); + } + + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, java.io.IOException { + + PrintWriter out = response.getWriter(); + System.out + .println("Inside ServletSecTestServlet.doTrace() ....." + "
"); + } + + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, java.io.IOException { + + PrintWriter out = response.getWriter(); + System.out.println("Inside ServletSecTestServlet.doGet() ....." + "
"); + + if ((request != null) && (request.getUserPrincipal() != null)) { + out.println("The user principal is: " + + request.getUserPrincipal().getName() + "
"); + } else { + out.println("The user principal is: Null." + "
"); + } + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/metadatacomplete/UnProtectedTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/metadatacomplete/UnProtectedTestServlet.java new file mode 100644 index 0000000000..e447617f78 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/metadatacomplete/UnProtectedTestServlet.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2012, 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 + */ + +package com.sun.ts.tests.servlet.spec.security.metadatacomplete; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.HttpConstraint; +import jakarta.servlet.annotation.ServletSecurity; +import jakarta.servlet.annotation.ServletSecurity.EmptyRoleSemantic; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +/* + * This annotation essentially sets Deny all access on the servlet. However, our + * DD is set with metadata-complete=true so the DD will cause any annotations + * in this servlet to be ignored and the DD settings currently leave the + * servlet unprotected so a Permit all should ultmiately be set on this servlet. + */ +@ServletSecurity(@HttpConstraint(EmptyRoleSemantic.DENY)) +@WebServlet(name = "UnProtectedTestLogicalName", urlPatterns = { + "/UnProtectedTest" }) +public class UnProtectedTestServlet extends HttpServlet { + + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter out = response.getWriter(); + if ((request != null) && (request.getUserPrincipal() == null)) { + out.println( + "The user principal is: " + request.getUserPrincipal() + "
"); + } else { + out.println("The user principal is: " + + request.getUserPrincipal().getName() + "
"); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/metadatacomplete/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/metadatacomplete/build.xml new file mode 100644 index 0000000000..0342ece711 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/metadatacomplete/build.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/metadatacomplete/servlet_sec_metadatacomplete.ear.sun-application.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/metadatacomplete/servlet_sec_metadatacomplete.ear.sun-application.xml new file mode 100644 index 0000000000..17ea98cca9 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/metadatacomplete/servlet_sec_metadatacomplete.ear.sun-application.xml @@ -0,0 +1,35 @@ + + + + + + + Administrator + j2ee + + + Manager + javajoe + + + Employee + javajoe + j2ee + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/metadatacomplete/servlet_sec_metadatacomplete_web.war.sun-web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/metadatacomplete/servlet_sec_metadatacomplete_web.war.sun-web.xml new file mode 100644 index 0000000000..2dbb8e7f8a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/metadatacomplete/servlet_sec_metadatacomplete_web.war.sun-web.xml @@ -0,0 +1,36 @@ + + + + + + servlet_sec_metadatacomplete_web + + Administrator + j2ee + + + Manager + javajoe + + + Employee + javajoe + j2ee + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/metadatacomplete/servlet_sec_metadatacomplete_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/metadatacomplete/servlet_sec_metadatacomplete_web.xml new file mode 100644 index 0000000000..70246ce8f4 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/metadatacomplete/servlet_sec_metadatacomplete_web.xml @@ -0,0 +1,158 @@ + + + + + servlet_sec_annotations + + GuestPageTestLogicalName + com.sun.ts.tests.servlet.spec.security.metadatacomplete.GuestPageTestServlet + + MGR + Manager + + + + DenyAllTestLogicalName + com.sun.ts.tests.servlet.spec.security.metadatacomplete.DenyAllServlet + + MGR + Manager + + + + UnProtectedTestLogicalName + com.sun.ts.tests.servlet.spec.security.metadatacomplete.UnProtectedTestServlet + + ADM + Administrator + + + MGR + Manager + + + EMP + Employee + + + + ServletSecTestLogicalName + com.sun.ts.tests.servlet.spec.security.metadatacomplete.ServletSecTestServlet + + ADM + Administrator + + + MGR + Manager + + + EMP + Employee + + + + GuestPageTestLogicalName + /GuestPageTest + + + DenyAllTestLogicalName + /ServletDenyAll + + + ServletSecTestLogicalName + /ServletSecTest + + + UnProtectedTestLogicalName + /UnProtectedTest + + + + MySecureBit1 + /GuestPageTest + POST + GET + + + Manager + + + NONE + + + + + MySecureBit2 + /ServletDenyAll + + + + NONE + + + + + MySecureBit20 + /ServletSecTest + POST + + + Manager + + + NONE + + + + + MySecureBit21 + /ServletSecTest + GET + + + Administrator + + + NONE + + + + 54 + + + BASIC + + + the administrator role + Administrator + + + the manager role + Manager + + + the employee role + Employee + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/Client.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/Client.java new file mode 100644 index 0000000000..892d8640a3 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/Client.java @@ -0,0 +1,475 @@ +/* + * 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$ + */ +package com.sun.ts.tests.servlet.spec.security.secbasic; + +import com.sun.ts.tests.servlet.common.request.SecBasicClient; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; + +import java.util.Properties; + + +/* + * This class uses the SecBasicClient to do most of its actual testing. + * The tests within this file will either test security constraints using the + * DD file or by using annotations. The naming scheme in this file is as + * follows: + * test1() - tests security constaints using DD file + * test1_anno() - tests security constraints using annotations + * In both cases (testing using DD or annotations) the actual tests are + * being done in the secBasicClient. The real difference regards whether + * the servlet under test is annotation or DD based. + * + */ +public class Client extends SecBasicClient { + + // TOFIX + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_sec_secbasic_web.war").addClasses(GuestPageAnnoTestServlet.class, GuestPageTestServlet.class, RoleReverseAnnoTestServlet.class, RoleReverseTestServlet.class, ServletSecAnnoTestServlet.class, ServletSecTestServlet.class, UnProtectedAnnoTestServlet.class, UnProtectedTestServlet.class).setWebXML(Client.class.getResource("servlet_sec_secbasic_web.xml")); + } + + /* + * setup() passes "servlet" as the argument to its parent class setup() + * + */ + + /* + * @class.setup_props: webServerHost; webServerPort; user; password; authuser; + * authpassword; ts_home; + * + */ + public void setup(String[] args, Properties p) throws Exception { + _props = p; + + // create newarguments to pass into superclass setup method. + String[] newargs = new String[2]; + + // "servlet" is the flag passed to superclass + String argExt = new String("servlet"); + newargs[0] = argExt; + newargs[1] = argExt; // dummy argument + + // Inform the super class to run servlet related tests + super.setup(newargs, p); + } + + /* + * @testName: test1 + * + * @assertion_ids:Servlet:SPEC:140; JavaEE:SPEC:21 + * + * @test_Strategy: 1. Send request to access jspSec.jsp 2. Receive + * authentication request. + * + */ + + /* + * @testName: test1_anno + * + * @assertion_ids:Servlet:SPEC:140; JavaEE:SPEC:21; Servlet:SPEC:290; + * Servlet:SPEC:291; Servlet:SPEC:293; Servlet:SPEC:296; Servlet:SPEC:297; + * + * @test_Strategy: This does the same thing as test1() with the difference + * being that this test is using a servlet w/ security constraints defined + * thru annotations instead of DD. This test validates the following: 1. Send + * request to access ServletSecAnnoTest (thru SecBasicClient) as + * unauthenticated user 2. Receive authentication request. + * + */ + @Test + public void test1_anno() throws Exception { + // save off pageSec so that we can reuse it + String tempPageSec = pageSec; + pageSec = "/servlet_sec_secbasic_web/ServletSecAnnoTest"; + try { + super.test1(); + } catch (Exception e) { + throw e; + } finally { + // reset pageSec to orig value + pageSec = tempPageSec; + } + } + + /* + * @testName: test2 + * + * @assertion_ids: Servlet:SPEC:140;Servlet:JAVADOC:368; JavaEE:SPEC:281 + * + * + * @test_Strategy: 1. Send request with correct authentication. 2. Receive + * page (ensure principal is correct, and ensure that getRemoteUser() returns + * the correct name) + * + * Note: 1. If user has not been authenticated and user attempts to access a + * protected web resource, and user enters a valid username and password, the + * original web resource is returned and user is authenticated. + * + * 2. getRemoteUser() returns the user name that the client authenticated + * with. + * + */ + /* + * @testName: test2_anno + * + * @assertion_ids: Servlet:SPEC:140; JavaEE:SPEC:21; Servlet:SPEC:290; + * Servlet:SPEC:291; Servlet:SPEC:293; Servlet:SPEC:296; Servlet:SPEC:297; + * + * @test_Strategy: This does the same thing as test2() with the difference + * being that this test is using a servlet w/ security constraints defined + * thru annotations instead of DD. This particular test (test2_anno) actually + * requires the use of the DD to set the and since + * these cant be linked using annotations only. + * + * This test validates the following: 1. Send request with correct + * authentication. 2. Receive page (ensure principal is correct, and ensure + * that getRemoteUser() returns the correct name) + * + * Note: 1. If user has not been authenticated and user attempts to access a + * protected web resource, and user enters a valid username and password, the + * original web resource is returned and user is authenticated. + * + * 2. getRemoteUser() returns the user name that the client authenticated + * with. NOTE: the test (test2 in secBasicClient) actually does a check of the + * "ADM" role (as defined in the DD via the role-link element.) + * + */ + @Test + public void test2_anno() throws Exception { + // save off pageSec so that we can reuse it + String tempPageSec = pageSec; + pageSec = "/servlet_sec_secbasic_web/ServletSecAnnoTest"; + try { + super.test2(); + } catch (Exception e) { + throw e; + } finally { + // reset pageSec to orig value + pageSec = tempPageSec; + } + } + + /* + * @testName: test3 + * + * @assertion_ids: Servlet:SPEC:162; JavaEE:SPEC:30; JavaEE:SPEC:281 + * + * @test_Strategy: 1. Re-send request with incorrect authentication. 2. + * Receive authentication request. + * + * Note: 1. If user has not been authenticated and user attempts to access a + * protected web resource, and user enters an invalid username and password, + * the container denies access to the web resource. + * + */ + /* + * @testName: test3_anno + * + * @assertion_ids: Servlet:SPEC:162; JavaEE:SPEC:30; JavaEE:SPEC:281; + * Servlet:SPEC:290; Servlet:SPEC:291; Servlet:SPEC:293; Servlet:SPEC:296; + * Servlet:SPEC:297; + * + * @test_Strategy: This does the same thing as test3() with the difference + * being that this test is using a servlet w/ security constraints defined + * thru annotations instead of DD. This test validates the following: 1. + * Re-send request with incorrect authentication. 2. Receive authentication + * request. + * + * Note: 1. If user has not been authenticated and user attempts to access a + * protected web resource, and user enters an invalid username and password, + * the container denies access to the web resource. + * + */ + @Test + public void test3_anno() throws Exception { + // save off pageSec so that we can reuse it + String tempPageSec = pageSec; + pageSec = "/servlet_sec_secbasic_web/ServletSecAnnoTest"; + try { + super.test3(); + } catch (Exception e) { + throw e; + } finally { + // reset pageSec to orig value + pageSec = tempPageSec; + } + } + + /* + * @testName: test4 + * + * @assertion_ids: Servlet:SPEC:162; JavaEE:SPEC:30; JavaEE:SPEC:281 + * + * @test_Strategy: 1. Send request with correct authentication for user + * javajoe for a page javajoe is allowed to access. 2. Receive page (this + * verifies that the javajoe user is set up properly). 3. Send request with + * correct authentication, but incorrect authorization to access resource 4. + * Receive error + * + * Note: If user has not been authenticated and user attempts to access a + * protected web resource, and user enters an valid username and password, but + * for a role that is not authorized to access the resource, the container + * denies access to the web resource. + * + */ + /* + * @testName: test4_anno + * + * @assertion_ids: Servlet:SPEC:162; JavaEE:SPEC:30; JavaEE:SPEC:281; + * Servlet:SPEC:290; Servlet:SPEC:291; Servlet:SPEC:293; Servlet:SPEC:298; + * + * @test_Strategy: This does the same thing as test4() with the difference + * being that this test is using a servlet w/ security constraints defined + * thru annotations instead of DD. This test validates the following: 1. Send + * request with correct authentication for user javajoe for a page javajoe is + * allowed to access. 2. Receive page (this verifies that the javajoe user is + * set up properly). 3. Send request with correct authentication, but + * incorrect authorization to access resource 4. Receive error + * + * Note: If user has not been authenticated and user attempts to access a + * protected web resource, and user enters an valid username and password, but + * for a role that is not authorized to access the resource, the container + * denies access to the web resource. + * + */ + @Test + public void test4_anno() throws Exception { + // save off pageSec so that we can reuse it + String tempPageSec = pageSec; + String tempPageGuest = pageGuest; + pageSec = "/servlet_sec_secbasic_web/ServletSecAnnoTest"; + pageGuest = "/servlet_sec_secbasic_web/GuestPageAnnoTest"; + try { + super.test4(); + } catch (Exception e) { + throw e; + } finally { + // reset pageSec to orig value + pageSec = tempPageSec; + pageGuest = tempPageGuest; + } + } + + /* + * @testName: test5 + * + * @assertion_ids: Servlet:JAVADOC:368; Servlet:JAVADOC:369; JavaEE:SPEC:30; + * JavaEE:SPEC:281 + * + * @test_Strategy: 1. Send request for unprotected.jsp with no authentication. + * 2. Receive page 3. Search the returned page for "!true!", which would + * indicate that at least one call to isUserInRole attempted by + * unprotected.jsp returned true. 4. check that getRemoteUser() returns null. + * + * Note: 1. If user has not been authenticated and user attempts to access an + * unprotected web resource, the web resource is returned without need to + * authenticate. 2. isUserInRole() must return false for any valid or invalid + * role reference. 3. getRemoteUser() must return false + * + */ + /* + * @testName: test5_anno + * + * @assertion_ids: Servlet:JAVADOC:368; Servlet:JAVADOC:369; JavaEE:SPEC:30; + * JavaEE:SPEC:281; Servlet:SPEC:290; Servlet:SPEC:298; + * + * @test_Strategy: This does the same thing as test5() with the difference + * being that this test is using a servlet w/ security constraints defined + * thru annotations instead of DD. This test validates the following: 1. Send + * request for unprotected.jsp with no authentication. 2. Receive page 3. + * Search the returned page for "!true!", which would indicate that at least + * one call to isUserInRole attempted by unprotected.jsp returned true. 4. + * check that getRemoteUser() returns null. + * + * Note: 1. If user has not been authenticated and user attempts to access an + * unprotected web resource, the web resource is returned without need to + * authenticate. 2. isUserInRole() must return false for any valid or invalid + * role reference. 3. getRemoteUser() must return false + * + */ + @Test + public void test5_anno() throws Exception { + // save off pageSec so that we can reuse it + String tempPageUnprotected = pageUnprotected; + pageUnprotected = "/servlet_sec_secbasic_web/UnProtectedAnnoTest"; + try { + super.test5(); + } catch (Exception e) { + throw e; + } finally { + // reset pageSec to orig value + pageUnprotected = tempPageUnprotected; + } + } + + /* + * @testName: test6 + * + * @assertion_ids: Servlet:SPEC:149 + * + * @test_Strategy: Given two servlets in the same application, each of which + * calls isUserInRole(X), and where X is linked to different roles in the + * scope of each of the servlets (i.e. R1 for servlet 1 and R2 for servlet 2), + * then a user whose identity is mapped to R1 but not R2, shall get a true + * return value from isUserInRole( X ) in servlet 1, and a false return value + * from servlet 2 (a user whose identity is mapped to R2 but not R1 should get + * the inverse set of return values). + * + * Since test1 already verifies the functionality for isUserInRole returning + * true, this test needs only verify that it should return false for the other + * jsp. For this test, MGR and ADM are swapped, so isUserInRole() should + * return opposite values from test1. + * + * 1. Send request to access rolereverse.jsp 2. Receive redirect to login + * page, extract location and session id cookie. 3. Send request to access new + * location, send cookie 4. Receive login page 5. Send form response with + * username and password 6. Receive redirect to resource 7. Request resource + * 8. Receive resource (check isUserInRole for all known roles) + * + */ + /* + * @testName: test6_anno + * + * @assertion_ids: Servlet:SPEC:149; Servlet:SPEC:290; Servlet:SPEC:293; + * Servlet:SPEC:296; Servlet:SPEC:297; + * + * @test_Strategy: This does the same thing as test6() with the difference + * being that this test is using a servlet w/ security constraints defined + * thru annotations instead of DD. This test validates the following: Given + * two servlets in the same application, each of which calls isUserInRole(X), + * and where X is linked to different roles in the scope of each of the + * servlets (i.e. R1 for servlet 1 and R2 for servlet 2), then a user whose + * identity is mapped to R1 but not R2, shall get a true return value from + * isUserInRole( X ) in servlet 1, and a false return value from servlet 2 (a + * user whose identity is mapped to R2 but not R1 should get the inverse set + * of return values). + * + * Since test1 already verifies the functionality for isUserInRole returning + * true, this test needs only verify that it should return false for the other + * jsp. For this test, MGR and ADM are swapped, so isUserInRole() should + * return opposite values from test1. + * + * 1. Send request to access rolereverse.jsp 2. Receive redirect to login + * page, extract location and session id cookie. 3. Send request to access new + * location, send cookie 4. Receive login page 5. Send form response with + * username and password 6. Receive redirect to resource 7. Request resource + * 8. Receive resource (check isUserInRole for all known roles) + * + */ + @Test + public void test6_anno() throws Exception { + // save off pageSec so that we can reuse it + String tempPageRoleReverse = pageRoleReverse; + pageRoleReverse = "/servlet_sec_secbasic_web/RoleReverseAnnoTest"; + try { + super.test6(); + } catch (Exception e) { + throw e; + } finally { + // reset pageSec to orig value + pageRoleReverse = tempPageRoleReverse; + } + } + + /* + * @testName: test7 + * + * @assertion_ids: Servlet:SPEC:162; JavaEE:SPEC:30; JavaEE:SPEC:281 + * + * @test_Strategy: 1. Re-send request with incorrect authentication. 2. + * Receive authentication request. + * + * Note: 1. If user has not been authenticated and user attempts to access a + * protected web resource, and user enters an invalid username and password, + * the container denies access to the web resource. + * + */ + /* + * @testName: test7_anno + * + * @assertion_ids: Servlet:SPEC:162; JavaEE:SPEC:30; JavaEE:SPEC:281; + * Servlet:SPEC:290; + * + * @test_Strategy: This does the same thing as test7() with the difference + * being that this test is using a servlet w/ security constraints defined + * thru annotations instead of DD. This test validates the following: 1. + * Re-send request with incorrect authentication. 2. Receive authentication + * request. + * + * Note: 1. If user has not been authenticated and user attempts to access a + * protected web resource, and user enters an invalid username and password, + * the container denies access to the web resource. + * + */ + @Test + public void test7_anno() throws Exception { + // save off pageSec so that we can reuse it + String tempPageSec = pageSec; + pageSec = "/servlet_sec_secbasic_web/ServletSecAnnoTest"; + try { + super.test7(); + } catch (Exception e) { + throw e; + } finally { + // reset pageSec to orig value + pageSec = tempPageSec; + } + } + + @Test() + public void test1() throws Exception { + super.test1(); + } + + @Test() + public void test2() throws Exception { + super.test2(); + } + + @Test() + public void test3() throws Exception { + super.test3(); + } + + @Test() + public void test4() throws Exception { + super.test4(); + } + + @Test() + public void test5() throws Exception { + super.test5(); + } + + @Test() + public void test6() throws Exception { + super.test6(); + } + + @Test() + public void test7() throws Exception { + super.test7(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/GuestPageAnnoTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/GuestPageAnnoTestServlet.java new file mode 100644 index 0000000000..bd31774b49 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/GuestPageAnnoTestServlet.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2012, 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 + */ + +package com.sun.ts.tests.servlet.spec.security.secbasic; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.annotation.security.DeclareRoles; +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.HttpConstraint; +import jakarta.servlet.annotation.ServletSecurity; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + + +/* + * This servlet is the annotation based equivalent of GuestPageTestServlet. + * As such this declares roles, and specifies that the GET and POST methods + * can be accessed by all of the declared roles. + * + * This annotation based version of GuestPageTestServlet varies a bit from + * it because GuestPageTestServlet specifies that GET and POST can be accessed + * by "Administrator", "Manager", "Employee" *but* all other http methods + * are left unprotected and so can be accessed by anyone. + * This servlet specifies that *all* http methods can be accessed by + * "Administrator", "Manager", "Employee" (including GET and POST) and NO + * http methods are left unprotected. Thus, this servlet is trying to + * be more secure yet it still leaves GET & POST accessible to all declared + * roles just as is done with GuestPageTestServlet. + * + */ +@DeclareRoles({ "Administrator", "Manager", "Employee" }) +@ServletSecurity(@HttpConstraint(rolesAllowed = { "Administrator", "Manager", + "Employee" })) +@WebServlet(name = "GuestPageAnnoTest", urlPatterns = { "/GuestPageAnnoTest" }) +public class GuestPageAnnoTestServlet extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + PrintWriter out = response.getWriter(); + out.println("The user principal is: " + request.getUserPrincipal().getName() + + "
"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/GuestPageTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/GuestPageTestServlet.java new file mode 100644 index 0000000000..69f2569df6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/GuestPageTestServlet.java @@ -0,0 +1,40 @@ +/* + * 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$ + */ +package com.sun.ts.tests.servlet.spec.security.secbasic; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class GuestPageTestServlet extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter out = response.getWriter(); + out.println("The user principal is: " + request.getUserPrincipal().getName() + + "
"); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/README b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/README new file mode 100644 index 0000000000..365fdbe8a6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/README @@ -0,0 +1,16 @@ +The security tests for both JSP and servlet performs the same functionality. + +So the common code between JSP and servlet is kept under + + TS_HOME/src/com/sun/ts/tests/common/jspservletsec/secbasicClient.java + TS_HOME/src/com/sun/ts/tests/common/jspservletsec/secformClient.java + +And they are extended and used under + + TS_HOME/src/com/sun/ts/tests/jsp/sec/secbasic/Client.java (JSP) + TS_HOME/src/com/sun/ts/tests/servlet/sec/secbasic/Client.java (Servlet) + + TS_HOME/src/com/sun/ts/tests/jsp/sec/secform/Client.java (JSP) + TS_HOME/src/com/sun/ts/tests/servlet/sec/secform/Client.java (Servlet) + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/RoleReverseAnnoTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/RoleReverseAnnoTestServlet.java new file mode 100644 index 0000000000..edf2b2e97c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/RoleReverseAnnoTestServlet.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2012, 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 + */ + +package com.sun.ts.tests.servlet.spec.security.secbasic; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.annotation.security.DeclareRoles; +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.HttpMethodConstraint; +import jakarta.servlet.annotation.ServletSecurity; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + + +/* + * This should require employee role perms to access the Get or Post + * methods. This should be an equivelent to RoleReverseTest with the + * main difference being that this uses Servlet based annotations whereas + * RoleReverseTest uses DD for configuring its security constraints. + * It is worth noting that all methods (besides GET and POST) do NOT + * have any security constraints on them and so are unprotected and the + * access to Get & POST requires you to be an employee role.. + * + */ + +@DeclareRoles({ "Administrator", "Manager", "VP", "Employee" }) +@ServletSecurity(httpMethodConstraints = { + @HttpMethodConstraint(value = "GET", rolesAllowed = "Employee"), + @HttpMethodConstraint(value = "POST", rolesAllowed = "Employee") }) +@WebServlet(name = "RoleReverseAnnoTestLogicalName", urlPatterns = { + "/RoleReverseAnnoTest" }) +public class RoleReverseAnnoTestServlet extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter out = response.getWriter(); + out.println("The user principal is: " + request.getUserPrincipal().getName() + + "
"); + + // Output whether the user is in any of the known or an unknown role. + // Surround these with !'s so they are easier to search for. + // (i.e. we can search for !true! or !false!) + out.println( + "isUserInRole(\"ADM\"): !" + request.isUserInRole("ADM") + "!
"); + out.println( + "isUserInRole(\"MGR\"): !" + request.isUserInRole("MGR") + "!
"); + out.println( + "isUserInRole(\"VP\"): !" + request.isUserInRole("VP") + "!
"); + out.println( + "isUserInRole(\"EMP\"): !" + request.isUserInRole("EMP") + "!
"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/RoleReverseTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/RoleReverseTestServlet.java new file mode 100644 index 0000000000..ed51273aac --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/RoleReverseTestServlet.java @@ -0,0 +1,51 @@ +/* + * 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$ + */ +package com.sun.ts.tests.servlet.spec.security.secbasic; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class RoleReverseTestServlet extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter out = response.getWriter(); + out.println("The user principal is: " + request.getUserPrincipal().getName() + + "
"); + + // Output whether the user is in any of the known or an unknown role. + // Surround these with !'s so they are easier to search for. + // (i.e. we can search for !true! or !false!) + out.println( + "isUserInRole(\"ADM\"): !" + request.isUserInRole("ADM") + "!
"); + out.println( + "isUserInRole(\"MGR\"): !" + request.isUserInRole("MGR") + "!
"); + out.println( + "isUserInRole(\"VP\"): !" + request.isUserInRole("VP") + "!
"); + out.println( + "isUserInRole(\"EMP\"): !" + request.isUserInRole("EMP") + "!
"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/ServletSecAnnoTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/ServletSecAnnoTestServlet.java new file mode 100644 index 0000000000..3c4a0b1ed1 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/ServletSecAnnoTestServlet.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2012, 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 + */ + +package com.sun.ts.tests.servlet.spec.security.secbasic; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.annotation.security.DeclareRoles; +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.HttpConstraint; +import jakarta.servlet.annotation.HttpMethodConstraint; +import jakarta.servlet.annotation.ServletSecurity; +import jakarta.servlet.annotation.ServletSecurity.EmptyRoleSemantic; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +/* + * This should allow the Aministrator role perms to access any of the servlet + * methods. This is an annotation based equivalent of ServletSecTestServlet + * with the main difference being that this uses Servlet based annotations whereas + * ServletSecTestServlet uses DD for configuring its security constraints. + */ + +@DeclareRoles({ "Administrator", "Manager", "Employee" }) +@ServletSecurity(value = @HttpConstraint(EmptyRoleSemantic.DENY), httpMethodConstraints = { + @HttpMethodConstraint(value = "GET", rolesAllowed = "Administrator"), + @HttpMethodConstraint(value = "POST", rolesAllowed = "Administrator") }) +@WebServlet(name = "ServletSecAnnoTestLogicalName", urlPatterns = { + "/ServletSecAnnoTest" }) +public class ServletSecAnnoTestServlet extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter out = response.getWriter(); + + System.out.println("Inside ServletSecAnnoTestServlet ....." + "
"); + System.out.println("The user principal is: " + + request.getUserPrincipal().getName() + "
"); + System.err.println("The user principal is: " + + request.getUserPrincipal().getName() + "
"); + + out.println("The user principal is: " + request.getUserPrincipal().getName() + + "
"); + out.println("getRemoteUser(): " + request.getRemoteUser() + "
"); + + out.println("Inside ServletSecAnnoTestServlet ....." + "
"); // used for + // validating + // test7 + + // Surround these with !'s so they are easier to search for. + // (i.e. we can search for !true! or !false!) + out.println( + "isUserInRole(\"ADM\"): !" + request.isUserInRole("ADM") + "!
"); + out.println( + "isUserInRole(\"MGR\"): !" + request.isUserInRole("MGR") + "!
"); + out.println( + "isUserInRole(\"VP\"): !" + request.isUserInRole("VP") + "!
"); + out.println( + "isUserInRole(\"EMP\"): !" + request.isUserInRole("EMP") + "!
"); + out.println("isUserInRole(\"Administrator\"): !" + + request.isUserInRole("Administrator") + "!
"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/ServletSecTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/ServletSecTestServlet.java new file mode 100644 index 0000000000..7c95a3a65a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/ServletSecTestServlet.java @@ -0,0 +1,66 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.security.secbasic; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class ServletSecTestServlet extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter out = response.getWriter(); + + System.out.println("Inside ServletSecTestServlet ....." + "
"); + System.out.println("The user principal is: " + + request.getUserPrincipal().getName() + "
"); + System.err.println("The user principal is: " + + request.getUserPrincipal().getName() + "
"); + + out.println("The user principal is: " + request.getUserPrincipal().getName() + + "
"); + out.println("getRemoteUser(): " + request.getRemoteUser() + "
"); + + out.println("Inside ServletSecTestServlet ....." + "
"); // used for + // validating + // test7 + + // Surround these with !'s so they are easier to search for. + // (i.e. we can search for !true! or !false!) + out.println( + "isUserInRole(\"ADM\"): !" + request.isUserInRole("ADM") + "!
"); + out.println( + "isUserInRole(\"MGR\"): !" + request.isUserInRole("MGR") + "!
"); + out.println( + "isUserInRole(\"VP\"): !" + request.isUserInRole("VP") + "!
"); + out.println( + "isUserInRole(\"EMP\"): !" + request.isUserInRole("EMP") + "!
"); + out.println("isUserInRole(\"Administrator\"): !" + + request.isUserInRole("Administrator") + "!
"); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/UnProtectedAnnoTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/UnProtectedAnnoTestServlet.java new file mode 100644 index 0000000000..c82f9d53b5 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/UnProtectedAnnoTestServlet.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2012, 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 + */ + +package com.sun.ts.tests.servlet.spec.security.secbasic; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.annotation.security.DeclareRoles; +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.HttpConstraint; +import jakarta.servlet.annotation.ServletSecurity; +import jakarta.servlet.annotation.ServletSecurity.TransportGuarantee; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +/* + * This servlet is the annotation based equivalent of UnProtectedTestServlet. + * As such, this declares roles but sets no security constraints and leaves + * the page unprotected. + * + */ +@DeclareRoles({ "Administrator", "Manager", "VP", "Employee" }) +@ServletSecurity(@HttpConstraint(transportGuarantee = TransportGuarantee.NONE)) +@WebServlet(name = "UnProtectedAnnoTest", urlPatterns = { + "/UnProtectedAnnoTest" }) +public class UnProtectedAnnoTestServlet extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter out = response.getWriter(); + if (request.getUserPrincipal() == null) + out.println( + "The user principal is: " + request.getUserPrincipal() + "
"); + else + out.println("The user principal is: " + + request.getUserPrincipal().getName() + "
"); + + // Output whether the user is in any of the known or an unknown role. + // Surround these with !'s so they are easier to search for. + // (i.e. we can search for !true! or !false!) + out.println( + "isUserInRole(\"ADM\"): !" + request.isUserInRole("ADM") + "!
"); + out.println( + "isUserInRole(\"MGR\"): !" + request.isUserInRole("MGR") + "!
"); + out.println( + "isUserInRole(\"VP\"): !" + request.isUserInRole("VP") + "!
"); + out.println( + "isUserInRole(\"EMP\"): !" + request.isUserInRole("EMP") + "!
"); + + // Test getRemoteUser() functionality: + out.println("
"); + out.println("getRemoteUser(): " + request.getRemoteUser()); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/UnProtectedTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/UnProtectedTestServlet.java new file mode 100644 index 0000000000..1d829626ca --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/UnProtectedTestServlet.java @@ -0,0 +1,61 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.security.secbasic; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class UnProtectedTestServlet extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter out = response.getWriter(); + if (request.getUserPrincipal() == null) + out.println( + "The user principal is: " + request.getUserPrincipal() + "
"); + else + out.println("The user principal is: " + + request.getUserPrincipal().getName() + "
"); + + // Output whether the user is in any of the known or an unknown role. + // Surround these with !'s so they are easier to search for. + // (i.e. we can search for !true! or !false!) + out.println( + "isUserInRole(\"ADM\"): !" + request.isUserInRole("ADM") + "!
"); + out.println( + "isUserInRole(\"MGR\"): !" + request.isUserInRole("MGR") + "!
"); + out.println( + "isUserInRole(\"VP\"): !" + request.isUserInRole("VP") + "!
"); + out.println( + "isUserInRole(\"EMP\"): !" + request.isUserInRole("EMP") + "!
"); + + // Test getRemoteUser() functionality: + out.println("
"); + out.println("getRemoteUser(): " + request.getRemoteUser()); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/build.xml new file mode 100644 index 0000000000..07c198f328 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/build.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/servlet_sec_secbasic.ear.sun-application.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/servlet_sec_secbasic.ear.sun-application.xml new file mode 100644 index 0000000000..8b8788aa16 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/servlet_sec_secbasic.ear.sun-application.xml @@ -0,0 +1,40 @@ + + + + + + + servlet_sec_secbasic_web.war + servlet_sec_secbasic_web + + 0 + + Administrator + j2ee + + + Manager + javajoe + + + Employee + javajoe + j2ee + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/servlet_sec_secbasic_web.war.sun-web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/servlet_sec_secbasic_web.war.sun-web.xml new file mode 100644 index 0000000000..3cc3346de5 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/servlet_sec_secbasic_web.war.sun-web.xml @@ -0,0 +1,36 @@ + + + + + + /servlet_sec_secbasic_web + + Administrator + j2ee + + + Manager + javajoe + + + Employee + javajoe + j2ee + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/servlet_sec_secbasic_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/servlet_sec_secbasic_web.xml new file mode 100644 index 0000000000..4da4600df5 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secbasic/servlet_sec_secbasic_web.xml @@ -0,0 +1,229 @@ + + + + + servlet_sec_secbasic + + RoleReverseTestLogicalName + com.sun.ts.tests.servlet.spec.security.secbasic.RoleReverseTestServlet + + MGR + Administrator + + + ADM + Manager + + + VP + VP + + + EMP + Employee + + + + RoleReverseAnnoTestLogicalName + com.sun.ts.tests.servlet.spec.security.secbasic.RoleReverseAnnoTestServlet + + MGR + Administrator + + + ADM + Manager + + + VP + VP + + + EMP + Employee + + + + GuestPageTestLogicalName + com.sun.ts.tests.servlet.spec.security.secbasic.GuestPageTestServlet + + ADM + Administrator + + + MGR + Manager + + + VP + VP + + + EMP + Employee + + + + UnProtectedTestLogicalName + com.sun.ts.tests.servlet.spec.security.secbasic.UnProtectedTestServlet + + ADM + Administrator + + + MGR + Manager + + + VP + VP + + + EMP + Employee + + + + ServletSecTestLogicalName + com.sun.ts.tests.servlet.spec.security.secbasic.ServletSecTestServlet + + ADM + Administrator + + + MGR + Manager + + + VP + VP + + + EMP + Employee + + + + ServletSecAnnoTestLogicalName + com.sun.ts.tests.servlet.spec.security.secbasic.ServletSecAnnoTestServlet + + ADM + Administrator + + + MGR + Manager + + + VP + VP + + + EMP + Employee + + + + RoleReverseTestLogicalName + /RoleReverseTest + + + GuestPageTestLogicalName + /GuestPageTest + + + UnProtectedTestLogicalName + /UnProtectedTest + + + ServletSecTestLogicalName + /ServletSecTest + + + 54 + + + + MySecureBit1 + /GuestPageTest + GET + POST + + + Administrator + Manager + VP + + + NONE + + + + + MySecureBit2 + /RoleReverseTest + GET + POST + + + Employee + + + NONE + + + + + MySecureBit0 + /ServletSecTest + GET + POST + + + Administrator + + + NONE + + + + BASIC + default + + + the administrator role + Administrator + + + the manager role + Manager + + + the VP role + VP + + + the employee role + Employee + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/Client.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/Client.java new file mode 100644 index 0000000000..61c3501d7c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/Client.java @@ -0,0 +1,747 @@ +/* + * 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$ + */ +package com.sun.ts.tests.servlet.spec.security.secform; + +import com.sun.ts.tests.servlet.common.request.SecformClient; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; +import java.util.Properties; + +/* + * This class uses the SecformClient to do most of its actual testing. + * The tests within this file will either test security constraints using the + * DD file or by using annotations. The naming scheme in this file is as + * follows: + * test1() - tests security constaints using DD file + * test1_anno() - tests security constraints using annotations + * In both cases (testing using DD or annotations) the actual tests are + * being done in the secformClient. The real difference regards whether + * the servlet under test is annotation or DD based. + * + */ +public class Client extends SecformClient { + + // TOFIX + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_sec_secform_web.war").addAsWebResource("spec/security/secform/login.jsp", "login.jsp").addAsWebResource("spec/security/secform/error.jsp", "error.jsp").addClasses(allRolesTestServlet.class, ControlServlet.class, ForwardedServlet.class, GuestPageAnnoTestServlet.class, GuestPageTestServlet.class, IncludedServlet.class, OneTestServlet.class, RoleReverseTestServlet.class, RoleReverseAnnoTestServlet.class, SampleTestServlet.class, ServletProgrammaticAuthen.class, ServletProgrammaticLogin.class, ServletProgrammaticLogout.class, ServletSecAnnoTestServlet.class, ServletSecTestServlet.class, TwoTestServlet.class, UnProtectedAnnoTestServlet.class, UnProtectedTestServlet.class).setWebXML(Client.class.getResource("servlet_sec_secform_web.xml")); + } + + // Shared test variables: + private Properties props = null; + + // Note: To share the commoncode between servlet and JSP, + // the commoncode is kept under + // (TS_HOME)/src/com/sun/ts/tests/common/jspservletsec/secformClient.java + // This subclass(Client.java) is used to flag the superclass + // to run servlet related secform tests + // + /* + * setup() passes "servlet" as the argument to its parent class setup() + * + */ + /* + * @class.setup_props: webServerHost; webServerPort; user; password; authuser; + * authpassword; + * + */ + public void setup(String[] args, Properties p) throws Exception { + super.setup(args, p); + props = p; + } + + /* + * @testName: test1 + * + * @assertion_ids: Servlet:SPEC:142; JavaEE:SPEC:21 + * + * @test_Strategy: 1. Send request to access jspSec.jsp 2. Receive login + * page(make sure it the expected login page) 3. Send form response with + * username and password 4. Receive jspSec.jsp (ensure principal is correct, + * and ensure getRemoteUser() returns the username, and ensure isUserInRole() + * is working properly) 5. Re-request jspSec.jsp 6. Ensure principal is still + * correct and getRemoteUser() still returns the correct username. Also ensure + * isUserInRole() is still working properly. + * + */ + /* + * @testName: test1_anno + * + * @assertion_ids: Servlet:SPEC:142; JavaEE:SPEC:21; Servlet:SPEC:290; + * Servlet:SPEC:291; Servlet:SPEC:293; Servlet:SPEC:296; Servlet:SPEC:297; + * Servlet:SPEC:298; + * + * @test_Strategy: This does the same thing as test1() with the difference + * being that this test is using a servlet w/ security constraints defined + * thru annotations instead of DD. This test validates the following: 1. Send + * request to access jspSec.jsp 2. Receive login page(make sure it the + * expected login page) 3. Send form response with username and password 4. + * Receive jspSec.jsp (ensure principal is correct, and ensure getRemoteUser() + * returns the username, and ensure isUserInRole() is working properly) 5. + * Re-request jspSec.jsp 6. Ensure principal is still correct and + * getRemoteUser() still returns the correct username. Also ensure + * isUserInRole() is still working properly. + * + */ + @Test + public void test1_anno() throws Exception { + // save off pageSec so that we can reuse it + String tempPageSec = pageSec; + pageSec = "/servlet_sec_secform_web/ServletSecAnnoTest"; + try { + super.test1(); + } catch (Exception e) { + throw e; + } finally { + // reset pageSec to orig value + pageSec = tempPageSec; + } + } + + /* + * @testName: test2 + * + * @assertion_ids: Servlet:SPEC:142.4.3 + * + * @test_Strategy: 1. Send request to access jspSec.jsp 2. Receive login page + * 3. Send form response with username and incorrect password 4. Receive error + * page (make sure it is the expected error page) + * + */ + /* + * @testName: test2_anno + * + * @assertion_ids: Servlet:SPEC:142.4.3; Servlet:SPEC:290; Servlet:SPEC:291; + * Servlet:SPEC:293; Servlet:SPEC:296; + * + * @test_Strategy: This does the same thing as test2() with the difference + * being that this test is using a servlet w/ security constraints defined + * thru annotations instead of DD. This test validates the following: 1. Send + * request to access jspSec.jsp 2. Receive login page 3. Send form response + * with username and incorrect password 4. Receive error page (make sure it is + * the expected error page) + * + */ + @Test + public void test2_anno() throws Exception { + // save off pageSec so that we can reuse it + String tempPageSec = pageSec; + pageSec = "/servlet_sec_secform_web/ServletSecAnnoTest"; + try { + super.test2(); + } catch (Exception e) { + throw e; + } finally { + // reset pageSec to orig value + pageSec = tempPageSec; + } + } + + /* + * @testName: test3 + * + * @assertion_ids: Servlet:SPEC:142 + * + * @test_Strategy: 1. Send request to access guestPage.jsp 2. Receive login + * page 3. Send form response with username(javajoe) and password 4. Receive + * resource (check user principal) Note: If user has not been authenticated + * and user attempts to access a protected web resource, and user enters + * correct username and password of a user that is authorized to access the + * resource, the resource is returned (similar to test1, but uses user javajoe + * instead of j2ee). This test establishes that the javajoe user is set up + * properly. + * + * + */ + /* + * @testName: test3_anno + * + * @assertion_ids: Servlet:SPEC:142; Servlet:SPEC:290; Servlet:SPEC:291; + * Servlet:SPEC:298; + * + * @test_Strategy: This does the same thing as test3() with the difference + * being that this test is using a servlet w/ security constraints defined + * thru annotations instead of DD. This test validates the following: 1. Send + * request with correct authentication for user javajoe for a page javajoe is + * allowed to access. 2. Receive login page (this verifies that the javajoe + * user is set up properly). 3. Send form response with username(javajoe) and + * password 4. Receive resource (check user principal) + * + * If user has not been authenticated and user attempts to access a protected + * web resource, and user enters correct username and password of a user that + * is authorized to access the resource, the resource is returned (similar to + * test1, but uses user javajoe instead of j2ee). This test establishes that + * the javajoe user is set up properly. + * + */ + @Test + public void test3_anno() throws Exception { + // save off pageGuest so that we can reuse it + String tempPageGuest = pageGuest; + pageGuest = "/servlet_sec_secform_web/GuestPageAnnoTest"; + try { + super.test3(); + } catch (Exception e) { + throw e; + } finally { + // reset pageGuest to orig value + pageGuest = tempPageGuest; + } + } + + /* + * @testName: test4 + * + * @assertion_ids: Servlet:SPEC:149;Servlet:SPEC:160;Servlet:SPEC:162 + * + * @test_Strategy: 1. Send request to access jspSec.jsp 2. Receive login page + * 3. Send form response with username and password 4. Receive an error + * (expected unauthorized error) 5. Send request to access unprotected.jsp 6. + * Receive unprotected.jsp. Note: If user has not been authenticated and user + * attempts to access a protected web resource, and user enters correct + * username and password of a user that is not authorized to access the + * resource, the resource is not returned. The authenticated user is not + * denied access to an unprotected page. + * + */ + /* + * @testName: test4_anno + * + * @assertion_ids: Servlet:SPEC:149;Servlet:SPEC:160;Servlet:SPEC:162; + * Servlet:SPEC:290; Servlet:SPEC:291; Servlet:SPEC:293; Servlet:SPEC:296; + * + * @test_Strategy: This does the same thing as test4() with the difference + * being that this test is using a servlet w/ security constraints defined + * thru annotations instead of DD. This test validates the following: 1. Send + * request to access jspSec.jsp 2. Receive login page 3. Send form response + * with username and password 4. Receive an error (expected unauthorized + * error) 5. Send request to access unprotected.jsp 6. Receive + * unprotected.jsp. Note: If user has not been authenticated and user attempts + * to access a protected web resource, and user enters correct username and + * password of a user that is not authorized to access the resource, the + * resource is not returned. The authenticated user is not denied access to an + * unprotected page. + * + */ + @Test + public void test4_anno() throws Exception { + // save off pageSec so that we can reuse it + String tempPageSec = pageSec; + pageSec = "/servlet_sec_secform_web/ServletSecAnnoTest"; + try { + super.test4(); + } catch (Exception e) { + throw e; + } finally { + // reset pageSec to orig value + pageSec = tempPageSec; + } + } + + /* + * @testName: test5 + * + * @assertion_ids: Servlet:JAVADOC:368; Servlet:JAVADOC:369;Servlet:SPEC:154.1 + * + * @test_Strategy: 1. Send request to access unprotected.jsp 2. Receive + * unprotected.jsp 3. Search the returned page for "!true!", which would + * indicate that at least one call to isUserInRole attempted by + * unprotected.jsp returned true. 4. Check that the call to getRemoteUser() + * returned null. Note: If user has not been authenticated and user attempts + * to access an unprotected web resource, the resource is returned, and the + * user is not forced to authenticate. Also, isUserInRole() must return false + * for any valid or invalid role reference. A call to getRemoteUser() must + * return null. + * + */ + /* + * @testName: test5_anno + * + * @assertion_ids: Servlet:JAVADOC:368; + * Servlet:JAVADOC:369;Servlet:SPEC:154.1; Servlet:SPEC:290; Servlet:SPEC:291; + * Servlet:SPEC:298; + * + * @test_Strategy: This does the same thing as test5() with the difference + * being that this test is using a servlet w/ security constraints defined + * thru annotations instead of DD. This test validates the following: 1. Send + * request to access unprotected.jsp 2. Receive unprotected.jsp 3. Search the + * returned page for "!true!", which would indicate that at least one call to + * isUserInRole attempted by unprotected.jsp returned true. 4. Check that the + * call to getRemoteUser() returned null. Note: If user has not been + * authenticated and user attempts to access an unprotected web resource, the + * resource is returned, and the user is not forced to authenticate. Also, + * isUserInRole() must return false for any valid or invalid role reference. A + * call to getRemoteUser() must return null. + * + */ + @Test + public void test5_anno() throws Exception { + // save off pageUnprotected so that we can reuse it + String tempPageUnprotected = pageUnprotected; + pageUnprotected = "/servlet_sec_secform_web/UnProtectedAnnoTest"; + try { + super.test5(); + } catch (Exception e) { + throw e; + } finally { + // reset to orig value + pageUnprotected = tempPageUnprotected; + } + } + + /* + * @testName: test6 + * + * @assertion_ids: Servlet:SPEC:149 + * + * @test_Strategy: Given two servlets in the same application, each of which + * calls isUserInRole(X), and where X is linked to different roles in the + * scope of each of the servlets (i.e. R1 for servlet 1 and R2 for servlet 2), + * then a user whose identity is mapped to R1 but not R2, shall get a true + * return value from isUserInRole( X ) in servlet 1, and a false return value + * from servlet 2 (a user whose identity is mapped to R2 but not R1 should get + * the inverse set of return values). + * + * Since test1 already verifies the functionality for isUserInRole returning + * true, this test needs only verify that it should return false for the other + * jsp. For this test, MGR and ADM are swapped, so isUserInRole() should + * return opposite values from test1. + * + * 1. Send request to access rolereverse.jsp 2. Receive login page 3. Send + * form response with username and password 4. Receive resource (check + * isUserInRole for all known roles) + * + */ + /* + * @testName: test6_anno + * + * @assertion_ids: Servlet:SPEC:149; Servlet:SPEC:290; Servlet:SPEC:291; + * Servlet:SPEC:296; Servlet:SPEC:297; + * + * @test_Strategy: This does the same thing as test6() with the difference + * being that this test is using a servlet w/ security constraints defined + * thru annotations instead of DD. This test validates the following: + * + * Given two servlets in the same application, each of which calls + * isUserInRole(X), and where X is linked to different roles in the scope of + * each of the servlets (i.e. R1 for servlet 1 and R2 for servlet 2), then a + * user whose identity is mapped to R1 but not R2, shall get a true return + * value from isUserInRole( X ) in servlet 1, and a false return value from + * servlet 2 (a user whose identity is mapped to R2 but not R1 should get the + * inverse set of return values). + * + * Since test1 already verifies the functionality for isUserInRole returning + * true, this test needs only verify that it should return false for the other + * jsp. For this test, MGR and ADM are swapped, so isUserInRole() should + * return opposite values from test1. + * + * 1. Send request to access rolereverse.jsp 2. Receive login page 3. Send + * form response with username and password 4. Receive resource (check + * isUserInRole for all known roles) + * + */ + @Test + public void test6_anno() throws Exception { + // save off pageRoleReverse so that we can reuse it + String tempPageReverse = pageRoleReverse; + pageSec = "/servlet_sec_secform_web/RoleReverseAnnoTest"; + try { + super.test6(); + } catch (Exception e) { + throw e; + } finally { + // reset tempPageReverse to orig value + pageRoleReverse = tempPageReverse; + } + } + + /* + * @testName: test7 + * + * @assertion_ids: Servlet:SPEC:89 + * + * @test_Strategy: 1) send a http request to WEB-INF directory 2) expect 404 + * or 403 3) repeat step 1 and 2 for the following a) web-inf (for case + * insensitive platforms) b) WEB-INF/web.xml c) web-inf/web.xml 4) based on + * the http return code, report test status + * + */ + /* + * @testName: test8 + * + * @assertion_ids: Servlet:SPEC:92.1 + * + * @test_Strategy: 1) send a http request to META-INF directory 2) expect 404 + * or 403 3) repeat step 1 and 2 for the following a) meta-inf (for case + * insensitive platforms) b) META-INF/MANIFEST.MF c) meta-inf/manifest.mf 4) + * based on the http return code, report test status + * + */ + /* + * @testName: test9 + * + * @assertion_ids: Servlet:SPEC:134 + * + * @test_Strategy: 1) Deploy a two webcomponents One.jsp and Two.jsp + * exercising various mapping rules 2) Make a http request with a URL(based on + * the above mapping rules) 3) Make a http request with a absolute match URL. + * 4) compare the results obtained through step 2 and 3 and declare test + * result Note: + * + * 1) A string beginning with a / character and ending with a /* postfix is + * used as a path mapping. 2) A string beginning with a *. prefix is used as + * an extension mapping. 3) All other strings are used as exact matches only + * 4) A string containing only the / character indicates that servlet + * specified by the mapping becomes the "deException" servlet of the application. + * In this case the servlet path is the request URI minus the context path and + * the path info is null. + * + */ + /* + * @testName: test10 + * + * @assertion_ids: Servlet:SPEC:138; Servlet:SPEC:139; Servlet:SPEC:294; + * + * @test_Strategy: Note: test5 and test6 verifies the first part of the + * assertion. This test verifies only the second part of this assertion + * + * 1. Send request to access SampleTestServlet 2. Receive login page(make sure + * it is the expected login page) 3. Send form response with username and + * password 4. Receive Sample.jsp (ensure principal is correct, and ensure + * getRemoteUser() returns the username, and ensure isUserInRole() is working + * properly) + * + */ + /* + * @testName: test11 + * + * @assertion_ids: Servlet:SPEC:150 + * + * @test_Strategy: Configure allRoles.jsp to be accessible by allRoles ( + * Administrator and * ) + * + * 1) Try accesing allRoles.jsp as the following user a) j2ee b) javajoe 2) + * Based on the http reply, report test status + * + * Note: The auth-constraint element indicates the user roles that should be + * permitted access to this resource collection. The role used here must + * either in a security-role-ref element, or be the specially reserved + * role-name * that is a compact syntax for indicating all roles in the web + * application. If both * and rolenames appear, the container interprets this + * as all roles. + * + */ + /* ***NOTE:test12 is only for JSP */ + /* + * @testName: test13 + * + * @assertion_ids: Servlet:SPEC:137; JavaEE:SPEC:24 + * + * @test_Strategy: + * + * 1) Configure two servlets (IncludedServlet and ForwardedServlet) to be + * accessible only by administrator. + * + * 2) Configure ControlServlet to be accessible by everyone (i.e no security + * constraints for ControlServlet) + * + * 3) Now as a unauthenticated user access ForwardedServlet and + * IncludedServlet from ControlServlet + * + * ControlServlet ===>ForwardedServlet===>IncludedServlet + * + * i.e 3.1) From a ControlServlet access ForwardedServlet through dispatcher's + * forward method. + * + * 3.2) From the ForwardedServlet access/include IncludedServlet through + * Request dispatcher's include method + * + * 4) If the servlets(ForwardedServlet and IncludedServlet) are accessible + * report the test success otherwise report test failure + * + * Note: test13 is ONLY for SERVLET Area + * + */ + /* + * @testName: test14 + * + * @assertion_ids: Servlet:SPEC:144 + * + * @test_Strategy: 1. Configure pageSec(jspSec.jsp or ServletSecTest) and + * pageSample(Sample.jsp or SampleTest ) to be accessible only by + * Administrator 2. Send request to access jspSec.jsp 3. Receive login page 4. + * Send form response with username and password 5. Receive jspSec.jsp (ensure + * principal is correct, and ensure getRemoteUser() returns the username, and + * ensure isUserInRole() is working properly) 6. Try accessing + * pageSample(Sample.jsp or SampleTest) which is also configured to be + * accessible with the same security identity, since we are already + * authenticated we should be able to access pageSample without going through + * login page again. 7. Ensure principal is still correct and getRemoteUser() + * still returns the correct username. Also ensure isUserInRole() is still + * working properly. Note: servlet container is required to track + * authentication information at the container level (rather than at the web + * application level). This allows users authenticated for one web application + * to access other resources managed by the container permitted to the same + * security identity. + * + */ + /* + * @testName: test14_anno + * + * @assertion_ids: Servlet:SPEC:144; Servlet:SPEC:290; Servlet:SPEC:291; + * Servlet:SPEC:293; Servlet:SPEC:296; + * + * @test_Strategy: This does the same thing as test14() with the difference + * being that this test is using a servlet w/ security constraints defined + * thru annotations instead of DD. This test validates the following: 1. + * Configure pageSec(jspSec.jsp or ServletSecTest) and pageSample(Sample.jsp + * or SampleTest ) to be accessible only by Administrator 2. Send request to + * access jspSec.jsp 3. Receive login page 4. Send form response with username + * and password 5. Receive jspSec.jsp (ensure principal is correct, and ensure + * getRemoteUser() returns the username, and ensure isUserInRole() is working + * properly) 6. Try accessing pageSample(Sample.jsp or SampleTest) which is + * also configured to be accessible with the same security identity, since we + * are already authenticated we should be able to access pageSample without + * going through login page again. 7. Ensure principal is still correct and + * getRemoteUser() still returns the correct username. Also ensure + * isUserInRole() is still working properly. Note: servlet container is + * required to track authentication information at the container level (rather + * than at the web application level). This allows users authenticated for one + * web application to access other resources managed by the container + * permitted to the same security identity. + * + */ + @Test + public void test14_anno() throws Exception { + // save off pageSec so that we can reuse it + String tempPageSec = pageSec; + pageSec = "/servlet_sec_secform_web/ServletSecAnnoTest"; + try { + super.test14(); + } catch (Exception e) { + throw e; + } finally { + // reset pageSec to orig value + pageSec = tempPageSec; + } + } + + /* + * @testName: test15 + * + * @test_Strategy: This is similar to test14 except this is validating that we + * can not bypass security constraints when sso is on by simply adding + * "/j_security_check" to the request url. By adding "j_security_check" to the + * end of a request but not specifying authN creds, we should NOT be + * redirected to the requested/restricted page as we have not yet + * authenticated (even though we tried to trick/confuse the system by + * appending 'j_security_check' onto our request.) 1. attempt to access a + * protected resource by: Sending a request to access url: + * "/j_security_check" 2. We should not be authenticated yet so + * should get a response back from server with either an error or login form + * (we must verify that we are not authenticated and that we did NOT get the + * requested(and restricted) form back from server. + * + */ + /* + * @testName: test15_anno + * + * @assertion_ids: Servlet:SPEC:144; Servlet:SPEC:290; Servlet:SPEC:291; + * Servlet:SPEC:293; Servlet:SPEC:296; + * + * @test_Strategy: This does the same thing as test15() with the difference + * being that this test is using a servlet w/ security constraints defined + * thru annotations instead of DD. This test validates the following: + * + * This is similar to test14 except this is validating that we can not bypass + * security constraints when sso is on by simply adding "/j_security_check" to + * the request url. By adding "j_security_check" to the end of a request but + * not specifying authN creds, we should NOT be redirected to the + * requested/restricted page as we have not yet authenticated (even though we + * tried to trick/confuse the system by appending 'j_security_check' onto our + * request.) + * + * 1. attempt to access a protected resource by: Sending a request to access + * url: "/j_security_check" 2. We should not be authenticated yet so + * should get a response back from server with either an error or login form + * (we must verify that we are not authenticated and that we did NOT get the + * requested(and restricted) form back from server. + * + */ + @Test + public void test15_anno() throws Exception { + // save off pageSec so that we can reuse it + String tempPageSec = pageSec; + pageSec = "/servlet_sec_secform_web/ServletSecAnnoTest"; + try { + super.test15(); + } catch (Exception e) { + throw e; + } finally { + // reset pageSec to orig value + pageSec = tempPageSec; + } + } + + /* + * @testName: test16 + * + * @assertion: Test ability to login via the HttpServletRequst.login() method. + * as specified in the Java Servlet Specification v3.1, Sec 13.3 + * + * If user has not been authenticated and user attempts to access an + * unprotected web resource, the user should be able to access it. Since the + * user was not authenticated, calls to getUserPrincipal() should not return + * the name of user "j2ee" since. Once in the servlet, we should be able to + * invoke the HttpServletRequest.login() call to authenticate user "j2ee" and + * then calls to getUserPrincipal() should return user "j2ee" + * + * + * @test_Strategy: 1. Send request to access ServletProgrammaticLogin 2. the + * servlet performs tasks and sends response data back 3. we parse the data to + * see if we got desired output + * + */ + /* + * @testName: test17 + * + * @assertion: Test FORM-based authentication, specified in the Java Servlet + * Specification v2.2, Sec 11.5.3. + * + * If user has been authenticated and user attempts to access a protected web + * resource, and user enters correct username and password of a user that is + * authorized to access the resource, the resource is returned (similar to + * test1) + * + * @test_Strategy: 1. Send request to access protected page (ie. + * pageServletProgLogout) 2. Receive login page 3. Send form response with + * username(j2ee) and password 4. Receive resource 5. make sure no ERRORs + * occurrred on pageServletProgLogout and that it actually did log us out. + * + */ + /* + * @testName: test18 + * + * @assertion: Test ability to authenticate using + * HttpServletRequst.authenticate() as specified in the Java Servlet + * Specification v3.1, Sec 13.3 + * + * If user has not been authenticated and user attempts to access an + * unprotected web resource, the user should be able to access it. Since the + * user was not authenticated, calls to getUserPrincipal() should return null. + * Calls to authenticate() should return false. Once in the servlet, we should + * be able to invoke the HttpServletRequest.login() call to login with user + * "j2ee" and then calls to getUserPrincipal() should return user "j2ee". + * Calls to authenticate() should return true. + * + * @test_Strategy: 1. Send request to access ServletProgrammaticLogin 2. the + * servlet performs tasks and sends response data back 3. we parse the data to + * see if we got desired output + * + */ + @Test() + public void test1() throws Exception { + super.test1(); + } + + @Test() + public void test10() throws Exception { + super.test10(); + } + + @Test() + public void test11() throws Exception { + super.test11(); + } + + @Test() + public void test13() throws Exception { + super.test13(); + } + + @Test() + public void test14() throws Exception { + super.test14(); + } + + @Test() + public void test15() throws Exception { + super.test15(); + } + + @Test() + public void test16() throws Exception { + super.test16(); + } + + @Test() + public void test17() throws Exception { + super.test17(); + } + + @Test() + public void test18() throws Exception { + super.test18(); + } + + @Test() + public void test2() throws Exception { + super.test2(); + } + + @Test() + public void test3() throws Exception { + super.test3(); + } + + @Test() + public void test4() throws Exception { + super.test4(); + } + + @Test() + public void test5() throws Exception { + super.test5(); + } + + @Test() + public void test6() throws Exception { + super.test6(); + } + + @Test() + public void test7() throws Exception { + super.test7(); + } + + @Test() + public void test8() throws Exception { + super.test8(); + } + + @Test() + public void test9() throws Exception { + super.test9(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/ControlServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/ControlServlet.java new file mode 100644 index 0000000000..4598c13765 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/ControlServlet.java @@ -0,0 +1,44 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.security.secform; + +import java.io.IOException; + +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class ControlServlet extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + // Using RequestDispatcher's forward() method the request to + // to ControlServlet is forwarded to ForwardedServlet + String path = "/ForwardedServlet"; + RequestDispatcher requestDispatcher = getServletContext() + .getRequestDispatcher(path); + requestDispatcher.forward(request, response); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/ForwardedServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/ForwardedServlet.java new file mode 100644 index 0000000000..f4ace6f0a9 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/ForwardedServlet.java @@ -0,0 +1,63 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.security.secform; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class ForwardedServlet extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter out = response.getWriter(); + response.setContentType("text/html"); + + // HttpSession session = request.getSession(true); + // session.setAttribute("ForwardedServletAttribute", "100"); + // out.println("HttpSession Id :"+ session.getId()); + + // Note: The request to ControlServlet was already forwarded + // to ForwardedServlet + out.println("\n\nContents From ForwardedServlet"); + out.println("Using RequestDispatcher's forward() method the request " + + "for ControlServlet was forwarded to ForwardedServlet"); + out.println("From ForwardedServlet: getRemoteUser(): " + + request.getRemoteUser() + "
"); + out.println("From ForwardedServlet: isUserInRole(\"Administrator\"): !" + + request.isUserInRole("Administrator") + "!
"); + + // Include "IncludedServlet" through request dispatcher's include() method + out.println("\nIncluding the responses from IncludedServlet \n"); + + String path = "/IncludedServlet"; + RequestDispatcher requestDispatcher = getServletContext() + .getRequestDispatcher(path); + requestDispatcher.include(request, response); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/GuestPageAnnoTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/GuestPageAnnoTestServlet.java new file mode 100644 index 0000000000..43f8145334 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/GuestPageAnnoTestServlet.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2012, 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 + */ + +package com.sun.ts.tests.servlet.spec.security.secform; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.annotation.security.DeclareRoles; +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.HttpConstraint; +import jakarta.servlet.annotation.ServletSecurity; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + + +/* + * This servlet is the annotation based equivalent of GuestPageTestServlet. + * As such this declares roles, and specifies that the GET and POST methods + * can be accessed by all of the declared roles. + * + * This annotation based version of GuestPageTestServlet varies a bit from + * it because GuestPageTestServlet specifies that GET and POST can be accessed + * by "Administrator", "Manager", "VP" *but* all other http methods + * are left unprotected and so can be accessed by anyone. + * This servlet specifies that *all* http methods can be accessed by + * "Administrator", "Manager", "Employee" (including GET and POST) and NO + * http methods are left unprotected. Thus, this servlet is trying to + * be more secure yet it still leaves GET & POST accessible to all declared + * roles just as is done with GuestPageTestServlet. + * + */ +@DeclareRoles({ "Administrator", "Manager", "Employee", "VP" }) +@ServletSecurity(@HttpConstraint(rolesAllowed = { "Administrator", "Manager", + "VP" })) +@WebServlet(name = "GuestPageAnnoTest", urlPatterns = { "/GuestPageAnnoTest" }) +public class GuestPageAnnoTestServlet extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + PrintWriter out = response.getWriter(); + out.println("The user principal is: " + request.getUserPrincipal().getName() + + "
"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/GuestPageTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/GuestPageTestServlet.java new file mode 100644 index 0000000000..09604a2ddf --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/GuestPageTestServlet.java @@ -0,0 +1,41 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.security.secform; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class GuestPageTestServlet extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter out = response.getWriter(); + out.println("The user principal is: " + request.getUserPrincipal().getName() + + "
"); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/IncludedServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/IncludedServlet.java new file mode 100644 index 0000000000..d0f6da86d5 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/IncludedServlet.java @@ -0,0 +1,63 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.security.secform; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class IncludedServlet extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter out = response.getWriter(); + response.setContentType("text/html"); + + out.println("Contents from IncludedServlet"); + + out.println("From IncludedServlet: getRemoteUser(): " + + request.getRemoteUser() + "
"); + + out.println("From IncludedServlet: isUserInRole(\"Administrator\"): !" + + request.isUserInRole("Administrator") + "!
"); + + // String forwardedServletAttribute=null; + // HttpSession session = request.getSession(true); + // out.println("HttpSession Id :"+ session.getId()); + + // forwardedServletAttribute = + // (String)session.getAttribute("ForwardedServletAttribute"); + // out.println("Attributes set from Forwarded Servlet: "+ + // forwardedServletAttribute); + + // if(forwardedServletAttribute!=null) + // out.println("HttpSession object attributes are shared between contexts"); + + out.flush(); + out.close(); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/OneTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/OneTestServlet.java new file mode 100644 index 0000000000..97745cdccb --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/OneTestServlet.java @@ -0,0 +1,45 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.security.secform; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class OneTestServlet extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter out = response.getWriter(); + out.println("This page can be accessed by the following URLs" + "
"); + out.println("http://hostname:port/jsp_secform/One.jsp" + "
"); + out.println("http://hostname:port/jsp_secform/On*" + "
"); + out.println("http://hostname:port/jsp_secform/One/index.html" + "
"); + out.println("http://hostname:port/jsp_secform/One/*" + "
"); + out.println("
"); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/README b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/README new file mode 100644 index 0000000000..b8a4f8e66c --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/README @@ -0,0 +1,16 @@ +The security tests for both JSP and servlet performs the same functionality. + +So the common code between JSP and servlet is kept under + + TS_HOME/com/sun/ts/tests/common/jspservletsec/secbasicClient.java + TS_HOME/com/sun/ts/tests/common/jspservletsec/secformClient.java + +And they are extended and used under + + TS_HOME/com/sun/ts/tests/jsp/sec/secbasic/Client.java (JSP) + TS_HOME/com/sun/ts/tests/servlet/sec/secbasic/Client.java (Servlet) + + TS_HOME/com/sun/ts/tests/jsp/sec/secform/Client.java (JSP) + TS_HOME/com/sun/ts/tests/servlet/sec/secform/Client.java (Servlet) + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/RoleReverseAnnoTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/RoleReverseAnnoTestServlet.java new file mode 100644 index 0000000000..29ee955813 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/RoleReverseAnnoTestServlet.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2012, 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 + */ + +package com.sun.ts.tests.servlet.spec.security.secform; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.annotation.security.DeclareRoles; +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.HttpConstraint; +import jakarta.servlet.annotation.HttpMethodConstraint; +import jakarta.servlet.annotation.ServletSecurity; +import jakarta.servlet.annotation.ServletSecurity.EmptyRoleSemantic; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +/* + * This should require employee role perms to access the Get or Post + * methods. This should be an equivelent to RoleReverseTest with the + * main difference being that this uses Servlet based annotations whereas + * RoleReverseTest uses DD for configuring its security constraints. + * It is worth noting that all methods (besides GET and POST) do NOT + * have a deny security constraint on them and so are protected and the + * only allowed Http method access is to Get & POST which requires + * you to be an employee role.. + * + */ + +@DeclareRoles({ "Administrator", "Manager", "VP", "Employee" }) +@ServletSecurity(value = @HttpConstraint(EmptyRoleSemantic.DENY), httpMethodConstraints = { + @HttpMethodConstraint(value = "GET", rolesAllowed = "Employee"), + @HttpMethodConstraint(value = "POST", rolesAllowed = "Employee") }) +@WebServlet(name = "RoleReverseAnnoTestLogicalName", urlPatterns = { + "/RoleReverseAnnoTest" }) +public class RoleReverseAnnoTestServlet extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter out = response.getWriter(); + out.println("The user principal is: " + request.getUserPrincipal().getName() + + "
"); + + // Output whether the user is in any of the known or an unknown role. + // Surround these with !'s so they are easier to search for. + // (i.e. we can search for !true! or !false!) + out.println( + "isUserInRole(\"ADM\"): !" + request.isUserInRole("ADM") + "!
"); + out.println( + "isUserInRole(\"MGR\"): !" + request.isUserInRole("MGR") + "!
"); + out.println( + "isUserInRole(\"VP\"): !" + request.isUserInRole("VP") + "!
"); + out.println( + "isUserInRole(\"EMP\"): !" + request.isUserInRole("EMP") + "!
"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/RoleReverseTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/RoleReverseTestServlet.java new file mode 100644 index 0000000000..7f6afab63d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/RoleReverseTestServlet.java @@ -0,0 +1,51 @@ +/* + * 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$ + */ +package com.sun.ts.tests.servlet.spec.security.secform; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class RoleReverseTestServlet extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter out = response.getWriter(); + out.println("The user principal is: " + request.getUserPrincipal().getName() + + "
"); + + // Output whether the user is in any of the known or an unknown role. + // Surround these with !'s so they are easier to search for. + // (i.e. we can search for !true! or !false!) + out.println( + "isUserInRole(\"ADM\"): !" + request.isUserInRole("ADM") + "!
"); + out.println( + "isUserInRole(\"MGR\"): !" + request.isUserInRole("MGR") + "!
"); + out.println( + "isUserInRole(\"VP\"): !" + request.isUserInRole("VP") + "!
"); + out.println( + "isUserInRole(\"EMP\"): !" + request.isUserInRole("EMP") + "!
"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/SampleTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/SampleTestServlet.java new file mode 100644 index 0000000000..11deee9f25 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/SampleTestServlet.java @@ -0,0 +1,64 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.security.secform; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.HttpConstraint; +import jakarta.servlet.annotation.ServletSecurity; +import jakarta.servlet.annotation.ServletSecurity.EmptyRoleSemantic; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +/* + * We have an annotation here that is trying to disable access to + * all HTTP methods. Normally, this would work *EXCEPT* for in this + * case, the DD file declares something completely different for the + * exact same context, and the DD overrides annotations in case of + * duplicate contexts. Do this annotation should be ignored and + * any attempts to access SampleTest must adhere to the DD definitions. + * + */ +@ServletSecurity(@HttpConstraint(EmptyRoleSemantic.DENY)) +@WebServlet(name = "SampleTestServletLogicalName", urlPatterns = { + "/SampleTest" }) +public class SampleTestServlet extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter out = response.getWriter(); + + out.println("The user principal is: " + request.getUserPrincipal().getName() + + "
"); + out.println("getRemoteUser(): " + request.getRemoteUser() + "
"); + + out.println("isUserInRole(\"Administrator\"): !" + + request.isUserInRole("Administrator") + "!
"); + + out.println("HTTP method " + request.getMethod() + " invoked"); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/ServletProgrammaticAuthen.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/ServletProgrammaticAuthen.java new file mode 100644 index 0000000000..47a0ad8179 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/ServletProgrammaticAuthen.java @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2012, 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 + */ + +package com.sun.ts.tests.servlet.spec.security.secform; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +/* + * This servlet will be used by test18. The output from this servlet will + * get parsed from within secformClient.java (in method test18). Changing + * the output statements in here could affect the test output so dont change + * the output statements unless you need to. + * + * This is testing that the HttpServletRequest.authenticate() method behaves correctly + * and that other Servlet Security methods from HttpServletRequest also behave + * according to the spec and javadoc. + * + */ +public class ServletProgrammaticAuthen extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter out = response.getWriter(); + + out.println("enterred ServletProgrammaticAuthen.service()"); + System.out.println("enterred ServletProgrammaticAuthen.service()"); + + // get user creds that are set in secformClient.test16() + String the_username = request.getParameter("the_username"); + String the_password = request.getParameter("the_password"); + + // we are not yet logged in nor authenticated so at this point calls + // to getRemoteUser(), getUserPrincipal(), and getAuthType() + // MUST return null (per Servlet 3.1 speec (section 13.3). + if ((request.getRemoteUser() != null) + || (request.getUserPrincipal() != null) + || (request.getAuthType() != null)) { + String str = "ERROR - HttpServletRequest.login() test failure. "; + str += "We did not get null for the following calls: "; + str += " getRemoteUser(), getUserPrincipal(), getAuthType()"; + sendOutput(str, out); + } + + // note: was planning to invoke request.authenticate(response) here to + // validate it returns false but we ended up getting redirected to + // login.jsp so not doing this. Spec is not clear here so omit. + + try { + request.login(the_username, the_password); + + // per javadoc, if login() worked with no exception then there must + // be non-null values for getUserPrincipal, getRemoteUser, and + // getAuthType. + if ((request.getRemoteUser() == null) + || (request.getUserPrincipal() == null) + || (request.getAuthType() == null)) { + sendOutput("ERROR - HttpServletRequest.login() failed", out); + sendOutput("request.getRemoteUser() = " + request.getRemoteUser(), out); + sendOutput("request.getUserPrincipal() = " + request.getUserPrincipal(), + out); + sendOutput("request.getRemoteUser() = " + request.getRemoteUser(), out); + } else { + sendOutput("request.getRemoteUser()=" + request.getRemoteUser(), out); + } + } catch (ServletException e) { + // per javadoc - if here, login failed. + sendOutput("ERROR - HttpServletRequest.login() failed", out); + } + + try { + // a call to authenticate should return true since we should be + // authenticated now + if (request.authenticate(response) != true) { + // Error - this should have returned true + sendOutput("ERROR - HttpServletRequest.authenticate failed.", out); + sendOutput( + "authenticate should have returned true since we are authenticated.", + out); + } else { + sendOutput("HttpServletRequest.authenticate passed.", out); + } + + request.logout(); // some cleanup + } catch (Exception ex) { + sendOutput("Exception calling authenticate()", out); + ex.printStackTrace(); + } + + } + + public void sendOutput(String str, PrintWriter out) { + String HDR = "ServletProgrammaticAuthen: "; + out.println(HDR + str); // this line is used for test validation + System.out.println(HDR + str); // this line is for debug aid + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/ServletProgrammaticLogin.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/ServletProgrammaticLogin.java new file mode 100644 index 0000000000..60fbfc3cfb --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/ServletProgrammaticLogin.java @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2012, 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: ServletProgrammaticLogin.java 62571 2011-04-18 20:58:13Z kgrucci $ + */ + +package com.sun.ts.tests.servlet.spec.security.secform; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +/* + * This servlet will be used by test16. The output from this servlet will + * get parsed from within secformClient.java (in method test16). Changing + * the output statements in here could affect the test output so dont unless + * you need to. + * + * This is testing that the HttpServletRequest.login() method behaves correctly + * and that other Servlet Security methods from HttpServletRequest also behave + * according to the spec and javadoc. + * + */ +public class ServletProgrammaticLogin extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter out = response.getWriter(); + + out.println("enterred ServletProgrammaticLogin.service()"); + System.out.println("enterred ServletProgrammaticLogin.service()"); + + // get user creds that are set in secformClient.test16() + String the_username = request.getParameter("the_username"); + String the_password = request.getParameter("the_password"); + + // we are not yet authenticated so at this point a call to getRemoteUser() + // MUST return null (per Servlet 3.1 speec (section 13.3). + if ((request.getRemoteUser() != null) + || (request.getUserPrincipal() != null) + || (request.getAuthType() != null)) { + String str = "ERROR - HttpServletRequest.login() test failure. "; + str += "We did not get null for the following calls: "; + str += " getRemoteUser(), getUserPrincipal(), getAuthType()"; + sendOutput(str, out); + } + + try { + request.login(the_username, the_password); + + // per javadoc, if login() worked with no exception then there must + // be non-null values for getUserPrincipal, getRemoteUser, and + // getAuthType. + if ((request.getRemoteUser() == null) + || (request.getUserPrincipal() == null) + || (request.getAuthType() == null)) { + sendOutput("ERROR - HttpServletRequest.login() failed", out); + sendOutput("request.getRemoteUser() = " + request.getRemoteUser(), out); + sendOutput("request.getUserPrincipal() = " + request.getUserPrincipal(), + out); + sendOutput("request.getRemoteUser() = " + request.getRemoteUser(), out); + } else { + sendOutput("request.getRemoteUser()=" + request.getRemoteUser(), out); + } + } catch (ServletException e) { + // per javadoc - if here, login failed. + sendOutput("ERROR - HttpServletRequest.login() failed", out); + } + + sendOutput("HttpServletRequest.login() passed", out); + } + + public void sendOutput(String str, PrintWriter out) { + String HDR = "ServletProgrammaticLogin: "; + out.println(HDR + str); // this line is used for test validation + System.out.println(HDR + str); // this line is for debug aid + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/ServletProgrammaticLogout.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/ServletProgrammaticLogout.java new file mode 100644 index 0000000000..dcca51b188 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/ServletProgrammaticLogout.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2012, 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: ServletProgrammaticLogout.java 62571 2011-04-18 20:58:13Z kgrucci $ + */ + +package com.sun.ts.tests.servlet.spec.security.secform; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +/* + * This servlet will be used by test17. The output from this servlet will + * get parsed from within secformClient.java (in method test17). Changing + * the output statements in here could affect the test output so dont unless + * you need to. + * + * This is testing that the HttpServletRequest.logout() method behaves correctly + * and that other Servlet Security methods from HttpServletRequest also behave + * according to the spec and javadoc. + * + * This servlet assumes that there has been successful authentication upon + * entry into here. After which, the logout() feature will be validated. + * + */ +public class ServletProgrammaticLogout extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter out = response.getWriter(); + + out.println("enterred ServletProgrammaticLogout.service()"); + System.out.println("enterred ServletProgrammaticLogout.service()"); + + // we should be authenticated at this point so a call to getRemoteUser(), + // getUserPrincipal(), and getAuthType() MUST NOT return null value + // (per Servlet 3.1 speec (section 13.3). + if ((request.getRemoteUser() == null) + || (request.getUserPrincipal() == null) + || (request.getAuthType() == null)) { + String str = "ERROR - HttpServletRequest.logout() - we got null for the following calls: "; + str += " getRemoteUser(), getUserPrincipal(), getAuthType()"; + sendOutput(str, out); + + // debug aid + sendOutput("request.getRemoteUser() = " + request.getRemoteUser(), out); + sendOutput("request.getUserPrincipal() = " + request.getUserPrincipal(), + out); + sendOutput("request.getRemoteUser() = " + request.getRemoteUser(), out); + } + + try { + request.logout(); + + // per javadoc, if logout() worked with no exception then there must + // be null values for getUserPrincipal, getRemoteUser, and getAuthType. + if ((request.getRemoteUser() != null) + || (request.getUserPrincipal() != null) + || (request.getAuthType() != null)) { + sendOutput("ERROR - HttpServletRequest.logout() failed", out); + + // debug aid + sendOutput("request.getRemoteUser() = " + request.getRemoteUser(), out); + sendOutput("request.getUserPrincipal() = " + request.getUserPrincipal(), + out); + sendOutput("request.getRemoteUser() = " + request.getRemoteUser(), out); + } else { + sendOutput("request.getRemoteUser()=" + request.getRemoteUser(), out); + } + } catch (ServletException e) { + sendOutput("ERROR - HttpServletRequest.logout() failed", out); + } + + } + + public void sendOutput(String str, PrintWriter out) { + String HDR = "ServletProgrammaticLogout: "; + out.println(HDR + str); // this line is used for test validation + System.out.println(HDR + str); // this line is for debug aid + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/ServletSecAnnoTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/ServletSecAnnoTestServlet.java new file mode 100644 index 0000000000..751357b3fa --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/ServletSecAnnoTestServlet.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2012, 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 + */ + +package com.sun.ts.tests.servlet.spec.security.secform; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.annotation.security.DeclareRoles; +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.HttpConstraint; +import jakarta.servlet.annotation.HttpMethodConstraint; +import jakarta.servlet.annotation.ServletSecurity; +import jakarta.servlet.annotation.ServletSecurity.EmptyRoleSemantic; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +/* + * This should allow the Aministrator role perms to access any of the servlet + * methods. This is an annotation based equivalent of ServletSecTestServlet + * with the main difference being that this uses Servlet based annotations whereas + * ServletSecTestServlet uses DD for configuring its security constraints. + */ + +@DeclareRoles({ "ADM", "MGR", "EMP" }) +@ServletSecurity(value = @HttpConstraint(EmptyRoleSemantic.DENY), httpMethodConstraints = { + @HttpMethodConstraint(value = "GET", rolesAllowed = "Administrator"), + @HttpMethodConstraint(value = "POST", rolesAllowed = "Administrator") }) +@WebServlet(name = "ServletSecAnnoTestLogicalName", urlPatterns = { + "/ServletSecAnnoTest" }) +public class ServletSecAnnoTestServlet extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter out = response.getWriter(); + + System.out.println("Inside ServletSecAnnoTestServlet ....." + "
"); + System.out.println("The user principal is: " + + request.getUserPrincipal().getName() + "
"); + System.err.println("The user principal is: " + + request.getUserPrincipal().getName() + "
"); + + out.println("The user principal is: " + request.getUserPrincipal().getName() + + "
"); + out.println("getRemoteUser(): " + request.getRemoteUser() + "
"); + + out.println("Inside ServletSecAnnoTestServlet ....." + "
"); // used for + // validating + // test7 + + // Surround these with !'s so they are easier to search for. + // (i.e. we can search for !true! or !false!) + out.println( + "isUserInRole(\"ADM\"): !" + request.isUserInRole("ADM") + "!
"); + out.println( + "isUserInRole(\"MGR\"): !" + request.isUserInRole("MGR") + "!
"); + out.println( + "isUserInRole(\"VP\"): !" + request.isUserInRole("VP") + "!
"); + out.println( + "isUserInRole(\"EMP\"): !" + request.isUserInRole("EMP") + "!
"); + out.println("isUserInRole(\"Administrator\"): !" + + request.isUserInRole("Administrator") + "!
"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/ServletSecTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/ServletSecTestServlet.java new file mode 100644 index 0000000000..fb15b5d2a1 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/ServletSecTestServlet.java @@ -0,0 +1,57 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.security.secform; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class ServletSecTestServlet extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter out = response.getWriter(); + + out.println("The user principal is: " + request.getUserPrincipal().getName() + + "
"); + out.println("getRemoteUser(): " + request.getRemoteUser() + "
"); + out.println("getAuthType(): " + request.getAuthType() + "
"); + + // Surround these with !'s so they are easier to search for. + // (i.e. we can search for !true! or !false!) + out.println( + "isUserInRole(\"ADM\"): !" + request.isUserInRole("ADM") + "!
"); + out.println( + "isUserInRole(\"MGR\"): !" + request.isUserInRole("MGR") + "!
"); + out.println( + "isUserInRole(\"VP\"): !" + request.isUserInRole("VP") + "!
"); + out.println( + "isUserInRole(\"EMP\"): !" + request.isUserInRole("EMP") + "!
"); + out.println("isUserInRole(\"Administrator\"): !" + + request.isUserInRole("Administrator") + "!
"); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/TwoTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/TwoTestServlet.java new file mode 100644 index 0000000000..a9ebb7140e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/TwoTestServlet.java @@ -0,0 +1,44 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.security.secform; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class TwoTestServlet extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter out = response.getWriter(); + out.println("This page can be accessed by the following URLs" + "
"); + out.println("http://hostname:port/jsp_secform/Two.jsp" + "
"); + out.println("http://hostname:port/jsp_secform/*.jsp" + "
"); + out.println("http://hostname:port/jsp_secform/*.two" + "
"); + out.println("
"); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/UnProtectedAnnoTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/UnProtectedAnnoTestServlet.java new file mode 100644 index 0000000000..3d9a140645 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/UnProtectedAnnoTestServlet.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2012, 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 + */ + +package com.sun.ts.tests.servlet.spec.security.secform; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.annotation.security.DeclareRoles; +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.HttpConstraint; +import jakarta.servlet.annotation.ServletSecurity; +import jakarta.servlet.annotation.ServletSecurity.TransportGuarantee; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +/* + * This servlet is the annotation based equivalent of UnProtectedTestServlet. + * As such, this declares roles but sets no security constraints and leaves + * the page unprotected. + * + */ +@DeclareRoles({ "Administrator", "Manager", "VP", "Employee" }) +@ServletSecurity(@HttpConstraint(transportGuarantee = TransportGuarantee.NONE)) +@WebServlet(urlPatterns = { "/UnProtectedAnnoTest" }) +public class UnProtectedAnnoTestServlet extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter out = response.getWriter(); + if (request.getUserPrincipal() == null) + out.println( + "The user principal is: " + request.getUserPrincipal() + "
"); + else + out.println("The user principal is: " + + request.getUserPrincipal().getName() + "
"); + + // Output whether the user is in any of the known or an unknown role. + // Surround these with !'s so they are easier to search for. + // (i.e. we can search for !true! or !false!) + out.println( + "isUserInRole(\"ADM\"): !" + request.isUserInRole("ADM") + "!
"); + out.println( + "isUserInRole(\"MGR\"): !" + request.isUserInRole("MGR") + "!
"); + out.println( + "isUserInRole(\"VP\"): !" + request.isUserInRole("VP") + "!
"); + out.println( + "isUserInRole(\"EMP\"): !" + request.isUserInRole("EMP") + "!
"); + + // Test getRemoteUser() functionality: + out.println("
"); + out.println("getRemoteUser(): " + request.getRemoteUser()); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/UnProtectedTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/UnProtectedTestServlet.java new file mode 100644 index 0000000000..0267b80fe6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/UnProtectedTestServlet.java @@ -0,0 +1,61 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.security.secform; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class UnProtectedTestServlet extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter out = response.getWriter(); + if (request.getUserPrincipal() == null) + out.println( + "The user principal is: " + request.getUserPrincipal() + "
"); + else + out.println("The user principal is: " + + request.getUserPrincipal().getName() + "
"); + + // Output whether the user is in any of the known or an unknown role. + // Surround these with !'s so they are easier to search for. + // (i.e. we can search for !true! or !false!) + out.println( + "isUserInRole(\"ADM\"): !" + request.isUserInRole("ADM") + "!
"); + out.println( + "isUserInRole(\"MGR\"): !" + request.isUserInRole("MGR") + "!
"); + out.println( + "isUserInRole(\"VP\"): !" + request.isUserInRole("VP") + "!
"); + out.println( + "isUserInRole(\"EMP\"): !" + request.isUserInRole("EMP") + "!
"); + + // Test getRemoteUser() functionality: + out.println("
"); + out.println("getRemoteUser(): " + request.getRemoteUser()); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/allRolesTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/allRolesTestServlet.java new file mode 100644 index 0000000000..f73b1dcf0d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/allRolesTestServlet.java @@ -0,0 +1,54 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.security.secform; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class allRolesTestServlet extends HttpServlet { + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + PrintWriter out = response.getWriter(); + + out.println("The user principal is: " + request.getUserPrincipal().getName() + + "
"); + + // Output whether the user is in any of the known or an unknown role. + // Surround these with !'s so they are easier to search for. + // (i.e. we can search for !true! or !false!) + out.println( + "isUserInRole(\"ADM\"): !" + request.isUserInRole("ADM") + "!
"); + out.println( + "isUserInRole(\"MGR\"): !" + request.isUserInRole("MGR") + "!
"); + out.println( + "isUserInRole(\"VP\"): !" + request.isUserInRole("VP") + "!
"); + out.println( + "isUserInRole(\"EMP\"): !" + request.isUserInRole("EMP") + "!
"); + + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/build.xml new file mode 100644 index 0000000000..c68cc93560 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/build.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/servlet_sec_secform.ear.sun-application.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/servlet_sec_secform.ear.sun-application.xml new file mode 100644 index 0000000000..6dd03e9865 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/servlet_sec_secform.ear.sun-application.xml @@ -0,0 +1,40 @@ + + + + + + + servlet_sec_secform_web.war + servlet_sec_secform_web + + 0 + + Administrator + j2ee + + + Manager + javajoe + + + Employee + javajoe + j2ee + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/servlet_sec_secform_web.war.sun-web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/servlet_sec_secform_web.war.sun-web.xml new file mode 100644 index 0000000000..e55d9a5ef8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/servlet_sec_secform_web.war.sun-web.xml @@ -0,0 +1,36 @@ + + + + + + /servlet_sec_secform_web + + Administrator + j2ee + + + Manager + javajoe + + + Employee + javajoe + j2ee + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/servlet_sec_secform_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/servlet_sec_secform_web.xml new file mode 100644 index 0000000000..bbca9ca6b8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/security/secform/servlet_sec_secform_web.xml @@ -0,0 +1,511 @@ + + + + + servlet_sec_secform + + ControlServletLogicalName + com.sun.ts.tests.servlet.spec.security.secform.ControlServlet + + + Login + /login.jsp + + ADM + Administrator + + + MGR + Manager + + + VP + VP + + + EMP + Employee + + + + RoleReverseAnnoTestLogicalName + com.sun.ts.tests.servlet.spec.security.secform.RoleReverseAnnoTestServlet + + MGR + Administrator + + + ADM + Manager + + + VP + VP + + + EMP + Employee + + + + RoleReverseTestLogicalName + com.sun.ts.tests.servlet.spec.security.secform.RoleReverseTestServlet + + MGR + Administrator + + + ADM + Manager + + + VP + VP + + + EMP + Employee + + + + ServletSecAnnoTestLogicalName + com.sun.ts.tests.servlet.spec.security.secform.ServletSecAnnoTestServlet + + ADM + Administrator + + + MGR + Manager + + + VP + VP + + + EMP + Employee + + + + TwoTestServletLogicalName + com.sun.ts.tests.servlet.spec.security.secform.TwoTestServlet + + + GuestPageTestLogicalName + com.sun.ts.tests.servlet.spec.security.secform.GuestPageTestServlet + + ADM + Administrator + + + MGR + Manager + + + VP + VP + + + EMP + Employee + + + + ForwardedServletLogicalName + com.sun.ts.tests.servlet.spec.security.secform.ForwardedServlet + + + SampleTestServletLogicalName + com.sun.ts.tests.servlet.spec.security.secform.SampleTestServlet + + + ServletSecTestLogicalName + com.sun.ts.tests.servlet.spec.security.secform.ServletSecTestServlet + + ADM + Administrator + + + MGR + Manager + + + VP + VP + + + EMP + Employee + + + + allRolesTestServletLogicalName + com.sun.ts.tests.servlet.spec.security.secform.allRolesTestServlet + + + error + /error.jsp + + ADM + Administrator + + + MGR + Manager + + + VP + VP + + + EMP + Employee + + + + UnProtectedTestLogicalName + com.sun.ts.tests.servlet.spec.security.secform.UnProtectedTestServlet + + ADM + Administrator + + + MGR + Manager + + + VP + VP + + + EMP + Employee + + + + ServletProgrammaticLoginLogicalName + com.sun.ts.tests.servlet.spec.security.secform.ServletProgrammaticLogin + + ADM + Administrator + + + MGR + Manager + + + VP + VP + + + EMP + Employee + + + + ServletProgrammaticLogoutLogicalName + com.sun.ts.tests.servlet.spec.security.secform.ServletProgrammaticLogout + + ADM + Administrator + + + MGR + Manager + + + VP + VP + + + EMP + Employee + + + + ServletProgrammaticAuthenLogicalName + com.sun.ts.tests.servlet.spec.security.secform.ServletProgrammaticAuthen + + ADM + Administrator + + + MGR + Manager + + + VP + VP + + + EMP + Employee + + + + IncludedServletLogicalName + com.sun.ts.tests.servlet.spec.security.secform.IncludedServlet + + + OneTestServletLogicalName + com.sun.ts.tests.servlet.spec.security.secform.OneTestServlet + + + ControlServletLogicalName + /ControlServlet + + + Login + /login.jsp + + + RoleReverseTestLogicalName + /RoleReverseTest + + + TwoTestServletLogicalName + /TwoTest + + + TwoTestServletLogicalName + *.jsp + + + TwoTestServletLogicalName + *.two + + + GuestPageTestLogicalName + /GuestPageTest + + + ForwardedServletLogicalName + /ForwardedServlet + + + SampleTestServletLogicalName + /SampleTest + + + ServletSecTestLogicalName + /ServletSecTest + + + allRolesTestServletLogicalName + /allRolesTest + + + error + /error.jsp + + + UnProtectedTestLogicalName + /UnProtectedTest + + + ServletProgrammaticLoginLogicalName + /ServletProgrammaticLogin + + + ServletProgrammaticLogoutLogicalName + /ServletProgrammaticLogout + + + ServletProgrammaticAuthenLogicalName + /ServletProgrammaticAuthen + + + IncludedServletLogicalName + /IncludedServlet + + + OneTestServletLogicalName + /OneTest + + + OneTestServletLogicalName + /On* + + + OneTestServletLogicalName + /One/index.html + + + OneTestServletLogicalName + /One/* + + + 54 + + + + MySecureBit0 + /login.jsp + GET + POST + + + NONE + + + + + MySecureBit4 + /SampleTest + + + Administrator + + + NONE + + + + + MySecureBit9 + /IncludedServlet + + + + NONE + + + + + MySecureBit6 + /allRolesTest + + + Administrator + * + + + NONE + + + + + MySecureBit8 + /ForwardedServlet + + + + NONE + + + + + MySecureBit2 + /GuestPageTest + GET + POST + + + Administrator + Manager + VP + + + NONE + + + + + MySecureBit7 + /ControlServlet + + + Administrator + + + NONE + + + + + MySecureBit3 + /RoleReverseTest + GET + POST + + + Employee + + + NONE + + + + + MySecureBit1 + /ServletSecTest + GET + POST + + + Administrator + + + NONE + + + + + MySecureBit10 + /ServletProgrammaticLogout + GET + POST + + + Administrator + + + NONE + + + + FORM + default + + /login.jsp + /error.jsp + + + + the administrator role + Administrator + + + the manager role + Manager + + + the VP role + VP + + + the employee role + Employee + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/serverpush/Client.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/serverpush/Client.java new file mode 100644 index 0000000000..1d5e56854d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/serverpush/Client.java @@ -0,0 +1,551 @@ +/* + * Copyright (c) 2017, 2022 Oracle and/or its affiliates and others. + * 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 + */ + +package com.sun.ts.tests.servlet.spec.serverpush; + +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.lib.util.WebUtil; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.net.Authenticator; +import java.net.CookieManager; +import java.net.CookiePolicy; +import java.net.HttpCookie; +import java.net.InetAddress; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.util.Arrays; +import java.util.Base64; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.StringTokenizer; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import java.util.function.Function; +import java.util.stream.Collectors; + +public class Client extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_spec_serverpush_web.war") + .addAsWebResource("spec/serverpush/index.html") + .addClasses(TestServlet.class, TestServlet2.class, TestServlet3.class, TestServlet4.class, + TestServlet5.class, TestServlet6.class, TestServlet7.class) + .setWebXML(Client.class.getResource("servlet_spec_serverpush_web.xml")); + } + + private String requestURI = null; + + private String hostname; + + private int portnum; + + private WebUtil.Response response = null; + + private String authUsername = "javajoe"; + + private String authPassword = "javajoe"; + + private CookieManager cm = new CookieManager(); + + /* + * @class.setup_props: webServerHost; webServerPort; authuser; authpassword; + * + */ + // TOFIX + public void setup(String[] args, Properties p) throws Exception { + + authUsername = p.getProperty(UNAUTH_USERNAME); + authPassword = p.getProperty(UNAUTH_PASSWORD); + hostname = p.getProperty(SERVLETHOSTPROP); + portnum = Integer.parseInt(p.getProperty(SERVLETPORTPROP)); + + logger.debug("hostname:port:{}:{}", hostname, portnum); + } + + /* + * @testName: serverPushTest + * + * @assertion_ids: N/A; + * + * @test_Strategy: Verify server push can work correctly. + */ + @Test + public void serverPushTest() throws Exception { + requestURI = "http://" + hostname + ":" + portnum + getContextRoot() + + "/TestServlet"; + Map headers = new HashMap<>(); + headers.put("foo", "bar"); + List> responses = sendRequest(headers, null, null); + verifyResponses(responses, new String[] { "hello", "INDEX from index.html" }); + } + + /* + * @testName: getNullPushBuilderTest + * + * @assertion_ids: N/A; + * + * @test_Strategy: Verify the returned PushBuilder Object is null if the + * current connection does not support server push. + */ + @Test + public void getNullPushBuilderTest() throws Exception { + try { + requestURI = getContextRoot() + "/TestServlet"; + TestUtil.logMsg("Sending request \"" + requestURI + "\""); + + response = WebUtil.sendRequest("GET", InetAddress.getByName(hostname), + portnum, getRequest(requestURI), null, null); + + logger.debug("response.statusToken: {}", response.statusToken); + logger.debug("response.content: {}", response.content); + + // Check that the page was found (no error). + if (response.isError()) { + logger.error("Could not find {}", requestURI); + throw new Exception("getNullPushBuilderTest failed."); + } + + if (!response.content.contains("Get Null PushBuilder")) { + throw new Exception("getNullPushBuilderTest failed."); + } + } catch (Exception e) { + logger.error("Caught exception: " + e.getMessage(), e); + throw new Exception("getNullPushBuilderTest failed: ", e); + } + } + + /* + * @testName: serverPushInitTest + * + * @assertion_ids: N/A; + * + * @test_Strategy: Verify PushBuilder is initialized correctly. + */ + @Test + public void serverPushInitTest() throws Exception { + requestURI = "http://" + hostname + ":" + portnum + getContextRoot() + + "/TestServlet2"; + Map headers = new HashMap<>(); + headers.put("foo", "bar"); + headers.put("If-Match", "*"); + headers.put("Range", "bytes=100-"); + + String authString = "Basic " + new String(Base64.getEncoder().encode((authUsername + ":" + authPassword).getBytes())); + + logger.debug("auth string: {}", authString); + + CookieManager cm = new CookieManager(); + headers.put("Authorization", authString); + headers.put("Referer", requestURI + "/test"); + + List> responses = sendRequest(headers, null, cm); + if (responses.size() != 1) { + throw new Exception("Test fail"); + } + String sessionid = responses.get(0) + .headers() + .allValues("set-cookie") + .stream() + .filter(value -> value.contains("JSESSIONID=")) + .findFirst() + .orElse(null); + + if (sessionid == null) { + throw new Exception("Test fail: new session ID should be used as the PushBuilder's session ID."); + } + + sessionid = sessionid + .substring(sessionid.indexOf("JSESSIONID=") + "JSESSIONID=".length()); + if (sessionid.indexOf(";") > 0) { + sessionid = sessionid.substring(0, sessionid.indexOf(";")); + } else if (sessionid.indexOf(".") > 0) { + sessionid = sessionid.substring(0, sessionid.indexOf(".")); + } + + logger.debug("Sessionid in cookie: {}", sessionid); + + String response = responses.get(0).body(); + + StringTokenizer token = new StringTokenizer(response, "\n"); + String newSessionId = ""; + while (token.hasMoreTokens()) { + String tmp = token.nextToken(); + if (tmp.startsWith("JSESSIONID:")) { + newSessionId = tmp.substring("JSESSIONID:".length()).trim(); + break; + } + } + + if (!sessionid.contains(newSessionId) && !newSessionId.contains(sessionid)) { + throw new Exception("Test fail: new session ID should be used as the " + + "PushBuilder's session ID."); + } + + if (!response.contains("Return new instance:true")) { + throw new Exception("Test fail: each call to newPushBuilder() should " + + "create a new instance"); + } + + if (!response.contains("Method:GET")) { + throw new Exception("Test fail: The method of PushBuilder should be " + + "initialized to \"GET\""); + } + + if (!response.contains("foo=bar")) { + throw new Exception("Test fail: The existing request headers of the current " + + "HttpServletRequest should be added to the builder"); + } + + if (response.contains("if-match")) { + throw new Exception( + "Test fail: Conditional headers should NOT be added to the builder"); + } + + if (response.contains("range")) { + throw new Exception( + "Test fail: Range headers should NOT be added to the builder"); + } + + if (!response.contains("authorization")) { + throw new Exception( + "Test fail: Authorization headers should be added to the builder"); + } + + if (!response.contains("referer=" + requestURI)) { + throw new Exception( + "Test fail: Referer headers should be set to " + requestURI); + } + } + + /* + * @testName: serverPushSessionTest + * + * @assertion_ids: N/A; + * + * @test_Strategy: Verify PushBuilder with session works as expected. + */ + @Test + public void serverPushSessionTest() throws Exception { + try { + requestURI = getContextRoot() + "/TestServlet3?generateSession=true"; + logger.debug("Sending request {}", requestURI); + + response = WebUtil.sendRequest("GET", InetAddress.getByName(hostname), + portnum, getRequest(requestURI), null, null); + logger.debug("The new sessionid is : {}", response.content); + + // Check that the page was found (no error). + if (response.isError()) { + logger.error("Could not find {}", requestURI); + throw new Exception("serverPushSessionTest failed."); + } + + requestURI = "http://" + hostname + ":" + portnum + getContextRoot() + + "/TestServlet3;jsessionid=" + response.content.trim(); + logger.debug("Sending request {}", requestURI); + List> responses = sendRequest(new HashMap<>(), null, null); + String responseStr = responses.get(0).body(); + + logger.debug("The test result : {}", responseStr); + if (!responseStr.contains("Test success")) { + throw new Exception("serverPushSessionTest failed."); + } + } catch (Exception e) { + logger.error("Caught exception: " + e.getMessage(), e); + throw new Exception("serverPushSessionTest failed: ", e); + } + } + + /* + * @testName: serverPushCookieTest + * + * @assertion_ids: N/A; + * + * @test_Strategy: Verify PushBuilder with cookie works as expected. + */ + @Test + public void serverPushCookieTest() throws Exception { + requestURI = "http://" + hostname + ":" + portnum + getContextRoot() + + "/TestServlet4"; + Map headers = new HashMap<>(); + headers.put("foo", "bar"); + CookieManager cm = new CookieManager(); + List> responses = sendRequest(headers, null, cm); + verifyResponses(responses, new String[] { "add cookies [foo,bar] [baz,qux] to response", "INDEX from index.html" }); + boolean cookieExisted = false; + String pbCookies = ""; + try { + for (HttpResponse r : responses) { + if (r.body().contains("Cookie header in PushBuilder: ")) { + cookieExisted = true; + pbCookies = r.body().substring(r.body().indexOf("Cookie header in PushBuilder: ")); + break; + } + } + if (!cookieExisted) { + throw new Exception("Wrong Responses"); + } + + if (!pbCookies.contains("foo") || !pbCookies.contains("bar")) { + throw new Exception("The Cookie header 'foo=bar' should be added to the PushBuilder."); + } + + if (pbCookies.contains("baz") || pbCookies.contains("qux")) { + throw new Exception("the maxAge for Cookie 'baz=qux' is <= 0, it should be removed from the builder"); + } + } catch (Exception e) { + logger.error("Caught exception: " + e.getMessage(), e); + throw new Exception("serverPushSessionTest failed: ", e); + } + } + + /* + * @testName: serverPushSessionTest2 + * + * @assertion_ids: N/A; + * + * @test_Strategy: Verify PushBuilder with Session works as expected. + */ + @Test + public void serverPushSessionTest2() throws Exception { + requestURI = "http://" + hostname + ":" + portnum + getContextRoot() + "/TestServlet5"; + Map headers = new HashMap<>(); + CookieManager cm = new CookieManager(); + cm.setCookiePolicy(CookiePolicy.ACCEPT_ALL); + List> responses = sendRequest(headers, null, cm); + boolean pass = false; + + try { + List cookies = cm.getCookieStore().get(new URI( + "http://" + hostname + ":" + portnum + getContextRoot() + "/index.html")); + for (HttpCookie cookie : cookies) { + if ("JSESSIONID".equals(cookie.getName())) { + pass = true; + break; + } + } + + if (!pass) { + for (HttpResponse response : responses) { + if (response.uri().toString().indexOf("index.html;jsessionid") > 0) { + pass = true; + } + } + } + } catch (Exception e) { + TestUtil.logErr("Caught exception: " + e.getMessage()); + e.printStackTrace(); + throw new Exception("serverPushSessionTest failed: ", e); + } + + if (!pass) { + throw new Exception( + "If the builder has a session ID, then the pushed request should " + + "include the session ID either as a Cookie or as a URI parameter as appropriate"); + } + } + + /* + * @testName: serverPushMiscTest + * + * @assertion_ids: N/A; + * + * @test_Strategy: Verify some methods of PushBuilder works as expected. + */ + @Test + public void serverPushMiscTest() throws Exception { + requestURI = "http://" + hostname + ":" + portnum + getContextRoot() + + "/TestServlet6"; + Map headers = new HashMap<>(); + headers.put("foo", "bar"); + headers.put("baz", "qux"); + List> responses = sendRequest(headers, null, null); + HttpResponse pushResp = null; + HttpRequest pushReq = null; + + for (HttpResponse response : responses) { + if (response.uri().toString().contains("index.html")) { + pushResp = response; + pushReq = response.request(); + } + } + + if (pushResp == null) + throw new Exception("can not get push response"); + + logMsg( + "expected header: h1=v1, foo=v2; expected querysting: querystring=1&querystring=2"); + Map> pushHeaders = pushReq.headers().map(); + logMsg("Current push request header: " + pushHeaders); + if (!(pushHeaders.get("h1") != null + && pushHeaders.get("h1").get(0).equals("v1"))) { + throw new Exception("test fail: could not find header h1=v1"); + } + + if (!(pushHeaders.get("foo") != null + && pushHeaders.get("foo").get(0).equals("v2"))) { + throw new Exception("test fail: could not find header foo=v2"); + } + + if (pushHeaders.get("baz") != null) { + throw new Exception("test fail"); + } + + logMsg("Current query string of the push request is " + + pushReq.uri().getQuery()); + if (pushReq.uri().getQuery() == null || !pushReq.uri().getQuery().contains("querystring=1&querystring=2")) { + throw new Exception( + "test fail: could not find correct querystring \"querystring=1&querystring=2\""); + } + } + + /* + * @testName: serverPushNegtiveTest + * + * @assertion_ids: N/A; + * + * @test_Strategy: Verify some methods of PushBuilder works as expected. + */ + @Test + public void serverPushNegtiveTest() throws Exception { + requestURI = "http://" + hostname + ":" + portnum + getContextRoot() + + "/TestServlet7"; + Map headers = new HashMap<>(); + + List> responses = sendRequest(headers, null, null); + HttpResponse servletResp = null; + for (HttpResponse response : responses) { + if (response.uri().toString().contains("TestServlet7")) { + servletResp = response; + } + } + + if (servletResp == null) + throw new Exception("can not get servlet response"); + if (!servletResp.body().contains("test passed")) { + throw new Exception("test fail"); + } + } + + private List> sendRequest(Map headers, + Authenticator auth, CookieManager cm) throws Exception { + HttpClient.Builder builder = HttpClient.newBuilder(); + if (auth != null) + builder.authenticator(auth); + if (cm != null) + builder.cookieHandler(cm); + + HttpClient client = builder.version(HttpClient.Version.HTTP_2) + .followRedirects(HttpClient.Redirect.ALWAYS) + // TODO nThreads configurable + .executor(Executors.newFixedThreadPool(3)) + .build(); + + List> responses = new CopyOnWriteArrayList<>(); + + try { + // GET + HttpRequest.Builder requestBuilder = HttpRequest + .newBuilder(new URI(requestURI)).version(HttpClient.Version.HTTP_2); + headers.forEach(requestBuilder::header); + + List>> futureResponses = new CopyOnWriteArrayList<>(); + + HttpResponse.PushPromiseHandler pushPromiseHandler = + (HttpRequest req, HttpRequest pushPromiseRequest, Function, CompletableFuture>> acceptor) -> + futureResponses.add(acceptor.apply(HttpResponse.BodyHandlers.ofString())); + + client.sendAsync(requestBuilder.build(), HttpResponse.BodyHandlers.ofString(), pushPromiseHandler) + .thenAccept(responses::add) + .get(Long.getLong("http2.timeout", 1), TimeUnit.MINUTES); + + responses.addAll(futureResponses.stream().map(httpResponseCompletableFuture -> { + try { + return httpResponseCompletableFuture.get(Long.getLong("http2.timeout", 1), TimeUnit.MINUTES); + } catch (InterruptedException | ExecutionException | TimeoutException e) { + throw new RuntimeException(e.getMessage(), e); + } + }).collect(Collectors.toList())); + + } catch (Exception e) { + throw new Exception("Test fail", e); + } + return responses; + } + + private void printResponse(HttpResponse response) { + logMsg("ResponseURI: " + response.uri()); + logMsg("ResponseBody: " + response.body()); + logMsg("HTTP-Version: " + response.version()); + logMsg("Statuscode: " + response.statusCode()); + logMsg("Header:"); + response.headers().map().forEach( + (header, values) -> logMsg(" " + header + " = " + values.stream() + .map(String::trim).reduce(String::concat).orElse("hallo"))); + } + + private void verifyResponses(List> responses, + String[] expectedResponses) throws Exception { + if (responses.size() == 0) { + throw new Exception("No Responses, expected responses are " + + Arrays.toString(expectedResponses)); + } + + if (responses.size() != expectedResponses.length) { + throw new Exception("Wrong Responses, expected responses are " + + Arrays.toString(expectedResponses)); + } + + for (String s : expectedResponses) { + boolean found = false; + for (HttpResponse r : responses) { + logMsg(r.body()); + if (r.body().contains(s)) { + found = true; + break; + } + } + if (!found) { + throw new Exception("Wrong Responses, expected responses are " + + Arrays.toString(expectedResponses)); + } + } + } +} \ No newline at end of file diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/serverpush/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/serverpush/TestServlet.java new file mode 100644 index 0000000000..3b2190781e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/serverpush/TestServlet.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2017, 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 + */ + +package com.sun.ts.tests.servlet.spec.serverpush; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.PushBuilder; + +public class TestServlet extends HttpServlet { + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + PrintWriter pw = resp.getWriter(); + PushBuilder pb = req.newPushBuilder(); + if (pb == null) { + pw.println("Get Null PushBuilder"); + } else { + pw.println("hello"); + pb.path("index.html"); + pb.addHeader("If-Match", "*"); + pb.push(); + pw.println( + pb.getPath() == null ? "path is cleared" : "path is not cleared"); + pw.println( + pb.getHeader("If-Match") == null ? "conditional headers are cleared" + : "conditional headers are not cleared"); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/serverpush/TestServlet2.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/serverpush/TestServlet2.java new file mode 100644 index 0000000000..744695a2a6 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/serverpush/TestServlet2.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2017, 2020 Oracle and/or its affiliates and others. + * 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 + */ + +package com.sun.ts.tests.servlet.spec.serverpush; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Locale; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.PushBuilder; + +public class TestServlet2 extends HttpServlet { + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + PrintWriter pw = resp.getWriter(); + req.getSession(true); + PushBuilder pb = req.newPushBuilder(); + String defaultMethod = pb.getMethod(); + pw.println("Method:" + defaultMethod); + PushBuilder pb2 = req.newPushBuilder(); + pw.println("Return new instance:" + String.valueOf(pb != pb2)); + pw.println("JSESSIONID: " + pb.getSessionId()); + pw.println("The headers of PushBuilder: "); + for (String name : pb.getHeaderNames()) { + /* + * Header names are case insensitive. Force to lower case to make client + * side test logic simpler. + */ + pw.print(name.toLowerCase(Locale.ENGLISH)); + pw.print("="); + pw.println(pb.getHeader(name)); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/serverpush/TestServlet3.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/serverpush/TestServlet3.java new file mode 100644 index 0000000000..fd80ff48e3 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/serverpush/TestServlet3.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2017, 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 + */ + +package com.sun.ts.tests.servlet.spec.serverpush; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpSession; +import jakarta.servlet.http.PushBuilder; + +public class TestServlet3 extends HttpServlet { + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + PrintWriter pw = resp.getWriter(); + + if ("true".equals(req.getParameter("generateSession"))) { + HttpSession session = req.getSession(true); + pw.print(session.getId()); + } else { + PushBuilder pb = req.newPushBuilder(); + if (req.getSession(false).getId().equals(pb.getSessionId())) { + pw.print("Test success"); + } else { + pw.println( + "The session ID for the PushBuilder should also come from the same source as the request"); + } + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/serverpush/TestServlet4.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/serverpush/TestServlet4.java new file mode 100644 index 0000000000..48d7fc4b87 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/serverpush/TestServlet4.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2017, 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 + */ + +package com.sun.ts.tests.servlet.spec.serverpush; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.Cookie; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpSession; +import jakarta.servlet.http.PushBuilder; + +public class TestServlet4 extends HttpServlet { + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + PrintWriter pw = resp.getWriter(); + Cookie cookie1 = new Cookie("foo", "bar"); + cookie1.setMaxAge(1000); + resp.addCookie(cookie1); + + Cookie cookie2 = new Cookie("baz", "qux"); + cookie2.setMaxAge(-1); + resp.addCookie(cookie2); + pw.println("add cookies [foo,bar] [baz,qux] to response"); + + HttpSession session = req.getSession(true); + pw.println("create session: " + session); + + PushBuilder pb = req.newPushBuilder(); + pw.println("Cookie header in PushBuilder: " + pb.getHeader("Cookie")); + pb.path("index.html"); + pb.push(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/serverpush/TestServlet5.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/serverpush/TestServlet5.java new file mode 100644 index 0000000000..978683ffee --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/serverpush/TestServlet5.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2017, 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 + */ + +package com.sun.ts.tests.servlet.spec.serverpush; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpSession; +import jakarta.servlet.http.PushBuilder; + +public class TestServlet5 extends HttpServlet { + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + PrintWriter pw = resp.getWriter(); + HttpSession session = req.getSession(true); + pw.print(session.getId()); + PushBuilder pb = req.newPushBuilder(); + pb.path("index.html"); + pb.push(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/serverpush/TestServlet6.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/serverpush/TestServlet6.java new file mode 100644 index 0000000000..5da2e5e3a1 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/serverpush/TestServlet6.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017, 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 + */ + +package com.sun.ts.tests.servlet.spec.serverpush; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.PushBuilder; + +public class TestServlet6 extends HttpServlet { + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + PrintWriter pw = resp.getWriter(); + pw.println("hello"); + PushBuilder pb = req.newPushBuilder(); + pb.addHeader("h1", "v1"); + pb.setHeader("foo", "v2"); + pb.removeHeader("baz"); + pb.queryString("querystring=2"); + pb.path("index.html?querystring=1"); + pb.push(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/serverpush/TestServlet7.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/serverpush/TestServlet7.java new file mode 100644 index 0000000000..10bfc7571b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/serverpush/TestServlet7.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2017, 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 + */ + +package com.sun.ts.tests.servlet.spec.serverpush; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.PushBuilder; + +public class TestServlet7 extends HttpServlet { + + private final static String[] METHODS = { "", "POST", "PUT", "DELETE", + "CONNECT", "OPTIONS", "TRACE" }; + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + PrintWriter pw = resp.getWriter(); + PushBuilder pb = req.newPushBuilder(); + boolean pass = true; + try { + pb.push(); + pw.println( + "IllegalStateException should be thrown if there was no call to path(java.lang.String) on this instance between its instantiation."); + pass = false; + } catch (IllegalStateException e) { + } + + pb = req.newPushBuilder(); + pb.path("index.html"); + pb.push(); + try { + pb.push(); + pw.println( + "IllegalStateException should be thrown if there was no call to path(java.lang.String) on this instance between the last call to push() that did not throw an IllegalStateException."); + pass = false; + } catch (IllegalStateException e) { + } + + pb = req.newPushBuilder(); + try { + pb.method(null); + pw.println( + "NullPointerException should be thrown if the argument of method() is null"); + pass = false; + } catch (NullPointerException e) { + } + + for (String method : METHODS) { + if (!testMethod(pb, pw, method)) + pass = false; + } + + if (pass) + pw.println("test passed"); + } + + private boolean testMethod(PushBuilder pb, PrintWriter pw, String method) { + try { + pb.method(method); + pw.println("IllegalArgumentException should be thrown if set method \"" + + method + "\" to be used for the push"); + return false; + } catch (IllegalArgumentException e) { + } + return true; + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/serverpush/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/serverpush/build.xml new file mode 100644 index 0000000000..5c7f6ccfb4 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/serverpush/build.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/serverpush/servlet_spec_serverpush_web.war.sun-web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/serverpush/servlet_spec_serverpush_web.war.sun-web.xml new file mode 100644 index 0000000000..393be70063 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/serverpush/servlet_spec_serverpush_web.war.sun-web.xml @@ -0,0 +1,32 @@ + + + + + + /servlet_spec_serverpush_web + + Manager + javajoe + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/serverpush/servlet_spec_serverpush_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/serverpush/servlet_spec_serverpush_web.xml new file mode 100644 index 0000000000..8132feb7bc --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/serverpush/servlet_spec_serverpush_web.xml @@ -0,0 +1,106 @@ + + + + + SerSpecServerPush + + + TestServlet + com.sun.ts.tests.servlet.spec.serverpush.TestServlet + + + TestServlet2 + com.sun.ts.tests.servlet.spec.serverpush.TestServlet2 + + + TestServlet3 + com.sun.ts.tests.servlet.spec.serverpush.TestServlet3 + + + TestServlet4 + com.sun.ts.tests.servlet.spec.serverpush.TestServlet4 + + + TestServlet5 + com.sun.ts.tests.servlet.spec.serverpush.TestServlet5 + + + TestServlet6 + com.sun.ts.tests.servlet.spec.serverpush.TestServlet6 + + + TestServlet7 + com.sun.ts.tests.servlet.spec.serverpush.TestServlet7 + + + TestServlet + /TestServlet + + + TestServlet2 + /TestServlet2 + + + TestServlet3 + /TestServlet3 + + + TestServlet4 + /TestServlet4 + + + TestServlet5 + /TestServlet5 + + + TestServlet6 + /TestServlet6 + + + TestServlet7 + /TestServlet7 + + + 54 + + + + + MySecureServlet2 + /TestServlet2 + GET + + + Manager + + + NONE + + + + + BASIC + default + + + + the manager role + Manager + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletcontext/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletcontext/TestServlet.java new file mode 100644 index 0000000000..e2996635a0 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletcontext/TestServlet.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2011, 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 + */ + +package com.sun.ts.tests.servlet.spec.servletcontext; + +import java.io.IOException; +import java.io.PrintWriter; + +import com.sun.ts.tests.servlet.common.servlets.GenericTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.ServletConfig; +import jakarta.servlet.ServletContext; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import jakarta.servlet.descriptor.JspConfigDescriptor; + +public class TestServlet extends GenericTCKServlet { + + public void getJspConfigDescriptorTest(ServletRequest request, + ServletResponse response) throws ServletException, IOException { + boolean passed = true; + PrintWriter pw = response.getWriter(); + ServletConfig config = this.getServletConfig(); + ServletContext context = config.getServletContext(); + JspConfigDescriptor results = context.getJspConfigDescriptor(); + if (results != null) { + passed = false; + pw.println("Unexpected JspConfigDescriptor exists: " + results); + } + ServletTestUtil.printResult(pw, passed); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletcontext/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletcontext/URLClient.java new file mode 100644 index 0000000000..8e85669f56 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletcontext/URLClient.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2011, 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 + */ + +package com.sun.ts.tests.servlet.spec.servletcontext; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_spec_servletcontext_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_spec_servletcontext_web.xml")); + } + + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* Run test */ + /* + * @testName: getJspConfigDescriptorTest + * + * @assertion_ids: Servlet:JAVADOC:690; + * + * @test_Strategy: Create a web application with no JSP, Create a Servlet, + * verify getJspConfigDescriptor retunes null; + */ + @Test + public void getJspConfigDescriptorTest() throws Exception { + TEST_PROPS.setProperty(APITEST, "getJspConfigDescriptorTest"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletcontext/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletcontext/build.xml new file mode 100644 index 0000000000..5610ebc1ca --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletcontext/build.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletcontext/servlet_spec_servletcontext_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletcontext/servlet_spec_servletcontext_web.xml new file mode 100644 index 0000000000..76cebeac07 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletcontext/servlet_spec_servletcontext_web.xml @@ -0,0 +1,33 @@ + + + + + SerSpecServletContext + + TestServlet + com.sun.ts.tests.servlet.spec.servletcontext.TestServlet + + + TestServlet + /TestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletmapping/TestServlet1.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletmapping/TestServlet1.java new file mode 100644 index 0000000000..0c97222e0b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletmapping/TestServlet1.java @@ -0,0 +1,38 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.servletmapping; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet1 extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println("TestServlet1 is invoked"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletmapping/TestServlet2.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletmapping/TestServlet2.java new file mode 100644 index 0000000000..8af32cfade --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletmapping/TestServlet2.java @@ -0,0 +1,38 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.servletmapping; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet2 extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println("TestServlet2 is invoked"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletmapping/TestServlet4.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletmapping/TestServlet4.java new file mode 100644 index 0000000000..779cd46197 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletmapping/TestServlet4.java @@ -0,0 +1,38 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.servletmapping; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet4 extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println("TestServlet4 is invoked"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletmapping/TestServlet5.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletmapping/TestServlet5.java new file mode 100644 index 0000000000..bb87417857 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletmapping/TestServlet5.java @@ -0,0 +1,38 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.servletmapping; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class TestServlet5 extends GenericServlet { + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println("TestServlet5 is invoked"); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletmapping/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletmapping/URLClient.java new file mode 100644 index 0000000000..1e5060f58b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletmapping/URLClient.java @@ -0,0 +1,143 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.servletmapping; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_js_servletmapping_web.war") + .addClasses(TestServlet1.class, TestServlet2.class, TestServlet4.class, TestServlet5.class) + .setWebXML(URLClient.class.getResource("servlet_js_servletmapping_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + /* + * @testName: multiURLmappingTest1 + * + * @assertion_ids: Servlet:SPEC:133; Servlet:SPEC:134.1; Servlet:SPEC:207; + * + * @test_Strategy: 1. Create servlet TestServlet1 with multiple URLs: + * /foo/bar/* /TestServlet1 /foo/baR/TestServlet1 /test/Test1.bop 2. Create + * servlet TestServlet2 with multiple URLs: /foo/baR/* /TestServlet2 3. Send + * request to /TestServlet1, verify TestServlet1 is invoked 4. Send request to + * /TestServlet2, verify TestServlet2 is invoked + */ + @Test + public void multiURLmappingTest1() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "TestServlet1"); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/TestServlet1" + " HTTP/1.1"); + invoke(); + + TEST_PROPS.setProperty(SEARCH_STRING, "TestServlet2"); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/TestServlet2" + " HTTP/1.1"); + invoke(); + } + + /* + * @testName: multiURLmappingTest2 + * + * @assertion_ids: Servlet:SPEC:133; Servlet:SPEC:134.1; Servlet:SPEC:134.2; + * Servlet:SPEC:134.4; Servlet:SPEC:207; + * + * @test_Strategy: 1. Create servlet TestServlet1 with multiple URLs: + * /foo/bar/* /TestServlet1 /foo/baR/TestServlet1 /test/Test1.bop 2. Create + * servlet TestServlet5 with multiple URLs: /foo/bar/TestServlet5 + * /TestServlet5 3. Send request to /foo/bar/xyz, verify TestServlet1 is + * invoked 4. Send request to /foo/bar/TestServlet5, verify TestServlet5 is + * invoked + */ + @Test + public void multiURLmappingTest2() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "TestServlet1"); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/foo/bar/xyz" + " HTTP/1.1"); + invoke(); + + TEST_PROPS.setProperty(SEARCH_STRING, "TestServlet5"); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/foo/bar/TestServlet5" + " HTTP/1.1"); + invoke(); + } + + /* + * @testName: multiURLmappingTest3 + * + * @assertion_ids: Servlet:SPEC:133; Servlet:SPEC:134.1; Servlet:SPEC:134.2; + * Servlet:SPEC:134.4; Servlet:SPEC:207; + * + * @test_Strategy: 1. Create servlet TestServlet1 with multiple URLs: + * /foo/bar/* /TestServlet1 /foo/baR/TestServlet1 /test/Test1.bop 2. Create + * servlet TestServlet2 with multiple URLs: /foo/baR/* /TestServlet2 3. Send + * request to /foo/baR/TestServlet1, verify TestServlet1 is invoked 4. Send + * request to /foo/baR/Ten, verify TestServlet2 is invoked + */ + @Test + public void multiURLmappingTest3() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "TestServlet1"); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/foo/baR/TestServlet1" + " HTTP/1.1"); + invoke(); + + TEST_PROPS.setProperty(SEARCH_STRING, "TestServlet2"); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/foo/baR/Ten" + " HTTP/1.1"); + invoke(); + } + + /* + * @testName: multiURLmappingTest4 + * + * @assertion_ids: Servlet:SPEC:133; Servlet:SPEC:134.1; Servlet:SPEC:134.2; + * Servlet:SPEC:134.3; Servlet:SPEC:134.4; Servlet:SPEC:207; + * + * @test_Strategy: 1. Create servlet TestServlet1 with multiple URLs: + * /foo/bar/* /TestServlet1 /foo/baR/TestServlet1 /test/Test1.bop 2. Create + * servlet TestServlet4 with multiple URLs: *.bop /TestServlet4 3. Send + * request to /test/Test1.bop, verify TestServlet1 is invoked 4. Send request + * to /Test1.bop, verify TestServlet4 is invoked + */ + @Test + public void multiURLmappingTest4() throws Exception { + TEST_PROPS.setProperty(SEARCH_STRING, "TestServlet1"); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/test/Test1.bop" + " HTTP/1.1"); + invoke(); + + TEST_PROPS.setProperty(SEARCH_STRING, "TestServlet4"); + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/Test1.bop" + " HTTP/1.1"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletmapping/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletmapping/build.xml new file mode 100644 index 0000000000..afa2903770 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletmapping/build.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletmapping/servlet_js_servletmapping_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletmapping/servlet_js_servletmapping_web.xml new file mode 100644 index 0000000000..cb611e81d2 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletmapping/servlet_js_servletmapping_web.xml @@ -0,0 +1,63 @@ + + + + + SerJaxSerservletmapping + + TestServlet1 + com.sun.ts.tests.servlet.spec.servletmapping.TestServlet1 + + + TestServlet2 + com.sun.ts.tests.servlet.spec.servletmapping.TestServlet2 + + + TestServlet4 + com.sun.ts.tests.servlet.spec.servletmapping.TestServlet4 + + + TestServlet5 + com.sun.ts.tests.servlet.spec.servletmapping.TestServlet5 + + + TestServlet1 + /TestServlet1 + /foo/bar/* + /foo/baR/TestServlet1 + /test/Test1.bop + + + TestServlet2 + /TestServlet2 + /foo/baR/* + + + TestServlet4 + /TestServlet4 + *.bop + + + TestServlet5 + /TestServlet5 + /foo/bar/TestServlet5 + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletresponse/HttpTestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletresponse/HttpTestServlet.java new file mode 100644 index 0000000000..b4407d1041 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletresponse/HttpTestServlet.java @@ -0,0 +1,70 @@ +/* + * 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: HttpTestServlet.java 51063 2006-08-11 19:56:36Z lschwenk $ + */ + +/* + * %E% %E% + */ + +package com.sun.ts.tests.servlet.spec.servletresponse; + +import java.io.IOException; +import java.io.PrintWriter; + +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 HttpTestServlet extends HttpServlet { + + private static final Logger LOGGER = LoggerFactory.getLogger(HttpTestServlet.class); + + public void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + response.setContentType("text/plain"); + PrintWriter pw = response.getWriter(); + + pw.write("flushBufferTest for compatibility\n\r"); + LOGGER.info("flushBufferTest for compatibility"); + response.flushBuffer(); + + try { + Thread.sleep(10000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + // write the second part of the document and flush by exit method + pw.write("Test Failed\n\r"); + } + + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + service(request, response); + } + + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + service(request, response); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletresponse/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletresponse/TestServlet.java new file mode 100644 index 0000000000..18fb52fed8 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletresponse/TestServlet.java @@ -0,0 +1,66 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.servletresponse; + +import java.io.IOException; +import java.io.PrintWriter; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class TestServlet extends GenericServlet { + + private static final Logger LOGGER = LoggerFactory.getLogger(TestServlet.class); + + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + + response.setContentType("text/plain"); + PrintWriter pw = response.getWriter(); + + pw.write("flushBufferTest for compatibility\n\r"); + LOGGER.info("flushBufferTest for compatibility"); + response.flushBuffer(); + + try { + Thread.sleep(10000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + // write the second part of the document and flush by exit method + pw.write("Test Failed\n\r"); + } + + public void doGet(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + service(request, response); + } + + public void doPost(ServletRequest request, ServletResponse response) + throws ServletException, IOException { + service(request, response); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletresponse/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletresponse/URLClient.java new file mode 100644 index 0000000000..b0942c22f5 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletresponse/URLClient.java @@ -0,0 +1,157 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.servletresponse; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URL; +import java.util.Calendar; + +public class URLClient extends AbstractUrlClient { + + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_spec_servletresponse_web.war") + .addClasses(HttpTestServlet.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_spec_servletresponse_web.xml")); + } + + /* Run test */ + /* + * @testName: testFlushBufferHttp + * + * @assertion_ids: Servlet:JAVADOC:603 + * + * @test_Strategy: Servlet writes data in the buffer and flushes it; Verify + * data is sent back to client due to the flush, not by exiting service method + * This is done by sleeping a long time between flush and exit in servlet; + * Then verify time gap on client side. + */ + @Test + public void testFlushBufferHttp() throws Exception { + logger.trace("testFlushBufferHttp"); + URL u = new URL( + "http://" + _hostname + ":" + _port + getContextRoot() + "/HttpTestServlet"); + logger.trace("URL: {}", u); + try (InputStream is = u.openStream(); + BufferedReader bis = new BufferedReader(new InputStreamReader(is))) { + String line = null; + long time1 = 0L; + long time2 = 0L; + + while ((line = bis.readLine()) != null) { + logger.trace(line); + if (line.contains("flushBufferTest for compatibility") + && (time1 == 0L)) { + Calendar cal1 = Calendar.getInstance(); + time1 = cal1.getTimeInMillis(); + logger.trace("Buffer flush clocked at time {}", time1); + } + + if (line.contains("Test Failed") && (time2 == 0L)) { + Calendar cal2 = Calendar.getInstance(); + time2 = cal2.getTimeInMillis(); + logger.trace("service method exit clocked at time {}", time2); + } + } + if (((time2 - time1) > 5000) && (time1 != 0L) && (time2 != 0L)) { + logger.trace("Test passed. There is decent time difference between two clocked time."); + } else { + throw new Exception( "Test failed: there is not enough time between two clocked time"); + } + + } catch (Exception ex) { + throw new Exception("Test failed with the above exception:" + ex.getMessage(), ex); + } + } + + /* + * @testName: testFlushBuffer + * + * @assertion_ids: Servlet:JAVADOC:153 + * + * @test_Strategy: Servlet writes data in the buffer and flushes it; Verify + * data is sent back to client due to the flush, not by exiting service method + * This is done by sleeping a long time between flush and exit in servlet; + * Then verify time gap on client side. + */ + @Test + public void testFlushBuffer() throws Exception { + logger.trace("testFlushBuffer"); + + URL u = new URL( + "http://" + _hostname + ":" + _port + getContextRoot() + "/TestServlet"); + logger.trace("URL: {}}", u); + + try (InputStream is = u.openStream(); + BufferedReader bis = new BufferedReader(new InputStreamReader(is))) { + + String line = null; + long time1 = 0L; + long time2 = 0L; + + while ((line = bis.readLine()) != null) { + logger.trace(line); + if (line.contains("flushBufferTest for compatibility") + && (time1 == 0L)) { + Calendar cal1 = Calendar.getInstance(); + time1 = cal1.getTimeInMillis(); + logger.trace("Buffer flush clocked at time {}", time1); + } + + if (line.contains("Test Failed") && (time2 == 0L)) { + Calendar cal2 = Calendar.getInstance(); + time2 = cal2.getTimeInMillis(); + logger.trace("service method exit clocked at time {}", time2); + } + } + + bis.close(); + + if (((time2 - time1) > 5000) && (time1 != 0L) && (time2 != 0L)) { + logger.trace( + "Test passed. There is decent time difference between two clocked time."); + } else { + throw new Exception( + "Test failed: there is not enough time between two clocked time"); + } + + } catch (Exception ex) { + throw new Exception("testFlushBuffer failed with the above exception:" + ex.getMessage(), ex); + } + } + + public void cleanup() throws Exception { + logger.info("[BaseUrlClient] Test cleanup OK"); + } + +} \ No newline at end of file diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletresponse/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletresponse/build.xml new file mode 100644 index 0000000000..32722d006d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletresponse/build.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletresponse/servlet_spec_servletresponse_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletresponse/servlet_spec_servletresponse_web.xml new file mode 100644 index 0000000000..e2037b3d53 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/servletresponse/servlet_spec_servletresponse_web.xml @@ -0,0 +1,41 @@ + + + + + SerJaxSerServletResponse + + HttpTestServlet + com.sun.ts.tests.servlet.spec.servletresponse.HttpTestServlet + + + TestServlet + com.sun.ts.tests.servlet.spec.servletresponse.TestServlet + + + TestServlet + /TestServlet + + + HttpTestServlet + /HttpTestServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/srlistener/ForwardedServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/srlistener/ForwardedServlet.java new file mode 100644 index 0000000000..f628e6ca6a --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/srlistener/ForwardedServlet.java @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2009, 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$ + */ +package com.sun.ts.tests.servlet.spec.srlistener; + +import java.io.IOException; +import java.io.PrintWriter; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class ForwardedServlet extends HttpServlet { + + private static final String TEST_HEADER = "testname"; + + private static final Class[] TEST_ARGS = { HttpServletRequest.class, + HttpServletResponse.class }; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws ServletException, IOException { + String test = req.getParameter(TEST_HEADER); + try { + Method method = this.getClass().getMethod(test, TEST_ARGS); + method.invoke(this, new Object[] { req, res }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + } + + public void simple(HttpServletRequest req, HttpServletResponse res) + throws ServletException, IOException { + PrintWriter pw = res.getWriter(); + pw.print("ForwardedServlet Invoked, simple method"); + System.out.println("In ForwardedServlet, simple method"); + ServletTestUtil.printResult(pw, true); + } + + public void forwardagain(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String path = "/forward/SecondForwardedServlet?testname=simple"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + System.out.println("In forwardedServlet, forwardagain method"); + if (rd == null) { + pw.println("Null RequestDispatcher got for path=" + path); + } else { + rd.forward(request, response); + } + } + + public void include(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String path = "/include/IncludedServlet?testname=simple"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + System.out.println("In forwardedServlet, include method"); + if (rd == null) { + pw.println("Null RequestDispatcher got for path=" + path); + } else { + rd.forward(request, response); + } + } + + public void error(HttpServletRequest req, HttpServletResponse res) + throws ServletException, IOException { + System.out.println("In ForwardedServlet, error method"); + res.sendError(403); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/srlistener/IncludedServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/srlistener/IncludedServlet.java new file mode 100644 index 0000000000..85cf38800e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/srlistener/IncludedServlet.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2009, 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$ + */ +package com.sun.ts.tests.servlet.spec.srlistener; + +import java.io.IOException; +import java.io.PrintWriter; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class IncludedServlet extends HttpServlet { + + private static final String TEST_HEADER = "testname"; + + private static final Class[] TEST_ARGS = { HttpServletRequest.class, + HttpServletResponse.class }; + + public void service(HttpServletRequest req, HttpServletResponse res) + throws ServletException, IOException { + String test = req.getParameter(TEST_HEADER); + try { + Method method = this.getClass().getMethod(test, TEST_ARGS); + method.invoke(this, new Object[] { req, res }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + } + + public void simple(HttpServletRequest req, HttpServletResponse res) + throws ServletException, IOException { + PrintWriter pw = res.getWriter(); + pw.print("IncludedServlet Invoked, simple method"); + System.out.println("In includedServlet, simple method"); + ServletTestUtil.printResult(pw, true); + } + + public void includeagain(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String path = "/include/SecondIncludedServlet?testname=simple"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + System.out.println("In includedServlet, includeagain method"); + if (rd == null) { + pw.println("Null RequestDispatcher got for path=" + path); + } else { + rd.include(request, response); + } + } + + public void forward(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String path = "/forward/ForwardedServlet?testname=simple"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + System.out.println("In method forward"); + if (rd == null) { + pw.println("Null RequestDispatcher got for path=" + path); + } else { + rd.forward(request, response); + } + } + + public void error(HttpServletRequest req, HttpServletResponse res) + throws ServletException, IOException { + System.out.println("In includedServlet, error method"); + req.setAttribute("ERROR_TEST_INCLUDE", "403"); + res.sendError(403); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/srlistener/SRListener.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/srlistener/SRListener.java new file mode 100644 index 0000000000..a6db8d4eec --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/srlistener/SRListener.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2009, 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:$ + */ +package com.sun.ts.tests.servlet.spec.srlistener; + +import java.util.ArrayList; + +import jakarta.servlet.ServletRequestEvent; +import jakarta.servlet.ServletRequestListener; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public final class SRListener implements ServletRequestListener { + + private static final Logger LOGGER = LoggerFactory.getLogger(SRListener.class); + + // Public Methods + public void requestDestroyed(ServletRequestEvent event) { + ArrayList al = null; + al = (ArrayList) event.getServletContext().getAttribute("arraylist"); + if (al != null) { + LOGGER.info("in requestDestroyed method of listener"); + al.add("in requestDestroyed method of listener"); + event.getServletContext().setAttribute("arraylist", al); + } + } + + public void requestInitialized(ServletRequestEvent event) { + ArrayList al = (ArrayList) event.getServletContext().getAttribute("arraylist"); + if (al == null) { + al = new ArrayList(); + } + LOGGER.info("in requestInitialized method of listener"); + al.add("in requestInitialized method of listener"); + event.getServletContext().setAttribute("arraylist", al); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/srlistener/SecondForwardedServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/srlistener/SecondForwardedServlet.java new file mode 100644 index 0000000000..f704709c08 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/srlistener/SecondForwardedServlet.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2009, 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$ + */ +package com.sun.ts.tests.servlet.spec.srlistener; + +import java.io.IOException; +import java.io.PrintWriter; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +public class SecondForwardedServlet extends GenericServlet { + + private static final String TEST_HEADER = "testname"; + + private static final Class[] TEST_ARGS = { ServletRequest.class, + ServletResponse.class }; + + public void service(ServletRequest req, ServletResponse res) + throws ServletException, IOException { + String test = req.getParameter(TEST_HEADER); + try { + Method method = this.getClass().getMethod(test, TEST_ARGS); + method.invoke(this, new Object[] { req, res }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + } + + public void simple(ServletRequest req, ServletResponse res) + throws ServletException, IOException { + PrintWriter pw = res.getWriter(); + pw.print("SecondForwardedServlet Invoked, simple method"); + System.out.println("In SecondForwardedServlet, simple method"); + ServletTestUtil.printResult(pw, true); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/srlistener/SecondIncludedServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/srlistener/SecondIncludedServlet.java new file mode 100644 index 0000000000..4dab01c59d --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/srlistener/SecondIncludedServlet.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2009, 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$ + */ +package com.sun.ts.tests.servlet.spec.srlistener; + +import java.io.IOException; +import java.io.PrintWriter; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.GenericServlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SecondIncludedServlet extends GenericServlet { + + private static final Logger LOGGER = LoggerFactory.getLogger(SecondIncludedServlet.class); + + private static final String TEST_HEADER = "testname"; + + private static final Class[] TEST_ARGS = { ServletRequest.class, + ServletResponse.class }; + + public void service(ServletRequest req, ServletResponse res) + throws ServletException, IOException { + String test = req.getParameter(TEST_HEADER); + try { + Method method = this.getClass().getMethod(test, TEST_ARGS); + method.invoke(this, new Object[] { req, res }); + } catch (InvocationTargetException ite) { + throw new ServletException(ite.getTargetException()); + } catch (NoSuchMethodException nsme) { + throw new ServletException("Test: " + test + " does not exist"); + } catch (Throwable t) { + throw new ServletException("Error executing test: " + test, t); + } + } + + public void simple(ServletRequest req, ServletResponse res) + throws ServletException, IOException { + PrintWriter pw = res.getWriter(); + pw.print("SecondIncludedServlet Invoked, simple method"); + LOGGER.info("In SecondIncludedServlet, simple method"); + ServletTestUtil.printResult(pw, true); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/srlistener/TestServlet.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/srlistener/TestServlet.java new file mode 100644 index 0000000000..5319a6db39 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/srlistener/TestServlet.java @@ -0,0 +1,326 @@ +/* + * Copyright (c) 2009, 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:$ + */ +package com.sun.ts.tests.servlet.spec.srlistener; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; + +import com.sun.ts.tests.servlet.common.servlets.HttpTCKServlet; +import com.sun.ts.tests.servlet.common.util.ServletTestUtil; + +import jakarta.servlet.AsyncContext; +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +public class TestServlet extends HttpTCKServlet { + + public void includes(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String path = "/include/IncludedServlet?testname=simple"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + logger.info("In method includes"); + if (rd == null) { + pw.println("Null RequestDispatcher got for path=" + path); + } else { + rd.include(request, response); + } + } + + public void multipleincludes(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String path = "/include/IncludedServlet?testname=includeagain"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + logger.debug("In method multipleincludes"); + + if (rd == null) { + pw.println("Null RequestDispatcher got for path=" + path); + } else { + rd.include(request, response); + } + } + + public void includeforward(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String path = "/include/IncludedServlet?testname=forward"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + logger.debug("In method includeforward"); + if (rd == null) { + pw.println("Null RequestDispatcher got for path=" + path); + } else { + rd.include(request, response); + } + } + + public void includeerror(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String path = "/include/IncludedServlet?testname=error"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + logger.debug("In method includeerror"); + if (rd == null) { + pw.println("Null RequestDispatcher got for path=" + path); + } else { + pw.println("In method includeerror"); + rd.include(request, response); + } + if (!((String) request.getAttribute("ERROR_TEST_INCLUDE")).equals("403")) { + pw.println("Test Failed"); + } else { + response.sendError(403); + } + + } + + public void forward(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String path = "/forward/ForwardedServlet?testname=simple"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + logger.debug("In method forward"); + if (rd == null) { + pw.println("Null RequestDispatcher got for path=" + path); + } else { + rd.forward(request, response); + } + } + + public void multipleforwards(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String path = "/forward/ForwardedServlet?testname=forwardagain"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + logger.debug("In method multipleforward"); + if (rd == null) { + pw.println("Null RequestDispatcher got for path=" + path); + } else { + rd.forward(request, response); + } + } + + public void forwardinclude(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String path = "/forward/ForwardedServlet?testname=include"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + logger.debug("In method forwardinclude"); + if (rd == null) { + pw.println("Null RequestDispatcher got for path=" + path); + } else { + rd.forward(request, response); + } + } + + public void forwarderror(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + + String path = "/forward/ForwardedServlet?testname=error"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + logger.debug("In method forwarderror"); + if (rd == null) { + pw.println("Null RequestDispatcher got for path=" + path); + } else { + rd.forward(request, response); + } + } + + public void async(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println("TestServlet Invoked"); + pw.println("In method async"); + logger.debug("In method async"); + try { + AsyncContext asyncc = request.startAsync(); + response.getWriter().println("TestServlet_Async=STARTED"); + asyncc.complete(); + } catch (IllegalStateException ilex) { + pw.println("TestServlet_Async=NOT_STARTED"); + } catch (Exception ex) { + pw.println("TestServlet_Async=FAILED: " + ex.getMessage()); + } + } + + public void simpleasyncinclude(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println("TestServlet Invoked"); + pw.println("In method simpleasyncinclude"); + logger.debug("In method simpleasyncinclude"); + try { + AsyncContext asyncc = request.startAsync(); + response.getWriter().println("TestServlet_Async=STARTED"); + + String path = "/include/IncludedServlet?testname=simple"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + if (rd == null) { + pw.println("Null RequestDispatcher got for path=" + path); + } else { + rd.include(request, response); + } + + asyncc.complete(); + } catch (IllegalStateException ilex) { + pw.println("TestServlet_Async=NOT_STARTED"); + } catch (Exception ex) { + pw.println("TestServlet_Async=FAILED: " + ex.getMessage()); + } + } + + public void simpleasyncforward(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println("TestServlet Invoked"); + pw.println("In method simpleasyncforward"); + logger.debug("In method simpleasyncforward"); + try { + AsyncContext asyncc = request.startAsync(); + response.getWriter().println("TestServlet_Async=STARTED"); + + String path = "/forward/ForwardedServlet?testname=simple"; + RequestDispatcher rd = getServletContext().getRequestDispatcher(path); + if (rd == null) { + pw.println("Null RequestDispatcher got for path=" + path); + } else { + rd.forward(request, response); + } + + asyncc.complete(); + } catch (IllegalStateException ilex) { + pw.println("TestServlet_Async=NOT_STARTED"); + } catch (Exception ex) { + pw.println("TestServlet_Async=FAILED: " + ex.getMessage()); + } + } + + public void simpleasyncerror(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + pw.println("TestServlet Invoked"); + pw.println("In method simpleasyncerror"); + logger.debug("In method simpleasyncerror"); + try { + AsyncContext asyncc = request.startAsync(); + response.getWriter().println("TestServlet_Async=STARTED"); + response.sendError(403); + asyncc.complete(); + } catch (IllegalStateException ilex) { + pw.println("TestServlet_Async=NOT_STARTED"); + } catch (Exception ex) { + pw.println("TestServlet_Async=FAILED: " + ex.getMessage()); + } + } + + public void error(HttpServletRequest req, HttpServletResponse res) + throws ServletException, IOException { + logger.debug("In TestServlet, error method"); + res.sendError(403); + } + + public void checkLogSimple(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + PrintWriter pw = response.getWriter(); + Boolean pass = true; + // the last item in the expected is a result of this servlet being called + String[] expected = { "in requestInitialized method of listener", + "in requestDestroyed method of listener", + "in requestInitialized method of listener" }; + int expected_len = expected.length; + + // verify results + ArrayList result = (ArrayList) getServletContext() + .getAttribute("arraylist"); + result.trimToSize(); + int len = result.size(); + if (len == expected_len) { + pw.write("Got expected " + expected_len + " access times"); + for (int i = 0; i < len; i++) { + Object val = null; + val = (String) result.get(i); + if (!expected[i].equals(val)) { + pass = false; + pw.write("Expecting " + expected[i] + " at position " + i); + pw.write(". Got " + val + " instead."); + } else { + pw.write("Got expected value: " + expected[i] + " at position " + i); + } + } + } else { + pass = false; + pw.write( + "RequestListener is invoked/deleted more or less times than required"); + pw.write("Expect " + expected_len + " times, got " + len + "."); + + if (len > expected_len) { + for (int i = 0; i < expected_len; i++) { + Object val = null; + val = (String) result.get(i); + if (!expected[i].equals(val)) { + pass = false; + pw.write("Expecting " + expected[i] + " at position " + i); + pw.write(". Got " + val + " instead."); + } else { + pw.write( + "Got expected value: " + expected[i] + " at position " + i); + } + } + + for (int i = expected_len; i < len; i++) { + pw.write("Extra access to Listener: " + result.get(i) + + " at position " + i); + } + + } else { + for (int i = 0; i < len; i++) { + Object val = null; + val = (String) result.get(i); + if (!expected[i].equals(val)) { + pass = false; + pw.write("Expecting " + expected[i] + " at position " + i); + pw.write(". Got " + val + " instead."); + } else { + pw.write( + "Got expected value: " + expected[i] + " at position " + i); + } + } + + for (int i = len; i < expected_len; i++) { + pw.write( + "Missing expected value: " + expected[i] + " at position " + i); + } + } + } + getServletContext().removeAttribute("arraylist"); + ServletTestUtil.printResult(pw, pass); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/srlistener/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/srlistener/URLClient.java new file mode 100644 index 0000000000..acecc9a599 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/srlistener/URLClient.java @@ -0,0 +1,448 @@ +/* + * Copyright (c) 2009, 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:$ + */ +package com.sun.ts.tests.servlet.spec.srlistener; + +import com.sun.ts.lib.util.TestUtil; +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import com.sun.ts.tests.servlet.common.servlets.CommonServlets; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + @BeforeEach + public void setupServletName() throws Exception { + setServletName("TestServlet"); + } + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_spec_srlistener_web.war") + .addAsLibraries(CommonServlets.getCommonServletsArchive()) + .addClasses(ForwardedServlet.class, IncludedServlet.class, SecondForwardedServlet.class, + SecondIncludedServlet.class, SRListener.class, TestServlet.class) + .setWebXML(URLClient.class.getResource("servlet_spec_srlistener_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: simpleinclude + * + * @assertion_ids: + * + * @test_Strategy: + */ + @Test + public void simpleinclude() throws Exception { + Boolean pass = true; + try { + TEST_PROPS.setProperty(APITEST, "includes"); + TEST_PROPS.setProperty(SEARCH_STRING, + "IncludedServlet Invoked|simple method"); + invoke(); + } catch (Exception flt) { + pass = false; + TestUtil.logErr("Test failed at the first invocation." + + "catch it here so the cleanup can continue", flt); + } + TEST_PROPS.setProperty(APITEST, "checkLogSimple"); + invoke(); + + if (!pass) { + throw new Exception("Test failed at the first invocation." + + "catch it here so the cleanup can continue"); + } + } + + /* + * @testName: multipleincludes + * + * @assertion_ids: + * + * @test_Strategy: + */ + @Test + public void multipleincludes() throws Exception { + Boolean pass = true; + try { + TEST_PROPS.setProperty(APITEST, "multipleincludes"); + TEST_PROPS.setProperty(SEARCH_STRING, + "SecondIncludedServlet Invoked|simple method"); + invoke(); + } catch (Exception flt) { + pass = false; + TestUtil.logErr("Test failed at the first invocation." + + "catch it here so the cleanup can continue", flt); + } + + TEST_PROPS.setProperty(APITEST, "checkLogSimple"); + invoke(); + + if (!pass) { + throw new Exception("Test failed at the first invocation." + + "catch it here so the cleanup can continue"); + } + } + + /* + * @testName: includeforward + * + * @assertion_ids: + * + * @test_Strategy: + */ + @Test + public void includeforward() throws Exception { + Boolean pass = true; + try { + TEST_PROPS.setProperty(APITEST, "includeforward"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ForwardedServlet Invoked|simple method"); + invoke(); + } catch (Exception flt) { + pass = false; + TestUtil.logErr("Test failed at the first invocation." + + "catch it here so the cleanup can continue", flt); + } + + TEST_PROPS.setProperty(APITEST, "checkLogSimple"); + invoke(); + + if (!pass) { + throw new Exception("Test failed at the first invocation." + + "catch it here so the cleanup can continue"); + } + } + + /* + * @testName: includeerror + * + * @assertion_ids: + * + * @test_Strategy: + */ + @Test + public void includeerror() throws Exception { + Boolean pass = true; + try { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/TestServlet?testname=includeerror HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, "403"); + invoke(); + } catch (Exception flt) { + pass = false; + TestUtil.logErr("Test failed at the first invocation." + + "catch it here so the cleanup can continue", flt); + } + + TEST_PROPS.setProperty(APITEST, "checkLogSimple"); + invoke(); + + if (!pass) { + throw new Exception("Test failed at the first invocation." + + "catch it here so the cleanup can continue"); + } + } + + /* + * @testName: simpleforward + * + * @assertion_ids: + * + * @test_Strategy: + */ + @Test + public void simpleforward() throws Exception { + Boolean pass = true; + try { + TEST_PROPS.setProperty(APITEST, "forward"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ForwardedServlet Invoked|simple method"); + invoke(); + } catch (Exception flt) { + pass = false; + TestUtil.logErr("Test failed at the first invocation." + + "catch it here so the cleanup can continue", flt); + } + + TEST_PROPS.setProperty(APITEST, "checkLogSimple"); + invoke(); + + if (!pass) { + throw new Exception("Test failed at the first invocation." + + "catch it here so the cleanup can continue"); + } + } + + /* + * @testName: multipleforwards + * + * @assertion_ids: + * + * @test_Strategy: + */ + @Test + public void multipleforwards() throws Exception { + Boolean pass = true; + try { + TEST_PROPS.setProperty(APITEST, "multipleforwards"); + TEST_PROPS.setProperty(SEARCH_STRING, + "SecondForwardedServlet Invoked|simple method"); + invoke(); + } catch (Exception flt) { + pass = false; + TestUtil.logErr("Test failed at the first invocation." + + "catch it here so the cleanup can continue", flt); + } + + TEST_PROPS.setProperty(APITEST, "checkLogSimple"); + invoke(); + + if (!pass) { + throw new Exception("Test failed at the first invocation." + + "catch it here so the cleanup can continue"); + } + } + + /* + * @testName: forwardinclude + * + * @assertion_ids: + * + * @test_Strategy: + */ + @Test + public void forwardinclude() throws Exception { + Boolean pass = true; + try { + TEST_PROPS.setProperty(APITEST, "forwardinclude"); + TEST_PROPS.setProperty(SEARCH_STRING, + "IncludedServlet Invoked|simple method"); + invoke(); + } catch (Exception flt) { + pass = false; + TestUtil.logErr("Test failed at the first invocation." + + "catch it here so the cleanup can continue", flt); + } + + TEST_PROPS.setProperty(APITEST, "checkLogSimple"); + invoke(); + + if (!pass) { + throw new Exception("Test failed at the first invocation." + + "catch it here so the cleanup can continue"); + } + } + + /* + * @testName: forwarderror + * + * @assertion_ids: + * + * @test_Strategy: + */ + @Test + public void forwarderror() throws Exception { + Boolean pass = true; + try { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/TestServlet?testname=forwarderror HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, "403"); + invoke(); + } catch (Exception flt) { + pass = false; + TestUtil.logErr("Test failed at the first invocation." + + "catch it here so the cleanup can continue", flt); + } + + TEST_PROPS.setProperty(APITEST, "checkLogSimple"); + invoke(); + + if (!pass) { + throw new Exception("Test failed at the first invocation." + + "catch it here so the cleanup can continue"); + } + } + + /* + * @testName: simpleasync + * + * @assertion_ids: + * + * @test_Strategy: + */ + @Test + public void simpleasync() throws Exception { + Boolean pass = true; + try { + TEST_PROPS.setProperty(APITEST, "async"); + TEST_PROPS.setProperty(SEARCH_STRING, + "TestServlet Invoked|method async|TestServlet_Async=STARTED"); + invoke(); + } catch (Exception flt) { + pass = false; + TestUtil.logErr("Test failed at the first invocation." + + "catch it here so the cleanup can continue", flt); + } + + TEST_PROPS.setProperty(APITEST, "checkLogSimple"); + invoke(); + + if (!pass) { + throw new Exception("Test failed at the first invocation." + + "catch it here so the cleanup can continue"); + } + } + + /* + * @testName: simpleasyncinclude + * + * @assertion_ids: + * + * @test_Strategy: + */ + @Test + public void simpleasyncinclude() throws Exception { + Boolean pass = true; + try { + TEST_PROPS.setProperty(APITEST, "simpleasyncinclude"); + TEST_PROPS.setProperty(SEARCH_STRING, + "TestServlet Invoked|method simpleasyncinclude" + + "|TestServlet_Async=STARTED" + + "|IncludedServlet Invoked||simple method"); + invoke(); + } catch (Exception flt) { + pass = false; + TestUtil.logErr("Test failed at the first invocation." + + "catch it here so the cleanup can continue", flt); + } + + TEST_PROPS.setProperty(APITEST, "checkLogSimple"); + invoke(); + + if (!pass) { + throw new Exception("Test failed at the first invocation." + + "catch it here so the cleanup can continue"); + } + } + + /* + * @testName: simpleasyncforward + * + * @assertion_ids: + * + * @test_Strategy: + */ + @Test + public void simpleasyncforward() throws Exception { + Boolean pass = true; + try { + TEST_PROPS.setProperty(APITEST, "simpleasyncforward"); + TEST_PROPS.setProperty(SEARCH_STRING, + "ForwardedServlet Invoked||simple method"); + invoke(); + } catch (Exception flt) { + pass = false; + TestUtil.logErr("Test failed at the first invocation." + + "catch it here so the cleanup can continue", flt); + } + + TEST_PROPS.setProperty(APITEST, "checkLogSimple"); + invoke(); + + if (!pass) { + throw new Exception("Test failed at the first invocation." + + "catch it here so the cleanup can continue"); + } + } + + /* + * @testName: simpleasyncerror + * + * @assertion_ids: + * + * @test_Strategy: + */ + @Test + public void simpleasyncerror() throws Exception { + Boolean pass = true; + try { + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + + "/TestServlet?testname=simpleasyncerror HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, "403"); + invoke(); + } catch (Exception flt) { + pass = false; + TestUtil.logErr("Test failed at the first invocation." + + "catch it here so the cleanup can continue", flt); + } + + TEST_PROPS.setProperty(APITEST, "checkLogSimple"); + invoke(); + + if (!pass) { + throw new Exception("Test failed at the first invocation." + + "catch it here so the cleanup can continue"); + } + } + + /* + * @testName: error + * + * @assertion_ids: + * + * @test_Strategy: + */ + @Test + public void error() throws Exception { + Boolean pass = true; + try { + TEST_PROPS.setProperty(REQUEST, + "GET " + getContextRoot() + "/TestServlet?testname=error HTTP/1.1"); + + TEST_PROPS.setProperty(STATUS_CODE, "403"); + invoke(); + } catch (Exception flt) { + pass = false; + TestUtil.logErr("Test failed at the first invocation." + + "catch it here so the cleanup can continue", flt); + } + + TEST_PROPS.setProperty(APITEST, "checkLogSimple"); + invoke(); + + if (!pass) { + throw new Exception("Test failed at the first invocation." + + "catch it here so the cleanup can continue"); + } + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/srlistener/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/srlistener/build.xml new file mode 100644 index 0000000000..6cb907ae3f --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/srlistener/build.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/srlistener/servlet_spec_srlistener_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/srlistener/servlet_spec_srlistener_web.xml new file mode 100644 index 0000000000..27b1f6a4b0 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/srlistener/servlet_spec_srlistener_web.xml @@ -0,0 +1,71 @@ + + + + + ServletRequestListener + + com.sun.ts.tests.servlet.spec.srlistener.SRListener + + + TestServlet + com.sun.ts.tests.servlet.spec.srlistener.TestServlet + true + + + IncludedServlet + com.sun.ts.tests.servlet.spec.srlistener.IncludedServlet + true + + + ForwardedServlet + com.sun.ts.tests.servlet.spec.srlistener.ForwardedServlet + true + + + SecondIncludedServlet + com.sun.ts.tests.servlet.spec.srlistener.SecondIncludedServlet + + + SecondForwardedServlet + com.sun.ts.tests.servlet.spec.srlistener.SecondForwardedServlet + + + TestServlet + /TestServlet/* + + + IncludedServlet + /include/IncludedServlet + + + SecondIncludedServlet + /include/SecondIncludedServlet + + + ForwardedServlet + /forward/ForwardedServlet + + + SecondForwardedServlet + /forward/SecondForwardedServlet + + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/webapps/accesswebinf/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/webapps/accesswebinf/URLClient.java new file mode 100644 index 0000000000..935931ad4b --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/webapps/accesswebinf/URLClient.java @@ -0,0 +1,66 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.webapps.accesswebinf; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; + +public class URLClient extends AbstractUrlClient { + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + return ShrinkWrap.create(WebArchive.class, "servlet_spec_webapps_accesswebinf_web.war") + .addAsWebInfResource("spec/webapps/accesswebinf/test.html", "test.html") + .setWebXML(URLClient.class.getResource("servlet_spec_webapps_accesswebinf_web.xml")); + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + * + */ + + /* Run test */ + + /* + * @testName: accessWebInfTest + * + * @assertion_ids: Servlet:SPEC:89 + * + * @test_Strategy: + */ + @Test + public void accessWebInfTest() throws Exception { + String testName = "accessWebInfTest"; + TEST_PROPS.setProperty(TEST_NAME, testName); + TEST_PROPS.setProperty(REQUEST, "GET " + getContextRoot() + "/" + + getServletName() + "/test.html HTTP/1.1"); + TEST_PROPS.setProperty(STATUS_CODE, NOT_FOUND); + + TEST_PROPS.setProperty(UNEXPECTED_RESPONSE_MATCH, "test html page"); + invoke(); + } +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/webapps/accesswebinf/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/webapps/accesswebinf/build.xml new file mode 100644 index 0000000000..389f73ecae --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/webapps/accesswebinf/build.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/webapps/accesswebinf/servlet_spec_webapps_accesswebinf_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/webapps/accesswebinf/servlet_spec_webapps_accesswebinf_web.xml new file mode 100644 index 0000000000..a6333d4a89 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/webapps/accesswebinf/servlet_spec_webapps_accesswebinf_web.xml @@ -0,0 +1,25 @@ + + + + + SerSpecWebappsAccessWebInf + + 54 + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/webapps/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/webapps/build.xml new file mode 100644 index 0000000000..30591c27ba --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/webapps/build.xml @@ -0,0 +1,22 @@ + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/welcomefiles/URLClient.java b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/welcomefiles/URLClient.java new file mode 100644 index 0000000000..8e8f52dd66 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/welcomefiles/URLClient.java @@ -0,0 +1,92 @@ +/* + * 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$ + */ + +package com.sun.ts.tests.servlet.spec.welcomefiles; + +import com.sun.ts.tests.servlet.common.client.AbstractUrlClient; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.Test; + +import java.net.URL; +import java.util.Arrays; + +public class URLClient extends AbstractUrlClient { + + /** + * Deployment for the test + */ + @Deployment(testable = false) + public static WebArchive getTestArchive() throws Exception { + WebArchive webArchive = + ShrinkWrap.create(WebArchive.class, "servlet_js_welcomefiles_web.war") + .setWebXML(URLClient.class.getResource("servlet_js_welcomefiles_web.xml")); + Arrays.asList("foo/index.html","foo/default.jsp","default.jsp", "foo/order.jsp", "index.html", "catalog/default.jsp") + .forEach(s -> webArchive.addAsWebResource("spec/welcomefiles/" +s, s)); + return webArchive; + } + + /* + * @class.setup_props: webServerHost; webServerPort; ts_home; + */ + + /* Run test */ + + /* + * @testName: partialfound1 + * + * @assertion_ids: Servlet:SPEC:141; + * + * @test_Strategy: 1. Create two welcome files + * index.html + * default.jsp 2. Verify + * that a request URI of /foo will be returned as /foo/index.html based on + * Servlet Spec(9.10) + */ + @Test + public void partialfound1() throws Exception { + TEST_PROPS.setProperty(FOLLOW_REDIRECT, "follow_redirect"); + TEST_PROPS.setProperty(SEARCH_STRING, + "||index.html|||INDEX from foo/index.html||"); + TEST_PROPS.setProperty(APITEST, "foo"); + invoke(); + } + + /* + * @testName: partialfound2 + * + * @assertion_ids: Servlet:SPEC:141; + * + * @test_Strategy: 1. Create two welcome files + * index.html + * default.jsp 2. Verify + * that a request URI of /catalog will be returned as /catalog/default.jsp + * based on Servlet Spec(9.10) + */ + @Test + public void partialfound2() throws Exception { + TEST_PROPS.setProperty(FOLLOW_REDIRECT, "follow_redirect"); + TEST_PROPS.setProperty(SEARCH_STRING, "HELLO from catalog/default.jsp"); + TEST_PROPS.setProperty(APITEST, "catalog"); + invoke(); + } + +} diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/welcomefiles/build.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/welcomefiles/build.xml new file mode 100644 index 0000000000..e7cf364976 --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/welcomefiles/build.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/welcomefiles/servlet_js_welcomefiles_web.xml b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/welcomefiles/servlet_js_welcomefiles_web.xml new file mode 100644 index 0000000000..23eac2874e --- /dev/null +++ b/tck/tck-runtime/src/main/java/com/sun/ts/tests/servlet/spec/welcomefiles/servlet_js_welcomefiles_web.xml @@ -0,0 +1,45 @@ + + + + + SerJaxSerWelcome + + DefaultJSP + /default.jsp + + + OrderFooJSP + /foo/order.jsp + + + DefaultFooJSP + /foo/default.jsp + + + DefaultCatalogJSP + /catalog/default.jsp + + + index.html + default.jsp + + + 54 + + diff --git a/tck/tck-runtime/src/main/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension b/tck/tck-runtime/src/main/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension new file mode 100644 index 0000000000..3f33b25099 --- /dev/null +++ b/tck/tck-runtime/src/main/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension @@ -0,0 +1 @@ +com.sun.ts.tests.servlet.common.util.TCKLoadableExtension \ No newline at end of file diff --git a/tck/tck-runtime/src/main/resources/certificates/README b/tck/tck-runtime/src/main/resources/certificates/README new file mode 100644 index 0000000000..47bc5fda80 --- /dev/null +++ b/tck/tck-runtime/src/main/resources/certificates/README @@ -0,0 +1,14 @@ +CTS Client certificate +---------------------- +This directory contains CTS client certificate stored in different file formats. + +1) cts_cert - This file is used for importing cts client cert + into a truststore . + +2) clientcert.jks - This file is used by the JSSE runtime + to identify CTS client's identity + +3) clientcert.p12 - This file contains cts client cert in pkcs12 format. + + +Note: All 3 files in this directory contains the same certificate named "cts" diff --git a/tck/tck-runtime/src/main/resources/certificates/clientcert.jks b/tck/tck-runtime/src/main/resources/certificates/clientcert.jks new file mode 100644 index 0000000000..09f5569c47 Binary files /dev/null and b/tck/tck-runtime/src/main/resources/certificates/clientcert.jks differ diff --git a/tck/tck-runtime/src/main/resources/certificates/clientcert.p12 b/tck/tck-runtime/src/main/resources/certificates/clientcert.p12 new file mode 100644 index 0000000000..409e41e673 Binary files /dev/null and b/tck/tck-runtime/src/main/resources/certificates/clientcert.p12 differ diff --git a/tck/tck-runtime/src/main/resources/certificates/cts_cert b/tck/tck-runtime/src/main/resources/certificates/cts_cert new file mode 100644 index 0000000000..0c3863c852 Binary files /dev/null and b/tck/tck-runtime/src/main/resources/certificates/cts_cert differ diff --git a/tck/tck-util/pom.xml b/tck/tck-util/pom.xml new file mode 100644 index 0000000000..7ffedfd39b --- /dev/null +++ b/tck/tck-util/pom.xml @@ -0,0 +1,42 @@ + + + + + 4.0.0 + + + jakarta.servlet + tck + 6.1.0-SNAPSHOT + + + tck-util + jar + + Jakarta Servlet TCK utilities + + + + org.slf4j + slf4j-api + + + + diff --git a/tck/tck-util/src/main/java/com/sun/ts/lib/util/RemoteLoggingInitException.java b/tck/tck-util/src/main/java/com/sun/ts/lib/util/RemoteLoggingInitException.java new file mode 100644 index 0000000000..1260d05247 --- /dev/null +++ b/tck/tck-util/src/main/java/com/sun/ts/lib/util/RemoteLoggingInitException.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2007, 2018 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$ + */ + +package com.sun.ts.lib.util; + +/** + * This exception is thrown by the init method of the TestUtil class, if + * anything goes wrong while establishing a socket connection back to the + * harness host. + * + * @author Kyle Grucci + */ +public class RemoteLoggingInitException extends Exception { + /** + * creates a RemoteLoggingInitException + */ + public RemoteLoggingInitException() { + super(); + } + + /** + * creates a RemoteLoggingInitException with a message + * + * @param s + * the message + */ + public RemoteLoggingInitException(String s) { + super(s); + } +} diff --git a/tck/tck-util/src/main/java/com/sun/ts/lib/util/TestUtil.java b/tck/tck-util/src/main/java/com/sun/ts/lib/util/TestUtil.java new file mode 100644 index 0000000000..fb37aaf03a --- /dev/null +++ b/tck/tck-util/src/main/java/com/sun/ts/lib/util/TestUtil.java @@ -0,0 +1,1155 @@ +/* + * Copyright (c) 2007, 2018 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$ + */ + +package com.sun.ts.lib.util; + +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.DataOutputStream; +import java.io.EOFException; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.PrintWriter; +import java.io.Serializable; +import java.io.StringWriter; +import java.net.ServerSocket; +import java.net.Socket; +import java.net.URL; +import java.net.URLConnection; +import java.net.URLEncoder; +import java.net.UnknownHostException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Enumeration; +import java.util.Properties; +import java.util.Set; +import java.util.Vector; + +/** + * TestUtil is a final utility class responsible for implementing logging across + * multiple VMs. It also contains many convenience methods for logging property + * object contents, stacktraces, and header lines. + * + * @author Kyle Grucci + * + */ +public final class TestUtil { + public static boolean traceflag = true; + + // this can be set in TestUtil's start logging method!! + public static String sTestName; + + public static final String[] EMPTY_STRING_ARRAY = new String[0]; + + public static final int VM_UNDER_TEST = 0; + + public static final int VM_HARNESS = 1; // this is really the test client VM + + public static final int VM_JAVATEST = 2; + + public static final int DEBUG_OUTPUT_LEVEL = 2; + + public static final int NORMAL_OUTPUT_LEVEL = 3; + + public static final int ERROR_STREAM = 4; + + public static final int OUTPUT_STREAM = 5; + + public static String NEW_LINE = System.getProperty("line.separator", "\n"); + + // by default so the testers don't have to do anything + public static int iWhereAreWe = VM_UNDER_TEST; + + private static PrintWriter out = null; + + private static PrintWriter err = null; + + private static PrintWriter additionalWriter = null; + + private static ObjectOutputStream objectOutputStream = null; + + private static ObjectOutputStream objectInputStream = null; + + private static Socket socketOnRemoteVM = null; + + private static boolean bAlreadyInitialized = false; + + private static Object socketMutex = new Object(); + + private static int portOfHarness = 2000; + + private static String hostOfHarness = "unset host"; + + private static Vector vBuffereredOutput = new Vector(); + + // Transaction Attribute Value Mapping Table + private static final String UNRECOGNIZED_STATUS = "UNRECOGNIZED_STATUS"; + + private static final String transactionTable[] = { "STATUS_ACTIVE", // 0 + "STATUS_MARKED_ROLLBACK", // 1 + "STATUS_PREPARED", // 2 + "STATUS_COMMITTED", // 3 + "STATUS_ROLLEDBACK", // 4 + "STATUS_UNKNOWN", // 5 + "STATUS_NO_TRANSACTION", // 6 + "STATUS_PREPARING", // 7 + "STATUS_COMMITTING", // 8 + "STATUS_ROLLING_BACK", // 9 + }; + + // debug flag for printing TS harness debug output + public static boolean harnessDebug; + + // hang onto the props that are passed in during logging init calls + private static Properties testProps = null; + + private static SimpleDateFormat df = new SimpleDateFormat( + "MM-dd-yyyy HH:mm:ss"); + + static { + harnessDebug = Boolean.getBoolean("cts.harness.debug"); + } + + /** + * used by harness to log debug output to the standard output stream + * + * @param s + * the output string + */ + public static void logHarnessDebug(String s) { + if (harnessDebug) { + logHarness(s, null); + } + } + + /** + * used by TSTestFinder and TSScript to log output to the standard output + * stream + * + * @param s + * the output string + * @param t + * a Throwable whose stacktrace gets printed + */ + public static void logHarness(String s, Throwable t) { + synchronized (System.out) { + System.out.println(df.format(new Date()) + ": Harness - " + s); + logToAdditionalWriter(s, t); + if (t != null) { + t.printStackTrace(); + } + } + } + + public static void logHarness(String s) { + logHarness(s, null); + } + + private static void logToAdditionalWriter(String s) { + logToAdditionalWriter(s, null); + } + + private static void logToAdditionalWriter(String s, Throwable t) { + if (additionalWriter != null) + additionalWriter.println(s); + if (t != null) { + t.printStackTrace(additionalWriter); + } + } + + /** + * This method returns the properties object + * + * @return the properties object + */ + public static Properties getProperties() { + if (testProps == null) { + testProps = getPropsFromFile(); + } + return testProps; + } + + /** + * This method returns the property value for the appropriate property key + * + * @param s + * the property name + * @return the property value + */ + public static String getProperty(String s) { + Properties p = getProperties(); + return p.getProperty(s); + } + + /** + * This method returns the property value for the appropriate property key + * + * @param s + * the property name + * @return the property value + */ + public static String getProperty(String s, String defaultValue) { + Properties p = getProperties(); + return p.getProperty(s, defaultValue); + } + + /** + * returns the transaction status value as a String given its integer + * representation + * + * @param status + * integer representation of a transaction status + * @return string representation of a transaction status + */ + public static String getTransactionStatus(int status) { + if (status < 0 || status > transactionTable.length - 1) + return UNRECOGNIZED_STATUS; + else + return transactionTable[status]; + } + + /** + * prints the transaction status value as a String given its integer + * representation + * + * @param status + * integer representation of a transaction status + */ + public static void printTransactionStatus(int status) { + logMsg("TRANSACTION_STATUS: " + getTransactionStatus(status)); + } + + // MilliSeconds Multiple + public static final int MILLI = 1000; + + /** + * pauses the calling thread for the specified number of seconds + * + * @param s + * number of seconds + */ + public static void sleepSec(int s) { + logTrace("Sleeping " + s + " seconds"); + try { + Thread.sleep(s * MILLI); + } catch (InterruptedException e) { + logErr("Exception: " + e); + } + } + + /** + * pauses the calling thread for the specified number of milliseconds + * + * @param s + * number of milliseconds + */ + public static void sleep(int s) { + sleepMsec(s); + } + + /** + * pauses the calling thread for the specified number of milliseconds + * + * @param s + * number of milliseconds + */ + public static void sleepMsec(int s) { + logTrace("Sleeping " + s + " milliseconds"); + try { + Thread.sleep(s); + } catch (InterruptedException e) { + logErr("Exception: " + e); + } + } + + public static void flushStream() { + synchronized (socketMutex) { + try { + objectOutputStream.flush(); + } catch (Throwable t) { + // Ignore + // System.out.println("EXCEPTION WHILE FLUSHING"); + } + } + } + + public static void writeObject(TestReportInfo info) { + synchronized (socketMutex) { + flushStream(); + try { + objectOutputStream.writeObject(info); + // System.out.println("WROTE: " + info.sOutput); + } catch (Exception e) { + // System.out.println("EXCEPTION WHILE WRITING: " + info.sOutput); + synchronized (vBuffereredOutput) { + vBuffereredOutput.addElement(info); + // System.out.println("ADDED THIS STRING TO BUFFERED OUT: " + + // info.sOutput); + } + } + flushStream(); + } + } + + private static void sendBufferedData() throws Exception { + TestReportInfo tri = null; + synchronized (vBuffereredOutput) { + try { + // logMsg("vBuffereredOutput size = " + vBuffereredOutput.size()); + synchronized (socketMutex) { + for (int ii = 0; ii < vBuffereredOutput.size(); ii++) { + tri = (TestReportInfo) vBuffereredOutput.elementAt(ii); + writeObject(tri); + // System.out.println("WRITING_bufferedoutput: " + tri.sOutput); + // objectOutputStream.writeObject(tri); + // objectOutputStream.flush(); + // logMsg("writing: " + ii); + // logMsg("writing: " + tri.sOutput); + } + } + // logMsg("wrote buffered output"); + } catch (Exception e) { + throw e; + } finally { + vBuffereredOutput.removeAllElements(); + // logMsg("reinititialized buffered output vector"); + } + } + } + + private static final String PROPS_FILE_NAME = "-cts-props.txt"; + + private static final String PROPS_FILE; + + static { + String userName = System.getProperty("user.name"); + String tmpDir = System.getProperty("java.io.tmpdir", + File.separator + "tmp"); + if (tmpDir.endsWith(File.separator)) { + PROPS_FILE = tmpDir + userName + PROPS_FILE_NAME; + } else { + PROPS_FILE = tmpDir + File.separator + userName + PROPS_FILE_NAME; + } + System.out.println( + "************************************************************"); + System.out.println("* props file set to \"" + PROPS_FILE + "\""); + System.out.println( + "************************************************************"); + } + + private static Properties getPropsFromFile() { + FileInputStream in = null; + Properties p = new Properties(); + try { + in = new FileInputStream(PROPS_FILE); + p.load(in); + } catch (Exception e) { + logErr("Error reading the Properties object", e); + } finally { + if (in != null) { + try { + in.close(); + } catch (Exception e) { + } + } + } + return p; + } + + private static void savePropsToFile(Properties p) { + try (FileOutputStream out = new FileOutputStream(PROPS_FILE)) { + p.store(out, "CTS Test Properties File"); + } catch (Exception e) { + logErr("Error saving the Properties object", e); + } + } + + /** + * This static method must be called once by each new remote VM. Once called, + * a socket connection is created back to the host running the test harness. + * All calls to logMsg, logErr, and logTrace are immediately sent back to the + * harness host. + * + * @param p + * properties containing harness host, port, and trace flag + * @exception RemoteLoggingInitException + * if an exception occurs while the server side is setting up the + * socket connection back to the client host + */ + public static void init(Properties p) throws RemoteLoggingInitException { + savePropsToFile(p); // persist properties to a disk file + // System.out.println("INIT_CALLED"); + synchronized (socketMutex) { + try { + // TSPropertyManager.createTSPropertyManager(p); + testProps = p; + if (p.isEmpty()) { + throw new RemoteLoggingInitException( + "Init: Error - Empty properties object passed to TestUtil.init"); + } + NEW_LINE = p.getProperty("line.separator"); + if (socketOnRemoteVM != null) { + socketOnRemoteVM.close(); + } + if (objectOutputStream != null) { + objectOutputStream.close(); + } + if (true) { + // System.out.println("INIT_CALLED AND SOCKET = NULL"); + traceflag = Boolean.parseBoolean(p.getProperty("harness.log.traceflag", "true")); + hostOfHarness = p.getProperty("harness.host"); + portOfHarness = Integer + .parseInt(p.getProperty("harness.log.port", "2000")); + if (hostOfHarness == null) { + throw new RemoteLoggingInitException( + "Init: Error while trying to getProperty(harness.host) - returned null"); + } + socketOnRemoteVM = new Socket(hostOfHarness, portOfHarness); + objectOutputStream = new ObjectOutputStream( + socketOnRemoteVM.getOutputStream()); + sendBufferedData(); + // logMsg("socketOnRemoteVM=null, renewed everything"); + } else { + // we'll never get here now... + // call flush to make sure that we still have an open connection. + // if the client went away and a new client is being run, we will + // get an IOException, in which case we will reconnect. + // logMsg("socketOnRemoteVM != null, calling flush"); + // objectOutputStream.flush(); + // if this fails, then the connection is gone + // this is better than flush, because flush seems to always fail + TestReportInfo tri = new TestReportInfo("SVR: " + "Logging check", + OUTPUT_STREAM, DEBUG_OUTPUT_LEVEL, null); + objectOutputStream.writeObject(tri); + // System.out.println("WROTE TEST OBJECT"); + } + } catch (UnknownHostException e) { + throw new RemoteLoggingInitException( + "You must pass a valid host string to init()"); + } catch (IOException e) { + // System.out.println("EXCEPTION WHILE WRITING TEST OBJECT"); + // the client VM may have shutdown, so establish a new connection + try { + // System.out.println("INIT_CALLED AND TRYING TO ESABLISH CONN. AFTER + // IOEXCEPTION"); + traceflag = Boolean.parseBoolean(p.getProperty("harness.log.traceflag", "true")); + hostOfHarness = p.getProperty("harness.host"); + portOfHarness = Integer + .parseInt(p.getProperty("harness.log.port", "2000")); + if (hostOfHarness == null) { + throw new RemoteLoggingInitException( + "Init: Error while trying to getProperty(harness.host) - returned null"); + } + socketOnRemoteVM.close(); + socketOnRemoteVM = new Socket(hostOfHarness, portOfHarness); + objectOutputStream = new ObjectOutputStream( + socketOnRemoteVM.getOutputStream()); + sendBufferedData(); + // logMsg("caught IOException from flush(), renewed everything"); + } catch (IOException e2) { + e2.printStackTrace(); + throw new RemoteLoggingInitException( + "IOException in TestUtil.init()"); + } catch (Exception e2) { + e2.printStackTrace(); + throw new RemoteLoggingInitException( + "got a random exception in init()"); + } + } catch (NumberFormatException e) { + throw new RemoteLoggingInitException( + "You must pass a valid port number string to init()"); + } catch (Exception e) { + e.printStackTrace(); + throw new RemoteLoggingInitException( + "got a random exception in init()"); + } + } + } + + /* + * This method is called by our harness code to allow code that is shared + * between the harness and the tests and calls TestUtil logMsg and logTrace to + * do the right thing inside of the JavaTest VM. These calls will call to our + * logHarness methods. + */ + public static void initJavaTest() { + iWhereAreWe = VM_JAVATEST; + } + + public static void setAdditionalWriter(PrintWriter pw) { + iWhereAreWe = VM_JAVATEST; + additionalWriter = pw; + } + + /** + * This static method must be called once by a VM which does not rely upon any + * remote logging. + * + * param p properties containing harness trace flag + */ + public static void initNoLogging(Properties p) { + if (bAlreadyInitialized) + return; + + testProps = p; + NEW_LINE = p.getProperty("line.separator"); + traceflag = Boolean.parseBoolean(p.getProperty("harness.log.traceflag", "true")); + iWhereAreWe = VM_HARNESS; + bAlreadyInitialized = true; + } + + /** + * This static method must be called once by the harness VM. Once called, a + * serversocket begins listening for Remote VMs to connect on the port + * specified by harness.log.port. + * + * @param p + * properties containing harness trace flag + */ + public static void initClient(Properties p) { + if (bAlreadyInitialized) + return; + // start listener thread + try { + testProps = p; + NEW_LINE = p.getProperty("line.separator"); + traceflag = Boolean.parseBoolean(p.getProperty("harness.log.traceflag", "true")); + iWhereAreWe = VM_HARNESS; + ServerSocket ss = getServerSocket(p); + new Acceptor(ss); + bAlreadyInitialized = true; + } catch (IOException e) { + e.printStackTrace(); + } + } + + private static ServerSocket getServerSocket(Properties p) throws IOException { + ServerSocket result = null; + int port = 2000; + int retry = 10; + final int delaySeconds = 1; + try { + port = Integer.parseInt(p.getProperty("harness.log.port", "2000")); + } catch (NumberFormatException e1) { + e1.printStackTrace(); + System.err.println("Invalid value for harness.log.port," + + " using default harness.log.port of " + port); + } + try { + retry = Integer + .parseInt(p.getProperty("harness.socket.retry.count", "10")); + } catch (NumberFormatException e2) { + e2.printStackTrace(); + System.err.println("Invalid value for harness.socket.retry.count," + + " using default harness.socket.retry.count of " + retry); + } + logTrace( + "####### Value of harness.socket.retry.count is \"" + retry + "\""); + logTrace("####### Value of harness.log.port is \"" + port + "\""); + result = getServerSocket0(port, retry, delaySeconds); + while (result == null) { + port++; + result = getServerSocket0(port, retry, delaySeconds); + } + p.setProperty("harness.log.port", Integer.toString(port)); + logTrace( + "####### Actual bind value of harness.log.port is \"" + port + "\""); + return result; + } + + private static ServerSocket getServerSocket0(int port, int retry, + int delaySeconds) { + ServerSocket result = null; + for (int i = 0; i < retry; i++) { + try { + result = new ServerSocket(port); + break; + } catch (IOException e3) { + try { + Thread.sleep(delaySeconds * 1000); + } catch (InterruptedException e4) { + } + } + } + return result; + } + + /** + * This static method must be called once by the harness VM in order to set + * the output and error streams and the name of the current test. + * + * @param testName + * the currently running testname as specified in the source code + * tags + * @param outStream + * stream printed to by the logMsg and logTrace methods + * @param errStream + * stream printed to by the logErr methods + */ + public static void setCurrentTest(String testName, PrintWriter outStream, + PrintWriter errStream) { + sTestName = testName; + out = outStream; + err = outStream; + } + + /** + * prints a string to the log stream. All tests should use this method for + * standard logging messages + * + * @param s + * string to print to the log stream + */ + public static void logMsg(String s) { + if (iWhereAreWe == VM_JAVATEST) { + logHarness(s); + } else if (iWhereAreWe == VM_HARNESS) { + synchronized (out) { + // just print to the appropriate stream + out.println(df.format(new Date()) + ": " + s); + out.flush(); + } + } else { + TestReportInfo tri = new TestReportInfo("SVR: " + s, OUTPUT_STREAM, + NORMAL_OUTPUT_LEVEL, null); + writeObject( + tri); /* + * try { synchronized(socketMutex) { objectOutputStream.flush(); + * objectOutputStream.writeObject(tri); + * objectOutputStream.flush(); //System.out. + * println("successfully wrote to objectOutputStream"); } } + * catch(Exception ex) { //System.out. + * println("got exception trying to write to objectOutputStream" + * ); //if we have any problem, buffer the data + * synchronized(vBuffereredOutput) { + * vBuffereredOutput.addElement(tri); } } + */ + + } + } + + /** + * prints a string as well as the provided Throwable's stacktrace to the log + * stream. All tests should use this method for standard logging messages + * + * @param s + * string to print to the log stream + * @param t + * - throwable whose stacktrace gets printed* + * + */ + public static void logMsg(String s, Throwable t) { + if (iWhereAreWe == VM_JAVATEST) { + logHarnessDebug(s); + if (t != null) { + t.printStackTrace(); + } + } else { + if (iWhereAreWe == VM_HARNESS) { + synchronized (out) { + // just print to the appropriate stream + out.println(df.format(new Date()) + ": " + s); + out.flush(); + } + } else { + TestReportInfo tri = new TestReportInfo("SVR: " + s, OUTPUT_STREAM, + NORMAL_OUTPUT_LEVEL, null); + writeObject(tri); + } + if (t != null) { + printStackTrace(t); + } + } + + } + + /** + * turns on/off debugging. Once on, all calls to the logTrace method result in + * messages being printed to the log stream. If off, all logTrace calls are + * not printed. + * + * @param b + * If true, debugging is on. If false, debugging is + * turned off. + */ + public static void setTrace(boolean b) { + traceflag = b; + } + + /** + * prints a debug string to the log stream. All tests should use this method + * for verbose logging messages. Whether or not the string is printed is + * determined by the last call to the setTrace method. + * + * @param s + * string to print to the log stream + */ + public static void logTrace(String s) { + logTrace(s, null); + } + + /** + * Prints a debug string as well as the provided Throwable's stacktrace. Use + * this if certain exceptions are only desired while tracing. + * + * @param s + * - string to print to the log stream + * @param t + * - throwable whose stactrace gets printed + */ + public static void logTrace(String s, Throwable t) { + if (traceflag) { + if (iWhereAreWe == VM_JAVATEST) { + logHarnessDebug(s); + } else { + if (iWhereAreWe == VM_HARNESS) { + synchronized (out) { + // just print to the appropriate stream + if (s != null && s.startsWith("SVR-TRACE")) + out.println(df.format(new Date()) + ": " + s); + else + out.println(df.format(new Date()) + ": TRACE: " + s); + } + } else { + TestReportInfo tri = new TestReportInfo("SVR-TRACE: " + s, + OUTPUT_STREAM, DEBUG_OUTPUT_LEVEL, null); + writeObject(tri); + } + } + if (t != null) { + t.printStackTrace(); + } + } + } + + /** + * prints an error string to the error stream. All tests should use this + * method for error messages. + * + * @param s + * string to print to the error stream + * @param e + * a Throwable whose stacktrace gets printed + */ + public static void logErr(String s, Throwable e) { + if (iWhereAreWe == VM_JAVATEST) { + logHarness(s); + if (e != null) { + e.printStackTrace(); + } + } else { + if (iWhereAreWe == VM_HARNESS) { + synchronized (err) { + // just print to the appropriate stream + if (s != null && s.startsWith("SVR-ERROR")) + err.println(df.format(new Date()) + ": " + s); + else + err.println(df.format(new Date()) + ": ERROR: " + s); + } + } else { + TestReportInfo tri = new TestReportInfo("SVR-ERROR: " + s, ERROR_STREAM, + NORMAL_OUTPUT_LEVEL, null); + writeObject(tri); + } + if (e != null) { + printStackTrace(e); + } + } + } + + /** + * prints an error string to the error stream. All tests should use this + * method for error messages. + * + * @param s + * string to print to the error stream + */ + public static void logErr(String s) { + logErr(s, null); + } + + /** + * prints the contents of a properties object to the logging stream + * + * @param p + * properties to print + */ + public static void list(Properties p) { + StringBuffer sb = new StringBuffer(); + if (p == null) + return; + sb.append("--- Property Listing ---").append(TestUtil.NEW_LINE); + Enumeration e = p.propertyNames(); + String key = null; + while (e.hasMoreElements()) { + key = (String) e.nextElement(); + sb.append(key).append("=").append(p.getProperty(key)) + .append(TestUtil.NEW_LINE); + } + sb.append("--- End Property Listing ---").append(TestUtil.NEW_LINE); + logTrace(new String(sb)); + } + + /** + * prints the stacktrace of a Throwable to the logging stream + * + * @param e + * exception to print the stacktrace of + */ + public static void printStackTrace(Throwable e) { + if (e == null) { + return; + } + try { + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + e.printStackTrace(writer); + logErr(sw.toString()); + writer.close(); + } catch (Exception E) { + } + } + + /** + * prints the stacktrace of a Throwable to a string + * + * @param e + * exception to print the stacktrace of + */ + public static String printStackTraceToString(Throwable e) { + String sTrace = ""; + if (e == null) + return ""; + try { + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + e.printStackTrace(writer); + sTrace = sw.toString(); + writer.close(); + } catch (Exception E) { + } + return sTrace; + } + + /** + * prints a line of asterisks to the logging stream + */ + public static void separator2() { + logMsg("**************************************************" + + "******************************"); + } + + /** + * prints a line of dashes to the logging stream + */ + public static void separator1() { + logMsg("--------------------------------------------------" + + "------------------------------"); + } + + /** + * Convience method to handle sucking in the data from a connection. + */ + public static String getResponse(URLConnection connection) + throws IOException { + StringBuffer content; + BufferedReader in; + // set up the streams / readers + InputStream instream = connection.getInputStream(); + InputStreamReader inreader = new InputStreamReader(instream); + in = new BufferedReader(inreader); + // data structures + content = new StringBuffer(1024); + char[] chars = new char[1024]; + int length = 0; + // pull the data into the content buffer + while (length != -1) { + content.append(chars, 0, length); + length = in.read(chars, 0, chars.length); + } + // return + instream.close(); // john feb 16 + inreader.close(); // john feb 16 + in.close(); // john feb 16 + return content.toString(); + } + + /** + * Loads any properties that might be in a given String. + */ + public static Properties getResponseProperties(String string) + throws IOException { + Properties props; + ByteArrayInputStream in; + byte[] bytes; + props = new Properties(); + bytes = string.getBytes(); + in = new ByteArrayInputStream(bytes); + props.load(in); + in.close(); + return props; + } + + /** + * One shot method to get Properties directly from a URLConnection. + */ + public static Properties getResponseProperties(URLConnection connection) + throws IOException { + Properties props; + String input; + input = getResponse(connection); + props = getResponseProperties(input); + return props; + } + + public static String toEncodedString(Properties args) { + StringBuffer buf = new StringBuffer(); + Enumeration names = args.propertyNames(); + while (names.hasMoreElements()) { + String name = (String) names.nextElement(); + String value = args.getProperty(name); + buf.append(URLEncoder.encode(name)).append("=") + .append(URLEncoder.encode(value)); + if (names.hasMoreElements()) + buf.append("&"); + } + return buf.toString(); + } + + public static URLConnection sendPostData(Properties p, URL url) + throws IOException { + TestUtil.logMsg("Openning url connection to: " + url.toString()); + URLConnection urlConn = url.openConnection(); + // Begin POST of properties to SERVLET + String argString = TestUtil.toEncodedString(p); + urlConn.setDoOutput(true); + urlConn.setDoInput(true); + urlConn.setUseCaches(false); + DataOutputStream out = new DataOutputStream(urlConn.getOutputStream()); + out.writeBytes(argString); + out.flush(); + out.close(); + // End POST + return urlConn; + } + + /** + * Parse a the table name from the ddl string such as: "create table foo" or + * "delete from foo" + * + * @param value + * buffer to parse + * @return The name of the table + */ + public static String getTableName(String value) { + String tableName = ""; + if (value != null) { + tableName = value.trim(); + int pos = tableName.lastIndexOf(" "); + tableName = tableName.substring(pos + 1); + } else { + TestUtil.logMsg("Error: Null value passed for table Name"); + } + return (tableName); + } // END -- getTableName + + public static String srcToDist(String src) { + return replaceLastSrc(src, "dist"); + } + + public static String replaceLastSrc(String src, String replacement) { + // find last index of /src/, remove "src", then replace it with replacement + StringBuffer sbToConvert = new StringBuffer(src); + int iStart = src.lastIndexOf("src"); + if (iStart != -1) { + if (harnessDebug) { + TestUtil.logHarnessDebug("Pre-converted src dir = " + sbToConvert); + } + sbToConvert.replace(iStart, iStart + 3, replacement); + + if (harnessDebug) { + TestUtil.logHarnessDebug( + "Converted " + replacement + " dir = " + sbToConvert); + } + } + return sbToConvert.toString(); + } + + public static String getDistString() { + // we may need to default to src until we are ready to convert for good + return "dist"; + } + + public static String getRelativePath(String oldVal) { + if (oldVal == null) { + return oldVal; + } + String result = oldVal; + oldVal = oldVal.replace('\\', '/'); + while (oldVal.endsWith("/")) { + oldVal = oldVal.substring(0, oldVal.length() - 1); + } + if (oldVal.endsWith("/src")) { + return result; + } + int pos = oldVal.indexOf("/src/"); + if (pos == -1) { + pos = oldVal.indexOf("/dist/"); + if (pos == -1) { + result = oldVal; + } else { + result = oldVal.substring(pos + 6); // len of '/dist/' + } + } else { + result = oldVal.substring(pos + 5); + } + return result; + } + + // Convert the given string of key-value-pair into a properties object + // + // for example : + // DatabaseName=derbyDB:user=cts1:password=cts1:serverName=localhost:portNumber=1527 + // + public static Properties strToProps(String strProps) { + + logTrace("Props String = " + strProps); + Properties props = new Properties(); + String strArray[] = strProps.split(":"); // Split the given string into + // array of key value pairs + + for (String keyValuePair : strArray) { + String strArray2[] = keyValuePair.split("="); // Take the key value pair + // and store it into + // properties + logTrace("Setting property " + strArray2[0] + " = " + strArray2[1]); + props.setProperty(strArray2[0], strArray2[1]); + } + + return props; + + } + + public static void printProperties(Properties props) { + Set propertyNames = props.stringPropertyNames(); + for (String key : propertyNames) { + logTrace(key + " = " + props.getProperty(key)); + } + } + +} + +// ======================= end of class TestUtil ====================== + +class Acceptor extends Thread { + ServerSocket serverSocket; + + private Socket outputSocket = null; + + public Acceptor(ServerSocket ss) { + serverSocket = ss; + this.start(); + } + + public void run() { + while (true) { + try { + outputSocket = serverSocket.accept(); + new SocketReader(outputSocket); + // System.out.println("new connection!!!!!"); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + } +} + +class TestReportInfo implements Serializable { + public int iDebugLevel = TestUtil.NORMAL_OUTPUT_LEVEL; + + public String sOutput = ""; // Constants.EMPTY_STRING; + + public Throwable exception = null; + + public int iStream = TestUtil.OUTPUT_STREAM; + + public TestReportInfo(String output, int stream, int level, Throwable e) { + if (sOutput != null) + sOutput = output; + iDebugLevel = level; + exception = e; + iStream = stream; + } +} + +class SocketReader extends Thread { + private Socket outputSocket = null; + + public SocketReader(Socket s) { + outputSocket = s; + this.start(); + } + + public void run() { + ObjectInputStream objIn; + TestReportInfo tri = null; + try { + objIn = new ObjectInputStream(outputSocket.getInputStream()); + // while((tri = (TestReportInfo)objIn.readObject()) != null) + while (true) { + tri = (TestReportInfo) objIn.readObject(); + if (tri.iDebugLevel == TestUtil.DEBUG_OUTPUT_LEVEL) { + // System.out.println("about to call logTrace"); + TestUtil.logTrace(tri.sOutput); + } else { + if (tri.iStream == TestUtil.ERROR_STREAM) { + if (tri.exception == null) + TestUtil.logErr(tri.sOutput); + else + TestUtil.logErr(tri.sOutput, tri.exception); + // System.out.println("about to call logErr"); + } else // assume outputstream + { + // System.out.println("about to call logMsg"); + TestUtil.logMsg(tri.sOutput); + } + } + } + } catch (EOFException e) { + // do nothing since the eof broke us out of the loop + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + // cleanup socket no matter what happens + /* + * try { outputSocket.close(); outputSocket = null; } catch(IOException e) { + * + * } + */ + } +} diff --git a/tck/tck-util/src/main/java/com/sun/ts/lib/util/WebUtil.java b/tck/tck-util/src/main/java/com/sun/ts/lib/util/WebUtil.java new file mode 100644 index 0000000000..99c1aafe75 --- /dev/null +++ b/tck/tck-util/src/main/java/com/sun/ts/lib/util/WebUtil.java @@ -0,0 +1,333 @@ +/* + * Copyright (c) 2007, 2018 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$ + */ + +package com.sun.ts.lib.util; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.net.ConnectException; +import java.net.InetAddress; +import java.net.MalformedURLException; +import java.net.Socket; +import java.net.URL; +import java.net.UnknownHostException; +import java.util.Base64; +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Properties; +import java.util.StringTokenizer; + +/** + * Contains convenience methods for interacting with a web server. + * + * @author Mark Roth + */ +public class WebUtil { + + /** + * Reponse object containing information returned from the web server + */ + public static class Response { + /** Version (usually HTTP/1.0) */ + public String versionToken; + + /** Status (e.g. 401) */ + public String statusToken; + + /** Location (for redirections) */ + public String location; + + /** Actual page content */ + public String content = ""; + + /** Storage for cookies */ + public Hashtable cookies = new Hashtable(); + + /** Flag; true if authentication requested */ + public boolean authenticationRequested = false; + + /** + * Parses a header line for an old-style cookie (not Set-Cookie2), and + * stores the cookie in the cookies table. Only the key and value are + * stored. Expected syntax: "Set-Cookie: NAME=VALUE[;...]" The key is stored + * in upper-case. + * + * @param cookieLine + * The string with the cookie in it. + */ + public void parseCookie(String cookieLine) { + // Strip Set-Cookie: from line: + cookieLine = cookieLine.substring("Set-Cookie:".length()).trim(); + + // Strip any additional parameters from the end of the line. + int semicolon = cookieLine.indexOf(";"); + if (semicolon != -1) { + cookieLine = cookieLine.substring(0, semicolon).trim(); + } + + // Now we have "NAME=VALUE" + int equals = cookieLine.indexOf("="); + String name = cookieLine.substring(0, equals).toUpperCase(); + String value = cookieLine.substring(equals + 1); + cookies.put(name.trim(), value.trim()); + } + + /** + * Returns true if the status token for this response represents an error, + * or false if the status token indicates the page was retrieved okay. Note + * that a redirection is not an error. + */ + public boolean isError() { + // According to RFC2616, all status tokens staring with 4xx or 5xx + // are errors. + return statusToken.startsWith("4") || statusToken.startsWith("5"); + } + } + + /** + * Converts a standard URL to a request. For example, the string + * "http://goodtimes:8000/testing" would be converted to "/testing". + * + * @param urlString + * The URL to convert + * @return The resulting GET request + * @exception MalformedURLException + * Thrown if the urlString does not contain a valid URL. + */ + public static String getRequestFromURL(String urlString) + throws MalformedURLException { + URL url = new URL(urlString); + return url.getFile(); + } + + /** + * Sends a request to the web server. A WebUtil.Response object is returned + * with the response information. + * + * @param method + * Can be either "GET" or "POST" + * @param addr + * Address of web server + * @param port + * Port of web server + * @param req + * The file to request (e.g. /jsp_dep_secContextRoot/jspSec.jsp) + * @param postData + * If this is a POST request, the data to be posted, encoded in a + * Properties class. null if no post data to be sent. + * @param cookieList + * A list of cookies to send when requesting the page. null if no + * cookie list is to be sent. + * @return WebUtil.Response object containing response information + * @exception IOException + * Thrown if request could not be made + */ + public static Response sendRequest(String method, InetAddress addr, int port, + String req, Properties postData, Hashtable cookieList) + throws IOException { + return sendAuthenticatedRequest(method, addr, port, req, postData, + cookieList, null, null); + } + + /** + * Sends an authenticated request to the web server. A WebUtil.Response object + * is returned with the response information. + * + * @param method + * Can be either "GET" or "POST" + * @param addr + * Address of web server + * @param port + * Port of web server + * @param req + * The file to request (e.g. /jsp_dep_secContextRoot/jspSec.jsp) + * @param postData + * If this is a POST request, the data to be posted, encoded in a + * Properties class. null if no post data to be sent. + * @param cookieList + * A list of cookies to send when requesting the page. null if no + * cookie list is to be sent. + * @param username + * The username for authentication, null if no authentication + * required. + * @param password + * The password for authentication, null if no authentication + * required. + * @return WebUtil.Response object containing response information + * @exception IOException + * Thrown if request could not be made + */ + public static Response sendAuthenticatedRequest(String method, + InetAddress addr, int port, String req, Properties postData, + Hashtable cookieList, String username, String password) + throws IOException { + String protocol = "HTTP/1.0"; + URL requestURL; + Socket socket = null; + PrintWriter out = null; + BufferedReader in = null; + String line = null; + Response response = new Response(); + String hostname = null; + + try { + hostname = addr.getHostName(); + requestURL = new URL("http", hostname, port, req); + req = method + " " + req + " " + protocol; + + socket = new Socket(addr, port); + + in = new BufferedReader(new InputStreamReader(socket.getInputStream())); + out = new PrintWriter(new OutputStreamWriter(socket.getOutputStream())); + send(out, req); + + // send Host header + if (port == 80) { + send(out, "Host: " + hostname); + } else { + send(out, "Host: " + hostname + ':' + port); + } + + if (cookieList != null) { + // Send cookies: + Enumeration keys = cookieList.keys(); + + // Does at least one cookie exist? + if (keys.hasMoreElements()) { + String cookieString = "Cookie: "; + + // Add each cookie to the string + boolean first = true; + while (keys.hasMoreElements()) { + String key = (String) keys.nextElement(); + String value = (String) cookieList.get(key); + cookieString += (first ? "" : "; ") + key + "=" + value; // + "; + // $Path=/"; + first = false; + } + + // Write cookies: + send(out, cookieString); + } + } + + // Send authentication information if necessary: + if (username != null) { + String code = encodeBase64(username + ":" + password); + send(out, "Authorization: Basic " + code.trim()); + } + + // Send extra header information if we are posting. + if (postData != null) { + send(out, "Content-type: application/x-www-form-urlencoded"); + } + + // If this is a post request, send post data: + if ((postData != null) && method.toUpperCase().equals("POST")) { + String postString = TestUtil.toEncodedString(postData); + + // Skip a line: + send(out, "Content-length: " + postString.length()); + send(out, ""); + send(out, postString); + } else { + // Skip a line: + send(out, ""); + } + + out.flush(); + + // Read first line and check for HTTP version and OK. + line = in.readLine(); + if (line != null) { + TestUtil.logTrace("HEADER: " + line); + + StringTokenizer st = new StringTokenizer(line.trim()); + response.versionToken = st.nextToken(); + response.statusToken = st.nextToken(); + } + + // Read each line of the header until we hit a blank line + while ((line = in.readLine()) != null) { + TestUtil.logTrace("HEADER: " + line); + + // Blank line means we are done with the header: + if (line.trim().equals("")) + break; + + // Analyze special tags location and set cookie + if (line.toLowerCase().startsWith("location:")) { + // This is a redirect. Extract valuable infomration: + response.location = line.substring(10); + } else if (line.toLowerCase().startsWith("set-cookie:")) { + // This is a cookie. Add the cookie to the response + // object. + response.parseCookie(line); + } else if (line.toLowerCase().startsWith("www-authenticate:")) { + // Request to authenticate this page. + response.authenticationRequested = true; + } + } + + // The rest is content: + while ((line = in.readLine()) != null) { + response.content += line + "\n"; + } + + in.close(); + out.close(); + } catch (MalformedURLException e) { + throw new IOException("MalformedURLException: " + e.getMessage()); + } catch (UnknownHostException e) { + throw new IOException("UnknownHostException: " + e.getMessage()); + } catch (ConnectException e) { + throw new IOException("ConnectException: " + e.getMessage()); + } + + return response; + } + + /** + * Outputs a single line of text to the given output stream. Appends a \r\n + * automatically. By adding a System.out.println here, you can easily echo + * what is being sent to the web server. + */ + private static void send(PrintWriter out, String s) { + out.print(s + "\r\n"); + TestUtil.logTrace("REQUEST: " + s); + } + + /** + * Encodes the given string in base64 format (useful for BASIC + * authentication). Base64 encoding is defined by RFC2047. + * + * @param s + * The string to encode + * @return The encoded string + */ + public static String encodeBase64(String s) { + return new String(Base64.getEncoder().encode(s.getBytes())); +// BASE64Encoder encoder = new BASE64Encoder(); +// return encoder.encodeBuffer(s.getBytes()); + } +}