1
我有來自GetCurrentUser()調用的用戶對象,並且我將Test Case作爲DynamicJsonObject,但只是將TestCase [「Owner」設置爲當前用戶不起作用 - 任何人都有代碼示例,這在哪裏工作?RallyAPI - 通過API更改TestCase所有者通過API
我有來自GetCurrentUser()調用的用戶對象,並且我將Test Case作爲DynamicJsonObject,但只是將TestCase [「Owner」設置爲當前用戶不起作用 - 任何人都有代碼示例,這在哪裏工作?RallyAPI - 通過API更改TestCase所有者通過API
所有者屬性是對用戶對象的引用。當創建測試用例並且設置所有者時,這是Java示例:
public class CreateTCsetOwner {
public static void main(String[] args) throws URISyntaxException, IOException {
String host = "https://rally1.rallydev.com";
String username = "[email protected]";
String password = "secret";
String wsapiVersion = "v2.0";
String projectRef = "/project/222";
String workspaceRef = "/workspace/111";
String applicationName = "RestExample_createTCsetOwner";
RallyRestApi restApi = new RallyRestApi(
new URI(host),
username,
password);
restApi.setWsapiVersion(wsapiVersion);
restApi.setApplicationName(applicationName);
QueryRequest userRequest = new QueryRequest("User");
userRequest.setFetch(new Fetch("UserName", "DisplayName"));
userRequest.setQueryFilter(new QueryFilter("UserName", "=", "[email protected]"));
QueryResponse userQueryResponse = restApi.query(userRequest);
String userRef = "";
for (int i=0; i<userQueryResponse.getResults().size();i++){
JsonObject userJsonObject = userQueryResponse.getResults().get(i).getAsJsonObject();
System.out.println("UserName: " + userJsonObject.get("UserName"));
userRef = userJsonObject.get("_ref").getAsString();
}
try {
for (int i=0; i<1; i++) {
System.out.println("Creating a test case...");
JsonObject newTC = new JsonObject();
newTC.addProperty("Name", "some test");
newTC.addProperty("Owner", userRef);
CreateRequest createRequest = new CreateRequest("testcase", newTC);
CreateResponse createResponse = restApi.create(createRequest);
if (createResponse.wasSuccessful()) {
System.out.println(String.format("Created %s", createResponse.getObject().get("_ref").getAsString()));
//Read TC
String ref = Ref.getRelativeRef(createResponse.getObject().get("_ref").getAsString());
System.out.println(String.format("\nReading testcase %s...", ref));
GetRequest getRequest = new GetRequest(ref);
} else {
String[] createErrors;
createErrors = createResponse.getErrors();
System.out.println("Error occurred creating a testcase: ");
for (int j=0; i<createErrors.length;j++) {
System.out.println(createErrors[j]);
}
}
}
} finally {
//Release all resources
restApi.close();
}
}
}
GAAH!我非常接近,以至於我偶然發現了答案:
DynamicJsonObject owner = new DynamicJsonObject();
owner["Owner"] = restApi.GetCurrentUser()["_ref"].ToString();
restApi.Update(existingTestCase["_ref"], owner);
完美地工作 - 感謝您的幫助。
我應該更具體 - 測試用例是一個現有的測試用例,我試圖將所有者更改爲當前用戶:existingTestCase [「Owner」] = restApi.GetCurrentUser()[「_ ref」]。ToString ();不起作用... –