org.jvnet.hudson.test
Class JenkinsRule

java.lang.Object
  extended by org.jvnet.hudson.test.JenkinsRule
All Implemented Interfaces:
hudson.ExtensionPoint, hudson.model.Action, hudson.model.ModelObject, hudson.model.RootAction, org.junit.rules.TestRule

public class JenkinsRule
extends Object
implements org.junit.rules.TestRule, hudson.model.RootAction

JUnit 4.10+ style rule to allow test cases to fire up a Jenkins instance

Author:
Stephen Connolly
See Also:
Wiki article about unit testing in Jenkins

Nested Class Summary
static class JenkinsRule.BreakException
           
static class JenkinsRule.ComputerListenerImpl
           
static class JenkinsRule.TestBuildWrapper
           
 class JenkinsRule.WebClient
          Extends WebClient and provide convenience methods for accessing Hudson.
 
Nested classes/interfaces inherited from interface hudson.ExtensionPoint
hudson.ExtensionPoint.LegacyInstancesAreScopedToHudson
 
Field Summary
 JenkinsComputerConnectorTester computerConnectorTester
           
protected  String contextPath
          Where in the Server is Hudson deployed?
protected  HudsonHomeLoader homeLoader
           
 hudson.model.Hudson hudson
          Points to the same object as jenkins does.
 jenkins.model.Jenkins jenkins
           
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.
static org.mortbay.jetty.MimeTypes MIME_TYPES
           
protected static List<hudson.tools.ToolProperty<?>> NO_PROPERTIES
           
protected  List<JenkinsRecipe.Runner> recipes
           
protected  org.mortbay.jetty.Server server
           
static int SLAVE_DEBUG_PORT
          Specify this to a TCP/IP port number to have slaves started with the debugger.
protected  List<LenientRunnable> tearDowns
          Runnables to be invoked at after() .
 boolean useLocalPluginManager
          Deprecated. Use pluginManager
 
Constructor Summary
JenkinsRule()
           
 
Method Summary
protected  void after()
          Override to tear down your specific external resource.
 org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runner.Description description)
           
 void assertAllImageLoadSuccessfully(com.gargoylesoftware.htmlunit.html.HtmlPage p)
          Makes sure that all the images in the page loads successfully.
<R extends hudson.model.Run>
R
assertBuildStatus(hudson.model.Result status, R r)
          Asserts that the outcome of the build is a specific outcome.
<R extends hudson.model.Run>
R
assertBuildStatusSuccess(Future<? extends R> r)
           
<R extends hudson.model.Run>
R
assertBuildStatusSuccess(R r)
           
 void assertEqualBeans(Object lhs, Object rhs, String properties)
          Asserts that two JavaBeans are equal as far as the given list of properties are concerned.
 void assertEqualDataBoundBeans(List<?> lhs, List<?> rhs)
          Makes sure that two collections are identical via assertEqualDataBoundBeans(Object, Object)
 void assertEqualDataBoundBeans(Object lhs, Object rhs)
          Works like assertEqualBeans(Object, Object, String) but figure out the properties via DataBoundConstructor
 void assertGoodStatus(com.gargoylesoftware.htmlunit.Page page)
          Assert that the specifed page can be served with a "good" HTTP status, eg, the page is not missing and can be served without a server error
 void assertHelpExists(Class<? extends hudson.model.Describable> type, String properties)
          Asserts that help files exist for the specified properties of the given instance.
 void assertLogContains(String substring, hudson.model.Run run)
          Asserts that the console output of the build contains the given substring.
 void assertStringContains(String haystack, String needle)
           
 void assertStringContains(String message, String haystack, String needle)
           
 void assertXPath(com.gargoylesoftware.htmlunit.html.DomNode page, String xpath)
          Asserts that the XPath matches the contents of a DomNode page.
 void assertXPath(com.gargoylesoftware.htmlunit.html.HtmlPage page, String xpath)
          Asserts that the XPath matches.
 void assertXPathResultsContainText(com.gargoylesoftware.htmlunit.html.DomNode page, String xpath, String needle)
           
 void assertXPathValue(com.gargoylesoftware.htmlunit.html.DomNode page, String xpath, String expectedValue)
           
 void assertXPathValueContains(com.gargoylesoftware.htmlunit.html.DomNode page, String xpath, String needle)
           
