How to add a new Test Case and associate it with User Story that already exists in Rally - rally

I have used the following code to Add a new Test Case and associate to an existing UserStory in Rally. It creates the new test case but does not associate with the existing User Story US4.Am I missing any references.Any Help would be highly appreciated
String storyFormattedID = "US4";
QueryRequest storyRequest = new QueryRequest("HierarchicalRequirement");
storyRequest.setFetch(new Fetch("FormattedID", "Name", "Changesets"));
storyRequest.setQueryFilter(new QueryFilter("FormattedID", "=",
storyFormattedID));
QueryResponse storyQueryResponse = restApi.query(storyRequest);
JsonObject storyJsonObject = storyQueryResponse.getResults().get(0)
.getAsJsonObject();
String storyRef = storyJsonObject.get("_ref").toString();
JsonObject newTestCase = new JsonObject();
newTestCase.addProperty("Name", "Test Case");
newTestCase.addProperty("Requirement", storyRef);
newTestCase.addProperty("Name",
"Newly added testcase associated to a Story");
CreateRequest createRequest = new CreateRequest("testcase", newTestCase);
CreateResponse response = restApi.create(createRequest);
System.out.println(response.toString());
JsonObject json = response.getObject();
System.out.println(json);

The correct attribute to associate a TestCase to a HierarchicalRequirement is WorkProduct, since TestCases can associate either to HierarchicalRequirement or Defect. So:
newTestCase.addProperty("WorkProduct", storyRef);
Should do the trick for you.

Related

How to add test case in existing test run through automation

I have created on test set and i want to add test case in existing test run . I used update request to add the test case, but its deleting existing test case in test run and adding it.
if(!testCaseList.isJsonNull()&&!update){
restApi.setApplicationName("PSN")
JsonObject newTS = new JsonObject()
newTS.addProperty("Name", TSName)
newTS.addProperty("PlanEstimate", points)
newTS.addProperty("Project", projectRef)
newTS.addProperty("Owner", userRef)
if (releaseRef!="") newTS.addProperty("Release", releaseRef)
if (iterationRef!="") newTS.addProperty("Iteration", iterationRef)
newTS.add("TestCases", testCaseList)
CreateRequest createRequest = new CreateRequest("testset",newTS)
CreateResponse createResponse = restApi.create(createRequest)
ref = createResponse.getObject().get("_ref").getAsString()
}
else if(!testCaseList.isJsonNull()&&update){
restApi.setApplicationName("PSN")
newTS.addProperty("Name", TSName)
newTS.addProperty("PlanEstimate", points)
newTS.addProperty("Project", projectRef)
newTS.addProperty("Owner", userRef)
if (releaseRef!="") newTS.addProperty("Release", releaseRef)
if (iterationRef!="") newTS.addProperty("Iteration", iterationRef)
newTS.add("TestCases", testCaseList)
UpdateRequest updateRequest = new UpdateRequest(ref,newTS)
UpdateResponse updateResponse = restApi.update(updateRequest)
ref = updateResponse.getObject().get("_ref").getAsString()
}
Rather than setting the TestCases collection directly you want to use the CollectionUpdateRequest and the updateCollection method.
https://github.com/RallyTools/RallyRestToolkitForJava/wiki/User-Guide#update-collection
CollectionUpdateRequest testsetTestCasesAddRequest = new CollectionUpdateRequest(ref + "/testcases", testCaseList, true);
CollectionUpdateResponse testsetTestCasesAddResponse = restApi.updateCollection(testsetTestCasesAddRequest);

Rally: Get user _ref from RallyRestApi object created using ApiKey

I created a connection to rally using the ApiKey constructor.
Question is how do i find out the User "_ref" associated with this User ApiKey ?
rallyRestApi= new RallyRestApi(new URI(host), "myApiKey");
I tried following 2 test runs:
doing a blank query (i.e. without any setQueryFilter) on User object; it returns me all the users.
QueryRequest userRequest = new QueryRequest("User");
QueryResponse userQueryResponse = connection.query(userRequest);
JsonArray userQueryResults = userQueryResponse.getResults();
Getting owner from Workspace object >> This returns me the owner of the Workspace
You may get a current user:
GetRequest getRequest = new GetRequest("/user");
GetResponse getResponse = restApi.get(getRequest);
JsonObject currentUser = getResponse.getObject();
String currentUserName = currentUser.get("_refObjectName").getAsString();
String currentUserRef = currentUser.get("_ref").getAsString();
System.out.println("current user: " + currentUserName + currentUserRef);
I tested it with latest Rally API toolkit for Java.

InsertAll using C# not working

