1   /*
2    * Wallace IMAP Server
3    * Copyright (C) 2004  Robert Newson
4    *
5    * This program is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU General Public License
7    * as published by the Free Software Foundation; either version 2
8    * of the License, or (at your option) any later version.
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with this program; if not, write to the Free Software
17   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18   */
19  package net.sf.wallace.commands;
20  
21  import java.io.File;
22  import java.util.Properties;
23  
24  import junit.framework.TestCase;
25  import net.sf.wallace.ServerResponse;
26  import net.sf.wallace.SessionHandler;
27  import net.sf.wallace.WallaceServerConfig;
28  import net.sf.wallace.WallaceSession;
29  
30  /***
31   * This abstract class sets up the following objects for subclasses;
32   * 
33   * netty Session WallaceSession WallaceServerConfig
34   * 
35   * A mechanism to retrieve a response message.
36   * 
37   * @author rnewson
38   */
39  public abstract class AbstractCommandTestCase extends TestCase {
40  
41      protected WallaceSession wallaceSession;
42  
43      protected WallaceServerConfig wallaceServerConfig;
44  
45      protected ServerResponse serverResponse;
46  
47      protected void setUp() {
48          wallaceServerConfig = new WallaceServerConfig();
49          wallaceServerConfig.setJavaMailProperties(new Properties());
50          wallaceServerConfig.setMailboxRootDirectory(new File(System.getProperty("java.io.tmpdir")));
51  
52          final SessionHandler sessionHandler = new SessionHandler() {
53  
54              public void respond(final ServerResponse newServerResponse) {
55                  serverResponse = newServerResponse;
56              }
57  
58              public void close() {
59                  // Empty block.
60              }
61          };
62  
63          final WallaceSession newWallaceSession = new WallaceSession();
64          newWallaceSession.setSessionHandler(sessionHandler);
65          newWallaceSession.setServerConfig(wallaceServerConfig);
66          wallaceSession = newWallaceSession;
67      }
68  
69      protected void tearDown() {
70          wallaceSession.close();
71      }
72  
73      protected ServerResponse getResponse() {
74          return serverResponse;
75      }
76  
77  }