01: /*
02: * User: Michael Rettig
03: * Date: Sep 7, 2002
04: * Time: 9:33:04 PM
05: */
06: package net.sourceforge.jaxor.example.tests;
07:
08: import junit.framework.TestCase;
09: import net.sourceforge.jaxor.util.SystemException;
10: import org.jdom.Document;
11: import org.jdom.Element;
12: import org.jdom.output.XMLOutputter;
13: import org.xml.sax.InputSource;
14:
15: import java.io.*;
16:
17: public class JaxorTestCase extends TestCase {
18:
19: public InputSource getInputSource(Element el) throws IOException {
20: return new InputSource(new StringReader(createXml(el)));
21: }
22:
23: private String createXml(Element el) throws IOException {
24: Document doc = new Document(el);
25: XMLOutputter out = new XMLOutputter();
26: StringWriter stringWriter = new StringWriter();
27: out.output(doc, stringWriter);
28: return stringWriter.toString();
29: }
30:
31: public Object serialize(Object obj) {
32: try {
33: ByteArrayOutputStream out = new ByteArrayOutputStream();
34: ObjectOutputStream output = new ObjectOutputStream(out);
35: output.writeObject(obj);
36: output.flush();
37: output.close();
38: ObjectInputStream input = new ObjectInputStream(
39: new ByteArrayInputStream(out.toByteArray()));
40: return input.readObject();
41: } catch (IOException e) {
42: throw new SystemException(e);
43: } catch (ClassNotFoundException e) {
44: throw new SystemException(e);
45: }
46: }
47:
48: public static void assertContains(String expected, String str) {
49: if (str.indexOf(expected) == -1)
50: fail("Expected to find: " + expected + " contained in: "
51: + str);
52: }
53: }
|