Skip to content

Commit

Permalink
JENKINS-21149 Added back old tests which are still valid and moved ne…
Browse files Browse the repository at this point in the history
…w test to correct test class
  • Loading branch information
patbos committed Jan 7, 2014
1 parent e6f5dd7 commit 62faf99
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@

import hudson.Extension;
import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.BuildListener;
import hudson.model.*;
import hudson.tasks.BuildWrapper;
import hudson.tasks.BuildWrapperDescriptor;
import org.jenkinsci.plugins.tokenmacro.MacroEvaluationException;
import org.jenkinsci.plugins.tokenmacro.TokenMacro;
import org.kohsuke.stapler.DataBoundConstructor;

import java.io.IOException;
import java.util.List;

public class PipelineVersionContributor extends BuildWrapper {

Expand Down Expand Up @@ -78,11 +77,20 @@ public void onStarted(AbstractBuild build, BuildListener listener) throws IOExce
}
}

public static String getVersion(AbstractBuild build) {
public static String getVersion(AbstractBuild build) {
PipelineVersionAction version = build.getAction(PipelineVersionAction.class);
if (version != null) {
return version.getVersion();
}
//Old way for backwards compatibility
List<ParametersAction> parameters = build.getActions(ParametersAction.class);
for (ParametersAction parameter : parameters) {
ParameterValue value = parameter.getParameter(PipelineVersionContributor.VERSION_PARAMETER);
if (value instanceof StringParameterValue) {
return ((StringParameterValue) value).value;
}
}

return null;
}

Expand Down
31 changes: 0 additions & 31 deletions src/test/java/se/diabol/jenkins/pipeline/PipelineFactoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -748,35 +748,4 @@ public void getPipelineLatestWithFolders() throws Exception {

}




@Test
@Bug(21149)
public void testVersionContributorConfiguredAndUpdated() throws Exception {

FreeStyleProject firstProject = jenkins.createFreeStyleProject("firstProject");
FreeStyleProject secondProject = jenkins.createFreeStyleProject("secondProject");
firstProject.getPublishersList().add(new BuildTrigger("secondProject", false));

firstProject.getBuildWrappersList().add(new PipelineVersionContributor(true, "1.0.0.${BUILD_NUMBER}"));
secondProject.getBuildWrappersList().add(new PipelineVersionContributor(false, "2.0.0.${BUILD_NUMBER}"));

jenkins.setQuietPeriod(0);
jenkins.getInstance().rebuildDependencyGraph();
jenkins.buildAndAssertSuccess(firstProject);
jenkins.waitUntilNoActivity();

assertNotNull(firstProject.getLastBuild());
assertNotNull(secondProject.getLastBuild());

Pipeline pipeline = PipelineFactory.createPipelineLatest(PipelineFactory.extractPipeline("Pipeline", firstProject), jenkins.getInstance());
assertNotNull(pipeline);
assertEquals("2.0.0.1", pipeline.getVersion());


}



}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@
import au.com.centrumsystems.hudson.plugin.buildpipeline.trigger.BuildPipelineTrigger;
import hudson.EnvVars;
import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.cli.BuildCommand;
import hudson.model.*;
import hudson.tasks.BuildTrigger;
import hudson.util.StreamTaskListener;
import org.apache.commons.io.FileUtils;
Expand All @@ -34,6 +32,7 @@
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.TestBuilder;
import se.diabol.jenkins.pipeline.model.Pipeline;

import java.io.IOException;

Expand Down Expand Up @@ -147,6 +146,45 @@ public void testVersionContributorErrorInPattern() throws Exception {
assertTrue(log.contains("Error creating version"));
}

@Test
public void testGetVersionFoundBackwardsCompatibility() throws Exception {
FreeStyleProject project = jenkins.createFreeStyleProject("firstProject");
FreeStyleBuild build = project.scheduleBuild2(0, new BuildCommand.CLICause(), new ParametersAction(new StringParameterValue("HEPP", "HOPP"), new StringParameterValue("PIPELINE_VERSION", "1.1"))).get();
assertEquals("1.1", PipelineVersionContributor.getVersion(build));
}

@Test
public void testGetVersionNotFoundBackwardsCompatibility() throws Exception {
FreeStyleProject project = jenkins.createFreeStyleProject("firstProject");
FreeStyleBuild build = project.scheduleBuild2(0, new BuildCommand.CLICause(), new ParametersAction(new StringParameterValue("HEPP", "HOPP"))).get();
assertNull(PipelineVersionContributor.getVersion(build));
}

@Test
@Bug(21149)
public void testVersionContributorConfiguredAndUpdated() throws Exception {

FreeStyleProject firstProject = jenkins.createFreeStyleProject("firstProject");
FreeStyleProject secondProject = jenkins.createFreeStyleProject("secondProject");
firstProject.getPublishersList().add(new BuildTrigger("secondProject", false));

firstProject.getBuildWrappersList().add(new PipelineVersionContributor(false, "1.0.0.${BUILD_NUMBER}"));
secondProject.getBuildWrappersList().add(new PipelineVersionContributor(false, "2.0.0.${BUILD_NUMBER}"));

jenkins.setQuietPeriod(0);
jenkins.getInstance().rebuildDependencyGraph();
jenkins.buildAndAssertSuccess(firstProject);
jenkins.waitUntilNoActivity();

assertNotNull(firstProject.getLastBuild());
assertNotNull(secondProject.getLastBuild());

Pipeline pipeline = PipelineFactory.createPipelineLatest(PipelineFactory.extractPipeline("Pipeline", firstProject), jenkins.getInstance());
assertNotNull(pipeline);
assertEquals("2.0.0.1", pipeline.getVersion());


}


private class AssertNoPipelineVersion extends TestBuilder {
Expand Down

0 comments on commit 62faf99

Please sign in to comment.