如何在Java中使用Rally Rest API获取TestSet ID?

时间:2012-10-10 12:32:37

标签: java rally

我使用以下代码来获取TestSet ID。但它没有给出任何结果

QueryRequest testsetRequest = new QueryRequest("Test Set");
testsetRequest.setFetch(new Fetch("FormattedID","Name"));
testsetRequest.setQueryFilter(new QueryFilter("TestSet.Name", "=", "TestSetName"));
QueryResponse testSetQueryResponse = restApi.query(testsetRequest);
System.out.println(String.format("\nTestSet:%d",testSetQueryResponse.getTotalResultCount()));
StringTestSetref=testSetQueryResponse.getResults().get(0).getAsJsonObject().get("_ref").toString();
System.out.println(TestSetref);

1 个答案:

答案 0 :(得分:1)

您的查询可能会收到错误消息。像这样的代码应该有效。 else子句还可以帮助您诊断在查询出现问题时会出现的错误。

QueryRequest testsetRequest = new QueryRequest("TestSet"); //no spaces
testsetRequest.setFetch(new Fetch("FormattedID","Name"));     

//No need to specify type again 
testsetRequest.setQueryFilter(new QueryFilter("Name", "=", "TestSetName")); 
QueryResponse testSetQueryResponse = restApi.query(testsetRequest);

if(testSetQueryResponse.wasSuccessful()) {
    for (JsonElement result : testSetQueryResponse.getResults()) {
        //handle results
    }
} else {
    //See what error occurred
    for (String err : testSetQueryResponse.getErrors()) {
        System.err.println("\t" + err);
    }
}