|
4 | 4 | import java.lang.reflect.InvocationTargetException; |
5 | 5 | import java.net.URL; |
6 | 6 | import java.nio.charset.StandardCharsets; |
| 7 | +import java.nio.file.Files; |
7 | 8 | import java.nio.file.Path; |
8 | 9 | import java.nio.file.Paths; |
| 10 | +import java.util.ArrayList; |
9 | 11 | import java.util.Arrays; |
10 | 12 | import java.util.List; |
11 | 13 |
|
@@ -37,7 +39,32 @@ public void testWriteFetchFile() throws Exception{ |
37 | 39 |
|
38 | 40 |
|
39 | 41 | assertFalse(fetch.exists()); |
40 | | - FetchWriter.writeFetchFile(itemsToFetch, Paths.get(rootDir.toURI()), StandardCharsets.UTF_8); |
| 42 | + FetchWriter.writeFetchFile(itemsToFetch, Paths.get(rootDir.toURI()), rootPath, StandardCharsets.UTF_8); |
41 | 43 | assertTrue(fetch.exists()); |
42 | 44 | } |
| 45 | + |
| 46 | + @Test |
| 47 | + public void testFetchFileIsFormattedCorrectly() throws Exception{ |
| 48 | + File rootDir = folder.newFolder(); |
| 49 | + Path rootPath = rootDir.toPath(); |
| 50 | + File fetch = new File(rootDir, "fetch.txt"); |
| 51 | + List<FetchItem> itemsToFetch = new ArrayList<>(); |
| 52 | + |
| 53 | + itemsToFetch.add(new FetchItem(new URL("http://localhost:8989/bags/v0_96/holey-bag/data/dir1/test3.txt"), null, rootPath.resolve("data/dir1/test3.txt"))); |
| 54 | + itemsToFetch.add(new FetchItem(new URL("http://localhost:8989/bags/v0_96/holey-bag/data/dir2/dir3/test5.txt"), null, rootPath.resolve("data/dir2/dir3/test5.txt"))); |
| 55 | + itemsToFetch.add(new FetchItem(new URL("http://localhost:8989/bags/v0_96/holey-bag/data/dir2/test4.txt"), null, rootPath.resolve("data/dir2/test4.txt"))); |
| 56 | + itemsToFetch.add(new FetchItem(new URL("http://localhost:8989/bags/v0_96/holey-bag/data/test%201.txt"), null, rootPath.resolve("data/test 1.txt"))); |
| 57 | + itemsToFetch.add(new FetchItem(new URL("http://localhost:8989/bags/v0_96/holey-bag/data/test2.txt"), null, rootPath.resolve("data/test2.txt"))); |
| 58 | + |
| 59 | + FetchWriter.writeFetchFile(itemsToFetch, Paths.get(rootDir.toURI()), rootPath, StandardCharsets.UTF_8); |
| 60 | + |
| 61 | + List<String> expectedLines = Arrays.asList("http://localhost:8989/bags/v0_96/holey-bag/data/dir1/test3.txt - data/dir1/test3.txt", |
| 62 | + "http://localhost:8989/bags/v0_96/holey-bag/data/dir2/dir3/test5.txt - data/dir2/dir3/test5.txt", |
| 63 | + "http://localhost:8989/bags/v0_96/holey-bag/data/dir2/test4.txt - data/dir2/test4.txt", |
| 64 | + "http://localhost:8989/bags/v0_96/holey-bag/data/test%201.txt - data/test 1.txt", |
| 65 | + "http://localhost:8989/bags/v0_96/holey-bag/data/test2.txt - data/test2.txt"); |
| 66 | + List<String> actualLines = Files.readAllLines(fetch.toPath()); |
| 67 | + |
| 68 | + assertEquals(expectedLines, actualLines); |
| 69 | + } |
43 | 70 | } |
0 commit comments