psk
psk

Reputation: 57

Inserting test case result using Java Rally Rest API failing when workspace is different from default set on account

My solution for Rally REST API with Java is working fine within one workspace. Please advise on inserting test case result when workspace is different. I am stuck for following situation as described in detail below:*

Setup

Steps

I am trying to setup result for test case TC1 in workspace YYY but does not seem to update and failing with following error.

// Query for Test Case to which we want to add results
QueryRequest testCaseRequest = new QueryRequest("TestCase");
testCaseRequest.setFetch(new Fetch("FormattedID","Name"));
testCaseRequest.setQueryFilter(new QueryFilter("FormattedID", "=", testCaseId));

String workspaceRef = "/workspace/YYY";
String projectRef = "/project/QQQ";

testCaseRequest.setWorkspace(workspaceRef);
testCaseRequest.setProject(projectRef);

QueryResponse testCaseQueryResponse = restApi.query(testCaseRequest);
JsonObject testCaseJsonObject = testCaseQueryResponse.getResults().get(0).getAsJsonObject();
String testCaseRef = testCaseJsonObject.get("_ref").toString();

//Add a Test Case Result                
System.out.println("Creating Test Case Result...");
JsonObject newTestCaseResult = new JsonObject();
newTestCaseResult.addProperty("Verdict", result);
java.util.Date date= new java.util.Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
String timestamp = sdf.format(date);

newTestCaseResult.addProperty("Date", timestamp);
newTestCaseResult.addProperty("Notes", "Automated Test Runs");
newTestCaseResult.addProperty("Build", build);
newTestCaseResult.addProperty("Tester", userRef);
newTestCaseResult.addProperty("TestCase", testCaseRef);

CreateRequest createRequest = new CreateRequest("testcaseresult", newTestCaseResult);
CreateResponse createResponse = restApi.create(createRequest);  

This fails at the last line with this error:

"{"CreateResult": {"_rallyAPIMajor": "1", "_rallyAPIMinor": "37", "Errors": ["Could not set value for Test Case: Cannot connect object to value, Test Case value is in a different workspace. [object workspace OID=XXX, value workspace OID=YYY"], "Warnings": []}}"

Upvotes: 3

Views: 2041

Answers (1)

Kyle Morse
Kyle Morse

Reputation: 8410

If you don't specify which workspace to create the TestCaseResult in it will default to your profile default (which in this case is different than the associated TestCase's workspace).

If you add the following code before your create it should succeed:

newTestCaseResult.addProperty("Workspace", testCaseJsonObject.get("Workspace").getAsJsonObject().get("_ref").getAsString());

You'll also need to fetch Workspace on the original query:

testCaseRequest.setFetch(new Fetch("FormattedID","Name", "Workspace"));

You'd think the WSAPI should be able to infer the correct workspace from the linked TestCase however this is common behavior across creates for all object types.

Upvotes: 1

Related Questions