Author: struberg
Date: Fri Apr 13 12:33:09 2018
New Revision: 1829067

URL: http://svn.apache.org/viewvc?rev=1829067&view=rev
Log:
OWB-1235 add test to ensure our ConversationContext is Serializable

Modified:
    
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/conversation/ConversationScopedBean.java
    
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/conversation/ConversationScopedTest.java

Modified: 
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/conversation/ConversationScopedBean.java
URL: 
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/conversation/ConversationScopedBean.java?rev=1829067&r1=1829066&r2=1829067&view=diff
==============================================================================
--- 
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/conversation/ConversationScopedBean.java
 (original)
+++ 
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/conversation/ConversationScopedBean.java
 Fri Apr 13 12:33:09 2018
@@ -44,4 +44,20 @@ public class ConversationScopedBean impl
     {
         return conversation;
     }
+
+    public void begin()
+    {
+        if (conversation.isTransient())
+        {
+            conversation.begin();
+        }
+    }
+
+    public void end()
+    {
+        if (!conversation.isTransient())
+        {
+            conversation.end();
+        }
+    }
 }

Modified: 
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/conversation/ConversationScopedTest.java
URL: 
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/conversation/ConversationScopedTest.java?rev=1829067&r1=1829066&r2=1829067&view=diff
==============================================================================
--- 
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/conversation/ConversationScopedTest.java
 (original)
+++ 
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/conversation/ConversationScopedTest.java
 Fri Apr 13 12:33:09 2018
@@ -18,13 +18,22 @@
 */
 package org.apache.webbeans.test.contexts.conversation;
 
+import javax.enterprise.context.ConversationScoped;
 import javax.enterprise.context.RequestScoped;
+import javax.enterprise.context.SessionScoped;
+import javax.enterprise.context.spi.Context;
 
 import org.junit.Assert;
 import org.apache.webbeans.config.OpenWebBeansConfiguration;
 import org.apache.webbeans.test.AbstractUnitTest;
 import org.junit.Test;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
 /**
  * test for CDI Conversations
  */
@@ -32,7 +41,7 @@ public class ConversationScopedTest exte
 {
 
     @Test
-    public void testTransientConversation()
+    public void testTransientConversation() throws Exception
     {
         try
         {
@@ -41,9 +50,13 @@ public class ConversationScopedTest exte
 
             ConversationScopedBean instance = 
getInstance(ConversationScopedBean.class);
             instance.setValue("a");
+            instance.begin();
+            ensureSerialisableContext();
 
             restartContext(RequestScoped.class);
 
+
+            instance.end();
             Assert.assertNull(instance.getValue());
 
         }
@@ -55,7 +68,7 @@ public class ConversationScopedTest exte
 
 
     @Test
-    public void testConversationEvents()
+    public void testConversationEvents() throws Exception
     {
         try
         {
@@ -70,6 +83,8 @@ public class ConversationScopedTest exte
 
             Assert.assertTrue(ConversationScopedInitBean.gotStarted);
 
+            ensureSerialisableContext();
+
             shutDownContainer();
 
             Assert.assertTrue(EndConversationObserver.endConversationCalled);
@@ -80,5 +95,19 @@ public class ConversationScopedTest exte
         }
     }
 
+    private void ensureSerialisableContext() throws IOException, 
ClassNotFoundException
+    {
+        Context context = 
getBeanManager().getContext(ConversationScoped.class);
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream oos = new ObjectOutputStream(baos);
+        oos.writeObject(context);
+        byte[] ba = baos.toByteArray();
+
+        ByteArrayInputStream bais = new ByteArrayInputStream(ba);
+        ObjectInputStream ois = new ObjectInputStream(bais);
+        Context newContext =  (Context) ois.readObject();
+        Assert.assertNotNull(newContext);
+    }
+
 
 }


Reply via email to