01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.io.serializer;
05:
06: import com.tc.io.serializer.api.BasicSerializer;
07: import com.tc.io.serializer.api.Serializer;
08: import com.tc.object.ObjectID;
09: 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(
24: new StringIndexImpl(new NullStringIndexPersistor()));
25: serializer = new BasicSerializer(policy);
26:
27: ObjectID oid = new ObjectID(1);
28: assertEquals(oid, serialize(oid));
29:
30: Boolean bool = new Boolean(true);
31: assertEquals(bool, serialize(bool));
32:
33: Byte b = new Byte((byte) 1);
34: assertEquals(b, serialize(b));
35:
36: Character c = new Character('c');
37: assertEquals(c, serialize(c));
38:
39: Double d = new Double(1);
40: assertEquals(d, serialize(d));
41:
42: Float f = new Float(1);
43: assertEquals(f, serialize(f));
44:
45: Integer i = new Integer(1);
46: assertEquals(i, serialize(i));
47:
48: Long l = new Long(1);
49: assertEquals(l, serialize(l));
50:
51: Short s = new Short((short) 1);
52: assertEquals(s, serialize(s));
53:
54: String string = "orion";
55: assertEquals(string, serialize(string));
56:
57: Object o = new java.util.Date();
58: try {
59: assertEquals(o, serialize(o));
60: assertTrue(false);
61: } catch (TCAssertionError ar) {
62: // Normal as Date Objects are not supported natively
63: }
64: }
65:
66: private Object serialize(Object o) throws Exception {
67: ByteArrayOutputStream bout = new ByteArrayOutputStream();
68: TCObjectOutputStream out = new TCObjectOutputStream(bout);
69:
70: serializer.serializeTo(o, out);
71: out.flush();
72:
73: ByteArrayInputStream bin = new ByteArrayInputStream(bout
74: .toByteArray());
75: TCObjectInputStream in = new TCObjectInputStream(bin);
76: return serializer.deserializeFrom(in);
77: }
78: }
|