use of com.hp.octane.integrations.dto.tests.TestRun in project octane-gitlab-service by MicroFocus.
the class JunitTestResultsProvider method createAndGetTestList.
public List<TestRun> createAndGetTestList(InputStream artifactFiles) {
List<TestRun> result = new ArrayList<>();
if (TestResultsHelper.isFilePatternExist(testResultsFilePattern)) {
try {
List<Map.Entry<String, ByteArrayInputStream>> artifacts = TestResultsHelper.extractArtifacts(artifactFiles, testResultsFilePattern);
JAXBContext jaxbContext = JAXBContext.newInstance(Testsuites.class);
for (Map.Entry<String, ByteArrayInputStream> artifact : artifacts) {
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setFeature("http://xml.org/sax/features/external-general-entities", false);
dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource(artifact.getValue()));
String rootTagName = doc.getDocumentElement().getTagName().toLowerCase();
artifact.getValue().reset();
switch(rootTagName) {
case "testsuites":
case "testsuite":
unmarshallAndAddToResults(result, jaxbContext, artifact.getValue());
break;
case "test-run":
case "test-results":
ByteArrayOutputStream os = new ByteArrayOutputStream();
nunitTransformer.transform(new StreamSource(artifact.getValue()), new StreamResult(os));
unmarshallAndAddToResults(result, jaxbContext, new ByteArrayInputStream(os.toByteArray()));
break;
default:
log.error(String.format("Artifact %s: unknown test result format that starts with the <%s> tag", artifact.getKey(), rootTagName));
break;
}
} catch (Exception e) {
log.warn("Failed to create a test result list based on the job artifact: " + artifact.getKey(), e);
}
}
} catch (Exception e) {
log.error("Failed to create a test list based on the job artifacts", e);
}
}
return result;
}
use of com.hp.octane.integrations.dto.tests.TestRun in project octane-ci-java-sdk by MicroFocus.
the class PluginServicesBasicFunctionalityTest method getTestsResult.
@Override
public InputStream getTestsResult(String jobId, String buildId) {
List<TestRun> testRuns = new LinkedList<>();
for (int i = 20; i > 0; i--) {
testRuns.add(dtoFactory.newDTO(TestRun.class).setModuleName("module").setClassName("class").setPackageName("package").setTestName("test").setDuration(1000).setResult(TestRunResult.FAILED));
}
TestsResult testsResult = dtoFactory.newDTO(TestsResult.class).setBuildContext(dtoFactory.newDTO(BuildContext.class).setJobId("job-a").setBuildId("1")).setTestRuns(testRuns);
return dtoFactory.dtoToXmlStream(testsResult);
}
use of com.hp.octane.integrations.dto.tests.TestRun in project octane-gitlab-service by MicroFocus.
the class JunitTestResultsProvider method addTestCase.
private void addTestCase(List<TestRun> result, Testsuite ts, Testcase tc) {
TestRunResult testResultStatus;
if (tc.getSkipped() != null && tc.getSkipped().trim().length() > 0) {
testResultStatus = TestRunResult.SKIPPED;
} else if (tc.getFailure().size() > 0) {
testResultStatus = TestRunResult.FAILED;
} else {
testResultStatus = TestRunResult.PASSED;
}
TestRun tr = dtoFactory.newDTO(TestRun.class).setModuleName("").setPackageName(ts.getPackage()).setClassName(tc.getClassname()).setTestName(tc.getName()).setResult(testResultStatus).setDuration(tc.getTime() != null ? Double.valueOf(tc.getTime()).longValue() * 1000 : 1);
if (tc.getError() != null && tc.getError().size() > 0) {
TestRunError error = dtoFactory.newDTO(TestRunError.class);
error.setErrorMessage(tc.getError().get(0).getMessage());
error.setErrorType(tc.getError().get(0).getType());
error.setStackTrace(tc.getError().get(0).getContent());
tr.setError(error);
} else if (tc.getFailure() != null && tc.getFailure().size() > 0) {
TestRunError error = dtoFactory.newDTO(TestRunError.class);
error.setErrorMessage(tc.getFailure().get(0).getMessage());
error.setErrorType(tc.getFailure().get(0).getType());
error.setStackTrace(tc.getFailure().get(0).getContent());
tr.setError(error);
}
result.add(tr);
}
Aggregations