[webbeans-commits] Webbeans SVN: r2287 - in tck/trunk/impl/src/main: java/org/jboss/jsr299/tck/tests/context/application/ejb and 2 other directories.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Tue Mar 31 17:49:34 EDT 2009


Author: dallen6
Date: 2009-03-31 17:49:34 -0400 (Tue, 31 Mar 2009)
New Revision: 2287

Added:
   tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/FilterTest.java
   tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/IntrospectApplication.java
   tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/SimpleApplicationBean.java
   tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/
   tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/Bird.java
   tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/BirdFeederService.java
   tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/CommonKingfisher.java
   tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/EJBApplicationContextTest.java
   tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/FMS.java
   tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/FMSModelIII.java
   tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/FeederService.java
   tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/SimpleApplicationBean.java
   tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/standalone/
   tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/standalone/ApplicationContextTest.java
   tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/standalone/NearMiss.java
   tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/standalone/SimpleApplicationBean.java
   tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/standalone/TargetEvent.java
   tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/standalone/TcasDisplay.java
   tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/standalone/TcasToFmsLink.java
   tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/context/application/SimplePage.html
Modified:
   tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ApplicationContextTest.java
   tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/context/application/web.xml
Log:
A few tests for application context

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-31 15:26:16 UTC (rev 2286)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ApplicationContextTest.java	2009-03-31 21:49:34 UTC (rev 2287)
@@ -9,16 +9,20 @@
 import org.jboss.testharness.impl.packaging.war.WarArtifactDescriptor;
 import org.testng.annotations.Test;
 
+import com.gargoylesoftware.htmlunit.TextPage;
 import com.gargoylesoftware.htmlunit.WebClient;
 
 /**
  * 
+ * @author David Allen
+ *
  * Spec version: PRD2
  */
 @Artifact
 @IntegrationTest(runLocally=true)
 @Resources({
-  @Resource(destination=WarArtifactDescriptor.WEB_XML_DESTINATION, source="web.xml")
+  @Resource(destination=WarArtifactDescriptor.WEB_XML_DESTINATION, source="web.xml"),
+  @Resource(destination="SimplePage.html", source="SimplePage.html")
 })
 public class ApplicationContextTest extends AbstractJSR299Test
 {
@@ -32,62 +36,45 @@
       webClient.getPage(getContextPath() + "serviceMethodTest");
    }
 
-   @Test(groups = { "stub", "contexts", "servlet", "integration" })
+   @Test(groups = { "contexts", "servlet", "integration" })
    @SpecAssertion(section = "8.5.3", id = "b")
    public void testApplicationScopeActiveDuringDoFilterMethod() throws Exception
    {
-      assert false;
+      WebClient webClient = new WebClient();
+      webClient.setThrowExceptionOnFailingStatusCode(true);
+      webClient.getPage(getContextPath() + "SimplePage.html");
    }
 
-   @Test(groups = { "stub", "contexts", "webservice", "integration" })
-   @SpecAssertion(section = "8.5.3", id = "c")
-   public void testApplicationScopeActiveDuringWebSericeInvocation()
-   {
-      assert false;
-   }
-
-   @Test(groups = { "stub", "contexts", "events", "integration" })
-   @SpecAssertion(section = "8.5.3", id = "d")
-   public void testApplicationScopeActiveDuringAsynchronousObserverMethodInvocation()
-   {
-      assert false;
-   }
-
    @Test(groups = { "stub", "contexts", "ejb3", "integration" })
    @SpecAssertion(section = "8.5.3", id = "e")
    public void testApplicationScopeActiveDuringRemoteMethodInvocationOfEjb()
    {
+      //TODO Easy to implement once global naming w/EJB3.1 is available
       assert false;
    }
 
-   @Test(groups = { "stub", "contexts", "ejb3", "integration" })
-   @SpecAssertion(section = "8.5.3", id = "f")
-   public void testApplicationScopeActiveDuringCallToEjbTimeoutMethod()
-   {
-      assert false;
-   }
-
-   @Test(groups = { "stub", "contexts", "ejb3", "integration" })
+   @Test(groups = { "stub", "contexts", "ejb3", "jms", "integration" })
    @SpecAssertion(section = "8.5.3", id = "g")
