Search in sources :

Example 1 with SubmittedException

use of com.qasymphony.ci.plugin.exception.SubmittedException in project jenkin-qtest-plugin by QASymphony.

the class TestResultFromxUnit method testParser.

@LocalData
@Test
public void testParser() throws InterruptedException, ExecutionException, TimeoutException, IOException {
    project = j.createFreeStyleProject("xunit-project");
    Configuration configuration = Configuration.newInstance();
    configuration.setReadFromJenkins(true);
    configuration.setProjectName("TestResultFromxUnitProject");
    // configuration.setAppSecretKey("34428172-cdba-4c97-aefb-b2ee5ae5db99");
    configuration.setAppSecretKey("5d65f50e-b368-47a1-9bff-e0a710011a3f");
    configuration.setReleaseId(1L);
    configuration.setId(1L);
    configuration.setProjectId(1L);
    configuration.setUrl("https://localhost:7443");
    configuration.setJenkinsProjectName("TestResultFromxUnitProject");
    configuration.setJenkinsServerUrl("http://localhost:8080/jenkins");
    TestResultFromxUnitProject testResultFromxUnitProject = new TestResultFromxUnitProject(configuration);
    configuration.setResultPattern("*.xml");
    project.getBuildersList().add(testResultFromxUnitProject);
    FreeStyleBuild build = project.scheduleBuild2(0).get(100, TimeUnit.MINUTES);
    assertNotNull("", testResultFromxUnitProject.getAutomationTestResultList());
    assertNotNull("Build is: ", build);
    String buildNumber = "1";
    String buildPath = "/jobs/TestResultFromxUnitProject/" + buildNumber;
    JunitSubmitterRequest submitterRequest = configuration.createJunitSubmitRequest();
    try {
        AutomationTestService.push(buildNumber, buildPath, testResultFromxUnitProject.getAutomationTestResultList(), submitterRequest, configuration.getAppSecretKey());
    } catch (SubmittedException e) {
        e.printStackTrace();
    }
}
Also used : SubmittedException(com.qasymphony.ci.plugin.exception.SubmittedException) Configuration(com.qasymphony.ci.plugin.model.Configuration) FreeStyleBuild(hudson.model.FreeStyleBuild) JunitSubmitterRequest(com.qasymphony.ci.plugin.submitter.JunitSubmitterRequest) LocalData(org.jvnet.hudson.test.recipes.LocalData) Test(org.junit.Test)

Example 2 with SubmittedException

use of com.qasymphony.ci.plugin.exception.SubmittedException in project jenkin-qtest-plugin by QASymphony.

the class PushingResultAction method submitTestResult.

private JunitSubmitterResult submitTestResult(JunitSubmitterRequest submitterRequest, AbstractBuild build, BuildListener listener, JunitSubmitter junitSubmitter, List<AutomationTestResult> automationTestResults) {
    PrintStream logger = listener.getLogger();
    JunitSubmitterResult result = null;
    LoggerUtils.formatInfo(logger, "Begin submit test results to qTest at: " + JsonUtils.getCurrentDateString());
    long start = System.currentTimeMillis();
    try {
        result = junitSubmitter.submit(submitterRequest);
    } catch (SubmittedException e) {
        LoggerUtils.formatError(logger, "Cannot submit test results to qTest:");
        LoggerUtils.formatError(logger, "   status code: " + e.getStatus());
        LoggerUtils.formatError(logger, "   error: " + e.getMessage());
    } catch (Exception e) {
        LoggerUtils.formatError(logger, "Cannot submit test results to qTest:");
        LoggerUtils.formatError(logger, "   error: " + e.getMessage());
    } finally {
        if (null == result) {
            result = new JunitSubmitterResult().setTestSuiteId(null).setSubmittedStatus(JunitSubmitterResult.STATUS_FAILED).setNumberOfTestResult(automationTestResults.size()).setNumberOfTestLog(0);
        }
        Boolean isSuccess = null != result.getTestSuiteId() && result.getTestSuiteId() > 0;
        LoggerUtils.formatHR(logger);
        LoggerUtils.formatInfo(logger, isSuccess ? "SUBMIT SUCCESS" : "SUBMIT FAILED");
        LoggerUtils.formatHR(logger);
        if (isSuccess) {
            LoggerUtils.formatInfo(logger, "   testLogs: %s", result.getNumberOfTestLog());
            LoggerUtils.formatInfo(logger, "   testSuite: name=%s, id=%s", result.getTestSuiteName(), result.getTestSuiteId());
            LoggerUtils.formatInfo(logger, "   link: %s", ConfigService.formatTestSuiteLink(configuration.getUrl(), configuration.getProjectId(), result.getTestSuiteId()));
        }
        LoggerUtils.formatInfo(logger, "Time elapsed: %s", LoggerUtils.elapsedTime(start));
        LoggerUtils.formatInfo(logger, "End submit test results to qTest at: %s", JsonUtils.getCurrentDateString());
        LoggerUtils.formatInfo(logger, "");
    }
    return result;
}
Also used : SubmittedException(com.qasymphony.ci.plugin.exception.SubmittedException) PrintStream(java.io.PrintStream) JunitSubmitterResult(com.qasymphony.ci.plugin.submitter.JunitSubmitterResult) ServletException(javax.servlet.ServletException) SubmittedException(com.qasymphony.ci.plugin.exception.SubmittedException) IOException(java.io.IOException) StoreResultException(com.qasymphony.ci.plugin.exception.StoreResultException)

