How to add test case in existing test run through automation - rally

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);

Related

Pentaho - upload file using API

I need to upload a file using an API.
I tried REST CLIENT and didn't find any options.
Tried with HTTP POST and that responded with 415.
Please suggest how to accomplish this
Error 415 is “Unsupported media type”.
You may need to change the media type of the request or check whether that type of file us accepted by the remote server.
https://en.m.wikipedia.org/wiki/List_of_HTTP_status_codes
This solution uses only standard classes of jre 7. Add a step Modified Java Script Value in your transformation. You will have to add two columns in the flow: URL_FORM_POST_MULTIPART_COLUMN and FILE_URL_COLUMN, you can add as many files as you want, you will just have to call outputStreamToRequestBody.write more times.
try
{
//in this step you will need to add two columns from the previous flow -> URL_FORM_POST_MULTIPART_COLUMN, FILE_URL_COLUMN
var serverUrl = new java.net.URL(URL_FORM_POST_MULTIPART_COLUMN);
var boundaryString = "999aaa000zzz09za";
var openBoundary = java.lang.String.format("\n\n--%s\nContent-Disposition: form-data\nContent-Type: text/xml\n\n" , boundaryString);
var closeBoundary = java.lang.String.format("\n\n--%s--\n", boundaryString);
// var netIPSocketAddress = java.net.InetSocketAddress("127.0.0.1", 8888);
// var proxy = java.net.Proxy(java.net.Proxy.Type.HTTP , netIPSocketAddress);
// var urlConnection = serverUrl.openConnection(proxy);
var urlConnection = serverUrl.openConnection();
urlConnection.setDoOutput(true); // Indicate that we want to write to the HTTP request body
urlConnection.setRequestMethod("POST");
//urlConnection.addRequestProperty("Authorization", "Basic " + Authorization);
urlConnection.addRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundaryString);
var outputStreamToRequestBody = urlConnection.getOutputStream();
outputStreamToRequestBody.write(openBoundary.getBytes(java.nio.charset.StandardCharsets.UTF_8));
outputStreamToRequestBody.write(java.nio.file.Files.readAllBytes(java.nio.file.Paths.get(FILE_URL_COLUMN)));
outputStreamToRequestBody.write(closeBoundary.getBytes(java.nio.charset.StandardCharsets.UTF_8));
outputStreamToRequestBody.flush();
var httpResponseReader = new java.io.BufferedReader(new java.io.InputStreamReader(urlConnection.getInputStream()));
var lineRead = "";
var finalText = "";
while((lineRead = httpResponseReader.readLine()) != null) {
finalText += lineRead;
}
var status = urlConnection.getResponseCode();
var result = finalText;
var time = new Date();
}
catch(e)
{
Alert(e);
}
I solved this by using the solution from http://www.dietz-solutions.com/2017/06/pentaho-data-integration-multi-part.html
Thanks Ben.
He's written a Java class for Multi-part Form submission. I extendd by adding a header for Authorization...

Kettle (Pentaho PDI): Couldn't find starting point in this job

I'm manually creating a Job using Kettle from Java, but I get the error message Couldn't find starting point in this job.
KettleEnvironment.init();
JobMeta jobMeta = new JobMeta();
JobEntrySpecial start = new JobEntrySpecial("START", true, false);
start.setStart(true);
JobEntryCopy startEntry = new JobEntryCopy(start);
jobMeta.addJobEntry(startEntry);
JobEntryTrans jet1 = new JobEntryTrans("first");
Trans trans1 = jet1.getTrans();
jet1.setFileName("file.ktr");
JobEntryCopy jc1 = new JobEntryCopy(jet1);
jobMeta.addJobEntry(jc1);
jobMeta.addJobHop(new JobHopMeta(startEntry, jc1));
Job job = new Job(null, jobMeta);
job.setInteractive(true);
job.start();
I've discovered that I was missing
job.setStartJobEntryCopy(startEntry);
Class org.pentaho.di.job.JobMeta class has method findJobEntry
U can use it to look for entry point called "START
This is how it is original source of kettle-pdi
private JobMeta jobMeta;
....
// Where do we start?
jobEntryCopy startpoint;
....
if ( startJobEntryCopy == null ) {
startpoint = jobMeta.findJobEntry( JobMeta.STRING_SPECIAL_START, 0, false );
// and then
JobEntrySpecial jes = (JobEntrySpecial) startpoint.getEntry();

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

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.

How to add a new Test Case and associate it with User Story that already exists in 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.