deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject git commit: DELTASPIKE-466 ExternalContainer spi added
Date Wed, 11 Dec 2013 09:01:31 GMT
Updated Branches:
  refs/heads/master 896bf88ae -> 307c757ae


DELTASPIKE-466 ExternalContainer spi added


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

Branch: refs/heads/master
Commit: 307c757ae1a18595852f01d7c50ed73311eb9364
Parents: 896bf88
Author: gpetracek <gpetracek@apache.org>
Authored: Wed Dec 11 09:46:45 2013 +0100
Committer: gpetracek <gpetracek@apache.org>
Committed: Wed Dec 11 09:49:02 2013 +0100

----------------------------------------------------------------------
 .../deltaspike/testcontrol/api/TestControl.java |  5 ++
 .../testcontrol/api/junit/CdiTestRunner.java    | 62 ++++++++++++++++++++
 .../api/literal/TestControlLiteral.java         |  6 ++
 .../testcontrol/spi/ExternalContainer.java      | 34 +++++++++++
 4 files changed, 107 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/307c757a/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/TestControl.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/TestControl.java
b/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/TestControl.java
index d32b2fb..c492c97 100644
--- a/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/TestControl.java
+++ b/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/TestControl.java
@@ -52,4 +52,9 @@ public @interface TestControl
      * only supported on test-class-level
      */
     Class<? extends Handler> logHandler() default ConsoleHandler.class;
+
+    /**
+     * Requires additional service-loader config
+     */
+    boolean startExternalContainers() default true;
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/307c757a/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 fcd85c8..8093357 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
@@ -29,6 +29,7 @@ import org.apache.deltaspike.core.util.ProjectStageProducer;
 import org.apache.deltaspike.core.util.ServiceUtils;
 import org.apache.deltaspike.testcontrol.api.TestControl;
 import org.apache.deltaspike.testcontrol.api.literal.TestControlLiteral;
+import org.apache.deltaspike.testcontrol.spi.ExternalContainer;
 import org.apache.deltaspike.testcontrol.spi.junit.TestStatementDecoratorFactory;
 import org.junit.Test;
 import org.junit.internal.runners.statements.FailOnTimeout;
@@ -358,6 +359,8 @@ public class CdiTestRunner extends BlockJUnit4ClassRunner
 
         private Stack<Class<? extends Annotation>> startedScopes = new Stack<Class<?
extends Annotation>>();
 
+        private List<ExternalContainer> externalContainers;
+
         ContainerAwareTestContext(TestControl testControl, ContainerAwareTestContext parent)
         {
             this.parent = parent;
@@ -404,6 +407,8 @@ public class CdiTestRunner extends BlockJUnit4ClassRunner
                 {
                     container.boot();
                     setContainerStarted();
+
+                    bootExternalContainers();
                 }
             }
 
@@ -423,6 +428,40 @@ public class CdiTestRunner extends BlockJUnit4ClassRunner
             startContexts(container, restrictedScopes.toArray(new Class[restrictedScopes.size()]));
         }
 
+        private void bootExternalContainers()
+        {
+            if (!this.testControl.startExternalContainers())
+            {
+                return;
+            }
+
+            if (this.externalContainers == null)
+            {
+                this.externalContainers = ServiceUtils.loadServiceImplementations(ExternalContainer.class);
+                Collections.sort(this.externalContainers, new Comparator<ExternalContainer>()
+                {
+                    @Override
+                    public int compare(ExternalContainer ec1, ExternalContainer ec2)
+                    {
+                        return ec1.getOrdinal() > ec2.getOrdinal() ? 1 : -1;
+                    }
+                });
+
+                for (ExternalContainer externalContainer : this.externalContainers)
+                {
+                    try
+                    {
+                        externalContainer.boot();
+                    }
+                    catch (RuntimeException e)
+                    {
+                        Logger.getLogger(CdiTestRunner.class.getName()).log(Level.WARNING,
+                                "booting " + externalContainer.getClass().getName() + " failed",
e);
+                    }
+                }
+            }
+        }
+
         void applyAfterClassConfig()
         {
             CdiContainer container = CdiContainerLoader.getCdiContainer();
@@ -433,12 +472,35 @@ public class CdiTestRunner extends BlockJUnit4ClassRunner
             {
                 if (CdiTestSuiteRunner.isStopContainerAllowed())
                 {
+                    shutdownExternalContainers();
+
                     container.shutdown(); //stop the container on the same level which started
it
                     CdiTestSuiteRunner.setContainerStarted(false);
                 }
             }
         }
 
+        private void shutdownExternalContainers()
+        {
+            if (this.externalContainers == null)
+            {
+                return;
+            }
+
+            for (ExternalContainer externalContainer : this.externalContainers)
+            {
+                try
+                {
+                    externalContainer.shutdown();
+                }
+                catch (RuntimeException e)
+                {
+                    Logger.getLogger(CdiTestRunner.class.getName()).log(Level.WARNING,
+                            "shutting down " + externalContainer.getClass().getName() + "
failed", e);
+                }
+            }
+        }
+
         void applyBeforeMethodConfig()
         {
             this.previousProjectStage = ProjectStageProducer.getInstance().getProjectStage();

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/307c757a/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/literal/TestControlLiteral.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/literal/TestControlLiteral.java
b/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/literal/TestControlLiteral.java
index 1e72856..071cdf6 100644
--- a/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/literal/TestControlLiteral.java
+++ b/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/api/literal/TestControlLiteral.java
@@ -54,4 +54,10 @@ public class TestControlLiteral extends AnnotationLiteral<TestControl>
implement
     {
         return defaultInstance.logHandler();
     }
+
+    @Override
+    public boolean startExternalContainers()
+    {
+        return defaultInstance.startExternalContainers();
+    }
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/307c757a/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/spi/ExternalContainer.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/spi/ExternalContainer.java
b/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/spi/ExternalContainer.java
new file mode 100644
index 0000000..ab4e8c8
--- /dev/null
+++ b/deltaspike/modules/test-control/api/src/main/java/org/apache/deltaspike/testcontrol/spi/ExternalContainer.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.deltaspike.testcontrol.spi;
+
+public interface ExternalContainer
+{
+    /**
+     * Bootstraps the container
+     */
+    void boot();
+
+    /**
+     * Closes the container
+     */
+    void shutdown();
+
+    int getOrdinal();
+}


Mime
View raw message