KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > io > serializer > impl > StringSerializerTest


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.io.serializer.impl;
5
6 import com.tc.io.serializer.TCObjectInputStream;
7 import com.tc.io.serializer.TCObjectOutputStream;
8 import com.tc.io.serializer.api.StringIndex;
9 import com.tc.objectserver.persistence.impl.NullStringIndexPersistor;
10 import com.tc.objectserver.persistence.impl.StringIndexImpl;
11
12 import java.io.ByteArrayInputStream JavaDoc;
13 import java.io.ByteArrayOutputStream JavaDoc;
14
15 import junit.framework.TestCase;
16
17 public class StringSerializerTest extends TestCase {
18   public void test() throws Exception JavaDoc {
19     StringIndex stringIndex = new StringIndexImpl(new NullStringIndexPersistor());
20     StringSerializer ss = new StringSerializer(stringIndex);
21     
22     ByteArrayOutputStream JavaDoc baout = new ByteArrayOutputStream JavaDoc();
23     for (int i=0; i<100; i++) {
24       String JavaDoc test = "This is a nice test string: " + i;
25       TCObjectOutputStream out = new TCObjectOutputStream(baout);
26       ss.serializeTo(test, out);
27       out.flush();
28       
29       ByteArrayInputStream JavaDoc bain = new ByteArrayInputStream JavaDoc(baout.toByteArray());
30       assertEquals(test, ss.deserializeFrom(new TCObjectInputStream(bain)));
31       baout.reset();
32     }
33   }
34 }
35
Popular Tags