Skip to content

Commit

Permalink
Massaging code after merging pull request #20
Browse files Browse the repository at this point in the history
  • Loading branch information
kinow committed Apr 16, 2016
1 parent fb3ce3c commit 1b06553
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 175 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<artifactId>testlink</artifactId>
<name>Jenkins TestLink Plugin</name>
<version>3.13-SNAPSHOT</version>
<version>3.12-SNAPSHOT</version>
<packaging>hpi</packaging>
<description>This plug-in integrates Jenkins to TestLink</description>

Expand Down
110 changes: 25 additions & 85 deletions src/main/java/hudson/plugins/testlink/AbstractTestLinkBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,14 @@
*/
package hudson.plugins.testlink;

import hudson.EnvVars;
import hudson.Util;
import hudson.model.Action;
import java.util.List;

import hudson.model.AbstractProject;
import hudson.model.Action;
import hudson.plugins.testlink.result.ResultSeeker;
import hudson.plugins.testlink.util.ExecutionOrderComparator;
import hudson.tasks.BuildStep;
import hudson.tasks.Builder;
import hudson.util.VariableResolver;

import java.util.List;
import java.util.StringTokenizer;

import org.apache.commons.lang.StringUtils;

/**
* Contains basic logic for a Builder for TestLink plug-in. This class was created to reduce complexity and reduce the
Expand All @@ -48,10 +42,6 @@
public class AbstractTestLinkBuilder extends Builder {

/* --- Job properties --- */
/**
* Comma constant for custom fields separated with delimiter.
*/
private static final String COMMA = ",";
/**
* The name of the TestLink installation.
*/
Expand All @@ -78,7 +68,7 @@ public class AbstractTestLinkBuilder extends Builder {
protected final String customFields;

/**
* Comma separated list of custom fields to download from TestLink.
* Comma separated list of test plan custom fields to download from TestLink.
*/
protected final String testPlanCustomFields;

Expand Down Expand Up @@ -167,6 +157,22 @@ public AbstractTestLinkBuilder(String testLinkName, String testProjectName, Stri
this.resultSeekers = resultSeekers;
}

/**
* Create a AbstractTestLinkBuilder.
* @deprecated to add test plan custom fields
*/
public AbstractTestLinkBuilder(String testLinkName, String testProjectName, String testPlanName,
String platformName, String buildName, 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,
/*testPlanCustomFields*/ null, singleBuildSteps, beforeIteratingAllTestCasesBuildSteps,
iterativeBuildSteps, afterIteratingAllTestCasesBuildSteps, transactional, failedTestsMarkBuildAsFailure,
failIfNoResults, failOnNotRun, resultSeekers);
}

/**
* This constructor is bound to a stapler request. All parameters here are passed by Jenkins.
*
Expand All @@ -188,15 +194,16 @@ public AbstractTestLinkBuilder(String testLinkName, String testProjectName, Stri
* @deprecated
*/
public AbstractTestLinkBuilder(String testLinkName, String testProjectName, String testPlanName,
String platformName, String buildName, String customFields, String testPlanCustomFields, Boolean executionStatusNotRun,
String platformName, String buildName, 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, testPlanCustomFields, singleBuildSteps,
beforeIteratingAllTestCasesBuildSteps, iterativeBuildSteps, afterIteratingAllTestCasesBuildSteps,
transactional, failedTestsMarkBuildAsFailure, failIfNoResults, failOnNotRun, resultSeekers);
this(testLinkName, testProjectName, testPlanName, platformName, buildName, customFields,
/*testPlanCustomFields*/ null, singleBuildSteps, beforeIteratingAllTestCasesBuildSteps,
iterativeBuildSteps, afterIteratingAllTestCasesBuildSteps, transactional, failedTestsMarkBuildAsFailure,
failIfNoResults, failOnNotRun, resultSeekers);
}

