01: /*
02: * CoadunationLib: The coaduntion implementation library.
03: * Copyright (C) 2006 Rift IT Contracting
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18: *
19: * ObjectSerializerTest.java
20: *
21: * JUnit based test
22: */
23:
24: package com.rift.coad.lib.common;
25:
26: import com.rift.coad.lib.common.*;
27: import junit.framework.*;
28: import java.io.ByteArrayInputStream;
29: import java.io.ByteArrayOutputStream;
30: import java.io.ObjectInputStream;
31: import java.io.ObjectOutputStream;
32:
33: /**
34: *
35: * @author mincemeat
36: */
37: public class ObjectSerializerTest extends TestCase {
38:
39: public static class TestObject implements java.io.Serializable {
40: public String key = null;
41: public String value = null;
42:
43: public TestObject() {
44:
45: }
46:
47: public TestObject(String key, String value) {
48: this .key = key;
49: this .value = value;
50: }
51: }
52:
53: public ObjectSerializerTest(String testName) {
54: super (testName);
55: }
56:
57: protected void setUp() throws Exception {
58: }
59:
60: protected void tearDown() throws Exception {
61: }
62:
63: public static Test suite() {
64: TestSuite suite = new TestSuite(ObjectSerializerTest.class);
65:
66: return suite;
67: }
68:
69: /**
70: * Test of serialize method, of class com.rift.coad.lib.common.ObjectSerializer.
71: */
72: public void testSerializer() throws Exception {
73: System.out.println("serializer");
74:
75: TestObject startObject = new TestObject("fred",
76: "freds value is here");
77: byte[] result = ObjectSerializer.serialize(startObject);
78: TestObject resultObject = (TestObject) ObjectSerializer
79: .deserialize(result);
80:
81: if (!startObject.key.equals(resultObject.key)
82: && startObject.value.equals(resultObject.value)) {
83: fail("The serialization and deserialization test failed");
84: }
85: }
86:
87: }
|