I tried getting the test case as json object. It will have Test folder information as a uri. How can I get the name of that test folder without hitting this uri again.
When I hit the URI it gives me the TFxxx
, This is what I need directly..
I tried getting as jsonObj.get("TestFolder.Name").toString();
which simply returns null.
Any help?
In the code below I query for a TestCase that happens to be in a TestFolder, and then traverse to the folder like this:
testCaseJsonObject.get("TestFolder").getAsJsonObject().get("Name")
Here is a full example that returns TestFolder's name:
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();
}
}
}
}