I´d like to know why this code is not working. It runs without errors but rows are not inserted. I´m using C# client library.
Any ideas? Thanks!!
string SERVICE_ACCOUNT_EMAIL = "(myserviceaccountemail)";
string SERVICE_ACCOUNT_PKCS12_FILE_PATH = #"C:\(myprivatekeyfile)";
System.Security.Cryptography.X509Certificates.X509Certificate2 certificate =
new System.Security.Cryptography.X509Certificates.X509Certificate2(SERVICE_ACCOUNT_PKCS12_FILE_PATH, "notasecret",
System.Security.Cryptography.X509Certificates.X509KeyStorageFlags.Exportable);
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(SERVICE_ACCOUNT_EMAIL)
{
Scopes = new[] { BigqueryService.Scope.BigqueryInsertdata, BigqueryService.Scope.Bigquery }
}.FromCertificate(certificate));
// Create the service.
var service = new BigqueryService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "test"
});
Google.Apis.Bigquery.v2.Data.TableDataInsertAllRequest tabreq = new Google.Apis.Bigquery.v2.Data.TableDataInsertAllRequest();
List<Google.Apis.Bigquery.v2.Data.TableDataInsertAllRequest.RowsData> tabrows = new List<Google.Apis.Bigquery.v2.Data.TableDataInsertAllRequest.RowsData>();
Google.Apis.Bigquery.v2.Data.TableDataInsertAllRequest.RowsData rd = new Google.Apis.Bigquery.v2.Data.TableDataInsertAllRequest.RowsData();
IDictionary<string,object> r = new Dictionary<string,object>();
r.Add("campo1", "test4");
r.Add("campo2", "test5");
rd.Json = r;
tabrows.Add(rd);
tabreq.Rows = tabrows;
service.Tabledata.InsertAll(tabreq, "(myprojectid)", "spots", "spots");
I think you should add the Kind field [1]. It should be something like this:
tabreq.Kind = "bigquery#tableDataInsertAllRequest";
Also remeber that every request of the API has a response [2] with additional info to help you find the issue's root cause.
var requestResponse = service.Tabledata.InsertAll(tabreq, "(myprojectid)", "spots", "spots");
[1] https://developers.google.com/resources/api-libraries/documentation/bigquery/v2/csharp/latest/classGoogle_1_1Apis_1_1Bigquery_1_1v2_1_1Data_1_1TableDataInsertAllRequest.html#aa2e9b0da5e15b158ae0d107378376b26
[2] https://cloud.google.com/bigquery/docs/reference/v2/tabledata/insertAll

LDAP search returning unexpected object type

I am issuing a LDAP query against an IBM Tivoli Directory Server (I am querying for the special user "cn=monitor", but I don't know if that is significant).
I execute the following code:
DirContext ctx = new InitialDirContext(env);
Object o = ctx.lookup ("cn=monitor");
I was expecting o to be of type NamingEnumeration, but instead it is of type DirContext. I can't figure out how to get the returned data from this object type.
Strangely enough, I can see that the data I want is being fetched because I set debugging on with the following command:
env.put("com.sun.jndi.ldap.trace.ber", System.out);
I was expecting o to be of type NamingEnumeration, but instead it is of type DirContext.
Why? NamingEnumerations are returned by the search() method. Not by the lookup() methods. There's nothing in the documentation to suggest otherwise.
I found out that I should be using search() instead of lookup().
I tried search() before, but it was failing due to incorrect scope setting. I fixed this and now my code is working,
In case if will be helpful, example code:
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://XXX");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "DOMAIN\\user.name");
env.put(Context.SECURITY_CREDENTIALS, "password");
DirContext ctx = new InitialDirContext(env);
if(ctx != null){
String []requiredAttributes = {"sn","cn","sAMAccountName","memberOf"};
SearchControls controls = new SearchControls();
controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
controls.setReturningAttributes(requiredAttributes);
SearchResult searchResult = null;
NamingEnumeration user = ctx.search(USER_SEARCH_BASE, USER_SEARCH_FILTER, controls);
while(users.hasMore()){
searchResult=(SearchResult)users.next();
Attributes attr = searchResult.getAttributes();
String commonName = attr.get("cn").get(0).toString();
System.out.println("Common Name: " + commonName);
}
}

How to Add New TestCases to an existing Rally Folder

I tried the below code to create test cases under existing folder. I'm able to create the testcase but dont see it under the associated folder.
QueryRequest testFolderRequest = new QueryRequest("TestFolder");
testFolderRequest .setFetch(new Fetch("FormattedID", "Name"));
QueryResponse testFolderQueryResponse = restApi.query(testsetRequest);
// JsonObject testSetJsonObject =
// testSetQueryResponse.getResults().get(0).getAsJsonObject();
String testFolderReference = testFolderQueryResponse.getResults().get(0)
.getAsJsonObject().get("_ref").toString();
// System.out.println("TestFolder object: "+testSetRef);
JsonObject newTestCase = new JsonObject();
newTestCase.addProperty("Name", "Newly added testcase in a folder");
newTestCase.addProperty("Test Folder", testFolderReference);
CreateRequest createRequest = new CreateRequest("testcase", newTestCase);
CreateResponse response = restApi.create(createRequest);
System.out.println(response.toString());
JsonObject json = response.getObject();
System.out.println(json);
Attributes in webservices API shouldn't have spaces. So:
newTestCase.addProperty("TestFolder", testFolderReference);
Should work.