JAMES-2142 Add JMAP integration test on GetMessageList filter by attachments
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/14a8a4f5 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/14a8a4f5 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/14a8a4f5 Branch: refs/heads/master Commit: 14a8a4f5ff1dcf3ce05584d7ce8874b14aa7aa1a Parents: fec80a1 Author: Antoine Duprat <[email protected]> Authored: Fri Sep 8 15:15:38 2017 +0200 Committer: Antoine Duprat <[email protected]> Committed: Wed Sep 13 10:21:07 2017 +0200 ---------------------------------------------------------------------- .../inmemory/InMemoryMailboxManager.java | 7 ++ mailbox/scanning-search/pom.xml | 16 ++- pom.xml | 18 ++- server/container/guice/cassandra-guice/pom.xml | 9 ++ .../org/apache/james/CassandraJmapTestRule.java | 4 +- server/container/guice/memory-guice/pom.xml | 9 ++ .../org/apache/james/MemoryJmapTestRule.java | 8 +- .../integration/GetMessageListMethodTest.java | 109 +++++++++++++++++++ .../src/test/resources/eml/attachment.pdf | Bin 0 -> 9404 bytes 9 files changed, 175 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/14a8a4f5/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManager.java ---------------------------------------------------------------------- diff --git a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManager.java b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManager.java index 55584d8..adf3044 100644 --- a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManager.java +++ b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMailboxManager.java @@ -39,6 +39,7 @@ import org.apache.james.mailbox.store.event.DelegatingMailboxListener; import org.apache.james.mailbox.store.event.MailboxEventDispatcher; import org.apache.james.mailbox.store.mail.model.Mailbox; import org.apache.james.mailbox.store.mail.model.impl.MessageParser; +import org.apache.james.mailbox.store.search.MessageSearchIndex; public class InMemoryMailboxManager extends StoreMailboxManager { @@ -65,6 +66,12 @@ public class InMemoryMailboxManager extends StoreMailboxManager { } @Override + @Inject + public void setMessageSearchIndex(MessageSearchIndex index) { + super.setMessageSearchIndex(index); + } + + @Override public EnumSet<MailboxCapabilities> getSupportedMailboxCapabilities() { return EnumSet.of(MailboxCapabilities.Move, MailboxCapabilities.UserFlag, MailboxCapabilities.Namespace, MailboxCapabilities.Annotation); } http://git-wip-us.apache.org/repos/asf/james-project/blob/14a8a4f5/mailbox/scanning-search/pom.xml ---------------------------------------------------------------------- diff --git a/mailbox/scanning-search/pom.xml b/mailbox/scanning-search/pom.xml index 1ee91bc..e8d3acc 100644 --- a/mailbox/scanning-search/pom.xml +++ b/mailbox/scanning-search/pom.xml @@ -64,7 +64,6 @@ <dependency> <groupId>org.apache.pdfbox</groupId> <artifactId>pdfbox</artifactId> - <version>2.0.7</version> <scope>test</scope> </dependency> <dependency> @@ -78,4 +77,19 @@ </dependency> </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>test-jar</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> </project> http://git-wip-us.apache.org/repos/asf/james-project/blob/14a8a4f5/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index a5f045b..cc7b4da 100644 --- a/pom.xml +++ b/pom.xml @@ -804,6 +804,17 @@ </dependency> <dependency> <groupId>${project.groupId}</groupId> + <artifactId>apache-james-mailbox-scanning-search</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>apache-james-mailbox-scanning-search</artifactId> + <version>${project.version}</version> + <type>test-jar</type> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> <artifactId>apache-james-mailbox-spring</artifactId> <version>${project.version}</version> </dependency> @@ -1996,6 +2007,11 @@ <version>${maven-reporting-impl.version}</version> </dependency> <dependency> + <groupId>org.apache.pdfbox</groupId> + <artifactId>pdfbox</artifactId> + <version>2.0.7</version> + </dependency> + <dependency> <groupId>org.apache.xbean</groupId> <artifactId>xbean-spring</artifactId> <version>${xbean-spring.version}</version> @@ -2717,7 +2733,7 @@ <goals> <goal>test-jar</goal> </goals> - <phase>package</phase> + <phase>package</phase> </execution> </executions> </plugin> http://git-wip-us.apache.org/repos/asf/james-project/blob/14a8a4f5/server/container/guice/cassandra-guice/pom.xml ---------------------------------------------------------------------- diff --git a/server/container/guice/cassandra-guice/pom.xml b/server/container/guice/cassandra-guice/pom.xml index 53f397c..598a0c4 100644 --- a/server/container/guice/cassandra-guice/pom.xml +++ b/server/container/guice/cassandra-guice/pom.xml @@ -73,6 +73,11 @@ </dependency> <dependency> <groupId>${project.groupId}</groupId> + <artifactId>apache-james-mailbox-scanning-search</artifactId> + <type>test-jar</type> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> <artifactId>apache-james-mailbox-tika</artifactId> <type>test-jar</type> <scope>test</scope> @@ -201,6 +206,10 @@ <artifactId>asyncretry</artifactId> </dependency> <dependency> + <groupId>org.apache.pdfbox</groupId> + <artifactId>pdfbox</artifactId> + </dependency> + <dependency> <groupId>org.assertj</groupId> <artifactId>assertj-core</artifactId> <scope>test</scope> http://git-wip-us.apache.org/repos/asf/james-project/blob/14a8a4f5/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJmapTestRule.java ---------------------------------------------------------------------- diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJmapTestRule.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJmapTestRule.java index 5b031a4..5d45c16 100644 --- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJmapTestRule.java +++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJmapTestRule.java @@ -19,7 +19,7 @@ package org.apache.james; import org.apache.james.mailbox.extractor.TextExtractor; -import org.apache.james.mailbox.store.extractor.DefaultTextExtractor; +import org.apache.james.mailbox.store.search.PDFTextExtractor; import org.apache.james.modules.TestESMetricReporterModule; import org.apache.james.modules.TestJMAPServerModule; import org.junit.rules.TestRule; @@ -49,7 +49,7 @@ public class CassandraJmapTestRule implements TestRule { public GuiceJamesServer jmapServer(Module... additionals) { return new GuiceJamesServer() .combineWith(CassandraJamesServerMain.cassandraServerModule, CassandraJamesServerMain.protocols) - .overrideWith(binder -> binder.bind(TextExtractor.class).to(DefaultTextExtractor.class)) + .overrideWith(binder -> binder.bind(TextExtractor.class).to(PDFTextExtractor.class)) .overrideWith(new TestJMAPServerModule(LIMIT_TO_3_MESSAGES)) .overrideWith(new TestESMetricReporterModule()) .overrideWith(guiceModuleTestRule.getModule()) http://git-wip-us.apache.org/repos/asf/james-project/blob/14a8a4f5/server/container/guice/memory-guice/pom.xml ---------------------------------------------------------------------- diff --git a/server/container/guice/memory-guice/pom.xml b/server/container/guice/memory-guice/pom.xml index f2df5be..828b740 100644 --- a/server/container/guice/memory-guice/pom.xml +++ b/server/container/guice/memory-guice/pom.xml @@ -41,6 +41,11 @@ </dependency> <dependency> <groupId>${project.groupId}</groupId> + <artifactId>apache-james-mailbox-scanning-search</artifactId> + <type>test-jar</type> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> <artifactId>apache-mailet-base</artifactId> <type>test-jar</type> <scope>test</scope> @@ -110,6 +115,10 @@ <artifactId>james-server-guice-webadmin-swagger</artifactId> </dependency> <dependency> + <groupId>org.apache.pdfbox</groupId> + <artifactId>pdfbox</artifactId> + </dependency> + <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <scope>test</scope> http://git-wip-us.apache.org/repos/asf/james-project/blob/14a8a4f5/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJmapTestRule.java ---------------------------------------------------------------------- diff --git a/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJmapTestRule.java b/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJmapTestRule.java index 91544aa..0aadadb 100644 --- a/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJmapTestRule.java +++ b/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJmapTestRule.java @@ -21,6 +21,10 @@ package org.apache.james; import org.apache.activemq.store.PersistenceAdapter; import org.apache.activemq.store.memory.MemoryPersistenceAdapter; +import org.apache.james.mailbox.extractor.TextExtractor; +import org.apache.james.mailbox.store.search.MessageSearchIndex; +import org.apache.james.mailbox.store.search.PDFTextExtractor; +import org.apache.james.mailbox.store.search.SimpleMessageSearchIndex; import org.apache.james.modules.TestFilesystemModule; import org.apache.james.modules.TestJMAPServerModule; import org.junit.rules.TemporaryFolder; @@ -42,7 +46,9 @@ public class MemoryJmapTestRule implements TestRule { .overrideWith(modules) .overrideWith(new TestFilesystemModule(temporaryFolder), new TestJMAPServerModule(LIMIT_TO_3_MESSAGES)) - .overrideWith((binder) -> binder.bind(PersistenceAdapter.class).to(MemoryPersistenceAdapter.class)); + .overrideWith(binder -> binder.bind(PersistenceAdapter.class).to(MemoryPersistenceAdapter.class)) + .overrideWith(binder -> binder.bind(TextExtractor.class).to(PDFTextExtractor.class)) + .overrideWith(binder -> binder.bind(MessageSearchIndex.class).to(SimpleMessageSearchIndex.class)); } @Override http://git-wip-us.apache.org/repos/asf/james-project/blob/14a8a4f5/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMessageListMethodTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMessageListMethodTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMessageListMethodTest.java index a58eadc..65e734c 100644 --- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMessageListMethodTest.java +++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMessageListMethodTest.java @@ -31,12 +31,14 @@ import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.not; import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.time.LocalDate; import java.time.ZoneId; import java.util.Date; import javax.mail.Flags; +import org.apache.commons.io.IOUtils; import org.apache.http.client.utils.URIBuilder; import org.apache.james.GuiceJamesServer; import org.apache.james.jmap.HttpJmapAuthentication; @@ -48,6 +50,13 @@ import org.apache.james.mailbox.model.MailboxId; import org.apache.james.mailbox.model.MailboxPath; import org.apache.james.mailbox.store.mail.model.Mailbox; import org.apache.james.mailbox.store.probe.MailboxProbe; +import org.apache.james.mime4j.dom.Message; +import org.apache.james.mime4j.dom.MessageWriter; +import org.apache.james.mime4j.dom.Multipart; +import org.apache.james.mime4j.message.BodyPart; +import org.apache.james.mime4j.message.BodyPartBuilder; +import org.apache.james.mime4j.message.DefaultMessageWriter; +import org.apache.james.mime4j.message.MultipartBuilder; import org.apache.james.modules.MailboxProbeImpl; import org.apache.james.probe.DataProbe; import org.apache.james.util.date.ImapDateTimeFormatter; @@ -782,6 +791,106 @@ public abstract class GetMessageListMethodTest { } @Test + public void getMessageListShouldFilterMessagesWhenTextFilterDoesntMatches() throws Exception { + mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); + mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), + new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags()); + await(); + + given() + .header("Authorization", accessToken.serialize()) + .body(String.format("[[\"getMessageList\", {\"filter\":{\"text\":\"bad\"}}, \"#0\"]]")) + .when() + .post("/jmap") + .then() + .statusCode(200) + .body(ARGUMENTS + ".messageIds", empty()); + } + + @Test + public void getMessageListShouldNotFilterMessagesWhenTextFilterMatchesBody() throws Exception { + mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); + ComposedMessageId message = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), + ClassLoader.getSystemResourceAsStream("eml/twoAttachments.eml"), new Date(), false, new Flags()); + await(); + + given() + .header("Authorization", accessToken.serialize()) + .body(String.format("[[\"getMessageList\", {\"filter\":{\"text\":\"html\"}}, \"#0\"]]")) + .when() + .post("/jmap") + .then() + .statusCode(200) + .body(ARGUMENTS + ".messageIds", contains(message.getMessageId().serialize())); + } + + @Test + public void getMessageListShouldFilterMessagesWhenAttachmentFilterDoesntMatches() throws Exception { + mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); + byte[] attachmentContent = IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/attachment.pdf")); + BodyPart attachment = BodyPartBuilder.create() + .setBody(attachmentContent, "application/pdf") + .setContentDisposition("attachment") + .build(); + BodyPart textPart = BodyPartBuilder.create().setBody("The message has a PDF attachment.", "plain", Charsets.UTF_8).build(); + Multipart multipart = MultipartBuilder.create("mixed") + .addBodyPart(attachment) + .addBodyPart(textPart) + .build(); + Message message = Message.Builder.of() + .setBody(multipart) + .build(); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + MessageWriter writer = new DefaultMessageWriter(); + writer.writeMessage(message, outputStream); + mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), + new ByteArrayInputStream(outputStream.toByteArray()), new Date(), false, new Flags()); + await(); + + given() + .header("Authorization", accessToken.serialize()) + .body(String.format("[[\"getMessageList\", {\"filter\":{\"attachments\":\"no apple inside\"}}, \"#0\"]]")) + .when() + .post("/jmap") + .then() + .statusCode(200) + .body(ARGUMENTS + ".messageIds", empty()); + } + + @Test + public void getMessageListShouldNotFilterMessagesWhenAttachmentFilterMatches() throws Exception { + mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); + byte[] attachmentContent = IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/attachment.pdf")); + BodyPart attachment = BodyPartBuilder.create() + .setBody(attachmentContent, "application/pdf") + .setContentDisposition("attachment") + .build(); + BodyPart textPart = BodyPartBuilder.create().setBody("The message has a PDF attachment.", "plain", Charsets.UTF_8).build(); + Multipart multipart = MultipartBuilder.create("mixed") + .addBodyPart(attachment) + .addBodyPart(textPart) + .build(); + Message message = Message.Builder.of() + .setBody(multipart) + .build(); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + MessageWriter writer = new DefaultMessageWriter(); + writer.writeMessage(message, outputStream); + ComposedMessageId composedMessageId = mailboxProbe.appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), + new ByteArrayInputStream(outputStream.toByteArray()), new Date(), false, new Flags()); + await(); + + given() + .header("Authorization", accessToken.serialize()) + .body(String.format("[[\"getMessageList\", {\"filter\":{\"attachments\":\"beautiful banana\"}}, \"#0\"]]")) + .when() + .post("/jmap") + .then() + .statusCode(200) + .body(ARGUMENTS + ".messageIds", contains(composedMessageId.getMessageId().serialize())); + } + + @Test public void getMessageListShouldSortMessagesWhenSortedByDateDefault() throws Exception { mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); http://git-wip-us.apache.org/repos/asf/james-project/blob/14a8a4f5/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/eml/attachment.pdf ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/eml/attachment.pdf b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/eml/attachment.pdf new file mode 100644 index 0000000..6db56a2 Binary files /dev/null and b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/eml/attachment.pdf differ --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
