JAMES-2537 Introduce a mail queue 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/bb9c0a39 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/bb9c0a39 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/bb9c0a39 Branch: refs/heads/master Commit: bb9c0a391dd29bf83b4b1454cf0de3239c8ff7ad Parents: 9d08602 Author: Antoine Duprat <adup...@linagora.com> Authored: Tue Sep 4 15:18:39 2018 +0200 Committer: Antoine Duprat <adup...@linagora.com> Committed: Thu Sep 6 15:29:38 2018 +0200 ---------------------------------------------------------------------- backends-common/pom.xml | 1 + backends-common/rabbitmq/pom.xml | 69 ++++++++++++++++++ .../mailqueue/RabbitMQConfiguration.java | 71 +++++++++++++++++++ .../mailqueue/RabbitMQConfigurationTest.java | 73 ++++++++++++++++++++ core/pom.xml | 2 +- pom.xml | 5 ++ 6 files changed, 220 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/bb9c0a39/backends-common/pom.xml ---------------------------------------------------------------------- diff --git a/backends-common/pom.xml b/backends-common/pom.xml index f5a4fc2..777397a 100644 --- a/backends-common/pom.xml +++ b/backends-common/pom.xml @@ -37,6 +37,7 @@ <module>cassandra</module> <module>elasticsearch</module> <module>jpa</module> + <module>rabbitmq</module> </modules> </project> http://git-wip-us.apache.org/repos/asf/james-project/blob/bb9c0a39/backends-common/rabbitmq/pom.xml ---------------------------------------------------------------------- diff --git a/backends-common/rabbitmq/pom.xml b/backends-common/rabbitmq/pom.xml new file mode 100644 index 0000000..ee842f2 --- /dev/null +++ b/backends-common/rabbitmq/pom.xml @@ -0,0 +1,69 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.james</groupId> + <artifactId>james-backends-common</artifactId> + <version>3.2.0-SNAPSHOT</version> + </parent> + + <artifactId>apache-james-backends-rabbitmq</artifactId> + <name>Apache James RabbitMQ backend</name> + + <dependencies> + <dependency> + <groupId>com.google.guava</groupId> + <artifactId>guava</artifactId> + </dependency> + <dependency> + <groupId>commons-configuration</groupId> + <artifactId>commons-configuration</artifactId> + </dependency> + <dependency> + <groupId>nl.jqno.equalsverifier</groupId> + <artifactId>equalsverifier</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-engine</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.junit.platform</groupId> + <artifactId>junit-platform-launcher</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>jcl-over-slf4j</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + +</project> http://git-wip-us.apache.org/repos/asf/james-project/blob/bb9c0a39/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 new file mode 100644 index 0000000..98283e4 --- /dev/null +++ b/backends-common/rabbitmq/src/main/java/org/apache/james/backend/mailqueue/RabbitMQConfiguration.java @@ -0,0 +1,71 @@ +/**************************************************************** + * 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.backend.mailqueue; + +import java.net.URI; +import java.util.Objects; + +import org.apache.commons.configuration.PropertiesConfiguration; + +import com.google.common.base.Preconditions; +import com.google.common.base.Strings; + +public class RabbitMQConfiguration { + + private static final String URI_PROPERTY_NAME = "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); + } + + private static URI checkURI(String uri) { + try { + return URI.create(uri); + } catch (Exception e) { + throw new IllegalStateException("You need to specify a valid URI", e); + } + } + private final URI uri; + + private RabbitMQConfiguration(URI uri) { + this.uri = uri; + } + + public URI getUri() { + return uri; + } + + @Override + public final boolean equals(Object o) { + if (o instanceof RabbitMQConfiguration) { + RabbitMQConfiguration that = (RabbitMQConfiguration) o; + + return Objects.equals(this.uri, that.uri); + } + return false; + } + + @Override + public final int hashCode() { + return Objects.hash(uri); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/bb9c0a39/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 new file mode 100644 index 0000000..b5b9d6e --- /dev/null +++ b/backends-common/rabbitmq/src/test/java/org/apache/james/backend/mailqueue/RabbitMQConfigurationTest.java @@ -0,0 +1,73 @@ +/**************************************************************** + * 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.backend.mailqueue; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.apache.commons.configuration.PropertiesConfiguration; +import org.junit.jupiter.api.Test; + +import nl.jqno.equalsverifier.EqualsVerifier; + +public class RabbitMQConfigurationTest { + + @Test + public void shouldRespectBeanContract() { + EqualsVerifier.forClass(RabbitMQConfiguration.class).verify(); + } + + @Test + public void fromShouldThrowWhenURIIsNotInTheConfiguration() { + PropertiesConfiguration configuration = new PropertiesConfiguration(); + + assertThatThrownBy(() -> RabbitMQConfiguration.from(configuration)) + .isInstanceOf(IllegalStateException.class) + .hasMessage("You need to specify the URI of RabbitMQ"); + } + + @Test + public void fromShouldThrowWhenURIIsNull() { + PropertiesConfiguration configuration = new PropertiesConfiguration(); + configuration.addProperty("uri", null); + + assertThatThrownBy(() -> RabbitMQConfiguration.from(configuration)) + .isInstanceOf(IllegalStateException.class) + .hasMessage("You need to specify the URI of RabbitMQ"); + } + + @Test + public void fromShouldThrowWhenURIIsEmpty() { + PropertiesConfiguration configuration = new PropertiesConfiguration(); + configuration.addProperty("uri", ""); + + assertThatThrownBy(() -> RabbitMQConfiguration.from(configuration)) + .isInstanceOf(IllegalStateException.class) + .hasMessage("You need to specify the URI of RabbitMQ"); + } + + @Test + public void fromShouldThrowWhenURIIsInvalid() { + PropertiesConfiguration configuration = new PropertiesConfiguration(); + configuration.addProperty("uri", ":invalid"); + + assertThatThrownBy(() -> RabbitMQConfiguration.from(configuration)) + .isInstanceOf(IllegalStateException.class) + .hasMessage("You need to specify a valid URI"); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/bb9c0a39/core/pom.xml ---------------------------------------------------------------------- diff --git a/core/pom.xml b/core/pom.xml index ffda134..6c2ec01 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -88,4 +88,4 @@ </dependency> </dependencies> -</project> \ No newline at end of file +</project> http://git-wip-us.apache.org/repos/asf/james-project/blob/bb9c0a39/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 508db16..d90eb59 100644 --- a/pom.xml +++ b/pom.xml @@ -701,6 +701,11 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> + <artifactId>apache-james-backends-rabbitmq</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>${james.groupId}</groupId> <artifactId>apache-james-spamassassin</artifactId> <version>${project.version}</version> </dependency> --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org