Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
87601f9
commit 89b6e51
Showing
2 changed files
with
82 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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")); | ||
} | ||
} |