This is an automated email from the ASF dual-hosted git repository. rcordier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 9760ae1a2589734334c5fa0d418652080a6f9726 Author: Rene Cordier <[email protected]> AuthorDate: Wed Feb 12 11:49:17 2020 +0700 JAMES-3057 Rename save method in MailboxMapper to rename Now that we are separating the logic between create a rename a mailbox, it makes sense to rename this --- .../cassandra/mail/CassandraMailboxMapper.java | 6 +-- .../CassandraMailboxMapperConcurrencyTest.java | 6 +-- .../cassandra/mail/CassandraMailboxMapperTest.java | 58 +++++++++++----------- .../mail/migration/MailboxPathV2MigrationTest.java | 4 +- ...asticSearchListeningMessageSearchIndexTest.java | 2 +- .../james/mailbox/jpa/mail/JPAMailboxMapper.java | 2 +- .../jpa/mail/TransactionalMailboxMapper.java | 4 +- .../mailbox/maildir/mail/MaildirMailboxMapper.java | 2 +- .../inmemory/mail/InMemoryMailboxMapper.java | 2 +- .../spamassassin/SpamAssassinListenerTest.java | 12 ++--- .../james/mailbox/store/StoreMailboxManager.java | 4 +- .../james/mailbox/store/mail/MailboxMapper.java | 6 +-- .../store/mail/model/MailboxMapperACLTest.java | 2 +- .../store/mail/model/MailboxMapperTest.java | 26 +++++----- .../store/mail/model/MessageIdMapperTest.java | 2 +- .../store/mail/model/MessageMapperTest.java | 2 +- .../mailbox/store/mail/model/MessageMoveTest.java | 2 +- .../adapter/mailbox/MailboxManagementTest.java | 46 ++++++++--------- 18 files changed, 94 insertions(+), 94 deletions(-) diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapper.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapper.java index 5aebd17..5f89b42 100644 --- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapper.java +++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapper.java @@ -190,16 +190,16 @@ public class CassandraMailboxMapper implements MailboxMapper { } @Override - public MailboxId save(Mailbox mailbox) throws MailboxException { + public MailboxId rename(Mailbox mailbox) throws MailboxException { CassandraId cassandraId = retrieveId(mailbox); mailbox.setMailboxId(cassandraId); - if (!trySave(mailbox, cassandraId)) { + if (!tryRename(mailbox, cassandraId)) { throw new MailboxExistsException(mailbox.generateAssociatedPath().asString()); } return cassandraId; } - private boolean trySave(Mailbox cassandraMailbox, CassandraId cassandraId) { + private boolean tryRename(Mailbox cassandraMailbox, CassandraId cassandraId) { return mailboxPathV2DAO.save(cassandraMailbox.generateAssociatedPath(), cassandraId) .filter(isCreated -> isCreated) .flatMap(mailboxHasCreated -> mailboxDAO.retrieveMailbox(cassandraId) diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapperConcurrencyTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapperConcurrencyTest.java index 9d6b69b..71b3f1b 100644 --- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapperConcurrencyTest.java +++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapperConcurrencyTest.java @@ -64,7 +64,7 @@ class CassandraMailboxMapperConcurrencyTest { @Test void saveShouldBeThreadSafe() throws Exception { ConcurrentTestRunner.builder() - .operation((a, b) -> testee.save(new Mailbox(MAILBOX_PATH, UID_VALIDITY))) + .operation((a, b) -> testee.rename(new Mailbox(MAILBOX_PATH, UID_VALIDITY))) .threadCount(THREAD_COUNT) .operationCount(OPERATION_COUNT) .runAcceptingErrorsWithin(Duration.ofMinutes(1)); @@ -75,12 +75,12 @@ class CassandraMailboxMapperConcurrencyTest { @Test void saveWithUpdateShouldBeThreadSafe() throws Exception { Mailbox mailbox = new Mailbox(MAILBOX_PATH, UID_VALIDITY); - testee.save(mailbox); + testee.rename(mailbox); mailbox.setName("newName"); ConcurrentTestRunner.builder() - .operation((a, b) -> testee.save(mailbox)) + .operation((a, b) -> testee.rename(mailbox)) .threadCount(THREAD_COUNT) .operationCount(OPERATION_COUNT) .runAcceptingErrorsWithin(Duration.ofMinutes(1)); diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapperTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapperTest.java index d5fbf3e..6d414d8 100644 --- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapperTest.java +++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxMapperTest.java @@ -166,7 +166,7 @@ class CassandraMailboxMapperTest { .when(mailboxDAO) .save(inbox); - doQuietly(() -> testee.save(inbox)); + doQuietly(() -> testee.rename(inbox)); SoftAssertions.assertSoftly(softly -> { softly.assertThatThrownBy(() -> testee.findMailboxById(inboxId)) @@ -182,13 +182,13 @@ class CassandraMailboxMapperTest { @Test void saveOnRenameThenFailToRetrieveMailboxShouldBeConsistentWhenFindByInbox() throws Exception { - testee.save(inbox); + testee.rename(inbox); when(mailboxDAO.retrieveMailbox(inboxId)) .thenReturn(Mono.error(new RuntimeException("mock exception"))) .thenCallRealMethod(); - doQuietly(() -> testee.save(inboxRenamed)); + doQuietly(() -> testee.rename(inboxRenamed)); SoftAssertions.assertSoftly(Throwing.consumer(softly -> { softly(softly) @@ -207,13 +207,13 @@ class CassandraMailboxMapperTest { @Disabled("JAMES-3056 returning two mailboxes with same name and id") @Test void saveOnRenameThenFailToRetrieveMailboxShouldBeConsistentWhenFindAll() throws Exception { - testee.save(inbox); + testee.rename(inbox); when(mailboxDAO.retrieveMailbox(inboxId)) .thenReturn(Mono.error(new RuntimeException("mock exception"))) .thenCallRealMethod(); - doQuietly(() -> testee.save(inboxRenamed)); + doQuietly(() -> testee.rename(inboxRenamed)); SoftAssertions.assertSoftly(Throwing.consumer(softly -> { softly.assertThat(testee.findMailboxWithPathLike(allMailboxesSearchQuery)) @@ -226,13 +226,13 @@ class CassandraMailboxMapperTest { @Disabled("JAMES-3056 find by renamed name returns unexpected results") @Test void saveOnRenameThenFailToRetrieveMailboxShouldBeConsistentWhenFindByRenamedInbox() throws Exception { - testee.save(inbox); + testee.rename(inbox); when(mailboxDAO.retrieveMailbox(inboxId)) .thenReturn(Mono.error(new RuntimeException("mock exception"))) .thenCallRealMethod(); - doQuietly(() -> testee.save(inboxRenamed)); + doQuietly(() -> testee.rename(inboxRenamed)); SoftAssertions.assertSoftly(Throwing.consumer(softly -> { softly.assertThatThrownBy(() -> testee.findMailboxByPath(inboxPathRenamed)) @@ -244,13 +244,13 @@ class CassandraMailboxMapperTest { @Test void saveOnRenameThenFailToDeleteMailboxPathShouldBeConsistentWhenFindByInbox() throws Exception { - testee.save(inbox); + testee.rename(inbox); when(mailboxPathV2DAO.delete(inboxPath)) .thenReturn(Mono.error(new RuntimeException("mock exception"))) .thenCallRealMethod(); - doQuietly(() -> testee.save(inboxRenamed)); + doQuietly(() -> testee.rename(inboxRenamed)); SoftAssertions.assertSoftly(Throwing.consumer(softly -> { softly(softly) @@ -269,13 +269,13 @@ class CassandraMailboxMapperTest { @Disabled("JAMES-3056 returning two mailboxes with same name and id") @Test void saveOnRenameThenFailToDeleteMailboxPathShouldBeConsistentWhenFindAll() throws Exception { - testee.save(inbox); + testee.rename(inbox); when(mailboxPathV2DAO.delete(inboxPath)) .thenReturn(Mono.error(new RuntimeException("mock exception"))) .thenCallRealMethod(); - doQuietly(() -> testee.save(inboxRenamed)); + doQuietly(() -> testee.rename(inboxRenamed)); SoftAssertions.assertSoftly(Throwing.consumer(softly -> { softly.assertThat(testee.findMailboxWithPathLike(allMailboxesSearchQuery)) @@ -288,13 +288,13 @@ class CassandraMailboxMapperTest { @Disabled("JAMES-3056 find by renamed name returns unexpected results") @Test void saveOnRenameThenFailToDeleteMailboxPathShouldBeConsistentWhenFindByRenamedInbox() throws Exception { - testee.save(inbox); + testee.rename(inbox); when(mailboxPathV2DAO.delete(inboxPath)) .thenReturn(Mono.error(new RuntimeException("mock exception"))) .thenCallRealMethod(); - doQuietly(() -> testee.save(inboxRenamed)); + doQuietly(() -> testee.rename(inboxRenamed)); SoftAssertions.assertSoftly(Throwing.consumer(softly -> { softly.assertThatThrownBy(() -> testee.findMailboxByPath(inboxPathRenamed)) @@ -307,7 +307,7 @@ class CassandraMailboxMapperTest { @Disabled("JAMES-3056 find by mailbox name returns unexpected results") @Test void deleteShouldBeConsistentWhenFailToDeleteMailbox() throws Exception { - testee.save(inbox); + testee.rename(inbox); doReturn(Mono.error(new RuntimeException("mock exception"))) .when(mailboxDAO) @@ -334,7 +334,7 @@ class CassandraMailboxMapperTest { @Disabled("JAMES-3056 both mailboxes of the same user have 'INBOX' name") @Test void missedMigrationShouldNotLeadToGhostMailbox() throws Exception { - testee.save(inbox); + testee.rename(inbox); // simulate mailbox old data has not been migrated to v2 mailboxPathDAO.save(inboxPath, inboxId).block(); mailboxPathV2DAO.delete(inboxPath).block(); @@ -343,7 +343,7 @@ class CassandraMailboxMapperTest { // => two mailboxes with same name but different ids CassandraId newId = CassandraId.timeBased(); Mailbox mailboxHasSameNameWithInbox = new Mailbox(inboxPath, UID_VALIDITY, newId); - testee.save(mailboxHasSameNameWithInbox); + testee.rename(mailboxHasSameNameWithInbox); assertThat(testee.findMailboxById(newId).getName()) .isNotEqualTo(testee.findMailboxById(inboxId).getName()); @@ -383,8 +383,8 @@ class CassandraMailboxMapperTest { .thenReturn(Mono.error(new RuntimeException("mock exception"))) .thenCallRealMethod(); - doQuietly(() -> testee.save(inbox)); - doQuietly(() -> testee.save(inbox)); + doQuietly(() -> testee.rename(inbox)); + doQuietly(() -> testee.rename(inbox)); SoftAssertions.assertSoftly(Throwing.consumer(softly -> { softly(softly) @@ -410,9 +410,9 @@ class CassandraMailboxMapperTest { .thenReturn(Mono.error(new RuntimeException("mock exception"))) .thenCallRealMethod(); - doQuietly(() -> testee.save(inbox)); + doQuietly(() -> testee.rename(inbox)); doQuietly(() -> testee.delete(inbox)); - doQuietly(() -> testee.save(inbox)); + doQuietly(() -> testee.rename(inbox)); SoftAssertions.assertSoftly(Throwing.consumer(softly -> { softly(softly) @@ -434,7 +434,7 @@ class CassandraMailboxMapperTest { @Test void deleteAfterAFailedDeleteShouldDeleteTheMailbox() throws Exception { - testee.save(inbox); + testee.rename(inbox); when(mailboxDAO.delete(inboxId)) .thenReturn(Mono.error(new RuntimeException("mock exception"))) @@ -459,14 +459,14 @@ class CassandraMailboxMapperTest { "findMailboxWithPathLike() returns a list with two same mailboxes") @Test void renameAfterRenameFailOnRetrieveMailboxShouldRenameTheMailbox() throws Exception { - testee.save(inbox); + testee.rename(inbox); when(mailboxDAO.retrieveMailbox(inboxId)) .thenReturn(Mono.error(new RuntimeException("mock exception"))) .thenCallRealMethod(); - doQuietly(() -> testee.save(inboxRenamed)); - doQuietly(() -> testee.save(inboxRenamed)); + doQuietly(() -> testee.rename(inboxRenamed)); + doQuietly(() -> testee.rename(inboxRenamed)); SoftAssertions.assertSoftly(Throwing.consumer(softly -> { softly(softly) @@ -491,14 +491,14 @@ class CassandraMailboxMapperTest { @Disabled("JAMES-3056 mailbox name is not updated to INBOX_RENAMED") @Test void renameAfterRenameFailOnDeletePathShouldRenameTheMailbox() throws Exception { - testee.save(inbox); + testee.rename(inbox); when(mailboxPathV2DAO.delete(inboxPath)) .thenReturn(Mono.error(new RuntimeException("mock exception"))) .thenCallRealMethod(); - doQuietly(() -> testee.save(inboxRenamed)); - doQuietly(() -> testee.save(inboxRenamed)); + doQuietly(() -> testee.rename(inboxRenamed)); + doQuietly(() -> testee.rename(inboxRenamed)); SoftAssertions.assertSoftly(Throwing.consumer(softly -> { softly(softly) @@ -533,12 +533,12 @@ class CassandraMailboxMapperTest { @Disabled("JAMES-2514 Cassandra 3 supports long mailbox names. Hence we can not rely on this for failing") @Test void saveShouldNotRemoveOldMailboxPathWhenCreatingTheNewMailboxPathFails() throws Exception { - testee.save(new Mailbox(MAILBOX_PATH, UID_VALIDITY)); + testee.rename(new Mailbox(MAILBOX_PATH, UID_VALIDITY)); Mailbox mailbox = testee.findMailboxByPath(MAILBOX_PATH); Mailbox newMailbox = new Mailbox(tooLongMailboxPath(mailbox.generateAssociatedPath()), UID_VALIDITY, mailbox.getMailboxId()); assertThatThrownBy(() -> - testee.save(newMailbox)) + testee.rename(newMailbox)) .isInstanceOf(TooLongMailboxNameException.class); assertThat(mailboxPathV2DAO.retrieveId(MAILBOX_PATH).blockOptional()) diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/migration/MailboxPathV2MigrationTest.java b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/migration/MailboxPathV2MigrationTest.java index 5a7409d..9129b8c 100644 --- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/migration/MailboxPathV2MigrationTest.java +++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/migration/MailboxPathV2MigrationTest.java @@ -93,7 +93,7 @@ class MailboxPathV2MigrationTest { @Test void newValuesShouldBeSavedInMostRecentDAO() throws Exception { - mailboxMapper.save(MAILBOX_1); + mailboxMapper.rename(MAILBOX_1); assertThat(daoV2.retrieveId(MAILBOX_PATH_1).blockOptional()) .contains(new CassandraIdAndPath(MAILBOX_ID_1, MAILBOX_PATH_1)); @@ -101,7 +101,7 @@ class MailboxPathV2MigrationTest { @Test void newValuesShouldNotBeSavedInOldDAO() throws Exception { - mailboxMapper.save(MAILBOX_1); + mailboxMapper.rename(MAILBOX_1); assertThat(daoV1.retrieveId(MAILBOX_PATH_1).blockOptional()) .isEmpty(); diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java index 0b1135f..3e3d61c 100644 --- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java +++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndexTest.java @@ -178,7 +178,7 @@ class ElasticSearchListeningMessageSearchIndexTest { session = sessionProvider.createSystemSession(USERNAME); mailbox = new Mailbox(MailboxPath.forUser(USERNAME, DefaultMailboxes.INBOX), MAILBOX_ID.id); - mapperFactory.getMailboxMapper(session).save(mailbox); + mapperFactory.getMailboxMapper(session).rename(mailbox); } @Test diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMailboxMapper.java b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMailboxMapper.java index 723d239..3d57fbb 100644 --- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMailboxMapper.java +++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMailboxMapper.java @@ -84,7 +84,7 @@ public class JPAMailboxMapper extends JPATransactionalMapper implements MailboxM } @Override - public MailboxId save(Mailbox mailbox) throws MailboxException { + public MailboxId rename(Mailbox mailbox) throws MailboxException { try { if (isPathAlreadyUsedByAnotherMailbox(mailbox)) { throw new MailboxExistsException(mailbox.getName()); diff --git a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/TransactionalMailboxMapper.java b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/TransactionalMailboxMapper.java index 4285f59..a2f3fd5 100644 --- a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/TransactionalMailboxMapper.java +++ b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/TransactionalMailboxMapper.java @@ -53,8 +53,8 @@ public class TransactionalMailboxMapper implements MailboxMapper { } @Override - public MailboxId save(Mailbox mailbox) throws MailboxException { - return wrapped.execute(() -> wrapped.save(mailbox)); + public MailboxId rename(Mailbox mailbox) throws MailboxException { + return wrapped.execute(() -> wrapped.rename(mailbox)); } @Override diff --git a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java index 50232e8..016231e 100644 --- a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java +++ b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMailboxMapper.java @@ -160,7 +160,7 @@ public class MaildirMailboxMapper extends NonTransactionalMapper implements Mail } @Override - public MailboxId save(Mailbox mailbox) throws MailboxException { + public MailboxId rename(Mailbox mailbox) throws MailboxException { MaildirId maildirId = Optional.ofNullable(mailbox.getMailboxId()) .map(mailboxId -> (MaildirId) mailboxId) .orElseGet(MaildirId::random); diff --git a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java index 748e0ff..ac84241 100644 --- a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java +++ b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMailboxMapper.java @@ -92,7 +92,7 @@ public class InMemoryMailboxMapper implements MailboxMapper { } @Override - public MailboxId save(Mailbox mailbox) throws MailboxException { + public MailboxId rename(Mailbox mailbox) throws MailboxException { InMemoryId id = (InMemoryId) mailbox.getMailboxId(); if (id == null) { id = InMemoryId.of(mailboxIdGenerator.incrementAndGet()); diff --git a/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java b/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java index 71ecbb3..160db3e 100644 --- a/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java +++ b/mailbox/plugin/spamassassin/src/test/java/org/apache/james/mailbox/spamassassin/SpamAssassinListenerTest.java @@ -88,12 +88,12 @@ class SpamAssassinListenerTest { inbox = new Mailbox(MailboxPath.forUser(USER, DefaultMailboxes.INBOX), UID_VALIDITY); mailbox1 = new Mailbox(MailboxPath.forUser(USER, "mailbox1"), UID_VALIDITY); mailbox2 = new Mailbox(MailboxPath.forUser(USER, "mailbox2"), UID_VALIDITY); - mailboxMapper.save(inbox); - mailboxId1 = mailboxMapper.save(mailbox1); - mailboxId2 = mailboxMapper.save(mailbox2); - spamMailboxId = mailboxMapper.save(new Mailbox(MailboxPath.forUser(USER, "Spam"), UID_VALIDITY)); - spamCapitalMailboxId = mailboxMapper.save(new Mailbox(MailboxPath.forUser(USER, "SPAM"), UID_VALIDITY)); - trashMailboxId = mailboxMapper.save(new Mailbox(MailboxPath.forUser(USER, "Trash"), UID_VALIDITY)); + mailboxMapper.rename(inbox); + mailboxId1 = mailboxMapper.rename(mailbox1); + mailboxId2 = mailboxMapper.rename(mailbox2); + spamMailboxId = mailboxMapper.rename(new Mailbox(MailboxPath.forUser(USER, "Spam"), UID_VALIDITY)); + spamCapitalMailboxId = mailboxMapper.rename(new Mailbox(MailboxPath.forUser(USER, "SPAM"), UID_VALIDITY)); + trashMailboxId = mailboxMapper.rename(new Mailbox(MailboxPath.forUser(USER, "Trash"), UID_VALIDITY)); listener = new SpamAssassinListener(spamAssassin, systemMailboxesProvider, mailboxManager, mapperFactory, MailboxListener.ExecutionMode.SYNCHRONOUS); } diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java index 31f7f7b..9341913 100644 --- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java +++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java @@ -530,7 +530,7 @@ public class StoreMailboxManager implements MailboxManager { mailbox.setNamespace(newMailboxPath.getNamespace()); mailbox.setUser(newMailboxPath.getUser()); mailbox.setName(newMailboxPath.getName()); - mapper.save(mailbox); + mapper.rename(mailbox); eventBus.dispatch(EventFactory.mailboxRenamed() .randomEventId() @@ -555,7 +555,7 @@ public class StoreMailboxManager implements MailboxManager { String subNewName = newMailboxPath.getName() + subOriginalName.substring(from.getName().length()); MailboxPath fromPath = new MailboxPath(from, subOriginalName); sub.setName(subNewName); - mapper.save(sub); + mapper.rename(sub); eventBus.dispatch(EventFactory.mailboxRenamed() .randomEventId() .mailboxSession(session) diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/MailboxMapper.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/MailboxMapper.java index 65a7489..3e138a7 100644 --- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/MailboxMapper.java +++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/MailboxMapper.java @@ -47,13 +47,13 @@ public interface MailboxMapper extends Mapper { default MailboxId create(Mailbox mailbox) throws MailboxException { Preconditions.checkArgument(mailbox.getMailboxId() == null, "A mailbox we want to create should not have a mailboxId set already"); - return save(mailbox); + return rename(mailbox); } /** - * Save the give {@link Mailbox} to the underlying storage + * Rename the given {@link Mailbox} to the underlying storage */ - MailboxId save(Mailbox mailbox) throws MailboxException; + MailboxId rename(Mailbox mailbox) throws MailboxException; /** * Delete the given {@link Mailbox} from the underlying storage diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MailboxMapperACLTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MailboxMapperACLTest.java index 1815659..41a3c6e 100644 --- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MailboxMapperACLTest.java +++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MailboxMapperACLTest.java @@ -58,7 +58,7 @@ public abstract class MailboxMapperACLTest { mailboxMapper = createMailboxMapper(); MailboxPath benwaInboxPath = MailboxPath.forUser(Username.of("benwa"), "INBOX"); benwaInboxMailbox = createMailbox(benwaInboxPath); - mailboxMapper.save(benwaInboxMailbox); + mailboxMapper.rename(benwaInboxMailbox); } @Test diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MailboxMapperTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MailboxMapperTest.java index 9963ba7..49d29ae 100644 --- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MailboxMapperTest.java +++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MailboxMapperTest.java @@ -123,19 +123,19 @@ public abstract class MailboxMapperTest { } @Test - void saveShouldPersistTheMailbox() throws MailboxException { - mailboxMapper.save(benwaInboxMailbox); + void renameShouldPersistTheMailbox() throws MailboxException { + mailboxMapper.rename(benwaInboxMailbox); assertThat(mailboxMapper.findMailboxByPath(benwaInboxPath)).isEqualTo(benwaInboxMailbox); } @Test - void saveShouldThrowWhenMailboxAlreadyExist() throws MailboxException { - mailboxMapper.save(benwaInboxMailbox); + void renameShouldThrowWhenMailboxAlreadyExist() throws MailboxException { + mailboxMapper.rename(benwaInboxMailbox); Mailbox mailbox = new Mailbox(benwaInboxMailbox); mailbox.setMailboxId(null); - assertThatThrownBy(() -> mailboxMapper.save(mailbox)) + assertThatThrownBy(() -> mailboxMapper.rename(mailbox)) .isInstanceOf(MailboxExistsException.class); } @@ -267,14 +267,14 @@ public abstract class MailboxMapperTest { } private void saveAll() throws MailboxException { - mailboxMapper.save(benwaInboxMailbox); - mailboxMapper.save(benwaWorkMailbox); - mailboxMapper.save(benwaWorkTodoMailbox); - mailboxMapper.save(benwaPersoMailbox); - mailboxMapper.save(benwaWorkDoneMailbox); - mailboxMapper.save(bobyMailbox); - mailboxMapper.save(bobDifferentNamespaceMailbox); - mailboxMapper.save(bobInboxMailbox); + mailboxMapper.rename(benwaInboxMailbox); + mailboxMapper.rename(benwaWorkMailbox); + mailboxMapper.rename(benwaWorkTodoMailbox); + mailboxMapper.rename(benwaPersoMailbox); + mailboxMapper.rename(benwaWorkDoneMailbox); + mailboxMapper.rename(bobyMailbox); + mailboxMapper.rename(bobDifferentNamespaceMailbox); + mailboxMapper.rename(bobInboxMailbox); } private Mailbox createMailbox(MailboxPath mailboxPath) { diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageIdMapperTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageIdMapperTest.java index e286a5b..cbaae3c 100644 --- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageIdMapperTest.java +++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageIdMapperTest.java @@ -960,7 +960,7 @@ public abstract class MessageIdMapperTest { private Mailbox createMailbox(MailboxPath mailboxPath) throws MailboxException { Mailbox mailbox = new Mailbox(mailboxPath, UID_VALIDITY); mailbox.setMailboxId(mapperProvider.generateId()); - mailboxMapper.save(mailbox); + mailboxMapper.rename(mailbox); return mailbox; } diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMapperTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMapperTest.java index bbe4b40..b29e0e6 100644 --- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMapperTest.java +++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMapperTest.java @@ -1190,7 +1190,7 @@ public abstract class MessageMapperTest { Mailbox mailbox = new Mailbox(mailboxPath, UID_VALIDITY); mailbox.setMailboxId(mapperProvider.generateId()); - mailboxMapper.save(mailbox); + mailboxMapper.rename(mailbox); return mailbox; } diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMoveTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMoveTest.java index c531a59..5b82b8c 100644 --- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMoveTest.java +++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMoveTest.java @@ -138,7 +138,7 @@ public abstract class MessageMoveTest { Mailbox mailbox = new Mailbox(mailboxPath, UID_VALIDITY); MailboxId id = mapperProvider.generateId(); mailbox.setMailboxId(id); - mailboxMapper.save(mailbox); + mailboxMapper.rename(mailbox); return mailbox; } diff --git a/server/container/mailbox-jmx/src/test/java/org/apache/james/adapter/mailbox/MailboxManagementTest.java b/server/container/mailbox-jmx/src/test/java/org/apache/james/adapter/mailbox/MailboxManagementTest.java index 1936b8e..2b89bee 100644 --- a/server/container/mailbox-jmx/src/test/java/org/apache/james/adapter/mailbox/MailboxManagementTest.java +++ b/server/container/mailbox-jmx/src/test/java/org/apache/james/adapter/mailbox/MailboxManagementTest.java @@ -65,21 +65,21 @@ public class MailboxManagementTest { @Test void deleteMailboxesShouldDeleteMailboxes() throws Exception { - mapperFactory.createMailboxMapper(session).save(new Mailbox(MailboxPath.forUser(USER, "name"), UID_VALIDITY)); + mapperFactory.createMailboxMapper(session).rename(new Mailbox(MailboxPath.forUser(USER, "name"), UID_VALIDITY)); mailboxManagerManagement.deleteMailboxes(USER.asString()); assertThat(mapperFactory.createMailboxMapper(session).list()).isEmpty(); } @Test void deleteMailboxesShouldDeleteInbox() throws Exception { - mapperFactory.createMailboxMapper(session).save(new Mailbox(MailboxPath.inbox(USER), UID_VALIDITY)); + mapperFactory.createMailboxMapper(session).rename(new Mailbox(MailboxPath.inbox(USER), UID_VALIDITY)); mailboxManagerManagement.deleteMailboxes(USER.asString()); assertThat(mapperFactory.createMailboxMapper(session).list()).isEmpty(); } @Test void deleteMailboxesShouldDeleteMailboxesChildren() throws Exception { - mapperFactory.createMailboxMapper(session).save(new Mailbox(MailboxPath.forUser(USER, "INBOX.test"), UID_VALIDITY)); + mapperFactory.createMailboxMapper(session).rename(new Mailbox(MailboxPath.forUser(USER, "INBOX.test"), UID_VALIDITY)); mailboxManagerManagement.deleteMailboxes(USER.asString()); assertThat(mapperFactory.createMailboxMapper(session).list()).isEmpty(); } @@ -87,7 +87,7 @@ public class MailboxManagementTest { @Test void deleteMailboxesShouldNotDeleteMailboxesBelongingToNotPrivateNamespace() throws Exception { Mailbox mailbox = new Mailbox(new MailboxPath("#top", USER, "name"), UID_VALIDITY); - mapperFactory.createMailboxMapper(session).save(mailbox); + mapperFactory.createMailboxMapper(session).rename(mailbox); mailboxManagerManagement.deleteMailboxes(USER.asString()); assertThat(mapperFactory.createMailboxMapper(session).list()).containsExactly(mailbox); } @@ -95,14 +95,14 @@ public class MailboxManagementTest { @Test void deleteMailboxesShouldNotDeleteMailboxesBelongingToOtherUsers() throws Exception { Mailbox mailbox = new Mailbox(MailboxPath.forUser(Username.of("userbis"), "name"), UID_VALIDITY); - mapperFactory.createMailboxMapper(session).save(mailbox); + mapperFactory.createMailboxMapper(session).rename(mailbox); mailboxManagerManagement.deleteMailboxes(USER.asString()); assertThat(mapperFactory.createMailboxMapper(session).list()).containsExactly(mailbox); } @Test void deleteMailboxesShouldDeleteMailboxesWithEmptyNames() throws Exception { - mapperFactory.createMailboxMapper(session).save(new Mailbox(MailboxPath.forUser(USER, ""), UID_VALIDITY)); + mapperFactory.createMailboxMapper(session).rename(new Mailbox(MailboxPath.forUser(USER, ""), UID_VALIDITY)); mailboxManagerManagement.deleteMailboxes(USER.asString()); assertThat(mapperFactory.createMailboxMapper(session).list()).isEmpty(); } @@ -121,9 +121,9 @@ public class MailboxManagementTest { @Test void deleteMailboxesShouldDeleteMultipleMailboxes() throws Exception { - mapperFactory.createMailboxMapper(session).save(new Mailbox(MailboxPath.forUser(USER, "name"), UID_VALIDITY)); - mapperFactory.createMailboxMapper(session).save(new Mailbox(MailboxPath.forUser(USER, "INBOX"), UID_VALIDITY)); - mapperFactory.createMailboxMapper(session).save(new Mailbox(MailboxPath.forUser(USER, "INBOX.test"), UID_VALIDITY)); + mapperFactory.createMailboxMapper(session).rename(new Mailbox(MailboxPath.forUser(USER, "name"), UID_VALIDITY)); + mapperFactory.createMailboxMapper(session).rename(new Mailbox(MailboxPath.forUser(USER, "INBOX"), UID_VALIDITY)); + mapperFactory.createMailboxMapper(session).rename(new Mailbox(MailboxPath.forUser(USER, "INBOX.test"), UID_VALIDITY)); mailboxManagerManagement.deleteMailboxes(USER.asString()); assertThat(mapperFactory.createMailboxMapper(session).list()).isEmpty(); } @@ -139,7 +139,7 @@ public class MailboxManagementTest { void createMailboxShouldThrowIfMailboxAlreadyExists() throws Exception { MailboxPath path = MailboxPath.forUser(USER, "name"); Mailbox mailbox = new Mailbox(path, UID_VALIDITY); - mapperFactory.createMailboxMapper(session).save(mailbox); + mapperFactory.createMailboxMapper(session).rename(mailbox); assertThatThrownBy(() -> mailboxManagerManagement.createMailbox(MailboxConstants.USER_NAMESPACE, USER.asString(), "name")) .isInstanceOf(RuntimeException.class) @@ -150,7 +150,7 @@ public class MailboxManagementTest { void createMailboxShouldNotCreateAdditionalMailboxesIfMailboxAlreadyExists() throws Exception { MailboxPath path = MailboxPath.forUser(USER, "name"); Mailbox mailbox = new Mailbox(path, UID_VALIDITY); - mapperFactory.createMailboxMapper(session).save(mailbox); + mapperFactory.createMailboxMapper(session).rename(mailbox); assertThat(mapperFactory.createMailboxMapper(session).list()).containsExactly(mailbox); } @@ -199,12 +199,12 @@ public class MailboxManagementTest { Mailbox mailbox4 = new Mailbox(MailboxPath.forUser(USER, "name4"), UID_VALIDITY); Mailbox mailbox5 = new Mailbox(MailboxPath.forUser(USER, "INBOX"), UID_VALIDITY); Mailbox mailbox6 = new Mailbox(MailboxPath.forUser(USER, "INBOX.toto"), UID_VALIDITY); - mapperFactory.createMailboxMapper(session).save(mailbox1); - mapperFactory.createMailboxMapper(session).save(mailbox2); - mapperFactory.createMailboxMapper(session).save(mailbox3); - mapperFactory.createMailboxMapper(session).save(mailbox4); - mapperFactory.createMailboxMapper(session).save(mailbox5); - mapperFactory.createMailboxMapper(session).save(mailbox6); + mapperFactory.createMailboxMapper(session).rename(mailbox1); + mapperFactory.createMailboxMapper(session).rename(mailbox2); + mapperFactory.createMailboxMapper(session).rename(mailbox3); + mapperFactory.createMailboxMapper(session).rename(mailbox4); + mapperFactory.createMailboxMapper(session).rename(mailbox5); + mapperFactory.createMailboxMapper(session).rename(mailbox6); assertThat(mailboxManagerManagement.listMailboxes(USER.asString())).containsOnly("name2", "name4", "INBOX", "INBOX.toto"); } @@ -222,7 +222,7 @@ public class MailboxManagementTest { @Test void deleteMailboxShouldDeleteGivenMailbox() throws Exception { - mapperFactory.createMailboxMapper(session).save(new Mailbox(MailboxPath.forUser(USER, "name"), UID_VALIDITY)); + mapperFactory.createMailboxMapper(session).rename(new Mailbox(MailboxPath.forUser(USER, "name"), UID_VALIDITY)); mailboxManagerManagement.deleteMailbox(MailboxConstants.USER_NAMESPACE, USER.asString(), "name"); assertThat(mapperFactory.createMailboxMapper(session).list()).isEmpty(); } @@ -230,7 +230,7 @@ public class MailboxManagementTest { @Test void deleteMailboxShouldNotDeleteGivenMailboxIfWrongNamespace() throws Exception { Mailbox mailbox = new Mailbox(new MailboxPath("#top", USER, "name"), UID_VALIDITY); - mapperFactory.createMailboxMapper(session).save(mailbox); + mapperFactory.createMailboxMapper(session).rename(mailbox); mailboxManagerManagement.deleteMailbox(MailboxConstants.USER_NAMESPACE, USER.asString(), "name"); assertThat(mapperFactory.createMailboxMapper(session).list()).containsOnly(mailbox); } @@ -238,7 +238,7 @@ public class MailboxManagementTest { @Test void deleteMailboxShouldNotDeleteGivenMailboxIfWrongUser() throws Exception { Mailbox mailbox = new Mailbox(MailboxPath.forUser(Username.of("userbis"), "name"), UID_VALIDITY); - mapperFactory.createMailboxMapper(session).save(mailbox); + mapperFactory.createMailboxMapper(session).rename(mailbox); mailboxManagerManagement.deleteMailbox(MailboxConstants.USER_NAMESPACE, USER.asString(), "name"); assertThat(mapperFactory.createMailboxMapper(session).list()).containsOnly(mailbox); } @@ -246,7 +246,7 @@ public class MailboxManagementTest { @Test void deleteMailboxShouldNotDeleteGivenMailboxIfWrongName() throws Exception { Mailbox mailbox = new Mailbox(MailboxPath.forUser(USER, "wrong_name"), UID_VALIDITY); - mapperFactory.createMailboxMapper(session).save(mailbox); + mapperFactory.createMailboxMapper(session).rename(mailbox); mailboxManagerManagement.deleteMailbox(MailboxConstants.USER_NAMESPACE, USER.asString(), "name"); assertThat(mapperFactory.createMailboxMapper(session).list()).containsOnly(mailbox); } @@ -255,7 +255,7 @@ public class MailboxManagementTest { void importEmlFileToMailboxShouldImportEmlFileToGivenMailbox() throws Exception { Mailbox mailbox = new Mailbox(MailboxPath.forUser(USER, "name"), UID_VALIDITY); - mapperFactory.createMailboxMapper(session).save(mailbox); + mapperFactory.createMailboxMapper(session).rename(mailbox); String emlpath = ClassLoader.getSystemResource("eml/frnog.eml").getFile(); mailboxManagerManagement.importEmlFileToMailbox(MailboxConstants.USER_NAMESPACE, USER.asString(), "name", emlpath); @@ -272,7 +272,7 @@ public class MailboxManagementTest { void importEmlFileToMailboxShouldNotImportEmlFileWithWrongPathToGivenMailbox() throws Exception { Mailbox mailbox = new Mailbox(MailboxPath.forUser(USER, "name"), UID_VALIDITY); - mapperFactory.createMailboxMapper(session).save(mailbox); + mapperFactory.createMailboxMapper(session).rename(mailbox); String emlpath = ClassLoader.getSystemResource("eml/frnog.eml").getFile(); mailboxManagerManagement.importEmlFileToMailbox(MailboxConstants.USER_NAMESPACE, USER.asString(), "name", "wrong_path" + emlpath); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
