2014-01-22 52 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);     

完美地工作 - 感谢您的帮助。