01: /*
02: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.object.dmi;
06:
07: import com.tc.bytes.TCByteBuffer;
08: import com.tc.io.TCByteBufferInputStream;
09: import com.tc.io.TCByteBufferOutputStream;
10: import com.tc.object.ObjectID;
11:
12: import java.io.IOException;
13: import java.util.Arrays;
14:
15: import junit.framework.TestCase;
16:
17: public class DmiDescriptorTest extends TestCase {
18:
19: final ObjectID receiverId = new ObjectID(567);
20: final ObjectID dmiCallId = new ObjectID(789);
21: final boolean faultRec = true;
22: final DmiClassSpec[] classSpecs = new DmiClassSpec[] { new DmiClassSpec(
23: "loaderDesc", "className") };
24:
25: public void testSerialization() throws IOException {
26:
27: final DmiDescriptor dd1 = new DmiDescriptor(receiverId,
28: dmiCallId, classSpecs, faultRec);
29: final DmiDescriptor dd2 = writeAndRead(dd1);
30: check(dd1, dd2);
31: }
32:
33: private void check(DmiDescriptor dd1, DmiDescriptor dd2) {
34: check(dd1);
35: check(dd2);
36: }
37:
38: private void check(DmiDescriptor dd2) {
39: assertEquals(receiverId, dd2.getReceiverId());
40: assertEquals(dmiCallId, dd2.getDmiCallId());
41: assertEquals(faultRec, dd2.isFaultReceiver());
42: assertTrue(Arrays.equals(classSpecs, dd2.getClassSpecs()));
43: }
44:
45: private DmiDescriptor writeAndRead(DmiDescriptor dd1)
46: throws IOException {
47: final TCByteBufferInputStream in = new TCByteBufferInputStream(
48: write(dd1));
49: final DmiDescriptor rv = new DmiDescriptor();
50: rv.deserializeFrom(in);
51: assertTrue(in.available() == 0);
52: return rv;
53: }
54:
55: private TCByteBuffer[] write(DmiDescriptor dd) {
56: final TCByteBufferOutputStream out = new TCByteBufferOutputStream();
57: dd.serializeTo(out);
58: out.close();
59: return out.toArray();
60: }
61: }
|