forked from Visual-Regression-Tracker/sdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVisualRegressionTrackerConfigTest.java
More file actions
114 lines (95 loc) · 4.42 KB
/
VisualRegressionTrackerConfigTest.java
File metadata and controls
114 lines (95 loc) · 4.42 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package io.visual_regression_tracker.sdk_java;
import org.testng.annotations.Test;
import uk.org.webcompere.systemstubs.environment.EnvironmentVariables;
import java.io.File;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
public class VisualRegressionTrackerConfigTest {
@Test(expectedExceptions = NullPointerException.class,
expectedExceptionsMessageRegExp = "apiKey is marked non-null but is null")
public void shouldThrowExceptionIfApiKeyMissed() {
VisualRegressionTrackerConfig
.builder()
.apiUrl("")
.project("")
.build();
}
@Test(expectedExceptions = NullPointerException.class,
expectedExceptionsMessageRegExp = "apiUrl is marked non-null but is null")
public void shouldThrowExceptionIfApiUrlMissed() {
VisualRegressionTrackerConfig
.builder()
.apiKey("")
.project("")
.build();
}
@Test(expectedExceptions = NullPointerException.class,
expectedExceptionsMessageRegExp = "project is marked non-null but is null")
public void shouldThrowExceptionIfProjectMissed() {
VisualRegressionTrackerConfig
.builder()
.apiKey("")
.apiUrl("")
.build();
}
@Test
public void shouldBeCreatedFromConfigFile() {
File configFile = new File("src/test/resources/vrt_config_example.json");
VisualRegressionTrackerConfig config = VisualRegressionTrackerConfig.builder()
.configFile(configFile)
.build();
assertThat(config.getApiKey(), is("SECRET"));
assertThat(config.getApiUrl(), is("http://162.243.161.172:4200"));
assertThat(config.getProject(), is("VRT"));
assertThat(config.getBranchName(), is("master"));
assertThat(config.getEnableSoftAssert(), is(false));
assertThat(config.getCiBuildId(), is("SOME_UNIQUE_ID"));
}
@Test
public void shouldBeCreatedFromEnvironment() throws Exception {
EnvironmentVariables environmentVariables = new EnvironmentVariables("VRT_APIKEY", "SECRET")
.set("VRT_APIURL", "http://162.243.161.172:4200")
.set("VRT_PROJECT", "VRT")
.set("VRT_BRANCHNAME", "master")
.set("VRT_ENABLESOFTASSERT", "false")
.set("VRT_CIBUILDID", "SOME_UNIQUE_ID");
VisualRegressionTrackerConfig config = environmentVariables.execute(() ->
VisualRegressionTrackerConfig.builder()
.build()
);
assertThat(config.getApiKey(), is("SECRET"));
assertThat(config.getApiUrl(), is("http://162.243.161.172:4200"));
assertThat(config.getProject(), is("VRT"));
assertThat(config.getBranchName(), is("master"));
assertThat(config.getEnableSoftAssert(), is(false));
assertThat(config.getCiBuildId(), is("SOME_UNIQUE_ID"));
}
@Test
public void shouldResolveFinalValuesInTheRightOrder() throws Exception {
EnvironmentVariables environmentVariables = new EnvironmentVariables("VRT_APIKEY", "ENV_SECRET")
.set("VRT_APIURL", "http://162.243.161.172:4201");
File configFile = new File("src/test/resources/vrt_config_example.json");
VisualRegressionTrackerConfig config = environmentVariables.execute(() ->
VisualRegressionTrackerConfig.builder()
.apiUrl("http://localhost:4200")
.configFile(configFile)
.build()
);
assertThat(config.getApiKey(), is("ENV_SECRET"));
assertThat(config.getApiUrl(), is("http://localhost:4200"));
assertThat(config.getProject(), is("VRT"));
assertThat(config.getBranchName(), is("master"));
assertThat(config.getEnableSoftAssert(), is(false));
assertThat(config.getCiBuildId(), is("SOME_UNIQUE_ID"));
}
@Test
public void shouldUseDefaultValuesIfNotProvided() {
VisualRegressionTrackerConfig config = VisualRegressionTrackerConfig.builder()
.apiUrl("http://localhost:4200")
.apiKey("KEY")
.project("PROJECT")
.build();
assertThat(config.getEnableSoftAssert(), is(false));
assertThat(config.getHttpTimeoutInSeconds(), is(10));
}
}