org.jvnet.hudson.test
Class HudsonTestCase

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.jvnet.hudson.test.HudsonTestCase
All Implemented Interfaces:
junit.framework.Test

public abstract class HudsonTestCase
extends junit.framework.TestCase

Base class for all Hudson test cases.

Author:
Kohsuke Kawaguchi
See Also:
Wiki article about unit testing in Hudson

Nested Class Summary
 class HudsonTestCase.WebClient
          Extends WebClient and provide convenience methods for accessing Hudson.
 
Field Summary
protected  java.lang.String contextPath
          Where in the Server is Hudson deploed?
protected  TestEnvironment env
           
protected  HudsonHomeLoader homeLoader
           
 Hudson hudson
           
protected  JavaScriptDebugger jsDebugger
          JavaScript "debugger" that provides you information about the JavaScript call stack and the current values of the local variables in those stack frame.
protected  int localPort
          TCP/IP port that the server is listening on.
protected  java.util.List<Recipe.Runner> recipes
           
protected  org.mortbay.jetty.Server server
           
protected  java.util.List<LenientRunnable> tearDowns
          Runnables to be invoked at tearDown().
 
Constructor Summary
protected HudsonTestCase()
           
protected HudsonTestCase(java.lang.String name)
           
 
Method Summary
<R extends Run>
R
assertBuildStatus(Result status, R r)
          Asserts that the outcome of the build is a specific outcome.
<R extends Run>
R
assertBuildStatusSuccess(R r)
           
 void assertLogContains(java.lang.String substring, Run run)
          Asserts that the console output of the build contains the given substring.
 void assertXPath(com.gargoylesoftware.htmlunit.html.HtmlPage page, java.lang.String xpath)
          Asserts that the XPath matches.
protected  void configureDefaultMaven()
          Locates Maven2 and configure that as the only Maven in the system.
protected  org.mortbay.jetty.security.UserRealm configureUserRealm()
          Configures a security realm for a test.
protected  FreeStyleProject createFreeStyleProject()
           
protected  FreeStyleProject createFreeStyleProject(java.lang.String name)
           
protected  Launcher.LocalLauncher createLocalLauncher()
          Creates Launcher.LocalLauncher.
protected  MatrixProject createMatrixProject()
           
protected  MatrixProject createMatrixProject(java.lang.String name)
           
protected  MavenModuleSet createMavenProject()
          Creates a empty Maven project with an unique name.
protected  MavenModuleSet createMavenProject(java.lang.String name)
          Creates a empty Maven project with the given name.
 DumbSlave createSlave()
           
 DumbSlave createSlave(Label l)
          Creates and launches a new slave on the local host.
 TaskListener createTaskListener()
          Creates a TaskListener connected to stdout.
 java.io.File createTmpDir()
          Allocates a new temporary directory for the duration of this test.
protected  javax.servlet.ServletContext createWebServer()
          Prepares a webapp hosting environment to get ServletContext implementation that we need for testing.
protected
<T> T
last(java.util.List<T> items)
          Returns the last item in the list.
protected  Hudson newHudson()
          Creates a new instance of Hudson.
protected  void pause()
          Pauses the execution until ENTER is hit in the console.
protected  void recipe()
          Called during the setUp() to give a test case an opportunity to control the test environment in which Hudson is run.
protected  void recipeLoadCurrentPlugin()
          If this test harness is launched for a Hudson plugin, locate the target/test-classes/the.hpl and add a recipe to install that to the new Hudson.
protected  void runTest()
           
protected  com.gargoylesoftware.htmlunit.Page search(java.lang.String q)
          Performs a search from the search box.
protected  void setUp()
           
 com.gargoylesoftware.htmlunit.html.HtmlPage submit(com.gargoylesoftware.htmlunit.html.HtmlForm form)
          Submits the form.
protected  void tearDown()
           
 HudsonTestCase with(HudsonHomeLoader homeLoader)
           
 HudsonTestCase withExistingHome(java.io.File source)
           
 HudsonTestCase withNewHome()
           
 HudsonTestCase withPresetData(java.lang.String name)
          Declares that this test case expects to start with one of the preset data sets.
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, setName, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

hudson

public Hudson hudson

env

protected final TestEnvironment env

homeLoader

protected HudsonHomeLoader homeLoader

localPort

protected int localPort
TCP/IP port that the server is listening on.


server

protected org.mortbay.jetty.Server server

contextPath

protected java.lang.String contextPath
Where in the Server is Hudson deploed?


tearDowns

protected java.util.List<LenientRunnable> tearDowns
Runnables to be invoked at tearDown().


recipes

protected java.util.List<Recipe.Runner> recipes

jsDebugger

protected JavaScriptDebugger jsDebugger
JavaScript "debugger" that provides you information about the JavaScript call stack and the current values of the local variables in those stack frame.

Unlike Java debugger, which you as a human interfaces directly and interactively, this JavaScript debugger is to be interfaced by your program (or through the expression evaluation capability of your Java debugger.)

Constructor Detail

HudsonTestCase

protected HudsonTestCase(java.lang.String name)

HudsonTestCase

protected HudsonTestCase()
Method Detail

setUp

protected void setUp()
              throws java.lang.Exception
Overrides:
setUp in class junit.framework.TestCase
Throws:
java.lang.Exception

tearDown

protected void tearDown()
                 throws java.lang.Exception
