Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement for updating build custom fields values #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/main/java/hudson/plugins/testlink/AbstractTestLinkBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public class AbstractTestLinkBuilder extends Builder {
* The name of the Build.
*/
protected String buildName;
/**
* The Build custom fields.
*/
protected String buildCustomFields;
/**
* The platform name.
*/
Expand Down Expand Up @@ -133,7 +137,7 @@ public class AbstractTestLinkBuilder extends Builder {
* Create a AbstractTestLinkBuilder.
*/
public AbstractTestLinkBuilder(String testLinkName, String testProjectName, String testPlanName,
String platformName, String buildName, String customFields, String testPlanCustomFields, List<BuildStep> singleBuildSteps,
String platformName, String buildName, String buildCustomFields, String customFields, String testPlanCustomFields, List<BuildStep> singleBuildSteps,
List<BuildStep> beforeIteratingAllTestCasesBuildSteps, List<BuildStep> iterativeBuildSteps,
List<BuildStep> afterIteratingAllTestCasesBuildSteps, Boolean transactional,
Boolean failedTestsMarkBuildAsFailure, Boolean failIfNoResults, Boolean failOnNotRun,
Expand All @@ -144,6 +148,7 @@ public AbstractTestLinkBuilder(String testLinkName, String testProjectName, Stri
this.testPlanName = testPlanName;
this.platformName = platformName;
this.buildName = buildName;
this.buildCustomFields = buildCustomFields;
this.customFields = customFields;
this.testPlanCustomFields = testPlanCustomFields;
this.singleBuildSteps = singleBuildSteps;
Expand All @@ -162,12 +167,12 @@ public AbstractTestLinkBuilder(String testLinkName, String testProjectName, Stri
* @deprecated to add test plan custom fields
*/
public AbstractTestLinkBuilder(String testLinkName, String testProjectName, String testPlanName,
String platformName, String buildName, String customFields, List<BuildStep> singleBuildSteps,
String platformName, String buildName, String buildCustomFields, String customFields, List<BuildStep> singleBuildSteps,
List<BuildStep> beforeIteratingAllTestCasesBuildSteps, List<BuildStep> iterativeBuildSteps,
List<BuildStep> afterIteratingAllTestCasesBuildSteps, Boolean transactional,
Boolean failedTestsMarkBuildAsFailure, Boolean failIfNoResults, Boolean failOnNotRun,
List<ResultSeeker> resultSeekers) {
this(testLinkName, testProjectName, testPlanName, platformName, buildName, customFields,
this(testLinkName, testProjectName, testPlanName, platformName, buildName, buildCustomFields, customFields,
/*testPlanCustomFields*/ null, singleBuildSteps, beforeIteratingAllTestCasesBuildSteps,
iterativeBuildSteps, afterIteratingAllTestCasesBuildSteps, transactional, failedTestsMarkBuildAsFailure,
failIfNoResults, failOnNotRun, resultSeekers);
Expand All @@ -181,8 +186,8 @@ public AbstractTestLinkBuilder(String testLinkName, String testProjectName, Stri
* @param testPlanName TestLink Test Plan name.
* @param platformName TestLink Platform name.
* @param buildName TestLink Build name.
* @param buildCustomFields TestLink Build custom fields.
* @param customFields TestLink comma-separated list of Custom Fields.
* @param keyCustomField Key custom field.
* @param singleBuildSteps List of build steps to execute once for all automated test cases.
* @param beforeIteratingAllTestCasesBuildSteps Command executed before iterating all test cases.
* @param iterativeBuildSteps List of build steps to execute for each Automated Test Case.
Expand All @@ -194,13 +199,13 @@ public AbstractTestLinkBuilder(String testLinkName, String testProjectName, Stri
* @deprecated
*/
public AbstractTestLinkBuilder(String testLinkName, String testProjectName, String testPlanName,
String platformName, String buildName, String customFields, Boolean executionStatusNotRun,
String platformName, String buildName, String buildCustomFields, String customFields, Boolean executionStatusNotRun,
Boolean executionStatusPassed, Boolean executionStatusFailed, Boolean executionStatusBlocked,
List<BuildStep> singleBuildSteps, List<BuildStep> beforeIteratingAllTestCasesBuildSteps,
List<BuildStep> iterativeBuildSteps, List<BuildStep> afterIteratingAllTestCasesBuildSteps,
Boolean transactional, Boolean failedTestsMarkBuildAsFailure, Boolean failIfNoResults,
Boolean failOnNotRun, List<ResultSeeker> resultSeekers) {
this(testLinkName, testProjectName, testPlanName, platformName, buildName, customFields,
this(testLinkName, testProjectName, testPlanName, platformName, buildName, buildCustomFields, customFields,
/*testPlanCustomFields*/ null, singleBuildSteps, beforeIteratingAllTestCasesBuildSteps,
iterativeBuildSteps, afterIteratingAllTestCasesBuildSteps, transactional, failedTestsMarkBuildAsFailure,
failIfNoResults, failOnNotRun, resultSeekers);
Expand All @@ -226,6 +231,8 @@ public String getBuildName() {
return this.buildName;
}

public String getBuildCustomFields() { return this.buildCustomFields; }

public String getCustomFields() {
return this.customFields;
}
Expand Down
31 changes: 23 additions & 8 deletions src/main/java/hudson/plugins/testlink/TestLinkBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -90,7 +91,7 @@ public TestLinkBuilder(String testLinkName, String testProjectName,
List<BuildStep> afterIteratingAllTestCasesBuildSteps,
Boolean transactional, Boolean failedTestsMarkBuildAsFailure,
Boolean failIfNoResults, List<ResultSeeker> resultSeekers) {
this(testLinkName, testProjectName, testPlanName, buildName,
this(testLinkName, testProjectName, testPlanName, buildName, null,
null, customFields, executionStatusNotRun, executionStatusPassed,
executionStatusFailed, executionStatusBlocked, singleBuildSteps,
beforeIteratingAllTestCasesBuildSteps, iterativeBuildSteps,
Expand All @@ -112,7 +113,7 @@ public TestLinkBuilder(String testLinkName, String testProjectName,
List<BuildStep> afterIteratingAllTestCasesBuildSteps,
Boolean transactional, Boolean failedTestsMarkBuildAsFailure,
Boolean failIfNoResults, Boolean failOnNotRun, List<ResultSeeker> resultSeekers) {
super(testLinkName, testProjectName, testPlanName, buildName, null,
super(testLinkName, testProjectName, testPlanName, buildName, null, null,
customFields, executionStatusNotRun, executionStatusPassed,
executionStatusFailed, executionStatusBlocked, singleBuildSteps,
beforeIteratingAllTestCasesBuildSteps, iterativeBuildSteps,
Expand All @@ -125,7 +126,7 @@ public TestLinkBuilder(String testLinkName, String testProjectName,
* @deprecated to add test plan custom fields
*/
public TestLinkBuilder(String testLinkName, String testProjectName,
String testPlanName, String platformName, String buildName, String customFields,
String testPlanName, String platformName, String buildName, String buildCustomFields, String customFields,
Boolean executionStatusNotRun, Boolean executionStatusPassed,
Boolean executionStatusFailed, Boolean executionStatusBlocked,
List<BuildStep> singleBuildSteps,
Expand All @@ -134,15 +135,16 @@ public TestLinkBuilder(String testLinkName, String testProjectName,
List<BuildStep> afterIteratingAllTestCasesBuildSteps,
Boolean transactional, Boolean failedTestsMarkBuildAsFailure,
Boolean failIfNoResults, Boolean failOnNotRun, List<ResultSeeker> resultSeekers) {
super(testLinkName, testProjectName, testPlanName, platformName, buildName,
super(testLinkName, testProjectName, testPlanName, platformName, buildName, buildCustomFields,
customFields, singleBuildSteps, beforeIteratingAllTestCasesBuildSteps, iterativeBuildSteps,
afterIteratingAllTestCasesBuildSteps, transactional, failedTestsMarkBuildAsFailure,
failIfNoResults, failOnNotRun, resultSeekers);
}

@DataBoundConstructor
public TestLinkBuilder(String testLinkName, String testProjectName,
String testPlanName, String platformName, String buildName, String customFields, String testPlanCustomFields,
String testPlanName, String platformName, String buildName,
String buildCustomFields, String customFields, String testPlanCustomFields,
Boolean executionStatusNotRun, Boolean executionStatusPassed,
Boolean executionStatusFailed, Boolean executionStatusBlocked,
List<BuildStep> singleBuildSteps,
Expand All @@ -151,7 +153,7 @@ public TestLinkBuilder(String testLinkName, String testProjectName,
List<BuildStep> afterIteratingAllTestCasesBuildSteps,
Boolean transactional, Boolean failedTestsMarkBuildAsFailure,
Boolean failIfNoResults, Boolean failOnNotRun, List<ResultSeeker> resultSeekers) {
super(testLinkName, testProjectName, testPlanName, platformName, buildName,
super(testLinkName, testProjectName, testPlanName, platformName, buildName, buildCustomFields,
customFields, testPlanCustomFields, singleBuildSteps, beforeIteratingAllTestCasesBuildSteps, iterativeBuildSteps,
afterIteratingAllTestCasesBuildSteps, transactional, failedTestsMarkBuildAsFailure,
failIfNoResults, failOnNotRun, resultSeekers);
Expand Down Expand Up @@ -194,16 +196,19 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
build.getEnvironment(listener), getPlatformName());
final String buildName = TestLinkHelper.expandVariable(build.getBuildVariableResolver(),
build.getEnvironment(listener), getBuildName());
final String buildCustomFields = TestLinkHelper.expandVariable(build.getBuildVariableResolver(),
build.getEnvironment(listener), getBuildCustomFields());
final String buildNotes = Messages.TestLinkBuilder_Build_Notes();
if(LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "TestLink project name: ["+testProjectName+"]");
LOGGER.log(Level.FINE, "TestLink plan name: ["+testPlanName+"]");
LOGGER.log(Level.FINE, "TestLink platform name: ["+platformName+"]");
LOGGER.log(Level.FINE, "TestLink build name: ["+buildName+"]");
LOGGER.log(Level.FINE, "TestLink build notes: ["+buildNotes+"]");
LOGGER.log(Level.FINE, "TestLink build Custom Fields: ["+buildCustomFields+"]");
}
// TestLink Site object
testLinkSite = this.getTestLinkSite(testLinkUrl, testLinkDevKey, testProjectName, testPlanName, platformName, buildName, buildNotes);
testLinkSite = this.getTestLinkSite(testLinkUrl, testLinkDevKey, testProjectName, testPlanName, platformName, buildName, buildCustomFields, buildNotes);

if (StringUtils.isNotBlank(platformName) && testLinkSite.getPlatform() == null)
listener.getLogger().println(Messages.TestLinkBuilder_PlatformNotFound(platformName));
Expand Down Expand Up @@ -325,7 +330,7 @@ private TestCaseWrapper[] transform(TestCase[] testCases) {
*/
public TestLinkSite getTestLinkSite(String testLinkUrl, String testLinkDevKey,
String testProjectName, String testPlanName, String platformName,
String buildName, String buildNotes) throws MalformedURLException {
String buildName, String buildCustomFields, String buildNotes) throws MalformedURLException {
final TestLinkAPI api;
final URL url = new URL(testLinkUrl);
api = new TestLinkAPI(url, testLinkDevKey);
Expand All @@ -344,7 +349,17 @@ public TestLinkSite getTestLinkSite(String testLinkUrl, String testLinkDevKey,
}
}

/* Extract custom fields and values */
java.util.Map<String, String> cfs = new HashMap<String, String>();
for (String part: buildCustomFields.split(",")) {
String[] cf = part.split(":");
String name = cf[0].replaceAll("\\s+", "");
String value = cf[1].replaceAll("\\s+", "");
cfs.put(name, value);
}

final Build build = api.createBuild(testPlan.getId(), buildName, buildNotes);
api.updateBuildCustomFields(build.getId(), testProject.getId(), testPlan.getId(), cfs);
return new TestLinkSite(api, testProject, testPlan, platform, build);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
<f:entry title="${%Build Name}" help="${rootURL}/../plugin/testlink/help-buildName.html">
<f:textbox name="TestLinkBuilder.buildName" value="${instance.buildName}" />
</f:entry>


<f:entry title="${%Build Custom Fields Values}" help="${rootURL}/../plugin/testlink/help-buildCustomFields.html">
<f:textbox name="TestLinkBuilder.buildCustomFields" value="${instance.buildCustomFields}" />
</f:entry>

<f:entry title="${%Custom Fields}" help="${rootURL}/../plugin/testlink/help-customFields.html">
<f:textbox id="customFields" name="TestLinkBuilder.customFields" value="${instance.customFields}" />
</f:entry>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Test\ Project\ Name=Test Project Name
Test\ Plan\ Name=Test Plan Name
Platform\ Name=Platform Name
Build\ Name=Build Name
Build\ Custom\ Fields\ Values=Build Custom Fields Values
Custom\ Fields=Custom Fields
Test\ Plan\ Custom\ Fields=Test Plan Custom Fields
Key\ Custom\ Field=Key Custom Field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ 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
Build\ Custom\ Fields\ Values=Construir valores de campos personalizados
Custom\ Fields=Campos personalizados
Key\ Custom\ Field=Campo customizado chave para testes automatizados do TestLink
Execution\ Status=Execution Status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ 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
Build\ Custom\ Fields\ Values=Construir valores personalizados Campos
Custom\ Fields=Campos customizados
Key\ Custom\ Field=Campo customizado chave para testes automatizados do TestLink
Single\ Test\ Build\ Steps=Build Steps �nicos
Expand Down
11 changes: 11 additions & 0 deletions src/main/webapp/help-buildCustomFields.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div>
<p>
Give a list of custom fields values for build.
</p>
<p>
Example: compiler:gcc, build_os:Windows
</p>
<p>You can use environment variables in this field. For example:
build_$BUILD_ID will be converted to something like
build_YYYY-MM-DD_HH-MI-SS.</p>
</div>
11 changes: 8 additions & 3 deletions src/test/java/hudson/plugins/testlink/TestTestLinkBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class TestTestLinkBuilder {

@Before
public void setUp() throws Exception {
builder = new TestLinkBuilder("No testlink", "No project", "No plan", "No platform", "No build",
builder = new TestLinkBuilder("No testlink", "No project", "No plan", "No platform", "No build", "Not build custom field",
"class, time, sample-job-$BUILD_ID", "host, user",Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, null,
null, null, null, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, null);
}
Expand Down Expand Up @@ -89,7 +89,7 @@ public void testListOfCustomFields() {
@Test
public void testNull() {
builder = new TestLinkBuilder(null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, null, null, null);
null, null, null, null, null, null, null, null);

assertNotNull(builder);

Expand All @@ -103,6 +103,8 @@ public void testNull() {

assertNull(builder.getBuildName());

assertNull(builder.getBuildCustomFields());

assertNull(builder.getSingleBuildSteps());

assertNull(builder.getBeforeIteratingAllTestCasesBuildSteps());
Expand Down Expand Up @@ -133,7 +135,7 @@ public void testGetters() {
List<BuildStep> singleBuildSteps = new ArrayList<BuildStep>();
singleBuildSteps.add(shell);

builder = new TestLinkBuilder("No testlink", "No project", "No plan", "No platform", "No build", "class, time",
builder = new TestLinkBuilder("No testlink", "No project", "No plan", "No platform", "No build", "No build custom fields", "class, time",
"host, user", Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, singleBuildSteps, null,
null, null, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, null);

Expand All @@ -157,6 +159,9 @@ public void testGetters() {
assertNotNull(builder.getBuildName());
assertEquals(builder.getBuildName(), "No build");

assertNotNull(builder.getBuildCustomFields());
assertEquals(builder.getBuildCustomFields(), "No build custom fields");

assertNotNull(builder.getSingleBuildSteps());
assertEquals(builder.getSingleBuildSteps(), singleBuildSteps);
assertEquals(builder.getSingleBuildSteps().size(), 1);
Expand Down