You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ad...@apache.org on 2019/04/02 12:09:46 UTC
[james-project] 11/13: JAMES-2671 use TestRules as they are
intended to be used
This is an automated email from the ASF dual-hosted git repository.
aduprat pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 16a48774b3d23e924c67fdb0c7df9008530f676d
Author: Matthieu Baechler <ma...@apache.org>
AuthorDate: Thu Mar 21 14:58:58 2019 +0100
JAMES-2671 use TestRules as they are intended to be used
---
.../mpt/smtp/AwsS3RabbitMQForwardSmtpTest.java | 9 ++++-
.../smtp/AwsS3RabbitMQSmtpStarttlsCommandTest.java | 10 +++++-
.../CassandraRabbitMQAwsS3SmtpTestRuleFactory.java | 9 ++---
.../james/blob/objectstorage/DockerAwsS3Rule.java | 40 ----------------------
.../objectstorage/aws/s3/DockerAwsS3TestRule.java | 22 ++++++------
.../james/CassandraRabbitMQAwsS3JmapTestRule.java | 7 ++--
.../james/modules/AwsS3BlobStoreExtension.java | 16 ++++-----
.../james/modules/TestAwsS3BlobStoreModule.java | 4 +--
.../rabbitmq/cucumber/RabbitMQAwsS3Stepdefs.java | 4 +--
9 files changed, 50 insertions(+), 71 deletions(-)
diff --git a/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/java/org/apache/james/mpt/smtp/AwsS3RabbitMQForwardSmtpTest.java b/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/java/org/apache/james/mpt/smtp/AwsS3RabbitMQForwardSmtpTest.java
index 368e031..eebe8df 100644
--- a/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/java/org/apache/james/mpt/smtp/AwsS3RabbitMQForwardSmtpTest.java
+++ b/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/java/org/apache/james/mpt/smtp/AwsS3RabbitMQForwardSmtpTest.java
@@ -25,13 +25,20 @@ import org.apache.james.backends.cassandra.DockerCassandraRule;
import org.apache.james.modules.objectstorage.aws.s3.DockerAwsS3TestRule;
import org.junit.ClassRule;
import org.junit.Rule;
+import org.junit.rules.RuleChain;
+import org.junit.rules.TestRule;
public class AwsS3RabbitMQForwardSmtpTest extends ForwardSmtpTest {
@ClassRule public static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+ private DockerAwsS3TestRule dockerAwsS3TestRule = new DockerAwsS3TestRule();
+
+ private SmtpTestRule cassandraRabbitMQAwsS3SmtpTestRule =
+ CassandraRabbitMQAwsS3SmtpTestRuleFactory.create(SMTP_GLOBAL_SERVER, cassandraServer.getHost(), dockerAwsS3TestRule);
+
@Rule
- public SmtpTestRule cassandraRabbitMQAwsS3SmtpTestRule = CassandraRabbitMQAwsS3SmtpTestRuleFactory.create(SMTP_GLOBAL_SERVER, cassandraServer.getHost());
+ public TestRule composedRule = RuleChain.outerRule(dockerAwsS3TestRule).around(cassandraRabbitMQAwsS3SmtpTestRule);
@Override
protected SmtpHostSystem createSmtpHostSystem() {
diff --git a/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/java/org/apache/james/mpt/smtp/AwsS3RabbitMQSmtpStarttlsCommandTest.java b/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/java/org/apache/james/mpt/smtp/AwsS3RabbitMQSmtpStarttlsCommandTest.java
index 882076b..262c9b3 100644
--- a/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/java/org/apache/james/mpt/smtp/AwsS3RabbitMQSmtpStarttlsCommandTest.java
+++ b/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/java/org/apache/james/mpt/smtp/AwsS3RabbitMQSmtpStarttlsCommandTest.java
@@ -25,13 +25,21 @@ import org.apache.james.backends.cassandra.DockerCassandraRule;
import org.apache.james.modules.objectstorage.aws.s3.DockerAwsS3TestRule;
import org.junit.ClassRule;
import org.junit.Rule;
+import org.junit.rules.RuleChain;
+import org.junit.rules.TestRule;
public class AwsS3RabbitMQSmtpStarttlsCommandTest extends SmtpStarttlsCommandTest {
@ClassRule public static DockerCassandraRule cassandraServer = new DockerCassandraRule();
+
+ private DockerAwsS3TestRule dockerAwsS3TestRule = new DockerAwsS3TestRule();
+
+ private SmtpTestRule cassandraRabbitMQAwsS3SmtpTestRule =
+ CassandraRabbitMQAwsS3SmtpTestRuleFactory.create(SMTP_START_TLS_SERVER, cassandraServer.getHost(), dockerAwsS3TestRule);
+
@Rule
- public SmtpTestRule cassandraRabbitMQAwsS3SmtpTestRule = CassandraRabbitMQAwsS3SmtpTestRuleFactory.create(SMTP_START_TLS_SERVER, cassandraServer.getHost());
+ public TestRule composedRule = RuleChain.outerRule(dockerAwsS3TestRule).around(cassandraRabbitMQAwsS3SmtpTestRule);
@Override
protected SmtpHostSystem createSmtpHostSystem() {
diff --git a/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/java/org/apache/james/mpt/smtp/CassandraRabbitMQAwsS3SmtpTestRuleFactory.java b/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/java/org/apache/james/mpt/smtp/CassandraRabbitMQAwsS3SmtpTestRuleFactory.java
index 51ee30f..43c6f25 100644
--- a/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/java/org/apache/james/mpt/smtp/CassandraRabbitMQAwsS3SmtpTestRuleFactory.java
+++ b/mpt/impl/smtp/cassandra-rabbitmq-object-storage/src/test/java/org/apache/james/mpt/smtp/CassandraRabbitMQAwsS3SmtpTestRuleFactory.java
@@ -28,6 +28,7 @@ import org.apache.james.dnsservice.api.DNSService;
import org.apache.james.modules.TestAwsS3BlobStoreModule;
import org.apache.james.modules.TestRabbitMQModule;
import org.apache.james.modules.blobstore.BlobStoreChoosingModule;
+import org.apache.james.modules.objectstorage.aws.s3.DockerAwsS3TestRule;
import org.apache.james.modules.protocols.SmtpGuiceProbe.SmtpServerConnectedType;
import org.apache.james.modules.rabbitmq.RabbitMQModule;
import org.apache.james.modules.server.CamelMailetContainerModule;
@@ -38,13 +39,13 @@ import org.apache.james.util.Host;
import org.junit.rules.TemporaryFolder;
public final class CassandraRabbitMQAwsS3SmtpTestRuleFactory {
- public static SmtpTestRule create(SmtpServerConnectedType smtpServerConnectedType, Host cassandraHost) {
- SmtpTestRule.ServerBuilder createJamesServer = (folder, dnsService) -> createJamesServer(cassandraHost, folder, dnsService);
+ public static SmtpTestRule create(SmtpServerConnectedType smtpServerConnectedType, Host cassandraHost, DockerAwsS3TestRule awsS3TestRule) {
+ SmtpTestRule.ServerBuilder createJamesServer = (folder, dnsService) -> createJamesServer(cassandraHost, awsS3TestRule, folder, dnsService);
return new SmtpTestRule(smtpServerConnectedType, createJamesServer);
}
- private static GuiceJamesServer createJamesServer(Host cassandraHost, TemporaryFolder folder, DNSService dnsService) throws Exception {
+ private static GuiceJamesServer createJamesServer(Host cassandraHost, DockerAwsS3TestRule awsS3TestRule, TemporaryFolder folder, DNSService dnsService) throws Exception {
Configuration configuration = Configuration.builder()
.workingDirectory(folder.newFolder())
.configurationFromClasspath()
@@ -61,7 +62,7 @@ public final class CassandraRabbitMQAwsS3SmtpTestRuleFactory {
new BlobStoreChoosingModule())
.overrideWith(
new TestRabbitMQModule(DockerRabbitMQSingleton.SINGLETON),
- new TestAwsS3BlobStoreModule(),
+ new TestAwsS3BlobStoreModule(awsS3TestRule),
binder -> binder.bind(ClusterConfiguration.class).toInstance(
ClusterConfiguration.builder()
.host(cassandraHost)
diff --git a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/DockerAwsS3Rule.java b/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/DockerAwsS3Rule.java
deleted file mode 100644
index 4031979..0000000
--- a/server/blob/blob-objectstorage/src/test/java/org/apache/james/blob/objectstorage/DockerAwsS3Rule.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.blob.objectstorage;
-
-import org.junit.runner.Description;
-import org.junit.runners.model.Statement;
-import org.testcontainers.containers.GenericContainer;
-
-public class DockerAwsS3Rule {
-
- public Statement apply(Statement base, Description description) {
- return base;
- }
-
- public GenericContainer<?> getRawContainer() {
- return DockerAwsS3Singleton.singleton.getRawContainer();
- }
-
- public DockerAwsS3 dockerAwsS3() {
- return DockerAwsS3Singleton.singleton.dockerAwsS3();
- }
-}
-
diff --git a/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/aws/s3/DockerAwsS3TestRule.java b/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/aws/s3/DockerAwsS3TestRule.java
index a9fc3b6..cb1fb5d 100644
--- a/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/aws/s3/DockerAwsS3TestRule.java
+++ b/server/container/guice/blob-objectstorage-guice/src/test/java/org/apache/james/modules/objectstorage/aws/s3/DockerAwsS3TestRule.java
@@ -26,7 +26,6 @@ import javax.inject.Inject;
import org.apache.james.CleanupTasksPerformer;
import org.apache.james.GuiceModuleTestRule;
import org.apache.james.blob.objectstorage.ContainerName;
-import org.apache.james.blob.objectstorage.DockerAwsS3Rule;
import org.apache.james.blob.objectstorage.DockerAwsS3Singleton;
import org.apache.james.blob.objectstorage.ObjectStorageBlobsDAO;
import org.apache.james.blob.objectstorage.PayloadCodec;
@@ -76,7 +75,6 @@ public class DockerAwsS3TestRule implements GuiceModuleTestRule {
}
private final PayloadCodecFactory payloadCodecFactory;
- private DockerAwsS3Rule awss3Container = new DockerAwsS3Rule();
public DockerAwsS3TestRule() {
this(PayloadCodecFactory.DEFAULT);
@@ -88,7 +86,17 @@ public class DockerAwsS3TestRule implements GuiceModuleTestRule {
@Override
public Statement apply(Statement base, Description description) {
- return awss3Container.apply(base, description);
+ return new Statement() {
+ @Override
+ public void evaluate() throws Throwable {
+ ensureAwsS3started();
+ base.evaluate();
+ }
+ };
+ }
+
+ private void ensureAwsS3started() {
+ DockerAwsS3Singleton.singleton.dockerAwsS3();
}
@Override
@@ -124,14 +132,8 @@ public class DockerAwsS3TestRule implements GuiceModuleTestRule {
};
}
-
public void start() {
- awss3Container.start();
+ ensureAwsS3started();
}
-
- public void stop() {
- awss3Container.stop();
- }
-
}
diff --git a/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQAwsS3JmapTestRule.java b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQAwsS3JmapTestRule.java
index 49220e4..85dd81b 100644
--- a/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQAwsS3JmapTestRule.java
+++ b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/CassandraRabbitMQAwsS3JmapTestRule.java
@@ -28,6 +28,8 @@ import org.apache.james.modules.TestAwsS3BlobStoreModule;
import org.apache.james.modules.TestESMetricReporterModule;
import org.apache.james.modules.TestJMAPServerModule;
import org.apache.james.modules.TestRabbitMQModule;
+import org.apache.james.modules.blobstore.BlobStoreChoosingConfiguration;
+import org.apache.james.modules.objectstorage.aws.s3.DockerAwsS3TestRule;
import org.apache.james.server.core.configuration.Configuration;
import org.junit.rules.TemporaryFolder;
import org.junit.rules.TestRule;
@@ -43,7 +45,7 @@ public class CassandraRabbitMQAwsS3JmapTestRule implements TestRule {
private final TemporaryFolder temporaryFolder;
public static CassandraRabbitMQAwsS3JmapTestRule defaultTestRule() {
- return new CassandraRabbitMQAwsS3JmapTestRule(new EmbeddedElasticSearchRule());
+ return new CassandraRabbitMQAwsS3JmapTestRule(new EmbeddedElasticSearchRule(), new DockerAwsS3TestRule());
}
private final GuiceModuleTestRule guiceModuleTestRule;
@@ -67,7 +69,8 @@ public class CassandraRabbitMQAwsS3JmapTestRule implements TestRule {
.combineWith(CassandraRabbitMQJamesServerMain.MODULES)
.overrideWith(binder -> binder.bind(TextExtractor.class).to(PDFTextExtractor.class))
.overrideWith(new TestRabbitMQModule(DockerRabbitMQSingleton.SINGLETON))
- .overrideWith(new TestAwsS3BlobStoreModule())
+ .overrideWith(binder -> binder.bind(BlobStoreChoosingConfiguration.class)
+ .toInstance(BlobStoreChoosingConfiguration.objectStorage()))
.overrideWith(new TestJMAPServerModule(LIMIT_TO_10_MESSAGES))
.overrideWith(new TestESMetricReporterModule())
.overrideWith(guiceModuleTestRule.getModule())
diff --git a/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/modules/AwsS3BlobStoreExtension.java b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/modules/AwsS3BlobStoreExtension.java
index 44cda7c..6d6ffaf 100644
--- a/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/modules/AwsS3BlobStoreExtension.java
+++ b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/modules/AwsS3BlobStoreExtension.java
@@ -20,6 +20,7 @@
package org.apache.james.modules;
import org.apache.james.GuiceModuleTestExtension;
+import org.apache.james.blob.objectstorage.DockerAwsS3Singleton;
import org.apache.james.modules.blobstore.BlobStoreChoosingConfiguration;
import org.apache.james.modules.objectstorage.PayloadCodecFactory;
import org.apache.james.modules.objectstorage.aws.s3.DockerAwsS3TestRule;
@@ -30,29 +31,28 @@ import com.google.inject.util.Modules;
public class AwsS3BlobStoreExtension implements GuiceModuleTestExtension {
- private final DockerAwsS3TestRule swiftRule;
+ private final DockerAwsS3TestRule awsS3TestRule;
public AwsS3BlobStoreExtension() {
- this.swiftRule = new DockerAwsS3TestRule();
+ this.awsS3TestRule = new DockerAwsS3TestRule();
}
public AwsS3BlobStoreExtension(PayloadCodecFactory payloadCodecFactory) {
- this.swiftRule = new DockerAwsS3TestRule(payloadCodecFactory);
+ this.awsS3TestRule = new DockerAwsS3TestRule(payloadCodecFactory);
}
@Override
public void beforeAll(ExtensionContext extensionContext) {
- swiftRule.start();
+ ensureAwsS3started();
}
- @Override
- public void afterAll(ExtensionContext extensionContext) {
- swiftRule.stop();
+ private void ensureAwsS3started() {
+ DockerAwsS3Singleton.singleton.dockerAwsS3();
}
@Override
public Module getModule() {
- return Modules.override(swiftRule.getModule())
+ return Modules.override(awsS3TestRule.getModule())
.with(binder -> binder.bind(BlobStoreChoosingConfiguration.class)
.toInstance(BlobStoreChoosingConfiguration.objectStorage()));
}
diff --git a/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/modules/TestAwsS3BlobStoreModule.java b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/modules/TestAwsS3BlobStoreModule.java
index 8d0ef83..ea9ae97 100644
--- a/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/modules/TestAwsS3BlobStoreModule.java
+++ b/server/container/guice/cassandra-rabbitmq-guice/src/test/java/org/apache/james/modules/TestAwsS3BlobStoreModule.java
@@ -30,8 +30,8 @@ public class TestAwsS3BlobStoreModule extends AbstractModule {
private final DockerAwsS3TestRule dockerAwsS3TestRule;
- public TestAwsS3BlobStoreModule() {
- this.dockerAwsS3TestRule = new DockerAwsS3TestRule();
+ public TestAwsS3BlobStoreModule(DockerAwsS3TestRule awsS3TestRule) {
+ this.dockerAwsS3TestRule = awsS3TestRule;
}
@Override
diff --git a/server/protocols/jmap-integration-testing/rabbitmq-jmap-integration-testing/src/test/java/org/apache/james/jmap/rabbitmq/cucumber/RabbitMQAwsS3Stepdefs.java b/server/protocols/jmap-integration-testing/rabbitmq-jmap-integration-testing/src/test/java/org/apache/james/jmap/rabbitmq/cucumber/RabbitMQAwsS3Stepdefs.java
index 64c2f91..8a19262 100644
--- a/server/protocols/jmap-integration-testing/rabbitmq-jmap-integration-testing/src/test/java/org/apache/james/jmap/rabbitmq/cucumber/RabbitMQAwsS3Stepdefs.java
+++ b/server/protocols/jmap-integration-testing/rabbitmq-jmap-integration-testing/src/test/java/org/apache/james/jmap/rabbitmq/cucumber/RabbitMQAwsS3Stepdefs.java
@@ -40,7 +40,6 @@ import org.apache.james.modules.TestESMetricReporterModule;
import org.apache.james.modules.TestElasticSearchModule;
import org.apache.james.modules.TestJMAPServerModule;
import org.apache.james.modules.TestRabbitMQModule;
-import org.apache.james.modules.TestAwsS3BlobStoreModule;
import org.apache.james.modules.objectstorage.aws.s3.DockerAwsS3TestRule;
import org.apache.james.server.CassandraTruncateTableTask;
import org.apache.james.server.core.configuration.Configuration;
@@ -48,7 +47,6 @@ import org.junit.rules.TemporaryFolder;
import com.github.fge.lambdas.runnable.ThrowingRunnable;
import com.google.inject.multibindings.Multibinder;
-
import cucumber.api.java.After;
import cucumber.api.java.Before;
import cucumber.runtime.java.guice.ScenarioScoped;
@@ -89,7 +87,7 @@ public class RabbitMQAwsS3Stepdefs {
.overrideWith(new TestJMAPServerModule(10))
.overrideWith(new TestESMetricReporterModule())
.overrideWith(new TestRabbitMQModule(rabbitMQServer.dockerRabbitMQ()))
- .overrideWith(new TestAwsS3BlobStoreModule())
+ .overrideWith(swiftServer.getModule())
.overrideWith(new TestElasticSearchModule(embeddedElasticSearch))
.overrideWith(cassandraServer.getModule())
.overrideWith(binder -> binder.bind(TextExtractor.class).to(DefaultTextExtractor.class))
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org