Basic.java revision 893:f06f30b29f36
1/*
2 * Copyright 2008-2009 Sun Microsystems, Inc.  All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/* @test
25 * @bug 4313887
26 * @summary Unit test for java.nio.file.FileSystem
27 * @library ..
28 */
29
30import java.nio.file.*;
31import java.nio.file.attribute.*;
32import java.io.IOException;
33
34/**
35 * Simple santity checks for java.nio.file.FileSystem
36 */
37public class Basic {
38
39    static void check(boolean okay, String msg) {
40        if (!okay)
41            throw new RuntimeException(msg);
42    }
43
44    static void checkSupported(FileSystem fs, String... views) {
45        for (String view: views) {
46            check(fs.supportedFileAttributeViews().contains(view),
47                "support for '" + view + "' expected");
48        }
49    }
50
51    public static void main(String[] args) throws IOException {
52        FileSystem fs = FileSystems.getDefault();
53
54        // close should throw UOE
55        try {
56            fs.close();
57            throw new RuntimeException("UnsupportedOperationException expected");
58        } catch (UnsupportedOperationException e) { }
59        check(fs.isOpen(), "should be open");
60
61        check(!fs.isReadOnly(), "should provide read-write access");
62
63        check(fs.provider().getScheme().equals("file"),
64            "should use 'file' scheme");
65
66        // santity check method - need to re-visit this in future as I/O errors
67        // are possible
68        for (FileStore store: fs.getFileStores()) {
69            System.out.println(store);
70        }
71
72        // sanity check supportedFileAttributeViews
73        checkSupported(fs, "basic");
74        String os = System.getProperty("os.name");
75        if (os.equals("SunOS"))
76            checkSupported(fs, "posix", "unix", "owner", "acl", "xattr");
77        if (os.equals("Linux"))
78            checkSupported(fs, "posix", "unix", "owner", "dos", "xattr");
79        if (os.equals("Windows"))
80            checkSupported(fs, "owner", "dos", "acl", "xattr");
81    }
82}
83