public String getTestLinkName() {
Expand All @@ -207,19 +214,6 @@ public String getTestProjectName() {
return this.testProjectName;
}

/**
* Expands a text variable like BUILD-$VAR replacing the $VAR part with a environment variable that matches its
* name, minus $.
*
* @param variableResolver Jenkins Build Variable Resolver.
* @param envVars Jenkins Build Environment Variables.
* @param variable Variable value (includes mask).
* @return Expanded test project name job configuration property.
*/
public String expandVariable(VariableResolver<String> variableResolver, EnvVars envVars, String variable) {
return Util.replaceMacro(envVars.expand(variable), variableResolver);
}

public String getTestPlanName() {
return this.testPlanName;
}
Expand Down Expand Up @@ -339,58 +333,4 @@ public Action getProjectAction(AbstractProject<?, ?> project) {
return new TestLinkProjectAction(project);
}

/* --- Utility methods --- */

/**
* Creates array of custom fields names using the Job configuration data.
*
* @param variableResolver Jenkins variable resolver
* @param envVars Jenkins environment variables
*
* @return Array of custom fields names.
*/
protected String[] createArrayOfCustomFieldsNames(final VariableResolver<String> variableResolver,
final EnvVars envVars) {
String[] customFieldNamesArray = new String[0];
String customFields = expandVariable(variableResolver, envVars, this.getCustomFields());

if (StringUtils.isNotBlank(customFields)) {
StringTokenizer tokenizer = new StringTokenizer(customFields, COMMA);
if (tokenizer.countTokens() > 0) {
customFieldNamesArray = new String[tokenizer.countTokens()];
int index = 0;
while (tokenizer.hasMoreTokens()) {
String customFieldName = tokenizer.nextToken();
customFieldName = customFieldName.trim();
customFieldNamesArray[index] = customFieldName;
index = index + 1;
}
}
}

return customFieldNamesArray;
}


protected String[] createArrayOfTestPlanCustomFieldsNames(final VariableResolver<String> variableResolver,
final EnvVars envVars){
String[] customFieldNamesArray = new String[0];
String customFields = expandVariable(variableResolver, envVars, this.getTestPlanCustomFields());

if (StringUtils.isNotBlank(customFields)) {
StringTokenizer tokenizer = new StringTokenizer(customFields, COMMA);
if (tokenizer.countTokens() > 0) {
customFieldNamesArray = new String[tokenizer.countTokens()];
int index = 0;
while (tokenizer.hasMoreTokens()) {
String customFieldName = tokenizer.nextToken();
customFieldName = customFieldName.trim();
customFieldNamesArray[index] = customFieldName;
index = index + 1;
}
}
}

return customFieldNamesArray;
}
}
80 changes: 50 additions & 30 deletions src/main/java/hudson/plugins/testlink/TestLinkBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,6 @@
*/
package hudson.plugins.testlink;

import hudson.AbortException;
import hudson.EnvVars;
import hudson.Extension;
import hudson.Launcher;
import hudson.model.BuildListener;
import hudson.model.EnvironmentContributingAction;
import hudson.model.Result;
import hudson.model.AbstractBuild;
import hudson.model.Descriptor;
import hudson.plugins.testlink.result.ResultSeeker;
import hudson.plugins.testlink.result.ResultSeekerException;
import hudson.plugins.testlink.result.TestCaseWrapper;
import hudson.plugins.testlink.util.Messages;
import hudson.plugins.testlink.util.TestLinkHelper;
import hudson.tasks.BuildStep;
import hudson.tasks.Builder;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
Expand All @@ -60,6 +43,22 @@
import br.eti.kinoshita.testlinkjavaapi.model.TestPlan;
import br.eti.kinoshita.testlinkjavaapi.model.TestProject;
import br.eti.kinoshita.testlinkjavaapi.util.TestLinkAPIException;
import hudson.AbortException;
import hudson.EnvVars;
import hudson.Extension;
import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.model.Descriptor;
import hudson.model.EnvironmentContributingAction;
import hudson.model.Result;
import hudson.plugins.testlink.result.ResultSeeker;
import hudson.plugins.testlink.result.ResultSeekerException;
import hudson.plugins.testlink.result.TestCaseWrapper;
import hudson.plugins.testlink.util.Messages;
import hudson.plugins.testlink.util.TestLinkHelper;
import hudson.tasks.BuildStep;
import hudson.tasks.Builder;

