0

我正在使用 Jira (Zephyr) 休息调用来创建测试周期并将测试用例添加到其中。根据此处提到的信息1,如果我使用此休息调用将测试添加到 Cycle,那么作为响应,我将获得 JobProgressToken。JobProgressToken 只不过是告诉测试周期中测试用例添加的进度。

现在我面临的问题是我没有从这个 JobProgressToken 获得任何输出。我尝试使用提到的格式触发 GET rest 调用,但我得到空响应。

有人可以解释一下如何使用这个 JobProgressToken 来获取我的任务进度吗?我想验证我添加到 Cycle 的测试是否成功添加?

4

1 回答 1

0

就在昨天,我遇到了同样的问题。ZAPI 文档确实令人困惑。我找到了以下解决方案:

获取作业进度的GET请求具有以下形式:http://jira/rest/zapi/latest/execution/jobProgress/0001498157843923-5056b64fdb-0001 其中0001498157843923-5056b64fdb-0001是特定 jobProgressToken 的值

由于某些异步操作而获得 jobProgressToken 后,我的代码正在等待进度变为 1(它从零上升到 1)

    //get the job progress token as a result of some async operation invocation
    String jobProgressToken = new JSONObject(zapiResponse).getString("jobProgressToken");
    waitAsyncJobToBeCompleted(jobProgressToken);


void waitAsyncJobToBeCompleted(String jobProgressToken) {
    double jobProgress;
    do {
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            LOG.error("Error while try to make the thread sleeping 500ms. " + e.getLocalizedMessage());
            e.printStackTrace();
        }
        jobProgress = getJobProgress(jobProgressToken);
    } while (Double.compare(jobProgress, 1) <0);

private double getJobProgress(String jobProgressToken) {
    URI uri = makeUriFromString(String.format(
            GET_GetJobProgress, //Get request pattern
            connectionParameters.getJiraUrl(),//host
            jobProgressToken)); //parameters

    HttpResponse response = executeHttpRequestWithResponse(new HttpGet(uri));
    String zapiResponse = null;
    try {
        zapiResponse = EntityUtils.toString(response.getEntity());
        LOG.trace("ZAPI RESPONSE: " + zapiResponse);
        EntityUtils.consumeQuietly(response.getEntity()); //cleanup the HTTP response
        double progress = new JSONObject(zapiResponse).getDouble("progress");
        LOG.debug("Job progress: " + progress);
        return progress;

    } catch (IOException e) {
        String err = String.format("Error while getting Zephyr API response: %s",
                e.getLocalizedMessage());
        LOG.fatal(err);
        throw new RestApiException(err, e);
    } catch (JSONException e) {
        String err = String.format("Error while retrieving the job progress from JSON: %s\n%s",
                zapiResponse, e.getLocalizedMessage());
        LOG.fatal(err);
        throw new RestApiException(err, e);
    }

}

这都是魔法:)

以下两个日志:第一个用于克隆测试周期,第二个用于删除

