Skip to content

Commit 210d534

Browse files
committed
Removed Configuration class
1 parent 4b32d5c commit 210d534

File tree

4 files changed

+81
-293
lines changed

4 files changed

+81
-293
lines changed

src/main/java/com/exceptionless/exceptionlessclient/configuration/Configuration.java

Lines changed: 0 additions & 139 deletions
This file was deleted.

src/main/java/com/exceptionless/exceptionlessclient/configuration/ConfigurationManager.java

Lines changed: 49 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ public static class Property {
7070
private final Set<String> dataExclusions;
7171
private final PluginManager pluginManager;
7272
@Getter private final StorageProviderIF storageProvider;
73-
@Getter private ValueProvider<String> apiKey;
74-
@Getter private ValueProvider<String> serverUrl;
75-
@Getter private ValueProvider<String> heartbeatServerUrl;
76-
@Getter private ValueProvider<String> configServerUrl;
77-
@Getter private ValueProvider<Long> updateSettingsWhenIdleInterval;
78-
@Getter private ValueProvider<Integer> submissionBatchSize;
79-
@Getter private ValueProvider<Integer> submissionClientTimeoutInMillis;
80-
@Getter private ValueProvider<Integer> settingsClientTimeoutInMillis;
73+
@Getter private final ValueProvider<String> apiKey;
74+
@Getter private final ValueProvider<String> serverUrl;
75+
@Getter private final ValueProvider<String> heartbeatServerUrl;
76+
@Getter private final ValueProvider<String> configServerUrl;
77+
@Getter private final ValueProvider<Long> updateSettingsWhenIdleInterval;
78+
@Getter private final ValueProvider<Integer> submissionBatchSize;
79+
@Getter private final ValueProvider<Integer> submissionClientTimeoutInMillis;
80+
@Getter private final ValueProvider<Integer> settingsClientTimeoutInMillis;
8181
private final PropertyChangeSupport propertyChangeSupport;
8282

8383
@Builder
@@ -98,6 +98,38 @@ public ConfigurationManager(
9898
Integer submissionBatchSize,
9999
Integer submissionClientTimeoutInMillis,
100100
Integer settingsClientTimeoutInMillis) {
101+
this.apiKey = ValueProvider.of(apiKey);
102+
this.serverUrl =
103+
serverUrl == null ? ValueProvider.of(DEFAULT_SERVER_URL) : ValueProvider.of(serverUrl);
104+
this.heartbeatServerUrl =
105+
heartbeatServerUrl == null
106+
? (serverUrl == null
107+
? ValueProvider.of(DEFAULT_HEARTBEAT_SERVER_URL)
108+
: ValueProvider.of(serverUrl))
109+
: ValueProvider.of(heartbeatServerUrl);
110+
this.configServerUrl =
111+
configServerUrl == null
112+
? (serverUrl == null
113+
? ValueProvider.of(DEFAULT_CONFIG_SERVER_URL)
114+
: ValueProvider.of(serverUrl))
115+
: ValueProvider.of(configServerUrl);
116+
this.updateSettingsWhenIdleInterval =
117+
updateSettingsWhenIdleInterval == null
118+
? ValueProvider.of(DEFAULT_UPDATE_SETTINGS_WHEN_IDLE_INTERVAL)
119+
: ValueProvider.of(updateSettingsWhenIdleInterval);
120+
this.submissionBatchSize =
121+
submissionBatchSize == null
122+
? ValueProvider.of(DEFAULT_SUBMISSION_BATCH_SIZE)
123+
: ValueProvider.of(submissionBatchSize);
124+
this.submissionClientTimeoutInMillis =
125+
submissionClientTimeoutInMillis == null
126+
? ValueProvider.of(DEFAULT_SUBMISSION_CLIENT_TIMEOUT_IN_MILLIS)
127+
: ValueProvider.of(submissionClientTimeoutInMillis);
128+
this.settingsClientTimeoutInMillis =
129+
settingsClientTimeoutInMillis == null
130+
? ValueProvider.of(DEFAULT_SETTINGS_CLIENT_TIMEOUT_IN_MILLIS)
131+
: ValueProvider.of(settingsClientTimeoutInMillis);
132+
this.propertyChangeSupport = new PropertyChangeSupport(this);
101133
this.lastReferenceIdManager =
102134
lastReferenceIdManager == null
103135
? DefaultLastReferenceIdManager.builder().build()
@@ -144,38 +176,6 @@ public ConfigurationManager(
144176
this.onChangedHandlers = new ArrayList<>();
145177
this.dataExclusions = new HashSet<>();
146178
this.privateInformationInclusions = PrivateInformationInclusions.builder().build();
147-
this.apiKey = ValueProvider.of(apiKey);
148-
this.serverUrl =
149-
serverUrl == null ? ValueProvider.of(DEFAULT_SERVER_URL) : ValueProvider.of(serverUrl);
150-
this.heartbeatServerUrl =
151-
heartbeatServerUrl == null
152-
? (serverUrl == null
153-
? ValueProvider.of(DEFAULT_HEARTBEAT_SERVER_URL)
154-
: ValueProvider.of(serverUrl))
155-
: ValueProvider.of(heartbeatServerUrl);
156-
this.configServerUrl =
157-
configServerUrl == null
158-
? (serverUrl == null
159-
? ValueProvider.of(DEFAULT_CONFIG_SERVER_URL)
160-
: ValueProvider.of(serverUrl))
161-
: ValueProvider.of(configServerUrl);
162-
this.updateSettingsWhenIdleInterval =
163-
updateSettingsWhenIdleInterval == null
164-
? ValueProvider.of(DEFAULT_UPDATE_SETTINGS_WHEN_IDLE_INTERVAL)
165-
: ValueProvider.of(updateSettingsWhenIdleInterval);
166-
this.submissionBatchSize =
167-
submissionBatchSize == null
168-
? ValueProvider.of(DEFAULT_SUBMISSION_BATCH_SIZE)
169-
: ValueProvider.of(submissionBatchSize);
170-
this.submissionClientTimeoutInMillis =
171-
submissionClientTimeoutInMillis == null
172-
? ValueProvider.of(DEFAULT_SUBMISSION_CLIENT_TIMEOUT_IN_MILLIS)
173-
: ValueProvider.of(submissionClientTimeoutInMillis);
174-
this.settingsClientTimeoutInMillis =
175-
settingsClientTimeoutInMillis == null
176-
? ValueProvider.of(DEFAULT_SETTINGS_CLIENT_TIMEOUT_IN_MILLIS)
177-
: ValueProvider.of(settingsClientTimeoutInMillis);
178-
this.propertyChangeSupport = new PropertyChangeSupport(this);
179179
checkApiKeyIsValid();
180180
addPropertyChangeListeners();
181181
addLogCapturer(logCatpurer);
@@ -192,8 +192,7 @@ private void checkApiKeyIsValid() {
192192
return;
193193
}
194194

195-
throw new InvalidApiKeyException(
196-
String.format("Apikey is not valid: [%s]", this.apiKey.get()));
195+
throw new InvalidApiKeyException(String.format("Apikey is not valid: [%s]", this.apiKey.get()));
197196
}
198197

199198
private void addLogCapturer(LogCapturerIF logCatpurer) {
@@ -210,35 +209,35 @@ private void addLogCapturer(LogCapturerIF logCatpurer) {
210209
public void setApiKey(String apiKey) {
211210
String prevValue = this.apiKey.get();
212211
this.apiKey.update(apiKey);
213-
propertyChangeSupport.firePropertyChange(Configuration.Property.API_KEY, prevValue, apiKey);
212+
propertyChangeSupport.firePropertyChange(Property.API_KEY, prevValue, apiKey);
214213
}
215214

216215
public void setServerUrl(String serverUrl) {
217216
String prevValue = this.serverUrl.get();
218217
this.serverUrl.update(serverUrl);
219218
propertyChangeSupport.firePropertyChange(
220-
Configuration.Property.SERVER_URL, prevValue, serverUrl);
219+
Property.SERVER_URL, prevValue, serverUrl);
221220
}
222221

223222
public void setConfigServerUrl(String configServerUrl) {
224223
String prevValue = this.configServerUrl.get();
225224
this.configServerUrl.update(configServerUrl);
226225
propertyChangeSupport.firePropertyChange(
227-
Configuration.Property.CONFIG_SERVER_URL, prevValue, configServerUrl);
226+
Property.CONFIG_SERVER_URL, prevValue, configServerUrl);
228227
}
229228

230229
public void setHeartbeatServerUrl(String heartbeatServerUrl) {
231230
String prevValue = this.heartbeatServerUrl.get();
232231
this.heartbeatServerUrl.update(heartbeatServerUrl);
233232
propertyChangeSupport.firePropertyChange(
234-
Configuration.Property.HEART_BEAT_SERVER_URL, prevValue, heartbeatServerUrl);
233+
Property.HEART_BEAT_SERVER_URL, prevValue, heartbeatServerUrl);
235234
}
236235

237236
public void setUpdateSettingsWhenIdleInterval(Long updateSettingsWhenIdleInterval) {
238237
Long prevValue = this.updateSettingsWhenIdleInterval.get();
239238
this.updateSettingsWhenIdleInterval.update(updateSettingsWhenIdleInterval);
240239
propertyChangeSupport.firePropertyChange(
241-
Configuration.Property.UPDATE_SETTINGS_WHEN_IDLE_INTERVAL,
240+
Property.UPDATE_SETTINGS_WHEN_IDLE_INTERVAL,
242241
prevValue,
243242
updateSettingsWhenIdleInterval);
244243
}
@@ -247,14 +246,14 @@ public void setSubmissionBatchSize(Integer submissionBatchSize) {
247246
Integer prevValue = this.submissionBatchSize.get();
248247
this.submissionBatchSize.update(submissionBatchSize);
249248
propertyChangeSupport.firePropertyChange(
250-
Configuration.Property.SUBMISSION_BATCH_SIZE, prevValue, submissionBatchSize);
249+
Property.SUBMISSION_BATCH_SIZE, prevValue, submissionBatchSize);
251250
}
252251

