11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @summary Basic test of jrt file system provider
27 * @run testng Basic
28 */
29
30 import java.io.InputStream;
31 import java.io.DataInputStream;
32 import java.nio.file.DirectoryStream;
33 import java.nio.file.InvalidPathException;
34 import java.nio.file.Files;
35 import java.nio.file.FileSystem;
36 import java.nio.file.FileSystems;
37 import java.nio.file.Path;
38 import java.nio.file.PathMatcher;
39 import java.nio.file.Paths;
40 import java.net.URI;
41 import java.util.Collections;
42 import java.util.Iterator;
43 import java.util.Map;
44 import java.util.NoSuchElementException;
45 import java.util.stream.Stream;
46
47 import org.testng.annotations.DataProvider;
48 import org.testng.annotations.Test;
49
50 import static org.testng.Assert.assertEquals;
565 javaxSeen = true;
566 }
567 }
568 }
569 assertTrue(javaSeen);
570 assertTrue(javaxSeen);
571 }
572
573 @Test
574 public void invalidPathTest() {
575 FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
576 InvalidPathException ipe = null;
577 try {
578 boolean res = Files.exists(fs.getPath("/packages/\ud834\udd7b"));
579 assertFalse(res);
580 return;
581 } catch (InvalidPathException e) {
582 ipe = e;
583 }
584 assertTrue(ipe != null);
585 }
586 }
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @summary Basic test of jrt file system provider
27 * @run testng Basic
28 */
29
30 import java.io.InputStream;
31 import java.io.IOException;
32 import java.io.DataInputStream;
33 import java.nio.file.DirectoryStream;
34 import java.nio.file.InvalidPathException;
35 import java.nio.file.Files;
36 import java.nio.file.FileSystem;
37 import java.nio.file.FileSystems;
38 import java.nio.file.Path;
39 import java.nio.file.PathMatcher;
40 import java.nio.file.Paths;
41 import java.net.URI;
42 import java.util.Collections;
43 import java.util.Iterator;
44 import java.util.Map;
45 import java.util.NoSuchElementException;
46 import java.util.stream.Stream;
47
48 import org.testng.annotations.DataProvider;
49 import org.testng.annotations.Test;
50
51 import static org.testng.Assert.assertEquals;
566 javaxSeen = true;
567 }
568 }
569 }
570 assertTrue(javaSeen);
571 assertTrue(javaxSeen);
572 }
573
574 @Test
575 public void invalidPathTest() {
576 FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
577 InvalidPathException ipe = null;
578 try {
579 boolean res = Files.exists(fs.getPath("/packages/\ud834\udd7b"));
580 assertFalse(res);
581 return;
582 } catch (InvalidPathException e) {
583 ipe = e;
584 }
585 assertTrue(ipe != null);
586 }
587
588 @DataProvider(name="packagesLinkedDirs")
589 private Object[][] packagesLinkedDirs() {
590 return new Object[][] {
591 { "/packages/java.lang/java.base/java/lang/ref" },
592 { "/packages/java.lang/java.base/java/util/zip" },
593 { "/packages/com.oracle/java.xml.ws/com" }
594 };
595 }
596
597 // @bug 8141521: jrt file system's DirectoryStream reports child paths
598 // with wrong paths for directories under /packages
599 @Test(dataProvider = "packagesLinkedDirs")
600 public void dirStreamContentUnderPackagesTest(String dirName) throws IOException {
601 FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
602 Path path = fs.getPath(dirName);
603
604 int childCount = 0, dirPrefixOkayCount = 0;
605 try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(path)) {
606 for (Path child : dirStream) {
607 childCount++;
608 if (child.toString().startsWith(dirName)) {
609 dirPrefixOkayCount++;
610 }
611 }
612 }
613
614 assertEquals(dirPrefixOkayCount, childCount);
615 }
616 }
|