protected  void before()
          Override to set up your specific external resource.
 hudson.model.FreeStyleBuild buildAndAssertSuccess(hudson.model.FreeStyleProject job)
          Avoids need for cumbersome this.<J,R>buildAndAssertSuccess(...) type hints under JDK 7 javac (and supposedly also IntelliJ).
<J extends hudson.model.AbstractProject<J,R>,R extends hudson.model.AbstractBuild<J,R>>
R
buildAndAssertSuccess(J job)
           
 hudson.maven.MavenBuild buildAndAssertSuccess(hudson.maven.MavenModule job)
           
 hudson.maven.MavenModuleSetBuild buildAndAssertSuccess(hudson.maven.MavenModuleSet job)
           
protected  void configRoundtrip()
          Hits the Hudson system configuration and submits without any modification.
protected
<B extends hudson.tasks.Builder>
B
configRoundtrip(B before)
          Performs a configuration round-trip testing for a builder.
protected
<C extends hudson.slaves.ComputerConnector>
C
configRoundtrip(C before)
           
protected
<N extends hudson.model.Node>
N
configRoundtrip(N node)
           
protected
<P extends hudson.model.Item>
P
configRoundtrip(P job)
           
protected
<P extends hudson.model.Job>
P
configRoundtrip(P job)
          Loads a configuration page and submits it without any modifications, to perform a round-trip configuration test.
protected
<P extends hudson.tasks.Publisher>
P
configRoundtrip(P before)
          Performs a configuration round-trip testing for a publisher.
protected  hudson.model.User configRoundtrip(hudson.model.User u)
           
protected
<V extends hudson.model.View>
V
configRoundtrip(V view)
           
protected  hudson.tasks.Ant.AntInstallation configureDefaultAnt()
          Extracts Ant and configures it.
protected  hudson.tasks.Maven.MavenInstallation configureDefaultMaven()
          Returns the older default Maven, while still allowing specification of other bundled Mavens.
protected  hudson.tasks.Maven.MavenInstallation configureDefaultMaven(String mavenVersion, int mavenReqVersion)
          Locates Maven2 and configure that as the only Maven in the system.
protected  hudson.tasks.Maven.MavenInstallation configureMaven3()
           
protected  void configureUpdateCenter()
          Configures the update center setting for the test.
protected  org.mortbay.jetty.security.UserRealm configureUserRealm()
          Configures a security realm for a test.
 hudson.slaves.CommandLauncher createComputerLauncher(hudson.EnvVars env)
          Creates a CommandLauncher for launching a slave locally.
 hudson.security.SecurityRealm createDummySecurityRealm()
          Creates a test SecurityRealm that recognizes username==password as valid.
protected  hudson.model.FreeStyleProject createFreeStyleProject()
           
protected  hudson.model.FreeStyleProject createFreeStyleProject(String name)
           
protected  hudson.Launcher.LocalLauncher createLocalLauncher()
          Creates Launcher.LocalLauncher.
protected  hudson.matrix.MatrixProject createMatrixProject()
           
protected  hudson.matrix.MatrixProject createMatrixProject(String name)
           
protected  hudson.maven.MavenModuleSet createMavenProject()
          Creates a empty Maven project with an unique name.
protected  hudson.maven.MavenModuleSet createMavenProject(String name)
          Creates a empty Maven project with the given name.
 hudson.slaves.DumbSlave createOnlineSlave()
          Create a new slave on the local host and wait for it to come onilne before returning.
 hudson.slaves.DumbSlave createOnlineSlave(hudson.model.Label l)
          Create a new slave on the local host and wait for it to come onilne before returning.
 hudson.slaves.DumbSlave createOnlineSlave(hudson.model.Label l, hudson.EnvVars env)
          Create a new slave on the local host and wait for it to come online before returning
 PretendSlave createPretendSlave(FakeLauncher faker)
           
 hudson.slaves.DumbSlave createSlave()
           
 hudson.slaves.DumbSlave createSlave(hudson.EnvVars env)
           
 hudson.slaves.DumbSlave createSlave(hudson.model.Label l)
          Creates and launches a new slave on the local host.
 hudson.slaves.DumbSlave createSlave(hudson.model.Label l, hudson.EnvVars env)
           
 hudson.slaves.DumbSlave createSlave(String labels, hudson.EnvVars env)
          Creates a slave with certain additional environment variables
 hudson.slaves.DumbSlave createSlave(String nodeName, String labels, hudson.EnvVars env)
           
 hudson.model.TaskListener createTaskListener()
          Creates a TaskListener connected to stdout.
 File createTmpDir()
          Allocates a new temporary directory for the duration of this test.
 JenkinsRule.WebClient createWebClient()
          This is to assist Groovy test clients who are incapable of instantiating the inner classes properly.
