如何使用其余的Api在Rally中获取格式化的测试用例ID

时间:2015-01-23 21:35:32

标签: java rest rally

我从Rally URL检索了testcase对象ID值。我需要从该值的格式化ID值。这可以使用拉力赛的休息api(java)来实现吗? 感谢

1 个答案:

答案 0 :(得分:0)

如果你有ObjectID,并且在你的提取中包含FormattedID,你可以在这个例子中得到它:

 public static void main(String[] args) throws Exception {

        String host = "https://rally1.rallydev.com";
        String apiKey = "_abc123"; 
        String applicationName = "Find TestCase by ObjectID"; 
        String workspaceRef = "/workspace/12345"; 

        RallyRestApi restApi = null;
        try {
            restApi = new RallyRestApi(new URI(host),apiKey);

            QueryRequest request = new QueryRequest("TestCase");
            request.setWorkspace(workspaceRef);
            restApi.setApplicationName(applicationName);
            request.setFetch(new Fetch("FormattedID"));

            request.setQueryFilter(new QueryFilter("ObjectID", "=", "14226025324")); 

            QueryResponse response = restApi.query(request);
            if(response.wasSuccessful()){
                System.out.println("Number of results: " + response.getResults().size());
                for (int i=0; i<response.getTotalResultCount();i++){
                    JsonObject jsonObject = response.getResults().get(i).getAsJsonObject();
                    System.out.println("FormattedID: " + jsonObject.get("FormattedID"));
                }
            }
            else{
                System.out.println("false? " + response.wasSuccessful());
            }
        } finally {
            if (restApi != null) {
                restApi.close();
            }
        }
    }