View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.vfs2.provider.ftp;
18  
19  import java.io.IOException;
20  import java.net.SocketException;
21  
22  import org.apache.commons.net.ftp.FTPClient;
23  import org.apache.commons.vfs2.AbstractVfsTestCase;
24  import org.apache.commons.vfs2.FileObject;
25  import org.apache.commons.vfs2.FileSystemException;
26  import org.apache.commons.vfs2.VFS;
27  import org.apache.ftpserver.ftplet.FtpException;
28  import org.junit.AfterClass;
29  import org.junit.BeforeClass;
30  import org.junit.Test;
31  
32  public class MultipleConnectionTestCase {
33  
34      @BeforeClass
35      public static void setUpClass() throws FtpException {
36          FtpProviderTestCase.setUpClass(AbstractVfsTestCase.getTestDirectory(), null, null);
37      }
38  
39      @AfterClass
40      public static void tearDownClass() {
41          FtpProviderTestCase.tearDownClass();
42      }
43  
44      private FileObject resolveRoot() throws FileSystemException {
45          return VFS.getManager().resolveFile(FtpProviderTestCase.getConnectionUri());
46      }
47  
48      @Test
49      public void testConnectRoot() throws IOException {
50          resolveRoot();
51          resolveRoot();
52      }
53  
54      @Test
55      public void testUnderlyingConnect() throws SocketException, IOException {
56          final FTPClient client1 = new FTPClient();
57          final FTPClient client2 = new FTPClient();
58          try {
59              final String hostname = "localhost";
60              client1.connect(hostname, FtpProviderTestCase.getSocketPort());
61              client2.connect(hostname, FtpProviderTestCase.getSocketPort());
62          } finally {
63              client1.disconnect();
64              client2.disconnect();
65          }
66      }
67  }