Test cases are associated to test sets via the TestCases collection on TestSet in the WSAPI. This code example demonstrates creating a few test cases and then creating a test set associated with the newly created test cases.
RallyRestApi restApi = new RallyRestApi(new URI(SERVER),
USERNAME, PASSWORD);
try {
//Create some test cases
JsonArray testCases = new JsonArray();
for(int i = 0; i < 3; i++) {
JsonObject newTestCase = new JsonObject();
newTestCase.addProperty("Name", "New Test Case " + i);
CreateRequest createRequest = new CreateRequest("testcase", newTestCase);
CreateResponse createResponse = restApi.create(createRequest);
String ref = createResponse.getObject().get("_ref").getAsString();
System.out.println(String.format("Created test case %s", ref));
//Keep track of the test case
JsonObject testCase = new JsonObject();
testCase.addProperty("_ref", ref);
testCases.add(testCase);
}
//Create test set
JsonObject newTestSet = new JsonObject();
newTestSet.addProperty("Name", "New Test Set");
newTestSet.add("TestCases", testCases);
CreateRequest createRequest = new CreateRequest("testset", newTestSet);
CreateResponse createResponse = restApi.create(createRequest);
System.out.println(String.format("Created test set %s", createResponse.getObject().get("_ref").getAsString()));
} finally {
//Release all resources
restApi.close();
}