KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.swing.Action JavaDoc;
23 import javax.swing.SwingUtilities JavaDoc;
24 import org.netbeans.junit.NbTestCase;
25 import org.openide.actions.OpenAction;
26 import org.openide.filesystems.FileObject;
27 import org.openide.filesystems.FileSystem;
28 import org.openide.filesystems.FileUtil;
29 import org.openide.modules.ModuleInfo;
30 import org.openide.nodes.Node;
31 import org.openide.util.Lookup;
32
33 /** DefaultDataObject is supposed to have open operation that shows the text
34  * editor or invokes a dialog with questions.
35  *
36  * @author Jaroslav Tulach
37  */

38 public final class DefaultDataObjectHasOpenActionTest extends NbTestCase {
39
40     private DataObject obj;
41
42     public DefaultDataObjectHasOpenActionTest(String JavaDoc name) {
43         super(name);
44     }
45
46     protected void setUp() throws Exception JavaDoc {
47         super.setUp();
48
49         // initialize modules
50
Lookup.getDefault().lookup(ModuleInfo.class);
51
52         FileSystem fs = FileUtil.createMemoryFileSystem();
53         FileObject fo = fs.getRoot().createData("x.test");
54         obj = DataObject.find(fo);
55
56         assertEquals("The right class", obj.getClass(), DefaultDataObject.class);
57
58         assertFalse("Designed to run outside of AWT", SwingUtilities.isEventDispatchThread());
59     }
60
61     public void testOpenActionIsAlwaysFirst() throws Exception JavaDoc {
62         Node n = obj.getNodeDelegate();
63
64         assertEquals(
65                 "Open action is the default one",
66                 OpenAction.get(OpenAction.class),
67                 n.getPreferredAction()
68                 );
69
70         Action JavaDoc[] actions = n.getActions(false);
71         assertTrue("There are some actions", actions.length > 1);
72
73         assertEquals(
74                 "First one is open",
75                 OpenAction.get(OpenAction.class),
76                 actions[0]
77                 );
78     }
79
80 }
81
Popular Tags