Skip to content

Commit 1c89da7

Browse files
authored
Merge pull request #30 from Visual-Regression-Tracker/130-test-run-result-added
130 test run result added
2 parents 10acbba + 1eec1a3 commit 1c89da7

File tree

7 files changed

+107
-16
lines changed

7 files changed

+107
-16
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
group 'io.visual-regression-tracker.sdk-java'
2-
version '4.1.1'
2+
version '4.3.0'
33

44
apply plugin: 'java'
55
apply plugin: 'jacoco'

src/main/java/io/visual_regression_tracker/sdk_java/PathProvider.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,11 @@ public String getBuildPathForBuild(String buildId) {
2121
public String getTestRunPath() {
2222
return baseApiUrl.concat(TEST_RUNS_PATH);
2323
}
24+
25+
public String getImageUrl(String name) {
26+
if(name == null || name.isEmpty()){
27+
return null;
28+
}
29+
return baseApiUrl.concat("/").concat(name);
30+
}
2431
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package io.visual_regression_tracker.sdk_java;
2+
3+
import io.visual_regression_tracker.sdk_java.response.TestRunResponse;
4+
import lombok.Getter;
5+
6+
@Getter
7+
public class TestRunResult {
8+
private final TestRunResponse testRunResponse;
9+
private final String imageUrl;
10+
private final String diffUrl;
11+
private final String baselineUrl;
12+
13+
public TestRunResult(TestRunResponse testRunResponse, PathProvider pathProvider) {
14+
this.testRunResponse = testRunResponse;
15+
this.imageUrl = pathProvider.getImageUrl(testRunResponse.getImageName());
16+
this.diffUrl = pathProvider.getImageUrl(testRunResponse.getDiffName());
17+
this.baselineUrl = pathProvider.getImageUrl(testRunResponse.getBaselineName());
18+
}
19+
}

src/main/java/io/visual_regression_tracker/sdk_java/VisualRegressionTracker.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void stop() throws IOException {
8484
log.info("Visual Regression Tracker is stopped for buildId <{}>", buildId);
8585
}
8686

87-
public void track(String name, String imageBase64, TestRunOptions testRunOptions)
87+
public TestRunResult track(String name, String imageBase64, TestRunOptions testRunOptions)
8888
throws IOException {
8989
log.info("Tracking test run <{}> with options <{}> for buildId <{}>", name, testRunOptions, buildId);
9090
TestRunResponse testResultDTO = submitTestRun(name, imageBase64, testRunOptions);
@@ -109,10 +109,12 @@ public void track(String name, String imageBase64, TestRunOptions testRunOptions
109109
throw new TestRunException(errorMessage);
110110
}
111111
}
112+
113+
return new TestRunResult(testResultDTO, this.paths);
112114
}
113115

