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/21 16:30:10 UTC

svn commit: r477697 - in /james/server/trunk/src: java/org/apache/james/imapserver/commands/ test/org/apache/james/imapserver/client/ test/org/apache/james/imapserver/handler/commands/

Author: joachim
Date: Tue Nov 21 07:30:09 2006
New Revision: 477697

URL: http://svn.apache.org/viewvc?view=rev&rev=477697
Log:
1. subscribe has to call buildFullName (fix + test)
2. CreateCommandTest

Added:
    james/server/trunk/src/test/org/apache/james/imapserver/client/SubscribeClientCommand.java
    james/server/trunk/src/test/org/apache/james/imapserver/handler/commands/CreateCommandTest.java
    james/server/trunk/src/test/org/apache/james/imapserver/handler/commands/SubscribeCommandTest.java
Modified:
    james/server/trunk/src/java/org/apache/james/imapserver/commands/SubscribeCommand.java
    james/server/trunk/src/test/org/apache/james/imapserver/handler/commands/AbstractCommandTest.java

Modified: james/server/trunk/src/java/org/apache/james/imapserver/commands/SubscribeCommand.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/imapserver/commands/SubscribeCommand.java?view=diff&rev=477697&r1=477696&r2=477697
==============================================================================
--- james/server/trunk/src/java/org/apache/james/imapserver/commands/SubscribeCommand.java (original)
+++ james/server/trunk/src/java/org/apache/james/imapserver/commands/SubscribeCommand.java Tue Nov 21 07:30:09 2006
@@ -31,8 +31,7 @@
  *
  * @version $Revision: 109034 $
  */
