1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.integrationtests;
35
36 import java.util.Optional;
37 import java.util.function.Function;
38
39 import org.apache.commons.beanutils.BeanUtilsBean;
40
41
42
43
44 public final class IntegrationTestSettings {
45
46 private static final IntegrationTestSettings INSTANCE = new IntegrationTestSettings();
47
48 public static IntegrationTestSettings access() {
49 return INSTANCE;
50 }
51
52 private BeanUtilsBean beanUtils = BeanUtilsBean.getInstance();
53
54 private Function<String, Integer> toInt = converter(Integer.class);
55 private Function<String, Boolean> toBool = converter(Boolean.class);
56
57
58 public String testOutputDirectory() {
59 return property("test.output.dir").orElse("target/failsafe-reports");
60 }
61
62 public String recordingsDirectory() {
63 return property("recordings.dir").orElse(String.format("%s/recordings/", testOutputDirectory()));
64 }
65
66 public String uploadDirectory() {
67 return property("upload.dir").orElse("target/test-classes");
68 }
69
70 public String seleniumHubContainerName() {
71 return property("selenium.hub.name").orElse("selenium-hub");
72 }
73
74 public String seleniumHubHost() {
75 return property("selenium.hub.host").orElse("localhost");
76 }
77
78 public int concurrentTestInstances() {
79 return property("concurrent.instances").map(toInt).orElse(1);
80 }
81
82
83
84
85
86 public String testNetworkName() {
87 return property("selenium.network").orElse("mgnl-integration-tests");
88 }
89
90 public String vncPassword() {
91 return property("vnc.password").orElse("secret");
92 }
93
94 public String seleniumBrowser() {
95 return property("seleniumBrowser").orElse("chrome");
96 }
97
98 public boolean testEnvironmentSetupRequired() {
99 return property("setup.test.env").map(toBool).orElse(true);
100 }
101
102 public int defaultDelayInSeconds() {
103 return 2;
104 }
105
106 public int driverTimeoutInSeconds() {
107 return 30;
108 }
109
110 public int vncPort() {
111 return property("vnc.port").map(toInt).orElse(5900);
112 }
113
114
115
116
117
118 public int concurrentTestCases() {
119 return property("concurrent.test.cases").map(toInt).orElse(1);
120 }
121
122 public int seleniumHubPort() {
123 return property("selenium.hub.port").map(toInt).orElse(4444);
124 }
125
126 public boolean debugMode() {
127 return property("debug.mode").map(toBool).orElse(true);
128 }
129
130 public boolean keepSuccessfulTestRecordings() {
131 return property("keep.successful").map(toBool).orElse(false);
132 }
133
134 public boolean useHeadlessSeleniumNodes() {
135 return property("run.headless").map(toBool).orElse(false);
136 }
137
138 private Optional<String> property(String key) {
139 return Optional.ofNullable(System.getProperty(key));
140 }
141
142 @SuppressWarnings("unchecked")
143 private <T> Function<String, T> converter(Class<T> clazz) {
144 return str -> (T) beanUtils.getConvertUtils().convert(str, clazz);
145 }
146
147 public String authorWarLocation() {
148 return property("author.war.location").orElse("target/wars/magnoliaAuthor.war");
149 }
150
151 public String publicWarLocation() {
152 return property("public.war.location").orElse("target/wars/magnoliaPublic.war");
153 }
154
155 public String authorContextPath() {
156 return property("authorContextPath").orElse("magnoliaAuthor");
157 }
158
159 public String publicContextPath() {
160 return property("publicContextPath").orElse("magnoliaPublic");
161 }
162
163
164
165
166
167
168
169
170
171 public String directContainerRootURL() {
172 return String.format("http://%s:%d", publicHostName(), publicPort());
173 }
174
175
176
177
178
179
180
181
182
183
184 public String privateHostName() {
185 return property("privateHostName").orElse("server");
186 }
187
188
189
190
191
192
193 public int privatePort() {
194 return property("privateContainerHttpPort").map(toInt).orElse(8080);
195 }
196
197
198
199
200
201
202
203
204
205 public String publicHostName() {
206 return property("containerHostName").orElse("localhost");
207 }
208
209
210
211
212
213
214
215
216 public int publicPort() {
217 return property(String.format("%s.public.port", privateHostName())).map(toInt).orElseGet(() ->
218 property("containerHttpPort")
219 .map(toInt)
220 .orElse(8599));
221 }
222
223
224
225
226
227 public String containerRootUrl() {
228 return String.format("http://%s:%d", privateHostName(), privatePort());
229 }
230
231 public Integer startupTimeout() {
232 return property("startupTimeout").map(toInt).orElse(7);
233 }
234 }