rmannibucau commented on a change in pull request #767:
URL: https://github.com/apache/tomee/pull/767#discussion_r595920794



##########
File path: 
container/openejb-core/src/main/java/org/apache/openejb/junit/jupiter/ApplicationComposerExtension.java
##########
@@ -0,0 +1,155 @@
+/*
+ * 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.jupiter;
+
+import org.apache.openejb.OpenEJBRuntimeException;
+import org.apache.openejb.testing.ApplicationComposers;
+import org.apache.openejb.testing.SingleApplicationComposerBase;
+import org.junit.jupiter.api.extension.*;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+
+public class ApplicationComposerExtension extends 
ApplicationComposerExtensionBase implements BeforeAllCallback, 
AfterAllCallback, BeforeEachCallback, AfterEachCallback {
+
+    private static final ExtensionContext.Namespace NAMESPACE = 
ExtensionContext.Namespace.create(ApplicationComposerExtension.class.getName());
+    private static final SingleApplicationComposerBase BASE = new 
SingleApplicationComposerBase();
+
+    @Override
+    public void beforeAll(ExtensionContext context) throws Exception {
+
+        if (isPerJvm(context)) {
+            BASE.start(context.getTestClass().orElse(null));
+        } else if (isPerAll(context)) {
+            doStart(context);
+        } else if (isPerDefault(context)) {
+            if (isPerClass(context)) {
+                doStart(context);
+            }
+        }
+
+        if (isPerClass(context)) {
+            doInject(context);
+        }
+    }
+
+    @Override
+    public void afterAll(ExtensionContext context) throws Exception {
+        if (isPerJvm(context) || isPerAll(context)) {
+            doRelease(context);
+        } else if (isPerDefault(context) && isPerClass(context)) {
+            doRelease(context);
+        }
+    }
+
+
+    @Override
+    public void beforeEach(ExtensionContext context) {
+
+        if (isPerEach(context)) {

Review comment:
       Yes, my starting point is that it is very error prone to test multiple 
times the same thing (let's ignore perf since it is simple tests). Since any 
"start" logic will put something (likely different) in the store, the presence 
can be used to test which case you are in to handle > start callbacks.
   One way to see it is to have 3 impls (3 extensions) of 
BeforeAll+BeforeEach+AfterAll+AfterEach and put the impl in beforeAll of this 
extension which will then acts as a facade and select which impl to use in 
before all.
   This way code path is unique each time and simple, only this extension 
beforeAll has some mode usage, all others are passthrough.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to