ZephyrClient.invokeHttpPost     - URI=http://jira/rest/zapi/latest/cycle JSON payload={"projectId": "13795","clonedCycleId": 2643,"name": "ZAPI client test","description": "Created With ZAPI client unit test","versionId": "-1"}
ZephyrClient.cloneTestCycle     - RESPONSE JSON: {"jobProgressToken":"0001498218783350-5056b64fdb-0001"}
ZephyrClient.executeHttpRequestWithResponse     - HTTP REQUEST: GET http://jira/rest/zapi/latest/execution/jobProgress/0001498218783350-5056b64fdb-0001 HTTP/1.1
ZephyrClient.executeHttpRequestWithResponse     - HTTP RESPONSE: HTTP/1.1 200 OK
ZephyrClient.getJobProgress     - ZAPI RESPONSE: {"timeTaken":"0 min, 1 sec","stepMessage":"","summaryMessage":"","errorMessage":"","progress":0.56,"message":"","stepLabel":"","stepMessages":[]}
ZephyrClient.getJobProgress     - Job progress: 0.56
ZephyrClient.executeHttpRequestWithResponse     - HTTP REQUEST: GET http://jira/rest/zapi/latest/execution/jobProgress/0001498218783350-5056b64fdb-0001 HTTP/1.1
ZephyrClient.executeHttpRequestWithResponse     - HTTP RESPONSE: HTTP/1.1 200 OK
ZephyrClient.getJobProgress     - ZAPI RESPONSE: {"timeTaken":"0 min, 1 sec","stepMessage":"","summaryMessage":"","errorMessage":"","progress":0.98,"message":"","stepLabel":"","stepMessages":[]}
ZephyrClient.getJobProgress     - Job progress: 0.98
ZephyrClient.executeHttpRequestWithResponse     - HTTP REQUEST: GET http://jira/rest/zapi/latest/execution/jobProgress/0001498218783350-5056b64fdb-0001 HTTP/1.1
ZephyrClient.executeHttpRequestWithResponse     - HTTP RESPONSE: HTTP/1.1 200 OK
ZephyrClient.getJobProgress     - ZAPI RESPONSE: {"timeTaken":"0 min, 2 sec","stepMessage":"","summaryMessage":"","errorMessage":"","progress":0.98,"message":"","stepLabel":"","stepMessages":[]}
ZephyrClient.getJobProgress     - Job progress: 0.98
ZephyrClient.executeHttpRequestWithResponse     - HTTP REQUEST: GET http://jira/rest/zapi/latest/execution/jobProgress/0001498218783350-5056b64fdb-0001 HTTP/1.1
ZephyrClient.executeHttpRequestWithResponse     - HTTP RESPONSE: HTTP/1.1 200 OK
ZephyrClient.getJobProgress     - ZAPI RESPONSE: {"timeTaken":"0 min, 3 sec","stepMessage":"","summaryMessage":"","errorMessage":"","progress":1.0,"message":"Cycle ZAPI client test created successfully.","stepLabel":"","stepMessages":[]}
ZephyrClient.getJobProgress     - Job progress: 1.0
ZephyrClient.executeHttpRequestWithResponse     - HTTP REQUEST: GET http://jira/rest/zapi/latest/cycle?projectId=13795&versionId=-1 HTTP/1.1
ZephyrClient.executeHttpRequestWithResponse     - HTTP RESPONSE: HTTP/1.1 200 OK

ZephyrClient.invokeHttpDelete   - URI=http://jira/rest/zapi/latest/cycle/2727
ZephyrClient.deleteTestCycle    - RESPONSE JSON: {"jobProgressToken":"0001498218815183-5056b64fdb-0001"}
ZephyrClient.executeHttpRequestWithResponse     - HTTP REQUEST: GET http://jira/rest/zapi/latest/execution/jobProgress/0001498218815183-5056b64fdb-0001 HTTP/1.1
ZephyrClient.executeHttpRequestWithResponse     - HTTP RESPONSE: HTTP/1.1 200 OK
ZephyrClient.getJobProgress     - ZAPI RESPONSE: {"timeTaken":"0 min, 0 sec","stepMessage":"","summaryMessage":"","errorMessage":"","progress":1.0,"message":"{\"success\":\"Cycle ZAPI client test успешно удален\"}","stepLabel":"","stepMessages":[]}
ZephyrClient.getJobProgress     - Job progress: 1.0
ZephyrClient.executeHttpRequestWithResponse     - HTTP REQUEST: GET http://jira/rest/zapi/latest/cycle?projectId=13795&versionId=-1 HTTP/1.1
ZephyrClient.executeHttpRequestWithResponse     - HTTP RESPONSE: HTTP/1.1 200 OK

PS这不是关于应该如何做的。这是关于它如何为我工作;)

于 2017-06-23T12:13:00.000 回答