1 /* 2 * Copyright (c) 2008, 2017, 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 6917021 7006126 6950237 8006645 26 * @summary Unit test for java.nio.file.Files copy and move methods (use -Dseed=X to set PRNG seed) 27 * @library .. /test/lib 28 * @build jdk.test.lib.RandomFactory 29 * CopyAndMove PassThroughFileSystem 30 * @run main/othervm CopyAndMove 31 * @key randomness 32 */ 33 34 import java.nio.ByteBuffer; 35 import java.nio.file.*; 36 import static java.nio.file.Files.*; 37 import static java.nio.file.StandardCopyOption.*; 38 import static java.nio.file.LinkOption.*; 39 import java.nio.file.attribute.*; 40 import java.io.*; 41 import java.util.*; 42 import java.util.concurrent.TimeUnit; 43 import jdk.test.lib.RandomFactory; 44 45 public class CopyAndMove { 431 * Test: move non-empty directory (same file system) 432 */ 433 source = createSourceDirectory(dir1); 434 createFile(source.resolve("foo")); 435 target = getTargetFile(dir1); 436 moveAndVerify(source, target); 437 delete(target.resolve("foo")); 438 delete(target); 439 440 /** 441 * Test: move non-empty directory (different file store) 442 */ 443 if (!sameDevice) { 444 source = createSourceDirectory(dir1); 445 createFile(source.resolve("foo")); 446 target = getTargetFile(dir2); 447 try { 448 moveAndVerify(source, target); 449 throw new RuntimeException("IOException expected"); 450 } catch (IOException x) { 451 } 452 delete(source.resolve("foo")); 453 delete(source); 454 } 455 456 /** 457 * Test atomic move of directory (same file store) 458 */ 459 source = createSourceDirectory(dir1); 460 createFile(source.resolve("foo")); 461 target = getTargetFile(dir1); 462 moveAndVerify(source, target, ATOMIC_MOVE); 463 delete(target.resolve("foo")); 464 delete(target); 465 466 // -- symbolic links -- 467 468 /** 469 * Test: Move symbolic link to file, target does not exist 470 */ | 1 /* 2 * Copyright (c) 2008, 2018, 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 6917021 7006126 6950237 8006645 8201407 26 * @summary Unit test for java.nio.file.Files copy and move methods (use -Dseed=X to set PRNG seed) 27 * @library .. /test/lib 28 * @build jdk.test.lib.RandomFactory 29 * CopyAndMove PassThroughFileSystem 30 * @run main/othervm CopyAndMove 31 * @key randomness 32 */ 33 34 import java.nio.ByteBuffer; 35 import java.nio.file.*; 36 import static java.nio.file.Files.*; 37 import static java.nio.file.StandardCopyOption.*; 38 import static java.nio.file.LinkOption.*; 39 import java.nio.file.attribute.*; 40 import java.io.*; 41 import java.util.*; 42 import java.util.concurrent.TimeUnit; 43 import jdk.test.lib.RandomFactory; 44 45 public class CopyAndMove { 431 * Test: move non-empty directory (same file system) 432 */ 433 source = createSourceDirectory(dir1); 434 createFile(source.resolve("foo")); 435 target = getTargetFile(dir1); 436 moveAndVerify(source, target); 437 delete(target.resolve("foo")); 438 delete(target); 439 440 /** 441 * Test: move non-empty directory (different file store) 442 */ 443 if (!sameDevice) { 444 source = createSourceDirectory(dir1); 445 createFile(source.resolve("foo")); 446 target = getTargetFile(dir2); 447 try { 448 moveAndVerify(source, target); 449 throw new RuntimeException("IOException expected"); 450 } catch (IOException x) { 451 if (!(x instanceof DirectoryNotEmptyException)) { 452 throw new RuntimeException 453 ("DirectoryNotEmptyException expected", x); 454 } 455 } 456 delete(source.resolve("foo")); 457 delete(source); 458 } 459 460 /** 461 * Test atomic move of directory (same file store) 462 */ 463 source = createSourceDirectory(dir1); 464 createFile(source.resolve("foo")); 465 target = getTargetFile(dir1); 466 moveAndVerify(source, target, ATOMIC_MOVE); 467 delete(target.resolve("foo")); 468 delete(target); 469 470 // -- symbolic links -- 471 472 /** 473 * Test: Move symbolic link to file, target does not exist 474 */ |