KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > editor > mimelookup > impl > Depr_MimeLookupTest


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.netbeans.modules.editor.mimelookup.impl;
21
22 import java.io.IOException JavaDoc;
23 import org.netbeans.api.editor.mimelookup.MimeLookup;
24 import org.netbeans.junit.NbTestCase;
25 import org.openide.util.Lookup;
26 import org.openide.util.Lookup.Result;
27 import org.openide.util.Lookup.Template;
28 import org.openide.util.LookupEvent;
29 import org.openide.util.LookupListener;
30
31 /**
32  * Testing basic functionality of MimeLookup
33  * Testing a deprecated MimePath.childLookup behaviour
34  *
35  * @author Martin Roskanin
36  */

37 public class Depr_MimeLookupTest extends NbTestCase {
38     
39     private static final int WAIT_TIME = 5000;
40     private static final int WAIT_TIME_FIRING = 1500;
41     final int resultChangedCount[] = new int[1];
42     
43     public Depr_MimeLookupTest(java.lang.String JavaDoc testName) {
44         super(testName);
45     }
46     
47     protected void setUp() throws java.lang.Exception JavaDoc {
48         String JavaDoc fsstruct [] = new String JavaDoc [] {
49             "Editors/text/xml/text/html/java-lang-StringBuffer.instance", //NOI18N
50
"Editors/text/jsp/testLookup/org-netbeans-modules-editor-mimelookup-impl-TestLookupObject.instance", //NOI18N
51
"Editors/text/x-java/text/xml/testLookupTwo/org-netbeans-modules-editor-mimelookup-impl-TestLookupObjectTwo.instance", //NOI18N
52
"Editors/text/html/text/xml/testLookup/org-netbeans-modules-editor-mimelookup-impl-TestLookupObject.instance", //NOI18N
53
"Editors/text/html/text/xml/testLookupTwo/org-netbeans-modules-editor-mimelookup-impl-TestLookupObjectTwo.instance", //NOI18N
54
"Editors/text/xml/org-netbeans-modules-editor-mimelookup-impl-TestLookupObjectInstantiation.instance", //NOI18N
55
"Editors/text/xml/text/jsp/testLookup/org-netbeans-modules-editor-mimelookup-impl-TestLookupObject.instance", //NOI18N
56
// testing "compound mime types like application/x-ant+xml"
57
"Editors/application/dtd/text/x-java/java-lang-String.instance", //NOI18N
58
"Editors/application/dtd/testLookup/org-netbeans-modules-editor-mimelookup-impl-TestLookupObject.instance", //NOI18N
59
"Editors/application/x-ant+dtd/java-lang-StringBuffer.instance", //NOI18N
60
"Editors/application/x-ant+dtd/text/x-java/testLookupTwo/org-netbeans-modules-editor-mimelookup-impl-TestLookupObjectTwo.instance", //NOI18N
61
};
62
63         EditorTestLookup.setLookup(fsstruct, getWorkDir(), new Object JavaDoc[] {},
64                    getClass().getClassLoader());
65         
66     }
67
68     private void createFile(String JavaDoc file) throws IOException JavaDoc{
69         TestUtilities.createFile(getWorkDir(), file); //NOI18N
70
}
71     
72     private void checkResultChange(final int count) throws IOException JavaDoc{
73         // wait for firing event
74
TestUtilities.waitMaxMilisForValue(WAIT_TIME_FIRING, new TestUtilities.ValueResolver(){
75             public Object JavaDoc getValue(){
76                 return Boolean.FALSE;
77             }
78         }, Boolean.TRUE);
79         assertTrue(("resultChangedCount is:"+resultChangedCount[0]+" instead of "+count), resultChangedCount[0] == count);
80     }
81     
82     /**
83      * Looking up the class that has registered subfolder via Class2LayerFolder
84      */

85     public void testRegisteredClassLookup() throws IOException JavaDoc{
86         
87         MimeLookup lookup;
88         
89         lookup = MimeLookup.getMimeLookup("text/jsp");//NOI18N
90
checkLookupObject(lookup, TestLookupObject.class, true);
91         checkLookupObject(lookup, TestLookupObjectTwo.class, false);
92
93         lookup = MimeLookup.getMimeLookup("text/x-java").childLookup("text/xml"); //NOI18N
94
checkLookupObject(lookup, TestLookupObject.class, false);
95         checkLookupObject(lookup ,TestLookupObjectTwo.class, true);
96
97         lookup = MimeLookup.getMimeLookup("text/html").childLookup("text/xml"); //NOI18N
98
checkLookupObject(lookup, TestLookupObject.class, true);
99         checkLookupObject(lookup, TestLookupObjectTwo.class, true);
100         
101         //test inheritance from underlaying mime types
102
lookup = MimeLookup.getMimeLookup("text/xml").childLookup("text/jsp").childLookup("text/html"); //NOI18N
103
checkLookupObject(lookup, TestLookupObject.class, true);
104         lookup = MimeLookup.getMimeLookup("text/xml");
105         checkLookupObject(lookup, TestLookupObject.class, false);
106         lookup = MimeLookup.getMimeLookup("text/xml").childLookup("text/jsp");
107         checkLookupObject(lookup, TestLookupObject.class, true);
108         
109         //simulating module uninstallation and removal of mime lookup file from xml layer
110
TestUtilities.deleteFile(getWorkDir(), "Editors/text/x-java/text/xml/testLookupTwo/org-netbeans-modules-editor-mimelookup-impl-TestLookupObjectTwo.instance");
111         lookup = MimeLookup.getMimeLookup("text/x-java").childLookup("text/xml"); //NOI18N
112
checkLookupObject(lookup, TestLookupObject.class, false);
113         checkLookupObject(lookup, TestLookupObjectTwo.class, false);
114         
115         lookup = MimeLookup.getMimeLookup("text/jsp");//NOI18N
116
checkLookupObject(lookup, TestLookupObject.class, true);
117         checkLookupObject(lookup, TestLookupObjectTwo.class, false);
118         
119         lookup = MimeLookup.getMimeLookup("text/html").childLookup("text/xml"); //NOI18N
120
checkLookupObject(lookup, TestLookupObject.class, true);
121         checkLookupObject(lookup, TestLookupObjectTwo.class, true);
122         
123         //simulate module installation, new file will be added
124
createFile("Editors/text/x-java/text/x-properties/testLookupTwo/" +
125                 "org-netbeans-modules-editor-mimelookup-impl-TestLookupObjectTwo.instance");
126
127         lookup = MimeLookup.getMimeLookup("text/x-java").childLookup("text/x-properties"); //NOI18N
128
checkLookupObject(lookup, TestLookupObject.class, false);
129         checkLookupObject(lookup, TestLookupObjectTwo.class, true);
130
131         createFile("Editors/text/x-java/text/x-properties/testLookup/" +
132                 "org-netbeans-modules-editor-mimelookup-impl-TestLookupObject.instance");
133         checkLookupObject(lookup, TestLookupObject.class, true);
134         checkLookupObject(lookup, TestLookupObjectTwo.class, true);
135
136         //uninstall ObjectTwo
137
TestUtilities.deleteFile(getWorkDir(),
138                 "Editors/text/x-java/text/x-properties/testLookupTwo/" +
139                 "org-netbeans-modules-editor-mimelookup-impl-TestLookupObjectTwo.instance");
140         checkLookupObject(lookup, TestLookupObject.class, true);
141         checkLookupObject(lookup, TestLookupObjectTwo.class, false);
142
143         //uninstall ObjectOne
144
TestUtilities.deleteFile(getWorkDir(),
145                 "Editors/text/x-java/text/x-properties/testLookup/" +
146                 "org-netbeans-modules-editor-mimelookup-impl-TestLookupObject.instance");
147         checkLookupObject(lookup, TestLookupObject.class, false);
148         checkLookupObject(lookup, TestLookupObjectTwo.class, false);
149         
150         //simulate module installation, new file will be added
151
createFile("Editors/text/x-java/text/x-properties/testLookupTwo/" +
152                 "org-netbeans-modules-editor-mimelookup-impl-TestLookupObjectTwo.instance");
153
154         lookup = MimeLookup.getMimeLookup("text/x-java").childLookup("text/x-properties"); //NOI18N
155
checkLookupObject(lookup, TestLookupObject.class, false);
156         checkLookupObject(lookup, TestLookupObjectTwo.class, true);
157
158         //delete all
159
TestUtilities.deleteFile(getWorkDir(),
160                 "Editors/text/jsp/testLookup/org-netbeans-modules-editor-mimelookup-impl-TestLookupObject.instance");
161         
162         TestUtilities.deleteFile(getWorkDir(),
163                 "Editors/text/x-java/text/xml/testLookupTwo/org-netbeans-modules-editor-mimelookup-impl-TestLookupObjectTwo.instance");
164         
165         TestUtilities.deleteFile(getWorkDir(),
166                 "Editors/text/html/text/xml/testLookup/org-netbeans-modules-editor-mimelookup-impl-TestLookupObject.instance");
167
168         TestUtilities.deleteFile(getWorkDir(),
169                 "Editors/text/html/text/xml/testLookupTwo/org-netbeans-modules-editor-mimelookup-impl-TestLookupObjectTwo.instance");
170         
171         lookup = MimeLookup.getMimeLookup("text/x-java").childLookup("text/xml"); //NOI18N
172
checkLookupObject(lookup, TestLookupObject.class, false);
173         checkLookupObject(lookup ,TestLookupObjectTwo.class, false);
174         
175         lookup = MimeLookup.getMimeLookup("text/jsp");//NOI18N
176
checkLookupObject(lookup, TestLookupObject.class, false);
177         checkLookupObject(lookup, TestLookupObjectTwo.class, false);
178         
179         lookup = MimeLookup.getMimeLookup("text/html").childLookup("text/xml"); //NOI18N
180
checkLookupObject(lookup, TestLookupObject.class, false);
181         checkLookupObject(lookup, TestLookupObjectTwo.class, false);
182
183         lookup = MimeLookup.getMimeLookup("text/x-java").childLookup("text/x-properties"); //NOI18N
184
checkLookupObject(lookup, TestLookupObject.class, false);
185         checkLookupObject(lookup, TestLookupObjectTwo.class, true);
186
187         //----------------------------------------------------------------------
188
//simulate module installation, new file will be added
189
lookup = MimeLookup.getMimeLookup("text/html").childLookup("text/xml"); //NOI18N
190
createFile("Editors/text/html/text/xml/testLookup/" +
191                 "org-netbeans-modules-editor-mimelookup-impl-TestLookupObject.instance");
192
193         checkLookupObject(lookup, TestLookupObject.class, true);
194         checkLookupObject(lookup, TestLookupObjectTwo.class, false);
195         
196         createFile("Editors/text/html/text/xml/testLookupTwo/" +
197                 "org-netbeans-modules-editor-mimelookup-impl-TestLookupObjectTwo.instance");
198         checkLookupObject(lookup, TestLookupObject.class, true);
199         checkLookupObject(lookup, TestLookupObjectTwo.class, true);
200         //----------------------------------------------------------------------
201

202         
203         //----------------------------------------------------------------------
204
// Register listener on a Result of lookup on unexisted object
205
resultChangedCount[0] = 0;
206         lookup = MimeLookup.getMimeLookup("text/dtd").childLookup("text/xml"); //NOI18N
207
Result result = lookup.lookup(new Template(TestLookupObject.class));
208         result.allInstances(); // remove this line if issue #60010 is fixed
209
LookupListener listener = new LookupListener(){
210             public void resultChanged(LookupEvent ev){
211                 resultChangedCount[0]++;
212             }
213         };
214         result.addLookupListener(listener);
215         
216         //simulate module installation, new file will be added
217
createFile("Editors/text/dtd/text/xml/testLookup/" + //NOI18N
218
"org-netbeans-modules-editor-mimelookup-impl-TestLookupObject.instance"); //NOI18N
219

220         checkResultChange(1);
221         result.removeLookupListener(listener);
222         resultChangedCount[0] = 0;
223         //----------------------------------------------------------------------
224

225         
226
227         
228         //----------------------------------------------------------------------
229
// result *NOT* firing on standard mime type testing
230
resultChangedCount[0] = 0;
231         lookup = MimeLookup.getMimeLookup("image/jpeg"); //NOI18N
232
// try to lookup TestLookupObjectTwo, while TestLookupObject will be installed.
233
// firing should not happen
234
result = lookup.lookup(new Template(TestLookupObjectTwo.class));
235         result.allInstances();
236         result.addLookupListener(listener);
237         checkResultChange(0);
238
239         //simulate module installation, new file will be added
240
createFile("Editors/image/jpeg/testLookup/" +
241                 "org-netbeans-modules-editor-mimelookup-impl-TestLookupObject.instance");
242         
243         checkResultChange(0);
244         checkLookupObject(lookup, TestLookupObjectTwo.class, false);
245         checkLookupObject(lookup, TestLookupObject.class, true);
246         result.removeLookupListener(listener);
247         resultChangedCount[0] = 0;
248         //----------------------------------------------------------------------
249

250         
251         //----------------------------------------------------------------------
252
//
253
// testing "compound" mime types like application/x-ant+dtd
254
// "Editors/application/dtd/text/x-java/java-lang-String.instance", //NOI18N
255
// "Editors/application/dtd/testLookup/org-netbeans-modules-editor-mimelookup-TestLookupObject.instance", //NOI18N
256
// "Editors/application/x-ant+dtd/java-lang-StringBuffer.instance", //NOI18N
257
// "Editors/application/x-ant+dtd/text/x-java/testLookupTwo/org-netbeans-modules-editor-mimelookup-TestLookupObjectTwo.instance", //NOI18N
258
lookup = MimeLookup.getMimeLookup("application/x-ant+dtd"); //NOI18N
259
checkLookupObject(lookup, TestLookupObject.class, true);
260         checkLookupObject(lookup, StringBuffer JavaDoc.class, true);
261         checkLookupObject(lookup, String JavaDoc.class, false);
262         checkLookupObject(lookup, TestLookupObjectTwo.class, false);
263         
264         lookup = MimeLookup.getMimeLookup("application/x-ant+dtd").childLookup("text/x-java"); //NOI18N
265
checkLookupObject(lookup, TestLookupObject.class, true); //it is inherited from parent
266
checkLookupObject(lookup, StringBuffer JavaDoc.class, true); //it is inherited from parent
267
checkLookupObject(lookup, String JavaDoc.class, true);
268         checkLookupObject(lookup, TestLookupObjectTwo.class, true);
269         //----------------------------------------------------------------------
270

271         
272         //----------------------------------------------------------------------
273
// Test lookup of "compound" mime types if the object is not installed yet
274
// "Editors/image/x-ant+dtd/text/x-java/testLookupTwo/org-netbeans-modules-editor-mimelookup-TestLookupObjectTwo.instance", //NOI18N
275
lookup = MimeLookup.getMimeLookup("image/x-ant+dtd").childLookup("text/x-java"); //NOI18N
276
checkLookupObject(lookup ,TestLookupObjectTwo.class, false);
277         createFile("Editors/image/x-ant+dtd/text/x-java/testLookupTwo/" +
278                 "org-netbeans-modules-editor-mimelookup-impl-TestLookupObjectTwo.instance");
279         checkLookupObject(lookup, TestLookupObjectTwo.class, true);
280         //----------------------------------------------------------------------
281

282
283         
284         //----------------------------------------------------------------------
285
// result firing on "compound" mime type testing
286
resultChangedCount[0] = 0;
287         lookup = MimeLookup.getMimeLookup("audio/x-ant+dtd").childLookup("text/x-java"); //NOI18N
288
result = lookup.lookup(new Template(TestLookupObjectTwo.class));
289         result.allInstances();
290         result.addLookupListener(listener);
291         checkResultChange(0);
292
293         //simulate module installation, new file will be added
294
createFile("Editors/audio/x-ant+dtd/text/x-java/testLookupTwo/" +
295                 "org-netbeans-modules-editor-mimelookup-impl-TestLookupObjectTwo.instance");
296         
297         checkResultChange(1);
298         checkLookupObject(lookup, TestLookupObjectTwo.class, true);
299         checkLookupObject(lookup, TestLookupObject.class, false);
300         result.removeLookupListener(listener);
301         resultChangedCount[0] = 0;
302         //----------------------------------------------------------------------
303

304          
305
306         //----------------------------------------------------------------------
307
// result *NOT* firing and firing on "compound" mime type testing where object is
308
// installed in inherited folder
309
resultChangedCount[0] = 0;
310         lookup = MimeLookup.getMimeLookup("audiox/mp3+dtd"); //NOI18N
311
result = lookup.lookup(new Template(TestLookupObject.class));
312         result.allInstances();
313         result.addLookupListener(listener);
314         checkResultChange(0);
315
316         //simulate module installation, new file will be added
317
createFile("Editors/audiox/dtd/testLookupTwo/" +
318                 "org-netbeans-modules-editor-mimelookup-impl-TestLookupObjectTwo.instance");
319         
320         checkResultChange(0);
321         checkLookupObject(lookup, TestLookupObjectTwo.class, true);
322         checkLookupObject(lookup, TestLookupObject.class, false);
323         
324         // now install TestLookupObject, firing should happen
325
//simulate module installation, new file will be added
326
createFile("Editors/audiox/dtd/testLookup/" +
327                 "org-netbeans-modules-editor-mimelookup-impl-TestLookupObject.instance");
328         
329         checkResultChange(1);
330         checkLookupObject(lookup, TestLookupObjectTwo.class, true);
331         checkLookupObject(lookup, TestLookupObject.class, true);
332         result.removeLookupListener(listener);
333         resultChangedCount[0] = 0;
334         //----------------------------------------------------------------------
335

336         //----------------------------------------------------------------------
337
// result *NOT* firing and firing on "compound" *SUB* mime type testing where object is
338
// installed in inherited folder
339
resultChangedCount[0] = 0;
340         lookup = MimeLookup.getMimeLookup("audioy/mp3+dtd").childLookup("audio/wav"); //NOI18N
341
result = lookup.lookup(new Template(TestLookupObject.class));
342         result.allInstances();
343         result.addLookupListener(listener);
344         checkResultChange(0);
345
346         //simulate module installation, new file will be added
347
createFile("Editors/audioy/dtd/audio/wav/testLookupTwo/" +
348                 "org-netbeans-modules-editor-mimelookup-impl-TestLookupObjectTwo.instance");
349         
350         checkResultChange(0);
351         checkLookupObject(lookup, TestLookupObjectTwo.class, true);
352         checkLookupObject(lookup, TestLookupObject.class, false);
353         
354         // now install TestLookupObject, firing should happen
355
//simulate module installation, new file will be added
356
createFile("Editors/audioy/dtd/audio/wav/testLookup/" +
357                 "org-netbeans-modules-editor-mimelookup-impl-TestLookupObject.instance");
358
359         checkResultChange(1);
360         checkLookupObject(lookup, TestLookupObjectTwo.class, true);
361         checkLookupObject(lookup, TestLookupObject.class, true);
362         result.removeLookupListener(listener);
363         resultChangedCount[0] = 0;
364         //----------------------------------------------------------------------
365

366         //----------------------------------------------------------------------
367
// result *NOT* firing and firing on "compound" *SUB* mime type testing where object is
368
// installed in inherited mime type folder
369
resultChangedCount[0] = 0;
370         lookup = MimeLookup.getMimeLookup("audioy/mp3+dtd").childLookup("audio/wav"); //NOI18N
371
result = lookup.lookup(new Template(IllegalStateException JavaDoc.class));
372         result.allInstances();
373         result.addLookupListener(listener);
374         checkResultChange(0);
375
376         //simulate module installation, new file will be added
377
createFile("Editors/audioy/dtd/" +
378                 "java-lang-InstantiationException.instance");
379         
380         checkResultChange(0);
381         checkLookupObject(lookup, IllegalStateException JavaDoc.class, false);
382         checkLookupObject(lookup, InstantiationException JavaDoc.class, true);
383         
384         // now install TestLookupObject, firing should happen
385
//simulate module installation, new file will be added
386
createFile("Editors/audioy/dtd/" +
387                 "java-lang-IllegalStateException.instance");
388
389         checkResultChange(1);
390         checkLookupObject(lookup, IllegalStateException JavaDoc.class, true);
391         checkLookupObject(lookup, InstantiationException JavaDoc.class, true);
392         result.removeLookupListener(listener);
393         resultChangedCount[0] = 0;
394         //----------------------------------------------------------------------
395

396         //----------------------------------------------------------------------
397
// result *NOT* firing and firing on mime type testing where object is
398
// installed in mime type folder
399
resultChangedCount[0] = 0;
400         lookup = MimeLookup.getMimeLookup("audioz/mp3"); //NOI18N
401
result = lookup.lookup(new Template(IllegalStateException JavaDoc.class));
402         result.allInstances();
403         result.addLookupListener(listener);
404         checkResultChange(0);
405
406         //simulate module installation, new file will be added
407
createFile("Editors/audioz/mp3/" +
408                 "java-lang-InstantiationException.instance");
409         
410         checkResultChange(0);
411         checkLookupObject(lookup, IllegalStateException JavaDoc.class, false);
412         checkLookupObject(lookup, InstantiationException JavaDoc.class, true);
413         
414         // now install TestLookupObject, firing should happen
415
//simulate module installation, new file will be added
416
createFile("Editors/audioz/mp3/" +
417                 "java-lang-IllegalStateException.instance");
418
419         checkResultChange(1);
420         checkLookupObject(lookup, IllegalStateException JavaDoc.class, true);
421         checkLookupObject(lookup, InstantiationException JavaDoc.class, true);
422         result.removeLookupListener(listener);
423         resultChangedCount[0] = 0;
424         //----------------------------------------------------------------------
425

426         
427     }
428
429     /**
430      * FolderLookup behaves recursively by default. It is not ideal as for MimeLookup,
431      * that should operate only on the mime-type-folder
432      * see issue #58991
433      * Testing if the MimeLookup is not recursive
434      */

435     public void testLookupFolderRecursivity(){
436         //StringBuffer.instance is declared
437
// in "Editors/text/xml/text/html/java-lang-StringBuffer.instance"
438
// it shouldn't be found in text/xml parent folder
439
MimeLookup lookup = MimeLookup.getMimeLookup("text/xml");
440         checkLookupObject(lookup, StringBuffer JavaDoc.class, false);
441     }
442
443     
444     /**
445      * Looking up the class that has NOT registered subfolder via Class2LayerFolder.
446      * It should be found appropriate mime-type specific folder
447      */

448     public void testNotRegisteredClassLookup() throws IOException JavaDoc {
449         MimeLookup lookup = MimeLookup.getMimeLookup("text/xml").childLookup("text/html"); //NOI18N
450
checkLookupObject(lookup, StringBuffer JavaDoc.class, true);
451         TestUtilities.deleteFile(getWorkDir(),
452                 "Editors/text/xml/text/html/java-lang-StringBuffer.instance");
453         checkLookupObject(lookup, StringBuffer JavaDoc.class, false);
454     }
455
456
457     /**
458      * Checking wheather the initialization of MimeLookup for appropriate
459      * mime type will not instantiate lookup object
460      */

461     public void testLazyLookupObjectInstantiation() throws IOException JavaDoc{
462         MimeLookup lookup = MimeLookup.getMimeLookup("text/xml"); //NOI18N
463
// lookup for some object in the mime lookup
464
checkLookupObject(lookup, StringBuffer JavaDoc.class, false);
465         // calling
466
// checkLookupObject(lookup, TestLookupObjectInstantiation.class, false);
467
// should fail
468
}
469     
470     /**
471      * Looking up the template that has registered subfolder via Class2LayerFolder
472      */

473     public void testRegisteredTemplatesLookup() throws IOException JavaDoc{
474         createFile("Editors/text/x-java/text/x-properties/testLookupTwo/" +
475                 "org-netbeans-modules-editor-mimelookup-impl-TestLookupObjectTwo.instance");
476
477         MimeLookup lookup = MimeLookup.getMimeLookup("text/x-java").childLookup("text/x-properties"); //NOI18N
478
checkLookupTemplate(lookup, TestLookupObject.class, 0);
479         checkLookupTemplate(lookup, TestLookupObjectTwo.class, 1);
480         
481         lookup = MimeLookup.getMimeLookup("text/xml").childLookup("text/jsp");//NOI18N
482
checkLookupTemplate(lookup, TestLookupObject.class, 1);
483         checkLookupTemplate(lookup, TestLookupObjectTwo.class, 0);
484
485         // testing issue #58941
486
TestUtilities.deleteFile(getWorkDir(),
487                 "Editors/text/xml/text/jsp/testLookup/org-netbeans-modules-editor-mimelookup-impl-TestLookupObject.instance");
488         TestUtilities.deleteFile(getWorkDir(),
489                 "Editors/text/jsp/testLookup/org-netbeans-modules-editor-mimelookup-impl-TestLookupObject.instance");
490         checkLookupTemplate(lookup, TestLookupObject.class, 0);
491         checkLookupTemplate(lookup, TestLookupObjectTwo.class, 0);
492     }
493
494     
495     private void checkLookupObject(final MimeLookup lookup, final Class JavaDoc clazz, final boolean shouldBePresent){
496         TestUtilities.waitMaxMilisForValue(WAIT_TIME, new TestUtilities.ValueResolver(){
497             public Object JavaDoc getValue(){
498                 Object JavaDoc obj = lookup.lookup(clazz);
499                 boolean bool = (shouldBePresent) ? obj != null : obj == null;
500                 return Boolean.valueOf(bool);
501             }
502         }, Boolean.TRUE);
503         Object JavaDoc obj = lookup.lookup(clazz);
504         if (shouldBePresent){
505             assertTrue("Object should be present in the lookup",obj!=null);
506         } else {
507             assertTrue("Object should NOT be present in the lookup",obj==null);
508         }
509     }
510     
511     private void checkLookupTemplate(final MimeLookup lookup, final Class JavaDoc clazz, final int instCount){
512         TestUtilities.waitMaxMilisForValue(WAIT_TIME, new TestUtilities.ValueResolver(){
513             public Object JavaDoc getValue(){
514                 Lookup.Result result = lookup.lookup(new Lookup.Template(clazz));
515                 boolean bool = result.allInstances().size() == instCount;
516                 return Boolean.valueOf(bool);
517             }
518         }, Boolean.TRUE);
519         Lookup.Result result = lookup.lookup(new Lookup.Template(clazz));
520         int size = result.allInstances().size();
521         boolean bool = (size == instCount);
522         assertTrue("Number of instances doesn't match. Found:"+size+". Should be presented:"+instCount+".", bool);
523     }
524
525 }
526
Popular Tags