Skip to content
Permalink
Browse files

[JENKINS-37477] - Demonstrate snippets not generating right for triggers

  • Loading branch information
abayer committed Aug 22, 2016
1 parent 281e8b2 commit 15aa0ae9be1867b7bc0911a2785000952df4d8ea
Showing with 30 additions and 0 deletions.
  1. +30 −0 src/test/java/org/jenkinsci/plugins/workflow/multibranch/JobPropertyStepTest.java
@@ -51,6 +51,7 @@
import jenkins.scm.api.SCMSource;
import org.jenkinsci.plugins.scriptsecurity.scripts.ScriptApproval;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.cps.SnippetizerTester;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.jenkinsci.plugins.workflow.job.properties.DisableConcurrentBuildsJobProperty;
@@ -59,6 +60,7 @@
import org.jenkinsci.plugins.workflow.steps.StepConfigTester;
import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep;
import static org.junit.Assert.*;

import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
@@ -296,6 +298,34 @@
assertEquals("[null, false, null]", MockTrigger.startsAndStops.toString());
}

@Issue("JENKINS-37477")
@Test
public void configRoundTripTrigger() throws Exception {
List<JobProperty> properties = Collections.<JobProperty>singletonList(new PipelineTriggersJobProperty(Collections.<Trigger<?>>singletonList(new TimerTrigger("@daily"))));

if (TimerTrigger.DescriptorImpl.class.isAnnotationPresent(Symbol.class)) {
new SnippetizerTester(r).assertGenerateSnippet("{'stapler-class':'" + JobPropertyStep.class.getName() + "', 'propertiesMap': {'stapler-class-bag': 'true', 'org-jenkinsci-plugins-workflow-job-properties-PipelineTriggersJobProperty': {'hudson-triggers-TimerTrigger': {'spec': '@daily'}}}}", "properties([pipelineTriggers([cron('@daily')])])", null);
new SnippetizerTester(r).assertRoundTrip(new JobPropertyStep(properties), "properties([pipelineTriggers([cron('@daily')])])");
} else {
new SnippetizerTester(r).assertGenerateSnippet("{'stapler-class':'" + JobPropertyStep.class.getName() + "', 'propertiesMap': {'stapler-class-bag': 'true', 'org-jenkinsci-plugins-workflow-job-properties-PipelineTriggersJobProperty': {'hudson-triggers-TimerTrigger': {'spec': '@daily'}}}}", "properties [pipelineTriggers([[$class: 'TimerTrigger', spec: '@daily']])]", null);
new SnippetizerTester(r).assertRoundTrip(new JobPropertyStep(properties), "properties [pipelineTriggers([[$class: 'TimerTrigger', spec: '@daily']])]");
}

StepConfigTester tester = new StepConfigTester(r);
properties = tester.configRoundTrip(new JobPropertyStep(properties)).getProperties();
assertEquals(1, properties.size());
PipelineTriggersJobProperty triggersJobProperty = getPropertyFromList(PipelineTriggersJobProperty.class, properties);
assertNotNull(triggersJobProperty);
assertEquals(1, triggersJobProperty.getTriggers().size());
assertEquals(TimerTrigger.class, triggersJobProperty.getTriggers().get(0).getClass());
TimerTrigger trigger = (TimerTrigger) triggersJobProperty.getTriggers().get(0);
assertEquals("@daily", trigger.getSpec());

List<JobProperty> emptyInput = tester.configRoundTrip(new JobPropertyStep(Collections.<JobProperty>emptyList())).getProperties();

assertEquals(Collections.emptyList(), removeTriggerProperty(emptyInput));
}

@Issue("JENKINS-37005")
@Test
public void noPropertiesWarnings() throws Exception {

0 comments on commit 15aa0ae

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