KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jmx > test > DeployServiceUnitTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.jmx.test;
23
24 import java.io.File JavaDoc;
25 import java.net.URL JavaDoc;
26 import java.util.Collection JavaDoc;
27 import javax.management.ObjectInstance JavaDoc;
28 import javax.management.ObjectName JavaDoc;
29 import javax.management.ReflectionException JavaDoc;
30
31 import org.jboss.deployment.IncompleteDeploymentException;
32 import org.jboss.test.JBossTestCase;
33
34 /**
35  * @author <a HREF="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
36  * @author Scott.Stark@jboss.org
37  * @version $Revision: 37406 $
38  */

39 public class DeployServiceUnitTestCase
40        extends JBossTestCase
41 {
42    // Constants -----------------------------------------------------
43
protected final static int INSTALLED = 0;
44    protected final static int CONFIGURED = 1;
45    protected final static int CREATED = 2;
46    protected final static int RUNNING = 3;
47    protected final static int FAILED = 4;
48    protected final static int STOPPED = 5;
49    protected final static int DESTROYED = 6;
50    protected final static int NOTYETINSTALLED = 7;
51    // Attributes ----------------------------------------------------
52

53    ObjectName JavaDoc serviceControllerName;
54    // Static --------------------------------------------------------
55
// Constructors --------------------------------------------------
56
/**
57     * Constructor for the DeployServiceUnitTestCase object
58     *
59     * @param name Test case name
60     */

61    public DeployServiceUnitTestCase(String JavaDoc name)
62    {
63       super(name);
64       try
65       {
66          serviceControllerName = new ObjectName JavaDoc("jboss.system:service=ServiceController");
67       }
68       catch (Exception JavaDoc e)
69       {
70       } // end of try-catch
71

72    }
73
74    // Public --------------------------------------------------------
75

76    /**
77     * Test deployment and undeployment of *-service.xml files. Make sure mbeans
78     * are removed on undeployment
79     *
80     * @exception Exception Description of Exception
81     */

82    public void testDeployXML() throws Exception JavaDoc
83    {
84       // The class loader used to locate the configuration file
85
ClassLoader JavaDoc loader = Thread.currentThread().getContextClassLoader();
86       assertTrue("ContextClassloader missing", loader != null);
87       //Get URL for deployable *service.xml file in resources
88
URL JavaDoc url = loader.getResource("jmx/test-service.xml");
89       if (url == null)
90       {
91          //if we're running from the jmxtest.jar, it should be here instead
92
url = loader.getResource("test-service.xml");
93       }
94       assertTrue("resource test-service.xml not found", url != null);
95       String JavaDoc testUrl = url.toString();
96
97       //the mbeans we are trying to deploy/undeploy
98
ObjectName JavaDoc testObjectName = new ObjectName JavaDoc("jboss.test:service=TestService,test=jmx");
99       //check they aren't there already
100
//Well, lets try to kill it.
101
if (getServer().isRegistered(testObjectName))
102       {
103          getServer().unregisterMBean(testObjectName);
104       } // end of if ()
105

106       assertTrue("test mbean already registered before deploy", !getServer().isRegistered(testObjectName));
107
108       //deploy the test xml doc.
109
deploy(testUrl);
110
111       //check deployment registered expected mbeans
112
assertTrue("test mbean not registered after deploy", checkState(testObjectName, RUNNING));
113
114       //deploy the test xml doc again, should undeploy and redeploy.
115
undeploy(testUrl);
116       deploy(testUrl);
117
118       //check deployment registered expected mbeans
119
assertTrue("test mbean not registered after redeploy", checkState(testObjectName, RUNNING));
120
121       //undeploy test xml doc.
122
undeploy(testUrl);
123
124       //check they aren't there any more
125
assertTrue("test mbean still registered after undeploy", !getServer().isRegistered(testObjectName));
126
127    }
128
129    /** Test that a spaces in the classpath element archives attribute do not
130     * affect the classpath seen.
131     * @throws Exception
132     */

133    public void testSpaceInClasspath() throws Exception JavaDoc
134    {
135       getLog().debug("+++ testSpaceInClasspath");
136       //deploy the test xml doc.
137
deploy("archivestest-service.xml");
138       ObjectName JavaDoc testObjectName = new ObjectName JavaDoc("test:name=TestSpaceInClasspath");
139       //check deployment registered expected mbeans
140
assertTrue(testObjectName+" registered", checkState(testObjectName, RUNNING));
141       undeploy("archivestest-service.xml");
142    }
143
144    /**
145     * Test deployment and undeployment of a service archive (sar). Test that
146     * after undeployment classes from the sar are not available.
147     *
148     * @exception Exception Description of Exception
149     */

150    public void testDeploySAR() throws Exception JavaDoc
151    {
152       //Find the testdeploy.sar file in lib directory with other jars.
153

154       String JavaDoc testUrl = "testdeploy.sar";
155       getLog().debug("testUrl is : " + testUrl);
156
157       //the mbeans we are trying to deploy/undeploy
158
ObjectName JavaDoc testObjectName = new ObjectName JavaDoc("test:name=TestDeployer");
159       ObjectName JavaDoc testObjectName2 = new ObjectName JavaDoc("test:name=TestDeployer2");
160       ObjectName JavaDoc testObjectName3 = new ObjectName JavaDoc("test:name=TestDeployer3");
161       //check they aren't there already
162
assertTrue("test mbean already registered before deploy", !getServer().isRegistered(testObjectName));
163
164       //deploy the test xml doc.
165
deploy(testUrl);
166
167       //check deployment registered expected mbeans
168
assertTrue("test mbean not registered after deploy", checkState(testObjectName, RUNNING));
169
170       //make sure we can create an mbean based on the class we just deployed.
171
try
172       {
173          getServer().createMBean("org.jboss.test.jmx.mbean.TestDeployer", testObjectName2);
174       }
175       catch (Exception JavaDoc e)
176       {
177          fail("could not create mbean after class loaded in jsr" + e);
178       }
179       //now remove it again
180
try
181       {
182          getServer().unregisterMBean(testObjectName2);
183       }
184       catch (Exception JavaDoc e)
185       {
186          fail("could not remove mbean after class loaded in jsr" + e);
187       }
188       //deploy the test xml doc again, should undeploy and redeploy.
189
undeploy(testUrl);
190       deploy(testUrl);
191
192       //check deployment registered expected mbeans
193
assertTrue("test mbean not registered after redeploy", checkState(testObjectName, RUNNING));
194
195       //undeploy test xml doc.
196
undeploy(testUrl);
197
198       //check they aren't there any more
199
assertTrue("test mbean still registered after undeploy", !getServer().isRegistered(testObjectName));
200
201       //check the class is not available
202
try
203       {
204          ObjectInstance JavaDoc oe = getServer().createMBean("org.jboss.test.jmx.mbean.TestDeployer", testObjectName3);
205          fail("created mbean when class should not be present: object instance: " + oe);
206       }
207       catch (ReflectionException JavaDoc re)
208       {
209          Exception JavaDoc e = re.getTargetException();
210          if (!(e instanceof ClassNotFoundException JavaDoc))
211          {
212             fail("Wrong exception thrown when trying to create mbean" + e);
213          }
214       }
215
216       //deploy the test xml doc a second time.
217
deploy(testUrl);
218
219       //check deployment registered expected mbeans
220
assertTrue("test mbean not registered after deploy", checkState(testObjectName, RUNNING));
221
222       //undeploy test xml doc.
223
undeploy(testUrl);
224
225       //check they aren't there any more
226
assertTrue("test mbean still registered after undeploy", !getServer().isRegistered(testObjectName));
227
228    }
229
230    /**
231     * Test deployment and undeployment of a service archive (sar). Test that
232     * after undeployment classes from the sar are not available.
233     *
234     * @exception Exception Description of Exception
235     */

236    public void testDeploySARWithJar() throws Exception JavaDoc
237    {
238       String JavaDoc testUrl = "testdeploye.sar";
239       getLog().debug("testUrl is : " + testUrl);
240
241       ObjectName JavaDoc testObjectName = new ObjectName JavaDoc("test:name=TestDeployerE");
242       deploy(testUrl);
243
244       // See that deployment registered expected mbeans
245
assertTrue("test:name=TestDeployerE is registered after deploy",
246          checkState(testObjectName, RUNNING));
247
248       // Invoke the accessUtilClass operation
249
Object JavaDoc[] args = {};
250       String JavaDoc[] sig = {};
251       getServer().invoke(testObjectName, "accessUtilClass", args, sig);
252
253       //make sure we can create an mbean based on the class we just deployed.
254
ObjectName JavaDoc testObjectName2 = new ObjectName JavaDoc("test:name=TestDeployerE#2");
255       getServer().createMBean("org.jboss.test.jmx.mbeane.TestDeployerE", testObjectName2);
256
257       // Remove the instance
258
getServer().unregisterMBean(testObjectName2);
259
260       undeploy(testUrl);
261    }
262
263    /**
264     * Test some deployment/undeployment dependencies for sars. C depends on A
265     * and B. Make sure undeploying A undeploys C, and redeploying A redeploys C.
266     *
267     * @exception Exception Description of Exception
268     */

269    public void testDependsElement() throws Exception JavaDoc
270    {
271       //C depends on A and B
272
//Find the testdeploy[ABC].sar files in lib directory with other jars.
273

274       String JavaDoc testUrlA = "testdeploya.sar";
275       String JavaDoc testUrlB = "testdeployb.sar";
276       String JavaDoc testUrlC = "testdeployc.sar";
277       getLog().debug("testUrlA is : " + testUrlA);
278
279       //the mbeans we are trying to deploy/undeploy
280
ObjectName JavaDoc testObjectNameA = new ObjectName JavaDoc("test:name=TestDeployerA");
281       ObjectName JavaDoc testObjectNameB = new ObjectName JavaDoc("test:name=TestDeployerB");
282       ObjectName JavaDoc testObjectNameC = new ObjectName JavaDoc("test:name=TestDeployerC");
283       try
284       {
285          //check they aren't there already
286
assertTrue("test mbean already registered before deploy", !getServer().isRegistered(testObjectNameA));
287          assertTrue("test mbean already registered before deploy", !getServer().isRegistered(testObjectNameB));
288          assertTrue("test mbean already registered before deploy", !getServer().isRegistered(testObjectNameC));
289
290          //deploy the test jsrs.
291
deploy(testUrlA);
292          deploy(testUrlB);
293          deploy(testUrlC);
294
295          //check deployment registered expected mbeans
296
assertTrue("test mbean A not running after deploy", checkState(testObjectNameA, RUNNING));
297          assertTrue("test mbean B not running after deploy", checkState(testObjectNameB, RUNNING));
298          assertTrue("test mbean C not running after deploy", checkState(testObjectNameC, RUNNING));
299
300          //we'll believe from testDeployJSR that the classes are available.
301

302          //undeploy test xml doc.
303
undeploy(testUrlA);
304
305          //check they aren't there any more or they have stopped.
306
assertTrue("test mbean A still registered after undeploy of A", !getServer().isRegistered(testObjectNameA));
307          assertTrue("test mbean C not stopped after undeploy of A", !checkState(testObjectNameC, RUNNING));
308          assertTrue("test mbean B stopped after undeploy of A", checkState(testObjectNameB, RUNNING));
309
310          //Now undeploy B, should prevent redeploy of C when A is redeployed.
311

312          // not working, skip for now
313
undeploy(testUrlB);
314          assertTrue("test mbean B is registered after undeploy of B", !getServer().isRegistered(testObjectNameB));
315
316          //deploy the test jsr A doc a second time.
317
deploy(testUrlA);
318
319          // check deployment registered expected mbeans
320
assertTrue("test mbean A not registered after deploy of A", checkState(testObjectNameA, RUNNING));
321          assertTrue("test mbean B is registered after deploy of A", !getServer().isRegistered(testObjectNameB));
322          assertTrue("test mbean C started after deploy of A, with B unregistered", !checkState(testObjectNameC, RUNNING));
323
324          //now redeploy B, should also redeploy C
325
deploy(testUrlB);
326          //check deployment registered expected mbeans- all three should be registered
327
assertTrue("test mbean A not running after deploy of B", checkState(testObjectNameA, RUNNING));
328          assertTrue("test mbean B not running after deploy of B", checkState(testObjectNameB, RUNNING));
329          assertTrue("test mbean C not running after deploy of B", checkState(testObjectNameC, RUNNING));
330
331          //undeploy test xml doc.
332
undeploy(testUrlC);
333          undeploy(testUrlA);
334          undeploy(testUrlB);
335
336          //check they aren't there any more
337
assertTrue("test mbean still registered after undeploy", !getServer().isRegistered(testObjectNameA));
338          assertTrue("test mbean still registered after undeploy", !getServer().isRegistered(testObjectNameB));
339          assertTrue("test mbean still registered after undeploy", !getServer().isRegistered(testObjectNameC));
340       }
341       finally
342       {
343          undeploy(testUrlC);
344          undeploy(testUrlA);
345          undeploy(testUrlB);
346       }
347
348    }
349
350    /**
351     * Test depends tag D depends on mbeans in A and C.
352     * Deploying D should wait for A and C; undeploying A and/or C should
353     * undeploy D's mbean. Redeploying both should resuscitate D's mbean.
354     *
355     * @exception Exception Description of Exception
356     */

357    public void testDependsListElement() throws Exception JavaDoc
358    {
359       //C depends on A and B via anonymous depends element.
360
//D depends on A and C via anonymous dependsList.
361
//Find the testdeploy[ABC].sar files in lib directory with other jars.
362

363       String JavaDoc testUrlA = "testdeploya.sar";
364       String JavaDoc testUrlB = "testdeployb.sar";
365       String JavaDoc testUrlC = "testdeployc.sar";
366       String JavaDoc testUrlD = "testdeployd.sar";
367       getLog().debug("testUrlA is : " + testUrlA);
368
369       //the mbeans we are trying to deploy/undeploy
370
ObjectName JavaDoc testObjectNameA = new ObjectName JavaDoc("test:name=TestDeployerA");
371       ObjectName JavaDoc testObjectNameB = new ObjectName JavaDoc("test:name=TestDeployerB");
372       ObjectName JavaDoc testObjectNameC = new ObjectName JavaDoc("test:name=TestDeployerC");
373       ObjectName JavaDoc testObjectNameD = new ObjectName JavaDoc("test:name=TestDeployerD");
374       try
375       {
376          //check they aren't there already
377
assertTrue("test mbean a already registered before deploy", !getServer().isRegistered(testObjectNameA));
378          assertTrue("test mbean b already registered before deploy", !getServer().isRegistered(testObjectNameB));
379          assertTrue("test mbean c already registered before deploy", !getServer().isRegistered(testObjectNameC));
380          assertTrue("test mbean d already registered before deploy", !getServer().isRegistered(testObjectNameD));
381
382          //deploy the test jsrs.
383
try
384          {
385             deploy(testUrlD);
386             fail("D deployed without dependencies");
387
388          }
389          catch (IncompleteDeploymentException e)
390          {
391             //expected
392
} // end of try-catch
393

394
395          assertTrue("test mbean D started with A, B, and C unregistered", !checkState(testObjectNameD, RUNNING));
396
397
398          //deploy A.
399
deploy(testUrlA);
400          //A should be started, not anything else
401
assertTrue("test mbean A not started", checkState(testObjectNameA, RUNNING));
402          assertTrue("test mbean D started with A, B, and C unregistered", !checkState(testObjectNameD, RUNNING));
403
404          //Deploy C, should not start since B is not deployed
405
try
406          {
407             deploy(testUrlC);
408             fail("C deployed completely, D should still be waiting");
409          }
410          catch (IncompleteDeploymentException e)
411          {
412             //expected
413
} // end of try-catch
414
assertTrue("test mbean C started with B unregistered", !checkState(testObjectNameC, RUNNING));
415
416
417
418          //deploy the test bean B. C and D should start too.
419
deploy(testUrlB);
420          assertTrue("test mbean A not started", checkState(testObjectNameA, RUNNING));
421          assertTrue("test mbean B not started", checkState(testObjectNameB, RUNNING));
422          assertTrue("test mbean C not started", checkState(testObjectNameC, RUNNING));
423          assertTrue("test mbean D not started", checkState(testObjectNameD, RUNNING));
424
425
426          //undeploy test xml doc.
427
undeploy(testUrlA);
428          assertTrue("test mbean A present after undeploy", !getServer().isRegistered(testObjectNameA));
429          assertTrue("test mbean B not started after undeploy of A", checkState(testObjectNameB, RUNNING));
430          assertTrue("test mbean C started after undeploy of A", !checkState(testObjectNameC, RUNNING));
431          assertTrue("test mbean D started after undeploy of A", !checkState(testObjectNameD, RUNNING));
432          undeploy(testUrlC);
433          undeploy(testUrlB);
434          undeploy(testUrlD);
435
436          //check they aren't there any more
437
Collection JavaDoc ds = (Collection JavaDoc)getServer().invoke(serviceControllerName,
438                                                   "listDeployedNames",
439                                                   new Object JavaDoc[] {},
440                                                   new String JavaDoc[] {});
441          assertTrue("test mbean A still registered after undeploy", !ds.contains(testObjectNameA));
442
443          assertTrue("test mbean B still registered after undeploy", !ds.contains(testObjectNameB));
444
445          assertTrue("test mbean C still registered after undeploy", !ds.contains(testObjectNameC));
446          assertTrue("test mbean D still registered after undeploy", !ds.contains(testObjectNameD));
447       }
448       finally
449       {
450          try
451          {
452             undeploy(testUrlD);
453          }
454          catch (Exception JavaDoc e)
455          {
456          }
457          try
458          {
459             undeploy(testUrlC);
460          }
461          catch (Exception JavaDoc e)
462          {
463          }
464          try
465          {
466             undeploy(testUrlA);
467          }
468          catch (Exception JavaDoc e)
469          {
470          }
471          try
472          {
473             undeploy(testUrlB);
474          }
475          catch (Exception JavaDoc e)
476          {
477          }
478
479       }
480
481    }
482
483     /**
484      * The <code>testCopyLocalDir</code> method tests the local-directory element
485      * in jboss-system.xml.
486      *
487      * @exception Exception if an error occurs
488      */

489    /*Needs a package not recognized as possibly deployable
490    public void testCopyLocalDir() throws Exception
491    {
492
493       String testUrl = "testcopylocaldir.sar";
494       getLog().debug("testUrl is : " + testUrl);
495
496       //the mbeans we are trying to deploy/undeploy
497       ObjectName testObjectName = new ObjectName("test:name=TestCopyLocalDir");
498       try
499       {
500          //check they aren't there already
501          assertTrue("test mbean already registered before deploy", !getServer().isRegistered(testObjectName));
502
503          //deploy C
504          deploy(testUrl);
505          String base = (String)getServer().getAttribute(testObjectName, "BaseDir");
506          File f = new File(base + File.separator + "db" + File.separator + "local-directory");
507          //local dir should still be there after undeploy.
508          undeploy(testUrl);
509          assertTrue("local-directory not found!", f.exists());
510          File[] subs = f.listFiles();
511          assertTrue("Subdir missing!", subs.length != 0);
512
513
514          //delete it, redeploy, check again - it might have been there before we deployed.
515          recursiveDelete(f);
516          deploy(testUrl);
517          assertTrue("local-directory not found!", f.exists());
518          subs = f.listFiles();
519          assertTrue("Subdir missing!", subs.length != 0);
520          recursiveDelete(f);
521       }
522       finally
523       {
524          undeploy(testUrl);
525       } // end of finally
526    }
527    */

528
529    public void testConfigureError() throws Exception JavaDoc
530    {
531
532       String JavaDoc testUrl = "testdeploy.sar";
533       getLog().debug("testUrl is : " + testUrl);
534
535       //deploy sar
536
deploy(testUrl);
537       try
538       {
539          //deploy service.xml with a nonexistent attribute to cause
540
//a configuration error
541
String JavaDoc errorUrl = "testConfigError-service.xml";
542          String JavaDoc fixedUrl = "testConfigFixed-service.xml";
543          ObjectName JavaDoc errorObjectName = new ObjectName JavaDoc("test:name=TestConfigError");
544          try
545          {
546             deploy(errorUrl);
547          } catch (Exception JavaDoc e)
548          {
549             //??
550
getLog().info("deploying errorUrl gave exception: ", e);
551          } // end of try-catch
552

553          if (getServer().isRegistered(errorObjectName))
554          {
555             System.out.println("Erroneous mbean state: " + (Integer JavaDoc)getServer().getAttribute(errorObjectName, "State"));
556             //assertTrue("Erroneous mbean is not failed!", checkState(errorObjectName, FAILED));
557
} // end of if ()
558

559          //the mbeans we are trying to deploy/undeploy
560
try
561          {
562             undeploy(errorUrl);
563
564
565          } catch (Exception JavaDoc e)
566          {
567
568          } // end of try-catch
569

570          try
571          {
572             deploy(fixedUrl);
573             assertTrue("Corrected mbean is not registered!", checkState(errorObjectName, RUNNING));
574
575          } finally
576          {
577             undeploy(fixedUrl);
578          } // end of try-catch
579
} finally
580       {
581          undeploy(testUrl);
582       } // end of try-catch
583

584    }
585
586
587    public void testCrashInStart() throws Exception JavaDoc
588    //Thanks to David Budworth for this test.
589
{
590       String JavaDoc testUrl = "testcrashinstart.sar";
591       getLog().debug("testUrl is : " + testUrl);
592       ObjectName JavaDoc dontCrashName = new ObjectName JavaDoc("CrashTest:name=DontCrash");
593       ObjectName JavaDoc crashName = new ObjectName JavaDoc("CrashTest:name=Crash");
594
595       //deploy sar
596
try
597       {
598          deploy(testUrl);
599          fail("expected IncompleteDeploymentException");
600       }
601       catch (IncompleteDeploymentException e)
602       {
603          //expected
604
} // end of try-catch
605

606
607       try
608       {
609          assertTrue("dontcrash mbean is missing!", getServer().isRegistered(dontCrashName));
610          assertTrue("crash mbean is missing!", getServer().isRegistered(crashName));
611
612          assertTrue("dontcrash mbean is started!", !getServer().getAttribute(dontCrashName, "StateString").equals("Started"));
613          assertTrue("crash mbean is started!", !getServer().getAttribute(crashName, "StateString").equals("Started"));
614
615          undeploy(testUrl);
616          assertTrue("dontcrash mbean is registered!", !getServer().isRegistered(dontCrashName));
617          assertTrue("crash mbean is registered!", !getServer().isRegistered(crashName));
618
619       } finally
620       {
621          undeploy(testUrl);
622       } // end of try-catch
623

624    }
625
626
627    public void testNullInfoInDynamicMBean() throws Exception JavaDoc
628    //Thanks to David Budworth for this test.
629
//Tries to deploy a DynamicMBean that returns null from getMBeanInfo.
630
//The Sun RI jmx registers this invalid mbean!!
631
{
632       String JavaDoc testUrl = "testnullinfo.sar";
633       getLog().debug("testUrl is : " + testUrl);
634       ObjectName JavaDoc nullInfoName = new ObjectName JavaDoc("NullInfoTest:name=NullInfo");
635       //deploy sar
636
try
637       {
638          deploy(testUrl);
639          fail("Was able to deploy invalid sar");
640       }
641       catch(Exception JavaDoc e)
642       {
643          getLog().debug("Deployment failed as expected", e);
644          boolean isRegistered = getServer().isRegistered(nullInfoName);
645          assertTrue("NullInfoTest:name=NullInfo is NOT registered", !isRegistered);
646       }
647       finally
648       {
649          try
650          {
651             undeploy(testUrl);
652          }
653          catch (Exception JavaDoc e)
654          {
655          }
656
657          try
658          {
659             getServer().unregisterMBean(nullInfoName);
660          }
661          catch (Exception JavaDoc e)
662          {
663          }
664       } // end of try-catch
665

666    }
667
668    /** Test that a sar deployment descriptor that
669     */

670    public void testDDEntityRefs() throws Exception JavaDoc
671    {
672       String JavaDoc testUrl = "entityref.sar";
673       getLog().debug("testUrl is : " + testUrl);
674       //deploy sar
675
deploy(testUrl);
676       //check deployment registered expected mbeans
677
ObjectName JavaDoc name = new ObjectName JavaDoc("test:name=EntityRefTest");
678       assertTrue("test:name=EntityRefTest is registered after deploy", checkState(name, RUNNING));
679       undeploy(testUrl);
680    }
681
682    /** Test that a sar deployment that has its service class in the default
683     * package
684     */

685    public void testDefaultPkgService() throws Exception JavaDoc
686    {
687       String JavaDoc testUrl = "defaultpkg.sar";
688       getLog().debug("testUrl is : " + testUrl);
689       //deploy sar
690
deploy(testUrl);
691       //check deployment registered expected mbeans
692
ObjectName JavaDoc name = new ObjectName JavaDoc("test:name=DefaultPkgService");
693       assertTrue("test:name=DefaultPkgService is registered after deploy", checkState(name, RUNNING));
694       undeploy(testUrl);
695    }
696
697    public void testExplicitStandardInterfaceService() throws Exception JavaDoc
698    {
699       String JavaDoc testUrl = "explicit-standard-interface.sar";
700       getLog().debug("testUrl is : " + testUrl);
701       //deploy sar
702
deploy(testUrl);
703       //check deployment registered expected mbeans
704
ObjectName JavaDoc name = new ObjectName JavaDoc("test:name=TestStandardService");
705       assertTrue("test:name=TestStandardService is registered after deploy", checkState(name, RUNNING));
706       undeploy(testUrl);
707    }
708
709    protected boolean recursiveDelete(File JavaDoc f)
710    {
711       if (f.isDirectory())
712       {
713          File JavaDoc[] files = f.listFiles();
714          for (int i = 0; i < files.length; ++i)
715          {
716             if (!recursiveDelete(files[i]))
717             {
718                return false;
719             }
720          }
721       }
722       return f.delete();
723    }
724
725    protected boolean checkState(ObjectName JavaDoc mbean, int state) throws Exception JavaDoc
726    {
727       Integer JavaDoc mbeanState = (Integer JavaDoc)getServer().getAttribute(mbean, "State");
728       return state == mbeanState.intValue();
729    }
730
731 }
732
Popular Tags