Author: jharting
Date: 2009-10-27 07:57:40 -0400 (Tue, 27 Oct 2009)
New Revision: 4347
Added:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/Result.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/TestHttpSessionListener.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/TestServlet.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/TestServletContextListener.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/TestServletRequestListener.java
Removed:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ServiceMethodServlet.java
Modified:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ApplicationContextTest.java
cdi-tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/context/application/web.xml
Log:
Tests for section 6.7.3
Modified:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ApplicationContextTest.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ApplicationContextTest.java 2009-10-27
06:48:52 UTC (rev 4346)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ApplicationContextTest.java 2009-10-27
11:57:40 UTC (rev 4347)
@@ -1,3 +1,19 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.jboss.jsr299.tck.tests.context.application;
import org.jboss.jsr299.tck.AbstractJSR299Test;
@@ -15,6 +31,7 @@
/**
* @author David Allen
+ * @author Jozef Hartinger
*/
@Artifact
@IntegrationTest(runLocally=true)
@@ -32,7 +49,7 @@
{
WebClient webClient = new WebClient();
webClient.setThrowExceptionOnFailingStatusCode(true);
- webClient.getPage(getContextPath() + "serviceMethodTest");
+ webClient.getPage(getContextPath() + "TestServlet?test=servlet");
}
@Test(groups = { "contexts", "servlet", "integration"
})
@@ -43,6 +60,31 @@
webClient.setThrowExceptionOnFailingStatusCode(true);
webClient.getPage(getContextPath() + "SimplePage.html");
}
+
+
+ @Test(groups = { "contexts", "integration" })
+ @SpecAssertion(section = "6.7.3", id = "ac")
+ public void testApplicationScopeActiveDuringServletContextListenerInvocation() throws
Exception {
+ WebClient webClient = new WebClient();
+ webClient.setThrowExceptionOnFailingStatusCode(true);
+ webClient.getPage(getContextPath() +
"TestServlet?test=servletContextListener");
+ }
+
+ @Test(groups = { "contexts", "integration" })
+ @SpecAssertion(section = "6.7.3", id = "ad")
+ public void testApplicationScopeActiveDuringHttpSessionListenerInvocation() throws
Exception {
+ WebClient webClient = new WebClient();
+ webClient.setThrowExceptionOnFailingStatusCode(true);
+ webClient.getPage(getContextPath() +
"TestServlet?test=httpSessionListener");
+ }
+
+ @Test(groups = { "contexts", "integration" })
+ @SpecAssertion(section = "6.7.3", id = "af")
+ public void testApplicationScopeActiveDuringServletRequestListenerInvocation() throws
Exception {
+ WebClient webClient = new WebClient();
+ webClient.setThrowExceptionOnFailingStatusCode(true);
+ webClient.getPage(getContextPath() +
"TestServlet?test=servletRequestListener");
+ }
@Test(groups = { "contexts", "integration" })
@SpecAssertion(section = "6.7.3", id = "e")
Added:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/Result.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/Result.java
(rev 0)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/Result.java 2009-10-27
11:57:40 UTC (rev 4347)
@@ -0,0 +1,36 @@
+package org.jboss.jsr299.tck.tests.context.application;
+
+import javax.enterprise.context.ApplicationScoped;
+
+@ApplicationScoped
+class Result
+{
+ private boolean applicationScopeActiveForServletContextListener = false;
+ private boolean applicationScopeActiveForHttpSessionListener = false;
+ private boolean applicationScopeActiveForServletRequestListener = false;
+
+ public boolean isApplicationScopeActiveForServletContextListener()
+ {
+ return applicationScopeActiveForServletContextListener;
+ }
+ public void setApplicationScopeActiveForServletContextListener(boolean
applicationScopeActiveForServletContextListener)
+ {
+ this.applicationScopeActiveForServletContextListener =
applicationScopeActiveForServletContextListener;
+ }
+ public boolean isApplicationScopeActiveForHttpSessionListener()
+ {
+ return applicationScopeActiveForHttpSessionListener;
+ }
+ public void setApplicationScopeActiveForHttpSessionListener(boolean
applicationScopeActiveForHttpSessionListener)
+ {
+ this.applicationScopeActiveForHttpSessionListener =
applicationScopeActiveForHttpSessionListener;
+ }
+ public boolean isApplicationScopeActiveForServletRequestListener()
+ {
+ return applicationScopeActiveForServletRequestListener;
+ }
+ public void setApplicationScopeActiveForServletRequestListener(boolean
applicationScopeActiveForServletRequestListener)
+ {
+ this.applicationScopeActiveForServletRequestListener =
applicationScopeActiveForServletRequestListener;
+ }
+}
Deleted:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ServiceMethodServlet.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ServiceMethodServlet.java 2009-10-27
06:48:52 UTC (rev 4346)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ServiceMethodServlet.java 2009-10-27
11:57:40 UTC (rev 4347)
@@ -1,63 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.jboss.jsr299.tck.tests.context.application;
-
-import java.io.IOException;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.inject.spi.BeanManager;
-import javax.inject.Inject;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-/**
- * Servlet used just to test context during service method.
- *
- * @author David Allen
- *
- */
-public class ServiceMethodServlet extends HttpServlet
-{
-
- private static final long serialVersionUID = 1L;
-
- @Inject
- private BeanManager jsr299Manager;
-
- @Override
- protected void service(HttpServletRequest req, HttpServletResponse resp) throws
ServletException, IOException
- {
- if (!jsr299Manager.getContext(ApplicationScoped.class).isActive())
- {
- throw new ServletException("Application context is not active");
- }
- else
- {
- super.service(req, resp);
- }
- }
-
- @Override
- protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws
ServletException, IOException
- {
- resp.setContentType("text/text");
- resp.getWriter().println("It worked!");
- }
-}
Added:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/TestHttpSessionListener.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/TestHttpSessionListener.java
(rev 0)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/TestHttpSessionListener.java 2009-10-27
11:57:40 UTC (rev 4347)
@@ -0,0 +1,26 @@
+package org.jboss.jsr299.tck.tests.context.application;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+import javax.servlet.http.HttpSessionEvent;
+import javax.servlet.http.HttpSessionListener;
+
+public class TestHttpSessionListener implements HttpSessionListener
+{
+ @Inject
+ private BeanManager manager;
+ @Inject
+ private Result result;
+
+ public void sessionCreated(HttpSessionEvent hsc)
+ {
+ boolean result = manager.getContext(ApplicationScoped.class).isActive();
+ this.result.setApplicationScopeActiveForHttpSessionListener(result);
+ }
+
+ public void sessionDestroyed(HttpSessionEvent hsc)
+ {
+ }
+
+}
Copied:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/TestServlet.java
(from rev 4217,
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ServiceMethodServlet.java)
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/TestServlet.java
(rev 0)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/TestServlet.java 2009-10-27
11:57:40 UTC (rev 4347)
@@ -0,0 +1,80 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jboss.jsr299.tck.tests.context.application;
+
+import java.io.IOException;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Servlet used to test application context during service method and also for reporting
+ * test results of testing the context during a method invocation on
ServletContextListener,
+ * HttpSessionListener and ServlerRequestListener.
+ *
+ * @author David Allen
+ *
+ */
+public class TestServlet extends HttpServlet
+{
+
+ private static final long serialVersionUID = 1L;
+
+ @Inject
+ private BeanManager jsr299Manager;
+ @Inject
+ private Result result;
+
+ @Override
+ protected void service(HttpServletRequest req, HttpServletResponse resp) throws
ServletException, IOException
+ {
+ if ("servlet".equals(req.getParameter("test"))) {
+ if (jsr299Manager.getContext(ApplicationScoped.class).isActive()) {
+ resp.setStatus(200);
+ } else {
+ resp.setStatus(500);
+ }
+ } else if
("servletContextListener".equals(req.getParameter("test"))) {
+ testServletContextListener(req, resp);
+ } else if
("httpSessionListener".equals(req.getParameter("test"))) {
+ testHttpSessionListener(req, resp);
+ } else if
("servletRequestListener".equals(req.getParameter("test"))) {
+ testServletRequestListener(req, resp);
+ } else {
+ resp.setStatus(404);
+ }
+ }
+
+ private void testServletContextListener(HttpServletRequest req, HttpServletResponse
resp) {
+ resp.setStatus((result.isApplicationScopeActiveForServletContextListener()) ? 200 :
500);
+ }
+
+ private void testHttpSessionListener(HttpServletRequest req, HttpServletResponse resp)
{
+ req.getSession().setAttribute("foo", "bar");
+ resp.setStatus((result.isApplicationScopeActiveForHttpSessionListener()) ? 200 :
500);
+ }
+
+ private void testServletRequestListener(HttpServletRequest req, HttpServletResponse
resp) {
+ resp.setStatus((result.isApplicationScopeActiveForServletRequestListener()) ? 200 :
500);
+ }
+}
Added:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/TestServletContextListener.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/TestServletContextListener.java
(rev 0)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/TestServletContextListener.java 2009-10-27
11:57:40 UTC (rev 4347)
@@ -0,0 +1,26 @@
+package org.jboss.jsr299.tck.tests.context.application;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+public class TestServletContextListener implements ServletContextListener
+{
+ @Inject
+ private BeanManager manager;
+ @Inject
+ private Result result;
+
+ public void contextDestroyed(ServletContextEvent sce)
+ {
+ }
+
+ public void contextInitialized(ServletContextEvent sce)
+ {
+ boolean result = manager.getContext(ApplicationScoped.class).isActive();
+ this.result.setApplicationScopeActiveForServletContextListener(result);
+ }
+
+}
Added:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/TestServletRequestListener.java
===================================================================
---
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/TestServletRequestListener.java
(rev 0)
+++
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/TestServletRequestListener.java 2009-10-27
11:57:40 UTC (rev 4347)
@@ -0,0 +1,27 @@
+package org.jboss.jsr299.tck.tests.context.application;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+import javax.servlet.ServletRequestEvent;
+import javax.servlet.ServletRequestListener;
+
+public class TestServletRequestListener implements ServletRequestListener
+{
+
+ @Inject
+ private BeanManager manager;
+ @Inject
+ private Result result;
+
+ public void requestDestroyed(ServletRequestEvent sre)
+ {
+ }
+
+ public void requestInitialized(ServletRequestEvent sre)
+ {
+ boolean result = manager.getContext(ApplicationScoped.class).isActive();
+ this.result.setApplicationScopeActiveForServletRequestListener(result);
+ }
+
+}
Modified:
cdi-tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/context/application/web.xml
===================================================================
---
cdi-tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/context/application/web.xml 2009-10-27
06:48:52 UTC (rev 4346)
+++
cdi-tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/context/application/web.xml 2009-10-27
11:57:40 UTC (rev 4347)
@@ -3,6 +3,15 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<description>Test servlets used to test session contexts.</description>
<display-name>Session Context Tests</display-name>
+ <listener>
+
<listener-class>org.jboss.jsr299.tck.tests.context.application.TestServletContextListener</listener-class>
+</listener>
+<listener>
+
<listener-class>org.jboss.jsr299.tck.tests.context.application.TestHttpSessionListener</listener-class>
+</listener>
+<listener>
+
<listener-class>org.jboss.jsr299.tck.tests.context.application.TestServletRequestListener</listener-class>
+</listener>
<filter>
<display-name>Test Filter for Sessions</display-name>
<filter-name>filterTest</filter-name>
@@ -16,9 +25,9 @@
<listener-class>org.jboss.testharness.impl.runner.servlet.HarnessServletListener</listener-class>
</listener>
<servlet>
- <display-name>serviceMethod</display-name>
- <servlet-name>service</servlet-name>
-
<servlet-class>org.jboss.jsr299.tck.tests.context.application.ServiceMethodServlet</servlet-class>
+ <display-name>TestServlet</display-name>
+ <servlet-name>TestServlet</servlet-name>
+
<servlet-class>org.jboss.jsr299.tck.tests.context.application.TestServlet</servlet-class>
</servlet>
<servlet>
<display-name>Introspection Service for Application Context</display-name>
@@ -26,8 +35,8 @@
<servlet-class>org.jboss.jsr299.tck.tests.context.application.IntrospectApplication</servlet-class>
</servlet>
<servlet-mapping>
- <servlet-name>service</servlet-name>
- <url-pattern>/serviceMethodTest</url-pattern>
+ <servlet-name>TestServlet</servlet-name>
+ <url-pattern>/TestServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>applicationIntrospector</servlet-name>