KickJava   Java API By Example, From Geeks To Geeks.

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


1 /***************************************
2  * *
3  * JBoss: The OpenSource J2EE WebOS *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  ***************************************/

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

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