protected  javax.servlet.ServletContext createWebServer()
          Prepares a webapp hosting environment to get ServletContext implementation that we need for testing.
<V> V
executeOnServer(Callable<V> c)
          Executes the given closure on the server, by the servlet request handling thread, in the context of an HTTP request.
protected  Constructor<?> findDataBoundConstructor(Class<?> c)
           
protected  com.gargoylesoftware.htmlunit.html.HtmlInput findPreviousInputElement(com.gargoylesoftware.htmlunit.html.HtmlElement current, String name)
           
protected
<T extends hudson.model.Descriptor<?>>
T
get(Class<T> d)
          Gets the descriptor instance of the current Hudson by its type.
protected  com.gargoylesoftware.htmlunit.html.HtmlButton getButtonByCaption(com.gargoylesoftware.htmlunit.html.HtmlForm f, String s)
           
 String getDisplayName()
           
 String getIconFileName()
           
 jenkins.model.Jenkins getInstance()
           
protected static String getLog(hudson.model.Run run)
          Get entire log file (this method is deprecated in hudson.model.Run, but in tests it is OK to load entire log).
 hudson.PluginManager getPluginManager()
           
 URL getURL()
          Returns the URL of the webapp top page.
 String getUrlName()
           
 File getWebAppRoot()
           
 void interactiveBreak()
          Blocks until the ENTER key is hit.
 boolean isGoodHttpStatus(int status)
          Determines whether the specifed HTTP status code is generally "good"
protected  boolean isSomethingHappening()
          Returns true if Hudson is building something or going to build something.
protected
<T> T
last(List<T> items)
          Returns the last item in the list.
protected  hudson.model.Hudson newHudson()
          Creates a new instance of Jenkins.
protected  void pause()
          Pauses the execution until ENTER is hit in the console.
protected  void recipe()
          Called during the before() 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 Jenkins plugin, locate the target/test-classes/the.hpl and add a recipe to install that to the new Jenkins.
protected  com.gargoylesoftware.htmlunit.Page search(String q)
          Performs a search from the search box.
 void setPluginManager(hudson.PluginManager pluginManager)
          Sets the PluginManager to be used when creating a new Jenkins instance.
protected  void setQuietPeriod(int qp)
           
 com.gargoylesoftware.htmlunit.html.HtmlPage submit(com.gargoylesoftware.htmlunit.html.HtmlForm form)
          Submits the form.
 com.gargoylesoftware.htmlunit.html.HtmlPage submit(com.gargoylesoftware.htmlunit.html.HtmlForm form, String name)
          Submits the form by clikcing the submit button of the given name.
protected  void waitUntilNoActivity()
          Waits until Hudson finishes building everything, including those in the queue.
protected  void waitUntilNoActivityUpTo(int timeout)
          Waits until Hudson finishes building everything, including those in the queue, or fail the test if the specified timeout milliseconds is
 JenkinsRule with(HudsonHomeLoader homeLoader)
           
 JenkinsRule with(hudson.PluginManager pluginManager)
           
 JenkinsRule withExistingHome(File source)
           
 JenkinsRule withNewHome()
           
 JenkinsRule withPresetData(String name)
          Declares that this test case expects to start with one of the preset data sets.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

hudson

public hudson.model.Hudson hudson
Points to the same object as jenkins does.


jenkins

public jenkins.model.Jenkins jenkins

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 String contextPath
Where in the Server is Hudson deployed?

