deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject git commit: DELTASPIKE-515 improved external-containers
Date Wed, 05 Feb 2014 11:34:02 GMT
Updated Branches:
  refs/heads/master 190f9982c -> 1018aee5d


DELTASPIKE-515 improved external-containers

 (required by the latest version of myfaces-test)


Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/1018aee5
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/1018aee5
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/1018aee5

Branch: refs/heads/master
Commit: 1018aee5dbc790b7427d7fe3711e8b1da004aa3b
Parents: 190f998
Author: gpetracek <gpetracek@apache.org>
Authored: Wed Feb 5 12:26:04 2014 +0100
Committer: gpetracek <gpetracek@apache.org>
Committed: Wed Feb 5 12:31:05 2014 +0100

----------------------------------------------------------------------
 .../testcontrol/api/junit/CdiTestRunner.java    | 12 ++--
 .../impl/jsf/MockedJsf2TestContainer.java       | 11 +++-
 .../impl/jsf/MockedJsfTestContainerAdapter.java | 67 +++++++++++++++++---
 3 files changed, 72 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/1018aee5/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestRunner.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestRunner.java
b/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestRunner.java
index 04c321f..f52b40a 100644
--- a/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestRunner.java
+++ b/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/junit/CdiTestRunner.java
@@ -608,18 +608,18 @@ public class CdiTestRunner extends BlockJUnit4ClassRunner
 
         private void addScopesForDefaultBehavior(List<Class<? extends Annotation>>
scopeClasses)
         {
-            if (this.parent != null && !this.parent.isScopeStarted(SessionScoped.class))
+            if (this.parent != null && !this.parent.isScopeStarted(RequestScoped.class))
             {
-                if (!scopeClasses.contains(SessionScoped.class))
+                if (!scopeClasses.contains(RequestScoped.class))
                 {
-                    scopeClasses.add(SessionScoped.class);
+                    scopeClasses.add(RequestScoped.class);
                 }
             }
-            if (this.parent != null && !this.parent.isScopeStarted(RequestScoped.class))
+            if (this.parent != null && !this.parent.isScopeStarted(SessionScoped.class))
             {
-                if (!scopeClasses.contains(RequestScoped.class))
+                if (!scopeClasses.contains(SessionScoped.class))
                 {
-                    scopeClasses.add(RequestScoped.class);
+                    scopeClasses.add(SessionScoped.class);
                 }
             }
         }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/1018aee5/deltaspike/modules/test-control/impl/src/main/java/org/apache/deltaspike/testcontrol/impl/jsf/MockedJsf2TestContainer.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/test-control/impl/src/main/java/org/apache/deltaspike/testcontrol/impl/jsf/MockedJsf2TestContainer.java
