1   /*
2    * $Id: AbstractFtpServerTestCase.java 7963 2007-08-21 08:53:15Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.providers.ftp;
12  
13  import org.mule.providers.ftp.server.NamedPayload;
14  import org.mule.providers.ftp.server.Server;
15  import org.mule.tck.FunctionalTestCase;
16  
17  
18  public abstract class AbstractFtpServerTestCase extends FunctionalTestCase
19  {
20  
21      public static final String TEST_MESSAGE = "Test FTP message";
22      private static int DEFAULT_TIMEOUT = 10000;
23      private int timeout;
24      private int port;
25      private Server server;
26  
27      public AbstractFtpServerTestCase(int port, int timeout)
28      {
29          this.port = port;
30          this.timeout = timeout;
31          setDisposeManagerPerSuite(true);
32      }
33  
34      public AbstractFtpServerTestCase(int port)
35      {
36          this(port, DEFAULT_TIMEOUT);
37      }
38  
39      protected void startServer() throws Exception
40      {
41          server = new Server(port);
42          server.awaitStart(timeout);
43          // this is really ugly, but the above doesn't get to waiting.
44          // need to improve this as part of ftp server work
45          synchronized(this)
46          {
47              wait(500);
48          }
49      }
50  
51      protected void stopServer() throws Exception
52      {
53          // stop the server
54          if (null != server)
55          {
56              server.stop();
57          }
58      }
59  
60      protected void doPostFunctionalSetUp() throws Exception
61      {
62          startServer();
63      }
64  
65      protected void doFunctionalTearDown() throws Exception
66      {
67          stopServer();
68      }
69  
70      protected int getTimeout()
71      {
72          return timeout;
73      }
74  
75      protected NamedPayload awaitUpload() throws InterruptedException
76      {
77          return server.awaitUpload(timeout);
78      }
79  
80  }