Skip to content
Permalink
Browse files

Add a regression test to fix JENKINS-15658

  • Loading branch information...
gboissinot committed Nov 2, 2012
1 parent b1d9dbe commit be86097a4ebf373d4874cc5e89e89fd250bf3a01
@@ -21,7 +21,7 @@
*/
public class EnvInjectJobProperty<T extends Job<?, ?>> extends JobProperty<T> {

private EnvInjectJobPropertyInfo info;
private EnvInjectJobPropertyInfo info = new EnvInjectJobPropertyInfo();
private boolean on;
private boolean keepJenkinsSystemVariables;
private boolean keepBuildVariables;
@@ -13,6 +13,10 @@
private String groovyScriptContent;
private boolean loadFilesFromMaster;

public EnvInjectJobPropertyInfo() {
super(null, null);
}

@DataBoundConstructor
public EnvInjectJobPropertyInfo(String propertiesFilePath, String propertiesContent, String scriptFilePath, String scriptContent, String groovyScriptContent, boolean loadFilesFromMaster) {
super(propertiesFilePath, propertiesContent);
@@ -0,0 +1,60 @@
package org.jenkinsci.plugins.envinject;

import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.Hudson;
import hudson.model.Result;
import hudson.slaves.EnvironmentVariablesNodeProperty;
import hudson.slaves.NodeProperty;
import hudson.slaves.NodePropertyDescriptor;
import hudson.util.DescribableList;
import junit.framework.Assert;
import org.jvnet.hudson.test.HudsonTestCase;

import java.util.Map;

/**
* @author Gregory Boissinot
*/
public class GlobalPropertiesTest extends HudsonTestCase {


private FreeStyleProject project;

@Override
public void setUp() throws Exception {
super.setUp();
project = createFreeStyleProject();
}


public void testGlobalPropertiesWithWORKSPACE() throws Exception {

final String testWorkspaceVariableName = "TEST_WORKSPACE";
final String testWorkspaceVariableValue = "${WORKSPACE}";
final String workspaceName = "WORKSPACE";

//A global node property TEST_WORKSPACE
DescribableList<NodeProperty<?>, NodePropertyDescriptor> globalNodeProperties = Hudson.getInstance().getGlobalNodeProperties();
globalNodeProperties.add(new EnvironmentVariablesNodeProperty(new EnvironmentVariablesNodeProperty.Entry(testWorkspaceVariableName, testWorkspaceVariableValue)));

EnvInjectJobProperty jobProperty = new EnvInjectJobProperty();
jobProperty.setOn(true);
jobProperty.setKeepBuildVariables(true);
jobProperty.setKeepJenkinsSystemVariables(true);
project.addProperty(jobProperty);

FreeStyleBuild build = project.scheduleBuild2(0).get();
Assert.assertEquals(Result.SUCCESS, build.getResult());

org.jenkinsci.lib.envinject.EnvInjectAction action = build.getAction(org.jenkinsci.lib.envinject.EnvInjectAction.class);
Map<String, String> envVars = action.getEnvMap();

String workspaceProcessed = envVars.get(workspaceName);
assertNotNull(workspaceProcessed);
String testWorkspaceProcessed = envVars.get(testWorkspaceVariableName);
assertNotNull(testWorkspaceProcessed);

assertEquals(workspaceProcessed, testWorkspaceProcessed);
}
}

0 comments on commit be86097

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