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 String |
BROKER_REQUIRED |
| Modifier and Type | Method and Description |
|---|---|
org.junit.runners.model.Statement |
apply(org.junit.runners.model.Statement base,
org.junit.runner.Description description) |
void |
deleteExchanges(String... exchanges)
Delete arbitrary exchanges from the broker.
|
void |
deleteQueues(String... queues)
Delete arbitrary queues from the broker.
|
String |
generateId()
Generate the connection id for the connection used by the rule's
connection factory.
|
com.rabbitmq.client.ConnectionFactory |
getConnectionFactory()
Get the connection factory used by this rule.
|
static BrokerRunning |
isBrokerAndManagementRunning() |
static BrokerRunning |
isBrokerAndManagementRunningWithEmptyQueues(String... queues) |
static BrokerRunning |
isNotRunning() |
static BrokerRunning |
isRunning() |
static BrokerRunning |
isRunningWithEmptyQueues(String... names)
Ensure the broker is running and has a empty queue(s) with the specified name(s) in the
default exchange.
|
void |
removeTestQueues(String... additionalQueues)
Remove any test queues that were created by an
isRunningWithEmptyQueues(String...) method. |
void |
setHostName(String hostName) |
void |
setPort(int port) |
public static final String BROKER_REQUIRED
public static BrokerRunning isRunningWithEmptyQueues(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(String... queues)
public void setPort(int port)
port - the port to setpublic void setHostName(String hostName)
hostName - the hostName to setpublic org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base,
org.junit.runner.Description description)
apply in interface org.junit.rules.TestRuleapply in class org.junit.rules.TestWatcherpublic String generateId()
public void removeTestQueues(String... additionalQueues)
isRunningWithEmptyQueues(String...) method.additionalQueues - additional queues to remove that might have been created by
tests.public void deleteQueues(String... queues)
queues - the queues to delete.public void deleteExchanges(String... exchanges)
exchanges - the exchanges to delete.public com.rabbitmq.client.ConnectionFactory getConnectionFactory()