Lines 13-18
Link Here
|
13 |
|
13 |
|
14 |
package org.openide.loaders; |
14 |
package org.openide.loaders; |
15 |
|
15 |
|
|
|
16 |
import java.io.*; |
16 |
import junit.textui.TestRunner; |
17 |
import junit.textui.TestRunner; |
17 |
import org.openide.filesystems.FileSystem; |
18 |
import org.openide.filesystems.FileSystem; |
18 |
import java.util.Enumeration; |
19 |
import java.util.Enumeration; |
Lines 25-30
Link Here
|
25 |
* @author Jesse Glick |
26 |
* @author Jesse Glick |
26 |
*/ |
27 |
*/ |
27 |
public class DataNodeTest extends NbTestCase { |
28 |
public class DataNodeTest extends NbTestCase { |
|
|
29 |
private DataFolder top; |
30 |
private DataObject obj; |
31 |
private org.openide.util.actions.SystemAction[] originalActions; |
28 |
|
32 |
|
29 |
public DataNodeTest(String name) { |
33 |
public DataNodeTest(String name) { |
30 |
super(name); |
34 |
super(name); |
Lines 36-47
Link Here
|
36 |
System.exit(0); |
40 |
System.exit(0); |
37 |
} |
41 |
} |
38 |
|
42 |
|
39 |
/* |
|
|
40 |
protected void setUp() throws Exception { |
43 |
protected void setUp() throws Exception { |
|
|
44 |
FileSystem sfs = Repository.getDefault().getDefaultFileSystem(); |
45 |
top = DataFolder.findFolder(sfs.getRoot ()); |
46 |
org.openide.filesystems.FileObject fo = org.openide.filesystems.FileUtil.createData ( |
47 |
sfs.getRoot (), "data.ext" |
48 |
); |
49 |
obj = DataObject.find (fo); |
50 |
|
51 |
originalActions = top.getLoader ().getActions (); |
41 |
} |
52 |
} |
|
|
53 |
|
42 |
protected void tearDown() throws Exception { |
54 |
protected void tearDown() throws Exception { |
|
|
55 |
top.getLoader ().setActions (originalActions); |
43 |
} |
56 |
} |
44 |
*/ |
|
|
45 |
|
57 |
|
46 |
/** Test that for all examples to be found in the system file system, |
58 |
/** Test that for all examples to be found in the system file system, |
47 |
* the node delegate has the same object as a cookie from DataObject.class. |
59 |
* the node delegate has the same object as a cookie from DataObject.class. |
Lines 55-62
Link Here
|
55 |
// outside a running IDE. |
67 |
// outside a running IDE. |
56 |
// TopManager tm = TopManager.getDefault(); |
68 |
// TopManager tm = TopManager.getDefault(); |
57 |
// Now scan SFS for all DO's and check the assertion. |
69 |
// Now scan SFS for all DO's and check the assertion. |
58 |
FileSystem sfs = Repository.getDefault().getDefaultFileSystem(); |
|
|
59 |
DataFolder top = DataFolder.findFolder(sfs.getRoot()); |
60 |
Enumeration e = top.children(true); |
70 |
Enumeration e = top.children(true); |
61 |
while (e.hasMoreElements()) { |
71 |
while (e.hasMoreElements()) { |
62 |
DataObject o = (DataObject)e.nextElement(); |
72 |
DataObject o = (DataObject)e.nextElement(); |
Lines 66-69
Link Here
|
66 |
} |
76 |
} |
67 |
} |
77 |
} |
68 |
|
78 |
|
|
|
79 |
public void testDataNodeReturnsLoadersActions () throws Exception { |
80 |
javax.swing.Action[] arr = { |
81 |
new MyAction ("Name"), |
82 |
new MyAction ("Two"), |
83 |
null, // separator |
84 |
new MyAction ("Last") |
85 |
}; |
86 |
obj.getLoader ().setActions (arr); |
87 |
|
88 |
javax.swing.Action[] nodeActions = obj.getNodeDelegate ().getActions (false); |
89 |
|
90 |
assertEquals ("Same actions", |
91 |
java.util.Arrays.asList (arr), |
92 |
java.util.Arrays.asList (nodeActions) |
93 |
); |
94 |
|
95 |
nodeActions = obj.getNodeDelegate ().getActions (true); |
96 |
|
97 |
assertEquals ("Same actions even of context ones", |
98 |
java.util.Arrays.asList (arr), |
99 |
java.util.Arrays.asList (nodeActions) |
100 |
); |
101 |
|
102 |
assertEquals ("There is just separator for system actions", |
103 |
java.util.Collections.singletonList (null), |
104 |
java.util.Arrays.asList (obj.getNodeDelegate ().getActions ()) |
105 |
); |
106 |
|
107 |
assertEquals ("Preferred is the first", |
108 |
arr[0], obj.getNodeDelegate ().getPreferredAction () |
109 |
); |
110 |
} |
111 |
|
112 |
public void testNonSerializableActionsAreRemovedAfterRebootSerializableStays () throws Exception { |
113 |
javax.swing.Action[] arr = { |
114 |
new MyAction ("NotSerial"), |
115 |
new SerAction ("Serial"), |
116 |
null, // separator |
117 |
org.openide.actions.OpenAction.get (org.openide.actions.OpenAction.class) |
118 |
}; |
119 |
obj.getLoader ().setActions (arr); |
120 |
|
121 |
org.openide.util.io.NbMarshalledObject mar = new org.openide.util.io.NbMarshalledObject (obj.getLoader ()); |
122 |
|
123 |
Object read = mar.get (); |
124 |
|
125 |
assertSame ("Well SharedClassObject means the instance is still same", read, obj.getLoader ()); |
126 |
|
127 |
javax.swing.Action[] newArr = ((DataLoader)read).getSwingActions (); |
128 |
|
129 |
assertEquals ("Only serial, null, open are present", 3, newArr.length); |
130 |
assertNull ("Separator is ok", newArr[1]); |
131 |
assertEquals ("Serial", arr[1], newArr[0]); |
132 |
assertEquals ("OpenAction", arr[2], newArr[1]); |
133 |
} |
134 |
|
135 |
private static class MyAction extends javax.swing.AbstractAction { |
136 |
String name; |
137 |
|
138 |
public MyAction (String name) { |
139 |
this.name = name; |
140 |
} |
141 |
|
142 |
|
143 |
public void actionPerformed (java.awt.event.ActionEvent e) { |
144 |
} |
145 |
|
146 |
public boolean equals (Object o) { |
147 |
if (o instanceof MyAction) { |
148 |
MyAction m = (MyAction)o; |
149 |
return m.name.equals (name); |
150 |
} |
151 |
return false; |
152 |
} |
153 |
|
154 |
public int hashCode () { |
155 |
return 7 + name.hashCode (); |
156 |
} |
157 |
|
158 |
public String toString () { |
159 |
return "MyAction " + name; |
160 |
} |
161 |
} |
162 |
|
163 |
private static final class SerAction extends MyAction implements java.io.Serializable { |
164 |
static final long serialVersionUID = 4398571748139L; |
165 |
|
166 |
public SerAction (String name) { |
167 |
super (name); |
168 |
} |
169 |
|
170 |
private void readObject (ObjectInputStream ois) throws IOException, ClassNotFoundException { |
171 |
name = (String)ois.readObject (); |
172 |
} |
173 |
|
174 |
private void writeObject (ObjectOutputStream oos) throws IOException { |
175 |
oos.writeObject (name); |
176 |
} |
177 |
} |
69 |
} |
178 |
} |