Hi

Can we revert it and add a flag - false by default - or a scope rule - new
ScopeRule(RequestScoped.class, ...) - to solve it.

Implicit start hides issues in actual deployment if not controllable.



---------- Message transféré ----------
De : <[email protected]>
Date : 10 oct. 2017 20:53
Objet : svn commit: r1811764 - in /openwebbeans/meecrowave/trunk: ./
meecrowave-junit/src/main/java/org/apache/meecrowave/junit/
meecrowave-junit/src/main/java/org/apache/meecrowave/testing/
meecrowave-junit/src/test/java/org/apache/meecrowave/junit/ meecrowav...
À : <[email protected]>
Cc :

Author: struberg
Date: Tue Oct 10 19:53:51 2017
New Revision: 1811764

URL: http://svn.apache.org/viewvc?rev=1811764&view=rev
Log:
MEECROWAVE-71 setup RequestContext and SessionContext for each test

Added:
    
openwebbeans/meecrowave/trunk/meecrowave-junit/src/test/java/org/app/MyAppClass.java
 (with props)
    
openwebbeans/meecrowave/trunk/meecrowave-junit/src/test/java/org/app/MyReqClass.java
 (with props)
    openwebbeans/meecrowave/trunk/meecrowave-junit/src/test/resources/
    openwebbeans/meecrowave/trunk/meecrowave-junit/src/test/
resources/META-INF/
    
openwebbeans/meecrowave/trunk/meecrowave-junit/src/test/resources/META-INF/beans.xml
 (with props)
Modified:
    openwebbeans/meecrowave/trunk/meecrowave-junit/src/main/
java/org/apache/meecrowave/junit/MonoMeecrowave.java
    openwebbeans/meecrowave/trunk/meecrowave-junit/src/main/
java/org/apache/meecrowave/testing/MonoBase.java
    openwebbeans/meecrowave/trunk/meecrowave-junit/src/test/
java/org/apache/meecrowave/junit/MonoMeecrowaveRuleTest.java
    openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/
main/resources/bin/meecrowave.sh
    openwebbeans/meecrowave/trunk/pom.xml

Modified: openwebbeans/meecrowave/trunk/meecrowave-junit/src/main/
java/org/apache/meecrowave/junit/MonoMeecrowave.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/
meecrowave-junit/src/main/java/org/apache/meecrowave/
junit/MonoMeecrowave.java?rev=1811764&r1=1811763&r2=1811764&view=diff
============================================================
==================
--- openwebbeans/meecrowave/trunk/meecrowave-junit/src/main/
java/org/apache/meecrowave/junit/MonoMeecrowave.java (original)
+++ openwebbeans/meecrowave/trunk/meecrowave-junit/src/main/
java/org/apache/meecrowave/junit/MonoMeecrowave.java Tue Oct 10 19:53:51
2017
@@ -21,15 +21,24 @@ package org.apache.meecrowave.junit;
 import org.apache.meecrowave.Meecrowave;
 import org.apache.meecrowave.testing.Injector;
 import org.apache.meecrowave.testing.MonoBase;
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.spi.ContextsService;
 import org.junit.rules.MethodRule;
 import org.junit.runners.BlockJUnit4ClassRunner;
 import org.junit.runners.model.InitializationError;
 import org.junit.runners.model.Statement;

+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.context.SessionScoped;
 import javax.enterprise.context.spi.CreationalContext;
 import java.util.List;