Example 3 with SubmittedException

use of com.qasymphony.ci.plugin.exception.SubmittedException in project jenkin-qtest-plugin by QASymphony.

the class JunitQtestSubmitterImpl method getTaskResponse.

private AutomationTestResponse getTaskResponse(JunitSubmitterRequest request, SubmittedTask task, Map<String, String> headers) throws SubmittedException {
    ResponseEntity responseEntity;
    try {
        // get task status
        responseEntity = AutomationTestService.getTaskStatus(request.getqTestURL(), task.getId(), headers);
    } catch (ClientRequestException e) {
        LoggerUtils.formatError(request.getListener().getLogger(), "Cannot get response of taskId: %s, error: %s", task.getId(), e.getMessage());
        throw new SubmittedException(e.getMessage(), -1);
    }
    LOG.info(String.format("project:%s, status:%s, body:%s", request.getJenkinsProjectName(), null == responseEntity ? -1 : responseEntity.getStatusCode(), null == responseEntity ? "" : responseEntity.getBody()));
    if ((null == responseEntity) || (responseEntity.getStatusCode() != HttpStatus.SC_OK)) {
        throw new SubmittedException(ConfigService.getErrorMessage(responseEntity.getBody()), responseEntity.getStatusCode());
    }
    return new AutomationTestResponse(responseEntity.getBody());
}
Also used : SubmittedException(com.qasymphony.ci.plugin.exception.SubmittedException) ResponseEntity(com.qasymphony.ci.plugin.utils.ResponseEntity) AutomationTestResponse(com.qasymphony.ci.plugin.model.AutomationTestResponse) ClientRequestException(com.qasymphony.ci.plugin.utils.ClientRequestException)

Example 4 with SubmittedException

use of com.qasymphony.ci.plugin.exception.SubmittedException in project jenkin-qtest-plugin by QASymphony.

the class JunitQtestSubmitterImpl method submit.

@Override
public JunitSubmitterResult submit(JunitSubmitterRequest request) throws Exception {
    String accessToken = OauthProvider.getAccessToken(request.getqTestURL(), request.getApiKey());
    if (StringUtils.isEmpty(accessToken))
        throw new SubmittedException(String.format("Cannot get access token from: %s, API key is: %s", request.getqTestURL(), request.getApiKey()));
    ResponseEntity responseEntity = AutomationTestService.push(request.getBuildNumber(), request.getBuildPath(), request.getTestResults(), request, accessToken);
    AutomationTestResponse response = null;
    if (responseEntity.getStatusCode() == HttpStatus.SC_CREATED) {
        // receive task response
        SubmittedTask task = JsonUtils.fromJson(responseEntity.getBody(), SubmittedTask.class);
        if (task == null || task.getId() <= 0)
            throw new SubmittedException(responseEntity.getBody(), responseEntity.getStatusCode());
        response = getSubmitLogResponse(request, task);
    } else {
        // if cannot passed validation from qTest
        throw new SubmittedException(ConfigService.getErrorMessage(responseEntity.getBody()), responseEntity.getStatusCode());
    }
    Boolean nullResponse = (null == response);
    Boolean isSubmitSuccess = ((!nullResponse && response.getTestSuiteId() > 0) ? true : false);
    JunitSubmitterResult result = new JunitSubmitterResult().setNumberOfTestResult(request.getTestResults().size()).setTestSuiteId(nullResponse ? null : response.getTestSuiteId()).setTestSuiteName(nullResponse ? "" : response.getTestSuiteName()).setNumberOfTestLog(nullResponse ? 0 : response.getTotalTestLogs()).setSubmittedStatus(isSubmitSuccess ? JunitSubmitterResult.STATUS_SUCCESS : JunitSubmitterResult.STATUS_FAILED);
    return result;
}
Also used : SubmittedException(com.qasymphony.ci.plugin.exception.SubmittedException) ResponseEntity(com.qasymphony.ci.plugin.utils.ResponseEntity) AutomationTestResponse(com.qasymphony.ci.plugin.model.AutomationTestResponse) SubmittedTask(com.qasymphony.ci.plugin.model.qtest.SubmittedTask)

