getVhost() {
+ return vhost;
+ }
+
+ /**
+ * Returns the port number specified in the AMQP URI.
+ *
+ * If the port is not specified in the URI it falls back to RabbitMQ defaults:
+ *
+ * AMQP --> 6572
+ * AMQPS --> 6571
+ *
+ *
+ * @return the port number from the AMQP URI
+ */
+ public int getPort() {
+ return connectionFactory.getPort();
+ }
+
+ /**
+ * Converts the `AmqpUri` object into a `RabbitMQConfiguration` object, which can be used to
+ * configure the RabbitMQ client.
+ *
+ * @return a `RabbitMQConfiguration` object representing the AMQP URI
+ */
+ public RabbitMQConfiguration toRabbitMqConfiguration() {
+ return RabbitMQConfiguration.builder()
+ .amqpUri(uri)
+ .managementUri(uri)
+ .managementCredentials(userInfo.asManagementCredentials())
+ .vhost(getVhost())
+ .build();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (!(o instanceof AmqpUri amqpUri)) {
+ return false;
+ }
+ return Objects.equals(uri, amqpUri.uri) &&
+ Objects.equals(userInfo, amqpUri.userInfo) &&
+ Objects.equals(vhost, amqpUri.vhost);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(uri, userInfo, vhost);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .add("amqpURI", uri)
+ .add("userInfo", userInfo)
+ .add("vhost", vhost)
+ .toString();
+ }
+}
\ No newline at end of file
diff --git a/tmail-backend/tmail-third-party/openpaas/src/main/java/com/linagora/tmail/AmqpUserInfo.java b/tmail-backend/tmail-third-party/openpaas/src/main/java/com/linagora/tmail/AmqpUserInfo.java
new file mode 100644
index 0000000000..2aeb815d77
--- /dev/null
+++ b/tmail-backend/tmail-third-party/openpaas/src/main/java/com/linagora/tmail/AmqpUserInfo.java
@@ -0,0 +1,16 @@
+package com.linagora.tmail;
+
+import org.apache.james.backends.rabbitmq.RabbitMQConfiguration;
+
+import com.google.common.base.Preconditions;
+
+public record AmqpUserInfo(String username, String password) {
+ public AmqpUserInfo {
+ Preconditions.checkNotNull(username, "Amqp username is required.");
+ Preconditions.checkNotNull(password, "Amqp password is required.");
+ }
+
+ public RabbitMQConfiguration.ManagementCredentials asManagementCredentials() {
+ return new RabbitMQConfiguration.ManagementCredentials(username, password.toCharArray());
+ }
+}
diff --git a/tmail-backend/tmail-third-party/openpaas/src/main/java/com/linagora/tmail/OpenPaasConfiguration.java b/tmail-backend/tmail-third-party/openpaas/src/main/java/com/linagora/tmail/OpenPaasConfiguration.java
deleted file mode 100644
index 65565a1f73..0000000000
--- a/tmail-backend/tmail-third-party/openpaas/src/main/java/com/linagora/tmail/OpenPaasConfiguration.java
+++ /dev/null
@@ -1,6 +0,0 @@
-package com.linagora.tmail;
-
-import java.net.URL;
-
-public record OpenPaasConfiguration(URL restClientUrl, String restClientUser, String restClientPassword) {
-}
diff --git a/tmail-backend/tmail-third-party/openpaas/src/main/java/com/linagora/tmail/OpenPaasModule.java b/tmail-backend/tmail-third-party/openpaas/src/main/java/com/linagora/tmail/OpenPaasModule.java
new file mode 100644
index 0000000000..367b86289b
--- /dev/null
+++ b/tmail-backend/tmail-third-party/openpaas/src/main/java/com/linagora/tmail/OpenPaasModule.java
@@ -0,0 +1,100 @@
+package com.linagora.tmail;
+
+import java.io.FileNotFoundException;
+
+import jakarta.inject.Named;
+import jakarta.inject.Singleton;
+
+import org.apache.commons.configuration2.Configuration;
+import org.apache.commons.configuration2.ex.ConfigurationException;
+import org.apache.james.backends.rabbitmq.RabbitMQConfiguration;
+import org.apache.james.backends.rabbitmq.RabbitMQConnectionFactory;
+import org.apache.james.backends.rabbitmq.ReactorRabbitMQChannelPool;
+import org.apache.james.backends.rabbitmq.SimpleConnectionPool;
+import org.apache.james.metrics.api.GaugeRegistry;
+import org.apache.james.metrics.api.MetricFactory;
+import org.apache.james.utils.InitializationOperation;
+import org.apache.james.utils.InitilizationOperationBuilder;
+import org.apache.james.utils.PropertiesProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Provides;
+import com.google.inject.multibindings.ProvidesIntoSet;
+import com.linagora.tmail.api.OpenPaasRestClient;
+import com.linagora.tmail.configuration.OpenPaasConfiguration;
+import com.linagora.tmail.contact.OpenPaasContactsConsumer;
+
+public class OpenPaasModule extends AbstractModule {
+ private static final Logger LOGGER = LoggerFactory.getLogger(OpenPaasModule.class);
+ public static final String OPENPAAS_INJECTION_KEY = "openpaas";
+ public static final String OPENPAAS_CONFIGURATION_NAME = "openpaas";
+
+ @ProvidesIntoSet
+ public InitializationOperation initializeContactsConsumer(OpenPaasContactsConsumer instance) {
+ return InitilizationOperationBuilder
+ .forClass(OpenPaasContactsConsumer.class)
+ .init(instance::start);
+ }
+
+ @Provides
+ @Named(OPENPAAS_CONFIGURATION_NAME)
+ @Singleton
+ public Configuration providePropertiesConfiguration(PropertiesProvider propertiesProvider) throws ConfigurationException {
+ try {
+ return propertiesProvider.getConfiguration(OPENPAAS_CONFIGURATION_NAME);
+ } catch (FileNotFoundException e) {
+ LOGGER.error("Could not find configuration file '{}.properties'",
+ OPENPAAS_CONFIGURATION_NAME);
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Provides
+ @Singleton
+ public OpenPaasConfiguration provideOpenPaasConfiguration(@Named(OPENPAAS_CONFIGURATION_NAME) Configuration propertiesConfiguration) {
+ return OpenPaasConfiguration.from(propertiesConfiguration);
+ }
+
+ @Provides
+ public OpenPaasRestClient provideOpenPaasRestCLient(OpenPaasConfiguration openPaasConfiguration) {
+ return new OpenPaasRestClient(openPaasConfiguration);
+ }
+
+ @Provides
+ @Named(OPENPAAS_INJECTION_KEY)
+ @Singleton
+ public RabbitMQConfiguration provideRabbitMQConfiguration(OpenPaasConfiguration openPaasConfiguration) {
+ return openPaasConfiguration.rabbitMqUri().toRabbitMqConfiguration();
+ }
+
+ @Provides
+ @Named(OPENPAAS_INJECTION_KEY)
+ @Singleton
+ public SimpleConnectionPool provideSimpleConnectionPool(@Named(OPENPAAS_INJECTION_KEY) RabbitMQConfiguration rabbitMQConfiguration) {
+ RabbitMQConnectionFactory rabbitMQConnectionFactory = new RabbitMQConnectionFactory(rabbitMQConfiguration);
+ try {
+ return new SimpleConnectionPool(rabbitMQConnectionFactory, SimpleConnectionPool.Configuration.DEFAULT);
+ } catch (Exception e) {
+ LOGGER.info("Error while retrieving SimpleConnectionPool.Configuration, falling back to defaults.", e);
+ return new SimpleConnectionPool(rabbitMQConnectionFactory, SimpleConnectionPool.Configuration.DEFAULT);
+ }
+ }
+
+ @Provides
+ @Named(OPENPAAS_INJECTION_KEY)
+ @Singleton
+ public ReactorRabbitMQChannelPool provideReactorRabbitMQChannelPool(
+ @Named(OPENPAAS_INJECTION_KEY) SimpleConnectionPool simpleConnectionPool,
+ MetricFactory metricFactory, GaugeRegistry gaugeRegistry) {
+
+ ReactorRabbitMQChannelPool channelPool = new ReactorRabbitMQChannelPool(
+ simpleConnectionPool.getResilientConnection(),
+ ReactorRabbitMQChannelPool.Configuration.DEFAULT,
+ metricFactory,
+ gaugeRegistry);
+ channelPool.start();
+ return channelPool;
+ }
+}
diff --git a/tmail-backend/tmail-third-party/openpaas/src/main/java/com/linagora/tmail/OpenPaasModuleChooserConfiguration.java b/tmail-backend/tmail-third-party/openpaas/src/main/java/com/linagora/tmail/OpenPaasModuleChooserConfiguration.java
new file mode 100644
index 0000000000..6dca6a4ccf
--- /dev/null
+++ b/tmail-backend/tmail-third-party/openpaas/src/main/java/com/linagora/tmail/OpenPaasModuleChooserConfiguration.java
@@ -0,0 +1,26 @@
+package com.linagora.tmail;
+
+import java.io.FileNotFoundException;
+
+import org.apache.commons.configuration2.ex.ConfigurationException;
+import org.apache.james.utils.PropertiesProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public record OpenPaasModuleChooserConfiguration(boolean enabled) {
+ private static final Logger LOGGER = LoggerFactory.getLogger(OpenPaasModuleChooserConfiguration.class);
+ public static final OpenPaasModuleChooserConfiguration ENABLED = new OpenPaasModuleChooserConfiguration(true);
+ public static final OpenPaasModuleChooserConfiguration DISABLED = new OpenPaasModuleChooserConfiguration(false);
+
+ public static OpenPaasModuleChooserConfiguration parse(PropertiesProvider propertiesProvider) throws
+ ConfigurationException {
+ try {
+ propertiesProvider.getConfiguration("openpaas");
+ LOGGER.info("OpenPaas module is turned on.");
+ return ENABLED;
+ } catch (FileNotFoundException e) {
+ LOGGER.info("OpenPaas module is turned off.");
+ return DISABLED;
+ }
+ }
+}
diff --git a/tmail-backend/tmail-third-party/openpaas/src/main/java/com/linagora/tmail/api/OpenPaasRestClient.java b/tmail-backend/tmail-third-party/openpaas/src/main/java/com/linagora/tmail/api/OpenPaasRestClient.java
index 02f70a7e61..f6eb155cf1 100644
--- a/tmail-backend/tmail-third-party/openpaas/src/main/java/com/linagora/tmail/api/OpenPaasRestClient.java
+++ b/tmail-backend/tmail-third-party/openpaas/src/main/java/com/linagora/tmail/api/OpenPaasRestClient.java
@@ -1,6 +1,6 @@
package com.linagora.tmail.api;
-import java.net.URL;
+import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
@@ -13,7 +13,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.linagora.tmail.HttpUtils;
-import com.linagora.tmail.OpenPaasConfiguration;
+import com.linagora.tmail.configuration.OpenPaasConfiguration;
import reactor.core.publisher.Mono;
import reactor.netty.ByteBufMono;
@@ -29,9 +29,10 @@ public class OpenPaasRestClient {
private final ObjectMapper deserializer = new ObjectMapper();
public OpenPaasRestClient(OpenPaasConfiguration openPaasConfiguration) {
- URL apiUrl = openPaasConfiguration.restClientUrl();
- String user = openPaasConfiguration.restClientUser();
- String password = openPaasConfiguration.restClientPassword();
+ URI apiUrl = openPaasConfiguration.apirUri();
+ String user = openPaasConfiguration.adminUsername();
+ String password = openPaasConfiguration.adminPassword();
+
this.client = HttpClient.create()
.baseUrl(apiUrl.toString())
.headers(headers -> headers.add(AUTHORIZATION_HEADER, HttpUtils.createBasicAuthenticationToken(user, password)))
diff --git a/tmail-backend/tmail-third-party/openpaas/src/main/java/com/linagora/tmail/configuration/OpenPaasConfiguration.java b/tmail-backend/tmail-third-party/openpaas/src/main/java/com/linagora/tmail/configuration/OpenPaasConfiguration.java
new file mode 100644
index 0000000000..b10dd7ff70
--- /dev/null
+++ b/tmail-backend/tmail-third-party/openpaas/src/main/java/com/linagora/tmail/configuration/OpenPaasConfiguration.java
@@ -0,0 +1,89 @@
+package com.linagora.tmail.configuration;
+
+import java.net.MalformedURLException;
+import java.net.URI;
+
+import org.apache.commons.configuration2.Configuration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.linagora.tmail.AmqpUri;
+
+import spark.utils.StringUtils;
+
+public record OpenPaasConfiguration(
+ AmqpUri rabbitMqUri,
+ URI apirUri,
+ String adminUsername,
+ String adminPassword) {
+ private static final Logger LOGGER = LoggerFactory.getLogger(OpenPaasConfiguration.class);
+ private static final String RABBITMQ_URI_PROPERTY = "rabbitmq.uri";
+ private static final String OPENPAAS_API_URI = "openpaas.api.uri";
+ private static final String OPENPAAS_ADMIN_USER_PROPERTY = "openpaas.admin.user";
+ private static final String OPENPAAS_ADMIN_PASSWORD_PROPERTY = "openpaas.admin.password";
+
+ public static OpenPaasConfiguration from(Configuration configuration) {
+ AmqpUri rabbitMqUri = readRabbitMqUri(configuration);
+ URI openPaasApiUri = readApiUri(configuration);
+ String adminUser = readAdminUsername(configuration);
+ String adminPassword = readAdminPassword(configuration);
+
+ return new OpenPaasConfiguration(rabbitMqUri, openPaasApiUri, adminUser, adminPassword);
+ }
+
+ private static AmqpUri readRabbitMqUri(Configuration configuration) {
+ String rabbitMqUri = configuration.getString(RABBITMQ_URI_PROPERTY);
+ if (StringUtils.isBlank(rabbitMqUri)) {
+ throw new IllegalStateException("RabbitMQ URI not defined in openpaas.properties.");
+ }
+
+ try {
+ return AmqpUri.from(URI.create(rabbitMqUri));
+ } catch (IllegalArgumentException e) {
+ throw new IllegalStateException("Invalid RabbitMQ URI in openpaas.properties.");
+ }
+ }
+
+ private static URI readApiUri(Configuration configuration) {
+ String openPaasApiUri = configuration.getString(OPENPAAS_API_URI);
+ if (StringUtils.isBlank(openPaasApiUri)) {
+ throw new IllegalStateException("OpenPaas API URI not specified.");
+ }
+
+ try {
+ return validateURI(URI.create(openPaasApiUri));
+ } catch (Exception e) {
+ throw new IllegalStateException("Invalid OpenPaas API URI in openpaas.properties.");
+ }
+ }
+
+ private static URI validateURI(URI uri) {
+ try {
+ // Otherwise, BAD_URI would be considered a valid URI.
+ uri.toURL();
+ return uri;
+ } catch (MalformedURLException | IllegalArgumentException e) {
+ throw new IllegalArgumentException("Bad URI!", e);
+ }
+ }
+
+ private static String readAdminUsername(Configuration configuration) {
+ String openPaasAdminUser = configuration.getString(OPENPAAS_ADMIN_USER_PROPERTY);
+
+ if (StringUtils.isBlank(openPaasAdminUser)) {
+ throw new IllegalStateException("OpenPaas admin user not specified.");
+ }
+
+ return openPaasAdminUser;
+ }
+
+ private static String readAdminPassword(Configuration configuration) {
+ String openPaasAdminPassword = configuration.getString(OPENPAAS_ADMIN_PASSWORD_PROPERTY);
+ if (StringUtils.isBlank(openPaasAdminPassword)) {
+ throw new IllegalStateException("OpenPaas admin password not specified.");
+ }
+
+ return openPaasAdminPassword;
+ }
+
+}
diff --git a/tmail-backend/tmail-third-party/openpaas/src/main/java/com/linagora/tmail/contact/OpenPaasContactsConsumer.java b/tmail-backend/tmail-third-party/openpaas/src/main/java/com/linagora/tmail/contact/OpenPaasContactsConsumer.java
index b569979703..c25b769855 100644
--- a/tmail-backend/tmail-third-party/openpaas/src/main/java/com/linagora/tmail/contact/OpenPaasContactsConsumer.java
+++ b/tmail-backend/tmail-third-party/openpaas/src/main/java/com/linagora/tmail/contact/OpenPaasContactsConsumer.java
@@ -1,5 +1,6 @@
package com.linagora.tmail.contact;
+import static com.linagora.tmail.OpenPaasModule.OPENPAAS_INJECTION_KEY;
import static org.apache.james.backends.rabbitmq.Constants.DURABLE;
import static org.apache.james.backends.rabbitmq.Constants.EMPTY_ROUTING_KEY;
@@ -7,6 +8,7 @@
import java.util.Optional;
import jakarta.inject.Inject;
+import jakarta.inject.Named;
import org.apache.james.backends.rabbitmq.RabbitMQConfiguration;
import org.apache.james.backends.rabbitmq.ReactorRabbitMQChannelPool;
@@ -53,8 +55,8 @@ public class OpenPaasContactsConsumer implements Startable, Closeable {
private Disposable consumeContactsDisposable;
@Inject
- public OpenPaasContactsConsumer(ReactorRabbitMQChannelPool channelPool,
- RabbitMQConfiguration commonRabbitMQConfiguration,
+ public OpenPaasContactsConsumer(@Named(OPENPAAS_INJECTION_KEY) ReactorRabbitMQChannelPool channelPool,
+ @Named(OPENPAAS_INJECTION_KEY) RabbitMQConfiguration commonRabbitMQConfiguration,
EmailAddressContactSearchEngine contactSearchEngine,
OpenPaasRestClient openPaasRestClient) {
this.receiverProvider = channelPool::createReceiver;
diff --git a/tmail-backend/tmail-third-party/openpaas/src/test/java/com/linagora/tmail/AmqpUriTest.java b/tmail-backend/tmail-third-party/openpaas/src/test/java/com/linagora/tmail/AmqpUriTest.java
new file mode 100644
index 0000000000..7f64e80fe0
--- /dev/null
+++ b/tmail-backend/tmail-third-party/openpaas/src/test/java/com/linagora/tmail/AmqpUriTest.java
@@ -0,0 +1,108 @@
+package com.linagora.tmail;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatCode;
+
+import java.util.stream.Stream;
+
+import nl.jqno.equalsverifier.EqualsVerifier;
+
+import org.assertj.core.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import com.rabbitmq.client.ConnectionFactory;
+
+class AmqpUriTest {
+ private static Stream goodAmqpURIs() {
+ return Stream.of(
+ Arguments.of("amqp://guest:guest@localhost:5672/"),
+ Arguments.of("amqp://user:password@host:port/vhost"),
+ Arguments.of("amqps://user:password@securehost:5671/securevhost"), // Using AMQPS for secure connection
+ Arguments.of("amqp://@localhost:5672/"),
+ Arguments.of("amqp://:password@host"),
+ Arguments.of("amqp://user@host"));
+ }
+
+ private static Stream badAmqpURIs() {
+ return Stream.of(
+ Arguments.of("http://guest:guest@localhost:5672/"), // Wrong protocol
+ Arguments.of("amqp://user:pass@host:5672/extra/path"), // Extra path element
+ Arguments.of("BAD_URI")); // Just bad
+ }
+
+ @ParameterizedTest
+ @MethodSource("goodAmqpURIs")
+ void testGoodAmpqUriString(String amqpUri) {
+ assertThatCode(() -> AmqpUri.from(amqpUri))
+ .doesNotThrowAnyException();
+ }
+
+ @ParameterizedTest
+ @MethodSource("badAmqpURIs")
+ void testBadAmpqUriString(String amqpUri) {
+ Assertions.assertThatThrownBy(() -> AmqpUri.from(amqpUri));
+ }
+
+ @Test
+ void shouldRespectBeanContract() throws Exception {
+ ConnectionFactory red = new ConnectionFactory();
+ ConnectionFactory blue = new ConnectionFactory();
+
+ red.setUri("amqp://username@rabbitmq.com");
+ blue.setUri("amqp://rabbitmq_test.com");
+
+ EqualsVerifier
+ .forClass(AmqpUri.class)
+ .withIgnoredFields("connectionFactory")
+ .withPrefabValues(ConnectionFactory.class, red, blue)
+ .verify();
+ }
+
+ @Test
+ void shouldUseEmptyUsernameWhenUsernameIsMissing() {
+ AmqpUri uri = AmqpUri.from("amqp://:password@rabbitmq.com/vhost");
+
+ assertThat(uri.getUserInfo().username()).isEqualTo("");
+ assertThat(uri.getUserInfo().password()).isEqualTo("password");
+ }
+
+ @Test
+ void shouldUseTheDefaultPasswordWhenPasswordIsMissing() {
+ AmqpUri uri = AmqpUri.from("amqp://user@rabbitmq.com/vhost");
+
+ assertThat(uri.getUserInfo().username()).isEqualTo("user");
+ assertThat(uri.getUserInfo().password()).isEqualTo("guest");
+ }
+
+ @Test
+ void shouldUseTheDefaultCredentialsWhenCredentialsIsMissing() {
+ AmqpUri uri = AmqpUri.from("amqp://rabbitmq.com/vhost");
+
+ assertThat(uri.getUserInfo().username()).isEqualTo("guest");
+ assertThat(uri.getUserInfo().password()).isEqualTo("guest");
+ }
+
+ @Test
+ void shouldUsePort5672WhenAmqpIsUsedAndPortIsMissing() {
+ AmqpUri uri = AmqpUri.from("amqp://user:pass@rabbitmq.com/vhost");
+
+ assertThat(uri.getPort()).isEqualTo(5672);
+ }
+
+ @Test
+ void shouldUseSpecificPortWhenSpecified() {
+ AmqpUri uri = AmqpUri.from("amqp://user:password@rabbitmq.com:1000/vhost");
+
+ assertThat(uri.getPort()).isEqualTo(1000);
+ }
+
+ @Test
+ void shouldUsePort5671WhenAmqpOverSslIsUsedAndPortIsMissing() {
+ AmqpUri uri = AmqpUri.from("amqps://user:pass@rabbitmq.com/vhost");
+
+ assertThat(uri.getPort()).isEqualTo(5671);
+ }
+}
\ No newline at end of file
diff --git a/tmail-backend/tmail-third-party/openpaas/src/test/java/com/linagora/tmail/configuration/OpenPaasConfigurationTest.java b/tmail-backend/tmail-third-party/openpaas/src/test/java/com/linagora/tmail/configuration/OpenPaasConfigurationTest.java
new file mode 100644
index 0000000000..ddae575a27
--- /dev/null
+++ b/tmail-backend/tmail-third-party/openpaas/src/test/java/com/linagora/tmail/configuration/OpenPaasConfigurationTest.java
@@ -0,0 +1,170 @@
+package com.linagora.tmail.configuration;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.net.URI;
+
+import org.apache.commons.configuration2.PropertiesConfiguration;
+import org.junit.jupiter.api.Test;
+
+import com.linagora.tmail.AmqpUri;
+
+import nl.jqno.equalsverifier.EqualsVerifier;
+
+class OpenPaasConfigurationTest {
+
+ @Test
+ void shouldRespectBeanContract() {
+ AmqpUri red = AmqpUri.from("amqp://rabbitmq.com");
+ AmqpUri blue = AmqpUri.from("amqp://rabbitmq_test.com");
+ EqualsVerifier.forClass(OpenPaasConfiguration.class)
+ .withPrefabValues(AmqpUri.class, red, blue)
+ .verify();
+ }
+
+ @Test
+ void fromShouldReturnTheConfigurationWhenAllParametersAreGiven() {
+ PropertiesConfiguration configuration = new PropertiesConfiguration();
+ configuration.addProperty("rabbitmq.uri", "amqp://james:james@rabbitmqhost:5672");
+ configuration.addProperty("openpaas.api.uri", "http://localhost:8080");
+ configuration.addProperty("openpaas.admin.user", "jhon_doe");
+ configuration.addProperty("openpaas.admin.password", "123");
+
+ OpenPaasConfiguration expected = new OpenPaasConfiguration(
+ AmqpUri.from("amqp://james:james@rabbitmqhost:5672"),
+ URI.create("http://localhost:8080"),
+ "jhon_doe",
+ "123"
+ );
+
+ assertThat(OpenPaasConfiguration.from(configuration))
+ .isEqualTo(expected);
+ }
+
+ @Test
+ void fromShouldThrowWhenOpenPaasApiUriNotConfigured() {
+ PropertiesConfiguration configuration = new PropertiesConfiguration();
+ configuration.addProperty("rabbitmq.uri", "amqp://james:james@rabbitmqhost:5672");
+ configuration.addProperty("openpaas.admin.user", "jhon_doe");
+ configuration.addProperty("openpaas.admin.password", "123");
+
+ assertThatThrownBy(() -> OpenPaasConfiguration.from(configuration))
+ .isInstanceOf(IllegalStateException.class)
+ .hasMessage("OpenPaas API URI not specified.");
+ }
+
+ @Test
+ void fromShouldThrowWhenOpenPaasApiUriIsBlank() {
+ PropertiesConfiguration configuration = new PropertiesConfiguration();
+ configuration.addProperty("rabbitmq.uri", "amqp://james:james@rabbitmqhost:5672");
+ configuration.addProperty("openpaas.admin.user", "jhon_doe");
+ configuration.addProperty("openpaas.api.uri", " ");
+ configuration.addProperty("openpaas.admin.password", "123");
+
+ assertThatThrownBy(() -> OpenPaasConfiguration.from(configuration))
+ .isInstanceOf(IllegalStateException.class)
+ .hasMessage("OpenPaas API URI not specified.");
+ }
+
+ @Test
+ void fromShouldThrowWhenOpenPaasApiUriIsInvalid() {
+ PropertiesConfiguration configuration = new PropertiesConfiguration();
+ configuration.addProperty("rabbitmq.uri", "amqp://james:james@rabbitmqhost:5672");
+ configuration.addProperty("openpaas.admin.user", "jhon_doe");
+ configuration.addProperty("openpaas.api.uri", "BAD_URI");
+ configuration.addProperty("openpaas.admin.password", "123");
+
+ assertThatThrownBy(() -> OpenPaasConfiguration.from(configuration))
+ .isInstanceOf(IllegalStateException.class)
+ .hasMessage("Invalid OpenPaas API URI in openpaas.properties.");
+ }
+
+ @Test
+ void fromShouldThrowWhenOpenPaasAdminUserNotConfigured() {
+ PropertiesConfiguration configuration = new PropertiesConfiguration();
+ configuration.addProperty("rabbitmq.uri", "amqp://james:james@rabbitmqhost:5672");
+ configuration.addProperty("openpaas.api.uri", "http://localhost:8080");
+ configuration.addProperty("openpaas.admin.password", "123");
+
+ assertThatThrownBy(() -> OpenPaasConfiguration.from(configuration))
+ .isInstanceOf(IllegalStateException.class)
+ .hasMessage("OpenPaas admin user not specified.");
+ }
+
+ @Test
+ void fromShouldThrowWhenOpenPaasAdminUserIsBlank() {
+ PropertiesConfiguration configuration = new PropertiesConfiguration();
+ configuration.addProperty("rabbitmq.uri", "amqp://james:james@rabbitmqhost:5672");
+ configuration.addProperty("openpaas.api.uri", "http://localhost:8080");
+ configuration.addProperty("openpaas.admin.user", " ");
+ configuration.addProperty("openpaas.admin.password", "123");
+
+ assertThatThrownBy(() -> OpenPaasConfiguration.from(configuration))
+ .isInstanceOf(IllegalStateException.class)
+ .hasMessage("OpenPaas admin user not specified.");
+ }
+
+ @Test
+ void fromShouldThrowWhenOpenPaasAdminPasswordNotConfigured() {
+ PropertiesConfiguration configuration = new PropertiesConfiguration();
+ configuration.addProperty("rabbitmq.uri", "amqp://james:james@rabbitmqhost:5672");
+ configuration.addProperty("openpaas.api.uri", "http://localhost:8080");
+ configuration.addProperty("openpaas.admin.user", "jhon_doe");
+
+ assertThatThrownBy(() -> OpenPaasConfiguration.from(configuration))
+ .isInstanceOf(IllegalStateException.class)
+ .hasMessage("OpenPaas admin password not specified.");
+ }
+
+ @Test
+ void fromShouldThrowWhenOpenPaasAdminPasswordIsBlank() {
+ PropertiesConfiguration configuration = new PropertiesConfiguration();
+ configuration.addProperty("rabbitmq.uri", "amqp://james:james@rabbitmqhost:5672");
+ configuration.addProperty("openpaas.api.uri", "http://localhost:8080");
+ configuration.addProperty("openpaas.admin.user", "jhon_doe");
+ configuration.addProperty("openpaas.admin.password", " ");
+
+ assertThatThrownBy(() -> OpenPaasConfiguration.from(configuration))
+ .isInstanceOf(IllegalStateException.class)
+ .hasMessage("OpenPaas admin password not specified.");
+ }
+
+ @Test
+ void fromShouldCrashWhenRabbitMqURINotConfigured() {
+ PropertiesConfiguration configuration = new PropertiesConfiguration();
+ configuration.addProperty("openpaas.api.uri", "http://localhost:8080");
+ configuration.addProperty("openpaas.admin.user", "jhon_doe");
+ configuration.addProperty("openpaas.admin.password", "123");
+
+ assertThatThrownBy(() -> OpenPaasConfiguration.from(configuration))
+ .isInstanceOf(IllegalStateException.class)
+ .hasMessage("RabbitMQ URI not defined in openpaas.properties.");
+ }
+
+ @Test
+ void fromShouldCrashWhenRabbitMqUriIsBlank() {
+ PropertiesConfiguration configuration = new PropertiesConfiguration();
+ configuration.addProperty("rabbitmq.uri", " ");
+ configuration.addProperty("openpaas.api.uri", "http://localhost:8080");
+ configuration.addProperty("openpaas.admin.user", "jhon_doe");
+ configuration.addProperty("openpaas.admin.password", "123");
+
+ assertThatThrownBy(() -> OpenPaasConfiguration.from(configuration))
+ .isInstanceOf(IllegalStateException.class)
+ .hasMessage("RabbitMQ URI not defined in openpaas.properties.");
+ }
+
+ @Test
+ void fromShouldThrowWhenConfiguredRabbitMqURIisInvalid() {
+ PropertiesConfiguration configuration = new PropertiesConfiguration();
+ configuration.addProperty("rabbitmq.uri", "BAD_SCHEME://james:james@rabbitmqhost:5672");
+ configuration.addProperty("openpaas.api.uri", "http://localhost:8080");
+ configuration.addProperty("openpaas.admin.user", "jhon_doe");
+ configuration.addProperty("openpaas.admin.password", "123");
+
+ assertThatThrownBy(() -> OpenPaasConfiguration.from(configuration))
+ .isInstanceOf(IllegalStateException.class)
+ .hasMessage("Invalid RabbitMQ URI in openpaas.properties.");
+ }
+}
\ No newline at end of file
diff --git a/tmail-backend/tmail-third-party/openpaas/src/test/java/com/linagora/tmail/contact/OpenPaasContactsConsumerTest.java b/tmail-backend/tmail-third-party/openpaas/src/test/java/com/linagora/tmail/contact/OpenPaasContactsConsumerTest.java
index 42e5971df6..134b3235f3 100644
--- a/tmail-backend/tmail-third-party/openpaas/src/test/java/com/linagora/tmail/contact/OpenPaasContactsConsumerTest.java
+++ b/tmail-backend/tmail-third-party/openpaas/src/test/java/com/linagora/tmail/contact/OpenPaasContactsConsumerTest.java
@@ -27,7 +27,8 @@
import jakarta.mail.internet.AddressException;
import com.github.fge.lambdas.Throwing;
-import com.linagora.tmail.OpenPaasConfiguration;
+import com.linagora.tmail.AmqpUri;
+import com.linagora.tmail.configuration.OpenPaasConfiguration;
import com.linagora.tmail.api.OpenPaasRestClient;
import com.linagora.tmail.api.OpenPaasServerExtension;
import com.linagora.tmail.james.jmap.contact.ContactFields;
@@ -51,7 +52,8 @@ class OpenPaasContactsConsumerTest {
void setup() throws URISyntaxException {
OpenPaasRestClient restClient = new OpenPaasRestClient(
new OpenPaasConfiguration(
- openPaasServerExtension.getBaseUrl(),
+ AmqpUri.from(rabbitMQExtension.getRabbitMQ().amqpUri()),
+ openPaasServerExtension.getBaseUrl().toURI(),
OpenPaasServerExtension.GOOD_USER(),
OpenPaasServerExtension.GOOD_PASSWORD()));
searchEngine = new InMemoryEmailAddressContactSearchEngine();
diff --git a/tmail-backend/tmail-third-party/openpaas/src/test/scala/com/linagora/tmail/api/OpenPaasRestClientTest.java b/tmail-backend/tmail-third-party/openpaas/src/test/scala/com/linagora/tmail/api/OpenPaasRestClientTest.java
index 68f0a91748..b8ca7c7006 100644
--- a/tmail-backend/tmail-third-party/openpaas/src/test/scala/com/linagora/tmail/api/OpenPaasRestClientTest.java
+++ b/tmail-backend/tmail-third-party/openpaas/src/test/scala/com/linagora/tmail/api/OpenPaasRestClientTest.java
@@ -1,5 +1,7 @@
package com.linagora.tmail.api;
+import java.net.URISyntaxException;
+import java.util.Optional;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
@@ -10,7 +12,8 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
-import com.linagora.tmail.OpenPaasConfiguration;
+import com.linagora.tmail.AmqpUri;
+import com.linagora.tmail.configuration.OpenPaasConfiguration;
public class OpenPaasRestClientTest {
public static final String BAD_USER_ID = "BAD_ID";
@@ -20,9 +23,10 @@ public class OpenPaasRestClientTest {
OpenPaasRestClient restClient;
@BeforeEach
- void setup() {
+ void setup() throws URISyntaxException {
OpenPaasConfiguration openPaasConfig = new OpenPaasConfiguration(
- openPaasServerExtension.getBaseUrl(),
+ AmqpUri.from("amqp://not_important.com"),
+ openPaasServerExtension.getBaseUrl().toURI(),
OpenPaasServerExtension.GOOD_USER(),
OpenPaasServerExtension.GOOD_PASSWORD());
@@ -42,9 +46,10 @@ void shouldReturnEmptyMonoWhenUserWithIdNotFound() {
}
@Test
- void shouldThrowExceptionOnErrorStatusCode() {
+ void shouldThrowExceptionOnErrorStatusCode() throws URISyntaxException {
OpenPaasConfiguration openPaasConfig = new OpenPaasConfiguration(
- openPaasServerExtension.getBaseUrl(),
+ AmqpUri.from("amqp://not_important.com"),
+ openPaasServerExtension.getBaseUrl().toURI(),
OpenPaasServerExtension.BAD_USER(),
OpenPaasServerExtension.BAD_PASSWORD());