Tuesday, January 28, 2014

Rally API integration with Java

Recently I worked on Rally API integration with our Java Automation framework .Rally is the ALM (Application Life Management tool) . In this blog I would be posting my experiences in Integrating Rally API and the context would be more on Test Management

Rally exposes some webservices typically REST services that allows user to Manage the Test Management. To access the webservices Rally does not provide any API. How ever there are many open source Rest Clients for Java,C#,python.....

I used Java Rest Client to access the Rally REST services you can download the libraries from the link
https://github.com/RallyTools/RallyRestToolkitForJava

How to update the test cases in rally with our Automation Test case results

Will soon post the BLOG...

How to Query for list of Test Cases using Query Filter

Will soon post the BLOG

How to create a Test Case using Rally Rest API

Will soon post the BLOG

How to Login in to Rally using Java Rest API client

To access to Rally you need to login authentication
public RallyRestApi authenticate() throws URISyntaxException, Exception {

            //Provide Rally url,username and password
            RallyRestApi restApi = new RallyRestApi(new URI(https://us1.rallydev.com),
"username, "password");

          //If you are behind a proxy server provide the following
            restApi.setProxy("proxyserver", "userName", "password");
try {
if (restApi == null) {
LOGGER.debug("Authenticating Rally with provided credentials");
System.out.println("Initializing Rally Connector with user : "
+ userName);
LOGGER.debug("Trying to connect and login to rally : ");
restApi = new RallyRestApi(new URI(rallyUrl), userName,
password);
QueryRequest userRequest = new QueryRequest("User");
// userRequest.setFetch(new Fetch("UserName", "Subscription",
// "DisplayName"));
userRequest.setQueryFilter(new QueryFilter("UserName", "=",
ReadProperties.getInstance().getProperty("username")));
QueryResponse userQueryResponse;

userQueryResponse = restApi.query(userRequest);
JsonArray userQueryResults = userQueryResponse.getResults();
JsonElement userQueryElement = userQueryResults.get(0);
JsonObject userQueryObject = userQueryElement.getAsJsonObject();
String userRef = userQueryObject.get("_ref").toString();
LOGGER.info("Rally Authentication Successful!");
}
} catch (Exception e) {
LOGGER.error("Failed to Authenticate User [" + userName + "]"
+ e.getMessage());
e.printStackTrace();
}
return restApi;
}