This is an automated email from the ASF dual-hosted git repository. rouazana pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 6f9f3635d1bfed47b6ae6e01f7e72aa771d38978 Author: RĂ©mi Kowalski <rkowal...@linagora.com> AuthorDate: Fri Mar 8 11:59:31 2019 +0100 JAMES-2681 mailbox backup to blob store --- mailbox/backup/pom.xml | 27 +++- .../james/mailbox/backup/DefaultMailboxBackup.java | 105 +++++++-------- .../org/apache/james/mailbox/backup/Zipper.java | 21 +-- .../mailbox/backup/DefaultMailboxBackupTest.java | 144 +++++++++++---------- .../mailbox/backup/MailboxMessageFixture.java | 32 ++++- pom.xml | 17 +++ 6 files changed, 206 insertions(+), 140 deletions(-) diff --git a/mailbox/backup/pom.xml b/mailbox/backup/pom.xml index cdd122e..837bb10 100644 --- a/mailbox/backup/pom.xml +++ b/mailbox/backup/pom.xml @@ -17,7 +17,8 @@ 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/maven-v4_0_0.xsd"> +<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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> @@ -45,6 +46,23 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> + <artifactId>apache-james-mailbox-memory</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>${james.groupId}</groupId> + <artifactId>apache-james-mailbox-memory</artifactId> + <type>test-jar</type> + <scope>test</scope> + </dependency> + <dependency> + <groupId>${james.groupId}</groupId> + <artifactId>apache-james-mailbox-store</artifactId> + <type>test-jar</type> + <scope>test</scope> + </dependency> + <dependency> + <groupId>${james.groupId}</groupId> <artifactId>apache-james-mailbox-store</artifactId> </dependency> <dependency> @@ -65,6 +83,11 @@ <artifactId>commons-compress</artifactId> </dependency> <dependency> + <groupId>ch.qos.logback</groupId> + <artifactId>logback-classic</artifactId> + <scope>test</scope> + </dependency> + <dependency> <groupId>org.assertj</groupId> <artifactId>assertj-core</artifactId> <scope>test</scope> @@ -93,5 +116,5 @@ </plugin> </plugins> </build> - + </project> diff --git a/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/DefaultMailboxBackup.java b/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/DefaultMailboxBackup.java index 2bff492..aa428ba 100644 --- a/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/DefaultMailboxBackup.java +++ b/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/DefaultMailboxBackup.java @@ -18,112 +18,103 @@ ****************************************************************/ package org.apache.james.mailbox.backup; -import java.io.BufferedInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.IOException; -import java.io.InputStream; import java.io.OutputStream; import java.util.List; -import java.util.Optional; -import java.util.UUID; -import java.util.function.Function; -import java.util.stream.Collectors; import java.util.stream.Stream; -import org.apache.james.blob.api.BlobStore; import org.apache.james.core.User; import org.apache.james.mailbox.MailboxManager; import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.exception.MailboxException; -import org.apache.james.mailbox.model.BlobId; import org.apache.james.mailbox.model.FetchGroupImpl; import org.apache.james.mailbox.model.MailboxAnnotation; +import org.apache.james.mailbox.model.MailboxMetaData; import org.apache.james.mailbox.model.MailboxPath; import org.apache.james.mailbox.model.MessageRange; import org.apache.james.mailbox.model.MessageResult; import org.apache.james.mailbox.model.search.MailboxQuery; import org.apache.james.mailbox.store.StoreMessageManager; import org.apache.james.mailbox.store.mail.model.Mailbox; -import org.apache.james.util.OptionalUtils; import org.apache.james.util.streams.Iterators; -import org.reactivestreams.Publisher; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.github.steveash.guavate.Guavate; + public class DefaultMailboxBackup implements MailboxBackup { private static final Logger LOGGER = LoggerFactory.getLogger(DefaultMailboxBackup.class); - protected class MailAccountContent { - final MailboxWithAnnotations mailboxWithAnnotations; - final Stream<MessageResult> messages; + private static class MailAccountContent { + private final MailboxWithAnnotations mailboxWithAnnotations; + private final Stream<MessageResult> messages; MailAccountContent(MailboxWithAnnotations mailboxWithAnnotations, Stream<MessageResult> messages) { this.mailboxWithAnnotations = mailboxWithAnnotations; this.messages = messages; } + + public MailboxWithAnnotations getMailboxWithAnnotations() { + return mailboxWithAnnotations; + } + + public Stream<MessageResult> getMessages() { + return messages; + } } - public DefaultMailboxBackup(MailboxManager mailboxManager, ArchiveService archiveService, BlobStore store) { + public DefaultMailboxBackup(MailboxManager mailboxManager, ArchiveService archiveService) { this.mailboxManager = mailboxManager; this.archiveService = archiveService; - this.store = store; + } + + @Override + public void backupAccount(User user, OutputStream destination) throws IOException, MailboxException { + MailboxSession session = mailboxManager.createSystemSession(user.asString()); + List<MailAccountContent> accountContents = getAccountContentForUser(session); + List<MailboxWithAnnotations> mailboxes = accountContents.stream() + .map(MailAccountContent::getMailboxWithAnnotations) + .collect(Guavate.toImmutableList()); + + Stream<MessageResult> messages = allMessagesForUser(accountContents); + archive(mailboxes, messages, destination); } private final MailboxManager mailboxManager; private final ArchiveService archiveService; - private final BlobStore store; - - private Function<MailboxPath, Optional<MailAccountContent>> getMailboxWithAnnotationsFromPath(MailboxSession session) { - return path -> { - try { - StoreMessageManager messageManager = (StoreMessageManager) mailboxManager.getMailbox(path, session); - Mailbox mailbox = messageManager.getMailboxEntity(); - List<MailboxAnnotation> annotations = mailboxManager.getAllAnnotations(path, session); - MailboxWithAnnotations mailboxWithAnnotations = new MailboxWithAnnotations(mailbox, annotations); - Stream<MessageResult> messages = Iterators.toStream(messageManager.getMessages(MessageRange.all(), FetchGroupImpl.FULL_CONTENT, session)); - return Optional.of(new MailAccountContent(mailboxWithAnnotations, messages)); - } catch (MailboxException e) { - LOGGER.error("Error while fetching Mailbox during backup", e); - return Optional.empty(); - } - }; + + private Stream<MailAccountContent> getMailboxWithAnnotationsFromPath(MailboxSession session, MailboxPath path) { + try { + StoreMessageManager messageManager = (StoreMessageManager) mailboxManager.getMailbox(path, session); + Mailbox mailbox = messageManager.getMailboxEntity(); + List<MailboxAnnotation> annotations = mailboxManager.getAllAnnotations(path, session); + MailboxWithAnnotations mailboxWithAnnotations = new MailboxWithAnnotations(mailbox, annotations); + Stream<MessageResult> messages = Iterators.toStream(messageManager.getMessages(MessageRange.all(), FetchGroupImpl.FULL_CONTENT, session)); + return Stream.of(new MailAccountContent(mailboxWithAnnotations, messages)); + } catch (MailboxException e) { + LOGGER.error("Error while fetching Mailbox during backup", e); + return Stream.empty(); + } } - private List<MailAccountContent> getAllMailboxesForUser(MailboxSession session) throws MailboxException { + private List<MailAccountContent> getAccountContentForUser(MailboxSession session) throws MailboxException { MailboxQuery queryUser = MailboxQuery.builder().username(session.getUser().asString()).build(); - Stream<MailboxPath> paths = mailboxManager.search(queryUser, session).stream().map(mailboxMetaData -> mailboxMetaData.getPath()); + Stream<MailboxPath> paths = mailboxManager.search(queryUser, session).stream() + .map(MailboxMetaData::getPath); List<MailAccountContent> mailboxes = paths - .flatMap(getMailboxWithAnnotationsFromPath(session).andThen(OptionalUtils::toStream)) - .collect(Collectors.toList()); + .flatMap(path -> getMailboxWithAnnotationsFromPath(session, path)) + .collect(Guavate.toImmutableList()); return mailboxes; } - private Publisher<BlobId> saveToStore(List<MailboxWithAnnotations> mailboxes, Stream<MessageResult> messages) throws IOException { - File tmp = File.createTempFile(UUID.randomUUID().toString(), ".tmp"); - try (OutputStream out = new FileOutputStream(tmp)) { - archiveService.archive(mailboxes, messages, out); - try (InputStream in = new BufferedInputStream(new FileInputStream(tmp))) { - return store.save(in).map(b -> BlobId.fromString(b.asString())); - } - } finally { - tmp.delete(); - } + private void archive(List<MailboxWithAnnotations> mailboxes, Stream<MessageResult> messages, OutputStream destination) throws IOException { + archiveService.archive(mailboxes, messages, destination); } private Stream<MessageResult> allMessagesForUser(List<MailAccountContent> mailboxes) { - return mailboxes.stream().flatMap(messages -> messages.messages); + return mailboxes.stream().flatMap(MailAccountContent::getMessages); } - @Override - public Publisher<BlobId> backupAccount(User user) throws IOException, MailboxException { - MailboxSession session = mailboxManager.createSystemSession(user.asString()); - List<MailAccountContent> mailboxesWithMessages = getAllMailboxesForUser(session); - List<MailboxWithAnnotations> mailboxes = mailboxesWithMessages.stream().map(m -> m.mailboxWithAnnotations).collect(Collectors.toList()); - Stream<MessageResult> messages = allMessagesForUser(mailboxesWithMessages); - return saveToStore(mailboxes, messages); - } } diff --git a/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/Zipper.java b/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/Zipper.java index bf003b6..1db1092 100644 --- a/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/Zipper.java +++ b/mailbox/backup/src/main/java/org/apache/james/mailbox/backup/Zipper.java @@ -123,14 +123,7 @@ public class Zipper implements ArchiveService { private void storeInArchive(MessageResult message, ZipArchiveOutputStream archiveOutputStream) throws IOException { String entryId = message.getMessageId().serialize(); - ZipArchiveEntry archiveEntry = (ZipArchiveEntry) archiveOutputStream.createArchiveEntry(new File(entryId), entryId); - - archiveEntry.addExtraField(new SizeExtraField(message.getSize())); - archiveEntry.addExtraField(new UidExtraField(message.getUid().asLong())); - archiveEntry.addExtraField(new MessageIdExtraField(message.getMessageId().serialize())); - archiveEntry.addExtraField(new MailboxIdExtraField(message.getMailboxId().serialize())); - archiveEntry.addExtraField(new InternalDateExtraField(message.getInternalDate())); - archiveEntry.addExtraField(new FlagsExtraField(message.getFlags())); + ZipArchiveEntry archiveEntry = createMessageZipArchiveEntry(message, archiveOutputStream, entryId); archiveOutputStream.putArchiveEntry(archiveEntry); try { @@ -144,4 +137,16 @@ public class Zipper implements ArchiveService { archiveOutputStream.closeArchiveEntry(); } + + private ZipArchiveEntry createMessageZipArchiveEntry(MessageResult message, ZipArchiveOutputStream archiveOutputStream, String entryId) throws IOException { + ZipArchiveEntry archiveEntry = (ZipArchiveEntry) archiveOutputStream.createArchiveEntry(new File(entryId), entryId); + + archiveEntry.addExtraField(new SizeExtraField(message.getSize())); + archiveEntry.addExtraField(new UidExtraField(message.getUid().asLong())); + archiveEntry.addExtraField(new MessageIdExtraField(message.getMessageId().serialize())); + archiveEntry.addExtraField(new MailboxIdExtraField(message.getMailboxId().serialize())); + archiveEntry.addExtraField(new InternalDateExtraField(message.getInternalDate())); + archiveEntry.addExtraField(new FlagsExtraField(message.getFlags())); + return archiveEntry; + } } diff --git a/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/DefaultMailboxBackupTest.java b/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/DefaultMailboxBackupTest.java index 3f57508..f31c989 100644 --- a/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/DefaultMailboxBackupTest.java +++ b/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/DefaultMailboxBackupTest.java @@ -19,130 +19,136 @@ package org.apache.james.mailbox.backup; -import java.io.File; -import java.io.FileOutputStream; -import java.io.InputStream; -import java.io.OutputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.util.Arrays; import java.util.HashSet; -import org.apache.commons.compress.archivers.zip.ZipFile; -import org.apache.james.blob.api.BlobStore; -import org.apache.james.blob.api.HashBlobId; -import org.apache.james.blob.memory.MemoryBlobStore; import org.apache.james.core.User; -import org.apache.james.junit.TemporaryFolderExtension; import org.apache.james.mailbox.MailboxManager; import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.MessageManager; import org.apache.james.mailbox.backup.ZipAssert.EntryChecks; import org.apache.james.mailbox.extension.PreDeletionHook; import org.apache.james.mailbox.inmemory.MemoryMailboxManagerProvider; -import org.apache.james.mailbox.manager.ManagerTestResources; -import org.apache.james.mailbox.model.BlobId; import org.apache.james.mailbox.model.MailboxId; import org.apache.james.mailbox.model.MailboxPath; -import org.apache.james.mailbox.store.mail.model.MailboxMessage; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.reactivestreams.Publisher; -import org.testcontainers.shaded.org.apache.commons.io.IOUtils; import com.github.fge.lambdas.Throwing; -import reactor.core.publisher.Mono; -@ExtendWith(TemporaryFolderExtension.class) class DefaultMailboxBackupTest implements MailboxMessageFixture { - private static final User USER1 = User.fromUsername(ManagerTestResources.USER); - private static final MailboxPath MAILBOX_PATH_USER1_MAILBOX1 = MailboxPath.forUser(ManagerTestResources.USER, MAILBOX_1_NAME); - private static final MailboxPath MAILBOX_PATH_OTHER_USER_MAILBOX1 = MailboxPath.forUser(ManagerTestResources.OTHER_USER, MAILBOX_OTHER_USER_NAME); - private static final HashBlobId.Factory BLOB_ID_FACTORY = new HashBlobId.Factory(); + private static final String USER = "user"; + private static final String OTHER_USER = "otherUser"; + + private static final User USER1 = User.fromUsername(USER); + private static final MailboxPath MAILBOX_PATH_USER1_MAILBOX1 = MailboxPath.forUser(USER, MAILBOX_1_NAME); + private static final MailboxPath MAILBOX_PATH_USER1_MAILBOX2 = MailboxPath.forUser(USER, MAILBOX_2_NAME); + private static final MailboxPath MAILBOX_PATH_OTHER_USER_MAILBOX1 = MailboxPath.forUser(OTHER_USER, MAILBOX_OTHER_USER_NAME); private static final HashSet<PreDeletionHook> PRE_DELETION_HOOKS = new HashSet<>(); + private static final int BUFFER_SIZE = 4096; + private final ArchiveService archiveService = new Zipper(); private MailboxManager mailboxManager; - private BlobStore store; - private File destination; private DefaultMailboxBackup backup; @BeforeEach - void beforeEach(TemporaryFolderExtension.TemporaryFolder temporaryFolder) throws Exception { - destination = File.createTempFile("backup-test", ".zip", temporaryFolder.getTempDir()); + void beforeEach() { mailboxManager = MemoryMailboxManagerProvider.provideMailboxManager(PRE_DELETION_HOOKS); - store = new MemoryBlobStore(new HashBlobId.Factory()); - backup = new DefaultMailboxBackup(mailboxManager, archiveService, store); + backup = new DefaultMailboxBackup(mailboxManager, archiveService); } - private void readFromStoreAndCopyInFile(BlobId blobId) throws Exception { - InputStream content = store.read(BLOB_ID_FACTORY.from(blobId.asString())); - try (OutputStream out = new FileOutputStream(destination)) { - IOUtils.copy(content, out); - } - } - - private void createMailBoxWithMessage(MailboxSession session, MailboxPath mailboxPath, MailboxMessage... messages) throws Exception { + private void createMailBoxWithMessage(MailboxSession session, MailboxPath mailboxPath, MessageManager.AppendCommand... messages) throws Exception { MailboxId mailboxId = mailboxManager.createMailbox(mailboxPath, session).get(); Arrays.stream(messages).forEach(Throwing.consumer(message -> - mailboxManager.getMailbox(mailboxId, session).appendMessage(MessageManager.AppendCommand.from(message.getFullContent()), session) + mailboxManager.getMailbox(mailboxId, session).appendMessage(message, session) ) ); } - private ZipAssert assertThatZipFromIdContainsOnly(Publisher<BlobId> blobIdPublisher, EntryChecks... onlyEntriesMatching) throws Exception { - BlobId blobId = Mono.from(blobIdPublisher).block(); - readFromStoreAndCopyInFile(blobId); - - try (ZipFile zipFile = new ZipFile(destination)) { - return ZipAssert.assertThatZip(zipFile).containsOnlyEntriesMatching(onlyEntriesMatching); - } - } - @Test void doBackupWithoutMailboxShouldStoreEmptyBackup() throws Exception { - Publisher<BlobId> res = backup.backupAccount(USER1); - - assertThatZipFromIdContainsOnly(res); + ByteArrayOutputStream destination = new ByteArrayOutputStream(BUFFER_SIZE); + backup.backupAccount(USER1, destination); + try (ZipAssert zipAssert = ZipAssert.assertThatZip(destination)) { + zipAssert.containsOnlyEntriesMatching(); + } } @Test void doBackupWithoutMessageShouldStoreAnArchiveWithOnlyOneEntry() throws Exception { - MailboxSession session = mailboxManager.createSystemSession(ManagerTestResources.USER); + ByteArrayOutputStream destination = new ByteArrayOutputStream(BUFFER_SIZE); + MailboxSession session = mailboxManager.createSystemSession(USER); createMailBoxWithMessage(session, MAILBOX_PATH_USER1_MAILBOX1); - Publisher<BlobId> res = backup.backupAccount(USER1); - - assertThatZipFromIdContainsOnly(res, EntryChecks.hasName(MAILBOX_1_NAME + "/").isDirectory()); + backup.backupAccount(USER1, destination); + try (ZipAssert zipAssert = ZipAssert.assertThatZip(destination)) { + zipAssert.containsOnlyEntriesMatching(EntryChecks.hasName(MAILBOX_1_NAME + "/").isDirectory()); + } } @Test void doBackupWithOneMessageShouldStoreAnArchiveWithTwoEntries() throws Exception { - MailboxSession session = mailboxManager.createSystemSession(ManagerTestResources.USER); - createMailBoxWithMessage(session, MAILBOX_PATH_USER1_MAILBOX1, MESSAGE_1); + ByteArrayOutputStream destination = new ByteArrayOutputStream(BUFFER_SIZE); + MailboxSession session = mailboxManager.createSystemSession(USER); + createMailBoxWithMessage(session, MAILBOX_PATH_USER1_MAILBOX1, getMessage1AppendCommand()); - Publisher<BlobId> res = backup.backupAccount(USER1); + backup.backupAccount(USER1, destination); - assertThatZipFromIdContainsOnly(res, - EntryChecks.hasName(MAILBOX_1_NAME + "/").isDirectory(), - EntryChecks.hasName(MESSAGE_ID_1.serialize()).hasStringContent(MESSAGE_CONTENT_1) - ); + try (ZipAssert zipAssert = ZipAssert.assertThatZip(destination)) { + zipAssert.containsOnlyEntriesMatching( + EntryChecks.hasName(MAILBOX_1_NAME + "/").isDirectory(), + EntryChecks.hasName(MESSAGE_ID_1.serialize()).hasStringContent(MESSAGE_CONTENT_1) + ); + } } @Test - void doBackupShouldOnlyArchiveTheMailboxOfTheUser() throws Exception { - MailboxSession session = mailboxManager.createSystemSession(ManagerTestResources.USER); - MailboxSession otherSession = mailboxManager.createSystemSession(ManagerTestResources.OTHER_USER); + void doBackupWithTwoMailboxesAndOneMessageShouldStoreAnArchiveWithThreeEntries() throws Exception { + ByteArrayOutputStream destination = new ByteArrayOutputStream(BUFFER_SIZE); + MailboxSession session = mailboxManager.createSystemSession(USER); + createMailBoxWithMessage(session, MAILBOX_PATH_USER1_MAILBOX1, getMessage1AppendCommand()); + createMailBoxWithMessage(session, MAILBOX_PATH_USER1_MAILBOX2); + + backup.backupAccount(USER1, destination); + + try (ZipAssert zipAssert = ZipAssert.assertThatZip(destination)) { + zipAssert.containsOnlyEntriesMatching( + EntryChecks.hasName(MAILBOX_1_NAME + "/").isDirectory(), + EntryChecks.hasName(MAILBOX_2_NAME + "/").isDirectory(), + EntryChecks.hasName(MESSAGE_ID_1.serialize()).hasStringContent(MESSAGE_CONTENT_1) + ); + } + } - createMailBoxWithMessage(session, MAILBOX_PATH_USER1_MAILBOX1, MESSAGE_1); - createMailBoxWithMessage(otherSession, MAILBOX_PATH_OTHER_USER_MAILBOX1, MESSAGE_1_OTHER_USER); + @Test + void doBackupShouldOnlyArchiveTheMailboxOfTheUser() throws Exception { + ByteArrayOutputStream destination = new ByteArrayOutputStream(BUFFER_SIZE); + MailboxSession session = mailboxManager.createSystemSession(USER); + MailboxSession otherSession = mailboxManager.createSystemSession(OTHER_USER); + + createMailBoxWithMessage(session, MAILBOX_PATH_USER1_MAILBOX1, getMessage1AppendCommand()); + createMailBoxWithMessage(otherSession, MAILBOX_PATH_OTHER_USER_MAILBOX1, getMessage1OtherUserAppendCommand()); + + backup.backupAccount(USER1, destination); + try (ZipAssert zipAssert = ZipAssert.assertThatZip(destination)) { + zipAssert.containsOnlyEntriesMatching( + EntryChecks.hasName(MAILBOX_1_NAME + "/").isDirectory(), + EntryChecks.hasName(MESSAGE_ID_1.serialize()).hasStringContent(MESSAGE_CONTENT_1) + ); + } + } - Publisher<BlobId> res = backup.backupAccount(USER1); + private MessageManager.AppendCommand getMessage1AppendCommand() throws IOException { + return MessageManager.AppendCommand.builder().withFlags(flags1).build(MESSAGE_1.getFullContent()); + } - assertThatZipFromIdContainsOnly(res, - EntryChecks.hasName(MAILBOX_1_NAME + "/").isDirectory(), - EntryChecks.hasName(MESSAGE_ID_1.serialize()).hasStringContent(MESSAGE_CONTENT_1) - ); + private MessageManager.AppendCommand getMessage1OtherUserAppendCommand() throws IOException { + return MessageManager.AppendCommand.builder().withFlags(flags1).build(MESSAGE_1_OTHER_USER.getFullContent()); } + } diff --git a/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/MailboxMessageFixture.java b/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/MailboxMessageFixture.java index c4a368a..87ffdb9 100644 --- a/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/MailboxMessageFixture.java +++ b/mailbox/backup/src/test/java/org/apache/james/mailbox/backup/MailboxMessageFixture.java @@ -60,20 +60,31 @@ public interface MailboxMessageFixture { SharedByteArrayInputStream CONTENT_STREAM_2 = new SharedByteArrayInputStream(MESSAGE_CONTENT_2.getBytes(MESSAGE_CHARSET)); MessageId MESSAGE_ID_1 = MESSAGE_ID_FACTORY.generate(); MessageId MESSAGE_ID_2 = MESSAGE_ID_FACTORY.generate(); + + MessageId MESSAGE_ID_OTHER_USER_1 = MESSAGE_ID_FACTORY.generate(); + long SIZE_1 = 1000; long SIZE_2 = 2000; long MESSAGE_UID_1_VALUE = 1111L; long MESSAGE_UID_2_VALUE = 2222L; + long MESSAGE_UID_OTHER_USER_1_VALUE = 1111L; MessageUid MESSAGE_UID_1 = MessageUid.of(MESSAGE_UID_1_VALUE); MessageUid MESSAGE_UID_2 = MessageUid.of(MESSAGE_UID_2_VALUE); + MessageUid MESSAGE_UID_OTHER_USER_1 = MessageUid.of(MESSAGE_UID_OTHER_USER_1_VALUE); MailboxId MAILBOX_ID_1 = TestId.of(1L); + MailboxId MAILBOX_ID_2 = TestId.of(2L); + MailboxId MAILBOX_ID_11 = TestId.of(11L); Flags flags1 = new Flags("myFlags"); MailboxSession MAILBOX_SESSION = MailboxSessionUtil.create("user"); - - Mailbox MAILBOX_1 = new SimpleMailbox(MailboxPath.forUser("user", "mailbox1"), 42, TestId.of(1L)); - Mailbox MAILBOX_1_SUB_1 = new SimpleMailbox(MailboxPath.forUser("user", "mailbox1" + MAILBOX_SESSION.getPathDelimiter() + "sub1"), 420, TestId.of(11L)); - Mailbox MAILBOX_2 = new SimpleMailbox(MailboxPath.forUser("user", "mailbox2"), 43, TestId.of(2L)); + + String MAILBOX_1_NAME = "mailbox1"; + String MAILBOX_2_NAME = "mailbox2"; + String MAILBOX_OTHER_USER_NAME = "mailbox_other"; + Mailbox MAILBOX_1 = new SimpleMailbox(MailboxPath.forUser("user", MAILBOX_1_NAME), 42, MAILBOX_ID_1); + Mailbox MAILBOX_1_OTHER_USER = new SimpleMailbox(MailboxPath.forUser("otherUser", MAILBOX_OTHER_USER_NAME), 42, MAILBOX_ID_11); + Mailbox MAILBOX_1_SUB_1 = new SimpleMailbox(MailboxPath.forUser("user", MAILBOX_1_NAME + MAILBOX_SESSION.getPathDelimiter() + "sub1"), 420, TestId.of(11L)); + Mailbox MAILBOX_2 = new SimpleMailbox(MailboxPath.forUser("user", MAILBOX_2_NAME), 43, MAILBOX_ID_2); List<MailboxAnnotation> NO_ANNOTATION = ImmutableList.of(); @@ -102,6 +113,19 @@ public interface MailboxMessageFixture { .propertyBuilder(new PropertyBuilder()) .mailboxId(MAILBOX_ID_1) .build(); + + SimpleMailboxMessage MESSAGE_1_OTHER_USER = SimpleMailboxMessage.builder() + .messageId(MESSAGE_ID_OTHER_USER_1) + .uid(MESSAGE_UID_OTHER_USER_1) + .content(CONTENT_STREAM_1) + .size(SIZE_1) + .internalDate(new Date(DATE_1.toEpochSecond())) + .bodyStartOctet(0) + .flags(flags1) + .propertyBuilder(new PropertyBuilder()) + .mailboxId(MAILBOX_ID_11) + .build(); + SimpleMailboxMessage MESSAGE_2 = SimpleMailboxMessage.builder() .messageId(MESSAGE_ID_2) .uid(MESSAGE_UID_2) diff --git a/pom.xml b/pom.xml index 335423e..bc1ff67 100644 --- a/pom.xml +++ b/pom.xml @@ -1145,6 +1145,12 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> + <artifactId>blob-memory</artifactId> + <version>${project.version}</version> + <type>test-jar</type> + </dependency> + <dependency> + <groupId>${james.groupId}</groupId> <artifactId>blob-union</artifactId> <version>${project.version}</version> </dependency> @@ -1210,6 +1216,17 @@ </dependency> <dependency> <groupId>${james.groupId}</groupId> + <artifactId>james-server-blob</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>${james.groupId}</groupId> + <artifactId>james-server-blob</artifactId> + <version>${project.version}</version> + <type>test-jar</type> + </dependency> + <dependency> + <groupId>${james.groupId}</groupId> <artifactId>james-server-cassandra-guice</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