public final class BrokerRunning
extends org.junit.rules.TestWatcher
@Rule public static BrokerRunning brokerIsRunning = BrokerRunning.isRunning(); @Test public void testSendAndReceive() throws Exception { // ... test using RabbitTemplate etc. }The rule can be declared as static so that it only has to check once for all tests in the enclosing test case, but there isn't a lot of overhead in making it non-static.
Use isRunningWithEmptyQueues(String...)
to declare and/or purge test queue(s)
when the rule is run.
Call removeTestQueues(String...)
from an @After
method to remove
those queues (and optionally others).
If you wish to enforce the broker being available, for example, on a CI server,
set the environment variable "RABBITMQ_SERVER_REQUIRED" to true
and the
tests will fail fast.
Assume
,
AssumptionViolatedException
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
BROKER_ADMIN_PW |
static java.lang.String |
BROKER_ADMIN_URI |
static java.lang.String |
BROKER_ADMIN_USER |
static java.lang.String |
BROKER_HOSTNAME |
static java.lang.String |
BROKER_PORT |
static java.lang.String |
BROKER_PW |
static java.lang.String |
BROKER_REQUIRED |
static java.lang.String |
BROKER_USER |
Modifier and Type | Method and Description |
---|---|
org.junit.runners.model.Statement |
apply(org.junit.runners.model.Statement base,
org.junit.runner.Description description) |
static void |
clearEnvironmentVariableOverrides()
Clear any environment variable overrides set in
setEnvironmentVariableOverrides(Map) . |
void |
deleteExchanges(java.lang.String... exchanges)
Delete arbitrary exchanges from the broker.
|
void |
deleteQueues(java.lang.String... queues)
Delete arbitrary queues from the broker.
|
static boolean |
fatal() |
java.lang.String |
generateId()
Generate the connection id for the connection used by the rule's
connection factory.
|
java.lang.String |
getAdminPassword()
Return the admin password.
|
java.lang.String |
getAdminUri()
Return the admin uri.
|
java.lang.String |
getAdminUser()
Return the admin user.
|
com.rabbitmq.client.ConnectionFactory |
getConnectionFactory()
Get the connection factory used by this rule.
|
java.lang.String |
getHostName()
Return the port.
|
java.lang.String |
getPassword()
Return the password.
|
int |
getPort()
Return the port.
|
java.lang.String |
getUser()
Return the user.
|
static BrokerRunning |
isBrokerAndManagementRunning() |
static BrokerRunning |
isBrokerAndManagementRunningWithEmptyQueues(java.lang.String... queues) |
static BrokerRunning |
isNotRunning() |
static BrokerRunning |
isRunning() |
static BrokerRunning |
isRunningWithEmptyQueues(java.lang.String... names)
Ensure the broker is running and has a empty queue(s) with the specified name(s) in the
default exchange.
|
void |
isUp() |
void |
removeTestQueues(java.lang.String... additionalQueues)
Remove any test queues that were created by an
isRunningWithEmptyQueues(String...) method. |
void |
setAdminPassword(java.lang.String password)
Set the password for the management REST API connection default "guest".
|
void |
setAdminUri(java.lang.String adminUri)
Set the uri for the REST API.
|
void |
setAdminUser(java.lang.String user)
Set the user for the management REST API connection default "guest".
|
static void |
setEnvironmentVariableOverrides(java.util.Map<java.lang.String,java.lang.String> environmentVariables)
Set environment variable overrides for host, port etc.
|
void |
setHostName(java.lang.String hostName) |
void |
setPassword(java.lang.String password)
Set the password for the amqp connection default "guest".
|
void |
setPort(int port) |
void |
setUser(java.lang.String user)
Set the user for the amqp connection default "guest".
|
public static final java.lang.String BROKER_ADMIN_URI
public static final java.lang.String BROKER_HOSTNAME
public static final java.lang.String BROKER_PORT
public static final java.lang.String BROKER_USER
public static final java.lang.String BROKER_PW
public static final java.lang.String BROKER_ADMIN_USER
public static final java.lang.String BROKER_ADMIN_PW
public static final java.lang.String BROKER_REQUIRED
public static void setEnvironmentVariableOverrides(java.util.Map<java.lang.String,java.lang.String> environmentVariables)
The variables will only apply to rule instances that are created after this method is called. The overrides will remain until
environmentVariables
- the variables.public static void clearEnvironmentVariableOverrides()
setEnvironmentVariableOverrides(Map)
.public static BrokerRunning isRunningWithEmptyQueues(java.lang.String... names)
names
- the queues to declare for the test.public static BrokerRunning isRunning()
public static BrokerRunning isNotRunning()
public static BrokerRunning isBrokerAndManagementRunning()
public static BrokerRunning isBrokerAndManagementRunningWithEmptyQueues(java.lang.String... queues)
queues
- the queues.public void setPort(int port)
port
- the port to setpublic void setHostName(java.lang.String hostName)
hostName
- the hostName to setpublic void setUser(java.lang.String user)
user
- the user.public void setPassword(java.lang.String password)
password
- the password.public void setAdminUri(java.lang.String adminUri)
adminUri
- the uri.public void setAdminUser(java.lang.String user)
user
- the user.public void setAdminPassword(java.lang.String password)
password
- the password.public int getPort()
public java.lang.String getHostName()
public java.lang.String getUser()
public java.lang.String getPassword()
public java.lang.String getAdminUser()
public java.lang.String getAdminPassword()
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
apply
in class org.junit.rules.TestWatcher
public void isUp() throws java.lang.Exception
java.lang.Exception
public static boolean fatal()
public java.lang.String generateId()
public void removeTestQueues(java.lang.String... additionalQueues)
isRunningWithEmptyQueues(String...)
method.additionalQueues
- additional queues to remove that might have been created by
tests.public void deleteQueues(java.lang.String... queues)
queues
- the queues to delete.public void deleteExchanges(java.lang.String... exchanges)
exchanges
- the exchanges to delete.public com.rabbitmq.client.ConnectionFactory getConnectionFactory()
public java.lang.String getAdminUri()