public class JenkinsRule extends Object implements org.junit.rules.TestRule, org.junit.rules.MethodRule, hudson.model.RootAction
RestartableJenkinsRule
Modifier and Type | Class and Description |
---|---|
static class |
JenkinsRule.BreakException |
static class |
JenkinsRule.DummySecurityRealm |
static class |
JenkinsRule.JSONWebResponse
Convenience wrapper for JSON responses.
|
static class |
JenkinsRule.TestBuildWrapper |
class |
JenkinsRule.WebClient
Extends
WebClient and provide convenience methods
for accessing Hudson. |
Modifier and Type | Field and Description |
---|---|
JenkinsComputerConnectorTester |
computerConnectorTester |
String |
contextPath
Where in the
Server is Jenkins deployed? |
protected TestEnvironment |
env |
protected HudsonHomeLoader |
homeLoader |
hudson.model.Hudson |
hudson
Deprecated.
|
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.eclipse.jetty.http.MimeTypes |
MIME_TYPES |
static List<hudson.tools.ToolProperty<?>> |
NO_PROPERTIES |
protected List<JenkinsRecipe.Runner> |
recipes |
protected org.eclipse.jetty.server.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
|
protected org.junit.runner.Description |
testDescription |
int |
timeout
Number of seconds until the test times out.
|
boolean |
useLocalPluginManager
Deprecated.
Use
pluginManager |
Constructor and Description |
---|
JenkinsRule() |
Modifier and Type | Method and Description |
---|---|
static 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 |
_configureUserRealm()
Creates a
HashLoginService with three users: alice, bob and charlie
The password is same as the username |
static org.apache.commons.lang3.tuple.ImmutablePair<org.eclipse.jetty.server.Server,javax.servlet.ServletContext> |
_createWebServer(String contextPath,
Consumer<Integer> portSetter,
ClassLoader classLoader,
int localPort,
Supplier<org.eclipse.jetty.security.LoginService> loginServiceSupplier)
Creates a web server on which Jenkins can run
|
static org.apache.commons.lang3.tuple.ImmutablePair<org.eclipse.jetty.server.Server,javax.servlet.ServletContext> |
_createWebServer(String contextPath,
Consumer<Integer> portSetter,
ClassLoader classLoader,
int localPort,
Supplier<org.eclipse.jetty.security.LoginService> loginServiceSupplier,
BiConsumer<org.eclipse.jetty.webapp.WebAppContext,org.eclipse.jetty.server.Server> contextAndServerConsumer)
Creates a web server on which Jenkins can run
|
static 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(com.gargoylesoftware.htmlunit.html.HtmlPage p)
Makes sure that all the images in the page loads successfully.
|
<R extends hudson.model.Run> |
assertBuildStatus(hudson.model.Result status,
Future<? extends R> r) |
<R extends hudson.model.Run> |
assertBuildStatus(hudson.model.Result status,
R r)
Asserts that the outcome of the build is a specific outcome.
|
<R extends hudson.model.Run> |
assertBuildStatusSuccess(Future<? extends R> r) |
<R extends hudson.model.Run> |
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 and DataBoundSetter |
void |
assertGoodStatus(com.gargoylesoftware.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
|
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 |
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(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) |
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> |
buildAndAssertStatus(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 cumbersome
this.<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> |
buildAndAssertSuccess(J job) |
void |
configRoundtrip()
Hits the Hudson system configuration and submits without any modification.
|
<B extends hudson.tasks.Builder> |
configRoundtrip(B before)
Performs a configuration round-trip testing for a builder.
|
<C extends hudson.slaves.ComputerConnector> |
configRoundtrip(C before) |
<N extends hudson.model.Node> |
configRoundtrip(N node) |
<P extends hudson.model.Item> |
configRoundtrip(P job)
Loads a configuration page and submits it without any modifications, to
perform a round-trip configuration test.
|
<P extends hudson.tasks.Publisher> |
configRoundtrip(P before)
Performs a configuration round-trip testing for a publisher.
|
hudson.model.User |
configRoundtrip(hudson.model.User u) |
<V extends hudson.model.View> |
configRoundtrip(V view) |
protected void |
configureUpdateCenter()
Configures the update center setting for the test.
|
protected org.eclipse.jetty.security.LoginService |
configureUserRealm()
Configures a security realm for a test.
|
String |
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.
|
JenkinsRule.DummySecurityRealm |
createDummySecurityRealm()
Creates a test
SecurityRealm that recognizes username==password as valid. |
MockFolder |
createFolder(String name)
Creates a simple folder that other jobs can be placed in.
|
hudson.model.FreeStyleProject |
createFreeStyleProject() |
hudson.model.FreeStyleProject |
createFreeStyleProject(String name) |
hudson.Launcher.LocalLauncher |
createLocalLauncher()
Creates
Launcher.LocalLauncher . |
hudson.slaves.DumbSlave |
createOnlineSlave()
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 returning
|
PretendSlave |
createPretendSlave(FakeLauncher faker) |
<T extends hudson.model.TopLevelItem> |
createProject(Class<T> type)
Creates a new job with an unique name.
|
<T extends hudson.model.TopLevelItem> |
createProject(Class<T> type,
String name)
Creates a new job.
|
hudson.slaves.DumbSlave |
createSlave() |
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 variables
|
hudson.slaves.DumbSlave |
createSlave(String nodeName,
String labels,
hudson.EnvVars env) |
hudson.model.TaskListener |
createTaskListener()
Creates a
TaskListener connected to stdout. |
File |
createTmpDir()
Deprecated.
Use
TemporaryFolder instead. |
protected String |
createUniqueProjectName() |
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. |
protected javax.servlet.ServletContext |
createWebServer(BiConsumer<org.eclipse.jetty.webapp.WebAppContext,org.eclipse.jetty.server.Server> contextAndServerConsumer)
Prepares a webapp hosting environment to get
ServletContext 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<?> |
findDataBoundConstructor(Class<?> c) |
com.gargoylesoftware.htmlunit.html.HtmlInput |
findPreviousInputElement(com.gargoylesoftware.htmlunit.html.HtmlElement current,
String name) |
<T extends hudson.model.Descriptor<?>> |
get(Class<T> d)
Gets the descriptor instance of the current Hudson by its type.
|
com.gargoylesoftware.htmlunit.html.HtmlButton |
getButtonByCaption(com.gargoylesoftware.htmlunit.html.HtmlForm f,
String s) |
String |
getDisplayName() |
String |
getIconFileName() |
jenkins.model.Jenkins |
getInstance() |
JenkinsRule.JSONWebResponse |
getJSON(String path)
Get JSON from A Jenkins endpoint.
|
static String |
getLog(hudson.model.Run run)
Get entire log file as plain text.
|
hudson.PluginManager |
getPluginManager() |
org.junit.runner.Description |
getTestDescription() |
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 specified HTTP status code is generally "good"
|
boolean |
isSomethingHappening()
Returns true if Hudson is building something or going to build something.
|
<T> T |
last(List<T> items)
Returns the last item in the list.
|
protected hudson.model.Hudson |
newHudson()
Creates a new instance of
Jenkins . |
void |
pause()
Pauses the execution until ENTER is hit in the console.
|
JenkinsRule.JSONWebResponse |
postJSON(String path,
Object json)
POST a JSON payload to a URL on the underlying Jenkins instance.
|
void |
recipe()
Called during the
before() to give a test case an opportunity to
control the test environment in which Hudson is run. |
void |
recipeLoadCurrentPlugin()
If this test harness is launched for a Jenkins plugin, locate the target/test-classes/the.jpl
and add a recipe to install that to the new Jenkins.
|
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. |
void |
setQuietPeriod(int qp) |
void |
showAgentLogs(hudson.model.Slave s,
LoggerRule loggerRule)
Same as
showAgentLogs(Slave, Map) but taking a preconfigured list of loggers as a convenience. |
void |
showAgentLogs(hudson.model.Slave s,
Map<String,Level> loggers)
Forward agent logs to standard error of the test process.
|
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 clicking the submit button of the given name.
|
<R extends hudson.model.Run<?,?>> |
waitForCompletion(R r)
Waits for a build to complete.
|
<R extends hudson.model.Run<?,?>> |
waitForMessage(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 |
waitUntilNoActivity()
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 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.
|
protected Object |
writeReplace()
Sometimes a part of a test case may ends up creeping into the serialization tree of
Saveable.save() ,
so detect that and flag that as an error. |
protected TestEnvironment env
protected org.junit.runner.Description testDescription
@Deprecated public hudson.model.Hudson hudson
jenkins
does.public jenkins.model.Jenkins jenkins
protected HudsonHomeLoader homeLoader
protected int localPort
protected org.eclipse.jetty.server.Server server
public String contextPath
Server
is Jenkins deployed?
Just like ServletContext.getContextPath()
, starts with '/' but doesn't end with '/'.
Unlike JenkinsRule.WebClient.getContextPath()
this is not a complete URL.
protected List<LenientRunnable> tearDowns
protected List<JenkinsRecipe.Runner> recipes
protected JavaScriptDebugger jsDebugger
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.)
public boolean useLocalPluginManager
pluginManager
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.public int timeout
WithTimeout
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.public JenkinsComputerConnectorTester computerConnectorTester
public static final List<hudson.tools.ToolProperty<?>> NO_PROPERTIES
public static final int SLAVE_DEBUG_PORT
public static final org.eclipse.jetty.http.MimeTypes MIME_TYPES
public jenkins.model.Jenkins getInstance()
public void before() throws Throwable
Throwable
- if setup fails (which will disable after
public static void _configureJenkinsForTest(jenkins.model.Jenkins jenkins) throws Exception
jenkins
- jenkins instance which has to be configuredException
- if unable to configureprotected void configureUpdateCenter() throws Exception
Exception
public static void _configureUpdateCenter(jenkins.model.Jenkins jenkins) throws Exception
jenkins
- the Jenkins to configureException
public void after() throws Exception
Exception
public static void _stopJenkins(org.eclipse.jetty.server.Server server, List<LenientRunnable> tearDowns, jenkins.model.Jenkins jenkins)
server
- server on which Jenkins is running.tearDowns
- tear down methods for testsjenkins
- the jenkins instancepublic org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runners.model.FrameworkMethod method, Object target)
apply
in interface org.junit.rules.MethodRule
public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runner.Description description)
apply
in interface org.junit.rules.TestRule
public String getIconFileName()
getIconFileName
in interface hudson.model.Action
public String getDisplayName()
getDisplayName
in interface hudson.model.Action
getDisplayName
in interface hudson.model.ModelObject
public String getUrlName()
getUrlName
in interface hudson.model.Action
protected hudson.model.Hudson newHudson() throws Exception
Jenkins
. If the derived class wants to create it in a different way,
you can override it.Exception
public hudson.PluginManager getPluginManager()
public void setPluginManager(hudson.PluginManager pluginManager)
PluginManager
to be used when creating a new Jenkins
instance.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.public JenkinsRule with(hudson.PluginManager pluginManager)
protected javax.servlet.ServletContext createWebServer() throws Exception
ServletContext
implementation
that we need for testing.Exception
protected javax.servlet.ServletContext createWebServer(@CheckForNull BiConsumer<org.eclipse.jetty.webapp.WebAppContext,org.eclipse.jetty.server.Server> contextAndServerConsumer) throws Exception
ServletContext
implementation
that we need for testing.contextAndServerConsumer
- configures the WebAppContext
and the Server
for the instance, before they are startedException
public static org.apache.commons.lang3.tuple.ImmutablePair<org.eclipse.jetty.server.Server,javax.servlet.ServletContext> _createWebServer(String contextPath, Consumer<Integer> portSetter, ClassLoader classLoader, int localPort, Supplier<org.eclipse.jetty.security.LoginService> loginServiceSupplier) throws Exception
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 the WebAppContext
localPort
- port on which the server runsloginServiceSupplier
- configures the LoginService
for the instanceServer
and the ServletContext
Exception
public static org.apache.commons.lang3.tuple.ImmutablePair<org.eclipse.jetty.server.Server,javax.servlet.ServletContext> _createWebServer(String contextPath, Consumer<Integer> portSetter, ClassLoader classLoader, int localPort, Supplier<org.eclipse.jetty.security.LoginService> loginServiceSupplier, @CheckForNull BiConsumer<org.eclipse.jetty.webapp.WebAppContext,org.eclipse.jetty.server.Server> contextAndServerConsumer) throws Exception
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 the WebAppContext
localPort
- port on which the server runsloginServiceSupplier
- configures the LoginService
for the instancecontextAndServerConsumer
- configures the WebAppContext
and the Server
for the instance, before they are startedServer
and the ServletContext
Exception
protected org.eclipse.jetty.security.LoginService configureUserRealm()
public static org.eclipse.jetty.security.LoginService _configureUserRealm()
HashLoginService
with three users: alice, bob and charlie
The password is same as the usernamepublic <T extends hudson.model.TopLevelItem> T createProject(Class<T> type, String name) throws IOException
type
- Top level item type.name
- Item name.IllegalArgumentException
- if the project of the given name already exists.IOException
public <T extends hudson.model.TopLevelItem> T createProject(Class<T> type) throws IOException
type
- Top level item type.IOException
public hudson.model.FreeStyleProject createFreeStyleProject() throws IOException
IOException
public hudson.model.FreeStyleProject createFreeStyleProject(String name) throws IOException
IOException
public MockFolder createFolder(String name) throws IOException
IOException
protected String createUniqueProjectName()
public hudson.Launcher.LocalLauncher createLocalLauncher()
Launcher.LocalLauncher
. Useful for launching processes.@Deprecated public File createTmpDir() throws IOException
TemporaryFolder
instead.IOException
public hudson.slaves.DumbSlave createSlave(boolean waitForChannelConnect) throws Exception
Exception
public void disconnectSlave(hudson.slaves.DumbSlave slave) throws Exception
Exception
public hudson.slaves.DumbSlave createSlave(hudson.model.Label l) throws Exception
Exception
public JenkinsRule.DummySecurityRealm createDummySecurityRealm()
SecurityRealm
that recognizes username==password as valid.MockAuthorizationStrategy
public URL getURL() throws IOException
IOException
public hudson.slaves.DumbSlave createSlave(hudson.EnvVars env) throws Exception
Exception
public hudson.slaves.DumbSlave createSlave(hudson.model.Label l, hudson.EnvVars env) throws Exception
Exception
public hudson.slaves.DumbSlave createSlave(String labels, hudson.EnvVars env) throws Exception
Exception
public hudson.slaves.DumbSlave createSlave(String nodeName, String labels, hudson.EnvVars env) throws Exception
Exception
public PretendSlave createPretendSlave(FakeLauncher faker) throws Exception
Exception
public hudson.slaves.ComputerLauncher createComputerLauncher(hudson.EnvVars env) throws URISyntaxException, IOException
env
- Environment variables to add to the slave process. Can be null.URISyntaxException
IOException
public hudson.slaves.DumbSlave createOnlineSlave() throws Exception
Exception
public hudson.slaves.DumbSlave createOnlineSlave(hudson.model.Label l) throws Exception
Exception
public hudson.slaves.DumbSlave createOnlineSlave(hudson.model.Label l, hudson.EnvVars env) throws Exception
Exception
waitOnline(hudson.model.Slave)
@Nonnull public String createApiToken(@Nonnull hudson.model.User user)
public void waitOnline(hudson.model.Slave s) throws Exception
Exception
createSlave()
public void showAgentLogs(hudson.model.Slave s, LoggerRule loggerRule) throws Exception
showAgentLogs(Slave, Map)
but taking a preconfigured list of loggers as a convenience.Exception
public void showAgentLogs(hudson.model.Slave s, Map<String,Level> loggers) throws Exception
Computer.getLogText()
etc.,
or discarded entirely (if below Level.INFO
).s
- an online agentloggers
- Logger.getName()
tied to log levelException
public void interactiveBreak() throws Exception
Exception
public <T> T last(List<T> items)
public void pause() throws IOException
This is often very useful so that you can interact with Hudson from an browser, while developing a test case.
IOException
public com.gargoylesoftware.htmlunit.Page search(String q) throws Exception
Exception
public JenkinsRule.JSONWebResponse getJSON(@Nonnull String path) throws IOException
path
- The endpoint URL.IOException
public JenkinsRule.JSONWebResponse postJSON(@Nonnull String path, @Nonnull Object json) throws IOException, SAXException
path
- The url path on Jenkins.json
- An object that produces a JSON string from it's toString
method.IOException
SAXException
public void configRoundtrip() throws Exception
Exception
public <P extends hudson.model.Item> P configRoundtrip(P job) throws Exception
See http://wiki.jenkins-ci.org/display/JENKINS/Unit+Test#UnitTest-Configurationroundtriptesting
Exception
public <B extends hudson.tasks.Builder> B configRoundtrip(B before) throws Exception
Exception
public <P extends hudson.tasks.Publisher> P configRoundtrip(P before) throws Exception
Exception
public <C extends hudson.slaves.ComputerConnector> C configRoundtrip(C before) throws Exception
Exception
public hudson.model.User configRoundtrip(hudson.model.User u) throws Exception
Exception
public <N extends hudson.model.Node> N configRoundtrip(N node) throws Exception
Exception
public <V extends hudson.model.View> V configRoundtrip(V view) throws Exception
Exception
public <R extends hudson.model.Run> R assertBuildStatus(hudson.model.Result status, R r) throws Exception
Exception
public <R extends hudson.model.Run> R assertBuildStatus(hudson.model.Result status, Future<? extends R> r) throws Exception
Exception
public boolean isGoodHttpStatus(int status)
public void assertGoodStatus(com.gargoylesoftware.htmlunit.Page page)
public <R extends hudson.model.Run> R assertBuildStatusSuccess(R r) throws Exception
Exception
public <R extends hudson.model.Run> R assertBuildStatusSuccess(Future<? extends R> r) throws Exception
Exception
@Nonnull public <J extends hudson.model.Job<J,R> & jenkins.model.ParameterizedJobMixIn.ParameterizedJob<J,R>,R extends hudson.model.Run<J,R> & hudson.model.Queue.Executable> R buildAndAssertSuccess(@Nonnull J job) throws Exception
Exception
@Nonnull public <J extends hudson.model.Job<J,R> & jenkins.model.ParameterizedJobMixIn.ParameterizedJob<J,R>,R extends hudson.model.Run<J,R> & hudson.model.Queue.Executable> R buildAndAssertStatus(@Nonnull hudson.model.Result status, @Nonnull J job) throws Exception
Exception
@Nonnull public hudson.model.FreeStyleBuild buildAndAssertSuccess(@Nonnull hudson.model.FreeStyleProject job) throws Exception
this.<J,R>buildAndAssertSuccess(...)
type hints under JDK 7 javac (and supposedly also IntelliJ).Exception
public void assertLogContains(String substring, hudson.model.Run run) throws IOException
IOException
public void assertLogNotContains(String substring, hudson.model.Run run) throws IOException
IOException
public static String getLog(hudson.model.Run run) throws IOException
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.IOException
public <R extends hudson.model.Run<?,?>> R waitForCompletion(R r) throws InterruptedException
BuildWatcher
.InterruptedException
public <R extends hudson.model.Run<?,?>> R waitForMessage(String message, R r) throws IOException, InterruptedException
BuildWatcher
.IOException
InterruptedException
public void assertXPath(com.gargoylesoftware.htmlunit.html.HtmlPage page, String xpath)
public void assertXPath(com.gargoylesoftware.htmlunit.html.DomNode page, String xpath)
public void assertXPathValue(com.gargoylesoftware.htmlunit.html.DomNode page, String xpath, String expectedValue)
public void assertXPathValueContains(com.gargoylesoftware.htmlunit.html.DomNode page, String xpath, String needle)
public void assertXPathResultsContainText(com.gargoylesoftware.htmlunit.html.DomNode page, String xpath, String needle)
public void assertAllImageLoadSuccessfully(com.gargoylesoftware.htmlunit.html.HtmlPage p)
public void assertStringContains(String message, String haystack, String needle)
public void assertHelpExists(Class<? extends hudson.model.Describable> type, String properties) throws Exception
type
- The describable class type that should have the associated help files.properties
- ','-separated list of properties whose help files should exist.Exception
public com.gargoylesoftware.htmlunit.html.HtmlPage submit(com.gargoylesoftware.htmlunit.html.HtmlForm form) throws Exception
HtmlForm.submit(com.gargoylesoftware.htmlunit.html.SubmittableElement)
doesn't work correctly due to the use of YUI in Hudson.Exception
public com.gargoylesoftware.htmlunit.html.HtmlPage submit(com.gargoylesoftware.htmlunit.html.HtmlForm form, String name) throws Exception
name
- This corresponds to the @name of <f:submit />
Exception
public com.gargoylesoftware.htmlunit.html.HtmlInput findPreviousInputElement(com.gargoylesoftware.htmlunit.html.HtmlElement current, String name)
public com.gargoylesoftware.htmlunit.html.HtmlButton getButtonByCaption(com.gargoylesoftware.htmlunit.html.HtmlForm f, String s)
public hudson.model.TaskListener createTaskListener()
TaskListener
connected to stdout.public void assertEqualBeans(Object lhs, Object rhs, String properties) throws Exception
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.
lhs
- One of the two objects to be compared.rhs
- The other object to be comparedproperties
- ','-separated list of property names that are compared.Exception
public void setQuietPeriod(int qp)
public void assertEqualDataBoundBeans(Object lhs, Object rhs) throws Exception
assertEqualBeans(Object, Object, String)
but figure out the properties
via DataBoundConstructor
and DataBoundSetter
Exception
public void assertEqualDataBoundBeans(List<?> lhs, List<?> rhs) throws Exception
assertEqualDataBoundBeans(Object, Object)
Exception
public Constructor<?> findDataBoundConstructor(Class<?> c)
public <T extends hudson.model.Descriptor<?>> T get(Class<T> d)
public boolean isSomethingHappening()
public void waitUntilNoActivity() throws Exception
Exception
public void waitUntilNoActivityUpTo(int timeout) throws Exception
Exception
public void recipe() throws Exception
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.
Exception
public void recipeLoadCurrentPlugin() throws Exception
This file is created by maven-hpi-plugin at the testCompile phase when the current packaging is jpi.
Exception
public JenkinsRule withNewHome()
public JenkinsRule withExistingHome(File source) throws Exception
Exception
public JenkinsRule withPresetData(String name)
test/src/main/preset-data/
for available datasets and what they mean.public JenkinsRule with(HudsonHomeLoader homeLoader)
public <V> V executeOnServer(Callable<V> c) throws Exception
In JenkinsRule
, 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.
c
- The closure to be executed on the server.Exception
- If a closure throws any exception, that exception will be carried forward.protected Object writeReplace()
Saveable.save()
,
so detect that and flag that as an error.public JenkinsRule.WebClient createWebClient()
public org.junit.runner.Description getTestDescription()
Copyright © 2004–2020. All rights reserved.