简体   繁体   中英

QueryFilter does not work as expected

I have this code that stopped to work as expected. I am pretty sure that it worked at least one year ago, but not anymore. I am trying to check if defect was already open for the same test case and for the same build.

Any ideas? Was rest-api changed recenty?

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;
}

Defects have a TestCases collection, so there's no singular TestCase attribute on them - thus querying on a single TestCase ref as a query condition would not be expected to work.

You'll need to fetch the TestCases collection off the defect and loop through it to look for the ref of the matching TestCase. Something like the following:

    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());

        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM