001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)TestSharedLibrary.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.framework;
030:
031: import com.sun.jbi.framework.ScaffoldPlatformContext;
032: import java.util.ArrayList;
033: import java.util.List;
034: import java.util.Properties;
035: import com.sun.jbi.JBIProvider;
036: import com.sun.jbi.ComponentType;
037: import com.sun.jbi.ComponentState;
038:
039: /**
040: * Tests the SharedLibrary class.
041: *
042: * @author Sun Microsystems, Inc.
043: */
044: public class TestSharedLibrary extends junit.framework.TestCase {
045: /**
046: * Local instance of the EnvironmentContext
047: */
048: private EnvironmentContext mContext;
049:
050: /**
051: * Local instance of the SharedLibrary class
052: */
053: private SharedLibrary mSl1;
054:
055: /**
056: * Classpath String for Shared Library 1
057: */
058: private String mSl1ClassPath;
059:
060: /**
061: * Classpath element list for Shared Library 1
062: */
063: private ArrayList mSl1ClassPathElements;
064:
065: /**
066: * Local instance of the SharedLibrary class
067: */
068: private SharedLibrary mSl2;
069:
070: /**
071: * Classpath String for Shared Library 2
072: */
073: private String mSl2ClassPath;
074:
075: /**
076: * Classpath element list for Shared Library 2
077: */
078: private ArrayList mSl2ClassPathElements;
079:
080: /**
081: * Local instance of the SharedLibrary class
082: */
083: private SharedLibrary mSl3;
084:
085: /**
086: * Classpath String for Shared Library 3
087: */
088: private String mSl3ClassPath;
089:
090: /**
091: * Classpath element list for Shared Library 3
092: */
093: private ArrayList mSl3ClassPathElements;
094:
095: /**
096: * Constant for Shared Library 1 unique ID
097: */
098: static final String SL_1 = "SL01";
099:
100: /**
101: * Constant for Shared Library 1 description
102: */
103: static final String SL_1_DESC = "Spacely Sprockets library namespace";
104:
105: /**
106: * Constant for Shared Library 1 root directory
107: */
108: static final String SL_1_ROOT = "/SL01";
109:
110: /**
111: * Constant for Shared Library 1 classpath element
112: */
113: static final String SL_1_CP_1 = "/com/spacely/sprockets/jetson.jar/";
114:
115: /**
116: * Constant for Shared Library 2 unique ID
117: */
118: static final String SL_2 = "SL02";
119:
120: /**
121: * Constant for Shared Library 2 description
122: */
123: static final String SL_2_DESC = "Acme Rocket Company library namespace";
124:
125: /**
126: * Constant for Shared Library 2 root directory
127: */
128: static final String SL_2_ROOT = "/SL02";
129:
130: /**
131: * Constant for Shared Library 2 classpath element
132: */
133: static final String SL_2_CP_1 = "/com/acme/rocket/classes/";
134:
135: /**
136: * Constant for Shared Library 2 classpath element
137: */
138: static final String SL_2_CP_2 = "/com/acme/rocket/lib/fuel.jar";
139:
140: /**
141: * Constant for Shared Library 3 unique ID
142: */
143: static final String SL_3 = "SL03";
144:
145: /**
146: * Constant for Shared Library 3 description
147: */
148: static final String SL_3_DESC = "Flinstones family library";
149:
150: /**
151: * Constant for Shared Library 3 root directory
152: */
153: static final String SL_3_ROOT = "/SL03";
154:
155: /**
156: * Constant for Shared Library 3 classpath element
157: */
158: static final String SL_3_CP_1 = "/com/flint/stone/lib/fred.jar";
159:
160: /**
161: * Constant for Shared Library 3 classpath element
162: */
163: static final String SL_3_CP_2 = "/com/flint/stone/lib/wilma.jar";
164:
165: /**
166: * Constant for Shared Library 3 classpath element
167: */
168: static final String SL_3_CP_3 = "/com/flint/stone/lib/pebbles.jar";
169:
170: /**
171: * The constructor for this testcase, forwards the test name to
172: * the jUnit TestCase base class.
173: * @param aTestName String with the name of this test.
174: */
175: public TestSharedLibrary(String aTestName) {
176: super (aTestName);
177: }
178:
179: /**
180: * Setup for the test. This creates the SharedLibrary instances
181: * and other objects needed for the tests. It also serves to test
182: * the constructor for the class.
183: * @throws Exception when set up fails for any reason.
184: */
185: public void setUp() throws Exception {
186: super .setUp();
187: mContext = new EnvironmentContext(
188: new ScaffoldPlatformContext(), new JBIFramework(),
189: new Properties());
190:
191: String sep = System.getProperty("path.separator");
192:
193: // Create a SharedLibrary with a single-element class path
194:
195: mSl1ClassPath = new String(SL_1_CP_1);
196: mSl1ClassPathElements = new ArrayList();
197: mSl1ClassPathElements.add(SL_1_CP_1);
198: mSl1 = new SharedLibrary(SL_1, SL_1_DESC, SL_1_ROOT, true,
199: mSl1ClassPathElements);
200:
201: // Create a SharedLibrary with a two-element class path
202:
203: mSl2ClassPath = new String(SL_2_CP_1 + sep + SL_2_CP_2);
204: mSl2ClassPathElements = new ArrayList();
205: mSl2ClassPathElements.add(SL_2_CP_1);
206: mSl2ClassPathElements.add(SL_2_CP_2);
207: mSl2 = new SharedLibrary(SL_2, SL_2_DESC, SL_2_ROOT, false,
208: mSl2ClassPathElements);
209:
210: // Create a SharedLibrary with a three-element class path
211:
212: mSl3ClassPath = new String(SL_3_CP_1 + sep + SL_3_CP_2 + sep
213: + SL_3_CP_3);
214: mSl3ClassPathElements = new ArrayList();
215: mSl3ClassPathElements.add(SL_3_CP_1);
216: mSl3ClassPathElements.add(SL_3_CP_2);
217: mSl3ClassPathElements.add(SL_3_CP_3);
218: mSl3 = new SharedLibrary(SL_3, SL_3_DESC, SL_3_ROOT,
219: mSl3ClassPathElements);
220: }
221:
222: /**
223: * Cleanup for the test.
224: * @throws Exception when tearDown fails for any reason.
225: */
226: public void tearDown() throws Exception {
227: super .tearDown();
228: }
229:
230: // ============================= test methods ================================
231:
232: /**
233: * Tests getClassPath with good results.
234: * @throws Exception if an unexpected error occurs.
235: */
236: public void testGetClassPathAsString() throws Exception {
237: String cp1 = mSl1.getClassPathAsString();
238: String cp2 = mSl2.getClassPathAsString();
239: String cp3 = mSl3.getClassPathAsString();
240:
241: assertEquals("Got wrong classpath: ", mSl1ClassPath, cp1);
242: assertEquals("Got wrong classpath: ", mSl2ClassPath, cp2);
243: assertEquals("Got wrong classpath: ", mSl3ClassPath, cp3);
244: }
245:
246: /**
247: * Tests getClassPathElements with good results.
248: * @throws Exception if an unexpected error occurs.
249: */
250: public void testGetClassPathElements() throws Exception {
251: List cpList1 = mSl1.getClassPathElements();
252: List cpList2 = mSl2.getClassPathElements();
253: List cpList3 = mSl3.getClassPathElements();
254:
255: assertEquals("Got wrong classpath elements list: ",
256: mSl1ClassPathElements, cpList1);
257: assertEquals("Got wrong classpath elements list: ",
258: mSl2ClassPathElements, cpList2);
259: assertEquals("Got wrong classpath elements list: ",
260: mSl3ClassPathElements, cpList3);
261: }
262:
263: /**
264: * Tests getComponentClassName with good results.
265: * @throws Exception if an unexpected error occurs.
266: */
267: public void testGetComponentClassName() throws Exception {
268: String name = mSl1.getComponentClassName();
269:
270: assertNull("Got wrong ComponentClassName, expected null, got "
271: + name, name);
272: }
273:
274: /**
275: * Tests getComponentType with good results.
276: * @throws Exception if an unexpected error occurs.
277: */
278: public void testGetComponentType() throws Exception {
279: ComponentType type = mSl1.getComponentType();
280:
281: assertEquals("Got incorrect component type: ",
282: ComponentType.SHARED_LIBRARY, type);
283: }
284:
285: /**
286: * Tests getDescription with good results.
287: * @throws Exception if an unexpected error occurs.
288: */
289: public void testGetDescription() throws Exception {
290: String desc = mSl1.getDescription();
291:
292: assertEquals("Got incorrect description: ", SL_1_DESC, desc);
293: }
294:
295: /**
296: * Tests getInstallRoot with good results.
297: * @throws Exception if an unexpected error occurs.
298: */
299: public void testGetInstallRoot() throws Exception {
300: String root = mSl1.getInstallRoot();
301:
302: assertEquals("Got incorrect install root: ", SL_1_ROOT, root);
303: }
304:
305: /**
306: * Tests getName with good results.
307: * @throws Exception if an unexpected error occurs.
308: */
309: public void testGetName() throws Exception {
310: String name = mSl1.getName();
311:
312: assertEquals("Got incorrect name: ", SL_1, name);
313: }
314:
315: /**
316: * Tests getSharedLibraryNames with good results.
317: * @throws Exception if an unexpected error occurs.
318: */
319: public void testGetSharedLibraryNames() throws Exception {
320: List list = mSl1.getSharedLibraryNames();
321:
322: assertNull("Got wrong SharedLibraryNames, expected null, got "
323: + list, list);
324: }
325:
326: /**
327: * Tests getStatus with good results.
328: * @throws Exception if an unexpected error occurs.
329: */
330: public void testGetStatus() throws Exception {
331: ComponentState status = mSl1.getStatus();
332:
333: assertEquals("Got incorrect status: ", ComponentState.SHUTDOWN,
334: status);
335: }
336:
337: /**
338: * Test the isClassLoaderSelfFirst method.
339: * @throws Exception if an unexpected error occurs.
340: */
341: public void testIsClassLoaderSelfFirst() throws Exception {
342: assertTrue("Failure in isClassLoaderSelfFirst: "
343: + "expected true, got false", mSl1
344: .isClassLoaderSelfFirst());
345: assertFalse("Failure in isClassLoaderSelfFirst: "
346: + "expected false, got true", mSl2
347: .isClassLoaderSelfFirst());
348: }
349:
350: /**
351: * Test the getBootstrapClassName method. It should always throw an
352: * exception.
353: * @throws Exception if an unexpected error occurs.
354: */
355: public void testGetBootstrapClassName() throws Exception {
356: try {
357: String cn = mSl1.getBootstrapClassName();
358: fail("Expected exception not received");
359: } catch (UnsupportedOperationException ex) {
360: } catch (Exception e) {
361: fail("Incorrect exception received");
362: }
363: }
364:
365: /**
366: * Test the getBootstrapClassPathElements method. It should always throw an
367: * exception.
368: * @throws Exception if an unexpected error occurs.
369: */
370: public void testGetBootstrapClassPathElements() throws Exception {
371: try {
372: java.util.List cp = mSl1.getBootstrapClassPathElements();
373: fail("Expected exception not received");
374: } catch (UnsupportedOperationException ex) {
375: } catch (Exception e) {
376: fail("Incorrect exception received");
377: }
378: }
379:
380: /**
381: * Test the getProperties method. It should always throw an exception.
382: * @throws Exception if an unexpected error occurs.
383: */
384: public void testGetProperties() throws Exception {
385: try {
386: java.util.Map p = mSl1.getProperties();
387: fail("Expected exception not received");
388: } catch (UnsupportedOperationException ex) {
389: } catch (Exception e) {
390: fail("Incorrect exception received");
391: }
392: }
393:
394: /**
395: * Test the getWorkspaceRoot method. It should always throw an exception.
396: * @throws Exception if an unexpected error occurs.
397: */
398: public void testGetWorkspaceRoot() throws Exception {
399: try {
400: String wr = mSl1.getWorkspaceRoot();
401: fail("Expected exception not received");
402: } catch (UnsupportedOperationException ex) {
403: } catch (Exception e) {
404: fail("Incorrect exception received");
405: }
406: }
407:
408: /**
409: * Test the isBootstrapClassLoaderSelfFirst method. It should always throw
410: * an exception.
411: * @throws Exception if an unexpected error occurs.
412: */
413: public void testIsBootstrapClassLoaderSelfFirst() throws Exception {
414: try {
415: boolean sf = mSl1.isBootstrapClassLoaderSelfFirst();
416: fail("Expected exception not received");
417: } catch (UnsupportedOperationException ex) {
418: } catch (Exception e) {
419: fail("Incorrect exception received");
420: }
421: }
422:
423: }
|