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