/**
* A builder to add a TestLink build step.
Expand All @@ -82,7 +81,7 @@ public class TestLinkBuilder extends AbstractTestLinkBuilder {
* @deprecated
*/
public TestLinkBuilder(String testLinkName, String testProjectName,
String testPlanName, String buildName, String customFields, String testPlanCustomFields,
String testPlanName, String buildName, String customFields,
Boolean executionStatusNotRun, Boolean executionStatusPassed,
Boolean executionStatusFailed, Boolean executionStatusBlocked,
List<BuildStep> singleBuildSteps,
Expand All @@ -91,8 +90,8 @@ public TestLinkBuilder(String testLinkName, String testProjectName,
List<BuildStep> afterIteratingAllTestCasesBuildSteps,
Boolean transactional, Boolean failedTestsMarkBuildAsFailure,
Boolean failIfNoResults, List<ResultSeeker> resultSeekers) {
super(testLinkName, testProjectName, testPlanName, buildName,
null, customFields, testPlanCustomFields, executionStatusNotRun, executionStatusPassed,
this(testLinkName, testProjectName, testPlanName, buildName,
null, customFields, executionStatusNotRun, executionStatusPassed,
executionStatusFailed, executionStatusBlocked, singleBuildSteps,
beforeIteratingAllTestCasesBuildSteps, iterativeBuildSteps,
afterIteratingAllTestCasesBuildSteps, transactional,
Expand All @@ -104,7 +103,7 @@ public TestLinkBuilder(String testLinkName, String testProjectName,
* @deprecated
*/
public TestLinkBuilder(String testLinkName, String testProjectName,
String testPlanName, String buildName, String customFields, String testPlanCustomFields,
String testPlanName, String buildName, String customFields,
Boolean executionStatusNotRun, Boolean executionStatusPassed,
Boolean executionStatusFailed, Boolean executionStatusBlocked,
List<BuildStep> singleBuildSteps,
Expand All @@ -114,13 +113,34 @@ public TestLinkBuilder(String testLinkName, String testProjectName,
Boolean transactional, Boolean failedTestsMarkBuildAsFailure,
Boolean failIfNoResults, Boolean failOnNotRun, List<ResultSeeker> resultSeekers) {
super(testLinkName, testProjectName, testPlanName, buildName, null,
customFields, testPlanCustomFields, executionStatusNotRun, executionStatusPassed,
customFields, executionStatusNotRun, executionStatusPassed,
executionStatusFailed, executionStatusBlocked, singleBuildSteps,
beforeIteratingAllTestCasesBuildSteps, iterativeBuildSteps,
afterIteratingAllTestCasesBuildSteps, transactional,
failedTestsMarkBuildAsFailure, failIfNoResults, failOnNotRun, resultSeekers);
}


/**
* Kept here for backward compatibility. Don't add new fields.
* @deprecated to add test plan custom fields
*/
@DataBoundConstructor
public TestLinkBuilder(String testLinkName, String testProjectName,
String testPlanName, String platformName, String buildName, 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) {
super(testLinkName, testProjectName, testPlanName, platformName, buildName,
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,
Expand Down Expand Up @@ -167,13 +187,13 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
listener.getLogger().println(Messages.TestLinkBuilder_UsedTLURL(testLinkUrl));

try {
final String testProjectName = expandVariable(build.getBuildVariableResolver(),
final String testProjectName = TestLinkHelper.expandVariable(build.getBuildVariableResolver(),
build.getEnvironment(listener), getTestProjectName());
final String testPlanName = expandVariable(build.getBuildVariableResolver(),
final String testPlanName = TestLinkHelper.expandVariable(build.getBuildVariableResolver(),
build.getEnvironment(listener), getTestPlanName());
final String platformName = expandVariable(build.getBuildVariableResolver(),
final String platformName = TestLinkHelper.expandVariable(build.getBuildVariableResolver(),
build.getEnvironment(listener), getPlatformName());
final String buildName = expandVariable(build.getBuildVariableResolver(),
final String buildName = TestLinkHelper.expandVariable(build.getBuildVariableResolver(),
build.getEnvironment(listener), getBuildName());
final String buildNotes = Messages.TestLinkBuilder_Build_Notes();
if(LOGGER.isLoggable(Level.FINE)) {
Expand All @@ -189,12 +209,12 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
if (StringUtils.isNotBlank(platformName) && testLinkSite.getPlatform() == null)
listener.getLogger().println(Messages.TestLinkBuilder_PlatformNotFound(platformName));

final String[] testCaseCustomFieldsNames = this.createArrayOfCustomFieldsNames(build.getBuildVariableResolver(), build.getEnvironment(listener));
final String[] testCaseCustomFieldsNames = TestLinkHelper.createArrayOfCustomFieldsNames(build.getBuildVariableResolver(), build.getEnvironment(listener), this.getCustomFields());
// Array of automated test cases
TestCase[] testCases = testLinkSite.getAutomatedTestCases(testCaseCustomFieldsNames);

final String[] testPlanCustomFieldsNames = this.createArrayOfTestPlanCustomFieldsNames(build.getBuildVariableResolver(), build.getEnvironment(listener));

// Retrieve custom fields in test plan
final String[] testPlanCustomFieldsNames = TestLinkHelper.createArrayOfCustomFieldsNames(build.getBuildVariableResolver(), build.getEnvironment(listener), this.getTestPlanCustomFields());
testPlan = testLinkSite.getTestPlanWithCustomFields(testPlanCustomFieldsNames);

// Transforms test cases into test case wrappers
Expand Down
Loading

0 comments on commit 1b06553

Please sign in to comment.