private MailboxPath buildMailboxPath(String namespace, String user, String mailboxName) { if (!namespace.equals(MailboxConstants.USER_NAMESPACE)) { throw new DeniedAccessOnSharedMailboxException(); } return new MailboxPath(namespace, user, sanitizeMailboxName(mailboxName)); }
private CassandraIdAndPath fromRowToCassandraIdAndPath(Row row) { return new CassandraIdAndPath( CassandraId.of(row.getUUID(MAILBOX_ID)), new MailboxPath(row.getString(NAMESPACE), row.getString(USER), row.getString(MAILBOX_NAME))); }
@Override public MailboxId getMailboxId(String namespace, String user, String name) { MailboxSession mailboxSession = null; try { mailboxSession = mailboxManager.createSystemSession(user); MailboxMapper mailboxMapper = mailboxMapperFactory.getMailboxMapper(mailboxSession); return mailboxMapper.findMailboxByPath(new MailboxPath(namespace, user, name)).getMailboxId(); } catch (MailboxException e) { throw new RuntimeException(e); } finally { closeSession(mailboxSession); } }
@Test public void buildPathShouldAcceptEmpty() { assertThat(pathConverter.buildFullPath("")) .isEqualTo(new MailboxPath("", "", "")); }
@Test public void isInboxShouldReturnTrueWhenINBOXWithOtherCase() { MailboxPath mailboxPath = new MailboxPath(MailboxConstants.USER_NAMESPACE, "user", "InBoX"); assertThat(mailboxPath.isInbox()).isTrue(); }
@Test public void isInboxShouldReturnFalseWhenOtherThanInbox() { MailboxPath mailboxPath = new MailboxPath(MailboxConstants.USER_NAMESPACE, "user", DefaultMailboxes.ARCHIVE); assertThat(mailboxPath.isInbox()).isFalse(); } }
@Test public void belongsToNamespaceAndUserShouldReturnTrueWithMailboxWithSameNamespaceAndUserWithNullUser() { MailboxQuery mailboxQuery = MailboxQuery.builder() .userAndNamespaceFrom(new MailboxPath("namespace", null, "name")) .build(); assertThat(mailboxQuery.belongsToRequestedNamespaceAndUser(new MailboxPath("namespace", null, "name"))) .isTrue(); }
@Test public void belongsToNamespaceAndUserShouldReturnTrueWithMailboxWithSameNamespaceAndUser() { MailboxQuery mailboxQuery = MailboxQuery.builder() .userAndNamespaceFrom(new MailboxPath("namespace", CURRENT_USER, "name")) .build(); assertThat(mailboxQuery.belongsToRequestedNamespaceAndUser(new MailboxPath("namespace", CURRENT_USER, "name2"))) .isTrue(); }
@Test public void belongsToNamespaceAndUserShouldReturnFalseWithDifferentUser() { MailboxQuery mailboxQuery = MailboxQuery.builder() .userAndNamespaceFrom(new MailboxPath("namespace", CURRENT_USER, "name")) .build(); assertThat(mailboxQuery.belongsToRequestedNamespaceAndUser(new MailboxPath("namespace", CURRENT_USER + "2", "name"))) .isFalse(); }
@Test public void belongsToNamespaceAndUserShouldReturnFalseWithOneOfTheUserNull() { MailboxQuery mailboxQuery = MailboxQuery.builder() .userAndNamespaceFrom(new MailboxPath("namespace", CURRENT_USER, "name")) .build(); assertThat(mailboxQuery.belongsToRequestedNamespaceAndUser(new MailboxPath("namespace", null, "name"))) .isFalse(); }
@Test public void belongsToNamespaceAndUserShouldReturnFalseWhenDifferentUser() { MailboxQuery mailboxQuery = MailboxQuery.builder() .userAndNamespaceFrom(new MailboxPath("namespace", CURRENT_USER, "name")) .build(); assertThat(mailboxQuery.belongsToRequestedNamespaceAndUser(new MailboxPath("namespace", "other", "name"))) .isFalse(); }
@Ignore("Shared mailbox is not supported yet") @Test public void buildFullPathShouldAcceptNamespacePrefix() { assertThat(pathConverter.buildFullPath("#")) .isEqualTo(new MailboxPath("#", null, "")); }
@Ignore("Shared mailbox is not supported yet") @Test public void buildFullPathShouldAcceptNamespaceAndDelimiter() { String namespace = "#any"; assertThat(pathConverter.buildFullPath(namespace + PATH_DELIMITER)) .isEqualTo(new MailboxPath(namespace, null, "")); }
@Ignore("Shared mailbox is not supported yet") @Test public void buildFullPathShouldAcceptFullAbsolutePath() { String namespace = "#any"; String mailboxName = "mailboxName"; assertThat(pathConverter.buildFullPath(namespace + PATH_DELIMITER + mailboxName)) .isEqualTo(new MailboxPath(namespace, null, mailboxName)); }
@Test public void listShouldNotListMailboxWithOtherNamespaceITALY() throws Exception { Assume.assumeTrue(system.supports(Feature.NAMESPACE_SUPPORT)); system.createMailbox(new MailboxPath("#namespace", USER, "Other")); simpleScriptedTestProtocol .withLocale(Locale.ITALY) .run("ListMailboxes"); }
@Test public void belongsToNamespaceAndUserShouldReturnTrueWithIdenticalMailboxesWithNullUser() { MailboxPath base = new MailboxPath("namespace", null, "name"); MailboxQuery mailboxQuery = MailboxQuery.builder() .userAndNamespaceFrom(base) .build(); assertThat(mailboxQuery.belongsToRequestedNamespaceAndUser(mailboxPath)) .isTrue(); }
@Test void mailboxPathWithNoUserShouldBeWellDeSerialized() { assertThat(DTO_JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" + " \"namespace\":\"#private\"," + " \"name\":\"mailboxName\"" + "}")).get()) .isEqualTo(DTOs.MailboxPath$.MODULE$.fromJava( new MailboxPath(MailboxConstants.USER_NAMESPACE, null, MAILBOX_NAME))); }
@Test void mailboxPathDeserializationShouldFailWhenNullNamespace() { assertThat(DTO_JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" + " \"namespace\":null," + " \"user\":\"user\"," + " \"name\":\"mailboxName\"" + "}")) .get().toJava()) .isEqualTo(new MailboxPath(MailboxConstants.USER_NAMESPACE, "user", MAILBOX_NAME)); }
@Test void mailboxPathWithNullUserShouldBeWellDeSerialized() { assertThat(DTO_JSON_SERIALIZE.mailboxPathReads().reads(Json.parse("{" + " \"namespace\":\"#private\"," + " \"user\":null," + " \"name\":\"mailboxName\"" + "}")).get()) .isEqualTo(DTOs.MailboxPath$.MODULE$.fromJava( new MailboxPath(MailboxConstants.USER_NAMESPACE, null, MAILBOX_NAME))); }
@Test void mailboxPathWithNullUserShouldBeWellSerialized() { assertThatJson(DTO_JSON_SERIALIZE.mailboxPathWrites().writes(DTOs.MailboxPath$.MODULE$.fromJava( new MailboxPath(MailboxConstants.USER_NAMESPACE, null, MAILBOX_NAME))).toString()) .isEqualTo( "{" + " \"namespace\":\"#private\"," + " \"name\":\"mailboxName\"" + "}"); }