1 /* 2 * Copyright (c) 2008, 2012, Oracle and/or its affiliates. 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 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 /* @test 25 * @bug 4313887 6838333 26 * @summary Unit test for java.nio.file.FileSystem 27 * @library .. 28 */ 29 30 import java.nio.file.*; 31 import java.nio.file.attribute.*; 32 import java.io.IOException; 33 34 /** 35 * Simple santity checks for java.nio.file.FileSystem 36 */ 37 public 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", "user"); 77 if (os.equals("Linux")) 78 checkSupported(fs, "posix", "unix", "owner", "dos", "user"); 79 if (os.contains("OS X")) 80 checkSupported(fs, "posix", "unix", "owner"); 81 if (os.equals("Windows")) 82 checkSupported(fs, "owner", "dos", "acl", "user"); 83 } 84 }