KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > remoting > marshall > serializable > SerializableMarshallingTestCase


1 /*
2 * JBoss, the OpenSource J2EE webOS
3 *
4 * Distributable under LGPL license.
5 * See terms of license at gnu.org.
6 */

7 package org.jboss.remoting.marshall.serializable;
8
9 import junit.framework.TestCase;
10 import org.jboss.remoting.marshal.MarshalFactory;
11 import org.jboss.remoting.marshal.Marshaller;
12 import org.jboss.remoting.marshal.UnMarshaller;
13 import org.jboss.remoting.marshal.serializable.SerializableMarshaller;
14 import org.jboss.remoting.marshal.serializable.SerializableUnMarshaller;
15
16 import java.io.ByteArrayInputStream JavaDoc;
17 import java.io.ByteArrayOutputStream JavaDoc;
18 import java.io.IOException JavaDoc;
19
20 /**
21  * @author <a HREF="mailto:telrod@e2technologies.net">Tom Elrod</a>
22  */

23 public class SerializableMarshallingTestCase extends TestCase
24 {
25    private Marshaller marshaller;
26    private UnMarshaller unmarshaller;
27
28    protected void setUp() throws Exception JavaDoc
29    {
30       super.setUp();
31       marshaller = MarshalFactory.getMarshaller(SerializableMarshaller.DATATYPE);
32       unmarshaller = MarshalFactory.getUnMarshaller(SerializableUnMarshaller.DATATYPE);
33    }
34
35    public void testMarshalling() throws IOException JavaDoc, ClassNotFoundException JavaDoc
36    {
37       String JavaDoc testData = "This is some test data";
38       Object JavaDoc param = new String JavaDoc(testData);
39
40       ByteArrayOutputStream JavaDoc output = new ByteArrayOutputStream JavaDoc();
41       marshaller.write(param, output);
42       byte[] byteArray = new byte[output.size()];
43       byteArray = output.toByteArray();
44       ByteArrayInputStream JavaDoc input = new ByteArrayInputStream JavaDoc(byteArray);
45       Object JavaDoc result = unmarshaller.read(input, null);
46
47       System.out.println("Result: " + result);
48       assertEquals(testData, result);
49    }
50
51    protected void tearDown() throws Exception JavaDoc
52    {
53       super.tearDown();
54       marshaller = null;
55       unmarshaller = null;
56    }
57
58 }
59
Popular Tags