【问题标题】:Unable to remove a TestSet from the TestSets collection on TestCase using the Rally Rest API无法使用 Rally Rest API 从 TestCase 上的 TestSets 集合中删除 TestSet
【发布时间】:2015-03-18 02:50:30
【问题描述】:

TestSets 属性的加法有效,但减法无效。并且清除 TestSets 属性如下是一个 NO-OP - 没有。

JsonObject updates = new JsonObject();
updates.add("TestSets", newTestSets);
UpdateRequest updateRequest = new UpdateRequest(ref, updates)

但由于添加工作我知道该属性不是只读的。

【问题讨论】:

    标签: java api rest collections rally


    【解决方案1】:

    我使用带有此端点和有效负载的 Chrome Advanced Rest Client 测试了从 TestCase 上的 TestSets 集合中删除 TestSet,并且它有效:

    https://rally1.rallydev.com/slm/webservice/v2.0/testcase/12458269829/testsets/remove
    
    {"CollectionItems":[{"_ref":"https://rally1.rallydev.com/slm/webservice/v2.0/testset/19255956341"}]}
    

    我尝试使用 Rally Java 工具包,它需要 gson-2.2.4.jar。该版本的 gson 没有 remove 方法。 具有remove 方法的gson-2.3.1。

    我使用 gson-2.3.1 的代码尝试从测试用例的 TestSets 集合中删除测试集。

    现在自动完成显示“删除”并且没有“无方法”错误,但从集合中删除元素会静默失败。我提交了一个错误。

    这是我测试的代码:

    public class RemoveTestSetFromCollection {
    
        public static void main(String[] args) throws URISyntaxException, IOException {
    
    
            String host = "https://rally1.rallydev.com";
            String apiKey = "_abc123";
            String workspaceRef = "/workspace/12352608129";
            String applicationName = "RestExample_updateTestSetsOnTC";
    
    
            RallyRestApi restApi = new RallyRestApi(new URI(host),apiKey);
            restApi.setApplicationName(applicationName);
    
            try {
                String setID = "TS25";
                String testid = "TC3";
                QueryRequest  tsRequest = new QueryRequest("TestSet");
                tsRequest.setWorkspace(workspaceRef);
                tsRequest.setQueryFilter(new QueryFilter("FormattedID", "=", setID));
                QueryResponse tsQueryResponse = restApi.query(tsRequest);
                if(tsQueryResponse.getTotalResultCount() == 0){
                    System.out.println("Cannot find tag: " + setID);
                    return;
                }
                JsonObject tsJsonObject = tsQueryResponse.getResults().get(0).getAsJsonObject();
                String tsRef = tsJsonObject.get("_ref").getAsString();
                System.out.println(tsRef);
    
                QueryRequest testCaseRequest = new QueryRequest("TestCase");
                testCaseRequest.setWorkspace(workspaceRef);
                testCaseRequest.setFetch(new Fetch("FormattedID", "Name", "TestSets"));
                testCaseRequest.setQueryFilter(new QueryFilter("FormattedID", "=",  testid));
                QueryResponse testCaseQueryResponse = restApi.query(testCaseRequest);;
    
                if (testCaseQueryResponse.getTotalResultCount() == 0) {
                    System.out.println("Cannot find test case : " + testid);
                    return;
                }
                JsonObject testCaseJsonObject = testCaseQueryResponse.getResults().get(0).getAsJsonObject();
                String testCaseRef = testCaseJsonObject.get("_ref").getAsString();
                System.out.println(testCaseRef);
    
                int numberOfTestSets = testCaseJsonObject.getAsJsonObject("TestSets").get("Count").getAsInt();
                System.out.println(numberOfTestSets + " testset(s) on " + testid);
                QueryRequest testsetCollectionRequest = new QueryRequest(testCaseJsonObject.getAsJsonObject("TestSets"));
                testsetCollectionRequest.setFetch(new Fetch("FormattedID"));
                JsonArray testsets = restApi.query(testsetCollectionRequest).getResults();
    
                for (int j=0;j<numberOfTestSets;j++){
                    System.out.println("FormattedID: " + testsets.get(j).getAsJsonObject().get("FormattedID"));
                }
    
                testsets.remove(tsJsonObject);
                JsonObject testCaseUpdate = new JsonObject();
                testCaseUpdate.add("TestSets", testsets);
                UpdateRequest updateTestCaseRequest = new UpdateRequest(testCaseRef,testCaseUpdate);
                UpdateResponse updateTestCaseResponse = restApi.update(updateTestCaseRequest);
                if (updateTestCaseResponse.wasSuccessful()) {
                    QueryRequest testsetCollectionRequest2 = new QueryRequest(testCaseJsonObject.getAsJsonObject("TestSets"));
                    testsetCollectionRequest2.setFetch(new Fetch("FormattedID"));
                    JsonArray testsetsAfterUpdate = restApi.query(testsetCollectionRequest2).getResults();
                    int numberOfTestSetsAfterUpdate = restApi.query(testsetCollectionRequest2).getResults().size();
                    System.out.println("Successfully updated : " + testid + " TestSets after update: " + numberOfTestSetsAfterUpdate);
                    for (int j=0;j<numberOfTestSetsAfterUpdate;j++){
                        System.out.println("FormattedID: " + testsetsAfterUpdate.get(j).getAsJsonObject().get("FormattedID"));
                    }
                }
            } finally {
                restApi.close();
            }
    
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2015-04-29
      • 2012-09-21
      • 1970-01-01
      • 2012-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多