1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 package org.jaxen.test;
51
52
53 import java.io.ByteArrayInputStream;
54 import java.io.ByteArrayOutputStream;
55 import java.io.FileInputStream;
56 import java.io.IOException;
57 import java.io.InputStream;
58 import java.io.ObjectInputStream;
59 import java.io.ObjectOutputStream;
60
61 import org.jaxen.SimpleVariableContext;
62 import org.jaxen.UnresolvableException;
63
64 import junit.framework.TestCase;
65
66 /***
67 * <p>
68 * Test for namespace context.
69 * </p>
70 *
71 * @author Elliotte Rusty Harold
72 * @version 1.1b12
73 *
74 */
75 public class SimpleVariableContextTest extends TestCase
76 {
77
78 public void testRoundTripSerialization()
79 throws IOException, ClassNotFoundException, UnresolvableException {
80
81
82 SimpleVariableContext original = new SimpleVariableContext();
83 original.setVariableValue("s", "String Value");
84 original.setVariableValue("x", new Double(3.1415292));
85 original.setVariableValue("b", Boolean.TRUE);
86
87
88 ByteArrayOutputStream out = new ByteArrayOutputStream();
89 ObjectOutputStream oos = new ObjectOutputStream(out);
90 oos.writeObject(original);
91 oos.close();
92
93
94 byte[] pickled = out.toByteArray();
95 InputStream in = new ByteArrayInputStream(pickled);
96 ObjectInputStream ois = new ObjectInputStream(in);
97 Object o = ois.readObject();
98 SimpleVariableContext copy = (SimpleVariableContext) o;
99
100
101 assertEquals("String Value", copy.getVariableValue("", "", "s"));
102 assertEquals(new Double(3.1415292), copy.getVariableValue("", "", "x"));
103 assertEquals(Boolean.TRUE, copy.getVariableValue("", "", "b"));
104 assertEquals("", "");
105
106 }
107
108 public void testSerializationFormatHasNotChanged()
109 throws IOException, ClassNotFoundException, UnresolvableException {
110
111
112 InputStream in = new FileInputStream("xml/simplevariablecontext.ser");
113 ObjectInputStream ois = new ObjectInputStream(in);
114 Object o = ois.readObject();
115 SimpleVariableContext context = (SimpleVariableContext) o;
116
117
118 assertEquals("String Value", context.getVariableValue("", "", "s"));
119 assertEquals(new Double(3.1415292), context.getVariableValue("", "", "x"));
120 assertEquals(Boolean.TRUE, context.getVariableValue("", "", "b"));
121 assertEquals("", "");
122
123 }
124
125 }