1 4 package com.tc.io.serializer; 5 6 import com.tc.io.serializer.api.BasicSerializer; 7 import com.tc.io.serializer.api.Serializer; 8 import com.tc.object.ObjectID; 9 import com.tc.objectserver.persistence.impl.NullStringIndexPersistor; 10 import com.tc.objectserver.persistence.impl.StringIndexImpl; 11 import com.tc.util.TCAssertionError; 12 13 import java.io.ByteArrayInputStream ; 14 import java.io.ByteArrayOutputStream ; 15 16 import junit.framework.TestCase; 17 18 public class DSOSerializerPolicyTest extends TestCase { 19 20 private Serializer serializer; 21 22 public void test() throws Exception { 23 DSOSerializerPolicy policy = new DSOSerializerPolicy(new StringIndexImpl(new NullStringIndexPersistor())); 24 serializer = new BasicSerializer(policy); 25 26 ObjectID oid = new ObjectID(1); 27 assertEquals(oid, serialize(oid)); 28 29 Boolean bool = new Boolean (true); 30 assertEquals(bool, serialize(bool)); 31 32 Byte b = new Byte ((byte) 1); 33 assertEquals(b, serialize(b)); 34 35 Character c = new Character ('c'); 36 assertEquals(c, serialize(c)); 37 38 Double d = new Double (1); 39 assertEquals(d, serialize(d)); 40 41 Float f = new Float (1); 42 assertEquals(f, serialize(f)); 43 44 Integer i = new Integer (1); 45 assertEquals(i, serialize(i)); 46 47 Long l = new Long (1); 48 assertEquals(l, serialize(l)); 49 50 Short s = new Short ((short) 1); 51 assertEquals(s, serialize(s)); 52 53 String string = "orion"; 54 assertEquals(string, serialize(string)); 55 56 Object o = new java.util.Date (); 57 try { 58 assertEquals(o, serialize(o)); 59 assertTrue(false); 60 } catch (TCAssertionError ar) { 61 } 63 } 64 65 private Object serialize(Object o) throws Exception { 66 ByteArrayOutputStream bout = new ByteArrayOutputStream (); 67 TCObjectOutputStream out = new TCObjectOutputStream(bout); 68 69 serializer.serializeTo(o, out); 70 out.flush(); 71 72 ByteArrayInputStream bin = new ByteArrayInputStream (bout.toByteArray()); 73 TCObjectInputStream in = new TCObjectInputStream(bin); 74 return serializer.deserializeFrom(in); 75 } 76 } 77 | Popular Tags |