Lines 17-22
Link Here
|
17 |
import java.io.FileOutputStream; |
17 |
import java.io.FileOutputStream; |
18 |
import java.io.OutputStream; |
18 |
import java.io.OutputStream; |
19 |
import java.net.URL; |
19 |
import java.net.URL; |
|
|
20 |
import java.util.ArrayList; |
20 |
import java.util.Arrays; |
21 |
import java.util.Arrays; |
21 |
import java.util.Collections; |
22 |
import java.util.Collections; |
22 |
import java.util.jar.JarEntry; |
23 |
import java.util.jar.JarEntry; |
Lines 72-77
Link Here
|
72 |
assertEquals("correct FO -> URL for " + textPath, textU, URLMapper.findURL(textFO, URLMapper.EXTERNAL)); |
73 |
assertEquals("correct FO -> URL for " + textPath, textU, URLMapper.findURL(textFO, URLMapper.EXTERNAL)); |
73 |
assertEquals("correct URL -> FO for root", Collections.singletonList(rootFO), Arrays.asList(URLMapper.findFileObjects(rootU))); |
74 |
assertEquals("correct URL -> FO for root", Collections.singletonList(rootFO), Arrays.asList(URLMapper.findFileObjects(rootU))); |
74 |
assertEquals("correct URL -> FO for " + textPath, Collections.singletonList(textFO), Arrays.asList(URLMapper.findFileObjects(textU))); |
75 |
assertEquals("correct URL -> FO for " + textPath, Collections.singletonList(textFO), Arrays.asList(URLMapper.findFileObjects(textU))); |
|
|
76 |
} |
77 |
|
78 |
public void testFindBestFileObject() throws Exception { |
79 |
// This tests creates three subfolders in working directory and a file |
80 |
// in each subfolder. Then it mounts all subfolders (including the working |
81 |
// dir) into repository as individual (overlapping) filesystems and |
82 |
// tests that "best" fileobject is returned for misc URLs. |
83 |
File workdir = getWorkDir(); |
84 |
String path = workdir.getAbsolutePath() + "/folder1/folder2/folder3"; |
85 |
File f = new File(path); |
86 |
f.mkdirs(); |
87 |
|
88 |
path = workdir.getAbsolutePath() + "/folder1/file1.txt"; |
89 |
f = new File(path); |
90 |
f.createNewFile(); |
91 |
path = workdir.getAbsolutePath() + "/folder1/folder2/file2.txt"; |
92 |
f = new File(path); |
93 |
f.createNewFile(); |
94 |
path = workdir.getAbsolutePath() + "/folder1/folder2/folder3/file3.txt"; |
95 |
f = new File(path); |
96 |
f.createNewFile(); |
97 |
|
98 |
LocalFileSystem lfs = new LocalFileSystem(); |
99 |
File folder = workdir; |
100 |
lfs.setRootDirectory(folder); |
101 |
Repository.getDefault().addFileSystem(lfs); |
102 |
lfs = new LocalFileSystem(); |
103 |
folder = new File(folder, "folder1"); |
104 |
lfs.setRootDirectory(folder); |
105 |
Repository.getDefault().addFileSystem(lfs); |
106 |
lfs = new LocalFileSystem(); |
107 |
folder = new File(folder, "folder2"); |
108 |
lfs.setRootDirectory(folder); |
109 |
Repository.getDefault().addFileSystem(lfs); |
110 |
lfs = new LocalFileSystem(); |
111 |
folder = new File(folder, "folder3"); |
112 |
lfs.setRootDirectory(folder); |
113 |
Repository.getDefault().addFileSystem(lfs); |
114 |
|
115 |
String base = workdir.toURI().toURL().toExternalForm(); |
116 |
FileObject fos[] = URLMapper.findFileObjects(new URL(base+"/folder1/folder2/folder3/file3.txt")); |
117 |
ArrayList list = new ArrayList(); |
118 |
for (int i=0; i<fos.length; i++) { |
119 |
list.add(fos[i].getPath()); |
120 |
} |
121 |
assertTrue("list="+list, list.remove("folder1/folder2/folder3/file3.txt")); |
122 |
assertTrue(list.remove("folder2/folder3/file3.txt")); |
123 |
assertTrue(list.remove("folder3/file3.txt")); |
124 |
assertTrue(list.remove("file3.txt")); |
125 |
assertEquals(0, list.size()); |
126 |
|
127 |
assertEquals("file3.txt", URLMapper.findBestFileObject(new URL(base+"/folder1/folder2/folder3/file3.txt")).getPath()); |
128 |
assertEquals("", URLMapper.findBestFileObject(new URL(base+"/folder1/folder2/folder3")).getPath()); |
129 |
assertEquals("file2.txt", URLMapper.findBestFileObject(new URL(base+"/folder1/folder2/file2.txt")).getPath()); |
130 |
assertEquals("", URLMapper.findBestFileObject(new URL(base+"/folder1/folder2")).getPath()); |
131 |
assertEquals("file1.txt", URLMapper.findBestFileObject(new URL(base+"/folder1/file1.txt")).getPath()); |
132 |
assertEquals("", URLMapper.findBestFileObject(new URL(base+"/folder1")).getPath()); |
133 |
assertEquals("", URLMapper.findBestFileObject(new URL(base)).getPath()); |
134 |
|
75 |
} |
135 |
} |
76 |
|
136 |
|
77 |
} |
137 |
} |