Rally Software

 View Only
  • 1.  Posting TestcCase results - Could not read: Object not found for Object ID

    Posted Jun 01, 2020 04:49 PM
    Hello! 
    I need to write a PASS/FAIL and date to a TestCase

    I get the following error 

    {"CreateResult": {"_rallyAPIMajor": "2", "_rallyAPIMinor": "0", "Errors": ["Could not read: Object not found for Object ID: null"], "Warnings": ["It is no longer necessary to append \".js\" to WSAPI resources."]}}

    Can anybody offer any guidance?

    public static void main(String[] args) throws URISyntaxException, IOException {

    String host = "https://rally1.rallydev.com";
    String username = "00377466@XXX.com";
    String apiKey = "_IcgM8kIQmO0uO92MJfyJXZT5n0wYEGypfPDKxrN58w";
    String wsapiVersion = "v2.0";
    String workspaceRef = "/workspace/Ops QA Automation";
    String applicationName = "RestExample_AddTCR";

    RallyRestApi restApi = new RallyRestApi(new URI(host), apiKey);
    restApi.setWsapiVersion(wsapiVersion);
    restApi.setApplicationName(applicationName);

    //Read User
    QueryRequest userRequest = new QueryRequest("User");
    userRequest.setFetch(new Fetch("UserName", "Subscription", "DisplayName", "SubscriptionAdmin"));
    userRequest.setQueryFilter(new QueryFilter("UserName", "=", username));
    QueryResponse userQueryResponse = restApi.query(userRequest);
    JsonArray userQueryResults = userQueryResponse.getResults();
    JsonElement userQueryElement = userQueryResults.get(0);
    JsonObject userQueryObject = userQueryElement.getAsJsonObject();
    String userRef = userQueryObject.get("_ref").getAsString();
    System.out.println(userRef);

    // Query for Test Case to which we want to add results
    QueryRequest testCaseRequest = new QueryRequest("TestCase");
    testCaseRequest.setFetch(new Fetch("FormattedID", "Name"));
    testCaseRequest.setWorkspace(workspaceRef);
    testCaseRequest.setQueryFilter(new QueryFilter("FormattedID", "=", "TC86026"));
    QueryResponse testCaseQueryResponse = restApi.query(testCaseRequest);

    String testCaseRef = testCaseQueryResponse.getResults().get(0).getAsJsonObject().get("_ref").getAsString();

    try {
    for (int i = 0; i < 2; i++) {

    //Add a Test Case Result
    System.out.println(testCaseRef);
    System.out.println("Creating Test Case Result...");
    JsonObject newTestCaseResult = new JsonObject();
    newTestCaseResult.addProperty("Verdict", "Pass");
    newTestCaseResult.addProperty("Date", "2020-05-21T13:00:00.000Z");
    newTestCaseResult.addProperty("Notes", "Some Scheduled Test");
    newTestCaseResult.addProperty("Build", "2.0");
    newTestCaseResult.addProperty("Tester", userRef);
    newTestCaseResult.addProperty("TestCase", testCaseRef);
    newTestCaseResult.addProperty("Workspace", workspaceRef);

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

    if (createResponse.wasSuccessful()) {
    System.out.println(String.format("Created %s", createResponse.getObject().get("_ref").getAsString()));

    //Read Test Case
    String ref = Ref.getRelativeRef(createResponse.getObject().get("_ref").getAsString());
    System.out.println(String.format("\nReading Test Case Result %s...", ref));
    GetRequest getRequest = new GetRequest(ref);
    getRequest.setFetch(new Fetch("Date", "Verdict"));
    GetResponse getResponse = restApi.get(getRequest);
    JsonObject obj = getResponse.getObject();
    System.out.println(String.format("my Read Test Case Result. Date = %s, Verdict = %s",
    obj.get("Date").getAsString(), obj.get("Verdict").getAsString()));
    }//End if (createResponse.wasSuccessful())

    else {
    String[] createErrors;
    createErrors = createResponse.getErrors();
    System.out.println("Error occurred creating Test Case Result: ");
    for (int j = 0; i < createErrors.length; j++) {
    System.out.println(createErrors[j]);
    }//End for
    }//End else
    }//End for (int i = 0; i < 2; i++)
    }//try

    finally {
    //Release all resources
    restApi.close();
    }//End finally
    }//End main


  • 2.  RE: Posting TestcCase results - Could not read: Object not found for Object ID

    Broadcom Employee
    Posted Jun 01, 2020 04:54 PM
    Hi Damian,

    One thing that jumps out at me is your workspace reference.  That should be the numeric object ID as opposed to a name reference.
    If you need to find the Object ID easily, we have an article you can follow here: https://knowledge.broadcom.com/external/article?articleId=47763


  • 3.  RE: Posting TestcCase results - Could not read: Object not found for Object ID

    Posted Jun 01, 2020 06:33 PM
    Hi David,

    Where and how would I add the objectId in my code? When I run in debug  I noticed the variable testCaseRef contains the objectID in its URL https://rally1.rallydev.com/slm/webservice/v2.0/testcase/392946925700 also the response contains
    "ObjectID": 392946925700



  • 4.  RE: Posting TestcCase results - Could not read: Object not found for Object ID
    Best Answer

    Broadcom Employee
    Posted Jun 02, 2020 04:14 AM
    Hi @Damian Healey

    I suspect that you don't need to set the workspace. You most likely would be better off by specifying the Project​ as this is mandatory when creating a TestCaseResult. The mandatory fields are marked with Required = true in the WSAPI docs here: https://rally1.rallydev.com/slm/doc/webservice/

    Here is an example of what the UI sets when creating a TestCaseResult which I captured from the browsers devtools:

    In this case, the code is setting the project to the _ref field that you would get from reading your project entry. I also have a vague recollection that the TesCaseResult must be placed in the same Project node as the TestCase itself... but that might not be accurate.



    ------------------------------
    Nik
    Ask me a question, I'm All Ears!
    Rally Sales Engineer
    Rally Software
    ------------------------------



  • 5.  RE: Posting TestcCase results - Could not read: Object not found for Object ID

    Posted Jun 02, 2020 08:49 AM
    Awesome that worked - thank you Nik :)