-class SubscribeCommand extends AuthenticatedStateCommand
-{
+class SubscribeCommand extends AuthenticatedStateCommand {
     public static final String NAME = "SUBSCRIBE";
     public static final String ARGS = "<mailbox>";
 
@@ -40,12 +39,13 @@
     protected void doProcess( ImapRequestLineReader request,
                               ImapResponse response,
                               ImapSession session )
-            throws ProtocolException, MailboxException
-    {
+            throws ProtocolException, MailboxException {
+        
         String mailboxName = parser.mailbox( request );
         parser.endLine( request );
 
         try {
+            mailboxName=session.buildFullName(mailboxName);
             session.getMailboxManager().setSubscription(mailboxName,true);
         } catch (MailboxManagerException e) {
            throw new MailboxException(e);
@@ -55,14 +55,12 @@
     }
 
     /** @see ImapCommand#getName */
-    public String getName()
-    {
+    public String getName() {
         return NAME;
     }
 
     /** @see CommandTemplate#getArgSyntax */
-    public String getArgSyntax()
-    {
+    public String getArgSyntax() {
         return ARGS;
     }
 }

Added: james/server/trunk/src/test/org/apache/james/imapserver/client/SubscribeClientCommand.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/imapserver/client/SubscribeClientCommand.java?view=auto&rev=477697
==============================================================================
--- james/server/trunk/src/test/org/apache/james/imapserver/client/SubscribeClientCommand.java (added)
+++ james/server/trunk/src/test/org/apache/james/imapserver/client/SubscribeClientCommand.java Tue Nov 21 07:30:09 2006
@@ -0,0 +1,28 @@
+/****************************************************************
+ * 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.client;
+
+public class SubscribeClientCommand extends AbstractCommand {
+
+    public SubscribeClientCommand(String folder) {
+        command = "SUBSCRIBE \""+folder+"\"";
+        statusResponse="OK SUBSCRIBE completed.";
+    }
+}

Modified: james/server/trunk/src/test/org/apache/james/imapserver/handler/commands/AbstractCommandTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/imapserver/handler/commands/AbstractCommandTest.java?view=diff&rev=477697&r1=477696&r2=477697
==============================================================================
--- james/server/trunk/src/test/org/apache/james/imapserver/handler/commands/AbstractCommandTest.java (original)
+++ james/server/trunk/src/test/org/apache/james/imapserver/handler/commands/AbstractCommandTest.java Tue Nov 21 07:30:09 2006
@@ -1,3 +1,22 @@
+/****************************************************************
+ * 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.commands;
 
 import java.io.ByteArrayInputStream;
@@ -5,7 +24,9 @@
 
 import org.apache.james.imapserver.ImapRequestHandler;
 import org.apache.james.imapserver.ImapSession;
+import org.apache.james.imapserver.ImapSessionState;
 import org.apache.james.imapserver.ProtocolException;
+import org.apache.james.mailboxmanager.manager.MailboxManager;
 import org.apache.james.services.User;
 import org.apache.james.services.UsersRepository;
 import org.apache.james.test.mock.avalon.MockLogger;
@@ -19,6 +40,7 @@
     Mock mockSession;
     Mock mockUsersRepository;
     Mock mockUser;
+    Mock mockMailboxManager;
 
     public void setUp() {
         handler=new ImapRequestHandler();
@@ -26,6 +48,7 @@
         mockSession = mock ( ImapSession.class);
         mockUsersRepository = mock ( UsersRepository.class );
         mockUser = mock (User.class );
+        mockMailboxManager = mock (MailboxManager.class);
     }
     
     public String handleRequest(String s) throws ProtocolException {
@@ -36,6 +59,14 @@
         String out=os.toString();
         System.out.println("OUT:"+out);
         return out;
+    }
+    
+    protected void setSessionState(ImapSessionState state) {
+        mockSession.expects(atLeastOnce()).method("getState").will(returnValue(state));
+    }
+    
+    protected void setUpMailboxManager() {
+        mockSession.expects(atLeastOnce()).method("getMailboxManager").withNoArguments().will(returnValue(mockMailboxManager.proxy()));
     }
     
 

Added: james/server/trunk/src/test/org/apache/james/imapserver/handler/commands/CreateCommandTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/imapserver/handler/commands/CreateCommandTest.java?view=auto&rev=477697
==============================================================================
--- james/server/trunk/src/test/org/apache/james/imapserver/handler/commands/CreateCommandTest.java (added)
+++ james/server/trunk/src/test/org/apache/james/imapserver/handler/commands/CreateCommandTest.java Tue Nov 21 07:30:09 2006
@@ -0,0 +1,45 @@
+/****************************************************************
+ * 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.commands;
+
+import org.apache.james.imapserver.ImapSessionState;
+import org.apache.james.imapserver.ProtocolException;
+
+public class CreateCommandTest extends AbstractCommandTest {
+
+    public void testCreateNonFq() throws ProtocolException {
+        final String fqMailboxName = "#mock.user.Test";
+
+        setSessionState(ImapSessionState.AUTHENTICATED);
+        setUpMailboxManager();
+
+        mockSession.expects(once()).method("buildFullName").with(eq("Test"))
+                .will(returnValue(fqMailboxName));
+        mockSession.expects(once()).method("unsolicitedResponses").withAnyArguments();
+
+        mockMailboxManager.expects(once()).method("createMailbox").with(
+                eq(fqMailboxName));
+
+        String response = handleRequest("1 CREATE Test\n");
+
+        assertEquals("1 OK CREATE completed.\r\n", response);
+    }
+
+}

Added: james/server/trunk/src/test/org/apache/james/imapserver/handler/commands/SubscribeCommandTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/imapserver/handler/commands/SubscribeCommandTest.java?view=auto&rev=477697
==============================================================================
--- james/server/trunk/src/test/org/apache/james/imapserver/handler/commands/SubscribeCommandTest.java (added)
+++ james/server/trunk/src/test/org/apache/james/imapserver/handler/commands/SubscribeCommandTest.java Tue Nov 21 07:30:09 2006
@@ -0,0 +1,47 @@
+/****************************************************************
+ * 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.commands;
+
+import org.apache.james.imapserver.ImapSessionState;
+import org.apache.james.imapserver.ProtocolException;
+import org.jmock.core.Constraint;
+
+public class SubscribeCommandTest extends AbstractCommandTest {
+
+    public void testSubscribeNonFq() throws ProtocolException {
+        final String fqMailboxName = "#mock.user.Test";
+
+        setSessionState(ImapSessionState.AUTHENTICATED);
+        setUpMailboxManager();
+
+        mockSession.expects(once()).method("buildFullName").with(eq("Test"))
+                .will(returnValue(fqMailboxName));
+        mockSession.expects(once()).method("unsolicitedResponses")
+                .withAnyArguments();
+
+        mockMailboxManager.expects(once()).method("setSubscription").with(
+                new Constraint[] {eq(fqMailboxName),eq(true)});
+
+        String response = handleRequest("1 SUBSCRIBE Test\n");
+
+        assertEquals("1 OK SUBSCRIBE completed.\r\n", response);
+    }
+
+}



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