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 jo...@apache.org on 2006/11/05 01:06:59 UTC
svn commit: r471302 - in /james/server/trunk/src:
java/org/apache/james/mailboxmanager/wrapper/
test/org/apache/james/imapserver/ test/org/apache/james/imapserver/client/
test/org/apache/james/imapserver/handler/session/
test/org/apache/james/mailboxma...
Author: joachim
Date: Sat Nov 4 16:06:58 2006
New Revision: 471302
URL: http://svn.apache.org/viewvc?view=rev&rev=471302
Log:
Fix for JAMES-667 - ArrayIndexOutOfBoundsException in UidToMsnBidiMap.assertValidity()
Tests for EXPUNGE command
Added:
james/server/trunk/src/test/org/apache/james/imapserver/client/ExpungeClientCommand.java
james/server/trunk/src/test/org/apache/james/imapserver/handler/session/ExpungeSessionTest.java
james/server/trunk/src/test/org/apache/james/mailboxmanager/wrapper/UidToMsnBidiMapTest.java
Modified:
james/server/trunk/src/java/org/apache/james/mailboxmanager/wrapper/UidToMsnBidiMap.java
james/server/trunk/src/test/org/apache/james/imapserver/TestConstants.java
Modified: james/server/trunk/src/java/org/apache/james/mailboxmanager/wrapper/UidToMsnBidiMap.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/mailboxmanager/wrapper/UidToMsnBidiMap.java?view=diff&rev=471302&r1=471301&r2=471302
==============================================================================
--- james/server/trunk/src/java/org/apache/james/mailboxmanager/wrapper/UidToMsnBidiMap.java (original)
+++ james/server/trunk/src/java/org/apache/james/mailboxmanager/wrapper/UidToMsnBidiMap.java Sat Nov 4 16:06:58 2006
@@ -84,8 +84,17 @@
throw new AssertionError("Msn at position "+(i+1)+" was "+msns[i].intValue());
}
}
- if (msns[msns.length-1].intValue()!=highestMsn) {
- throw new AssertionError("highestMsn "+highestMsn+" msns[msns.length-1] "+msns[msns.length-1]);
+ if (msns.length > 0) {
+ if (msns[msns.length - 1].intValue() != highestMsn) {
+ throw new AssertionError("highestMsn " + highestMsn
+ + " msns[msns.length-1] " + msns[msns.length - 1]);
+ }
+ } else {
+ if (highestMsn != 0) {
+ throw new AssertionError(
+ "highestMsn in empty map has to be 0 but is"
+ + highestMsn);
+ }
}
if (!msnToUid.keySet().equals(new TreeSet(uidToMsn.values()))) {
System.out.println(msnToUid.keySet());
@@ -105,6 +114,10 @@
highestMsn++;
add(highestMsn, uid);
}
+ }
+
+ int size() {
+ return uidToMsn.size();
}
}
Modified: james/server/trunk/src/test/org/apache/james/imapserver/TestConstants.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/imapserver/TestConstants.java?view=diff&rev=471302&r1=471301&r2=471302
==============================================================================
--- james/server/trunk/src/test/org/apache/james/imapserver/TestConstants.java (original)
+++ james/server/trunk/src/test/org/apache/james/imapserver/TestConstants.java Sat Nov 4 16:06:58 2006
@@ -4,6 +4,8 @@
{
final static String USER_NAME="tuser";
final static String USER_MAILBOX_ROOT=ImapConstants.USER_NAMESPACE+"."+USER_NAME;
+ final static String USER_INBOX=USER_MAILBOX_ROOT+".INBOX";
+
final static String USER_PASSWORD="abc";
final static String USER_REALNAME="Test User";
Added: james/server/trunk/src/test/org/apache/james/imapserver/client/ExpungeClientCommand.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/imapserver/client/ExpungeClientCommand.java?view=auto&rev=471302
==============================================================================
--- james/server/trunk/src/test/org/apache/james/imapserver/client/ExpungeClientCommand.java (added)
+++ james/server/trunk/src/test/org/apache/james/imapserver/client/ExpungeClientCommand.java Sat Nov 4 16:06:58 2006
@@ -0,0 +1,42 @@
+package org.apache.james.imapserver.client;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.mail.Flags;
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeMessage;
+
+public class ExpungeClientCommand extends AbstractCommand {
+
+ List expungedMsns = new ArrayList();
+
+ public ExpungeClientCommand(MimeMessage[] msgs) throws MessagingException {
+ int msnOffset = 0;
+
+ command = "EXPUNGE";
+ statusResponse = "OK EXPUNGE completed.";
+ for (int i = 0; i < msgs.length; i++) {
+ if (msgs[i].getFlags().contains(Flags.Flag.DELETED)) {
+ expungedMsns.add(new Integer(i + msnOffset + 1));
+ msnOffset--;
+ }
+ }
+ }
+
+ public List getExpectedResponseList() throws MessagingException,
+ IOException {
+ List responseList = new LinkedList();
+
+ for (Iterator it = expungedMsns.iterator(); it.hasNext();) {
+ final int no = ((Integer) it.next()).intValue();
+ String line = "* " + no + " EXPUNGE";
+ responseList.add(line);
+ }
+ return responseList;
+ }
+
+}
Added: james/server/trunk/src/test/org/apache/james/imapserver/handler/session/ExpungeSessionTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/imapserver/handler/session/ExpungeSessionTest.java?view=auto&rev=471302
==============================================================================
--- james/server/trunk/src/test/org/apache/james/imapserver/handler/session/ExpungeSessionTest.java (added)
+++ james/server/trunk/src/test/org/apache/james/imapserver/handler/session/ExpungeSessionTest.java Sat Nov 4 16:06:58 2006
@@ -0,0 +1,88 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+
+package org.apache.james.imapserver.handler.session;
+
+import java.io.IOException;
+
+import javax.mail.Flags;
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeMessage;
+
+import org.apache.james.imapserver.ProtocolException;
+import org.apache.james.imapserver.client.ExpungeClientCommand;
+import org.apache.james.imapserver.client.LoginCommand;
+import org.apache.james.imapserver.client.SelectCommand;
+import org.apache.james.imapserver.store.MailboxException;
+import org.apache.james.imapserver.util.MessageGenerator;
+import org.apache.james.mailboxmanager.MailboxManagerException;
+
+public class ExpungeSessionTest extends AbstractSessionTest {
+
+ String[] onlyInbox = { USER_INBOX };
+
+ MimeMessage[] msgs = null;
+
+ long[] uids = null;
+
+ public void setUp() throws MailboxException, MessagingException,
+ IOException, MailboxManagerException {
+ super.setUp();
+ createFolders(onlyInbox);
+ }
+
+ public void testExpungeOneMessage() throws MessagingException,
+ MailboxManagerException, ProtocolException, IOException {
+ msgs = MessageGenerator.generateSimplesMessages(1);
+ msgs[0].setFlag(Flags.Flag.DELETED, true);
+ addUIDMessagesOpen(USER_INBOX, msgs);
+ verifyCommand(new LoginCommand(USER_NAME, USER_PASSWORD));
+ verifyCommand(new SelectCommand("INBOX", msgs,
+ getUidValidity(USER_INBOX)));
+ verifyCommandOrdered(new ExpungeClientCommand(msgs));
+ }
+
+ public void testExpunge3Messages() throws MessagingException,
+ MailboxManagerException, ProtocolException, IOException {
+ msgs = MessageGenerator.generateSimplesMessages(3);
+ msgs[0].setFlag(Flags.Flag.DELETED, true);
+ msgs[1].setFlag(Flags.Flag.DELETED, true);
+ msgs[2].setFlag(Flags.Flag.DELETED, true);
+ addUIDMessagesOpen(USER_INBOX, msgs);
+ verifyCommand(new LoginCommand(USER_NAME, USER_PASSWORD));
+ verifyCommand(new SelectCommand("INBOX", msgs,
+ getUidValidity(USER_INBOX)));
+ verifyCommandOrdered(new ExpungeClientCommand(msgs));
+ }
+
+ public void testExpunge4Of6Messages() throws MessagingException,
+ MailboxManagerException, ProtocolException, IOException {
+ msgs = MessageGenerator.generateSimplesMessages(6);
+ msgs[0].setFlag(Flags.Flag.DELETED, true);
+ msgs[2].setFlag(Flags.Flag.DELETED, true);
+ msgs[3].setFlag(Flags.Flag.DELETED, true);
+ msgs[5].setFlag(Flags.Flag.DELETED, true);
+ addUIDMessagesOpen(USER_INBOX, msgs);
+ verifyCommand(new LoginCommand(USER_NAME, USER_PASSWORD));
+ verifyCommand(new SelectCommand("INBOX", msgs,
+ getUidValidity(USER_INBOX)));
+ verifyCommandOrdered(new ExpungeClientCommand(msgs));
+ }
+}
Added: james/server/trunk/src/test/org/apache/james/mailboxmanager/wrapper/UidToMsnBidiMapTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/mailboxmanager/wrapper/UidToMsnBidiMapTest.java?view=auto&rev=471302
==============================================================================
--- james/server/trunk/src/test/org/apache/james/mailboxmanager/wrapper/UidToMsnBidiMapTest.java (added)
+++ james/server/trunk/src/test/org/apache/james/mailboxmanager/wrapper/UidToMsnBidiMapTest.java Sat Nov 4 16:06:58 2006
@@ -0,0 +1,43 @@
+/****************************************************************
+ * 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.mailboxmanager.wrapper;
+
+import junit.framework.TestCase;
+
+public class UidToMsnBidiMapTest extends TestCase {
+
+ UidToMsnBidiMap map;
+
+ public void setUp() {
+ map = new UidToMsnBidiMap();
+ }
+
+ public void testAssertValidityEmpty() {
+ map.assertValidity();
+ }
+
+ public void testExpungeLast() {
+ map.add(1);
+ assertEquals(1, map.size());
+ map.expunge(1);
+ assertEquals(0, map.size());
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org