Author: dallen6
Date: 2009-03-23 14:42:20 -0400 (Mon, 23 Mar 2009)
New Revision: 2150
Added:
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/resources/org/jboss/jsr299/tck/tests/context/session/
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/context/session/SimplePage.html
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/context/session/web.xml
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/ManagerImpl.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/NormalContextTest.java
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/lookup/manager/jndi/ManagerTest.java
tck/trunk/impl/src/main/resources/tck-audit.xml
Log:
Added some servlet session context tests, JNDI manager test (broken), and RI/SPI changes
to support JNDI binding of Manager.
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/ManagerImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/ManagerImpl.java 2009-03-23 18:27:55
UTC (rev 2149)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/ManagerImpl.java 2009-03-23 18:42:20
UTC (rev 2150)
@@ -95,7 +95,7 @@
private static final long serialVersionUID = 3021562879133838561L;
// The JNDI key to place the manager under
- public static final String JNDI_KEY = "java:comp/Manager";
+ public static final String JNDI_KEY = "java:app/Manager";
// The enabled deployment types from web-beans.xml
private transient List<Class<? extends Annotation>>
enabledDeploymentTypes;
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java 2009-03-23
18:27:55 UTC (rev 2149)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java 2009-03-23
18:42:20 UTC (rev 2150)
@@ -20,6 +20,9 @@
import java.lang.annotation.Annotation;
import java.util.List;
+import javax.inject.ExecutionException;
+import javax.inject.manager.Manager;
+
import org.jboss.webbeans.BeanValidator;
import org.jboss.webbeans.CurrentManager;
import org.jboss.webbeans.ManagerImpl;
@@ -48,7 +51,7 @@
import org.jboss.webbeans.jsf.JSFApiAbstraction;
import org.jboss.webbeans.literal.DeployedLiteral;
import org.jboss.webbeans.literal.InitializedLiteral;
-import org.jboss.webbeans.log.LogProvider;
+import org.jboss.webbeans.log.Log;
import org.jboss.webbeans.log.Logging;
import org.jboss.webbeans.resources.DefaultNamingContext;
import org.jboss.webbeans.resources.DefaultResourceLoader;
@@ -70,7 +73,7 @@
{
// The log provider
- private static LogProvider log = Logging.getLogProvider(WebBeansBootstrap.class);
+ private static Log log = Logging.getLog(WebBeansBootstrap.class);
// The Web Beans manager
private ManagerImpl manager;
@@ -94,7 +97,14 @@
}
addImplementationServices();
this.manager = new
ManagerImpl(ServiceRegistries.unmodifiableServiceRegistry(getServices()));
- getServices().get(NamingContext.class).bind(ManagerImpl.JNDI_KEY, getManager());
+ try
+ {
+ getServices().get(NamingContext.class).lookup(ManagerImpl.JNDI_KEY,
Manager.class);
+ }
+ catch (ExecutionException e)
+ {
+ getServices().get(NamingContext.class).bind(ManagerImpl.JNDI_KEY,
getManager());
+ }
CurrentManager.setRootManager(manager);
initializeContexts();
}
@@ -230,6 +240,7 @@
{
endApplication(getApplicationContext());
manager.cleanup();
+ getServices().get(NamingContext.class).unbind(ManagerImpl.JNDI_KEY);
}
}
Modified:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/NormalContextTest.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/NormalContextTest.java 2009-03-23
18:27:55 UTC (rev 2149)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/NormalContextTest.java 2009-03-23
18:42:20 UTC (rev 2150)
@@ -102,19 +102,4 @@
destroyContext(sessionContext);
assert bean.isDestroyCalled();
}
-
-
-
-
- /**
- * There may be no more than one mapped instance per contextual type per
- * thread
- */
- @Test(groups = { "contexts", "stub",
"underInvestigation" })
- @SpecAssertion(section = "8.2", id = "a")
- public void testOnlyOneMappedInstancePerContextualTypePerThread()
- {
- assert false;
- }
-
}
Added:
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
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/session/FilterTest.java 2009-03-23
18:42:20 UTC (rev 2150)
@@ -0,0 +1,58 @@
+package org.jboss.jsr299.tck.tests.context.session;
+
+import java.io.IOException;
+
+import javax.context.SessionScoped;
+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()
+ {
+ }
+
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain
chain) throws IOException, ServletException
+ {
+ if (!jsr299Manager.getContext(SessionScoped.class).isActive())
+ {
+ throw new ServletException("Session is not active");
+ }
+ else
+ {
+ chain.doFilter(request, response);
+ }
+ }
+
+ public void init(FilterConfig filterConfig) throws ServletException
+ {
+ //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");
+ }
+ }
+ catch (NamingException e)
+ {
+ throw new ServletException("Error looking up manager", e);
+ }
+ }
+
+}
Property changes on:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/session/FilterTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
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
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/session/ServiceMethodServlet.java 2009-03-23
18:42:20 UTC (rev 2150)
@@ -0,0 +1,91 @@
+/*
+ * 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.context.SessionScoped;
+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(SessionScoped.class).isActive())
+ {
+ throw new ServletException("Session 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");
+ if (jsr299Manager == null)
+ {
+ throw new ServletException("Failed to find the Manager in JNDI");
+ }
+ }
+ 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/ServiceMethodServlet.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
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-23
18:27:55 UTC (rev 2149)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/session/SessionContextTest.java 2009-03-23
18:42:20 UTC (rev 2150)
@@ -4,27 +4,47 @@
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"),
+ @Resource(destination="SimplePage.html",
source="SimplePage.html"),
+})
public class SessionContextTest extends AbstractJSR299Test
{
- @Test(groups = { "stub", "contexts", "servlet",
"integration" })
+ @Test(groups = { "contexts", "servlet", "integration"
})
@SpecAssertion(section = "8.5.2", id = "a")
- public void testSessionScopeActiveDuringServiceMethod()
+ public void testSessionScopeActiveDuringServiceMethod() throws Exception
{
- assert false;
+ WebClient webClient = new WebClient();
+ webClient.setThrowExceptionOnFailingStatusCode(true);
+ webClient.getPage(getContextPath() + "serviceMethodTest");
}
+ @Test(groups = { "contexts", "servlet", "integration"
})
+ @SpecAssertion(section = "8.5.2", id = "b")
+ public void testSessionScopeActiveDuringDoFilterMethod() throws Exception
+ {
+ WebClient webClient = new WebClient();
+ webClient.setThrowExceptionOnFailingStatusCode(true);
+ webClient.getPage(getContextPath() + "SimplePage.html");
+ }
+
@Test(groups = { "stub", "contexts", "servlet",
"integration" })
@SpecAssertion(section = "8.5.2", id = "c")
- public void testSessionContextSharedBetweenServletRequestsInSameHttpSession()
+ public void testSessionContextSharedBetweenServletRequestsInSameHttpSession() throws
Exception
{
assert false;
}
Modified:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/manager/jndi/ManagerTest.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/manager/jndi/ManagerTest.java 2009-03-23
18:27:55 UTC (rev 2149)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/manager/jndi/ManagerTest.java 2009-03-23
18:42:20 UTC (rev 2150)
@@ -1,15 +1,24 @@
package org.jboss.jsr299.tck.tests.lookup.manager.jndi;
+import javax.inject.manager.Manager;
+import javax.naming.InitialContext;
+
import org.hibernate.tck.annotations.SpecAssertion;
import org.jboss.jsr299.tck.AbstractJSR299Test;
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.testharness.impl.packaging.IntegrationTest;
import org.testng.annotations.Test;
+@Artifact
+@IntegrationTest
public class ManagerTest extends AbstractJSR299Test
{
- @Test(groups = { "stub", "manager", "ejb3",
"integration" })
+ @Test(groups = { "broken", "manager", "ejb3",
"integration" })
@SpecAssertion(section = "5.7.2", id = "b")
- public void testManagerLookupInJndi()
+ public void testManagerLookupInJndi() throws Exception
{
- assert false;
+ InitialContext ctx = new InitialContext();
+ Manager manager = (Manager) ctx.lookup("java:app/Manager");
+ assert manager != null;
}
}
Added:
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/context/session/SimplePage.html
===================================================================
---
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/context/session/SimplePage.html
(rev 0)
+++
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/context/session/SimplePage.html 2009-03-23
18:42:20 UTC (rev 2150)
@@ -0,0 +1,11 @@
+<!DOCTYPE html
+ PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html
xmlns="http://www.w3.org/1999/xhtml" xml:lang="de"
lang="de">
+<head>
+</head>
+
+<body>
+</body>
+
+</html>
Property changes on:
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/context/session/SimplePage.html
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
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
(rev 0)
+++
tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/context/session/web.xml 2009-03-23
18:42:20 UTC (rev 2150)
@@ -0,0 +1,33 @@
+<?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>
+ <filter>
+ <display-name>Test Filter for Sessions</display-name>
+ <filter-name>filterTest</filter-name>
+
<filter-class>org.jboss.jsr299.tck.tests.context.session.FilterTest</filter-class>
+ </filter>
+ <filter-mapping>
+ <filter-name>filterTest</filter-name>
+ <url-pattern>/SimplePage.html</url-pattern>
+ </filter-mapping>
+ <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.session.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/tck-audit.xml
===================================================================
--- tck/trunk/impl/src/main/resources/tck-audit.xml 2009-03-23 18:27:55 UTC (rev 2149)
+++ tck/trunk/impl/src/main/resources/tck-audit.xml 2009-03-23 18:42:20 UTC (rev 2150)
@@ -524,7 +524,7 @@
<assertion id="b" testable="false">
<text>A bean may declare zero stereotypes</text>
- <note>I can't see how to test this</note>
+ <note>Not testable through API</note>
</assertion>
<assertion id="c">
@@ -4530,8 +4530,9 @@
</section>
<section id="8.2" title="Normal scopes and pseudo-scopes">
- <assertion id="a">
+ <assertion id="a" testable="false">
<text>There may be no more than one mapped instance of a context object per
contextual type per thread</text>
+ <note>Not testable through API</note>
</assertion>
<assertion id="b" testable="false">