QueryFilter无法按预期工作

时间:2015-05-05 22:46:41

标签: java rally

我有这个代码停止按预期工作。我很确定它至少在一年前有效,但现在不行了。我试图检查相同的测试用例和相同的构建是否已经打开了缺陷。

有什么想法吗? rest-api最近改变了吗?

private boolean isOldDefect(String refTestCase, String foundIn) throws IOException {

    boolean oldDefect = false;
    // Query for Test Case to associate later with new Defect
    QueryRequest defectRequest = new QueryRequest("defect");
    defectRequest.setFetch(new Fetch(RALLY_FormattedID, "Name", "FoundInBuild", RALLY_TestCase, "Owner"));
    defectRequest.setQueryFilter(new QueryFilter("FoundInBuild", "=", foundIn).and(new QueryFilter("TestCase",
            "=", refTestCase)));

    QueryResponse defQueryResponse = restApi.query(defectRequest);
    if (defQueryResponse.wasSuccessful()) {
        if (defQueryResponse.getResults().size() > 1) {
            oldDefect = true;
        }
    }
    return oldDefect;
}

1 个答案:

答案 0 :(得分:1)

缺陷有一个TestCases集合,因此它们没有单一的TestCase属性 - 因此查询单个TestCase ref作为查询条件将不会起作用。

您需要从缺陷中获取TestCases集合并循环遍历它以查找匹配的TestCase的ref。如下所示:

    String rallyURL = new String("https://rally1.rallydev.com");
    String wsapiVersion = new String("v2.0");
    String wsapiURL = new String(rallyURL + "/slm/webservice/" + wsapiVersion);
    ....
    // Fetch Test Cases collection
    QueryRequest testCasesRequest = new QueryRequest(defectJsonObject.getAsJsonObject("TestCases"));
    testCasesRequest.setFetch(new Fetch("Name", "FormattedID", "ObjectID"));

    // Query the TestCases collection
    JsonArray testCasesOfDefect = restApi.query(testCasesRequest).getResults();

    String myTestCaseRef = new String(wsapiURL + "/testcase/12345678910");

    for (int i=0; i<testCasesOfDefect.size(); i++) {
        if (testCasesOfDefect.get(i).getAsJsonObject().get("_ref").getAsString().equals(myTestCaseRef)) {
            System.out.println("Matching TestCase Found:");
            System.out.println(testCasesOfDefect.get(i).getAsJsonObject().get("_ref").getAsString());
            System.out.println("Name: " + testCasesOfDefect.get(i).getAsJsonObject().get("Name") + "; " + testCasesOfDefect.get(i).getAsJsonObject().get("FormattedID").getAsString());

        }
    }