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 rd...@apache.org on 2008/09/18 23:45:03 UTC
svn commit: r696828 [6/32] - in /james/protocols/imap/trunk:
api/src/main/java/org/apache/james/api/imap/
api/src/main/java/org/apache/james/api/imap/display/
api/src/main/java/org/apache/james/api/imap/imap4rev1/
api/src/main/java/org/apache/james/api...
Modified: james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/FetchCommandParserPartialFetchTest.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/FetchCommandParserPartialFetchTest.java?rev=696828&r1=696827&r2=696828&view=diff
==============================================================================
--- james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/FetchCommandParserPartialFetchTest.java (original)
+++ james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/FetchCommandParserPartialFetchTest.java Thu Sep 18 14:44:56 2008
@@ -38,13 +38,19 @@
public class FetchCommandParserPartialFetchTest extends MockObjectTestCase {
FetchCommandParser parser;
+
Mock mockCommandFactory;
+
Mock mockMessageFactory;
+
Mock mockCommand;
+
Mock mockMessage;
+
ImapCommand command;
+
ImapMessage message;
-
+
protected void setUp() throws Exception {
super.setUp();
parser = new FetchCommandParser();
@@ -56,7 +62,8 @@
mockMessage = mock(ImapMessage.class);
message = (ImapMessage) mockMessage.proxy();
parser.init((Imap4Rev1CommandFactory) mockCommandFactory.proxy());
- parser.setMessageFactory((Imap4Rev1MessageFactory) mockMessageFactory.proxy());
+ parser.setMessageFactory((Imap4Rev1MessageFactory) mockMessageFactory
+ .proxy());
}
protected void tearDown() throws Exception {
@@ -64,38 +71,42 @@
}
public void testShouldParseZeroAndLength() throws Exception {
- IdRange[] ranges = {new IdRange(1)};
+ IdRange[] ranges = { new IdRange(1) };
FetchData data = new FetchData();
- data.add(new BodyFetchElement("BODY[]", BodyFetchElement.CONTENT, null, null,
- new Long(0), new Long(100)), false);
+ data.add(new BodyFetchElement("BODY[]", BodyFetchElement.CONTENT, null,
+ null, new Long(0), new Long(100)), false);
check("1 (BODY[]<0.100>)\r\n", ranges, false, data, "A01");
}
-
+
public void testShouldParseNonZeroAndLength() throws Exception {
- IdRange[] ranges = {new IdRange(1)};
+ IdRange[] ranges = { new IdRange(1) };
FetchData data = new FetchData();
- data.add(new BodyFetchElement("BODY[]", BodyFetchElement.CONTENT, null, null,
- new Long(20), new Long(12342348)), false);
+ data.add(new BodyFetchElement("BODY[]", BodyFetchElement.CONTENT, null,
+ null, new Long(20), new Long(12342348)), false);
check("1 (BODY[]<20.12342348>)\r\n", ranges, false, data, "A01");
}
-
+
public void testShouldNotParseZeroLength() throws Exception {
try {
- ImapRequestLineReader reader = new ImapRequestLineReader(new ByteArrayInputStream("1 (BODY[]<20.0>)\r\n".getBytes("US-ASCII")),
- new ByteArrayOutputStream());
+ ImapRequestLineReader reader = new ImapRequestLineReader(
+ new ByteArrayInputStream("1 (BODY[]<20.0>)\r\n"
+ .getBytes("US-ASCII")), new ByteArrayOutputStream());
parser.decode(command, reader, "A01", false);
fail("Number of octets must be non-zero");
} catch (ProtocolException e) {
// expected
}
}
-
-
- private void check(String input, final IdRange[] idSet, final boolean useUids, FetchData data, String tag) throws Exception {
- ImapRequestLineReader reader = new ImapRequestLineReader(new ByteArrayInputStream(input.getBytes("US-ASCII")),
- new ByteArrayOutputStream());
- Constraint[] constraints = {eq(command), eq(useUids), eq(idSet), eq(data), same(tag)};
- mockMessageFactory.expects(once()).method("createFetchMessage").with(constraints).will(returnValue(message));
+
+ private void check(String input, final IdRange[] idSet,
+ final boolean useUids, FetchData data, String tag) throws Exception {
+ ImapRequestLineReader reader = new ImapRequestLineReader(
+ new ByteArrayInputStream(input.getBytes("US-ASCII")),
+ new ByteArrayOutputStream());
+ Constraint[] constraints = { eq(command), eq(useUids), eq(idSet),
+ eq(data), same(tag) };
+ mockMessageFactory.expects(once()).method("createFetchMessage").with(
+ constraints).will(returnValue(message));
parser.decode(command, reader, tag, useUids);
}
}
Modified: james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/MockLogger.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/MockLogger.java?rev=696828&r1=696827&r2=696828&view=diff
==============================================================================
--- james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/MockLogger.java (original)
+++ james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/MockLogger.java Thu Sep 18 14:44:56 2008
@@ -70,30 +70,30 @@
}
public void warn(Object arg0) {
-
+
}
public void warn(Object arg0, Throwable arg1) {
-
+
}
- public void fatal(Object arg0) {
- }
+ public void fatal(Object arg0) {
+ }
- public void fatal(Object arg0, Throwable arg1) {
- }
+ public void fatal(Object arg0, Throwable arg1) {
+ }
- public boolean isFatalEnabled() {
- return false;
- }
+ public boolean isFatalEnabled() {
+ return false;
+ }
- public boolean isTraceEnabled() {
- return false;
- }
+ public boolean isTraceEnabled() {
+ return false;
+ }
- public void trace(Object arg0) {
- }
+ public void trace(Object arg0) {
+ }
- public void trace(Object arg0, Throwable arg1) {
- }
+ public void trace(Object arg0, Throwable arg1) {
+ }
}
\ No newline at end of file
Modified: james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/SearchCommandParserAndParenthesesTest.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/SearchCommandParserAndParenthesesTest.java?rev=696828&r1=696827&r2=696828&view=diff
==============================================================================
--- james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/SearchCommandParserAndParenthesesTest.java (original)
+++ james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/SearchCommandParserAndParenthesesTest.java Thu Sep 18 14:44:56 2008
@@ -39,17 +39,18 @@
public class SearchCommandParserAndParenthesesTest extends MockObjectTestCase {
- Input[] variety = {sequence(), uid(), fromHeader(), since(), stringQuoted(), stringUnquoted(), draft(),
- mailingListHeader(), on(), unanswered()};
-
+ Input[] variety = { sequence(), uid(), fromHeader(), since(),
+ stringQuoted(), stringUnquoted(), draft(), mailingListHeader(),
+ on(), unanswered() };
+
public static Input and(Input[] parts, boolean parens) {
List keys = new ArrayList();
StringBuffer buffer = new StringBuffer();
if (parens) {
- buffer.append("(");
+ buffer.append("(");
}
for (int i = 0; i < parts.length; i++) {
- if (i>0) {
+ if (i > 0) {
buffer.append(' ');
}
buffer.append(parts[i].input);
@@ -61,85 +62,98 @@
Input input = new Input(buffer.toString(), SearchKey.buildAnd(keys));
return input;
}
-
+
public static Input sequence() {
- IdRange[] range = {new IdRange(Long.MAX_VALUE, 100), new IdRange(110), new IdRange(200, 201),
- new IdRange(400, Long.MAX_VALUE)};
+ IdRange[] range = { new IdRange(Long.MAX_VALUE, 100), new IdRange(110),
+ new IdRange(200, 201), new IdRange(400, Long.MAX_VALUE) };
SearchKey key = SearchKey.buildSequenceSet(range);
return new Input("*:100,110,200:201,400:*", key);
}
-
+
public static Input uid() {
- IdRange[] range = {new IdRange(Long.MAX_VALUE, 100), new IdRange(110), new IdRange(200, 201),
- new IdRange(400, Long.MAX_VALUE)};
+ IdRange[] range = { new IdRange(Long.MAX_VALUE, 100), new IdRange(110),
+ new IdRange(200, 201), new IdRange(400, Long.MAX_VALUE) };
SearchKey key = SearchKey.buildUidSet(range);
return new Input("UID *:100,110,200:201,400:*", key);
}
-
+
public static Input fromHeader() {
SearchKey key = SearchKey.buildHeader("FROM", "Smith");
return new Input("HEADER FROM Smith", key);
}
-
+
public static Input to() {
- SearchKey key = SearchKey.buildTo("JAMES Server Development <se...@james.apache.org>");
- return new Input("To \"JAMES Server Development <se...@james.apache.org>\"", key);
+ SearchKey key = SearchKey
+ .buildTo("JAMES Server Development <se...@james.apache.org>");
+ return new Input(
+ "To \"JAMES Server Development <se...@james.apache.org>\"",
+ key);
}
-
+
public static Input mailingListHeader() {
- SearchKey key = SearchKey.buildHeader("Mailing-List", "contact server-dev-help@james.apache.org; run by ezmlm");
- return new Input("HEADER Mailing-List \"contact server-dev-help@james.apache.org; run by ezmlm\"", key);
+ SearchKey key = SearchKey.buildHeader("Mailing-List",
+ "contact server-dev-help@james.apache.org; run by ezmlm");
+ return new Input(
+ "HEADER Mailing-List \"contact server-dev-help@james.apache.org; run by ezmlm\"",
+ key);
}
-
+
public static Input since() {
- SearchKey key = SearchKey.buildSince(new DayMonthYear(11,1, 2001));
+ SearchKey key = SearchKey.buildSince(new DayMonthYear(11, 1, 2001));
return new Input("since 11-Jan-2001", key);
}
-
+
public static Input on() {
- SearchKey key = SearchKey.buildOn(new DayMonthYear(1,2, 2001));
+ SearchKey key = SearchKey.buildOn(new DayMonthYear(1, 2, 2001));
return new Input("on 1-Feb-2001", key);
}
-
+
public static Input stringUnquoted() {
SearchKey key = SearchKey.buildFrom("Smith");
return new Input("FROM Smith", key);
}
-
+
public static Input stringQuoted() {
SearchKey key = SearchKey.buildFrom("Smith And Jones");
return new Input("FROM \"Smith And Jones\"", key);
}
-
+
public static Input draft() {
SearchKey key = SearchKey.buildDraft();
return new Input("DRAFT", key);
}
-
+
public static Input unanswered() {
SearchKey key = SearchKey.buildUnanswered();
return new Input("unanswered", key);
}
-
+
public static final class Input {
public String input;
+
public SearchKey key;
-
+
public Input(String input, SearchKey key) {
super();
this.input = input;
this.key = key;
}
}
-
+
SearchCommandParser parser;
+
Mock mockCommandFactory;
+
Mock mockMessageFactory;
+
Mock mockCommand;
+
Mock mockMessage;
+
ImapCommand command;
+
ImapMessage message;
-
+
protected void setUp() throws Exception {
super.setUp();
parser = new SearchCommandParser();
@@ -151,7 +165,8 @@
mockMessage = mock(ImapMessage.class);
message = (ImapMessage) mockMessage.proxy();
parser.init((Imap4Rev1CommandFactory) mockCommandFactory.proxy());
- parser.setMessageFactory((Imap4Rev1MessageFactory) mockMessageFactory.proxy());
+ parser.setMessageFactory((Imap4Rev1MessageFactory) mockMessageFactory
+ .proxy());
}
protected void tearDown() throws Exception {
@@ -161,30 +176,36 @@
public void testShouldParseTopLevelParentheses() throws Exception {
check(and(variety, true));
}
-
+
public void testShouldParseDeepParentheses() throws Exception {
- Input[] deep = {and(variety, true), and(variety, true), sequence(), and(variety, true), draft(), mailingListHeader()};
- Input[] mid = {and(deep, true), since(), and(variety, true), unanswered()};
- Input[] top = {uid(), and(deep, true), and(mid, true), stringQuoted(), and(mid, true)};
+ Input[] deep = { and(variety, true), and(variety, true), sequence(),
+ and(variety, true), draft(), mailingListHeader() };
+ Input[] mid = { and(deep, true), since(), and(variety, true),
+ unanswered() };
+ Input[] top = { uid(), and(deep, true), and(mid, true), stringQuoted(),
+ and(mid, true) };
check(and(top, true));
}
-
+
public void testShouldParseParenthesesOnTopLevel() throws Exception {
- Input[] deep = {and(variety, true), and(variety, true), sequence(), and(variety, true), draft(), mailingListHeader()};
- Input[] mid = {and(deep, true), since(), and(variety, true), unanswered()};
- Input[] top = {uid(), and(deep, true), and(mid, true), stringQuoted(), and(mid, true)};
+ Input[] deep = { and(variety, true), and(variety, true), sequence(),
+ and(variety, true), draft(), mailingListHeader() };
+ Input[] mid = { and(deep, true), since(), and(variety, true),
+ unanswered() };
+ Input[] top = { uid(), and(deep, true), and(mid, true), stringQuoted(),
+ and(mid, true) };
check(and(top, false));
}
-
- private void check(Input in) throws UnsupportedEncodingException, ProtocolException {
+
+ private void check(Input in) throws UnsupportedEncodingException,
+ ProtocolException {
String input = in.input + "\r\n";
ImapRequestLineReader reader = new ImapRequestLineReader(
- new ByteArrayInputStream(input.getBytes("US-ASCII")),
- new ByteArrayOutputStream());
+ new ByteArrayInputStream(input.getBytes("US-ASCII")),
+ new ByteArrayOutputStream());
final SearchKey result = parser.decode(reader);
assertEquals(in.key, result);
}
-
}
Modified: james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/SearchCommandParserCharsetTest.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/SearchCommandParserCharsetTest.java?rev=696828&r1=696827&r2=696828&view=diff
==============================================================================
--- james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/SearchCommandParserCharsetTest.java (original)
+++ james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/SearchCommandParserCharsetTest.java Thu Sep 18 14:44:56 2008
@@ -42,21 +42,39 @@
public class SearchCommandParserCharsetTest extends MockObjectTestCase {
private static final Charset UTF8 = Charset.forName("UTF-8");
+
private static final Charset ASCII = Charset.forName("US-ASCII");
+
private static final String TAG = "A1";
+
private static final String ASCII_SEARCH_TERM = "A Search Term";
+
private static final String NON_ASCII_SEARCH_TERM = "\u043A\u0430\u043A \u0414\u0435\u043B\u0430?";
- private static final byte[] BYTES_NON_ASCII_SEARCH_TERM = NioUtils.toBytes(NON_ASCII_SEARCH_TERM, UTF8);
- private static final byte[] BYTES_UTF8_NON_ASCII_SEARCH_TERM = NioUtils.add(NioUtils.toBytes(" {16}\r\n", ASCII), BYTES_NON_ASCII_SEARCH_TERM);
- private static final byte[] CHARSET = NioUtils.toBytes("CHARSET UTF-8 ", ASCII);
-
+
+ private static final byte[] BYTES_NON_ASCII_SEARCH_TERM = NioUtils.toBytes(
+ NON_ASCII_SEARCH_TERM, UTF8);
+
+ private static final byte[] BYTES_UTF8_NON_ASCII_SEARCH_TERM = NioUtils
+ .add(NioUtils.toBytes(" {16}\r\n", ASCII),
+ BYTES_NON_ASCII_SEARCH_TERM);
+
+ private static final byte[] CHARSET = NioUtils.toBytes("CHARSET UTF-8 ",
+ ASCII);
+
SearchCommandParser parser;
+
Mock mockStatusResponseFactory;
+
Mock mockCommandFactory;
+
Mock mockMessageFactory;
+
Mock mockCommand;
+
Mock mockMessage;
+
ImapCommand command;
+
ImapMessage message;
protected void setUp() throws Exception {
@@ -71,91 +89,106 @@
mockStatusResponseFactory = mock(StatusResponseFactory.class);
message = (ImapMessage) mockMessage.proxy();
parser.init((Imap4Rev1CommandFactory) mockCommandFactory.proxy());
- parser.setMessageFactory((Imap4Rev1MessageFactory) mockMessageFactory.proxy());
- parser.setStatusResponseFactory((StatusResponseFactory) mockStatusResponseFactory.proxy());
+ parser.setMessageFactory((Imap4Rev1MessageFactory) mockMessageFactory
+ .proxy());
+ parser
+ .setStatusResponseFactory((StatusResponseFactory) mockStatusResponseFactory
+ .proxy());
parser.setLog(new MockLogger());
}
protected void tearDown() throws Exception {
super.tearDown();
}
-
+
public void testBadCharset() throws Exception {
Collection charsetNames = new HashSet();
- for (final Iterator it = Charset.availableCharsets().values().iterator(); it.hasNext();) {
+ for (final Iterator it = Charset.availableCharsets().values()
+ .iterator(); it.hasNext();) {
final Charset charset = (Charset) it.next();
final Set aliases = charset.aliases();
charsetNames.addAll(aliases);
}
- mockStatusResponseFactory.expects(once()).method("taggedNo").with(eq(TAG), same(command), eq(HumanReadableTextKey.BAD_CHARSET), eq(StatusResponse.ResponseCode.badCharset(charsetNames)));
- ImapRequestLineReader reader = new ImapRequestLineReader(new ByteArrayInputStream("CHARSET BOGUS ".getBytes("US-ASCII")),
+ mockStatusResponseFactory.expects(once()).method("taggedNo").with(
+ eq(TAG), same(command), eq(HumanReadableTextKey.BAD_CHARSET),
+ eq(StatusResponse.ResponseCode.badCharset(charsetNames)));
+ ImapRequestLineReader reader = new ImapRequestLineReader(
+ new ByteArrayInputStream("CHARSET BOGUS ".getBytes("US-ASCII")),
new ByteArrayOutputStream());
parser.decode(command, reader, TAG, false);
}
-
+
public void testBCCShouldConvertCharset() throws Exception {
SearchKey key = SearchKey.buildBcc(NON_ASCII_SEARCH_TERM);
checkUTF8Valid("BCC".getBytes("US-ASCII"), key);
}
-
+
public void testBODYShouldConvertCharset() throws Exception {
SearchKey key = SearchKey.buildBody(NON_ASCII_SEARCH_TERM);
checkUTF8Valid("BODY".getBytes("US-ASCII"), key);
}
-
+
public void testCCShouldConvertCharset() throws Exception {
SearchKey key = SearchKey.buildCc(NON_ASCII_SEARCH_TERM);
- checkUTF8Valid("CC".getBytes("US-ASCII"), key);
+ checkUTF8Valid("CC".getBytes("US-ASCII"), key);
}
-
+
public void testFROMShouldConvertCharset() throws Exception {
SearchKey key = SearchKey.buildFrom(NON_ASCII_SEARCH_TERM);
checkUTF8Valid("FROM".getBytes("US-ASCII"), key);
}
-
+
public void testHEADERShouldConvertCharset() throws Exception {
- SearchKey key = SearchKey.buildHeader("whatever", NON_ASCII_SEARCH_TERM);
+ SearchKey key = SearchKey
+ .buildHeader("whatever", NON_ASCII_SEARCH_TERM);
checkUTF8Valid("HEADER whatever".getBytes("US-ASCII"), key);
}
-
+
public void testSUBJECTShouldConvertCharset() throws Exception {
SearchKey key = SearchKey.buildSubject(NON_ASCII_SEARCH_TERM);
checkUTF8Valid("SUBJECT".getBytes("US-ASCII"), key);
}
-
+
public void testTEXTShouldConvertCharset() throws Exception {
SearchKey key = SearchKey.buildText(NON_ASCII_SEARCH_TERM);
checkUTF8Valid("TEXT".getBytes("US-ASCII"), key);
}
-
+
public void testTOShouldConvertCharset() throws Exception {
SearchKey key = SearchKey.buildTo(NON_ASCII_SEARCH_TERM);
checkUTF8Valid("TO".getBytes("US-ASCII"), key);
}
-
+
public void testASCIICharset() throws Exception {
SearchKey key = SearchKey.buildBcc(ASCII_SEARCH_TERM);
- checkValid("CHARSET US-ASCII BCC \"" + ASCII_SEARCH_TERM + "\"", key, true, "US-ASCII");
+ checkValid("CHARSET US-ASCII BCC \"" + ASCII_SEARCH_TERM + "\"", key,
+ true, "US-ASCII");
}
-
+
public void testSimpleUTF8Charset() throws Exception {
SearchKey key = SearchKey.buildBcc(ASCII_SEARCH_TERM);
- checkValid("CHARSET UTF-8 BCC \"" + ASCII_SEARCH_TERM + "\"", key, true, "US-ASCII");
+ checkValid("CHARSET UTF-8 BCC \"" + ASCII_SEARCH_TERM + "\"", key,
+ true, "US-ASCII");
}
-
- private void checkUTF8Valid(byte[] term, final SearchKey key) throws Exception {
- ImapRequestLineReader reader = new ImapRequestLineReader(new ByteArrayInputStream(NioUtils.add(NioUtils.add(CHARSET, term), BYTES_UTF8_NON_ASCII_SEARCH_TERM)),
+
+ private void checkUTF8Valid(byte[] term, final SearchKey key)
+ throws Exception {
+ ImapRequestLineReader reader = new ImapRequestLineReader(
+ new ByteArrayInputStream(NioUtils.add(NioUtils.add(CHARSET,
+ term), BYTES_UTF8_NON_ASCII_SEARCH_TERM)),
new ByteArrayOutputStream());
final SearchKey searchKey = parser.searchKey(reader, null, true);
assertEquals(key, searchKey);
}
-
- private void checkValid(String input, final SearchKey key, boolean isFirst, String charset) throws Exception {
- ImapRequestLineReader reader = new ImapRequestLineReader(new ByteArrayInputStream(input.getBytes(charset)),
+
+ private void checkValid(String input, final SearchKey key, boolean isFirst,
+ String charset) throws Exception {
+ ImapRequestLineReader reader = new ImapRequestLineReader(
+ new ByteArrayInputStream(input.getBytes(charset)),
new ByteArrayOutputStream());
final SearchKey searchKey = parser.searchKey(reader, null, isFirst);
assertEquals(key, searchKey);
}
-
+
}
Modified: james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/SearchCommandParserNotTest.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/SearchCommandParserNotTest.java?rev=696828&r1=696827&r2=696828&view=diff
==============================================================================
--- james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/SearchCommandParserNotTest.java (original)
+++ james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/SearchCommandParserNotTest.java Thu Sep 18 14:44:56 2008
@@ -36,11 +36,17 @@
public class SearchCommandParserNotTest extends MockObjectTestCase {
SearchCommandParser parser;
+
Mock mockCommandFactory;
+
Mock mockMessageFactory;
+
Mock mockCommand;
+
Mock mockMessage;
+
ImapCommand command;
+
ImapMessage message;
protected void setUp() throws Exception {
@@ -54,7 +60,8 @@
mockMessage = mock(ImapMessage.class);
message = (ImapMessage) mockMessage.proxy();
parser.init((Imap4Rev1CommandFactory) mockCommandFactory.proxy());
- parser.setMessageFactory((Imap4Rev1MessageFactory) mockMessageFactory.proxy());
+ parser.setMessageFactory((Imap4Rev1MessageFactory) mockMessageFactory
+ .proxy());
}
protected void tearDown() throws Exception {
@@ -62,30 +69,30 @@
}
public void testShouldParseNotSequence() throws Exception {
- IdRange[] range = {new IdRange(Long.MAX_VALUE, 100), new IdRange(110), new IdRange(200, 201),
- new IdRange(400, Long.MAX_VALUE)};
+ IdRange[] range = { new IdRange(Long.MAX_VALUE, 100), new IdRange(110),
+ new IdRange(200, 201), new IdRange(400, Long.MAX_VALUE) };
SearchKey notdKey = SearchKey.buildSequenceSet(range);
SearchKey key = SearchKey.buildNot(notdKey);
checkValid("NOT *:100,110,200:201,400:*\r\n", key);
}
-
+
public void testShouldParseNotUid() throws Exception {
- IdRange[] range = {new IdRange(Long.MAX_VALUE, 100), new IdRange(110), new IdRange(200, 201),
- new IdRange(400, Long.MAX_VALUE)};
+ IdRange[] range = { new IdRange(Long.MAX_VALUE, 100), new IdRange(110),
+ new IdRange(200, 201), new IdRange(400, Long.MAX_VALUE) };
SearchKey notdKey = SearchKey.buildUidSet(range);
SearchKey key = SearchKey.buildNot(notdKey);
checkValid("NOT UID *:100,110,200:201,400:*\r\n", key);
}
-
+
public void testShouldParseNotHeaderKey() throws Exception {
SearchKey notdKey = SearchKey.buildHeader("FROM", "Smith");
SearchKey key = SearchKey.buildNot(notdKey);
checkValid("NOT HEADER FROM Smith\r\n", key);
checkValid("NOT header FROM Smith\r\n", key);
}
-
+
public void testShouldParseNotDateParameterKey() throws Exception {
- SearchKey notdKey = SearchKey.buildSince(new DayMonthYear(11,1, 2001));
+ SearchKey notdKey = SearchKey.buildSince(new DayMonthYear(11, 1, 2001));
SearchKey key = SearchKey.buildNot(notdKey);
checkValid("NOT since 11-Jan-2001\r\n", key);
checkValid("NOT SINCE 11-Jan-2001\r\n", key);
@@ -97,13 +104,13 @@
checkValid("NOT FROM Smith\r\n", key);
checkValid("NOT FROM \"Smith\"\r\n", key);
}
-
+
public void testShouldParseNotStringQuotedParameterKey() throws Exception {
SearchKey notdKey = SearchKey.buildFrom("Smith And Jones");
SearchKey key = SearchKey.buildNot(notdKey);
checkValid("NOT FROM \"Smith And Jones\"\r\n", key);
}
-
+
public void testShouldParseNotNoParameterKey() throws Exception {
SearchKey notdKey = SearchKey.buildNew();
SearchKey key = SearchKey.buildNot(notdKey);
@@ -111,9 +118,10 @@
checkValid("Not NEW\r\n", key);
checkValid("not new\r\n", key);
}
-
+
private void checkValid(String input, final SearchKey key) throws Exception {
- ImapRequestLineReader reader = new ImapRequestLineReader(new ByteArrayInputStream(input.getBytes("US-ASCII")),
+ ImapRequestLineReader reader = new ImapRequestLineReader(
+ new ByteArrayInputStream(input.getBytes("US-ASCII")),
new ByteArrayOutputStream());
assertEquals(key, parser.searchKey(reader, null, false));
Modified: james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/SearchCommandParserOrTest.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/SearchCommandParserOrTest.java?rev=696828&r1=696827&r2=696828&view=diff
==============================================================================
--- james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/SearchCommandParserOrTest.java (original)
+++ james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/SearchCommandParserOrTest.java Thu Sep 18 14:44:56 2008
@@ -35,13 +35,19 @@
public class SearchCommandParserOrTest extends MockObjectTestCase {
SearchCommandParser parser;
+
Mock mockCommandFactory;
+
Mock mockMessageFactory;
+
Mock mockCommand;
+
Mock mockMessage;
+
ImapCommand command;
+
ImapMessage message;
-
+
protected void setUp() throws Exception {
super.setUp();
parser = new SearchCommandParser();
@@ -53,52 +59,53 @@
mockMessage = mock(ImapMessage.class);
message = (ImapMessage) mockMessage.proxy();
parser.init((Imap4Rev1CommandFactory) mockCommandFactory.proxy());
- parser.setMessageFactory((Imap4Rev1MessageFactory) mockMessageFactory.proxy());
+ parser.setMessageFactory((Imap4Rev1MessageFactory) mockMessageFactory
+ .proxy());
}
protected void tearDown() throws Exception {
super.tearDown();
}
-
+
public Input sequence() {
- IdRange[] range = {new IdRange(Long.MAX_VALUE, 100), new IdRange(110), new IdRange(200, 201),
- new IdRange(400, Long.MAX_VALUE)};
+ IdRange[] range = { new IdRange(Long.MAX_VALUE, 100), new IdRange(110),
+ new IdRange(200, 201), new IdRange(400, Long.MAX_VALUE) };
SearchKey key = SearchKey.buildSequenceSet(range);
return new Input("*:100,110,200:201,400:*", key);
}
-
+
public Input uid() {
- IdRange[] range = {new IdRange(Long.MAX_VALUE, 100), new IdRange(110), new IdRange(200, 201),
- new IdRange(400, Long.MAX_VALUE)};
+ IdRange[] range = { new IdRange(Long.MAX_VALUE, 100), new IdRange(110),
+ new IdRange(200, 201), new IdRange(400, Long.MAX_VALUE) };
SearchKey key = SearchKey.buildUidSet(range);
return new Input("UID *:100,110,200:201,400:*", key);
}
-
+
public Input header() {
SearchKey key = SearchKey.buildHeader("FROM", "Smith");
return new Input("HEADER FROM Smith", key);
}
-
+
public Input date() {
- SearchKey key = SearchKey.buildSince(new DayMonthYear(11,1, 2001));
+ SearchKey key = SearchKey.buildSince(new DayMonthYear(11, 1, 2001));
return new Input("since 11-Jan-2001", key);
}
-
+
public Input stringUnquoted() {
SearchKey key = SearchKey.buildFrom("Smith");
return new Input("FROM Smith", key);
}
-
+
public Input stringQuoted() {
SearchKey key = SearchKey.buildFrom("Smith And Jones");
return new Input("FROM \"Smith And Jones\"", key);
}
-
+
public Input draft() {
SearchKey key = SearchKey.buildDraft();
return new Input("DRAFT", key);
}
-
+
public void testDraftPermutations() throws Exception {
checkValid(draft(), draft());
checkValid(draft(), stringQuoted());
@@ -108,7 +115,7 @@
checkValid(draft(), date());
checkValid(draft(), uid());
}
-
+
public void testDatePermutations() throws Exception {
checkValid(date(), draft());
checkValid(date(), stringQuoted());
@@ -118,7 +125,7 @@
checkValid(date(), date());
checkValid(date(), uid());
}
-
+
public void testHeaderPermutations() throws Exception {
checkValid(header(), draft());
checkValid(header(), stringQuoted());
@@ -128,7 +135,7 @@
checkValid(header(), date());
checkValid(header(), uid());
}
-
+
public void testSequencePermutations() throws Exception {
checkValid(sequence(), draft());
checkValid(sequence(), stringQuoted());
@@ -138,7 +145,7 @@
checkValid(sequence(), date());
checkValid(sequence(), uid());
}
-
+
public void testStringQuotedPermutations() throws Exception {
checkValid(stringQuoted(), draft());
checkValid(stringQuoted(), stringQuoted());
@@ -148,7 +155,7 @@
checkValid(stringQuoted(), date());
checkValid(stringQuoted(), uid());
}
-
+
public void testStringUnquotedPermutations() throws Exception {
checkValid(stringUnquoted(), draft());
checkValid(stringUnquoted(), stringQuoted());
@@ -158,7 +165,7 @@
checkValid(stringUnquoted(), date());
checkValid(stringUnquoted(), uid());
}
-
+
public void testUidPermutations() throws Exception {
checkValid(uid(), draft());
checkValid(uid(), stringQuoted());
@@ -168,20 +175,22 @@
checkValid(uid(), date());
checkValid(uid(), uid());
}
-
+
private void checkValid(Input one, Input two) throws Exception {
String input = "OR " + one.input + " " + two.input + "\r\n";
SearchKey key = SearchKey.buildOr(one.key, two.key);
- ImapRequestLineReader reader = new ImapRequestLineReader(new ByteArrayInputStream(input.getBytes("US-ASCII")),
+ ImapRequestLineReader reader = new ImapRequestLineReader(
+ new ByteArrayInputStream(input.getBytes("US-ASCII")),
new ByteArrayOutputStream());
assertEquals(key, parser.searchKey(reader, null, false));
}
-
+
public class Input {
public String input;
+
public SearchKey key;
-
+
public Input(String input, SearchKey key) {
super();
this.input = input;
Modified: james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/SearchCommandParserQuotedCharsetTest.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/SearchCommandParserQuotedCharsetTest.java?rev=696828&r1=696827&r2=696828&view=diff
==============================================================================
--- james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/SearchCommandParserQuotedCharsetTest.java (original)
+++ james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/SearchCommandParserQuotedCharsetTest.java Thu Sep 18 14:44:56 2008
@@ -43,42 +43,102 @@
public class SearchCommandParserQuotedCharsetTest extends MockObjectTestCase {
private static final Charset UTF8 = Charset.forName("UTF-8");
+
private static final Charset ASCII = Charset.forName("US-ASCII");
+
private static final String TAG = "A1";
+
private static final String ASCII_SEARCH_TERM = "A Search Term";
+
private static final String NON_ASCII_SEARCH_TERM = "\u043A\u0430\u043A \u0414\u0435\u043B\u0430?";
- private static final String LENGTHY_NON_ASCII_SEARCH_TERM = NON_ASCII_SEARCH_TERM + NON_ASCII_SEARCH_TERM + NON_ASCII_SEARCH_TERM + NON_ASCII_SEARCH_TERM +
- NON_ASCII_SEARCH_TERM + NON_ASCII_SEARCH_TERM + NON_ASCII_SEARCH_TERM + NON_ASCII_SEARCH_TERM +
- NON_ASCII_SEARCH_TERM + NON_ASCII_SEARCH_TERM + NON_ASCII_SEARCH_TERM + NON_ASCII_SEARCH_TERM +
- NON_ASCII_SEARCH_TERM + NON_ASCII_SEARCH_TERM + NON_ASCII_SEARCH_TERM + NON_ASCII_SEARCH_TERM +
- NON_ASCII_SEARCH_TERM + NON_ASCII_SEARCH_TERM + NON_ASCII_SEARCH_TERM + NON_ASCII_SEARCH_TERM +
- NON_ASCII_SEARCH_TERM + NON_ASCII_SEARCH_TERM + NON_ASCII_SEARCH_TERM + NON_ASCII_SEARCH_TERM +
- NON_ASCII_SEARCH_TERM + NON_ASCII_SEARCH_TERM + NON_ASCII_SEARCH_TERM + NON_ASCII_SEARCH_TERM +
- NON_ASCII_SEARCH_TERM + NON_ASCII_SEARCH_TERM + NON_ASCII_SEARCH_TERM + NON_ASCII_SEARCH_TERM +
- NON_ASCII_SEARCH_TERM + NON_ASCII_SEARCH_TERM + NON_ASCII_SEARCH_TERM + NON_ASCII_SEARCH_TERM +
- NON_ASCII_SEARCH_TERM + NON_ASCII_SEARCH_TERM + NON_ASCII_SEARCH_TERM + NON_ASCII_SEARCH_TERM +
- NON_ASCII_SEARCH_TERM + NON_ASCII_SEARCH_TERM + NON_ASCII_SEARCH_TERM + NON_ASCII_SEARCH_TERM;
- private static final byte[] BYTES_LENGTHY_NON_ASCII_SEARCH_TERM = NioUtils.toBytes(LENGTHY_NON_ASCII_SEARCH_TERM, UTF8);
- private static final byte[] BYTES_NON_ASCII_SEARCH_TERM = NioUtils.toBytes(NON_ASCII_SEARCH_TERM, UTF8);
- private static final byte[] BYTES_QUOTED_UTF8_LENGTHY_NON_ASCII_SEARCH_TERM = add(add(NioUtils.toBytes(" \"", ASCII), BYTES_LENGTHY_NON_ASCII_SEARCH_TERM), NioUtils.toBytes("\"", ASCII));
- private static final byte[] BYTES_QUOTED_UTF8_NON_ASCII_SEARCH_TERM = add(add(NioUtils.toBytes(" \"", ASCII), BYTES_NON_ASCII_SEARCH_TERM), NioUtils.toBytes("\"", ASCII));
- private static final byte[] BYTES_UTF8_NON_ASCII_SEARCH_TERM = add(NioUtils.toBytes(" {16}\r\n",ASCII), BYTES_NON_ASCII_SEARCH_TERM);
- private static final byte[] CHARSET = NioUtils.toBytes("CHARSET UTF-8 ", ASCII);
-
+
+ private static final String LENGTHY_NON_ASCII_SEARCH_TERM = NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM
+ + NON_ASCII_SEARCH_TERM;
+
+ private static final byte[] BYTES_LENGTHY_NON_ASCII_SEARCH_TERM = NioUtils
+ .toBytes(LENGTHY_NON_ASCII_SEARCH_TERM, UTF8);
+
+ private static final byte[] BYTES_NON_ASCII_SEARCH_TERM = NioUtils.toBytes(
+ NON_ASCII_SEARCH_TERM, UTF8);
+
+ private static final byte[] BYTES_QUOTED_UTF8_LENGTHY_NON_ASCII_SEARCH_TERM = add(
+ add(NioUtils.toBytes(" \"", ASCII),
+ BYTES_LENGTHY_NON_ASCII_SEARCH_TERM), NioUtils.toBytes(
+ "\"", ASCII));
+
+ private static final byte[] BYTES_QUOTED_UTF8_NON_ASCII_SEARCH_TERM = add(
+ add(NioUtils.toBytes(" \"", ASCII), BYTES_NON_ASCII_SEARCH_TERM),
+ NioUtils.toBytes("\"", ASCII));
+
+ private static final byte[] BYTES_UTF8_NON_ASCII_SEARCH_TERM = add(NioUtils
+ .toBytes(" {16}\r\n", ASCII), BYTES_NON_ASCII_SEARCH_TERM);
+
+ private static final byte[] CHARSET = NioUtils.toBytes("CHARSET UTF-8 ",
+ ASCII);
+
private static final byte[] add(byte[] one, byte[] two) {
byte[] results = new byte[one.length + two.length];
System.arraycopy(one, 0, results, 0, one.length);
System.arraycopy(two, 0, results, one.length, two.length);
return results;
}
-
+
SearchCommandParser parser;
+
Mock mockStatusResponseFactory;
+
Mock mockCommandFactory;
+
Mock mockMessageFactory;
+
Mock mockCommand;
+
Mock mockMessage;
+
ImapCommand command;
+
ImapMessage message;
protected void setUp() throws Exception {
@@ -93,123 +153,142 @@
mockStatusResponseFactory = mock(StatusResponseFactory.class);
message = (ImapMessage) mockMessage.proxy();
parser.init((Imap4Rev1CommandFactory) mockCommandFactory.proxy());
- parser.setMessageFactory((Imap4Rev1MessageFactory) mockMessageFactory.proxy());
- parser.setStatusResponseFactory((StatusResponseFactory) mockStatusResponseFactory.proxy());
+ parser.setMessageFactory((Imap4Rev1MessageFactory) mockMessageFactory
+ .proxy());
+ parser
+ .setStatusResponseFactory((StatusResponseFactory) mockStatusResponseFactory
+ .proxy());
parser.setLog(new MockLogger());
}
protected void tearDown() throws Exception {
super.tearDown();
}
-
-
+
public void testShouldDecoderLengthyQuotedCharset() throws Exception {
SearchKey key = SearchKey.buildBcc(LENGTHY_NON_ASCII_SEARCH_TERM);
- ImapRequestLineReader reader = new ImapRequestLineReader(new ByteArrayInputStream(
- add(
- add(CHARSET, "BCC".getBytes("US-ASCII")), BYTES_QUOTED_UTF8_LENGTHY_NON_ASCII_SEARCH_TERM)),
+ ImapRequestLineReader reader = new ImapRequestLineReader(
+ new ByteArrayInputStream(add(add(CHARSET, "BCC"
+ .getBytes("US-ASCII")),
+ BYTES_QUOTED_UTF8_LENGTHY_NON_ASCII_SEARCH_TERM)),
new ByteArrayOutputStream());
final SearchKey searchKey = parser.searchKey(reader, null, true);
assertEquals(key, searchKey);
}
-
+
public void testShouldDecoderQuotedCharset() throws Exception {
SearchKey key = SearchKey.buildBcc(NON_ASCII_SEARCH_TERM);
- ImapRequestLineReader reader = new ImapRequestLineReader(new ByteArrayInputStream(add(add(CHARSET, "BCC".getBytes("US-ASCII")), BYTES_QUOTED_UTF8_NON_ASCII_SEARCH_TERM)),
+ ImapRequestLineReader reader = new ImapRequestLineReader(
+ new ByteArrayInputStream(add(add(CHARSET, "BCC"
+ .getBytes("US-ASCII")),
+ BYTES_QUOTED_UTF8_NON_ASCII_SEARCH_TERM)),
new ByteArrayOutputStream());
final SearchKey searchKey = parser.searchKey(reader, null, true);
assertEquals(key, searchKey);
}
-
+
public void testBadCharset() throws Exception {
Collection charsetNames = new HashSet();
- for (final Iterator it = Charset.availableCharsets().values().iterator(); it.hasNext();) {
+ for (final Iterator it = Charset.availableCharsets().values()
+ .iterator(); it.hasNext();) {
final Charset charset = (Charset) it.next();
final Set aliases = charset.aliases();
charsetNames.addAll(aliases);
}
- mockStatusResponseFactory.expects(once()).method("taggedNo").with(eq(TAG), same(command), eq(HumanReadableTextKey.BAD_CHARSET), eq(StatusResponse.ResponseCode.badCharset(charsetNames)));
- ImapRequestLineReader reader = new ImapRequestLineReader(new ByteArrayInputStream("CHARSET BOGUS ".getBytes("US-ASCII")),
+ mockStatusResponseFactory.expects(once()).method("taggedNo").with(
+ eq(TAG), same(command), eq(HumanReadableTextKey.BAD_CHARSET),
+ eq(StatusResponse.ResponseCode.badCharset(charsetNames)));
+ ImapRequestLineReader reader = new ImapRequestLineReader(
+ new ByteArrayInputStream("CHARSET BOGUS ".getBytes("US-ASCII")),
new ByteArrayOutputStream());
parser.decode(command, reader, TAG, false);
}
-
-
-
- public void testShouldThrowProtocolExceptionWhenBytesAreNotEncodedByCharset() throws Exception {
+
+ public void testShouldThrowProtocolExceptionWhenBytesAreNotEncodedByCharset()
+ throws Exception {
try {
- ImapRequestLineReader reader = new ImapRequestLineReader(new ByteArrayInputStream(add("CHARSET US-ASCII BCC ".getBytes("US-ASCII"), BYTES_NON_ASCII_SEARCH_TERM)),
+ ImapRequestLineReader reader = new ImapRequestLineReader(
+ new ByteArrayInputStream(add("CHARSET US-ASCII BCC "
+ .getBytes("US-ASCII"), BYTES_NON_ASCII_SEARCH_TERM)),
new ByteArrayOutputStream());
parser.decode(command, reader, TAG, false);
fail("A protocol exception should be thrown when charset is incompatible with input");
} catch (ProtocolException e) {
- //expected
+ // expected
}
}
-
+
public void testBCCShouldConvertCharset() throws Exception {
SearchKey key = SearchKey.buildBcc(NON_ASCII_SEARCH_TERM);
checkUTF8Valid("BCC".getBytes("US-ASCII"), key);
}
-
+
public void testBODYShouldConvertCharset() throws Exception {
SearchKey key = SearchKey.buildBody(NON_ASCII_SEARCH_TERM);
checkUTF8Valid("BODY".getBytes("US-ASCII"), key);
}
-
+
public void testCCShouldConvertCharset() throws Exception {
SearchKey key = SearchKey.buildCc(NON_ASCII_SEARCH_TERM);
- checkUTF8Valid("CC".getBytes("US-ASCII"), key);
+ checkUTF8Valid("CC".getBytes("US-ASCII"), key);
}
-
+
public void testFROMShouldConvertCharset() throws Exception {
SearchKey key = SearchKey.buildFrom(NON_ASCII_SEARCH_TERM);
checkUTF8Valid("FROM".getBytes("US-ASCII"), key);
}
-
+
public void testHEADERShouldConvertCharset() throws Exception {
- SearchKey key = SearchKey.buildHeader("whatever", NON_ASCII_SEARCH_TERM);
+ SearchKey key = SearchKey
+ .buildHeader("whatever", NON_ASCII_SEARCH_TERM);
checkUTF8Valid("HEADER whatever".getBytes("US-ASCII"), key);
}
-
+
public void testSUBJECTShouldConvertCharset() throws Exception {
SearchKey key = SearchKey.buildSubject(NON_ASCII_SEARCH_TERM);
checkUTF8Valid("SUBJECT".getBytes("US-ASCII"), key);
}
-
+
public void testTEXTShouldConvertCharset() throws Exception {
SearchKey key = SearchKey.buildText(NON_ASCII_SEARCH_TERM);
checkUTF8Valid("TEXT".getBytes("US-ASCII"), key);
}
-
+
public void testTOShouldConvertCharset() throws Exception {
SearchKey key = SearchKey.buildTo(NON_ASCII_SEARCH_TERM);
checkUTF8Valid("TO".getBytes("US-ASCII"), key);
}
-
+
public void testASCIICharset() throws Exception {
SearchKey key = SearchKey.buildBcc(ASCII_SEARCH_TERM);
- checkValid("CHARSET US-ASCII BCC \"" + ASCII_SEARCH_TERM + "\"", key, true, "US-ASCII");
+ checkValid("CHARSET US-ASCII BCC \"" + ASCII_SEARCH_TERM + "\"", key,
+ true, "US-ASCII");
}
-
+
public void testSimpleUTF8Charset() throws Exception {
SearchKey key = SearchKey.buildBcc(ASCII_SEARCH_TERM);
- checkValid("CHARSET UTF-8 BCC \"" + ASCII_SEARCH_TERM + "\"", key, true, "US-ASCII");
+ checkValid("CHARSET UTF-8 BCC \"" + ASCII_SEARCH_TERM + "\"", key,
+ true, "US-ASCII");
}
-
- private void checkUTF8Valid(byte[] term, final SearchKey key) throws Exception {
- ImapRequestLineReader reader = new ImapRequestLineReader(new ByteArrayInputStream(add(add(CHARSET, term), BYTES_UTF8_NON_ASCII_SEARCH_TERM)),
+
+ private void checkUTF8Valid(byte[] term, final SearchKey key)
+ throws Exception {
+ ImapRequestLineReader reader = new ImapRequestLineReader(
+ new ByteArrayInputStream(add(add(CHARSET, term),
+ BYTES_UTF8_NON_ASCII_SEARCH_TERM)),
new ByteArrayOutputStream());
final SearchKey searchKey = parser.searchKey(reader, null, true);
assertEquals(key, searchKey);
}
-
- private void checkValid(String input, final SearchKey key, boolean isFirst, String charset) throws Exception {
- ImapRequestLineReader reader = new ImapRequestLineReader(new ByteArrayInputStream(input.getBytes(charset)),
+
+ private void checkValid(String input, final SearchKey key, boolean isFirst,
+ String charset) throws Exception {
+ ImapRequestLineReader reader = new ImapRequestLineReader(
+ new ByteArrayInputStream(input.getBytes(charset)),
new ByteArrayOutputStream());
final SearchKey searchKey = parser.searchKey(reader, null, isFirst);
assertEquals(key, searchKey);
}
-
+
}
Modified: james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/SearchCommandParserSearchKeySequenceSetTest.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/SearchCommandParserSearchKeySequenceSetTest.java?rev=696828&r1=696827&r2=696828&view=diff
==============================================================================
--- james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/SearchCommandParserSearchKeySequenceSetTest.java (original)
+++ james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/SearchCommandParserSearchKeySequenceSetTest.java Thu Sep 18 14:44:56 2008
@@ -32,14 +32,21 @@
import org.jmock.Mock;
import org.jmock.MockObjectTestCase;
-public class SearchCommandParserSearchKeySequenceSetTest extends MockObjectTestCase {
+public class SearchCommandParserSearchKeySequenceSetTest extends
+ MockObjectTestCase {
SearchCommandParser parser;
+
Mock mockCommandFactory;
+
Mock mockMessageFactory;
+
Mock mockCommand;
+
Mock mockMessage;
+
ImapCommand command;
+
ImapMessage message;
protected void setUp() throws Exception {
@@ -53,33 +60,36 @@
mockMessage = mock(ImapMessage.class);
message = (ImapMessage) mockMessage.proxy();
parser.init((Imap4Rev1CommandFactory) mockCommandFactory.proxy());
- parser.setMessageFactory((Imap4Rev1MessageFactory) mockMessageFactory.proxy());
+ parser.setMessageFactory((Imap4Rev1MessageFactory) mockMessageFactory
+ .proxy());
}
protected void tearDown() throws Exception {
super.tearDown();
}
-
+
public void testAllNumbers() throws Exception {
-
- IdRange[] range = {new IdRange(2), new IdRange(4), new IdRange(9),
- new IdRange(16), new IdRange(25), new IdRange(36), new IdRange(49),
- new IdRange(64), new IdRange(81), new IdRange(100)};
+
+ IdRange[] range = { new IdRange(2), new IdRange(4), new IdRange(9),
+ new IdRange(16), new IdRange(25), new IdRange(36),
+ new IdRange(49), new IdRange(64), new IdRange(81),
+ new IdRange(100) };
check("2,4,9,16,25,36,49,64,81,100", range);
}
-
+
public void testEndStar() throws Exception {
- IdRange[] range = {new IdRange(8), new IdRange(9,10), new IdRange(17),
- new IdRange(100, Long.MAX_VALUE)};
+ IdRange[] range = { new IdRange(8), new IdRange(9, 10),
+ new IdRange(17), new IdRange(100, Long.MAX_VALUE) };
check("8,9:10,17,100:*", range);
}
-
+
public void testStartStar() throws Exception {
- IdRange[] range = {new IdRange(Long.MAX_VALUE, 9), new IdRange(15), new IdRange(799, 820)};
+ IdRange[] range = { new IdRange(Long.MAX_VALUE, 9), new IdRange(15),
+ new IdRange(799, 820) };
check("*:9,15,799:820", range);
}
- private void check(String sequence, IdRange[] range) throws Exception{
+ private void check(String sequence, IdRange[] range) throws Exception {
checkUid(sequence, range);
checkSequence(sequence, range);
}
@@ -90,17 +100,19 @@
checkValid("uid " + sequence, key);
checkValid("Uid " + sequence, key);
}
-
- private void checkSequence(String sequence, IdRange[] range) throws Exception {
+
+ private void checkSequence(String sequence, IdRange[] range)
+ throws Exception {
SearchKey key = SearchKey.buildSequenceSet(range);
checkValid(sequence, key);
checkValid(sequence, key);
checkValid(sequence, key);
}
-
+
private void checkValid(String input, final SearchKey key) throws Exception {
input = input + "\r\n";
- ImapRequestLineReader reader = new ImapRequestLineReader(new ByteArrayInputStream(input.getBytes("US-ASCII")),
+ ImapRequestLineReader reader = new ImapRequestLineReader(
+ new ByteArrayInputStream(input.getBytes("US-ASCII")),
new ByteArrayOutputStream());
final SearchKey searchKey = parser.searchKey(reader, null, false);
Modified: james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/SearchCommandParserSearchKeyTest.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/SearchCommandParserSearchKeyTest.java?rev=696828&r1=696827&r2=696828&view=diff
==============================================================================
--- james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/SearchCommandParserSearchKeyTest.java (original)
+++ james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/SearchCommandParserSearchKeyTest.java Thu Sep 18 14:44:56 2008
@@ -37,12 +37,19 @@
public class SearchCommandParserSearchKeyTest extends MockObjectTestCase {
private static final DayMonthYear DATE = new DayMonthYear(1, 1, 2000);
+
SearchCommandParser parser;
+
Mock mockCommandFactory;
+
Mock mockMessageFactory;
+
Mock mockCommand;
+
Mock mockMessage;
+
ImapCommand command;
+
ImapMessage message;
protected void setUp() throws Exception {
@@ -56,7 +63,8 @@
mockMessage = mock(ImapMessage.class);
message = (ImapMessage) mockMessage.proxy();
parser.init((Imap4Rev1CommandFactory) mockCommandFactory.proxy());
- parser.setMessageFactory((Imap4Rev1MessageFactory) mockMessageFactory.proxy());
+ parser.setMessageFactory((Imap4Rev1MessageFactory) mockMessageFactory
+ .proxy());
}
protected void tearDown() throws Exception {
@@ -72,7 +80,7 @@
checkInvalid("alm\r\n", key);
checkInvalid("alm\r\n", key);
}
-
+
public void testShouldParseAnswered() throws Exception {
SearchKey key = SearchKey.buildAnswered();
checkValid("ANSWERED\r\n", key);
@@ -86,7 +94,7 @@
checkInvalid("answer\r\n", key);
checkInvalid("answere\r\n", key);
}
-
+
public void testShouldParseBcc() throws Exception {
SearchKey key = SearchKey.buildBcc("Somebody");
checkValid("BCC Somebody\r\n", key);
@@ -100,7 +108,7 @@
checkInvalid("bg\r\n", key);
checkInvalid("bccc\r\n", key);
}
-
+
public void testShouldParseOn() throws Exception {
SearchKey key = SearchKey.buildOn(DATE);
checkValid("ON 1-Jan-2000\r\n", key);
@@ -117,7 +125,7 @@
checkInvalid("on 1-Jan\r\n", key);
checkInvalid("on 1-Jan-\r\n", key);
}
-
+
public void testShouldParseSentBefore() throws Exception {
SearchKey key = SearchKey.buildSentBefore(DATE);
checkValid("SENTBEFORE 1-Jan-2000\r\n", key);
@@ -139,7 +147,7 @@
checkInvalid("sentbefore 1-Jan\r\n", key);
checkInvalid("sentbefore 1-Jan-\r\n", key);
}
-
+
public void testShouldParseSentOn() throws Exception {
SearchKey key = SearchKey.buildSentOn(DATE);
checkValid("SENTON 1-Jan-2000\r\n", key);
@@ -157,7 +165,7 @@
checkInvalid("senton 1-Jan\r\n", key);
checkInvalid("senton 1-Jan-\r\n", key);
}
-
+
public void testShouldParseSentSince() throws Exception {
SearchKey key = SearchKey.buildSentSince(DATE);
checkValid("SENTSINCE 1-Jan-2000\r\n", key);
@@ -178,7 +186,7 @@
checkInvalid("sentsince 1-Jan\r\n", key);
checkInvalid("sentsince 1-Jan-\r\n", key);
}
-
+
public void testShouldParseSince() throws Exception {
SearchKey key = SearchKey.buildSince(DATE);
checkValid("SINCE 1-Jan-2000\r\n", key);
@@ -196,7 +204,7 @@
checkInvalid("since 1-Jan\r\n", key);
checkInvalid("since 1-Jan-\r\n", key);
}
-
+
public void testShouldParseBefore() throws Exception {
SearchKey key = SearchKey.buildBefore(DATE);
checkValid("BEFORE 1-Jan-2000\r\n", key);
@@ -218,7 +226,7 @@
checkInvalid("BEforE 1-Jan\r\n", key);
checkInvalid("BEforE 1-Jan-\r\n", key);
}
-
+
public void testShouldParseBody() throws Exception {
SearchKey key = SearchKey.buildBody("Text");
checkValid("BODY Text\r\n", key);
@@ -231,9 +239,9 @@
checkInvalid("Bo\r\n", key);
checkInvalid("Bod\r\n", key);
checkInvalid("Bodd\r\n", key);
- checkInvalid("Bodym\r\n", key);
+ checkInvalid("Bodym\r\n", key);
}
-
+
public void testShouldParseTo() throws Exception {
SearchKey key = SearchKey.buildTo("AnAddress");
checkValid("TO AnAddress\r\n", key);
@@ -247,7 +255,7 @@
checkInvalid("too\r\n", key);
checkInvalid("to \r\n", key);
}
-
+
public void testShouldParseText() throws Exception {
SearchKey key = SearchKey.buildText("SomeText");
checkValid("TEXT SomeText\r\n", key);
@@ -262,7 +270,7 @@
checkInvalid("text\r\n", key);
checkInvalid("text \r\n", key);
}
-
+
public void testShouldParseSubject() throws Exception {
SearchKey key = SearchKey.buildSubject("ASubject");
checkValid("SUBJECT ASubject\r\n", key);
@@ -280,7 +288,7 @@
checkInvalid("subject\r\n", key);
checkInvalid("subject \r\n", key);
}
-
+
public void testShouldParseCc() throws Exception {
SearchKey key = SearchKey.buildCc("SomeText");
checkValid("CC SomeText\r\n", key);
@@ -307,7 +315,7 @@
checkInvalid("ftom\r\n", key);
checkInvalid("froml\r\n", key);
}
-
+
public void testShouldParseKeyword() throws Exception {
SearchKey key = SearchKey.buildKeyword("AFlag");
checkValid("KEYWORD AFlag\r\n", key);
@@ -325,7 +333,7 @@
checkInvalid("keywordi\r\n", key);
checkInvalid("keyword \r\n", key);
}
-
+
public void testShouldParseUnKeyword() throws Exception {
SearchKey key = SearchKey.buildUnkeyword("AFlag");
checkValid("UNKEYWORD AFlag\r\n", key);
@@ -345,7 +353,6 @@
checkInvalid("unkeywordi\r\n", key);
checkInvalid("unkeyword \r\n", key);
}
-
public void testShouldParseHeader() throws Exception {
SearchKey key = SearchKey.buildHeader("Field", "Value");
@@ -364,9 +371,10 @@
checkInvalid("header field\r\n", key);
checkInvalid("header field \r\n", key);
}
-
+
private void checkValid(String input, final SearchKey key) throws Exception {
- ImapRequestLineReader reader = new ImapRequestLineReader(new ByteArrayInputStream(input.getBytes("US-ASCII")),
+ ImapRequestLineReader reader = new ImapRequestLineReader(
+ new ByteArrayInputStream(input.getBytes("US-ASCII")),
new ByteArrayOutputStream());
assertEquals(key, parser.searchKey(reader, null, false));
@@ -390,73 +398,73 @@
checkInvalid("e\r\n", key);
checkInvalid("ee\r\n", key);
}
-
+
public void testGShouldBeInvalid() throws Exception {
SearchKey key = SearchKey.buildDeleted();
checkInvalid("g\r\n", key);
checkInvalid("G\r\n", key);
}
-
+
public void testIShouldBeInvalid() throws Exception {
SearchKey key = SearchKey.buildDeleted();
checkInvalid("i\r\n", key);
checkInvalid("I\r\n", key);
}
-
+
public void testJShouldBeInvalid() throws Exception {
SearchKey key = SearchKey.buildDeleted();
checkInvalid("j\r\n", key);
checkInvalid("J\r\n", key);
}
-
+
public void testMShouldBeInvalid() throws Exception {
SearchKey key = SearchKey.buildDeleted();
checkInvalid("m\r\n", key);
checkInvalid("M\r\n", key);
}
-
+
public void testPShouldBeInvalid() throws Exception {
SearchKey key = SearchKey.buildDeleted();
checkInvalid("p\r\n", key);
checkInvalid("Pp\r\n", key);
}
-
+
public void testQShouldBeInvalid() throws Exception {
SearchKey key = SearchKey.buildDeleted();
checkInvalid("q\r\n", key);
checkInvalid("Qq\r\n", key);
}
-
+
public void testWShouldBeInvalid() throws Exception {
SearchKey key = SearchKey.buildDeleted();
checkInvalid("w\r\n", key);
checkInvalid("ww\r\n", key);
}
-
+
public void testVShouldBeInvalid() throws Exception {
SearchKey key = SearchKey.buildDeleted();
checkInvalid("v\r\n", key);
checkInvalid("vv\r\n", key);
}
-
+
public void testXShouldBeInvalid() throws Exception {
SearchKey key = SearchKey.buildDeleted();
checkInvalid("x\r\n", key);
checkInvalid("xx\r\n", key);
}
-
+
public void testYShouldBeInvalid() throws Exception {
SearchKey key = SearchKey.buildDeleted();
checkInvalid("y\r\n", key);
checkInvalid("yy\r\n", key);
}
-
+
public void testZShouldBeInvalid() throws Exception {
SearchKey key = SearchKey.buildDeleted();
checkInvalid("z\r\n", key);
checkInvalid("zz\r\n", key);
}
-
+
public void testShouldParseRecent() throws Exception {
SearchKey key = SearchKey.buildRecent();
checkValid("RECENT\r\n", key);
@@ -468,7 +476,7 @@
checkInvalid("rece\r\n", key);
checkInvalid("recen\r\n", key);
}
-
+
public void testShouldParseDraft() throws Exception {
SearchKey key = SearchKey.buildDraft();
checkValid("DRAFT\r\n", key);
@@ -479,7 +487,7 @@
checkInvalid("DRA\r\n", key);
checkInvalid("DRAF\r\n", key);
}
-
+
public void testShouldParseUnanswered() throws Exception {
SearchKey key = SearchKey.buildUnanswered();
checkValid("UNANSWERED\r\n", key);
@@ -495,7 +503,7 @@
checkInvalid("unanswer\r\n", key);
checkInvalid("unanswere\r\n", key);
}
-
+
public void testShouldParseUndeleted() throws Exception {
SearchKey key = SearchKey.buildUndeleted();
checkValid("UNDELETED\r\n", key);
@@ -510,7 +518,7 @@
checkInvalid("undelet\r\n", key);
checkInvalid("undelete\r\n", key);
}
-
+
public void testShouldParseUnseen() throws Exception {
SearchKey key = SearchKey.buildUnseen();
checkValid("UNSEEN\r\n", key);
@@ -522,7 +530,7 @@
checkInvalid("unse\r\n", key);
checkInvalid("unsee\r\n", key);
}
-
+
public void testShouldParseUndraft() throws Exception {
SearchKey key = SearchKey.buildUndraft();
checkValid("UNDRAFT\r\n", key);
@@ -535,7 +543,7 @@
checkInvalid("undra\r\n", key);
checkInvalid("undraf\r\n", key);
}
-
+
public void testShouldParseUnflagged() throws Exception {
SearchKey key = SearchKey.buildUnflagged();
checkValid("UNFLAGGED\r\n", key);
@@ -550,7 +558,7 @@
checkInvalid("unflagg\r\n", key);
checkInvalid("unflagge\r\n", key);
}
-
+
public void testShouldParseSeen() throws Exception {
SearchKey key = SearchKey.buildSeen();
checkValid("SEEN\r\n", key);
@@ -560,7 +568,7 @@
checkInvalid("se\r\n", key);
checkInvalid("see\r\n", key);
}
-
+
public void testShouldParseNew() throws Exception {
SearchKey key = SearchKey.buildNew();
checkValid("NEW\r\n", key);
@@ -570,7 +578,7 @@
checkInvalid("ne\r\n", key);
checkInvalid("nwe\r\n", key);
}
-
+
public void testShouldParseOld() throws Exception {
SearchKey key = SearchKey.buildOld();
checkValid("OLD\r\n", key);
@@ -580,7 +588,7 @@
checkInvalid("ol\r\n", key);
checkInvalid("olr\r\n", key);
}
-
+
public void testShouldParseFlagged() throws Exception {
SearchKey key = SearchKey.buildFlagged();
checkValid("FLAGGED\r\n", key);
@@ -608,8 +616,8 @@
checkInvalid("smalle\r\n", key);
checkInvalid("smaller \r\n", key);
checkInvalid("smaller peach\r\n", key);
- }
-
+ }
+
public void testShouldParseLarger() throws Exception {
SearchKey key = SearchKey.buildLarger(1234);
checkValid("LARGER 1234\r\n", key);
@@ -624,9 +632,9 @@
checkInvalid("larger \r\n", key);
checkInvalid("larger peach\r\n", key);
}
-
+
public void testShouldParseUid() throws Exception {
- IdRange[] range = {new IdRange(1)};
+ IdRange[] range = { new IdRange(1) };
SearchKey key = SearchKey.buildUidSet(range);
checkValid("UID 1\r\n", key);
checkValid("Uid 1\r\n", key);
@@ -636,7 +644,7 @@
checkInvalid("uid\r\n", key);
checkInvalid("uid \r\n", key);
}
-
+
public void testShouldParseNot() throws Exception {
SearchKey notdKey = SearchKey.buildSeen();
SearchKey key = SearchKey.buildNot(notdKey);
@@ -648,7 +656,7 @@
checkInvalid("not\r\n", key);
checkInvalid("not \r\n", key);
}
-
+
public void testShouldParseOr() throws Exception {
SearchKey oneKey = SearchKey.buildSeen();
SearchKey twoKey = SearchKey.buildDraft();
@@ -662,7 +670,7 @@
checkInvalid("or seen\r\n", key);
checkInvalid("or seen \r\n", key);
}
-
+
public void testShouldParseSequenceSet() throws Exception {
checkSequenceSet(1);
checkSequenceSet(2);
@@ -681,20 +689,22 @@
}
private void checkSequenceSet(int number) throws Exception {
- IdRange[] range = {new IdRange(number)};
+ IdRange[] range = { new IdRange(number) };
SearchKey key = SearchKey.buildSequenceSet(range);
checkValid(number + "\r\n", key);
}
-
- private void checkInvalid(String input, final SearchKey key) throws Exception {
- ImapRequestLineReader reader = new ImapRequestLineReader(new ByteArrayInputStream(input.getBytes("US-ASCII")),
+
+ private void checkInvalid(String input, final SearchKey key)
+ throws Exception {
+ ImapRequestLineReader reader = new ImapRequestLineReader(
+ new ByteArrayInputStream(input.getBytes("US-ASCII")),
new ByteArrayOutputStream());
try {
parser.searchKey(reader, null, false);
fail("Expected protocol exception to be throw since input is invalid");
} catch (ProtocolException e) {
- //expected
+ // expected
}
}
}
Modified: james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/SearchCommandParserTopLevelAndTest.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/SearchCommandParserTopLevelAndTest.java?rev=696828&r1=696827&r2=696828&view=diff
==============================================================================
--- james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/SearchCommandParserTopLevelAndTest.java (original)
+++ james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/SearchCommandParserTopLevelAndTest.java Thu Sep 18 14:44:56 2008
@@ -39,91 +39,106 @@
public class SearchCommandParserTopLevelAndTest extends MockObjectTestCase {
- Input[] one = {sequence()};
-
- Input[] base = {sequence(), uid(), fromHeader(), since(), stringQuoted(), stringUnquoted(), draft()};
-
- Input[] variety = {sequence(), uid(), fromHeader(), since(), stringQuoted(), stringUnquoted(), draft(),
- mailingListHeader(), on(), unanswered(), };
-
+ Input[] one = { sequence() };
+
+ Input[] base = { sequence(), uid(), fromHeader(), since(), stringQuoted(),
+ stringUnquoted(), draft() };
+
+ Input[] variety = { sequence(), uid(), fromHeader(), since(),
+ stringQuoted(), stringUnquoted(), draft(), mailingListHeader(),
+ on(), unanswered(), };
+
public static Input sequence() {
- IdRange[] range = {new IdRange(Long.MAX_VALUE, 100), new IdRange(110), new IdRange(200, 201),
- new IdRange(400, Long.MAX_VALUE)};
+ IdRange[] range = { new IdRange(Long.MAX_VALUE, 100), new IdRange(110),
+ new IdRange(200, 201), new IdRange(400, Long.MAX_VALUE) };
SearchKey key = SearchKey.buildSequenceSet(range);
return new Input("*:100,110,200:201,400:*", key);
}
-
+
public static Input uid() {
- IdRange[] range = {new IdRange(Long.MAX_VALUE, 100), new IdRange(110), new IdRange(200, 201),
- new IdRange(400, Long.MAX_VALUE)};
+ IdRange[] range = { new IdRange(Long.MAX_VALUE, 100), new IdRange(110),
+ new IdRange(200, 201), new IdRange(400, Long.MAX_VALUE) };
SearchKey key = SearchKey.buildUidSet(range);
return new Input("UID *:100,110,200:201,400:*", key);
}
-
+
public static Input fromHeader() {
SearchKey key = SearchKey.buildHeader("FROM", "Smith");
return new Input("HEADER FROM Smith", key);
}
-
+
public static Input to() {
- SearchKey key = SearchKey.buildTo("JAMES Server Development <se...@james.apache.org>");
- return new Input("To \"JAMES Server Development <se...@james.apache.org>\"", key);
+ SearchKey key = SearchKey
+ .buildTo("JAMES Server Development <se...@james.apache.org>");
+ return new Input(
+ "To \"JAMES Server Development <se...@james.apache.org>\"",
+ key);
}
-
+
public static Input mailingListHeader() {
- SearchKey key = SearchKey.buildHeader("Mailing-List", "contact server-dev-help@james.apache.org; run by ezmlm");
- return new Input("HEADER Mailing-List \"contact server-dev-help@james.apache.org; run by ezmlm\"", key);
+ SearchKey key = SearchKey.buildHeader("Mailing-List",
+ "contact server-dev-help@james.apache.org; run by ezmlm");
+ return new Input(
+ "HEADER Mailing-List \"contact server-dev-help@james.apache.org; run by ezmlm\"",
+ key);
}
-
+
public static Input since() {
- SearchKey key = SearchKey.buildSince(new DayMonthYear(11,1, 2001));
+ SearchKey key = SearchKey.buildSince(new DayMonthYear(11, 1, 2001));
return new Input("since 11-Jan-2001", key);
}
-
+
public static Input on() {
- SearchKey key = SearchKey.buildOn(new DayMonthYear(1,2, 2001));
+ SearchKey key = SearchKey.buildOn(new DayMonthYear(1, 2, 2001));
return new Input("on 1-Feb-2001", key);
}
-
+
public static Input stringUnquoted() {
SearchKey key = SearchKey.buildFrom("Smith");
return new Input("FROM Smith", key);
}
-
+
public static Input stringQuoted() {
SearchKey key = SearchKey.buildFrom("Smith And Jones");
return new Input("FROM \"Smith And Jones\"", key);
}
-
+
public static Input draft() {
SearchKey key = SearchKey.buildDraft();
return new Input("DRAFT", key);
}
-
+
public static Input unanswered() {
SearchKey key = SearchKey.buildUnanswered();
return new Input("unanswered", key);
}
-
+
public static final class Input {
public String input;
+
public SearchKey key;
-
+
public Input(String input, SearchKey key) {
super();
this.input = input;
this.key = key;
}
}
-
+
SearchCommandParser parser;
+
Mock mockCommandFactory;
+
Mock mockMessageFactory;
+
Mock mockCommand;
+
Mock mockMessage;
+
ImapCommand command;
+
ImapMessage message;
-
+
protected void setUp() throws Exception {
super.setUp();
parser = new SearchCommandParser();
@@ -135,34 +150,36 @@
mockMessage = mock(ImapMessage.class);
message = (ImapMessage) mockMessage.proxy();
parser.init((Imap4Rev1CommandFactory) mockCommandFactory.proxy());
- parser.setMessageFactory((Imap4Rev1MessageFactory) mockMessageFactory.proxy());
+ parser.setMessageFactory((Imap4Rev1MessageFactory) mockMessageFactory
+ .proxy());
}
protected void tearDown() throws Exception {
super.tearDown();
}
-
+
public void testLargePermutations() throws Exception {
permute(16, one);
permute(32, one);
}
-
+
public void testBasePermutations() throws Exception {
permute(2, base);
permute(3, base);
permute(4, base);
permute(5, base);
}
-
+
public void testVarietyPermutations() throws Exception {
permute(5, variety);
}
-
+
private void permute(int mutations, Input[] inputs) throws Exception {
permute(mutations, new ArrayList(), new StringBuffer(), inputs);
}
-
- private void permute(int mutations, List keys, StringBuffer buffer, Input[] inputs) throws Exception {
+
+ private void permute(int mutations, List keys, StringBuffer buffer,
+ Input[] inputs) throws Exception {
if (mutations == 0) {
check(keys, buffer);
} else {
@@ -180,13 +197,14 @@
}
}
- private void check(List keys, StringBuffer buffer) throws UnsupportedEncodingException, ProtocolException {
+ private void check(List keys, StringBuffer buffer)
+ throws UnsupportedEncodingException, ProtocolException {
buffer.append("\r\n");
String input = buffer.toString();
SearchKey key = SearchKey.buildAnd(keys);
ImapRequestLineReader reader = new ImapRequestLineReader(
- new ByteArrayInputStream(input.getBytes("US-ASCII")),
- new ByteArrayOutputStream());
+ new ByteArrayInputStream(input.getBytes("US-ASCII")),
+ new ByteArrayOutputStream());
assertEquals(input, key, parser.decode(reader));
}
Modified: james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/StoreCommandParserTest.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/StoreCommandParserTest.java?rev=696828&r1=696827&r2=696828&view=diff
==============================================================================
--- james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/StoreCommandParserTest.java (original)
+++ james/protocols/imap/trunk/codec/src/test/java/org/apache/james/imapserver/codec/decode/imap4rev1/StoreCommandParserTest.java Thu Sep 18 14:44:56 2008
@@ -37,13 +37,19 @@
public class StoreCommandParserTest extends MockObjectTestCase {
StoreCommandParser parser;
+
Mock mockCommandFactory;
+
Mock mockMessageFactory;
+
Mock mockCommand;
+
Mock mockMessage;
+
ImapCommand command;
+
ImapMessage message;
-
+
protected void setUp() throws Exception {
super.setUp();
parser = new StoreCommandParser();
@@ -55,7 +61,8 @@
mockMessage = mock(ImapMessage.class);
message = (ImapMessage) mockMessage.proxy();
parser.init((Imap4Rev1CommandFactory) mockCommandFactory.proxy());
- parser.setMessageFactory((Imap4Rev1MessageFactory) mockMessageFactory.proxy());
+ parser.setMessageFactory((Imap4Rev1MessageFactory) mockMessageFactory
+ .proxy());
}
protected void tearDown() throws Exception {
@@ -63,22 +70,25 @@
}
public void testShouldParseSilentDraftFlagged() throws Exception {
- IdRange[] ranges = {new IdRange(1)};
+ IdRange[] ranges = { new IdRange(1) };
Flags flags = new Flags();
flags.add(Flags.Flag.DRAFT);
flags.add(Flags.Flag.FLAGGED);
- check("1 FLAGS.SILENT (\\Draft \\Flagged)\r\n", ranges, true, null, flags,
- false, "A01");
+ check("1 FLAGS.SILENT (\\Draft \\Flagged)\r\n", ranges, true, null,
+ flags, false, "A01");
}
-
- private void check(String input, final IdRange[] idSet, boolean silent, Boolean sign,
- final Flags flags, final boolean useUids, String tag) throws Exception {
- ImapRequestLineReader reader = new ImapRequestLineReader(new ByteArrayInputStream(input.getBytes("US-ASCII")),
- new ByteArrayOutputStream());
-
- Constraint[] constraints = {eq(command), eq(idSet), eq(silent), eq(sign),
- eq(flags), eq(useUids), same(tag)};
- mockMessageFactory.expects(once()).method("createStoreMessage").with(constraints).will(returnValue(message));
+
+ private void check(String input, final IdRange[] idSet, boolean silent,
+ Boolean sign, final Flags flags, final boolean useUids, String tag)
+ throws Exception {
+ ImapRequestLineReader reader = new ImapRequestLineReader(
+ new ByteArrayInputStream(input.getBytes("US-ASCII")),
+ new ByteArrayOutputStream());
+
+ Constraint[] constraints = { eq(command), eq(idSet), eq(silent),
+ eq(sign), eq(flags), eq(useUids), same(tag) };
+ mockMessageFactory.expects(once()).method("createStoreMessage").with(
+ constraints).will(returnValue(message));
parser.decode(command, reader, tag, useUids);
}
}
Modified: james/protocols/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/ExperimentalAuthenticatedStateTest.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/ExperimentalAuthenticatedStateTest.java?rev=696828&r1=696827&r2=696828&view=diff
==============================================================================
--- james/protocols/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/ExperimentalAuthenticatedStateTest.java (original)
+++ james/protocols/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/ExperimentalAuthenticatedStateTest.java Thu Sep 18 14:44:56 2008
@@ -21,7 +21,8 @@
import org.apache.james.test.functional.imap.AbstractAuthenticatedStateTestSuite;
-public class ExperimentalAuthenticatedStateTest extends AbstractAuthenticatedStateTestSuite {
+public class ExperimentalAuthenticatedStateTest extends
+ AbstractAuthenticatedStateTestSuite {
public ExperimentalAuthenticatedStateTest() throws Exception {
super(HostSystemFactory.createStandardImap());
}
Modified: james/protocols/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/ExperimentalConcurrentSessionsTest.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/ExperimentalConcurrentSessionsTest.java?rev=696828&r1=696827&r2=696828&view=diff
==============================================================================
--- james/protocols/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/ExperimentalConcurrentSessionsTest.java (original)
+++ james/protocols/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/ExperimentalConcurrentSessionsTest.java Thu Sep 18 14:44:56 2008
@@ -21,7 +21,8 @@
import org.apache.james.test.functional.imap.AbstractTestConcurrentSessions;
-public class ExperimentalConcurrentSessionsTest extends AbstractTestConcurrentSessions {
+public class ExperimentalConcurrentSessionsTest extends
+ AbstractTestConcurrentSessions {
public ExperimentalConcurrentSessionsTest() throws Exception {
super(HostSystemFactory.createStandardImap());
Modified: james/protocols/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/ExperimentalFetchBodySectionTest.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/ExperimentalFetchBodySectionTest.java?rev=696828&r1=696827&r2=696828&view=diff
==============================================================================
--- james/protocols/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/ExperimentalFetchBodySectionTest.java (original)
+++ james/protocols/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/ExperimentalFetchBodySectionTest.java Thu Sep 18 14:44:56 2008
@@ -21,7 +21,8 @@
import org.apache.james.test.functional.imap.AbstractTestFetchBodySection;
-public class ExperimentalFetchBodySectionTest extends AbstractTestFetchBodySection {
+public class ExperimentalFetchBodySectionTest extends
+ AbstractTestFetchBodySection {
public ExperimentalFetchBodySectionTest() throws Exception {
super(HostSystemFactory.createStandardImap());
Modified: james/protocols/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/ExperimentalFetchBodyStructureTest.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/ExperimentalFetchBodyStructureTest.java?rev=696828&r1=696827&r2=696828&view=diff
==============================================================================
--- james/protocols/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/ExperimentalFetchBodyStructureTest.java (original)
+++ james/protocols/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/ExperimentalFetchBodyStructureTest.java Thu Sep 18 14:44:56 2008
@@ -21,7 +21,8 @@
import org.apache.james.test.functional.imap.AbstractTestFetchBodyStructure;
-public class ExperimentalFetchBodyStructureTest extends AbstractTestFetchBodyStructure {
+public class ExperimentalFetchBodyStructureTest extends
+ AbstractTestFetchBodyStructure {
public ExperimentalFetchBodyStructureTest() throws Exception {
super(HostSystemFactory.createStandardImap());
Modified: james/protocols/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/ExperimentalHostSystem.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/ExperimentalHostSystem.java?rev=696828&r1=696827&r2=696828&view=diff
==============================================================================
--- james/protocols/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/ExperimentalHostSystem.java (original)
+++ james/protocols/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/ExperimentalHostSystem.java Thu Sep 18 14:44:56 2008
@@ -40,25 +40,30 @@
public class ExperimentalHostSystem implements HostSystem {
private ImapDecoder decoder;
+
private ImapEncoder encoder;
+
private ImapProcessor processor;
+
private Resetable dataReset;
+
private final Set users;
-
+
public ExperimentalHostSystem() {
super();
users = new HashSet();
}
-
- public void configure(final ImapDecoder decoder, final ImapEncoder encoder,
- final ImapProcessor processor, final Resetable dataReset) {
+
+ public void configure(final ImapDecoder decoder, final ImapEncoder encoder,
+ final ImapProcessor processor, final Resetable dataReset) {
this.decoder = decoder;
this.encoder = encoder;
this.processor = processor;
this.dataReset = dataReset;
}
-
- public HostSystem.Session newSession(Continuation continuation) throws Exception {
+
+ public HostSystem.Session newSession(Continuation continuation)
+ throws Exception {
return new Session(continuation);
}
@@ -95,14 +100,17 @@
return name;
}
- class Session implements HostSystem.Session
- {
+ class Session implements HostSystem.Session {
ByteBufferOutputStream out;
+
ByteBufferInputStream in;
+
ImapRequestHandler handler;
+
ImapSessionImpl session;
+
boolean isReadLast = true;
-
+
public Session(Continuation continuation) {
out = new ByteBufferOutputStream(continuation);
in = new ByteBufferInputStream();
@@ -110,7 +118,7 @@
handler.setLog(new MockLogger());
session = new ImapSessionImpl();
}
-
+
public String readLine() throws Exception {
if (!isReadLast) {
handler.handleRequest(in, out, session);
@@ -126,7 +134,7 @@
}
public void stop() throws Exception {
-
+
}
public void writeLine(String line) throws Exception {
@@ -142,13 +150,15 @@
}
}
}
-
+
static class ByteBufferInputStream extends InputStream {
-
+
ByteBuffer buffer = ByteBuffer.allocate(16384);
+
CharsetEncoder encoder = Charset.forName("ASCII").newEncoder();
+
boolean readLast = true;
-
+
public int read() throws IOException {
if (!readLast) {
readLast = true;
@@ -160,34 +170,39 @@
}
return result;
}
-
+
public void nextLine(String line) {
if (buffer.position() > 0 && readLast) {
buffer.compact();
}
encoder.encode(CharBuffer.wrap(line), buffer, true);
- buffer.put((byte)'\r');
- buffer.put((byte)'\n');
+ buffer.put((byte) '\r');
+ buffer.put((byte) '\n');
readLast = false;
}
}
-
+
static class ByteBufferOutputStream extends OutputStream {
ByteBuffer buffer = ByteBuffer.allocate(65536);
+
Charset ascii = Charset.forName("ASCII");
+
Continuation continuation;
+
boolean matchPlus = false;
+
boolean matchCR = false;
+
boolean matchLF = false;
-
+
public ByteBufferOutputStream(Continuation continuation) {
this.continuation = continuation;
}
-
+
public void write(String message) throws IOException {
ascii.newEncoder().encode(CharBuffer.wrap(message), buffer, true);
}
-
+
public void write(int b) throws IOException {
buffer.put((byte) b);
if (b == '\n' && matchPlus && matchCR && matchLF) {
@@ -209,8 +224,8 @@
matchCR = false;
matchLF = false;
}
- }
-
+ }
+
public String nextLine() throws Exception {
buffer.flip();
byte last = 0;
@@ -233,13 +248,13 @@
return result;
}
}
-
+
public interface Resetable {
public void reset() throws Exception;
}
- public boolean addUser(String user, String password) throws Exception {
- TorqueMailboxManagerProviderSingleton.addUser(user, password);
- return true;
- }
+ public boolean addUser(String user, String password) throws Exception {
+ TorqueMailboxManagerProviderSingleton.addUser(user, password);
+ return true;
+ }
}
Modified: james/protocols/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/ExperimentalListingTest.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/ExperimentalListingTest.java?rev=696828&r1=696827&r2=696828&view=diff
==============================================================================
--- james/protocols/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/ExperimentalListingTest.java (original)
+++ james/protocols/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/ExperimentalListingTest.java Thu Sep 18 14:44:56 2008
@@ -26,5 +26,5 @@
public ExperimentalListingTest() throws Exception {
super(HostSystemFactory.createStandardImap());
}
-
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org