首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jobProgressToken: Jira (Zephyr) Rest

jobProgressToken: Jira (Zephyr) Rest
EN

Stack Overflow用户
提问于 2017-04-28 21:54:35
回答 1查看 868关注 0票数 0

我使用Jira (Zephyr) rest调用来创建测试周期,并在其中添加测试用例。根据提到的信息,here1,如果我使用rest调用添加测试循环,那么作为响应,我将得到JobProgressToken。JobProgressToken只会告诉测试周期中添加测试用例的进度。

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

有人能解释一下如何使用这个JobProgressToken来获得我任务的进展吗?我想确认一下,我添加到循环中的测试是否正确?

EN

回答 1

Stack Overflow用户

发布于 2017-06-23 12:13:00

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

用于检索作业进度的GET请求有以下形式:http://jira/rest/zapi/latest/execution/jobProgress/0001498157843923-5056b64fdb-0001,其中0001498157843923-5056b64fdb-0001是特定jobProgressToken的值。

由于某种异步操作而得到一个jobProgressToken后,我的代码正在等待进程变为1(它正在从0到1)。

代码语言:javascript
复制
    //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);
    }

}

这一切都很神奇:)

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

代码语言:javascript
复制
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
代码语言:javascript
复制
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

这不是该怎么做的问题。(这是关于我是如何工作的;)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43689413

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档