大约一个月前,我编写了一个脚本,它可以成功创建标签并将它们添加到测试用例中。但是在过去的几天里,脚本无法为测试用例添加标签,但它仍然能够创建标签。这是我写的源代码:
//Looks for a specific tag
public static void ChkTag(RallyRestApi r, String tagname) throws IOException{
boolean tagfound = false;
QueryRequest alltags = new QueryRequest("Tag");
QueryResponse resp = r.query(alltags);
if(resp.wasSuccessful()){
//System.out.println("query for all tags was successful.");
for(JsonElement result : resp.getResults()){
JsonObject temp = result.getAsJsonObject();
if(temp.get("Name").getAsString().equals(tagname)){
tagfound =true;
}
}
if(tagfound==false){
System.out.println("Tag for this testcase is missing..creating now...");
ExportTCtoRally_adk.createTag(r, tagname);
}
}
}
public static void createTag(RallyRestApi r, String name) throws IOException{
//Create Tag
JsonObject mytag = new JsonObject();
mytag.addProperty("Name", name);
CreateRequest mytagc = new CreateRequest("Tag", mytag);
CreateResponse mytagcc = r.create(mytagc);
String ref_tag = Ref.getRelativeRef(mytagcc.getObject().get("_ref").getAsString());
if(mytagcc.wasSuccessful())
System.out.println("Tag successfully created.");
return;
}
然后在创建测试用例时我运行以下代码:
//-----------------FOR TAGS----------------------
boolean tagfound = false;
if (creating1.wasSuccessful()){
System.out.println("testcase created.");
QueryRequest alltags = new QueryRequest("Tag");
QueryResponse resp = r.query(alltags);
JsonElement out = null;
if(resp.wasSuccessful()){
System.out.println("query for all tags was successful.");
for(JsonElement result : resp.getResults()){
JsonObject temp = result.getAsJsonObject();
if(temp.get("Name").getAsString().equals(tagx)){
System.out.println("desired tag found.");
tagfound=true;
out=result;
}
}
if(tagfound==false){
System.out.println("Tag wasn't found.");
ExportTCtoRally_adk.createTag(r, tagx);
System.out.println("New Tag created.");
}
JsonArray tiger = new JsonArray();
tiger.add(out);
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 succeccfully added to the test case");
}
//-----------------------------------------------
我知道有些东西在这里运行了两次,但是由于它不会引起任何问题,所以我就这样离开了。
所以我的问题是我的代码有什么问题吗?
谢谢。