KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > object > dna > impl > ObjectStringSerializerTest


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.object.dna.impl;
5
6 import com.tc.io.TCByteBufferInputStream;
7 import com.tc.io.TCByteBufferOutputStream;
8
9 import java.io.IOException JavaDoc;
10
11 import junit.framework.TestCase;
12
13 public class ObjectStringSerializerTest extends TestCase {
14
15   public void test() throws IOException JavaDoc {
16     // write it
17
TCByteBufferOutputStream out = new TCByteBufferOutputStream();
18     ObjectStringSerializer ser = new ObjectStringSerializer();
19
20     ser.writeFieldName(out, "className.fieldName");
21     ser.writeString(out, "timmy teck");
22     ser.writeFieldName(out, "className.fieldName");
23     ser.writeString(out, "timmy teck");
24
25     // cook it
26
TCByteBufferOutputStream data = new TCByteBufferOutputStream();
27     ser.serializeTo(data);
28     data.write(out.toArray());
29
30     // read it
31
TCByteBufferInputStream in = new TCByteBufferInputStream(data.toArray());
32     ObjectStringSerializer ser2 = new ObjectStringSerializer();
33     ser2.deserializeFrom(in);
34
35     String JavaDoc fn1 = ser2.readFieldName(in);
36     String JavaDoc s1 = ser2.readString(in);
37     String JavaDoc fn2 = ser2.readFieldName(in);
38     String JavaDoc s2 = ser2.readString(in);
39
40     assertEquals("className.fieldName", fn1);
41     assertEquals("timmy teck", s1);
42     assertEquals("className.fieldName", fn2);
43     assertEquals("timmy teck", s2);
44   }
45
46 }
47
Popular Tags