From a6096d798c64e5f8c1ca5c95d4084f9f0ab014a8 Mon Sep 17 00:00:00 2001 From: Mohamed Amine BERGAOUI Date: Thu, 5 Sep 2013 17:21:03 +0200 Subject: [PATCH] adding platform management --- .../testlink/AbstractTestLinkBuilder.java | 13 ++++++ .../plugins/testlink/TestLinkBuilder.java | 29 ++++++++++---- .../hudson/plugins/testlink/TestLinkSite.java | 40 ++++++++++++++++--- .../testlink/TestLinkBuilder/config.jelly | 4 ++ .../TestLinkBuilder/config.properties | 1 + .../TestLinkBuilder/config_es.properties | 1 + .../TestLinkBuilder/config_pt.properties | 1 + .../plugins/testlink/TestLinkSiteFake.java | 2 +- .../plugins/testlink/TestTestLinkBuilder.java | 23 +++++++---- 9 files changed, 93 insertions(+), 21 deletions(-) diff --git a/src/main/java/hudson/plugins/testlink/AbstractTestLinkBuilder.java b/src/main/java/hudson/plugins/testlink/AbstractTestLinkBuilder.java index 936d206..59cc55b 100644 --- a/src/main/java/hudson/plugins/testlink/AbstractTestLinkBuilder.java +++ b/src/main/java/hudson/plugins/testlink/AbstractTestLinkBuilder.java @@ -72,6 +72,10 @@ public class AbstractTestLinkBuilder extends Builder { /** * The name of the Build. */ + protected final String platformName; + /** + * The platform name. + */ protected String buildName; /** @@ -171,6 +175,7 @@ public AbstractTestLinkBuilder( String testLinkName, String testProjectName, String testPlanName, + String platformName, String buildName, String customFields, Boolean executionStatusNotRun, @@ -190,6 +195,7 @@ public AbstractTestLinkBuilder( this.testLinkName = testLinkName; this.testProjectName = testProjectName; this.testPlanName = testPlanName; + this.platformName = platformName; this.buildName = buildName; this.customFields = customFields; this.executionStatusNotRun = executionStatusNotRun; @@ -229,6 +235,7 @@ public AbstractTestLinkBuilder( String testLinkName, String testProjectName, String testPlanName, + String platformName, String buildName, String customFields, Boolean executionStatusNotRun, @@ -249,6 +256,7 @@ public AbstractTestLinkBuilder( this.testLinkName = testLinkName; this.testProjectName = testProjectName; this.testPlanName = testPlanName; + this.platformName = platformName; this.buildName = buildName; this.customFields = customFields; this.executionStatusNotRun = executionStatusNotRun; @@ -295,6 +303,11 @@ public String getTestPlanName() return this.testPlanName; } + public String getPlatformName() + { + return this.platformName; + } + public String getBuildName() { return this.buildName; diff --git a/src/main/java/hudson/plugins/testlink/TestLinkBuilder.java b/src/main/java/hudson/plugins/testlink/TestLinkBuilder.java index bcc76fb..41c8cae 100644 --- a/src/main/java/hudson/plugins/testlink/TestLinkBuilder.java +++ b/src/main/java/hudson/plugins/testlink/TestLinkBuilder.java @@ -55,6 +55,7 @@ import br.eti.kinoshita.testlinkjavaapi.TestLinkAPI; import br.eti.kinoshita.testlinkjavaapi.constants.ExecutionStatus; import br.eti.kinoshita.testlinkjavaapi.model.Build; +import br.eti.kinoshita.testlinkjavaapi.model.Platform; import br.eti.kinoshita.testlinkjavaapi.model.TestCase; import br.eti.kinoshita.testlinkjavaapi.model.TestPlan; import br.eti.kinoshita.testlinkjavaapi.model.TestProject; @@ -80,7 +81,7 @@ public class TestLinkBuilder extends AbstractTestLinkBuilder { * @deprecated */ public TestLinkBuilder(String testLinkName, String testProjectName, - String testPlanName, String buildName, String customFields, + String testPlanName, String platformName, String buildName, String customFields, Boolean executionStatusNotRun, Boolean executionStatusPassed, Boolean executionStatusFailed, Boolean executionStatusBlocked, List singleBuildSteps, @@ -89,7 +90,7 @@ public TestLinkBuilder(String testLinkName, String testProjectName, List afterIteratingAllTestCasesBuildSteps, Boolean transactional, Boolean failedTestsMarkBuildAsFailure, Boolean failIfNoResults, List resultSeekers) { - super(testLinkName, testProjectName, testPlanName, buildName, + super(testLinkName, testProjectName, testPlanName, platformName, buildName, customFields, executionStatusNotRun, executionStatusPassed, executionStatusFailed, executionStatusBlocked, singleBuildSteps, beforeIteratingAllTestCasesBuildSteps, iterativeBuildSteps, @@ -99,7 +100,7 @@ public TestLinkBuilder(String testLinkName, String testProjectName, @DataBoundConstructor public TestLinkBuilder(String testLinkName, String testProjectName, - String testPlanName, String buildName, String customFields, + String testPlanName, String platformName, String buildName, String customFields, Boolean executionStatusNotRun, Boolean executionStatusPassed, Boolean executionStatusFailed, Boolean executionStatusBlocked, List singleBuildSteps, @@ -108,7 +109,7 @@ public TestLinkBuilder(String testLinkName, String testProjectName, List afterIteratingAllTestCasesBuildSteps, Boolean transactional, Boolean failedTestsMarkBuildAsFailure, Boolean failIfNoResults, Boolean failOnNotRun, List resultSeekers) { - super(testLinkName, testProjectName, testPlanName, buildName, + super(testLinkName, testProjectName, testPlanName, platformName, buildName, customFields, executionStatusNotRun, executionStatusPassed, executionStatusFailed, executionStatusBlocked, singleBuildSteps, beforeIteratingAllTestCasesBuildSteps, iterativeBuildSteps, @@ -148,6 +149,8 @@ public boolean perform(AbstractBuild build, Launcher launcher, build.getEnvironment(listener), getTestProjectName()); final String testPlanName = expandVariable(build.getBuildVariableResolver(), build.getEnvironment(listener), getTestPlanName()); + final String platformName = expandVariable(build.getBuildVariableResolver(), + build.getEnvironment(listener), getPlatformName()); final String buildName = expandVariable(build.getBuildVariableResolver(), build.getEnvironment(listener), getBuildName()); final String buildNotes = Messages.TestLinkBuilder_Build_Notes(); @@ -158,7 +161,7 @@ public boolean perform(AbstractBuild build, Launcher launcher, LOGGER.log(Level.FINE, "TestLink build notes: ["+buildNotes+"]"); } // TestLink Site object - testLinkSite = this.getTestLinkSite(testLinkUrl, testLinkDevKey, testProjectName, testPlanName, buildName, buildNotes); + testLinkSite = this.getTestLinkSite(testLinkUrl, testLinkDevKey, testProjectName, testPlanName, platformName, buildName, buildNotes); final String[] customFieldsNames = this.createArrayOfCustomFieldsNames(build.getBuildVariableResolver(), build.getEnvironment(listener)); final Set executionStatuses = this.getExecutionStatuses(); // Array of automated test cases @@ -273,7 +276,7 @@ private TestCaseWrapper[] transform(TestCase[] testCases) { */ public TestLinkSite getTestLinkSite(String testLinkUrl, String testLinkDevKey, String testProjectName, String testPlanName, - String buildName, String buildNotes) throws MalformedURLException { + String platformName, String buildName, String buildNotes) throws MalformedURLException { final TestLinkAPI api; final URL url = new URL(testLinkUrl); api = new TestLinkAPI(url, testLinkDevKey); @@ -283,11 +286,23 @@ public TestLinkSite getTestLinkSite(String testLinkUrl, final TestPlan testPlan = api.getTestPlanByName(testPlanName, testProjectName); + + Platform p = null; + if (!platformName.equals("")){ + Platform platforms[] = api.getProjectPlatforms(testProject.getId()); + for (int i = 0; i < platforms.length; i++) { + if (platforms[i].getName().equals(platformName)) { + p = platforms[i]; + break; + } + } + } + final Platform platform = p; final Build build = api.createBuild(testPlan.getId(), buildName, buildNotes); - return new TestLinkSite(api, testProject, testPlan, build); + return new TestLinkSite(api, testProject, testPlan, platform, build); } /** diff --git a/src/main/java/hudson/plugins/testlink/TestLinkSite.java b/src/main/java/hudson/plugins/testlink/TestLinkSite.java index 9cba2fc..e20071d 100644 --- a/src/main/java/hudson/plugins/testlink/TestLinkSite.java +++ b/src/main/java/hudson/plugins/testlink/TestLinkSite.java @@ -40,6 +40,7 @@ import br.eti.kinoshita.testlinkjavaapi.model.TestCase; import br.eti.kinoshita.testlinkjavaapi.model.TestPlan; import br.eti.kinoshita.testlinkjavaapi.model.TestProject; +import br.eti.kinoshita.testlinkjavaapi.model.Platform; /** * Immutable object that represents the TestLink site with a Test Project, @@ -54,6 +55,7 @@ public class TestLinkSite protected final TestLinkAPI api; protected final TestProject testProject; protected final TestPlan testPlan; + protected final Platform platform; protected final Build build; protected final Report report; @@ -63,12 +65,13 @@ public class TestLinkSite * @param testPlan TestLink Test Plan * @param build TestLink Build */ - public TestLinkSite(TestLinkAPI api, TestProject testProject, TestPlan testPlan, Build build) + public TestLinkSite(TestLinkAPI api, TestProject testProject, TestPlan testPlan, Platform platform, Build build) { super(); this.api = api; this.testProject = testProject; this.testPlan = testPlan; + this.platform = platform; this.build = build; if(build != null) { @@ -101,7 +104,15 @@ public TestPlan getTestPlan() { return testPlan; } - + + /** + * @return the platform + */ + public Platform getPlatform() + { + return platform; + } + /** * @return the build */ @@ -185,7 +196,25 @@ public int updateTestCase(TestCaseWrapper testCase) { && !ExecutionStatus.NOT_RUN.equals(testCase .getExecutionStatus())) { // Update Test Case status - final ReportTCResultResponse reportTCResultResponse = api.reportTCResult( + ReportTCResultResponse reportTCResultResponse = null; + if (platform != null){ + reportTCResultResponse = api.reportTCResult( + testCase.getId(), + testCase.getInternalId(), + testPlan.getId(), + testCase.getExecutionStatus(), + build.getId(), + build.getName(), + testCase.getNotes(), + null, // guess + null, // bug id + platform.getId(), + platform.getName(), + null, // custom fields + null); + } + else { + reportTCResultResponse = api.reportTCResult( testCase.getId(), testCase.getInternalId(), testPlan.getId(), @@ -195,10 +224,11 @@ public int updateTestCase(TestCaseWrapper testCase) { testCase.getNotes(), null, // guess null, // bug id - null, // platform id - testCase.getPlatform(), // platform name + null, + null, // platform name null, // custom fields null); + } switch(testCase.getExecutionStatus()) { case PASSED: diff --git a/src/main/resources/hudson/plugins/testlink/TestLinkBuilder/config.jelly b/src/main/resources/hudson/plugins/testlink/TestLinkBuilder/config.jelly index cf2940c..e3cb2c2 100644 --- a/src/main/resources/hudson/plugins/testlink/TestLinkBuilder/config.jelly +++ b/src/main/resources/hudson/plugins/testlink/TestLinkBuilder/config.jelly @@ -20,6 +20,10 @@ + + + + diff --git a/src/main/resources/hudson/plugins/testlink/TestLinkBuilder/config.properties b/src/main/resources/hudson/plugins/testlink/TestLinkBuilder/config.properties index ea224ae..6b58666 100644 --- a/src/main/resources/hudson/plugins/testlink/TestLinkBuilder/config.properties +++ b/src/main/resources/hudson/plugins/testlink/TestLinkBuilder/config.properties @@ -1,6 +1,7 @@ Test\Link\ Version=TestLink Version Test\ Project\ Name=Test Project Name Test\ Plan\ Name=Test Plan Name +Platform\ Name=Platform Name Build\ Name=Build Name Custom\ Fields=Custom Fields Key\ Custom\ Field=Key Custom Field diff --git a/src/main/resources/hudson/plugins/testlink/TestLinkBuilder/config_es.properties b/src/main/resources/hudson/plugins/testlink/TestLinkBuilder/config_es.properties index 004aa12..bf41081 100644 --- a/src/main/resources/hudson/plugins/testlink/TestLinkBuilder/config_es.properties +++ b/src/main/resources/hudson/plugins/testlink/TestLinkBuilder/config_es.properties @@ -1,6 +1,7 @@ Test\Link\ Version=Versión del TestLink Test\ Project\ Name=Nombre del Proyecto de Pruebas Test\ Plan\ Name=Nombre del Plan de Pruebas +Platform\ Name=Nombre de la Plataforma Build\ Name=Nombre del Build Custom\ Fields=Campos personalizados Key\ Custom\ Field=Campo customizado chave para testes automatizados do TestLink diff --git a/src/main/resources/hudson/plugins/testlink/TestLinkBuilder/config_pt.properties b/src/main/resources/hudson/plugins/testlink/TestLinkBuilder/config_pt.properties index a881ee9..3db0262 100644 --- a/src/main/resources/hudson/plugins/testlink/TestLinkBuilder/config_pt.properties +++ b/src/main/resources/hudson/plugins/testlink/TestLinkBuilder/config_pt.properties @@ -1,6 +1,7 @@ Test\Link\ Version=Versão do TestLink Test\ Project\ Name=Nome do Projeto de Testes Test\ Plan\ Name=Nome do Plano de Testes +Platform\ Name=Nome da Plataforma Build\ Name=Nome do Build Custom\ Fields=Campos customizados Key\ Custom\ Field=Campo customizado chave para testes automatizados do TestLink diff --git a/src/test/java/hudson/plugins/testlink/TestLinkSiteFake.java b/src/test/java/hudson/plugins/testlink/TestLinkSiteFake.java index 29665c1..22dcff5 100644 --- a/src/test/java/hudson/plugins/testlink/TestLinkSiteFake.java +++ b/src/test/java/hudson/plugins/testlink/TestLinkSiteFake.java @@ -41,7 +41,7 @@ public class TestLinkSiteFake extends TestLinkSite { protected List testCases = new LinkedList(); public TestLinkSiteFake() { - super(null, null, null, new Build(1, 1, "Fake build", "Fake notes")); + super(null, null, null, null, new Build(1, 1, "Fake build", "Fake notes")); } /* (non-Javadoc) diff --git a/src/test/java/hudson/plugins/testlink/TestTestLinkBuilder.java b/src/test/java/hudson/plugins/testlink/TestTestLinkBuilder.java index 2544e1a..541413f 100644 --- a/src/test/java/hudson/plugins/testlink/TestTestLinkBuilder.java +++ b/src/test/java/hudson/plugins/testlink/TestTestLinkBuilder.java @@ -64,6 +64,7 @@ public void setUp() "No testlink", "No project", "No plan", + "No platform", "No build", "class, time, sample-job-$BUILD_ID", Boolean.FALSE, @@ -103,7 +104,7 @@ public void testListOfCustomFields() public void testNull() { - builder = new TestLinkBuilder(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null); + builder = new TestLinkBuilder(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null); assertNotNull( builder ); @@ -113,6 +114,8 @@ public void testNull() assertNull( builder.getTestPlanName() ); + assertNull( builder.getPlatformName() ); + assertNull( builder.getBuildName() ); assertNull( builder.getSingleBuildSteps() ); @@ -147,6 +150,7 @@ public void testGetters() "No testlink", "No project", "No plan", + "No platform", "No build", "class, time", Boolean.FALSE, @@ -176,6 +180,9 @@ public void testGetters() assertNotNull( builder.getTestPlanName() ); assertEquals( builder.getTestPlanName(), "No plan" ); + assertNotNull( builder.getPlatformName() ); + assertEquals( builder.getPlatformName(), "No platform" ); + assertNotNull( builder.getBuildName() ); assertEquals( builder.getBuildName(), "No build" ); @@ -194,7 +201,7 @@ public void testGetters() @Test public void getExecutionStatusesShouldReturnAllWhenAllAreFalse() { - builder = new TestLinkBuilder(null, null, null, null, null, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, null, null, null, null, null, null, null, null, null ); + builder = new TestLinkBuilder(null, null, null, null, null, null, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, null, null, null, null, null, null, null, null, null ); Set statuses = builder.getExecutionStatuses(); assertThat(statuses, hasSize(4)); assertThat( @@ -205,7 +212,7 @@ public void getExecutionStatusesShouldReturnAllWhenAllAreFalse() { @Test public void getExecutionStatusesShouldReturnAllWhenAllAreNull() { - builder = new TestLinkBuilder(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null ); + builder = new TestLinkBuilder(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null ); Set statuses = builder.getExecutionStatuses(); assertThat(statuses, hasSize(4)); assertThat( @@ -216,7 +223,7 @@ public void getExecutionStatusesShouldReturnAllWhenAllAreNull() { @Test public void getExecutionStatusesShouldReturnSomeWhenSomeAreTrue() { - builder = new TestLinkBuilder(null, null, null, null, null, Boolean.TRUE, Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, null, null, null, null, null, null, null, null, null); + builder = new TestLinkBuilder(null, null, null, null, null, null, Boolean.TRUE, Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, null, null, null, null, null, null, null, null, null); Set statuses = builder.getExecutionStatuses(); assertThat(statuses, hasSize(2)); assertThat( @@ -226,7 +233,7 @@ public void getExecutionStatusesShouldReturnSomeWhenSomeAreTrue() { @Test public void getExecutionStatusesShouldOneSomeWhenNotRunIsTrue() { - builder = new TestLinkBuilder(null, null, null, null, null, Boolean.TRUE, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, null, null, null, null, null, null, null, null, null); + builder = new TestLinkBuilder(null, null, null, null, null, null, Boolean.TRUE, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, null, null, null, null, null, null, null, null, null); Set statuses = builder.getExecutionStatuses(); assertThat(statuses, hasSize(1)); assertThat( @@ -236,7 +243,7 @@ public void getExecutionStatusesShouldOneSomeWhenNotRunIsTrue() { @Test public void getExecutionStatusesShouldOneSomeWhenPassedIsTrue() { - builder = new TestLinkBuilder(null, null, null, null, null, Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, Boolean.FALSE, null, null, null, null, null, null, null, null, null); + builder = new TestLinkBuilder(null, null, null, null, null, null, Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, Boolean.FALSE, null, null, null, null, null, null, null, null, null); Set statuses = builder.getExecutionStatuses(); assertThat(statuses, hasSize(1)); assertThat( @@ -246,7 +253,7 @@ public void getExecutionStatusesShouldOneSomeWhenPassedIsTrue() { @Test public void getExecutionStatusesShouldOneSomeWhenFailedIsTrue() { - builder = new TestLinkBuilder(null, null, null, null, null, Boolean.FALSE, Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, null, null, null, null, null, null, null, null, null); + builder = new TestLinkBuilder(null, null, null, null, null, null, Boolean.FALSE, Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, null, null, null, null, null, null, null, null, null); Set statuses = builder.getExecutionStatuses(); assertThat(statuses, hasSize(1)); assertThat( @@ -256,7 +263,7 @@ public void getExecutionStatusesShouldOneSomeWhenFailedIsTrue() { @Test public void getExecutionStatusesShouldOneSomeWhenBlockedIsTrue() { - builder = new TestLinkBuilder(null, null, null, null, null, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, Boolean.TRUE, null, null, null, null, null, null, null, null, null); + builder = new TestLinkBuilder(null, null, null, null, null, null, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, Boolean.TRUE, null, null, null, null, null, null, null, null, null); Set statuses = builder.getExecutionStatuses(); assertThat(statuses, hasSize(1)); assertThat(