Skip to content

Commit 680ca56

Browse files
committed
#36 Extract config name enum in own file forbetter readability
Signed-off-by: Sven Strittmatter <sven.strittmatter@iteratec.com>
1 parent 86834d3 commit 680ca56

File tree

3 files changed

+59
-57
lines changed

3 files changed

+59
-57
lines changed

src/main/java/io/securecodebox/persistence/defectdojo/http/ProxyConfigFactory.java

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.securecodebox.persistence.defectdojo.http;
22

3-
import lombok.Getter;
43
import lombok.NonNull;
54

65
/**
@@ -55,42 +54,6 @@ public ProxyConfig create() {
5554
return builder.build();
5655
}
5756

58-
/**
59-
* These properties can be configured by passing them to the running Java process w/ flag {@literal -D}
60-
* <p>
61-
* Example: {@literal java -Dhttp.proxyHost=... -D... -jar ...}
62-
* </p>
63-
* <p>
64-
* <strong>Important</strong>: All four parameters are mandatory. You must set them all
65-
* or none of them!
66-
* </p>
67-
*/
68-
@Getter
69-
public enum ProxyConfigNames {
70-
/**
71-
* System property name for the proxy username
72-
*/
73-
HTTP_PROXY_USER("http.proxyUser"),
74-
/**
75-
* System property name for the proxy user's password
76-
*/
77-
HTTP_PROXY_PASSWORD("http.proxyPassword"),
78-
/**
79-
* System property name for the proxy's hostname
80-
*/
81-
HTTP_PROXY_HOST("http.proxyHost"),
82-
/**
83-
* System property for the proxy's port number
84-
*/
85-
HTTP_PROXY_PORT("http.proxyPort");
86-
87-
private final String literat;
88-
89-
ProxyConfigNames(String literat) {
90-
this.literat = literat;
91-
}
92-
}
93-
9457
private static class SystemPropertyFinder {
9558
private boolean hasProperty(@NonNull final ProxyConfigNames name) {
9659
return System.getProperty(name.getLiterat()) != null;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package io.securecodebox.persistence.defectdojo.http;
2+
3+
import lombok.Getter;
4+
5+
/**
6+
* These properties can be configured by passing them to the running Java process w/ flag {@literal -D}
7+
* <p>
8+
* Example: {@literal java -Dhttp.proxyHost=... -D... -jar ...}
9+
* </p>
10+
* <p>
11+
* <strong>Important</strong>: All four parameters are mandatory. You must set them all
12+
* or none of them!
13+
* </p>
14+
*/
15+
@Getter
16+
public enum ProxyConfigNames {
17+
/**
18+
* System property name for the proxy username
19+
*/
20+
HTTP_PROXY_USER("http.proxyUser"),
21+
/**
22+
* System property name for the proxy user's password
23+
*/
24+
HTTP_PROXY_PASSWORD("http.proxyPassword"),
25+
/**
26+
* System property name for the proxy's hostname
27+
*/
28+
HTTP_PROXY_HOST("http.proxyHost"),
29+
/**
30+
* System property for the proxy's port number
31+
*/
32+
HTTP_PROXY_PORT("http.proxyPort");
33+
34+
private final String literat;
35+
36+
ProxyConfigNames(String literat) {
37+
this.literat = literat;
38+
}
39+
}

src/test/java/io/securecodebox/persistence/defectdojo/http/ProxyConfigFactoryTest.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ class ProxyConfigFactoryTest {
2121

2222
@Test
2323
void create_throesExceptionIfUserNotSet() {
24-
System.clearProperty(ProxyConfigFactory.ProxyConfigNames.HTTP_PROXY_USER.getLiterat());
25-
System.setProperty(ProxyConfigFactory.ProxyConfigNames.HTTP_PROXY_PASSWORD.getLiterat(), "password");
26-
System.setProperty(ProxyConfigFactory.ProxyConfigNames.HTTP_PROXY_HOST.getLiterat(), "host");
27-
System.setProperty(ProxyConfigFactory.ProxyConfigNames.HTTP_PROXY_PORT.getLiterat(), "4242");
24+
System.clearProperty(ProxyConfigNames.HTTP_PROXY_USER.getLiterat());
25+
System.setProperty(ProxyConfigNames.HTTP_PROXY_PASSWORD.getLiterat(), "password");
26+
System.setProperty(ProxyConfigNames.HTTP_PROXY_HOST.getLiterat(), "host");
27+
System.setProperty(ProxyConfigNames.HTTP_PROXY_PORT.getLiterat(), "4242");
2828

2929
final var thrown = assertThrows(
3030
ProxyConfigFactory.MissingProxyConfigValue.class,
@@ -35,10 +35,10 @@ void create_throesExceptionIfUserNotSet() {
3535

3636
@Test
3737
void create_throesExceptionIfPasswordNotSet() {
38-
System.setProperty(ProxyConfigFactory.ProxyConfigNames.HTTP_PROXY_USER.getLiterat(), "user");
39-
System.clearProperty(ProxyConfigFactory.ProxyConfigNames.HTTP_PROXY_PASSWORD.getLiterat());
40-
System.setProperty(ProxyConfigFactory.ProxyConfigNames.HTTP_PROXY_HOST.getLiterat(), "host");
41-
System.setProperty(ProxyConfigFactory.ProxyConfigNames.HTTP_PROXY_PORT.getLiterat(), "4242");
38+
System.setProperty(ProxyConfigNames.HTTP_PROXY_USER.getLiterat(), "user");
39+
System.clearProperty(ProxyConfigNames.HTTP_PROXY_PASSWORD.getLiterat());
40+
System.setProperty(ProxyConfigNames.HTTP_PROXY_HOST.getLiterat(), "host");
41+
System.setProperty(ProxyConfigNames.HTTP_PROXY_PORT.getLiterat(), "4242");
4242

4343
final var thrown = assertThrows(
4444
ProxyConfigFactory.MissingProxyConfigValue.class,
@@ -49,10 +49,10 @@ void create_throesExceptionIfPasswordNotSet() {
4949

5050
@Test
5151
void create_throesExceptionIfHostNotSet() {
52-
System.setProperty(ProxyConfigFactory.ProxyConfigNames.HTTP_PROXY_USER.getLiterat(), "user");
53-
System.setProperty(ProxyConfigFactory.ProxyConfigNames.HTTP_PROXY_PASSWORD.getLiterat(), "password");
54-
System.clearProperty(ProxyConfigFactory.ProxyConfigNames.HTTP_PROXY_HOST.getLiterat());
55-
System.setProperty(ProxyConfigFactory.ProxyConfigNames.HTTP_PROXY_PORT.getLiterat(), "4242");
52+
System.setProperty(ProxyConfigNames.HTTP_PROXY_USER.getLiterat(), "user");
53+
System.setProperty(ProxyConfigNames.HTTP_PROXY_PASSWORD.getLiterat(), "password");
54+
System.clearProperty(ProxyConfigNames.HTTP_PROXY_HOST.getLiterat());
55+
System.setProperty(ProxyConfigNames.HTTP_PROXY_PORT.getLiterat(), "4242");
5656

5757
final var thrown = assertThrows(
5858
ProxyConfigFactory.MissingProxyConfigValue.class,
@@ -63,10 +63,10 @@ void create_throesExceptionIfHostNotSet() {
6363

6464
@Test
6565
void create_throesExceptionIfPortNotSet() {
66-
System.setProperty(ProxyConfigFactory.ProxyConfigNames.HTTP_PROXY_USER.getLiterat(), "user");
67-
System.setProperty(ProxyConfigFactory.ProxyConfigNames.HTTP_PROXY_PASSWORD.getLiterat(), "password");
68-
System.setProperty(ProxyConfigFactory.ProxyConfigNames.HTTP_PROXY_HOST.getLiterat(), "host");
69-
System.clearProperty(ProxyConfigFactory.ProxyConfigNames.HTTP_PROXY_PORT.getLiterat());
66+
System.setProperty(ProxyConfigNames.HTTP_PROXY_USER.getLiterat(), "user");
67+
System.setProperty(ProxyConfigNames.HTTP_PROXY_PASSWORD.getLiterat(), "password");
68+
System.setProperty(ProxyConfigNames.HTTP_PROXY_HOST.getLiterat(), "host");
69+
System.clearProperty(ProxyConfigNames.HTTP_PROXY_PORT.getLiterat());
7070

7171
final var thrown = assertThrows(
7272
ProxyConfigFactory.MissingProxyConfigValue.class,
@@ -77,10 +77,10 @@ void create_throesExceptionIfPortNotSet() {
7777

7878
@Test
7979
void create_throesExceptionIfPortIsNotInteger() {
80-
System.setProperty(ProxyConfigFactory.ProxyConfigNames.HTTP_PROXY_USER.getLiterat(), "user");
81-
System.setProperty(ProxyConfigFactory.ProxyConfigNames.HTTP_PROXY_PASSWORD.getLiterat(), "password");
82-
System.setProperty(ProxyConfigFactory.ProxyConfigNames.HTTP_PROXY_HOST.getLiterat(), "host");
83-
System.setProperty(ProxyConfigFactory.ProxyConfigNames.HTTP_PROXY_PORT.getLiterat(), "FUBAR");
80+
System.setProperty(ProxyConfigNames.HTTP_PROXY_USER.getLiterat(), "user");
81+
System.setProperty(ProxyConfigNames.HTTP_PROXY_PASSWORD.getLiterat(), "password");
82+
System.setProperty(ProxyConfigNames.HTTP_PROXY_HOST.getLiterat(), "host");
83+
System.setProperty(ProxyConfigNames.HTTP_PROXY_PORT.getLiterat(), "FUBAR");
8484

8585
final var thrown = assertThrows(
8686
IllegalArgumentException.class,

0 commit comments

Comments
 (0)