|
1 | 1 | package org.jenkinsci.plugins.parameterizedscheduler;
|
2 | 2 |
|
| 3 | +import com.cwctravel.hudson.plugins.extended_choice_parameter.ExtendedChoiceParameterDefinition; |
3 | 4 | import hudson.model.FreeStyleProject;
|
4 | 5 | import hudson.model.Job;
|
| 6 | +import hudson.model.ParameterDefinition; |
| 7 | +import hudson.model.ParameterValue; |
5 | 8 | import hudson.model.ParametersAction;
|
6 | 9 | import hudson.model.ParametersDefinitionProperty;
|
7 | 10 | import hudson.model.StringParameterDefinition;
|
8 | 11 | import hudson.triggers.Trigger;
|
| 12 | +import net.sf.json.JSONObject; |
9 | 13 | import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
|
10 | 14 | import org.jenkinsci.plugins.workflow.job.WorkflowJob;
|
11 | 15 | import org.jenkinsci.plugins.workflow.job.WorkflowRun;
|
12 | 16 | import org.junit.Rule;
|
13 | 17 | import org.junit.Test;
|
| 18 | +import org.jvnet.hudson.test.Issue; |
14 | 19 | import org.jvnet.hudson.test.JenkinsRule;
|
| 20 | +import org.kohsuke.stapler.StaplerRequest; |
| 21 | + |
| 22 | +import javax.annotation.CheckForNull; |
| 23 | +import javax.annotation.Nonnull; |
15 | 24 |
|
16 | 25 | import static org.hamcrest.MatcherAssert.assertThat;
|
17 | 26 | import static org.hamcrest.Matchers.is;
|
@@ -97,4 +106,63 @@ public void declarative() throws Exception {
|
97 | 106 | assertThat(p.getLastCompletedBuild(), is(not(wfr)));
|
98 | 107 | assertThat((String) p.getLastCompletedBuild().getAction(ParametersAction.class).getParameter("foo").getValue(), is("bar"));
|
99 | 108 | }
|
| 109 | + |
| 110 | + @Test |
| 111 | + @Issue("JENKINS-49372") |
| 112 | + public void extendedChoiceJson() throws Exception { |
| 113 | + FreeStyleProject p = r.createFreeStyleProject(); |
| 114 | + p.addProperty(new ParametersDefinitionProperty(new ExtendedChoiceParameterDefinition("foo", ExtendedChoiceParameterDefinition.PARAMETER_TYPE_JSON, "", |
| 115 | + "", "", "def jsonSlurper = new groovy.json.JsonSlurper()\n" + |
| 116 | + "def object = jsonSlurper.parseText('{\"schema\":{\"type\":\"object\",\"title\":\"Car\",\"properties\":{\"make\":{\"type\":\"string\",\"enum\":[\"Toyota\",\"BMW\",\"Honda\",\"Ford\",\"Chevy\",\"VW\"]},\"model\":{\"type\":\"string\"},\"year\":{\"type\":\"integer\",\"enum\":[1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014],\"default\":2008}}}}')\n" + |
| 117 | + "return object", "", "", "", "", |
| 118 | + "", "", "" , "", "", "", |
| 119 | + "", "", "", "", "", "", |
| 120 | + "", "", "", "", false, false, |
| 121 | + 0, "", ""))); |
| 122 | + assertThat(p.getLastCompletedBuild(), is(nullValue())); |
| 123 | + Trigger<Job> t = new ParameterizedTimerTrigger("* * * * *%foo={\"make\":\"Toyota\",\"model\":\"test\",\"year\":2008}"); |
| 124 | + t.start(p, true); |
| 125 | + p.addTrigger(t); |
| 126 | + new Cron().doRun(); |
| 127 | + assertThat(p.isInQueue(), is(true)); |
| 128 | + r.waitUntilNoActivity(); |
| 129 | + // Build should complete successfully but will not have any value |
| 130 | + assertThat(p.getLastCompletedBuild(), is(notNullValue())); |
| 131 | + assertThat(p.getLastCompletedBuild().getAction(ParametersAction.class).getParameter("foo").getValue(), is("{\"make\":\"Toyota\",\"model\":\"test\",\"year\":2008}")); |
| 132 | + } |
| 133 | + |
| 134 | + @Test |
| 135 | + @Issue("JENKINS-49372") |
| 136 | + public void nullValueCreated() throws Exception { |
| 137 | + FreeStyleProject p = r.createFreeStyleProject(); |
| 138 | + p.addProperty(new ParametersDefinitionProperty(new NullParameterDefinition("foo"))); |
| 139 | + assertThat(p.getLastCompletedBuild(), is(nullValue())); |
| 140 | + Trigger<Job> t = new ParameterizedTimerTrigger("* * * * *%foo=test"); |
| 141 | + t.start(p, true); |
| 142 | + p.addTrigger(t); |
| 143 | + new Cron().doRun(); |
| 144 | + assertThat(p.isInQueue(), is(true)); |
| 145 | + r.waitUntilNoActivity(); |
| 146 | + // Build should complete successfully but will not have any value |
| 147 | + assertThat(p.getLastCompletedBuild(), is(notNullValue())); |
| 148 | + } |
| 149 | + |
| 150 | + private static class NullParameterDefinition extends ParameterDefinition { |
| 151 | + |
| 152 | + public NullParameterDefinition(@Nonnull String name) { |
| 153 | + super(name, null); |
| 154 | + } |
| 155 | + |
| 156 | + @CheckForNull |
| 157 | + @Override |
| 158 | + public ParameterValue createValue(StaplerRequest staplerRequest, JSONObject jsonObject) { |
| 159 | + return null; |
| 160 | + } |
| 161 | + |
| 162 | + @CheckForNull |
| 163 | + @Override |
| 164 | + public ParameterValue createValue(StaplerRequest staplerRequest) { |
| 165 | + return null; |
| 166 | + } |
| 167 | + } |
100 | 168 | }
|
0 commit comments