2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.modules.editor.mimelookup.impl;
44
import java.io.IOException;
45
import org.netbeans.api.editor.mimelookup.MimeLookup;
46
import org.netbeans.api.editor.mimelookup.MimePath;
47
import org.netbeans.junit.NbTestCase;
48
import org.openide.util.Lookup;
49
import org.openide.util.Lookup.Result;
50
import org.openide.util.Lookup.Template;
51
import org.openide.util.LookupEvent;
52
import org.openide.util.LookupListener;
55
* Testing basic functionality of MimeLookup
57
* @author Martin Roskanin
59
public class MimeLookupTest extends NbTestCase {
61
private static final int WAIT_TIME = 5000;
62
private static final int WAIT_TIME_FIRING = 1500;
63
final int resultChangedCount[] = new int[1];
65
public MimeLookupTest(String testName) {
69
protected @Override void setUp() throws Exception {
71
String fsstruct [] = new String [] {
72
"Editors/text/xml/text/html/java-lang-StringBuffer.instance", //NOI18N
73
"Editors/text/x-java/text/xml/testLookupTwo/org-netbeans-modules-editor-mimelookup-impl-TestLookupObjectTwo.instance", //NOI18N
74
"Editors/text/jsp/testLookup/org-netbeans-modules-editor-mimelookup-impl-TestLookupObject.instance", //NOI18N
75
"Editors/text/html/text/xml/testLookup/org-netbeans-modules-editor-mimelookup-impl-TestLookupObject.instance", //NOI18N
76
"Editors/text/html/text/xml/testLookupTwo/org-netbeans-modules-editor-mimelookup-impl-TestLookupObjectTwo.instance", //NOI18N
77
"Editors/text/jsp/text/html/testLookup/org-netbeans-modules-editor-mimelookup-impl-TestLookupObject.instance", //NOI18N
78
"Editors/text/xml/org-netbeans-modules-editor-mimelookup-impl-TestLookupObjectInstantiation.instance", //NOI18N
79
// testing "compound mime types like application/x-ant+xml"
80
"Editors/application/dtd/testLookup/org-netbeans-modules-editor-mimelookup-impl-TestLookupObject.instance", //NOI18N
81
"Editors/application/x-ant+dtd/java-lang-StringBuffer.instance", //NOI18N
82
"Editors/text/x-java/application/x-ant+dtd/testLookupTwo/org-netbeans-modules-editor-mimelookup-impl-TestLookupObjectTwo.instance", //NOI18N
85
EditorTestLookup.setLookup(fsstruct, getWorkDir(), new Object[] {},
86
getClass().getClassLoader());
89
private void createFile(String file) throws IOException{
90
TestUtilities.createFile(getWorkDir(), file); //NOI18N
93
private void checkResultChange(final int count) throws IOException{
94
// wait for firing event
95
TestUtilities.waitMaxMilisForValue(WAIT_TIME_FIRING, new TestUtilities.ValueResolver(){
96
public Object getValue(){
100
assertTrue(("resultChangedCount is:"+resultChangedCount[0]+" instead of "+count), resultChangedCount[0] == count);
104
* Looking up the class that has registered subfolder via Class2LayerFolder
106
public void testRegisteredClassLookup() throws IOException{
107
MimePath mp = MimePath.parse("text/x-java/text/xml");
108
Lookup lookup = MimeLookup.getLookup(mp);
109
checkLookupObject(lookup, TestLookupObject.class, false);
110
checkLookupObject(lookup ,TestLookupObjectTwo.class, true);
112
lookup = MimeLookup.getLookup("text/jsp");//NOI18N
113
checkLookupObject(lookup, TestLookupObject.class, true);
114
checkLookupObject(lookup, TestLookupObjectTwo.class, false);
116
mp = MimePath.parse("text/html/text/xml");
117
lookup = MimeLookup.getLookup(mp);
118
checkLookupObject(lookup, TestLookupObject.class, true);
119
checkLookupObject(lookup, TestLookupObjectTwo.class, true);
121
//test inheritance from underlaying mime types
122
mp = MimePath.parse("text/xml/text/jsp/text/html"); //NOI18N
123
lookup = MimeLookup.getLookup(mp);
124
checkLookupObject(lookup, TestLookupObject.class, true);
125
lookup = MimeLookup.getLookup("text/html");
126
checkLookupObject(lookup, TestLookupObject.class, false);
127
mp = MimePath.parse("text/jsp/text/html");
128
lookup = MimeLookup.getLookup(mp);
129
checkLookupObject(lookup, TestLookupObject.class, true);
131
//simulating module uninstallation and removal of mime lookup file from xml layer
132
TestUtilities.deleteFile(getWorkDir(), "Editors/text/x-java/text/xml/testLookupTwo/org-netbeans-modules-editor-mimelookup-impl-TestLookupObjectTwo.instance");
133
mp = MimePath.parse("text/x-java/text/xml"); //NOI18N
134
lookup = MimeLookup.getLookup(mp);
135
checkLookupObject(lookup, TestLookupObject.class, false);
136
checkLookupObject(lookup, TestLookupObjectTwo.class, false);
138
lookup = MimeLookup.getLookup("text/jsp");//NOI18N
139
checkLookupObject(lookup, TestLookupObject.class, true);
140
checkLookupObject(lookup, TestLookupObjectTwo.class, false);
142
mp = MimePath.parse("text/html/text/xml"); //NOI18N
143
lookup = MimeLookup.getLookup(mp);
144
checkLookupObject(lookup, TestLookupObject.class, true);
145
checkLookupObject(lookup, TestLookupObjectTwo.class, true);
147
//simulate module installation, new file will be added
148
createFile("Editors/text/x-java/text/x-properties/testLookupTwo/" +
149
"org-netbeans-modules-editor-mimelookup-impl-TestLookupObjectTwo.instance");
151
mp = MimePath.get(MimePath.get("text/x-java"), "text/x-properties"); //NOI18N
152
lookup = MimeLookup.getLookup(mp);
153
checkLookupObject(lookup, TestLookupObject.class, false);
154
checkLookupObject(lookup, TestLookupObjectTwo.class, true);
156
createFile("Editors/text/x-java/text/x-properties/testLookup/" +
157
"org-netbeans-modules-editor-mimelookup-impl-TestLookupObject.instance");
158
checkLookupObject(lookup, TestLookupObject.class, true);
159
checkLookupObject(lookup, TestLookupObjectTwo.class, true);
161
//uninstall ObjectTwo
162
TestUtilities.deleteFile(getWorkDir(),
163
"Editors/text/x-java/text/x-properties/testLookupTwo/" +
164
"org-netbeans-modules-editor-mimelookup-impl-TestLookupObjectTwo.instance");
165
checkLookupObject(lookup, TestLookupObject.class, true);
166
checkLookupObject(lookup, TestLookupObjectTwo.class, false);
168
//uninstall ObjectOne
169
TestUtilities.deleteFile(getWorkDir(),
170
"Editors/text/x-java/text/x-properties/testLookup/" +
171
"org-netbeans-modules-editor-mimelookup-impl-TestLookupObject.instance");
172
checkLookupObject(lookup, TestLookupObject.class, false);
173
checkLookupObject(lookup, TestLookupObjectTwo.class, false);
175
//simulate module installation, new file will be added
176
createFile("Editors/text/x-java/text/x-properties/testLookupTwo/" +
177
"org-netbeans-modules-editor-mimelookup-impl-TestLookupObjectTwo.instance");
179
mp = MimePath.parse("text/x-java/text/x-properties"); //NOI18N
180
lookup = MimeLookup.getLookup(mp);
181
checkLookupObject(lookup, TestLookupObject.class, false);
182
checkLookupObject(lookup, TestLookupObjectTwo.class, true);
185
TestUtilities.deleteFile(getWorkDir(),
186
"Editors/text/jsp/testLookup/org-netbeans-modules-editor-mimelookup-impl-TestLookupObject.instance");
188
TestUtilities.deleteFile(getWorkDir(),
189
"Editors/text/x-java/text/xml/testLookupTwo/org-netbeans-modules-editor-mimelookup-impl-TestLookupObjectTwo.instance");
191
TestUtilities.deleteFile(getWorkDir(),
192
"Editors/text/html/text/xml/testLookup/org-netbeans-modules-editor-mimelookup-impl-TestLookupObject.instance");
194
TestUtilities.deleteFile(getWorkDir(),
195
"Editors/text/html/text/xml/testLookupTwo/org-netbeans-modules-editor-mimelookup-impl-TestLookupObjectTwo.instance");
197
mp = MimePath.parse("text/x-java/text/xml"); //NOI18N
198
lookup = MimeLookup.getLookup(mp);
199
checkLookupObject(lookup, TestLookupObject.class, false);
200
checkLookupObject(lookup ,TestLookupObjectTwo.class, false);
202
lookup = MimeLookup.getLookup("text/jsp");//NOI18N
203
checkLookupObject(lookup, TestLookupObject.class, false);
204
checkLookupObject(lookup, TestLookupObjectTwo.class, false);
206
mp = MimePath.get(MimePath.get("text/html"), "text/xml"); //NOI18N
207
lookup = MimeLookup.getLookup(mp);
209
checkLookupObject(lookup, TestLookupObject.class, false);
210
checkLookupObject(lookup, TestLookupObjectTwo.class, false);
212
mp = MimePath.parse("text/x-java/text/x-properties"); //NOI18N
213
lookup = MimeLookup.getLookup(mp);
215
checkLookupObject(lookup, TestLookupObject.class, false);
216
checkLookupObject(lookup, TestLookupObjectTwo.class, true);
218
//----------------------------------------------------------------------
219
//simulate module installation, new file will be added
220
mp = MimePath.parse("text/html/text/xml"); //NOI18N
221
lookup = MimeLookup.getLookup(mp);
222
createFile("Editors/text/html/text/xml/testLookup/" +
223
"org-netbeans-modules-editor-mimelookup-impl-TestLookupObject.instance");
225
checkLookupObject(lookup, TestLookupObject.class, true);
226
checkLookupObject(lookup, TestLookupObjectTwo.class, false);
228
createFile("Editors/text/html/text/xml/testLookupTwo/" +
229
"org-netbeans-modules-editor-mimelookup-impl-TestLookupObjectTwo.instance");
230
checkLookupObject(lookup, TestLookupObject.class, true);
231
checkLookupObject(lookup, TestLookupObjectTwo.class, true);
232
//----------------------------------------------------------------------
235
//----------------------------------------------------------------------
236
// Register listener on a Result of lookup on unexisted object
237
resultChangedCount[0] = 0;
238
mp = MimePath.parse("text/dtd/text/xml"); //NOI18N
239
lookup = MimeLookup.getLookup(mp);
240
Result result = lookup.lookup(new Template(TestLookupObject.class));
241
result.allInstances(); // remove this line if issue #60010 is fixed
242
LookupListener listener = new LookupListener(){
243
public void resultChanged(LookupEvent ev){
244
resultChangedCount[0]++;
247
result.addLookupListener(listener);
249
//simulate module installation, new file will be added
250
createFile("Editors/text/dtd/text/xml/testLookup/" + //NOI18N
251
"org-netbeans-modules-editor-mimelookup-impl-TestLookupObject.instance"); //NOI18N
253
checkResultChange(1);
254
result.removeLookupListener(listener);
255
resultChangedCount[0] = 0;
256
//----------------------------------------------------------------------
261
//----------------------------------------------------------------------
262
// result *NOT* firing on standard mime type testing
263
resultChangedCount[0] = 0;
264
lookup = MimeLookup.getLookup("image/jpeg"); //NOI18N
265
// try to lookup TestLookupObjectTwo, while TestLookupObject will be installed.
266
// firing should not happen
267
result = lookup.lookup(new Template(TestLookupObjectTwo.class));
268
result.allInstances();
269
result.addLookupListener(listener);
270
checkResultChange(0);
272
//simulate module installation, new file will be added
273
createFile("Editors/image/jpeg/testLookup/" +
274
"org-netbeans-modules-editor-mimelookup-impl-TestLookupObject.instance");
276
checkResultChange(0);
277
checkLookupObject(lookup, TestLookupObjectTwo.class, false);
278
checkLookupObject(lookup, TestLookupObject.class, true);
279
result.removeLookupListener(listener);
280
resultChangedCount[0] = 0;
281
//----------------------------------------------------------------------
284
//----------------------------------------------------------------------
286
// testing "compound" mime types like application/x-ant+dtd
287
// "Editors/application/dtd/text/x-java/java-lang-String.instance", //NOI18N
288
// "Editors/application/dtd/testLookup/org-netbeans-modules-editor-mimelookup-TestLookupObject.instance", //NOI18N
289
// "Editors/application/x-ant+dtd/java-lang-StringBuffer.instance", //NOI18N
290
// "Editors/application/x-ant+dtd/text/x-java/testLookupTwo/org-netbeans-modules-editor-mimelookup-TestLookupObjectTwo.instance", //NOI18N
291
lookup = MimeLookup.getLookup("application/x-ant+dtd"); //NOI18N
292
checkLookupObject(lookup, TestLookupObject.class, true);
293
checkLookupObject(lookup, StringBuffer.class, true);
294
checkLookupObject(lookup, String.class, false);
295
checkLookupObject(lookup, TestLookupObjectTwo.class, false);
297
mp = MimePath.parse("text/x-java/application/x-ant+dtd"); //NOI18N
298
lookup = MimeLookup.getLookup(mp);
299
checkLookupObject(lookup, TestLookupObject.class, true); //it is inherited from parent
300
checkLookupObject(lookup, StringBuffer.class, true); //it is inherited from parent
301
checkLookupObject(lookup, TestLookupObjectTwo.class, true);
302
//----------------------------------------------------------------------
305
//----------------------------------------------------------------------
306
// Test lookup of "compound" mime types if the object is not installed yet
307
// "Editors/image/x-ant+dtd/text/x-java/testLookupTwo/org-netbeans-modules-editor-mimelookup-TestLookupObjectTwo.instance", //NOI18N
308
mp = MimePath.parse("image/x-ant+dtd/text/x-java"); //NOI18N
309
lookup = MimeLookup.getLookup(mp);
310
checkLookupObject(lookup ,TestLookupObjectTwo.class, false);
311
createFile("Editors/image/x-ant+dtd/text/x-java/testLookupTwo/" +
312
"org-netbeans-modules-editor-mimelookup-impl-TestLookupObjectTwo.instance");
313
checkLookupObject(lookup, TestLookupObjectTwo.class, true);
314
//----------------------------------------------------------------------
318
//----------------------------------------------------------------------
319
// result firing on "compound" mime type testing
320
resultChangedCount[0] = 0;
321
mp = MimePath.parse("audio/x-ant+dtd/text/x-java"); //NOI18N
322
lookup = MimeLookup.getLookup(mp);
323
result = lookup.lookup(new Template(TestLookupObjectTwo.class));
324
result.allInstances();
325
result.addLookupListener(listener);
326
checkResultChange(0);
328
//simulate module installation, new file will be added
329
createFile("Editors/audio/x-ant+dtd/text/x-java/testLookupTwo/" +
330
"org-netbeans-modules-editor-mimelookup-impl-TestLookupObjectTwo.instance");
332
checkResultChange(1);
333
checkLookupObject(lookup, TestLookupObjectTwo.class, true);
334
checkLookupObject(lookup, TestLookupObject.class, false);
335
result.removeLookupListener(listener);
336
resultChangedCount[0] = 0;
337
//----------------------------------------------------------------------
341
//----------------------------------------------------------------------
342
// result *NOT* firing and firing on "compound" mime type testing where object is
343
// installed in inherited folder
344
resultChangedCount[0] = 0;
345
lookup = MimeLookup.getLookup("video/mp3+dtd"); //NOI18N
346
result = lookup.lookup(new Template(TestLookupObject.class));
347
result.allInstances();
348
result.addLookupListener(listener);
349
checkResultChange(0);
351
//simulate module installation, new file will be added
352
createFile("Editors/video/dtd/testLookupTwo/" +
353
"org-netbeans-modules-editor-mimelookup-impl-TestLookupObjectTwo.instance");
355
checkResultChange(0);
356
checkLookupObject(lookup, TestLookupObjectTwo.class, true);
357
checkLookupObject(lookup, TestLookupObject.class, false);
359
// now install TestLookupObject, firing should happen
360
//simulate module installation, new file will be added
361
createFile("Editors/video/dtd/testLookup/" +
362
"org-netbeans-modules-editor-mimelookup-impl-TestLookupObject.instance");
364
checkResultChange(1);
365
checkLookupObject(lookup, TestLookupObjectTwo.class, true);
366
checkLookupObject(lookup, TestLookupObject.class, true);
367
result.removeLookupListener(listener);
368
resultChangedCount[0] = 0;
369
//----------------------------------------------------------------------
371
//----------------------------------------------------------------------
372
// result *NOT* firing and firing on "compound" *SUB* mime type testing where object is
373
// installed in inherited folder
374
resultChangedCount[0] = 0;
375
mp = MimePath.parse("message/mp3+dtd/audio/wav"); //NOI18N
376
lookup = MimeLookup.getLookup(mp);
377
result = lookup.lookup(new Template(TestLookupObject.class));
378
result.allInstances();
379
result.addLookupListener(listener);
380
checkResultChange(0);
382
//simulate module installation, new file will be added
383
createFile("Editors/message/dtd/audio/wav/testLookupTwo/" +
384
"org-netbeans-modules-editor-mimelookup-impl-TestLookupObjectTwo.instance");
386
checkResultChange(0);
387
checkLookupObject(lookup, TestLookupObjectTwo.class, true);
388
checkLookupObject(lookup, TestLookupObject.class, false);
390
// now install TestLookupObject, firing should happen
391
//simulate module installation, new file will be added
392
createFile("Editors/message/dtd/audio/wav/testLookup/" +
393
"org-netbeans-modules-editor-mimelookup-impl-TestLookupObject.instance");
395
checkResultChange(1);
396
checkLookupObject(lookup, TestLookupObjectTwo.class, true);
397
checkLookupObject(lookup, TestLookupObject.class, true);
398
result.removeLookupListener(listener);
399
resultChangedCount[0] = 0;
400
//----------------------------------------------------------------------
402
//----------------------------------------------------------------------
403
// result *NOT* firing and firing on "compound" *SUB* mime type testing where object is
404
// installed in inherited mime type folder
405
resultChangedCount[0] = 0;
406
mp = MimePath.get(MimePath.get("message/mp3+dtd"), "audio/wav"); //NOI18N
407
lookup = MimeLookup.getLookup(mp);
408
result = lookup.lookup(new Template(IllegalStateException.class));
409
result.allInstances();
410
result.addLookupListener(listener);
411
checkResultChange(0);
413
//simulate module installation, new file will be added
414
createFile("Editors/message/dtd/audio/wav/" +
415
"java-lang-InstantiationException.instance");
417
checkResultChange(0);
418
checkLookupObject(lookup, IllegalStateException.class, false);
419
checkLookupObject(lookup, InstantiationException.class, true);
421
// now install TestLookupObject, firing should happen
422
//simulate module installation, new file will be added
423
createFile("Editors/message/dtd/audio/wav/" +
424
"java-lang-IllegalStateException.instance");
426
checkResultChange(1);
427
checkLookupObject(lookup, IllegalStateException.class, true);
428
checkLookupObject(lookup, InstantiationException.class, true);
429
result.removeLookupListener(listener);
430
resultChangedCount[0] = 0;
431
//----------------------------------------------------------------------
433
//----------------------------------------------------------------------
434
// result *NOT* firing and firing on mime type testing where object is
435
// installed in mime type folder
436
resultChangedCount[0] = 0;
437
lookup = MimeLookup.getLookup("model/mp3"); //NOI18N
438
result = lookup.lookup(new Template(IllegalStateException.class));
439
result.allInstances();
440
result.addLookupListener(listener);
441
checkResultChange(0);
443
//simulate module installation, new file will be added
444
createFile("Editors/model/mp3/" +
445
"java-lang-InstantiationException.instance");
447
checkResultChange(0);
448
checkLookupObject(lookup, IllegalStateException.class, false);
449
checkLookupObject(lookup, InstantiationException.class, true);
451
// now install TestLookupObject, firing should happen
452
//simulate module installation, new file will be added
453
createFile("Editors/model/mp3/" +
454
"java-lang-IllegalStateException.instance");
456
checkResultChange(1);
457
checkLookupObject(lookup, IllegalStateException.class, true);
458
checkLookupObject(lookup, InstantiationException.class, true);
459
result.removeLookupListener(listener);
460
resultChangedCount[0] = 0;
461
//----------------------------------------------------------------------
467
* FolderLookup behaves recursively by default. It is not ideal as for MimeLookup,
468
* that should operate only on the mime-type-folder
470
* Testing if the MimeLookup is not recursive
472
public void testLookupFolderRecursivity(){
473
//StringBuffer.instance is declared
474
// in "Editors/text/xml/text/html/java-lang-StringBuffer.instance"
475
// it shouldn't be found in text/xml parent folder
476
Lookup lookup = MimeLookup.getLookup("text/xml");
477
checkLookupObject(lookup, StringBuffer.class, false);
482
* Looking up the class that has NOT registered subfolder via Class2LayerFolder.
483
* It should be found appropriate mime-type specific folder
485
public void testNotRegisteredClassLookup() throws IOException {
486
MimePath mp = MimePath.get(MimePath.get("text/xml"), "text/html"); //NOI18N
487
Lookup lookup = MimeLookup.getLookup(mp);
488
checkLookupObject(lookup, StringBuffer.class, true);
489
TestUtilities.deleteFile(getWorkDir(),
490
"Editors/text/xml/text/html/java-lang-StringBuffer.instance");
491
checkLookupObject(lookup, StringBuffer.class, false);
496
* Checking wheather the initialization of MimeLookup for appropriate
497
* mime type will not instantiate lookup object
499
public void testLazyLookupObjectInstantiation() throws IOException{
500
Lookup lookup = MimeLookup.getLookup("text/xml"); //NOI18N
501
// lookup for some object in the mime lookup
502
checkLookupObject(lookup, StringBuffer.class, false);
504
// checkLookupObject(lookup, TestLookupObjectInstantiation.class, false);
509
* Lookuping the template that has registered subfolder via Class2LayerFolder
511
public void testRegisteredTemplatesLookup() throws IOException{
512
createFile("Editors/text/x-java/text/x-properties/testLookupTwo/" +
513
"org-netbeans-modules-editor-mimelookup-impl-TestLookupObjectTwo.instance");
515
MimePath mp = MimePath.parse("text/x-java/text/x-properties"); //NOI18N
516
Lookup lookup = MimeLookup.getLookup(mp);
517
checkLookupTemplate(lookup, TestLookupObject.class, 0);
518
checkLookupTemplate(lookup, TestLookupObjectTwo.class, 1);
520
mp = MimePath.parse("text/xml/text/jsp"); //NOI18N
521
lookup = MimeLookup.getLookup(mp);
522
checkLookupTemplate(lookup, TestLookupObject.class, 1);
523
checkLookupTemplate(lookup, TestLookupObjectTwo.class, 0);
525
// testing issue #58941
526
TestUtilities.deleteFile(getWorkDir(),
527
"Editors/text/xml/text/jsp/testLookup/org-netbeans-modules-editor-mimelookup-impl-TestLookupObject.instance");
528
TestUtilities.deleteFile(getWorkDir(),
529
"Editors/text/jsp/testLookup/org-netbeans-modules-editor-mimelookup-impl-TestLookupObject.instance");
530
checkLookupTemplate(lookup, TestLookupObject.class, 0);
531
checkLookupTemplate(lookup, TestLookupObjectTwo.class, 0);
535
private void checkLookupObject(final Lookup lookup, final Class clazz, final boolean shouldBePresent){
536
TestUtilities.waitMaxMilisForValue(WAIT_TIME, new TestUtilities.ValueResolver(){
537
public Object getValue(){
538
Object obj = lookup.lookup(clazz);
539
boolean bool = (shouldBePresent) ? obj != null : obj == null;
540
return Boolean.valueOf(bool);
543
Object obj = lookup.lookup(clazz);
544
if (shouldBePresent){
545
assertTrue("Object should be present in the lookup",obj!=null);
547
assertTrue("Object should NOT be present in the lookup",obj==null);
551
private void checkLookupTemplate(final Lookup lookup, final Class clazz, final int instCount){
552
TestUtilities.waitMaxMilisForValue(WAIT_TIME, new TestUtilities.ValueResolver(){
553
public Object getValue(){
554
Lookup.Result result = lookup.lookup(new Lookup.Template(clazz));
555
boolean bool = result.allInstances().size() == instCount;
556
return Boolean.valueOf(bool);
559
Lookup.Result result = lookup.lookup(new Lookup.Template(clazz));
560
int size = result.allInstances().size();
561
boolean bool = (size == instCount);
562
assertTrue("Number of instances doesn't match. Found:"+size+". Should be presented:"+instCount+".", bool);