You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ad...@apache.org on 2017/11/08 07:29:48 UTC

[1/9] james-project git commit: MAILBOX-318 Use SetMailboxes method to update rights instead of the ACLProbe

Repository: james-project
Updated Branches:
  refs/heads/master ae155b8d3 -> 0e99fb117


MAILBOX-318 Use SetMailboxes method to update rights instead of the ACLProbe


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

Branch: refs/heads/master
Commit: 562eeaab0279728d0e31a888e9947f16de5bc827
Parents: 30483cf
Author: Antoine Duprat <ad...@linagora.com>
Authored: Fri Nov 3 11:26:15 2017 +0100
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Tue Nov 7 15:33:42 2017 +0100

----------------------------------------------------------------------
 .../cucumber/SetMailboxesMethodStepdefs.java    | 47 +++++++++++++++-----
 1 file changed, 37 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/562eeaab/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java
index 449a407..d26df19 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java
@@ -24,17 +24,18 @@ import static org.assertj.core.api.Assertions.assertThat;
 import java.io.ByteArrayInputStream;
 import java.util.Date;
 import java.util.List;
+import java.util.stream.Collectors;
 import java.util.stream.IntStream;
 
 import javax.inject.Inject;
 import javax.mail.Flags;
 
 import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.exception.UnsupportedRightException;
 import org.apache.james.mailbox.model.MailboxACL;
 import org.apache.james.mailbox.model.MailboxConstants;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
-import org.apache.james.modules.ACLProbeImpl;
 
 import com.github.fge.lambdas.Throwing;
 import com.jayway.awaitility.Awaitility;
@@ -87,18 +88,44 @@ public class SetMailboxesMethodStepdefs {
     }
 
     @Given("^\"([^\"]*)\" shares its mailbox \"([^\"]*)\" with rights \"([^\"]*)\" with \"([^\"]*)\"$")
