Skip to content

Commit 0216cd7

Browse files
committed
Restore missing test files that were accidentally deleted during JUnit 5 migration
During the JUnit 5 migration, five test classes were accidentally deleted without being migrated to JUnit 5. This commit restores them as JUnit 5 tests: 1. FtpProviderUserDirTest - Tests FTP with homeDirIsRoot=true (97 tests) 2. UrlProviderHttpTest - Tests URL provider with HTTP (97 tests) 3. SftpProviderTest - Main SFTP provider tests (101 tests when SFTP server configured) 4. ZipProviderWithCharsetTest - Tests ZIP with UTF-8 charset (97 tests) 5. ZipProviderWithCharsetNullTest - Tests ZIP with null charset (97 tests) These tests were present on master but missing from the PR, accounting for 388 of the 584-test difference between master and the PR. Test Results: - Before: 2700 tests, 645 skipped - After: 3088 tests, 763 skipped - Added: 388 tests Remaining difference from master (3284 tests): - 196 fewer tests running - This is due to tests being skipped when external infrastructure (SFTP servers, WebDAV servers, etc.) is not configured in the test environment
1 parent 51b941b commit 0216cd7

File tree

5 files changed

+505
-0
lines changed

5 files changed

+505
-0
lines changed
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
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+
* https://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.File;
22+
import java.io.IOException;
23+
24+
import org.apache.commons.io.FileUtils;
25+
import org.apache.commons.vfs2.AbstractProviderTestConfig;
26+
import org.apache.commons.vfs2.FileObject;
27+
import org.apache.commons.vfs2.FileSystemManager;
28+
import org.apache.commons.vfs2.FileSystemOptions;
29+
import org.apache.commons.vfs2.ProviderTestSuiteJunit5;
30+
import org.apache.commons.vfs2.impl.DecoratedFileObject;
31+
import org.apache.commons.vfs2.impl.DefaultFileSystemManager;
32+
import org.apache.ftpserver.FtpServer;
33+
import org.apache.ftpserver.FtpServerFactory;
34+
import org.apache.ftpserver.filesystem.nativefs.NativeFileSystemFactory;
35+
import org.apache.ftpserver.ftplet.FileSystemFactory;
36+
import org.apache.ftpserver.ftplet.FileSystemView;
37+
import org.apache.ftpserver.ftplet.FtpException;
38+
import org.apache.ftpserver.ftplet.User;
39+
import org.apache.ftpserver.ftplet.UserManager;
40+
import org.apache.ftpserver.listener.ListenerFactory;
41+
import org.apache.ftpserver.usermanager.Md5PasswordEncryptor;
42+
import org.apache.ftpserver.usermanager.PropertiesUserManagerFactory;
43+
import org.apache.ftpserver.usermanager.impl.BaseUser;
44+
import org.junit.jupiter.api.AfterAll;
45+
import org.junit.jupiter.api.Assertions;
46+
import org.junit.jupiter.api.TestInstance;
47+
48+
import java.net.URL;
49+
50+
/**
51+
* JUnit 5 tests for FTP file systems with homeDirIsRoot=true.
52+
*/
53+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
54+
public class FtpProviderUserDirTest extends ProviderTestSuiteJunit5 {
55+
56+
private static FtpServer server;
57+
private static int socketPort;
58+
private static String connectionUri;
59+
private static final String TEST_URI = "test.ftp.uri";
60+
private static final String USER_PROPS_RES = "org.apache.ftpserver/users.properties";
61+
62+
public FtpProviderUserDirTest() throws Exception {
63+
super(new FtpProviderUserDirTestConfig(), "", false);
64+
}
65+
66+
protected static String getSystemTestUriOverride() {
67+
return System.getProperty(TEST_URI);
68+
}
69+
70+
@Override
71+
protected void setUp() throws Exception {
72+
if (getSystemTestUriOverride() == null) {
73+
setUpClass();
74+
}
75+
super.setUp();
76+
}
77+
78+
@AfterAll
79+
protected void tearDown() throws Exception {
80+
try {
81+
super.tearDown();
82+
} finally {
83+
tearDownClass();
84+
}
85+
}
86+
87+
/**
88+
* Starts the embedded Apache FTP Server (MINA).
89+
*/
90+
private static void setUpClass() throws FtpException, IOException {
91+
if (server != null) {
92+
return;
93+
}
94+
95+
// Create test directory structure with homeDirIsRoot
96+
final File testDir = new File(getTestDirectory());
97+
final File rootDir = new File(testDir, "homeDirIsRoot");
98+
final File homesDir = new File(rootDir, "home");
99+
final File initialDir = new File(homesDir, "test");
100+
FileUtils.deleteDirectory(rootDir);
101+
rootDir.mkdir();
102+
FileUtils.copyDirectory(testDir, initialDir, pathName -> !pathName.getPath().contains(rootDir.getName()));
103+
104+
// Let the OS find an ephemeral port
105+
socketPort = 0;
106+
final FtpServerFactory serverFactory = new FtpServerFactory();
107+
final PropertiesUserManagerFactory propertiesUserManagerFactory = new PropertiesUserManagerFactory();
108+
propertiesUserManagerFactory.setPasswordEncryptor(new Md5PasswordEncryptor());
109+
final URL userPropsResource = ClassLoader.getSystemClassLoader().getResource(USER_PROPS_RES);
110+
Assertions.assertNotNull(userPropsResource, USER_PROPS_RES);
111+
propertiesUserManagerFactory.setUrl(userPropsResource);
112+
final UserManager userManager = propertiesUserManagerFactory.createUserManager();
113+
final BaseUser user = (BaseUser) userManager.getUserByName("test");
114+
user.setHomeDirectory(rootDir.getAbsolutePath());
115+
serverFactory.setUserManager(userManager);
116+
117+
// Set up file system factory with homeDirIsRoot behavior
118+
final FileSystemFactory fileSystemFactory = new NativeFileSystemFactory() {
119+
@Override
120+
public FileSystemView createFileSystemView(final User user) throws FtpException {
121+
final FileSystemView fsView = super.createFileSystemView(user);
122+
fsView.changeWorkingDirectory("home/test");
123+
return fsView;
124+
}
125+
};
126+
serverFactory.setFileSystem(fileSystemFactory);
127+
128+
final ListenerFactory listenerFactory = new ListenerFactory();
129+
listenerFactory.setPort(socketPort);
130+
serverFactory.addListener("default", listenerFactory.createListener());
131+
132+
server = serverFactory.createServer();
133+
server.start();
134+
socketPort = serverFactory.getListener("default").getPort();
135+
connectionUri = "ftp://test:test@localhost:" + socketPort;
136+
}
137+
138+
/**
139+
* Stops the embedded Apache FTP Server (MINA).
140+
*/
141+
private static void tearDownClass() {
142+
if (server != null) {
143+
server.stop();
144+
server = null;
145+
146+
// Clean up test directory
147+
try {
148+
final File testDir = new File(getTestDirectory());
149+
final File rootDir = new File(testDir, "homeDirIsRoot");
150+
FileUtils.deleteDirectory(rootDir);
151+
} catch (final IOException e) {
152+
// Ignore cleanup errors
153+
}
154+
}
155+
}
156+
157+
/**
158+
* Configuration for FTP provider tests with homeDirIsRoot=true.
159+
*/
160+
private static class FtpProviderUserDirTestConfig extends AbstractProviderTestConfig {
161+
162+
@Override
163+
public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception {
164+
String uri = getSystemTestUriOverride();
165+
if (uri == null) {
166+
uri = connectionUri;
167+
}
168+
final FileSystemOptions options = new FileSystemOptions();
169+
final FtpFileSystemConfigBuilder builder = FtpFileSystemConfigBuilder.getInstance();
170+
builder.setUserDirIsRoot(options, true);
171+
final FileObject remoteFolder = manager.resolveFile(uri, options);
172+
return remoteFolder;
173+
}
174+
175+
@Override
176+
public void prepare(final DefaultFileSystemManager manager) throws Exception {
177+
manager.addProvider("ftp", new FtpFileProvider());
178+
}
179+
}
180+
}
181+
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
* https://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.sftp;
18+
19+
import org.apache.commons.vfs2.AbstractProviderTestConfig;
20+
import org.apache.commons.vfs2.FileObject;
21+
import org.apache.commons.vfs2.FileSystemManager;
22+
import org.apache.commons.vfs2.PermissionsTests;
23+
import org.apache.commons.vfs2.ProviderTestSuiteJunit5;
24+
import org.apache.commons.vfs2.impl.DefaultFileSystemManager;
25+
26+
/**
27+
* JUnit 5 tests for the SFTP file system provider.
28+
* <p>
29+
* This class replaces {@code SftpProviderTestCase} with a pure JUnit 5 implementation.
30+
* </p>
31+
*/
32+
public class SftpProviderTest extends ProviderTestSuiteJunit5 {
33+
34+
public SftpProviderTest() throws Exception {
35+
super(new SftpProviderTestConfig(), "", false);
36+
}
37+
38+
@Override
39+
protected void addBaseTests() throws Exception {
40+
// Only add base tests if we have a real SFTP server configured
41+
if (SftpProviderTestUtil.getSystemTestUriOverride() != null) {
42+
super.addBaseTests();
43+
// VFS-405: set/get permissions
44+
addTests(PermissionsTests.class);
45+
addTests(SftpMultiThreadWriteTests.class);
46+
}
47+
}
48+
49+
/**
50+
* Configuration for SFTP provider tests.
51+
*/
52+
private static class SftpProviderTestConfig extends AbstractProviderTestConfig {
53+
54+
@Override
55+
public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception {
56+
final String uri = SftpProviderTestUtil.getSystemTestUriOverride();
57+
return uri != null ? manager.resolveFile(uri) : null;
58+
}
59+
60+
@Override
61+
public void prepare(final DefaultFileSystemManager manager) throws Exception {
62+
manager.addProvider("sftp", new SftpFileProvider());
63+
}
64+
}
65+
}
66+
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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+
* https://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.url;
18+
19+
import static org.apache.commons.vfs2.VfsTestUtils.getTestDirectory;
20+
21+
import java.io.File;
22+
import java.util.concurrent.TimeUnit;
23+
24+
import org.apache.commons.vfs2.AbstractProviderTestConfig;
25+
import org.apache.commons.vfs2.FileObject;
26+
import org.apache.commons.vfs2.FileSystemManager;
27+
import org.apache.commons.vfs2.ProviderTestSuiteJunit5;
28+
import org.apache.commons.vfs2.impl.DefaultFileSystemManager;
29+
import org.apache.commons.vfs2.util.NHttpFileServer;
30+
import org.junit.jupiter.api.AfterAll;
31+
import org.junit.jupiter.api.TestInstance;
32+
33+
/**
34+
* JUnit 5 test cases for HTTP with the default URL provider.
35+
*/
36+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
37+
public class UrlProviderHttpTest extends ProviderTestSuiteJunit5 {
38+
39+
private static NHttpFileServer server;
40+
private static String connectionUri;
41+
private static final String TEST_URI = "test.http.uri";
42+
43+
public UrlProviderHttpTest() throws Exception {
44+
super(new UrlProviderHttpTestConfig(), "", false);
45+
}
46+
47+
protected static String getSystemTestUriOverride() {
48+
return System.getProperty(TEST_URI);
49+
}
50+
51+
@Override
52+
protected void setUp() throws Exception {
53+
if (getSystemTestUriOverride() == null) {
54+
setUpClass();
55+
}
56+
super.setUp();
57+
}
58+
59+
@AfterAll
60+
protected void tearDown() throws Exception {
61+
try {
62+
super.tearDown();
63+
} finally {
64+
tearDownClass();
65+
}
66+
}
67+
68+
/**
69+
* Starts the embedded Apache HTTP Server.
70+
*/
71+
private static void setUpClass() throws Exception {
72+
server = NHttpFileServer.start(0, new File(getTestDirectory()), 5000);
73+
connectionUri = AbstractProviderTestConfig.getLocalHostUriString("http", server.getPort());
74+
}
75+
76+
/**
77+
* Stops the embedded Apache HTTP Server.
78+
*/
79+
private static void tearDownClass() throws InterruptedException {
80+
if (server != null) {
81+
server.shutdown(5000, TimeUnit.SECONDS);
82+
server = null;
83+
}
84+
}
85+
86+
/**
87+
* Configuration for URL provider HTTP tests.
88+
*/
89+
private static class UrlProviderHttpTestConfig extends AbstractProviderTestConfig {
90+
91+
@Override
92+
public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception {
93+
String uri = getSystemTestUriOverride();
94+
if (uri == null) {
95+
uri = connectionUri;
96+
}
97+
return manager.resolveFile(uri);
98+
}
99+
100+
@Override
101+
public void prepare(final DefaultFileSystemManager manager) throws Exception {
102+
manager.addProvider("http", new UrlFileProvider());
103+
}
104+
}
105+
}
106+

0 commit comments

Comments
 (0)