You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by an...@apache.org on 2015/12/02 22:18:42 UTC

[1/4] tomee git commit: fixing app composer container handling

Repository: tomee
Updated Branches:
  refs/heads/tomee-7.0.0-M1 ffa109cc3 -> c90d7ee75


fixing app composer container handling


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

Branch: refs/heads/tomee-7.0.0-M1
Commit: c63f2ec304a174ccefd88dda48bbe440c2036a5f
Parents: 06f4b74
Author: Romain Manni-Bucau <rm...@gmail.com>
Authored: Wed Dec 2 18:37:28 2015 +0100
Committer: Romain Manni-Bucau <rm...@gmail.com>
Committed: Wed Dec 2 18:37:28 2015 +0100

----------------------------------------------------------------------
 .../openejb/testing/ApplicationComposers.java   | 14 +++---
 .../junit/ContainerAndApplicationRulesTest.java | 46 ++++++++++++++++++++
 2 files changed, 53 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/c63f2ec3/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java b/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java
index d7c42f2..bc5fefd 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java
@@ -385,6 +385,13 @@ public class ApplicationComposers {
     }
 
     public void deployApp(final Object inputTestInstance) throws Exception {
+        // test injections
+        ClassFinder testClassFinder = testClassFinders.remove(inputTestInstance);
+        if (testClassFinder == null) {
+            testClassFinders.put(inputTestInstance, testClassFinders.remove(this));
+            testClassFinder = testClassFinders.remove(inputTestInstance);
+        }
+
         final ClassLoader loader = testClass.getClassLoader();
         AppModule appModule = new AppModule(loader, testClass.getSimpleName());
 
@@ -731,13 +738,6 @@ public class ApplicationComposers {
 
         System.getProperties().put(OPENEJB_APPLICATION_COMPOSER_CONTEXT, appContext.getGlobalJndiContext());
 
-        // test injections
-        ClassFinder testClassFinder = testClassFinders.remove(inputTestInstance);
-        if (testClassFinder == null) {
-            testClassFinders.put(inputTestInstance, testClassFinders.remove(this));
-            testClassFinder = testClassFinders.remove(inputTestInstance);
-        }
-
         final List<Field> fields = new ArrayList<>(testClassFinder.findAnnotatedFields(AppResource.class));
         fields.addAll(testClassFinder.findAnnotatedFields(org.apache.openejb.junit.AppResource.class));
         for (final Field field : fields) {

http://git-wip-us.apache.org/repos/asf/tomee/blob/c63f2ec3/container/openejb-core/src/test/java/org/apache/openejb/junit/ContainerAndApplicationRulesTest.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/test/java/org/apache/openejb/junit/ContainerAndApplicationRulesTest.java b/container/openejb-core/src/test/java/org/apache/openejb/junit/ContainerAndApplicationRulesTest.java
new file mode 100644
index 0000000..1f0ce56
--- /dev/null
+++ b/container/openejb-core/src/test/java/org/apache/openejb/junit/ContainerAndApplicationRulesTest.java
@@ -0,0 +1,46 @@
+package org.apache.openejb.junit;
+
+import org.apache.openejb.api.configuration.PersistenceUnitDefinition;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.RuleChain;
+import org.junit.rules.TestRule;
+
+import javax.inject.Inject;
+import javax.inject.Provider;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+public class ContainerAndApplicationRulesTest {
+    private final ContainerRule instanceContainer = new ContainerRule(new Container());
+    private final ApplicationRule instanceServer = new ApplicationRule(new App());
+
+    @Rule
+    public final TestRule rule = RuleChain.outerRule(instanceContainer).around(instanceServer);
+
+    @Test
+    public void test() {
+        assertNotNull(instanceServer.getInstance(App.class).v);
+        assertNull(instanceContainer.getInstance(Container.class).ignored);
+    }
+
+    @org.apache.openejb.testing.Classes(cdi = true, value = Ignored.class) // @Classes invalid for a container
+    public static class Container {
+        @Inject
+        private Provider<Ignored> ignored;
+    }
+
+    @PersistenceUnitDefinition
+    @org.apache.openejb.testing.Classes(context = "App1", cdi = true, value = Valuable.class)
+    public static class App {
+        @Inject
+        private Valuable v;
+    }
+
+    public static class Ignored {
+    }
+
+    public static class Valuable {
+    }
+}


[2/4] tomee git commit: header

Posted by an...@apache.org.
header


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/04294bfd
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/04294bfd
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/04294bfd

Branch: refs/heads/tomee-7.0.0-M1
Commit: 04294bfdeaeb2d7fa6df80dd5129fbc7bf7e2aea
Parents: c63f2ec
Author: Romain Manni-Bucau <rm...@gmail.com>
Authored: Wed Dec 2 18:38:36 2015 +0100
Committer: Romain Manni-Bucau <rm...@gmail.com>
Committed: Wed Dec 2 18:38:36 2015 +0100

----------------------------------------------------------------------
 .../junit/ContainerAndApplicationRulesTest.java     | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/04294bfd/container/openejb-core/src/test/java/org/apache/openejb/junit/ContainerAndApplicationRulesTest.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/test/java/org/apache/openejb/junit/ContainerAndApplicationRulesTest.java b/container/openejb-core/src/test/java/org/apache/openejb/junit/ContainerAndApplicationRulesTest.java
index 1f0ce56..12df385 100644
--- a/container/openejb-core/src/test/java/org/apache/openejb/junit/ContainerAndApplicationRulesTest.java
+++ b/container/openejb-core/src/test/java/org/apache/openejb/junit/ContainerAndApplicationRulesTest.java
@@ -1,3 +1,19 @@
+/*
+ * 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.openejb.junit;
 
 import org.apache.openejb.api.configuration.PersistenceUnitDefinition;


[4/4] tomee git commit: Merge branch 'master' into tomee-7.0.0-M1

Posted by an...@apache.org.
Merge branch 'master' into tomee-7.0.0-M1


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

Branch: refs/heads/tomee-7.0.0-M1
Commit: c90d7ee754d1868f5e158aca841aa37f995ccc3a
Parents: ffa109c f9f73a4
Author: AndyGee <an...@gmx.de>
Authored: Wed Dec 2 22:18:23 2015 +0100
Committer: AndyGee <an...@gmx.de>
Committed: Wed Dec 2 22:18:23 2015 +0100

----------------------------------------------------------------------
 .../openejb/testing/ApplicationComposers.java   | 37 ++++++++----
 .../apache/openejb/bval/BeanValidationTest.java |  4 ++
 .../junit/ContainerAndApplicationRulesTest.java | 62 ++++++++++++++++++++
 3 files changed, 93 insertions(+), 10 deletions(-)
----------------------------------------------------------------------



[3/4] tomee git commit: some NPE protections

Posted by an...@apache.org.
some NPE protections


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

Branch: refs/heads/tomee-7.0.0-M1
Commit: f9f73a49bc51e56613da9e64c85b79502fcb5b2a
Parents: 04294bf
Author: Romain Manni-Bucau <rm...@gmail.com>
Authored: Wed Dec 2 19:31:31 2015 +0100
Committer: Romain Manni-Bucau <rm...@gmail.com>
Committed: Wed Dec 2 19:31:31 2015 +0100

----------------------------------------------------------------------
 .../openejb/testing/ApplicationComposers.java   | 35 +++++++++++++++-----
 .../apache/openejb/bval/BeanValidationTest.java |  4 +++
 2 files changed, 30 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/f9f73a49/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java b/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java
index bc5fefd..4f54482 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java
@@ -373,8 +373,7 @@ public class ApplicationComposers {
 
     @SuppressWarnings("unchecked")
     public void before(final Object inputTestInstance) throws Exception {
-        // we hacked testInstance while we were not aware of it, now we can solve it
-        testClassFinders.put(inputTestInstance, testClassFinders.remove(this));
+        fixFakeClassFinder(inputTestInstance);
 
         startContainer(inputTestInstance);
 
@@ -385,12 +384,7 @@ public class ApplicationComposers {
     }
 
     public void deployApp(final Object inputTestInstance) throws Exception {
-        // test injections
-        ClassFinder testClassFinder = testClassFinders.remove(inputTestInstance);
-        if (testClassFinder == null) {
-            testClassFinders.put(inputTestInstance, testClassFinders.remove(this));
-            testClassFinder = testClassFinders.remove(inputTestInstance);
-        }
+        final ClassFinder testClassFinder = fixFakeClassFinder(inputTestInstance);
 
         final ClassLoader loader = testClass.getClassLoader();
         AppModule appModule = new AppModule(loader, testClass.getSimpleName());
@@ -773,6 +767,29 @@ public class ApplicationComposers {
         testClassFinders.put(this, testClassFinder);
     }
 
+    private ClassFinder fixFakeClassFinder(final Object inputTestInstance) {
+        // test injections, we faked the instance before having it so ensuring we use the right finder
+        ClassFinder testClassFinder = testClassFinders.get(inputTestInstance);
+        if (testClassFinder == null) {
+            final ApplicationComposers self = this;
+            final ClassFinder remove = testClassFinders.remove(self);
+            if (remove != null) {
+                testClassFinders.put(inputTestInstance, remove);
+                testClassFinder = remove;
+                afterRunnables.add(new Runnable() { // reset state for next test
+                    @Override
+                    public void run() {
+                        final ClassFinder classFinder = testClassFinders.remove(inputTestInstance);
+                        if (classFinder != null) {
+                            testClassFinders.put(self, classFinder);
+                        }
+                    }
+                });
+            }
+        }
+        return testClassFinder;
+    }
+
     private boolean isCdi(final boolean cdi, final Class<?>[] cdiInterceptors,
                           final Class<?>[] cdiAlternatives, final Class<?>[] cdiStereotypes,
                           final Class<?>[] cdiDecorators) {
@@ -1264,7 +1281,7 @@ public class ApplicationComposers {
     public void startContainer(final Object instance) throws Exception {
         originalProperties = (Properties) System.getProperties().clone();
         originalLoader = Thread.currentThread().getContextClassLoader();
-        testClassFinders.remove(this); // see constructor
+        fixFakeClassFinder(instance);
 
         // For the moment we just take the first @Configuration method
         // maybe later we can add something fancy to allow multiple configurations using a qualifier

http://git-wip-us.apache.org/repos/asf/tomee/blob/f9f73a49/container/openejb-core/src/test/java/org/apache/openejb/bval/BeanValidationTest.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/test/java/org/apache/openejb/bval/BeanValidationTest.java b/container/openejb-core/src/test/java/org/apache/openejb/bval/BeanValidationTest.java
index 9ac79d6..4d7136f 100644
--- a/container/openejb-core/src/test/java/org/apache/openejb/bval/BeanValidationTest.java
+++ b/container/openejb-core/src/test/java/org/apache/openejb/bval/BeanValidationTest.java
@@ -23,6 +23,7 @@ import org.apache.openejb.jee.jpa.unit.PersistenceUnit;
 import org.apache.openejb.junit.ApplicationComposer;
 import org.apache.openejb.testing.Configuration;
 import org.apache.openejb.testing.Module;
+import org.apache.openejb.testing.SimpleLog;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -51,12 +52,15 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+@SimpleLog
 @RunWith(ApplicationComposer.class)
 public class BeanValidationTest {
     @EJB
     private PersistManager persistManager;
+
     @Resource
     private Validator validator;
+
     @Resource
     private ValidatorFactory validatorFactory;