You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by st...@apache.org on 2010/02/21 11:38:21 UTC
svn commit: r912327 - in
/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/contexts:
SerializationTest.java serialize/ serialize/AppScopedBean.java
serialize/SessScopedBean.java
Author: struberg
Date: Sun Feb 21 10:38:21 2010
New Revision: 912327
URL: http://svn.apache.org/viewvc?rev=912327&view=rev
Log:
OWB-294 add Test for ApplicationScoped proxy serialization
this will only work after OWB-295 got fixed
Added:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/contexts/serialize/
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/contexts/serialize/AppScopedBean.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/contexts/serialize/SessScopedBean.java
Modified:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/contexts/SerializationTest.java
Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/contexts/SerializationTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/contexts/SerializationTest.java?rev=912327&r1=912326&r2=912327&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/contexts/SerializationTest.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/contexts/SerializationTest.java Sun Feb 21 10:38:21 2010
@@ -22,6 +22,8 @@
import org.apache.webbeans.container.SerializableBean;
import org.apache.webbeans.container.SerializableBeanVault;
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;
@@ -35,6 +37,8 @@
import junit.framework.Assert;
import org.junit.Test;
+import javassist.util.proxy.ProxyObject;
+
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
@@ -102,14 +106,54 @@
bean = (Bean<?>) SerializableBeanVault.getInstance().getSerializableBean(bean);
byte[] serial = serializeBean(bean);
- Bean b2 = deSerializeBean(serial);
+ Bean<?> b2 = deSerializeBean(serial);
- Assert.assertEquals(((SerializableBean)bean).getBean(), ((SerializableBean)b2).getBean());
+ Assert.assertEquals(((SerializableBean<?>)bean).getBean(), ((SerializableBean<?>)b2).getBean());
}
}
}
+
+ @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 = getLifecycle().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 ProxyObject);
+
+ 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
{
@@ -120,8 +164,8 @@
}
private Bean<?> deSerializeBean(byte[] serial) throws IOException, ClassNotFoundException {
- ByteArrayInputStream baos = new ByteArrayInputStream(serial);
- ObjectInputStream ois = new ObjectInputStream(baos);
+ ByteArrayInputStream bais = new ByteArrayInputStream(serial);
+ ObjectInputStream ois = new ObjectInputStream(bais);
return (Bean<?>) ois.readObject();
}
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/contexts/serialize/AppScopedBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/contexts/serialize/AppScopedBean.java?rev=912327&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/contexts/serialize/AppScopedBean.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/contexts/serialize/AppScopedBean.java Sun Feb 21 10:38:21 2010
@@ -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.apache.webbeans.newtests.contexts.serialize;
+
+import javax.enterprise.context.ApplicationScoped;
+
+@ApplicationScoped
+public class AppScopedBean {
+
+ private int i;
+
+ public int getI() {
+ return i;
+ }
+
+ public void setI(int i) {
+ this.i = i;
+ }
+}
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/contexts/serialize/SessScopedBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/contexts/serialize/SessScopedBean.java?rev=912327&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/contexts/serialize/SessScopedBean.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/contexts/serialize/SessScopedBean.java Sun Feb 21 10:38:21 2010
@@ -0,0 +1,39 @@
+/*
+ * 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.webbeans.newtests.contexts.serialize;
+
+import java.io.Serializable;
+
+import javax.enterprise.context.SessionScoped;
+import javax.inject.Inject;
+
+@SessionScoped
+public class SessScopedBean implements Serializable {
+
+ private @Inject AppScopedBean app;
+
+ public AppScopedBean getApp() {
+ return app;
+ }
+
+ public void setApp(AppScopedBean app) {
+ this.app = app;
+ }
+
+}