Rally Rest API新手。我使用以下代码获得了一些构造函数和方法错误。你能解释为什么会出现这些问题吗?我已经注意到符号“>”的错误类型。 thx提前。
import com.google.gson.JsonObject;
import com.rallydev.rest.RallyRestApi;
import com.rallydev.rest.util.Fetch;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.rallydev.rest.request.CreateRequest;
import com.rallydev.rest.request.DeleteRequest;
import com.rallydev.rest.request.GetRequest;
import com.rallydev.rest.request.UpdateRequest;
import com.rallydev.rest.response.CreateResponse;
import com.rallydev.rest.response.DeleteResponse;
import com.rallydev.rest.response.GetResponse;
import com.rallydev.rest.response.UpdateResponse;
import com.rallydev.rest.util.Ref;
import com.rallydev.rest.request.QueryRequest;
import com.rallydev.rest.response.QueryResponse;
import com.rallydev.rest.util.QueryFilter;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import java.net.URISyntaxException;
import java.net.URI;
public class RallyUpdate {
public static void main(String[] args) throws URISyntaxException, IOException {
RallyRestApi restApi = new RallyRestApi(new URI("https://rally1.rallydev.com"),"jsmith@company.com", "password");
restApi.setWsapiVersion("1.38");
restApi.setApplicationName("Add Test Case Result");
QueryRequest userRequest = new QueryRequest("User");
**>constructor - Fetch>**userRequest.setFetch(new Fetch("UserName", "Subscription", "Joe Smith"));
userRequest.setQueryFilter(new QueryFilter("UserName", "=", "jsmith@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").toString();
if (userQueryResponse.wasSuccessful()) {
System.out.println("User Found");
} else {
System.out.println("User not found");
}
System.out.println("Creating a test case result...");
QueryRequest testCaseRequest = new QueryRequest("TestCase");
**>constructor - Fetch>**testCaseRequest.setFetch(new Fetch("FormattedID","Rally REST API Enhancment Object ID to Formatted ID"));
testCaseRequest.setQueryFilter(new QueryFilter("FormattedID", "=", "TCxxx"));
QueryResponse testCaseQueryResponse = restApi.query(testCaseRequest);
JsonObject testCaseJsonObject = testCaseQueryResponse.getResults().get(0).getAsJsonObject();
String testCaseRef = testCaseQueryResponse.getResults().get(0).getAsJsonObject().get("_ref").getAsString();
if (testCaseQueryResponse.wasSuccessful()) {
System.out.println("Test Case Found");
} else {
System.out.println("Test Case not found");
}
try {
//Add a Test Case Result
System.out.println("Creating TestCase Result...");
JsonObject newTestCaseResult = new JsonObject();
newTestCaseResult.addProperty("Verdict", "Pass");
newTestCaseResult.addProperty("Notes", "Test");
newTestCaseResult.addProperty("Build", "2014.03.31.0020101");
newTestCaseResult.addProperty("Tester", "Joe Smith");
newTestCaseResult.addProperty("TestCase", "/testcae/17080774xxx");
System.out.println("added testcase info");
CreateRequest createRequest = new CreateRequest("newtestcaseresult", newTestCaseResult);
CreateResponse createResponse = restApi.create(createRequest);
if (createResponse.wasSuccessful()) {
**>method>**System.out.println(String.format("Created %s", createResponse.getObject().get("_ref").getAsString()));
//Read Test Case
String ref = Ref.getRelativeRef(createResponse.getObject().get("_ref").getAsString());
**>method>**System.out.println(String.format("\nReading Test Case Result %s...", ref));
GetRequest getRequest = new GetRequest(ref);
**>method>**getRequest.setFetch(new Fetch("Date", "Verdict"));
GetResponse getResponse = restApi.get(getRequest);
JsonObject obj = getResponse.getObject();
**>method>**System.out.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]);
System.out.println(createErrors[i]);
}
}
}finally {
//Release all resources
restApi.close();
}
}
}
错误:
Row 40 : The constructor Fetch(String, String, String, String) is undefined
Row 53: The constructor Fetch(String, String) is undefined
Row 83: The method format(String, Object[]) in the type String is not applicable for the arguments (String, String)
Row 90: The method format(String, Object[]) in the type String is not applicable for the arguments (String, String)
Row 93: The constructor Fetch(String, String) is undefined
Row 98: The method format(Locale, String, Object[]) in the type String is not applicable for the arguments (String, String, String)
答案 0 :(得分:0)
请使用v2.0,而不是不再支持1.38版本的WS API。
restApi.setWsapiVersion("v2.0");
我还注意到错误testcae
,您的意思是testcase
:
newTestCaseResult.addProperty("TestCase", "/testcae/17080774xxx");
并且您的Fetches包括&#34; Joe Smith&#34;而不是有效的字段名称&#34; DisplayName&#34;和#34; Rally REST API Enhancment Object ID to Formatted ID&#34;而不是有效的字段名称&#34;名称&#34;。
以下是参考资料的完整应用。完整代码可在this github repo
中找到public class addTCRtoTC {
public static void main(String[] args) throws URISyntaxException, IOException {
String host = "https://rally1.rallydev.com";
String username = "user@co.com";
String password = "secret";
String wsapiVersion = "v2.0";
String projectRef = "/project/2222";
String workspaceRef = "/workspace/11111";
String applicationName = "RestExample_AddTCR";
RallyRestApi restApi = new RallyRestApi(
new URI(host),
username,
password);
restApi.setWsapiVersion(wsapiVersion);
restApi.setApplicationName(applicationName);
//Read User
QueryRequest userRequest = new QueryRequest("User");
userRequest.setFetch(new Fetch("UserName", "Subscription", "DisplayName", "SubscriptionAdmin"));
userRequest.setQueryFilter(new QueryFilter("UserName", "=", "nick@wsapi.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();
System.out.println(userRef);
// Query for Test Case to which we want to add results
QueryRequest testCaseRequest = new QueryRequest("TestCase");
testCaseRequest.setFetch(new Fetch("FormattedID","Name"));
testCaseRequest.setWorkspace(workspaceRef);
testCaseRequest.setQueryFilter(new QueryFilter("FormattedID", "=", "TC6"));
QueryResponse testCaseQueryResponse = restApi.query(testCaseRequest);
JsonObject testCaseJsonObject = testCaseQueryResponse.getResults().get(0).getAsJsonObject();
String testCaseRef = testCaseQueryResponse.getResults().get(0).getAsJsonObject().get("_ref").getAsString();
try {
for (int i=0; i<2; i++) {
//Add a Test Case Result
System.out.println(testCaseRef);
System.out.println("Creating Test Case Result...");
JsonObject newTestCaseResult = new JsonObject();
newTestCaseResult.addProperty("Verdict", "Pass");
newTestCaseResult.addProperty("Date", "2014-03-07T18:00:00.000Z");
newTestCaseResult.addProperty("Notes", "Some Scheduled Test");
newTestCaseResult.addProperty("Build", "2.0");
newTestCaseResult.addProperty("Tester", userRef);
newTestCaseResult.addProperty("TestCase", testCaseRef);
newTestCaseResult.addProperty("Workspace", workspaceRef);
CreateRequest createRequest = new CreateRequest("testcaseresult", newTestCaseResult);
CreateResponse createResponse = restApi.create(createRequest);
if (createResponse.wasSuccessful()) {
System.out.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();
System.out.println(String.format("my 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 Result: ");
for (int j=0; i<createErrors.length;j++) {
System.out.println(createErrors[j]);
}
}
}
} finally {
//Release all resources
restApi.close();
}
}
}