Author: dallen6
Date: 2009-03-26 17:29:53 -0400 (Thu, 26 Mar 2009)
New Revision: 2220
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ServiceMethodServlet.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/session/IntrospectSession.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/session/InvalidateSession.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/session/SimpleSessionBean.java
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/context/application/
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/context/application/web.xml
Modified:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ApplicationContextTest.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/session/FilterTest.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/session/ServiceMethodServlet.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/session/SessionContextTest.java
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/context/session/web.xml
Log:
Finished session context tests and added an application context test
Modified:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ApplicationContextTest.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ApplicationContextTest.java 2009-03-26
18:06:38 UTC (rev 2219)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ApplicationContextTest.java 2009-03-26
21:29:53 UTC (rev 2220)
@@ -4,22 +4,32 @@
import org.jboss.jsr299.tck.AbstractJSR299Test;
import org.jboss.testharness.impl.packaging.Artifact;
import org.jboss.testharness.impl.packaging.IntegrationTest;
+import org.jboss.testharness.impl.packaging.Resource;
+import org.jboss.testharness.impl.packaging.Resources;
+import org.jboss.testharness.impl.packaging.war.WarArtifactDescriptor;
import org.testng.annotations.Test;
+import com.gargoylesoftware.htmlunit.WebClient;
+
/**
*
* Spec version: PRD2
*/
@Artifact
-@IntegrationTest
+@IntegrationTest(runLocally=true)
+@Resources({
+ @Resource(destination=WarArtifactDescriptor.WEB_XML_DESTINATION,
source="web.xml")
+})
public class ApplicationContextTest extends AbstractJSR299Test
{
- @Test(groups = { "stub", "contexts", "servlet",
"integration" })
+ @Test(groups = { "contexts", "servlet", "integration"
})
@SpecAssertion(section = "8.5.3", id = "a")
- public void testApplicationScopeActiveDuringServiceMethod()
+ public void testApplicationScopeActiveDuringServiceMethod() throws Exception
{
- assert false;
+ WebClient webClient = new WebClient();
+ webClient.setThrowExceptionOnFailingStatusCode(true);
+ webClient.getPage(getContextPath() + "serviceMethodTest");
}
@Test(groups = { "stub", "contexts", "webservice",
"integration" })
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ServiceMethodServlet.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ServiceMethodServlet.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ServiceMethodServlet.java 2009-03-26
21:29:53 UTC (rev 2220)
@@ -0,0 +1,87 @@
+/*
+ * 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.context.ApplicationScoped;
+import javax.inject.Current;
+import javax.inject.manager.Manager;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.servlet.ServletConfig;
+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;
+
+ @Current
+ private Manager 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!");
+ }
+
+ @Override
+ public void init() throws ServletException
+ {
+ //TODO Remove init code once injection works in servlet container
+ try
+ {
+ InitialContext ic = new InitialContext();
+ jsr299Manager = (Manager) ic.lookup("java:app/Manager");
+ }
+ catch (NamingException e)
+ {
+ throw new ServletException("Error looking up manager", e);
+ }
+ }
+
+ @Override
+ public void init(ServletConfig config) throws ServletException
+ {
+ init();
+ }
+}
Property changes on:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ServiceMethodServlet.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/session/FilterTest.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/session/FilterTest.java 2009-03-26
18:06:38 UTC (rev 2219)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/session/FilterTest.java 2009-03-26
21:29:53 UTC (rev 2220)
@@ -6,23 +6,21 @@
import javax.inject.Current;
import javax.inject.manager.Manager;
import javax.naming.InitialContext;
-import javax.naming.NamingException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletResponse;
public class FilterTest implements Filter
{
-
@Current
private Manager jsr299Manager;
public void destroy()
{
+ jsr299Manager = null;
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain
chain) throws IOException, ServletException
@@ -42,14 +40,13 @@
//TODO Remove init code once injection works in servlet container
try
{
- InitialContext ic = new InitialContext();
- jsr299Manager = (Manager) ic.lookup("java:app/Manager");
if (jsr299Manager == null)
{
- throw new ServletException("Failed to find the Manager in JNDI");
+ InitialContext ic = new InitialContext();
+ jsr299Manager = (Manager) ic.lookup("java:app/Manager");
}
}
- catch (NamingException e)
+ catch (Exception e)
{
throw new ServletException("Error looking up manager", e);
}
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/session/IntrospectSession.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/session/IntrospectSession.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/session/IntrospectSession.java 2009-03-26
21:29:53 UTC (rev 2220)
@@ -0,0 +1,73 @@
+/*
+ * 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.session;
+
+import java.io.IOException;
+
+import javax.inject.Current;
+import javax.inject.manager.Manager;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Used to process requests to check which session context is in use.
+ *
+ * @author David Allen
+ *
+ */
+public class IntrospectSession extends HttpServlet
+{
+ private static final long serialVersionUID = 1L;
+
+ @Current
+ private Manager jsr299Manager;
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws
ServletException, IOException
+ {
+ resp.setContentType("text/text");
+ SimpleSessionBean aBean =
jsr299Manager.getInstanceByType(SimpleSessionBean.class);
+ resp.getWriter().print(aBean.hashCode());
+ }
+
+ @Override
+ public void init() throws ServletException
+ {
+ //TODO Remove init code once injection works in servlet container
+ try
+ {
+ InitialContext ic = new InitialContext();
+ jsr299Manager = (Manager) ic.lookup("java:app/Manager");
+ }
+ catch (NamingException e)
+ {
+ throw new ServletException("Error looking up manager", e);
+ }
+ }
+
+ @Override
+ public void init(ServletConfig config) throws ServletException
+ {
+ init();
+ }
+}
Property changes on:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/session/IntrospectSession.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/session/InvalidateSession.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/session/InvalidateSession.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/session/InvalidateSession.java 2009-03-26
21:29:53 UTC (rev 2220)
@@ -0,0 +1,65 @@
+package org.jboss.jsr299.tck.tests.context.session;
+
+import java.io.IOException;
+
+import javax.inject.Current;
+import javax.inject.manager.Manager;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+public class InvalidateSession extends HttpServlet
+{
+ private static final long serialVersionUID = 1L;
+
+ @Current
+ private Manager jsr299Manager;
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws
ServletException, IOException
+ {
+ resp.setContentType("text/text");
+
+ if (req.getParameter("timeout") != null)
+ {
+ SimpleSessionBean.setBeanDestroyed(false);
+ jsr299Manager.getInstanceByType(SimpleSessionBean.class);
+
req.getSession().setMaxInactiveInterval(Integer.parseInt(req.getParameter("timeout")));
+ }
+ else if (req.getParameter("isBeanDestroyed") != null)
+ {
+ resp.getWriter().print(SimpleSessionBean.isBeanDestroyed());
+ }
+ else
+ {
+ SimpleSessionBean.setBeanDestroyed(false);
+ jsr299Manager.getInstanceByType(SimpleSessionBean.class);
+ req.getSession().invalidate();
+ }
+ }
+
+ @Override
+ public void init() throws ServletException
+ {
+ //TODO Remove init code once injection works in servlet container
+ try
+ {
+ InitialContext ic = new InitialContext();
+ jsr299Manager = (Manager) ic.lookup("java:app/Manager");
+ }
+ catch (NamingException e)
+ {
+ throw new ServletException("Error looking up manager", e);
+ }
+ }
+
+ @Override
+ public void init(ServletConfig config) throws ServletException
+ {
+ init();
+ }
+}
Property changes on:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/session/InvalidateSession.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/session/ServiceMethodServlet.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/session/ServiceMethodServlet.java 2009-03-26
18:06:38 UTC (rev 2219)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/session/ServiceMethodServlet.java 2009-03-26
21:29:53 UTC (rev 2220)
@@ -72,10 +72,6 @@
{
InitialContext ic = new InitialContext();
jsr299Manager = (Manager) ic.lookup("java:app/Manager");
- if (jsr299Manager == null)
- {
- throw new ServletException("Failed to find the Manager in JNDI");
- }
}
catch (NamingException e)
{
Modified:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/session/SessionContextTest.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/session/SessionContextTest.java 2009-03-26
18:06:38 UTC (rev 2219)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/session/SessionContextTest.java 2009-03-26
21:29:53 UTC (rev 2220)
@@ -9,6 +9,7 @@
import org.jboss.testharness.impl.packaging.war.WarArtifactDescriptor;
import org.testng.annotations.Test;
+import com.gargoylesoftware.htmlunit.TextPage;
import com.gargoylesoftware.htmlunit.WebClient;
/**
@@ -23,7 +24,6 @@
})
public class SessionContextTest extends AbstractJSR299Test
{
-
@Test(groups = { "contexts", "servlet", "integration"
})
@SpecAssertion(section = "8.5.2", id = "a")
public void testSessionScopeActiveDuringServiceMethod() throws Exception
@@ -42,25 +42,62 @@
webClient.getPage(getContextPath() + "SimplePage.html");
}
- @Test(groups = { "stub", "contexts", "servlet",
"integration" })
+ @Test(groups = { "contexts", "servlet", "integration"
})
@SpecAssertion(section = "8.5.2", id = "c")
public void testSessionContextSharedBetweenServletRequestsInSameHttpSession() throws
Exception
{
- assert false;
+ WebClient webClient = new WebClient();
+ webClient.setThrowExceptionOnFailingStatusCode(true);
+ TextPage firstRequestResult = webClient.getPage(getContextPath() +
"IntrospectSession");
+ assert firstRequestResult.getContent() != null;
+ assert Long.parseLong(firstRequestResult.getContent()) != 0;
+ // Make a second request and make sure the same context is used
+ TextPage secondRequestResult = webClient.getPage(getContextPath() +
"IntrospectSession");
+ assert secondRequestResult.getContent() != null;
+ assert Long.parseLong(secondRequestResult.getContent()) ==
Long.parseLong(firstRequestResult.getContent());
}
- @Test(groups = { "stub", "contexts", "integration" })
+ @Test(groups = { "contexts", "integration" })
@SpecAssertion(section = "8.5.2", id = "d")
- public void testSessionContextDestroyedWhenHttpSessionInvalidated()
+ public void testSessionContextDestroyedWhenHttpSessionInvalidated() throws Exception
{
- assert false;
+ WebClient webClient = new WebClient();
+ webClient.setThrowExceptionOnFailingStatusCode(true);
+ TextPage firstRequestResult = webClient.getPage(getContextPath() +
"IntrospectSession");
+ assert firstRequestResult.getContent() != null;
+ assert Long.parseLong(firstRequestResult.getContent()) != 0;
+ webClient.getPage(getContextPath() + "InvalidateSession");
+ // Make a second request and make sure the same context is not there
+ TextPage secondRequestResult = webClient.getPage(getContextPath() +
"IntrospectSession");
+ assert secondRequestResult.getContent() != null;
+ assert Long.parseLong(secondRequestResult.getContent()) !=
Long.parseLong(firstRequestResult.getContent());
+
+ // As final confirmation that the context was destroyed, check that its beans
+ // were also destroyed.
+ TextPage beanDestructionResult = webClient.getPage(getContextPath() +
"InvalidateSession?isBeanDestroyed");
+ assert Boolean.parseBoolean(beanDestructionResult.getContent());
}
- @Test(groups = { "stub", "contexts", "integration" })
+ @Test(groups = { "contexts", "integration" })
@SpecAssertion(section = "8.5.2", id = "e")
- public void testSessionContextDestroyedWhenHttpSessionTimesOut()
+ public void testSessionContextDestroyedWhenHttpSessionTimesOut() throws Exception
{
- assert false;
+ WebClient webClient = new WebClient();
+ webClient.setThrowExceptionOnFailingStatusCode(true);
+ TextPage firstRequestResult = webClient.getPage(getContextPath() +
"IntrospectSession");
+ assert firstRequestResult.getContent() != null;
+ assert Long.parseLong(firstRequestResult.getContent()) != 0;
+ webClient.getPage(getContextPath() + "InvalidateSession?timeout=1");
+ Thread.sleep(1500);
+ // Make a second request and make sure the same context is not there
+ TextPage secondRequestResult = webClient.getPage(getContextPath() +
"IntrospectSession");
+ assert secondRequestResult.getContent() != null;
+ assert Long.parseLong(secondRequestResult.getContent()) !=
Long.parseLong(firstRequestResult.getContent());
+
+ // As final confirmation that the context was destroyed, check that its beans
+ // were also destroyed.
+ TextPage beanDestructionResult = webClient.getPage(getContextPath() +
"InvalidateSession?isBeanDestroyed");
+ assert Boolean.parseBoolean(beanDestructionResult.getContent());
}
}
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/session/SimpleSessionBean.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/session/SimpleSessionBean.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/session/SimpleSessionBean.java 2009-03-26
21:29:53 UTC (rev 2220)
@@ -0,0 +1,30 @@
+package org.jboss.jsr299.tck.tests.context.session;
+
+import java.io.Serializable;
+
+import javax.annotation.PreDestroy;
+import javax.context.SessionScoped;
+
+@SessionScoped
+class SimpleSessionBean implements Serializable
+{
+
+ private static final long serialVersionUID = 1L;
+ private static boolean beanDestroyed = false;
+
+ @PreDestroy
+ public void destroyBean()
+ {
+ beanDestroyed = true;
+ }
+
+ public static boolean isBeanDestroyed()
+ {
+ return beanDestroyed;
+ }
+
+ public static void setBeanDestroyed(boolean beanDestroyed)
+ {
+ SimpleSessionBean.beanDestroyed = beanDestroyed;
+ }
+}
Property changes on:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/session/SimpleSessionBean.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied:
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/context/application/web.xml
(from rev 2212,
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/context/session/web.xml)
===================================================================
---
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/context/application/web.xml
(rev 0)
+++
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/context/application/web.xml 2009-03-26
21:29:53 UTC (rev 2220)
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
+
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.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>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>service</servlet-name>
+ <url-pattern>/serviceMethodTest</url-pattern>
+ </servlet-mapping>
+ <session-config>
+ <session-timeout>10</session-timeout>
+ </session-config>
+ <login-config>
+ <auth-method>BASIC</auth-method>
+ </login-config>
+</web-app>
Modified:
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/context/session/web.xml
===================================================================
---
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/context/session/web.xml 2009-03-26
18:06:38 UTC (rev 2219)
+++
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/context/session/web.xml 2009-03-26
21:29:53 UTC (rev 2220)
@@ -20,10 +20,28 @@
<servlet-name>service</servlet-name>
<servlet-class>org.jboss.jsr299.tck.tests.context.session.ServiceMethodServlet</servlet-class>
</servlet>
+ <servlet>
+ <display-name>Introspection Service for Sessions</display-name>
+ <servlet-name>sessionIntrospector</servlet-name>
+
<servlet-class>org.jboss.jsr299.tck.tests.context.session.IntrospectSession</servlet-class>
+ </servlet>
+ <servlet>
+ <display-name>Session Invalidation</display-name>
+ <servlet-name>invalidator</servlet-name>
+
<servlet-class>org.jboss.jsr299.tck.tests.context.session.InvalidateSession</servlet-class>
+ </servlet>
<servlet-mapping>
<servlet-name>service</servlet-name>
<url-pattern>/serviceMethodTest</url-pattern>
</servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>sessionIntrospector</servlet-name>
+ <url-pattern>/IntrospectSession</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>invalidator</servlet-name>
+ <url-pattern>/InvalidateSession</url-pattern>
+ </servlet-mapping>
<session-config>
<session-timeout>10</session-timeout>
</session-config>