openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1477173 - in /openwebbeans/trunk: webbeans-impl/src/main/java/org/apache/webbeans/intercept/NormalScopedBeanInterceptorHandler.java webbeans-web/src/test/java/org/apache/webbeans/web/tests/interceptor/SerializationTest.java
Date Mon, 29 Apr 2013 16:18:24 GMT
Author: rmannibucau
Date: Mon Apr 29 16:18:24 2013
New Revision: 1477173

URL: http://svn.apache.org/r1477173
Log:
OWB-848 serialization of request scoped beans

Added:
    openwebbeans/trunk/webbeans-web/src/test/java/org/apache/webbeans/web/tests/interceptor/SerializationTest.java
      - copied, changed from r1476613, openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/contexts/SerializationTest.java
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/NormalScopedBeanInterceptorHandler.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/NormalScopedBeanInterceptorHandler.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/NormalScopedBeanInterceptorHandler.java?rev=1477173&r1=1477172&r2=1477173&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/NormalScopedBeanInterceptorHandler.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/NormalScopedBeanInterceptorHandler.java
Mon Apr 29 16:18:24 2013
@@ -116,7 +116,7 @@ public class NormalScopedBeanInterceptor
      * }
      * </pre>
     */
-    Object readResolve() throws ObjectStreamException
+    protected Object readResolve() throws ObjectStreamException
     {
         WebBeansContext webBeansContext = WebBeansContext.getInstance();
         this.beanManager = webBeansContext.getBeanManagerImpl();

Copied: openwebbeans/trunk/webbeans-web/src/test/java/org/apache/webbeans/web/tests/interceptor/SerializationTest.java
(from r1476613, openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/contexts/SerializationTest.java)
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-web/src/test/java/org/apache/webbeans/web/tests/interceptor/SerializationTest.java?p2=openwebbeans/trunk/webbeans-web/src/test/java/org/apache/webbeans/web/tests/interceptor/SerializationTest.java&p1=openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/contexts/SerializationTest.java&r1=1476613&r2=1477173&rev=1477173&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/contexts/SerializationTest.java
(original)
+++ openwebbeans/trunk/webbeans-web/src/test/java/org/apache/webbeans/web/tests/interceptor/SerializationTest.java
Mon Apr 29 16:18:24 2013
@@ -16,43 +16,24 @@
 * specific language governing permissions and limitations
 * under the License.
 */
-package org.apache.webbeans.newtests.contexts;
+package org.apache.webbeans.web.tests.interceptor;
 
 
-import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.container.SerializableBean;
-import org.apache.webbeans.newtests.AbstractUnitTest;
-import org.apache.webbeans.newtests.contexts.serialize.AppScopedBean;
-import org.apache.webbeans.newtests.contexts.serialize.SessScopedBean;
-import org.apache.webbeans.newtests.contexts.session.common.PersonalDataBean;
-import org.apache.webbeans.newtests.decorators.multiple.Decorator1;
-import org.apache.webbeans.newtests.decorators.multiple.OutputProvider;
-import org.apache.webbeans.newtests.decorators.multiple.RequestStringBuilder;
-import org.apache.webbeans.newtests.injection.circular.beans.CircularApplicationScopedBean;
-import org.apache.webbeans.newtests.injection.circular.beans.CircularConstructorOrProducerMethodParameterBean;
-import org.apache.webbeans.newtests.injection.circular.beans.CircularDependentScopedBean;
-import org.apache.webbeans.newtests.injection.circular.beans.CircularNormalInConstructor;
-import org.apache.webbeans.proxy.OwbNormalScopeProxy;
-import org.apache.webbeans.test.component.CheckWithCheckPayment;
-import org.apache.webbeans.test.component.CheckWithMoneyPayment;
-import org.apache.webbeans.test.component.IPayment;
-import org.apache.webbeans.test.component.PaymentProcessorComponent;
-import org.apache.webbeans.test.component.event.normal.ComponentWithObserves1;
-import org.apache.webbeans.test.component.event.normal.ComponentWithObserves2;
-import org.apache.webbeans.test.component.event.normal.TransactionalInterceptor;
-import org.apache.webbeans.util.WebBeansUtil;
-
 import junit.framework.Assert;
-
+import org.apache.webbeans.newtests.AbstractUnitTest;
+import org.apache.webbeans.web.tests.MockServletContext;
+import org.apache.webbeans.web.tests.MockServletRequest;
 import org.junit.Test;
 
-
-import javax.enterprise.context.SessionScoped;
-import javax.enterprise.context.spi.Context;
-import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.context.RequestScoped;
 import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.BeanManager;
-import java.io.*;
+import javax.servlet.ServletRequestEvent;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Set;
@@ -63,135 +44,29 @@ import java.util.Set;
  */
 public class SerializationTest extends AbstractUnitTest
 {
-
-    @SuppressWarnings("unchecked")
     @Test
-    public void testCreationalContextSerialization() throws Exception
+    public void testDeserializationOfRequestScopedBean() throws Exception
     {
-        Collection<Class<?>> classes = new ArrayList<Class<?>>();
+        final MockServletContext mockServletContext = new MockServletContext();
+        final MockServletRequest mockServletRequest = new MockServletRequest();
+        final ServletRequestEvent servletRequestEvent = new ServletRequestEvent(mockServletContext,
mockServletRequest);
 
-        // add a few random classes
-        classes.add(PersonalDataBean.class);
-        classes.add(CircularDependentScopedBean.class);
-        classes.add(CircularApplicationScopedBean.class);
+        final Collection<Class<?>> classes = new ArrayList<Class<?>>();
+        classes.add(ReqBean.class);
         startContainer(classes);
 
-        BeanManager bm = getBeanManager();
-        Set<Bean<?>> beans = getBeanManager().getBeans(PersonalDataBean.class);
-        Assert.assertNotNull(beans);
-        Assert.assertTrue(beans.size() == 1);
-        Bean pdbBean = beans.iterator().next();
-        CreationalContext<PersonalDataBean> pdbCreational = bm.createCreationalContext(pdbBean);
-        Assert.assertNotNull(pdbCreational);
-
-        // oki, now let's serializeBean the CreationalContext
-        byte[] serial = serializeObject(pdbCreational);
-        CreationalContext<?> cc2 = (CreationalContext<?>) deSerializeObject(serial);
-        Assert.assertNotNull(cc2);
-    }
-
-    @Test
-    public void testPersonalDataBean() throws ClassNotFoundException, IOException
-    {
-        Collection<Class<?>> classes = new ArrayList<Class<?>>();
+        getWebBeansContext().getContextsService().startContext(RequestScoped.class, servletRequestEvent);
 
-        // add a few random classes
-        classes.add(PersonalDataBean.class);
-        classes.add(OutputProvider.class);
-        classes.add(Decorator1.class);
-        classes.add(CircularApplicationScopedBean.class);
-        classes.add(CircularDependentScopedBean.class);
-        classes.add(RequestStringBuilder.class);
-        classes.add(CircularConstructorOrProducerMethodParameterBean.class);
-        classes.add(CircularDependentScopedBean.class);
-        classes.add(CircularNormalInConstructor.class);
-        classes.add(TransactionalInterceptor.class);
-        classes.add(ComponentWithObserves1.class);
-        classes.add(ComponentWithObserves2.class);
-        classes.add(PaymentProcessorComponent.class);
-        classes.add(IPayment.class);
-        classes.add(CheckWithCheckPayment.class);
-        classes.add(CheckWithMoneyPayment.class);
+        final BeanManager bm = getBeanManager();
+        final Set<Bean<?>> beans = getBeanManager().getBeans(ReqBean.class);
+        final Bean pdbBean = beans.iterator().next();
+        final ReqBean instance = ReqBean.class.cast(getBeanManager().getReference(pdbBean,
ReqBean.class, bm.createCreationalContext(pdbBean)));
+        Assert.assertNotNull(instance);
 
-        startContainer(classes);
+        final Object deserial = deSerializeObject(serializeObject(instance));
+        Assert.assertTrue(ReqBean.class.isInstance(deserial));
 
-        Set<Bean<?>> beans = getBeanManager().getBeans(Object.class);
-        Assert.assertNotNull(beans);
-        Assert.assertTrue(beans.size() > 7);
-
-        WebBeansContext webBeansContext = WebBeansContext.getInstance();
-        for (Bean<?> bean : beans)
-        {
-            String id = null;
-            if((id = WebBeansUtil.isPassivationCapable(bean)) != null)
-            {
-                bean = (Bean<?>) webBeansContext.getSerializableBeanVault().getSerializableBean(bean);
-                
-                byte[] serial = serializeBean(bean);
-                Bean<?> b2 = deSerializeBean(serial);
-
-                Assert.assertEquals(((SerializableBean<?>)bean).getBean(), ((SerializableBean<?>)b2).getBean());
-                
-            }
-        }
-        
-        // and now we are keen and try to serialize the whole passivatable Contexts!
-        PersonalDataBean pdb = getInstance(PersonalDataBean.class);
-        pdb.business();
-        
-        // first we need to actually create a few instances
-
-        Context sessionContext = webBeansContext.getContextFactory().getStandardContext(SessionScoped.class);
-        Assert.assertNotNull(sessionContext);
-        byte[] ba = serializeObject(sessionContext);
-        Assert.assertNotNull(ba);
-        Context sessContext2 = (Context) deSerializeObject(ba);
-        Assert.assertNotNull(sessContext2);
-    }
-
-    @Test
-    public void testProxySerialization() throws Exception
-    {
-        Collection<Class<?>> classes = new ArrayList<Class<?>>();
-
-        // add a few random classes
-        classes.add(SessScopedBean.class);
-        classes.add(AppScopedBean.class);
-
-        startContainer(classes);
-
-        Set<Bean<?>> beans = getBeanManager().getBeans(SessScopedBean.class);
-        Assert.assertNotNull(beans);
-        Assert.assertTrue(beans.size() == 1);
-        
-        @SuppressWarnings("unchecked")
-        Bean<SessScopedBean> bean = (Bean<SessScopedBean>) beans.iterator().next();
-        CreationalContext<SessScopedBean> ssbCreational = getBeanManager().createCreationalContext(bean);
-        Assert.assertNotNull(ssbCreational);
-        
-        SessScopedBean reference = (SessScopedBean) getBeanManager().getReference(bean, SessScopedBean.class,
ssbCreational);
-        Assert.assertNotNull(reference);
-        Assert.assertTrue(reference instanceof OwbNormalScopeProxy);
-        
-        reference.getApp().setI(4711);
-        
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        ObjectOutputStream oos = new ObjectOutputStream(baos);
-        oos.writeObject(reference);
-        byte[] ba = baos.toByteArray();
-        
-        ByteArrayInputStream bais = new ByteArrayInputStream(ba);
-        ObjectInputStream ois = new ObjectInputStream(bais);
-        SessScopedBean ssb2 =  (SessScopedBean) ois.readObject();
-        Assert.assertNotNull(ssb2);
-        
-        Assert.assertNotNull(ssb2.getApp());
-        Assert.assertTrue(ssb2.getApp().getI() == 4711);
-    }
-
-    private byte[] serializeBean(Bean<?> bean) throws IOException
-    {
-        return serializeObject(bean);
+        getWebBeansContext().getContextsService().endContext(RequestScoped.class, servletRequestEvent);
     }
     
     private byte[] serializeObject(Object o) throws IOException
@@ -201,11 +76,6 @@ public class SerializationTest extends A
         oos.writeObject(o);
         return baos.toByteArray();
     }
-
-    private Bean<?> deSerializeBean(byte[] serial) throws IOException, ClassNotFoundException
-    {
-        return (Bean<?>) deSerializeObject(serial);
-    }
     
     private Object deSerializeObject(byte[] serial) throws IOException, ClassNotFoundException
     {
@@ -214,4 +84,10 @@ public class SerializationTest extends A
         return ois.readObject();
     }
 
+    @RequestScoped
+    public static class ReqBean {
+        public String ok() {
+            return "ok";
+        }
+    }
 }



Mime
View raw message