james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rouaz...@apache.org
Subject [06/10] james-project git commit: MAILBOX-270: getmetadata command, mailbox api support get annotation by depth
Date Wed, 31 Aug 2016 08:06:55 GMT
MAILBOX-270: getmetadata command, mailbox api support get annotation by depth


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/7ac9840d
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/7ac9840d
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/7ac9840d

Branch: refs/heads/master
Commit: 7ac9840df8198e488564589c7fd8a8610ae928f5
Parents: 0d3c88b
Author: Quynh Nguyen <qnguyen@linagora.com>
Authored: Tue Jul 5 14:09:04 2016 +0700
Committer: Quynh Nguyen <qnguyen@linagora.com>
Committed: Tue Aug 30 09:35:06 2016 +0700

----------------------------------------------------------------------
 .../apache/james/mailbox/MailboxManager.java    | 33 +++++++-
 .../james/mailbox/model/MailboxAnnotation.java  | 47 +++--------
 .../mailbox/model/MailboxAnnotationKey.java     | 88 ++++++++++++++++++++
 .../james/mailbox/MailboxManagerTest.java       | 61 +++++++++++---
 .../mailbox/model/MailboxAnnotationTest.java    | 48 +++++++----
 .../base/MailboxEventAnalyserTest.java          | 15 +++-
 .../FirstUserConnectionFilterThreadTest.java    | 15 +++-
 7 files changed, 239 insertions(+), 68 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/7ac9840d/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxManager.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxManager.java b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxManager.java
index 2eac8c3..e2cbdac 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxManager.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxManager.java
@@ -33,6 +33,7 @@ import org.apache.james.mailbox.exception.UnsupportedRightException;
 import org.apache.james.mailbox.model.MailboxACL;
 import org.apache.james.mailbox.model.MailboxAnnotation;
 import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.mailbox.model.MailboxAnnotationKey;
 import org.apache.james.mailbox.model.MailboxMetaData;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MailboxQuery;
