james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [2/2] james-project git commit: JAMES-2544 ManagementCredentials info should be apart of RabbitMQConfiguration
Date Wed, 03 Oct 2018 02:32:36 GMT
JAMES-2544 ManagementCredentials info should be apart of RabbitMQConfiguration


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/0ca09252
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/0ca09252
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/0ca09252

Branch: refs/heads/master
Commit: 0ca09252ac44886c0f88cfd04c59c206fb679e8d
Parents: a076d13
Author: duc <dtran@linagora.com>
Authored: Tue Oct 2 16:13:34 2018 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Wed Oct 3 09:31:58 2018 +0700

----------------------------------------------------------------------
 .../backend/rabbitmq/RabbitMQConfiguration.java | 90 ++++++++++++++++--
 .../rabbitmq/RabbitMQConfigurationTest.java     | 97 ++++++++++++++++++++
 .../rabbitmq/RabbitMQConnectionFactoryTest.java |  4 +
 .../james/backend/rabbitmq/RabbitMQFixture.java |  5 +
 .../rabbitmq/RabbitMQHealthCheckTest.java       |  3 +-
 .../queue/rabbitmq/RabbitMQManagementApi.java   |  9 +-
 .../rabbitmq/RabbitMQManagementCredentials.java | 40 --------
 ...abbitMQMailQueueConfigurationChangeTest.java |  4 +-
 .../queue/rabbitmq/RabbitMQMailQueueTest.java   |  7 +-
 .../rabbitmq/RabbitMqMailQueueFactoryTest.java  |  8 +-
 10 files changed, 203 insertions(+), 64 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/0ca09252/backends-common/rabbitmq/src/main/java/org/apache/james/backend/rabbitmq/RabbitMQConfiguration.java
----------------------------------------------------------------------
diff --git a/backends-common/rabbitmq/src/main/java/org/apache/james/backend/rabbitmq/RabbitMQConfiguration.java
b/backends-common/rabbitmq/src/main/java/org/apache/james/backend/rabbitmq/RabbitMQConfiguration.java
index 9f475b4..8da712a 100644
--- a/backends-common/rabbitmq/src/main/java/org/apache/james/backend/rabbitmq/RabbitMQConfiguration.java
+++ b/backends-common/rabbitmq/src/main/java/org/apache/james/backend/rabbitmq/RabbitMQConfiguration.java
@@ -19,6 +19,7 @@
 package org.apache.james.backend.rabbitmq;
 
 import java.net.URI;
+import java.util.Arrays;
 import java.util.Objects;
 import java.util.Optional;
 
