01: /*
02: * Copyright (C) 2004, 2005 Joe Walnes.
03: * Copyright (C) 2006, 2007 XStream Committers.
04: * All rights reserved.
05: *
06: * The software in this package is published under the terms of the BSD
07: * style license a copy of which has been included with this distribution in
08: * the LICENSE.txt file.
09: *
10: * Created on 30. May 2004 by Joe Walnes
11: */
12: package com.thoughtworks.acceptance;
13:
14: import com.thoughtworks.acceptance.objects.StatusEnum;
15:
16: import java.io.ByteArrayInputStream;
17: import java.io.ByteArrayOutputStream;
18: import java.io.IOException;
19: import java.io.ObjectInputStream;
20: import java.io.ObjectOutputStream;
21:
22: /**
23: * @author Chris Kelly
24: * @author Joe Walnes
25: */
26: public class ReadResolveTest extends AbstractAcceptanceTest {
27:
28: public void testReadResolveWithDefaultSerialization()
29: throws IOException, ClassNotFoundException {
30: StatusEnum status = StatusEnum.STARTED;
31:
32: ByteArrayOutputStream bout = new ByteArrayOutputStream();
33: ObjectOutputStream os = new ObjectOutputStream(bout);
34: os.writeObject(status);
35:
36: byte[] bArray = bout.toByteArray();
37: StatusEnum rStatus = null;
38: ObjectInputStream in = null;
39:
40: ByteArrayInputStream bin = new ByteArrayInputStream(bArray);
41: in = new ObjectInputStream(bin);
42: rStatus = (StatusEnum) in.readObject();
43: assertNotNull(rStatus);
44:
45: assertSame(status, rStatus);
46: }
47:
48: public void testReadResolveWithXStream() {
49: StatusEnum status = StatusEnum.STARTED;
50:
51: String xml = xstream.toXML(status);
52: StatusEnum rStatus = (StatusEnum) xstream.fromXML(xml);
53:
54: assertSame(status, rStatus);
55: }
56: }
|