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 static org.apache.commons.vfs2.VfsTestUtils.getTestDirectory;
20  
21  import java.io.IOException;
22  import java.net.SocketException;
23  
24  import org.apache.commons.net.ftp.FTPClient;
25  import org.apache.commons.vfs2.FileObject;
26  import org.apache.commons.vfs2.FileSystemException;
27  import org.apache.commons.vfs2.VFS;
28  import org.apache.ftpserver.ftplet.FtpException;
29  import org.junit.jupiter.api.AfterAll;
30  import org.junit.jupiter.api.BeforeAll;
31  import org.junit.jupiter.api.Test;
32  
33  public class MultipleConnectionTest {
34  
35      @BeforeAll
36      public static void setUpClass() throws FtpException {
37          FtpProviderTestCase.setUpClass(getTestDirectory(), null, null);
38      }
39  
40      @AfterAll
41      public static void tearDownClass() {
42          FtpProviderTestCase.tearDownClass();
43      }
44  
45      private FileObject resolveRoot() throws FileSystemException {
46          return VFS.getManager().resolveFile(FtpProviderTestCase.getConnectionUri());
47      }
48  
49      @Test
50      public void testConnectRoot() throws IOException {
51          resolveRoot();
52          resolveRoot();
53      }
54  
55      @Test
56      public void testUnderlyingConnect() throws SocketException, IOException {
57          final FTPClient client1 = new FTPClient();
58          final FTPClient client2 = new FTPClient();
59          try {
60              final String hostname = "localhost";
61              client1.connect(hostname, FtpProviderTestCase.getSocketPort());
62              client2.connect(hostname, FtpProviderTestCase.getSocketPort());
63          } finally {
64              client1.disconnect();
65              client2.disconnect();
66          }
67      }
68  
69  }