Skip to content

Commit ee4762e

Browse files
author
Sergey Brenko
authored
Merge pull request #59 from zebrunner/refactoring/config
Refactoring config
2 parents f487f02 + 0e38dbb commit ee4762e

11 files changed

+470
-591
lines changed

src/main/java/com/zebrunner/agent/core/config/ReportingConfiguration.java

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package com.zebrunner.agent.core.config;
22

3+
import com.zebrunner.agent.core.config.annotation.Configuration;
4+
import com.zebrunner.agent.core.config.annotation.EnvironmentVariable;
5+
import com.zebrunner.agent.core.config.annotation.PropertiesFileProperty;
6+
import com.zebrunner.agent.core.config.annotation.SystemProperty;
7+
import com.zebrunner.agent.core.config.annotation.YamlProperty;
38
import lombok.AllArgsConstructor;
49
import lombok.Builder;
510
import lombok.Data;
@@ -10,14 +15,35 @@
1015
@Getter
1116
@Setter
1217
@Builder
18+
@NoArgsConstructor
19+
@AllArgsConstructor
1320
public class ReportingConfiguration {
1421

22+
@YamlProperty("reporting.enabled")
23+
@SystemProperty("reporting.enabled")
24+
@EnvironmentVariable("REPORTING_ENABLED")
25+
@PropertiesFileProperty("reporting.enabled")
1526
private Boolean reportingEnabled;
27+
28+
@EnvironmentVariable("REPORTING_PROJECT_KEY")
29+
@YamlProperty({"reporting.project-key", "reporting.projectKey"})
30+
@SystemProperty({"reporting.project-key", "reporting.projectKey"})
31+
@PropertiesFileProperty({"reporting.project-key", "reporting.projectKey"})
1632
private String projectKey;
33+
34+
@Configuration
1735
private ServerConfiguration server;
36+
37+
@Configuration
1838
private RunConfiguration run;
39+
40+
@Configuration
1941
private MilestoneConfiguration milestone;
42+
43+
@Configuration
2044
private NotificationConfiguration notification;
45+
46+
@Configuration
2147
private TcmConfiguration tcm;
2248

2349
public boolean isReportingEnabled() {
@@ -29,7 +55,16 @@ public boolean isReportingEnabled() {
2955
@AllArgsConstructor
3056
public static class MilestoneConfiguration {
3157

58+
@YamlProperty("reporting.milestone.id")
59+
@SystemProperty("reporting.milestone.id")
60+
@EnvironmentVariable("REPORTING_MILESTONE_ID")
61+
@PropertiesFileProperty("reporting.milestone.id")
3262
private Long id;
63+
64+
@YamlProperty("reporting.milestone.name")
65+
@SystemProperty("reporting.milestone.name")
66+
@EnvironmentVariable("REPORTING_MILESTONE_NAME")
67+
@PropertiesFileProperty("reporting.milestone.name")
3368
private String name;
3469

3570
}
@@ -40,7 +75,16 @@ public static class MilestoneConfiguration {
4075
@AllArgsConstructor
4176
public static class ServerConfiguration {
4277

78+
@YamlProperty("reporting.server.hostname")
79+
@SystemProperty("reporting.server.hostname")
80+
@EnvironmentVariable("REPORTING_SERVER_HOSTNAME")
81+
@PropertiesFileProperty("reporting.server.hostname")
4382
private String hostname;
83+
84+
@YamlProperty("reporting.server.access-token")
85+
@EnvironmentVariable("REPORTING_SERVER_ACCESS_TOKEN")
86+
@PropertiesFileProperty("reporting.server.access-token")
87+
@SystemProperty({"reporting.server.access-token", "reporting.server.accessToken"})
4488
private String accessToken;
4589

4690
}
@@ -51,12 +95,43 @@ public static class ServerConfiguration {
5195
@AllArgsConstructor
5296
public static class RunConfiguration {
5397

98+
@EnvironmentVariable("REPORTING_RUN_DISPLAY_NAME")
99+
@YamlProperty({"reporting.run.display-name", "reporting.run.displayName"})
100+
@SystemProperty({"reporting.run.display-name", "reporting.run.displayName"})
101+
@PropertiesFileProperty({"reporting.run.display-name", "reporting.run.displayName"})
54102
private String displayName;
103+
104+
@YamlProperty("reporting.run.build")
105+
@SystemProperty("reporting.run.build")
106+
@EnvironmentVariable("REPORTING_RUN_BUILD")
107+
@PropertiesFileProperty("reporting.run.build")
55108
private String build;
109+
110+
@YamlProperty("reporting.run.environment")
111+
@SystemProperty("reporting.run.environment")
112+
@EnvironmentVariable("REPORTING_RUN_ENVIRONMENT")
113+
@PropertiesFileProperty("reporting.run.environment")
56114
private String environment;
115+
116+
@YamlProperty("reporting.run.context")
117+
@SystemProperty("reporting.run.context")
118+
@EnvironmentVariable("REPORTING_RUN_CONTEXT")
119+
@PropertiesFileProperty("reporting.run.context")
57120
private String context;
121+
122+
@YamlProperty("reporting.run.retry-known-issues")
123+
@EnvironmentVariable("REPORTING_RUN_RETRY_KNOWN_ISSUES")
124+
@PropertiesFileProperty("reporting.run.retry-known-issues")
125+
@SystemProperty({"reporting.run.retry-known-issues", "reporting.run.retryKnownIssues"})
58126
private Boolean retryKnownIssues;
127+
128+
@EnvironmentVariable("REPORTING_RUN_SUBSTITUTE_REMOTE_WEB_DRIVERS")
59129
private Boolean substituteRemoteWebDrivers;
130+
131+
@YamlProperty("reporting.run.treat-skips-as-failures")
132+
@SystemProperty("reporting.run.treat-skips-as-failures")
133+
@EnvironmentVariable("REPORTING_RUN_TREAT_SKIPS_AS_FAILURES")
134+
@PropertiesFileProperty("reporting.run.treat-skips-as-failures")
60135
private Boolean treatSkipsAsFailures;
61136

62137
}
@@ -66,10 +141,34 @@ public static class RunConfiguration {
66141
@AllArgsConstructor
67142
public static class NotificationConfiguration {
68143

144+
@YamlProperty("reporting.notification.enabled")
145+
@SystemProperty("reporting.notification.enabled")
146+
@EnvironmentVariable("REPORTING_NOTIFICATION_ENABLED")
147+
@PropertiesFileProperty("reporting.notification.enabled")
69148
private Boolean enabled;
149+
150+
@YamlProperty("reporting.notification.notify-on-each-failure")
151+
@SystemProperty("reporting.notification.notify-on-each-failure")
152+
@EnvironmentVariable("REPORTING_NOTIFICATION_NOTIFY_ON_EACH_FAILURE")
153+
@PropertiesFileProperty("reporting.notification.notify-on-each-failure")
70154
private Boolean notifyOnEachFailure;
155+
156+
@YamlProperty("reporting.notification.slack-channels")
157+
@SystemProperty("reporting.notification.slack-channels")
158+
@EnvironmentVariable("REPORTING_NOTIFICATION_SLACK_CHANNELS")
159+
@PropertiesFileProperty("reporting.notification.slack-channels")
71160
private String slackChannels;
161+
162+
@YamlProperty("reporting.notification.ms-teams-channels")
163+
@SystemProperty("reporting.notification.ms-teams-channels")
164+
@EnvironmentVariable("REPORTING_NOTIFICATION_MS_TEAMS_CHANNELS")
165+
@PropertiesFileProperty("reporting.notification.ms-teams-channels")
72166
private String msTeamsChannels;
167+
168+
@YamlProperty("reporting.notification.emails")
169+
@SystemProperty("reporting.notification.emails")
170+
@EnvironmentVariable("REPORTING_NOTIFICATION_EMAILS")
171+
@PropertiesFileProperty("reporting.notification.emails")
73172
private String emails;
74173

75174
}
@@ -80,10 +179,15 @@ public static class NotificationConfiguration {
80179
@AllArgsConstructor
81180
public static class TcmConfiguration {
82181

182+
@Configuration
83183
private TestCaseStatus testCaseStatus = new TestCaseStatus();
184+
@Configuration
84185
private Zebrunner zebrunner = new Zebrunner();
186+
@Configuration
85187
private TestRail testRail = new TestRail();
188+
@Configuration
86189
private Xray xray = new Xray();
190+
@Configuration
87191
private Zephyr zephyr = new Zephyr();
88192

89193
@Getter
@@ -92,8 +196,22 @@ public static class TcmConfiguration {
92196
@AllArgsConstructor
93197
public static class TestCaseStatus {
94198

199+
@YamlProperty("reporting.tcm.test-case-status.on-pass")
200+
@SystemProperty("reporting.tcm.test-case-status.on-pass")
201+
@EnvironmentVariable("REPORTING_TCM_TEST_CASE_STATUS_ON_PASS")
202+
@PropertiesFileProperty("reporting.tcm.test-case-status.on-pass")
95203
private String onPass;
204+
205+
@YamlProperty("reporting.tcm.test-case-status.on-fail")
206+
@SystemProperty("reporting.tcm.test-case-status.on-fail")
207+
@EnvironmentVariable("REPORTING_TCM_TEST_CASE_STATUS_ON_FAIL")
208+
@PropertiesFileProperty("reporting.tcm.test-case-status.on-fail")
96209
private String onFail;
210+
211+
@YamlProperty("reporting.tcm.test-case-status.on-skip")
212+
@SystemProperty("reporting.tcm.test-case-status.on-skip")
213+
@EnvironmentVariable("REPORTING_TCM_TEST_CASE_STATUS_ON_SKIP")
214+
@PropertiesFileProperty("reporting.tcm.test-case-status.on-skip")
97215
private String onSkip;
98216

99217
}
@@ -104,8 +222,22 @@ public static class TestCaseStatus {
104222
@AllArgsConstructor
105223
public static class Zebrunner {
106224

225+
@YamlProperty("reporting.tcm.zebrunner.push-results")
226+
@SystemProperty("reporting.tcm.zebrunner.push-results")
227+
@EnvironmentVariable("REPORTING_TCM_ZEBRUNNER_PUSH_RESULTS")
228+
@PropertiesFileProperty("reporting.tcm.zebrunner.push-results")
107229
private Boolean pushResults;
230+
231+
@YamlProperty("reporting.tcm.zebrunner.push-in-real-time")
232+
@SystemProperty("reporting.tcm.zebrunner.push-in-real-time")
233+
@EnvironmentVariable("REPORTING_TCM_ZEBRUNNER_PUSH_IN_REAL_TIME")
234+
@PropertiesFileProperty("reporting.tcm.zebrunner.push-in-real-time")
108235
private Boolean pushInRealTime;
236+
237+
@EnvironmentVariable("REPORTING_TCM_ZEBRUNNER_RUN_ID")
238+
@YamlProperty({"reporting.tcm.zebrunner.test-run-id", "reporting.tcm.zebrunner.run-id"})
239+
@SystemProperty({"reporting.tcm.zebrunner.test-run-id", "reporting.tcm.zebrunner.run-id"})
240+
@PropertiesFileProperty({"reporting.tcm.zebrunner.test-run-id", "reporting.tcm.zebrunner.run-id"})
109241
private String testRunId;
110242

111243
}
@@ -117,13 +249,52 @@ public static class Zebrunner {
117249
@AllArgsConstructor
118250
public static class TestRail {
119251

252+
@YamlProperty("reporting.tcm.test-rail.push-results")
253+
@SystemProperty("reporting.tcm.test-rail.push-results")
254+
@EnvironmentVariable("REPORTING_TCM_TEST_RAIL_PUSH_RESULTS")
255+
@PropertiesFileProperty("reporting.tcm.test-rail.push-results")
120256
private Boolean pushResults;
257+
258+
@YamlProperty("reporting.tcm.test-rail.push-in-real-time")
259+
@SystemProperty("reporting.tcm.test-rail.push-in-real-time")
260+
@EnvironmentVariable("REPORTING_TCM_TEST_RAIL_PUSH_IN_REAL_TIME")
261+
@PropertiesFileProperty("reporting.tcm.test-rail.push-in-real-time")
121262
private Boolean pushInRealTime;
263+
264+
@YamlProperty("reporting.tcm.test-rail.suite-id")
265+
@SystemProperty("reporting.tcm.test-rail.suite-id")
266+
@EnvironmentVariable("REPORTING_TCM_TEST_RAIL_SUITE_ID")
267+
@PropertiesFileProperty("reporting.tcm.test-rail.suite-id")
122268
private String suiteId;
269+
270+
@YamlProperty("reporting.tcm.test-rail.run-id")
271+
@SystemProperty("reporting.tcm.test-rail.run-id")
272+
@EnvironmentVariable("REPORTING_TCM_TEST_RAIL_RUN_ID")
273+
@PropertiesFileProperty("reporting.tcm.test-rail.run-id")
123274
private String runId;
275+
276+
@YamlProperty("reporting.tcm.test-rail.include-all-test-cases-in-new-run")
277+
@SystemProperty("reporting.tcm.test-rail.include-all-test-cases-in-new-run")
278+
@EnvironmentVariable("REPORTING_TCM_TEST_RAIL_INCLUDE_ALL_TEST_CASES_IN_NEW_RUN")
279+
@PropertiesFileProperty("reporting.tcm.test-rail.include-all-test-cases-in-new-run")
124280
private Boolean includeAllTestCasesInNewRun;
281+
282+
@YamlProperty("reporting.tcm.test-rail.run-name")
283+
@SystemProperty("reporting.tcm.test-rail.run-name")
284+
@EnvironmentVariable("REPORTING_TCM_TEST_RAIL_RUN_NAME")
285+
@PropertiesFileProperty("reporting.tcm.test-rail.run-name")
125286
private String runName;
287+
288+
@YamlProperty("reporting.tcm.test-rail.milestone-name")
289+
@SystemProperty("reporting.tcm.test-rail.milestone-name")
290+
@EnvironmentVariable("REPORTING_TCM_TEST_RAIL_MILESTONE_NAME")
291+
@PropertiesFileProperty("reporting.tcm.test-rail.milestone-name")
126292
private String milestoneName;
293+
294+
@YamlProperty("reporting.tcm.test-rail.assignee")
295+
@SystemProperty("reporting.tcm.test-rail.assignee")
296+
@EnvironmentVariable("REPORTING_TCM_TEST_RAIL_ASSIGNEE")
297+
@PropertiesFileProperty("reporting.tcm.test-rail.assignee")
127298
private String assignee;
128299

129300
}
@@ -134,8 +305,22 @@ public static class TestRail {
134305
@AllArgsConstructor
135306
public static class Xray {
136307

308+
@YamlProperty("reporting.tcm.xray.push-results")
309+
@SystemProperty("reporting.tcm.xray.push-results")
310+
@EnvironmentVariable("REPORTING_TCM_XRAY_PUSH_RESULTS")
311+
@PropertiesFileProperty("reporting.tcm.xray.push-results")
137312
private Boolean pushResults;
313+
314+
@YamlProperty("reporting.tcm.xray.push-in-real-time")
315+
@SystemProperty("reporting.tcm.xray.push-in-real-time")
316+
@EnvironmentVariable("REPORTING_TCM_XRAY_PUSH_IN_REAL_TIME")
317+
@PropertiesFileProperty("reporting.tcm.xray.push-in-real-time")
138318
private Boolean pushInRealTime;
319+
320+
@YamlProperty("reporting.tcm.xray.execution-key")
321+
@SystemProperty("reporting.tcm.xray.execution-key")
322+
@EnvironmentVariable("REPORTING_TCM_XRAY_EXECUTION_KEY")
323+
@PropertiesFileProperty("reporting.tcm.xray.execution-key")
139324
private String executionKey;
140325

141326
}
@@ -146,9 +331,28 @@ public static class Xray {
146331
@AllArgsConstructor
147332
public static class Zephyr {
148333

334+
@YamlProperty("reporting.tcm.zephyr.push-results")
335+
@SystemProperty("reporting.tcm.zephyr.push-results")
336+
@EnvironmentVariable("REPORTING_TCM_ZEPHYR_PUSH_RESULTS")
337+
@PropertiesFileProperty("reporting.tcm.zephyr.push-results")
149338
private Boolean pushResults;
339+
340+
@YamlProperty("reporting.tcm.zephyr.push-in-real-time")
341+
@SystemProperty("reporting.tcm.zephyr.push-in-real-time")
342+
@EnvironmentVariable("REPORTING_TCM_ZEPHYR_PUSH_IN_REAL_TIME")
343+
@PropertiesFileProperty("reporting.tcm.zephyr.push-in-real-time")
150344
private Boolean pushInRealTime;
345+
346+
@YamlProperty("reporting.tcm.zephyr.jira-project-key")
347+
@SystemProperty("reporting.tcm.zephyr.jira-project-key")
348+
@EnvironmentVariable("REPORTING_TCM_ZEPHYR_JIRA_PROJECT_KEY")
349+
@PropertiesFileProperty("reporting.tcm.zephyr.jira-project-key")
151350
private String jiraProjectKey;
351+
352+
@YamlProperty("reporting.tcm.zephyr.test-cycle-key")
353+
@SystemProperty("reporting.tcm.zephyr.test-cycle-key")
354+
@EnvironmentVariable("REPORTING_TCM_ZEPHYR_TEST_CYCLE_KEY")
355+
@PropertiesFileProperty("reporting.tcm.zephyr.test-cycle-key")
152356
private String testCycleKey;
153357

154358
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.zebrunner.agent.core.config.annotation;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
@Target(ElementType.FIELD)
9+
@Retention(RetentionPolicy.RUNTIME)
10+
public @interface Configuration {
11+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.zebrunner.agent.core.config.annotation;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
@Target(ElementType.FIELD)
9+
@Retention(RetentionPolicy.RUNTIME)
10+
public @interface EnvironmentVariable {
11+
12+
String value();
13+
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.zebrunner.agent.core.config.annotation;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
@Target(ElementType.FIELD)
9+
@Retention(RetentionPolicy.RUNTIME)
10+
public @interface PropertiesFileProperty {
11+
12+
String[] value();
13+
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.zebrunner.agent.core.config.annotation;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
@Target(ElementType.FIELD)
9+
@Retention(RetentionPolicy.RUNTIME)
10+
public @interface SystemProperty {
11+
12+
String[] value();
13+
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.zebrunner.agent.core.config.annotation;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
@Target(ElementType.FIELD)
9+
@Retention(RetentionPolicy.RUNTIME)
10+
public @interface YamlProperty {
11+
12+
String[] value();
13+
14+
}

0 commit comments

Comments
 (0)