253252
public void setSubmissionClientTimeoutInMillis(Integer submissionClientTimeoutInMillis) {
254253
Integer prevValue = this.submissionClientTimeoutInMillis.get();
255254
this.submissionClientTimeoutInMillis.update(submissionClientTimeoutInMillis);
256255
propertyChangeSupport.firePropertyChange(
257-
Configuration.Property.SUBMISSION_CLIENT_TIMEOUT_IN_MILLIS,
256+
Property.SUBMISSION_CLIENT_TIMEOUT_IN_MILLIS,
258257
prevValue,
259258
submissionClientTimeoutInMillis);
260259
}
@@ -263,7 +262,7 @@ public void setSettingsClientTimeoutInMillis(Integer settingsClientTimeoutInMill
263262
Integer prevValue = this.settingsClientTimeoutInMillis.get();
264263
this.settingsClientTimeoutInMillis.update(settingsClientTimeoutInMillis);
265264
propertyChangeSupport.firePropertyChange(
266-
Configuration.Property.SETTINGS_CLIENT_TIMEOUT_IN_MILLIS,
265+
Property.SETTINGS_CLIENT_TIMEOUT_IN_MILLIS,
267266
prevValue,
268267
settingsClientTimeoutInMillis);
269268
}

src/test/java/com/exceptionless/exceptionlessclient/configuration/ConfigurationManagerTest.java

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
package com.exceptionless.exceptionlessclient.configuration;
22

