harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r553125 - in /harmony/enhanced/classlib/trunk/modules/beans/src/test: java/org/apache/harmony/beans/tests/java/beans/beancontext/ resources/serialization/org/apache/harmony/beans/tests/java/beans/beancontext/
Date Wed, 04 Jul 2007 08:41:11 GMT
Author: pyang
Date: Wed Jul  4 01:41:10 2007
New Revision: 553125

URL: http://svn.apache.org/viewvc?view=rev&rev=553125
Log:
Add serialization test and golden file for java.beans.beancontext.BeanContextEvent

Added:
    harmony/enhanced/classlib/trunk/modules/beans/src/test/resources/serialization/org/apache/harmony/beans/tests/java/beans/beancontext/BeanContextEventTest.golden.ser
  (with props)
Modified:
    harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/beancontext/BeanContextEventTest.java

Modified: harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/beancontext/BeanContextEventTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/beancontext/BeanContextEventTest.java?view=diff&rev=553125&r1=553124&r2=553125
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/beancontext/BeanContextEventTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/beancontext/BeanContextEventTest.java
Wed Jul  4 01:41:10 2007
@@ -19,10 +19,21 @@
 
 import java.beans.beancontext.BeanContext;
 import java.beans.beancontext.BeanContextEvent;
+import java.beans.beancontext.BeanContextServicesSupport;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Locale;
 
 import junit.framework.TestCase;
 
+import org.apache.harmony.beans.tests.support.beancontext.Utils;
 import org.apache.harmony.beans.tests.support.beancontext.mock.MockBeanContext;
+import org.apache.harmony.beans.tests.support.beancontext.mock.MockBeanContextServiceProviderS;
+import org.apache.harmony.beans.tests.support.beancontext.mock.MockBeanContextServicesListenerS;
+import org.apache.harmony.testframework.serialization.SerializationTest;
+import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
 
 /**
  * Test BeanContextEvent
@@ -43,7 +54,7 @@
             assertSame(bc, getBeanContext());
             assertNull(this.propagatedFrom);
         }
-
+        
     }
 
     public static void main(String[] args) {
@@ -120,5 +131,91 @@
 
         event.setPropagatedFrom(null);
         assertNull(event.getPropagatedFrom());
+    }
+    
+    public void testSerialization() throws Exception {
+        final BeanContextServicesSupport ctx = new BeanContextServicesSupport(
+                null, Locale.FRANCE, false, false);
+        final BeanContextServicesSupport ctx2 = new BeanContextServicesSupport(
+                ctx, Locale.ITALY, true, true);
+        BeanContextEvent event = new MockBeanContextEvent(ctx2);
+        event.setPropagatedFrom(ctx);
+        SerializationTest.verifySelf(event, new SerializableAssert(){
+            public void assertDeserialized(Serializable arg0, Serializable arg1) {
+                BeanContextEvent e1 = (BeanContextEvent)arg0;
+                BeanContextEvent e2 = (BeanContextEvent)arg1;
+                assertNull((BeanContextServicesSupport)e2.getSource());
+                assertNotNull((BeanContextServicesSupport)e1.getSource());
+                assertEqualsSerially((BeanContextServicesSupport)e1.getPropagatedFrom(),
(BeanContextServicesSupport)e2.getPropagatedFrom());
+                assertEqualsSerially(ctx, (BeanContextServicesSupport)e2.getPropagatedFrom());
+            }
+        });
+    }
+    
+    public static void assertEqualsSerially(BeanContextServicesSupport orig,
+            BeanContextServicesSupport ser) {
+
+        // check bcsListeners
+        ArrayList origBcsListeners = (ArrayList) Utils.getField(orig,
+                "bcsListeners");
+        ArrayList serBcsListeners = (ArrayList) Utils.getField(ser,
+                "bcsListeners");
+        int i = 0, j = 0;
+        while (i < origBcsListeners.size()) {
+            Object l1 = origBcsListeners.get(i);
+            if (l1 instanceof Serializable) {
+                Object l2 = serBcsListeners.get(j);
+                assertSame(l1.getClass(), l2.getClass());
+                if (l1 instanceof MockBeanContextServicesListenerS) {
+                    assertEquals(((MockBeanContextServicesListenerS) l1).id,
+                            ((MockBeanContextServicesListenerS) l2).id);
+                }
+                j++;
+            }
+            i++;
+        }
+        assertEquals(j, serBcsListeners.size());
+
+        // check services
+        HashMap origServices = (HashMap) Utils.getField(orig, "services");
+        HashMap serServices = (HashMap) Utils.getField(ser, "services");
+        int count = 0;
+        for (Iterator iter = origServices.keySet().iterator(); iter.hasNext();) {
+            Object serviceClass = iter.next();
+            Object bcssProvider = origServices.get(serviceClass);
+            Object provider = Utils.getField(bcssProvider, "serviceProvider");
+            if (provider instanceof Serializable) {
+                assertTrue(serServices.containsKey(serviceClass));
+                if (provider instanceof MockBeanContextServiceProviderS) {
+                    Object serProvider = Utils.getField(serServices
+                            .get(serviceClass), "serviceProvider");
+                    assertEquals(
+                            ((MockBeanContextServiceProviderS) provider).id,
+                            ((MockBeanContextServiceProviderS) serProvider).id);
+                }
+                count++;
+            }
+        }
+        assertEquals(count, serServices.size());
+    }    
+
+    public void testSerializationComptibility() throws Exception {
+        final BeanContextServicesSupport ctx = new BeanContextServicesSupport(
+                null, Locale.ITALY, true, true);
+        final BeanContextServicesSupport ctx2 = new BeanContextServicesSupport(
+                null, Locale.CHINA, true, true);
+        
+        BeanContextEvent event = new MockBeanContextEvent(ctx);
+        event.setPropagatedFrom(ctx2);
+        SerializationTest.verifyGolden(this, event, new SerializableAssert(){
+            public void assertDeserialized(Serializable arg0, Serializable arg1) {
+                BeanContextEvent e1 = (BeanContextEvent)arg0;
+                BeanContextEvent e2 = (BeanContextEvent)arg1;
+                assertNull((BeanContextServicesSupport)e2.getSource());
+                assertNotNull((BeanContextServicesSupport)e1.getSource());
+                assertEqualsSerially((BeanContextServicesSupport)e1.getPropagatedFrom(),
(BeanContextServicesSupport)e2.getPropagatedFrom());
+                assertEqualsSerially(ctx2, (BeanContextServicesSupport)e2.getPropagatedFrom());
+            }
+        });
     }
 }

Added: harmony/enhanced/classlib/trunk/modules/beans/src/test/resources/serialization/org/apache/harmony/beans/tests/java/beans/beancontext/BeanContextEventTest.golden.ser
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/beans/src/test/resources/serialization/org/apache/harmony/beans/tests/java/beans/beancontext/BeanContextEventTest.golden.ser?view=auto&rev=553125
==============================================================================
Binary file - no diff available.

Propchange: harmony/enhanced/classlib/trunk/modules/beans/src/test/resources/serialization/org/apache/harmony/beans/tests/java/beans/beancontext/BeanContextEventTest.golden.ser
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



Mime
View raw message