Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法使用java rest api创建测试用例_Java_Web Services_Rest_Rally - Fatal编程技术网

无法使用java rest api创建测试用例

无法使用java rest api创建测试用例,java,web-services,rest,rally,Java,Web Services,Rest,Rally,当我尝试使用rally api创建测试用例时,它不起作用,它给出了一个错误 无法读取:找不到对象ID为null的对象 但当我试图查询它时,它是有效的 下面是代码片段 public class App { public static void main( String[] args ){ String host = "https://rally1.rallydev.com/"; String wsapiVersion = "v2.0"; S

当我尝试使用rally 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);
        }

    }
}
公共类应用程序{
公共静态void main(字符串[]args){
字符串主机=”https://rally1.rallydev.com/";
字符串wsapiVersion=“v2.0”;
字符串projectRef=“/project/test”;
字符串applicationName=“拉力测试”;
字符串myWorkspace=“/workspace/myWorkspace”;
RallyRestApi restApi=new-RallyRestApi(新URI(主机),“我的api密钥”);
restApi.setApplicationName(applicationName);
restApi.setApplicationVersion(wsapiVersion);
字符串e=“代理URL”;
字符串user=“username”;
字符串pwd=“通过”;
setProxy(新的URI(e)、用户、pwd);
JsonObject newTestCase=新JsonObject();
newTestCase.addProperty(“项目”,projectRef);
newTestCase.addProperty(“名称”、“拉力测试”);
CreateRequest CreateRequest=新的CreateRequest(“testcase”,newTestCase);
CreateResponse CreateResponse=restApi.create(createRequest);
if(createResponse.wasSuccessful()){
System.out.println(“已成功创建测试用例”);
}
否则{
System.out.println(“无法创建测试用例”);
字符串[]创建错误;
createErrors=createResponse.getErrors();
System.out.println(“创建测试用例时出错:”);
对于(int i=0;i 0){
JsonObject userObject=response.getResults().get(0.getAsJsonObject();
String ref=ref.getRelativeRef(userObject.get(“\u ref”).getAsString());
System.out.println(“hWeowhowhochwoiiCeihh”+ref);
}
QueryRequest subscriptionRequest=新的QueryRequest(“订阅”);
QueryResponse subscriptionQueryResponse=restApi.query(subscriptionRequest);
String subName=subscriptionQueryResponse.getResults().get(0.getAsJsonObject().get(“Name”).toString();
System.out.println(“读取订阅:+subName”);
QueryRequest workspaceRequest1=新的QueryRequest(subscriptionQueryResponse.getResults().get(0).getAsJsonObject().getAsJsonObject(“工作空间”);
workspaceRequest1.setFetch(新的Fetch(“Name”,“_ref”));
JsonArray myworkspace=restApi.query(workspaceRequest1.getResults();
//遍历工作区以找到正确的工作区
字符串workspaceName=“”;
字符串Wspace_ref;

对于(int i=0;iIn,您的真实代码是projectRef,更像“/project/12345”?这是我唯一觉得奇怪的事情…我尝试了/project/projectID,它是rally url的一部分,它起了作用,早些时候我尝试使用name。在您的真实代码中,是projectRef,更像“/project/12345”这是我唯一觉得奇怪的事情…我试过使用/project/projectd,它是rally url的一部分,它起作用了,早些时候我试过使用name。