我想用現有標籤更新Rally中的TestCase,但是我從服務器收到錯誤。 我的步驟是:使用Rally Java API更新帶標籤的TestCase時出錯
- 查找基於測試ID的測試用例,保持裁判和標籤對象
- 找到標記,保持基準
- 如果_tagsNameArray JSON數組不包含我的標籤,更新
- 發送更新反彈服務器
下面的代碼我有更新測試用例:
String tagref = getTagReference(tagname); //this is where I get the reference to the existing Tag
QueryRequest testCaseRequest = new QueryRequest("TestCase");
testCaseRequest.setFetch(new Fetch("FormattedID", "Name", "Tags"));
testCaseRequest.setQueryFilter(new QueryFilter("FormattedID", "=", testID));
QueryResponse testCaseQueryResponse;
testCaseQueryResponse = restApi.query(testCaseRequest);
JsonArray resultArray = testCaseQueryResponse.getResults();
if (resultArray.size() == 0) {
System.out.println("Test " + testID + "does not exist anymore");
return;
}
JsonObject testCaseJson = resultArray.get(0).getAsJsonObject();
String testCaseRef = testCaseJson.get("_ref").getAsString();
JsonObject tasks = testCaseJson.get("Tags").getAsJsonObject();
JsonArray taskarray = tasks.get("_tagsNameArray").getAsJsonArray();
boolean tagfound = false;
for (JsonElement el : taskarray) {
JsonObject task = el.getAsJsonObject();
String tgnm = task.get("Name").getAsString();
if (tgnm.contentEquals(tagname)) {
tagfound = true;
break;
}
}
if (!tagfound) {
String shortref = Ref.getRelativeRef(tagref);
String shorttestref = Ref.getRelativeRef(testCaseRef);
JsonObject json = new JsonObject();
json.addProperty("Name", tagname); // not mandatory, I guess
json.addProperty("_ref", shortref);
taskarray.add(json);
tasks.add("_tagsNameArray", taskarray);
JsonObject updateTCJson = new JsonObject();
updateTCJson.add("Tags", tasks);
UpdateRequest updateTestCaseRequest = new UpdateRequest(testCaseRef, updateTCJson);
UpdateResponse updateTestCaseResponse = restApi.update(updateTestCaseRequest);
if (updateTestCaseResponse.wasSuccessful()) {
System.out.println("Updated Test Case with tag: " + tagname);
} else {
System.err.println("Cannot update test case tags pentru ca: "+updateTestCaseResponse.getErrors()[0]);
}
問題是,我從服務器獲取這樣的:
{"OperationResult": {"_rallyAPIMajor": "2", "_rallyAPIMinor": "0", "Errors": ["Could not read: Could not read referenced object 2"], "Warnings": ["It is no longer necessary to append \".js\" to WSAPI resources."]}}
這是我的命,我花了很多時間的調試,我不能發現問題。有任何想法嗎?
你檢查了taskarray和現有任務之間的區別嗎?也許嘗試評論'tasks.add(「_ tagsNameArray」,taskarray);'並報告你的結果? – pherris 2014-09-30 16:47:01