KickJava   Java API By Example, From Geeks To Geeks.

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


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.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import junit.extensions.*;
25 import junit.textui.TestRunner;
26
27 import org.openide.filesystems.*;
28 import junit.framework.*;
29 import org.netbeans.junit.*;
30 import java.io.IOException JavaDoc;
31 import org.openide.loaders.DataLoader.RecognizedFiles;
32 import org.openide.nodes.Node;
33 import java.lang.ref.WeakReference JavaDoc;
34 import java.io.*;
35 import java.util.*;
36 import java.beans.PropertyVetoException JavaDoc;
37 import javax.swing.event.ChangeListener JavaDoc;
38 import javax.swing.event.ChangeEvent JavaDoc;
39 import org.openide.*;
40 import org.openide.util.Enumerations;
41 import org.openide.util.HelpCtx;
42 import org.openide.util.RequestProcessor;
43 import org.openide.nodes.CookieSet;
44
45 /**
46  * @author Jaroslav Tulach
47  */

48 public class RejectOnCopyCreatesDefaultTest extends LoggingTestCaseHid {
49     FileSystem fs;
50     DataObject one;
51     DataFolder from;
52     DataFolder to;
53     ErrorManager err;
54     
55     
56     /** Creates new DataObjectTest */
57     public RejectOnCopyCreatesDefaultTest (String JavaDoc name) {
58         super (name);
59     }
60     
61     public void setUp() throws Exception JavaDoc {
62         clearWorkDir();
63         
64         SimpleLoader.active = true;
65         
66         super.setUp();
67         
68         registerIntoLookup(new Pool());
69         
70         err = ErrorManager.getDefault().getInstance("TEST-" + getName());
71         
72         LocalFileSystem lfs = new LocalFileSystem();
73         lfs.setRootDirectory(getWorkDir());
74         fs = lfs;
75         FileUtil.createData(fs.getRoot(), "from/x.prima");
76         FileUtil.createFolder(fs.getRoot(), "to/");
77         
78         one = DataObject.find(fs.findResource("from/x.prima"));
79         assertEquals(MultiDataObject.class, one.getClass());
80         assertEquals(SimpleLoader.getLoader(SimpleLoader.class), one.getLoader());
81         
82         from = one.getFolder();
83         to = DataFolder.findFolder(fs.findResource("to/"));
84         
85         assertEquals("Nothing there", 0, to.getPrimaryFile().getChildren().length);
86     }
87     
88     public void testCopyAndSee() throws Exception JavaDoc {
89         
90         SimpleLoader.active = false;
91         
92         DataObject copy = one.copy(to);
93         
94         if (copy.getLoader() == one.getLoader()) {
95             fail("Loaders shall be different:\n" + one + "\nand:\n" + copy);
96         }
97     }
98
99     private static class Pool extends DataLoaderPool {
100         protected Enumeration loaders() {
101             return Enumerations.singleton(SimpleLoader.getLoader(SimpleLoader.class));
102         }
103     }
104     
105     public static final class SimpleLoader extends MultiFileLoader {
106         public SimpleLoader() {
107             super(MultiDataObject.class.getName());
108         }
109         protected String JavaDoc displayName() {
110             return "SimpleLoader";
111         }
112         
113         public static boolean active = true;
114         
115         protected FileObject findPrimaryFile(FileObject fo) {
116             if (!fo.isFolder() && active) {
117                 return fo.hasExt("prima") ? fo : null;
118             }
119             return null;
120         }
121         protected MultiDataObject createMultiObject(FileObject primaryFile) throws DataObjectExistsException, IOException JavaDoc {
122             return new MultiDataObject(primaryFile, this);
123         }
124         protected MultiDataObject.Entry createPrimaryEntry(MultiDataObject obj, FileObject primaryFile) {
125             return new FileEntry(obj, primaryFile);
126         }
127         protected MultiDataObject.Entry createSecondaryEntry(MultiDataObject obj, FileObject secondaryFile) {
128             return new FileEntry(obj, secondaryFile);
129         }
130     }
131 }
132
Popular Tags