diff --git a/src/main/java/br/eti/kinoshita/testlinkjavaapi/BuildService.java b/src/main/java/br/eti/kinoshita/testlinkjavaapi/BuildService.java index 14d20091..61fdf3fa 100644 --- a/src/main/java/br/eti/kinoshita/testlinkjavaapi/BuildService.java +++ b/src/main/java/br/eti/kinoshita/testlinkjavaapi/BuildService.java @@ -149,4 +149,37 @@ protected Map getExecCountersByBuild(Integer testPlanId) { return responseMap; } + /** + * + * @param buildId + * @param testProjectId + * @param customFields + */ + protected Map updateBuildCustomFields(Integer buildId, Integer testProjectId, Integer testPlanId, Map customFields) { + + Map responseMap =null; + + try { + Map executionData = new HashMap(); + + executionData.put(TestLinkParams.BUILD_ID.toString(), buildId); + executionData.put(TestLinkParams.TEST_PROJECT_ID.toString(), testProjectId); + executionData.put(TestLinkParams.TEST_PLAN_ID.toString(), testPlanId); + executionData.put(TestLinkParams.CUSTOM_FIELDS.toString(), customFields); + + Object response = this.executeXmlRpcCall(TestLinkMethods.UPDATE_BUILD_CUSTOM_FIELDS.toString(), + executionData); + if (response instanceof Map) { + responseMap = Util.castToMap(response); + } else if (! (response instanceof String) ) { + responseMap = Util.castToMap(((Object[]) response)[0]); + } + } catch (XmlRpcException xmlrpcex) { + throw new TestLinkAPIException("Error updating Build custom fields. " + xmlrpcex.getMessage(), + xmlrpcex); + } + + return responseMap; + + } } diff --git a/src/main/java/br/eti/kinoshita/testlinkjavaapi/TestLinkAPI.java b/src/main/java/br/eti/kinoshita/testlinkjavaapi/TestLinkAPI.java index 7dbc3b1c..05762cea 100644 --- a/src/main/java/br/eti/kinoshita/testlinkjavaapi/TestLinkAPI.java +++ b/src/main/java/br/eti/kinoshita/testlinkjavaapi/TestLinkAPI.java @@ -603,6 +603,20 @@ public Map addPlatformToTestPlan(Integer testProjectId, Integer /** * Creates a Build. * + * @param buildId Build ID + * @param testProjectId Test Project ID + * @param testPlanId Test Plan ID + * @param customFields Custom Fields name,value pairs + * @return Response XML-RPC Response + * @throws TestLinkAPIException if the service returns as error + */ + public Map updateBuildCustomFields(Integer buildId, Integer testProjectId, Integer testPlanId, Map customFields) throws TestLinkAPIException { + return this.buildService.updateBuildCustomFields(buildId, testProjectId, testPlanId, customFields); + } + + /** + * Creates a Build. + * * @param testPlanId test plan ID * @param buildName build name * @param buildNotes build notes diff --git a/src/main/java/br/eti/kinoshita/testlinkjavaapi/constants/TestLinkMethods.java b/src/main/java/br/eti/kinoshita/testlinkjavaapi/constants/TestLinkMethods.java index 3aab7c60..b904d9aa 100644 --- a/src/main/java/br/eti/kinoshita/testlinkjavaapi/constants/TestLinkMethods.java +++ b/src/main/java/br/eti/kinoshita/testlinkjavaapi/constants/TestLinkMethods.java @@ -29,60 +29,65 @@ */ public enum TestLinkMethods { - ASSIGN_TEST_CASE_EXECUTION_TASK("tl.assignTestCaseExecutionTask"), CREATE_TEST_PROJECT( - "tl.createTestProject"), GET_TEST_PROJECT_BY_NAME("tl.getTestProjectByName"), CHECK_DEV_KEY( - "tl.checkDevKey"), GET_PROJECTS("tl.getProjects"), CREATE_TEST_PLAN( - "tl.createTestPlan"), GET_TEST_PLAN_BY_NAME("tl.getTestPlanByName"), GET_PROJECT_TEST_PLANS( - "tl.getProjectTestPlans"), GET_TEST_PLAN_PLATFORMS( - "tl.getTestPlanPlatforms"), CREATE_TEST_CASE( - "tl.createTestCase"), UPDATE_TEST_CASE( - "tl.updateTestCase"), CREATE_TEST_CASE_STEPS( - "tl.createTestCaseSteps"), DELETE_TEST_CASE_STEPS( - "tl.deleteTestCaseSteps"), CREATE_TEST_SUITE( - "tl.createTestSuite"), ADD_TEST_CASE_TO_TEST_PLAN( - "tl.addTestCaseToTestPlan"), DOES_USER_EXIST( - "tl.doesUserExist"), GET_USER_BY_LOGIN( - "tl.getUserByLogin"), SAY_HELLO( - "tl.sayHello"), ABOUT( - "tl.about"), GET_TEST_SUITE_BY_ID( - "tl.getTestSuiteByID"), SET_TEST_MODE( - "tl.setTestMode"), REPEAT( - "tl.repeat"), GET_TEST_CASE( - "tl.getTestCase"), GET_TEST_CASES_FOR_TEST_SUITE( - "tl.getTestCasesForTestSuite"), CREATE_BUILD( - "tl.createBuild"), GET_TEST_CASES_FOR_TEST_PLAN( - "tl.getTestCasesForTestPlan"), GET_TEST_CASE_ID_BY_NAME( - "tl.getTestCaseIDByName"), GET_TEST_SUITES_FOR_TEST_PLAN( - "tl.getTestSuitesForTestPlan"), UPLOAD_ATTACHMENT( - "tl.uploadAttachment"), UPLOAD_TEST_CASE_ATTACHMENT( - "tl.uploadTestCaseAttachment"), UPLOAD_TEST_SUITE_ATTACHMENT( - "tl.uploadTestSuiteAttachment"), UPLOAD_TEST_PROJECT_ATTACHMENT( - "tl.uploadTestProjectAttachment"), UPLOAD_REQUIREMENT_ATTACHMENT( - "tl.uploadRequirementAttachment"), UPLOAD_REQUIREMENT_SPECIFICATION_ATTACHMENT( - "tl.uploadRequirementSpecificationAttachment"), GET_TEST_CASE_ATTACHMENTS( - "tl.getTestCaseAttachments"), UPLOAD_EXECUTION_ATTACHMENT( - "tl.uploadExecutionAttachment"), DELETE_EXECUTION( - "tl.deleteExecution"), GET_FULL_PATH( - "tl.getFullPath"), ASSIGN_REQUIREMENTS( - "tl.assignRequirements"), GET_TEST_SUITES_FOR_TEST_SUITE( - "tl.getTestSuitesForTestSuite"), GET_FIRST_LEVEL_TEST_SUITES_FOR_TEST_PROJECT( - "tl.getFirstLevelTestSuitesForTestProject"), REPORT_TC_RESULT( - "tl.reportTCResult"), GET_LAST_EXECUTION_RESULT( - "tl.getLastExecutionResult"), GET_BUILDS_FOR_TEST_PLAN( - "tl.getBuildsForTestPlan"), GET_LATEST_BUILD_FOR_TEST_PLAN( - "tl.getLatestBuildForTestPlan"), GET_TEST_CASE_KEYWORDS( - "tl.getTestCaseKeywords"), GET_TEST_CASE_CUSTOM_FIELD_DESIGN_VALUE( - "tl.getTestCaseCustomFieldDesignValue"), GET_TEST_CASE_CUSTOM_FIELD_TEST_PLAN_DESIGN_VALUE( - "tl.getTestCaseCustomFieldTestPlanDesignValue"), GET_TEST_CASE_CUSTOM_FIELD_EXECUTION_VALUE( - "tl.getTestCaseCustomFieldExecutionValue"), GET_TEST_PLAN_CUSTOM_FIELD_DESIGN_VALUE( - "tl.getTestPlanCustomFieldDesignValue"), GET_TOTALS_FOR_TEST_PLAN( - "tl.getTotalsForTestPlan"), GET_EXEC_COUNTERS_BY_BUILD( - "tl.getExecCountersByBuild"), UPDATE_TEST_CASE_CUSTOM_FIELD_VALUE( - "tl.updateTestCaseCustomFieldDesignValue"), SET_TEST_CASE_EXECUTION_TYPE( - "tl.setTestCaseExecutionType"), GET_PROJECT_PLATFORMS( - "tl.getProjectPlatforms"), REMOVE_PLATFORM_FROM_TEST_PLAN( - "tl.removePlatformFromTestPlan"), ADD_PLATFORM_TO_TEST_PLAN( - "tl.addPlatformToTestPlan"); + ASSIGN_TEST_CASE_EXECUTION_TASK("tl.assignTestCaseExecutionTask"), + CREATE_TEST_PROJECT("tl.createTestProject"), + GET_TEST_PROJECT_BY_NAME("tl.getTestProjectByName"), + CHECK_DEV_KEY("tl.checkDevKey"), + GET_PROJECTS("tl.getProjects"), + CREATE_TEST_PLAN("tl.createTestPlan"), + GET_TEST_PLAN_BY_NAME("tl.getTestPlanByName"), + GET_PROJECT_TEST_PLANS("tl.getProjectTestPlans"), + GET_TEST_PLAN_PLATFORMS("tl.getTestPlanPlatforms"), + CREATE_TEST_CASE("tl.createTestCase"), + UPDATE_TEST_CASE("tl.updateTestCase"), + CREATE_TEST_CASE_STEPS("tl.createTestCaseSteps"), + DELETE_TEST_CASE_STEPS("tl.deleteTestCaseSteps"), + CREATE_TEST_SUITE("tl.createTestSuite"), + ADD_TEST_CASE_TO_TEST_PLAN("tl.addTestCaseToTestPlan"), + DOES_USER_EXIST("tl.doesUserExist"), + GET_USER_BY_LOGIN("tl.getUserByLogin"), + SAY_HELLO("tl.sayHello"), + ABOUT("tl.about"), + GET_TEST_SUITE_BY_ID("tl.getTestSuiteByID"), + SET_TEST_MODE("tl.setTestMode"), + REPEAT("tl.repeat"), + GET_TEST_CASE("tl.getTestCase"), + GET_TEST_CASES_FOR_TEST_SUITE("tl.getTestCasesForTestSuite"), + CREATE_BUILD("tl.createBuild"), + GET_TEST_CASES_FOR_TEST_PLAN("tl.getTestCasesForTestPlan"), + GET_TEST_CASE_ID_BY_NAME("tl.getTestCaseIDByName"), + GET_TEST_SUITES_FOR_TEST_PLAN("tl.getTestSuitesForTestPlan"), + UPLOAD_ATTACHMENT("tl.uploadAttachment"), + UPLOAD_TEST_CASE_ATTACHMENT("tl.uploadTestCaseAttachment"), + UPLOAD_TEST_SUITE_ATTACHMENT("tl.uploadTestSuiteAttachment"), + UPLOAD_TEST_PROJECT_ATTACHMENT("tl.uploadTestProjectAttachment"), + UPLOAD_REQUIREMENT_ATTACHMENT("tl.uploadRequirementAttachment"), + UPLOAD_REQUIREMENT_SPECIFICATION_ATTACHMENT("tl.uploadRequirementSpecificationAttachment"), + GET_TEST_CASE_ATTACHMENTS("tl.getTestCaseAttachments"), + UPLOAD_EXECUTION_ATTACHMENT("tl.uploadExecutionAttachment"), + DELETE_EXECUTION("tl.deleteExecution"), + GET_FULL_PATH("tl.getFullPath"), + ASSIGN_REQUIREMENTS("tl.assignRequirements"), + GET_TEST_SUITES_FOR_TEST_SUITE("tl.getTestSuitesForTestSuite"), + GET_FIRST_LEVEL_TEST_SUITES_FOR_TEST_PROJECT("tl.getFirstLevelTestSuitesForTestProject"), + REPORT_TC_RESULT("tl.reportTCResult"), + GET_LAST_EXECUTION_RESULT("tl.getLastExecutionResult"), + GET_BUILDS_FOR_TEST_PLAN("tl.getBuildsForTestPlan"), + GET_LATEST_BUILD_FOR_TEST_PLAN("tl.getLatestBuildForTestPlan"), + GET_TEST_CASE_KEYWORDS("tl.getTestCaseKeywords"), + GET_TEST_CASE_CUSTOM_FIELD_DESIGN_VALUE("tl.getTestCaseCustomFieldDesignValue"), + GET_TEST_CASE_CUSTOM_FIELD_TEST_PLAN_DESIGN_VALUE("tl.getTestCaseCustomFieldTestPlanDesignValue"), + GET_TEST_CASE_CUSTOM_FIELD_EXECUTION_VALUE("tl.getTestCaseCustomFieldExecutionValue"), + GET_TEST_PLAN_CUSTOM_FIELD_DESIGN_VALUE("tl.getTestPlanCustomFieldDesignValue"), + GET_TOTALS_FOR_TEST_PLAN("tl.getTotalsForTestPlan"), + GET_EXEC_COUNTERS_BY_BUILD("tl.getExecCountersByBuild"), + UPDATE_TEST_CASE_CUSTOM_FIELD_VALUE("tl.updateTestCaseCustomFieldDesignValue"), + SET_TEST_CASE_EXECUTION_TYPE("tl.setTestCaseExecutionType"), + GET_PROJECT_PLATFORMS("tl.getProjectPlatforms"), + REMOVE_PLATFORM_FROM_TEST_PLAN("tl.removePlatformFromTestPlan"), + ADD_PLATFORM_TO_TEST_PLAN("tl.addPlatformToTestPlan"), + UPDATE_BUILD_CUSTOM_FIELDS("tl.updateBuildCustomFieldsValues") + ; private String value; diff --git a/src/test/java/br/eti/kinoshita/testlinkjavaapi/build/TestUpdateBuildCustomFields.java b/src/test/java/br/eti/kinoshita/testlinkjavaapi/build/TestUpdateBuildCustomFields.java new file mode 100644 index 00000000..d4cfc7f1 --- /dev/null +++ b/src/test/java/br/eti/kinoshita/testlinkjavaapi/build/TestUpdateBuildCustomFields.java @@ -0,0 +1,72 @@ +/* + * The MIT License + * + * Copyright (c) <2010> + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package br.eti.kinoshita.testlinkjavaapi.build; + +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import br.eti.kinoshita.testlinkjavaapi.BaseTest; +import br.eti.kinoshita.testlinkjavaapi.model.TestCase; +import br.eti.kinoshita.testlinkjavaapi.util.TestLinkAPIException; +import org.testng.mustache.Value; + +import java.util.HashMap; + +/** + * @author Mohammad Azim Khan - https://github.com/mazimkhan + * @since 1.0 + */ +public class TestUpdateBuildCustomFields extends BaseTest { + + @DataProvider(name = "buildcfdata") + public Object[][] createData() { + return new Object[][] { + { 2, 1, 3, "new", "Yahoo" } + }; + } + + @Test(dataProvider = "buildcfdata") + public void testUpdateBuildCustomFields(Integer buildId, Integer testProjectId, Integer testPlanId, String cfname, String cfvalue) { + this.loadXMLRPCMockData("tl.updateBuildCustomFields.xml"); + + java.util.Map customFields = new HashMap(); + customFields.put(cfname, cfvalue); + + java.util.Map response = null; + + try { + response = api.updateBuildCustomFields(buildId, testProjectId, testPlanId, customFields); + } catch (TestLinkAPIException e) { + Assert.fail(e.getMessage(), e); + } + + Assert.assertNotNull(response); + System.out.println(response.toString()); + Assert.assertTrue(Integer.parseInt(response.get("buildid").toString()) > 0); + Assert.assertTrue(Integer.parseInt(response.get("testplanid").toString()) > 0); + Assert.assertTrue(Integer.parseInt(response.get("testprojectid").toString()) > 0); + } + +} diff --git a/src/test/resources/br/eti/kinoshita/testlinkjavaapi/testdata/tl.updateBuildCustomFields.xml b/src/test/resources/br/eti/kinoshita/testlinkjavaapi/testdata/tl.updateBuildCustomFields.xml new file mode 100644 index 00000000..694c606a --- /dev/null +++ b/src/test/resources/br/eti/kinoshita/testlinkjavaapi/testdata/tl.updateBuildCustomFields.xml @@ -0,0 +1,22 @@ + + + + + + + + buildid2 + testplanid3 + testprojectid1 + devKeyf3230e0850876097abdfef4e3cd01145 + + + 2 + 2 + /* Class:testcase - Method: setExecutionType */ UPDATE tcversions SET execution_type=2 WHERE id = 5 + + + + + +