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/lang/ref" },
593 { "packages/java.lang/java.base/java/lang/ref" },
594 { "/packages/../packages/java.lang/java.base/java/lang/ref" },
595 { "/packages/java.lang/java.base/java/util/zip" },
596 { "/./packages/java.lang/java.base/java/util/zip" },
597 { "packages/java.lang/java.base/java/util/zip" },
598 { "/packages/../packages/java.lang/java.base/java/util/zip" },
599 { "/packages/com.oracle/java.xml.ws/com" },
600 { "/./packages/com.oracle/java.xml.ws/com" },
601 { "packages/com.oracle/java.xml.ws/com" },
602 { "/packages/../packages/com.oracle/java.xml.ws/com" }
603 };
604 }
605
606 // @bug 8141521: jrt file system's DirectoryStream reports child paths
607 // with wrong paths for directories under /packages
608 @Test(dataProvider = "packagesLinkedDirs")
609 public void dirStreamPackagesDirTest(String dirName) throws IOException {
610 FileSystem fs = FileSystems.getFileSystem(URI.create("jrt:/"));
611 Path path = fs.getPath(dirName);
612
613 int childCount = 0, dirPrefixOkayCount = 0;
614 try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(path)) {
615 for (Path child : dirStream) {
616 childCount++;
617 if (child.toString().startsWith(dirName)) {
618 dirPrefixOkayCount++;
619 }
620 }
621 }
622
623 assertTrue(childCount != 0);
624 assertEquals(dirPrefixOkayCount, childCount);
625 }
626 }
|