@@ -369,7 +370,8 @@ public interface MailboxManager extends RequestAware, MailboxListenerSupport
{
     List<MailboxPath> list(MailboxSession session) throws MailboxException;
 
     /**
-     * Return all mailbox's annotation as the {@link List} of {@link MailboxAnnotation} without
order and not duplicated by key
+     * Return all mailbox's annotation as the {@link List} of {@link MailboxAnnotation} without
order and
+     * do not contain any two annotations with the same key
      * 
      * @param mailboxPath   the current mailbox
      * @param session       the current session
@@ -379,7 +381,8 @@ public interface MailboxManager extends RequestAware, MailboxListenerSupport
{
     List<MailboxAnnotation> getAllAnnotations(MailboxPath mailboxPath, MailboxSession
session) throws MailboxException;
 
     /**
-     * Return all mailbox's annotation filter by the list of the keys without order and not
duplicated by key
+     * Return all mailbox's annotation filter by the list of the keys without order and
+     * do not contain any two annotations with the same key
      * 
      * @param mailboxPath   the current mailbox
      * @param session       the current session
@@ -387,7 +390,31 @@ public interface MailboxManager extends RequestAware, MailboxListenerSupport
{
      * @return              List<MailboxAnnotation>
      * @throws MailboxException in case of selected mailbox does not exist
      */
-    List<MailboxAnnotation> getAnnotationsByKeys(MailboxPath mailboxPath, MailboxSession
session, Set<String> keys) throws MailboxException;
+    List<MailboxAnnotation> getAnnotationsByKeys(MailboxPath mailboxPath, MailboxSession
session, Set<MailboxAnnotationKey> keys) throws MailboxException;
+
+    /**
+     * Return all mailbox's annotation by the list of the keys and its children entries without
order and
+     * do not contain any two annotations with the same key
+     *
+     * @param mailboxPath   the current mailbox
+     * @param session       the current session
+     * @param keys          list of the keys should be filter
+     * @return              List<MailboxAnnotation>
+     * @throws MailboxException in case of selected mailbox does not exist
+     */
+    List<MailboxAnnotation> getAnnotationsByKeysWithOneDepth(MailboxPath mailboxPath,
MailboxSession session, Set<MailboxAnnotationKey> keys) throws MailboxException;
+
+    /**
+     * Return all mailbox's annotation by the list of the keys and its below entries without
order and
+     * do not contain any two annotations with the same key
+     *
+     * @param mailboxPath   the current mailbox
+     * @param session       the current session
+     * @param keys          list of the keys should be filter
+     * @return              List<MailboxAnnotation>
+     * @throws MailboxException in case of selected mailbox does not exist
+     */
+    List<MailboxAnnotation> getAnnotationsByKeysWithAllDepth(MailboxPath mailboxPath,
MailboxSession session, Set<MailboxAnnotationKey> keys) throws MailboxException;
 
     /**
      * Update the mailbox's annotations. This method can:

http://git-wip-us.apache.org/repos/asf/james-project/blob/7ac9840d/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxAnnotation.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxAnnotation.java
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxAnnotation.java
index b2152d4..22ecf13 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxAnnotation.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxAnnotation.java
@@ -19,44 +19,33 @@
 
 package org.apache.james.mailbox.model;
 
-import org.apache.commons.lang.StringUtils;
-
-import com.google.common.base.CharMatcher;
 import com.google.common.base.Objects;
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 
 public class MailboxAnnotation {
 
-    private static final CharMatcher NAME_ANNOTATION_PATTERN = CharMatcher.ASCII
-            .and(CharMatcher.inRange('\u0000', '\u0019').negate()).and(CharMatcher.isNot('*'))
-            .and(CharMatcher.isNot('%'));
-    
-    public static final String SLASH_CHARACTER = "/";
-    
-    public static final String TWO_SLASH_CHARACTER = "//";
-    
-    public static MailboxAnnotation nil(String key) {
+    public static MailboxAnnotation nil(MailboxAnnotationKey key) {
         return new MailboxAnnotation(key, Optional.<String> absent());
     }
 
-    public static MailboxAnnotation newInstance(String key, String value) {
+    public static MailboxAnnotation newInstance(MailboxAnnotationKey key, String value) {
         return new MailboxAnnotation(key, Optional.of(value));
     }
 
-    private final String key;
+    private final MailboxAnnotationKey key;
     private final Optional<String> value;
 
-    private MailboxAnnotation(String key, Optional<String> value) {
+    private MailboxAnnotation(MailboxAnnotationKey key, Optional<String> value) {
         Preconditions.checkNotNull(key);
         Preconditions.checkNotNull(value);
-        Preconditions.checkArgument(isValidKey(key), 
-                "Key must start with '/' and not end with '/' and does not contain charater
with hex from '\u0000' to '\u00019' or {'*', '%', two consecutive '/'} ");
+        Preconditions.checkArgument(key.isValid(),
+            "Key must start with '/' and not end with '/' and does not contain charater with
hex from '\u0000' to '\u00019' or {'*', '%', two consecutive '/'} ");
         this.key = key;
         this.value = value;
     }
 
-    public String getKey() {
+    public MailboxAnnotationKey getKey() {
         return key;
     }
 
@@ -64,24 +53,11 @@ public class MailboxAnnotation {
         return value;
     }
 
-    private static boolean isValidKey(String input) {
-        if (StringUtils.isBlank(input)) {
-            return false;
-        }
-        String key = input.trim();
-        if (!key.startsWith(SLASH_CHARACTER)) {
-            return false;
-        }
-        if (key.contains(TWO_SLASH_CHARACTER)) {
-            return false;
+    public int size() {
+        if (isNil()) {
+            return 0;
         }
-        if (key.endsWith(SLASH_CHARACTER)) {
-            return false;
-        }
-        if (!NAME_ANNOTATION_PATTERN.matchesAllOf(key)) {
-            return false;
-        }
-        return true;
+        return value.get().length();
     }
 
     @Override
@@ -102,4 +78,5 @@ public class MailboxAnnotation {
             return false;
         }
     }
+
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/7ac9840d/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxAnnotationKey.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxAnnotationKey.java
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxAnnotationKey.java
new file mode 100644
index 0000000..0817ded
--- /dev/null
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxAnnotationKey.java
@@ -0,0 +1,88 @@
+/****************************************************************
+ * 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.mailbox.model;
+
+import com.google.common.base.CharMatcher;
+import com.google.common.base.Objects;
+import org.apache.commons.lang.StringUtils;
+
+/**
+ * Created by quynh on 04/07/2016.
+ */
+public class MailboxAnnotationKey {
+    public static final String SLASH_CHARACTER = "/";
+
+    public static final String TWO_SLASH_CHARACTER = "//";
+
+    private static final CharMatcher NAME_ANNOTATION_PATTERN = CharMatcher.ASCII
+        .and(CharMatcher.inRange('\u0000', '\u0019').negate()).and(CharMatcher.isNot('*'))
+        .and(CharMatcher.isNot('%'));
+
+    private final String key;
+
+    public MailboxAnnotationKey(String key) {
+        this.key = key;
+    }
+
+    public boolean isValid() {
+        if (StringUtils.isBlank(key)) {
+            return false;
+        }
+        if (key.contains(" ")) {
+            return false;
+        }
+        if (!key.startsWith(SLASH_CHARACTER)) {
+            return false;
+        }
+        if (key.contains(TWO_SLASH_CHARACTER)) {
+            return false;
+        }
+        if (key.endsWith(SLASH_CHARACTER)) {
+            return false;
+        }
+        if (!NAME_ANNOTATION_PATTERN.matchesAllOf(key)) {
+            return false;
+        }
+        return true;
+    }
+
+    public int countSlash() {
+        return StringUtils.countMatches(key, SLASH_CHARACTER);
+    }
+
+    public String getKey() {
+        return key;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj instanceof MailboxAnnotationKey) {
+            MailboxAnnotationKey anotherKey = (MailboxAnnotationKey)obj;
+            return Objects.equal(anotherKey.getKey(), key);
+        } else {
+            return false;
+        }
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hashCode(key);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/7ac9840d/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
index 756ddd9..b578d28 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
@@ -31,11 +31,7 @@ import org.apache.james.mailbox.MailboxManager.MailboxCapabilities;
 import org.apache.james.mailbox.exception.BadCredentialsException;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.mock.MockMailboxManager;
-import org.apache.james.mailbox.model.MailboxAnnotation;
-import org.apache.james.mailbox.model.MailboxConstants;
-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.model.*;
 import org.junit.After;
 import org.junit.Assume;
 import org.junit.Rule;
@@ -63,9 +59,16 @@ public class MailboxManagerTest<T extends MailboxManager> {
     public final static String USER_1 = "USER_1";
     public final static String USER_2 = "USER_2";
 
-    private static final MailboxAnnotation PRIVATE_ANNOTATION = MailboxAnnotation.newInstance("/private/comment",
"My private comment");
-    private static final MailboxAnnotation PRIVATE_ANNOTATION_UPDATE = MailboxAnnotation.newInstance("/private/comment",
"My updated private comment");
-    private static final MailboxAnnotation SHARED_ANNOTATION =  MailboxAnnotation.newInstance("/shared/comment",
"My shared comment");
+    private static final MailboxAnnotationKey PRIVATE_KEY = new MailboxAnnotationKey("/private/comment");
+    private static final MailboxAnnotationKey PRIVATE_CHILD_KEY = new MailboxAnnotationKey("/private/comment/user");
+    private static final MailboxAnnotationKey PRIVATE_GRANDCHILD_KEY = new MailboxAnnotationKey("/private/comment/user/name");
+    private static final MailboxAnnotationKey SHARED_KEY = new MailboxAnnotationKey("/shared/comment");
+
+    private static final MailboxAnnotation PRIVATE_ANNOTATION = MailboxAnnotation.newInstance(PRIVATE_KEY,
"My private comment");
+    private static final MailboxAnnotation PRIVATE_CHILD_ANNOTATION = MailboxAnnotation.newInstance(PRIVATE_CHILD_KEY,
"My private comment");
+    private static final MailboxAnnotation PRIVATE_GRANDCHILD_ANNOTATION = MailboxAnnotation.newInstance(PRIVATE_GRANDCHILD_KEY,
"My private comment");
+    private static final MailboxAnnotation PRIVATE_ANNOTATION_UPDATE = MailboxAnnotation.newInstance(PRIVATE_KEY,
"My updated private comment");
+    private static final MailboxAnnotation SHARED_ANNOTATION =  MailboxAnnotation.newInstance(SHARED_KEY,
"My shared comment");
 
     private static final List<MailboxAnnotation> ANNOTATIONS = ImmutableList.of(PRIVATE_ANNOTATION,
SHARED_ANNOTATION);
 
@@ -264,7 +267,7 @@ public class MailboxManagerTest<T extends MailboxManager> {
 
         mailboxManager.updateAnnotations(inbox, session, ImmutableList.of(PRIVATE_ANNOTATION));
 
-        mailboxManager.updateAnnotations(inbox, session, ImmutableList.of(MailboxAnnotation.nil("/private/comment")));
+        mailboxManager.updateAnnotations(inbox, session, ImmutableList.of(MailboxAnnotation.nil(PRIVATE_KEY)));
         assertThat(mailboxManager.getAllAnnotations(inbox, session)).isEmpty();
     }
 
@@ -319,7 +322,7 @@ public class MailboxManagerTest<T extends MailboxManager> {
 
         mailboxManager.updateAnnotations(inbox, session, ANNOTATIONS);
 
-        assertThat(mailboxManager.getAnnotationsByKeys(inbox, session, ImmutableSet.of("/private/comment")))
+        assertThat(mailboxManager.getAnnotationsByKeys(inbox, session, ImmutableSet.of(PRIVATE_KEY)))
             .containsOnly(PRIVATE_ANNOTATION);
     }
 
@@ -330,7 +333,43 @@ public class MailboxManagerTest<T extends MailboxManager> {
         session = mailboxManager.createSystemSession(USER_2, LoggerFactory.getLogger("Test"));
         MailboxPath inbox = MailboxPath.inbox(session);
 
-        mailboxManager.getAnnotationsByKeys(inbox, session, ImmutableSet.of("/private/comment"));
+        mailboxManager.getAnnotationsByKeys(inbox, session, ImmutableSet.of(PRIVATE_KEY));
+    }
+
+    @ContractTest
+    public void getAnnotationsByKeysWithOneDepthShouldRetriveAnnotationsWithOneDepth() throws
BadCredentialsException, MailboxException {
+        Assume.assumeTrue(mailboxManager.hasCapability(MailboxCapabilities.Annotation));
+        session = mailboxManager.createSystemSession(USER_2, LoggerFactory.getLogger("Test"));
+        MailboxPath inbox = MailboxPath.inbox(session);
+        mailboxManager.createMailbox(inbox, session);
+
+        mailboxManager.updateAnnotations(inbox, session, ImmutableList.of(PRIVATE_ANNOTATION,
PRIVATE_CHILD_ANNOTATION, PRIVATE_GRANDCHILD_ANNOTATION));
+
+        assertThat(mailboxManager.getAnnotationsByKeysWithOneDepth(inbox, session, ImmutableSet.of(PRIVATE_KEY)))
+            .contains(PRIVATE_ANNOTATION, PRIVATE_CHILD_ANNOTATION);
+    }
+
+    @ContractTest
+    public void getAnnotationsByKeysWithAllDepthShouldThrowExceptionWhenMailboxDoesNotExist()
throws BadCredentialsException, MailboxException {
+        expected.expect(MailboxException.class);
+        Assume.assumeTrue(mailboxManager.hasCapability(MailboxCapabilities.Annotation));
+        session = mailboxManager.createSystemSession(USER_2, LoggerFactory.getLogger("Test"));
+        MailboxPath inbox = MailboxPath.inbox(session);
+
+        mailboxManager.getAnnotationsByKeysWithAllDepth(inbox, session, ImmutableSet.of(PRIVATE_KEY));
+    }
+
+    @ContractTest
+    public void getAnnotationsByKeysWithAllDepthShouldRetriveAnnotationsWithAllDepth() throws
BadCredentialsException, MailboxException {
+        Assume.assumeTrue(mailboxManager.hasCapability(MailboxCapabilities.Annotation));
+        session = mailboxManager.createSystemSession(USER_2, LoggerFactory.getLogger("Test"));
+        MailboxPath inbox = MailboxPath.inbox(session);
+        mailboxManager.createMailbox(inbox, session);
+
+        mailboxManager.updateAnnotations(inbox, session, ImmutableList.of(PRIVATE_ANNOTATION,
PRIVATE_CHILD_ANNOTATION, PRIVATE_GRANDCHILD_ANNOTATION));
+
+        assertThat(mailboxManager.getAnnotationsByKeysWithAllDepth(inbox, session, ImmutableSet.of(PRIVATE_KEY)))
+            .contains(PRIVATE_ANNOTATION, PRIVATE_CHILD_ANNOTATION, PRIVATE_GRANDCHILD_ANNOTATION);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/7ac9840d/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxAnnotationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxAnnotationTest.java
b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxAnnotationTest.java
index ba85a58..97fe2eb 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxAnnotationTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxAnnotationTest.java
@@ -19,20 +19,33 @@
 
 package org.apache.james.mailbox.model;
 
+import org.junit.Test;
+
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.guava.api.Assertions.assertThat;
 
-import org.junit.Test;
-
 public class MailboxAnnotationTest {
     private static final String ASTERISK_CHARACTER = "*";
 
     private static final String PERCENT_CHARACTER = "%";
 
-    private static final String ANY_KEY = "shared";
-    private static final String ANNOTATION_KEY = "/private/comment"; 
+    private static final MailboxAnnotationKey ANY_KEY = new MailboxAnnotationKey("shared");
+    private static final MailboxAnnotationKey ANNOTATION_KEY = new MailboxAnnotationKey("/private/comment");
     private static final String ANNOTATION_VALUE = "anyValue";
 
+    @Test
+    public void sizeOfAnnotationShouldBeReturnLengthOfValue() throws Exception {
+        MailboxAnnotation mailboxAnnotation = MailboxAnnotation.newInstance(ANNOTATION_KEY,
ANNOTATION_VALUE);
+
+        assertThat(mailboxAnnotation.size()).isEqualTo(8);
+    }
+
+    @Test
+    public void sizeOfNilAnnotationShouldBeZero() throws Exception {
+        MailboxAnnotation mailboxAnnotation = MailboxAnnotation.nil(ANNOTATION_KEY);
+
+        assertThat(mailboxAnnotation.size()).isEqualTo(0);
+    }
     @Test(expected = NullPointerException.class)
     public void newInstanceShouldThrowsExceptionWithNullKey() throws Exception {
         MailboxAnnotation.newInstance(null, null);
@@ -45,12 +58,12 @@ public class MailboxAnnotationTest {
 
     @Test(expected = IllegalArgumentException.class)
     public void newInstanceShouldThrowsExceptionWithEmptyKey() throws Exception {
-        MailboxAnnotation.newInstance("", ANNOTATION_VALUE);
+        MailboxAnnotation.newInstance(new MailboxAnnotationKey(""), ANNOTATION_VALUE);
     }
 
     @Test(expected = IllegalArgumentException.class)
     public void newInstanceShouldThrowsExceptionWithBlankKey() throws Exception {
-        MailboxAnnotation.newInstance("   ", ANNOTATION_VALUE);
+        MailboxAnnotation.newInstance(new MailboxAnnotationKey("    "), ANNOTATION_VALUE);
     }
 
     @Test(expected = IllegalArgumentException.class)
@@ -60,33 +73,32 @@ public class MailboxAnnotationTest {
 
     @Test(expected = IllegalArgumentException.class)
     public void newInstanceShouldThrowsExceptionWhenKeyContainsAsterisk() throws Exception
{
-        MailboxAnnotation.newInstance(buildAnnotationKey(ASTERISK_CHARACTER), ANNOTATION_VALUE);
+        MailboxAnnotation.newInstance(new MailboxAnnotationKey("/private/key*comment"), ANNOTATION_VALUE);
     }
 
     @Test(expected = IllegalArgumentException.class)
     public void newInstanceShouldThrowsExceptionWhenKeyContainsPercent() throws Exception
{
-        MailboxAnnotation.newInstance(buildAnnotationKey(PERCENT_CHARACTER), ANNOTATION_VALUE);
+        MailboxAnnotation.newInstance(new MailboxAnnotationKey("/private/key%comment"), ANNOTATION_VALUE);
     }
 
     @Test(expected = IllegalArgumentException.class)
     public void validKeyShouldThrowsExceptionWhenKeyContainsTwoConsecutiveSlash() throws
Exception {
-        MailboxAnnotation.newInstance(buildAnnotationKey(MailboxAnnotation.TWO_SLASH_CHARACTER),
ANNOTATION_VALUE);
+        MailboxAnnotation.newInstance(new MailboxAnnotationKey("/private//keycomment"), ANNOTATION_VALUE);
     }
 
     @Test(expected = IllegalArgumentException.class)
     public void validKeyShouldThrowsExceptionWhenKeyEndsWithSlash() throws Exception {
-        MailboxAnnotation.newInstance(buildAnnotationKey(MailboxAnnotation.SLASH_CHARACTER)
+ MailboxAnnotation.SLASH_CHARACTER, 
-            ANNOTATION_VALUE);
+        MailboxAnnotation.newInstance(new MailboxAnnotationKey("/private/keycomment/"), ANNOTATION_VALUE);
     }
 
     @Test(expected = IllegalArgumentException.class)
     public void validKeyShouldThrowsExceptionWhenKeyContainsNonASCII() throws Exception {
-        MailboxAnnotation.newInstance(buildAnnotationKey(" "), ANNOTATION_VALUE);
+        MailboxAnnotation.newInstance(new MailboxAnnotationKey("/private/key comment"),
ANNOTATION_VALUE);
     }
 
     @Test(expected = IllegalArgumentException.class)
     public void validKeyShouldThrowsExceptionWhenKeyContainsTabCharacter() throws Exception
{
-        MailboxAnnotation.newInstance(buildAnnotationKey("\t"), ANNOTATION_VALUE);
+        MailboxAnnotation.newInstance(new MailboxAnnotationKey("/private/key\tcomment"),
ANNOTATION_VALUE);
     }
 
     @Test
@@ -104,7 +116,7 @@ public class MailboxAnnotationTest {
 
     @Test
     public void isNilShouldReturnFalseForNotNilObject() throws Exception {
-        MailboxAnnotation nilAnnotation = MailboxAnnotation.newInstance(ANNOTATION_KEY, ANY_KEY);
+        MailboxAnnotation nilAnnotation = MailboxAnnotation.newInstance(ANNOTATION_KEY, ANNOTATION_VALUE);
         assertThat(nilAnnotation.isNil()).isFalse();
     }
 
@@ -117,12 +129,14 @@ public class MailboxAnnotationTest {
     public void newInstanceMailboxAnnotationShouldCreateNewInstance() throws Exception {
         MailboxAnnotation annotation = MailboxAnnotation.newInstance(ANNOTATION_KEY, ANNOTATION_VALUE);
 
-        assertThat(annotation.getKey()).contains(ANNOTATION_KEY);
+        assertThat(annotation.getKey()).isEqualTo(ANNOTATION_KEY);
         assertThat(annotation.getValue()).contains(ANNOTATION_VALUE);
     }
 
-    private String buildAnnotationKey(String apartOfKey) {
-        return MailboxAnnotation.SLASH_CHARACTER + ANY_KEY + apartOfKey + ANY_KEY;
+    @Test
+    public void countSlashShouldReturnRightNumberOfSlash() throws Exception {
+        MailboxAnnotation annotation = MailboxAnnotation.newInstance(new MailboxAnnotationKey("/private/comment/user/name"),
ANNOTATION_VALUE);
+        assertThat(annotation.getKey().countSlash()).isEqualTo(4);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/7ac9840d/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
index 7ea9e0f..35d1a4e 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
@@ -56,6 +56,7 @@ import org.apache.james.mailbox.model.MailboxACL.MailboxACLEntryKey;
 import org.apache.james.mailbox.model.MailboxACL.MailboxACLRight;
 import org.apache.james.mailbox.model.MailboxACL.MailboxACLRights;
 import org.apache.james.mailbox.model.MailboxAnnotation;
+import org.apache.james.mailbox.model.MailboxAnnotationKey;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxMetaData;
 import org.apache.james.mailbox.model.MailboxPath;
@@ -396,7 +397,7 @@ public class MailboxEventAnalyserTest {
 
         @Override
         public List<MailboxAnnotation> getAnnotationsByKeys(MailboxPath mailboxPath,
MailboxSession session,
-                Set<String> keys) throws MailboxException {
+                Set<MailboxAnnotationKey> keys) throws MailboxException {
             return null;
         }
 
@@ -410,6 +411,18 @@ public class MailboxEventAnalyserTest {
             return null;
         }
 
+        @Override
+        public List<MailboxAnnotation> getAnnotationsByKeysWithOneDepth(MailboxPath
mailboxPath, MailboxSession session,
+                Set<MailboxAnnotationKey> keys) throws MailboxException {
+            return null;
+        }
+
+        @Override
+        public List<MailboxAnnotation> getAnnotationsByKeysWithAllDepth(MailboxPath
mailboxPath, MailboxSession session,
+                Set<MailboxAnnotationKey> keys) throws MailboxException {
+            return null;
+        }
+
     };
     
     private final class MyMailboxSession implements MailboxSession {

http://git-wip-us.apache.org/repos/asf/james-project/blob/7ac9840d/server/protocols/jmap/src/test/java/org/apache/james/jmap/FirstUserConnectionFilterThreadTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/FirstUserConnectionFilterThreadTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/FirstUserConnectionFilterThreadTest.java
index 641aa4f..7cde34c 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/FirstUserConnectionFilterThreadTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/FirstUserConnectionFilterThreadTest.java
@@ -35,6 +35,7 @@ import org.apache.james.mailbox.model.MailboxACL.MailboxACLEntryKey;
 import org.apache.james.mailbox.model.MailboxACL.MailboxACLRight;
 import org.apache.james.mailbox.model.MailboxACL.MailboxACLRights;
 import org.apache.james.mailbox.model.MailboxAnnotation;
+import org.apache.james.mailbox.model.MailboxAnnotationKey;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxMetaData;
 import org.apache.james.mailbox.model.MailboxPath;
@@ -220,7 +221,7 @@ public class FirstUserConnectionFilterThreadTest {
         }
 
         @Override
-        public List<MailboxAnnotation> getAnnotationsByKeys(MailboxPath mailboxPath,
MailboxSession session, Set<String> keys) throws MailboxException {
+        public List<MailboxAnnotation> getAnnotationsByKeys(MailboxPath mailboxPath,
MailboxSession session, Set<MailboxAnnotationKey> keys) throws MailboxException {
             return null;
         }
 
@@ -238,6 +239,18 @@ public class FirstUserConnectionFilterThreadTest {
         public Map<MailboxId, Collection<Long>> search(MultimailboxesSearchQuery
expression, MailboxSession session) throws MailboxException {
             return null;
         }
+
+        @Override
+        public List<MailboxAnnotation> getAnnotationsByKeysWithOneDepth(MailboxPath
mailboxPath, MailboxSession session,
+                Set<MailboxAnnotationKey> keys) throws MailboxException {
+            return null;
+        }
+
+        @Override
+        public List<MailboxAnnotation> getAnnotationsByKeysWithAllDepth(MailboxPath
mailboxPath, MailboxSession session,
+                Set<MailboxAnnotationKey> keys) throws MailboxException {
+            return null;
+        }
     }
 }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message