[seam-commits] Seam SVN: r14578 - in branches/community/Seam_2_3: seam-integration-tests/src/test/resources/WEB-INF and 1 other directory.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Fri Apr 13 11:49:03 EDT 2012


Author: maschmid
Date: 2012-04-13 11:48:58 -0400 (Fri, 13 Apr 2012)
New Revision: 14578

Added:
   branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/mock/MockSeamListener.java
Modified:
   branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/mock/AbstractSeamTest.java
   branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/mock/JUnitSeamTest.java
   branches/community/Seam_2_3/seam-integration-tests/src/test/resources/WEB-INF/web.xml
Log:
implementation of MockSeamListener


Modified: branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/mock/AbstractSeamTest.java
===================================================================
--- branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/mock/AbstractSeamTest.java	2012-04-13 15:25:03 UTC (rev 14577)
+++ branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/mock/AbstractSeamTest.java	2012-04-13 15:48:58 UTC (rev 14578)
@@ -934,12 +934,16 @@
     */
    protected void startSeam() throws Exception
    {
+      if (realServletContext == null && MockSeamListener.getServletContext() != null) {
+         realServletContext = MockSeamListener.getServletContext();
+      }
+
       // If the Seam Filter is already initialized, we can grab the real servlet context
-     if (realServletContext == null && ServletLifecycle.getServletContext() != null) {
-        realServletContext = ServletLifecycle.getServletContext();
-     }
-     
-     ServletContext realContext = realServletContext;
+      if (realServletContext == null && ServletLifecycle.getServletContext() != null) {
+         realServletContext = ServletLifecycle.getServletContext();
+      }
+
+      ServletContext realContext = realServletContext;
       this.servletContext = createServletContext(realContext);
       ServletLifecycle.beginApplication(servletContext);
       FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY, MockApplicationFactory.class.getName());

Modified: branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/mock/JUnitSeamTest.java
===================================================================
--- branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/mock/JUnitSeamTest.java	2012-04-13 15:25:03 UTC (rev 14577)
+++ branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/mock/JUnitSeamTest.java	2012-04-13 15:48:58 UTC (rev 14578)
@@ -30,8 +30,8 @@
       try {
          if (!seamStarted) {
             startSeam();
+            setupClass();
             seamStarted = true;
-            setupClass();
          }
       }
       catch (Exception x) {

Added: branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/mock/MockSeamListener.java
===================================================================
--- branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/mock/MockSeamListener.java	                        (rev 0)
+++ branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/mock/MockSeamListener.java	2012-04-13 15:48:58 UTC (rev 14578)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.seam.mock;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+import org.jboss.seam.Seam;
+import org.jboss.seam.log.LogProvider;
+import org.jboss.seam.log.Logging;
+
+/**
+ * Used to retrieve real ServletContext for the AbstractSeamTest startSeam
+ * 
+ * @author Marek Schmidt
+ */
+public class MockSeamListener implements ServletContextListener
+{
+   private static final LogProvider log = Logging.getLogProvider(ServletContextListener.class);
+   
+   private static ServletContext servletContext;
+   
+   public void contextInitialized(ServletContextEvent event) 
+   {
+      log.info( "Welcome to Mock Seam " + Seam.getVersion() );
+      event.getServletContext().setAttribute( Seam.VERSION, Seam.getVersion() );
+      servletContext = event.getServletContext();
+   }
+   
+   public void contextDestroyed(ServletContextEvent event) 
+   {
+   }
+   
+   public static ServletContext getServletContext() {
+      return servletContext;
+   }
+}

Modified: branches/community/Seam_2_3/seam-integration-tests/src/test/resources/WEB-INF/web.xml
===================================================================
--- branches/community/Seam_2_3/seam-integration-tests/src/test/resources/WEB-INF/web.xml	2012-04-13 15:25:03 UTC (rev 14577)
+++ branches/community/Seam_2_3/seam-integration-tests/src/test/resources/WEB-INF/web.xml	2012-04-13 15:48:58 UTC (rev 14578)
@@ -5,7 +5,7 @@
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
 
     <listener>
-        <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
+        <listener-class>org.jboss.seam.mock.MockSeamListener</listener-class>
     </listener>
 
 </web-app>



More information about the seam-commits mailing list