diff --git a/test/src/test/java/hudson/model/DescriptorTest.java b/test/src/test/java/hudson/model/DescriptorTest.java index 06885a568f..e3b1dba053 100644 --- a/test/src/test/java/hudson/model/DescriptorTest.java +++ b/test/src/test/java/hudson/model/DescriptorTest.java @@ -30,15 +30,18 @@ import hudson.tasks.BuildStepDescriptor; import hudson.tasks.Builder; import hudson.tasks.Shell; import java.io.IOException; +import java.util.Arrays; import java.util.List; import jenkins.model.Jenkins; import net.sf.json.JSONObject; import static org.junit.Assert.*; +import org.junit.Ignore; import org.junit.Rule; 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 org.kohsuke.stapler.StaplerRequest; @SuppressWarnings({"unchecked", "rawtypes"}) @@ -114,4 +117,94 @@ public class DescriptorTest { @TestExtension("overriddenId") public static final BuildStepDescriptor builderA = new DescriptorImpl("builder-a"); @TestExtension("overriddenId") public static final BuildStepDescriptor builderB = new DescriptorImpl("builder-b"); + @Issue("JENKINS-28110") + @Test public void nestedDescribableOverridingId() throws Exception { + FreeStyleProject p = rule.createFreeStyleProject("p"); + p.getBuildersList().add(new B1(Arrays.asList(new D1(), new D2()))); + rule.configRoundtrip(p); + rule.assertLogContains("[D 1, D 2]", rule.buildAndAssertSuccess(p)); + } + public static abstract class D extends AbstractDescribableImpl { + @Override public String toString() {return getDescriptor().getDisplayName();} + } + public static class D1 extends D { + @DataBoundConstructor public D1() {} + @TestExtension("nestedDescribableOverridingId") public static class DescriptorImpl extends Descriptor { + @Override public String getDisplayName() {return "D 1";} + @Override public String getId() {return "D1-id";} + } + } + public static class D2 extends D { + @DataBoundConstructor public D2() {} + @TestExtension("nestedDescribableOverridingId") public static class DescriptorImpl extends Descriptor { + @Override public String getDisplayName() {return "D 2";} + @Override public String getId() {return "D2-id";} + } + } + public static class B1 extends Builder { + public final List ds; + @DataBoundConstructor public B1(List ds) { + this.ds = ds; + } + @Override public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { + listener.getLogger().println(ds); + return true; + } + @TestExtension("nestedDescribableOverridingId") public static class DescriptorImpl extends Descriptor { + @Override public String getDisplayName() {return "B1";} + } + } + + @Ignore("never worked: TypePair.convertJSON looks for @DataBoundConstructor on D3 (Stapler does not grok Descriptor)") + @Issue("JENKINS-28110") + @Test public void nestedDescribableSharingClass() throws Exception { + FreeStyleProject p = rule.createFreeStyleProject("p"); + p.getBuildersList().add(new B2(Arrays.asList(new D3("d3a"), new D3("d3b")))); + rule.configRoundtrip(p); + rule.assertLogContains("[d3a, d3b]", rule.buildAndAssertSuccess(p)); + } + public static class D3 implements Describable { + private final String id; + D3(String id) { + this.id = id; + } + @Override public String toString() { + return id; + } + @Override public Descriptor getDescriptor() { + return Jenkins.getInstance().getDescriptorByName(id); + } + } + public static class D3D extends Descriptor { + private final String id; + public D3D(String id) { + super(D3.class); + this.id = id; + } + @Override public String getId() { + return id; + } + @Override public D3 newInstance(StaplerRequest req, JSONObject formData) throws Descriptor.FormException { + return new D3(id); + } + @Override public String getDisplayName() { + return id; + } + } + @TestExtension("nestedDescribableSharingClass") public static final Descriptor d3a = new D3D("d3a"); + @TestExtension("nestedDescribableSharingClass") public static final Descriptor d3b = new D3D("d3b"); + public static class B2 extends Builder { + public final List ds; + @DataBoundConstructor public B2(List ds) { + this.ds = ds; + } + @Override public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { + listener.getLogger().println(ds); + return true; + } + @TestExtension("nestedDescribableSharingClass") public static class DescriptorImpl extends Descriptor { + @Override public String getDisplayName() {return "B2";} + } + } + } diff --git a/test/src/test/resources/hudson/model/DescriptorTest/B1/config.jelly b/test/src/test/resources/hudson/model/DescriptorTest/B1/config.jelly new file mode 100644 index 0000000000..494873409f --- /dev/null +++ b/test/src/test/resources/hudson/model/DescriptorTest/B1/config.jelly @@ -0,0 +1,7 @@ + + + + + + + diff --git a/test/src/test/resources/hudson/model/DescriptorTest/B2/config.jelly b/test/src/test/resources/hudson/model/DescriptorTest/B2/config.jelly new file mode 100644 index 0000000000..494873409f --- /dev/null +++ b/test/src/test/resources/hudson/model/DescriptorTest/B2/config.jelly @@ -0,0 +1,7 @@ + + + + + + + diff --git a/test/src/test/resources/hudson/model/DescriptorTest/D1/config.jelly b/test/src/test/resources/hudson/model/DescriptorTest/D1/config.jelly new file mode 100644 index 0000000000..ac4ef60956 --- /dev/null +++ b/test/src/test/resources/hudson/model/DescriptorTest/D1/config.jelly @@ -0,0 +1,3 @@ + + + diff --git a/test/src/test/resources/hudson/model/DescriptorTest/D2/config.jelly b/test/src/test/resources/hudson/model/DescriptorTest/D2/config.jelly new file mode 100644 index 0000000000..ac4ef60956 --- /dev/null +++ b/test/src/test/resources/hudson/model/DescriptorTest/D2/config.jelly @@ -0,0 +1,3 @@ + + + diff --git a/test/src/test/resources/hudson/model/DescriptorTest/D3/config.jelly b/test/src/test/resources/hudson/model/DescriptorTest/D3/config.jelly new file mode 100644 index 0000000000..ac4ef60956 --- /dev/null +++ b/test/src/test/resources/hudson/model/DescriptorTest/D3/config.jelly @@ -0,0 +1,3 @@ + + +