Skip to content
Browse files
[JENKINS-26781] Reproduced problem in test.
Besides failing in master, it also fails in 4e0af43 (merge of #1443), but passes in the 1.598-SNAPSHOT parent 239caf8.
(cherry picked from commit 3304190)
  • Loading branch information
jglick committed May 14, 2015
1 parent 5ecda76 commit 00cbb2823187df7efcf8c9de33907f0f58c77729
Showing with 65 additions and 0 deletions.
  1. +65 −0 test/src/test/java/hudson/model/
@@ -24,14 +24,25 @@

package hudson.model;

import hudson.Launcher;
import hudson.model.Descriptor.PropertyType;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.Builder;
import hudson.tasks.Shell;
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.StaplerRequest;

@SuppressWarnings({"unchecked", "rawtypes"})
public class DescriptorTest {

public @Rule JenkinsRule rule = new JenkinsRule();
@@ -51,4 +62,58 @@ public class DescriptorTest {

@Ignore("TODO currently fails: after first configRoundtrip, builders list is empty because in newInstancesFromHeteroList $class is BuilderImpl (like stapler-class), kind=builder-a is ignored, and so d is null")
@Test public void overriddenId() throws Exception {
FreeStyleProject p = rule.createFreeStyleProject();
p.getBuildersList().add(new BuilderImpl("builder-a"));
List<Builder> builders = p.getBuildersList();
assertEquals(1, builders.size());
assertEquals(BuilderImpl.class, builders.get(0).getClass());
assertEquals("builder-a", ((BuilderImpl) builders.get(0)).id);
rule.assertLogContains("running builder-a", rule.buildAndAssertSuccess(p));
p.getBuildersList().replace(new BuilderImpl("builder-b"));
builders = p.getBuildersList();
assertEquals(1, builders.size());
assertEquals(BuilderImpl.class, builders.get(0).getClass());
assertEquals("builder-b", ((BuilderImpl) builders.get(0)).id);
rule.assertLogContains("running builder-b", rule.buildAndAssertSuccess(p));
private static final class BuilderImpl extends Builder {
private final String id;
BuilderImpl(String id) { = id;
@Override public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
listener.getLogger().println("running " + getDescriptor().getId());
return true;
@Override public Descriptor<Builder> getDescriptor() {
return (Descriptor<Builder>) Jenkins.getInstance().getDescriptorByName(id);
private static final class DescriptorImpl extends BuildStepDescriptor<Builder> {
private final String id;
DescriptorImpl(String id) {
super(BuilderImpl.class); = id;
@Override public String getId() {
return id;
@Override public Builder newInstance(StaplerRequest req, JSONObject formData) throws Descriptor.FormException {
return new BuilderImpl(id);
@Override public String getDisplayName() {
return id;
@Override public boolean isApplicable(Class<? extends AbstractProject> jobType) {
return true;
@TestExtension("overriddenId") public static final BuildStepDescriptor<Builder> builderA = new DescriptorImpl("builder-a");
@TestExtension("overriddenId") public static final BuildStepDescriptor<Builder> builderB = new DescriptorImpl("builder-b");


0 comments on commit 00cbb28

Please sign in to comment.