Skip to content

Commit

Permalink
Reworked how Test Cycles are handled
Browse files Browse the repository at this point in the history
Re-used Cycles to support Test Plans and for better reporting
  • Loading branch information
Dmitry Mayer committed Aug 5, 2020
1 parent 3df7b01 commit f6c1718
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import retrofit2.http.POST;
import retrofit2.http.Part;
import retrofit2.http.Path;
import retrofit2.http.Query;

import java.util.List;

Expand All @@ -20,6 +21,10 @@ interface TM4JAPIClient {
@POST("testrun")
Call<TestRun> createTestRun(@Body TestRun body);

@Headers("Content-Type: application/json")
@GET("testrun/search")
Call<List<TestRun>> searchTestRun(@Query("query") String query);

@Headers("Content-Type: application/json")
@GET("testrun/{testRunKey}")
Call<TestRun> getTestRun(@Path("testRunKey") String testRunKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

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

@Log4j2
public class TM4JClient {
Expand All @@ -25,15 +27,15 @@ public TestRun createTestRun(String projectKey, String name) {
String testRunKey =
apiClient.createTestRun(testRun).execute().body().getKey();
testRun =
getTestRun(testRunKey);
getTestRunByKey(testRunKey);
return testRun;
} catch (IOException e) {
log.throwing(e);
return null;
}
}

public TestRun getTestRun(String testRunKey) {
public TestRun getTestRunByKey(String testRunKey) {
try {
return apiClient.getTestRun(testRunKey).execute().body();
} catch (IOException e) {
Expand All @@ -42,6 +44,20 @@ public TestRun getTestRun(String testRunKey) {
}
}

public Optional<TestRun> getTestRunByProjectKeyAndName(String projectKey, String testRunName) {
try {
String searchByProjectKeyQuery = String.format("projectKey = \"%s\"", projectKey);
List<TestRun> testRuns = apiClient.searchTestRun(searchByProjectKeyQuery).execute().body();
return Objects.requireNonNull(testRuns).stream()
.filter(t -> t.getProjectKey().equalsIgnoreCase(projectKey)
&& t.getName().equalsIgnoreCase(testRunName))
.findFirst();
} catch (IOException e) {
log.throwing(e);
return Optional.empty();
}
}

public void postResult(Execution execution) {
try {
apiClient.postExecution(execution).execute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.github.letsrokk.tm4j.client.TM4JClientFactory;
import com.github.letsrokk.tm4j.client.model.Execution;
import com.github.letsrokk.tm4j.client.model.ExecutionStatus;
import com.github.letsrokk.tm4j.client.model.TestRun;
import com.github.letsrokk.tm4j.testng.container.CustomExecutionContainer;
import com.github.letsrokk.tm4j.testng.container.CustomExecutionException;
import com.github.letsrokk.tm4j.testng.container.CustomSuiteContainer;
Expand Down Expand Up @@ -78,8 +77,11 @@ private void initSuiteContainer(String projectKey, String suiteName) {
.name(suiteName)
.build();

TestRun testRun = tm4jClient.createTestRun(suiteContainer.getProjectKey(), suiteContainer.getName());
suiteContainer.setTestRunKey(testRun.getKey());
String testRunKey = tm4jClient.getTestRunByProjectKeyAndName(projectKey, suiteName)
.orElseGet(() -> tm4jClient.createTestRun(suiteContainer.getProjectKey(), suiteContainer.getName()))
.getKey();

suiteContainer.setTestRunKey(testRunKey);
} else {
log.error("TM4J Project Key is not set");
suiteContainer = CustomSuiteContainer.builder()
Expand Down

0 comments on commit f6c1718

Please sign in to comment.