@Issue("JENKINS-37219") @Test public void snippetGeneratorOverrideIndexing() throws Exception { String snippetJson = "{'propertiesMap':\n" + "{'stapler-class-bag': 'true', 'jenkins-branch-OverrideIndexTriggersJobProperty': \n" + "{'specified': true, 'enableTriggers': true}},\n" + "'stapler-class': 'org.jenkinsci.plugins.workflow.multibranch.JobPropertyStep',\n" + "'$class': 'org.jenkinsci.plugins.workflow.multibranch.JobPropertyStep'}"; new SnippetizerTester(r).assertGenerateSnippet(snippetJson, "properties([overrideIndexTriggers(true)])", null); }
@Issue("JENKINS-37477") @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'}"; new SnippetizerTester(r).assertGenerateSnippet(snippetJson, "properties([pipelineTriggers([cron('@daily')])])", null); new SnippetizerTester(r).assertRoundTrip(new JobPropertyStep(properties), "properties([pipelineTriggers([cron('@daily')])])"); }
@Issue("JENKINS-37721") @Test public void configRoundTripSCMTrigger() throws Exception { List<JobProperty> properties = Collections.<JobProperty>singletonList(new PipelineTriggersJobProperty(Collections.<Trigger>singletonList(new SCMTrigger("@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-SCMTrigger': {'scmpoll_spec': '@daily', 'ignorePostCommitHooks': false }\n" + " }}},\n" + " 'stapler-class': 'org.jenkinsci.plugins.workflow.multibranch.JobPropertyStep',\n" + " '$class': 'org.jenkinsci.plugins.workflow.multibranch.JobPropertyStep'}"; new SnippetizerTester(r).assertGenerateSnippet(snippetJson, "properties([pipelineTriggers([pollSCM('@daily')])])", null); new SnippetizerTester(r).assertRoundTrip(new JobPropertyStep(properties), "properties([pipelineTriggers([pollSCM('@daily')])])"); }
@Issue("JENKINS-34464") @Test public void configRoundTripReverseBuildTrigger() throws Exception { List<JobProperty> properties = Collections.<JobProperty>singletonList(new PipelineTriggersJobProperty(Collections.<Trigger>singletonList(new ReverseBuildTrigger("some-job", Result.UNSTABLE)))); String snippetJson = "{'propertiesMap': {\n" + " 'stapler-class-bag': 'true',\n" + " 'org-jenkinsci-plugins-workflow-job-properties-PipelineTriggersJobProperty': {'triggers': {\n" + " 'stapler-class-bag': 'true',\n" + " 'jenkins-triggers-ReverseBuildTrigger': { 'threshold': 'UNSTABLE', 'upstreamProjects': 'some-job'}\n" + " }}},\n" + " 'stapler-class': 'org.jenkinsci.plugins.workflow.multibranch.JobPropertyStep',\n" + " '$class': 'org.jenkinsci.plugins.workflow.multibranch.JobPropertyStep'}"; new SnippetizerTester(r).assertGenerateSnippet(snippetJson, "properties([pipelineTriggers([upstream(threshold: 'UNSTABLE', upstreamProjects: 'some-job')])])", null); new SnippetizerTester(r).assertRoundTrip(new JobPropertyStep(properties), "properties([pipelineTriggers([upstream(threshold: 'UNSTABLE', upstreamProjects: 'some-job')])])"); }
@Issue("JENKINS-26143") @Test public void testChoiceParameterSnippetizer() throws Exception { //new SnippetizerTester(r).assertGenerateSnippet(); new SnippetizerTester(r).assertRoundTrip(new JobPropertyStep(Arrays.asList(new ParametersDefinitionProperty(new ChoiceParameterDefinition("paramName", new String[] { "foo", "bar", "baz" }, "")))), "properties([parameters([choice(choices: ['foo', 'bar', 'baz'], description: '', name: 'paramName')])])"); }
@Test public void configRoundTrip() throws Exception { SnippetizerTester st = new SnippetizerTester(rule); JUnitResultsStep step = new JUnitResultsStep("**/target/surefire-reports/TEST-*.xml"); st.assertRoundTrip(step, "junit '**/target/surefire-reports/TEST-*.xml'"); step.setAllowEmptyResults(true); st.assertRoundTrip(step, "junit allowEmptyResults: true, testResults: '**/target/surefire-reports/TEST-*.xml'"); step.setHealthScaleFactor(2.0); st.assertRoundTrip(step, "junit allowEmptyResults: true, healthScaleFactor: 2.0, testResults: '**/target/surefire-reports/TEST-*.xml'"); MockTestDataPublisher publisher = new MockTestDataPublisher("testing"); step.setTestDataPublishers(Collections.<TestDataPublisher>singletonList(publisher)); st.assertRoundTrip(step, "junit allowEmptyResults: true, healthScaleFactor: 2.0, testDataPublishers: [[$class: 'MockTestDataPublisher', name: 'testing']], testResults: '**/target/surefire-reports/TEST-*.xml'"); }
@SuppressWarnings("rawtypes") @Test public void configRoundTripParameters() throws Exception { List<JobProperty> properties = Collections.<JobProperty>singletonList(new ParametersDefinitionProperty(new BooleanParameterDefinition("flag", true, null))); // TODO *ParameterDefinition.description ought to be defaulted to null: new SnippetizerTester(r).assertRoundTrip(new JobPropertyStep(properties), "properties([parameters([booleanParam(defaultValue: true, name: 'flag')])])"); StepConfigTester tester = new StepConfigTester(r); properties = tester.configRoundTrip(new JobPropertyStep(properties)).getProperties(); assertEquals(1, properties.size()); ParametersDefinitionProperty pdp = getPropertyFromList(ParametersDefinitionProperty.class, properties); assertNotNull(pdp); assertEquals(1, pdp.getParameterDefinitions().size()); assertEquals(BooleanParameterDefinition.class, pdp.getParameterDefinitions().get(0).getClass()); BooleanParameterDefinition bpd = (BooleanParameterDefinition) pdp.getParameterDefinitions().get(0); assertEquals("flag", bpd.getName()); assertTrue(bpd.isDefaultValue()); List<JobProperty> emptyInput = tester.configRoundTrip(new JobPropertyStep(Collections.<JobProperty>emptyList())).getProperties(); assertEquals(Collections.emptyList(), removeTriggerProperty(emptyInput)); }
@SuppressWarnings("rawtypes") @Test public void configRoundTripBuildDiscarder() throws Exception { List<JobProperty> properties = Collections.<JobProperty>singletonList(new BuildDiscarderProperty(new LogRotator(1, 2, -1, 3))); // TODO structural form of LogRotator is awful; confusion between integer and string types, and failure to handle default values: new SnippetizerTester(r).assertRoundTrip(new JobPropertyStep(properties), "properties([buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '3', daysToKeepStr: '1', numToKeepStr: '2'))])"); StepConfigTester tester = new StepConfigTester(r); properties = tester.configRoundTrip(new JobPropertyStep(properties)).getProperties(); assertEquals(1, properties.size()); BuildDiscarderProperty bdp = getPropertyFromList(BuildDiscarderProperty.class, properties); assertNotNull(bdp); BuildDiscarder strategy = bdp.getStrategy(); assertNotNull(strategy); assertEquals(LogRotator.class, strategy.getClass()); LogRotator lr = (LogRotator) strategy; assertEquals(1, lr.getDaysToKeep()); assertEquals(2, lr.getNumToKeep()); assertEquals(-1, lr.getArtifactDaysToKeep()); assertEquals(3, lr.getArtifactNumToKeep()); }