user7375157
user7375157

Reputation: 13

Java Rally REST API: How to create new test case

I have been able to successfully create test RESULTS through the Rally APIs, but now I would like to create a test case if one is not already present in Rally.

I am receiving an error from Rally that “Object ID is null”, which implies that Rally thinks I am UPDATING a test case, even though I am trying to create one.

Has anyone tried the create test case Rally API, or does anyone see what I need to fix? Thank you!

//Method to build the JSON and create the new test CASE in Rally
    public static void createNewTestCase(String currentMethodName) 
    throws URISyntaxException, IOException{
        Configuration conf = new Configuration();
        RallyRestApi restApi = new RallyRestApi(new URI(
        "https://rally1.rallydev.com"),
        {authentication code});
        restApi.setApplicationName("Test Case");             
         try {
                //Create test case
                JsonObject newTestCase = new JsonObject();
                newTestCase.addProperty("Name", currentMethodName);
                newTestCase.addProperty("Description", "Created by Rally");
                newTestCase.addProperty("Project", "Project1"));
                newTestCase.addProperty("Type", "Functional");
                newTestCase.addProperty("Method", "Automated");
                newTestCase.addProperty("DefectStatus", "NONE");
            CreateRequest createRequest = new CreateRequest("testcase",
                newTestCase);
            CreateResponse createResponse = restApi.create(createRequest);
                if (createResponse.wasSuccessful()){
                System.out.println("Test case created successfully");
                }
                else {
                System.out.println("The test case could not be created");
                String[] createErrors;
                createErrors = createResponse.getErrors();
                System.out.println("Error occurred creating Test Case: ");
                for (int i=0; i<createErrors.length;i++) {
                   System.out.println(createErrors[i]);
               }
                }

         }catch (Exception e){
                e.printStackTrace();
         }
         finally {
                restApi.close();
         }
   }

Upvotes: 1

Views: 1590

Answers (1)

Kyle Morse
Kyle Morse

Reputation: 8410

My guess is the problem is with setting the project. Object relationships in Rally are always expressed as refs: /type/objectid.

newTestCase.addProperty("Project", "/project/12345");

Upvotes: 1

Related Questions