Skip to content
Permalink
Browse files
Test to verify JENKINS-20660 exists in current code
The test is not an exact duplication of the error scenario, but is close
enough to show the problem is resolved.  Exact duplication would require
that a job be defined without a RegExToKill defined, then that job would
need to be executed in a Jenkins instance with the new plugin.

Adds dependency on JUnit 4.11 and Hamcrest, modeled after the same
technique used in Jenkins core and in plugins like the Git plugin.
  • Loading branch information
MarkEWaite committed Nov 27, 2013
1 parent 87601f9 commit 89b6e510450c4b03715cfe1023116fd91a0209bc
Showing with 82 additions and 2 deletions.
  1. +15 −2 pom.xml
  2. +67 −0 src/test/java/hudson/plugins/xshell/UpgradeTest.java
17 pom.xml
@@ -54,6 +54,19 @@
<url>http://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>
</project>


<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
</dependency>
</dependencies>

</project>
@@ -0,0 +1,67 @@
package hudson.plugins.xshell;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

import org.apache.commons.io.FileUtils;

import org.junit.Rule;
import org.junit.Test;

import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.HudsonTestCase;
import org.jvnet.hudson.test.JenkinsRule;

import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;

import hudson.plugins.xshell.XShellBuilder;

/**
* Test upgrade from one version of XShell to another.
*
* @author MarkEWaite
*/
@RunWith(JUnit4.class)
public class UpgradeTest extends HudsonTestCase {
@Rule public JenkinsRule j = new JenkinsRule();

/**
* XShell upgrade from 0.8 to 0.9 reported a null pointer
* exception when the job was first executed after the upgrade.
* The null pointer exception was in the constructor for a regular
* expression.
*
* Creating a new job with a null pointer for the regular
* expression to kill the job shows the same bug, so this test
* creates and executes a new job with a null regexToKill.
*/
@Test @Bug(20660)
public void testXShellBuilderNullAsRegExToKill() throws IOException, InterruptedException, ExecutionException {

FreeStyleProject project = j.createFreeStyleProject();

final String arguments = "hello world";

final boolean execFromWorkingDir = false;
final String regexToKill = null;
final String timeAllocated = null;

project.getBuildersList().add(new XShellBuilder("echo " + arguments, execFromWorkingDir, regexToKill, timeAllocated));

FreeStyleBuild build = project.scheduleBuild2(0).get();
String s = FileUtils.readFileToString(build.getLogFile());

assertThat(s, not(containsString("java.lang.NullPointerException")));
assertThat(s, containsString(arguments));
assertThat(s, containsString("SUCCESS"));
}
}

0 comments on commit 89b6e51

Please sign in to comment.