Rally API - 通过API更改测试用例所有者

时间:2014-01-22 17:56:16

标签: c# rally

我有来自GetCurrentUser()调用的用户对象,我将测试用例作为DynamicJsonObject,但只是将TestCase [" Owner"]设置为当前用户不起作用 - 任何人都得到了一个代码示例吗?

2 个答案:

答案 0 :(得分:1)

GAAH!我是如此接近,我偶然发现了答案:

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

完美无缺 - 感谢您的帮助。

答案 1 :(得分:0)

Owner属性是对User对象的引用。以下是创建测试用例并设置所有者时的Java示例:

public class CreateTCsetOwner {

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


           String host = "https://rally1.rallydev.com";
            String username = "user@co.com";
            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", "=", "otheruser@co.com"));
        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();
        }   

    } 

}