1 5 package com.tc.object.dmi; 6 7 import com.tc.bytes.TCByteBuffer; 8 import com.tc.io.TCByteBufferInputStream; 9 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("loaderDesc", "className") }; 23 24 public void testSerialization() throws IOException { 25 26 final DmiDescriptor dd1 = new DmiDescriptor(receiverId, dmiCallId, classSpecs, faultRec); 27 final DmiDescriptor dd2 = writeAndRead(dd1); 28 check(dd1, dd2); 29 } 30 31 private void check(DmiDescriptor dd1, DmiDescriptor dd2) { 32 check(dd1); 33 check(dd2); 34 } 35 36 private void check(DmiDescriptor dd2) { 37 assertEquals(receiverId, dd2.getReceiverId()); 38 assertEquals(dmiCallId, dd2.getDmiCallId()); 39 assertEquals(faultRec, dd2.isFaultReceiver()); 40 assertTrue(Arrays.equals(classSpecs, dd2.getClassSpecs())); 41 } 42 43 private DmiDescriptor writeAndRead(DmiDescriptor dd1) throws IOException { 44 final TCByteBufferInputStream in = new TCByteBufferInputStream(write(dd1)); 45 final DmiDescriptor rv = new DmiDescriptor(); 46 rv.deserializeFrom(in); 47 assertTrue(in.available() == 0); 48 return rv; 49 } 50 51 private TCByteBuffer[] write(DmiDescriptor dd) { 52 final TCByteBufferOutputStream out = new TCByteBufferOutputStream(); 53 dd.serializeTo(out); 54 out.close(); 55 return out.toArray(); 56 } 57 } 58 | Popular Tags |