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 java.io.File;
20 import java.io.IOException;
21 import java.util.concurrent.TimeUnit;
22
23 import org.apache.commons.vfs2.AbstractProviderTestConfig;
24 import org.apache.commons.vfs2.FileObject;
25 import org.apache.commons.vfs2.FileSystemManager;
26 import org.apache.commons.vfs2.ProviderTestSuite;
27 import org.apache.commons.vfs2.impl.DefaultFileSystemManager;
28 import org.apache.commons.vfs2.util.NHttpFileServer;
29
30 import junit.framework.Test;
31
32
33
34
35
36 public class UrlProviderHttpTestCase extends AbstractProviderTestConfig {
37 private static NHttpFileServer Server;
38
39 private static int SocketPort;
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 SocketPort = Server.getPort();
60 ConnectionUri = "http://localhost:" + SocketPort;
61 }
62
63 public static Test suite() throws Exception {
64 return new ProviderTestSuite(new UrlProviderHttpTestCase()) {
65 @Override
66 protected void setUp() throws Exception {
67 if (getSystemTestUriOverride() == null) {
68 setUpClass();
69 }
70 super.setUp();
71 }
72
73 @Override
74 protected void tearDown() throws Exception {
75 tearDownClass();
76 super.tearDown();
77 }
78 };
79 }
80
81
82
83
84
85 public static void tearDownClass() throws InterruptedException {
86 if (Server != null) {
87 Server.shutdown(5000, TimeUnit.SECONDS);
88 }
89 }
90
91 public UrlProviderHttpTestCase() throws IOException {
92
93 }
94
95
96
97
98 @Override
99 public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception {
100 String uri = getSystemTestUriOverride();
101 if (uri == null) {
102 uri = ConnectionUri;
103 }
104 return manager.resolveFile(uri);
105 }
106
107
108
109
110 @Override
111 public void prepare(final DefaultFileSystemManager manager) throws Exception {
112 manager.addProvider("http", new UrlFileProvider());
113 }
114 }