Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-14154] Added a test to demonstrate JENKINS-14154.
  • Loading branch information
ikedam committed Sep 21, 2014
1 parent 9d4982d commit 1a77ddb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
Expand Up @@ -25,20 +25,26 @@
package org.jvnet.hudson.plugins.groovypostbuild;

import static org.junit.Assert.*;

import java.util.Collections;

import hudson.matrix.AxisList;
import hudson.matrix.Combination;
import hudson.matrix.MatrixBuild;
import hudson.matrix.MatrixProject;
import hudson.matrix.TextAxis;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;

import org.apache.commons.lang.StringUtils;
import org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript;
import org.jenkinsci.plugins.scriptsecurity.scripts.ClasspathEntry;
import org.jenkinsci.plugins.scriptsecurity.scripts.ScriptApproval;
import org.jenkinsci.plugins.scriptsecurity.scripts.languages.GroovyLanguage;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.recipes.WithPlugin;

public class GroovyPostbuildRecorderTest {
@Rule
Expand All @@ -64,7 +70,7 @@ public void testMatrixProjectWithParent() throws Exception {
MatrixProject p = j.createMatrixProject();
AxisList axisList = new AxisList(new TextAxis("axis1", "value1", "value2"));
p.setAxes(axisList);
p.getPublishersList().add(new GroovyPostbuildRecorder(new SecureGroovyScript(SCRIPT_FOR_MATRIX, true), 2, true));
p.getPublishersList().add(new GroovyPostbuildRecorder(new SecureGroovyScript(SCRIPT_FOR_MATRIX, true, Collections.<ClasspathEntry>emptyList()), 2, true));

MatrixBuild b = p.scheduleBuild2(0).get();
j.assertBuildStatusSuccess(b);
Expand All @@ -79,7 +85,7 @@ public void testMatrixProjectWithoutParent() throws Exception {
MatrixProject p = j.createMatrixProject();
AxisList axisList = new AxisList(new TextAxis("axis1", "value1", "value2"));
p.setAxes(axisList);
p.getPublishersList().add(new GroovyPostbuildRecorder(new SecureGroovyScript(SCRIPT_FOR_MATRIX, true), 2, false));
p.getPublishersList().add(new GroovyPostbuildRecorder(new SecureGroovyScript(SCRIPT_FOR_MATRIX, true, Collections.<ClasspathEntry>emptyList()), 2, false));

MatrixBuild b = p.scheduleBuild2(0).get();
j.assertBuildStatusSuccess(b);
Expand All @@ -88,4 +94,31 @@ public void testMatrixProjectWithoutParent() throws Exception {
assertEquals("value1", b.getRun(new Combination(axisList, "value1")).getAction(GroovyPostbuildAction.class).getText());
assertEquals("value2", b.getRun(new Combination(axisList, "value2")).getAction(GroovyPostbuildAction.class).getText());
}

@Test
@WithPlugin("dependee.hpi") // provides org.jenkinsci.plugins.dependencytest.dependee.Dependee.getValue() which returns "dependee".
public void testDependencyToAnotherPlugin() throws Exception {
final String SCRIPT =
"import org.jenkinsci.plugins.dependencytest.dependee.Dependee;"
+ "manager.addShortText(Dependee.getValue());";
// as Dependee.getValue isn't whitelisted, we need to approve that.
ScriptApproval.get().preapprove(SCRIPT, GroovyLanguage.get());

FreeStyleProject p = j.createFreeStyleProject();
p.getPublishersList().add(
new GroovyPostbuildRecorder(
new SecureGroovyScript(
SCRIPT,
false,
Collections.<ClasspathEntry>emptyList()
),
2,
false
)
);

FreeStyleBuild b = p.scheduleBuild2(0).get();
j.assertBuildStatusSuccess(b);
assertEquals("dependee", b.getAction(GroovyPostbuildAction.class).getText());
}
}
Binary file added src/test/resources/plugins/dependee.hpi
Binary file not shown.

0 comments on commit 1a77ddb

Please sign in to comment.