1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.configuration.event;
18
19
20 import org.apache.commons.configuration.AbstractConfiguration;
21 import org.junit.Before;
22 import org.junit.Test;
23
24
25
26
27
28
29
30
31
32
33
34
35
36 public abstract class AbstractTestConfigurationEvents
37 {
38
39 static final String TEST_PROPNAME = "event.test";
40
41
42 static final String TEST_PROPVALUE = "a value";
43
44
45 static final String EXIST_PROPERTY = "event.property";
46
47
48 protected AbstractConfiguration config;
49
50
51 protected ConfigurationListenerTestImpl l;
52
53 @Before
54 public void setUp() throws Exception
55 {
56 config = createConfiguration();
57 config.addProperty(EXIST_PROPERTY, "existing value");
58 l = new ConfigurationListenerTestImpl(config);
59 config.addConfigurationListener(l);
60 }
61
62
63
64
65
66
67 protected abstract AbstractConfiguration createConfiguration();
68
69
70
71
72 @Test
73 public void testAddPropertyEvent()
74 {
75 config.addProperty(TEST_PROPNAME, TEST_PROPVALUE);
76 l.checkEvent(AbstractConfiguration.EVENT_ADD_PROPERTY, TEST_PROPNAME,
77 TEST_PROPVALUE, true);
78 l.checkEvent(AbstractConfiguration.EVENT_ADD_PROPERTY, TEST_PROPNAME,
79 TEST_PROPVALUE, false);
80 l.done();
81 }
82
83
84
85
86 @Test
87 public void testAddPropertyEventWithDetails()
88 {
89 config.setDetailEvents(true);
90 config.addProperty(TEST_PROPNAME, TEST_PROPVALUE);
91 l.checkEventCount(2);
92 l.checkEvent(AbstractConfiguration.EVENT_ADD_PROPERTY, TEST_PROPNAME,
93 TEST_PROPVALUE, true);
94 l.skipToLast(AbstractConfiguration.EVENT_ADD_PROPERTY);
95 l.checkEvent(AbstractConfiguration.EVENT_ADD_PROPERTY, TEST_PROPNAME,
96 TEST_PROPVALUE, false);
97 l.done();
98 }
99
100
101
102
103 @Test
104 public void testClearPropertyEvent()
105 {
106 config.clearProperty(EXIST_PROPERTY);
107 l.checkEvent(AbstractConfiguration.EVENT_CLEAR_PROPERTY,
108 EXIST_PROPERTY, null, true);
109 l.checkEvent(AbstractConfiguration.EVENT_CLEAR_PROPERTY,
110 EXIST_PROPERTY, null, false);
111 l.done();
112 }
113
114
115
116
117 @Test
118 public void testClearPropertyEventWithDetails()
119 {
120 config.setDetailEvents(true);
121 config.clearProperty(EXIST_PROPERTY);
122 l.checkEventCount(2);
123 l.checkEvent(AbstractConfiguration.EVENT_CLEAR_PROPERTY,
124 EXIST_PROPERTY, null, true);
125 l.skipToLast(AbstractConfiguration.EVENT_CLEAR_PROPERTY);
126 l.checkEvent(AbstractConfiguration.EVENT_CLEAR_PROPERTY,
127 EXIST_PROPERTY, null, false);
128 l.done();
129 }
130
131
132
133
134 @Test
135 public void testSetPropertyEvent()
136 {
137 config.setProperty(EXIST_PROPERTY, TEST_PROPVALUE);
138 l.checkEvent(AbstractConfiguration.EVENT_SET_PROPERTY, EXIST_PROPERTY,
139 TEST_PROPVALUE, true);
140 l.checkEvent(AbstractConfiguration.EVENT_SET_PROPERTY, EXIST_PROPERTY,
141 TEST_PROPVALUE, false);
142 l.done();
143 }
144
145
146
147
148 @Test
149 public void testSetPropertyEventWithDetails()
150 {
151 config.setDetailEvents(true);
152 config.setProperty(EXIST_PROPERTY, TEST_PROPVALUE);
153 l.checkEventCount(2);
154 l.checkEvent(AbstractConfiguration.EVENT_SET_PROPERTY, EXIST_PROPERTY,
155 TEST_PROPVALUE, true);
156 l.skipToLast(AbstractConfiguration.EVENT_SET_PROPERTY);
157 l.checkEvent(AbstractConfiguration.EVENT_SET_PROPERTY, EXIST_PROPERTY,
158 TEST_PROPVALUE, false);
159 l.done();
160 }
161
162
163
164
165 @Test
166 public void testClearEvent()
167 {
168 config.clear();
169 l.checkEvent(AbstractConfiguration.EVENT_CLEAR, null, null, true);
170 l.checkEvent(AbstractConfiguration.EVENT_CLEAR, null, null, false);
171 l.done();
172 }
173
174
175
176
177
178 @Test
179 public void testClearEventWithDetails()
180 {
181 config.setDetailEvents(true);
182 config.clear();
183 l.checkEventCount(2);
184 l.checkEvent(AbstractConfiguration.EVENT_CLEAR, null, null, true);
185 l.skipToLast(AbstractConfiguration.EVENT_CLEAR);
186 l.checkEvent(AbstractConfiguration.EVENT_CLEAR, null, null, false);
187 l.done();
188 }
189 }