Added
Link Here
|
1 |
/* |
2 |
* Sun Public License Notice |
3 |
* |
4 |
* The contents of this file are subject to the Sun Public License |
5 |
* Version 1.0 (the "License"). You may not use this file except in |
6 |
* compliance with the License. A copy of the License is available at |
7 |
* http://www.sun.com/ |
8 |
* |
9 |
* The Original Code is NetBeans. The Initial Developer of the Original |
10 |
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2001 Sun |
11 |
* Microsystems, Inc. All Rights Reserved. |
12 |
*/ |
13 |
|
14 |
package org.openide.actions; |
15 |
|
16 |
import junit.textui.TestRunner; |
17 |
|
18 |
import org.openide.filesystems.*; |
19 |
import org.openide.util.Lookup; |
20 |
import java.io.IOException; |
21 |
import java.util.*; |
22 |
import org.netbeans.junit.*; |
23 |
import java.beans.PropertyChangeListener; |
24 |
import javax.swing.Action; |
25 |
|
26 |
/** Test basic functionality of data loaders. |
27 |
* @author Jesse Glick |
28 |
*/ |
29 |
public class SaveActionTest extends NbTestCase { |
30 |
|
31 |
public SaveActionTest (String name) { |
32 |
super(name); |
33 |
} |
34 |
|
35 |
public static void main(String[] args) { |
36 |
TestRunner.run(new NbTestSuite(SaveActionTest.class)); |
37 |
} |
38 |
|
39 |
protected void setUp() throws Exception { |
40 |
System.setProperty ("org.openide.util.Lookup", "org.openide.actions.SaveActionTest$Lkp"); |
41 |
assertNotNull ("MyDisplayer is used", Lookup.getDefault ().lookup (MyStatusDisplayer.class)); |
42 |
} |
43 |
/* |
44 |
protected void tearDown() throws Exception { |
45 |
} |
46 |
*/ |
47 |
|
48 |
/** Test for bugfix #23065 |
49 |
*/ |
50 |
public void testSaveActionTakesNameOfDataNodeIfAvaible() throws Exception { |
51 |
try { |
52 |
FileSystem lfs = TestUtilHid.createLocalFileSystem(getName(), new String[] { |
53 |
"folder/file.simple", |
54 |
}); |
55 |
FileObject fo = lfs.findResource("folder/file.simple"); |
56 |
assertNotNull(fo); |
57 |
final org.openide.loaders.DataObject obj = org.openide.loaders.DataObject.find (fo); |
58 |
|
59 |
SaveAction sa = (SaveAction)SaveAction.get (SaveAction.class); |
60 |
|
61 |
class MyNode extends org.openide.nodes.FilterNode |
62 |
implements org.openide.cookies.SaveCookie { |
63 |
public int cnt; |
64 |
|
65 |
public MyNode () { |
66 |
super (obj.getNodeDelegate ()); |
67 |
disableDelegation ( |
68 |
org.openide.nodes.FilterNode.DELEGATE_GET_NAME | |
69 |
org.openide.nodes.FilterNode.DELEGATE_GET_DISPLAY_NAME | |
70 |
org.openide.nodes.FilterNode.DELEGATE_GET_SHORT_DESCRIPTION | |
71 |
org.openide.nodes.FilterNode.DELEGATE_SET_NAME | |
72 |
org.openide.nodes.FilterNode.DELEGATE_SET_DISPLAY_NAME | |
73 |
org.openide.nodes.FilterNode.DELEGATE_SET_SHORT_DESCRIPTION |
74 |
); |
75 |
|
76 |
setName ("my name"); |
77 |
} |
78 |
|
79 |
public org.openide.nodes.Node.Cookie getCookie (Class c) { |
80 |
if (c.isInstance (this)) { |
81 |
return this; |
82 |
} |
83 |
return super.getCookie (c); |
84 |
} |
85 |
|
86 |
public void save () { |
87 |
cnt++; |
88 |
} |
89 |
} |
90 |
|
91 |
MyNode myNode = new MyNode (); |
92 |
Action clone = sa.createContextAwareInstance (org.openide.util.lookup.Lookups.singleton (myNode)); |
93 |
|
94 |
clone.actionPerformed (new java.awt.event.ActionEvent (this, 0, "waitFinished")); |
95 |
|
96 |
assertEquals ("Save called", 1, myNode.cnt); |
97 |
assertEquals ("One msgs", 1, MyStatusDisplayer.cnt); |
98 |
if (MyStatusDisplayer.text.indexOf ("file.simple") < 0) { |
99 |
fail ("Wrong message: " + MyStatusDisplayer.text); |
100 |
} |
101 |
} finally { |
102 |
TestUtilHid.destroyLocalFileSystem(getName()); |
103 |
} |
104 |
} |
105 |
|
106 |
public static class Lkp extends org.openide.util.lookup.AbstractLookup { |
107 |
public Lkp () { |
108 |
this (new org.openide.util.lookup.InstanceContent ()); |
109 |
} |
110 |
|
111 |
private Lkp (org.openide.util.lookup.InstanceContent ic) { |
112 |
super (ic); |
113 |
ic.add (new MyStatusDisplayer ()); |
114 |
ic.add (new org.openide.loaders.DataLoaderPool () { |
115 |
public Enumeration loaders () { |
116 |
return org.openide.util.enum.EmptyEnumeration.EMPTY; |
117 |
} |
118 |
}); |
119 |
} |
120 |
} |
121 |
|
122 |
public static class MyStatusDisplayer extends org.openide.awt.StatusDisplayer { |
123 |
public static int cnt; |
124 |
public static String text; |
125 |
|
126 |
public void addChangeListener (javax.swing.event.ChangeListener l) { |
127 |
} |
128 |
|
129 |
public String getStatusText () { |
130 |
return text; |
131 |
} |
132 |
|
133 |
public void removeChangeListener (javax.swing.event.ChangeListener l) { |
134 |
} |
135 |
|
136 |
public void setStatusText (String msg) { |
137 |
cnt++; |
138 |
text = msg; |
139 |
} |
140 |
|
141 |
} |
142 |
|
143 |
} |