Skip to content
Permalink
Browse files

[JENKINS-26694] Make tests succeed on Windows: HudsonTestCase using w…

…orkflow-1.1 fails for JENKINS-26030.
  • Loading branch information...
ikedam committed Feb 28, 2015
1 parent 5346281 commit 1308f8da0170ff3010054417bdcf5d88bd536df4
@@ -71,8 +71,6 @@
import org.acegisecurity.context.SecurityContext;
import org.acegisecurity.context.SecurityContextHolder;
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.junit.Test;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.ExtractResourceSCM;
@@ -1134,54 +1132,6 @@ public void testSpecificBuildSelectorWithParameterFilter() throws Exception {
assertFile(false, "foo.txt", b);
}

/**
* Test filtering on parameters works to copy from workflow jobs.
*/
@Bug(26694)
public void testFilterByParametersForWorkflow() throws Exception {
WorkflowJob copiee = jenkins.createProject(WorkflowJob.class, createUniqueProjectName());
copiee.addProperty(new ParametersDefinitionProperty(
new StringParameterDefinition("PARAM", "")
));
copiee.setDefinition(new CpsFlowDefinition(
"node {"
+ "writeFile text: \"${PARAM}\", file:'artifact.txt';"
+ "archive includes:'artifact.txt';"
+ "}",
true
));

FreeStyleProject copier = createFreeStyleProject();
copier.addProperty(new ParametersDefinitionProperty(
new StringParameterDefinition("PARAM_TO_COPY", "")
));
copier.getBuildersList().add(CopyArtifactUtil.createCopyArtifact(
copiee.getFullName(),
"PARAM=${PARAM_TO_COPY}",
new LastCompletedBuildSelector(),
"artifact.txt",
"",
false,
false
));

// #1: PARAM=foo
assertBuildStatusSuccess(copiee.scheduleBuild2(0, new ParametersAction(
new StringParameterValue("PARAM", "foo")
)));
// #2: PARAM=bar
assertBuildStatusSuccess(copiee.scheduleBuild2(0, new ParametersAction(
new StringParameterValue("PARAM", "bar")
)));

FreeStyleBuild build = copier.scheduleBuild2(0, new UserCause(), new ParametersAction(
new StringParameterValue("PARAM_TO_COPY", "foo")
)).get();
assertBuildStatusSuccess(build);

assertEquals("foo", build.getWorkspace().child("artifact.txt").readToString());
}

// Verify BuildSelector defaults to false
public void testBuildSelectorDefault() {
assertFalse(new BuildSelector() { }.isSelectable(null, null));
@@ -23,13 +23,24 @@
*/
package hudson.plugins.copyartifact;

import static org.junit.Assert.*;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.ParametersAction;
import hudson.model.ParametersDefinitionProperty;
import hudson.model.Run;
import hudson.model.StringParameterDefinition;
import hudson.model.StringParameterValue;
import hudson.model.Cause.UserCause;
import hudson.plugins.copyartifact.testutils.CopyArtifactUtil;

import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.JenkinsRule;

import java.io.IOException;
@@ -60,6 +71,58 @@ public void test_simpleUntriggeredCopy() throws Exception {
assertArtifactInArchive(b);
}

/**
* Test filtering on parameters works to copy from workflow jobs.
*/
@Bug(26694)
@Test
public void testFilterByParametersForWorkflow() throws Exception {
WorkflowJob copiee = createWorkflow("copiee",
"writeFile text: \"${PARAM}\", file:'artifact.txt';"
+ "archive includes:'artifact.txt';"
);
copiee.addProperty(new ParametersDefinitionProperty(
new StringParameterDefinition("PARAM", "")
));
copiee.setDefinition(new CpsFlowDefinition(
"node {"
+ "writeFile text: \"${PARAM}\", file:'artifact.txt';"
+ "archive includes:'artifact.txt';"
+ "}",
true
));

FreeStyleProject copier = jenkinsRule.createFreeStyleProject();
copier.addProperty(new ParametersDefinitionProperty(
new StringParameterDefinition("PARAM_TO_COPY", "")
));
copier.getBuildersList().add(CopyArtifactUtil.createCopyArtifact(
copiee.getFullName(),
"PARAM=${PARAM_TO_COPY}",
new LastCompletedBuildSelector(),
"artifact.txt",
"",
false,
false
));

// #1: PARAM=foo
jenkinsRule.assertBuildStatusSuccess(copiee.scheduleBuild2(0, new ParametersAction(
new StringParameterValue("PARAM", "foo")
)));
// #2: PARAM=bar
jenkinsRule.assertBuildStatusSuccess(copiee.scheduleBuild2(0, new ParametersAction(
new StringParameterValue("PARAM", "bar")
)));

FreeStyleBuild build = copier.scheduleBuild2(0, new UserCause(), new ParametersAction(
new StringParameterValue("PARAM_TO_COPY", "foo")
)).get();
jenkinsRule.assertBuildStatusSuccess(build);

assertEquals("foo", build.getWorkspace().child("artifact.txt").readToString());
}

private void assertArtifactInArchive(Run b) {
List<WorkflowRun.Artifact> artifacts = b.getArtifacts();
Assert.assertEquals(1, artifacts.size());

0 comments on commit 1308f8d

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