Just like ServletContext.getContextPath(), starts with '/' but doesn't end with '/'.


tearDowns

protected List<LenientRunnable> tearDowns
Runnables to be invoked at after() .


recipes

protected List<JenkinsRecipe.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.)


useLocalPluginManager

public boolean useLocalPluginManager
Deprecated. Use pluginManager
If this test case has additional WithPlugin annotations, set to true. This will cause a fresh PluginManager to be created for this test. Leaving this to false enables the test harness to use a pre-loaded plugin manager, which runs faster.


computerConnectorTester

public JenkinsComputerConnectorTester computerConnectorTester

NO_PROPERTIES

protected static final List<hudson.tools.ToolProperty<?>> NO_PROPERTIES

SLAVE_DEBUG_PORT

public static int SLAVE_DEBUG_PORT
Specify this to a TCP/IP port number to have slaves started with the debugger.


MIME_TYPES

public static final org.mortbay.jetty.MimeTypes MIME_TYPES
Constructor Detail

JenkinsRule

public JenkinsRule()
Method Detail

getInstance

public jenkins.model.Jenkins getInstance()

before

protected void before()
               throws Throwable
Override to set up your specific external resource.

Throws:
Throwable - if setup fails (which will disable after

configureUpdateCenter

protected void configureUpdateCenter()
                              throws Exception
Configures the update center setting for the test. By default, we load updates from local proxy to avoid network traffic as much as possible.

Throws:
Exception

after

protected void after()
Override to tear down your specific external resource.


apply

public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base,
                                               org.junit.runner.Description description)
Specified by:
apply in interface org.junit.rules.TestRule

getIconFileName

public String getIconFileName()
Specified by:
getIconFileName in interface hudson.model.Action

getDisplayName

public String getDisplayName()
Specified by:
getDisplayName in interface hudson.model.Action
Specified by:
getDisplayName in interface hudson.model.ModelObject

getUrlName

public String getUrlName()
Specified by:
getUrlName in interface hudson.model.Action

newHudson

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

Throws:
Exception

getPluginManager

public hudson.PluginManager getPluginManager()

setPluginManager

public void setPluginManager(hudson.PluginManager pluginManager)
Sets the PluginManager to be used when creating a new Jenkins instance.

Parameters:
pluginManager - null to let Jenkins create a new instance of default plugin manager, like it normally does when running as a webapp outside the test.

with

public JenkinsRule with(hudson.PluginManager pluginManager)

getWebAppRoot

public File getWebAppRoot()
                   throws Exception
Throws:
Exception

createWebServer

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

Throws:
Exception

configureUserRealm

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


configureDefaultMaven

protected hudson.tasks.Maven.MavenInstallation configureDefaultMaven()
                                                              throws Exception
Returns the older default Maven, while still allowing specification of other bundled Mavens.

Throws:
Exception

configureMaven3

protected hudson.tasks.Maven.MavenInstallation configureMaven3()
                                                        throws Exception
Throws:
Exception

configureDefaultMaven

protected hudson.tasks.Maven.MavenInstallation configureDefaultMaven(String mavenVersion,
                                                                     int mavenReqVersion)
                                                              throws Exception
Locates Maven2 and configure that as the only Maven in the system.

Throws:
Exception

configureDefaultAnt

protected hudson.tasks.Ant.AntInstallation configureDefaultAnt()
                                                        throws Exception
Extracts Ant and configures it.

Throws:
Exception

createFreeStyleProject

protected hudson.model.FreeStyleProject createFreeStyleProject()
                                                        throws IOException
Throws:
IOException

createFreeStyleProject

protected hudson.model.FreeStyleProject createFreeStyleProject(String name)
                                                        throws IOException
Throws:
IOException

createMatrixProject

protected hudson.matrix.MatrixProject createMatrixProject()
                                                   throws IOException
Throws:
IOException

createMatrixProject

protected hudson.matrix.MatrixProject createMatrixProject(String name)
                                                   throws IOException
Throws:
IOException

createMavenProject

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

Throws:
IOException
See Also:
configureDefaultMaven()

createMavenProject

protected hudson.maven.MavenModuleSet createMavenProject(String name)
                                                  throws IOException