33
import com.exceptionless.exceptionlessclient.TestFixtures;
4+
import com.exceptionless.exceptionlessclient.enums.EventPropertyKey;
45
import com.exceptionless.exceptionlessclient.exceptions.InvalidApiKeyException;
56
import com.exceptionless.exceptionlessclient.logging.LogCapturerIF;
67
import com.exceptionless.exceptionlessclient.models.EventPluginContext;
78
import com.exceptionless.exceptionlessclient.models.UserInfo;
8-
import com.exceptionless.exceptionlessclient.enums.EventPropertyKey;
9-
import com.exceptionless.exceptionlessclient.settings.ServerSettings;
109
import com.exceptionless.exceptionlessclient.plugins.EventPluginIF;
10+
import com.exceptionless.exceptionlessclient.settings.ServerSettings;
1111
import com.exceptionless.exceptionlessclient.storage.InMemoryStorage;
1212
import com.exceptionless.exceptionlessclient.storage.InMemoryStorageProvider;
1313
import com.exceptionless.exceptionlessclient.submission.DefaultSubmissionClient;
14+
import org.assertj.core.api.Assertions;
1415
import org.junit.jupiter.api.BeforeEach;
1516
import org.junit.jupiter.api.Test;
1617
import org.junit.jupiter.api.extension.ExtendWith;
@@ -19,6 +20,7 @@
1920
import org.slf4j.Logger;
2021
import org.slf4j.LoggerFactory;
2122

23+
import java.beans.PropertyChangeListener;
2224
import java.util.List;
2325
import java.util.Map;
2426
import java.util.Set;
@@ -40,6 +42,9 @@ public class ConfigurationManagerTest {
4042
private ConfigurationManager configurationManager;
4143
private InMemoryStorage<ServerSettings> storage;
4244

45+
public ConfigurationManagerTest(PropertyChangeListener listener) {
46+
}
47+
4348
@BeforeEach
4449
public void setup() {
4550
storage = InMemoryStorage.<ServerSettings>builder().build();
@@ -52,11 +57,7 @@ public void setup() {
5257

5358
@Test
5459
public void itThrowsInvalidApiKeyExceptionForInvalidApiKeys() {
55-
assertThatThrownBy(
56-
() ->
57-
TestFixtures.aDefaultConfigurationManager()
58-
.apiKey("xxx")
59-
.build())
60+
assertThatThrownBy(() -> TestFixtures.aDefaultConfigurationManager().apiKey("xxx").build())
6061
.isInstanceOf(InvalidApiKeyException.class)
6162
.hasMessage("Apikey is not valid: [xxx]");
6263
}
@@ -196,4 +197,28 @@ public void itCanDetectChanges() {
196197

197198
verify(handler, times(1)).accept(configurationManager);
198199
}
200+
201+
@Test
202+
public void itCanSetDefaultValueHeartBeatServerUrlToServerUrlIfAbsent() {
203+
ConfigurationManager configurationManager =
204+
ConfigurationManager.builder()
205+
.serverUrl("test-server-url")
206+
.apiKey("12345678abcdef")
207+
.build();
208+
209+
Assertions.assertThat(configurationManager.getHeartbeatServerUrl().get())
210+
.isEqualTo("test-server-url");
211+
}
212+
213+
@Test
214+
public void itCanSetDefaultValueConfigServerUrlToServerUrlIfAbsent() {
215+
ConfigurationManager configurationManager =
216+
ConfigurationManager.builder()
217+
.serverUrl("test-server-url")
218+
.apiKey("12345678abcdef")
219+
.build();
220+
221+
Assertions.assertThat(configurationManager.getConfigServerUrl().get())
222+
.isEqualTo("test-server-url");
223+
}
199224
}

0 commit comments

Comments
 (0)