2014-01-22 75 views

回答

0

所有者屬性是對用戶對象的引用。當創建測試用例並且設置所有者時,這是Java示例:

public class CreateTCsetOwner { 

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


      String host = "https://rally1.rallydev.com"; 
      String username = "[email protected]"; 
      String password = "secret"; 
      String wsapiVersion = "v2.0"; 
      String projectRef = "/project/222"; 
      String workspaceRef = "/workspace/111"; 
      String applicationName = "RestExample_createTCsetOwner"; 


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

     QueryRequest userRequest = new QueryRequest("User"); 
     userRequest.setFetch(new Fetch("UserName", "DisplayName")); 
     userRequest.setQueryFilter(new QueryFilter("UserName", "=", "[email protected]")); 
     QueryResponse userQueryResponse = restApi.query(userRequest); 
     String userRef = ""; 
     for (int i=0; i<userQueryResponse.getResults().size();i++){ 
       JsonObject userJsonObject = userQueryResponse.getResults().get(i).getAsJsonObject(); 
       System.out.println("UserName: " + userJsonObject.get("UserName")); 
       userRef = userJsonObject.get("_ref").getAsString(); 

      } 


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

       System.out.println("Creating a test case..."); 
       JsonObject newTC = new JsonObject(); 
       newTC.addProperty("Name", "some test"); 
       newTC.addProperty("Owner", userRef); 


       CreateRequest createRequest = new CreateRequest("testcase", newTC); 
       CreateResponse createResponse = restApi.create(createRequest); 
       if (createResponse.wasSuccessful()) { 

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

        //Read TC 
        String ref = Ref.getRelativeRef(createResponse.getObject().get("_ref").getAsString()); 
        System.out.println(String.format("\nReading testcase %s...", ref)); 
        GetRequest getRequest = new GetRequest(ref);   
       } else { 
        String[] createErrors; 
        createErrors = createResponse.getErrors(); 
        System.out.println("Error occurred creating a testcase: "); 
        for (int j=0; i<createErrors.length;j++) { 
         System.out.println(createErrors[j]); 
        } 
       } 
      } 


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

    } 

} 
+0

我應該更具體 - 測試用例是一個現有的測試用例,我試圖將所有者更改爲當前用戶:existingTestCase [「Owner」] = restApi.GetCurrentUser()[「_ ref」]。ToString ();不起作用... –

1

GAAH!我非常接近,以至於我偶然發現了答案:

DynamicJsonObject owner = new DynamicJsonObject(); 
owner["Owner"] = restApi.GetCurrentUser()["_ref"].ToString();         
restApi.Update(existingTestCase["_ref"], owner);     

完美地工作 - 感謝您的幫助。