author | lancea |
Tue, 29 Oct 2019 14:22:18 -0400 | |
changeset 58845 | e492513d3630 |
parent 58465 | ff45c1bf8129 |
permissions | -rw-r--r-- |
58465
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
1 |
/* |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
4 |
* |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
8 |
* |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
13 |
* accompanied this code). |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
14 |
* |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
18 |
* |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
21 |
* questions. |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
22 |
* |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
23 |
*/ |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
24 |
import org.testng.annotations.BeforeTest; |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
25 |
import org.testng.annotations.Test; |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
26 |
|
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
27 |
import java.io.IOException; |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
28 |
import java.net.URI; |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
29 |
import java.nio.file.FileSystemNotFoundException; |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
30 |
import java.nio.file.FileSystems; |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
31 |
import java.nio.file.Path; |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
32 |
import java.util.Map; |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
33 |
|
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
34 |
import static org.testng.Assert.assertThrows; |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
35 |
|
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
36 |
/** |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
37 |
* @test |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
38 |
* @bug 8223771 |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
39 |
* @summary Validate the correct Exception is thrown if the Zip/JAR is not found |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
40 |
* |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
41 |
* @modules jdk.zipfs |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
42 |
* @run testng/othervm NonExistentPathTests |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
43 |
*/ |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
44 |
public class NonExistentPathTests { |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
45 |
private static final String ZIPFS_SCHEME = "jar"; |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
46 |
private static final ClassLoader CLASS_LOADER = null; |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
47 |
// Non-exist JAR file to test against |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
48 |
private static final Path INVALID_JAR_FILE = Path.of("jarDoesNotExist.jar"); |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
49 |
// Standard Exception expected from FileSystems.newFileSystem |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
50 |
private static Class<? extends Exception> testException = IOException.class; |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
51 |
|
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
52 |
/** |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
53 |
* Validate that the correct Exception is thrown when specifying a Path |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
54 |
* to a JAR that does not exist and is not being created. |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
55 |
*/ |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
56 |
@Test |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
57 |
public void testNewFileSystemWithPath() { |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
58 |
assertThrows(testException, () -> |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
59 |
FileSystems.newFileSystem(INVALID_JAR_FILE)); |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
60 |
assertThrows(testException, () -> |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
61 |
FileSystems.newFileSystem(INVALID_JAR_FILE, Map.of())); |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
62 |
assertThrows(testException, () -> |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
63 |
FileSystems.newFileSystem(INVALID_JAR_FILE, CLASS_LOADER)); |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
64 |
assertThrows(testException, () -> |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
65 |
FileSystems.newFileSystem(INVALID_JAR_FILE, Map.of(), CLASS_LOADER)); |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
66 |
} |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
67 |
|
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
68 |
/** |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
69 |
* Validate that the correct Exception is thrown when specifying a URI |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
70 |
* to a JAR that does not exist and is not being created. |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
71 |
*/ |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
72 |
@Test |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
73 |
public void testNewFileSystemWithUri() throws Exception { |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
74 |
var jarURI = new URI(ZIPFS_SCHEME, |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
75 |
INVALID_JAR_FILE.toUri().toString(), null); |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
76 |
|
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
77 |
assertThrows(testException, () -> |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
78 |
FileSystems.newFileSystem(jarURI, Map.of())); |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
79 |
|
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
80 |
assertThrows(testException, () -> |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
81 |
FileSystems.newFileSystem(jarURI, Map.of(), CLASS_LOADER)); |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
82 |
} |
ff45c1bf8129
8223771: FileSystemProvider.newFileSystem(Path, Map) should throw IOException when called with a file that cannot be open
lancea
parents:
diff
changeset
|
83 |
} |