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
33 static final String TEST_PROPNAME = "event.test";
34
35
36 static final String TEST_PROPVALUE = "a value";
37
38
39 static final String EXIST_PROPERTY = "event.property";
40
41
42 protected AbstractConfiguration config;
43
44
45 protected EventListenerTestImpl listener;
46
47
48
49
50
51
52 protected abstract AbstractConfiguration createConfiguration();
53
54 @BeforeEach
55 public void setUp() throws Exception {
56 config = createConfiguration();
57 config.addProperty(EXIST_PROPERTY, "existing value");
58 listener = new EventListenerTestImpl(config);
59 config.addEventListener(ConfigurationEvent.ANY, listener);
60 }
61
62
63
64
65 @Test
66 void testAddPropertyEvent() {
67 config.addProperty(TEST_PROPNAME, TEST_PROPVALUE);
68 listener.checkEvent(ConfigurationEvent.ADD_PROPERTY, TEST_PROPNAME, TEST_PROPVALUE, true);
69 listener.checkEvent(ConfigurationEvent.ADD_PROPERTY, TEST_PROPNAME, TEST_PROPVALUE, false);
70 listener.done();
71 }
72
73
74
75
76 @Test
77 void testAddPropertyEventWithDetails() {
78 config.setDetailEvents(true);
79 config.addProperty(TEST_PROPNAME, TEST_PROPVALUE);
80 listener.checkEventCount(2);
81 listener.checkEvent(ConfigurationEvent.ADD_PROPERTY, TEST_PROPNAME, TEST_PROPVALUE, true);
82 listener.skipToLast(ConfigurationEvent.ADD_PROPERTY);
83 listener.checkEvent(ConfigurationEvent.ADD_PROPERTY, TEST_PROPNAME, TEST_PROPVALUE, false);
84 listener.done();
85 }
86
87
88
89
90 @Test
91 void testClearEvent() {
92 config.clear();
93 listener.checkEvent(ConfigurationEvent.CLEAR, null, null, true);
94 listener.checkEvent(ConfigurationEvent.CLEAR, null, null, false);
95 listener.done();
96 }
97
98
99
100
101 @Test
102 void testClearEventWithDetails() {
103 config.setDetailEvents(true);
104 config.clear();
105 listener.checkEventCount(2);
106 listener.checkEvent(ConfigurationEvent.CLEAR, null, null, true);
107 listener.skipToLast(ConfigurationEvent.CLEAR);
108 listener.checkEvent(ConfigurationEvent.CLEAR, null, null, false);
109 listener.done();
110 }
111
112
113
114
115 @Test
116 void testClearPropertyEvent() {
117 config.clearProperty(EXIST_PROPERTY);
118 listener.checkEvent(ConfigurationEvent.CLEAR_PROPERTY, EXIST_PROPERTY, null, true);
119 listener.checkEvent(ConfigurationEvent.CLEAR_PROPERTY, EXIST_PROPERTY, null, false);
120 listener.done();
121 }
122
123
124
125
126 @Test
127 void testClearPropertyEventWithDetails() {
128 config.setDetailEvents(true);
129 config.clearProperty(EXIST_PROPERTY);
130 listener.checkEventCount(2);
131 listener.checkEvent(ConfigurationEvent.CLEAR_PROPERTY, EXIST_PROPERTY, null, true);
132 listener.skipToLast(ConfigurationEvent.CLEAR_PROPERTY);
133 listener.checkEvent(ConfigurationEvent.CLEAR_PROPERTY, EXIST_PROPERTY, null, false);
134 listener.done();
135 }
136
137
138
139
140 @Test
141 void testSetPropertyEvent() {
142 config.setProperty(EXIST_PROPERTY, TEST_PROPVALUE);
143 listener.checkEvent(ConfigurationEvent.SET_PROPERTY, EXIST_PROPERTY, TEST_PROPVALUE, true);
144 listener.checkEvent(ConfigurationEvent.SET_PROPERTY, EXIST_PROPERTY, TEST_PROPVALUE, false);
145 listener.done();
146 }
147
148
149
150
151 @Test
152 void testSetPropertyEventWithDetails() {
153 config.setDetailEvents(true);
154 config.setProperty(EXIST_PROPERTY, TEST_PROPVALUE);
155 listener.checkEventCount(2);
156 listener.checkEvent(ConfigurationEvent.SET_PROPERTY, EXIST_PROPERTY, TEST_PROPVALUE, true);
157 listener.skipToLast(ConfigurationEvent.SET_PROPERTY);
158 listener.checkEvent(ConfigurationEvent.SET_PROPERTY, EXIST_PROPERTY, TEST_PROPVALUE, false);
159 listener.done();
160 }
161 }