我尝试将测试用例作为json对象。它将测试文件夹信息作为uri。如何在不再次访问此uri的情况下获取该测试文件夹的名称。
当我点击URI时,它会给我TFxxx
,这就是我需要的......
我尝试获取jsonObj.get("TestFolder.Name").toString();
只返回null。
任何帮助?
答案 0 :(得分:1)
在下面的代码中,我查询恰好位于TestFolder中的TestCase,然后遍历到这样的文件夹:
testCaseJsonObject.get("TestFolder").getAsJsonObject().get("Name")
这是一个返回TestFolder名称的完整示例:
public class GetTestFolder {
public static void main(String[] args) throws Exception {
String host = "https://rally1.rallydev.com";
String applicationName = "Example: get Folder of TestCase";
String projectRef = "/project/12352608219";
String apiKey = "_abc123";
RallyRestApi restApi = null;
try {
restApi = new RallyRestApi(new URI(host),apiKey);
restApi.setApplicationName(applicationName);
QueryRequest testCaseRequest = new QueryRequest("TestCase");
testCaseRequest.setProject(projectRef);
testCaseRequest.setFetch(new Fetch(new String[] {"FormattedID","Name","TestFolder"}));
testCaseRequest.setQueryFilter(new QueryFilter("FormattedID", "=", "TC47"));
testCaseRequest.setScopedDown(false);
testCaseRequest.setScopedUp(false);
QueryResponse testCaseResponse = restApi.query(testCaseRequest);
System.out.println("Successful: " + testCaseResponse.wasSuccessful());
for (int i=0; i<testCaseResponse.getResults().size();i++){
JsonObject testCaseJsonObject = testCaseResponse.getResults().get(i).getAsJsonObject();
System.out.println("Name: " + testCaseJsonObject.get("Name") + " FormattedID: " + testCaseJsonObject.get("FormattedID") + " TestFolder: " + testCaseJsonObject.get("TestFolder").getAsJsonObject().get("Name"));
}
} finally {
if (restApi != null) {
restApi.close();
}
}
}
}