Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[FIXED JENKINS-17576] [FIXED JENKINS-16870] support conditional build…
…step plugin
- Loading branch information
Showing
5 changed files
with
168 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
src/test/java/com/tikal/jenkins/plugins/multijob/test/ConditionalPhaseTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package com.tikal.jenkins.plugins.multijob.test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import hudson.model.Result; | ||
import hudson.model.TopLevelItem; | ||
import hudson.model.Cause.UserCause; | ||
import hudson.model.FreeStyleProject; | ||
import hudson.tasks.BuildStep; | ||
import hudson.tasks.Shell; | ||
|
||
import org.jenkins_ci.plugins.run_condition.BuildStepRunner; | ||
import org.jenkins_ci.plugins.run_condition.core.AlwaysRun; | ||
import org.jenkinsci.plugins.conditionalbuildstep.ConditionalBuilder; | ||
import org.junit.Assert; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
|
||
import com.tikal.jenkins.plugins.multijob.MultiJobBuilder; | ||
import com.tikal.jenkins.plugins.multijob.MultiJobBuilder.ContinuationCondition; | ||
import com.tikal.jenkins.plugins.multijob.views.PhaseWrapper; | ||
import com.tikal.jenkins.plugins.multijob.views.ProjectWrapper; | ||
import com.tikal.jenkins.plugins.multijob.MultiJobProject; | ||
import com.tikal.jenkins.plugins.multijob.PhaseJobsConfig; | ||
|
||
/** | ||
* @author Bartholdi Dominik (imod) | ||
*/ | ||
public class ConditionalPhaseTest { | ||
@Rule | ||
public JenkinsRule j = new JenkinsRule(); | ||
|
||
@Test | ||
public void testConditionalPhase() throws Exception { | ||
j.jenkins.getInjector().injectMembers(this); | ||
|
||
// MultiTop | ||
// |_ FirstPhase | ||
// |_ free | ||
// |_ [?] SecondPhase | ||
// |_ free2 | ||
|
||
final FreeStyleProject free = j.jenkins.createProject(FreeStyleProject.class, "Free"); | ||
free.getBuildersList().add(new Shell("echo hello")); | ||
final FreeStyleProject free2 = j.jenkins.createProject(FreeStyleProject.class, "Free2"); | ||
free2.getBuildersList().add(new Shell("echo hello2")); | ||
|
||
final MultiJobProject multi = j.jenkins.createProject(MultiJobProject.class, "MultiTop"); | ||
|
||
// create 'FirstPhase' containing job 'free' | ||
PhaseJobsConfig firstPhase = new PhaseJobsConfig("free", null, true, null); | ||
List<PhaseJobsConfig> configTopList = new ArrayList<PhaseJobsConfig>(); | ||
configTopList.add(firstPhase); | ||
MultiJobBuilder firstPhaseBuilder = new MultiJobBuilder("FirstPhase", configTopList, ContinuationCondition.SUCCESSFUL); | ||
|
||
|
||
// create 'SecondPhase' containing job 'free2' | ||
PhaseJobsConfig secondPhase = new PhaseJobsConfig("free2", null, true, null); | ||
List<PhaseJobsConfig> configTopList2 = new ArrayList<PhaseJobsConfig>(); | ||
configTopList.add(secondPhase); | ||
MultiJobBuilder secondPhaseBuilder = new MultiJobBuilder("SecondPhase", configTopList2, ContinuationCondition.SUCCESSFUL); | ||
|
||
multi.getBuildersList().add(new Shell("echo dude")); | ||
multi.getBuildersList().add(firstPhaseBuilder); | ||
|
||
// wrap second phase in condition | ||
List<BuildStep> blist = new ArrayList<BuildStep>(); | ||
blist.add(secondPhaseBuilder); | ||
multi.getBuildersList().add(new ConditionalBuilder(new AlwaysRun(), new BuildStepRunner.Run(), blist)); | ||
|
||
j.assertBuildStatus(Result.SUCCESS, multi.scheduleBuild2(0, new UserCause()).get()); | ||
Assert.assertTrue("shell task writes 'hello' to log", free.getLastBuild().getLog(10).contains("hello")); | ||
Assert.assertTrue("shell task writes 'dude' to log", multi.getLastBuild().getLog(10).contains("dude")); | ||
|
||
// check for correct number of items to be displayed | ||
int numberOfPhases = 0; | ||
int numberOfConditionalPhases = 0; | ||
int numberOfProjects = 0; | ||
for (TopLevelItem item : multi.getView().getRootItem(multi)) { | ||
if(item instanceof ProjectWrapper) { | ||
++numberOfProjects; | ||
}else if (item instanceof PhaseWrapper) { | ||
++numberOfPhases; | ||
if(((PhaseWrapper)item).isConditional()) { | ||
++numberOfConditionalPhases; | ||
} | ||
} | ||
} | ||
Assert.assertEquals("there should be two phases and three projects", 5, multi.getView().getRootItem(multi).size()); | ||
Assert.assertEquals("there should be two phases", 2, numberOfPhases); | ||
Assert.assertEquals("there should be three projects", 3, numberOfProjects); | ||
Assert.assertEquals("there should be 1 conditional phase", 1, numberOfConditionalPhases); | ||
|
||
} | ||
|
||
} |