summaryrefslogtreecommitdiffstats
path: root/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/TestReport.java
diff options
context:
space:
mode:
Diffstat (limited to 'vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/TestReport.java')
-rw-r--r--vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/TestReport.java66
1 files changed, 23 insertions, 43 deletions
diff --git a/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/TestReport.java b/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/TestReport.java
index 9a1200d0bf3..b3ca47e2480 100644
--- a/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/TestReport.java
+++ b/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/TestReport.java
@@ -1,13 +1,7 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.testrunner;
-import com.yahoo.exception.ExceptionUtils;
-import com.yahoo.slime.Cursor;
-import com.yahoo.slime.Slime;
-import com.yahoo.slime.SlimeUtils;
-import com.yahoo.yolean.Exceptions;
-
-import java.nio.charset.StandardCharsets;
+import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.logging.LogRecord;
@@ -16,15 +10,16 @@ import java.util.logging.LogRecord;
* @author mortent
*/
public class TestReport {
- private final long totalCount;
- private final long successCount;
- private final long failedCount;
- private final long ignoredCount;
- private final long abortedCount;
- private final List<Failure> failures;
- private final List<LogRecord> logLines;
-
- public TestReport(long totalCount, long successCount, long failedCount, long ignoredCount, long abortedCount, List<Failure> failures, List<LogRecord> logLines) {
+
+ final long totalCount;
+ final long successCount;
+ final long failedCount;
+ final long ignoredCount;
+ final long abortedCount;
+ final List<Failure> failures;
+ final List<LogRecord> logLines;
+
+ private TestReport(long totalCount, long successCount, long failedCount, long ignoredCount, long abortedCount, List<Failure> failures, List<LogRecord> logLines) {
this.totalCount = totalCount;
this.successCount = successCount;
this.failedCount = failedCount;
@@ -34,31 +29,6 @@ public class TestReport {
this.logLines = logLines;
}
- private void serializeFailure(Failure failure, Cursor slime) {
- var testIdentifier = failure.testId();
- slime.setString("testName", failure.testId());
- slime.setString("testError",failure.exception().getMessage());
- slime.setString("exception", ExceptionUtils.getStackTraceAsString(failure.exception()));
- }
-
- public String toJson() {
- var slime = new Slime();
- var root = slime.setObject();
- var summary = root.setObject("summary");
- summary.setLong("total", totalCount);
- summary.setLong("success", successCount);
- summary.setLong("failed", failedCount);
- summary.setLong("ignored", ignoredCount);
- summary.setLong("aborted", abortedCount);
- var failureRoot = summary.setArray("failures");
- this.failures.forEach(failure -> serializeFailure(failure, failureRoot.addObject()));
-
- var output = root.setArray("output");
- logLines.forEach(lr -> output.addString(lr.getMessage()));
-
- return Exceptions.uncheck(() -> new String(SlimeUtils.toJsonBytes(slime), StandardCharsets.UTF_8));
- }
-
public List<LogRecord> logLines() {
return logLines;
}
@@ -71,7 +41,9 @@ public class TestReport {
return new Builder();
}
+
public static class Builder {
+
private long totalCount;
private long successCount;
private long failedCount;
@@ -88,18 +60,22 @@ public class TestReport {
this.totalCount = totalCount;
return this;
}
+
public Builder withSuccessCount(long successCount) {
this.successCount = successCount;
return this;
}
+
public Builder withFailedCount(long failedCount) {
this.failedCount = failedCount;
return this;
}
+
public Builder withIgnoredCount(long ignoredCount) {
this.ignoredCount = ignoredCount;
return this;
}
+
public Builder withAbortedCount(long abortedCount) {
this.abortedCount = abortedCount;
return this;
@@ -110,12 +86,14 @@ public class TestReport {
return this;
}
- public Builder withLogs(List<LogRecord> logRecords) {
- this.logLines = logRecords;
+ public Builder withLogs(Collection<LogRecord> logRecords) {
+ this.logLines = List.copyOf(logRecords);
return this;
}
+
}
+
public static class Failure {
private final String testId;
private final Throwable exception;
@@ -132,5 +110,7 @@ public class TestReport {
public Throwable exception() {
return exception;
}
+
}
+
}