Skip to content
Permalink
Browse files

[JENKINS-28110] Reproduced problem in test.

Starting in 4f24a02 (1.587-SNAPSHOT, before #1443 or stapler #39), nestedDescribableOverridingId passes.
nestedDescribableSharingClass fails given {stapler-class: D3, kind: d3a}.
(Stapler has no way of interpreting kind since it knows nothing of Descriptor, only implementation class names.)
In master (3080573), both fail in the way reported (only kind is passed in).
After adding stapler-class back, nestedDescribableOverridingId passes again.
(cherry picked from commit 1f41bec)
  • Loading branch information...
jglick committed Apr 28, 2015
1 parent 2e51740 commit 11d46ad639943feb9f17da5d4d1529cdfbd87495
@@ -30,15 +30,18 @@
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 @@
@TestExtension("overriddenId") public static final BuildStepDescriptor<Builder> builderA = new DescriptorImpl("builder-a");
@TestExtension("overriddenId") public static final BuildStepDescriptor<Builder> 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<D> {
@Override public String toString() {return getDescriptor().getDisplayName();}
}
public static class D1 extends D {
@DataBoundConstructor public D1() {}
@TestExtension("nestedDescribableOverridingId") public static class DescriptorImpl extends Descriptor<D> {
@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<D> {
@Override public String getDisplayName() {return "D 2";}
@Override public String getId() {return "D2-id";}
}
}
public static class B1 extends Builder {
public final List<D> ds;
@DataBoundConstructor public B1(List<D> 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<Builder> {
@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<D3> {
private final String id;
D3(String id) {
this.id = id;
}
@Override public String toString() {
return id;
}
@Override public Descriptor<D3> getDescriptor() {
return Jenkins.getInstance().getDescriptorByName(id);
}
}
public static class D3D extends Descriptor<D3> {
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<D3> d3a = new D3D("d3a");
@TestExtension("nestedDescribableSharingClass") public static final Descriptor<D3> d3b = new D3D("d3b");
public static class B2 extends Builder {
public final List<D3> ds;
@DataBoundConstructor public B2(List<D3> 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<Builder> {
@Override public String getDisplayName() {return "B2";}
}
}

}
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
<f:block>
<f:repeatableHeteroProperty field="ds"/>
</f:block>
</j:jelly>
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
<f:block>
<f:repeatableHeteroProperty field="ds"/>
</f:block>
</j:jelly>
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core"/>
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core"/>
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core"/>

0 comments on commit 11d46ad

Please sign in to comment.
You can’t perform that action at this time.