Skip to content

Commit

Permalink
Fix codestyle
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanNemeth committed Feb 14, 2025
1 parent c23832b commit 6f4a61b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.tum.cit.aet.helios.tests;

import de.tum.cit.aet.helios.github.GitHubService;
import de.tum.cit.aet.helios.tests.parsers.JUnitParser;
import de.tum.cit.aet.helios.tests.parsers.JunitParser;
import de.tum.cit.aet.helios.tests.parsers.TestParserResult;
import de.tum.cit.aet.helios.workflow.WorkflowRun;
import de.tum.cit.aet.helios.workflow.WorkflowRunRepository;
Expand All @@ -24,22 +24,25 @@ public class TestResultProcessor {
private final GitHubService gitHubService;
private final WorkflowRunRepository workflowRunRepository;
private final TestResultRepository testResultRepository;
private final JUnitParser junitParser;
private final JunitParser junitParser;

@Value("${tests.artifactName:Test Results}")
private String testArtifactName;

public void processRun(long workflowRunId) {
final WorkflowRun workflowRun = this.workflowRunRepository.findById(workflowRunId)
.orElseThrow(() -> new TestResultException("Workflow run not found"));
final WorkflowRun workflowRun =
this.workflowRunRepository
.findById(workflowRunId)
.orElseThrow(() -> new TestResultException("Workflow run not found"));

log.debug("Processing test results for workflow run {}", workflowRunId);

GHArtifact testResultsArtifact = null;

try {
PagedIterable<GHArtifact> artifacts = this.gitHubService.getWorkflowRunArtifacts(
workflowRun.getRepository().getRepositoryId(), workflowRunId);
PagedIterable<GHArtifact> artifacts =
this.gitHubService.getWorkflowRunArtifacts(
workflowRun.getRepository().getRepositoryId(), workflowRunId);

// Traverse page iterable to find the first artifact with the configured name
for (GHArtifact artifact : artifacts) {
Expand Down Expand Up @@ -68,39 +71,41 @@ public void processRun(long workflowRunId) {

log.debug("Parsed {} test results. Persisting...", results.size());

results.forEach(result -> {
final TestResult testResult = new TestResult();
testResult.setWorkflowRun(workflowRun);
testResult.setTotal(result.total());
testResult.setPassed(result.passed());
testResult.setFailures(result.failures());
testResult.setErrors(result.errors());
testResult.setSkipped(result.skipped());
testResultRepository.save(testResult);
});
results.forEach(
result -> {
final TestResult testResult = new TestResult();
testResult.setWorkflowRun(workflowRun);
testResult.setTotal(result.total());
testResult.setPassed(result.passed());
testResult.setFailures(result.failures());
testResult.setErrors(result.errors());
testResult.setSkipped(result.skipped());
testResultRepository.save(testResult);
});

log.debug("Persisted test results");
}

private List<TestParserResult> processTestResultArtifact(GHArtifact artifact) throws IOException {
// Download the ZIP artifact, find all parsable XML files and parse them
return artifact.download(stream -> {
List<TestParserResult> results = new ArrayList<>();

try (ZipInputStream zipInput = new ZipInputStream(stream)) {
ZipEntry entry;

while ((entry = zipInput.getNextEntry()) != null) {
if (!entry.isDirectory()) {
if (this.junitParser.supports(entry.getName())) {
results.add(this.junitParser.parse(zipInput));
return artifact.download(
stream -> {
List<TestParserResult> results = new ArrayList<>();

try (ZipInputStream zipInput = new ZipInputStream(stream)) {
ZipEntry entry;

while ((entry = zipInput.getNextEntry()) != null) {
if (!entry.isDirectory()) {
if (this.junitParser.supports(entry.getName())) {
results.add(this.junitParser.parse(zipInput));
}
}
zipInput.closeEntry();
}
}
zipInput.closeEntry();
}
}

return results;
});
return results;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,15 @@

@Component
@Log4j2
public class JUnitParser implements TestResultParser {
public class JunitParser implements TestResultParser {
public TestParserResult parse(InputStream inputStream) {
try {
JAXBContext context = JAXBContext.newInstance(TestSuite.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
TestSuite suite = (TestSuite) unmarshaller.unmarshal(inputStream);

return new TestParserResult(
suite.tests,
suite.failures,
suite.errors,
suite.skipped,
suite.time);
suite.tests, suite.failures, suite.errors, suite.skipped, suite.time);
} catch (JAXBException e) {
throw new TestResultParseException("Failed to parse JUnit XML", e);
}
Expand All @@ -35,15 +31,10 @@ public boolean supports(String fileName) {

@XmlRootElement(name = "testsuite")
public static class TestSuite {
@XmlAttribute
public int tests;
@XmlAttribute
public int failures;
@XmlAttribute
public int errors;
@XmlAttribute
public int skipped;
@XmlAttribute
public double time;
@XmlAttribute public int tests;
@XmlAttribute public int failures;
@XmlAttribute public int errors;
@XmlAttribute public int skipped;
@XmlAttribute public double time;
}
}

0 comments on commit 6f4a61b

Please sign in to comment.