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:51 UTC
[4/9] james-project git commit: PROTOCOL-117 get rid of boolean
crazyness in ListResponse
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