1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.chain.impl;
17
18
19 import junit.framework.Test;
20 import junit.framework.TestSuite;
21 import org.apache.commons.chain.Context;
22
23
24 /***
25 * Extension of <code>ContextBaseTestCase</code> to validate property
26 * delegation.
27 */
28
29 public class TestContextTestCase extends ContextBaseTestCase {
30
31
32
33
34 /***
35 * Construct a new instance of this test case.
36 *
37 * @param name Name of the test case
38 */
39 public TestContextTestCase(String name) {
40 super(name);
41 }
42
43
44
45
46
47 /***
48 * Set up instance variables required by this test case.
49 */
50 public void setUp() {
51 context = createContext();
52 }
53
54
55 /***
56 * Return the tests included in this test suite.
57 */
58 public static Test suite() {
59 return (new TestSuite(TestContextTestCase.class));
60 }
61
62
63
64
65
66
67 public void testPristine() {
68
69 super.testPristine();
70 assertEquals("readOnly", (String) context.get("readOnly"));
71 assertEquals("readWrite", (String) context.get("readWrite"));
72 assertEquals("writeOnly", ((TestContext) context).returnWriteOnly());
73
74 }
75
76
77
78 public void testReadOnly() {
79
80 Object readOnly = context.get("readOnly");
81 assertNotNull("readOnly found", readOnly);
82 assertTrue("readOnly String",
83 readOnly instanceof String);
84 assertEquals("readOnly value", "readOnly", readOnly);
85
86 try {
87 context.put("readOnly", "new readOnly");
88 fail("Should have thrown UnsupportedOperationException");
89 } catch (UnsupportedOperationException e) {
90 ;
91 }
92 assertEquals("readOnly unchanged", "readOnly",
93 (String) context.get("readOnly"));
94
95 }
96
97
98
99 public void testReadWrite() {
100
101 Object readWrite = context.get("readWrite");
102 assertNotNull("readWrite found", readWrite);
103 assertTrue("readWrite String",
104 readWrite instanceof String);
105 assertEquals("readWrite value", "readWrite", readWrite);
106
107 context.put("readWrite", "new readWrite");
108 readWrite = context.get("readWrite");
109 assertNotNull("readWrite found", readWrite);
110 assertTrue("readWrite String",
111 readWrite instanceof String);
112 assertEquals("readWrite value", "new readWrite", readWrite);
113
114 }
115
116
117
118 public void testWriteOnly() {
119
120 Object writeOnly = ((TestContext) context).returnWriteOnly();
121 assertNotNull("writeOnly found", writeOnly);
122 assertTrue("writeOnly String",
123 writeOnly instanceof String);
124 assertEquals("writeOnly value", "writeOnly", writeOnly);
125
126 context.put("writeOnly", "new writeOnly");
127 writeOnly = ((TestContext) context).returnWriteOnly();
128 assertNotNull("writeOnly found", writeOnly);
129 assertTrue("writeOnly String",
130 writeOnly instanceof String);
131 assertEquals("writeOnly value", "new writeOnly", writeOnly);
132
133 }
134
135
136
137
138
139
140 protected Context createContext() {
141 return (new TestContext());
142 }
143
144
145 }