Overrides:
tearDown in class junit.framework.TestCase
Throws:
java.lang.Exception

runTest

protected void runTest()
                throws java.lang.Throwable
Overrides:
runTest in class junit.framework.TestCase
Throws:
java.lang.Throwable

newHudson

protected Hudson newHudson()
                    throws java.lang.Exception
Creates a new instance of Hudson. If the derived class wants to create it in a different way, you can override it.

Throws:
java.lang.Exception

createWebServer

protected javax.servlet.ServletContext createWebServer()
                                                throws java.lang.Exception
Prepares a webapp hosting environment to get ServletContext implementation that we need for testing.

Throws:
java.lang.Exception

configureUserRealm

protected org.mortbay.jetty.security.UserRealm configureUserRealm()
Configures a security realm for a test.


configureDefaultMaven

protected void configureDefaultMaven()
                              throws java.lang.Exception
Locates Maven2 and configure that as the only Maven in the system.

Throws:
java.lang.Exception

createFreeStyleProject

protected FreeStyleProject createFreeStyleProject()
                                           throws java.io.IOException
Throws:
java.io.IOException

createFreeStyleProject

protected FreeStyleProject createFreeStyleProject(java.lang.String name)
                                           throws java.io.IOException
Throws:
java.io.IOException

createMatrixProject

protected MatrixProject createMatrixProject()
                                     throws java.io.IOException
Throws:
java.io.IOException

createMatrixProject

protected MatrixProject createMatrixProject(java.lang.String name)
                                     throws java.io.IOException
Throws:
java.io.IOException

createMavenProject

protected MavenModuleSet createMavenProject()
                                     throws java.io.IOException
Creates a empty Maven project with an unique name.

Throws:
java.io.IOException
See Also:
configureDefaultMaven()

createMavenProject

protected MavenModuleSet createMavenProject(java.lang.String name)
                                     throws java.io.IOException
Creates a empty Maven project with the given name.

Throws:
java.io.IOException
See Also:
configureDefaultMaven()

createLocalLauncher

protected Launcher.LocalLauncher createLocalLauncher()
Creates Launcher.LocalLauncher. Useful for launching processes.


createTmpDir

public java.io.File createTmpDir()
                          throws java.io.IOException
Allocates a new temporary directory for the duration of this test.

Throws:
java.io.IOException

createSlave

public DumbSlave createSlave()
                      throws java.lang.Exception
Throws:
java.lang.Exception

createSlave

public DumbSlave createSlave(Label l)
                      throws java.lang.Exception
Creates and launches a new slave on the local host.

Throws:
java.lang.Exception

last

protected <T> T last(java.util.List<T> items)
Returns the last item in the list.


pause

protected void pause()
              throws java.io.IOException
Pauses the execution until ENTER is hit in the console.

This is often very useful so that you can interact with Hudson from an browser, while developing a test case.

Throws:
java.io.IOException

search

protected com.gargoylesoftware.htmlunit.Page search(java.lang.String q)
                                             throws java.lang.Exception
Performs a search from the search box.

Throws:
java.lang.Exception

assertBuildStatus

public <R extends Run> R assertBuildStatus(Result status,
                                           R r)
                                throws java.lang.Exception
Asserts that the outcome of the build is a specific outcome.

Throws:
java.lang.Exception

assertBuildStatusSuccess

public <R extends Run> R assertBuildStatusSuccess(R r)
                                       throws java.lang.Exception
Throws:
java.lang.Exception

assertLogContains

public void assertLogContains(java.lang.String substring,
                              Run run)
                       throws java.lang.Exception
Asserts that the console output of the build contains the given substring.

Throws:
java.lang.Exception

assertXPath

public void assertXPath(com.gargoylesoftware.htmlunit.html.HtmlPage page,
                        java.lang.String xpath)
Asserts that the XPath matches.


submit

public com.gargoylesoftware.htmlunit.html.HtmlPage submit(com.gargoylesoftware.htmlunit.html.HtmlForm form)
                                                   throws java.lang.Exception
Submits the form.

Throws:
java.lang.Exception

createTaskListener

public TaskListener createTaskListener()
Creates a TaskListener connected to stdout.


recipe

protected void recipe()
               throws java.lang.Exception
Called during the setUp() to give a test case an opportunity to control the test environment in which Hudson is run.

One could override this method and call a series of withXXX methods, or you can use the annotations with Recipe meta-annotation.

Throws:
java.lang.Exception

recipeLoadCurrentPlugin

protected void recipeLoadCurrentPlugin()
                                throws java.lang.Exception
If this test harness is launched for a Hudson plugin, locate the target/test-classes/the.hpl and add a recipe to install that to the new Hudson.

This file is created by maven-hpi-plugin at the testCompile phase when the current packaging is hpi.

Throws:
java.lang.Exception

withNewHome

public HudsonTestCase withNewHome()

withExistingHome

public HudsonTestCase withExistingHome(java.io.File source)
                                throws java.lang.Exception
Throws:
java.lang.Exception

withPresetData

public HudsonTestCase withPresetData(java.lang.String name)
Declares that this test case expects to start with one of the preset data sets. See https://svn.dev.java.net/svn/hudson/trunk/hudson/main/test/src/main/preset-data/ for available datasets and what they mean.


with

public HudsonTestCase with(HudsonHomeLoader homeLoader)


Copyright © 2009. All Rights Reserved.