Skip to content
Permalink
Browse files

[JENKINS-37477] Working test for snippet generator for triggers.

Can't do round tripping due to JENKINS-29711, and StepConfigTester
doesn't work due to this being a Pipeline-specific JobProperty, but
the snippet generator test does what's expected.
  • Loading branch information
abayer committed Aug 22, 2016
1 parent 3786313 commit debde517af80c551a86e17c14f7a6f2eb1ccab83
Showing with 14 additions and 18 deletions.
  1. +14 −18 src/test/java/org/jenkinsci/plugins/workflow/multibranch/JobPropertyStepTest.java
@@ -302,28 +302,24 @@
@Test
public void configRoundTripTrigger() throws Exception {
List<JobProperty> properties = Collections.<JobProperty>singletonList(new PipelineTriggersJobProperty(Collections.<Trigger>singletonList(new TimerTrigger("@daily"))));
String snippetJson = "{'propertiesMap': {\n" +
" 'stapler-class-bag': 'true',\n" +
" 'org-jenkinsci-plugins-workflow-job-properties-PipelineTriggersJobProperty': {'triggers': {\n" +
" 'stapler-class-bag': 'true',\n" +
" 'hudson-triggers-TimerTrigger': {'spec': '@daily'}\n" +
" }}},\n" +
" 'stapler-class': 'org.jenkinsci.plugins.workflow.multibranch.JobPropertyStep',\n" +
" '$class': 'org.jenkinsci.plugins.workflow.multibranch.JobPropertyStep'}";

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')])])");
new SnippetizerTester(r).assertGenerateSnippet(snippetJson, "properties [pipelineTriggers([cron('@daily')])]", null);
// TODO: JENKINS-29711 like other roundtrip tests here.
//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']])]");
new SnippetizerTester(r).assertGenerateSnippet(snippetJson, "properties [pipelineTriggers([[$class: 'TimerTrigger', spec: '@daily']])]", null);
// TODO: JENKINS-29711 like other roundtrip tests here.
//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")

0 comments on commit debde51

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