1 19 20 package org.apache.james.imapserver.handler.commands; 21 22 import java.io.ByteArrayInputStream ; 23 import java.io.ByteArrayOutputStream ; 24 25 import org.apache.james.imapserver.ImapRequestHandler; 26 import org.apache.james.imapserver.ImapSession; 27 import org.apache.james.imapserver.ImapSessionState; 28 import org.apache.james.imapserver.ProtocolException; 29 import org.apache.james.mailboxmanager.manager.MailboxManager; 30 import org.apache.james.services.User; 31 import org.apache.james.services.UsersRepository; 32 import org.apache.james.test.mock.avalon.MockLogger; 33 import org.jmock.Mock; 34 import org.jmock.MockObjectTestCase; 35 36 public abstract class AbstractCommandTest extends MockObjectTestCase 37 { 38 39 ImapRequestHandler handler; 40 Mock mockSession; 41 Mock mockUsersRepository; 42 Mock mockUser; 43 Mock mockMailboxManager; 44 45 public void setUp() { 46 handler=new ImapRequestHandler(); 47 handler.enableLogging(new MockLogger()); 48 mockSession = mock ( ImapSession.class); 49 mockUsersRepository = mock ( UsersRepository.class ); 50 mockUser = mock (User.class ); 51 mockMailboxManager = mock (MailboxManager.class); 52 } 53 54 public String handleRequest(String s) throws ProtocolException { 55 ByteArrayInputStream is=new ByteArrayInputStream (s.getBytes()); 56 ByteArrayOutputStream os=new ByteArrayOutputStream (); 57 System.out.println("IN :"+s); 58 handler.handleRequest(is,os,(ImapSession) mockSession.proxy()); 59 String out=os.toString(); 60 System.out.println("OUT:"+out); 61 return out; 62 } 63 64 protected void setSessionState(ImapSessionState state) { 65 mockSession.expects(atLeastOnce()).method("getState").will(returnValue(state)); 66 } 67 68 protected void setUpMailboxManager() { 69 mockSession.expects(atLeastOnce()).method("getMailboxManager").withNoArguments().will(returnValue(mockMailboxManager.proxy())); 70 } 71 72 73 } 74 | Popular Tags |