Class JenkinsRule
- All Implemented Interfaces:
hudson.ExtensionPoint
,hudson.model.Action
,hudson.model.ModelObject
,hudson.model.RootAction
,org.junit.rules.MethodRule
,org.junit.rules.TestRule
- Direct Known Subclasses:
GroovyJenkinsRule
,NodeProvisionerRule
,RealJenkinsRule.CustomJenkinsRule
- Since:
- 1.436
- Author:
- Stephen Connolly
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static class
static class
Convenience wrapper for JSON responses.static class
class
ExtendsWebClient
and provide convenience methods for accessing Hudson.Nested classes/interfaces inherited from interface hudson.ExtensionPoint
hudson.ExtensionPoint.LegacyInstancesAreScopedToHudson
-
Field Summary
Modifier and TypeFieldDescriptionWhere in theServer
is Jenkins deployed?protected TestEnvironment
protected HudsonHomeLoader
hudson.model.Hudson
Deprecated.jenkins.model.Jenkins
protected JavaScriptDebugger
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
TCP/IP port that the server is listening on.static final List<hudson.tools.ToolProperty<?>>
protected List<JenkinsRecipe.Runner>
protected org.eclipse.jetty.server.Server
static final int
Specify this to a TCP/IP port number to have slaves started with the debugger.protected List<LenientRunnable>
protected org.junit.runner.Description
int
Number of seconds until the test times out.boolean
Deprecated. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
_configureJenkinsForTest
(jenkins.model.Jenkins jenkins) Configures a Jenkins instance for test.static void
_configureUpdateCenter
(jenkins.model.Jenkins jenkins) Internal method used to configure update center to avoid network traffic.static org.eclipse.jetty.security.LoginService
Creates aHashLoginService
with three users: alice, bob and charlie The password is same as the usernamestatic org.eclipse.jetty.ee9.webapp.WebAppContext
_createWebAppContext2
(String contextPath, Consumer<Integer> portSetter, ClassLoader classLoader, int localPort, Supplier<org.eclipse.jetty.security.LoginService> loginServiceSupplier) Creates a web server on which Jenkins can runstatic org.eclipse.jetty.ee9.webapp.WebAppContext
_createWebAppContext2
(String contextPath, Consumer<Integer> portSetter, ClassLoader classLoader, int localPort, Supplier<org.eclipse.jetty.security.LoginService> loginServiceSupplier, BiConsumer<org.eclipse.jetty.ee9.webapp.WebAppContext, org.eclipse.jetty.server.Server> contextAndServerConsumer) Creates a web server on which Jenkins can runstatic void
_stopJenkins
(org.eclipse.jetty.server.Server server, List<LenientRunnable> tearDowns, jenkins.model.Jenkins jenkins) Internal method to stop Jenkins instance.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) org.junit.runners.model.Statement
apply
(org.junit.runners.model.Statement base, org.junit.runners.model.FrameworkMethod method, Object target) Backward compatibility with JUnit 4.8.void
assertAllImageLoadSuccessfully
(org.htmlunit.html.HtmlPage p) Makes sure that all the images in the page loads successfully.<R extends hudson.model.Run>
RassertBuildStatus
(hudson.model.Result status, Future<? extends R> r) <R extends hudson.model.Run>
RassertBuildStatus
(hudson.model.Result status, R r) Asserts that the outcome of the build is a specific outcome.<R extends hudson.model.Run>
RassertBuildStatusSuccess
(Future<? extends R> r) <R extends hudson.model.Run>
Rvoid
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
(Object lhs, Object rhs) Works likeassertEqualBeans(Object, Object, String)
but figure out the properties viaDataBoundConstructor
andDataBoundSetter
void
assertEqualDataBoundBeans
(List<?> lhs, List<?> rhs) Makes sure that two collections are identical viaassertEqualDataBoundBeans(Object, Object)
void
assertGoodStatus
(org.htmlunit.Page page) Assert that the specified page can be served with a "good" HTTP status, eg, the page is not missing and can be served without a server errorvoid
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
assertLogNotContains
(String substring, hudson.model.Run run) Asserts that the console output of the build does not contain the given substring.void
assertStringContains
(String haystack, String needle) void
assertStringContains
(String message, String haystack, String needle) void
assertXPath
(org.htmlunit.html.DomNode page, String xpath) Asserts that the XPath matches the contents of a DomNode page.void
assertXPath
(org.htmlunit.html.HtmlPage page, String xpath) Asserts that the XPath matches.void
assertXPathResultsContainText
(org.htmlunit.html.DomNode page, String xpath, String needle) void
assertXPathValue
(org.htmlunit.html.DomNode page, String xpath, String expectedValue) void
assertXPathValueContains
(org.htmlunit.html.DomNode page, String xpath, String needle) void
before()
Override to set up your specific external resource.<J extends hudson.model.Job<J,
R> & jenkins.model.ParameterizedJobMixIn.ParameterizedJob<J, R>, R extends hudson.model.Run<J, R> & hudson.model.Queue.Executable>
RbuildAndAssertStatus
(hudson.model.Result status, J job) Runs specified job and asserts that in finished with given build result.hudson.model.FreeStyleBuild
buildAndAssertSuccess
(hudson.model.FreeStyleProject job) Avoids need for cumbersomethis.<J,R>buildAndAssertSuccess(...)
type hints under JDK 7 javac (and supposedly also IntelliJ).<J extends hudson.model.Job<J,
R> & jenkins.model.ParameterizedJobMixIn.ParameterizedJob<J, R>, R extends hudson.model.Run<J, R> & hudson.model.Queue.Executable>
RbuildAndAssertSuccess
(J job) void
Hits the Hudson system configuration and submits without any modification.<B extends hudson.tasks.Builder>
BconfigRoundtrip
(B before) Performs a configuration round-trip testing for a builder.<C extends hudson.slaves.ComputerConnector>
CconfigRoundtrip
(C before) hudson.model.User
configRoundtrip
(hudson.model.User u) <N extends hudson.model.Node>
NconfigRoundtrip
(N node) <P extends hudson.model.Item>
PconfigRoundtrip
(P job) Loads a configuration page and submits it without any modifications, to perform a round-trip configuration test.<V extends hudson.model.View>
VconfigRoundtrip
(V view) protected void
Configures the update center setting for the test.protected org.eclipse.jetty.security.LoginService
Configures a security realm for a test.createApiToken
(hudson.model.User user) Use the new API token system introduced in 2.129 to generate a token for the given user.hudson.slaves.ComputerLauncher
createComputerLauncher
(hudson.EnvVars env) Creates a launcher for starting a local agent.Creates a testSecurityRealm
that recognizes username==password as valid.createFolder
(String name) Creates a simple folder that other jobs can be placed in.hudson.model.FreeStyleProject
hudson.model.FreeStyleProject
createFreeStyleProject
(String name) hudson.Launcher.LocalLauncher
CreatesLauncher.LocalLauncher
.hudson.slaves.DumbSlave
Create a new slave on the local host and wait for it to come online before returning.hudson.slaves.DumbSlave
createOnlineSlave
(hudson.model.Label l) Create a new slave on the local host and wait for it to come online 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 returningcreatePretendSlave
(FakeLauncher faker) <T extends hudson.model.TopLevelItem>
TcreateProject
(Class<T> type) Creates a new job with an unique name.<T extends hudson.model.TopLevelItem>
TcreateProject
(Class<T> type, String name) Creates a new job.hudson.slaves.DumbSlave
Creates and attaches a new outbound agent.hudson.slaves.DumbSlave
createSlave
(boolean waitForChannelConnect) 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 variableshudson.slaves.DumbSlave
createSlave
(String nodeName, String labels, hudson.EnvVars env) hudson.model.TaskListener
Creates aTaskListener
connected to stdout.Deprecated.UseTemporaryFolder
instead.protected String
Create a web client instance using the browser version returned byBrowserVersion.getDefault()
with support for the Fetch API.protected jakarta.servlet.ServletContext
Prepares a webapp hosting environment to getServletContext
implementation that we need for testing.protected jakarta.servlet.ServletContext
createWebServer2
(BiConsumer<org.eclipse.jetty.ee9.webapp.WebAppContext, org.eclipse.jetty.server.Server> contextAndServerConsumer) Prepares a webapp hosting environment to getServletContext
implementation that we need for testing.void
disconnectSlave
(hudson.slaves.DumbSlave slave) <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.Constructor<?>
org.htmlunit.html.HtmlInput
findPreviousInputElement
(org.htmlunit.html.HtmlElement current, String name) <T extends hudson.model.Descriptor<?>>
TGets the descriptor instance of the current Hudson by its type.org.htmlunit.html.HtmlButton
getButtonByCaption
(org.htmlunit.html.HtmlForm f, String s) jenkins.model.Jenkins
Get JSON from a Jenkins relative endpoint.static String
getLog
(hudson.model.Run run) Get entire log file as plain text.hudson.PluginManager
org.junit.runner.Description
getURL()
Returns the URL of the webapp top page.void
Blocks until the ENTER key is hit.boolean
isGoodHttpStatus
(int status) Determines whether the specified HTTP status code is generally "good"boolean
Returns true if Hudson is building something or going to build something.<T> T
Returns the last item in the list.protected hudson.model.Hudson
Creates a new instance ofJenkins
.void
pause()
Pauses the execution until ENTER is hit in the console.POST a JSON payload to a URL on the underlying Jenkins instance using the crumb.void
recipe()
Called during thebefore()
to give a test case an opportunity to control the test environment in which Hudson is run.void
If this test harness is launched for a Jenkins plugin, locate thetarget/test-classes/the.jpl
and add a recipe to install that to the new Jenkins.org.htmlunit.Page
Performs a search from the search box.void
setPluginManager
(hudson.PluginManager pluginManager) Sets thePluginManager
to be used when creating a newJenkins
instance.void
setQuietPeriod
(int qp) Deprecated.useJenkins.setQuietPeriod(java.lang.Integer)
void
showAgentLogs
(hudson.model.Slave s, Map<String, Level> loggers) Forward agent logs to standard error of the test process.void
showAgentLogs
(hudson.model.Slave s, LoggerRule loggerRule) Same asshowAgentLogs(Slave, Map)
but taking a preconfigured list of loggers as a convenience.org.htmlunit.html.HtmlPage
submit
(org.htmlunit.html.HtmlForm form) Submits the form.org.htmlunit.html.HtmlPage
Submits the form by clicking the submit button of the given name.<R extends hudson.model.Run<?,
?>>
RwaitForCompletion
(R r) Waits for a build to complete.<R extends hudson.model.Run<?,
?>>
RwaitForMessage
(String message, R r) Waits for a build log to contain a specified string.void
waitOnline
(hudson.model.Slave s) Waits for a newly created slave to come online.void
Waits until Hudson finishes building everything, including those in the queue.void
waitUntilNoActivityUpTo
(int timeout) Waits until Hudson finishes building everything, including those in the queue, or fail the test if the specified timeout milliseconds iswith
(hudson.PluginManager pluginManager) with
(HudsonHomeLoader homeLoader) withExistingHome
(File source) withPresetData
(String name) Declares that this test case expects to start with one of the preset data sets.protected Object
Sometimes a part of a test case may ends up creeping into the serialization tree ofSaveable.save()
, so detect that and flag that as an error.
-
Field Details
-
env
-
testDescription
protected org.junit.runner.Description testDescription -
hudson
Deprecated.Points to the same object asjenkins
does. -
jenkins
public jenkins.model.Jenkins jenkins -
homeLoader
-
localPort
protected int localPortTCP/IP port that the server is listening on. -
server
protected org.eclipse.jetty.server.Server server -
contextPath
Where in theServer
is Jenkins deployed?Just like
ServletContext.getContextPath()
, starts with '/' but doesn't end with '/'. UnlikeJenkinsRule.WebClient.getContextPath()
this is not a complete URL. -
tearDowns
-
recipes
-
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
Deprecated.UsepluginManager
If this test case has additionalWithPlugin
annotations, set to true. This will cause a freshPluginManager
to be created for this test. Leaving this to false enables the test harness to use a pre-loaded plugin manager, which runs faster. -
timeout
public int timeoutNumber of seconds until the test times out. TheWithTimeout
rule can be used to specify this value per test. In case of debugging session, the default timeout behavior is removed. Otherwise it's set to 3 minutes. -
computerConnectorTester
-
NO_PROPERTIES
-
SLAVE_DEBUG_PORT
public static final int SLAVE_DEBUG_PORTSpecify this to a TCP/IP port number to have slaves started with the debugger.
-
-
Constructor Details
-
JenkinsRule
public JenkinsRule()
-
-
Method Details
-
getInstance
public jenkins.model.Jenkins getInstance() -
before
Override to set up your specific external resource.- Throws:
Throwable
- if setup fails (which will disableafter
-
_configureJenkinsForTest
Configures a Jenkins instance for test.- Parameters:
jenkins
- jenkins instance which has to be configured- Throws:
Exception
- if unable to configure- Since:
- 2.50
-
configureUpdateCenter
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
-
_configureUpdateCenter
Internal method used to configure update center to avoid network traffic.- Parameters:
jenkins
- the Jenkins to configure- Throws:
Exception
- Since:
- 2.50
-
after
Override to tear down your specific external resource.- Throws:
Exception
-
_stopJenkins
public static void _stopJenkins(org.eclipse.jetty.server.Server server, List<LenientRunnable> tearDowns, jenkins.model.Jenkins jenkins) Internal method to stop Jenkins instance.- Parameters:
server
- server on which Jenkins is running.tearDowns
- tear down methods for testsjenkins
- the jenkins instance- Since:
- 2.50
-
apply
public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runners.model.FrameworkMethod method, Object target) Backward compatibility with JUnit 4.8.- Specified by:
apply
in interfaceorg.junit.rules.MethodRule
-
apply
public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runner.Description description) - Specified by:
apply
in interfaceorg.junit.rules.TestRule
-
getIconFileName
- Specified by:
getIconFileName
in interfacehudson.model.Action
-
getDisplayName
- Specified by:
getDisplayName
in interfacehudson.model.Action
- Specified by:
getDisplayName
in interfacehudson.model.ModelObject
-
getUrlName
- Specified by:
getUrlName
in interfacehudson.model.Action
-
newHudson
Creates a new instance ofJenkins
. 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 thePluginManager
to be used when creating a newJenkins
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
-
getWebAppRoot
- Throws:
Exception
-
createWebServer2
Prepares a webapp hosting environment to getServletContext
implementation that we need for testing.- Throws:
Exception
-
createWebServer2
protected jakarta.servlet.ServletContext createWebServer2(@CheckForNull BiConsumer<org.eclipse.jetty.ee9.webapp.WebAppContext, org.eclipse.jetty.server.Server> contextAndServerConsumer) throws ExceptionPrepares a webapp hosting environment to getServletContext
implementation that we need for testing.- Parameters:
contextAndServerConsumer
- configures theWebAppContext
and theServer
for the instance, before they are started- Throws:
Exception
- Since:
- 2.63
-
_createWebAppContext2
public static org.eclipse.jetty.ee9.webapp.WebAppContext _createWebAppContext2(String contextPath, Consumer<Integer> portSetter, ClassLoader classLoader, int localPort, Supplier<org.eclipse.jetty.security.LoginService> loginServiceSupplier) throws Exception Creates a web server on which Jenkins can run- Parameters:
contextPath
- the context path at which to put JenkinsportSetter
- the port on which the server runs will be set using this functionclassLoader
- the class loader for theWebAppContext
localPort
- port on which the server runsloginServiceSupplier
- configures theLoginService
for the instance- Returns:
- the
Server
- Throws:
Exception
- Since:
- 2.50
-
_createWebAppContext2
public static org.eclipse.jetty.ee9.webapp.WebAppContext _createWebAppContext2(String contextPath, Consumer<Integer> portSetter, ClassLoader classLoader, int localPort, Supplier<org.eclipse.jetty.security.LoginService> loginServiceSupplier, @CheckForNull BiConsumer<org.eclipse.jetty.ee9.webapp.WebAppContext, org.eclipse.jetty.server.Server> contextAndServerConsumer) throws ExceptionCreates a web server on which Jenkins can run- Parameters:
contextPath
- the context path at which to put JenkinsportSetter
- the port on which the server runs will be set using this functionclassLoader
- the class loader for theWebAppContext
localPort
- port on which the server runsloginServiceSupplier
- configures theLoginService
for the instancecontextAndServerConsumer
- configures theWebAppContext
and theServer
for the instance, before they are started- Returns:
- the
Server
- Throws:
Exception
- Since:
- 2.50
-
configureUserRealm
protected org.eclipse.jetty.security.LoginService configureUserRealm()Configures a security realm for a test. -
_configureUserRealm
public static org.eclipse.jetty.security.LoginService _configureUserRealm()Creates aHashLoginService
with three users: alice, bob and charlie The password is same as the username- Returns:
- a new login service
- Since:
- 2.50
-
createProject
public <T extends hudson.model.TopLevelItem> T createProject(Class<T> type, String name) throws IOException Creates a new job.- Parameters:
type
- Top level item type.name
- Item name.- Throws:
IllegalArgumentException
- if the project of the given name already exists.IOException
-
createProject
Creates a new job with an unique name.- Parameters:
type
- Top level item type.- Throws:
IOException
-
createFreeStyleProject
- Throws:
IOException
-
createFreeStyleProject
- Throws:
IOException
-
createFolder
Creates a simple folder that other jobs can be placed in.- Throws:
IOException
- Since:
- 1.494
-
createUniqueProjectName
-
createLocalLauncher
public hudson.Launcher.LocalLauncher createLocalLauncher()CreatesLauncher.LocalLauncher
. Useful for launching processes. -
createTmpDir
Deprecated.UseTemporaryFolder
instead.Allocates a new temporary directory for the duration of this test.- Throws:
IOException
-
createSlave
- Throws:
Exception
-
disconnectSlave
- Throws:
Exception
-
createSlave
Creates and attaches a new outbound agent.- Throws:
Exception
- See Also:
-
createSlave
@NonNull public hudson.slaves.DumbSlave createSlave(@CheckForNull hudson.model.Label l) throws Exception Creates and launches a new slave on the local host.- Throws:
Exception
-
createDummySecurityRealm
Creates a testSecurityRealm
that recognizes username==password as valid.- See Also:
-
getURL
Returns the URL of the webapp top page. URL ends with '/'.- Throws:
IOException
-
createSlave
@NonNull public hudson.slaves.DumbSlave createSlave(@CheckForNull hudson.EnvVars env) throws Exception - Throws:
Exception
-
createSlave
@NonNull public hudson.slaves.DumbSlave createSlave(@CheckForNull hudson.model.Label l, @CheckForNull hudson.EnvVars env) throws Exception - Throws:
Exception
-
createSlave
@NonNull public hudson.slaves.DumbSlave createSlave(@CheckForNull String labels, @CheckForNull hudson.EnvVars env) throws Exception Creates a slave with certain additional environment variables- Throws:
Exception
-
createSlave
@NonNull public hudson.slaves.DumbSlave createSlave(@NonNull String nodeName, @CheckForNull String labels, @CheckForNull hudson.EnvVars env) throws Exception - Throws:
Exception
-
createPretendSlave
- Throws:
Exception
-
createComputerLauncher
@NonNull public hudson.slaves.ComputerLauncher createComputerLauncher(@CheckForNull hudson.EnvVars env) throws URISyntaxException, IOException Creates a launcher for starting a local agent. This is an outbound agent usingSimpleCommandLauncher
.- Parameters:
env
- Environment variables to add to the slave process. Can benull
.- Throws:
URISyntaxException
IOException
- See Also:
-
createOnlineSlave
Create a new slave on the local host and wait for it to come online before returning.- Throws:
Exception
-
createOnlineSlave
@NonNull public hudson.slaves.DumbSlave createOnlineSlave(@CheckForNull hudson.model.Label l) throws Exception Create a new slave on the local host and wait for it to come online before returning.- Throws:
Exception
-
createOnlineSlave
@NonNull public hudson.slaves.DumbSlave createOnlineSlave(@CheckForNull hudson.model.Label l, @CheckForNull hudson.EnvVars env) throws Exception Create a new slave on the local host and wait for it to come online before returning- Throws:
Exception
- See Also:
-
createApiToken
Use the new API token system introduced in 2.129 to generate a token for the given user. -
waitOnline
Waits for a newly created slave to come online.- Throws:
Exception
- See Also:
-
showAgentLogs
Same asshowAgentLogs(Slave, Map)
but taking a preconfigured list of loggers as a convenience.- Throws:
Exception
-
showAgentLogs
Forward agent logs to standard error of the test process. Otherwise log messages would be sent only toComputer.getLogText()
etc., or discarded entirely (if belowLevel.INFO
).- Parameters:
s
- an online agentloggers
-Logger.getName()
tied to log level- Throws:
Exception
-
interactiveBreak
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
Returns the last item in the list. -
pause
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
Performs a search from the search box.- Throws:
Exception
-
getJSON
Get JSON from a Jenkins relative endpoint. Create a new default webclient. If you want to configure the webclient, for example to set a token for authentication, or accept other HTTP responses than 200, you can useJenkinsRule.WebClient.getJSON(String)
directly.- Parameters:
path
- relative path, should not start with '/'- Returns:
- The JSON response from server.
- Throws:
IOException
-
postJSON
public JenkinsRule.JSONWebResponse postJSON(@NonNull String path, @NonNull Object json) throws IOException, SAXException POST a JSON payload to a URL on the underlying Jenkins instance using the crumb.- Parameters:
path
- The url path on Jenkins.json
- An object that produces a JSON string from it'stoString
method.- Returns:
- A JSON response.
- Throws:
IOException
SAXException
-
configRoundtrip
Hits the Hudson system configuration and submits without any modification.- Throws:
Exception
-
configRoundtrip
Loads a configuration page and submits it without any modifications, to perform a round-trip configuration test.- Throws:
Exception
-
configRoundtrip
Performs a configuration round-trip testing for a builder.- Throws:
Exception
-
configRoundtrip
Performs a configuration round-trip testing for a publisher.- Throws:
Exception
-
configRoundtrip
- Throws:
Exception
-
configRoundtrip
- Throws:
Exception
-
configRoundtrip
- Throws:
Exception
-
configRoundtrip
- Throws:
Exception
-
configRoundtrip
Performs a configuration round-trip testing for a cloud. The given cloud is added to the cloud list of Jenkins.If a cloud with the same name already exists, then this old one will be replaced by the given one.
- 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.Consider
RunMatchers.hasStatus(Result)
as an alternative.- Throws:
Exception
-
assertBuildStatus
public <R extends hudson.model.Run> R assertBuildStatus(hudson.model.Result status, Future<? extends R> r) throws Exception - Throws:
Exception
-
isGoodHttpStatus
public boolean isGoodHttpStatus(int status) Determines whether the specified HTTP status code is generally "good" -
assertGoodStatus
public void assertGoodStatus(org.htmlunit.Page page) Assert that the specified page can be served with a "good" HTTP status, eg, the page is not missing and can be served without a server error -
assertBuildStatusSuccess
- Throws:
Exception
-
assertBuildStatusSuccess
public <R extends hudson.model.Run> R assertBuildStatusSuccess(Future<? extends R> r) throws Exception - Throws:
Exception
-
buildAndAssertSuccess
@NonNull public <J extends hudson.model.Job<J,R> & jenkins.model.ParameterizedJobMixIn.ParameterizedJob<J, R buildAndAssertSuccessR>, R extends hudson.model.Run<J, R> & hudson.model.Queue.Executable> (@NonNull J job) throws Exception - Throws:
Exception
-
buildAndAssertStatus
@NonNull public <J extends hudson.model.Job<J,R> & jenkins.model.ParameterizedJobMixIn.ParameterizedJob<J, R buildAndAssertStatusR>, R extends hudson.model.Run<J, R> & hudson.model.Queue.Executable> (@NonNull hudson.model.Result status, @NonNull J job) throws Exception Runs specified job and asserts that in finished with given build result.- Throws:
Exception
- Since:
- TODO
-
buildAndAssertSuccess
@NonNull public hudson.model.FreeStyleBuild buildAndAssertSuccess(@NonNull hudson.model.FreeStyleProject job) throws Exception Avoids need for cumbersomethis.<J,R>buildAndAssertSuccess(...)
type hints under JDK 7 javac (and supposedly also IntelliJ).- Throws:
Exception
-
assertLogContains
Asserts that the console output of the build contains the given substring.Consider
RunMatchers.logContains(String)
as an alternative.- Throws:
IOException
-
assertLogNotContains
Asserts that the console output of the build does not contain the given substring.Consider
Matchers.not(org.hamcrest.Matcher<T>)
andRunMatchers.logContains(String)
as an alternative.- Throws:
IOException
-
getLog
Get entire log file as plain text.Run.getLog()
is deprecated for reasons that are irrelevant in tests, and also does not strip console annotations which are a distraction in test output.- Throws:
IOException
-
waitForCompletion
Waits for a build to complete. Useful in conjunction withBuildWatcher
.As an alternative, if using Awaitibility, you can use
await().until(() -> r, RunMatchers.completed());
- Returns:
- the same build, once done
- Throws:
InterruptedException
- Since:
- 1.607
-
waitForMessage
public <R extends hudson.model.Run<?,?>> R waitForMessage(String message, R r) throws IOException, InterruptedException Waits for a build log to contain a specified string. Useful in conjunction withBuildWatcher
.- Returns:
- the same build, once it does
- Throws:
IOException
InterruptedException
- Since:
- 1.607
-
assertXPath
Asserts that the XPath matches. -
assertXPath
Asserts that the XPath matches the contents of a DomNode page. This variant of assertXPath(HtmlPage page, String xpath) allows us to examine XmlPages. -
assertXPathValue
-
assertXPathValueContains
-
assertXPathResultsContainText
-
assertAllImageLoadSuccessfully
public void assertAllImageLoadSuccessfully(org.htmlunit.html.HtmlPage p) Makes sure that all the images in the page loads successfully. (By default, HtmlUnit doesn't load images.) -
assertStringContains
-
assertStringContains
-
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
Submits the form. PlainHtmlForm.submit(SubmittableElement)
doesn't work correctly due to the use of YUI in Jenkins.- Throws:
Exception
-
submit
public org.htmlunit.html.HtmlPage submit(org.htmlunit.html.HtmlForm form, String name) throws Exception Submits the form by clicking the submit button of the given name.- Parameters:
name
- This corresponds to the @name of<f:submit />
- Throws:
Exception
-
findPreviousInputElement
public org.htmlunit.html.HtmlInput findPreviousInputElement(org.htmlunit.html.HtmlElement current, String name) -
getButtonByCaption
-
createTaskListener
public hudson.model.TaskListener createTaskListener()Creates aTaskListener
connected to stdout. -
assertEqualBeans
public void assertEqualBeans(Object lhs, Object rhs, String properties) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException 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
MatcherAssert.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 comparedproperties
- ','-separated list of property names that are compared.- Throws:
InvocationTargetException
IllegalAccessException
NoSuchMethodException
- Since:
- 1.297
-
setQuietPeriod
Deprecated.useJenkins.setQuietPeriod(java.lang.Integer)
-
assertEqualDataBoundBeans
public void assertEqualDataBoundBeans(Object lhs, Object rhs) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException Works likeassertEqualBeans(Object, Object, String)
but figure out the properties viaDataBoundConstructor
andDataBoundSetter
-
assertEqualDataBoundBeans
Makes sure that two collections are identical viaassertEqualDataBoundBeans(Object, Object)
- Throws:
Exception
-
findDataBoundConstructor
-
get
Gets the descriptor instance of the current Hudson by its type. -
isSomethingHappening
public boolean isSomethingHappening()Returns true if Hudson is building something or going to build something. -
waitUntilNoActivity
Waits until Hudson finishes building everything, including those in the queue.- Throws:
Exception
-
waitUntilNoActivityUpTo
Waits until Hudson finishes building everything, including those in the queue, or fail the test if the specified timeout milliseconds is- Throws:
Exception
-
recipe
Called during thebefore()
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 withRecipe
meta-annotation.- Throws:
Exception
-
recipeLoadCurrentPlugin
If this test harness is launched for a Jenkins plugin, locate thetarget/test-classes/the.jpl
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 isjpi
.- Throws:
Exception
-
withNewHome
-
withExistingHome
- Throws:
Exception
-
withPresetData
Declares that this test case expects to start with one of the preset data sets. Seetest/src/main/preset-data/
for available datasets and what they mean. -
with
-
executeOnServer
Executes the given closure on the server, by the servlet request handling thread, in the context of an HTTP request.In
JenkinsRule
, a thread that's executing the test code is different from the thread that carries out HTTP requests made throughJenkinsRule.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
StaplerRequest2
andStaplerResponse2
, or getting the credential of the current user (viaJenkins.getAuthentication()
, and so on.- Parameters:
c
- The closure to be executed on the server.- Returns:
- The return value from the closure.
- Throws:
Exception
- If a closure throws any exception, that exception will be carried forward.
-
writeReplace
Sometimes a part of a test case may ends up creeping into the serialization tree ofSaveable.save()
, so detect that and flag that as an error. -
createWebClient
Create a web client instance using the browser version returned byBrowserVersion.getDefault()
with support for the Fetch API. -
getTestDescription
public org.junit.runner.Description getTestDescription()
-
pluginManager