gpt4 book ai didi

rest - 无法使用对指定测试集的引用来创建/更新 Rally TestCaseResult

转载 作者:行者123 更新时间:2023-12-01 07:33:29 26 4
gpt4 key购买 nike

有了拉力赛,我需要

Update a TestCaseResult with a new TestSet Ref.

OR

Create a new TestCaseResult by copying everything from a previous TestCaseResult and just changing the TestSet Ref.

我正在尝试通过 Java REST toolkit from Rally 做同样的事情.它似乎在内部使用 JSON REST API。

当我尝试使用 CreateRequest 或 UpdateRequest 执行此操作时,我收到来自 API 的错误消息“无法为测试集设置值:null

是否无法更新 TestCaseResult 的 TestSet(无论是现有的还是新创建的)?

这是我正在使用的一些示例代码(显示通过更改测试集从现有的创建测试用例结果)。

        //get testcaseresult object
GetRequest tcrReq = new GetRequest("/testcaseresult/12345.js");
tcrReq.setFetch(new Fetch("FormattedID", "Name"));
GetResponse tcrResponse = restApi.get(tcrReq);

//update testcaseresult object with new testset
JsonObject tsRef = new JsonObject();
tsRef.addProperty("_ref", "https://rally1.rallydev.com/slm/webservice/1.39/testset/1029348.js");
tcrResponse.getObject().add("TestSet",tsRef);
tcrResponse.getObject().remove("_ref");

//Create API for new testcaseresult object
CreateRequest createRequest = new CreateRequest("testcaseresult", tcrResponse.getObject());
CreateResponse createResponse = restApi.create(createRequest);
if(createResponse.wasSuccessful()){
System.out.println(createResponse.getObject());
}else{
String[] ss = createResponse.getErrors();
for(int i=0; i<ss.length; i++){
System.out.println(ss[i]);
}
}

能否请您帮助了解我是做错了什么还是拉力赛的限制?

最佳答案

我相信您收到“Could not set value for Test Set: null” 错误消息的原因是 TestCaseResults 上存在一个“不可见”约束,它们所在的 TestCase在可以将 TestCaseResult 作为属性分配给该 TestSet 之前,关联必须被安排到感兴趣的 TestSet 中。

不幸的是,TestCases 上没有 TestSet 属性,因此您必须从 TestSet 中查询 TestCases 集合,然后遍历该集合以检查父 TestCase 是否是该集合的成员。一旦确认 TestCase 位于该 TestSet 的 TestCases 集合中,您就可以继续使用感兴趣的 TestSet 属性成功更新成员 TestCaseResult。我测试了下面的内容,它按预期工作。

下面的代码片段说明了如何实现这一点:

    // Create and configure a new instance of RallyRestApi
// Connection parameters
String rallyURL = "https://rally1.rallydev.com";
String wsapiVersion = "1.38";
String applicationName = "RestExample_UpdateTestSetOnTestCaseResult";

// Credentials
String userName = "user@company.com";
String userPassword = "password";

RallyRestApi restApi = new RallyRestApi(
new URI(rallyURL),
userName,
userPassword);
restApi.setWsapiVersion(wsapiVersion);
restApi.setApplicationName(applicationName);

// Ref to Test Case Result of Interest
String testCaseResultRef = "/testcaseresult/1234567891.js";

GetRequest testCaseResultRequest = new GetRequest(testCaseResultRef);
GetResponse testCaseResultResponse = restApi.get(testCaseResultRequest);
JsonObject testCaseResultObj = testCaseResultResponse.getObject();

// Get the Test Case Result's Parent Test Case
JsonObject testCase = testCaseResultObj.get("TestCase").getAsJsonObject();

String testCaseRef = testCase.get("_ref").getAsString();
GetRequest testCaseRequest = new GetRequest(testCaseRef);
GetResponse testCaseResponse = restApi.get(testCaseRequest);
JsonObject testCaseObj = testCaseResponse.getObject();

System.out.println(testCaseRef);

// Ref to Test Set of Interest
String testSetRef = "/TestSet/12345678910.js";

// Get the Test Set of interest
GetRequest testSetRequest = new GetRequest(testSetRef);
GetResponse testSetResponse = restApi.get(testSetRequest);
JsonObject testSetObject = testSetResponse.getObject();

// Grab the Test Cases in this Test Set
JsonArray testCasesInTestSet = testSetObject.get("TestCases").getAsJsonArray();

// Loop through and see if our Test Case of interest is a member
boolean testCaseIsInSet = false;
for (int i=0; i<testCasesInTestSet.size(); i++) {
JsonObject thisTestCase = testCasesInTestSet.get(i).getAsJsonObject();
String thisTestCaseRef = thisTestCase.get("_ref").getAsString();

if (thisTestCaseRef.equals(testCaseRef)) {
testCaseIsInSet = true;
}
}

if (testCaseIsInSet) {
// Update Test Set on Existing Test Case Result
try {

//Add Test Set
System.out.println("\nUpdating Existing Test Case Result's Test Set attribute...");
testCaseResultObj.addProperty("TestSet", testSetRef);

UpdateRequest updateExistTestCaseResultRequest = new UpdateRequest(testCaseResultRef, testCaseResultObj);
UpdateResponse updateExistTestCaseResultResponse = restApi.update(updateExistTestCaseResultRequest);

if (updateExistTestCaseResultResponse.wasSuccessful()) {
System.out.println("Updated Test Case Result with new Test Set");
String[] updateExistTestCaseResultWarnings;

updateExistTestCaseResultWarnings = updateExistTestCaseResultResponse.getWarnings();
System.out.println("Warning(s) occurred updating Test Case Result: ");
for (int i=0; i<updateExistTestCaseResultWarnings.length;i++) {
System.out.println(updateExistTestCaseResultWarnings[i]);
}

} else {
String[] updateExistTestCaseResultErrors;
updateExistTestCaseResultErrors = updateExistTestCaseResultResponse.getErrors();
System.out.println("Error occurred updating Test Case Result: ");
for (int i=0; i<updateExistTestCaseResultErrors.length;i++) {
System.out.println(updateExistTestCaseResultErrors[i]);
}
}
} catch (Exception e) {
System.out.println("Exception occurred while updating Tags on existing Test Case: ");
e.printStackTrace();
}

finally {
//Release all resources
restApi.close();
}
} else {
System.out.println("Unable to Update Test Case Result with specified Test Set");
System.out.println("Parent Test Case is not a member of this Test Set");
}
}

关于rest - 无法使用对指定测试集的引用来创建/更新 Rally TestCaseResult,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13443500/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com