//this will query for the tag, if not found it will create the tag.
ChkTag(r, wspace_ref, projref, tagx);
QueryRequest tg = new QueryRequest("Tag");
tg.setWorkspace(wspace_ref);
tg.setProject(projref);
tg.setQueryFilter(new QueryFilter("Name", "=", tagx));
QueryResponse resp = r.query(tg);
if(resp.wasSuccessful()&&resp.getTotalResultCount()==1){
System.out.println("The tag: "+tagx+" is found.");
} else {
System.err.println("The tag wasn't found for this testcase.\n"
+ "ChkTag() method was run earlier which should have created the tag. something weird is going on...");
}
//Now adding the tag to the test case
JsonArray tiger = new JsonArray();
tiger.add(resp.getResults().get(0));
//System.out.println("Updating testcase tags...");
JsonObject updatedtesttag = new JsonObject();
updatedtesttag.add("Tags", tiger);
UpdateRequest updatetag = new UpdateRequest(ref_testcase, updatedtesttag);
UpdateResponse updatetagresp = r.update(updatetag);
if(updatetagresp.wasSuccessful())
System.out.println("Tag successfully added to the test case");
}else{
System.out.println("Tag for this testcase is Null...\nSkipping Tag...");
}
我不确定这一行:
tiger.add(resp.getResults().get(0));
这一行是否会将测试用例重置为只有这一个标记,或者这会将这一个标记附加到测试用例的现有标记列表中吗?我不想丢失现有的测试用例标签。
答案 0 :(得分:0)
在此项目中,执行此操作的能力是一个长期未解决的问题:https://github.com/RallyTools/RallyRestToolkitForJava/issues/14
昨天我有一些额外的时间,所以我实现了写入集合端点的能力,并发布了工具包的新版本(2.2.1)。
这是做你想做的事的一个例子:
//Build the array of tags to add
JsonArray tagRefs = new JsonArray();
JsonObject tagRef = new JsonObject();
tagRef.addProperty("_ref", "/tag/12345");
tagRefs.add(tagRef);
//Update the collection
CollectionUpdateRequest testCaseTagCollectionAddRequest = new CollectionUpdateRequest("/testcase/23456", tagRefs, true);
testCaseTagCollectionAddRequest.setFetch(new Fetch("Name"));
CollectionUpdateResponse testCaseTagCollectionAddResponse = restApi.updateCollection(testCaseTagCollectionAddRequest);
请注意,您也可以使用updateCollection方法从集合中删除项目。
这个新功能只是在WSAPI v2.0中包装可写集合端点,如下所述:https://rally1.rallydev.com/slm/doc/webservice/rest_collections.jsp