Creates a empty Maven project with the given name.

Throws:
IOException
See Also:
configureDefaultMaven()

createLocalLauncher

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


createTmpDir

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

Throws:
IOException

createSlave

public hudson.slaves.DumbSlave createSlave()
                                    throws Exception
Throws:
Exception

createSlave

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

Throws:
Exception

createDummySecurityRealm

public hudson.security.SecurityRealm createDummySecurityRealm()
Creates a test SecurityRealm that recognizes username==password as valid.


getURL

public URL getURL()
           throws IOException
Returns the URL of the webapp top page. URL ends with '/'.

Throws:
IOException

createSlave

public hudson.slaves.DumbSlave createSlave(hudson.EnvVars env)
                                    throws Exception
Throws:
Exception

createSlave

public hudson.slaves.DumbSlave createSlave(hudson.model.Label l,
                                           hudson.EnvVars env)
                                    throws Exception
Throws:
Exception

createSlave

public hudson.slaves.DumbSlave createSlave(String labels,
                                           hudson.EnvVars env)
                                    throws Exception
Creates a slave with certain additional environment variables

Throws:
Exception

createSlave

public hudson.slaves.DumbSlave createSlave(String nodeName,
                                           String labels,
                                           hudson.EnvVars env)
                                    throws Exception
Throws:
Exception

createPretendSlave

public PretendSlave createPretendSlave(FakeLauncher faker)
                                throws Exception
Throws:
Exception

createComputerLauncher

public hudson.slaves.CommandLauncher createComputerLauncher(hudson.EnvVars env)
                                                     throws URISyntaxException,
                                                            MalformedURLException
Creates a CommandLauncher for launching a slave locally.

Parameters:
env - Environment variables to add to the slave process. Can be null.
Throws:
URISyntaxException
MalformedURLException

createOnlineSlave

public hudson.slaves.DumbSlave createOnlineSlave()
                                          throws Exception
Create a new slave on the local host and wait for it to come onilne before returning.

Throws:
Exception

createOnlineSlave

public hudson.slaves.DumbSlave createOnlineSlave(hudson.model.Label l)
                                          throws Exception
Create a new slave on the local host and wait for it to come onilne before returning.

Throws:
Exception

createOnlineSlave

public hudson.slaves.DumbSlave createOnlineSlave(hudson.model.Label l,
                                                 hudson.EnvVars env)
                                          throws Exception
Create a new slave on the local host and wait for it to come online before returning

Throws:
Exception

interactiveBreak

public void interactiveBreak()
                      throws Exception
Blocks until the ENTER key is hit. This is useful during debugging a test so that one can inspect the state of Hudson through the web browser.

Throws:
Exception

last

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


pause

protected void pause()
              throws 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:
IOException

search

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

Throws:
Exception

configRoundtrip

protected void configRoundtrip()
                        throws Exception
Hits the Hudson system configuration and submits without any modification.

Throws:
Exception

configRoundtrip

protected <P extends hudson.model.Job> P configRoundtrip(P job)
                                              throws Exception
Loads a configuration page and submits it without any modifications, to perform a round-trip configuration test.

See http://wiki.jenkins-ci.org/display/JENKINS/Unit+Test#UnitTest-Configurationroundtriptesting

Throws:
Exception

configRoundtrip

protected <P extends hudson.model.Item> P configRoundtrip(P job)
                                               throws Exception
Throws:
Exception

configRoundtrip

protected <B extends hudson.tasks.Builder> B configRoundtrip(B before)
                                                  throws Exception
Performs a configuration round-trip testing for a builder.

Throws:
Exception

configRoundtrip

protected <P extends hudson.tasks.Publisher> P configRoundtrip(P before)
                                                    throws Exception
Performs a configuration round-trip testing for a publisher.

Throws:
Exception

configRoundtrip

protected <C extends hudson.slaves.ComputerConnector> C configRoundtrip(C before)
                                                             throws Exception
Throws:
Exception

configRoundtrip

protected hudson.model.User configRoundtrip(hudson.model.User u)
                                     throws Exception
Throws:
Exception

configRoundtrip

protected <N extends hudson.model.Node> N configRoundtrip(N node)
                                               throws Exception
