Repository: james-project Updated Branches: refs/heads/master f9f6e8499 -> 68ab61763
JAMES-1712 Introduce MailboxUtils in order to share common MailboxManager usage Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/166ee8f3 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/166ee8f3 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/166ee8f3 Branch: refs/heads/master Commit: 166ee8f36d9f1e9aaec1a6a570e23163ec0dbfa3 Parents: 64ff43e Author: Antoine Duprat <[email protected]> Authored: Thu Mar 31 11:22:08 2016 +0200 Committer: Antoine Duprat <[email protected]> Committed: Mon Apr 4 16:27:11 2016 +0200 ---------------------------------------------------------------------- mailbox/api/pom.xml | 16 ++ mailbox/memory/pom.xml | 16 ++ server/pom.xml | 13 ++ server/protocols/jmap/pom.xml | 12 ++ .../james/jmap/methods/GetMailboxesMethod.java | 49 +----- .../apache/james/jmap/utils/MailboxUtils.java | 119 ++++++++++++++ .../jmap/methods/GetMailboxesMethodTest.java | 7 +- .../james/jmap/utils/MailboxUtilsTest.java | 164 +++++++++++++++++++ 8 files changed, 350 insertions(+), 46 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/166ee8f3/mailbox/api/pom.xml ---------------------------------------------------------------------- diff --git a/mailbox/api/pom.xml b/mailbox/api/pom.xml index 964bf82..c8a2d9e 100644 --- a/mailbox/api/pom.xml +++ b/mailbox/api/pom.xml @@ -76,4 +76,20 @@ <scope>test</scope> </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/166ee8f3/mailbox/memory/pom.xml ---------------------------------------------------------------------- diff --git a/mailbox/memory/pom.xml b/mailbox/memory/pom.xml index 4a9ad04..a08a5d1 100644 --- a/mailbox/memory/pom.xml +++ b/mailbox/memory/pom.xml @@ -81,4 +81,20 @@ <scope>test</scope> </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/166ee8f3/server/pom.xml ---------------------------------------------------------------------- diff --git a/server/pom.xml b/server/pom.xml index 5a4e8e6..4b4863f 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -604,6 +604,13 @@ </dependency> <dependency> <groupId>org.apache.james</groupId> + <artifactId>apache-james-mailbox-memory</artifactId> + <version>${mailbox.version}</version> + <type>test-jar</type> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.james</groupId> <artifactId>apache-james-mailbox-cassandra</artifactId> <version>${mailbox.version}</version> </dependency> @@ -625,6 +632,12 @@ </dependency> <dependency> <groupId>org.apache.james</groupId> + <artifactId>apache-james-mailbox-api</artifactId> + <version>${mailbox.version}</version> + <type>test-jar</type> + </dependency> + <dependency> + <groupId>org.apache.james</groupId> <artifactId>apache-james-mailbox-elasticsearch</artifactId> <version>${mailbox.version}</version> </dependency> http://git-wip-us.apache.org/repos/asf/james-project/blob/166ee8f3/server/protocols/jmap/pom.xml ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/pom.xml b/server/protocols/jmap/pom.xml index 296d752..e088819 100644 --- a/server/protocols/jmap/pom.xml +++ b/server/protocols/jmap/pom.xml @@ -158,11 +158,23 @@ </dependency> <dependency> <groupId>org.apache.james</groupId> + <artifactId>apache-james-mailbox-api</artifactId> + <scope>test</scope> + <type>test-jar</type> + </dependency> + <dependency> + <groupId>org.apache.james</groupId> <artifactId>apache-james-mailbox-memory</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.james</groupId> + <artifactId>apache-james-mailbox-memory</artifactId> + <scope>test</scope> + <type>test-jar</type> + </dependency> + <dependency> + <groupId>org.apache.james</groupId> <artifactId>apache-james-mailbox-store</artifactId> </dependency> <dependency> http://git-wip-us.apache.org/repos/asf/james-project/blob/166ee8f3/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java index 53a22e2..d5f63b6 100644 --- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java @@ -32,20 +32,13 @@ import org.apache.james.jmap.model.GetMailboxesRequest; import org.apache.james.jmap.model.GetMailboxesResponse; import org.apache.james.jmap.model.MailboxProperty; import org.apache.james.jmap.model.mailbox.Mailbox; -import org.apache.james.jmap.model.mailbox.Role; -import org.apache.james.jmap.model.mailbox.SortOrder; +import org.apache.james.jmap.utils.MailboxUtils; import org.apache.james.mailbox.MailboxManager; import org.apache.james.mailbox.MailboxSession; -import org.apache.james.mailbox.MessageManager; -import org.apache.james.mailbox.MessageManager.MetaData.FetchGroup; import org.apache.james.mailbox.exception.MailboxException; import org.apache.james.mailbox.model.MailboxMetaData; -import org.apache.james.mailbox.model.MailboxPath; import org.apache.james.mailbox.model.MailboxQuery; -import org.apache.james.mailbox.store.mail.MailboxMapperFactory; import org.apache.james.mailbox.store.mail.model.MailboxId; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; @@ -56,18 +49,16 @@ import com.google.common.collect.Sets; public class GetMailboxesMethod<Id extends MailboxId> implements Method { - private static final boolean DONT_RESET_RECENT = false; - private static final Logger LOGGER = LoggerFactory.getLogger(GetMailboxesMethod.class); private static final Method.Request.Name METHOD_NAME = Method.Request.name("getMailboxes"); private static final Method.Response.Name RESPONSE_NAME = Method.Response.name("mailboxes"); private final MailboxManager mailboxManager; - private final MailboxMapperFactory<Id> mailboxMapperFactory; + private final MailboxUtils<Id> mailboxUtils; @Inject - @VisibleForTesting public GetMailboxesMethod(MailboxManager mailboxManager, MailboxMapperFactory<Id> mailboxMapperFactory) { + @VisibleForTesting public GetMailboxesMethod(MailboxManager mailboxManager, MailboxUtils<Id> mailboxUtils) { this.mailboxManager = mailboxManager; - this.mailboxMapperFactory = mailboxMapperFactory; + this.mailboxUtils = mailboxUtils; } @Override @@ -101,7 +92,7 @@ public class GetMailboxesMethod<Id extends MailboxId> implements Method { retrieveUserMailboxes(mailboxSession) .stream() .map(MailboxMetaData::getPath) - .map(mailboxPath -> mailboxFromMailboxPath(mailboxPath, mailboxSession)) + .map(mailboxPath -> mailboxUtils.mailboxFromMailboxPath(mailboxPath, mailboxSession)) .filter(Optional::isPresent) .map(Optional::get) .filter(filterMailboxesById(mailboxesRequest.getIds())) @@ -123,34 +114,4 @@ public class GetMailboxesMethod<Id extends MailboxId> implements Method { session); } - private Optional<Mailbox> mailboxFromMailboxPath(MailboxPath mailboxPath, MailboxSession mailboxSession) { - try { - Optional<Role> role = Role.from(mailboxPath.getName()); - MessageManager.MetaData mailboxMetaData = getMailboxMetaData(mailboxPath, mailboxSession); - return Optional.ofNullable(Mailbox.builder() - .id(getMailboxId(mailboxPath, mailboxSession)) - .name(mailboxPath.getName()) - .role(role) - .unreadMessages(mailboxMetaData.getUnseenCount()) - .totalMessages(mailboxMetaData.getMessageCount()) - .sortOrder(SortOrder.getSortOrder(role)) - .build()); - } catch (MailboxException e) { - LOGGER.warn("Cannot find mailbox for :" + mailboxPath.getName(), e); - return Optional.empty(); - } - } - - private String getMailboxId(MailboxPath mailboxPath, MailboxSession mailboxSession) throws MailboxException { - return mailboxMapperFactory.getMailboxMapper(mailboxSession) - .findMailboxByPath(mailboxPath) - .getMailboxId() - .serialize(); - } - - private MessageManager.MetaData getMailboxMetaData(MailboxPath mailboxPath, MailboxSession mailboxSession) throws MailboxException { - return mailboxManager.getMailbox(mailboxPath, mailboxSession) - .getMetaData(DONT_RESET_RECENT, mailboxSession, FetchGroup.UNSEEN_COUNT); - } - } http://git-wip-us.apache.org/repos/asf/james-project/blob/166ee8f3/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailboxUtils.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailboxUtils.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailboxUtils.java new file mode 100644 index 0000000..b8128e3 --- /dev/null +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailboxUtils.java @@ -0,0 +1,119 @@ +/**************************************************************** +O * 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.utils; + +import java.util.List; +import java.util.Optional; + +import javax.inject.Inject; + +import org.apache.james.jmap.model.mailbox.Mailbox; +import org.apache.james.jmap.model.mailbox.Role; +import org.apache.james.jmap.model.mailbox.SortOrder; +import org.apache.james.mailbox.MailboxManager; +import org.apache.james.mailbox.MailboxSession; +import org.apache.james.mailbox.MessageManager; +import org.apache.james.mailbox.exception.MailboxException; +import org.apache.james.mailbox.model.MailboxPath; +import org.apache.james.mailbox.store.mail.MailboxMapperFactory; +import org.apache.james.mailbox.store.mail.model.MailboxId; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Splitter; + +public class MailboxUtils<Id extends MailboxId> { + + private static final boolean DONT_RESET_RECENT = false; + private static final Logger LOGGER = LoggerFactory.getLogger(MailboxUtils.class); + + private final MailboxManager mailboxManager; + private final MailboxMapperFactory<Id> mailboxMapperFactory; + + @Inject + @VisibleForTesting + public MailboxUtils(MailboxManager mailboxManager, MailboxMapperFactory<Id> mailboxMapperFactory) { + this.mailboxManager = mailboxManager; + this.mailboxMapperFactory = mailboxMapperFactory; + } + + public Optional<Mailbox> mailboxFromMailboxPath(MailboxPath mailboxPath, MailboxSession mailboxSession) { + try { + Optional<Role> role = Role.from(mailboxPath.getName()); + MessageManager.MetaData mailboxMetaData = getMailboxMetaData(mailboxPath, mailboxSession); + String mailboxId = getMailboxId(mailboxPath, mailboxSession); + return Optional.ofNullable(Mailbox.builder() + .id(mailboxId) + .name(getName(mailboxPath, mailboxSession)) + .parentId(getParentIdFromMailboxPath(mailboxPath, mailboxSession)) + .role(role) + .unreadMessages(mailboxMetaData.getUnseenCount()) + .totalMessages(mailboxMetaData.getMessageCount()) + .sortOrder(SortOrder.getSortOrder(role)) + .build()); + } catch (MailboxException e) { + LOGGER.warn("Cannot find mailbox for :" + mailboxPath.getName(), e); + return Optional.empty(); + } + } + + private String getMailboxId(MailboxPath mailboxPath, MailboxSession mailboxSession) throws MailboxException { + return mailboxMapperFactory.getMailboxMapper(mailboxSession) + .findMailboxByPath(mailboxPath) + .getMailboxId() + .serialize(); + } + + private MessageManager.MetaData getMailboxMetaData(MailboxPath mailboxPath, MailboxSession mailboxSession) throws MailboxException { + return mailboxManager.getMailbox(mailboxPath, mailboxSession) + .getMetaData(DONT_RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.UNSEEN_COUNT); + } + + @VisibleForTesting String getName(MailboxPath mailboxPath, MailboxSession mailboxSession) { + String name = mailboxPath.getName(); + if (name.contains(String.valueOf(mailboxSession.getPathDelimiter()))) { + List<String> levels = Splitter.on(mailboxSession.getPathDelimiter()).splitToList(name); + return levels.get(levels.size() - 1); + } + return name; + } + + public Optional<String> getMailboxNameFromId(String mailboxId, MailboxSession mailboxSession) throws MailboxException { + return getMailboxFromId(mailboxId, mailboxSession) + .map(org.apache.james.mailbox.store.mail.model.Mailbox::getName); + } + + private Optional<org.apache.james.mailbox.store.mail.model.Mailbox<Id>> getMailboxFromId(String mailboxId, MailboxSession mailboxSession) throws MailboxException { + return mailboxMapperFactory.getMailboxMapper(mailboxSession) + .list().stream() + .filter(mailbox -> mailbox.getMailboxId().serialize().equals(mailboxId)) + .findFirst(); + } + + @VisibleForTesting String getParentIdFromMailboxPath(MailboxPath mailboxPath, MailboxSession mailboxSession) throws MailboxException { + List<MailboxPath> levels = mailboxPath.getHierarchyLevels(mailboxSession.getPathDelimiter()); + if (levels.size() <= 1) { + return null; + } + MailboxPath parent = levels.get(levels.size() - 2); + return getMailboxId(parent, mailboxSession); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/166ee8f3/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java index 08f8ef3..fbbcaf1 100644 --- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java @@ -37,6 +37,7 @@ import org.apache.james.jmap.model.GetMailboxesResponse; import org.apache.james.jmap.model.mailbox.Mailbox; import org.apache.james.jmap.model.mailbox.Role; import org.apache.james.jmap.model.mailbox.SortOrder; +import org.apache.james.jmap.utils.MailboxUtils; import org.apache.james.mailbox.MailboxManager; import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.MessageManager; @@ -69,6 +70,7 @@ public class GetMailboxesMethodTest { private GetMailboxesMethod<InMemoryId> getMailboxesMethod; private ClientId clientId; private InMemoryMailboxSessionMapperFactory mailboxMapperFactory; + private MailboxUtils<InMemoryId> mailboxUtils; @Before public void setup() throws Exception { @@ -78,8 +80,9 @@ public class GetMailboxesMethodTest { GroupMembershipResolver groupMembershipResolver = new SimpleGroupMembershipResolver(); mailboxManager = new StoreMailboxManager<>(mailboxMapperFactory, new MockAuthenticator(), aclResolver, groupMembershipResolver); mailboxManager.init(); + mailboxUtils = new MailboxUtils<>(mailboxManager, mailboxMapperFactory); - getMailboxesMethod = new GetMailboxesMethod<>(mailboxManager, mailboxMapperFactory); + getMailboxesMethod = new GetMailboxesMethod<>(mailboxManager, mailboxUtils); } @Test @@ -107,7 +110,7 @@ public class GetMailboxesMethodTest { .thenReturn(ImmutableList.of(new MailboxPath("namespace", "user", "name"))); when(mockedMailboxManager.getMailbox(any(), any())) .thenThrow(new MailboxException()); - GetMailboxesMethod<InMemoryId> testee = new GetMailboxesMethod<>(mockedMailboxManager, mailboxMapperFactory); + GetMailboxesMethod<InMemoryId> testee = new GetMailboxesMethod<>(mockedMailboxManager, mailboxUtils); GetMailboxesRequest getMailboxesRequest = GetMailboxesRequest.builder() .build(); http://git-wip-us.apache.org/repos/asf/james-project/blob/166ee8f3/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/MailboxUtilsTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/MailboxUtilsTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/MailboxUtilsTest.java new file mode 100644 index 0000000..f6a4a89 --- /dev/null +++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/MailboxUtilsTest.java @@ -0,0 +1,164 @@ +/**************************************************************** + * 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.utils; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Optional; + +import org.apache.james.jmap.model.mailbox.Mailbox; +import org.apache.james.mailbox.MailboxManager; +import org.apache.james.mailbox.MailboxSession; +import org.apache.james.mailbox.inmemory.InMemoryId; +import org.apache.james.mailbox.inmemory.InMemoryMailboxSessionMapperFactory; +import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources; +import org.apache.james.mailbox.model.MailboxPath; +import org.apache.james.mailbox.store.mail.MailboxMapperFactory; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class MailboxUtilsTest { + + private static final Logger LOGGER = LoggerFactory.getLogger(MailboxUtilsTest.class); + + private MailboxManager mailboxManager; + private MailboxMapperFactory<InMemoryId> mailboxMapperFactory; + private MailboxSession mailboxSession; + private MailboxUtils<InMemoryId> sut; + + @Before + public void setup() throws Exception { + InMemoryIntegrationResources inMemoryIntegrationResources = new InMemoryIntegrationResources(); + mailboxManager = inMemoryIntegrationResources.createMailboxManager(inMemoryIntegrationResources.createGroupMembershipResolver()); + mailboxMapperFactory = new InMemoryMailboxSessionMapperFactory(); + mailboxSession = mailboxManager.login("[email protected]", "pass", LOGGER); + sut = new MailboxUtils<>(mailboxManager, mailboxMapperFactory); + } + + @Test + public void mailboxFromMailboxPathShouldReturnNotEmptyWhenMailboxExists() throws Exception { + MailboxPath mailboxPath = new MailboxPath("#private", "user", "mailbox"); + mailboxManager.createMailbox(mailboxPath, mailboxSession); + + Optional<Mailbox> optionalMailbox = sut.mailboxFromMailboxPath(mailboxPath, mailboxSession); + assertThat(optionalMailbox).isPresent(); + Mailbox mailbox = optionalMailbox.get(); + assertThat(mailbox.getId()).isNotEmpty(); + } + + @Test + public void mailboxFromMailboxPathShouldReturnEmptyWhenMailboxDoesntExist() throws Exception { + MailboxPath mailboxPath = new MailboxPath("#private", "user", "mailbox"); + + Optional<Mailbox> optionalMailbox = sut.mailboxFromMailboxPath(mailboxPath, mailboxSession); + assertThat(optionalMailbox).isEmpty(); + } + + @Test + public void getNameShouldReturnMailboxNameWhenRootMailbox() throws Exception { + String expected = "mailbox"; + MailboxPath mailboxPath = new MailboxPath("#private", "user", expected); + + String name = sut.getName(mailboxPath, mailboxSession); + assertThat(name).isEqualTo(expected); + } + + @Test + public void getNameShouldReturnMailboxNameWhenChildMailbox() throws Exception { + String expected = "mailbox"; + MailboxPath mailboxPath = new MailboxPath("#private", "user", "inbox." + expected); + + String name = sut.getName(mailboxPath, mailboxSession); + assertThat(name).isEqualTo(expected); + } + + @Test + public void getNameShouldReturnMailboxNameWhenChildOfChildMailbox() throws Exception { + String expected = "mailbox"; + MailboxPath mailboxPath = new MailboxPath("#private", "user", "inbox.children." + expected); + + String name = sut.getName(mailboxPath, mailboxSession); + assertThat(name).isEqualTo(expected); + } + + @Test + public void getMailboxNameFromIdShouldReturnNotEmptyWhenMailboxExists() throws Exception { + String expected = "mailbox"; + MailboxPath mailboxPath = new MailboxPath("#private", "user", expected); + mailboxManager.createMailbox(mailboxPath, mailboxSession); + InMemoryId mailboxId = mailboxMapperFactory.getMailboxMapper(mailboxSession) + .findMailboxByPath(mailboxPath) + .getMailboxId(); + + Optional<String> optionalName = sut.getMailboxNameFromId(mailboxId.serialize(), mailboxSession); + assertThat(optionalName).isPresent(); + String name = optionalName.get(); + assertThat(name).isEqualTo(expected); + } + + @Test + public void getMailboxNameFromIdShouldReturnEmptyWhenMailboxDoesntExist() throws Exception { + Optional<String> optionalName = sut.getMailboxNameFromId("unknown", mailboxSession); + assertThat(optionalName).isEmpty(); + } + + @Test + public void getParentIdFromMailboxPathShouldReturNullWhenRootMailbox() throws Exception { + MailboxPath mailboxPath = new MailboxPath("#private", "user", "mailbox"); + mailboxManager.createMailbox(mailboxPath, mailboxSession); + + String id = sut.getParentIdFromMailboxPath(mailboxPath, mailboxSession); + assertThat(id).isNull(); + } + + @Test + public void getParentIdFromMailboxPathShouldReturnParentIdWhenChildMailbox() throws Exception { + MailboxPath parentMailboxPath = new MailboxPath("#private", "user", "inbox"); + mailboxManager.createMailbox(parentMailboxPath, mailboxSession); + InMemoryId parentId = mailboxMapperFactory.getMailboxMapper(mailboxSession) + .findMailboxByPath(parentMailboxPath) + .getMailboxId(); + + MailboxPath mailboxPath = new MailboxPath("#private", "user", "inbox.mailbox"); + mailboxManager.createMailbox(mailboxPath, mailboxSession); + + String id = sut.getParentIdFromMailboxPath(mailboxPath, mailboxSession); + assertThat(id).isEqualTo(parentId.serialize()); + } + + @Test + public void getParentIdFromMailboxPathShouldReturnParentIdWhenChildOfChildMailbox() throws Exception { + MailboxPath mailboxPath = new MailboxPath("#private", "user", "inbox.children.mailbox"); + mailboxManager.createMailbox(new MailboxPath("#private", "user", "inbox"), mailboxSession); + + MailboxPath parentMailboxPath = new MailboxPath("#private", "user", "inbox.children"); + mailboxManager.createMailbox(parentMailboxPath, mailboxSession); + InMemoryId parentId = mailboxMapperFactory.getMailboxMapper(mailboxSession) + .findMailboxByPath(parentMailboxPath) + .getMailboxId(); + + mailboxManager.createMailbox(mailboxPath, mailboxSession); + + String id = sut.getParentIdFromMailboxPath(mailboxPath, mailboxSession); + assertThat(id).isEqualTo(parentId.serialize()); + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