-    public void shareMailboxWithRight(String owner, String mailbox, String rights, String shareTo) throws Throwable {
-        MailboxPath mailboxPath = MailboxPath.forUser(owner, mailbox);
-
-        mainStepdefs.aclProbe.replaceRights(mailboxPath, shareTo, MailboxACL.Rfc4314Rights.fromSerializedRfc4314Rights(rights));
+    public void shareMailboxWithRight(String owner, String mailboxName, String rights, String shareTo) throws Throwable {
+        userStepdefs.connectUser(owner);
+        Mailbox mailbox = mainStepdefs.mailboxProbe.getMailbox("#private", owner, mailboxName);
+        String mailboxId = mailbox.getMailboxId().serialize();
+        String requestBody =
+                "[" +
+                    "  [ \"setMailboxes\"," +
+                    "    {" +
+                    "      \"update\": {" +
+                    "        \"" + mailboxId + "\" : {" +
+                    "          \"sharedWith\" : { \"" + shareTo + "\" : " + rightsAsString(rights) + " }" +
+                    "        }" +
+                    "      }" +
+                    "    }," +
+                    "    \"#0\"" +
+                    "  ]" +
+                    "]";
+        httpClient.post(requestBody);
+    }
+    
+    private String rightsAsString(String rights) throws UnsupportedRightException {
+        return MailboxACL.Rfc4314Rights
+            .fromSerializedRfc4314Rights(rights)
+            .list()
+            .stream()
+            .map(MailboxACL.Right::asCharacter)
+            .map(String::valueOf)
+            .map(this::surroundWithDoubleQuotes)
+            .collect(Collectors.joining(", ", "[ ", " ]"));
+    }
+    
+    private String surroundWithDoubleQuotes(String input) {
+        return "\"" + input + "\"";
     }
     
     @Given("^\"([^\"]*)\" shares (?:his|her) mailbox \"([^\"]*)\" with \"([^\"]*)\" with \"([^\"]*)\" rights$")
-    public void shareMailbox(String owner, String mailbox, String shareTo, String rights) throws Throwable {
-        mainStepdefs.jmapServer.getProbe(ACLProbeImpl.class)
-            .replaceRights(MailboxPath.forUser(owner, mailbox),
-                shareTo,
-                MailboxACL.Rfc4314Rights.fromSerializedRfc4314Rights(rights));
+    public void shareMailbox(String owner, String mailboxName, String shareTo, String rights) throws Throwable {
+        shareMailboxWithRight(owner, mailboxName, rights, shareTo);
     }
 
     @When("^renaming mailbox \"([^\"]*)\" to \"([^\"]*)\"")


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


[9/9] james-project git commit: Merge remote-tracking branch 'mine/MAILBOX-318-2'

Posted by ad...@apache.org.
Merge remote-tracking branch 'mine/MAILBOX-318-2'


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

Branch: refs/heads/master
Commit: 0e99fb117c369d97e0f82d8a90624fa553184518
Parents: efe8549 d0d9b2f
Author: Antoine Duprat <ad...@linagora.com>
Authored: Wed Nov 8 08:29:12 2017 +0100
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Wed Nov 8 08:29:12 2017 +0100

----------------------------------------------------------------------
 .../exception/DifferentDomainException.java     | 27 ++++++++
 mailbox/store/pom.xml                           |  4 ++
 .../james/mailbox/store/StoreRightManager.java  | 27 ++++++++
 .../mailbox/store/StoreRightManagerTest.java    | 59 ++++++++++++++++++
 ...CassandraSetMailboxesMethodCucumberTest.java |  4 +-
 .../integration/GetMailboxesMethodTest.java     | 11 ++--
 .../integration/SetMailboxesMethodTest.java     | 10 +--
 .../integration/cucumber/MailboxStepdefs.java   | 61 ------------------
 .../cucumber/SetMailboxesMethodStepdefs.java    | 65 ++++++++++++++++++++
 .../resources/cucumber/SetMailboxes.feature     | 30 +++++++++
 .../MemorySetMailboxesMethodCucumberTest.java   |  4 +-
 .../methods/SetMailboxesUpdateProcessor.java    |  6 ++
 12 files changed, 233 insertions(+), 75 deletions(-)
----------------------------------------------------------------------



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


[5/9] james-project git commit: PROTOCOL-117 refactor ListProcessorTest to make it clear what the test covers

Posted by ad...@apache.org.
PROTOCOL-117 refactor ListProcessorTest to make it clear what the test covers


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

Branch: refs/heads/master
Commit: 7ed93d9ec3df3a0a71f6aa1370c6e6ec98993b78
Parents: ae155b8
Author: Matthieu Baechler <ma...@apache.org>
Authored: Mon Nov 6 17:49:13 2017 +0100
Committer: Matthieu Baechler <ma...@apache.org>
Committed: Tue Nov 7 17:55:48 2017 +0100

----------------------------------------------------------------------
 .../james/imap/processor/ListProcessor.java     |  18 +-
 .../james/imap/processor/ListProcessorTest.java | 188 ++++++++++---------
 2 files changed, 111 insertions(+), 95 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/7ed93d9e/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java
index b91ad75..b23f649 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java
@@ -36,6 +36,7 @@ import org.apache.james.imap.api.process.MailboxType;
 import org.apache.james.imap.api.process.MailboxTyper;
 import org.apache.james.imap.main.PathConverter;
 import org.apache.james.imap.message.request.ListRequest;
+import org.apache.james.imap.message.response.AbstractListingResponse;
 import org.apache.james.imap.message.response.ListResponse;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
@@ -52,6 +53,8 @@ import org.apache.james.util.MDCBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.annotations.VisibleForTesting;
+
 public class ListProcessor extends AbstractMailboxProcessor<ListRequest> {
     private static final Logger LOGGER = LoggerFactory.getLogger(ListProcessor.class);
 
@@ -194,14 +197,19 @@ public class ListProcessor extends AbstractMailboxProcessor<ListRequest> {
         }
     }
 
-    void processResult(Responder responder, boolean relative, MailboxMetaData listResult, MailboxType mailboxType) {
+    private void processResult(Responder responder, boolean relative, MailboxMetaData listResult, MailboxType mailboxType) {
+        ImapResponseMessage response = convertMetadataToListResponse(relative, listResult, mailboxType);
+        responder.respond(response);
+    }
+
+    @VisibleForTesting <T extends AbstractListingResponse & ImapResponseMessage> T convertMetadataToListResponse(boolean relative, MailboxMetaData listResult, MailboxType mailboxType) {
         final char delimiter = listResult.getHierarchyDelimiter();
         final String mailboxName = mailboxName(relative, listResult.getPath(), delimiter);
 
         final Children inferiors = listResult.inferiors();
-        final boolean noInferior = MailboxMetaData.Children.NO_INFERIORS.equals(inferiors);
-        final boolean hasChildren = MailboxMetaData.Children.HAS_CHILDREN.equals(inferiors);
-        final boolean hasNoChildren = MailboxMetaData.Children.HAS_NO_CHILDREN.equals(inferiors);
+        final boolean noInferior = Children.NO_INFERIORS.equals(inferiors);
+        final boolean hasChildren = Children.HAS_CHILDREN.equals(inferiors);
+        final boolean hasNoChildren = Children.HAS_NO_CHILDREN.equals(inferiors);
         boolean noSelect = false;
         boolean marked = false;
         boolean unmarked = false;
@@ -218,7 +226,7 @@ public class ListProcessor extends AbstractMailboxProcessor<ListRequest> {
         default:
             break;
         }
-        responder.respond(createResponse(noInferior, noSelect, marked, unmarked, hasChildren, hasNoChildren, mailboxName, delimiter, mailboxType));
+        return (T)createResponse(noInferior, noSelect, marked, unmarked, hasChildren, hasNoChildren, mailboxName, delimiter, mailboxType);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/james-project/blob/7ed93d9e/protocols/imap/src/test/java/org/apache/james/imap/processor/ListProcessorTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/ListProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/ListProcessorTest.java
index 2d48f28..4c546b9 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/ListProcessorTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/ListProcessorTest.java
@@ -19,130 +19,138 @@
 
 package org.apache.james.imap.processor;
 
-import org.apache.james.imap.api.ImapCommand;
+import static org.assertj.core.api.Assertions.assertThat;
+
 import org.apache.james.imap.api.message.response.StatusResponseFactory;
 import org.apache.james.imap.api.process.ImapProcessor;
-import org.apache.james.imap.api.process.ImapSession;
 import org.apache.james.imap.api.process.MailboxType;
 import org.apache.james.imap.message.response.ListResponse;
 import org.apache.james.mailbox.MailboxManager;
-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.store.SimpleMailboxMetaData;
 import org.apache.james.metrics.api.NoopMetricFactory;
-import org.jmock.Expectations;
-import org.jmock.Mockery;
-import org.jmock.integration.junit4.JUnit4Mockery;
 import org.junit.Before;
 import org.junit.Test;
 
 public class ListProcessorTest  {
 
-    ListProcessor processor;
-
-    ImapProcessor next;
-
-    MailboxManager manager;
-
-    ImapProcessor.Responder responder;
-
-    MailboxMetaData result;
-
-    ImapSession session;
-
-    ImapCommand command;
-
-    StatusResponseFactory serverResponseFactory;
-
     MailboxPath inboxPath = new MailboxPath("", "", "INBOX");
+    ListProcessor processor;
 
-    private Mockery mockery = new JUnit4Mockery();
-    
     @Before
     public void setUp() throws Exception {
-        serverResponseFactory = mockery.mock(StatusResponseFactory.class);
-        session = mockery.mock(ImapSession.class);
-        command = ImapCommand.anyStateCommand("Command");
-        next = mockery.mock(ImapProcessor.class);
-        responder = mockery.mock(ImapProcessor.Responder.class);
-        result = mockery.mock(MailboxMetaData.class);
-        manager = mockery.mock(MailboxManager.class);
-        processor = createProcessor(next, manager, serverResponseFactory);
-    }
-
-    ListProcessor createProcessor(ImapProcessor next,
-            MailboxManager manager, StatusResponseFactory factory) {
-        return new ListProcessor(next, manager, factory, new NoopMetricFactory());
+        StatusResponseFactory serverResponseFactory = null;
+        ImapProcessor next = null;
+        MailboxManager manager = null;
+        processor = new ListProcessor(next, manager, serverResponseFactory, new NoopMetricFactory());
     }
 
-    ListResponse createResponse(boolean noinferior, boolean noselect,
-            boolean marked, boolean unmarked, boolean hasChildren,
-            boolean hasNoChildren, char hierarchyDelimiter, String mailboxName) {
-        return new ListResponse(noinferior, noselect, marked, unmarked,
-                hasChildren, hasNoChildren, MailboxConstants.USER_NAMESPACE + MailboxConstants.DEFAULT_DELIMITER + mailboxName, hierarchyDelimiter);
-    }
-
-    void setUpResult(final MailboxMetaData.Children children, final MailboxMetaData.Selectability selectability,
-            final char hierarchyDelimiter, final MailboxPath path) {
-        mockery.checking(new Expectations() {{
-            oneOf(result).inferiors();will(returnValue(children));
-            oneOf(result).getSelectability();will(returnValue(selectability));
-            oneOf(result).getHierarchyDelimiter();will(returnValue(hierarchyDelimiter));
-            oneOf(result).getPath();will(returnValue(path));
-        }});
-    }
-    
     @Test
-    public void testHasChildren() throws Exception {
-        setUpResult(MailboxMetaData.Children.HAS_CHILDREN, MailboxMetaData.Selectability.NONE, '.', inboxPath);
-        mockery.checking(new Expectations() {{
-            oneOf(responder).respond(with(equal(createResponse(false, false, false, false, true, false, '.', "INBOX"))));
-        }});
-        processor.processResult(responder, false, result,MailboxType.OTHER);
+    public void convertHasChildrenShouldHaveHasChildrenFlagOnly() throws Exception {
+        ListResponse actual = processor.convertMetadataToListResponse(false,
+            new SimpleMailboxMetaData(inboxPath, null, '.', MailboxMetaData.Children.HAS_CHILDREN, MailboxMetaData.Selectability.NONE),
+            MailboxType.OTHER);
+        assertThat(actual).isEqualTo(
+            new ListResponse(
+                false,
+                false,
+                false,
+                false,
+                true,
+                false,
+                inboxPath.getFullName('.'),
+                '.')
+        );
     }
 
     @Test
-    public void testHasNoChildren() throws Exception {
-        setUpResult(MailboxMetaData.Children.HAS_NO_CHILDREN, MailboxMetaData.Selectability.NONE, '.', inboxPath);
-        mockery.checking(new Expectations() {{
-            oneOf(responder).respond(with(equal(createResponse(false, false, false, false, false, true, '.', "INBOX"))));
-        }});
-        processor.processResult(responder, false, result,MailboxType.OTHER);
+    public void convertHasNoChildrenShouldHaveHasNoChildrenFlagOnly() throws Exception {
+        ListResponse actual = processor.convertMetadataToListResponse(false,
+            new SimpleMailboxMetaData(inboxPath, null, '.', MailboxMetaData.Children.HAS_NO_CHILDREN, MailboxMetaData.Selectability.NONE),
+            MailboxType.OTHER);
+        assertThat(actual).isEqualTo(
+            new ListResponse(
+                false,
+                false,
+                false,
+                false,
+                false,
+                true,
+                inboxPath.getFullName('.'),
+                '.')
+        );
     }
     
     @Test
-    public void testNoInferiors() throws Exception {
-        setUpResult(MailboxMetaData.Children.NO_INFERIORS, MailboxMetaData.Selectability.NONE, '.', inboxPath);
-        mockery.checking(new Expectations() {{
-            oneOf(responder).respond(with(equal(createResponse(true, false, false, false, false, false, '.', "INBOX"))));
-        }});
-        processor.processResult(responder, false, result,MailboxType.OTHER);
+    public void convertNoInferiorShouldHaveNoInferiorFlagOnly() throws Exception {
+        ListResponse actual = processor.convertMetadataToListResponse(false,
+            new SimpleMailboxMetaData(inboxPath, null, '.', MailboxMetaData.Children.NO_INFERIORS, MailboxMetaData.Selectability.NONE),
+            MailboxType.OTHER);
+        assertThat(actual).isEqualTo(
+            new ListResponse(
+                true,
+                false,
+                false,
+                false,
+                false,
+                false,
+                inboxPath.getFullName('.'),
+                '.')
+        );
     }
 
     @Test
-    public void testNoSelect() throws Exception {
-        setUpResult(MailboxMetaData.Children.CHILDREN_ALLOWED_BUT_UNKNOWN, MailboxMetaData.Selectability.NOSELECT, '.', inboxPath);
-        mockery.checking(new Expectations() {{
-            oneOf(responder).respond(with(equal(createResponse(false, true, false, false, false, false, '.', "INBOX"))));
-        }});
-        processor.processResult(responder, false, result,MailboxType.OTHER);
+    public void convertNoSelectUnknownChildrenShouldHaveNoSelectFlagOnly() throws Exception {
+        ListResponse actual = processor.convertMetadataToListResponse(false,
+            new SimpleMailboxMetaData(inboxPath, null, '.', MailboxMetaData.Children.CHILDREN_ALLOWED_BUT_UNKNOWN, MailboxMetaData.Selectability.NOSELECT),
+            MailboxType.OTHER);
+        assertThat(actual).isEqualTo(
+            new ListResponse(
+                false,
+                true,
+                false,
+                false,
+                false,
+                false,
+                inboxPath.getFullName('.'),
+                '.')
+        );
     }
 
     @Test
-    public void testUnMarked() throws Exception {
-        setUpResult(MailboxMetaData.Children.CHILDREN_ALLOWED_BUT_UNKNOWN, MailboxMetaData.Selectability.UNMARKED, '.', inboxPath);
-        mockery.checking(new Expectations() {{
-            oneOf(responder).respond(with(equal(createResponse(false, false, false, true, false, false, '.', "INBOX"))));
-        }});
-        processor.processResult(responder, false, result,MailboxType.OTHER);
+    public void convertUnmarkedUnknownChildrenShouldHaveUnmarkedFlagOnly() throws Exception {
+        ListResponse actual = processor.convertMetadataToListResponse(false,
+            new SimpleMailboxMetaData(inboxPath, null, '.', MailboxMetaData.Children.CHILDREN_ALLOWED_BUT_UNKNOWN, MailboxMetaData.Selectability.UNMARKED),
+            MailboxType.OTHER);
+        assertThat(actual).isEqualTo(
+            new ListResponse(
+                false,
+                false,
+                false,
+                true,
+                false,
+                false,
+                inboxPath.getFullName('.'),
+                '.')
+        );
     }
 
     @Test
-    public void testMarked() throws Exception {
-        setUpResult(MailboxMetaData.Children.CHILDREN_ALLOWED_BUT_UNKNOWN, MailboxMetaData.Selectability.MARKED, '.', inboxPath);
-        mockery.checking(new Expectations() {{
-            oneOf(responder).respond(with(equal(createResponse(false, false, true, false, false, false, '.', "INBOX"))));
-        }});
-        processor.processResult(responder, false, result,MailboxType.OTHER);
+    public void convertMarkedUnknownChildrenShouldHaveMarkedFlagOnly() throws Exception {
+        ListResponse actual = processor.convertMetadataToListResponse(false,
+            new SimpleMailboxMetaData(inboxPath, null, '.', MailboxMetaData.Children.CHILDREN_ALLOWED_BUT_UNKNOWN, MailboxMetaData.Selectability.MARKED),
+            MailboxType.OTHER);
+        assertThat(actual).isEqualTo(
+            new ListResponse(
+                false,
+                false,
+                true,
+                false,
+                false,
+                false,
+                inboxPath.getFullName('.'),
+                '.')
+        );
     }
 }


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


[8/9] james-project git commit: PROTOCOL-117 cover ListingEncodingUtils with tests

Posted by ad...@apache.org.
PROTOCOL-117 cover ListingEncodingUtils with tests


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

Branch: refs/heads/master
Commit: 1411959de159366e35b4341938308ba463defb0a
Parents: 78f2390
Author: Matthieu Baechler <ma...@apache.org>
Authored: Tue Nov 7 16:37:08 2017 +0100
Committer: Matthieu Baechler <ma...@apache.org>
Committed: Tue Nov 7 17:55:48 2017 +0100

----------------------------------------------------------------------
 .../imap/encode/LSubResponseEncoderTest.java    | 49 +++++------
 .../imap/encode/ListResponseEncoderTest.java    | 62 ++++----------
 .../imap/encode/ListingEncodingUtilsTest.java   | 86 ++++++++++++++------
 .../imap/encode/XListResponseEncoderTest.java   | 81 ++++++++++++++++++
 4 files changed, 183 insertions(+), 95 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/1411959d/protocols/imap/src/test/java/org/apache/james/imap/encode/LSubResponseEncoderTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/encode/LSubResponseEncoderTest.java b/protocols/imap/src/test/java/org/apache/james/imap/encode/LSubResponseEncoderTest.java
index 23836f1..a0c9348 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/encode/LSubResponseEncoderTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/encode/LSubResponseEncoderTest.java
@@ -19,6 +19,7 @@
 
 package org.apache.james.imap.encode;
 
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
@@ -34,50 +35,44 @@ import org.junit.Before;
 import org.junit.Test;
 
 public class LSubResponseEncoderTest  {
+    private LSubResponseEncoder encoder;
 
-    LSubResponseEncoder encoder;
-
-    ImapEncoder mockNextEncoder;
-
-    ByteImapResponseWriter writer = new ByteImapResponseWriter();
-    ImapResponseComposer composer = new ImapResponseComposerImpl(writer);
+    private ByteImapResponseWriter writer = new ByteImapResponseWriter();
+    private ImapResponseComposer composer = new ImapResponseComposerImpl(writer);
 
     private Mockery context = new JUnit4Mockery();
-    
+
     @Before
     public void setUp() throws Exception {
-        mockNextEncoder = context.mock(ImapEncoder.class);
-        encoder = new LSubResponseEncoder(mockNextEncoder);
+        encoder = new LSubResponseEncoder(context.mock(ImapEncoder.class));
     }
 
     @Test
-    public void testIsAcceptable() {
-        assertFalse(encoder.isAcceptable(new ListResponse(true, true, true,
-                true, false, false, "name", '.')));
-        assertTrue(encoder.isAcceptable(new LSubResponse("name", true, '.')));
-        assertFalse(encoder.isAcceptable(context.mock(ImapMessage.class)));
-        assertFalse(encoder.isAcceptable(null));
+    public void encoderShouldNotAcceptListResponse() {
+        assertThat(encoder.isAcceptable(new ListResponse(true, true, true,
+            true, false, false, "name", '.')))
+            .isFalse();
     }
 
     @Test
-	public void testName() throws Exception {
-        encoder.encode(new LSubResponse("INBOX.name", false, '.'), composer, new FakeImapSession());
-        assertEquals("* LSUB () \".\" \"INBOX.name\"\r\n", writer.getString());
-
+    public void encoderShouldAcceptLsubResponse() {
+        assertThat(encoder.isAcceptable(new LSubResponse("name", true, '.'))).isTrue();
     }
 
     @Test
-	public void testDelimiter() throws Exception {
-        encoder.encode(new LSubResponse("INBOX.name", false, '.'), composer, new FakeImapSession());
-        assertEquals("* LSUB () \".\" \"INBOX.name\"\r\n", writer.getString());
-
+    public void encoderShouldNotAcceptImapMessage() {
+        assertThat(encoder.isAcceptable(context.mock(ImapMessage.class))).isFalse();
     }
 
     @Test
-    public void testNoSelect() throws Exception {
-        encoder.encode(new LSubResponse("INBOX.name", true, '.'), composer, new FakeImapSession());
-        assertEquals("* LSUB (\\Noselect) \".\" \"INBOX.name\"\r\n", writer.getString());
-
+    public void encoderShouldNotAcceptNull() {
+        assertThat(encoder.isAcceptable(null)).isFalse();
+    }
 
+    @Test
+    public void encoderShouldIncludeLSUBCommand() throws Exception {
+        encoder.encode(new LSubResponse("name", true, '.'), composer, new FakeImapSession());
+        assertThat(writer.getString()).startsWith("* LSUB");
     }
+
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/1411959d/protocols/imap/src/test/java/org/apache/james/imap/encode/ListResponseEncoderTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/encode/ListResponseEncoderTest.java b/protocols/imap/src/test/java/org/apache/james/imap/encode/ListResponseEncoderTest.java
index 67bd1bc..e70572d 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/encode/ListResponseEncoderTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/encode/ListResponseEncoderTest.java
@@ -19,6 +19,7 @@
 
 package org.apache.james.imap.encode;
 
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
@@ -37,8 +38,6 @@ public class ListResponseEncoderTest {
 
     private ListResponseEncoder encoder;
 
-    private ImapEncoder mockNextEncoder;
-
     private ByteImapResponseWriter writer = new ByteImapResponseWriter();
     private ImapResponseComposer composer = new ImapResponseComposerImpl(writer);
 
@@ -46,63 +45,36 @@ public class ListResponseEncoderTest {
     
     @Before
     public void setUp() throws Exception {
-        mockNextEncoder = context.mock(ImapEncoder.class);
-        encoder = new ListResponseEncoder(mockNextEncoder);
-    }
-
-    @Test
-    public void testIsAcceptable() {
-        assertTrue(encoder.isAcceptable(new ListResponse(true, true, true,
-                true, false, false, "name", '.')));
-        assertFalse(encoder.isAcceptable(new LSubResponse("name", true, '.')));
-        assertFalse(encoder.isAcceptable(context.mock(ImapMessage.class)));
-        assertFalse(encoder.isAcceptable(null));
-    }
-
-    @Test
-	public void testName() throws Exception {     
-        encoder.encode(new ListResponse(false, false, false, false, false, false, "INBOX.name", '.'), composer, new FakeImapSession());
-        assertEquals("* LIST () \".\" \"INBOX.name\"\r\n", writer.getString());
-    }
-
-    @Test
-	public void testDelimiter() throws Exception {
-        encoder.encode(new ListResponse(false, false, false, false, false, false, "INBOX.name", '.'), composer, new FakeImapSession());
-        assertEquals("* LIST () \".\" \"INBOX.name\"\r\n", writer.getString());
+        encoder = new ListResponseEncoder(context.mock(ImapEncoder.class));
     }
 
-
     @Test
-    public void testAllAttributes() throws Exception {
-        encoder.encode(new ListResponse(true, true, true, true, false, false, "INBOX.name", '.'), composer, new FakeImapSession());
-        assertEquals("* LIST (\\Noinferiors \\Noselect \\Marked \\Unmarked) \".\" \"INBOX.name\"\r\n", writer.getString());
-
+    public void encoderShouldAcceptListResponse() {
+        assertThat(encoder.isAcceptable(new ListResponse(true, true, true,
+            true, false, false, "name", '.')))
+        .isTrue();
     }
 
     @Test
-    public void testNoInferiors() throws Exception {      
-        encoder.encode(new ListResponse(true, false, false, false, false, false, "INBOX.name", '.'), composer, new FakeImapSession());
-        assertEquals("* LIST (\\Noinferiors) \".\" \"INBOX.name\"\r\n", writer.getString());
+    public void encoderShouldNotAcceptLsubResponse() {
+        assertThat(encoder.isAcceptable(new LSubResponse("name", true, '.'))).isFalse();
+        assertFalse(encoder.isAcceptable(context.mock(ImapMessage.class)));
+        assertFalse(encoder.isAcceptable(null));
     }
 
     @Test
-    public void testNoSelect() throws Exception {
-        encoder.encode(new ListResponse(false, true, false, false, false, false, "INBOX.name", '.'), composer, new FakeImapSession());
-        assertEquals("* LIST (\\Noselect) \".\" \"INBOX.name\"\r\n", writer.getString());
-
+    public void encoderShouldNotAcceptImapMessage() {
+        assertThat(encoder.isAcceptable(context.mock(ImapMessage.class))).isFalse();
     }
 
     @Test
-    public void testMarked() throws Exception {
-        encoder.encode(new ListResponse(false, false, true, false, false, false, "INBOX.name", '.'), composer, new FakeImapSession());
-        assertEquals("* LIST (\\Marked) \".\" \"INBOX.name\"\r\n", writer.getString());
-
+    public void encoderShouldNotAcceptNull() {
+        assertThat(encoder.isAcceptable(null)).isFalse();
     }
 
     @Test
-    public void testUnmarked() throws Exception {
-        encoder.encode(new ListResponse(false, false, false, true, false, false, "INBOX.name", '.'), composer, new FakeImapSession());
-        assertEquals("* LIST (\\Unmarked) \".\" \"INBOX.name\"\r\n", writer.getString());
-
+	public void encoderShouldIncludeListCommand() throws Exception {
+        encoder.encode(new ListResponse(false, false, false, false, false, false, "INBOX.name", '.'), composer, new FakeImapSession());
+        assertThat(writer.getString()).startsWith("* LIST");
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/1411959d/protocols/imap/src/test/java/org/apache/james/imap/encode/ListingEncodingUtilsTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/encode/ListingEncodingUtilsTest.java b/protocols/imap/src/test/java/org/apache/james/imap/encode/ListingEncodingUtilsTest.java
index bb5b187..dc2f439 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/encode/ListingEncodingUtilsTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/encode/ListingEncodingUtilsTest.java
@@ -18,52 +18,92 @@
  ****************************************************************/
 package org.apache.james.imap.encode;
 
-import java.util.ArrayList;
-import java.util.List;
+import static org.assertj.core.api.Assertions.assertThat;
 
+import org.apache.james.imap.api.process.MailboxType;
 import org.apache.james.imap.encode.base.ByteImapResponseWriter;
 import org.apache.james.imap.encode.base.ImapResponseComposerImpl;
 import org.apache.james.imap.message.response.ListResponse;
-import org.junit.Assert;
-import org.junit.Before;
+import org.apache.james.imap.message.response.XListResponse;
 import org.junit.Test;
 
 public class ListingEncodingUtilsTest  {
 
-    final String nameParameter = "LIST";
-    final String typeNameParameters = "A Type Name";
+    final String nameParameter = "mailbox";
+    final String typeNameParameters = "LIST";
     
-    List<String> attributesOutput;
-        
     private ByteImapResponseWriter writer = new ByteImapResponseWriter();
     private ImapResponseComposer composer = new ImapResponseComposerImpl(writer);
-    
-    @Before
-    public void setUp() throws Exception {
-        attributesOutput = new ArrayList<>();
-      
+
+    @Test
+    public void encodeShouldWriteNilDelimiterWhenUnassigned() throws Exception {
+        ListResponse input = new ListResponse(false, false, false, false, true, false, nameParameter, ((char) Character.UNASSIGNED));
+
+        ListingEncodingUtils.encodeListingResponse(typeNameParameters, composer, input);
+        assertThat(writer.getString()).isEqualTo("* LIST (\\HasChildren) NIL \"mailbox\"\r\n");
     }
 
     @Test
-    public void testShouldAddHasChildrenToAttributes() throws Exception {
-        // Setup 
-        attributesOutput.add("\\HasChildren");
+    public void encodeShouldWriteAnyDelimiter() throws Exception {
+        ListResponse input = new ListResponse(false, false, false, false, true, false, nameParameter, '#');
+
+        ListingEncodingUtils.encodeListingResponse(typeNameParameters, composer, input);
+        assertThat(writer.getString()).isEqualTo("* LIST (\\HasChildren) \"#\" \"mailbox\"\r\n");
+    }
+
+    @Test
+    public void encodeShouldNotIncludeAttributeWhenNone() throws Exception {
+        ListResponse input = new ListResponse(false, false, false, false, false, false, nameParameter, '.');
+
+        ListingEncodingUtils.encodeListingResponse(typeNameParameters, composer, input);
+        assertThat(writer.getString()).isEqualTo("* LIST () \".\" \"mailbox\"\r\n");
+    }
+
+    @Test
+    public void encodeShouldAddHasChildrenToAttributes() throws Exception {
         ListResponse input = new ListResponse(false, false, false, false, true, false, nameParameter, '.');
             
-        // Exercise
         ListingEncodingUtils.encodeListingResponse(typeNameParameters, composer, input);
-        Assert.assertEquals("* A Type Name (\\HasChildren) \".\" \"LIST\"\r\n", writer.getString());
+        assertThat(writer.getString()).isEqualTo("* LIST (\\HasChildren) \".\" \"mailbox\"\r\n");
     }
     
     @Test
-    public void testShouldAddHasNoChildrenToAttributes() throws Exception {
-        // Setup 
-        attributesOutput.add("\\HasNoChildren");
+    public void encodeShouldAddHasNoChildrenToAttributes() throws Exception {
         ListResponse input = new ListResponse(false, false, false, false, false, true, nameParameter, '.');
             
-        // Exercise
         ListingEncodingUtils.encodeListingResponse(typeNameParameters, composer, input);
-        Assert.assertEquals("* A Type Name (\\HasNoChildren) \".\" \"LIST\"\r\n", writer.getString());
+        assertThat(writer.getString()).isEqualTo("* LIST (\\HasNoChildren) \".\" \"mailbox\"\r\n");
+    }
+
+    @Test
+    public void encodeShouldAddSeveralAttributes() throws Exception {
+        ListResponse input = new ListResponse(true, true, false, false, false, true, nameParameter, '.');
+
+        ListingEncodingUtils.encodeListingResponse(typeNameParameters, composer, input);
+        assertThat(writer.getString()).isEqualTo("* LIST (\\Noinferiors \\Noselect \\HasNoChildren) \".\" \"mailbox\"\r\n");
+    }
+
+    @Test
+    public void encodeShouldAddMarkedAttribute() throws Exception {
+        ListResponse input = new ListResponse(false, false, true, false, false, false, nameParameter, '.');
+
+        ListingEncodingUtils.encodeListingResponse(typeNameParameters, composer, input);
+        assertThat(writer.getString()).isEqualTo("* LIST (\\Marked) \".\" \"mailbox\"\r\n");
+    }
+
+    @Test
+    public void encodeShouldAddUnmarkedAttribute() throws Exception {
+        ListResponse input = new ListResponse(false, false, false, true, false, false, nameParameter, '.');
+
+        ListingEncodingUtils.encodeListingResponse(typeNameParameters, composer, input);
+        assertThat(writer.getString()).isEqualTo("* LIST (\\Unmarked) \".\" \"mailbox\"\r\n");
+    }
+
+    @Test
+    public void encodeShouldAddXListAttributeWhenTypeIsInbox() throws Exception {
+        XListResponse input = new XListResponse(false, false, false, false, true, false, nameParameter, '.', MailboxType.INBOX);
 
+        ListingEncodingUtils.encodeListingResponse("XLIST", composer, input);
+        assertThat(writer.getString()).isEqualTo("* XLIST (\\HasChildren \\Inbox) \".\" \"mailbox\"\r\n");
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/1411959d/protocols/imap/src/test/java/org/apache/james/imap/encode/XListResponseEncoderTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/encode/XListResponseEncoderTest.java b/protocols/imap/src/test/java/org/apache/james/imap/encode/XListResponseEncoderTest.java
new file mode 100644
index 0000000..7216dc8
--- /dev/null
+++ b/protocols/imap/src/test/java/org/apache/james/imap/encode/XListResponseEncoderTest.java
@@ -0,0 +1,81 @@
+/****************************************************************
+ * 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.imap.encode;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertFalse;
+
+import org.apache.james.imap.api.ImapMessage;
+import org.apache.james.imap.api.process.MailboxType;
+import org.apache.james.imap.encode.base.ByteImapResponseWriter;
+import org.apache.james.imap.encode.base.ImapResponseComposerImpl;
+import org.apache.james.imap.message.response.LSubResponse;
+import org.apache.james.imap.message.response.ListResponse;
+import org.apache.james.imap.message.response.XListResponse;
+import org.jmock.Mockery;
+import org.jmock.integration.junit4.JUnit4Mockery;
+import org.junit.Before;
+import org.junit.Test;
+
+public class XListResponseEncoderTest {
+
+    private XListResponseEncoder encoder;
+
+    private ByteImapResponseWriter writer = new ByteImapResponseWriter();
+    private ImapResponseComposer composer = new ImapResponseComposerImpl(writer);
+
+    private Mockery context = new JUnit4Mockery();
+    
+    @Before
+    public void setUp() throws Exception {
+        encoder = new XListResponseEncoder(context.mock(ImapEncoder.class));
+    }
+
+    @Test
+    public void encoderShouldAcceptXListResponse() {
+        assertThat(encoder.isAcceptable(new XListResponse(true, true, true,
+            true, false, false, "name", '.', MailboxType.INBOX)))
+        .isTrue();
+    }
+
+    @Test
+    public void encoderShouldNotAcceptLsubResponse() {
+        assertThat(encoder.isAcceptable(new LSubResponse("name", true, '.'))).isFalse();
+        assertFalse(encoder.isAcceptable(context.mock(ImapMessage.class)));
+        assertFalse(encoder.isAcceptable(null));
+    }
+
+    @Test
+    public void encoderShouldNotAcceptImapMessage() {
+        assertThat(encoder.isAcceptable(context.mock(ImapMessage.class))).isFalse();
+    }
+
+    @Test
+    public void encoderShouldNotAcceptNull() {
+        assertThat(encoder.isAcceptable(null)).isFalse();
+    }
+
+    @Test
+	public void encoderShouldIncludeListCommand() throws Exception {
+        encoder.encode(new XListResponse(true, true, true,
+            true, false, false, "name", '.', MailboxType.INBOX), composer, new FakeImapSession());
+        assertThat(writer.getString()).startsWith("* XLIST");
+    }
+}


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


[6/9] james-project git commit: PROTOCOL-117 refactor ListingEncodingUtils to a more straightforward style

Posted by ad...@apache.org.
PROTOCOL-117 refactor ListingEncodingUtils to a more straightforward style


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

Branch: refs/heads/master
Commit: 86214d8a1920c705c0a1f0c9d52d0aabc71a95d8
Parents: 1411959
Author: Matthieu Baechler <ma...@apache.org>
Authored: Tue Nov 7 16:44:44 2017 +0100
Committer: Matthieu Baechler <ma...@apache.org>
Committed: Tue Nov 7 17:55:48 2017 +0100

----------------------------------------------------------------------
 .../james/imap/encode/ListingEncodingUtils.java | 68 ++++++++------------
 .../response/AbstractListingResponse.java       | 10 ---
 2 files changed, 28 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/86214d8a/protocols/imap/src/main/java/org/apache/james/imap/encode/ListingEncodingUtils.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/encode/ListingEncodingUtils.java b/protocols/imap/src/main/java/org/apache/james/imap/encode/ListingEncodingUtils.java
index 81b7309..f152cbc 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/encode/ListingEncodingUtils.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/encode/ListingEncodingUtils.java
@@ -27,64 +27,52 @@ import org.apache.james.imap.api.ImapConstants;
 import org.apache.james.imap.api.process.MailboxType;
 import org.apache.james.imap.message.response.AbstractListingResponse;
 
-/**
- * Utilities for encoding LIST and LSUB responses.
- */
 public class ListingEncodingUtils {
 
     public static void encodeListingResponse(String responseTypeName, ImapResponseComposer composer, AbstractListingResponse response) throws IOException {
-        final List<String> attributes = getNameAttributes(response);
 
-        final String name = response.getName();
-        final char hierarchyDelimiter = response.getHierarchyDelimiter();
-                
         composer.untagged();
         composer.message(responseTypeName);
         composer.openParen();
-        if (attributes != null) {
-            for (String attribute : attributes) {
-                composer.message(attribute);
-            }
+        for (String attribute : getNameAttributes(response)) {
+            composer.message(attribute);
         }
         composer.closeParen();
+        writeDelimiter(composer, response.getHierarchyDelimiter());
+        composer.mailbox(response.getName());
+        composer.end();
+    }
 
+    private static void writeDelimiter(ImapResponseComposer composer, char hierarchyDelimiter) throws IOException {
         if (hierarchyDelimiter == Character.UNASSIGNED) {
         	composer.nil();
         } else {
         	composer.quote(Character.toString(hierarchyDelimiter));
         }
-        composer.mailbox(name);
-
-        composer.end();
     }
 
     private static List<String> getNameAttributes(AbstractListingResponse response) {
-        final List<String> attributes;
-        if (response.isNameAttributed()) {
-            attributes = new ArrayList<>();
-            if (response.isNoInferiors()) {
-                attributes.add(ImapConstants.NAME_ATTRIBUTE_NOINFERIORS);
-            }
-            if (response.isNoSelect()) {
-                attributes.add(ImapConstants.NAME_ATTRIBUTE_NOSELECT);
-            }
-            if (response.isMarked()) {
-                attributes.add(ImapConstants.NAME_ATTRIBUTE_MARKED);
-            }
-            if (response.isUnmarked()) {
-                attributes.add(ImapConstants.NAME_ATTRIBUTE_UNMARKED);
-            }
-            if (response.hasChildren()) {
-                attributes.add(ImapConstants.NAME_ATTRIBUTE_HAS_CHILDREN);
-            }
-            if (response.hasNoChildren()) {
-                attributes.add(ImapConstants.NAME_ATTRIBUTE_HAS_NO_CHILDREN);
-            }
-            if (!MailboxType.OTHER.equals(response.getType())) {
-                attributes.add(response.getType().getAttributeName());
-            }
-        } else {
-            attributes = null;
+        final List<String> attributes = new ArrayList<>();
+        if (response.isNoInferiors()) {
+            attributes.add(ImapConstants.NAME_ATTRIBUTE_NOINFERIORS);
+        }
+        if (response.isNoSelect()) {
+            attributes.add(ImapConstants.NAME_ATTRIBUTE_NOSELECT);
+        }
+        if (response.isMarked()) {
+            attributes.add(ImapConstants.NAME_ATTRIBUTE_MARKED);
+        }
+        if (response.isUnmarked()) {
+            attributes.add(ImapConstants.NAME_ATTRIBUTE_UNMARKED);
+        }
+        if (response.hasChildren()) {
+            attributes.add(ImapConstants.NAME_ATTRIBUTE_HAS_CHILDREN);
+        }
+        if (response.hasNoChildren()) {
+            attributes.add(ImapConstants.NAME_ATTRIBUTE_HAS_NO_CHILDREN);
+        }
+        if (!MailboxType.OTHER.equals(response.getType())) {
+            attributes.add(response.getType().getAttributeName());
         }
         return attributes;
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/86214d8a/protocols/imap/src/main/java/org/apache/james/imap/message/response/AbstractListingResponse.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/message/response/AbstractListingResponse.java b/protocols/imap/src/main/java/org/apache/james/imap/message/response/AbstractListingResponse.java
index a66ffb5..53fcf78 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/message/response/AbstractListingResponse.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/message/response/AbstractListingResponse.java
@@ -138,16 +138,6 @@ public abstract class AbstractListingResponse {
         return type;
     }
 
-    /**
-     * Are any name attributes set?
-     * 
-     * @return true if {@link #isNoInferiors()}, {@link #isNoSelect()},
-     *         {@link #isMarked()} or {@link #isUnmarked()}
-     */
-    public final boolean isNameAttributed() {
-        return noInferiors || noSelect || marked || unmarked || children || noChildren || (!MailboxType.OTHER.equals(type));
-    }
-
     @Override
     public int hashCode() {
         final int PRIME = 31;


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


[4/9] james-project git commit: PROTOCOL-117 get rid of boolean crazyness in ListResponse

Posted by ad...@apache.org.
PROTOCOL-117 get rid of boolean crazyness in ListResponse


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

Branch: refs/heads/master
Commit: efe854926659f3ff367da3cb6ec8548dfd1ff17f
Parents: 86214d8
Author: Matthieu Baechler <ma...@apache.org>
Authored: Tue Nov 7 17:54:35 2017 +0100
Committer: Matthieu Baechler <ma...@apache.org>
Committed: Tue Nov 7 17:55:48 2017 +0100

----------------------------------------------------------------------
 .../james/imap/encode/ListingEncodingUtils.java |  64 ++++---
 .../response/AbstractListingResponse.java       | 175 +++++--------------
 .../imap/message/response/LSubResponse.java     |  10 +-
 .../imap/message/response/ListResponse.java     |   6 +-
 .../imap/message/response/XListResponse.java    |   6 +-
 .../james/imap/processor/ListProcessor.java     |  45 ++---
 .../james/imap/processor/XListProcessor.java    |   5 +-
 .../imap/encode/LSubResponseEncoderTest.java    |   4 +-
 .../imap/encode/ListResponseEncoderTest.java    |   6 +-
 .../imap/encode/ListingEncodingUtilsTest.java   |  22 +--
 .../imap/encode/SearchResponseEncoderTest.java  |   4 +
 .../imap/encode/XListResponseEncoderTest.java   |  21 ++-
 .../james/imap/processor/ListProcessorTest.java | 156 -----------------
 13 files changed, 151 insertions(+), 373 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/efe85492/protocols/imap/src/main/java/org/apache/james/imap/encode/ListingEncodingUtils.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/encode/ListingEncodingUtils.java b/protocols/imap/src/main/java/org/apache/james/imap/encode/ListingEncodingUtils.java
index f152cbc..9be5fdc 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/encode/ListingEncodingUtils.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/encode/ListingEncodingUtils.java
@@ -20,12 +20,14 @@
 package org.apache.james.imap.encode;
 
 import java.io.IOException;
-import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.james.imap.api.ImapConstants;
 import org.apache.james.imap.api.process.MailboxType;
 import org.apache.james.imap.message.response.AbstractListingResponse;
+import org.apache.james.mailbox.model.MailboxMetaData;
+
+import com.google.common.collect.ImmutableList;
 
 public class ListingEncodingUtils {
 
@@ -51,30 +53,48 @@ public class ListingEncodingUtils {
         }
     }
 
-    private static List<String> getNameAttributes(AbstractListingResponse response) {
-        final List<String> attributes = new ArrayList<>();
-        if (response.isNoInferiors()) {
-            attributes.add(ImapConstants.NAME_ATTRIBUTE_NOINFERIORS);
-        }
-        if (response.isNoSelect()) {
-            attributes.add(ImapConstants.NAME_ATTRIBUTE_NOSELECT);
-        }
-        if (response.isMarked()) {
-            attributes.add(ImapConstants.NAME_ATTRIBUTE_MARKED);
-        }
-        if (response.isUnmarked()) {
-            attributes.add(ImapConstants.NAME_ATTRIBUTE_UNMARKED);
-        }
-        if (response.hasChildren()) {
-            attributes.add(ImapConstants.NAME_ATTRIBUTE_HAS_CHILDREN);
+    private static ImmutableList<String> getNameAttributes(AbstractListingResponse response) {
+        return ImmutableList
+            .<String>builder()
+            .addAll(selectabilityAsString(response.getSelectability()))
+            .addAll(childrenAsString(response.getChildren()))
+            .addAll(mailboxAttributeAsString(response.getType()))
+            .build();
+    }
+
+
+    private static List<String> selectabilityAsString(MailboxMetaData.Selectability selectability) {
+        switch (selectability) {
+            case MARKED:
+                return ImmutableList.of(ImapConstants.NAME_ATTRIBUTE_MARKED);
+            case NOSELECT:
+                return ImmutableList.of(ImapConstants.NAME_ATTRIBUTE_NOSELECT);
+            case UNMARKED:
+                return ImmutableList.of(ImapConstants.NAME_ATTRIBUTE_UNMARKED);
+            default:
+                return ImmutableList.of();
         }
-        if (response.hasNoChildren()) {
-            attributes.add(ImapConstants.NAME_ATTRIBUTE_HAS_NO_CHILDREN);
+    }
+
+    private static ImmutableList<String> childrenAsString(MailboxMetaData.Children children) {
+        switch (children) {
+            case HAS_CHILDREN:
+                return ImmutableList.of(ImapConstants.NAME_ATTRIBUTE_HAS_CHILDREN);
+            case HAS_NO_CHILDREN:
+                return ImmutableList.of(ImapConstants.NAME_ATTRIBUTE_HAS_NO_CHILDREN);
+            case NO_INFERIORS:
+                return ImmutableList.of(ImapConstants.NAME_ATTRIBUTE_NOINFERIORS);
+            default:
+                return ImmutableList.of();
         }
-        if (!MailboxType.OTHER.equals(response.getType())) {
-            attributes.add(response.getType().getAttributeName());
+    }
+
+    private static ImmutableList<String> mailboxAttributeAsString(MailboxType type) {
+        String attributeName = type.getAttributeName();
+        if (attributeName != null) {
+            return ImmutableList.of(attributeName);
         }
-        return attributes;
+        return ImmutableList.of();
     }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/efe85492/protocols/imap/src/main/java/org/apache/james/imap/message/response/AbstractListingResponse.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/message/response/AbstractListingResponse.java b/protocols/imap/src/main/java/org/apache/james/imap/message/response/AbstractListingResponse.java
index 53fcf78..ca198dd 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/message/response/AbstractListingResponse.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/message/response/AbstractListingResponse.java
@@ -19,39 +19,27 @@
 
 package org.apache.james.imap.message.response;
 
-import org.apache.james.imap.api.process.MailboxType;
-
-/**
- * <code>LIST</code> and <code>LSUB</code> return identical data.
- */
-public abstract class AbstractListingResponse {
-
-    private final boolean children;
-
-    private final boolean noChildren;
-
-    private final boolean noInferiors;
-
-    private final boolean noSelect;
+import java.util.Objects;
 
-    private final boolean marked;
+import org.apache.james.imap.api.process.MailboxType;
+import org.apache.james.mailbox.model.MailboxMetaData;
 
-    private final boolean unmarked;
+import com.google.common.base.MoreObjects;
 
-    private final char hierarchyDelimiter;
+public abstract class AbstractListingResponse {
 
+    private final MailboxMetaData.Children children;
+    private final MailboxMetaData.Selectability selectability;
     private final String name;
-
+    private final char hierarchyDelimiter;
     private final MailboxType type;
 
-    public AbstractListingResponse(boolean noInferiors, boolean noSelect, boolean marked, boolean unmarked, boolean hasChildren, boolean hasNoChildren, String name, char hierarchyDelimiter, MailboxType type) {
+    public AbstractListingResponse(MailboxMetaData.Children children,
+                                   MailboxMetaData.Selectability selectability,
+                                   String name, char hierarchyDelimiter, MailboxType type) {
         super();
-        this.noInferiors = noInferiors;
-        this.noSelect = noSelect;
-        this.marked = marked;
-        this.unmarked = unmarked;
-        this.children = hasChildren;
-        this.noChildren = hasNoChildren;
+        this.children = children;
+        this.selectability = selectability;
         this.name = name;
         this.hierarchyDelimiter = hierarchyDelimiter;
         this.type = type;
@@ -60,22 +48,13 @@ public abstract class AbstractListingResponse {
     /**
      * Gets hierarchy delimiter.
      * 
-     * @return hierarchy delimiter, or null if no hierarchy exists
+     * @return hierarchy delimiter, or Character.UNASSIGNED if no hierarchy exists
      */
     public final char getHierarchyDelimiter() {
         return hierarchyDelimiter;
     }
 
     /**
-     * Is <code>Marked</code> name attribute set?
-     * 
-     * @return true if <code>Marked</code>, false otherwise
-     */
-    public final boolean isMarked() {
-        return marked;
-    }
-
-    /**
      * Gets the listed name.
      * 
      * @return name of the listed mailbox, not null
@@ -84,119 +63,45 @@ public abstract class AbstractListingResponse {
         return name;
     }
 
-    /**
-     * Is <code>Noinferiors</code> name attribute set?
-     * 
-     * @return true if <code>Noinferiors</code>, false otherwise
-     */
-    public final boolean isNoInferiors() {
-        return noInferiors;
-    }
-
-    /**
-     * Is <code>Noselect</code> name attribute set?
-     * 
-     * @return true if <code>Noselect</code>, false otherwise
-     */
-    public final boolean isNoSelect() {
-        return noSelect;
-    }
-
-    /**
-     * Is <code>Unmarked</code> name attribute set?
-     * 
-     * @return true if <code>Unmarked</code>, false otherwise
-     */
-    public final boolean isUnmarked() {
-        return unmarked;
-    }
-
-    /**
-     * Is the <code>HasNoChildren</code> name attribute set?
-     * 
-     * @return true if <code>HasNoChildren</code>, false otherwise
-     */
-    public boolean hasNoChildren() {
-        return noChildren;
+    public MailboxType getType() {
+        return type;
     }
 
-    /**
-     * Is the <code>HasChildren</code> name attribute set?
-     * 
-     * @return true if <code>HasChildren</code>, false otherwise
-     */
-    public boolean hasChildren() {
+    public MailboxMetaData.Children getChildren() {
         return children;
     }
 
-    /**
-     * returns type of the mailbox
-     * 
-     * @return mailbox type
-     */
-    public MailboxType getType() {
-        return type;
+    public MailboxMetaData.Selectability getSelectability() {
+        return selectability;
     }
 
     @Override
-    public int hashCode() {
-        final int PRIME = 31;
-        int result = 1;
-        result = PRIME * result + (children ? 1231 : 1237);
-        result = PRIME * result + hierarchyDelimiter;
-        result = PRIME * result + type.ordinal();
-        result = PRIME * result + (marked ? 1231 : 1237);
-        result = PRIME * result + ((name == null) ? 0 : name.hashCode());
-        result = PRIME * result + (noChildren ? 1231 : 1237);
-        result = PRIME * result + (noInferiors ? 1231 : 1237);
-        result = PRIME * result + (noSelect ? 1231 : 1237);
-        result = PRIME * result + (unmarked ? 1231 : 1237);
-        return result;
+    public boolean equals(Object other) {
+        if (other instanceof AbstractListingResponse) {
+            AbstractListingResponse that = (AbstractListingResponse) other;
+
+            return Objects.equals(this.children, that.children) &&
+                Objects.equals(this.selectability, that.selectability) &&
+                Objects.equals(this.name, that.name) &&
+                Objects.equals(this.hierarchyDelimiter, that.hierarchyDelimiter) &&
+                Objects.equals(this.type, that.type);
+        }
+        return false;
     }
 
     @Override
-    public boolean equals(Object obj) {
-        if (this == obj)
-            return true;
-        if (obj == null)
-            return false;
-        if (getClass() != obj.getClass())
-            return false;
-        final AbstractListingResponse other = (AbstractListingResponse) obj;
-        if (children != other.children)
-            return false;
-        if (hierarchyDelimiter != other.hierarchyDelimiter)
-            return false;
-        if (marked != other.marked)
-            return false;
-        if (name == null) {
-            if (other.name != null)
-                return false;
-        } else if (!name.equals(other.name))
-            return false;
-        if (noChildren != other.noChildren)
-            return false;
-        if (noInferiors != other.noInferiors)
-            return false;
-        if (noSelect != other.noSelect)
-            return false;
-        if (unmarked != other.unmarked)
-            return false;
-        if (!type.equals(other.type))
-            return false;
-        return true;
+    public int hashCode() {
+        return Objects.hash(children, selectability, name, hierarchyDelimiter, type);
     }
 
-    /**
-     * Renders object as a string suitable for logging.
-     * 
-     * @return a <code>String</code> representation of this object.
-     */
+    @Override
     public String toString() {
-        final String TAB = " ";
-
-        return getClass().getName() + " ( " + "noInferiors = " + this.noInferiors + TAB + "noSelect = " + this.noSelect + TAB + "marked = " + this.marked + TAB + "unmarked = " + this.unmarked + TAB + "hierarchyDelimiter = " + this.hierarchyDelimiter + TAB + "name = " + this.name + TAB
-                + "type = " + this.type + TAB + " )";
+        return MoreObjects.toStringHelper(this)
+            .add("children", children)
+            .add("selectability", selectability)
+            .add("name", name)
+            .add("hierarchyDelimiter", hierarchyDelimiter)
+            .add("type", type)
+            .toString();
     }
-
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/efe85492/protocols/imap/src/main/java/org/apache/james/imap/message/response/LSubResponse.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/message/response/LSubResponse.java b/protocols/imap/src/main/java/org/apache/james/imap/message/response/LSubResponse.java
index 3a14e69..a4b1aa4 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/message/response/LSubResponse.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/message/response/LSubResponse.java
@@ -20,12 +20,20 @@ package org.apache.james.imap.message.response;
 
 import org.apache.james.imap.api.message.response.ImapResponseMessage;
 import org.apache.james.imap.api.process.MailboxType;
+import org.apache.james.mailbox.model.MailboxMetaData;
 
 /**
  * Values an IMAP4rev1 <code>LIST</code> response.
  */
 public final class LSubResponse extends AbstractListingResponse implements ImapResponseMessage {
     public LSubResponse(String name, boolean noSelect, char delimiter) {
-        super(false, noSelect, false, false, false, false, name, delimiter, MailboxType.OTHER);
+        super(MailboxMetaData.Children.CHILDREN_ALLOWED_BUT_UNKNOWN, fromNoSelect(noSelect), name, delimiter, MailboxType.OTHER);
+    }
+
+    private static MailboxMetaData.Selectability fromNoSelect(boolean noSelect) {
+        if (noSelect) {
+            return MailboxMetaData.Selectability.NOSELECT;
+        }
+        return MailboxMetaData.Selectability.NONE;
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/efe85492/protocols/imap/src/main/java/org/apache/james/imap/message/response/ListResponse.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/message/response/ListResponse.java b/protocols/imap/src/main/java/org/apache/james/imap/message/response/ListResponse.java
index 4e84b96..62efa61 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/message/response/ListResponse.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/message/response/ListResponse.java
@@ -20,13 +20,15 @@ package org.apache.james.imap.message.response;
 
 import org.apache.james.imap.api.message.response.ImapResponseMessage;
 import org.apache.james.imap.api.process.MailboxType;
+import org.apache.james.mailbox.model.MailboxMetaData;
 
 /**
  * Values an IMAP4rev1 <code>LIST</code> response.
  */
 public final class ListResponse extends AbstractListingResponse implements ImapResponseMessage {
 
-    public ListResponse(boolean noInferiors, boolean noSelect, boolean marked, boolean unmarked, boolean hasChildren, boolean hasNoChildren, String name, char delimiter) {
-        super(noInferiors, noSelect, marked, unmarked, hasChildren, hasNoChildren, name, delimiter, MailboxType.OTHER);
+    public ListResponse(MailboxMetaData.Children children, MailboxMetaData.Selectability selectability, String name, char hierarchyDelimiter) {
+        super(children, selectability, name, hierarchyDelimiter, MailboxType.OTHER);
     }
+
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/efe85492/protocols/imap/src/main/java/org/apache/james/imap/message/response/XListResponse.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/message/response/XListResponse.java b/protocols/imap/src/main/java/org/apache/james/imap/message/response/XListResponse.java
index eec5c98..df4b392 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/message/response/XListResponse.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/message/response/XListResponse.java
@@ -21,13 +21,15 @@ package org.apache.james.imap.message.response;
 
 import org.apache.james.imap.api.message.response.ImapResponseMessage;
 import org.apache.james.imap.api.process.MailboxType;
+import org.apache.james.mailbox.model.MailboxMetaData;
 
 /**
  * XLIST command response
  */
 public class XListResponse extends AbstractListingResponse implements ImapResponseMessage {
 
-    public XListResponse(boolean noInferiors, boolean noSelect, boolean marked, boolean unmarked, boolean hasChildren, boolean hasNoChildren, String name, char delimiter, MailboxType type) {
-        super(noInferiors, noSelect, marked, unmarked, hasChildren, hasNoChildren, name, delimiter, type);
+    public XListResponse(MailboxMetaData.Children children, MailboxMetaData.Selectability selectability, String name, char hierarchyDelimiter, MailboxType type) {
+        super(children, selectability, name, hierarchyDelimiter, type);
     }
+
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/efe85492/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java
index b23f649..e8f7d98 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java
@@ -36,7 +36,6 @@ import org.apache.james.imap.api.process.MailboxType;
 import org.apache.james.imap.api.process.MailboxTyper;
 import org.apache.james.imap.main.PathConverter;
 import org.apache.james.imap.message.request.ListRequest;
-import org.apache.james.imap.message.response.AbstractListingResponse;
 import org.apache.james.imap.message.response.ListResponse;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
@@ -44,7 +43,6 @@ import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.MailboxConstants;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxMetaData;
-import org.apache.james.mailbox.model.MailboxMetaData.Children;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.search.MailboxQuery;
 import org.apache.james.mailbox.model.search.PrefixedRegex;
@@ -53,8 +51,6 @@ import org.apache.james.util.MDCBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.annotations.VisibleForTesting;
-
 public class ListProcessor extends AbstractMailboxProcessor<ListRequest> {
     private static final Logger LOGGER = LoggerFactory.getLogger(ListProcessor.class);
 
@@ -77,8 +73,8 @@ public class ListProcessor extends AbstractMailboxProcessor<ListRequest> {
         doProcess(baseReferenceName, mailboxPatternString, session, tag, command, responder, null);
     }
 
-    protected ImapResponseMessage createResponse(boolean noInferior, boolean noSelect, boolean marked, boolean unmarked, boolean hasChildren, boolean hasNoChildren, String mailboxName, char delimiter, MailboxType type) {
-        return new ListResponse(noInferior, noSelect, marked, unmarked, hasChildren, hasNoChildren, mailboxName, delimiter);
+    protected ImapResponseMessage createResponse(MailboxMetaData.Children children, MailboxMetaData.Selectability selectability, String name, char hierarchyDelimiter, MailboxType type) {
+        return new ListResponse(children, selectability, name, hierarchyDelimiter);
     }
 
     /**
@@ -198,37 +194,18 @@ public class ListProcessor extends AbstractMailboxProcessor<ListRequest> {
     }
 
     private void processResult(Responder responder, boolean relative, MailboxMetaData listResult, MailboxType mailboxType) {
-        ImapResponseMessage response = convertMetadataToListResponse(relative, listResult, mailboxType);
+        final String mailboxName = mailboxName(relative, listResult.getPath(), listResult.getHierarchyDelimiter());
+
+        ImapResponseMessage response =
+            createResponse(
+                listResult.inferiors(),
+                listResult.getSelectability(),
+                mailboxName,
+                listResult.getHierarchyDelimiter(),
+                mailboxType);
         responder.respond(response);
     }
 
-    @VisibleForTesting <T extends AbstractListingResponse & ImapResponseMessage> T convertMetadataToListResponse(boolean relative, MailboxMetaData listResult, MailboxType mailboxType) {
-        final char delimiter = listResult.getHierarchyDelimiter();
-        final String mailboxName = mailboxName(relative, listResult.getPath(), delimiter);
-
-        final Children inferiors = listResult.inferiors();
-        final boolean noInferior = Children.NO_INFERIORS.equals(inferiors);
-        final boolean hasChildren = Children.HAS_CHILDREN.equals(inferiors);
-        final boolean hasNoChildren = Children.HAS_NO_CHILDREN.equals(inferiors);
-        boolean noSelect = false;
-        boolean marked = false;
-        boolean unmarked = false;
-        switch (listResult.getSelectability()) {
-        case MARKED:
-            marked = true;
-            break;
-        case UNMARKED:
-            unmarked = true;
-            break;
-        case NOSELECT:
-            noSelect = true;
-            break;
-        default:
-            break;
-        }
-        return (T)createResponse(noInferior, noSelect, marked, unmarked, hasChildren, hasNoChildren, mailboxName, delimiter, mailboxType);
-    }
-
     /**
      * retrieve mailboxType for specified mailboxPath using provided
      * MailboxTyper

http://git-wip-us.apache.org/repos/asf/james-project/blob/efe85492/protocols/imap/src/main/java/org/apache/james/imap/processor/XListProcessor.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/XListProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/XListProcessor.java
index eed6ec2..6ec007c 100644
--- a/protocols/imap/src/main/java/org/apache/james/imap/processor/XListProcessor.java
+++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/XListProcessor.java
@@ -35,6 +35,7 @@ import org.apache.james.imap.message.request.ListRequest;
 import org.apache.james.imap.message.request.XListRequest;
 import org.apache.james.imap.message.response.XListResponse;
 import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.model.MailboxMetaData;
 import org.apache.james.metrics.api.MetricFactory;
 
 import com.google.common.collect.ImmutableList;
@@ -81,7 +82,7 @@ public class XListProcessor extends ListProcessor implements CapabilityImplement
     }
 
     @Override
-    protected ImapResponseMessage createResponse(boolean noInferior, boolean noSelect, boolean marked, boolean unmarked, boolean hasChildren, boolean hasNoChildren, String mailboxName, char delimiter, MailboxType type) {
-        return new XListResponse(noInferior, noSelect, marked, unmarked, hasChildren, hasNoChildren, mailboxName, delimiter, type);
+    protected ImapResponseMessage createResponse(MailboxMetaData.Children children, MailboxMetaData.Selectability selectability, String name, char hierarchyDelimiter, MailboxType type) {
+        return new XListResponse(children, selectability, name, hierarchyDelimiter, type);
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/efe85492/protocols/imap/src/test/java/org/apache/james/imap/encode/LSubResponseEncoderTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/encode/LSubResponseEncoderTest.java b/protocols/imap/src/test/java/org/apache/james/imap/encode/LSubResponseEncoderTest.java
index a0c9348..119a0e4 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/encode/LSubResponseEncoderTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/encode/LSubResponseEncoderTest.java
@@ -29,6 +29,7 @@ import org.apache.james.imap.encode.base.ByteImapResponseWriter;
 import org.apache.james.imap.encode.base.ImapResponseComposerImpl;
 import org.apache.james.imap.message.response.LSubResponse;
 import org.apache.james.imap.message.response.ListResponse;
+import org.apache.james.mailbox.model.MailboxMetaData;
 import org.jmock.Mockery;
 import org.jmock.integration.junit4.JUnit4Mockery;
 import org.junit.Before;
@@ -49,8 +50,7 @@ public class LSubResponseEncoderTest  {
 
     @Test
     public void encoderShouldNotAcceptListResponse() {
-        assertThat(encoder.isAcceptable(new ListResponse(true, true, true,
-            true, false, false, "name", '.')))
+        assertThat(encoder.isAcceptable(new ListResponse(MailboxMetaData.Children.HAS_CHILDREN, MailboxMetaData.Selectability.NOSELECT, "name", '.')))
             .isFalse();
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/efe85492/protocols/imap/src/test/java/org/apache/james/imap/encode/ListResponseEncoderTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/encode/ListResponseEncoderTest.java b/protocols/imap/src/test/java/org/apache/james/imap/encode/ListResponseEncoderTest.java
index e70572d..2aef368 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/encode/ListResponseEncoderTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/encode/ListResponseEncoderTest.java
@@ -29,6 +29,7 @@ import org.apache.james.imap.encode.base.ByteImapResponseWriter;
 import org.apache.james.imap.encode.base.ImapResponseComposerImpl;
 import org.apache.james.imap.message.response.LSubResponse;
 import org.apache.james.imap.message.response.ListResponse;
+import org.apache.james.mailbox.model.MailboxMetaData;
 import org.jmock.Mockery;
 import org.jmock.integration.junit4.JUnit4Mockery;
 import org.junit.Before;
@@ -50,8 +51,7 @@ public class ListResponseEncoderTest {
 
     @Test
     public void encoderShouldAcceptListResponse() {
-        assertThat(encoder.isAcceptable(new ListResponse(true, true, true,
-            true, false, false, "name", '.')))
+        assertThat(encoder.isAcceptable(new ListResponse(MailboxMetaData.Children.HAS_CHILDREN, MailboxMetaData.Selectability.NONE, "name", '.')))
         .isTrue();
     }
 
@@ -74,7 +74,7 @@ public class ListResponseEncoderTest {
 
     @Test
 	public void encoderShouldIncludeListCommand() throws Exception {
-        encoder.encode(new ListResponse(false, false, false, false, false, false, "INBOX.name", '.'), composer, new FakeImapSession());
+        encoder.encode(new ListResponse(MailboxMetaData.Children.HAS_CHILDREN, MailboxMetaData.Selectability.NONE, "name", '.'), composer, new FakeImapSession());
         assertThat(writer.getString()).startsWith("* LIST");
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/efe85492/protocols/imap/src/test/java/org/apache/james/imap/encode/ListingEncodingUtilsTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/encode/ListingEncodingUtilsTest.java b/protocols/imap/src/test/java/org/apache/james/imap/encode/ListingEncodingUtilsTest.java
index dc2f439..746b707 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/encode/ListingEncodingUtilsTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/encode/ListingEncodingUtilsTest.java
@@ -18,6 +18,7 @@
  ****************************************************************/
 package org.apache.james.imap.encode;
 
+import static org.apache.james.mailbox.model.MailboxMetaData.*;
 import static org.assertj.core.api.Assertions.assertThat;
 
 import org.apache.james.imap.api.process.MailboxType;
@@ -25,6 +26,7 @@ import org.apache.james.imap.encode.base.ByteImapResponseWriter;
 import org.apache.james.imap.encode.base.ImapResponseComposerImpl;
 import org.apache.james.imap.message.response.ListResponse;
 import org.apache.james.imap.message.response.XListResponse;
+import org.apache.james.mailbox.model.MailboxMetaData;
 import org.junit.Test;
 
 public class ListingEncodingUtilsTest  {
@@ -37,7 +39,7 @@ public class ListingEncodingUtilsTest  {
 
     @Test
     public void encodeShouldWriteNilDelimiterWhenUnassigned() throws Exception {
-        ListResponse input = new ListResponse(false, false, false, false, true, false, nameParameter, ((char) Character.UNASSIGNED));
+        ListResponse input = new ListResponse(Children.HAS_CHILDREN, Selectability.NONE, nameParameter, ((char) Character.UNASSIGNED));
 
         ListingEncodingUtils.encodeListingResponse(typeNameParameters, composer, input);
         assertThat(writer.getString()).isEqualTo("* LIST (\\HasChildren) NIL \"mailbox\"\r\n");
@@ -45,7 +47,7 @@ public class ListingEncodingUtilsTest  {
 
     @Test
     public void encodeShouldWriteAnyDelimiter() throws Exception {
-        ListResponse input = new ListResponse(false, false, false, false, true, false, nameParameter, '#');
+        ListResponse input = new ListResponse(Children.HAS_CHILDREN, Selectability.NONE, nameParameter, '#');
 
         ListingEncodingUtils.encodeListingResponse(typeNameParameters, composer, input);
         assertThat(writer.getString()).isEqualTo("* LIST (\\HasChildren) \"#\" \"mailbox\"\r\n");
@@ -53,7 +55,7 @@ public class ListingEncodingUtilsTest  {
 
     @Test
     public void encodeShouldNotIncludeAttributeWhenNone() throws Exception {
-        ListResponse input = new ListResponse(false, false, false, false, false, false, nameParameter, '.');
+        ListResponse input = new ListResponse(Children.CHILDREN_ALLOWED_BUT_UNKNOWN, MailboxMetaData.Selectability.NONE, nameParameter, '.');
 
         ListingEncodingUtils.encodeListingResponse(typeNameParameters, composer, input);
         assertThat(writer.getString()).isEqualTo("* LIST () \".\" \"mailbox\"\r\n");
@@ -61,7 +63,7 @@ public class ListingEncodingUtilsTest  {
 
     @Test
     public void encodeShouldAddHasChildrenToAttributes() throws Exception {
-        ListResponse input = new ListResponse(false, false, false, false, true, false, nameParameter, '.');
+        ListResponse input = new ListResponse(Children.HAS_CHILDREN, Selectability.NONE, nameParameter, '.');
             
         ListingEncodingUtils.encodeListingResponse(typeNameParameters, composer, input);
         assertThat(writer.getString()).isEqualTo("* LIST (\\HasChildren) \".\" \"mailbox\"\r\n");
@@ -69,7 +71,7 @@ public class ListingEncodingUtilsTest  {
     
     @Test
     public void encodeShouldAddHasNoChildrenToAttributes() throws Exception {
-        ListResponse input = new ListResponse(false, false, false, false, false, true, nameParameter, '.');
+        ListResponse input = new ListResponse(Children.HAS_NO_CHILDREN, Selectability.NONE, nameParameter, '.');
             
         ListingEncodingUtils.encodeListingResponse(typeNameParameters, composer, input);
         assertThat(writer.getString()).isEqualTo("* LIST (\\HasNoChildren) \".\" \"mailbox\"\r\n");
@@ -77,15 +79,15 @@ public class ListingEncodingUtilsTest  {
 
     @Test
     public void encodeShouldAddSeveralAttributes() throws Exception {
-        ListResponse input = new ListResponse(true, true, false, false, false, true, nameParameter, '.');
+        ListResponse input = new ListResponse(Children.NO_INFERIORS, Selectability.NOSELECT, nameParameter, '.');
 
         ListingEncodingUtils.encodeListingResponse(typeNameParameters, composer, input);
-        assertThat(writer.getString()).isEqualTo("* LIST (\\Noinferiors \\Noselect \\HasNoChildren) \".\" \"mailbox\"\r\n");
+        assertThat(writer.getString()).isEqualTo("* LIST (\\Noselect \\Noinferiors) \".\" \"mailbox\"\r\n");
     }
 
     @Test
     public void encodeShouldAddMarkedAttribute() throws Exception {
-        ListResponse input = new ListResponse(false, false, true, false, false, false, nameParameter, '.');
+        ListResponse input = new ListResponse(Children.CHILDREN_ALLOWED_BUT_UNKNOWN, Selectability.MARKED, nameParameter, '.');
 
         ListingEncodingUtils.encodeListingResponse(typeNameParameters, composer, input);
         assertThat(writer.getString()).isEqualTo("* LIST (\\Marked) \".\" \"mailbox\"\r\n");
@@ -93,7 +95,7 @@ public class ListingEncodingUtilsTest  {
 
     @Test
     public void encodeShouldAddUnmarkedAttribute() throws Exception {
-        ListResponse input = new ListResponse(false, false, false, true, false, false, nameParameter, '.');
+        ListResponse input = new ListResponse(Children.CHILDREN_ALLOWED_BUT_UNKNOWN, Selectability.UNMARKED, nameParameter, '.');
 
         ListingEncodingUtils.encodeListingResponse(typeNameParameters, composer, input);
         assertThat(writer.getString()).isEqualTo("* LIST (\\Unmarked) \".\" \"mailbox\"\r\n");
@@ -101,7 +103,7 @@ public class ListingEncodingUtilsTest  {
 
     @Test
     public void encodeShouldAddXListAttributeWhenTypeIsInbox() throws Exception {
-        XListResponse input = new XListResponse(false, false, false, false, true, false, nameParameter, '.', MailboxType.INBOX);
+        XListResponse input = new XListResponse(Children.HAS_CHILDREN, Selectability.NONE, nameParameter, '.', MailboxType.INBOX);
 
         ListingEncodingUtils.encodeListingResponse("XLIST", composer, input);
         assertThat(writer.getString()).isEqualTo("* XLIST (\\HasChildren \\Inbox) \".\" \"mailbox\"\r\n");

http://git-wip-us.apache.org/repos/asf/james-project/blob/efe85492/protocols/imap/src/test/java/org/apache/james/imap/encode/SearchResponseEncoderTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/encode/SearchResponseEncoderTest.java b/protocols/imap/src/test/java/org/apache/james/imap/encode/SearchResponseEncoderTest.java
index fe6d0a0..70ea129 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/encode/SearchResponseEncoderTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/encode/SearchResponseEncoderTest.java
@@ -26,7 +26,10 @@ import static org.junit.Assert.assertTrue;
 import org.apache.james.imap.api.ImapMessage;
 import org.apache.james.imap.encode.base.ByteImapResponseWriter;
 import org.apache.james.imap.encode.base.ImapResponseComposerImpl;
+import org.apache.james.imap.message.response.LSubResponse;
+import org.apache.james.imap.message.response.ListResponse;
 import org.apache.james.imap.message.response.SearchResponse;
+import org.apache.james.mailbox.model.MailboxMetaData;
 import org.jmock.Mockery;
 import org.jmock.integration.junit4.JUnit4Mockery;
 import org.junit.Before;
@@ -57,6 +60,7 @@ public class SearchResponseEncoderTest {
     @Test
     public void testIsAcceptable() {
         assertTrue(encoder.isAcceptable(response));
+        assertFalse(encoder.isAcceptable(new LSubResponse("name", true, '.')));
         assertFalse(encoder.isAcceptable(context.mock(ImapMessage.class)));
         assertFalse(encoder.isAcceptable(null));
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/efe85492/protocols/imap/src/test/java/org/apache/james/imap/encode/XListResponseEncoderTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/encode/XListResponseEncoderTest.java b/protocols/imap/src/test/java/org/apache/james/imap/encode/XListResponseEncoderTest.java
index 7216dc8..c11b1f0 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/encode/XListResponseEncoderTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/encode/XListResponseEncoderTest.java
@@ -29,6 +29,7 @@ import org.apache.james.imap.encode.base.ImapResponseComposerImpl;
 import org.apache.james.imap.message.response.LSubResponse;
 import org.apache.james.imap.message.response.ListResponse;
 import org.apache.james.imap.message.response.XListResponse;
+import org.apache.james.mailbox.model.MailboxMetaData;
 import org.jmock.Mockery;
 import org.jmock.integration.junit4.JUnit4Mockery;
 import org.junit.Before;
@@ -50,8 +51,13 @@ public class XListResponseEncoderTest {
 
     @Test
     public void encoderShouldAcceptXListResponse() {
-        assertThat(encoder.isAcceptable(new XListResponse(true, true, true,
-            true, false, false, "name", '.', MailboxType.INBOX)))
+        assertThat(encoder.isAcceptable(
+            new XListResponse(
+                MailboxMetaData.Children.HAS_CHILDREN,
+                MailboxMetaData.Selectability.NONE,
+                "name",
+                '.',
+                MailboxType.INBOX)))
         .isTrue();
     }
 
@@ -74,8 +80,15 @@ public class XListResponseEncoderTest {
 
     @Test
 	public void encoderShouldIncludeListCommand() throws Exception {
-        encoder.encode(new XListResponse(true, true, true,
-            true, false, false, "name", '.', MailboxType.INBOX), composer, new FakeImapSession());
+        encoder.encode(
+            new XListResponse(
+                MailboxMetaData.Children.HAS_CHILDREN,
+                MailboxMetaData.Selectability.NONE,
+                "name",
+                '.',
+                MailboxType.INBOX),
+            composer,
+            new FakeImapSession());
         assertThat(writer.getString()).startsWith("* XLIST");
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/efe85492/protocols/imap/src/test/java/org/apache/james/imap/processor/ListProcessorTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/ListProcessorTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/ListProcessorTest.java
deleted file mode 100644
index 4c546b9..0000000
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/ListProcessorTest.java
+++ /dev/null
@@ -1,156 +0,0 @@
-/****************************************************************
- * 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.imap.processor;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import org.apache.james.imap.api.message.response.StatusResponseFactory;
-import org.apache.james.imap.api.process.ImapProcessor;
-import org.apache.james.imap.api.process.MailboxType;
-import org.apache.james.imap.message.response.ListResponse;
-import org.apache.james.mailbox.MailboxManager;
-import org.apache.james.mailbox.model.MailboxMetaData;
-import org.apache.james.mailbox.model.MailboxPath;
-import org.apache.james.mailbox.store.SimpleMailboxMetaData;
-import org.apache.james.metrics.api.NoopMetricFactory;
-import org.junit.Before;
-import org.junit.Test;
-
-public class ListProcessorTest  {
-
-    MailboxPath inboxPath = new MailboxPath("", "", "INBOX");
-    ListProcessor processor;
-
-    @Before
-    public void setUp() throws Exception {
-        StatusResponseFactory serverResponseFactory = null;
-        ImapProcessor next = null;
-        MailboxManager manager = null;
-        processor = new ListProcessor(next, manager, serverResponseFactory, new NoopMetricFactory());
-    }
-
-    @Test
-    public void convertHasChildrenShouldHaveHasChildrenFlagOnly() throws Exception {
-        ListResponse actual = processor.convertMetadataToListResponse(false,
-            new SimpleMailboxMetaData(inboxPath, null, '.', MailboxMetaData.Children.HAS_CHILDREN, MailboxMetaData.Selectability.NONE),
-            MailboxType.OTHER);
-        assertThat(actual).isEqualTo(
-            new ListResponse(
-                false,
-                false,
-                false,
-                false,
-                true,
-                false,
-                inboxPath.getFullName('.'),
-                '.')
-        );
-    }
-
-    @Test
-    public void convertHasNoChildrenShouldHaveHasNoChildrenFlagOnly() throws Exception {
-        ListResponse actual = processor.convertMetadataToListResponse(false,
-            new SimpleMailboxMetaData(inboxPath, null, '.', MailboxMetaData.Children.HAS_NO_CHILDREN, MailboxMetaData.Selectability.NONE),
-            MailboxType.OTHER);
-        assertThat(actual).isEqualTo(
-            new ListResponse(
-                false,
-                false,
-                false,
-                false,
-                false,
-                true,
-                inboxPath.getFullName('.'),
-                '.')
-        );
-    }
-    
-    @Test
-    public void convertNoInferiorShouldHaveNoInferiorFlagOnly() throws Exception {
-        ListResponse actual = processor.convertMetadataToListResponse(false,
-            new SimpleMailboxMetaData(inboxPath, null, '.', MailboxMetaData.Children.NO_INFERIORS, MailboxMetaData.Selectability.NONE),
-            MailboxType.OTHER);
-        assertThat(actual).isEqualTo(
-            new ListResponse(
-                true,
-                false,
-                false,
-                false,
-                false,
-                false,
-                inboxPath.getFullName('.'),
-                '.')
-        );
-    }
-
-    @Test
-    public void convertNoSelectUnknownChildrenShouldHaveNoSelectFlagOnly() throws Exception {
-        ListResponse actual = processor.convertMetadataToListResponse(false,
-            new SimpleMailboxMetaData(inboxPath, null, '.', MailboxMetaData.Children.CHILDREN_ALLOWED_BUT_UNKNOWN, MailboxMetaData.Selectability.NOSELECT),
-            MailboxType.OTHER);
-        assertThat(actual).isEqualTo(
-            new ListResponse(
-                false,
-                true,
-                false,
-                false,
-                false,
-                false,
-                inboxPath.getFullName('.'),
-                '.')
-        );
-    }
-
-    @Test
-    public void convertUnmarkedUnknownChildrenShouldHaveUnmarkedFlagOnly() throws Exception {
-        ListResponse actual = processor.convertMetadataToListResponse(false,
-            new SimpleMailboxMetaData(inboxPath, null, '.', MailboxMetaData.Children.CHILDREN_ALLOWED_BUT_UNKNOWN, MailboxMetaData.Selectability.UNMARKED),
-            MailboxType.OTHER);
-        assertThat(actual).isEqualTo(
-            new ListResponse(
-                false,
-                false,
-                false,
-                true,
-                false,
-                false,
-                inboxPath.getFullName('.'),
-                '.')
-        );
-    }
-
-    @Test
-    public void convertMarkedUnknownChildrenShouldHaveMarkedFlagOnly() throws Exception {
-        ListResponse actual = processor.convertMetadataToListResponse(false,
-            new SimpleMailboxMetaData(inboxPath, null, '.', MailboxMetaData.Children.CHILDREN_ALLOWED_BUT_UNKNOWN, MailboxMetaData.Selectability.MARKED),
-            MailboxType.OTHER);
-        assertThat(actual).isEqualTo(
-            new ListResponse(
-                false,
-                false,
-                true,
-                false,
-                false,
-                false,
-                inboxPath.getFullName('.'),
-                '.')
-        );
-    }
-}


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


[3/9] james-project git commit: MAILBOX-318 Refuse to share mailbox with other domains

Posted by ad...@apache.org.
MAILBOX-318 Refuse to share mailbox with other domains


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

Branch: refs/heads/master
Commit: d0d9b2f9ea106691b2b3627ad4fe28aaa2fb7e7b
Parents: 562eeaa
Author: Antoine Duprat <ad...@linagora.com>
Authored: Fri Nov 3 14:30:54 2017 +0100
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Tue Nov 7 15:33:53 2017 +0100

----------------------------------------------------------------------
 .../exception/DifferentDomainException.java     | 27 +++++++++
 mailbox/store/pom.xml                           |  4 ++
 .../james/mailbox/store/StoreRightManager.java  | 27 +++++++++
 .../mailbox/store/StoreRightManagerTest.java    | 59 ++++++++++++++++++++
 ...CassandraSetMailboxesMethodCucumberTest.java |  4 +-
 .../integration/GetMailboxesMethodTest.java     | 11 ++--
 .../integration/SetMailboxesMethodTest.java     | 10 ++--
 .../cucumber/SetMailboxesMethodStepdefs.java    | 15 +++++
 .../resources/cucumber/SetMailboxes.feature     | 30 ++++++++++
 .../MemorySetMailboxesMethodCucumberTest.java   |  4 +-
 .../methods/SetMailboxesUpdateProcessor.java    |  6 ++
 11 files changed, 183 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/d0d9b2f9/mailbox/api/src/main/java/org/apache/james/mailbox/exception/DifferentDomainException.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/exception/DifferentDomainException.java b/mailbox/api/src/main/java/org/apache/james/mailbox/exception/DifferentDomainException.java
new file mode 100644
index 0000000..20e7aa8
--- /dev/null
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/exception/DifferentDomainException.java
@@ -0,0 +1,27 @@
+/****************************************************************
+ * 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.exception;
+
+public class DifferentDomainException extends MailboxException {
+
+    public DifferentDomainException() {
+        super();
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/d0d9b2f9/mailbox/store/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/store/pom.xml b/mailbox/store/pom.xml
index 3049c2e..9befb3a 100644
--- a/mailbox/store/pom.xml
+++ b/mailbox/store/pom.xml
@@ -56,6 +56,10 @@
         </dependency>
         <dependency>
             <groupId>${project.groupId}</groupId>
+            <artifactId>james-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${project.groupId}</groupId>
             <artifactId>james-server-util</artifactId>
         </dependency>
         <dependency>

http://git-wip-us.apache.org/repos/asf/james-project/blob/d0d9b2f9/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java
index 1ddfd6c..e1796fb 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreRightManager.java
@@ -19,20 +19,24 @@
 
 package org.apache.james.mailbox.store;
 
+import java.util.Map;
 import java.util.Optional;
 
 import javax.inject.Inject;
 import javax.mail.Flags;
 
+import org.apache.james.core.User;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.RightManager;
 import org.apache.james.mailbox.acl.GroupMembershipResolver;
 import org.apache.james.mailbox.acl.MailboxACLResolver;
+import org.apache.james.mailbox.exception.DifferentDomainException;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.exception.UnsupportedRightException;
 import org.apache.james.mailbox.model.MailboxACL;
 import org.apache.james.mailbox.model.MailboxACL.ACLCommand;
 import org.apache.james.mailbox.model.MailboxACL.EntryKey;
+import org.apache.james.mailbox.model.MailboxACL.NameType;
 import org.apache.james.mailbox.model.MailboxACL.Rfc4314Rights;
 import org.apache.james.mailbox.model.MailboxACL.Right;
 import org.apache.james.mailbox.model.MailboxId;
@@ -112,11 +116,16 @@ public class StoreRightManager implements RightManager {
 
     @Override
     public void applyRightsCommand(MailboxPath mailboxPath, ACLCommand mailboxACLCommand, MailboxSession session) throws MailboxException {
+        assertSharesBelongsToUserDomain(mailboxPath.getUser(), mailboxACLCommand);
         MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(session);
         Mailbox mailbox = mapper.findMailboxByPath(mailboxPath);
         mapper.execute(Mapper.toTransaction(() -> mapper.updateACL(mailbox, mailboxACLCommand)));
     }
 
+    private void assertSharesBelongsToUserDomain(String user, ACLCommand mailboxACLCommand) throws DifferentDomainException {
+        assertSharesBelongsToUserDomain(user, ImmutableMap.of(mailboxACLCommand.getEntryKey(), mailboxACLCommand.getRights()));
+    }
+
     public boolean isReadWrite(MailboxSession session, Mailbox mailbox, Flags sharedPermanentFlags) throws UnsupportedRightException {
         Rfc4314Rights rights = myRights(mailbox, session);
 
@@ -161,12 +170,30 @@ public class StoreRightManager implements RightManager {
 
     @Override
     public void setRights(MailboxPath mailboxPath, MailboxACL mailboxACL, MailboxSession session) throws MailboxException {
+        assertSharesBelongsToUserDomain(mailboxPath.getUser(), mailboxACL.getEntries());
         MailboxMapper mapper = mailboxSessionMapperFactory.getMailboxMapper(session);
         Mailbox mailbox = mapper.findMailboxByPath(mailboxPath);
 
         setRights(mailboxACL, mapper, mailbox);
     }
 
+    @VisibleForTesting
+    void assertSharesBelongsToUserDomain(String user, Map<EntryKey, Rfc4314Rights> entries) throws DifferentDomainException {
+        if (entries.keySet().stream()
+            .filter(entry -> !entry.getNameType().equals(NameType.special))
+            .map(EntryKey::getName)
+            .anyMatch(name -> areDomainsDifferent(name, user))) {
+            throw new DifferentDomainException();
+        }
+    }
+
+    @VisibleForTesting
+    boolean areDomainsDifferent(String user, String otherUser) {
+        Optional<String> domain = User.fromUsername(user).getDomainPart();
+        Optional<String> otherDomain = User.fromUsername(otherUser).getDomainPart();
+        return !domain.equals(otherDomain);
+    }
+
     private void setRights(MailboxACL mailboxACL, MailboxMapper mapper, Mailbox mailbox) throws MailboxException {
         mapper.execute(Mapper.toTransaction(() -> mapper.setACL(mailbox, mailboxACL)));
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/d0d9b2f9/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreRightManagerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreRightManagerTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreRightManagerTest.java
index 2b9a81b..265bfe8 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreRightManagerTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreRightManagerTest.java
@@ -24,6 +24,7 @@ import static org.apache.james.mailbox.fixture.MailboxFixture.BOB;
 import static org.apache.james.mailbox.fixture.MailboxFixture.CEDRIC;
 import static org.apache.james.mailbox.fixture.MailboxFixture.INBOX_ALICE;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -33,12 +34,14 @@ import org.apache.james.mailbox.acl.GroupMembershipResolver;
 import org.apache.james.mailbox.acl.MailboxACLResolver;
 import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
 import org.apache.james.mailbox.acl.UnionMailboxACLResolver;
+import org.apache.james.mailbox.exception.DifferentDomainException;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.exception.MailboxNotFoundException;
 import org.apache.james.mailbox.exception.UnsupportedRightException;
 import org.apache.james.mailbox.fixture.MailboxFixture;
 import org.apache.james.mailbox.mock.MockMailboxSession;
 import org.apache.james.mailbox.model.MailboxACL;
+import org.apache.james.mailbox.model.MailboxACL.ACLCommand;
 import org.apache.james.mailbox.model.MailboxACL.Right;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.store.mail.MailboxMapper;
@@ -223,4 +226,60 @@ public class StoreRightManagerTest {
             new SimpleMailbox(INBOX_ALICE, UID_VALIDITY), acl, new MockMailboxSession(BOB));
         assertThat(actual.getEntries()).containsKey(MailboxACL.EntryKey.createUserEntryKey(BOB));
     }
+
+    @Test
+    public void areDomainsDifferentShouldReturnTrueWhenOneHasDomainNotTheOther() {
+        assertThat(storeRightManager.areDomainsDifferent("user@domain.org", "otherUser")).isTrue();
+    }
+
+    @Test
+    public void areDomainsDifferentShouldReturnTrueWhenOtherHasDomainNotTheOne() {
+        assertThat(storeRightManager.areDomainsDifferent("user", "otherUser@domain.org")).isTrue();
+    }
+
+    @Test
+    public void areDomainsDifferentShouldReturnFalseWhenNoDomain() {
+        assertThat(storeRightManager.areDomainsDifferent("user", "otherUser")).isFalse();
+    }
+
+    @Test
+    public void areDomainsDifferentShouldReturnTrueWhenDomainsAreDifferent() {
+        assertThat(storeRightManager.areDomainsDifferent("user@domain.org", "otherUser@otherdomain.org")).isTrue();
+    }
+
+    @Test
+    public void areDomainsDifferentShouldReturnFalseWhenDomainsAreIdentical() {
+        assertThat(storeRightManager.areDomainsDifferent("user@domain.org", "otherUser@domain.org")).isFalse();
+    }
+
+    @Test
+    public void assertSharesBelongsToUserDomainShouldThrowWhenOneDomainIsDifferent() throws Exception  {
+        MailboxACL mailboxACL = new MailboxACL(new MailboxACL.Entry("a@domain.org", Right.Write), 
+                new MailboxACL.Entry("b@otherdomain.org", Right.Write), 
+                new MailboxACL.Entry("c@domain.org", Right.Write));
+        
+        assertThatThrownBy(() -> storeRightManager.assertSharesBelongsToUserDomain("user@domain.org", mailboxACL.getEntries()))
+            .isInstanceOf(DifferentDomainException.class);
+    }
+
+    @Test
+    public void assertSharesBelongsToUserDomainShouldNotThrowWhenDomainsAreIdentical() throws Exception  {
+        MailboxACL mailboxACL = new MailboxACL(new MailboxACL.Entry("a@domain.org", Right.Write), 
+                new MailboxACL.Entry("b@domain.org", Right.Write), 
+                new MailboxACL.Entry("c@domain.org", Right.Write));
+        
+        storeRightManager.assertSharesBelongsToUserDomain("user@domain.org", mailboxACL.getEntries());
+    }
+
+    @Test
+    public void applyRightsCommandShouldThrowWhenDomainsAreDifferent() {
+        MailboxPath mailboxPath = MailboxPath.forUser("user@domain.org", "mailbox");
+        ACLCommand aclCommand = MailboxACL.command()
+            .forUser("otherUser@otherdomain.org")
+            .rights(MailboxACL.FULL_RIGHTS)
+            .asAddition();
+       
+        assertThatThrownBy(() -> storeRightManager.applyRightsCommand(mailboxPath, aclCommand, aliceSession))
+            .isInstanceOf(DifferentDomainException.class);
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/d0d9b2f9/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraSetMailboxesMethodCucumberTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraSetMailboxesMethodCucumberTest.java b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraSetMailboxesMethodCucumberTest.java
index c7ed001..1751d4b 100644
--- a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraSetMailboxesMethodCucumberTest.java
+++ b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/cucumber/CassandraSetMailboxesMethodCucumberTest.java
@@ -27,8 +27,8 @@ import cucumber.api.CucumberOptions;
 import cucumber.api.junit.Cucumber;
 
 @RunWith(Cucumber.class)
-@CucumberOptions(features="classpath:cucumber/MailboxModification.feature",
-                glue={"org.apache.james.jmap.methods.integration", "org.apache.james.jmap.cassandra.cucumber"},
+@CucumberOptions(features= { "classpath:cucumber/MailboxModification.feature", "classpath:cucumber/SetMailboxes.feature" },
+                glue= { "org.apache.james.jmap.methods.integration", "org.apache.james.jmap.cassandra.cucumber" },
                 strict = true)
 public class CassandraSetMailboxesMethodCucumberTest {
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/d0d9b2f9/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMailboxesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMailboxesMethodTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMailboxesMethodTest.java
index 48c7a39..ffc7e89 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMailboxesMethodTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMailboxesMethodTest.java
@@ -84,6 +84,7 @@ public abstract class GetMailboxesMethodTest {
     protected abstract GuiceJamesServer createJmapServer();
 
     private AccessToken accessToken;
+    private String domain;
     private String alice;
     private String bob;
     private String cedric;
@@ -106,7 +107,7 @@ public abstract class GetMailboxesMethodTest {
                 .build();
         RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
 
-        String domain = "domain.tld";
+        domain = "domain.tld";
         alice = "alice@" + domain;
         String alicePassword = "aliceSecret";
         bob = "bob@" + domain;
@@ -252,8 +253,8 @@ public abstract class GetMailboxesMethodTest {
     public void getMailboxesShouldReturnSharedWithProperty() throws Exception {
         String mailboxName = "myMailbox";
         String myMailboxId = mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, alice, mailboxName).serialize();
-        String targetUser1 = "toUser1@domain.com";
-        String targetUser2 = "toUser2@domain.com";
+        String targetUser1 = "toUser1@" + domain;
+        String targetUser2 = "toUser2@" + domain;
         Mailbox myMailbox = mailboxProbe.getMailbox(MailboxConstants.USER_NAMESPACE, alice, mailboxName);
         aclProbe.replaceRights(myMailbox.generateAssociatedPath(), targetUser1, new Rfc4314Rights(Right.Lookup, Right.Administer));
         aclProbe.replaceRights(myMailbox.generateAssociatedPath(), targetUser2, new Rfc4314Rights(Right.Read, Right.Lookup));
@@ -275,7 +276,7 @@ public abstract class GetMailboxesMethodTest {
     public void getMailboxesShouldRemoveOwnerRight() throws Exception {
         String mailboxName = "myMailbox";
         String myMailboxId = mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, alice, mailboxName).serialize();
-        String targetUser1 = "toUser1@domain.com";
+        String targetUser1 = "toUser1@" + domain;
         Mailbox myMailbox = mailboxProbe.getMailbox(MailboxConstants.USER_NAMESPACE, alice, mailboxName);
         aclProbe.replaceRights(myMailbox.generateAssociatedPath(), alice, new Rfc4314Rights(Right.Read, Right.Administer));
         aclProbe.replaceRights(myMailbox.generateAssociatedPath(), targetUser1, new Rfc4314Rights(Right.Read, Right.Lookup));
@@ -313,7 +314,7 @@ public abstract class GetMailboxesMethodTest {
     public void nonHandledRightsShouldBeFilteredOut() throws Exception {
         String mailboxName = "myMailbox";
         String myMailboxId = mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, alice, mailboxName).serialize();
-        String targetUser1 = "toUser1@domain.com";
+        String targetUser1 = "toUser1@" + domain;
         Mailbox myMailbox = mailboxProbe.getMailbox(MailboxConstants.USER_NAMESPACE, alice, mailboxName);
         aclProbe.replaceRights(myMailbox.generateAssociatedPath(), targetUser1, new Rfc4314Rights(Right.Lookup, Right.Post));
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/d0d9b2f9/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodTest.java
index baeac41..690de87 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMailboxesMethodTest.java
@@ -1176,7 +1176,7 @@ public abstract class SetMailboxesMethodTest {
                 "    {" +
                 "      \"update\": {" +
                 "        \"" + mailboxId.serialize() + "\" : {" +
-                "          \"sharedWith\" : {\"user\": [\"a\", \"w\"]}" +
+                "          \"sharedWith\" : {\"user@" + USERS_DOMAIN + "\": [\"a\", \"w\"]}" +
                 "        }" +
                 "      }" +
                 "    }," +
@@ -1285,7 +1285,7 @@ public abstract class SetMailboxesMethodTest {
     @Test
     public void updateShouldApplyWhenSettingNewACL() {
         String myBox = "myBox";
-        String user = "user";
+        String user = "user@" + USERS_DOMAIN;
         MailboxId mailboxId = mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, myBox);
         String requestBody =
             "[" +
@@ -1321,7 +1321,7 @@ public abstract class SetMailboxesMethodTest {
     @Test
     public void updateShouldModifyStoredDataWhenUpdatingACL() {
         String myBox = "myBox";
-        String user = "user";
+        String user = "user@" + USERS_DOMAIN;
         MailboxId mailboxId = mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, myBox);
 
         with()
@@ -1421,8 +1421,8 @@ public abstract class SetMailboxesMethodTest {
     @Test
     public void updateShouldModifyStoredDataWhenSwitchingACLUser() {
         String myBox = "myBox";
-        String user1 = "user1";
-        String user2 = "user2";
+        String user1 = "user1@" + USERS_DOMAIN;
+        String user2 = "user2@" + USERS_DOMAIN;
         MailboxId mailboxId = mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, myBox);
 
         with()

http://git-wip-us.apache.org/repos/asf/james-project/blob/d0d9b2f9/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java
index d26df19..3705db7 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java
@@ -24,6 +24,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 import java.io.ByteArrayInputStream;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 import java.util.stream.IntStream;
 
@@ -38,6 +39,7 @@ import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 
 import com.github.fge.lambdas.Throwing;
+import com.google.common.collect.Maps;
 import com.jayway.awaitility.Awaitility;
 import com.jayway.awaitility.Duration;
 import com.jayway.jsonpath.DocumentContext;
@@ -191,4 +193,17 @@ public class SetMailboxesMethodStepdefs {
             return jsonPath.<List<String>>read(ARGUMENTS + ".messageIds").size() == messageCount;
         });
     }
+
+    @Then("^\"([^\"]*)\" receives not updated on mailbox \"([^\"]*)\" with kind \"([^\"]*)\" and message \"([^\"]*)\"$")
+    public void assertNotUpdatedWithGivenProperties(String userName, String mailboxName, String type, String message) throws Exception {
+        Mailbox mailbox = mainStepdefs.mailboxProbe.getMailbox("#private", userName, mailboxName);
+        assertThat(httpClient.response.getStatusLine().getStatusCode()).isEqualTo(200);
+        assertThat(httpClient.jsonPath.<String>read(NAME)).isEqualTo("mailboxesSet");
+        
+        Map<String, Map<String, String>> notUpdated = httpClient.jsonPath.<Map<String, Map<String, String>>>read(ARGUMENTS + ".notUpdated");
+        assertThat(notUpdated).hasSize(1);
+        Map<String, String> parameters = notUpdated.get(mailbox.getMailboxId().serialize());
+        assertThat(parameters).contains(Maps.immutableEntry("type", type),
+                Maps.immutableEntry("description", message));
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/d0d9b2f9/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/SetMailboxes.feature
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/SetMailboxes.feature b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/SetMailboxes.feature
new file mode 100644
index 0000000..57a7512
--- /dev/null
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/SetMailboxes.feature
@@ -0,0 +1,30 @@
+#***************************************************************
+# 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.                                           *
+# **************************************************************/
+Feature: SetMailboxes method
+
+  Background:
+    Given a domain named "domain.tld"
+    And a user "alice@domain.tld"
+    And "alice@domain.tld" has a mailbox "shared"
+
+  Scenario: setMailboxes should reject sharing a mailbox to another domain
+    Given a domain named "otherdomain.tld"
+    And a user "bob@otherdomain.tld"
+    When "alice@domain.tld" shares its mailbox "shared" with rights "lrw" with "bob@otherdomain.tld"
+    Then "alice@domain.tld" receives not updated on mailbox "shared" with kind "invalidArguments" and message "Cannot share a mailbox to another domain"

http://git-wip-us.apache.org/repos/asf/james-project/blob/d0d9b2f9/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemorySetMailboxesMethodCucumberTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemorySetMailboxesMethodCucumberTest.java b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemorySetMailboxesMethodCucumberTest.java
index c61cfb5..e0cbec0 100644
--- a/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemorySetMailboxesMethodCucumberTest.java
+++ b/server/protocols/jmap-integration-testing/memory-jmap-integration-testing/src/test/java/org/apache/james/jmap/memory/cucumber/MemorySetMailboxesMethodCucumberTest.java
@@ -25,8 +25,8 @@ import cucumber.api.CucumberOptions;
 import cucumber.api.junit.Cucumber;
 
 @RunWith(Cucumber.class)
-@CucumberOptions(features="classpath:cucumber/MailboxModification.feature",
-                glue={"org.apache.james.jmap.methods.integration", "org.apache.james.jmap.memory.cucumber"},
+@CucumberOptions(features= { "classpath:cucumber/MailboxModification.feature", "classpath:cucumber/SetMailboxes.feature" },
+                glue= { "org.apache.james.jmap.methods.integration", "org.apache.james.jmap.memory.cucumber" },
                 strict = true)
 public class MemorySetMailboxesMethodCucumberTest {
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/d0d9b2f9/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java
index 634c73a..4d7a8fd 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMailboxesUpdateProcessor.java
@@ -41,6 +41,7 @@ import org.apache.james.jmap.utils.MailboxUtils;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.SubscriptionManager;
+import org.apache.james.mailbox.exception.DifferentDomainException;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.exception.MailboxExistsException;
 import org.apache.james.mailbox.exception.MailboxNameException;
@@ -134,6 +135,11 @@ public class SetMailboxesUpdateProcessor implements SetMailboxesProcessor {
                     .type("invalidArguments")
                     .description("Cannot rename a mailbox to an already existing mailbox.")
                     .build());
+        } catch (DifferentDomainException e) {
+            responseBuilder.notUpdated(mailboxId, SetError.builder()
+                .type("invalidArguments")
+                .description("Cannot share a mailbox to another domain")
+                .build());
         } catch (MailboxException e) {
             LOGGER.error("Error while updating mailbox", e);
             responseBuilder.notUpdated(mailboxId, SetError.builder()


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


[2/9] james-project git commit: MAILBOX-318 Merge SetMailboxes stepdefs together

Posted by ad...@apache.org.
MAILBOX-318 Merge SetMailboxes stepdefs together


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

Branch: refs/heads/master
Commit: 30483cf18fe1075b0ec9bb934200e8877fdbbde2
Parents: b3262f5
Author: Antoine Duprat <ad...@linagora.com>
Authored: Fri Nov 3 10:59:01 2017 +0100
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Tue Nov 7 15:33:42 2017 +0100

----------------------------------------------------------------------
 .../integration/cucumber/MailboxStepdefs.java   | 61 --------------------
 .../cucumber/SetMailboxesMethodStepdefs.java    | 23 ++++++++
 2 files changed, 23 insertions(+), 61 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/30483cf1/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/MailboxStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/MailboxStepdefs.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/MailboxStepdefs.java
deleted file mode 100644
index fca2cb9..0000000
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/MailboxStepdefs.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/****************************************************************
- * 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.methods.integration.cucumber;
-
-import javax.inject.Inject;
-
-import org.apache.james.mailbox.model.MailboxACL;
-import org.apache.james.mailbox.model.MailboxConstants;
-import org.apache.james.mailbox.model.MailboxPath;
-import org.apache.james.modules.ACLProbeImpl;
-
-import cucumber.api.java.en.Given;
-import cucumber.runtime.java.guice.ScenarioScoped;
-
-@ScenarioScoped
-public class MailboxStepdefs {
-
-    private final MainStepdefs mainStepdefs;
-
-    @Inject
-    private MailboxStepdefs(MainStepdefs mainStepdefs) {
-        this.mainStepdefs = mainStepdefs;
-    }
-
-    @Given("^\"([^\"]*)\" has a mailbox \"([^\"]*)\"$")
-    public void createMailbox(String username, String mailbox) throws Throwable {
-        mainStepdefs.mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, mailbox);
-    }
-
-    @Given("^\"([^\"]*)\" shares its mailbox \"([^\"]*)\" with rights \"([^\"]*)\" with \"([^\"]*)\"$")
-    public void shareMailboxWithRight(String owner, String mailbox, String rights, String shareTo) throws Throwable {
-        MailboxPath mailboxPath = MailboxPath.forUser(owner, mailbox);
-
-        mainStepdefs.aclProbe.replaceRights(mailboxPath, shareTo, MailboxACL.Rfc4314Rights.fromSerializedRfc4314Rights(rights));
-    }
-    
-    @Given("^\"([^\"]*)\" shares (?:his|her) mailbox \"([^\"]*)\" with \"([^\"]*)\" with \"([^\"]*)\" rights$")
-    public void shareMailbox(String owner, String mailbox, String shareTo, String rights) throws Throwable {
-        mainStepdefs.jmapServer.getProbe(ACLProbeImpl.class)
-            .replaceRights(MailboxPath.forUser(owner, mailbox),
-                shareTo,
-                MailboxACL.Rfc4314Rights.fromSerializedRfc4314Rights(rights));
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/30483cf1/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java
index f01e325..449a407 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/SetMailboxesMethodStepdefs.java
@@ -30,8 +30,11 @@ import javax.inject.Inject;
 import javax.mail.Flags;
 
 import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxACL;
+import org.apache.james.mailbox.model.MailboxConstants;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
+import org.apache.james.modules.ACLProbeImpl;
 
 import com.github.fge.lambdas.Throwing;
 import com.jayway.awaitility.Awaitility;
@@ -78,6 +81,26 @@ public class SetMailboxesMethodStepdefs {
                 new ByteArrayInputStream(content.getBytes()), new Date(), false, new Flags());
     }
 
+    @Given("^\"([^\"]*)\" has a mailbox \"([^\"]*)\"$")
+    public void createMailbox(String username, String mailbox) throws Throwable {
+        mainStepdefs.mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, username, mailbox);
+    }
+
+    @Given("^\"([^\"]*)\" shares its mailbox \"([^\"]*)\" with rights \"([^\"]*)\" with \"([^\"]*)\"$")
+    public void shareMailboxWithRight(String owner, String mailbox, String rights, String shareTo) throws Throwable {
+        MailboxPath mailboxPath = MailboxPath.forUser(owner, mailbox);
+
+        mainStepdefs.aclProbe.replaceRights(mailboxPath, shareTo, MailboxACL.Rfc4314Rights.fromSerializedRfc4314Rights(rights));
+    }
+    
+    @Given("^\"([^\"]*)\" shares (?:his|her) mailbox \"([^\"]*)\" with \"([^\"]*)\" with \"([^\"]*)\" rights$")
+    public void shareMailbox(String owner, String mailbox, String shareTo, String rights) throws Throwable {
+        mainStepdefs.jmapServer.getProbe(ACLProbeImpl.class)
+            .replaceRights(MailboxPath.forUser(owner, mailbox),
+                shareTo,
+                MailboxACL.Rfc4314Rights.fromSerializedRfc4314Rights(rights));
+    }
+
     @When("^renaming mailbox \"([^\"]*)\" to \"([^\"]*)\"")
     public void renamingMailbox(String actualMailboxName, String newMailboxName) throws Throwable {
         Mailbox mailbox = mainStepdefs.mailboxProbe.getMailbox("#private", userStepdefs.getConnectedUser(), actualMailboxName);


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


[7/9] james-project git commit: PROTOCOL-117 swap SearchResponseEncoderTest and ListResponseEncoderTest (no code change)

Posted by ad...@apache.org.
PROTOCOL-117 swap SearchResponseEncoderTest and ListResponseEncoderTest (no code change)


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

Branch: refs/heads/master
Commit: 78f23907f8405efdc69d7d22b41dfde821394c95
Parents: 7ed93d9
Author: Matthieu Baechler <ma...@apache.org>
Authored: Tue Nov 7 17:33:22 2017 +0100
Committer: Matthieu Baechler <ma...@apache.org>
Committed: Tue Nov 7 17:55:48 2017 +0100

----------------------------------------------------------------------
 .../imap/encode/ListResponseEncoderTest.java    | 63 ++++++++++++++++----
 .../imap/encode/SearchResponseEncoderTest.java  | 63 ++++----------------
 2 files changed, 63 insertions(+), 63 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/78f23907/protocols/imap/src/test/java/org/apache/james/imap/encode/ListResponseEncoderTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/encode/ListResponseEncoderTest.java b/protocols/imap/src/test/java/org/apache/james/imap/encode/ListResponseEncoderTest.java
index 8c26450..67bd1bc 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/encode/ListResponseEncoderTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/encode/ListResponseEncoderTest.java
@@ -26,7 +26,8 @@ import static org.junit.Assert.assertTrue;
 import org.apache.james.imap.api.ImapMessage;
 import org.apache.james.imap.encode.base.ByteImapResponseWriter;
 import org.apache.james.imap.encode.base.ImapResponseComposerImpl;
-import org.apache.james.imap.message.response.SearchResponse;
+import org.apache.james.imap.message.response.LSubResponse;
+import org.apache.james.imap.message.response.ListResponse;
 import org.jmock.Mockery;
 import org.jmock.integration.junit4.JUnit4Mockery;
 import org.junit.Before;
@@ -34,11 +35,7 @@ import org.junit.Test;
 
 public class ListResponseEncoderTest {
 
-    private static final long[] IDS = { 1, 4, 9, 16 };
-
-    private SearchResponse response;
-
-    private SearchResponseEncoder encoder;
+    private ListResponseEncoder encoder;
 
     private ImapEncoder mockNextEncoder;
 
@@ -50,20 +47,62 @@ public class ListResponseEncoderTest {
     @Before
     public void setUp() throws Exception {
         mockNextEncoder = context.mock(ImapEncoder.class);
-        response = new SearchResponse(IDS, null);
-        encoder = new SearchResponseEncoder(mockNextEncoder);
+        encoder = new ListResponseEncoder(mockNextEncoder);
     }
 
     @Test
     public void testIsAcceptable() {
-        assertTrue(encoder.isAcceptable(response));
+        assertTrue(encoder.isAcceptable(new ListResponse(true, true, true,
+                true, false, false, "name", '.')));
+        assertFalse(encoder.isAcceptable(new LSubResponse("name", true, '.')));
         assertFalse(encoder.isAcceptable(context.mock(ImapMessage.class)));
         assertFalse(encoder.isAcceptable(null));
     }
 
     @Test
-    public void testEncode() throws Exception {
-        encoder.encode(response, composer, new FakeImapSession());
-        assertEquals("* SEARCH 1 4 9 16\r\n", writer.getString());
+	public void testName() throws Exception {     
+        encoder.encode(new ListResponse(false, false, false, false, false, false, "INBOX.name", '.'), composer, new FakeImapSession());
+        assertEquals("* LIST () \".\" \"INBOX.name\"\r\n", writer.getString());
+    }
+
+    @Test
+	public void testDelimiter() throws Exception {
+        encoder.encode(new ListResponse(false, false, false, false, false, false, "INBOX.name", '.'), composer, new FakeImapSession());
+        assertEquals("* LIST () \".\" \"INBOX.name\"\r\n", writer.getString());
+    }
+
+
+    @Test
+    public void testAllAttributes() throws Exception {
+        encoder.encode(new ListResponse(true, true, true, true, false, false, "INBOX.name", '.'), composer, new FakeImapSession());
+        assertEquals("* LIST (\\Noinferiors \\Noselect \\Marked \\Unmarked) \".\" \"INBOX.name\"\r\n", writer.getString());
+
+    }
+
+    @Test
+    public void testNoInferiors() throws Exception {      
+        encoder.encode(new ListResponse(true, false, false, false, false, false, "INBOX.name", '.'), composer, new FakeImapSession());
+        assertEquals("* LIST (\\Noinferiors) \".\" \"INBOX.name\"\r\n", writer.getString());
+    }
+
+    @Test
+    public void testNoSelect() throws Exception {
+        encoder.encode(new ListResponse(false, true, false, false, false, false, "INBOX.name", '.'), composer, new FakeImapSession());
+        assertEquals("* LIST (\\Noselect) \".\" \"INBOX.name\"\r\n", writer.getString());
+
+    }
+
+    @Test
+    public void testMarked() throws Exception {
+        encoder.encode(new ListResponse(false, false, true, false, false, false, "INBOX.name", '.'), composer, new FakeImapSession());
+        assertEquals("* LIST (\\Marked) \".\" \"INBOX.name\"\r\n", writer.getString());
+
+    }
+
+    @Test
+    public void testUnmarked() throws Exception {
+        encoder.encode(new ListResponse(false, false, false, true, false, false, "INBOX.name", '.'), composer, new FakeImapSession());
+        assertEquals("* LIST (\\Unmarked) \".\" \"INBOX.name\"\r\n", writer.getString());
+
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/78f23907/protocols/imap/src/test/java/org/apache/james/imap/encode/SearchResponseEncoderTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/encode/SearchResponseEncoderTest.java b/protocols/imap/src/test/java/org/apache/james/imap/encode/SearchResponseEncoderTest.java
index 1b2bb80..fe6d0a0 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/encode/SearchResponseEncoderTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/encode/SearchResponseEncoderTest.java
@@ -26,8 +26,7 @@ import static org.junit.Assert.assertTrue;
 import org.apache.james.imap.api.ImapMessage;
 import org.apache.james.imap.encode.base.ByteImapResponseWriter;
 import org.apache.james.imap.encode.base.ImapResponseComposerImpl;
-import org.apache.james.imap.message.response.LSubResponse;
-import org.apache.james.imap.message.response.ListResponse;
+import org.apache.james.imap.message.response.SearchResponse;
 import org.jmock.Mockery;
 import org.jmock.integration.junit4.JUnit4Mockery;
 import org.junit.Before;
@@ -35,7 +34,11 @@ import org.junit.Test;
 
 public class SearchResponseEncoderTest {
 
-    private ListResponseEncoder encoder;
+    private static final long[] IDS = { 1, 4, 9, 16 };
+
+    private SearchResponse response;
+
+    private SearchResponseEncoder encoder;
 
     private ImapEncoder mockNextEncoder;
 
@@ -47,62 +50,20 @@ public class SearchResponseEncoderTest {
     @Before
     public void setUp() throws Exception {
         mockNextEncoder = context.mock(ImapEncoder.class);
-        encoder = new ListResponseEncoder(mockNextEncoder);
+        response = new SearchResponse(IDS, null);
+        encoder = new SearchResponseEncoder(mockNextEncoder);
     }
 
     @Test
     public void testIsAcceptable() {
-        assertTrue(encoder.isAcceptable(new ListResponse(true, true, true,
-                true, false, false, "name", '.')));
-        assertFalse(encoder.isAcceptable(new LSubResponse("name", true, '.')));
+        assertTrue(encoder.isAcceptable(response));
         assertFalse(encoder.isAcceptable(context.mock(ImapMessage.class)));
         assertFalse(encoder.isAcceptable(null));
     }
 
     @Test
-	public void testName() throws Exception {     
-        encoder.encode(new ListResponse(false, false, false, false, false, false, "INBOX.name", '.'), composer, new FakeImapSession());
-        assertEquals("* LIST () \".\" \"INBOX.name\"\r\n", writer.getString());
-    }
-
-    @Test
-	public void testDelimiter() throws Exception {
-        encoder.encode(new ListResponse(false, false, false, false, false, false, "INBOX.name", '.'), composer, new FakeImapSession());
-        assertEquals("* LIST () \".\" \"INBOX.name\"\r\n", writer.getString());
-    }
-
-
-    @Test
-    public void testAllAttributes() throws Exception {
-        encoder.encode(new ListResponse(true, true, true, true, false, false, "INBOX.name", '.'), composer, new FakeImapSession());
-        assertEquals("* LIST (\\Noinferiors \\Noselect \\Marked \\Unmarked) \".\" \"INBOX.name\"\r\n", writer.getString());
-
-    }
-
-    @Test
-    public void testNoInferiors() throws Exception {      
-        encoder.encode(new ListResponse(true, false, false, false, false, false, "INBOX.name", '.'), composer, new FakeImapSession());
-        assertEquals("* LIST (\\Noinferiors) \".\" \"INBOX.name\"\r\n", writer.getString());
-    }
-
-    @Test
-    public void testNoSelect() throws Exception {
-        encoder.encode(new ListResponse(false, true, false, false, false, false, "INBOX.name", '.'), composer, new FakeImapSession());
-        assertEquals("* LIST (\\Noselect) \".\" \"INBOX.name\"\r\n", writer.getString());
-
-    }
-
-    @Test
-    public void testMarked() throws Exception {
-        encoder.encode(new ListResponse(false, false, true, false, false, false, "INBOX.name", '.'), composer, new FakeImapSession());
-        assertEquals("* LIST (\\Marked) \".\" \"INBOX.name\"\r\n", writer.getString());
-
-    }
-
-    @Test
-    public void testUnmarked() throws Exception {
-        encoder.encode(new ListResponse(false, false, false, true, false, false, "INBOX.name", '.'), composer, new FakeImapSession());
-        assertEquals("* LIST (\\Unmarked) \".\" \"INBOX.name\"\r\n", writer.getString());
-
+    public void testEncode() throws Exception {
+        encoder.encode(response, composer, new FakeImapSession());
+        assertEquals("* SEARCH 1 4 9 16\r\n", writer.getString());
     }
 }


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