FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

130 test run result added by pashidlos · Pull Request #30 · Visual-Regression-Tracker/sdk-java · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .gradle  (1) .java  (6) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 1 addition & 1 deletion build.gradle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'io.visual-regression-tracker.sdk-java'
version '4.1.1'
version '4.3.0'

apply plugin: 'java'
apply plugin: 'jacoco'
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,11 @@ public String getBuildPathForBuild(String buildId) {
public String getTestRunPath() {
return baseApiUrl.concat(TEST_RUNS_PATH);
}

public String getImageUrl(String name) {
if(name == null || name.isEmpty()){
return null;
}
return baseApiUrl.concat("/").concat(name);
}
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.visual_regression_tracker.sdk_java;

import io.visual_regression_tracker.sdk_java.response.TestRunResponse;
import lombok.Getter;

@Getter
public class TestRunResult {
private final TestRunResponse testRunResponse;
private final String imageUrl;
private final String diffUrl;
private final String baselineUrl;

public TestRunResult(TestRunResponse testRunResponse, PathProvider pathProvider) {
this.testRunResponse = testRunResponse;
this.imageUrl = pathProvider.getImageUrl(testRunResponse.getImageName());
this.diffUrl = pathProvider.getImageUrl(testRunResponse.getDiffName());
this.baselineUrl = pathProvider.getImageUrl(testRunResponse.getBaselineName());
}
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void stop() throws IOException {
log.info("Visual Regression Tracker is stopped for buildId <{}>", buildId);
}

public void track(String name, String imageBase64, TestRunOptions testRunOptions)
public TestRunResult track(String name, String imageBase64, TestRunOptions testRunOptions)
throws IOException {
log.info("Tracking test run <{}> with options <{}> for buildId <{}>", name, testRunOptions, buildId);
TestRunResponse testResultDTO = submitTestRun(name, imageBase64, testRunOptions);
Expand All @@ -109,10 +109,12 @@ public void track(String name, String imageBase64, TestRunOptions testRunOptions
throw new TestRunException(errorMessage);
}
}

return new TestRunResult(testResultDTO, this.paths);
}

public void track(String name, String imageBase64) throws IOException {
track(name, imageBase64, TestRunOptions.builder().build());
public TestRunResult track(String name, String imageBase64) throws IOException {
return track(name, imageBase64, TestRunOptions.builder().build());
}

protected boolean isStarted() {
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
@Getter
@Builder
public class TestRunResponse {
private final String id;
private final String imageName;
private final String diffName;
private final String baselineName;
private final Float diffPercent;
private final Float diffTollerancePercent;
private final Integer pixelMisMatchCount;
private final Boolean merge;
private final String url;
private final TestRunStatus status;
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.visual_regression_tracker.sdk_java;

import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

public class PathProviderTest {

private final String apiUrl = "http://localhost:4200";
private PathProvider pathProvider;

@BeforeMethod()
public void setUp() {
pathProvider = new PathProvider(apiUrl);
}

@DataProvider(name = "shouldGetImageUrlCases")
public Object[][] shouldGetImageUrlCases() {
return new Object[][] {
{null, null}, {"", null}, {"some", apiUrl.concat("/some")},
};
}

@Test(dataProvider = "shouldGetImageUrlCases")
public void shouldGetImageUrl(String imageName, String expectedResult) {
String result = pathProvider.getImageUrl(imageName);

assertThat(result, is(expectedResult));
}
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package io.visual_regression_tracker.sdk_java;

import java.io.IOException;
import java.util.Objects;

import com.google.gson.Gson;
import io.visual_regression_tracker.sdk_java.request.BuildRequest;
import io.visual_regression_tracker.sdk_java.request.TestRunRequest;
Expand All @@ -24,6 +21,9 @@
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import java.io.IOException;
import java.util.Objects;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
Expand All @@ -34,6 +34,7 @@
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.times;

public class VisualRegressionTrackerTest {

Expand Down Expand Up @@ -67,6 +68,7 @@ public void setup() {
this.config.setApiUrl(server.url("/").toString());
vrt = new VisualRegressionTracker(config);
vrtMocked = mock(VisualRegressionTracker.class);
vrtMocked.paths = new PathProvider("baseApiUrl");
}

@SneakyThrows
Expand Down Expand Up @@ -175,13 +177,19 @@ public Object[][] trackErrorCases() {
{
TestRunResponse.builder()
.url("https://someurl.com/test/123123")
.imageName("imageName")
.baselineName("baselineName")
.diffName("diffName")
.status(TestRunStatus.UNRESOLVED)
.build(),
"Difference found: https://someurl.com/test/123123"
},
{
TestRunResponse.builder()
.url("https://someurl.com/test/123123")
.imageName("imageName")
.baselineName("baselineName")
.diffName("diffName")
.status(TestRunStatus.NEW)
.build(),
"No baseline: https://someurl.com/test/123123"
Expand Down Expand Up @@ -214,30 +222,44 @@ public void trackShouldLogSevere(TestRunResponse testRunResponse, String expecte

@DataProvider(name = "shouldTrackPassCases")
public Object[][] shouldTrackPassCases() {
return new Object[][] {
{
TestRunResponse.builder()
.url("https://someurl.com/test/123123")
.status(TestRunStatus.OK)
.build(),
}
return new Object[][] {
{
TestRunResponse.builder()
.id("someId")
.imageName("imageName")
.baselineName("baselineName")
.diffName("diffName")
.diffPercent(12.32f)
.diffTollerancePercent(0.01f)
.pixelMisMatchCount(1)
.merge(false)
.url("https://someurl.com/test/123123")
.status(TestRunStatus.OK)
.build(),
}
};
}

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

doCallRealMethod().when(vrtMocked).track(anyString(), anyString(), any());
vrtMocked.track("name", "image", TestRunOptions.builder().build());
TestRunResult testRunResult = vrtMocked.track("name", "image", TestRunOptions.builder().build());

assertThat(testRunResult.getTestRunResponse(), is(testRunResponse));
assertThat(testRunResult.getImageUrl(), is("backendUrl/".concat(testRunResponse.getImageName())));
assertThat(testRunResult.getDiffUrl(), is("backendUrl/".concat(testRunResponse.getDiffName())));
assertThat(testRunResult.getBaselineUrl(), is("backendUrl/".concat(testRunResponse.getBaselineName())));
}

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

verify(vrtMocked, Mockito.times(1)).track(anyString(), anyString(), any(TestRunOptions.class));
verify(vrtMocked, times(1)).track(anyString(), anyString(), any(TestRunOptions.class));
}

@DataProvider(name = "shouldReturnIsStartedCases")
Expand Down

Back | FazBrowse Home | New Git URL