114-
public void track(String name, String imageBase64) throws IOException {
115-
track(name, imageBase64, TestRunOptions.builder().build());
116+
public TestRunResult track(String name, String imageBase64) throws IOException {
117+
return track(name, imageBase64, TestRunOptions.builder().build());
116118
}
117119

118120
protected boolean isStarted() {

src/main/java/io/visual_regression_tracker/sdk_java/response/TestRunResponse.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
@Getter
88
@Builder
99
public class TestRunResponse {
10+
private final String id;
11+
private final String imageName;
12+
private final String diffName;
13+
private final String baselineName;
14+
private final Float diffPercent;
15+
private final Float diffTollerancePercent;
16+
private final Integer pixelMisMatchCount;
17+
private final Boolean merge;
1018
private final String url;
1119
private final TestRunStatus status;
1220
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package io.visual_regression_tracker.sdk_java;
2+
3+
import org.testng.annotations.BeforeMethod;
4+
import org.testng.annotations.DataProvider;
5+
import org.testng.annotations.Test;
6+
7+
import static org.hamcrest.CoreMatchers.is;
8+
import static org.hamcrest.MatcherAssert.assertThat;
9+
10+
public class PathProviderTest {
11+
12+
private final String apiUrl = "http://localhost:4200";
13+
private PathProvider pathProvider;
14+
15+
@BeforeMethod()
16+
public void setUp() {
17+
pathProvider = new PathProvider(apiUrl);
18+
}
19+
20+
@DataProvider(name = "shouldGetImageUrlCases")
21+
public Object[][] shouldGetImageUrlCases() {
22+
return new Object[][] {
23+
{null, null}, {"", null}, {"some", apiUrl.concat("/some")},
24+
};
25+
}
26+
27+
@Test(dataProvider = "shouldGetImageUrlCases")
28+
public void shouldGetImageUrl(String imageName, String expectedResult) {
29+
String result = pathProvider.getImageUrl(imageName);
30+
31+
assertThat(result, is(expectedResult));
32+
}
33+
}

src/test/java/io/visual_regression_tracker/sdk_java/VisualRegressionTrackerTest.java

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package io.visual_regression_tracker.sdk_java;
22

3-
import java.io.IOException;
4-
import java.util.Objects;
5-
63
import com.google.gson.Gson;
74
import io.visual_regression_tracker.sdk_java.request.BuildRequest;
85
import io.visual_regression_tracker.sdk_java.request.TestRunRequest;
@@ -24,6 +21,9 @@
2421
import org.testng.annotations.DataProvider;
2522
import org.testng.annotations.Test;
2623

24+
import java.io.IOException;
25+
import java.util.Objects;
26+
2727
import static org.hamcrest.CoreMatchers.containsString;
2828
import static org.hamcrest.CoreMatchers.is;
2929
import static org.hamcrest.MatcherAssert.assertThat;
@@ -34,6 +34,7 @@
3434
import static org.mockito.Mockito.reset;
3535
import static org.mockito.Mockito.verify;
3636
import static org.mockito.Mockito.when;
37+
import static org.mockito.Mockito.times;
3738

3839
public class VisualRegressionTrackerTest {
3940

@@ -67,6 +68,7 @@ public void setup() {
6768
this.config.setApiUrl(server.url("/").toString());
6869
vrt = new VisualRegressionTracker(config);
6970
vrtMocked = mock(VisualRegressionTracker.class);
71+
vrtMocked.paths = new PathProvider("baseApiUrl");
7072
}
7173

7274
@SneakyThrows
@@ -175,13 +177,19 @@ public Object[][] trackErrorCases() {
175177
{
176178
TestRunResponse.builder()
177179
.url("https://someurl.com/test/123123")
180+
.imageName("imageName")
181+
.baselineName("baselineName")
182+
.diffName("diffName")
178183
.status(TestRunStatus.UNRESOLVED)
179184
.build(),
180185
"Difference found: https://someurl.com/test/123123"
181186
},
182187
{
183188
TestRunResponse.builder()
184189
.url("https://someurl.com/test/123123")
190+
.imageName("imageName")
191+
.baselineName("baselineName")
192+
.diffName("diffName")
185193
.status(TestRunStatus.NEW)
186194
.build(),
187195
"No baseline: https://someurl.com/test/123123"
@@ -214,30 +222,44 @@ public void trackShouldLogSevere(TestRunResponse testRunResponse, String expecte
214222

215223
@DataProvider(name = "shouldTrackPassCases")
216224
public Object[][] shouldTrackPassCases() {
217-
return new Object[][] {
218-
{
219-
TestRunResponse.builder()
220-
.url("https://someurl.com/test/123123")
221-
.status(TestRunStatus.OK)
222-
.build(),
223-
}
225+
return new Object[][] {
226+
{
227+
TestRunResponse.builder()
228+
.id("someId")
229+
.imageName("imageName")
230+
.baselineName("baselineName")
231+
.diffName("diffName")
232+
.diffPercent(12.32f)
233+
.diffTollerancePercent(0.01f)
234+
.pixelMisMatchCount(1)
235+
.merge(false)
236+
.url("https://someurl.com/test/123123")
237+
.status(TestRunStatus.OK)
238+
.build(),
239+
}
224240
};
225241
}
226242

227243
@Test(dataProvider = "shouldTrackPassCases")
228244
public void shouldTrackPass(TestRunResponse testRunResponse) throws IOException {
229245
when(vrtMocked.submitTestRun(anyString(), anyString(), any())).thenReturn(testRunResponse);
246+
vrtMocked.paths = new PathProvider("backendUrl");
230247

231248
doCallRealMethod().when(vrtMocked).track(anyString(), anyString(), any());
232-
vrtMocked.track("name", "image", TestRunOptions.builder().build());
249+
TestRunResult testRunResult = vrtMocked.track("name", "image", TestRunOptions.builder().build());
250+
251+
assertThat(testRunResult.getTestRunResponse(), is(testRunResponse));
252+
assertThat(testRunResult.getImageUrl(), is("backendUrl/".concat(testRunResponse.getImageName())));
253+
assertThat(testRunResult.getDiffUrl(), is("backendUrl/".concat(testRunResponse.getDiffName())));
254+
assertThat(testRunResult.getBaselineUrl(), is("backendUrl/".concat(testRunResponse.getBaselineName())));
233255
}
234256

235257
@Test()
236258
public void shouldTrackOverload() throws IOException {
237259
doCallRealMethod().when(vrtMocked).track(anyString(), anyString());
238260
vrtMocked.track("name", "image");
239261

240-
verify(vrtMocked, Mockito.times(1)).track(anyString(), anyString(), any(TestRunOptions.class));
262+
verify(vrtMocked, times(1)).track(anyString(), anyString(), any(TestRunOptions.class));
241263
}
242264

243265
@DataProvider(name = "shouldReturnIsStartedCases")

0 commit comments

Comments
 (0)