Sagi, Sorry for late response. Here is the code:
package com.qa.framework.executor.test;
import java.net.URI;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.rallydev.rest.RallyRestApi;
import com.rallydev.rest.request.QueryRequest;
import com.rallydev.rest.response.QueryResponse;
import com.rallydev.rest.util.Fetch;
import com.rallydev.rest.util.QueryFilter;
public class GetTCofTF {
public static void main(String[] args) throws Exception {
String host = "https://rally1.rallydev.com";
String applicationName = "RESTExampleFindTestCasesOfTestSet";
String workspaceRef = "/workspace/25194919975";
String projectRef = "/project/58270664632";
String wsapiVersion = "v2.0";
RallyRestApi restApi = null;
try {
if (null == restApi || null == restApi) {
restApi=new RallyRestApi(
new URI(host),
"<RALLY KEY>");
restApi.setApplicationName(applicationName);
QueryRequest testSetRequest = new QueryRequest("TestCases");
testSetRequest.setWorkspace(workspaceRef);
restApi.setWsapiVersion(wsapiVersion);
testSetRequest.setFetch(new Fetch(new String[] {"Name","FormattedID"}));
// testSetRequest.setQueryFilter(new QueryFilter("FormattedID", "=", "TS5169"));
//Query for test cases present in the Test Plan folder
QueryFilter children = new QueryFilter("TestFolder.Name", "=", "TF17980");
QueryFilter grandChildren = new QueryFilter("TestFolder.Parent.Name", "=", "TF17980");
testSetRequest.setQueryFilter(children.or(grandChildren));
QueryResponse testSetQueryResponse = restApi.query(testSetRequest);
System.out.println("Successful: " + testSetQueryResponse.wasSuccessful());
System.out.println("Size: " + testSetQueryResponse.getTotalResultCount());
for (int i=0; i<testSetQueryResponse.getResults().size();i++){
JsonObject testSetJsonObject = testSetQueryResponse.getResults().get(i).getAsJsonObject();
System.out.println("Name: " + testSetJsonObject.get("Name") + " ref: " + testSetJsonObject.get("_ref").getAsString() + " Test Cases: " + testSetJsonObject.get("TestCases"));
//TestCases is an object with a Count and a ref to load the collection
int numberOfTestCases = testSetJsonObject.getAsJsonObject("TestCases").get("Count").getAsInt();
if(numberOfTestCases > 0) {
QueryRequest testCaseRequest = new QueryRequest(testSetJsonObject.getAsJsonObject("TestCases"));
testCaseRequest.setFetch(new Fetch("FormattedID"));
//load the collection
JsonArray testCases = restApi.query(testCaseRequest).getResults();
for (int j=0;j<numberOfTestCases;j++){
System.out.println(testCases.get(j).getAsJsonObject().get("FormattedID").getAsString());
}
}
}
}
} catch (Exception e){
e.printStackTrace();
} finally {
if (restApi != null) {
restApi.close();
}
}
}
}