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