Class BrokerRunning

java.lang.Object
org.junit.rules.TestWatcher
org.springframework.amqp.rabbit.junit.BrokerRunning
All Implemented Interfaces:
org.junit.rules.TestRule

@Deprecated(since="4.0", forRemoval=true) public final class BrokerRunning extends org.junit.rules.TestWatcher
Deprecated, for removal: This API element is subject to removal in a future version.
since 4.0 in favor of JUnit 5 RabbitAvailable.
A rule that prevents integration tests from failing if the Rabbit broker application is not running or not accessible. If the Rabbit broker is not running in the background all the tests here will simply be skipped (by default) because of a violated assumption (showing as successful). Usage:
 @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.

Since:
1.7
Author:
Dave Syer, Gary Russell, Artem Bilan
  • Method Summary

    Modifier and Type
    Method
    Description
    org.junit.runners.model.Statement
    apply(org.junit.runners.model.Statement base, org.junit.runner.Description description)
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    static void
    Deprecated, for removal: This API element is subject to removal in a future version.
    Clear any environment variable overrides set in setEnvironmentVariableOverrides(Map).
    void
    deleteExchanges(String... exchanges)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Delete arbitrary exchanges from the broker.
    void
    deleteQueues(String... queuesToDelete)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Delete arbitrary queues from the broker.
    static boolean
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    Deprecated, for removal: This API element is subject to removal in a future version.
    Generate the connection id for the connection used by the rule's connection factory.
    Deprecated, for removal: This API element is subject to removal in a future version.
    Return the admin password.
    Deprecated, for removal: This API element is subject to removal in a future version.
    Return the admin uri.
    Deprecated, for removal: This API element is subject to removal in a future version.
    Return the admin user.
    com.rabbitmq.client.ConnectionFactory
    Deprecated, for removal: This API element is subject to removal in a future version.
    Get the connection factory used by this rule.
    Deprecated, for removal: This API element is subject to removal in a future version.
    Return the port.
    Deprecated, for removal: This API element is subject to removal in a future version.
    Return the password.
    int
    Deprecated, for removal: This API element is subject to removal in a future version.
    Return the port.
    Deprecated, for removal: This API element is subject to removal in a future version.
    Return the user.
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    Deprecated, for removal: This API element is subject to removal in a future version.
    Ensure the broker is running and has a empty queue(s) with the specified name(s) in the default exchange.
    void
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    void
    Deprecated, for removal: This API element is subject to removal in a future version.
    Delete and re-declare all the configured queues.
    void
    removeTestQueues(String... additionalQueues)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Remove any test queues that were created by an isRunningWithEmptyQueues(String...) method.
    void
    Deprecated, for removal: This API element is subject to removal in a future version.
    Set the password for the management REST API connection default "guest".
    void
    setAdminUri(String adminUri)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Set the uri for the REST API.
    void
    Deprecated, for removal: This API element is subject to removal in a future version.
    Set the user for the management REST API connection default "guest".
    static void
    Deprecated, for removal: This API element is subject to removal in a future version.
    Set environment variable overrides for host, port etc.
    void
    setHostName(String hostName)
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    void
    setPassword(String password)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Set the password for the amqp connection default "guest".
    void
    setPort(int port)
    Deprecated, for removal: This API element is subject to removal in a future version.
     
    void
    Deprecated, for removal: This API element is subject to removal in a future version.
    Set the user for the amqp connection default "guest".

    Methods inherited from class org.junit.rules.TestWatcher

    failed, finished, skipped, skipped, starting, succeeded

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • setEnvironmentVariableOverrides

      public static void setEnvironmentVariableOverrides(Map<String,String> environmentVariables)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Set environment variable overrides for host, port etc. Will override any real environment variables, if present.

      The variables will only apply to rule instances that are created after this method is called. The overrides will remain until clearEnvironmentVariableOverrides() is called.

      Parameters:
      environmentVariables - the variables.
    • clearEnvironmentVariableOverrides

      public static void clearEnvironmentVariableOverrides()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Clear any environment variable overrides set in setEnvironmentVariableOverrides(Map).
    • isRunningWithEmptyQueues

      public static BrokerRunning isRunningWithEmptyQueues(String... names)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Ensure the broker is running and has a empty queue(s) with the specified name(s) in the default exchange.
      Parameters:
      names - the queues to declare for the test.
      Returns:
      a new rule that assumes an existing running broker
    • isRunning

      public static BrokerRunning isRunning()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Returns:
      a new rule that assumes an existing running broker
    • isNotRunning

      public static BrokerRunning isNotRunning()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Returns:
      a new rule that assumes there is no existing broker
    • isBrokerAndManagementRunning

      public static BrokerRunning isBrokerAndManagementRunning()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Returns:
      a new rule that assumes an existing broker with the management plugin
    • isBrokerAndManagementRunningWithEmptyQueues

      public static BrokerRunning isBrokerAndManagementRunningWithEmptyQueues(String... queues)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Parameters:
      queues - the queues.
      Returns:
      a new rule that assumes an existing broker with the management plugin with the provided queues declared (and emptied if needed)..
    • setPort

      public void setPort(int port)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Parameters:
      port - the port to set
    • setHostName

      public void setHostName(String hostName)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Parameters:
      hostName - the hostName to set
    • setUser

      public void setUser(String user)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Set the user for the amqp connection default "guest".
      Parameters:
      user - the user.
      Since:
      1.7.2
    • setPassword

      public void setPassword(String password)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Set the password for the amqp connection default "guest".
      Parameters:
      password - the password.
      Since:
      1.7.2
    • setAdminUri

      public void setAdminUri(String adminUri)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Set the uri for the REST API.
      Parameters:
      adminUri - the uri.
      Since:
      1.7.2
    • setAdminUser

      public void setAdminUser(String user)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Set the user for the management REST API connection default "guest".
      Parameters:
      user - the user.
      Since:
      1.7.2
    • setAdminPassword

      public void setAdminPassword(String password)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Set the password for the management REST API connection default "guest".
      Parameters:
      password - the password.
      Since:
      1.7.2
    • getPort

      public int getPort()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Return the port.
      Returns:
      the port.
      Since:
      1.7.2
    • getHostName

      public String getHostName()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Return the port.
      Returns:
      the port.
      Since:
      1.7.2
    • getUser

      public String getUser()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Return the user.
      Returns:
      the user.
      Since:
      1.7.2
    • getPassword

      public String getPassword()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Return the password.
      Returns:
      the password.
      Since:
      1.7.2
    • getAdminUser

      public String getAdminUser()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Return the admin user.
      Returns:
      the user.
      Since:
      1.7.2
    • getAdminPassword

      public String getAdminPassword()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Return the admin password.
      Returns:
      the password.
      Since:
      1.7.2
    • apply

      public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runner.Description description)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Specified by:
      apply in interface org.junit.rules.TestRule
      Overrides:
      apply in class org.junit.rules.TestWatcher
    • isUp

      public void isUp()
      Deprecated, for removal: This API element is subject to removal in a future version.
    • fatal

      public static boolean fatal()
      Deprecated, for removal: This API element is subject to removal in a future version.
    • generateId

      public String generateId()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Generate the connection id for the connection used by the rule's connection factory.
      Returns:
      the id.
    • removeTestQueues

      public void removeTestQueues(String... additionalQueues)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Remove any test queues that were created by an isRunningWithEmptyQueues(String...) method.
      Parameters:
      additionalQueues - additional queues to remove that might have been created by tests.
    • purgeTestQueues

      public void purgeTestQueues()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Delete and re-declare all the configured queues. Can be used between tests when a test might leave stale data and multiple tests use the same queue.
    • deleteQueues

      public void deleteQueues(String... queuesToDelete)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Delete arbitrary queues from the broker.
      Parameters:
      queuesToDelete - the queues to delete.
    • deleteExchanges

      public void deleteExchanges(String... exchanges)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Delete arbitrary exchanges from the broker.
      Parameters:
      exchanges - the exchanges to delete.
    • getConnectionFactory

      public com.rabbitmq.client.ConnectionFactory getConnectionFactory()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Get the connection factory used by this rule.
      Returns:
      the connection factory.
    • getAdminUri

      public String getAdminUri()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Return the admin uri.
      Returns:
      the uri.
      Since:
      1.7.2