KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > mbeans > ConfigsMBeanTest


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * $Id: ConfigsMBeanTest.java,v 1.3 2005/12/25 03:43:12 tcfujii Exp $
26  */

27
28 package com.sun.enterprise.admin.mbeans;
29
30 //jdk imports
31
import java.util.Properties JavaDoc;
32 import java.io.File JavaDoc;
33
34 //junit imports
35
import junit.framework.*;
36 import junit.textui.TestRunner;
37
38 //JMX imports
39
import javax.management.AttributeList JavaDoc;
40 import javax.management.Attribute JavaDoc;
41 import javax.management.ObjectName JavaDoc;
42 import javax.management.MBeanException JavaDoc;
43 import javax.management.MBeanServer JavaDoc;
44
45 //config imports
46
import com.sun.enterprise.config.ConfigFactory;
47 import com.sun.enterprise.config.ConfigContext;
48 import com.sun.enterprise.config.ConfigException;
49
50 //config mbean imports
51
import com.sun.enterprise.admin.meta.MBeanRegistry;
52 import com.sun.enterprise.admin.meta.MBeanRegistryFactory;
53 import com.sun.enterprise.admin.BaseAdminMBean;
54
55 public class ConfigsMBeanTest extends TestCase
56 {
57     public void testCreateConfigsMBean()
58     {
59         ConfigsMBean mbean = new ConfigsMBean();
60         Assert.assertTrue(mbean != null);
61     }
62
63     public void testGetConfigMBean() throws Exception JavaDoc
64     {
65         ObjectName JavaDoc on = configsMBean.getConfigMBean(getTarget());
66         Assert.assertEquals(getConfigMBean(), on);
67     }
68
69     public void testGetHttpServiceMBean() throws Exception JavaDoc
70     {
71         ObjectName JavaDoc on = configsMBean.getHttpServiceMBean(getTarget());
72         Assert.assertEquals(getHttpService(), on);
73     }
74
75     public void testHttpListener() throws Exception JavaDoc
76     {
77         final String JavaDoc target = getTargetName();
78         ObjectName JavaDoc on = configsMBean.createHttpListener(
79                                 getHttpListenerAttrs(), null, target);
80         Assert.assertTrue(on != null);
81         Assert.assertEquals(getHttpListener(), on);
82         ObjectName JavaDoc[] names = configsMBean.listHttpListeners(target);
83         Assert.assertTrue(names != null);
84         Assert.assertTrue(names.length > 0);
85         Assert.assertTrue(exists(getHttpListener(), names));
86         boolean isDeleted = configsMBean.deleteHttpListener("mylistener", null);
87         Assert.assertTrue(isDeleted);
88         names = configsMBean.listHttpListeners(target);
89         Assert.assertFalse(exists(getHttpListener(), names));
90     }
91
92     private AttributeList JavaDoc getHttpListenerAttrs()
93     {
94         AttributeList JavaDoc attrList = new AttributeList JavaDoc();
95         attrList.add(new Attribute JavaDoc("id", "mylistener"));
96         attrList.add(new Attribute JavaDoc("address", "abcd"));
97         attrList.add(new Attribute JavaDoc("port", "9999"));
98         attrList.add(new Attribute JavaDoc("server-name", "server-name"));
99         attrList.add(new Attribute JavaDoc("default-virtual-server", "server-name"));
100         return attrList;
101     }
102
103     public void testIiopListener() throws Exception JavaDoc
104     {
105         final String JavaDoc target = getTargetName();
106         ObjectName JavaDoc on = configsMBean.createIiopListener(
107                                 getIiopListenerAttrs(), null, target);
108         Assert.assertTrue(on != null);
109         Assert.assertEquals(getIiopListener(), on);
110         ObjectName JavaDoc[] names = configsMBean.listIiopListeners(target);
111         Assert.assertTrue(names != null);
112         Assert.assertTrue(names.length > 0);
113         Assert.assertTrue(exists(getIiopListener(), names));
114         boolean isDeleted = configsMBean.deleteIiopListener("mylistener", null);
115         Assert.assertTrue(isDeleted);
116         names = configsMBean.listIiopListeners(target);
117         Assert.assertFalse(exists(getIiopListener(), names));
118     }
119
120     private AttributeList JavaDoc getIiopListenerAttrs()
121     {
122         AttributeList JavaDoc attrList = new AttributeList JavaDoc();
123         attrList.add(new Attribute JavaDoc("id", "mylistener"));
124         attrList.add(new Attribute JavaDoc("address", "address"));
125         return attrList;
126     }
127
128     public void testSSL() throws Exception JavaDoc
129     {
130         final String JavaDoc target = getTargetName();
131         try
132         {
133             configsMBean.createHttpListener(getHttpListenerAttrs(), null, target);
134             configsMBean.createIiopListener(getIiopListenerAttrs(), null, target);
135             testSSL("http-listener");
136             testSSL("iiop-listener");
137             testSSL("iiop-service");
138         }
139         finally
140         {
141             configsMBean.deleteHttpListener("mylistener", target);
142             configsMBean.deleteIiopListener("mylistener", target);
143         }
144     }
145
146     void testSSL(String JavaDoc type) throws Exception JavaDoc
147     {
148         ObjectName JavaDoc ssl = null;
149         final String JavaDoc target = getTargetName();
150         AttributeList JavaDoc al = new AttributeList JavaDoc();
151         al.add(new Attribute JavaDoc("cert-nickname", "nick1"));
152         ssl = configsMBean.createSsl(al, "mylistener", type, target);
153         Assert.assertTrue(ssl != null);
154         ObjectName JavaDoc on = configsMBean.getSsl(type, "mylistener", target);
155         Assert.assertEquals(ssl, on);
156         boolean isDeleted = configsMBean.deleteSsl(
157                             "mylistener", type, target);
158         Assert.assertTrue(isDeleted);
159     }
160
161     public void testVirtualServer() throws Exception JavaDoc
162     {
163         final String JavaDoc target = getTargetName();
164         ObjectName JavaDoc on = configsMBean.createVirtualServer(
165                                 getVirtualServerAttrs(), null, target);
166         Assert.assertTrue(on != null);
167         Assert.assertEquals(getVirtualServer(), on);
168         ObjectName JavaDoc[] names = configsMBean.listVirtualServers(target);
169         Assert.assertTrue(names != null);
170         Assert.assertTrue(names.length > 0);
171         Assert.assertTrue(exists(getVirtualServer(), names));
172         boolean isDeleted = configsMBean.deleteVirtualServer(
173             "my-virtual-server", null);
174         Assert.assertTrue(isDeleted);
175         names = configsMBean.listVirtualServers(target);
176         Assert.assertFalse(exists(getVirtualServer(), names));
177     }
178
179     private AttributeList JavaDoc getVirtualServerAttrs()
180     {
181         AttributeList JavaDoc attrList = new AttributeList JavaDoc();
182         attrList.add(new Attribute JavaDoc("id", "my-virtual-server"));
183         attrList.add(new Attribute JavaDoc("hosts", "host1,host2"));
184         return attrList;
185     }
186
187     public void testAuthRealm() throws Exception JavaDoc
188     {
189         final String JavaDoc target = getTargetName();
190         final String JavaDoc realm = "myAuth";
191         final AttributeList JavaDoc al = new AttributeList JavaDoc();
192         al.add(new Attribute JavaDoc("name", realm));
193         al.add(new Attribute JavaDoc("classname", "myauth.Auth"));
194
195         ObjectName JavaDoc on = configsMBean.createAuthRealm(al, null, target);
196         Assert.assertTrue(on != null);
197         Assert.assertEquals(getAuthRealm(realm), on);
198         ObjectName JavaDoc[] authRealms = configsMBean.listAuthRealms(target);
199         Assert.assertTrue(authRealms != null);
200         Assert.assertTrue(exists(on, authRealms));
201         boolean deleted = configsMBean.deleteAuthRealm(realm, target);
202         Assert.assertTrue(deleted);
203         authRealms = configsMBean.listAuthRealms(target);
204         Assert.assertTrue(authRealms != null);
205         Assert.assertTrue(!exists(on, authRealms));
206     }
207
208     public void testProfiler() throws Exception JavaDoc
209     {
210         final String JavaDoc name = "myprofiler";
211         AttributeList JavaDoc al = new AttributeList JavaDoc();
212         al.add(new Attribute JavaDoc("name", name));
213
214         ObjectName JavaDoc on = configsMBean.createProfiler(
215                                 al, getProperties(), null);
216         Assert.assertTrue(on != null);
217         Assert.assertEquals(getProfiler(), on);
218         on = configsMBean.getProfiler(getTargetName());
219         Assert.assertEquals(getObjectName("profiler", null), on);
220         boolean isDeleted = configsMBean.deleteProfiler(null);
221         Assert.assertTrue(isDeleted);
222     }
223
224     public void testJvmOptions() throws Exception JavaDoc
225     {
226         String JavaDoc[] exOpts = configsMBean.getJvmOptions(false, getTargetName());
227         Assert.assertTrue(exOpts != null);
228         String JavaDoc[] jvmOpts = new String JavaDoc[] {"-Dn1=v1", "-Dn2=v2", "-Dn3=v3"};
229         configsMBean.createJvmOptions(jvmOpts, false, getTargetName());
230         configsMBean.deleteJvmOptions(jvmOpts, false, getTargetName());
231     }
232
233     public void testFileUser() throws Exception JavaDoc
234     {
235         final String JavaDoc user = "ramakant3";
236         final String JavaDoc pwd = "ramakant";
237         final String JavaDoc[] grps = {"grp1"};
238         final String JavaDoc realm = "file";
239
240         configsMBean.addUser(user, pwd, grps, realm, getTargetName());
241         configsMBean.updateUser(user, pwd, grps, realm, getTargetName());
242         String JavaDoc[] users = configsMBean.getUserNames(realm, getTargetName());
243         Assert.assertTrue(users != null);
244         Assert.assertTrue(exists(user, users));
245
246         String JavaDoc[] groups = configsMBean.getGroupNames(user, realm,
247                             getTargetName());
248         Assert.assertTrue(groups != null);
249         Assert.assertTrue(exists(grps[0], groups));
250
251         configsMBean.removeUser(user, realm, getTargetName());
252         users = configsMBean.getUserNames(realm, getTargetName());
253         Assert.assertFalse(exists(user, users));
254         groups = configsMBean.getGroupNames(null, realm, getTargetName());
255         Assert.assertFalse(exists(grps[0], groups));
256     }
257
258     public void testAuditModule() throws Exception JavaDoc
259     {
260         AttributeList JavaDoc attrs = new AttributeList JavaDoc();
261         attrs.add(new Attribute JavaDoc("name", "xaudit"));
262         attrs.add(new Attribute JavaDoc("classname", "audit.xaudit"));
263
264         ObjectName JavaDoc on = configsMBean.createAuditModule(
265                             attrs, getProperties(), getTargetName());
266         Assert.assertTrue(on != null);
267         Assert.assertEquals(getAuditModule("xaudit"), on);
268
269         ObjectName JavaDoc[] onames = configsMBean.listAuditModules(getTargetName());
270         Assert.assertTrue(onames != null);
271         Assert.assertTrue(onames.length > 0);
272         Assert.assertTrue(exists(getAuditModule("xaudit"), onames));
273
274         boolean isDeleted = configsMBean.deleteAuditModule(
275                                 "xaudit", getTargetName());
276         Assert.assertTrue(isDeleted);
277         onames = configsMBean.listAuditModules(getTargetName());
278         Assert.assertTrue(!exists(getAuditModule("xaudit"), onames));
279     }
280
281     public void testJmsHost() throws Exception JavaDoc
282     {
283         final AttributeList JavaDoc attrs = new AttributeList JavaDoc();
284         attrs.add(new Attribute JavaDoc("name", "host1"));
285
286         ObjectName JavaDoc on = configsMBean.createJmsHost(
287                             attrs, getProperties(), getTargetName());
288         Assert.assertTrue(on != null);
289         Assert.assertEquals(getJmsHost("host1"), on);
290         ObjectName JavaDoc[] onames = configsMBean.listJmsHosts(getTargetName());
291         Assert.assertTrue(onames != null);
292         Assert.assertTrue(onames.length > 0);
293         Assert.assertTrue(exists(getJmsHost("host1"), onames));
294         boolean isDeleted = configsMBean.deleteJmsHost("host1", getTargetName());
295         Assert.assertTrue(isDeleted);
296         onames = configsMBean.listJmsHosts(getTargetName());
297         Assert.assertTrue(!exists(getJmsHost("host1"), onames));
298     }
299
300     public void testJaccProvider() throws Exception JavaDoc
301     {
302         final AttributeList JavaDoc attrs = new AttributeList JavaDoc();
303         attrs.add(new Attribute JavaDoc("name", "provider1"));
304         attrs.add(new Attribute JavaDoc("policy-provider", "provider1"));
305         attrs.add(new Attribute JavaDoc("policy-configuration-factory-provider",
306                     "providerfactory"));
307
308         ObjectName JavaDoc on = configsMBean.createJaccProvider(
309                             attrs, getProperties(), getTargetName());
310         ObjectName JavaDoc[] onames = configsMBean.listJaccProviders(getTargetName());
311         Assert.assertTrue(onames != null);
312         Assert.assertTrue(onames.length > 0);
313         Assert.assertTrue(exists(getJaccProvider("provider1"), onames));
314         boolean isDeleted = configsMBean.deleteJaccProvider(
315                                 "provider1", getTargetName());
316         Assert.assertTrue(isDeleted);
317         onames = configsMBean.listJaccProviders(getTargetName());
318         Assert.assertTrue(!exists(getJaccProvider("provider1"), onames));
319     }
320
321     public void testThreadPool() throws Exception JavaDoc
322     {
323         final AttributeList JavaDoc attrs = new AttributeList JavaDoc();
324         attrs.add(new Attribute JavaDoc("thread-pool-id", "testPool"));
325
326         ObjectName JavaDoc on = configsMBean.createThreadPool(
327                             attrs, null, getTargetName());
328         ObjectName JavaDoc[] onames = configsMBean.listThreadPools(getTargetName());
329         Assert.assertTrue(onames != null);
330         Assert.assertTrue(onames.length > 0);
331         Assert.assertTrue(exists(getThreadPool("testPool"), onames));
332         boolean isDeleted = configsMBean.deleteThreadPool(
333                                 "testPool", getTargetName());
334         Assert.assertTrue(isDeleted);
335         onames = configsMBean.listThreadPools(getTargetName());
336         Assert.assertTrue(!exists(getThreadPool("testPool"), onames));
337     }
338
339     public void testGetChild() throws Exception JavaDoc
340     {
341         getChild("http-listener", new String JavaDoc[] {"http-listener-1"});
342         getChild("ejb-container", null);
343         getChild("ssl", new String JavaDoc[] {"http-listener-1"});
344         getChild("ssl#", null);
345         getChild("ssl##", new String JavaDoc[]{"SSL"});
346
347         try
348         {
349             ObjectName JavaDoc on = configsMBean.getChild(null, null, getTargetName());
350             Assert.assertTrue(false);
351         }
352         catch (Exception JavaDoc e)
353         {
354             //ok
355
}
356     }
357
358     private void getChild(String JavaDoc type, String JavaDoc[] loc) throws Exception JavaDoc
359     {
360         try
361         {
362             ObjectName JavaDoc on = configsMBean.getChild(type, loc, getTargetName());
363             Assert.assertEquals(getObjectName(type, loc), on);
364         }
365         catch (MBeanException JavaDoc mbe) {}
366     }
367
368     public void testGetters() throws Exception JavaDoc
369     {
370         ObjectName JavaDoc on = configsMBean.getHttpService(getTargetName());
371         Assert.assertEquals(getObjectName("http-service", null), on);
372
373         on = configsMBean.getIiopService(getTargetName());
374         Assert.assertEquals(getObjectName("iiop-service", null), on);
375
376         on = configsMBean.getTransactionService(getTargetName());
377         Assert.assertEquals(getObjectName("transaction-service", null), on);
378
379         on = configsMBean.getMonitoringService(getTargetName());
380         Assert.assertEquals(getObjectName("monitoring-service", null), on);
381
382         on = configsMBean.getLogService(getTargetName());
383         Assert.assertEquals(getObjectName("log-service", null), on);
384
385         on = configsMBean.getSecurityService(getTargetName());
386         Assert.assertEquals(getObjectName("security-service", null), on);
387
388         on = configsMBean.getJmsService(getTargetName());
389         Assert.assertEquals(getObjectName("jms-service", null), on);
390
391         on = configsMBean.getEjbContainer(getTargetName());
392         Assert.assertEquals(getObjectName("ejb-container", null), on);
393
394         on = configsMBean.getWebContainer(getTargetName());
395         Assert.assertEquals(getObjectName("web-container", null), on);
396
397         on = configsMBean.getMdbContainer(getTargetName());
398         Assert.assertEquals(getObjectName("mdb-container", null), on);
399
400         on = configsMBean.getJavaConfig(getTargetName());
401         Assert.assertEquals(getObjectName("java-config", null), on);
402
403         on = configsMBean.getHttpListener("http-listener-1", getTargetName());
404         Assert.assertEquals(
405             getObjectName1("http-listener", "http-listener-1"), on);
406
407         on = configsMBean.getVirtualServer("server", getTargetName());
408         Assert.assertEquals(getObjectName1("virtual-server", "server"), on);
409
410         on = configsMBean.getOrb(getTargetName());
411         Assert.assertEquals(getObjectName("orb", null), on);
412
413         on = configsMBean.getIiopListener("orb-listener-1", getTargetName());
414         Assert.assertEquals(
415             getObjectName1("iiop-listener", "orb-listener-1"), on);
416
417         on = configsMBean.getJmsHost("default_JMS_host", getTargetName());
418         Assert.assertEquals(getObjectName1("jms-host", "default_JMS_host"), on);
419
420         on = configsMBean.getAuthRealm("file", getTargetName());
421         Assert.assertEquals(getObjectName1("auth-realm", "file"), on);
422
423         on = configsMBean.getAuditModule("default", getTargetName());
424         Assert.assertEquals(getObjectName1("audit-module", "default"), on);
425
426         on = configsMBean.getJaccProvider("default", getTargetName());
427         Assert.assertEquals(getObjectName1("jacc-provider", "default"), on);
428
429         on = configsMBean.getModuleLogLevels(getTargetName());
430         Assert.assertEquals(getObjectName("module-log-levels", null), on);
431
432         on = configsMBean.getModuleMonitoringLevels(getTargetName());
433         Assert.assertEquals(getObjectName("module-monitoring-levels", null), on);
434
435         on = configsMBean.getThreadPool("thread-pool-1", getTargetName());
436         Assert.assertEquals(getObjectName1("thread-pool", "thread-pool-1"), on);
437     }
438
439     public void testEjbTimerService() throws Exception JavaDoc
440     {
441         ObjectName JavaDoc on = configsMBean.createEjbTimerService(
442             null, getProperties(), getTargetName());
443         Assert.assertTrue(on != null);
444         on = configsMBean.getEjbTimerService(getTargetName());
445         Assert.assertEquals(getObjectName("ejb-timer-service", null), on);
446         boolean isDeleted = configsMBean.deleteEjbTimerService(getTargetName());
447         Assert.assertTrue(isDeleted);
448         try
449         {
450             configsMBean.getEjbTimerService(getTargetName());
451             Assert.assertTrue(false);
452         }
453         catch (Exception JavaDoc e)
454         {
455             //ok
456
}
457     }
458
459     public void testSessionConfig() throws Exception JavaDoc
460     {
461         ObjectName JavaDoc on = null;
462         boolean isDeleted = false;
463
464         on = configsMBean.createSessionProperties(null, getProperties(),
465             getTargetName());
466         Assert.assertEquals(getObjectName("session-properties", null), on);
467         on = configsMBean.getSessionProperties(getTargetName());
468         Assert.assertEquals(getObjectName("session-properties", null), on);
469         isDeleted = configsMBean.deleteSessionProperties(getTargetName());
470         Assert.assertTrue(isDeleted);
471
472         on = configsMBean.createManagerProperties(null, null, getTargetName());
473         Assert.assertEquals(getObjectName("manager-properties", null), on);
474         on = configsMBean.getManagerProperties(getTargetName());
475         Assert.assertEquals(getObjectName("manager-properties", null), on);
476         isDeleted = configsMBean.deleteManagerProperties(getTargetName());
477         Assert.assertTrue(isDeleted);
478
479         on = configsMBean.createStoreProperties(null, null, getTargetName());
480         Assert.assertEquals(getObjectName("store-properties", null), on);
481         on = configsMBean.getStoreProperties(getTargetName());
482         Assert.assertEquals(getObjectName("store-properties", null), on);
483         isDeleted = configsMBean.deleteStoreProperties(getTargetName());
484         Assert.assertTrue(isDeleted);
485
486         isDeleted = configsMBean.deleteSessionConfig(getTargetName());
487         Assert.assertTrue(isDeleted);
488     }
489
490     public ConfigsMBeanTest(String JavaDoc name) throws Exception JavaDoc
491     {
492         super(name);
493     }
494
495     private ConfigContext configContext;
496     private ConfigsMBean configsMBean;
497
498     protected void setUp()
499     {
500         configsMBean = new MyConfigsMBean();
501         try
502         {
503             configContext = ConfigFactory.createConfigContext(
504                                 domainXml.getAbsolutePath());
505             loadMBeanRegistry();
506         }
507         catch (Exception JavaDoc e)
508         {
509             throw new RuntimeException JavaDoc(e.getMessage());
510         }
511     }
512
513     protected void tearDown()
514     {
515         configsMBean = null;
516         configContext = null;
517         mbeanRegistry = null;
518     }
519
520     public static junit.framework.Test suite()
521     {
522         TestSuite suite = new TestSuite(ConfigsMBeanTest.class);
523         return suite;
524     }
525
526     public static void main(String JavaDoc args[]) throws Exception JavaDoc
527     {
528         setDomainXml(new File JavaDoc(args[0]));
529         setMBeanDescriptor(new File JavaDoc(args[1]));
530
531         final TestRunner runner= new TestRunner();
532         final TestResult result = runner.doRun(ConfigsMBeanTest.suite(), false);
533         System.exit(result.errorCount() + result.failureCount());
534     }
535
536     private static File JavaDoc domainXml;
537
538     public static void setDomainXml(File JavaDoc xml)
539     {
540         domainXml = xml;
541     }
542
543     private static File JavaDoc mbeanDescriptor;
544
545     public static void setMBeanDescriptor(File JavaDoc f)
546     {
547         mbeanDescriptor = f;
548     }
549
550     private static MBeanRegistry mbeanRegistry;
551
552     private static void loadMBeanRegistry() throws Exception JavaDoc
553     {
554         if (null == mbeanRegistry)
555         {
556             mbeanRegistry = MBeanRegistryFactory.getMBeanRegistry(
557                                 mbeanDescriptor.getAbsolutePath());
558         }
559     }
560
561     private String JavaDoc getConfigRef() throws Exception JavaDoc
562     {
563         Target target = TargetBuilder.INSTANCE.createTarget(
564                             getTargetName(), configContext);
565         return target.getConfigRef();
566     }
567
568     ObjectName JavaDoc getHttpService() throws Exception JavaDoc
569     {
570         return new ObjectName JavaDoc(
571             getTestDomain() +
572             ":type=http-service,category=config,config=" + getConfigRef());
573     }
574
575     ObjectName JavaDoc getConfigMBean() throws Exception JavaDoc
576     {
577         return new ObjectName JavaDoc(
578             getTestDomain() +
579             ":type=config,category=config,name=" + getConfigRef());
580     }
581
582     ObjectName JavaDoc getHttpListener() throws Exception JavaDoc
583     {
584         return new ObjectName JavaDoc(
585             getTestDomain() +
586             ":type=http-listener,category=config,id=mylistener,config=" +
587             getConfigRef());
588     }
589
590     ObjectName JavaDoc getHttpListener(String JavaDoc listenerId) throws Exception JavaDoc
591     {
592         return new ObjectName JavaDoc(
593             getTestDomain() +
594             ":type=http-listener,category=config,id=" + listenerId +
595             ",config=" + getConfigRef());
596     }
597
598     ObjectName JavaDoc getIiopListener() throws Exception JavaDoc
599     {
600         return new ObjectName JavaDoc(
601             getTestDomain() +
602             ":type=iiop-listener,category=config,id=mylistener,config=" +
603             getConfigRef());
604     }
605
606     ObjectName JavaDoc getVirtualServer() throws Exception JavaDoc
607     {
608         return new ObjectName JavaDoc(
609             getTestDomain() +
610             ":type=virtual-server,category=config,id=my-virtual-server,config="
611             + getConfigRef());
612     }
613
614     ObjectName JavaDoc getAuthRealm(String JavaDoc name) throws Exception JavaDoc
615     {
616         return new ObjectName JavaDoc(
617             getTestDomain() +
618             ":type=auth-realm,category=config,config=" + getConfigRef() +
619             ",name=" + name);
620     }
621
622     ObjectName JavaDoc getProfiler() throws Exception JavaDoc
623     {
624         return new ObjectName JavaDoc(
625             getTestDomain() +
626             ":type=profiler,category=config,config=" + getConfigRef());
627     }
628
629     ObjectName JavaDoc getAuditModule(String JavaDoc name) throws Exception JavaDoc
630     {
631         return new ObjectName JavaDoc(
632             getTestDomain() +
633             ":type=audit-module,category=config,config=" + getConfigRef() +
634             ",name=" + name);
635     }
636
637     ObjectName JavaDoc getJmsHost(String JavaDoc name) throws Exception JavaDoc
638     {
639         return new ObjectName JavaDoc(
640             getTestDomain() +
641             ":type=jms-host,category=config,config=" + getConfigRef() +
642             ",name=" + name);
643     }
644
645     ObjectName JavaDoc getJaccProvider(String JavaDoc name) throws Exception JavaDoc
646     {
647         return new ObjectName JavaDoc(
648             getTestDomain() +
649             ":type=jacc-provider,category=config,config=" + getConfigRef() +
650             ",name=" + name);
651     }
652
653     ObjectName JavaDoc getEjbContainer() throws Exception JavaDoc
654     {
655         return new ObjectName JavaDoc(
656             getTestDomain() +
657             ":type=ejb-container,category=config,config=" + getConfigRef());
658     }
659
660     ObjectName JavaDoc getSsl(String JavaDoc type, String JavaDoc id) throws Exception JavaDoc
661     {
662         String JavaDoc on = getTestDomain() + ":type=ssl,category=config,config=" +
663                     getConfigRef();
664         on += "iiop-service".equals(type) ? "" : ("," + type + '=' + id);
665         return new ObjectName JavaDoc(on);
666     }
667
668     ObjectName JavaDoc getThreadPool(String JavaDoc threadPoolId) throws Exception JavaDoc
669     {
670         return new ObjectName JavaDoc(
671             getTestDomain() +
672             ":type=thread-pool,category=config,config=" + getConfigRef() +
673             ",thread-pool-id=" + threadPoolId);
674     }
675
676     ObjectName JavaDoc getObjectName1(String JavaDoc type, String JavaDoc loc) throws Exception JavaDoc
677     {
678         return getObjectName(type, new String JavaDoc[] {loc});
679     }
680
681     ObjectName JavaDoc getObjectName2(String JavaDoc type, String JavaDoc loc1, String JavaDoc loc2)
682         throws Exception JavaDoc
683     {
684         return getObjectName(type, new String JavaDoc[] {loc1, loc2});
685     }
686
687     ObjectName JavaDoc getObjectName(String JavaDoc type, String JavaDoc[] loc) throws Exception JavaDoc
688     {
689         if (null == loc) { loc = new String JavaDoc[0]; }
690         String JavaDoc[] oTokens = new String JavaDoc[loc.length + 2];
691         oTokens[0] = getTestDomain();
692         oTokens[1] = getConfigRef();
693         for (int i = 2; i < oTokens.length; i++)
694         {
695             oTokens[i] = loc[i-2];
696         }
697         return mbeanRegistry.getMbeanObjectName(type, oTokens);
698     }
699
700     boolean exists(Object JavaDoc on, Object JavaDoc[] names)
701     {
702         for (int i = 0; i < names.length; i++)
703         {
704             if (names[i].equals(on))
705             {
706                 return true;
707             }
708         }
709         return false;
710     }
711
712     private String JavaDoc getTargetName()
713     {
714         return null;
715     }
716
717     private Target getTarget() throws Exception JavaDoc
718     {
719         return TargetBuilder.INSTANCE.createTarget(getTargetName(),
720                     configContext);
721     }
722
723     private Properties JavaDoc getProperties()
724     {
725         Properties JavaDoc props = new Properties JavaDoc();
726         props.put("prop1", "val1");
727         return props;
728     }
729
730     private String JavaDoc getTestDomain()
731     {
732         return "testdomain";
733     }
734
735     private class MyConfigsMBean extends ConfigsMBean
736     {
737         private MBeanServer JavaDoc mbeanServer;
738
739         public ConfigContext getConfigContext()
740         {
741             return configContext;
742         }
743
744         public MBeanServer JavaDoc getMBeanServer() throws MBeanException JavaDoc
745         {
746             if (mbeanServer == null)
747             {
748                 mbeanServer = javax.management.MBeanServerFactory.
749                                     createMBeanServer();
750             }
751             return mbeanServer;
752         }
753
754         protected void postInvoke(String JavaDoc opName, Object JavaDoc ret)
755             throws MBeanException JavaDoc
756         {
757             try
758             {
759                 if (ret instanceof ObjectName JavaDoc)
760                 {
761                     ObjectName JavaDoc on = (ObjectName JavaDoc)ret;
762                     if (!getMBeanServer().isRegistered(on))
763                     {
764                         BaseAdminMBean mbean =
765                             mbeanRegistry.instantiateConfigMBean(
766                                         on, null, getConfigContext());
767                         getMBeanServer().registerMBean(mbean, on);
768                     }
769                 }
770                 flush();
771             }
772             catch (Exception JavaDoc e)
773             {
774                 throw MBeanExceptionFormatter.toMBeanException(e, null);
775             }
776         }
777
778         private void flush() throws MBeanException JavaDoc
779         {
780             try
781             {
782                 final ConfigContext cctx = getConfigContext();
783                 if (cctx.isChanged())
784                 {
785                     cctx.flush();
786                 }
787             }
788             catch (Exception JavaDoc e)
789             {
790                 throw MBeanExceptionFormatter.toMBeanException(e, null);
791             }
792         }
793
794         public String JavaDoc getDomainName()
795         {
796             return getTestDomain();
797         }
798     }
799 }
Popular Tags