Saturday, March 15, 2014

How to Fetch the Rally User Story List

public Map<String, Map<String, String>> getFolderList() throws IOException {
if (folderReferenceMap.isEmpty()) {
QueryRequest folderRequest = new QueryRequest("TestFolder");
// spaces
folderRequest.setFetch(new Fetch("FormattedID", "Name"));
LOGGER.info("Feting the folder list from Rally for project ["
+ ReadProperties.getInstance().getProperty("rallyProject")
+ "]");
folderRequest.setQueryFilter(new QueryFilter("Project.Name", "=",
ReadProperties.getInstance().getProperty("rallyProject")));
QueryResponse folderQueryResponse = restApi.query(folderRequest);
// JsonObject testSetJsonObject =
// testSetQueryResponse.getResults().get(0).getAsJsonObject();
JsonArray resultArray = folderQueryResponse.getResults();
for (JsonElement result : resultArray) {
String rallyFolderObjId = result.getAsJsonObject().get("_ref")
.getAsString();
LOGGER.debug(rallyFolderObjId);
String rallyFolderName = result.getAsJsonObject()
.get("_refObjectName").getAsString();
// System.out.println(rallyFolderName);

String formattedId = result.getAsJsonObject()
.get("FormattedID").getAsString();
// System.out.println(formattedId);

String testFolder = "testfolder";
int stringPosition = rallyFolderObjId.indexOf(testFolder)
+ testFolder.length() + 1;
rallyFolderObjId = rallyFolderObjId.substring(stringPosition,
rallyFolderObjId.length());
// System.out.println(rallyFolderObjId);
Map<String, String> folderMap = new HashMap<String, String>();
folderMap.put(rallyFolderObjId, rallyFolderName);
folderReferenceMap.put(formattedId, folderMap);

}
LOGGER.debug("Folder list loading  from Rally is complete");
}

return folderReferenceMap;

}

How to fetch the Rally Folder List

public Map<String, Map<String, String>> getFolderList() throws IOException {
if (folderReferenceMap.isEmpty()) {
QueryRequest folderRequest = new QueryRequest("TestFolder");
// spaces
folderRequest.setFetch(new Fetch("FormattedID", "Name"));
LOGGER.info("Feting the folder list from Rally for project ["
+ ReadProperties.getInstance().getProperty("rallyProject")
+ "]");
folderRequest.setQueryFilter(new QueryFilter("Project.Name", "=",
ReadProperties.getInstance().getProperty("rallyProject")));
QueryResponse folderQueryResponse = restApi.query(folderRequest);
// JsonObject testSetJsonObject =
// testSetQueryResponse.getResults().get(0).getAsJsonObject();
JsonArray resultArray = folderQueryResponse.getResults();
for (JsonElement result : resultArray) {
String rallyFolderObjId = result.getAsJsonObject().get("_ref")
.getAsString();
LOGGER.debug(rallyFolderObjId);
String rallyFolderName = result.getAsJsonObject()
.get("_refObjectName").getAsString();
// System.out.println(rallyFolderName);

String formattedId = result.getAsJsonObject()
.get("FormattedID").getAsString();
// System.out.println(formattedId);

String testFolder = "testfolder";
int stringPosition = rallyFolderObjId.indexOf(testFolder)
+ testFolder.length() + 1;
rallyFolderObjId = rallyFolderObjId.substring(stringPosition,
rallyFolderObjId.length());
// System.out.println(rallyFolderObjId);
Map<String, String> folderMap = new HashMap<String, String>();
folderMap.put(rallyFolderObjId, rallyFolderName);
folderReferenceMap.put(formattedId, folderMap);
xAFTRallyScenarioDataMap.getInstance().setFolderReferenceMap(
folderReferenceMap);
}
LOGGER.debug("Folder list loading  from Rally is complete");
}

return folderReferenceMap;

}

How to get the List of all Test Cases

//Below Code fetches the list of TestCases based on Filter (Project,Folder,Owner..)

