我正在开发java / groovy并且是Rally API的新手,我上周开始使用它。我希望能够使用REST API创建新的测试用例结果。星期五(我写这篇文章的星期一),我使用下面的例子让它工作,将我想要的数据放入方法中。我在另一个网站上找到了这个例子。
今天当我运行代码时,我不认为我改变了任何东西,我不断得到“ConnectionClosedException:Content-Length分隔邮件正文的过早结束(预期:1390;收到:1389)。
我再次重写了代码,这次没有改变示例中的任何内容只是为了让它再次运行,我得到了相同的异常。继承我正在使用的代码:
public static void createTestCaseResults(){
// Create and configure a new instance of RallyRestApi
RallyRestApi restApi = new RallyRestApi(new URI("https://rally1.rallydev.com"),"username@company.com", "Password");
restApi.setWsapiVersion("1.36");
restApi.setApplicationName("Add Test Case Result");
//Query User
QueryRequest userRequest = new QueryRequest("User");
userRequest.setFetch(new Fetch("UserName", "Subscription", "DisplayName"));
userRequest.setQueryFilter(new QueryFilter("UserName", "=", "username@company.com"));
QueryResponse userQueryResponse = restApi.query(userRequest);
JsonArray userQueryResults = userQueryResponse.getResults();
JsonElement userQueryElement = userQueryResults.get(0);
JsonObject userQueryObject = userQueryElement.getAsJsonObject();
String userRef = userQueryObject.get("_ref").getAsString();
// Query for Test Case to which we want to add results
QueryRequest testCaseRequest = new QueryRequest("TestCase");
testCaseRequest.setFetch(new Fetch("FormattedID","Name"));
testCaseRequest.setQueryFilter(new QueryFilter("FormattedID", "=", "TC7562"));
QueryResponse testCaseQueryResponse = restApi.query(testCaseRequest);
JsonObject testCaseJsonObject = testCaseQueryResponse.getResults().get(0).getAsJsonObject();
String testCaseRef = testCaseQueryResponse.getResults().get(0).getAsJsonObject().get("_ref").getAsString();
try{
//Add a Test Case Result
System.out.println("Creating Test Case Result...");
JsonObject newTestCaseResult = new JsonObject();
newTestCaseResult.addProperty("Verdict", "Pass");
newTestCaseResult.addProperty("Date", "2012-06-12T18:00:00.000Z");
newTestCaseResult.addProperty("Notes", "Automated Selenium Test Runs");
newTestCaseResult.addProperty("Build", "2012.05.31.0020101");
newTestCaseResult.addProperty("Tester", userRef);
newTestCaseResult.addProperty("TestCase", testCaseRef);
CreateRequest createRequest = new CreateRequest("testcaseresult", newTestCaseResult);
CreateResponse createResponse = restApi.create(createRequest);
if(createResponse.wasSuccessful()){
println(String.format("Created %s", createResponse.getObject().get("_ref").getAsString()));
//Read Test Case
String ref = Ref.getRelativeRef(createResponse.getObject().get("_ref").getAsString());
System.out.println(String.format("\nReading Test Case Result %s...", ref));
GetRequest getRequest = new GetRequest(ref);
getRequest.setFetch(new Fetch("Date", "Verdict"));
GetResponse getResponse = restApi.get(getRequest);
JsonObject obj = getResponse.getObject();
println(String.format("Read Test Case Result. Date = %s, Verdict = %s", obj.get("Date").getAsString(), obj.get("Verdict").getAsString()));
} else {
String[] createErrors;
createErrors = createResponse.getErrors();
System.out.println("Error occurred creating Test Case: ");
for (int i=0; i<createErrors.length;i++) {
System.out.println(createErrors[i]);
}
}
}
finally{
restApi.close()
}
}
感谢您的任何帮助。谢谢。 :)
答案 0 :(得分:1)
今天这还在发生吗?我只是在rally1和我们的演示系统上尝试了你的代码,它每次都可靠地工作(只更改了用户名和密码,以及测试用例格式化的id)。
作为可能的下一步,我将在RallyRestApi.doRequest中设置一个断点,其中检查服务器响应代码并查看可用的其他信息 - 例如,响应代码以及响应的正文和标题。
答案 1 :(得分:1)
这很可能是底层Apache HttpComponents库中的一个错误。我刚升级到最新的4.2.1组件。你介意试试新的1.0.2罐吗?
https://github.com/RallyTools/RallyRestToolkitForJava
<强>更新强> 这已经在今天的工具包的1.0.4版本中修复: https://github.com/downloads/RallyTools/RallyRestToolkitForJava/rally-rest-api-1.0.4.jar