代码调用Rally的接口介绍

本文链接: https://www.cnblogs.com/hchengmx/p/test-framework-integrate-with-rally.html


1. 支持的语言

根据官方GitHub显示,https://github.com/RallyTools

目前支持的语言有 Python, NodeJs, .Net, Clojure, Ruby, Java, PHP..

以下均以Java举例。

其中Get/Query/Create用的比较多,所以只介绍了这几种。更多的请求可参考 官方API文档

2. 创建API Key

API Key可以理解为替代了账号密码。

Rally Application Manager 中Create New API Keys

创建以后,需要在代码中引用API Keys

RallyRestApi restApi = new RallyRestApi(new URI(host), "API Keys");

3. GetRequest

得到某Referance的详细参数(Get the specified object.)

String ref =  Ref.getRelativeRef(testCaseQueryResponse.getResults().get(0).getAsJsonObject().get("_ref").getAsString()); //testcase/457072321724
GetRequest getRequest = new GetRequest(ref);
GetResponse getResponse = restApi.get(getRequest);

4. QueryRequest

QueryRequest testCaseQueryRequest = new QueryRequest("TestCase");
testCaseQueryRequest.setFetch(new Fetch(new String[]{testCaseID, "Name", "FormattedID"}));
QueryFilter queryFilter = new QueryFilter("FormattedID", "=", testCaseID);
testCaseQueryRequest.setQueryFilter(queryFilter);
QueryResponse testCaseQueryResponse = restApi.query(testCaseQueryRequest);

5. CreateRequest

比如遇到情况,一个资源是另外一个资源的其中属性,比如Test Case Result必须是某一个Test Case的,Test Case是Test Case Result的其中一个属性,这种需要先根据Test CaseId找到Test Case Reference,然后Test Case Result再引用。

QueryResponse testCaseQueryResponse = restApi.query(testCaseQueryRequest);
String testCaseRef = testCaseQueryResponse.getResults().get(0).getAsJsonObject().get("_ref").getAsString(); //get test case reference
 
JsonObject newTestCaseResult = new JsonObject();
newTestCaseResult.addProperty("Verdict", verdict);
newTestCaseResult.addProperty("Date", s1);
newTestCaseResult.addProperty("Notes", Notes);
newTestCaseResult.addProperty("Build", Build);
newTestCaseResult.addProperty("TestCase", testCaseRef);
 
CreateRequest  testCaseResultCreateRequest  = new CreateRequest("testcaseresult", newTestCaseResult);
CreateResponse testCaseResultCreateResponse = restApi.create(testCaseResultCreateRequest);

6. 参考资料

  1. Rally Software Introduction
  2. GitHub - RallyTools/RallyRestToolkitForJava: A Java Toolkit for Accessing Rally's Webservice API
  3. CA Agile Central Web Services API Documentation v2.0
  4. For Developers
  5. Agile Central App SDK 2.1 Docs
  6. CA Agile Central - Webhooks(beta)
  7. RallyRestApi (Rally Rest Toolkit For Java 2.2.1 API)
原文地址:https://www.cnblogs.com/hchengmx/p/test-framework-integrate-with-rally.html