Source Code Cross Referenced for QueryMBeansObjectNameOnlyTestCase.java in  » EJB-Server-JBoss-4.2.1 » jmx » test » compliance » query » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » EJB Server JBoss 4.2.1 » jmx » test.compliance.query 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JBoss, Home of Professional Open Source.
003:         * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004:         * as indicated by the @author tags. See the copyright.txt file in the
005:         * distribution for a full listing of individual contributors.
006:         *
007:         * This is free software; you can redistribute it and/or modify it
008:         * under the terms of the GNU Lesser General Public License as
009:         * published by the Free Software Foundation; either version 2.1 of
010:         * the License, or (at your option) any later version.
011:         *
012:         * This software is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this software; if not, write to the Free
019:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021:         */
022:        package test.compliance.query;
023:
024:        import junit.framework.TestCase;
025:
026:        import test.compliance.query.support.Trivial;
027:
028:        import java.util.Iterator;
029:        import java.util.Set;
030:        import java.util.HashSet;
031:
032:        import javax.management.MBeanServer;
033:        import javax.management.MBeanServerFactory;
034:        import javax.management.ObjectInstance;
035:        import javax.management.ObjectName;
036:
037:        /**
038:         * Object Name Query tests.<p>
039:         *
040:         * TODO: More tests, more systematic?
041:         *
042:         * @author  <a href="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>.
043:         */
044:        public class QueryMBeansObjectNameOnlyTestCase extends TestCase {
045:            // Attributes ----------------------------------------------------------------
046:
047:            /**
048:             * The number of objects registered in a server
049:             */
050:            int implSize;
051:
052:            // Constructor ---------------------------------------------------------------
053:
054:            /**
055:             * Construct the test
056:             */
057:            public QueryMBeansObjectNameOnlyTestCase(String s) {
058:                super (s);
059:
060:                // Determine the number of objects in the implementation
061:                MBeanServer server = MBeanServerFactory.createMBeanServer();
062:                implSize = server.getMBeanCount().intValue();
063:                MBeanServerFactory.releaseMBeanServer(server);
064:            }
065:
066:            // Tests ---------------------------------------------------------------------
067:
068:            /**
069:             * Test single bean found.
070:             */
071:            public void testExactFound() {
072:                MBeanServer server = null;
073:                HashSet instances = new HashSet();
074:                Set resultMBeans = null;
075:                Set resultNames = null;
076:                try {
077:                    server = MBeanServerFactory
078:                            .createMBeanServer("QueryMBeans");
079:                    instances.add(server.registerMBean(new Trivial(),
080:                            new ObjectName("Domain1:type=instance1")));
081:                    server.registerMBean(new Trivial(), new ObjectName(
082:                            "Domain1:type=instance2"));
083:                    server.registerMBean(new Trivial(), new ObjectName(
084:                            "Domain2:type=instance1"));
085:                    server.registerMBean(new Trivial(), new ObjectName(
086:                            "Domain3:type=instance1"));
087:                    resultMBeans = server.queryMBeans(new ObjectName(
088:                            "Domain1:type=instance1"), null);
089:                    resultNames = server.queryNames(new ObjectName(
090:                            "Domain1:type=instance1"), null);
091:                } catch (Exception e) {
092:                    fail(e.toString());
093:                }
094:
095:                checkit(resultMBeans, resultNames, instances, 0);
096:
097:                if (server != null)
098:                    MBeanServerFactory.releaseMBeanServer(server);
099:            }
100:
101:            /**
102:             * Test single bean not found.
103:             */
104:            public void testExactNotFound() {
105:                MBeanServer server = null;
106:                HashSet instances = new HashSet();
107:                Set resultMBeans = null;
108:                Set resultNames = null;
109:                try {
110:                    server = MBeanServerFactory
111:                            .createMBeanServer("QueryMBeans");
112:                    server.registerMBean(new Trivial(), new ObjectName(
113:                            "Domain1:type=instance1"));
114:                    server.registerMBean(new Trivial(), new ObjectName(
115:                            "Domain1:type=instance2"));
116:                    server.registerMBean(new Trivial(), new ObjectName(
117:                            "Domain2:type=instance1"));
118:                    server.registerMBean(new Trivial(), new ObjectName(
119:                            "Domain3:type=instance1"));
120:                    resultMBeans = server.queryMBeans(new ObjectName(
121:                            "Domain2:type=instance2"), null);
122:                    resultNames = server.queryNames(new ObjectName(
123:                            "Domain2:type=instance2"), null);
124:                } catch (Exception e) {
125:                    fail(e.toString());
126:                }
127:
128:                checkit(resultMBeans, resultNames, instances, 0);
129:
130:                if (server != null)
131:                    MBeanServerFactory.releaseMBeanServer(server);
132:            }
133:
134:            /**
135:             * Test Get All.
136:             */
137:            public void testGetAllMBeans() {
138:                MBeanServer server = null;
139:                HashSet instances = new HashSet();
140:                Set resultMBeans = null;
141:                Set resultNames = null;
142:                try {
143:                    server = MBeanServerFactory
144:                            .createMBeanServer("QueryMBeans");
145:                    instances.add(server.registerMBean(new Trivial(),
146:                            new ObjectName("Domain1:type=instance1")));
147:                    instances.add(server.registerMBean(new Trivial(),
148:                            new ObjectName("Domain1:type=instance2")));
149:                    instances.add(server.registerMBean(new Trivial(),
150:                            new ObjectName("Domain2:type=instance1")));
151:                    instances.add(server.registerMBean(new Trivial(),
152:                            new ObjectName("Domain3:type=instance1")));
153:                    resultMBeans = server.queryMBeans(new ObjectName("*:*"),
154:                            null);
155:                    resultNames = server
156:                            .queryNames(new ObjectName("*:*"), null);
157:                } catch (Exception e) {
158:                    fail(e.toString());
159:                }
160:
161:                checkit(resultMBeans, resultNames, instances, implSize);
162:
163:                if (server != null)
164:                    MBeanServerFactory.releaseMBeanServer(server);
165:            }
166:
167:            /**
168:             * Test Get All.
169:             */
170:            public void testGetAllMBeans2() {
171:                MBeanServer server = null;
172:                HashSet instances = new HashSet();
173:                Set resultMBeans = null;
174:                Set resultNames = null;
175:                try {
176:                    server = MBeanServerFactory
177:                            .createMBeanServer("QueryMBeans");
178:                    instances.add(server.registerMBean(new Trivial(),
179:                            new ObjectName("Domain1:type=instance1")));
180:                    instances.add(server.registerMBean(new Trivial(),
181:                            new ObjectName("Domain1:type=instance2")));
182:                    instances.add(server.registerMBean(new Trivial(),
183:                            new ObjectName("Domain2:type=instance1")));
184:                    instances.add(server.registerMBean(new Trivial(),
185:                            new ObjectName("Domain3:type=instance1")));
186:                    resultMBeans = server.queryMBeans(new ObjectName(""), null);
187:                    resultNames = server.queryNames(new ObjectName(""), null);
188:                } catch (Exception e) {
189:                    fail(e.toString());
190:                }
191:
192:                checkit(resultMBeans, resultNames, instances, implSize);
193:
194:                if (server != null)
195:                    MBeanServerFactory.releaseMBeanServer(server);
196:            }
197:
198:            /**
199:             * Test Get All.
200:             */
201:            public void testGetAllMBeans3() {
202:                MBeanServer server = null;
203:                HashSet instances = new HashSet();
204:                Set resultMBeans = null;
205:                Set resultNames = null;
206:                try {
207:                    server = MBeanServerFactory
208:                            .createMBeanServer("QueryMBeans");
209:                    instances.add(server.registerMBean(new Trivial(),
210:                            new ObjectName("Domain1:type=instance1")));
211:                    instances.add(server.registerMBean(new Trivial(),
212:                            new ObjectName("Domain1:type=instance2")));
213:                    instances.add(server.registerMBean(new Trivial(),
214:                            new ObjectName("Domain2:type=instance1")));
215:                    instances.add(server.registerMBean(new Trivial(),
216:                            new ObjectName("Domain3:type=instance1")));
217:                    resultMBeans = server.queryMBeans(null, null);
218:                    resultNames = server.queryNames(null, null);
219:                } catch (Exception e) {
220:                    fail(e.toString());
221:                }
222:
223:                checkit(resultMBeans, resultNames, instances, implSize);
224:
225:                if (server != null)
226:                    MBeanServerFactory.releaseMBeanServer(server);
227:            }
228:
229:            /**
230:             * Test one domain.
231:             */
232:            public void testGetOneDomain() {
233:                MBeanServer server = null;
234:                HashSet instances = new HashSet();
235:                Set resultMBeans = null;
236:                Set resultNames = null;
237:                try {
238:                    server = MBeanServerFactory
239:                            .createMBeanServer("QueryMBeans");
240:                    instances.add(server.registerMBean(new Trivial(),
241:                            new ObjectName("Domain1:type=instance1")));
242:                    instances.add(server.registerMBean(new Trivial(),
243:                            new ObjectName("Domain1:type=instance2")));
244:                    server.registerMBean(new Trivial(), new ObjectName(
245:                            "Domain2:type=instance1"));
246:                    server.registerMBean(new Trivial(), new ObjectName(
247:                            "Domain3:type=instance1"));
248:                    resultMBeans = server.queryMBeans(new ObjectName(
249:                            "Domain1:*"), null);
250:                    resultNames = server.queryNames(
251:                            new ObjectName("Domain1:*"), null);
252:                } catch (Exception e) {
253:                    fail(e.toString());
254:                }
255:
256:                checkit(resultMBeans, resultNames, instances, 0);
257:
258:                if (server != null)
259:                    MBeanServerFactory.releaseMBeanServer(server);
260:            }
261:
262:            /**
263:             * Test default domain.
264:             */
265:            public void testGetDefaultDomain() {
266:                MBeanServer server = null;
267:                HashSet instances = new HashSet();
268:                Set resultMBeans = null;
269:                Set resultNames = null;
270:                try {
271:                    server = MBeanServerFactory.createMBeanServer("Domain1");
272:                    instances.add(server.registerMBean(new Trivial(),
273:                            new ObjectName("Domain1:type=instance1")));
274:                    instances.add(server.registerMBean(new Trivial(),
275:                            new ObjectName("Domain1:type=instance2")));
276:                    server.registerMBean(new Trivial(), new ObjectName(
277:                            "Domain2:type=instance1"));
278:                    server.registerMBean(new Trivial(), new ObjectName(
279:                            "Domain3:type=instance1"));
280:                    resultMBeans = server.queryMBeans(new ObjectName(":*"),
281:                            null);
282:                    resultNames = server.queryNames(new ObjectName(":*"), null);
283:                } catch (Exception e) {
284:                    fail(e.toString());
285:                }
286:
287:                checkit(resultMBeans, resultNames, instances, 0);
288:
289:                if (server != null)
290:                    MBeanServerFactory.releaseMBeanServer(server);
291:            }
292:
293:            /**
294:             * Test one property.
295:             */
296:            public void testGetOneProperty() {
297:                MBeanServer server = null;
298:                HashSet instances = new HashSet();
299:                Set resultMBeans = null;
300:                Set resultNames = null;
301:                try {
302:                    server = MBeanServerFactory
303:                            .createMBeanServer("QueryMBeans");
304:                    instances.add(server.registerMBean(new Trivial(),
305:                            new ObjectName("Domain1:type=instance1")));
306:                    server.registerMBean(new Trivial(), new ObjectName(
307:                            "Domain1:type=instance2"));
308:                    instances.add(server.registerMBean(new Trivial(),
309:                            new ObjectName("Domain2:type=instance1")));
310:                    instances.add(server.registerMBean(new Trivial(),
311:                            new ObjectName("Domain3:type=instance1")));
312:                    resultMBeans = server.queryMBeans(new ObjectName(
313:                            "*:type=instance1"), null);
314:                    resultNames = server.queryNames(new ObjectName(
315:                            "*:type=instance1"), null);
316:                } catch (Exception e) {
317:                    fail(e.toString());
318:                }
319:
320:                checkit(resultMBeans, resultNames, instances, 0);
321:
322:                if (server != null)
323:                    MBeanServerFactory.releaseMBeanServer(server);
324:            }
325:
326:            /**
327:             * This one is from the spec.
328:             */
329:            public void testSpecAll() {
330:                MBeanServer server = null;
331:                HashSet instances = new HashSet();
332:                Set resultMBeans = null;
333:                Set resultNames = null;
334:                try {
335:                    server = MBeanServerFactory.createMBeanServer();
336:                    instances
337:                            .add(server
338:                                    .registerMBean(
339:                                            new Trivial(),
340:                                            new ObjectName(
341:                                                    "MyDomain:description=Printer,type=laser")));
342:                    instances
343:                            .add(server
344:                                    .registerMBean(
345:                                            new Trivial(),
346:                                            new ObjectName(
347:                                                    "DefaultDomain:description=Printer,type=laser,date=1993")));
348:                    instances
349:                            .add(server
350:                                    .registerMBean(
351:                                            new Trivial(),
352:                                            new ObjectName(
353:                                                    "Socrates:description=Printer,type=laser,date=1993")));
354:                    instances
355:                            .add(server
356:                                    .registerMBean(
357:                                            new Trivial(),
358:                                            new ObjectName(
359:                                                    "DefaultDomain:description=Printer,type=ink")));
360:                    instances.add(server.registerMBean(new Trivial(),
361:                            new ObjectName(
362:                                    "MyDomain:description=Disk,capacity=2")));
363:                    instances
364:                            .add(server
365:                                    .registerMBean(
366:                                            new Trivial(),
367:                                            new ObjectName(
368:                                                    "DefaultDomain:description=Disk,capacity=1")));
369:                    resultMBeans = server.queryMBeans(new ObjectName("*:*"),
370:                            null);
371:                    resultNames = server
372:                            .queryNames(new ObjectName("*:*"), null);
373:                } catch (Exception e) {
374:                    fail(e.toString());
375:                }
376:
377:                checkit(resultMBeans, resultNames, instances, implSize);
378:
379:                if (server != null)
380:                    MBeanServerFactory.releaseMBeanServer(server);
381:            }
382:
383:            /**
384:             * This one is from the spec.
385:             */
386:            public void testSpecDefault() {
387:                MBeanServer server = null;
388:                HashSet instances = new HashSet();
389:                Set resultMBeans = null;
390:                Set resultNames = null;
391:                try {
392:                    server = MBeanServerFactory.createMBeanServer();
393:                    server.registerMBean(new Trivial(), new ObjectName(
394:                            "MyDomain:description=Printer,type=laser"));
395:                    instances
396:                            .add(server
397:                                    .registerMBean(
398:                                            new Trivial(),
399:                                            new ObjectName(
400:                                                    "DefaultDomain:description=Printer,type=laser,date=1993")));
401:                    server
402:                            .registerMBean(
403:                                    new Trivial(),
404:                                    new ObjectName(
405:                                            "Socrates:description=Printer,type=laser,date=1993"));
406:                    instances
407:                            .add(server
408:                                    .registerMBean(
409:                                            new Trivial(),
410:                                            new ObjectName(
411:                                                    "DefaultDomain:description=Printer,type=ink")));
412:                    server.registerMBean(new Trivial(), new ObjectName(
413:                            "MyDomain:description=Disk,capacity=2"));
414:                    instances
415:                            .add(server
416:                                    .registerMBean(
417:                                            new Trivial(),
418:                                            new ObjectName(
419:                                                    "DefaultDomain:description=Disk,capacity=1")));
420:                    resultMBeans = server.queryMBeans(new ObjectName(":*"),
421:                            null);
422:                    resultNames = server.queryNames(new ObjectName(":*"), null);
423:                } catch (Exception e) {
424:                    fail(e.toString());
425:                }
426:
427:                checkit(resultMBeans, resultNames, instances, 0);
428:
429:                if (server != null)
430:                    MBeanServerFactory.releaseMBeanServer(server);
431:            }
432:
433:            /**
434:             * This one is from the spec.
435:             */
436:            public void testSpecMyDomain() {
437:                MBeanServer server = null;
438:                HashSet instances = new HashSet();
439:                Set resultMBeans = null;
440:                Set resultNames = null;
441:                try {
442:                    server = MBeanServerFactory.createMBeanServer();
443:                    instances
444:                            .add(server
445:                                    .registerMBean(
446:                                            new Trivial(),
447:                                            new ObjectName(
448:                                                    "MyDomain:description=Printer,type=laser")));
449:                    server
450:                            .registerMBean(
451:                                    new Trivial(),
452:                                    new ObjectName(
453:                                            "DefaultDomain:description=Printer,type=laser,date=1993"));
454:                    server
455:                            .registerMBean(
456:                                    new Trivial(),
457:                                    new ObjectName(
458:                                            "Socrates:description=Printer,type=laser,date=1993"));
459:                    server.registerMBean(new Trivial(), new ObjectName(
460:                            "DefaultDomain:description=Printer,type=ink"));
461:                    instances.add(server.registerMBean(new Trivial(),
462:                            new ObjectName(
463:                                    "MyDomain:description=Disk,capacity=2")));
464:                    server.registerMBean(new Trivial(), new ObjectName(
465:                            "DefaultDomain:description=Disk,capacity=1"));
466:                    resultMBeans = server.queryMBeans(new ObjectName(
467:                            "MyDomain:*"), null);
468:                    resultNames = server.queryNames(
469:                            new ObjectName("MyDomain:*"), null);
470:                } catch (Exception e) {
471:                    fail(e.toString());
472:                }
473:
474:                checkit(resultMBeans, resultNames, instances, 0);
475:
476:                if (server != null)
477:                    MBeanServerFactory.releaseMBeanServer(server);
478:            }
479:
480:            /**
481:             * This one is from the spec.
482:             */
483:            public void testSpecAnyAnyDomain() {
484:                MBeanServer server = null;
485:                HashSet instances = new HashSet();
486:                Set resultMBeans = null;
487:                Set resultNames = null;
488:                try {
489:                    server = MBeanServerFactory.createMBeanServer();
490:                    instances
491:                            .add(server
492:                                    .registerMBean(
493:                                            new Trivial(),
494:                                            new ObjectName(
495:                                                    "MyDomain:description=Printer,type=laser")));
496:                    server
497:                            .registerMBean(
498:                                    new Trivial(),
499:                                    new ObjectName(
500:                                            "DefaultDomain:description=Printer,type=laser,date=1993"));
501:                    server
502:                            .registerMBean(
503:                                    new Trivial(),
504:                                    new ObjectName(
505:                                            "Socrates:description=Printer,type=laser,date=1993"));
506:                    server.registerMBean(new Trivial(), new ObjectName(
507:                            "DefaultDomain:description=Printer,type=ink"));
508:                    instances.add(server.registerMBean(new Trivial(),
509:                            new ObjectName(
510:                                    "MyDomain:description=Disk,capacity=2")));
511:                    server.registerMBean(new Trivial(), new ObjectName(
512:                            "DefaultDomain:description=Disk,capacity=1"));
513:                    resultMBeans = server.queryMBeans(new ObjectName(
514:                            "??Domain:*"), null);
515:                    resultNames = server.queryNames(
516:                            new ObjectName("??Domain:*"), null);
517:                } catch (Exception e) {
518:                    fail(e.toString());
519:                }
520:
521:                checkit(resultMBeans, resultNames, instances, 0);
522:
523:                if (server != null)
524:                    MBeanServerFactory.releaseMBeanServer(server);
525:            }
526:
527:            /**
528:             * This one is from the spec.
529:             */
530:            public void testAsteriskDomAsterisk() {
531:                MBeanServer server = null;
532:                HashSet instances = new HashSet();
533:                Set resultMBeans = null;
534:                Set resultNames = null;
535:                try {
536:                    server = MBeanServerFactory.createMBeanServer();
537:                    instances
538:                            .add(server
539:                                    .registerMBean(
540:                                            new Trivial(),
541:                                            new ObjectName(
542:                                                    "MyDomain:description=Printer,type=laser")));
543:                    instances
544:                            .add(server
545:                                    .registerMBean(
546:                                            new Trivial(),
547:                                            new ObjectName(
548:                                                    "DefaultDomain:description=Printer,type=laser,date=1993")));
549:                    server
550:                            .registerMBean(
551:                                    new Trivial(),
552:                                    new ObjectName(
553:                                            "Socrates:description=Printer,type=laser,date=1993"));
554:                    instances
555:                            .add(server
556:                                    .registerMBean(
557:                                            new Trivial(),
558:                                            new ObjectName(
559:                                                    "DefaultDomain:description=Printer,type=ink")));
560:                    instances.add(server.registerMBean(new Trivial(),
561:                            new ObjectName(
562:                                    "MyDomain:description=Disk,capacity=2")));
563:                    instances
564:                            .add(server
565:                                    .registerMBean(
566:                                            new Trivial(),
567:                                            new ObjectName(
568:                                                    "DefaultDomain:description=Disk,capacity=1")));
569:                    resultMBeans = server.queryMBeans(
570:                            new ObjectName("*Dom*:*"), null);
571:                    resultNames = server.queryNames(new ObjectName("*Dom*:*"),
572:                            null);
573:                } catch (Exception e) {
574:                    fail(e.toString());
575:                }
576:
577:                checkit(resultMBeans, resultNames, instances, 0);
578:
579:                if (server != null)
580:                    MBeanServerFactory.releaseMBeanServer(server);
581:            }
582:
583:            /**
584:             * This one is from the spec.
585:             */
586:            public void testSpecLaserPrinters() {
587:                MBeanServer server = null;
588:                HashSet instances = new HashSet();
589:                Set resultMBeans = null;
590:                Set resultNames = null;
591:                try {
592:                    server = MBeanServerFactory.createMBeanServer();
593:                    instances
594:                            .add(server
595:                                    .registerMBean(
596:                                            new Trivial(),
597:                                            new ObjectName(
598:                                                    "MyDomain:description=Printer,type=laser")));
599:                    instances
600:                            .add(server
601:                                    .registerMBean(
602:                                            new Trivial(),
603:                                            new ObjectName(
604:                                                    "DefaultDomain:description=Printer,type=laser,date=1993")));
605:                    instances
606:                            .add(server
607:                                    .registerMBean(
608:                                            new Trivial(),
609:                                            new ObjectName(
610:                                                    "Socrates:description=Printer,type=laser,date=1993")));
611:                    server.registerMBean(new Trivial(), new ObjectName(
612:                            "DefaultDomain:description=Printer,type=ink"));
613:                    server.registerMBean(new Trivial(), new ObjectName(
614:                            "MyDomain:description=Disk,capacity=2"));
615:                    server.registerMBean(new Trivial(), new ObjectName(
616:                            "DefaultDomain:description=Disk,capacity=1"));
617:                    resultMBeans = server.queryMBeans(new ObjectName(
618:                            "*:description=Printer,type=laser,*"), null);
619:                    resultNames = server.queryNames(new ObjectName(
620:                            "*:description=Printer,type=laser,*"), null);
621:                } catch (Exception e) {
622:                    fail(e.toString());
623:                }
624:
625:                checkit(resultMBeans, resultNames, instances, 0);
626:
627:                if (server != null)
628:                    MBeanServerFactory.releaseMBeanServer(server);
629:            }
630:
631:            /**
632:             * This one is from the spec.
633:             */
634:            public void testSpecPrinters() {
635:                MBeanServer server = null;
636:                HashSet instances = new HashSet();
637:                Set resultMBeans = null;
638:                Set resultNames = null;
639:                try {
640:                    server = MBeanServerFactory.createMBeanServer();
641:                    instances
642:                            .add(server
643:                                    .registerMBean(
644:                                            new Trivial(),
645:                                            new ObjectName(
646:                                                    "MyDomain:description=Printer,type=laser")));
647:                    instances
648:                            .add(server
649:                                    .registerMBean(
650:                                            new Trivial(),
651:                                            new ObjectName(
652:                                                    "DefaultDomain:description=Printer,type=laser,date=1993")));
653:                    instances
654:                            .add(server
655:                                    .registerMBean(
656:                                            new Trivial(),
657:                                            new ObjectName(
658:                                                    "Socrates:description=Printer,type=laser,date=1993")));
659:                    instances
660:                            .add(server
661:                                    .registerMBean(
662:                                            new Trivial(),
663:                                            new ObjectName(
664:                                                    "DefaultDomain:description=Printer,type=ink")));
665:                    server.registerMBean(new Trivial(), new ObjectName(
666:                            "MyDomain:description=Disk,capacity=2"));
667:                    server.registerMBean(new Trivial(), new ObjectName(
668:                            "DefaultDomain:description=Disk,capacity=2"));
669:                    resultMBeans = server.queryMBeans(new ObjectName(
670:                            "*:description=Printer,*"), null);
671:                    resultNames = server.queryNames(new ObjectName(
672:                            "*:description=Printer,*"), null);
673:                } catch (Exception e) {
674:                    fail(e.toString());
675:                }
676:
677:                checkit(resultMBeans, resultNames, instances, 0);
678:
679:                if (server != null)
680:                    MBeanServerFactory.releaseMBeanServer(server);
681:            }
682:
683:            /**
684:             * Test suffix asterisk on domain.
685:             */
686:            public void testSuffixMatchManyDomain() {
687:                MBeanServer server = null;
688:                HashSet instances = new HashSet();
689:                Set resultMBeans = null;
690:                Set resultNames = null;
691:                try {
692:                    server = MBeanServerFactory
693:                            .createMBeanServer("QueryMBeans");
694:                    instances.add(server.registerMBean(new Trivial(),
695:                            new ObjectName("DomainA123:type=instance1")));
696:                    instances.add(server.registerMBean(new Trivial(),
697:                            new ObjectName("DomainA321:type=instance2")));
698:                    instances.add(server.registerMBean(new Trivial(),
699:                            new ObjectName("DomainA2224:type=instance1")));
700:                    instances.add(server.registerMBean(new Trivial(),
701:                            new ObjectName("DomainA3:type=instance1")));
702:                    instances.add(server.registerMBean(new Trivial(),
703:                            new ObjectName("DomainA:type=instance1")));
704:                    server.registerMBean(new Trivial(), new ObjectName(
705:                            "Domain:type=instance1"));
706:                    server.registerMBean(new Trivial(), new ObjectName(
707:                            "Dom:type=instance1"));
708:                    resultMBeans = server.queryMBeans(new ObjectName(
709:                            "DomainA*:*"), null);
710:                    resultNames = server.queryNames(
711:                            new ObjectName("DomainA*:*"), null);
712:                } catch (Exception e) {
713:                    fail(e.toString());
714:                }
715:
716:                checkit(resultMBeans, resultNames, instances, 0);
717:
718:                if (server != null)
719:                    MBeanServerFactory.releaseMBeanServer(server);
720:            }
721:
722:            /**
723:             * Test prefix asterisk on domain.
724:             */
725:            public void testPrefixMatchManyDomain() {
726:                MBeanServer server = null;
727:                HashSet instances = new HashSet();
728:                Set resultMBeans = null;
729:                Set resultNames = null;
730:                try {
731:                    server = MBeanServerFactory
732:                            .createMBeanServer("QueryMBeans");
733:                    instances.add(server.registerMBean(new Trivial(),
734:                            new ObjectName("123ADomain:type=instance1")));
735:                    instances.add(server.registerMBean(new Trivial(),
736:                            new ObjectName("321ADomain:type=instance2")));
737:                    instances.add(server.registerMBean(new Trivial(),
738:                            new ObjectName("2224ADomain:type=instance1")));
739:                    instances.add(server.registerMBean(new Trivial(),
740:                            new ObjectName("3ADomain:type=instance1")));
741:                    instances
742:                            .add(server
743:                                    .registerMBean(
744:                                            new Trivial(),
745:                                            new ObjectName(
746:                                                    "3ADomai123ADomain:type=instance1")));
747:                    instances.add(server.registerMBean(new Trivial(),
748:                            new ObjectName("ADomain:type=instance1")));
749:                    server.registerMBean(new Trivial(), new ObjectName(
750:                            "Domain:type=instance1"));
751:                    server.registerMBean(new Trivial(), new ObjectName(
752:                            "ADomai:type=instance1"));
753:                    server.registerMBean(new Trivial(), new ObjectName(
754:                            "main:type=instance1"));
755:                    resultMBeans = server.queryMBeans(new ObjectName(
756:                            "*ADomain:*"), null);
757:                    resultNames = server.queryNames(
758:                            new ObjectName("*ADomain:*"), null);
759:                } catch (Exception e) {
760:                    fail(e.toString());
761:                }
762:
763:                checkit(resultMBeans, resultNames, instances, 0);
764:
765:                if (server != null)
766:                    MBeanServerFactory.releaseMBeanServer(server);
767:            }
768:
769:            // Support ----------------------------------------------------------------
770:
771:            /**
772:             * Check the resultMBeans
773:             */
774:            private void checkit(Set resultMBeans, Set resultNames,
775:                    HashSet expected, int others) {
776:                // Quick tests
777:                assertEquals(expected.size() + others, resultMBeans.size());
778:                assertEquals(expected.size() + others, resultNames.size());
779:
780:                // Get the expected ObjectNames
781:                HashSet expectedNames = new HashSet();
782:                Iterator iterator = expected.iterator();
783:                while (iterator.hasNext()) {
784:                    expectedNames.add(((ObjectInstance) iterator.next())
785:                            .getObjectName());
786:                }
787:
788:                // Check resultMBeans
789:                iterator = resultMBeans.iterator();
790:                while (iterator.hasNext()) {
791:                    ObjectInstance instance = (ObjectInstance) iterator.next();
792:                    Iterator iterator2 = expected.iterator();
793:                    boolean found = false;
794:                    while (iterator2.hasNext()) {
795:                        if (iterator2.next().equals(instance)) {
796:                            iterator2.remove();
797:                            found = true;
798:                            break;
799:                        }
800:                    }
801:                    if (found == false
802:                            && instance.getObjectName().getDomain().equals(
803:                                    "JMImplementation") == false)
804:                        fail("Unexpected instance " + instance.getObjectName());
805:                }
806:
807:                // Check resultNames
808:                iterator = resultNames.iterator();
809:                while (iterator.hasNext()) {
810:                    ObjectName name = (ObjectName) iterator.next();
811:                    Iterator iterator2 = expectedNames.iterator();
812:                    boolean found = false;
813:                    while (iterator2.hasNext()) {
814:                        if (iterator2.next().equals(name)) {
815:                            iterator2.remove();
816:                            found = true;
817:                            break;
818:                        }
819:                    }
820:                    if (found == false
821:                            && name.getDomain().equals("JMImplementation") == false)
822:                        fail("Unexpected name " + name);
823:                }
824:            }
825:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.