问题描述
我正在使用rally dev api 2.2.1,并且我正在尝试一次性创建步骤。而不是循环并逐一创建。
我写了这个,它运行良好,但一步一步地创建步骤 1 并且需要时间。
private void updateSteps(TestCase testCase,JsonObject createResponse) {
try {
String testCaseRef = createResponse.get("_ref").getAsstring();
String testCaseID = createResponse.get("FormattedID").getAsstring();
final int[] stepCount = {1};
LOGGER.info("*-*-*-*-*-*-*-*-*-*-*-*-*-*-* Creating steps for " + testCaseID + " *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
testCase.getTestCaseSteps().forEach(step -> {
try {
StopWatch timer = new StopWatch();
timer.start();
executeDBGetStep(step);
JsonObject stepRequest = new JsonObject();
stepRequest.addProperty("TestCase",testCaseRef);
stepRequest.addProperty("StepIndex",stepCount[0]);
stepRequest.addProperty("Input",step.getTestStepDescription() + "<br/><br/>" + format(this.getobjectAsstring(step.getTestStepDataRequest(true))));
if (step.getTestStepAssert() == null) {
stepRequest.addProperty("ExpectedResult","As Expected");
} else {
JsonNode assertObject;
try {
assertObject = step.getTestStepAssert(true);
} catch (Exception ex) {
assertObject = step.getTestStepAssert(false);
}
stepRequest.addProperty("ExpectedResult",format(this.getobjectAsstring(assertObject)));
}
CreateRequest createStepRequest = new CreateRequest("testCaseStep",stepRequest);
CreateResponse createStepResponse = this.rallyClient.getRestApi().create(createStepRequest);
timer.stop();
if (ExceptionHandlers.isResponseSuccessful(createStepResponse)) {
LOGGER.info("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
LOGGER.info("Step " + stepCount[0] + " created for test case " + testCaseID + " in " + timer.getLastTasktimeMillis() + " milliseconds");
LOGGER.info("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
}
stepCount[0]++;
} catch (IOException ex) {
ex.printstacktrace();
}
});
LOGGER.info("*-*-*-*-*-*-*-*-*-*-*-* Finished creating steps for " + testCaseID + " -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
} catch (Exception ex) {
ex.printstacktrace();
}
}
所以,到目前为止我已经尝试过这个并且我得到 404 NOT FOUND 因为我假设在执行 collectionUpdate 时它正在请求中寻找 _ref 对象并且因为我是第一次创建它,引用没有存在并抛出此错误。
private void updateSteps(TestCase testCase,JsonObject createResponse) {
try {
String testCaseRef = createResponse.get("_ref").getAsstring();
String testCaseID = createResponse.get("FormattedID").getAsstring();
final int[] stepCount = {1};
LOGGER.info("*-*-*-*-*-*-*-*-*-*-*-*-*-*-* Creating steps for " + testCaseID + " *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
StopWatch timer = new StopWatch();
timer.start();
JsonArray stepsTobeUpdated = new JsonArray();
testCase.getTestCaseSteps().forEach(step -> {
executeDBGetStep(step);
JsonObject stepRequest = new JsonObject();
JsonObject testCaSEObject = new JsonObject();
testCaSEObject.addProperty("_ref",testCaseRef);
stepRequest.add("TestCase",testCaSEObject);
stepRequest.addProperty("StepIndex",stepCount[0]);
stepRequest.addProperty("Input",step.getTestStepDescription() + "<br/><br/>" + format(this.getobjectAsstring(step.getTestStepDataRequest(true))));
if (step.getTestStepAssert() == null) {
stepRequest.addProperty("ExpectedResult","As Expected");
} else {
JsonNode assertObject;
try {
assertObject = step.getTestStepAssert(true);
} catch (Exception ex) {
assertObject = step.getTestStepAssert(false);
}
stepRequest.addProperty("ExpectedResult",format(this.getobjectAsstring(assertObject)));
}
stepsTobeUpdated.add(stepRequest);
stepCount[0]++;
});
CollectionUpdateRequest testStepCollectionAddRequest = new CollectionUpdateRequest(testCaseRef + "/steps",stepsTobeUpdated,true);
try {
CollectionUpdateResponse testStepCollectionAddResponse = rallyClient.getRestApi().updateCollection(testStepCollectionAddRequest);
if (ExceptionHandlers.isResponseSuccessful(testStepCollectionAddResponse)) {
LOGGER.info(stepsTobeUpdated.size() + " steps updated/created in test case " + testCase.getTestCaseCode());
} else {
ExceptionHandlers.getErrors("Error while updating/creating steps in test case ").forEach(LOGGER::error);
}
} catch (IOException exception) {
throw new IllegalStateException(exception);
}
timer.stop();
LOGGER.info("*-*-*-*-*-*-*-*-*-*-*-* Finished creating steps for " + testCaseID + " -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
} catch (Exception ex) {
ex.printstacktrace();
}
}
在谷歌上搜索了很多,之前好像没有人问过这个,可能是因为不可能。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)