-   public void testApplicationScopeActiveDuringEjbMessageDelivery()
+   public void testApplicationScopeActiveDuringMdbMessageDelivery()
    {
       assert false;
    }
 
-   @Test(groups = { "stub", "contexts", "integration" })
+   @Test(groups = { "contexts", "integration" })
    @SpecAssertion(section = "8.5.3", id = "h")
-   public void testApplicationContextSharedBetweenServletRequests()
+   public void testApplicationContextSharedBetweenServletRequests() throws Exception
    {
-      assert false;
+      WebClient webClient = new WebClient();
+      webClient.setThrowExceptionOnFailingStatusCode(true);
+      TextPage firstRequestResult = webClient.getPage(getContextPath() + "IntrospectApplication");
+      assert firstRequestResult.getContent() != null;
+      assert Double.parseDouble(firstRequestResult.getContent()) != 0;
+      // Make a second request and make sure the same context is used
+      TextPage secondRequestResult = webClient.getPage(getContextPath() + "IntrospectApplication");
+      assert secondRequestResult.getContent() != null;
+      assert Double.parseDouble(secondRequestResult.getContent()) == Double.parseDouble(firstRequestResult.getContent());
    }
 
-   @Test(groups = { "stub", "contexts", "events", "integration" })
-   @SpecAssertion(section = "8.5.3", id = "i")
-   public void testApplicationContextSharedBetweenAsynchronousObservers()
-   {
-      assert false;
-   }
-
    @Test(groups = { "stub", "contexts", "webservice", "integration" })
    @SpecAssertion(section = "8.5.3", id = "j")
    public void testApplicationContextSharedBetweenWebServices()
@@ -99,16 +86,10 @@
    @SpecAssertion(section = "8.5.3", id = "k")
    public void testApplicationContextSharedBetweenRemoteMethodInvokations()
    {
+      //TODO Easy to implement once global naming w/EJB3.1 is available
       assert false;
    }
 
-   @Test(groups = { "stub", "contexts", "ejb3", "integration" })
-   @SpecAssertion(section = "8.5.3", id = "l")
-   public void testApplicationContextSharedBetweenEJBTimeoutInvokations()
-   {
-      assert false;
-   }
-
    @Test(groups = { "stub", "contexts", "jms", "integration" })
    @SpecAssertion(section = "8.5.3", id = "m")
    public void testApplicationContextSharedBetweenMDBMessageDeliveries()
@@ -116,10 +97,11 @@
       assert false;
    }
 
-   @Test(groups = { "stub", "contexts", "integration" })
+   @Test(groups = { "underInvestigation", "contexts", "integration" })
    @SpecAssertion(section = "8.5.3", id = "n")
    public void testApplicationScopeDestroyedWhenApplicationIsUndeployed()
    {
+      //TODO How can the WB container be tested after the app is undeployed?
       assert false;
    }
 

