1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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.io.IOException;
23 import java.util.concurrent.TimeUnit;
24
25 import junit.framework.Test;
26
27 import org.apache.commons.vfs2.AbstractProviderTestConfig;
28 import org.apache.commons.vfs2.FileObject;
29 import org.apache.commons.vfs2.FileSystemManager;
30 import org.apache.commons.vfs2.ProviderTestSuite;
31 import org.apache.commons.vfs2.impl.DefaultFileSystemManager;
32 import org.apache.commons.vfs2.util.NHttpFileServer;
33
34
35
36
37 public class UrlProviderHttpTestCase extends AbstractProviderTestConfig {
38
39 private static NHttpFileServer server;
40
41 private static final String TEST_URI = "test.http.uri";
42
43
44
45
46 private static String connectionUri;
47
48 private static String getSystemTestUriOverride() {
49 return System.getProperty(TEST_URI);
50 }
51
52
53
54
55
56
57 private static void setUpClass() throws Exception {
58 server = NHttpFileServer.start(0, new File(getTestDirectory()), 5000);
59 connectionUri = getLocalHostUriString("http", server.getPort());
60 }
61
62 public static Test suite() throws Exception {
63 return new ProviderTestSuite(new UrlProviderHttpTestCase()) {
64 @Override
65 protected void setUp() throws Exception {
66 if (getSystemTestUriOverride() == null) {
67 setUpClass();
68 }
69 super.setUp();
70 }
71
72 @Override
73 protected void tearDown() throws Exception {
74 tearDownClass();
75 super.tearDown();
76 }
77 };
78 }
79
80
81
82
83
84 public static void tearDownClass() throws InterruptedException {
85 if (server != null) {
86 server.shutdown(5000, TimeUnit.SECONDS);
87 }
88 }
89
90 public UrlProviderHttpTestCase() throws IOException {
91
92 }
93
94
95
96
97 @Override
98 public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception {
99 String uri = getSystemTestUriOverride();
100 if (uri == null) {
101 uri = connectionUri;
102 }
103 return manager.resolveFile(uri);
104 }
105
106
107
108
109 @Override
110 public void prepare(final DefaultFileSystemManager manager) throws Exception {
111 manager.addProvider("http", new UrlFileProvider());
112 }
113
114 }