-// a MeecrowaveRule starting a single container, very awesome for
forkCount=1, reuseForks=true
+/**
+ * A MeecrowaveRule starting a single container.
+ * Very awesome for forkCount=1, reuseForks=true
+ *
+ */
+
 public class MonoMeecrowave {
     private static final MonoBase BASE = new MonoBase();
     private static final AutoCloseable NOOP_CLOSEABLE = () -> {
@@ -47,12 +56,18 @@ public class MonoMeecrowave {
                 @Override
                 public void evaluate() throws Throwable {
                     BASE.startIfNeeded();
+                    ContextsService contextsService = WebBeansContext.
currentInstance().getContextsService();
+
                     configInjection(test.getClass(), test);
                     final CreationalContext<?> creationalContext =
Injector.inject(test);
                     try {
+                        contextsService.startContext(RequestScoped.class,
null);
+                        contextsService.startContext(SessionScoped.class,
null);
                         base.evaluate();
                     } finally {
                         creationalContext.release();
+                        contextsService.endContext(SessionScoped.class,
null);
+                        contextsService.endContext(RequestScoped.class,
null);
                     }
                 }


Modified: openwebbeans/meecrowave/trunk/meecrowave-junit/src/main/
java/org/apache/meecrowave/testing/MonoBase.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/
meecrowave-junit/src/main/java/org/apache/meecrowave/
testing/MonoBase.java?rev=1811764&r1=1811763&r2=1811764&view=diff
============================================================
==================
--- openwebbeans/meecrowave/trunk/meecrowave-junit/src/main/
java/org/apache/meecrowave/testing/MonoBase.java (original)
+++ openwebbeans/meecrowave/trunk/meecrowave-junit/src/main/
java/org/apache/meecrowave/testing/MonoBase.java Tue Oct 10 19:53:51 2017
@@ -27,7 +27,7 @@ import java.util.concurrent.atomic.Atomi
 import java.util.stream.StreamSupport;

 public class MonoBase {
-    private static final AtomicReference<AutoCloseable> CONTAINER = new
AtomicReference<>();
+    private static final AtomicReference<Meecrowave> CONTAINER = new
AtomicReference<>();
     private static final AtomicReference<Meecrowave.Builder> CONFIGURATION
= new AtomicReference<>();

     public Meecrowave.Builder doBoot() {
@@ -90,6 +90,8 @@ public class MonoBase {
         return getConfiguration();
     }

+
+
     public interface Configuration {
         default int order() {
             return 0;

Modified: openwebbeans/meecrowave/trunk/meecrowave-junit/src/test/
java/org/apache/meecrowave/junit/MonoMeecrowaveRuleTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/
meecrowave-junit/src/test/java/org/apache/meecrowave/
junit/MonoMeecrowaveRuleTest.java?rev=1811764&r1=1811763&
r2=1811764&view=diff
============================================================
==================
--- openwebbeans/meecrowave/trunk/meecrowave-junit/src/test/
java/org/apache/meecrowave/junit/MonoMeecrowaveRuleTest.java (original)
+++ openwebbeans/meecrowave/trunk/meecrowave-junit/src/test/
java/org/apache/meecrowave/junit/MonoMeecrowaveRuleTest.java Tue Oct 10
19:53:51 2017
@@ -21,9 +21,12 @@ package org.apache.meecrowave.junit;
 import org.apache.meecrowave.Meecrowave;
 import org.apache.meecrowave.io.IO;
 import org.apache.meecrowave.testing.ConfigurationInject;
+import org.app.MyAppClass;
+import org.app.MyReqClass;
 import org.junit.Test;
 import org.junit.runner.RunWith;

+import javax.inject.Inject;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
@@ -38,14 +41,43 @@ public class MonoMeecrowaveRuleTest {
     public static final MonoMeecrowave.Rule RULE = new
MonoMeecrowave.Rule();
     */

+    private static int count = 0;
+
     @ConfigurationInject
     private Meecrowave.Builder config;

+    private @Inject MyAppClass appClass;
+    private @Inject MyReqClass reqClass;
+
+
     @Test
     public void test() throws IOException {
         assertEquals("simple", slurp(new URL("http://localhost:"; +
config.getHttpPort() + "/api/test")));
+
+        testScopes();
+    }
+
+    @Test
+    public void anotherTest() throws IOException {
+        assertEquals("simple", slurp(new URL("http://localhost:"; +
config.getHttpPort() + "/api/test")));
+
+        testScopes();
+    }
+
+    private void testScopes() {
+        count++;
+
+        if (count == 2) {
+            assertEquals("beenhere", appClass.getX());
+            assertEquals("init", reqClass.getX());
+        }
+        else {
+            reqClass.setX("beenhere");
+            appClass.setX("beenhere");
+        }
     }

+
     private String slurp(final URL url) {
         try (final InputStream is = url.openStream()) {
             return IO.toString(is);
@@ -54,4 +86,5 @@ public class MonoMeecrowaveRuleTest {
         }
         return null;
     }
+
 }

Added: openwebbeans/meecrowave/trunk/meecrowave-junit/src/test/
java/org/app/MyAppClass.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/
meecrowave-junit/src/test/java/org/app/MyAppClass.java?rev=1811764&view=auto
============================================================
==================
--- 
openwebbeans/meecrowave/trunk/meecrowave-junit/src/test/java/org/app/MyAppClass.java
(added)
+++ 
openwebbeans/meecrowave/trunk/meecrowave-junit/src/test/java/org/app/MyAppClass.java
Tue Oct 10 19:53:51 2017
@@ -0,0 +1,35 @@
+/*
+ * 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.app;
+
+import javax.enterprise.context.ApplicationScoped;
+
+/**
+ * @author <a href="mailto:[email protected]";>Mark Struberg</a>
+ */
+@ApplicationScoped
+public class MyAppClass {
+    private String x = "init";
+
+    public String getX() {
+        return x;
+    }
+
+    public void setX(String x) {
+        this.x = x;
+    }
+}

Propchange: openwebbeans/meecrowave/trunk/meecrowave-junit/src/test/
java/org/app/MyAppClass.java
------------------------------------------------------------
------------------
    svn:eol-style = native

Added: openwebbeans/meecrowave/trunk/meecrowave-junit/src/test/
java/org/app/MyReqClass.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/
meecrowave-junit/src/test/java/org/app/MyReqClass.java?rev=1811764&view=auto
============================================================
==================
--- 
openwebbeans/meecrowave/trunk/meecrowave-junit/src/test/java/org/app/MyReqClass.java
(added)
+++ 
openwebbeans/meecrowave/trunk/meecrowave-junit/src/test/java/org/app/MyReqClass.java
Tue Oct 10 19:53:51 2017
@@ -0,0 +1,35 @@
+/*
+ * 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.app;
+
+import javax.enterprise.context.RequestScoped;
+
+/**
+ * @author <a href="mailto:[email protected]";>Mark Struberg</a>
+ */
+@RequestScoped
+public class MyReqClass {
+    private String x = "init";
+
+    public String getX() {
+        return x;
+    }
+
+    public void setX(String x) {
+        this.x = x;
+    }
+}

Propchange: openwebbeans/meecrowave/trunk/meecrowave-junit/src/test/
java/org/app/MyReqClass.java
------------------------------------------------------------
------------------
    svn:eol-style = native

Added: openwebbeans/meecrowave/trunk/meecrowave-junit/src/test/
resources/META-INF/beans.xml
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/
meecrowave-junit/src/test/resources/META-INF/beans.xml?rev=1811764&view=auto
============================================================
==================
    (empty)

Propchange: openwebbeans/meecrowave/trunk/meecrowave-junit/src/test/
resources/META-INF/beans.xml
------------------------------------------------------------
------------------
    svn:eol-style = native

Modified: openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/
main/resources/bin/meecrowave.sh
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/
meecrowave-maven-plugin/src/main/resources/bin/meecrowave.
sh?rev=1811764&r1=1811763&r2=1811764&view=diff
============================================================
==================
--- openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/
main/resources/bin/meecrowave.sh (original)
+++ openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/
main/resources/bin/meecrowave.sh Tue Oct 10 19:53:51 2017
@@ -209,6 +209,7 @@ if $cygwin; then
   MEECROWAVE_BASE=`cygpath --absolute --windows "$MEECROWAVE_BASE"`
   MEECROWAVE_TMPDIR=`cygpath --absolute --windows "$MEECROWAVE_TMPDIR"`
   CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
+  JAVA_ENDORSED_DIRS=`cygpath --path --windows "$JAVA_ENDORSED_DIRS"`
 fi

 if [ -z "$JSSE_OPTS" ] ; then

Modified: openwebbeans/meecrowave/trunk/pom.xml
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/
pom.xml?rev=1811764&r1=1811763&r2=1811764&view=diff
============================================================
==================
--- openwebbeans/meecrowave/trunk/pom.xml (original)
+++ openwebbeans/meecrowave/trunk/pom.xml Tue Oct 10 19:53:51 2017
@@ -93,7 +93,6 @@
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-surefire-plugin</artifactId>
-        <version>2.19.1</version>
         <configuration>
           <trimStackTrace>false</trimStackTrace>
         </configuration>

Reply via email to