diff --git a/pom.xml b/pom.xml
index 36b3374..d5e656b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
com.nullin
testrail-integration
- 2.3.5-SNAPHSOT
+ 2.3.5-SNAPSHOT
pom
TestRail Integration
@@ -60,6 +60,19 @@
1.7
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+
+
+ attach-sources
+
+ jar
+
+
+
+
diff --git a/testrail-connector/pom.xml b/testrail-connector/pom.xml
index b647344..ab46fc1 100644
--- a/testrail-connector/pom.xml
+++ b/testrail-connector/pom.xml
@@ -5,7 +5,7 @@
com.nullin
testrail-integration
- 2.3.5-SNAPHSOT
+ 2.3.5-SNAPSHOT
testrail-connector
diff --git a/testrail-connector/src/main/java/com/nullin/testrail/TestRailReporter.java b/testrail-connector/src/main/java/com/nullin/testrail/TestRailReporter.java
index 627186a..e8fb8fc 100644
--- a/testrail-connector/src/main/java/com/nullin/testrail/TestRailReporter.java
+++ b/testrail-connector/src/main/java/com/nullin/testrail/TestRailReporter.java
@@ -13,6 +13,8 @@
import java.util.Set;
import java.util.logging.Logger;
+import org.apache.http.HttpException;
+
import com.nullin.testrail.client.ClientException;
import com.nullin.testrail.client.TestRailClient;
import com.nullin.testrail.dto.Case;
@@ -171,58 +173,77 @@ public void reportResult(String automationId, Map properties) {
if (!enabled) {
return; //do nothing
}
+
+ int retryCount = 5;
+
+ while (retryCount > 0) {
+ ResultStatus resultStatus = (ResultStatus)properties.get(KEY_STATUS);
+ Throwable throwable = (Throwable)properties.get(KEY_THROWABLE);
+ String elapsed = (String)properties.get(KEY_ELAPSED);
+ String screenshotUrl = (String)properties.get(KEY_SCREENSHOT_URL);
+ Map moreInfo = (Map)properties.get(KEY_MORE_INFO);
+
+ try {
+ Integer caseId = caseIdLookupMap.get(automationId);
+ if (caseId == null) {
+ logger.severe("Didn't find case id for test with automation id " + automationId);
+ return; //nothing more to do
+ }
+
+ StringBuilder comment = new StringBuilder("More Info (if any):\n");
+ if (moreInfo != null && !moreInfo.isEmpty()) {
+ for (Map.Entry entry: moreInfo.entrySet()) {
+ comment.append("- ").append(entry.getKey()).append(" : ")
+ .append('`').append(entry.getValue()).append("`\n");
+ }
+ } else {
+ comment.append("- `none`\n");
+ }
+ comment.append("\n");
+ if (screenshotUrl != null && !screenshotUrl.isEmpty()) {
+ comment.append("![](").append(screenshotUrl).append(")\n\n");
+ }
+ if (resultStatus.equals(ResultStatus.SKIP)) {
+ comment.append("Test skipped because of configuration method failure. " +
+ "Related config error (if captured): \n\n");
+ comment.append(getStackTraceAsString(throwable));
+ }
+ if (resultStatus.equals(ResultStatus.FAIL)) {
+ comment.append("Test failed with following exception (if captured): \n\n");
+ comment.append(getStackTraceAsString(throwable));
+ }
+
+ //add the result
+ Map body = new HashMap();
+ body.put("status_id", getStatus(resultStatus));
+ body.put("comment", new String(comment.toString().getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8));
+ body.put("elapsed", elapsed);
+
+ Integer runId = testToRunIdMap.get(automationId + config);
+ if (runId == null) {
+ throw new IllegalArgumentException("Unable to find run id for test with automation id "
+ + automationId + " and configuration set as " + config);
+ }
+ client.addResultForCase(runId, caseId, body);
+
+ retryCount = 0;
+ } catch(Exception ex) {
+ if (ex.getMessage().contains("Received status code 409 with content")) {
+ logger.warning("Maintenance mode, sleep 1 second and retry: " + ex.getMessage());
+ retryCount--;
- ResultStatus resultStatus = (ResultStatus)properties.get(KEY_STATUS);
- Throwable throwable = (Throwable)properties.get(KEY_THROWABLE);
- String elapsed = (String)properties.get(KEY_ELAPSED);
- String screenshotUrl = (String)properties.get(KEY_SCREENSHOT_URL);
- Map moreInfo = (Map)properties.get(KEY_MORE_INFO);
-
- try {
- Integer caseId = caseIdLookupMap.get(automationId);
- if (caseId == null) {
- logger.severe("Didn't find case id for test with automation id " + automationId);
- return; //nothing more to do
- }
-
- StringBuilder comment = new StringBuilder("More Info (if any):\n");
- if (moreInfo != null && !moreInfo.isEmpty()) {
- for (Map.Entry entry: moreInfo.entrySet()) {
- comment.append("- ").append(entry.getKey()).append(" : ")
- .append('`').append(entry.getValue()).append("`\n");
- }
- } else {
- comment.append("- `none`\n");
- }
- comment.append("\n");
- if (screenshotUrl != null && !screenshotUrl.isEmpty()) {
- comment.append("![](").append(screenshotUrl).append(")\n\n");
- }
- if (resultStatus.equals(ResultStatus.SKIP)) {
- comment.append("Test skipped because of configuration method failure. " +
- "Related config error (if captured): \n\n");
- comment.append(getStackTraceAsString(throwable));
- }
- if (resultStatus.equals(ResultStatus.FAIL)) {
- comment.append("Test failed with following exception (if captured): \n\n");
- comment.append(getStackTraceAsString(throwable));
- }
-
- //add the result
- Map body = new HashMap();
- body.put("status_id", getStatus(resultStatus));
- body.put("comment", new String(comment.toString().getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8));
- body.put("elapsed", elapsed);
-
- Integer runId = testToRunIdMap.get(automationId + config);
- if (runId == null) {
- throw new IllegalArgumentException("Unable to find run id for test with automation id "
- + automationId + " and configuration set as " + config);
- }
- client.addResultForCase(runId, caseId, body);
- } catch(Exception ex) {
- //only log and do nothing else
- logger.severe("Ran into exception " + ex.getMessage());
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ }
+
+ } else {
+ //only log and do nothing else
+ logger.severe("Ran into exception " + ex.getMessage());
+
+ retryCount = 0;
+ }
+ }
}
}
diff --git a/testrail-connector/src/main/java/com/nullin/testrail/client/TestRailClient.java b/testrail-connector/src/main/java/com/nullin/testrail/client/TestRailClient.java
index af7915e..03fbd1b 100644
--- a/testrail-connector/src/main/java/com/nullin/testrail/client/TestRailClient.java
+++ b/testrail-connector/src/main/java/com/nullin/testrail/client/TestRailClient.java
@@ -1,16 +1,20 @@
package com.nullin.testrail.client;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.apache.commons.codec.binary.StringUtils;
+
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.nullin.testrail.dto.Case;
+import com.nullin.testrail.dto.CaseList;
import com.nullin.testrail.dto.Milestone;
import com.nullin.testrail.dto.Plan;
import com.nullin.testrail.dto.PlanEntry;
@@ -19,6 +23,7 @@
import com.nullin.testrail.dto.Section;
import com.nullin.testrail.dto.Suite;
import com.nullin.testrail.dto.Test;
+import com.nullin.testrail.dto.TestList;
/**
* TestRail Client for endpoints described at
@@ -156,7 +161,23 @@ public Test getTest(int testId) throws IOException, ClientException {
}
public List getTests(int runId) throws IOException, ClientException {
- return objectMapper.readValue(client.invokeHttpGet("get_tests/" + runId), new TypeReference>(){});
+ List result = new ArrayList<>();
+ String url = "get_tests/" + runId;
+
+ while (url != null) {
+ TestList testList = objectMapper.readValue(client.invokeHttpGet(url), TestList.class);
+
+ if (testList != null && testList._links.next != null) {
+
+ result.addAll(testList.tests);
+
+ url = testList._links.next.replace("/api/v2", "");
+ } else {
+ break;
+ }
+ }
+
+ return result;
}
/*
@@ -193,7 +214,21 @@ public List getCases(int projectId, int suiteId, int sectionId, Map>(){});
+
+ List result = new ArrayList<>();
+ while (url != null) {
+ CaseList caseList = objectMapper.readValue(client.invokeHttpGet(url), CaseList.class);
+
+ if (caseList != null && caseList._links.next != null) {
+ result.addAll(caseList.cases);
+
+ url = caseList._links.next.replace("/api/v2", "");
+ } else {
+ break;
+ }
+ }
+
+ return result;
}
/**
diff --git a/testrail-connector/src/main/java/com/nullin/testrail/dto/CaseList.java b/testrail-connector/src/main/java/com/nullin/testrail/dto/CaseList.java
new file mode 100644
index 0000000..6181732
--- /dev/null
+++ b/testrail-connector/src/main/java/com/nullin/testrail/dto/CaseList.java
@@ -0,0 +1,7 @@
+package com.nullin.testrail.dto;
+
+import java.util.List;
+
+public class CaseList extends ResultList {
+ public List cases;
+}
diff --git a/testrail-connector/src/main/java/com/nullin/testrail/dto/Links.java b/testrail-connector/src/main/java/com/nullin/testrail/dto/Links.java
new file mode 100644
index 0000000..2122ce7
--- /dev/null
+++ b/testrail-connector/src/main/java/com/nullin/testrail/dto/Links.java
@@ -0,0 +1,6 @@
+package com.nullin.testrail.dto;
+
+public class Links {
+ public String next;
+ public String prev;
+}
diff --git a/testrail-connector/src/main/java/com/nullin/testrail/dto/ResultList.java b/testrail-connector/src/main/java/com/nullin/testrail/dto/ResultList.java
new file mode 100644
index 0000000..0d1a813
--- /dev/null
+++ b/testrail-connector/src/main/java/com/nullin/testrail/dto/ResultList.java
@@ -0,0 +1,8 @@
+package com.nullin.testrail.dto;
+
+public class ResultList {
+ public int offset;
+ public int limit;
+ public int size;
+ public Links _links;
+}
diff --git a/testrail-connector/src/main/java/com/nullin/testrail/dto/TestList.java b/testrail-connector/src/main/java/com/nullin/testrail/dto/TestList.java
new file mode 100644
index 0000000..36e40d5
--- /dev/null
+++ b/testrail-connector/src/main/java/com/nullin/testrail/dto/TestList.java
@@ -0,0 +1,7 @@
+package com.nullin.testrail.dto;
+
+import java.util.List;
+
+public class TestList extends ResultList {
+ public List tests;
+}