KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > classloader > test > ClasspathExtensionUnitTestCase


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.classloader.test;
23
24 import javax.management.Attribute JavaDoc;
25 import javax.management.ObjectName JavaDoc;
26
27 import junit.framework.Test;
28
29 import org.jboss.test.JBossTestCase;
30 import org.jboss.test.JBossTestSetup;
31
32 /**
33  * Unit tests for the org.jboss.deployment.ClasspathExtension
34  * @author Scott.Stark@jboss.org
35  * @version $Revision: 44687 $
36  */

37 public class ClasspathExtensionUnitTestCase extends JBossTestCase
38 {
39    ObjectName JavaDoc extension;
40
41    public ClasspathExtensionUnitTestCase(String JavaDoc name)
42    {
43       super(name);
44
45       try
46       {
47          extension = new ObjectName JavaDoc("jboss.test:test=ClasspathTest,mbean=extension");
48       }
49       catch (Exception JavaDoc ignored)
50       {
51       }
52    }
53
54    public void testClasspathExtension() throws Exception JavaDoc
55    {
56       assertTrue("Shouldn't find the resource before deployment", findResource() == false);
57       getServer().createMBean("org.jboss.deployment.ClasspathExtension", extension);
58       try
59       {
60          getServer().setAttribute(extension, new Attribute JavaDoc("MetadataURL", getDeployURL("").toString()));
61          getServer().invoke(extension, "create", new Object JavaDoc[0], new String JavaDoc[0]);
62          getServer().invoke(extension, "start", new Object JavaDoc[0], new String JavaDoc[0]);
63          assertTrue("Should find the resource after deployment", findResource());
64       }
65       finally
66       {
67          getServer().invoke(extension, "stop", new Object JavaDoc[0], new String JavaDoc[0]);
68          getServer().invoke(extension, "destroy", new Object JavaDoc[0], new String JavaDoc[0]);
69          getServer().unregisterMBean(extension);
70       }
71       assertTrue("Shouldn't find the resource after undeployment", findResource() == false);
72    }
73
74    private boolean findResource()
75       throws Exception JavaDoc
76    {
77       return ((Boolean JavaDoc) getServer().invoke(new ObjectName JavaDoc("jboss.test:test=ClasspathTest"), "findResource",
78          new Object JavaDoc[] { "classpath.sar" }, new String JavaDoc[] { String JavaDoc.class.getName() })).booleanValue();
79    }
80
81    public static Test suite() throws Exception JavaDoc
82    {
83       return new JBossTestSetup(getDeploySetup(ClasspathExtensionUnitTestCase.class, "classpath.sar"));
84    }
85 }
86
Popular Tags