KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > loaders > DataFolderCopyMoreWindowsLikeTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.openide.loaders;
21
22 import java.util.Enumeration JavaDoc;
23 import junit.framework.TestCase;
24 import org.openide.filesystems.FileObject;
25 import org.openide.filesystems.FileUtil;
26 import org.openide.filesystems.Repository;
27
28 /** Mostly to test the correct behaviour of AWTTask.waitFinished.
29  *
30  * @author Jaroslav Tulach
31  */

32 public class DataFolderCopyMoreWindowsLikeTest extends TestCase {
33     DataFolder target;
34     DataFolder source;
35     DataFolder sub;
36
37     public DataFolderCopyMoreWindowsLikeTest(String JavaDoc testName) {
38         super (testName);
39     }
40     
41     protected void setUp() throws Exception JavaDoc {
42         FileObject root = Repository.getDefault ().getDefaultFileSystem ().getRoot ();
43         FileObject[] arr = root.getChildren ();
44         for (int i = 0; i < arr.length; i++) {
45             arr[i].delete ();
46         }
47         
48         target = DataFolder.findFolder (FileUtil.createFolder (root, "Target"));
49         source = DataFolder.findFolder (FileUtil.createFolder (root, "Source"));
50         sub = DataFolder.findFolder (FileUtil.createFolder (root, "Source/Sub/"));
51         FileUtil.createData (root, "Source/Sub/A.txt");
52     }
53
54     public void testCopyIntoTheSameFolderCreatesFolderNamed2 () throws Exception JavaDoc {
55         sub.copy (source);
56        
57         assertFO ("Sibling to Sub created", "/Source/Sub_1/A.txt");
58     }
59     
60     public void testCopyIntoDifferentEmptyFolderIsWithotuRenames () throws Exception JavaDoc {
61         sub.copy (target);
62        
63         assertFO ("A.txt name preserved", "/Target/Sub/A.txt");
64     }
65
66     public void testCopyIntoDifferentNonEmptyFolderCreatesSibling () throws Exception JavaDoc {
67         FileUtil.createData (Repository.getDefault ().getDefaultFileSystem ().getRoot(), "Target/Sub/A.txt");
68         
69         sub.copy (target);
70        
71         assertFO ("A_1.txt sibling created", "/Target/Sub/A_1.txt");
72     }
73
74     public void testMoveIntoTheSameFolderIsForbiden() throws Exception JavaDoc {
75         FileObject old = source.getPrimaryFile ();
76         
77         sub.move (source);
78         
79         assertEquals ("No change", old, source.getPrimaryFile ());
80     }
81     
82     private static void assertFO (String JavaDoc msg, String JavaDoc name) {
83         FileObject fo = Repository.getDefault ().getDefaultFileSystem ().findResource (name);
84         if (fo == null) {
85             StringBuffer JavaDoc sb = new StringBuffer JavaDoc (msg);
86             sb.append (" - cannot find ");
87             sb.append (name);
88             Enumeration JavaDoc en = Repository.getDefault ().getDefaultFileSystem ().getRoot ().getChildren (true);
89             while (en.hasMoreElements ()) {
90                 sb.append ('\n');
91                 sb.append (" ");
92                 sb.append (en.nextElement ());
93             }
94             fail (sb.toString ());
95         }
96     }
97     
98 }
99
Popular Tags