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 org.jboss.test.classloader.test;
023:
024: import javax.management.MBeanException;
025: import javax.management.ObjectName;
026:
027: import org.jboss.test.JBossTestCase;
028: import org.jboss.system.ServiceMBean;
029:
030: /** Unit tests for the org.jboss.mx.loading.UnifiedLoaderRepository
031: * @author Scott.Stark@jboss.org
032: * @version $Revision: 57211 $
033: */
034: public class UnifiedLoaderUnitTestCase extends JBossTestCase {
035: public UnifiedLoaderUnitTestCase(String name) {
036: super (name);
037: }
038:
039: /** Test the UnifiedLoaderRepository for multi-threaded class loading
040: */
041: public void testClassLoadingMBean() throws Exception {
042: try {
043: deploy("concurrentloader.sar");
044: ObjectName testName = new ObjectName(
045: "jboss.test:name=ConcurrentLoader");
046: boolean isRegistered = getServer().isRegistered(testName);
047: assertTrue(testName + " isRegistered", isRegistered);
048: Integer state = (Integer) getServer().getAttribute(
049: testName, "State");
050: assertTrue("state.intValue() == ServiceMBean.STARTED",
051: state.intValue() == ServiceMBean.STARTED);
052: } finally {
053: undeploy("concurrentloader.sar");
054: } // end of try-finally
055: }
056:
057: /** Test the UnifiedLoaderRepository being accessed by thread with an
058: interrupted status
059: */
060: public void testInterruptedThreads() throws Exception {
061: try {
062: deploy("interrupt.sar");
063: ObjectName testName = new ObjectName(
064: "jboss.test:name=InterruptTest");
065: boolean isRegistered = getServer().isRegistered(testName);
066: assertTrue(testName + " isRegistered", isRegistered);
067: Integer state = (Integer) getServer().getAttribute(
068: testName, "State");
069: assertTrue("state.intValue() == ServiceMBean.STARTED",
070: state.intValue() == ServiceMBean.STARTED);
071: } finally {
072: undeploy("interrupt.sar");
073: } // end of try-finally
074: }
075:
076: /**
077: * Test the UnifiedLoaderRepository finding local and global resources
078: */
079: public void testResource() throws Exception {
080: try {
081: deploy("loadingresource.ear");
082: ObjectName testName = new ObjectName(
083: "jboss.test:name=LoadingResource");
084: boolean isRegistered = getServer().isRegistered(testName);
085: assertTrue(testName + " isRegistered", isRegistered);
086: Integer state = (Integer) getServer().getAttribute(
087: testName, "State");
088: assertTrue("state.intValue() == ServiceMBean.STARTED",
089: state.intValue() == ServiceMBean.STARTED);
090: } finally {
091: undeploy("loadingresource.ear");
092: } // end of try-finally
093: }
094:
095: public void testUnpackedResources() throws Exception {
096: deploy("unpacked/loadingresource1.ear");
097: deploy("unpacked/loadingresource2.ear");
098:
099: // Assert that the version1 LoadingResource service is started
100: ObjectName testName = new ObjectName(
101: "jboss.test:name=LoadingResource,version=1");
102: boolean isRegistered = getServer().isRegistered(testName);
103: assertTrue(testName + " isRegistered", isRegistered);
104: Integer state = (Integer) getServer().getAttribute(testName,
105: "State");
106: assertTrue("state.intValue() == ServiceMBean.STARTED", state
107: .intValue() == ServiceMBean.STARTED);
108:
109: // Assert that the version1 LoadingResource service is started
110: testName = new ObjectName(
111: "jboss.test:name=LoadingResource,version=2");
112: isRegistered = getServer().isRegistered(testName);
113: assertTrue(testName + " isRegistered", isRegistered);
114: state = (Integer) getServer().getAttribute(testName, "State");
115: assertTrue("state.intValue() == ServiceMBean.STARTED", state
116: .intValue() == ServiceMBean.STARTED);
117:
118: undeploy("unpacked/loadingresource1.ear");
119: undeploy("unpacked/loadingresource2.ear");
120: }
121:
122: public void testLoadingArrayClass() throws Exception {
123: deploy("loadingclazz.sar");
124:
125: ObjectName testName = new ObjectName(
126: "jboss.test:name=LoadingClazz");
127:
128: boolean isRegistered = getServer().isRegistered(testName);
129:
130: assertTrue(testName + " is registered", isRegistered);
131:
132: try {
133: try {
134: getServer().invoke(testName, "loadClass",
135: new Object[] { "[Ljava.lang.String;" },
136: new String[] { String.class.getName() });
137: } catch (MBeanException ex) {
138: Exception tex = ex.getTargetException();
139: if (tex instanceof ClassNotFoundException) {
140: fail("java.lang.String[] not found: "
141: + ex.getMessage());
142: } else {
143: throw tex;
144: }
145: }
146:
147: try {
148: getServer().invoke(testName, "loadClassFromTCL",
149: new Object[] { "[Ljava.lang.String;" },
150: new String[] { String.class.getName() });
151: } catch (MBeanException ex) {
152: Exception tex = ex.getTargetException();
153: if (tex instanceof ClassNotFoundException) {
154: fail("java.lang.String[] not found from TCL: "
155: + ex.getMessage());
156: } else {
157: throw tex;
158: }
159: }
160:
161: try {
162: getServer()
163: .invoke(
164: testName,
165: "loadClass",
166: new Object[] { "org.jboss.test.classloader.clazz.ClazzTest" },
167: new String[] { String.class.getName() });
168: } catch (MBeanException ex) {
169: Exception tex = ex.getTargetException();
170: if (tex instanceof ClassNotFoundException) {
171: fail("org.jboss.test.classloader.clazz.ClazzTest not found: "
172: + ex.getMessage());
173: } else {
174: throw tex;
175: }
176: }
177:
178: try {
179: getServer()
180: .invoke(
181: testName,
182: "loadClassFromTCL",
183: new Object[] { "org.jboss.test.classloader.clazz.ClazzTest" },
184: new String[] { String.class.getName() });
185: } catch (MBeanException ex) {
186: Exception tex = ex.getTargetException();
187: if (tex instanceof ClassNotFoundException) {
188: fail("org.jboss.test.classloader.clazz.ClazzTest not found from TCL: "
189: + ex.getMessage());
190: } else {
191: throw tex;
192: }
193: }
194:
195: try {
196: getServer()
197: .invoke(
198: testName,
199: "loadClass",
200: new Object[] { "[Lorg.jboss.test.classloader.clazz.ClazzTest;" },
201: new String[] { String.class.getName() });
202: } catch (MBeanException ex) {
203: Exception tex = ex.getTargetException();
204: if (tex instanceof ClassNotFoundException) {
205: fail("org.jboss.test.classloader.clazz.ClazzTest[] not found: "
206: + ex.getMessage());
207: } else {
208: throw tex;
209: }
210: }
211:
212: try {
213: getServer()
214: .invoke(
215: testName,
216: "loadClassFromTCL",
217: new Object[] { "[Lorg.jboss.test.classloader.clazz.ClazzTest;" },
218: new String[] { String.class.getName() });
219: } catch (MBeanException ex) {
220: Exception tex = ex.getTargetException();
221: if (tex instanceof ClassNotFoundException) {
222: fail("org.jboss.test.classloader.clazz.ClazzTest[] not found from TCL: "
223: + ex.getMessage());
224: } else {
225: throw tex;
226: }
227: }
228: } finally {
229: undeploy("loadingclazz.sar");
230: }
231: }
232:
233: protected void debug(String message) {
234: getLog().debug(message);
235: }
236: }
|