openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1811779 - in /openwebbeans/meecrowave/trunk/meecrowave-junit/src/main/java/org/apache/meecrowave/junit5: MeecrowaveConfig.java MeecrowaveExtension.java
Date Tue, 10 Oct 2017 23:07:56 GMT
Author: rmannibucau
Date: Tue Oct 10 23:07:56 2017
New Revision: 1811779

URL: http://svn.apache.org/viewvc?rev=1811779&view=rev
Log:
adding scope handling to junit 5 integration for consistency

Modified:
    openwebbeans/meecrowave/trunk/meecrowave-junit/src/main/java/org/apache/meecrowave/junit5/MeecrowaveConfig.java
    openwebbeans/meecrowave/trunk/meecrowave-junit/src/main/java/org/apache/meecrowave/junit5/MeecrowaveExtension.java

Modified: openwebbeans/meecrowave/trunk/meecrowave-junit/src/main/java/org/apache/meecrowave/junit5/MeecrowaveConfig.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-junit/src/main/java/org/apache/meecrowave/junit5/MeecrowaveConfig.java?rev=1811779&r1=1811778&r2=1811779&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-junit/src/main/java/org/apache/meecrowave/junit5/MeecrowaveConfig.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-junit/src/main/java/org/apache/meecrowave/junit5/MeecrowaveConfig.java
Tue Oct 10 23:07:56 2017
@@ -20,6 +20,7 @@ package org.apache.meecrowave.junit5;
 
 import org.junit.jupiter.api.extension.ExtendWith;
 
+import java.lang.annotation.Annotation;
 import java.lang.annotation.Retention;
 import java.lang.annotation.Target;
 
@@ -83,4 +84,6 @@ public @interface MeecrowaveConfig {
     boolean tomcatWrapLoader() default false;
     String sharedLibraries() default "";
     boolean useLog4j2JulLogManager() default false;
+
+    Class<? extends Annotation>[] scopes() default {};
 }

Modified: openwebbeans/meecrowave/trunk/meecrowave-junit/src/main/java/org/apache/meecrowave/junit5/MeecrowaveExtension.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-junit/src/main/java/org/apache/meecrowave/junit5/MeecrowaveExtension.java?rev=1811779&r1=1811778&r2=1811779&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-junit/src/main/java/org/apache/meecrowave/junit5/MeecrowaveExtension.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-junit/src/main/java/org/apache/meecrowave/junit5/MeecrowaveExtension.java
Tue Oct 10 23:07:56 2017
@@ -18,10 +18,17 @@
  */
 package org.apache.meecrowave.junit5;
 
+import static java.util.Arrays.asList;
+
 import java.io.File;
+import java.lang.annotation.Annotation;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
 import java.util.Optional;
+import java.util.stream.Stream;
 
 import javax.enterprise.context.spi.CreationalContext;
 
@@ -90,6 +97,10 @@ public class MeecrowaveExtension impleme
 
     @Override
     public void beforeEach(final ExtensionContext context) throws Exception {
+        getScopes(context).ifPresent(scopes -> {
+           final ContextsService contextsService = WebBeansContext.currentInstance().getContextsService();
+           Stream.of(scopes).forEach(s -> contextsService.startContext(s, null));
+        });
         context.getStore(NAMESPACE).put(CreationalContext.class.getName(), Injector.inject(context.getTestInstance().orElse(null)));
         Injector.injectConfig(Meecrowave.Builder.class.cast(context.getStore(NAMESPACE).get(Meecrowave.Builder.class.getName())),
context.getTestInstance().orElse(null));
     }
@@ -97,5 +108,18 @@ public class MeecrowaveExtension impleme
     @Override
     public void afterEach(final ExtensionContext context) throws Exception {
         CreationalContext.class.cast(context.getStore(NAMESPACE).get(CreationalContext.class.getName())).release();
+        getScopes(context).ifPresent(scopes -> {
+            final ContextsService contextsService = WebBeansContext.currentInstance().getContextsService();
+            final List<Class<? extends Annotation>> list = new ArrayList<>(asList(scopes));
+            Collections.reverse(list);
+            list.forEach(s -> contextsService.endContext(s, null));
+        });
+    }
+
+    private Optional<Class<? extends Annotation>[]> getScopes(final ExtensionContext
context) {
+        return context.getElement()
+                      .map(e -> e.getAnnotation(MeecrowaveConfig.class))
+                      .map(MeecrowaveConfig::scopes)
+                      .filter(s -> s.length > 0);
     }
 }



Mime
View raw message