@@ -28,6 +29,57 @@ import com.google.common.base.Preconditions;
 import com.google.common.base.Strings;
 
 public class RabbitMQConfiguration {
+
+    public static class ManagementCredentials {
+
+        static ManagementCredentials from(Configuration configuration) {
+            String user = configuration.getString(MANAGEMENT_CREDENTIAL_USER_PROPERTY);
+            Preconditions.checkState(!Strings.isNullOrEmpty(user), "You need to specify the
" +
+                MANAGEMENT_CREDENTIAL_USER_PROPERTY + " property as username of rabbitmq
management admin account");
+
+            String passwordString = configuration.getString(MANAGEMENT_CREDENTIAL_PASSWORD_PROPERTY);
+            Preconditions.checkState(!Strings.isNullOrEmpty(passwordString), "You need to
specify the " +
+                MANAGEMENT_CREDENTIAL_PASSWORD_PROPERTY + " property as password of rabbitmq
management admin account");
+
+            return new ManagementCredentials(user, passwordString.toCharArray());
+        }
+
+        private static final String MANAGEMENT_CREDENTIAL_USER_PROPERTY = "management.user";
+        private static final String MANAGEMENT_CREDENTIAL_PASSWORD_PROPERTY = "management.password";
+        private final String user;
+        private final char[] password;
+
+        ManagementCredentials(String user, char[] password) {
+            Preconditions.checkNotNull(user);
+            Preconditions.checkNotNull(password);
+            this.user = user;
+            this.password = password;
+        }
+
+        public String getUser() {
+            return user;
+        }
+
+        public char[] getPassword() {
+            return password;
+        }
+
+        @Override
+        public final boolean equals(Object o) {
+            if (o instanceof ManagementCredentials) {
+                ManagementCredentials that = (ManagementCredentials) o;
+                return Objects.equals(this.user, that.user)
+                    && Arrays.equals(this.password, that.password);
+            }
+            return false;
+        }
+
+        @Override
+        public final int hashCode() {
+            return Objects.hash(user, Arrays.hashCode(password));
+        }
+    }
+
     @FunctionalInterface
     public interface RequireAmqpUri {
         RequireManagementUri amqpUri(URI amqpUri);
@@ -35,21 +87,28 @@ public class RabbitMQConfiguration {
 
     @FunctionalInterface
     public interface RequireManagementUri {
-        Builder managementUri(URI managementUri);
+        RequireManagementCredentials managementUri(URI managementUri);
+    }
+
+    @FunctionalInterface
+    public interface RequireManagementCredentials {
+        Builder managementCredentials(ManagementCredentials managementCredentials);
     }
 
     public static class Builder {
-        public static final int DEFAULT_MAX_RETRIES = 7;
-        public static final int DEFAULT_MIN_DELAY = 3000;
+        static final int DEFAULT_MAX_RETRIES = 7;
+        static final int DEFAULT_MIN_DELAY = 3000;
 
         private final URI amqpUri;
         private final URI managementUri;
+        private final ManagementCredentials managementCredentials;
         private Optional<Integer> maxRetries;
         private Optional<Integer> minDelay;
 
-        private Builder(URI amqpUri, URI managementUri) {
+        private Builder(URI amqpUri, URI managementUri, ManagementCredentials managementCredentials)
{
             this.amqpUri = amqpUri;
             this.managementUri = managementUri;
+            this.managementCredentials = managementCredentials;
             this.maxRetries = Optional.empty();
             this.minDelay = Optional.empty();
         }
@@ -67,8 +126,10 @@ public class RabbitMQConfiguration {
         public RabbitMQConfiguration build() {
             Preconditions.checkNotNull(amqpUri, "'amqpUri' should not be null");
             Preconditions.checkNotNull(managementUri, "'managementUri' should not be null");
-            return new RabbitMQConfiguration(amqpUri, 
-                    managementUri, 
+            Preconditions.checkNotNull(managementCredentials, "'managementCredentials' should
not be null");
+            return new RabbitMQConfiguration(amqpUri,
+                    managementUri,
+                    managementCredentials,
                     maxRetries.orElse(DEFAULT_MAX_RETRIES),
                     minDelay.orElse(DEFAULT_MIN_DELAY));
         }
@@ -78,7 +139,7 @@ public class RabbitMQConfiguration {
     private static final String MANAGEMENT_URI_PROPERTY_NAME = "management.uri";
 
     public static RequireAmqpUri builder() {
-        return amqpUri -> managementUri -> new Builder(amqpUri, managementUri);
+        return amqpUri -> managementUri -> managementCredentials -> new Builder(amqpUri,
managementUri, managementCredentials);
     }
 
     public static RabbitMQConfiguration from(Configuration configuration) {
@@ -90,9 +151,11 @@ public class RabbitMQConfiguration {
         Preconditions.checkState(!Strings.isNullOrEmpty(managementUriAsString), "You need
to specify the management URI of RabbitMQ");
         URI managementUri = checkURI(managementUriAsString);
 
+        ManagementCredentials managementCredentials = ManagementCredentials.from(configuration);
         return builder()
             .amqpUri(amqpUri)
             .managementUri(managementUri)
+            .managementCredentials(managementCredentials)
             .build();
     }
 
@@ -108,10 +171,12 @@ public class RabbitMQConfiguration {
     private final URI managementUri;
     private final int maxRetries;
     private final int minDelay;
+    private final ManagementCredentials managementCredentials;
 
-    private RabbitMQConfiguration(URI uri, URI managementUri, int maxRetries, int minDelay)
{
+    private RabbitMQConfiguration(URI uri, URI managementUri, ManagementCredentials managementCredentials,
int maxRetries, int minDelay) {
         this.uri = uri;
         this.managementUri = managementUri;
+        this.managementCredentials = managementCredentials;
         this.maxRetries = maxRetries;
         this.minDelay = minDelay;
     }
@@ -132,6 +197,10 @@ public class RabbitMQConfiguration {
         return minDelay;
     }
 
+    public ManagementCredentials getManagementCredentials() {
+        return managementCredentials;
+    }
+
     @Override
     public final boolean equals(Object o) {
         if (o instanceof RabbitMQConfiguration) {
@@ -140,13 +209,14 @@ public class RabbitMQConfiguration {
             return Objects.equals(this.uri, that.uri)
                 && Objects.equals(this.managementUri, that.managementUri)
                 && Objects.equals(this.maxRetries, that.maxRetries)
-                && Objects.equals(this.minDelay, that.minDelay);
+                && Objects.equals(this.minDelay, that.minDelay)
+                && Objects.equals(this.managementCredentials, that.managementCredentials);
         }
         return false;
     }
 
     @Override
     public final int hashCode() {
-        return Objects.hash(uri, managementUri, maxRetries, minDelay);
+        return Objects.hash(uri, managementUri, maxRetries, minDelay, managementCredentials);
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/0ca09252/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQConfigurationTest.java
----------------------------------------------------------------------
diff --git a/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQConfigurationTest.java
b/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQConfigurationTest.java
index 7a1a747..cbdf02f 100644
--- a/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQConfigurationTest.java
+++ b/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQConfigurationTest.java
@@ -18,6 +18,9 @@
  ****************************************************************/
 package org.apache.james.backend.rabbitmq;
 
+import static org.apache.james.backend.rabbitmq.RabbitMQFixture.DEFAULT_MANAGEMENT_CREDENTIAL;
+import static org.apache.james.backend.rabbitmq.RabbitMQFixture.DEFAULT_PASSWORD_STRING;
+import static org.apache.james.backend.rabbitmq.RabbitMQFixture.DEFAULT_USER;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
@@ -25,6 +28,7 @@ import java.net.URI;
 import java.net.URISyntaxException;
 
 import org.apache.commons.configuration.PropertiesConfiguration;
+import org.junit.jupiter.api.Nested;
 import org.junit.jupiter.api.Test;
 
 import nl.jqno.equalsverifier.EqualsVerifier;
@@ -125,19 +129,55 @@ class RabbitMQConfigurationTest {
         configuration.addProperty("uri", amqpUri);
         String managementUri = "http://james:james@rabbitmq_host:15672/api/";
         configuration.addProperty("management.uri", managementUri);
+        configuration.addProperty("management.user", DEFAULT_USER);
+        configuration.addProperty("management.password", DEFAULT_PASSWORD_STRING);
 
         assertThat(RabbitMQConfiguration.from(configuration))
             .isEqualTo(RabbitMQConfiguration.builder()
                 .amqpUri(URI.create(amqpUri))
                 .managementUri(URI.create(managementUri))
+                .managementCredentials(DEFAULT_MANAGEMENT_CREDENTIAL)
                 .build());
     }
 
     @Test
+    void fromShouldThrowWhenManagementCredentialsAreNotGiven() {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        String amqpUri = "amqp://james:james@rabbitmq_host:5672";
+        configuration.addProperty("uri", amqpUri);
+        String managementUri = "http://james:james@rabbitmq_host:15672/api/";
+        configuration.addProperty("management.uri", managementUri);
+
+        assertThatThrownBy(() -> RabbitMQConfiguration.from(configuration))
+            .isInstanceOf(IllegalStateException.class)
+            .hasMessage("You need to specify the management.user property as username of
rabbitmq management admin account");
+    }
+
+    @Test
+    void fromShouldReturnCustomValueWhenManagementCredentialsAreGiven() {
+        PropertiesConfiguration configuration = new PropertiesConfiguration();
+        String amqpUri = "amqp://james:james@rabbitmq_host:5672";
+        configuration.addProperty("uri", amqpUri);
+        String managementUri = "http://james:james@rabbitmq_host:15672/api/";
+        configuration.addProperty("management.uri", managementUri);
+        String user = "james";
+        configuration.addProperty("management.user", user);
+        String passwordString = "james_password";
+        configuration.addProperty("management.password", passwordString);
+
+        RabbitMQConfiguration.ManagementCredentials credentials = new RabbitMQConfiguration.ManagementCredentials(
+            user, passwordString.toCharArray());
+
+        assertThat(RabbitMQConfiguration.from(configuration).getManagementCredentials())
+            .isEqualTo(credentials);
+    }
+
+    @Test
     void maxRetriesShouldEqualsDefaultValueWhenNotGiven() throws URISyntaxException {
         RabbitMQConfiguration rabbitMQConfiguration = RabbitMQConfiguration.builder()
             .amqpUri(new URI("amqp://james:james@rabbitmq_host:5672"))
             .managementUri(new URI("http://james:james@rabbitmq_host:15672/api/"))
+            .managementCredentials(DEFAULT_MANAGEMENT_CREDENTIAL)
             .build();
 
         assertThat(rabbitMQConfiguration.getMaxRetries())
@@ -151,6 +191,7 @@ class RabbitMQConfigurationTest {
         RabbitMQConfiguration rabbitMQConfiguration = RabbitMQConfiguration.builder()
             .amqpUri(new URI("amqp://james:james@rabbitmq_host:5672"))
             .managementUri(new URI("http://james:james@rabbitmq_host:15672/api/"))
+            .managementCredentials(DEFAULT_MANAGEMENT_CREDENTIAL)
             .maxRetries(maxRetries)
             .build();
 
@@ -163,6 +204,7 @@ class RabbitMQConfigurationTest {
         RabbitMQConfiguration rabbitMQConfiguration = RabbitMQConfiguration.builder()
             .amqpUri(new URI("amqp://james:james@rabbitmq_host:5672"))
             .managementUri(new URI("http://james:james@rabbitmq_host:15672/api/"))
+            .managementCredentials(DEFAULT_MANAGEMENT_CREDENTIAL)
             .build();
 
         assertThat(rabbitMQConfiguration.getMinDelay())
@@ -176,10 +218,65 @@ class RabbitMQConfigurationTest {
         RabbitMQConfiguration rabbitMQConfiguration = RabbitMQConfiguration.builder()
             .amqpUri(new URI("amqp://james:james@rabbitmq_host:5672"))
             .managementUri(new URI("http://james:james@rabbitmq_host:15672/api/"))
+            .managementCredentials(DEFAULT_MANAGEMENT_CREDENTIAL)
             .minDelay(minDelay)
             .build();
 
         assertThat(rabbitMQConfiguration.getMinDelay())
             .isEqualTo(minDelay);
     }
+
+    @Nested
+    class ManagementCredentialsTest {
+        @Test
+        void managementCredentialShouldRespectBeanContract() {
+            EqualsVerifier.forClass(RabbitMQConfiguration.ManagementCredentials.class)
+                .verify();
+        }
+
+        @Test
+        void fromShouldThrowWhenUserAndPasswordAreNotGiven() {
+            PropertiesConfiguration configuration = new PropertiesConfiguration();
+
+            assertThatThrownBy(() -> RabbitMQConfiguration.ManagementCredentials.from(configuration))
+                .isInstanceOf(IllegalStateException.class)
+                .hasMessage("You need to specify the management.user property as username
of rabbitmq management admin account");
+        }
+
+        @Test
+        void fromShouldThrowWhenUserIsNotGiven() {
+            PropertiesConfiguration configuration = new PropertiesConfiguration();
+            String passwordString = "password";
+            configuration.addProperty("management.password", passwordString);
+
+            assertThatThrownBy(() -> RabbitMQConfiguration.ManagementCredentials.from(configuration))
+                .isInstanceOf(IllegalStateException.class)
+                .hasMessage("You need to specify the management.user property as username
of rabbitmq management admin account");
+        }
+
+        @Test
+        void fromShouldThrowWhenPasswordIsNotGiven() {
+            PropertiesConfiguration configuration = new PropertiesConfiguration();
+            String userString = "guest";
+            configuration.addProperty("management.user", userString);
+
+            assertThatThrownBy(() -> RabbitMQConfiguration.ManagementCredentials.from(configuration))
+                .isInstanceOf(IllegalStateException.class)
+                .hasMessage("You need to specify the management.password property as password
of rabbitmq management admin account");
+        }
+
+        @Test
+        void fromShouldReturnCorrespondingCredentialWhenGiven() {
+            PropertiesConfiguration configuration = new PropertiesConfiguration();
+            String userString = "guest";
+            configuration.addProperty("management.user", userString);
+            String passwordString = "password";
+            configuration.addProperty("management.password", passwordString);
+
+            RabbitMQConfiguration.ManagementCredentials credentialWithUserAndPassword = new
RabbitMQConfiguration.ManagementCredentials(
+                userString, passwordString.toCharArray());
+            assertThat(RabbitMQConfiguration.ManagementCredentials.from(configuration))
+                .isEqualTo(credentialWithUserAndPassword);
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/0ca09252/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQConnectionFactoryTest.java
----------------------------------------------------------------------
diff --git a/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQConnectionFactoryTest.java
b/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQConnectionFactoryTest.java
index 3d0c13f..489f557f 100644
--- a/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQConnectionFactoryTest.java
+++ b/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQConnectionFactoryTest.java
@@ -18,6 +18,7 @@
  ****************************************************************/
 package org.apache.james.backend.rabbitmq;
 
+import static org.apache.james.backend.rabbitmq.RabbitMQFixture.DEFAULT_MANAGEMENT_CREDENTIAL;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import java.net.URI;
@@ -43,6 +44,7 @@ class RabbitMQConnectionFactoryTest {
         RabbitMQConfiguration rabbitMQConfiguration = RabbitMQConfiguration.builder()
             .amqpUri(URI.create("amqp://james:james@rabbitmq_host:5672"))
             .managementUri(URI.create("http://james:james@rabbitmq_host:15672/api/"))
+            .managementCredentials(DEFAULT_MANAGEMENT_CREDENTIAL)
             .build();
 
         new RabbitMQConnectionFactory(rabbitMQConfiguration, new AsyncRetryExecutor(scheduledExecutor));
@@ -53,6 +55,7 @@ class RabbitMQConnectionFactoryTest {
         RabbitMQConfiguration rabbitMQConfiguration = RabbitMQConfiguration.builder()
             .amqpUri(URI.create("badprotocol://james:james@rabbitmq_host:5672"))
             .managementUri(URI.create("http://james:james@rabbitmq_host:15672/api/"))
+            .managementCredentials(DEFAULT_MANAGEMENT_CREDENTIAL)
             .build();
 
         assertThatThrownBy(() -> new RabbitMQConnectionFactory(rabbitMQConfiguration,
new AsyncRetryExecutor(scheduledExecutor)))
@@ -64,6 +67,7 @@ class RabbitMQConnectionFactoryTest {
         RabbitMQConfiguration rabbitMQConfiguration = RabbitMQConfiguration.builder()
                 .amqpUri(URI.create("amqp://james:james@rabbitmq_host:5672"))
                 .managementUri(URI.create("http://james:james@rabbitmq_host:15672/api/"))
+                .managementCredentials(DEFAULT_MANAGEMENT_CREDENTIAL)
                 .maxRetries(1)
                 .minDelay(1)
                 .build();

http://git-wip-us.apache.org/repos/asf/james-project/blob/0ca09252/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQFixture.java
----------------------------------------------------------------------
diff --git a/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQFixture.java
b/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQFixture.java
index f8d62c9..afa0cfe 100644
--- a/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQFixture.java
+++ b/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQFixture.java
@@ -39,6 +39,11 @@ public class RabbitMQFixture {
     public static final boolean AUTO_DELETE = true;
     public static final String WORK_QUEUE = "workQueue";
 
+    static final String DEFAULT_USER = "guest";
+    static final String DEFAULT_PASSWORD_STRING = "guest";
+    static final char[] DEFAULT_PASSWORD = DEFAULT_PASSWORD_STRING.toCharArray();
+    public static final RabbitMQConfiguration.ManagementCredentials DEFAULT_MANAGEMENT_CREDENTIAL
= new RabbitMQConfiguration.ManagementCredentials(DEFAULT_USER, DEFAULT_PASSWORD);
+
     public static Duration slowPacedPollInterval = ONE_HUNDRED_MILLISECONDS;
     public static ConditionFactory calmlyAwait = Awaitility.with()
         .pollInterval(slowPacedPollInterval)

http://git-wip-us.apache.org/repos/asf/james-project/blob/0ca09252/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQHealthCheckTest.java
----------------------------------------------------------------------
diff --git a/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQHealthCheckTest.java
b/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQHealthCheckTest.java
index 22a7d3c..bc25ebc 100644
--- a/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQHealthCheckTest.java
+++ b/backends-common/rabbitmq/src/test/java/org/apache/james/backend/rabbitmq/RabbitMQHealthCheckTest.java
@@ -19,9 +19,9 @@
 
 package org.apache.james.backend.rabbitmq;
 
+import static org.apache.james.backend.rabbitmq.RabbitMQFixture.DEFAULT_MANAGEMENT_CREDENTIAL;
 import static org.assertj.core.api.Assertions.assertThat;
 
-import java.net.URI;
 import java.util.concurrent.Executors;
 
 import org.apache.james.core.healthcheck.Result;
@@ -41,6 +41,7 @@ class RabbitMQHealthCheckTest {
         RabbitMQConfiguration rabbitMQConfiguration = RabbitMQConfiguration.builder()
             .amqpUri(rabbitMQ.amqpUri())
             .managementUri(rabbitMQ.managementUri())
+            .managementCredentials(DEFAULT_MANAGEMENT_CREDENTIAL)
             .build();
 
         RabbitMQConnectionFactory rabbitMQConnectionFactory = new RabbitMQConnectionFactory(rabbitMQConfiguration,

http://git-wip-us.apache.org/repos/asf/james-project/blob/0ca09252/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/RabbitMQManagementApi.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/RabbitMQManagementApi.java
b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/RabbitMQManagementApi.java
index 6822aab..356b918 100644
--- a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/RabbitMQManagementApi.java
+++ b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/RabbitMQManagementApi.java
@@ -19,14 +19,14 @@
 
 package org.apache.james.queue.rabbitmq;
 
-import java.net.MalformedURLException;
-import java.net.URI;
 import java.util.List;
 import java.util.stream.Stream;
 
+import org.apache.james.backend.rabbitmq.RabbitMQConfiguration;
 import org.apache.james.util.OptionalUtils;
 
 import com.fasterxml.jackson.annotation.JsonProperty;
+
 import feign.Feign;
 import feign.Logger;
 import feign.RequestLine;
@@ -51,14 +51,15 @@ class RabbitMQManagementApi {
 
     private final Api api;
 
-    RabbitMQManagementApi(URI rabbitManagementUri, RabbitMQManagementCredentials credentials)
throws MalformedURLException {
+    RabbitMQManagementApi(RabbitMQConfiguration configuration) {
+        RabbitMQConfiguration.ManagementCredentials credentials = configuration.getManagementCredentials();
         api = Feign.builder()
             .requestInterceptor(new BasicAuthRequestInterceptor(credentials.getUser(), new
String(credentials.getPassword())))
             .logger(new Slf4jLogger(RabbitMQManagementApi.class))
             .logLevel(Logger.Level.FULL)
             .encoder(new JacksonEncoder())
             .decoder(new JacksonDecoder())
-            .target(Api.class, rabbitManagementUri.toString());
+            .target(Api.class, configuration.getManagementUri().toString());
 
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/0ca09252/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/RabbitMQManagementCredentials.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/RabbitMQManagementCredentials.java
b/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/RabbitMQManagementCredentials.java
deleted file mode 100644
index 145767b..0000000
--- a/server/queue/queue-rabbitmq/src/main/java/org/apache/james/queue/rabbitmq/RabbitMQManagementCredentials.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.queue.rabbitmq;
-
-public class RabbitMQManagementCredentials {
-
-    private final String user;
-    private final char[] password;
-
-    RabbitMQManagementCredentials(String user, char[] password) {
-        this.user = user;
-        this.password = password;
-    }
-
-    public String getUser() {
-        return user;
-    }
-
-    public char[] getPassword() {
-        return password;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/0ca09252/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueConfigurationChangeTest.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueConfigurationChangeTest.java
b/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueConfigurationChangeTest.java
index c28b14c..ad43a5e 100644
--- a/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueConfigurationChangeTest.java
+++ b/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueConfigurationChangeTest.java
@@ -21,6 +21,7 @@ package org.apache.james.queue.rabbitmq;
 
 import static java.time.temporal.ChronoUnit.HOURS;
 import static java.time.temporal.ChronoUnit.MINUTES;
+import static org.apache.james.backend.rabbitmq.RabbitMQFixture.DEFAULT_MANAGEMENT_CREDENTIAL;
 import static org.apache.james.queue.api.Mails.defaultMail;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -103,6 +104,7 @@ class RabbitMQMailQueueConfigurationChangeTest {
         RabbitMQConfiguration rabbitMQConfiguration = RabbitMQConfiguration.builder()
             .amqpUri(rabbitMQ.amqpUri())
             .managementUri(rabbitMQ.managementUri())
+            .managementCredentials(DEFAULT_MANAGEMENT_CREDENTIAL)
             .build();
         clock = new UpdatableTickingClock(IN_SLICE_1);
         random = ThreadLocalRandom.current();
@@ -111,7 +113,7 @@ class RabbitMQMailQueueConfigurationChangeTest {
             new AsyncRetryExecutor(Executors.newSingleThreadScheduledExecutor()));
 
         rabbitClient = new RabbitClient(new RabbitChannelPool(rabbitMQConnectionFactory));
-        mqManagementApi = new RabbitMQManagementApi(rabbitMQ.managementUri(), new RabbitMQManagementCredentials("guest",
"guest".toCharArray()));
+        mqManagementApi = new RabbitMQManagementApi(rabbitMQConfiguration);
     }
 
     private RabbitMQMailQueue getRabbitMQMailQueue(CassandraCluster cassandra, CassandraMailQueueViewConfiguration
mailQueueViewConfiguration) throws Exception {

http://git-wip-us.apache.org/repos/asf/james-project/blob/0ca09252/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueTest.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueTest.java
b/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueTest.java
index 0ad51a7..109e47e 100644
--- a/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueTest.java
+++ b/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMQMailQueueTest.java
@@ -20,13 +20,12 @@
 package org.apache.james.queue.rabbitmq;
 
 import static java.time.temporal.ChronoUnit.HOURS;
+import static org.apache.james.backend.rabbitmq.RabbitMQFixture.DEFAULT_MANAGEMENT_CREDENTIAL;
 import static org.apache.james.queue.api.Mails.defaultMail;
 import static org.assertj.core.api.Assertions.assertThat;
 
-import java.time.Clock;
 import java.time.Duration;
 import java.time.Instant;
-import java.time.ZoneId;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ThreadLocalRandom;
 import java.util.function.Function;
@@ -35,7 +34,6 @@ import java.util.stream.Stream;
 
 import javax.mail.internet.MimeMessage;
 
-import org.apache.commons.lang3.NotImplementedException;
 import org.apache.james.backend.rabbitmq.DockerRabbitMQ;
 import org.apache.james.backend.rabbitmq.RabbitChannelPool;
 import org.apache.james.backend.rabbitmq.RabbitMQConfiguration;
@@ -124,6 +122,7 @@ public class RabbitMQMailQueueTest implements ManageableMailQueueContract,
MailQ
         RabbitMQConfiguration rabbitMQConfiguration = RabbitMQConfiguration.builder()
             .amqpUri(rabbitMQ.amqpUri())
             .managementUri(rabbitMQ.managementUri())
+            .managementCredentials(DEFAULT_MANAGEMENT_CREDENTIAL)
             .build();
 
         RabbitMQConnectionFactory rabbitMQConnectionFactory = new RabbitMQConnectionFactory(rabbitMQConfiguration,
@@ -137,7 +136,7 @@ public class RabbitMQMailQueueTest implements ManageableMailQueueContract,
MailQ
             BLOB_ID_FACTORY,
             mailQueueView,
             clock);
-        RabbitMQManagementApi mqManagementApi = new RabbitMQManagementApi(rabbitMQ.managementUri(),
new RabbitMQManagementCredentials("guest", "guest".toCharArray()));
+        RabbitMQManagementApi mqManagementApi = new RabbitMQManagementApi(rabbitMQConfiguration);
         mailQueueFactory = new RabbitMQMailQueueFactory(rabbitClient, mqManagementApi, factory);
         mailQueue = mailQueueFactory.createQueue(SPOOL);
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/0ca09252/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMqMailQueueFactoryTest.java
----------------------------------------------------------------------
diff --git a/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMqMailQueueFactoryTest.java
b/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMqMailQueueFactoryTest.java
index 990a259..aa2d553 100644
--- a/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMqMailQueueFactoryTest.java
+++ b/server/queue/queue-rabbitmq/src/test/java/org/apache/james/queue/rabbitmq/RabbitMqMailQueueFactoryTest.java
@@ -19,10 +19,10 @@
 
 package org.apache.james.queue.rabbitmq;
 
+import static org.apache.james.backend.rabbitmq.RabbitMQFixture.DEFAULT_MANAGEMENT_CREDENTIAL;
 import static org.mockito.Mockito.mock;
 
 import java.io.IOException;
-import java.net.URI;
 import java.net.URISyntaxException;
 import java.time.Clock;
 import java.util.concurrent.Executors;
@@ -30,16 +30,15 @@ import java.util.concurrent.TimeoutException;
 
 import javax.mail.internet.MimeMessage;
 
-import org.apache.http.client.utils.URIBuilder;
 import org.apache.james.backend.rabbitmq.DockerRabbitMQ;
 import org.apache.james.backend.rabbitmq.RabbitChannelPool;
 import org.apache.james.backend.rabbitmq.RabbitMQConfiguration;
 import org.apache.james.backend.rabbitmq.RabbitMQConnectionFactory;
 import org.apache.james.backend.rabbitmq.RabbitMQExtension;
 import org.apache.james.blob.api.HashBlobId;
-import org.apache.james.metrics.api.NoopMetricFactory;
 import org.apache.james.blob.api.Store;
 import org.apache.james.blob.mail.MimeMessagePartsId;
+import org.apache.james.metrics.api.NoopMetricFactory;
 import org.apache.james.queue.api.MailQueueFactory;
 import org.apache.james.queue.api.MailQueueFactoryContract;
 import org.apache.james.queue.rabbitmq.view.api.MailQueueView;
@@ -62,6 +61,7 @@ class RabbitMqMailQueueFactoryTest implements MailQueueFactoryContract<RabbitMQM
         RabbitMQConfiguration rabbitMQConfiguration = RabbitMQConfiguration.builder()
             .amqpUri(rabbitMQ.amqpUri())
             .managementUri(rabbitMQ.managementUri())
+            .managementCredentials(DEFAULT_MANAGEMENT_CREDENTIAL)
             .build();
 
         RabbitMQConnectionFactory rabbitMQConnectionFactory = new RabbitMQConnectionFactory(
@@ -70,7 +70,7 @@ class RabbitMqMailQueueFactoryTest implements MailQueueFactoryContract<RabbitMQM
 
         RabbitClient rabbitClient = new RabbitClient(new RabbitChannelPool(rabbitMQConnectionFactory));
         RabbitMQMailQueue.Factory factory = new RabbitMQMailQueue.Factory(new NoopMetricFactory(),
rabbitClient, mimeMessageStore, BLOB_ID_FACTORY, mailQueueView, Clock.systemUTC());
-        RabbitMQManagementApi mqManagementApi = new RabbitMQManagementApi(rabbitMQ.managementUri(),
new RabbitMQManagementCredentials("guest", "guest".toCharArray()));
+        RabbitMQManagementApi mqManagementApi = new RabbitMQManagementApi(rabbitMQConfiguration);
         mailQueueFactory = new RabbitMQMailQueueFactory(rabbitClient, mqManagementApi, factory);
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message