Example 5 with SubmittedException

use of com.qasymphony.ci.plugin.exception.SubmittedException in project jenkin-qtest-plugin by QASymphony.

the class AutomationTestService method push.

public static ResponseEntity push(String buildNumber, String buildPath, List<AutomationTestResult> testResults, JunitSubmitterRequest request, String accessToken) throws SubmittedException {
    if (testResults.size() <= 0)
        return null;
    String url;
    AutomationTestResultWrapper wrapper = new AutomationTestResultWrapper();
    wrapper.setBuildNumber(buildNumber);
    wrapper.setBuildPath(buildPath);
    wrapper.setSkipCreatingAutomationModule(true);
    Long moduleId = request.getModuleID();
    if (null != moduleId && 0 < moduleId) {
        wrapper.setParent_module(moduleId);
    }
    if (request.getSubmitToExistingContainer()) {
        String fullURL = request.getJenkinsServerURL();
        if (!fullURL.endsWith("/")) {
            fullURL += "/";
        }
        fullURL += buildPath;
        for (int i = 0; i < testResults.size(); i++) {
            AutomationTestResult result = testResults.get(i);
            result.setBuildNumber(buildNumber);
            result.setBuildURL(fullURL);
        }
        url = String.format(AUTO_TEST_LOG_ENDPOINT_V3_1, request.getqTestURL(), request.getProjectID(), 0);
        Long testSuiteId = prepareTestSuite(request, accessToken);
        if (-1 == testSuiteId) {
            throw new SubmittedException("Could not find or create test suite to submit test logs", -1);
        }
        wrapper.setTest_suite(testSuiteId);
        wrapper.setTest_logs(testResults);
    } else {
        /**
         * using {@link String#format(Locale, String, Object...)}  instead {@link java.text.MessageFormat#format(String, Object...)}
         * to avoid unexpected formatted link. see: QTE-2798 for more details.
         */
        url = String.format(AUTO_TEST_LOG_ENDPOINT_V3, request.getqTestURL(), request.getProjectID(), 0, request.getConfigurationID());
        wrapper.setTestResults(testResults);
    }
    Map<String, String> headers = OauthProvider.buildHeaders(accessToken, null);
    ResponseEntity responseEntity = null;
    try {
        String data = JsonUtils.toJson(wrapper);
        responseEntity = HttpClientUtils.post(url, headers, data);
    } catch (ClientRequestException e) {
        throw new SubmittedException(e.getMessage(), null == responseEntity ? 0 : responseEntity.getStatusCode());
    }
    return responseEntity;
}
Also used : SubmittedException(com.qasymphony.ci.plugin.exception.SubmittedException) AutomationTestResultWrapper(com.qasymphony.ci.plugin.model.AutomationTestResultWrapper) AutomationTestResult(com.qasymphony.ci.plugin.model.AutomationTestResult) ResponseEntity(com.qasymphony.ci.plugin.utils.ResponseEntity) ClientRequestException(com.qasymphony.ci.plugin.utils.ClientRequestException)

Aggregations

SubmittedException (com.qasymphony.ci.plugin.exception.SubmittedException)5 ResponseEntity (com.qasymphony.ci.plugin.utils.ResponseEntity)3 AutomationTestResponse (com.qasymphony.ci.plugin.model.AutomationTestResponse)2 ClientRequestException (com.qasymphony.ci.plugin.utils.ClientRequestException)2 StoreResultException (com.qasymphony.ci.plugin.exception.StoreResultException)1 AutomationTestResult (com.qasymphony.ci.plugin.model.AutomationTestResult)1 AutomationTestResultWrapper (com.qasymphony.ci.plugin.model.AutomationTestResultWrapper)1 Configuration (com.qasymphony.ci.plugin.model.Configuration)1 SubmittedTask (com.qasymphony.ci.plugin.model.qtest.SubmittedTask)1 JunitSubmitterRequest (com.qasymphony.ci.plugin.submitter.JunitSubmitterRequest)1 JunitSubmitterResult (com.qasymphony.ci.plugin.submitter.JunitSubmitterResult)1 FreeStyleBuild (hudson.model.FreeStyleBuild)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 ServletException (javax.servlet.ServletException)1 Test (org.junit.Test)1 LocalData (org.jvnet.hudson.test.recipes.LocalData)1