KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > james > imapserver > handler > commands > AbstractCommandTest


1 /****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one *
3  * or more contributor license agreements. See the NOTICE file *
4  * distributed with this work for additional information *
5  * regarding copyright ownership. The ASF licenses this file *
6  * to you under the Apache License, Version 2.0 (the *
7  * "License"); you may not use this file except in compliance *
8  * with the License. You may obtain a copy of the License at *
9  * *
10  * http://www.apache.org/licenses/LICENSE-2.0 *
11  * *
12  * Unless required by applicable law or agreed to in writing, *
13  * software distributed under the License is distributed on an *
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
15  * KIND, either express or implied. See the License for the *
16  * specific language governing permissions and limitations *
17  * under the License. *
18  ****************************************************************/

19
20 package org.apache.james.imapserver.handler.commands;
21
22 import java.io.ByteArrayInputStream JavaDoc;
23 import java.io.ByteArrayOutputStream JavaDoc;
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 JavaDoc handleRequest(String JavaDoc s) throws ProtocolException {
55         ByteArrayInputStream JavaDoc is=new ByteArrayInputStream JavaDoc(s.getBytes());
56         ByteArrayOutputStream JavaDoc os=new ByteArrayOutputStream JavaDoc();
57         System.out.println("IN :"+s);
58         handler.handleRequest(is,os,(ImapSession) mockSession.proxy());
59         String JavaDoc 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