如何创建缺陷并通过Rally API(java)将其附加到缺陷套件?
如何创建缺陷并通过Rally API(java)将其附加到缺陷套件? 你能举个例子吗如何创建缺陷并通过Rally API(java)将其附加到缺陷套件?,java,rally,suite,Java,Rally,Suite,如何创建缺陷并通过Rally API(java)将其附加到缺陷套件? 你能举个例子吗 感谢Eyal以下是一个java示例,该示例查询现有缺陷套件,创建新缺陷,将缺陷套件添加到新缺陷的缺陷套件集合中,并更新缺陷: import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.rallydev.rest.RallyRestApi; import com.rallydev.rest.request.Cre
感谢Eyal以下是一个java示例,该示例查询现有缺陷套件,创建新缺陷,将缺陷套件添加到新缺陷的缺陷套件集合中,并更新缺陷:
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.rallydev.rest.RallyRestApi;
import com.rallydev.rest.request.CreateRequest;
import com.rallydev.rest.request.QueryRequest;
import com.rallydev.rest.request.UpdateRequest;
import com.rallydev.rest.response.CreateResponse;
import com.rallydev.rest.response.QueryResponse;
import com.rallydev.rest.response.UpdateResponse;
import com.rallydev.rest.util.Fetch;
import com.rallydev.rest.util.QueryFilter;
import com.rallydev.rest.util.Ref;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
public class addDefectToSuite {
public static void main(String[] args) throws URISyntaxException, IOException {
String host = "https://rally1.rallydev.com";
String username = "user@company.com";
String password = "secret";
String wsapiVersion = "v2.0";
String projectRef = "/project/12352608219";
String workspaceRef = "/workspace/12352608129";
String applicationName = "Create defect, add to a defectsuite";
RallyRestApi restApi = new RallyRestApi(
new URI(host),
username,
password);
restApi.setWsapiVersion(wsapiVersion);
restApi.setApplicationName(applicationName);
QueryRequest defectSuiteRequest = new QueryRequest("DefectSuite");
defectSuiteRequest.setFetch(new Fetch("FormattedID","Name", "Defects"));
defectSuiteRequest.setWorkspace(workspaceRef);
defectSuiteRequest.setQueryFilter(new QueryFilter("FormattedID", "=", "DS1"));
QueryResponse defectSuiteQueryResponse = restApi.query(defectSuiteRequest);
JsonObject defectSuiteJsonObject = defectSuiteQueryResponse.getResults().get(0).getAsJsonObject();
System.out.println("defectSuiteJsonObject" + defectSuiteJsonObject);
String defectSuiteRef = defectSuiteJsonObject.get("_ref").getAsString();
int numberOfDefects = defectSuiteJsonObject.getAsJsonObject("Defects").get("Count").getAsInt();
System.out.println(defectSuiteJsonObject.get("Name") + " ref: " + defectSuiteRef + "number of defects: " + numberOfDefects + " " + defectSuiteJsonObject.get("Defects"));
try {
JsonObject defect = new JsonObject();
defect.addProperty("Name", "bad defect 668");
CreateRequest createRequest = new CreateRequest("defect", defect);
CreateResponse createResponse = restApi.create(createRequest);
if (createResponse.wasSuccessful()) {
JsonObject defectJsonObject = createResponse.getObject();
String defectRef = Ref.getRelativeRef(createResponse.getObject().get("_ref").getAsString());
System.out.println(String.format("Created %s", defectRef));
JsonObject defectSuitesOfThisDefect = (JsonObject) defectJsonObject.get("DefectSuites");
int numberOfSuites = defectSuitesOfThisDefect.get("Count").getAsInt();
System.out.println("number of defect suites this defect is part of: " + numberOfSuites);
QueryRequest defectSuitesOfThisDefectRequest = new QueryRequest(defectSuitesOfThisDefect);
JsonArray suites = restApi.query(defectSuitesOfThisDefectRequest).getResults();
System.out.println("suites: " + suites);
suites.add(defectSuiteJsonObject);
System.out.println("suites after add: " + suites);
//Update defect: add to defectsutites collection
JsonObject defectUpdate = new JsonObject();
defectUpdate.add("DefectSuites", suites);
UpdateRequest updateDefectRequest = new UpdateRequest(defectRef,defectUpdate);
UpdateResponse updateResponse = restApi.update(updateDefectRequest);
if (updateResponse.wasSuccessful()) {
System.out.println("Successfully updated defect: " + defectJsonObject.get("FormattedID"));
}
else {
String[] updateErrors;
updateErrors = createResponse.getErrors();
System.out.println("Error");
for (int i=0; i<updateErrors.length;i++) {
System.out.println(updateErrors[i]);
}
}
} else {
System.out.println("error");
}
} finally {
restApi.close();
}
}
}
import com.google.gson.JsonArray;
导入com.google.gson.JsonObject;
导入com.rallydev.rest.RallyRestApi;
导入com.rallydev.rest.request.CreateRequest;
导入com.rallydev.rest.request.QueryRequest;
导入com.rallydev.rest.request.UpdateRequest;
导入com.rallydev.rest.response.CreateResponse;
导入com.rallydev.rest.response.QueryResponse;
导入com.rallydev.rest.response.UpdateResponse;
导入com.rallydev.rest.util.Fetch;
导入com.rallydev.rest.util.QueryFilter;
导入com.rallydev.rest.util.Ref;
导入java.io.IOException;
导入java.net.URI;
导入java.net.URISyntaxException;
公共类addDefectToSuite{
公共静态void main(字符串[]args)抛出URISyntaxException、IOException{
字符串主机=”https://rally1.rallydev.com";
字符串用户名=”user@company.com";
字符串password=“secret”;
字符串wsapiVersion=“v2.0”;
字符串projectRef=“/project/12352608219”;
字符串workspaceRef=“/workspace/12352608129”;
String applicationName=“创建缺陷,添加到缺陷套件”;
RallyRestApi restApi=新的RallyRestApi(
新URI(主机),
用户名,
密码);
restApi.setWsapiVersion(wsapiVersion);
restApi.setApplicationName(applicationName);
QueryRequest defectSuiteRequest=新的QueryRequest(“DefectSuite”);
setFetch(新的Fetch(“FormattedID”、“Name”、“Defects”);
defectSuiteRequest.setWorkspace(workspaceRef);
setQueryFilter(新的QueryFilter(“FormattedID”,“=”,“DS1”));
QueryResponse DefectSuiteRequestResponse=restApi.query(defectSuiteRequest);
JsonObject defectSuiteJsonObject=defectSuiteQueryResponse.getResults().get(0.getAsJsonObject();
System.out.println(“defectSuiteJsonObject”+defectSuiteJsonObject);
字符串defectSuiteRef=defectSuiteJsonObject.get(“\u ref”).getAsString();
int numberOfDefects=defectSuiteJsonObject.getAsJsonObject(“缺陷”).get(“计数”).getAsInt();
System.out.println(defectSuiteJsonObject.get(“Name”)+“ref:“+defectSuiteRef+”缺陷数量:“+numberOfDefects+”+defectSuiteJsonObject.get(“缺陷”);
试一试{
JsonObject缺陷=新的JsonObject();
缺陷。添加属性(“名称”、“不良缺陷668”);
CreateRequest CreateRequest=新的CreateRequest(“缺陷”,缺陷);
CreateResponse CreateResponse=restApi.create(createRequest);
if(createResponse.wasSuccessful()){
JsonObject缺陷JsonObject=createResponse.getObject();
字符串defectRef=Ref.getRelativeRef(createResponse.getObject().get(“\u Ref”).getAsString());
System.out.println(String.format(“已创建%s”,defectRef));
JsonObject缺陷套件此缺陷=(JsonObject)缺陷JsonObject.get(“缺陷套件”);
int numberOfSuites=defectSuitesOfThisDefect.get(“Count”).getAsInt();
System.out.println(“此缺陷所属的缺陷套件数量:“+numberOfSuites”);
QueryRequest defectSuitesOfThisDefectRequest=新的QueryRequest(defectSuitesOfThisDefect);
JsonArray suites=restApi.query(defectSuitesOfThisDefectRequest.getResults();
System.out.println(“suites:+suites”);
suites.add(defectSuiteJsonObject);
System.out.println(“添加后的套件:+套件”);
//更新缺陷:添加到缺陷集合
JsonObject defectUpdate=新建JsonObject();
缺陷更新。添加(“缺陷套件”,套件);
UpdateRequest updateDefectRequest=新的UpdateRequest(defectRef,defectUpdate);
UpdateResponse UpdateResponse=restApi.update(updateDefectRequest);
if(updateResponse.wasSuccessful()){
System.out.println(“已成功更新缺陷:+defectJsonObject.get(“FormattedID”));
}
否则{
字符串[]更新错误;
updateErrors=createResponse.getErrors();
System.out.println(“错误”);
对于(int i=0;我认为你的问题太宽泛了。请举一个更具体的例子,讲述你的故事。此外,你不必在意给出的是哪种语言的例子。放弃这个要求也会得到更多的答案。