Throws:
Exception

configRoundtrip

protected <V extends hudson.model.View> V configRoundtrip(V view)
                                               throws Exception
Throws:
Exception

assertBuildStatus

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

Throws:
Exception

isGoodHttpStatus

public boolean isGoodHttpStatus(int status)
Determines whether the specifed HTTP status code is generally "good"


assertGoodStatus

public void assertGoodStatus(com.gargoylesoftware.htmlunit.Page page)
Assert that the specifed page can be served with a "good" HTTP status, eg, the page is not missing and can be served without a server error

Parameters:
page -

assertBuildStatusSuccess

public <R extends hudson.model.Run> R assertBuildStatusSuccess(R r)
                                                    throws Exception
Throws:
Exception

assertBuildStatusSuccess

public <R extends hudson.model.Run> R assertBuildStatusSuccess(Future<? extends R> r)
                                                    throws Exception
Throws:
Exception

buildAndAssertSuccess

public <J extends hudson.model.AbstractProject<J,R>,R extends hudson.model.AbstractBuild<J,R>> R buildAndAssertSuccess(J job)
                                                                throws Exception
Throws:
Exception

buildAndAssertSuccess

public hudson.model.FreeStyleBuild buildAndAssertSuccess(hudson.model.FreeStyleProject job)
                                                  throws Exception
Avoids need for cumbersome this.<J,R>buildAndAssertSuccess(...) type hints under JDK 7 javac (and supposedly also IntelliJ).

Throws:
Exception

buildAndAssertSuccess

public hudson.maven.MavenModuleSetBuild buildAndAssertSuccess(hudson.maven.MavenModuleSet job)
                                                       throws Exception
Throws:
Exception

buildAndAssertSuccess

public hudson.maven.MavenBuild buildAndAssertSuccess(hudson.maven.MavenModule job)
                                              throws Exception
Throws:
Exception

assertLogContains

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

Throws:
Exception

getLog

protected static String getLog(hudson.model.Run run)
                        throws IOException
Get entire log file (this method is deprecated in hudson.model.Run, but in tests it is OK to load entire log).

Throws:
IOException

assertXPath

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


assertXPath

public void assertXPath(com.gargoylesoftware.htmlunit.html.DomNode page,
                        String xpath)
Asserts that the XPath matches the contents of a DomNode page. This variant of assertXPath(HtmlPage page, String xpath) allows us to examine XmlPages.

Parameters:
page -
xpath -

assertXPathValue

public void assertXPathValue(com.gargoylesoftware.htmlunit.html.DomNode page,
                             String xpath,
                             String expectedValue)

assertXPathValueContains

public void assertXPathValueContains(com.gargoylesoftware.htmlunit.html.DomNode page,
                                     String xpath,
                                     String needle)

assertXPathResultsContainText

public void assertXPathResultsContainText(com.gargoylesoftware.htmlunit.html.DomNode page,
                                          String xpath,
                                          String needle)

assertAllImageLoadSuccessfully

