Repository: james-project Updated Branches: refs/heads/master 9d086021c -> 269e35915
JAMES-2537 Add management uri in RabbitMQ configuration Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/269e3591 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/269e3591 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/269e3591 Branch: refs/heads/master Commit: 269e35915cec68035b2f55462ca34e9c24de22e2 Parents: 6a44a81 Author: Antoine Duprat <adup...@linagora.com> Authored: Wed Sep 5 11:31:46 2018 +0200 Committer: Antoine Duprat <adup...@linagora.com> Committed: Thu Sep 6 15:29:38 2018 +0200 ---------------------------------------------------------------------- .../mailqueue/RabbitMQConfiguration.java | 22 +++++++-- .../mailqueue/RabbitMQConfigurationTest.java | 52 ++++++++++++++++++++ .../destination/conf/rabbitmq.properties | 3 +- .../destination/conf/rabbitmq.properties | 3 +- .../src/test/resources/rabbitmq.properties | 3 +- 5 files changed, 76 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/269e3591/backends-common/rabbitmq/src/main/java/org/apache/james/backend/mailqueue/RabbitMQConfiguration.java ---------------------------------------------------------------------- diff --git a/backends-common/rabbitmq/src/main/java/org/apache/james/backend/mailqueue/RabbitMQConfiguration.java b/backends-common/rabbitmq/src/main/java/org/apache/james/backend/mailqueue/RabbitMQConfiguration.java index 98283e4..b36c87a 100644 --- a/backends-common/rabbitmq/src/main/java/org/apache/james/backend/mailqueue/RabbitMQConfiguration.java +++ b/backends-common/rabbitmq/src/main/java/org/apache/james/backend/mailqueue/RabbitMQConfiguration.java @@ -29,12 +29,18 @@ import com.google.common.base.Strings; public class RabbitMQConfiguration { private static final String URI_PROPERTY_NAME = "uri"; + private static final String MANAGEMENT_URI_PROPERTY_NAME = "management.uri"; public static RabbitMQConfiguration from(PropertiesConfiguration configuration) { String uriAsString = configuration.getString(URI_PROPERTY_NAME); Preconditions.checkState(!Strings.isNullOrEmpty(uriAsString), "You need to specify the URI of RabbitMQ"); URI uri = checkURI(uriAsString); - return new RabbitMQConfiguration(uri); + + String managementUriAsString = configuration.getString(MANAGEMENT_URI_PROPERTY_NAME); + Preconditions.checkState(!Strings.isNullOrEmpty(managementUriAsString), "You need to specify the management URI of RabbitMQ"); + URI managementUri = checkURI(managementUriAsString); + + return new RabbitMQConfiguration(uri, managementUri); } private static URI checkURI(String uri) { @@ -44,28 +50,36 @@ public class RabbitMQConfiguration { throw new IllegalStateException("You need to specify a valid URI", e); } } + private final URI uri; + private final URI managementUri; - private RabbitMQConfiguration(URI uri) { + private RabbitMQConfiguration(URI uri, URI managementUri) { this.uri = uri; + this.managementUri = managementUri; } public URI getUri() { return uri; } + public URI getManagementUri() { + return managementUri; + } + @Override public final boolean equals(Object o) { if (o instanceof RabbitMQConfiguration) { RabbitMQConfiguration that = (RabbitMQConfiguration) o; - return Objects.equals(this.uri, that.uri); + return Objects.equals(this.uri, that.uri) + && Objects.equals(this.managementUri, that.managementUri); } return false; } @Override public final int hashCode() { - return Objects.hash(uri); + return Objects.hash(uri, managementUri); } } http://git-wip-us.apache.org/repos/asf/james-project/blob/269e3591/backends-common/rabbitmq/src/test/java/org/apache/james/backend/mailqueue/RabbitMQConfigurationTest.java ---------------------------------------------------------------------- diff --git a/backends-common/rabbitmq/src/test/java/org/apache/james/backend/mailqueue/RabbitMQConfigurationTest.java b/backends-common/rabbitmq/src/test/java/org/apache/james/backend/mailqueue/RabbitMQConfigurationTest.java index b5b9d6e..10109cb 100644 --- a/backends-common/rabbitmq/src/test/java/org/apache/james/backend/mailqueue/RabbitMQConfigurationTest.java +++ b/backends-common/rabbitmq/src/test/java/org/apache/james/backend/mailqueue/RabbitMQConfigurationTest.java @@ -70,4 +70,56 @@ public class RabbitMQConfigurationTest { .isInstanceOf(IllegalStateException.class) .hasMessage("You need to specify a valid URI"); } + + @Test + public void fromShouldThrowWhenManagementURIIsNotInTheConfiguration() { + PropertiesConfiguration configuration = new PropertiesConfiguration(); + configuration.addProperty("uri", "amqp://james:james@rabbitmq_host:5672"); + + assertThatThrownBy(() -> RabbitMQConfiguration.from(configuration)) + .isInstanceOf(IllegalStateException.class) + .hasMessage("You need to specify the management URI of RabbitMQ"); + } + + @Test + public void fromShouldThrowWhenManagementURIIsNull() { + PropertiesConfiguration configuration = new PropertiesConfiguration(); + configuration.addProperty("uri", "amqp://james:james@rabbitmq_host:5672"); + configuration.addProperty("management.uri", null); + + assertThatThrownBy(() -> RabbitMQConfiguration.from(configuration)) + .isInstanceOf(IllegalStateException.class) + .hasMessage("You need to specify the management URI of RabbitMQ"); + } + + @Test + public void fromShouldThrowWhenManagementURIIsEmpty() { + PropertiesConfiguration configuration = new PropertiesConfiguration(); + configuration.addProperty("uri", "amqp://james:james@rabbitmq_host:5672"); + configuration.addProperty("management.uri", ""); + + assertThatThrownBy(() -> RabbitMQConfiguration.from(configuration)) + .isInstanceOf(IllegalStateException.class) + .hasMessage("You need to specify the management URI of RabbitMQ"); + } + + @Test + public void fromShouldThrowWhenManagementURIIsInvalid() { + PropertiesConfiguration configuration = new PropertiesConfiguration(); + configuration.addProperty("uri", "amqp://james:james@rabbitmq_host:5672"); + configuration.addProperty("management.uri", ":invalid"); + + assertThatThrownBy(() -> RabbitMQConfiguration.from(configuration)) + .isInstanceOf(IllegalStateException.class) + .hasMessage("You need to specify a valid URI"); + } + + @Test + public void fromShouldNotThrowWhenRequiredParametersAreGiven() { + PropertiesConfiguration configuration = new PropertiesConfiguration(); + configuration.addProperty("uri", "amqp://james:james@rabbitmq_host:5672"); + configuration.addProperty("management.uri", "http://james:james@rabbitmq_host:15672/api/"); + + RabbitMQConfiguration.from(configuration); + } } http://git-wip-us.apache.org/repos/asf/james-project/blob/269e3591/dockerfiles/run/guice/cassandra-ldap/destination/conf/rabbitmq.properties ---------------------------------------------------------------------- diff --git a/dockerfiles/run/guice/cassandra-ldap/destination/conf/rabbitmq.properties b/dockerfiles/run/guice/cassandra-ldap/destination/conf/rabbitmq.properties index 216956e..25d0dd6 100644 --- a/dockerfiles/run/guice/cassandra-ldap/destination/conf/rabbitmq.properties +++ b/dockerfiles/run/guice/cassandra-ldap/destination/conf/rabbitmq.properties @@ -1 +1,2 @@ -uri=amqp://james:james@rabbitmq_host:5672 \ No newline at end of file +uri=amqp://james:james@rabbitmq_host:5672 +management.uri=http://james:james@rabbitmq_host:15672/api/ \ No newline at end of file http://git-wip-us.apache.org/repos/asf/james-project/blob/269e3591/dockerfiles/run/guice/cassandra/destination/conf/rabbitmq.properties ---------------------------------------------------------------------- diff --git a/dockerfiles/run/guice/cassandra/destination/conf/rabbitmq.properties b/dockerfiles/run/guice/cassandra/destination/conf/rabbitmq.properties index 216956e..25d0dd6 100644 --- a/dockerfiles/run/guice/cassandra/destination/conf/rabbitmq.properties +++ b/dockerfiles/run/guice/cassandra/destination/conf/rabbitmq.properties @@ -1 +1,2 @@ -uri=amqp://james:james@rabbitmq_host:5672 \ No newline at end of file +uri=amqp://james:james@rabbitmq_host:5672 +management.uri=http://james:james@rabbitmq_host:15672/api/ \ No newline at end of file http://git-wip-us.apache.org/repos/asf/james-project/blob/269e3591/server/container/guice/cassandra-guice/src/test/resources/rabbitmq.properties ---------------------------------------------------------------------- diff --git a/server/container/guice/cassandra-guice/src/test/resources/rabbitmq.properties b/server/container/guice/cassandra-guice/src/test/resources/rabbitmq.properties index 216956e..25d0dd6 100644 --- a/server/container/guice/cassandra-guice/src/test/resources/rabbitmq.properties +++ b/server/container/guice/cassandra-guice/src/test/resources/rabbitmq.properties @@ -1 +1,2 @@ -uri=amqp://james:james@rabbitmq_host:5672 \ No newline at end of file +uri=amqp://james:james@rabbitmq_host:5672 +management.uri=http://james:james@rabbitmq_host:15672/api/ \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org