KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > explorer > ExplorerActionsImplTest


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
21 package org.openide.explorer;
22
23 import java.util.Arrays JavaDoc;
24
25 import junit.framework.Test;
26 import junit.framework.TestSuite;
27 import org.netbeans.junit.NbTestCase;
28 import org.netbeans.junit.NbTestSuite;
29
30 import javax.swing.Action JavaDoc;
31 import javax.swing.ActionMap JavaDoc;
32 import javax.swing.JMenu JavaDoc;
33 import javax.swing.text.DefaultEditorKit JavaDoc;
34
35 import org.openide.actions.CopyAction;
36 import org.openide.actions.CutAction;
37 import org.openide.nodes.Children;
38 import org.openide.nodes.Node;
39 import org.openide.nodes.AbstractNode;
40 import org.openide.util.actions.SystemAction;
41 import org.openide.util.ContextAwareAction;
42 import org.openide.util.Lookup;
43 import org.openide.util.Utilities;
44 import org.openide.util.datatransfer.PasteType;
45
46
47 /**
48  * Test whether the old behaviour of ExplorerPanel is correctly simulated
49  * by new API. Inherits testing methods from ExplorerPanel tests, just
50  * setup is changed.
51  *
52  * @author Jaroslav Tulach
53  */

54 public class ExplorerActionsImplTest extends ExplorerPanelTest {
55     
56     public ExplorerActionsImplTest(java.lang.String JavaDoc testName) {
57         super(testName);
58     }
59     
60     public static void main(java.lang.String JavaDoc[] args) {
61         junit.textui.TestRunner.run(suite());
62     }
63     
64     public static Test suite() {
65         TestSuite suite = new NbTestSuite(ExplorerActionsImplTest.class);
66         return suite;
67     }
68
69     /** Creates a manager to operate on.
70      */

71     protected Object JavaDoc[] createManagerAndContext (boolean confirm) {
72         ExplorerManager em = new ExplorerManager ();
73         ActionMap JavaDoc map = new ActionMap JavaDoc ();
74         map.put (DefaultEditorKit.copyAction, ExplorerUtils.actionCopy(em));
75         map.put (DefaultEditorKit.cutAction, ExplorerUtils.actionCut(em));
76         map.put (DefaultEditorKit.pasteAction, ExplorerUtils.actionPaste(em));
77         map.put ("delete", ExplorerUtils.actionDelete(em, confirm));
78         
79         return new Object JavaDoc[] { em, org.openide.util.lookup.Lookups.singleton(map) };
80     }
81     
82     /** Instructs the actions to stop/
83      */

84     protected void stopActions(ExplorerManager em) {
85         ExplorerUtils.activateActions (em, false);
86     }
87     /** Instructs the actions to start again.
88      */

89     protected void startActions (ExplorerManager em) {
90         ExplorerUtils.activateActions (em, true);
91     }
92     
93     
94     public void testActionDeleteDoesNotAffectStateOfPreviousInstances () throws Exception JavaDoc {
95         ExplorerManager em = new ExplorerManager ();
96         Action JavaDoc a1 = ExplorerUtils.actionDelete(em, false);
97         Action JavaDoc a2 = ExplorerUtils.actionDelete(em, true);
98         
99         Node node = new AbstractNode (Children.LEAF) {
100             public boolean canDestroy () {
101                 return true;
102             }
103         };
104         em.setRootContext(node);
105         em.setSelectedNodes(new Node[] { node });
106         
107         assertTrue ("A1 enabled", a1.isEnabled());
108         assertTrue ("A2 enabled", a2.isEnabled());
109         
110         // this should not show a dialog
111
a1.actionPerformed (new java.awt.event.ActionEvent JavaDoc (this, 0, ""));
112     }
113 }
114
Popular Tags