You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rz...@apache.org on 2023/03/12 19:07:16 UTC

[tomee] branch main updated: TOMEE-4190 RunWithApplicationComposer should support inheritance

This is an automated email from the ASF dual-hosted git repository.

rzo1 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomee.git


The following commit(s) were added to refs/heads/main by this push:
     new 7a77407ea4 TOMEE-4190 RunWithApplicationComposer should support inheritance
7a77407ea4 is described below

commit 7a77407ea4610ea1cccac54da016e8a47d50a61c
Author: G-Ork <ts...@gmail.com>
AuthorDate: Sun Mar 12 08:53:11 2023 +0100

    TOMEE-4190 RunWithApplicationComposer should support inheritance
    
    - Added Inherited annotation.
    - Added unittests to proove fix.
---
 .../openejb/junit5/RunWithApplicationComposer.java |  2 +
 .../openejb/junit5/AppComposerPerClassBase.java    | 54 ++++++++++++++++++++++
 .../AppComposerPerClassInheritanceTest.java}       | 19 ++------
 .../junit5/AppComposerSnifferExtension.java}       | 26 +++++------
 4 files changed, 70 insertions(+), 31 deletions(-)

diff --git a/container/openejb-junit5/src/main/java/org/apache/openejb/junit5/RunWithApplicationComposer.java b/container/openejb-junit5/src/main/java/org/apache/openejb/junit5/RunWithApplicationComposer.java
index 12ee2b3c47..17db2ddf02 100644
--- a/container/openejb-junit5/src/main/java/org/apache/openejb/junit5/RunWithApplicationComposer.java
+++ b/container/openejb-junit5/src/main/java/org/apache/openejb/junit5/RunWithApplicationComposer.java
@@ -20,10 +20,12 @@ package org.apache.openejb.junit5;
 import org.junit.jupiter.api.extension.ExtendWith;
 
 import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
+@Inherited
 @Target(ElementType.TYPE)
 @Retention(RetentionPolicy.RUNTIME)
 @ExtendWith(ApplicationComposerExtension.class)
diff --git a/container/openejb-junit5/src/test/java/org/apache/openejb/junit5/AppComposerPerClassBase.java b/container/openejb-junit5/src/test/java/org/apache/openejb/junit5/AppComposerPerClassBase.java
new file mode 100644
index 0000000000..dc73450d7b
--- /dev/null
+++ b/container/openejb-junit5/src/test/java/org/apache/openejb/junit5/AppComposerPerClassBase.java
@@ -0,0 +1,54 @@
+/*
+ * 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.junit5;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import org.apache.openejb.jee.jpa.unit.Persistence;
+import org.apache.openejb.jee.jpa.unit.PersistenceUnit;
+import org.apache.openejb.testing.Classes;
+import org.apache.openejb.testing.Module;
+import org.apache.openejb.testing.PersistenceRootUrl;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import jakarta.inject.Inject;
+
+@RunWithApplicationComposer(mode = ExtensionMode.PER_EACH)
+@Classes(cdi = true, innerClassesAsBean = true)
+@ExtendWith(AppComposerSnifferExtension.class)
+public class AppComposerPerClassBase {
+  
+  @Module
+  @PersistenceRootUrl(value = "")
+  public Persistence jpa() throws Exception {
+      return new Persistence(new PersistenceUnit("jpa"));
+  }
+
+  @Inject
+  private Marker bean;
+
+  @Test
+  public void run() {
+      assertNotNull(bean);
+      assertEquals(ApplicationComposerPerEachExtension.class, AppComposerSnifferExtension.COMPOSER_CLASS);
+  }
+
+  public static class Marker {}
+
+}
diff --git a/container/openejb-junit5/src/main/java/org/apache/openejb/junit5/RunWithApplicationComposer.java b/container/openejb-junit5/src/test/java/org/apache/openejb/junit5/AppComposerPerClassInheritanceTest.java
similarity index 62%
copy from container/openejb-junit5/src/main/java/org/apache/openejb/junit5/RunWithApplicationComposer.java
copy to container/openejb-junit5/src/test/java/org/apache/openejb/junit5/AppComposerPerClassInheritanceTest.java
index 12ee2b3c47..13f455cf66 100644
--- a/container/openejb-junit5/src/main/java/org/apache/openejb/junit5/RunWithApplicationComposer.java
+++ b/container/openejb-junit5/src/test/java/org/apache/openejb/junit5/AppComposerPerClassInheritanceTest.java
@@ -14,23 +14,10 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.openejb.junit5;
 
-import org.junit.jupiter.api.extension.ExtendWith;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Target(ElementType.TYPE)
-@Retention(RetentionPolicy.RUNTIME)
-@ExtendWith(ApplicationComposerExtension.class)
-public @interface RunWithApplicationComposer {
+import org.apache.openejb.testing.Classes;
 
-    /**
-     * The test container lifecycle <em>mode</em> to use.
-     */
-    ExtensionMode mode() default ExtensionMode.AUTO;
+@Classes(cdi = true, innerClassesAsBean = true)
+public class AppComposerPerClassInheritanceTest extends AppComposerPerClassBase {
 }
diff --git a/container/openejb-junit5/src/main/java/org/apache/openejb/junit5/RunWithApplicationComposer.java b/container/openejb-junit5/src/test/java/org/apache/openejb/junit5/AppComposerSnifferExtension.java
similarity index 53%
copy from container/openejb-junit5/src/main/java/org/apache/openejb/junit5/RunWithApplicationComposer.java
copy to container/openejb-junit5/src/test/java/org/apache/openejb/junit5/AppComposerSnifferExtension.java
index 12ee2b3c47..e9227bbeac 100644
--- a/container/openejb-junit5/src/main/java/org/apache/openejb/junit5/RunWithApplicationComposer.java
+++ b/container/openejb-junit5/src/test/java/org/apache/openejb/junit5/AppComposerSnifferExtension.java
@@ -14,23 +14,19 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.openejb.junit5;
 
-import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.api.extension.BeforeEachCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
 
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
+public class AppComposerSnifferExtension implements BeforeEachCallback {
 
-@Target(ElementType.TYPE)
-@Retention(RetentionPolicy.RUNTIME)
-@ExtendWith(ApplicationComposerExtension.class)
-public @interface RunWithApplicationComposer {
+  private static final ExtensionContext.Namespace NAMESPACE = ExtensionContext.Namespace.create(ApplicationComposerExtension.class.getName());
+  public static Class<?> COMPOSER_CLASS = null;
 
-    /**
-     * The test container lifecycle <em>mode</em> to use.
-     */
-    ExtensionMode mode() default ExtensionMode.AUTO;
-}
+  @Override
+  public void beforeEach(ExtensionContext context) throws Exception {
+    ApplicationComposerPerXYExtensionBase delegate = context.getStore(NAMESPACE).get(ApplicationComposerPerXYExtensionBase.class, ApplicationComposerPerXYExtensionBase.class);
+    AppComposerSnifferExtension.COMPOSER_CLASS = (null == delegate) ? null : delegate.getClass();
+  }
+}
\ No newline at end of file