Basic.java revision 2362
5390N/A/*
5390N/A * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
5390N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5390N/A *
5390N/A * This code is free software; you can redistribute it and/or modify it
5390N/A * under the terms of the GNU General Public License version 2 only, as
5390N/A * published by the Free Software Foundation.
5390N/A *
5390N/A * This code is distributed in the hope that it will be useful, but WITHOUT
5390N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5390N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5390N/A * version 2 for more details (a copy is included in the LICENSE file that
5390N/A * accompanied this code).
5390N/A *
5390N/A * You should have received a copy of the GNU General Public License version
5390N/A * 2 along with this work; if not, write to the Free Software Foundation,
5390N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5390N/A *
5390N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5390N/A * or visit www.oracle.com if you need additional information or have any
5390N/A * questions.
5390N/A */
5390N/A
5390N/A/* @test
5390N/A * @bug 4313887 6838333
5390N/A * @summary Unit test for java.nio.file.FileSystem
5390N/A * @library ..
5390N/A */
5390N/A
5390N/Aimport java.nio.file.*;
5390N/Aimport java.nio.file.attribute.*;
5390N/Aimport java.io.IOException;
5615N/A
5390N/A/**
5390N/A * Simple santity checks for java.nio.file.FileSystem
5390N/A */
5390N/Apublic class Basic {
5390N/A
5390N/A static void check(boolean okay, String msg) {
5390N/A if (!okay)
5390N/A throw new RuntimeException(msg);
5390N/A }
5390N/A
5390N/A static void checkSupported(FileSystem fs, String... views) {
5390N/A for (String view: views) {
5390N/A check(fs.supportedFileAttributeViews().contains(view),
5390N/A "support for '" + view + "' expected");
5390N/A }
5390N/A }
5390N/A
5390N/A public static void main(String[] args) throws IOException {
5390N/A FileSystem fs = FileSystems.getDefault();
5390N/A
5390N/A // close should throw UOE
5390N/A try {
5390N/A fs.close();
5390N/A throw new RuntimeException("UnsupportedOperationException expected");
5390N/A } catch (UnsupportedOperationException e) { }
5390N/A check(fs.isOpen(), "should be open");
5390N/A
5390N/A check(!fs.isReadOnly(), "should provide read-write access");
5390N/A
5390N/A check(fs.provider().getScheme().equals("file"),
5390N/A "should use 'file' scheme");
5390N/A
5390N/A // santity check method - need to re-visit this in future as I/O errors
5390N/A // are possible
5390N/A for (FileStore store: fs.getFileStores()) {
5390N/A System.out.println(store);
5390N/A }
5390N/A
5390N/A // sanity check supportedFileAttributeViews
5390N/A checkSupported(fs, "basic");
5390N/A String os = System.getProperty("os.name");
5390N/A if (os.equals("SunOS"))
5390N/A checkSupported(fs, "posix", "unix", "owner", "acl", "user");
5615N/A if (os.equals("Linux"))
5390N/A checkSupported(fs, "posix", "unix", "owner", "dos", "user");
5390N/A if (os.equals("Windows"))
5390N/A checkSupported(fs, "owner", "dos", "acl", "user");
5390N/A }
5390N/A}
5390N/A