public List<String> getTestCaseDetails(RallyRestApi restApi,
String methodName, String folder, String projectName)
throws IOException {
// All Test cases
QueryRequest testcases = new QueryRequest("Test Case");
testcases.setFetch(new Fetch("FormattedID", "Name", "Owner",
"Test Folder"));
testcases.setQueryFilter(new QueryFilter("Project.Name", "=",
projectName).and(
new QueryFilter("TestFolder.Name", "=", folder)).and(
new QueryFilter("Method", "=", methodName)));
testcases.setOrder("FormattedID ASC");
QueryResponse queryResponse = restApi.query(testcases);
JsonArray testCaseList = new JsonArray();
if (queryResponse.wasSuccessful()) {
System.out.println(String.format("\nTotal results: %d",
queryResponse.getTotalResultCount()));

testCaseList = queryResponse.getResults().getAsJsonArray();
for (JsonElement testCase : testCaseList) {
JsonObject json = new JsonObject();
json = testCase.getAsJsonObject();
System.out.println(json.get("FormattedID"));
System.out.println(json.get("LastVerdict"));
System.out.println(testCase);
testCaseInfoList.add(testCase.toString());
}
} else {
for (String err : queryResponse.getErrors()) {
System.err.println("\t" + err);
}
}
return testCaseInfoList;
}

How to get list of Rally Projects

public Map<String, List<String>> getProjectReferenceMap()
throws IOException {
// Get the workspace references
List<String> workspaceReferenceList = getWorkSpaceReferences();
String workSpaceName = "";
String projectRef = "";
GetRequest workspaceRequest;
GetResponse workspaceResponse;
Map<String, List<String>> projectWorkSpaceMap = new HashMap<String, List<String>>();
List<String> projectList = new ArrayList<String>();
// Iterate through each workspace and get all the project associated
// with each workspace
for (String workspaceRef : workspaceReferenceList) {
// Get the workspaces
if (workspaceRef.equalsIgnoreCase("workSpace")) {
workspaceRequest = new GetRequest(workspaceRef);
workspaceRequest.setFetch(new Fetch("Name", "Projects"));
workspaceResponse = restApi.get(workspaceRequest);
JsonObject workspaceObj = workspaceResponse.getObject();
JsonArray workspaceArray = workspaceObj.get("Results")
.getAsJsonArray();
JsonObject jo;
JsonElement projRef;
// For each workspace get the list of projects
for (int i = 0; i < workspaceArray.size(); i++) {
jo = workspaceArray.get(i).getAsJsonObject();
workSpaceName = jo.get("Name").getAsString();
projRef = jo.get("Projects");
JsonObject jobject = projRef.getAsJsonObject();
JsonElement je = jobject.get("_ref");
projectRef = je.toString();
projectList.add(projectRef);
}
projectWorkSpaceMap.put(workSpaceName, projectList);
}

}

return projectWorkSpaceMap;
}

How to fetch the Rally WorkSpace Reference


//Below code would return the list of Workspaces
private List<String> getWorkSpaceReferences() throws IOException {
List<String> workSpaceRefArray = new ArrayList<String>();
// Get Subscription Response
JsonObject subscriptionObject = getSubScriptionResponse();
// From the workspaces get all workspaces
JsonElement workSpaces = subscriptionObject.get("Workspaces");

// Check if the subscription contains multiple projects which are
// returned as an array
if (workSpaces.isJsonArray()) {
// TODO
} else {
// Get the single workspace
JsonObject myWorkspaceObject = workSpaces.getAsJsonObject();
JsonObject workspaceObject = myWorkspaceObject.getAsJsonObject();
// Get the workspace reference
String workspaceRef = workspaceObject.get("_ref").getAsString();
workSpaceRefArray.add(workspaceRef);
}
return workSpaceRefArray;
}

How to get User Subscription details from Rally




//Below code gives the User Details Subscriptions
private JsonObject getSubScriptionResponse() {

                RallyRestApi restApi = new RallyRestApi(new URI(rallyURL),
"user@yourcomapany.com", "password");
QueryRequest subscriptionRequest = new QueryRequest("Subscriptions");
subscriptionRequest.setFetch(new Fetch("Name", "SubscriptionID",
"Workspaces", "Name"));

QueryResponse subscriptionQueryResponse = null;
JsonObject subscriptionQueryObject = null;
try {
subscriptionQueryResponse = restApi.query(subscriptionRequest);
JsonArray subscriptionQueryResults = subscriptionQueryResponse
.getResults();
JsonElement subscriptionQueryElement = subscriptionQueryResults
.get(0);
subscriptionQueryObject = subscriptionQueryElement
.getAsJsonObject();
this.subscriptionId = subscriptionQueryObject.get("SubscriptionID")
.toString();
System.out.println("Read Subscription: " + subscriptionId);
} catch (IOException e) {
e.printStackTrace();
}
return subscriptionQueryObject;

}

How to Delete Rally Test Cases