Skip to content

Commit

Permalink
Merge pull request #185 from nfalco79/feature/JENKINS-61438
Browse files Browse the repository at this point in the history
[JENKINS-61438] Demonstration of IAE from Stapler
  • Loading branch information
bitwiseman authored Aug 28, 2020
2 parents 75d97a7 + be94713 commit e4acacf
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
1 change: 1 addition & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
buildPlugin(configurations: [
[ platform: "linux", jdk: "8", jenkins: null ],
[ platform: "linux", jdk: "11", jenkins: "2.249" ],
[ platform: "windows", jdk: "8", jenkins: "2.235.3", javaLevel: "8" ],
[ platform: "linux", jdk: "11", jenkins: "2.235.3", javaLevel: "8" ]
])
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,35 @@
package jenkins.branch;

import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.model.ChoiceParameterDefinition;
import hudson.model.ItemGroup;
import hudson.model.Job;
import hudson.model.ParameterDefinition;
import hudson.model.StringParameterDefinition;
import hudson.model.TopLevelItem;
import hudson.util.VersionNumber;
import integration.harness.BasicDummyStepBranchProperty;
import integration.harness.BasicMultiBranchProject;
import java.util.Arrays;
import java.util.Collections;

import jenkins.model.Jenkins;
import jenkins.model.ParameterizedJobMixIn;
import jenkins.scm.impl.mock.MockSCMController;
import jenkins.scm.impl.mock.MockSCMDiscoverBranches;
import jenkins.scm.impl.mock.MockSCMSource;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.TestExtension;
import org.kohsuke.stapler.DataBoundConstructor;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.hasProperty;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.*;
import static org.junit.Assume.assumeThat;

public class ParameterDefinitionBranchPropertyTest {
/**
Expand Down Expand Up @@ -116,6 +118,39 @@ public void jobDecorator_Job_implementing_ParameterizedJob() throws Exception {
assertThat(new ParameterDefinitionBranchPropertyImpl().jobDecorator((Class) ParamJob.class), notNullValue());
}

@Issue("JENKINS-61438")
@Test
public void choiceParameterIssue() throws Exception {
assumeThat(Jenkins.getVersion(), greaterThanOrEqualTo(new VersionNumber("2.242")));
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
BasicMultiBranchProject prj = r.jenkins.createProject(BasicMultiBranchProject.class, "foo");
prj.setCriteria(null);
BranchSource source = new BranchSource(new MockSCMSource(c, "foo", new MockSCMDiscoverBranches()));
ParameterDefinitionBranchPropertyImpl instance = new ParameterDefinitionBranchPropertyImpl();
instance.setParameterDefinitions(Collections.<ParameterDefinition>singletonList(
new ChoiceParameterDefinition("CHOOSE", new String[] { "a", "b" }, "choose one")
));
source.setStrategy(new DefaultBranchPropertyStrategy(new BranchProperty[]{
instance, new BasicDummyStepBranchProperty()
}));
prj.getSourcesList().add(source);
r.configRoundtrip(prj);
assertThat(prj.getSources().get(0).getStrategy(), instanceOf(DefaultBranchPropertyStrategy.class));
DefaultBranchPropertyStrategy strategy =
(DefaultBranchPropertyStrategy) prj.getSources().get(0).getStrategy();
assertThat(strategy.getProps().get(0), instanceOf(ParameterDefinitionBranchPropertyImpl.class));
ParameterDefinitionBranchPropertyImpl property = (ParameterDefinitionBranchPropertyImpl) strategy.getProps().get(0);
assertThat(property.getParameterDefinitions(), contains(
allOf(
instanceOf(ChoiceParameterDefinition.class),
hasProperty("name", is("CHOOSE")),
hasProperty("choices", is(Arrays.asList("a", "b"))),
hasProperty("description", is("choose one"))
)
));
}
}
@Test
public void configRoundtrip() throws Exception {
try (MockSCMController c = MockSCMController.create()) {
Expand Down

0 comments on commit e4acacf

Please sign in to comment.