1 package org.sapia.ubik.rmi.naming.remote; 2 3 import junit.framework.TestCase; 4 5 import org.sapia.ubik.rmi.naming.remote.proxy.BindingCache; 6 7 import java.io.ByteArrayInputStream ; 8 import java.io.ByteArrayOutputStream ; 9 import java.io.ObjectInputStream ; 10 import java.io.ObjectOutputStream ; 11 12 13 22 public class BindingCacheTest extends TestCase { 23 public BindingCacheTest(String arg0) { 24 super(arg0); 25 } 26 27 public void testAdd() { 28 BindingCache bc = new BindingCache(); 29 Object o; 30 bc.add("junit", "someObject", new Object ()); 31 super.assertEquals(1, bc.cachedRefs().size()); 32 } 33 34 public void testSerializeNotNull() throws Exception { 35 BindingCache bc = new BindingCache(); 36 Object o; 37 bc.add("junit", "someObject", "theObject"); 38 39 ByteArrayOutputStream bos = new ByteArrayOutputStream (); 40 ObjectOutputStream ous = new ObjectOutputStream (bos); 41 ous.writeObject(bc); 42 ous.flush(); 43 ous.close(); 44 45 ObjectInputStream ois = new ObjectInputStream (new ByteArrayInputStream ( 46 bos.toByteArray())); 47 bc = (BindingCache) ois.readObject(); 48 super.assertEquals(1, bc.cachedRefs().size()); 49 50 BindingCache.BoundRef ref = (BindingCache.BoundRef) bc.cachedRefs().get(0); 51 super.assertEquals("someObject", ref.name); 52 super.assertEquals("theObject", ref.obj); 53 } 54 55 public void testSerializeNull() throws Exception { 56 BindingCache bc = new BindingCache(); 57 Object o; 58 bc.add("junit", "someObject", null); 59 60 ByteArrayOutputStream bos = new ByteArrayOutputStream (); 61 ObjectOutputStream ous = new ObjectOutputStream (bos); 62 ous.writeObject(bc); 63 ous.flush(); 64 ous.close(); 65 66 ObjectInputStream ois = new ObjectInputStream (new ByteArrayInputStream ( 67 bos.toByteArray())); 68 bc = (BindingCache) ois.readObject(); 69 super.assertEquals(0, bc.cachedRefs().size()); 70 } 71 } 72 | Popular Tags |