Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java rally api-如何使用集合创建步骤,而不是逐个创建步骤1_Java_Rallyapi - Fatal编程技术网

Java rally api-如何使用集合创建步骤,而不是逐个创建步骤1

Java rally api-如何使用集合创建步骤,而不是逐个创建步骤1,java,rallyapi,Java,Rallyapi,我正在使用rally dev api 2.2.1,并尝试在1GO中创建步骤。而不是一个接一个地循环和创建 我写了这个,它工作得很好,但是创建了一个接一个的步骤,需要时间 private void updateSteps(TestCase testCase, JsonObject createResponse) { try { String testCaseRef = createResponse.get("_ref").getAsStr

我正在使用rally dev api 2.2.1,并尝试在1GO中创建步骤。而不是一个接一个地循环和创建

我写了这个,它工作得很好,但是创建了一个接一个的步骤,需要时间

private void updateSteps(TestCase testCase, JsonObject createResponse) {
        try {
            String testCaseRef = createResponse.get("_ref").getAsString();
            String testCaseID = createResponse.get("FormattedID").getAsString();
            final int[] stepCount = {1};
            LOGGER.info("*-*-*-*-*-*-*-*-*-*-*-*-*-*-* Creating steps for " + testCaseID + " *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
            testCase.getTestCaseSteps().forEach(step -> {
                try {
                    StopWatch timer = new StopWatch();
                    timer.start();
                    executeDBGetStep(step);
                    JsonObject stepRequest = new JsonObject();
                    stepRequest.addProperty("TestCase", testCaseRef);
                    stepRequest.addProperty("StepIndex", stepCount[0]);
                    stepRequest.addProperty("Input", step.getTestStepDescription() + "<br/><br/>" + format(this.getObjectAsString(step.getTestStepDataRequest(true))));
                    if (step.getTestStepAssert() == null) {
                        stepRequest.addProperty("ExpectedResult", "As Expected");
                    } else {
                        JsonNode assertObject;
                        try {
                            assertObject = step.getTestStepAssert(true);
                        } catch (Exception ex) {
                            assertObject = step.getTestStepAssert(false);
                        }
                        stepRequest.addProperty("ExpectedResult", format(this.getObjectAsString(assertObject)));
                    }
                    CreateRequest createStepRequest = new CreateRequest("testCaseStep", stepRequest);
                    CreateResponse createStepResponse = this.rallyClient.getRestApi().create(createStepRequest);
                    timer.stop();
                    if (ExceptionHandlers.isResponseSuccessful(createStepResponse)) {
                        LOGGER.info("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
                        LOGGER.info("Step " + stepCount[0] + " created for test case " + testCaseID + " in " + timer.getLastTaskTimeMillis() + " milliseconds");
                        LOGGER.info("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
                    }
                    stepCount[0]++;
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            });
            LOGGER.info("*-*-*-*-*-*-*-*-*-*-*-* Finished creating steps for " + testCaseID + " -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

private void updatesps(TestCase TestCase,JsonObject createResponse){
试一试{
字符串testCaseRef=createResponse.get(“_ref”).getAsString();
字符串testCaseID=createResponse.get(“FormattedID”).getAsString();
最终int[]步数={1};
LOGGER.info(“*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*”);
testCase.getTestCaseSteps().forEach(步骤->{
试一试{
秒表计时器=新秒表();
timer.start();
已执行的bGetStep(步骤);
JsonObject stepRequest=新的JsonObject();
addProperty(“TestCase”,testCaseRef);
stepRequest.addProperty(“StepIndex”,stepCount[0]);
stepRequest.addProperty(“输入”,step.getTestStepDescription()+”

“+格式(此.getObjectAsString(step.getTestStepDataRequest(true))); if(step.getTestStepAssert()==null){ stepRequest.addProperty(“ExpectedResult”,“按预期”); }否则{ JsonNode assertObject; 试一试{ assertObject=step.getTestStepAssert(true); }捕获(例外情况除外){ assertObject=step.getTestStepAssert(false); } addProperty(“ExpectedResult”,格式为this.getObjectAsString(assertObject)); } CreateRequest createStepRequest=新建CreateRequest(“testCaseStep”,stepRequest); CreateResponse createStepResponse=this.rallyClient.getRestApi().create(createStepRequest); timer.stop(); if(ExceptionHandlers.isResponseSuccessful(createStepResponse)){ LOGGER.info(“*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*; LOGGER.info(“步骤”+stepCount[0]+”为“+timer.getLastTaskTimeMillis()+”毫秒”中的测试用例“+testCaseID+”创建); LOGGER.info(“*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*; } 步数[0]++; }捕获(IOEX异常){ 例如printStackTrace(); } }); LOGGER.info(“*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*”)完成了“+testCaseID+”的创建步骤; }捕获(例外情况除外){ 例如printStackTrace(); } }
到目前为止,我已经尝试了这个方法,但我发现404找不到,因为我假设在执行collectionUpdate时,它正在请求中查找_ref对象,并且因为我是第一次创建它,所以引用不存在,它抛出了这个错误

private void updateSteps(TestCase testCase, JsonObject createResponse) {
        try {
            String testCaseRef = createResponse.get("_ref").getAsString();
            String testCaseID = createResponse.get("FormattedID").getAsString();
            final int[] stepCount = {1};
            LOGGER.info("*-*-*-*-*-*-*-*-*-*-*-*-*-*-* Creating steps for " + testCaseID + " *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
            StopWatch timer = new StopWatch();
            timer.start();
            JsonArray stepsTobeUpdated = new JsonArray();
            testCase.getTestCaseSteps().forEach(step -> {
                executeDBGetStep(step);
                JsonObject stepRequest = new JsonObject();
                JsonObject testCaseObject = new JsonObject();
                testCaseObject.addProperty("_ref", testCaseRef);
                stepRequest.add("TestCase", testCaseObject);
                stepRequest.addProperty("StepIndex", stepCount[0]);
                stepRequest.addProperty("Input", step.getTestStepDescription() + "<br/><br/>" + format(this.getObjectAsString(step.getTestStepDataRequest(true))));
                if (step.getTestStepAssert() == null) {
                    stepRequest.addProperty("ExpectedResult", "As Expected");
                } else {
                    JsonNode assertObject;
                    try {
                        assertObject = step.getTestStepAssert(true);
                    } catch (Exception ex) {
                        assertObject = step.getTestStepAssert(false);
                    }
                    stepRequest.addProperty("ExpectedResult", format(this.getObjectAsString(assertObject)));
                }
                stepsTobeUpdated.add(stepRequest);
                stepCount[0]++;
            });


            CollectionUpdateRequest testStepCollectionAddRequest = new CollectionUpdateRequest(testCaseRef + "/steps", stepsTobeUpdated, true);
            try {
                CollectionUpdateResponse testStepCollectionAddResponse = rallyClient.getRestApi().updateCollection(testStepCollectionAddRequest);
                if (ExceptionHandlers.isResponseSuccessful(testStepCollectionAddResponse)) {
                    LOGGER.info(stepsTobeUpdated.size() + " steps updated/created in test case " + testCase.getTestCaseCode());
                } else {
                    ExceptionHandlers.getErrors("Error while updating/creating steps in test case ").forEach(LOGGER::error);
                }
            } catch (IOException exception) {
                throw new IllegalStateException(exception);
            }
            timer.stop();

            LOGGER.info("*-*-*-*-*-*-*-*-*-*-*-* Finished creating steps for " + testCaseID + " -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
private void updatesps(TestCase TestCase,JsonObject createResponse){
试一试{
字符串testCaseRef=createResponse.get(“_ref”).getAsString();
字符串testCaseID=createResponse.get(“FormattedID”).getAsString();
最终int[]步数={1};
LOGGER.info(“*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*”);
秒表计时器=新秒表();
timer.start();
JsonArray stepsTobeUpdated=新的JsonArray();
testCase.getTestCaseSteps().forEach(步骤->{
已执行的bGetStep(步骤);
JsonObject stepRequest=新的JsonObject();
JsonObject testCaseObject=新的JsonObject();
addProperty(“\u ref”,testCaseRef);
添加(“TestCase”,testCaseObject);
stepRequest.addProperty(“StepIndex”,stepCount[0]);
stepRequest.addProperty(“输入”,step.getTestStepDescription()+”

“+格式(此.getObjectAsString(step.getTestStepDataRequest(true))); if(step.getTestStepAssert()==null){ stepRequest.addProperty(“ExpectedResult”,“按预期”); }否则{ JsonNode assertObject; 试一试{ assertObject=step.getTestStepAssert(true); }捕获(例外情况除外){ assertObject=step.getTestStepAssert(false); } addProperty(“ExpectedResult”,格式为this.getObjectAsString(assertObject)); } 步骤stobeupdated.add(步骤请求); 步数[0]++; }); CollectionUpdateRequest TestStepCollectionAddressRequest=新的CollectionUpdateRequest(testCaseRef+“/steps”,StepStobeUpdate,true); 试一试{ CollectionUpdateResponse TestStepCollectionAddressResponse=rallyClient.getRestApi().updateCollection(TestStepCollectionAddressRequest); if(ExceptionHandlers.isResponseSuccessful(TestStepCollectionAddressResponse)){ LOGGER.info(stepsTobeUpdated.size()+“在测试用例中更新/创建的步骤”+testCase.getTestCaseCode()); }否则{ ExceptionHandlers.getErrors(“在测试用例中更新/创建步骤时出错”).forEach(LOGGER::Error); } }捕获(IOException异常){ 抛出新的IllegalStateException(异常); } timer.stop(); 记录器。