Source Code Cross Referenced for DefaultDomainTestCase.java in  » EJB-Server-JBoss-4.2.1 » jmx » test » compliance » server » 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.server 
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.server;
023:
024:        import javax.management.InstanceAlreadyExistsException;
025:        import javax.management.InstanceNotFoundException;
026:        import javax.management.MBeanServer;
027:        import javax.management.MBeanServerFactory;
028:        import javax.management.ObjectName;
029:        import javax.management.relation.RelationService;
030:
031:        import junit.framework.TestCase;
032:        import test.compliance.server.support.Broadcaster;
033:        import test.compliance.server.support.Test;
034:
035:        /**
036:         * Tests default domain handling in the Server.<p>
037:         *
038:         * TODO createMBean x4.
039:         * TODO deserialize x2 
040:         * TODO getAttribute x2 
041:         * TODO getMBeanInfo 
042:         * TODO instantiate x2
043:         * TODO isInstanceOf
044:         * TODO isRegistered
045:         * TODO removeNotificationListener x2
046:         * TODO setAttribute x2
047:         *
048:         * @author  <a href="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>.
049:         */
050:        public class DefaultDomainTestCase extends TestCase {
051:            // Attributes ----------------------------------------------------------------
052:
053:            // Constructor ---------------------------------------------------------------
054:
055:            /**
056:             * Construct the test
057:             */
058:            public DefaultDomainTestCase(String s) {
059:                super (s);
060:            }
061:
062:            // Tests ---------------------------------------------------------------------
063:
064:            /**
065:             * Test Register in the "anonymous" default domain.
066:             */
067:            public void testDefaultDomainRegisterUnqualified() {
068:                MBeanServer server = null;
069:                ObjectName unqualifiedName = null;
070:                ObjectName qualifiedName = null;
071:                try {
072:                    server = MBeanServerFactory.createMBeanServer();
073:                    unqualifiedName = new ObjectName(":property=1");
074:                    qualifiedName = new ObjectName("DefaultDomain:property=1");
075:                    server.registerMBean(new Test(), unqualifiedName);
076:                } catch (Exception e) {
077:                    fail(e.toString());
078:                }
079:
080:                assertEquals("DefaultDomain", server.getDefaultDomain());
081:
082:                try {
083:                    server.getObjectInstance(unqualifiedName);
084:                } catch (InstanceNotFoundException e) {
085:                    fail("Unqualified lookup failed");
086:                }
087:
088:                try {
089:                    server.getObjectInstance(qualifiedName);
090:                } catch (InstanceNotFoundException e) {
091:                    fail("Qualified lookup failed");
092:                }
093:
094:                if (server != null)
095:                    MBeanServerFactory.releaseMBeanServer(server);
096:            }
097:
098:            /**
099:             * Test Register in the "anonymous" default domain.
100:             */
101:            public void testDefaultDomainRegisterQualified() {
102:                MBeanServer server = null;
103:                ObjectName unqualifiedName = null;
104:                ObjectName qualifiedName = null;
105:                try {
106:                    server = MBeanServerFactory.createMBeanServer();
107:                    unqualifiedName = new ObjectName(":property=1");
108:                    qualifiedName = new ObjectName("DefaultDomain:property=1");
109:                    server.registerMBean(new Test(), qualifiedName);
110:                } catch (Exception e) {
111:                    fail(e.toString());
112:                }
113:
114:                assertEquals("DefaultDomain", server.getDefaultDomain());
115:
116:                try {
117:                    server.getObjectInstance(unqualifiedName);
118:                } catch (InstanceNotFoundException e) {
119:                    fail("Unqualified lookup failed");
120:                }
121:
122:                try {
123:                    server.getObjectInstance(qualifiedName);
124:                } catch (InstanceNotFoundException e) {
125:                    fail("Qualified lookup failed");
126:                }
127:
128:                if (server != null)
129:                    MBeanServerFactory.releaseMBeanServer(server);
130:            }
131:
132:            /**
133:             * Test Register in a named default domain.
134:             */
135:            public void testMyDefaultDomainRegisterUnqualified() {
136:                MBeanServer server = null;
137:                ObjectName unqualifiedName = null;
138:                ObjectName qualifiedName = null;
139:                try {
140:                    server = MBeanServerFactory.createMBeanServer("MyDomain");
141:                    unqualifiedName = new ObjectName(":property=1");
142:                    qualifiedName = new ObjectName("MyDomain:property=1");
143:                    server.registerMBean(new Test(), unqualifiedName);
144:                } catch (Exception e) {
145:                    fail(e.toString());
146:                }
147:
148:                assertEquals("MyDomain", server.getDefaultDomain());
149:
150:                try {
151:                    server.getObjectInstance(unqualifiedName);
152:                } catch (InstanceNotFoundException e) {
153:                    fail("Unqualified lookup failed");
154:                }
155:
156:                try {
157:                    server.getObjectInstance(qualifiedName);
158:                } catch (InstanceNotFoundException e) {
159:                    fail("Qualified lookup failed");
160:                }
161:
162:                if (server != null)
163:                    MBeanServerFactory.releaseMBeanServer(server);
164:            }
165:
166:            /**
167:             * Test Register in a named default domain.
168:             */
169:            public void testMyDefaultDomainRegisterQualified() {
170:                MBeanServer server = null;
171:                ObjectName unqualifiedName = null;
172:                ObjectName qualifiedName = null;
173:                try {
174:                    server = MBeanServerFactory.createMBeanServer("MyDomain");
175:                    unqualifiedName = new ObjectName(":property=1");
176:                    qualifiedName = new ObjectName("MyDomain:property=1");
177:                    server.registerMBean(new Test(), qualifiedName);
178:                } catch (Exception e) {
179:                    fail(e.toString());
180:                }
181:
182:                assertEquals("MyDomain", server.getDefaultDomain());
183:
184:                try {
185:                    server.getObjectInstance(unqualifiedName);
186:                } catch (InstanceNotFoundException e) {
187:                    fail("Unqualified lookup failed");
188:                }
189:
190:                try {
191:                    server.getObjectInstance(qualifiedName);
192:                } catch (InstanceNotFoundException e) {
193:                    fail("Qualified lookup failed");
194:                }
195:
196:                if (server != null)
197:                    MBeanServerFactory.releaseMBeanServer(server);
198:            }
199:
200:            /**
201:             * Test register qualified/unqualifed.
202:             */
203:            public void testRegisterQualifiedUnqualified() {
204:                duplicateRegister(":property=1", "MyDomain:property=1");
205:            }
206:
207:            /**
208:             * Test register unqualified/qualifed.
209:             */
210:            public void testRegisterUnqualifiedQualified() {
211:                duplicateRegister("MyDomain:property=1", ":property=1");
212:            }
213:
214:            /**
215:             * Test register unqualified/unqualified.
216:             */
217:            public void testRegisterUnqualifiedUnqualified() {
218:                duplicateRegister(":property=1", ":property=1");
219:            }
220:
221:            /**
222:             * Test invoke qualified/unqualifed.
223:             */
224:            public void testInvokeQualifiedUnqualified() {
225:                invoke(":property=1", "MyDomain:property=1");
226:            }
227:
228:            /**
229:             * Test invoke unqualified/qualifed.
230:             */
231:            public void testInvokeUnqualifiedQualified() {
232:                invoke("MyDomain:property=1", ":property=1");
233:            }
234:
235:            /**
236:             * Test invoke unqualified/unqualified.
237:             */
238:            public void testInvokeUnqualifiedUnqualified() {
239:                invoke(":property=1", ":property=1");
240:            }
241:
242:            /**
243:             * Test register qualified unregister unqualified.
244:             */
245:            public void testRegisterQualifiedUnregisterUnqualified() {
246:                unregister("MyDomain:property=1", ":property=1");
247:            }
248:
249:            /**
250:             * Test register unqualified unregister qualifed.
251:             */
252:            public void testRegisterUnQualifiedUnregisterQualified() {
253:                unregister(":property=1", "MyDomain:property=1");
254:            }
255:
256:            /**
257:             * Test register unqualified unregister unqualified.
258:             */
259:            public void testRegisterUnqualifiedUnregisterUnqualified() {
260:                unregister(":property=1", ":property=1");
261:            }
262:
263:            /**
264:             * Add notification listenter. ObjectName, Listener
265:             */
266:            public void testAddNLUnqualifiedNameListenerRegisterQualified() {
267:                addNLNameListener("MyDomain:property=1", ":property=1");
268:            }
269:
270:            /**
271:             * Add notification listenter. ObjectName, Listener
272:             */
273:            public void testAddNLQualifiedNameListenerRegisterUnqualified() {
274:                addNLNameListener(":property=1", "MyDomain:property=1");
275:            }
276:
277:            /**
278:             * Add notification listenter. ObjectName, Listener
279:             */
280:            public void testAddNLUnqualifiedNameListenerRegisterUnqualified() {
281:                addNLNameListener(":property=1", ":property=1");
282:            }
283:
284:            /**
285:             * Add notification listenter. ObjectName, ObjectName
286:             */
287:            public void testAddNLUnqualifiedQualifiedRegisterUnqualifiedQualified() {
288:                addNLNameName(":property=1", "MyDomain:property=2",
289:                        ":property=1", "MyDomain:property=2");
290:            }
291:
292:            /**
293:             * Add notification listenter. ObjectName, ObjectName
294:             */
295:            public void testAddNLUnqualifiedQualifiedRegisterQualifiedQualified() {
296:                addNLNameName(":property=1", "MyDomain:property=2",
297:                        "MyDomain:property=1", "MyDomain:property=2");
298:            }
299:
300:            /**
301:             * Add notification listenter. ObjectName, ObjectName
302:             */
303:            public void testAddNLQualifiedQualifiedRegisterUnqualifiedQualified() {
304:                addNLNameName("MyDomain:property=1", "MyDomain:property=2",
305:                        ":property=1", "MyDomain:property=2");
306:            }
307:
308:            /**
309:             * Add notification listenter. ObjectName, ObjectName
310:             */
311:            public void testAddNLQualifiedUnqualifiedRegisterQualifiedUnqualified() {
312:                addNLNameName("MyDomain:property=1", ":property=2",
313:                        "MyDomain:property=1", ":property=2");
314:            }
315:
316:            /**
317:             * Add notification listenter. ObjectName, ObjectName
318:             */
319:            public void testAddNLQualifiedUnqualifiedRegisterQualifiedQualified() {
320:                addNLNameName("MyDomain:property=1", ":property=2",
321:                        "MyDomain:property=1", "MyDomain:property=2");
322:            }
323:
324:            /**
325:             * Add notification listenter. ObjectName, ObjectName
326:             */
327:            public void testAddNLQualifiedQualifiedRegisterQualifiedUnqualified() {
328:                addNLNameName("MyDomain:property=1", "MyDomain:property=2",
329:                        "MyDomain:property=1", ":property=2");
330:            }
331:
332:            // Support -----------------------------------------------------------------
333:
334:            /**
335:             * Test Duplicate Register.
336:             */
337:            private void duplicateRegister(String register, String test) {
338:                MBeanServer server = null;
339:                ObjectName registerName = null;
340:                ObjectName testName = null;
341:                try {
342:                    server = MBeanServerFactory.createMBeanServer("MyDomain");
343:                    registerName = new ObjectName(register);
344:                    testName = new ObjectName(test);
345:                    server.registerMBean(new Test(), registerName);
346:                } catch (Exception e) {
347:                    fail(e.toString());
348:                }
349:
350:                boolean caught = false;
351:                try {
352:                    server.registerMBean(new Test(), testName);
353:                } catch (InstanceAlreadyExistsException e) {
354:                    caught = true;
355:                } catch (Exception e) {
356:                    fail(e.toString());
357:                }
358:
359:                if (caught == false)
360:                    fail("Allows duplicate registration");
361:
362:                if (server != null)
363:                    MBeanServerFactory.releaseMBeanServer(server);
364:            }
365:
366:            /**
367:             * Test unregister
368:             */
369:            private void unregister(String register, String test) {
370:                MBeanServer server = null;
371:                ObjectName registerName = null;
372:                ObjectName testName = null;
373:                try {
374:                    server = MBeanServerFactory.createMBeanServer("MyDomain");
375:                    registerName = new ObjectName(register);
376:                    testName = new ObjectName(test);
377:                    server.registerMBean(new Test(), registerName);
378:                } catch (Exception e) {
379:                    fail(e.toString());
380:                }
381:
382:                try {
383:                    server.unregisterMBean(testName);
384:                } catch (InstanceNotFoundException e) {
385:                    fail("FAILS IN RI: unregisterMBean doesn't add the default domain");
386:                } catch (Exception e) {
387:                    fail(e.toString());
388:                }
389:
390:                if (server != null)
391:                    MBeanServerFactory.releaseMBeanServer(server);
392:            }
393:
394:            /**
395:             * Add notification listenter. ObjectName, Listener
396:             */
397:            private void addNLNameListener(String register, String test) {
398:                MBeanServer server = null;
399:                ObjectName registerName = null;
400:                ObjectName testName = null;
401:                try {
402:                    server = MBeanServerFactory.createMBeanServer("MyDomain");
403:                    registerName = new ObjectName(register);
404:                    testName = new ObjectName(test);
405:                    server.registerMBean(new Broadcaster(), registerName);
406:                } catch (Exception e) {
407:                    fail(e.toString());
408:                }
409:
410:                try {
411:                    server.addNotificationListener(testName,
412:                            new RelationService(true), null, null);
413:                } catch (Exception e) {
414:                    fail(e.toString());
415:                }
416:
417:                if (server != null)
418:                    MBeanServerFactory.releaseMBeanServer(server);
419:            }
420:
421:            /**
422:             * Add notification listenter. ObjectName, ObjectName
423:             */
424:            private void addNLNameName(String register1, String register2,
425:                    String test1, String test2) {
426:                MBeanServer server = null;
427:                ObjectName register1Name = null;
428:                ObjectName register2Name = null;
429:                ObjectName test1Name = null;
430:                ObjectName test2Name = null;
431:                try {
432:                    server = MBeanServerFactory.createMBeanServer("MyDomain");
433:                    register1Name = new ObjectName(register1);
434:                    register2Name = new ObjectName(register2);
435:                    test1Name = new ObjectName(test1);
436:                    test2Name = new ObjectName(test2);
437:                    server.registerMBean(new Broadcaster(), register1Name);
438:                    server.registerMBean(new RelationService(true),
439:                            register2Name);
440:                } catch (Exception e) {
441:                    fail(e.toString());
442:                }
443:
444:                try {
445:                    server.addNotificationListener(test1Name, test2Name, null,
446:                            null);
447:                } catch (Exception e) {
448:                    fail(e.toString());
449:                }
450:
451:                if (server != null)
452:                    MBeanServerFactory.releaseMBeanServer(server);
453:            }
454:
455:            /**
456:             * Test Invoke.
457:             */
458:            private void invoke(String register, String test) {
459:                MBeanServer server = null;
460:                ObjectName registerName = null;
461:                ObjectName testName = null;
462:                try {
463:                    server = MBeanServerFactory.createMBeanServer("MyDomain");
464:                    registerName = new ObjectName(register);
465:                    testName = new ObjectName(test);
466:                    server.registerMBean(new Broadcaster(), registerName);
467:                } catch (Exception e) {
468:                    fail(e.toString());
469:                }
470:
471:                try {
472:                    server.invoke(testName, "doSomething", new Object[0],
473:                            new String[0]);
474:                } catch (Exception e) {
475:                    fail(e.toString());
476:                }
477:
478:                if (server != null)
479:                    MBeanServerFactory.releaseMBeanServer(server);
480:            }
481:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.