JAMES-2341 Provide an integration test for SpamAssassin learning with Cassandra Fix guice injection for Cassandra
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/0d607c13 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/0d607c13 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/0d607c13 Branch: refs/heads/master Commit: 0d607c13dbf1580a1fc458768f7528da88100225 Parents: 91c7372 Author: Antoine Duprat <[email protected]> Authored: Tue Mar 6 15:37:22 2018 +0100 Committer: Antoine Duprat <[email protected]> Committed: Thu Mar 8 10:36:36 2018 +0100 ---------------------------------------------------------------------- .../modules/mailbox/CassandraMailboxModule.java | 4 +- .../src/test/resources/mailetcontainer.xml | 8 ++ .../cassandra-jmap-integration-testing/pom.xml | 31 +++++- .../jmap/cassandra/CassandraJmapExtension.java | 100 +++++++++++++++++++ .../CassandraSpamAssassinContract.java | 27 +++++ .../src/test/resources/spamassassin_db | 1 + 6 files changed, 163 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/0d607c13/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java ---------------------------------------------------------------------- diff --git a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java index 67da8b6..f6a4ea5 100644 --- a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java +++ b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java @@ -72,7 +72,6 @@ import org.apache.james.mailbox.store.StoreMailboxManager; import org.apache.james.mailbox.store.StoreMessageIdManager; import org.apache.james.mailbox.store.StoreRightManager; import org.apache.james.mailbox.store.event.MailboxEventDispatcher; -import org.apache.james.mailbox.store.event.SpamEventListener; import org.apache.james.mailbox.store.mail.AttachmentMapperFactory; import org.apache.james.mailbox.store.mail.MailboxMapperFactory; import org.apache.james.mailbox.store.mail.MessageMapperFactory; @@ -179,8 +178,7 @@ public class CassandraMailboxModule extends AbstractModule { @Named(Names.MAILBOXMANAGER_NAME) @Singleton public MailboxManager provideMailboxManager(CassandraMailboxManager cassandraMailboxManager, ListeningCurrentQuotaUpdater quotaUpdater, - QuotaManager quotaManager, QuotaRootResolver quotaRootResolver, BatchSizes batchSizes, - SpamEventListener spamEventListener) throws MailboxException { + QuotaManager quotaManager, QuotaRootResolver quotaRootResolver, BatchSizes batchSizes) throws MailboxException { cassandraMailboxManager.setQuotaUpdater(quotaUpdater); cassandraMailboxManager.setQuotaManager(quotaManager); cassandraMailboxManager.setQuotaRootResolver(quotaRootResolver); http://git-wip-us.apache.org/repos/asf/james-project/blob/0d607c13/server/container/guice/cassandra-guice/src/test/resources/mailetcontainer.xml ---------------------------------------------------------------------- diff --git a/server/container/guice/cassandra-guice/src/test/resources/mailetcontainer.xml b/server/container/guice/cassandra-guice/src/test/resources/mailetcontainer.xml index 3d8e823..263738b 100644 --- a/server/container/guice/cassandra-guice/src/test/resources/mailetcontainer.xml +++ b/server/container/guice/cassandra-guice/src/test/resources/mailetcontainer.xml @@ -59,6 +59,14 @@ </mailet> <mailet match="All" class="RecipientRewriteTable" /> <mailet match="RecipientIsLocal" class="org.apache.james.jmap.mailet.VacationMailet"/> + <mailet match="RecipientIsLocal" class="SpamAssassin"> + <spamdHost>localhost</spamdHost> + <spamdPort>783</spamdPort> + </mailet> + <mailet match="IsMarkedAsSpam" class="ToRecipientFolder"> + <folder>Spam</folder> + <consume>true</consume> + </mailet> <mailet match="RecipientIsLocal" class="LocalDelivery"/> <mailet match="HostIsLocal" class="ToProcessor"> <processor>local-address-error</processor> http://git-wip-us.apache.org/repos/asf/james-project/blob/0d607c13/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/pom.xml ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/pom.xml b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/pom.xml index b305cae..606ac21 100644 --- a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/pom.xml +++ b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/pom.xml @@ -59,6 +59,11 @@ </dependency> <dependency> <groupId>${project.groupId}</groupId> + <artifactId>apache-james-mailbox-spamassassin</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> <artifactId>apache-james-mailbox-tika</artifactId> <type>test-jar</type> <scope>test</scope> @@ -110,6 +115,12 @@ </dependency> <dependency> <groupId>${project.groupId}</groupId> + <artifactId>james-server-util</artifactId> + <type>test-jar</type> + <scope>test</scope> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> <artifactId>james-server-util-java8</artifactId> <type>test-jar</type> <scope>test</scope> @@ -141,11 +152,6 @@ <scope>test</scope> </dependency> <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - <dependency> <groupId>org.assertj</groupId> <artifactId>assertj-core</artifactId> <scope>test</scope> @@ -156,6 +162,21 @@ <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.junit.vintage</groupId> + <artifactId>junit-vintage-engine</artifactId> + <scope>test</scope> + </dependency> + <dependency> <groupId>org.testcontainers</groupId> <artifactId>testcontainers</artifactId> <scope>test</scope> http://git-wip-us.apache.org/repos/asf/james-project/blob/0d607c13/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraJmapExtension.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraJmapExtension.java b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraJmapExtension.java new file mode 100644 index 0000000..ee9e88d --- /dev/null +++ b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraJmapExtension.java @@ -0,0 +1,100 @@ +/**************************************************************** + * 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.jmap.cassandra; + +import org.apache.james.CassandraJamesServerMain; +import org.apache.james.DockerCassandraRule; +import org.apache.james.GuiceJamesServer; +import org.apache.james.backends.es.EmbeddedElasticSearch; +import org.apache.james.jmap.methods.integration.JamesWithSpamAssassin; +import org.apache.james.jmap.methods.integration.SpamAssassinModule; +import org.apache.james.mailbox.elasticsearch.MailboxElasticSearchConstants; +import org.apache.james.mailbox.extractor.TextExtractor; +import org.apache.james.mailbox.store.search.PDFTextExtractor; +import org.apache.james.modules.TestESMetricReporterModule; +import org.apache.james.modules.TestElasticSearchModule; +import org.apache.james.modules.TestFilesystemModule; +import org.apache.james.modules.TestJMAPServerModule; +import org.apache.james.util.scanner.SpamAssassinExtension; +import org.junit.jupiter.api.extension.AfterAllCallback; +import org.junit.jupiter.api.extension.BeforeAllCallback; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.ParameterContext; +import org.junit.jupiter.api.extension.ParameterResolutionException; +import org.junit.jupiter.api.extension.ParameterResolver; +import org.junit.rules.TemporaryFolder; + +public class CassandraJmapExtension implements BeforeAllCallback, AfterAllCallback, ParameterResolver { + + private static final int LIMIT_TO_20_MESSAGES = 20; + + private final TemporaryFolder temporaryFolder; + private final DockerCassandraRule cassandra; + private final EmbeddedElasticSearch elasticSearch; + private final SpamAssassinExtension spamAssassinExtension; + private final JamesWithSpamAssassin james; + + public CassandraJmapExtension() { + this.temporaryFolder = new TemporaryFolder(); + this.cassandra = new DockerCassandraRule(); + this.elasticSearch = new EmbeddedElasticSearch(temporaryFolder, MailboxElasticSearchConstants.DEFAULT_MAILBOX_INDEX); + this.spamAssassinExtension = new SpamAssassinExtension(); + this.james = james(); + } + + private JamesWithSpamAssassin james() { + return new JamesWithSpamAssassin( + new GuiceJamesServer() + .combineWith(CassandraJamesServerMain.CASSANDRA_SERVER_MODULE, CassandraJamesServerMain.PROTOCOLS) + .overrideWith(binder -> binder.bind(TextExtractor.class).to(PDFTextExtractor.class)) + .overrideWith(new TestJMAPServerModule(LIMIT_TO_20_MESSAGES)) + .overrideWith(new TestESMetricReporterModule()) + .overrideWith(new TestFilesystemModule(temporaryFolder::getRoot)) + .overrideWith(cassandra.getModule()) + .overrideWith(new TestElasticSearchModule(elasticSearch)) + .overrideWith(new SpamAssassinModule(spamAssassinExtension)), + spamAssassinExtension); + } + + @Override + public void beforeAll(ExtensionContext context) throws Exception { + temporaryFolder.create(); + spamAssassinExtension.beforeAll(context); + cassandra.start(); + elasticSearch.before(); + } + + @Override + public void afterAll(ExtensionContext context) throws Exception { + elasticSearch.after(); + cassandra.stop(); + spamAssassinExtension.afterAll(context); + temporaryFolder.delete(); + } + + @Override + public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { + return parameterContext.getParameter().getType() == JamesWithSpamAssassin.class; + } + + @Override + public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { + return james; + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/0d607c13/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraSpamAssassinContract.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraSpamAssassinContract.java b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraSpamAssassinContract.java new file mode 100644 index 0000000..66f188d --- /dev/null +++ b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraSpamAssassinContract.java @@ -0,0 +1,27 @@ +/**************************************************************** + * 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.jmap.cassandra; + +import org.apache.james.jmap.methods.integration.SpamAssassinContract; +import org.junit.jupiter.api.extension.ExtendWith; + +@ExtendWith(CassandraJmapExtension.class) +public class CassandraSpamAssassinContract implements SpamAssassinContract { + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/0d607c13/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/resources/spamassassin_db ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/resources/spamassassin_db b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/resources/spamassassin_db new file mode 120000 index 0000000..de1933d --- /dev/null +++ b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/resources/spamassassin_db @@ -0,0 +1 @@ +../../../../jmap-integration-testing-common/src/test/resources/spamassassin_db \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