public void assertAllImageLoadSuccessfully(com.gargoylesoftware.htmlunit.html.HtmlPage p)
Makes sure that all the images in the page loads successfully. (By default, HtmlUnit doesn't load images.)


assertStringContains

public void assertStringContains(String message,
                                 String haystack,
                                 String needle)

assertStringContains

public void assertStringContains(String haystack,
                                 String needle)

assertHelpExists

public void assertHelpExists(Class<? extends hudson.model.Describable> type,
                             String properties)
                      throws Exception
Asserts that help files exist for the specified properties of the given instance.

Parameters:
type - The describable class type that should have the associated help files.
properties - ','-separated list of properties whose help files should exist.
Throws:
Exception

submit

public com.gargoylesoftware.htmlunit.html.HtmlPage submit(com.gargoylesoftware.htmlunit.html.HtmlForm form)
                                                   throws Exception
Submits the form. Plain HtmlForm.submit() doesn't work correctly due to the use of YUI in Hudson.

Throws:
Exception

submit

public com.gargoylesoftware.htmlunit.html.HtmlPage submit(com.gargoylesoftware.htmlunit.html.HtmlForm form,
                                                          String name)
                                                   throws Exception
Submits the form by clikcing the submit button of the given name.

Parameters:
name - This corresponds to the @name of <f:submit />
Throws:
Exception

findPreviousInputElement

protected com.gargoylesoftware.htmlunit.html.HtmlInput findPreviousInputElement(com.gargoylesoftware.htmlunit.html.HtmlElement current,
                                                                                String name)

getButtonByCaption

protected com.gargoylesoftware.htmlunit.html.HtmlButton getButtonByCaption(com.gargoylesoftware.htmlunit.html.HtmlForm f,
                                                                           String s)

createTaskListener

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


assertEqualBeans

public void assertEqualBeans(Object lhs,
                             Object rhs,
                             String properties)
                      throws Exception
Asserts that two JavaBeans are equal as far as the given list of properties are concerned.

This method takes two objects that have properties (getXyz, isXyz, or just the public xyz field), and makes sure that the property values for each given property are equals (by using Assert.assertThat(Object, org.hamcrest.Matcher))

Property values can be null on both objects, and that is OK, but passing in a property that doesn't exist will fail an assertion.

This method is very convenient for comparing a large number of properties on two objects, for example to verify that the configuration is identical after a config screen roundtrip.

Parameters:
lhs - One of the two objects to be compared.
rhs - The other object to be compared
properties - ','-separated list of property names that are compared.
Throws:
Exception
Since:
1.297

setQuietPeriod

protected void setQuietPeriod(int qp)

assertEqualDataBoundBeans

public void assertEqualDataBoundBeans(Object lhs,
                                      Object rhs)
                               throws Exception
Works like assertEqualBeans(Object, Object, String) but figure out the properties via DataBoundConstructor

Throws:
Exception

assertEqualDataBoundBeans

public void assertEqualDataBoundBeans(List<?> lhs,
                                      List<?> rhs)
                               throws Exception
Makes sure that two collections are identical via assertEqualDataBoundBeans(Object, Object)

Throws:
Exception

findDataBoundConstructor

protected Constructor<?> findDataBoundConstructor(Class<?> c)

get

protected <T extends hudson.model.Descriptor<?>> T get(Class<T> d)
Gets the descriptor instance of the current Hudson by its type.


isSomethingHappening

protected boolean isSomethingHappening()
Returns true if Hudson is building something or going to build something.


waitUntilNoActivity

protected void waitUntilNoActivity()
                            throws Exception
Waits until Hudson finishes building everything, including those in the queue.

This method uses a default time out to prevent infinite hang in the automated test execution environment.

Throws:
Exception

waitUntilNoActivityUpTo

protected void waitUntilNoActivityUpTo(int timeout)
                                throws Exception
Waits until Hudson finishes building everything, including those in the queue, or fail the test if the specified timeout milliseconds is

Throws:
Exception

recipe

protected void recipe()
               throws Exception
Called during the before() 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:
Exception

recipeLoadCurrentPlugin

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

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

Throws:
Exception

withNewHome

public JenkinsRule withNewHome()

withExistingHome

public JenkinsRule withExistingHome(File source)
                             throws Exception
Throws:
Exception

withPresetData

public JenkinsRule withPresetData(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 JenkinsRule with(HudsonHomeLoader homeLoader)

executeOnServer

public <V> V executeOnServer(Callable<V> c)
                  throws Exception
Executes the given closure on the server, by the servlet request handling thread, in the context of an HTTP request.

In HudsonTestCase, a thread that's executing the test code is different from the thread that carries out HTTP requests made through JenkinsRule.WebClient. But sometimes you want to make assertions and other calls with side-effect from within the request handling thread.

This method allows you to do just that. It is useful for testing some methods that require StaplerRequest and StaplerResponse, or getting the credential of the current user (via Jenkins.getAuthentication(), and so on.

Parameters:
c - The closure to be executed on the server.
Returns:
The return value from the closure.
Throws:
JenkinsRule.BreakException - If a closure throws any exception, that exception will be carried forward.
Exception

createWebClient

public JenkinsRule.WebClient createWebClient()
This is to assist Groovy test clients who are incapable of instantiating the inner classes properly.



Copyright © 2004-2012. All Rights Reserved.