From 417b80f0dfbf97fc2091de960968a9b7cb3edb7b Mon Sep 17 00:00:00 2001 From: Mohammad Azim Khan Date: Fri, 22 Jul 2016 13:10:59 +0100 Subject: [PATCH] Introduced API for updating Build custom field values --- .../testlinkjavaapi/BuildService.java | 33 +++++++++ .../testlinkjavaapi/TestLinkAPI.java | 13 ++++ .../constants/TestLinkMethods.java | 3 +- .../build/TestUpdateBuildCustomFields.java | 72 +++++++++++++++++++ .../testdata/tl.updateBuildCustomFields.xml | 22 ++++++ 5 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 src/test/java/br/eti/kinoshita/testlinkjavaapi/build/TestUpdateBuildCustomFields.java create mode 100644 src/test/resources/br/eti/kinoshita/testlinkjavaapi/testdata/tl.updateBuildCustomFields.xml diff --git a/src/main/java/br/eti/kinoshita/testlinkjavaapi/BuildService.java b/src/main/java/br/eti/kinoshita/testlinkjavaapi/BuildService.java index 58010ce0..9799d1f1 100644 --- a/src/main/java/br/eti/kinoshita/testlinkjavaapi/BuildService.java +++ b/src/main/java/br/eti/kinoshita/testlinkjavaapi/BuildService.java @@ -165,4 +165,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 dfa90200..e0f98061 100644 --- a/src/main/java/br/eti/kinoshita/testlinkjavaapi/TestLinkAPI.java +++ b/src/main/java/br/eti/kinoshita/testlinkjavaapi/TestLinkAPI.java @@ -587,6 +587,19 @@ public Map addPlatformToTestPlan(Integer testProjectId, Integer /** * Creates a Build. * + * @param buildId + * @param testProjectId + * @param customFields + * @return Response + * @throws TestLinkAPIException + */ + 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 * @param buildName * @param buildNotes 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 190f23b6..dd044347 100644 --- a/src/main/java/br/eti/kinoshita/testlinkjavaapi/constants/TestLinkMethods.java +++ b/src/main/java/br/eti/kinoshita/testlinkjavaapi/constants/TestLinkMethods.java @@ -85,7 +85,8 @@ public enum TestLinkMethods { 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") + 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 + + + + + +