Copied: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/FilterTest.java (from rev 2242, 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/application/FilterTest.java	                        (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/FilterTest.java	2009-03-31 21:49:34 UTC (rev 2287)
@@ -0,0 +1,55 @@
+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.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+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
+   {
+      if (!jsr299Manager.getContext(ApplicationScoped.class).isActive())
+      {
+         throw new ServletException("Application context 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
+      {
+         if (jsr299Manager == null)
+         {
+            InitialContext ic = new InitialContext();
+            jsr299Manager = (Manager) ic.lookup("java:app/Manager");
+         }
+      }
+      catch (Exception e)
+      {
+         throw new ServletException("Error looking up manager", e);
+      }
+   }
+
+}

Added: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/IntrospectApplication.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/IntrospectApplication.java	                        (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/IntrospectApplication.java	2009-03-31 21:49:34 UTC (rev 2287)
@@ -0,0 +1,50 @@
+package org.jboss.jsr299.tck.tests.context.application;
+
+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 IntrospectApplication 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");
+      SimpleApplicationBean aBean = jsr299Manager.getInstanceByType(SimpleApplicationBean.class);
+      resp.getWriter().print(aBean.getId());
+   }
+
+   @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/IntrospectApplication.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/SimpleApplicationBean.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/SimpleApplicationBean.java	                        (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/SimpleApplicationBean.java	2009-03-31 21:49:34 UTC (rev 2287)
@@ -0,0 +1,14 @@
+package org.jboss.jsr299.tck.tests.context.application;
+
+import javax.context.ApplicationScoped;
+
+ at ApplicationScoped
+class SimpleApplicationBean
+{
+   private double id = Math.random();
+
+   public double getId()
+   {
+      return id;
+   }
+}


Property changes on: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/SimpleApplicationBean.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/Bird.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/Bird.java	                        (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/Bird.java	2009-03-31 21:49:34 UTC (rev 2287)
@@ -0,0 +1,9 @@
+package org.jboss.jsr299.tck.tests.context.application.ejb;
+
+import javax.ejb.Local;
+
+ at Local
+public interface Bird
+{
+   public void eat();
+}


Property changes on: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/Bird.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/BirdFeederService.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/BirdFeederService.java	                        (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/BirdFeederService.java	2009-03-31 21:49:34 UTC (rev 2287)
@@ -0,0 +1,37 @@
+package org.jboss.jsr299.tck.tests.context.application.ejb;
+
+import javax.context.ApplicationScoped;
+import javax.ejb.Stateless;
+import javax.inject.Current;
+import javax.inject.manager.Manager;
+import javax.jws.WebMethod;
+import javax.jws.WebService;
+
+ at Stateless
+ at WebService
+public class BirdFeederService implements FeederService
+{
+   @Current
+   private Manager jsr299Manager;
+
+   private static boolean applicationScopeActive = false;
+
+   @WebMethod
+   public void refillFood()
+   {
+      if (jsr299Manager.getContext(ApplicationScoped.class).isActive())
+      {
+         applicationScopeActive = true;
+      }
+      else
+      {
+         applicationScopeActive = false;
+      }
+   }
+
+   public boolean adequateFood()
+   {
+      return applicationScopeActive;
+   }
+
+}


Property changes on: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/BirdFeederService.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/CommonKingfisher.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/CommonKingfisher.java	                        (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/CommonKingfisher.java	2009-03-31 21:49:34 UTC (rev 2287)
@@ -0,0 +1,18 @@
+package org.jboss.jsr299.tck.tests.context.application.ejb;
+
+import javax.ejb.Stateless;
+import javax.xml.ws.WebServiceRef;
+
+ at Stateless
+public class CommonKingfisher implements Bird
+{
+
+   @WebServiceRef
+   private FeederService birdFeeder;
+
+   public void eat()
+   {
+      birdFeeder.refillFood();
+   }
+
+}


Property changes on: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/CommonKingfisher.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/EJBApplicationContextTest.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/EJBApplicationContextTest.java	                        (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/EJBApplicationContextTest.java	2009-03-31 21:49:34 UTC (rev 2287)
@@ -0,0 +1,55 @@
+package org.jboss.jsr299.tck.tests.context.application.ejb;
+
+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.jboss.testharness.impl.packaging.Packaging;
+import org.jboss.testharness.impl.packaging.PackagingType;
+import org.testng.annotations.Test;
+
+/**
+ * EJB and related tests with the built-in application context.
+ * 
+ * @author David Allen
+ *
+ * Spec version: PRD2
+ */
+ at Artifact
+ at IntegrationTest
+ at Packaging(PackagingType.EAR)
+public class EJBApplicationContextTest extends AbstractJSR299Test
+{
+   @Test(groups = { "broken", "contexts", "webservice", "integration" })
+   @SpecAssertion(section = "8.5.3", id = "c")
+   public void testApplicationScopeActiveDuringWebSericeInvocation()
+   {
+      //TODO This test might work better with a separate client over HTTP
+      FeederService birdFeeder = getCurrentManager().getInstanceByType(FeederService.class);
+      Bird bird = getCurrentManager().getInstanceByType(Bird.class);
+      bird.eat();
+      assert birdFeeder.adequateFood();
+   }
+
+   @Test(groups = { "contexts", "ejb3", "integration" })
+   @SpecAssertion(section = "8.5.3", id = "f")
+   public void testApplicationScopeActiveDuringCallToEjbTimeoutMethod() throws Exception
+   {
+      FMS flightManagementSystem = getCurrentManager().getInstanceByType(FMS.class);
+      flightManagementSystem.climb();
+      Thread.sleep(250);
+      assert flightManagementSystem.isApplicationScopeActive();
+   }
+
+   @Test(groups = { "contexts", "ejb3", "integration" })
+   @SpecAssertion(section = "8.5.3", id = "l")
+   public void testApplicationContextSharedBetweenEJBTimeoutInvokations() throws Exception
+   {
+      FMS flightManagementSystem = getCurrentManager().getInstanceByType(FMS.class);
+      flightManagementSystem.climb();
+      flightManagementSystem.descend();
+      Thread.sleep(250);
+      assert flightManagementSystem.isSameBean();
+   }
+
+}


Property changes on: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/EJBApplicationContextTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/FMS.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/FMS.java	                        (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/FMS.java	2009-03-31 21:49:34 UTC (rev 2287)
@@ -0,0 +1,21 @@
+package org.jboss.jsr299.tck.tests.context.application.ejb;
+
+import javax.ejb.Local;
+
+ at Local
+public interface FMS
+{
+   public void turnLeft();
+   
+   public void turnRight();
+   
+   public void climb();
+   
+   public void descend();
+   
+   public boolean isApplicationScopeActive();
+
+   public void setApplicationScopeActive(boolean applicationScopeActive);
+   
+   public boolean isSameBean();
+}


Property changes on: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/FMS.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/FMSModelIII.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/FMSModelIII.java	                        (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/FMSModelIII.java	2009-03-31 21:49:34 UTC (rev 2287)
@@ -0,0 +1,82 @@
+package org.jboss.jsr299.tck.tests.context.application.ejb;
+
+import javax.annotation.Resource;
+import javax.context.ApplicationScoped;
+import javax.ejb.Stateless;
+import javax.ejb.Timeout;
+import javax.ejb.Timer;
+import javax.ejb.TimerService;
+import javax.inject.Current;
+import javax.inject.manager.Manager;
+
+ at Stateless
+public class FMSModelIII implements FMS
+{
+   private static final long serialVersionUID = 1L;
+
+   @Resource
+   private TimerService timerService;
+   
+   @Current
+   private Manager manager;
+
+   private static boolean applicationScopeActive = false;
+   private static double beanId = 0.0d;
+   private static boolean sameBean = false;
+
+   public void climb()
+   {
+      timerService.createTimer(200, "Climb command timeout");
+   }
+
+   public void descend()
+   {
+      timerService.createTimer(100, "Descend command timeout");
+      beanId = 0.0d;
+      sameBean = false;
+   }
+
+   public void turnLeft()
+   {
+   }
+
+   public void turnRight()
+   {
+   }
+
+   @Timeout
+   public void timeout(Timer timer)
+   {
+      if (manager.getContext(ApplicationScoped.class).isActive())
+      {
+         applicationScopeActive = true;
+         if (beanId > 0.0)
+         {
+            if (beanId == manager.getInstanceByType(SimpleApplicationBean.class).getId())
+            {
+               sameBean = true;
+            }
+         }
+         else
+         {
+            beanId = manager.getInstanceByType(SimpleApplicationBean.class).getId();
+         }
+      }
+   }
+
+   public boolean isApplicationScopeActive()
+   {
+      return applicationScopeActive;
+   }
+
+   public void setApplicationScopeActive(boolean applicationScopeActive)
+   {
+      FMSModelIII.applicationScopeActive = applicationScopeActive;
+   }
+
+   public boolean isSameBean()
+   {
+      return sameBean;
+   }
+
+}


Property changes on: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/FMSModelIII.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/FeederService.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/FeederService.java	                        (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/FeederService.java	2009-03-31 21:49:34 UTC (rev 2287)
@@ -0,0 +1,10 @@
+package org.jboss.jsr299.tck.tests.context.application.ejb;
+
+import javax.ejb.Local;
+
+ at Local
+public interface FeederService
+{
+   public void refillFood();
+   public boolean adequateFood();
+}


Property changes on: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/FeederService.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/SimpleApplicationBean.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/SimpleApplicationBean.java	                        (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/SimpleApplicationBean.java	2009-03-31 21:49:34 UTC (rev 2287)
@@ -0,0 +1,14 @@
+package org.jboss.jsr299.tck.tests.context.application.ejb;
+
+import javax.context.ApplicationScoped;
+
+ at ApplicationScoped
+class SimpleApplicationBean
+{
+   private double id = Math.random();
+
+   public double getId()
+   {
+      return id;
+   }
+}


Property changes on: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/ejb/SimpleApplicationBean.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/standalone/ApplicationContextTest.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/standalone/ApplicationContextTest.java	                        (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/standalone/ApplicationContextTest.java	2009-03-31 21:49:34 UTC (rev 2287)
@@ -0,0 +1,53 @@
+/*
+ * 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.standalone;
+
+import org.hibernate.tck.annotations.SpecAssertion;
+import org.jboss.jsr299.tck.AbstractJSR299Test;
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.testng.annotations.Test;
+
+/**
+ * @author David Allen
+ *
+ * Spec version: PRD2
+ *
+ */
+ at Artifact
+public class ApplicationContextTest extends AbstractJSR299Test
+{
+   @Test(groups = { "contexts", "events" })
+   @SpecAssertion(section = "8.5.3", id = "d")
+   public void testApplicationScopeActiveDuringAsynchronousObserverMethodInvocation() throws Exception
+   {
+      getCurrentManager().fireEvent(new TargetEvent());
+      Thread.sleep(200);
+      assert TcasDisplay.isApplicationScopeActive();
+   }
+
+   @Test(groups = { "contexts", "events", "integration" })
+   @SpecAssertion(section = "8.5.3", id = "i")
+   public void testApplicationContextSharedBetweenAsynchronousObservers() throws Exception
+   {
+      NearMiss event = new NearMiss();
+      getCurrentManager().fireEvent(event);
+      Thread.sleep(200);
+      assert event.isSameBean();
+   }
+
+}


Property changes on: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/standalone/ApplicationContextTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/standalone/NearMiss.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/standalone/NearMiss.java	                        (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/standalone/NearMiss.java	2009-03-31 21:49:34 UTC (rev 2287)
@@ -0,0 +1,32 @@
+package org.jboss.jsr299.tck.tests.context.application.standalone;
+
+class NearMiss
+{
+   private SimpleApplicationBean bean;
+   private boolean sameBean = false;
+
+   public SimpleApplicationBean getBean()
+   {
+      return bean;
+   }
+   public void setBean(SimpleApplicationBean bean)
+   {
+      if (this.bean == null)
+      {
+      this.bean = bean;
+      }
+      else
+      {
+         sameBean = this.bean.getId() == bean.getId();
+      }
+   }
+   public boolean isSameBean()
+   {
+      return sameBean;
+   }
+   public void setSameBean(boolean sameBean)
+   {
+      this.sameBean = sameBean;
+   }
+   
+}


Property changes on: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/standalone/NearMiss.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/standalone/SimpleApplicationBean.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/standalone/SimpleApplicationBean.java	                        (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/standalone/SimpleApplicationBean.java	2009-03-31 21:49:34 UTC (rev 2287)
@@ -0,0 +1,14 @@
+package org.jboss.jsr299.tck.tests.context.application.standalone;
+
+import javax.context.ApplicationScoped;
+
+ at ApplicationScoped
+class SimpleApplicationBean
+{
+   private double id = Math.random();
+
+   public double getId()
+   {
+      return id;
+   }
+}


Property changes on: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/standalone/SimpleApplicationBean.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/standalone/TargetEvent.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/standalone/TargetEvent.java	                        (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/standalone/TargetEvent.java	2009-03-31 21:49:34 UTC (rev 2287)
@@ -0,0 +1,6 @@
+package org.jboss.jsr299.tck.tests.context.application.standalone;
+
+class TargetEvent
+{
+
+}


Property changes on: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/standalone/TargetEvent.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/standalone/TcasDisplay.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/standalone/TcasDisplay.java	                        (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/standalone/TcasDisplay.java	2009-03-31 21:49:34 UTC (rev 2287)
@@ -0,0 +1,38 @@
+package org.jboss.jsr299.tck.tests.context.application.standalone;
+
+import javax.context.ApplicationScoped;
+import javax.event.Asynchronously;
+import javax.event.Observes;
+import javax.inject.Current;
+import javax.inject.manager.Manager;
+
+class TcasDisplay
+{
+   @Current
+   private Manager manager;
+   
+   private static boolean applicationScopeActive = false;
+   
+   public void drawTarget(@Observes @Asynchronously TargetEvent targetEvent)
+   {
+      if (manager.getContext(ApplicationScoped.class).isActive())
+      {
+         applicationScopeActive = true;
+      }
+   }
+
+   public void drawNearMiss(@Observes @Asynchronously NearMiss event)
+   {
+      event.setBean(manager.getInstanceByType(SimpleApplicationBean.class));
+   }
+
+   public static boolean isApplicationScopeActive()
+   {
+      return applicationScopeActive;
+   }
+
+   public static void setApplicationScopeActive(boolean applicationScopeActive)
+   {
+      TcasDisplay.applicationScopeActive = applicationScopeActive;
+   }
+}


Property changes on: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/standalone/TcasDisplay.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/standalone/TcasToFmsLink.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/standalone/TcasToFmsLink.java	                        (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/standalone/TcasToFmsLink.java	2009-03-31 21:49:34 UTC (rev 2287)
@@ -0,0 +1,18 @@
+package org.jboss.jsr299.tck.tests.context.application.standalone;
+
+import javax.event.Asynchronously;
+import javax.event.Observes;
+import javax.inject.Current;
+import javax.inject.manager.Manager;
+
+class TcasToFmsLink
+{
+   @Current
+   private Manager manager;
+   
+   public void avoidanceAction(@Observes @Asynchronously NearMiss event)
+   {
+      event.setBean(manager.getInstanceByType(SimpleApplicationBean.class));
+   }
+
+}


Property changes on: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/standalone/TcasToFmsLink.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Copied: tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/context/application/SimplePage.html (from rev 2242, 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/application/SimplePage.html	                        (rev 0)
+++ tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/context/application/SimplePage.html	2009-03-31 21:49:34 UTC (rev 2287)
@@ -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>

Modified: tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/context/application/web.xml
===================================================================
--- tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/context/application/web.xml	2009-03-31 15:26:16 UTC (rev 2286)
+++ tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/context/application/web.xml	2009-03-31 21:49:34 UTC (rev 2287)
@@ -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>
+ <filter>
+  <display-name>Test Filter for Sessions</display-name>
+  <filter-name>filterTest</filter-name>
+  <filter-class>org.jboss.jsr299.tck.tests.context.application.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>
@@ -11,10 +20,19 @@
   <servlet-name>service</servlet-name>
   <servlet-class>org.jboss.jsr299.tck.tests.context.application.ServiceMethodServlet</servlet-class>
  </servlet>
+ <servlet>
+  <display-name>Introspection Service for Application Context</display-name>
+  <servlet-name>applicatoinIntrospector</servlet-name>
+  <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-mapping>
+ <servlet-mapping>
+  <servlet-name>applicationIntrospector</servlet-name>
+  <url-pattern>/IntrospectApplication</url-pattern>
+ </servlet-mapping>
  <session-config>
   <session-timeout>10</session-timeout>
  </session-config>




More information about the weld-commits mailing list