Skip to content

Commit

Permalink
[JENKINS-51584] Added unit test showing the issue.
Browse files Browse the repository at this point in the history
The Actions are created for the hudson.model.Queue$WaitingItem and
hudson.model.Queue$BuildableItem but get persisted in the actions list
of the build.
  • Loading branch information
jtnord committed May 30, 2018
1 parent 466e49d commit cf3389f
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions test/src/test/java/jenkins/model/TransientActionFactoryTest.java
Expand Up @@ -25,24 +25,26 @@
package jenkins.model;

import hudson.Util;
import hudson.model.AbstractItem;
import hudson.model.AbstractProject;
import hudson.model.Action;
import hudson.model.FreeStyleProject;
import hudson.model.InvisibleAction;
import hudson.model.ProminentProjectAction;
import hudson.model.*;
import hudson.model.queue.FoldableAction;

import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.hamcrest.Matchers;

import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.*;
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.MockFolder;
import org.jvnet.hudson.test.TestExtension;

import javax.annotation.Nonnull;

public class TransientActionFactoryTest {

@Rule public JenkinsRule r = new JenkinsRule();
Expand Down Expand Up @@ -147,6 +149,31 @@ private static class MyAction implements Action {
}
}

@Issue("JENKINS-51584")
@Test
public void transientActionsAreNotPersistedOnQueueItems() throws Exception {
FreeStyleProject p = r.createFreeStyleProject();
FreeStyleBuild build = r.buildAndAssertSuccess(p);
// MyProminentProjectAction is only added via the TransientActionFactory and should never be persisted.
assertThat(build.getActions(MyProminentProjectAction.class), hasSize(0));
assertThat(Util.filter(build.getAllActions(), MyProminentProjectAction.class), hasSize(1));
}

@TestExtension("transientActionsAreNotPersistedOnQueueItems")
public static class AllFactory extends TransientActionFactory<Actionable> {

@Override
public Class<Actionable> type() {
return Actionable.class;
}

@Nonnull
@Override
public Collection<? extends Action> createFor(@Nonnull Actionable target) {
return Collections.singleton(new MyProminentProjectAction());
}
}

private static class MyProminentProjectAction extends InvisibleAction implements ProminentProjectAction {}

}

0 comments on commit cf3389f

Please sign in to comment.