我正在尝试更新测试用例的自定义字段,这是我的代码:
JsonObject update_story = new JsonObject();
update_story.addProperty("c_UTMSURI",url); //url is a string
UpdateRequest updateReq = new UpdateRequest(ref,update_story);
try{
UpdateResponse response = rest.update(update);
return (response.wasSuccessful());
}
catch(Exception e){
String errorMsg = "Caught exception while updating external ID for "+ref+"\n More Details "+e.getMessage();
Logger.Log(errorMsg);
System.out.println(errorMsg);
return false;
}
我很困惑,因为这段代码工作正常,直到几天后,现在脚本刚刚破解并且让我犯了这个错误:
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.http.client.utils.URLEncodedUtils.parse(Ljava/lang/String;Ljava/nio/charset/Charset;)Ljava/util/List;
答案 0 :(得分:1)
如果这些是您拥有的外部罐子:
httpcore-4.2.4.jar
httpclient-4.2.5.jar
commons-logging-1.1.1.jar
commons-codec-1.6.jar
gson-2.2.4.jar
rally-rest-api-2.0.4.jar
此列表与我在项目中的内容相匹配。 例如,在Eclipse中有外部库的访问规则。如果您的IDE有类似的东西,访问限制?此错误可能表示httpclient库的版本错误或存在冲突。
您是否测试过以下内容?
我尝试使用下面的代码,并成功更新了字符串类型的自定义字段。
import com.google.gson.JsonObject;
import com.rallydev.rest.RallyRestApi;
import com.rallydev.rest.request.CreateRequest;
import com.rallydev.rest.request.UpdateRequest;
import com.rallydev.rest.response.CreateResponse;
import com.rallydev.rest.response.UpdateResponse;
import com.rallydev.rest.util.Ref;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
public class CreateUpdateTC {
public static void main(String[] args) throws URISyntaxException, IOException {
String url = "https://rally1.rallydev.com";
String username = "user@co.com";
String password = "secret";
String projectRef = "/project/12345";
String applicationName = "create update test case";
RallyRestApi restApi = new RallyRestApi(
new URI(url),
username,
password);
restApi.setApplicationName(applicationName);
try {
for (int i=0; i<1; i++) {
System.out.println("Creating a test case...");
JsonObject newTC = new JsonObject();
newTC.addProperty("Name", "some testcase");
newTC.addProperty("Project", projectRef);
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 tcRef = Ref.getRelativeRef(createResponse.getObject().get("_ref").getAsString());
System.out.println(String.format("\nReading test case %s...", tcRef));
//Update tc
JsonObject tcUpdate = new JsonObject();
tcUpdate.addProperty("c_CustomString", url);
UpdateRequest updateRequest = new UpdateRequest(tcRef,tcUpdate);
UpdateResponse updateResponse = restApi.update(updateRequest);
if (updateResponse.wasSuccessful()) {
System.out.println("Successfully updated test case: " + newTC.get("Name") +
" CustomString: " + tcUpdate.get("c_CustomString"));
}
else {
String[] updateErrors;
updateErrors = createResponse.getErrors();
System.out.println("Error");
for (int j=0; i<updateErrors.length;j++) {
System.out.println(updateErrors[j]);
}
}
} else {
String[] createErrors;
createErrors = createResponse.getErrors();
System.out.println("Error");
for (int j=0; i<createErrors.length;j++) {
System.out.println(createErrors[j]);
}
}
}
} finally {
//Release all resources
restApi.close();
}
}
}
答案 1 :(得分:1)
谢谢@nickm。问题是我的工具在运行时添加了另一个lbapi jar文件。这导致了这个问题。更新现在通过。谢谢你的帮助。