当我尝试使用拉力api创建测试用例时它不起作用,它会出错,
无法读取:找不到对象ID的对象:null
但是当我尝试查询它时,它可以工作。
下面的是代码段,
public class App {
public static void main( String[] args ){
String host = "https://rally1.rallydev.com/";
String wsapiVersion = "v2.0";
String projectRef = "/project/test";
String applicationName = "Rally test";
String myWorkspace = "/workspace/myWorkspace";
RallyRestApi restApi = new RallyRestApi(new URI(host),"my api key");
restApi.setApplicationName(applicationName);
restApi.setApplicationVersion(wsapiVersion);
String e = "proxy URL";
String user = "username";
String pwd = "pass";
restApi.setProxy(new URI(e), user, pwd);
JsonObject newTestCase = new JsonObject();
newTestCase.addProperty("Project", projectRef);
newTestCase.addProperty("Name", "Rally test");
CreateRequest createRequest = new CreateRequest("testcase",newTestCase);
CreateResponse createResponse = restApi.create(createRequest);
if (createResponse.wasSuccessful()){
System.out.println("Test case created successfully");
}
else {
System.out.println("The test case could not be created");
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]);
}
}
QueryRequest request = new QueryRequest("User");
request.setFetch(new Fetch(new String[] { "UserName" }));
request.setQueryFilter(new QueryFilter("UserName","=", "rally user"));
QueryResponse response = restApi.query(request);
if (response.getTotalResultCount() > 0) {
JsonObject userObject = response.getResults().get(0).getAsJsonObject();
String ref = Ref.getRelativeRef(userObject.get("_ref").getAsString());
System.out.println("hweouhowhochwoiiceihh"+ref);
}
QueryRequest subscriptionRequest = new QueryRequest("Subscriptions");
QueryResponse subscriptionQueryResponse = restApi.query(subscriptionRequest);
String subName = subscriptionQueryResponse.getResults().get(0).getAsJsonObject().get("Name").toString();
System.out.println("Read Subscription: " + subName);
QueryRequest workspaceRequest1 = new QueryRequest(subscriptionQueryResponse.getResults().get(0).getAsJsonObject().getAsJsonObject("Workspaces"));
workspaceRequest1.setFetch(new Fetch("Name", "_ref"));
JsonArray myWorkspaces = restApi.query(workspaceRequest1).getResults();
//Iterate through the Workspaces to find the correct one
String workspaceName = "";
String Wspace_ref;
for (int i=0; i<myWorkspaces.size(); i++){
workspaceName = myWorkspaces.get(i).getAsJsonObject().get("Name").getAsString();
System.out.printf("Workspace found ==> %s\n", workspaceName);
Wspace_ref = myWorkspaces.get(i).getAsJsonObject().get("_ref").getAsString();
System.out.println("Wspace_ref "+Wspace_ref);
}
}
}