Search in sources :

Example 1 with TestRun

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;
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) StreamResult(javax.xml.transform.stream.StreamResult) StreamSource(javax.xml.transform.stream.StreamSource) ArrayList(java.util.ArrayList) JAXBContext(javax.xml.bind.JAXBContext) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.w3c.dom.Document) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) JAXBException(javax.xml.bind.JAXBException) ByteArrayInputStream(java.io.ByteArrayInputStream) DocumentBuilder(javax.xml.parsers.DocumentBuilder) TestRun(com.hp.octane.integrations.dto.tests.TestRun) Map(java.util.Map)

Example 2 with TestRun

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);
}
Also used : TestRun(com.hp.octane.integrations.dto.tests.TestRun) TestsResult(com.hp.octane.integrations.dto.tests.TestsResult) LinkedList(java.util.LinkedList)

Example 3 with TestRun

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);
}
Also used : TestRun(com.hp.octane.integrations.dto.tests.TestRun) TestRunError(com.hp.octane.integrations.dto.tests.TestRunError) TestRunResult(com.hp.octane.integrations.dto.tests.TestRunResult)

Aggregations

TestRun (com.hp.octane.integrations.dto.tests.TestRun)3 TestRunError (com.hp.octane.integrations.dto.tests.TestRunError)1 TestRunResult (com.hp.octane.integrations.dto.tests.TestRunResult)1 TestsResult (com.hp.octane.integrations.dto.tests.TestsResult)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 JAXBContext (javax.xml.bind.JAXBContext)1 JAXBException (javax.xml.bind.JAXBException)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)1 StreamResult (javax.xml.transform.stream.StreamResult)1 StreamSource (javax.xml.transform.stream.StreamSource)1 Document (org.w3c.dom.Document)1 InputSource (org.xml.sax.InputSource)1