b/deltaspike/modules/test-control/impl/src/main/java/org/apache/deltaspike/testcontrol/impl/jsf/MockedJsf2TestContainer.java
index c8952c3..ef2d142 100644
--- a/deltaspike/modules/test-control/impl/src/main/java/org/apache/deltaspike/testcontrol/impl/jsf/MockedJsf2TestContainer.java
+++ b/deltaspike/modules/test-control/impl/src/main/java/org/apache/deltaspike/testcontrol/impl/jsf/MockedJsf2TestContainer.java
@@ -228,8 +228,15 @@ public class MockedJsf2TestContainer implements ExternalContainer
 
     protected void initSession()
     {
-        this.session = new MockHttpSession();
-        this.session.setServletContext(this.servletContext);
+        if (this.request != null)
+        {
+            this.session = (MockHttpSession)this.request.getSession(true);
+        }
+        else
+        {
+            this.session = new MockHttpSession();
+            this.session.setServletContext(this.servletContext);
+        }
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/1018aee5/deltaspike/modules/test-control/impl/src/main/java/org/apache/deltaspike/testcontrol/impl/jsf/MockedJsfTestContainerAdapter.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/test-control/impl/src/main/java/org/apache/deltaspike/testcontrol/impl/jsf/MockedJsfTestContainerAdapter.java
b/deltaspike/modules/test-control/impl/src/main/java/org/apache/deltaspike/testcontrol/impl/jsf/MockedJsfTestContainerAdapter.java
index 7cffdc5..23a7c60 100644
--- a/deltaspike/modules/test-control/impl/src/main/java/org/apache/deltaspike/testcontrol/impl/jsf/MockedJsfTestContainerAdapter.java
+++ b/deltaspike/modules/test-control/impl/src/main/java/org/apache/deltaspike/testcontrol/impl/jsf/MockedJsfTestContainerAdapter.java
@@ -23,6 +23,7 @@ import org.apache.deltaspike.core.util.ExceptionUtils;
 import org.apache.deltaspike.testcontrol.spi.ExternalContainer;
 
 import javax.enterprise.context.RequestScoped;
+import javax.enterprise.context.SessionScoped;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
 
@@ -35,8 +36,14 @@ public class MockedJsfTestContainerAdapter implements ExternalContainer
 {
     private final Object mockedMyFacesTestContainer;
 
-    private final Method containerStartMethod;
-    private final Method containerStopMethod;
+    private final Method startContainerMethod;
+    private final Method stopContainerMethod;
+
+    private final Method startRequestMethod;
+    private final Method stopRequestMethod;
+
+    private final Method startSessionMethod;
+    private final Method stopSessionMethod;
 
     public MockedJsfTestContainerAdapter()
     {
@@ -50,8 +57,14 @@ public class MockedJsfTestContainerAdapter implements ExternalContainer
 
         try
         {
-            this.containerStartMethod = this.mockedMyFacesTestContainer.getClass().getDeclaredMethod("setUp");
-            this.containerStopMethod = this.mockedMyFacesTestContainer.getClass().getDeclaredMethod("tearDown");
+            this.startContainerMethod = this.mockedMyFacesTestContainer.getClass().getDeclaredMethod("setUp");
+            this.stopContainerMethod = this.mockedMyFacesTestContainer.getClass().getDeclaredMethod("tearDown");
+
+            this.startRequestMethod = this.mockedMyFacesTestContainer.getClass().getDeclaredMethod("startRequest");
+            this.stopRequestMethod = this.mockedMyFacesTestContainer.getClass().getDeclaredMethod("endRequest");
+
+            this.startSessionMethod = this.mockedMyFacesTestContainer.getClass().getDeclaredMethod("startSession");
+            this.stopSessionMethod = this.mockedMyFacesTestContainer.getClass().getDeclaredMethod("endSession");
         }
         catch (NoSuchMethodException e)
         {
@@ -61,7 +74,14 @@ public class MockedJsfTestContainerAdapter implements ExternalContainer
 
     public void boot()
     {
-        //MockedJsfTestContainer needs to be bootstrapped for every request
+        try
+        {
+            this.startContainerMethod.invoke(this.mockedMyFacesTestContainer);
+        }
+        catch (Exception e)
+        {
+            throw ExceptionUtils.throwAsRuntimeException(e);
+        }
     }
 
     @Override
@@ -71,8 +91,18 @@ public class MockedJsfTestContainerAdapter implements ExternalContainer
         {
             try
             {
-                //see the comment at #boot
-                this.containerStartMethod.invoke(this.mockedMyFacesTestContainer);
+                this.startRequestMethod.invoke(this.mockedMyFacesTestContainer);
+            }
+            catch (Exception e)
+            {
+                throw ExceptionUtils.throwAsRuntimeException(e);
+            }
+        }
+        else if (SessionScoped.class.equals(scopeClass))
+        {
+            try
+            {
+                this.startSessionMethod.invoke(this.mockedMyFacesTestContainer);
             }
             catch (Exception e)
             {
@@ -88,8 +118,18 @@ public class MockedJsfTestContainerAdapter implements ExternalContainer
         {
             try
             {
-                //see the comment at #shutdown
-                this.containerStopMethod.invoke(this.mockedMyFacesTestContainer);
+                this.stopRequestMethod.invoke(this.mockedMyFacesTestContainer);
+            }
+            catch (Exception e)
+            {
+                throw ExceptionUtils.throwAsRuntimeException(e);
+            }
+        }
+        else if (SessionScoped.class.equals(scopeClass))
+        {
+            try
+            {
+                this.stopSessionMethod.invoke(this.mockedMyFacesTestContainer);
             }
             catch (Exception e)
             {
@@ -100,7 +140,14 @@ public class MockedJsfTestContainerAdapter implements ExternalContainer
 
     public void shutdown()
     {
-        //MockedJsfTestContainer needs to be stopped after every request
+        try
+        {
+            this.stopContainerMethod.invoke(this.mockedMyFacesTestContainer);
+        }
+        catch (Exception e)
+        {
+            throw ExceptionUtils.throwAsRuntimeException(e);
+        }
     }
 
     @Override


Mime
View raw message