|
2 | 2 |
|
3 | 3 | import hudson.model.FreeStyleProject; |
4 | 4 | import hudson.model.Job; |
| 5 | +import hudson.model.ParameterDefinition; |
| 6 | +import hudson.model.ParameterValue; |
5 | 7 | import hudson.model.ParametersAction; |
6 | 8 | import hudson.model.ParametersDefinitionProperty; |
7 | 9 | import hudson.model.StringParameterDefinition; |
8 | 10 | import hudson.triggers.Trigger; |
| 11 | +import net.sf.json.JSONObject; |
9 | 12 | import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition; |
10 | 13 | import org.jenkinsci.plugins.workflow.job.WorkflowJob; |
11 | 14 | import org.jenkinsci.plugins.workflow.job.WorkflowRun; |
12 | 15 | import org.junit.Rule; |
13 | 16 | import org.junit.Test; |
| 17 | +import org.jvnet.hudson.test.Issue; |
14 | 18 | import org.jvnet.hudson.test.JenkinsRule; |
| 19 | +import org.kohsuke.stapler.StaplerRequest; |
| 20 | + |
| 21 | +import javax.annotation.CheckForNull; |
| 22 | +import javax.annotation.Nonnull; |
15 | 23 |
|
16 | 24 | import static org.hamcrest.MatcherAssert.assertThat; |
17 | 25 | import static org.hamcrest.Matchers.is; |
@@ -97,4 +105,39 @@ public void declarative() throws Exception { |
97 | 105 | assertThat(p.getLastCompletedBuild(), is(not(wfr))); |
98 | 106 | assertThat((String) p.getLastCompletedBuild().getAction(ParametersAction.class).getParameter("foo").getValue(), is("bar")); |
99 | 107 | } |
| 108 | + |
| 109 | + @Test |
| 110 | + @Issue("JENKINS-49372") |
| 111 | + public void nullValueCreated() throws Exception { |
| 112 | + FreeStyleProject p = r.createFreeStyleProject(); |
| 113 | + p.addProperty(new ParametersDefinitionProperty(new NullParameterDefinition("foo"))); |
| 114 | + assertThat(p.getLastCompletedBuild(), is(nullValue())); |
| 115 | + Trigger<Job> t = new ParameterizedTimerTrigger("* * * * *%foo=test"); |
| 116 | + t.start(p, true); |
| 117 | + p.addTrigger(t); |
| 118 | + new Cron().doRun(); |
| 119 | + assertThat(p.isInQueue(), is(true)); |
| 120 | + r.waitUntilNoActivity(); |
| 121 | + // Build should complete successfully but will not have any value |
| 122 | + assertThat(p.getLastCompletedBuild(), is(notNullValue())); |
| 123 | + } |
| 124 | + |
| 125 | + private static class NullParameterDefinition extends ParameterDefinition { |
| 126 | + |
| 127 | + public NullParameterDefinition(@Nonnull String name) { |
| 128 | + super(name, null); |
| 129 | + } |
| 130 | + |
| 131 | + @CheckForNull |
| 132 | + @Override |
| 133 | + public ParameterValue createValue(StaplerRequest staplerRequest, JSONObject jsonObject) { |
| 134 | + return null; |
| 135 | + } |
| 136 | + |
| 137 | + @CheckForNull |
| 138 | + @Override |
| 139 | + public ParameterValue createValue(StaplerRequest staplerRequest) { |
| 140 | + return null; |
| 141 | + } |
| 142 | + } |
100 | 143 | } |
0 commit comments