Skip to content
Permalink
Browse files

[JENKINS-34005] Add test for PipelineTriggersJobProperty.

  • Loading branch information...
abayer committed Jul 14, 2016
1 parent 54615b1 commit 25b46d278c43817556fe8492ad811418d51fa66e
Showing with 57 additions and 0 deletions.
  1. +57 −0 src/test/java/org/jenkinsci/plugins/workflow/multibranch/JobPropertyStepTest.java
@@ -33,6 +33,9 @@
import hudson.tasks.LogRotator;
import java.util.Collections;
import java.util.List;

import hudson.triggers.TimerTrigger;
import hudson.triggers.Trigger;
import jenkins.branch.BranchProperty;
import jenkins.branch.BranchSource;
import jenkins.branch.DefaultBranchPropertyStrategy;
@@ -44,6 +47,7 @@
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty;
import org.jenkinsci.plugins.workflow.steps.StepConfigTester;
import static org.junit.Assert.*;

@@ -187,6 +191,59 @@
r.assertBuildStatusSuccess(r.waitForCompletion(b4));
}

@Issue("JENKINS-34005")
@Test public void triggersProperty() throws Exception {
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
// Verify the base case behavior.
p.setDefinition(new CpsFlowDefinition("echo 'foo'"));

assertTrue(p.getTriggers().isEmpty());

r.assertBuildStatusSuccess(p.scheduleBuild2(0));

// Make sure the triggers are still empty.
assertTrue(p.getTriggers().isEmpty());

// Now add a trigger.
p.setDefinition(new CpsFlowDefinition("properties([[$class: 'PipelineTriggersJobProperty',\n"
+ " triggers: [[$class: 'TimerTrigger', spec: '@daily']]]])\n"
+ "echo 'foo'"));

r.assertBuildStatusSuccess(p.scheduleBuild2(0));

assertEquals(1, p.getTriggers().size());

PipelineTriggersJobProperty triggerProp = p.getTriggersJobProperty();

TimerTrigger timerTrigger = getTriggerFromList(TimerTrigger.class, triggerProp.getTriggers());

assertNotNull(timerTrigger);

assertEquals("@daily", timerTrigger.getSpec());

// Now run a properties step with a different property and verify that we still have a
// PipelineTriggersJobProperty, but with no triggers in it.
p.setDefinition(new CpsFlowDefinition("properties([[$class: 'DisableConcurrentBuildsJobProperty']])\n"
+ "echo 'foo'"));

r.assertBuildStatusSuccess(p.scheduleBuild2(0));

assertNotNull(p.getTriggersJobProperty());

assertTrue(p.getTriggers().isEmpty());

}

private <T extends Trigger> T getTriggerFromList(Class<T> clazz, List<Trigger<?>> triggers) {
for (Trigger t : triggers) {
if (clazz.isInstance(t)) {
return clazz.cast(t);
}
}

return null;
}

private <T extends JobProperty> T getPropertyFromList(Class<T> clazz, List<JobProperty> properties) {
for (JobProperty p : properties) {
if (clazz.isInstance(p)) {

0 comments on commit 25b46d2

Please sign in to comment.
You can’t perform that action at this time.