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: * @(#)TestComponentRegistry.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.ComponentInfo;
032: import com.sun.jbi.ComponentState;
033: import com.sun.jbi.ComponentType;
034:
035: import java.util.ArrayList;
036: import java.util.List;
037:
038: /**
039: * Tests the ComponentRegistry class.
040: *
041: * @author Sun Microsystems, Inc.
042: */
043: public class TestComponentRegistry extends junit.framework.TestCase {
044: /**
045: * Current test name.
046: */
047: private String mTestName;
048:
049: /**
050: * Value of the $SRCROOT environment variable
051: */
052: private String mSrcroot;
053:
054: /**
055: * Local handle to the EnvironmentContext
056: */
057: private EnvironmentContext mContext;
058:
059: /**
060: * The EnvironmentSetup helper class
061: */
062: private EnvironmentSetup mSetup;
063:
064: /**
065: * Local handle to the ComponentRegistry class
066: */
067: private ComponentRegistry mCompReg;
068:
069: /**
070: * Local instance of the Component class
071: */
072: private Component mBinding;
073:
074: /**
075: * Local instance of the Component class
076: */
077: private Component mEngine;
078:
079: /**
080: * Local instance of the SharedLibrary class
081: */
082: private SharedLibrary mSl1;
083:
084: /**
085: * Local instance of the SharedLibrary class
086: */
087: private SharedLibrary mSl2;
088:
089: /**
090: * Constant for test results
091: */
092: static final int THREE = 3;
093:
094: /**
095: * Constant for test results
096: */
097: static final int FOUR = 4;
098:
099: /**
100: * Constant for BC component ID
101: */
102: static final String BC_ID = "BC01";
103:
104: /**
105: * Constant for BC bootstrap class name
106: */
107: static final String BC_BOOTSTRAP_CLASS_NAME = "com.sun.jbi.framework.BindingBootstrap";
108:
109: /**
110: * Constant for BC bootstrap class path
111: */
112: static final String BC_BOOTSTRAP_CLASS_PATH = "framework/bld/com/sun/jbi/framework/";
113:
114: /**
115: * Constant for BC life cycle class name
116: */
117: static final String BC_LIFECYCLE_CLASS_NAME = "com.sun.jbi.framework.Binding";
118:
119: /**
120: * Constant for BC life cycle class path
121: */
122: static final String BC_LIFECYCLE_CLASS_PATH = "framework/bld/com/sun/jbi/framework/";
123: /**
124: * Constant for SE component ID
125: */
126: static final String SE_ID = "SE01";
127:
128: /**
129: * Constant for SE bootstrap class name
130: */
131: static final String SE_BOOTSTRAP_CLASS_NAME = "com.sun.jbi.framework.EngineBootstrap";
132:
133: /**
134: * Constant for SE bootstrap class path
135: */
136: static final String SE_BOOTSTRAP_CLASS_PATH = "framework/bld/com/sun/jbi/framework/";
137:
138: /**
139: * Constant for SE life cycle class name
140: */
141: static final String SE_LIFECYCLE_CLASS_NAME = "com.sun.jbi.framework.Engine";
142:
143: /**
144: * Constant for SE life cycle class path
145: */
146: static final String SE_LIFECYCLE_CLASS_PATH = "framework/bld/com/sun/jbi/framework/";
147:
148: /**
149: * Constant for Shared Library 1
150: */
151: static final String SHARED_LIBRARY_1 = "SL01";
152:
153: /**
154: * Constant for Shared Library 2
155: */
156: static final String SHARED_LIBRARY_2 = "SL02";
157:
158: /**
159: * Constant for Service Assembly 1
160: */
161: static final String SA_NAME_1 = "SA01";
162:
163: /**
164: * Constant for Service Assembly 2
165: */
166: static final String SA_NAME_2 = "SA02";
167:
168: /**
169: * Constant for Service Unit 1
170: */
171: static final String SU_NAME_1 = "SU01";
172:
173: /**
174: * Constant for Service Unit 1 root file path
175: */
176: static final String SU_PATH_1 = "framework/bld/com/sun/jbi/framework/su01.xml";
177:
178: /**
179: * Constant for Service Unit 2
180: */
181: static final String SU_NAME_2 = "SU02";
182:
183: /**
184: * Constant for Service Unit 2 root file path
185: */
186: static final String SU_PATH_2 = "framework/bld/com/sun/jbi/framework/su02.xml";
187:
188: /**
189: * The constructor for this testcase, forwards the test name to
190: * the jUnit TestCase base class.
191: * @param aTestName String with the name of this test.
192: */
193: public TestComponentRegistry(String aTestName) {
194: super (aTestName);
195: mTestName = aTestName;
196: }
197:
198: /**
199: * Setup for the test. This creates the ComponentRegistry instance
200: * and other objects needed for the tests.
201: * @throws Exception when set up fails for any reason.
202: */
203: public void setUp() throws Exception {
204: super .setUp();
205: System.err.println("***** START of test " + mTestName);
206: mSrcroot = System.getProperty("junit.srcroot") + "/";
207:
208: // Create EnvironmentContext and ComponentRegistry, and initialize
209: // and start the ComponentRegistry
210: mSetup = new EnvironmentSetup();
211: mContext = mSetup.getEnvironmentContext();
212: mSetup.startup(true, false);
213: mCompReg = mContext.getComponentRegistry();
214:
215: // Create a Component instance for a binding component
216:
217: mBinding = new Component();
218: mBinding.setName(BC_ID);
219: mBinding.setComponentType(ComponentType.BINDING);
220: mBinding.setBootstrapClassName(BC_BOOTSTRAP_CLASS_NAME);
221: ArrayList bcBootClassPath = new ArrayList();
222: bcBootClassPath.add(mSrcroot + BC_BOOTSTRAP_CLASS_PATH);
223: mBinding.setBootstrapClassPathElements(bcBootClassPath);
224: mBinding.setComponentClassName(BC_LIFECYCLE_CLASS_NAME);
225: ArrayList bcLifeClassPath = new ArrayList();
226: bcLifeClassPath.add(mSrcroot + BC_LIFECYCLE_CLASS_PATH);
227: mBinding.setComponentClassPathElements(bcLifeClassPath);
228: mBinding.setInstallRoot("C:/BC01");
229: mBinding.setWorkspaceRoot("C:/BC01");
230:
231: // Create a Component instance for a service engine
232:
233: mEngine = new Component();
234: mEngine.setName(SE_ID);
235: mEngine.setComponentType(ComponentType.ENGINE);
236: mEngine.setBootstrapClassName(SE_BOOTSTRAP_CLASS_NAME);
237: ArrayList bpeBootClassPath = new ArrayList();
238: bpeBootClassPath.add(mSrcroot + SE_BOOTSTRAP_CLASS_PATH);
239: mEngine.setBootstrapClassPathElements(bpeBootClassPath);
240: mEngine.setComponentClassName(SE_LIFECYCLE_CLASS_NAME);
241: ArrayList bpeLifeClassPath = new ArrayList();
242: bpeLifeClassPath.add(mSrcroot + SE_LIFECYCLE_CLASS_PATH);
243: mEngine.setComponentClassPathElements(bpeLifeClassPath);
244: mEngine.setInstallRoot("C:/SE01");
245: mEngine.setWorkspaceRoot("C:/SE01");
246:
247: // Create SharedLibrary instances for two Shared Libraries
248:
249: ArrayList cp1 = new ArrayList();
250: cp1.add("C:/d/jbi/antbld/lib/sl01.jar");
251: cp1.add("C:/d/jbi/framework/bld/com/sun/jbi/framework");
252: mSl1 = new SharedLibrary(SHARED_LIBRARY_1,
253: "Framework library and classes", "/SHARED_LIBRARY_1",
254: cp1);
255:
256: ArrayList cp2 = new ArrayList();
257: cp2.add("C:/d/jbi/antbld/lib/sl02.jar");
258: mSl2 = new SharedLibrary(SHARED_LIBRARY_2,
259: "Shared library jar file", "/SHARED_LIBRARY_2", cp2);
260: }
261:
262: /**
263: * Cleanup for the test.
264: * @throws Exception when tearDown fails for any reason.
265: */
266: public void tearDown() throws Exception {
267: super .tearDown();
268: mSetup.shutdown(true, false);
269: System.err.println("***** END of test " + mTestName);
270: }
271:
272: // ============================= test methods ================================
273:
274: // ----------------------------------------------------------------------------
275: // First, test the registration methods, as the other tests depend upon
276: // these to set up their test data.
277: // ----------------------------------------------------------------------------
278:
279: /**
280: * Tests registerComponent with a good result.
281: * @throws Exception if an unexpected error occurs.
282: */
283: public void testRegisterComponentGood() throws Exception {
284: mCompReg.registerComponent(mBinding);
285: mCompReg.registerComponent(mEngine);
286: assertTrue("Failure registering component", mCompReg
287: .isComponentRegistered(BC_ID));
288: assertTrue("Failure registering component", mCompReg
289: .isComponentRegistered(SE_ID));
290: }
291:
292: /**
293: * Tests registerComponent with a null component parameter. An exception
294: * is expected.
295: * @throws Exception if an unexpected error occurs.
296: */
297: public void testRegisterComponentBadInput() throws Exception {
298: try {
299: mCompReg.registerComponent(null);
300: fail("Expected exception not received");
301: } catch (java.lang.IllegalArgumentException ex) {
302: // Verification
303: assertTrue("Unexpected exception received: "
304: + ex.toString(), (-1 < ex.getMessage().indexOf(
305: "Null argument")));
306: }
307: }
308:
309: /**
310: * Tests registerComponent with a duplicate Component. An exception is
311: * expected.
312: * @throws Exception if an unexpected error occurs.
313: */
314: public void testRegisterComponentBadDuplicate() throws Exception {
315: try {
316: // Attempt to register the same component twice
317: mCompReg.registerComponent(mBinding);
318: mCompReg.registerComponent(mBinding);
319: fail("Expected exception not received");
320: } catch (javax.jbi.JBIException ex) {
321: // Verification
322: assertTrue("Unexpected exception received: "
323: + ex.toString(), (-1 < ex.getMessage().indexOf(
324: "already registered")));
325: }
326: }
327:
328: /**
329: * Tests registerSharedLibrary with a good result.
330: * @throws Exception if an unexpected error occurs.
331: */
332: public void testRegisterSharedLibraryGood() throws Exception {
333: mCompReg.registerSharedLibrary(mSl1);
334: mCompReg.registerSharedLibrary(mSl2);
335: assertTrue("Failure registering shared library", mCompReg
336: .isSharedLibraryRegistered(SHARED_LIBRARY_1));
337: assertTrue("Failure registering shared library", mCompReg
338: .isSharedLibraryRegistered(SHARED_LIBRARY_2));
339: }
340:
341: /**
342: * Tests registerSharedLibrary with a null SharedLibrary parameter. An
343: * exception is expected.
344: * @throws Exception if an unexpected error occurs.
345: */
346: public void testRegisterSharedLibraryBadInput() throws Exception {
347: try {
348: mCompReg.registerSharedLibrary(null);
349: fail("Expected exception not received");
350: } catch (java.lang.IllegalArgumentException ex) {
351: // Verification
352: assertTrue("Unexpected exception received: "
353: + ex.toString(), (-1 < ex.getMessage().indexOf(
354: "Null argument")));
355: }
356: }
357:
358: /**
359: * Tests registerSharedLibrary with a duplicate SharedLibrary. An exception
360: * is expected.
361: * @throws Exception if an unexpected error occurs.
362: */
363: public void testRegisterSharedLibraryBadDuplicate()
364: throws Exception {
365: try {
366: // Try to register the same SharedLibrary twice
367: mCompReg.registerSharedLibrary(mSl1);
368: mCompReg.registerSharedLibrary(mSl1);
369: fail("Expected exception not received");
370: } catch (javax.jbi.JBIException ex) {
371: // Verification
372: assertTrue("Unexpected exception received: "
373: + ex.toString(), (-1 < ex.getMessage().indexOf(
374: "already registered")));
375: }
376: }
377:
378: // ----------------------------------------------------------------------------
379: // Test methods that are part of the ServiceUnitRegistration interface.
380: // ----------------------------------------------------------------------------
381:
382: /**
383: * Tests registerServiceUnit with a good result.
384: * @throws Exception if an unexpected error occurs.
385: */
386: public void testRegisterServiceUnitGood() throws Exception {
387: mCompReg.registerComponent(mBinding);
388: mCompReg.registerServiceUnit(BC_ID, SA_NAME_1, SU_NAME_1,
389: SU_PATH_1);
390: assertTrue("Failure registering Service Unit 1", mCompReg
391: .isServiceUnitRegistered(BC_ID, SU_NAME_1));
392: mCompReg.registerServiceUnit(BC_ID, SA_NAME_1, SU_NAME_2,
393: SU_PATH_2);
394: assertTrue("Failure registering Service Unit 2", mCompReg
395: .isServiceUnitRegistered(BC_ID, SU_NAME_2));
396: }
397:
398: /**
399: * Tests registerServiceUnit with a null input parameter. An exception
400: * is expected.
401: * @throws Exception if an unexpected error occurs.
402: */
403: public void testRegisterServiceUnitBadInput() throws Exception {
404: try {
405: mCompReg.registerServiceUnit(null, SA_NAME_1, SU_NAME_1,
406: SU_PATH_1);
407: fail("Expected exception not received");
408: } catch (java.lang.IllegalArgumentException ex) {
409: // Verification
410: assertTrue("Unexpected exception received: "
411: + ex.toString(), (-1 < ex.getMessage().indexOf(
412: "Null argument")));
413: }
414: try {
415: mCompReg.registerServiceUnit(BC_ID, null, SU_NAME_1,
416: SU_PATH_1);
417: fail("Expected exception not received");
418: } catch (java.lang.IllegalArgumentException ex) {
419: // Verification
420: assertTrue("Unexpected exception received: "
421: + ex.toString(), (-1 < ex.getMessage().indexOf(
422: "Null argument")));
423: }
424: try {
425: mCompReg.registerServiceUnit(BC_ID, SA_NAME_1, null,
426: SU_PATH_1);
427: fail("Expected exception not received");
428: } catch (java.lang.IllegalArgumentException ex) {
429: // Verification
430: assertTrue("Unexpected exception received: "
431: + ex.toString(), (-1 < ex.getMessage().indexOf(
432: "Null argument")));
433: }
434: try {
435: mCompReg.registerServiceUnit(BC_ID, SA_NAME_1, SU_NAME_1,
436: null);
437: fail("Expected exception not received");
438: } catch (java.lang.IllegalArgumentException ex) {
439: // Verification
440: assertTrue("Unexpected exception received: "
441: + ex.toString(), (-1 < ex.getMessage().indexOf(
442: "Null argument")));
443: }
444: }
445:
446: /**
447: * Tests registerServiceUnit with a duplicate Service Unit. An exception is
448: * expected.
449: * @throws Exception if an unexpected error occurs.
450: */
451: public void testRegisterServiceUnitBadDuplicate() throws Exception {
452: mCompReg.registerComponent(mBinding);
453: try {
454: // Attempt to register the same Service Unit twice
455: mCompReg.registerServiceUnit(BC_ID, SA_NAME_1, SU_NAME_1,
456: SU_PATH_1);
457: mCompReg.registerServiceUnit(BC_ID, SA_NAME_1, SU_NAME_1,
458: SU_PATH_1);
459: fail("Expected exception not received");
460: } catch (javax.jbi.JBIException ex) {
461: // Verification
462: assertTrue("Unexpected exception received: "
463: + ex.toString(), (-1 < ex.getMessage().indexOf(
464: "JBIFW2400")));
465: }
466: }
467:
468: /**
469: * Tests registerServiceUnit with a nonexistent Component. An exception is
470: * expected.
471: * @throws Exception if an unexpected error occurs.
472: */
473: public void testRegisterServiceUnitBadNotFound() throws Exception {
474: try {
475: mCompReg.registerServiceUnit(BC_ID, SA_NAME_1, SU_NAME_1,
476: SU_PATH_1);
477: fail("Expected exception not received");
478: } catch (javax.jbi.JBIException ex) {
479: // Verification
480: assertTrue("Unexpected exception received: "
481: + ex.toString(), (-1 < ex.getMessage().indexOf(
482: "No component")));
483: }
484: }
485:
486: /**
487: * Tests unregisterServiceUnit with a good result.
488: * @throws Exception if an unexpected error occurs.
489: */
490: public void testUnregisterServiceUnitGood() throws Exception {
491: mCompReg.registerComponent(mEngine);
492: mCompReg.registerServiceUnit(SE_ID, SA_NAME_1, SU_NAME_1,
493: SU_PATH_1);
494: mCompReg.registerComponent(mBinding);
495: mCompReg.registerServiceUnit(BC_ID, SA_NAME_2, SU_NAME_2,
496: SU_PATH_2);
497: mCompReg.unregisterServiceUnit(BC_ID, SU_NAME_2);
498: assertFalse("Failure unregistering Service Unit 2", mCompReg
499: .isServiceUnitRegistered(BC_ID, SU_NAME_2));
500: mCompReg.unregisterServiceUnit(SE_ID, SU_NAME_1);
501: assertFalse("Failure unregistering Service Unit 1", mCompReg
502: .isServiceUnitRegistered(SE_ID, SU_NAME_1));
503: }
504:
505: /**
506: * Tests unregisterServiceUnit with null parameters. An
507: * exception is expected.
508: * @throws Exception if an unexpected error occurs.
509: */
510: public void testUnregisterServiceUnitBadInput() throws Exception {
511: try {
512: mCompReg.unregisterServiceUnit(null, SU_NAME_1);
513: fail("Expected exception not received");
514: } catch (java.lang.IllegalArgumentException ex) {
515: // Verification
516: assertTrue("Unexpected exception received: "
517: + ex.toString(), (-1 < ex.getMessage().indexOf(
518: "Null argument")));
519: }
520: try {
521: mCompReg.unregisterServiceUnit(BC_ID, null);
522: fail("Expected exception not received");
523: } catch (java.lang.IllegalArgumentException ex) {
524: // Verification
525: assertTrue("Unexpected exception received: "
526: + ex.toString(), (-1 < ex.getMessage().indexOf(
527: "Null argument")));
528: }
529: }
530:
531: /**
532: * Tests unregisterServiceUnit with a Service Unit name that is not
533: * registered.
534: * An exception is expected.
535: * @throws Exception if an unexpected error occurs.
536: */
537: public void testUnregisterServiceUnitBadNotRegistered()
538: throws Exception {
539: mCompReg.registerComponent(mBinding);
540: try {
541: mCompReg.unregisterServiceUnit(BC_ID, SU_NAME_1);
542: fail("Expected exception not received");
543: } catch (javax.jbi.JBIException ex) {
544: // Verification
545: assertTrue("Unexpected exception received: "
546: + ex.toString(), (-1 < ex.getMessage().indexOf(
547: "not found for")));
548: }
549: }
550:
551: /**
552: * Tests unregisterServiceUnit with a Component name that does not exist.
553: * An exception is expected.
554: * @throws Exception if an unexpected error occurs.
555: */
556: public void testUnregisterServiceUnitBadNotFound() throws Exception {
557: try {
558: mCompReg.unregisterServiceUnit(BC_ID, SU_NAME_1);
559: fail("Expected exception not received");
560: } catch (javax.jbi.JBIException ex) {
561: // Verification
562: assertTrue("Unexpected exception received: "
563: + ex.toString(), (-1 < ex.getMessage().indexOf(
564: "No component")));
565: }
566: }
567:
568: // ----------------------------------------------------------------------------
569: // Test methods that are not accessible outside the framework.
570: // ----------------------------------------------------------------------------
571:
572: /**
573: * Tests getComponent with a good result.
574: * @throws Exception if an unexpected error occurs.
575: */
576: public void testGetComponentGood() throws Exception {
577: Component comp = null;
578:
579: // Test that a null is returned when the component does not exist
580: comp = mCompReg.getComponent(BC_ID);
581: assertNull("Failure getting component: "
582: + "expected null return value , got non-null", comp);
583:
584: // Test that the correct component is returned
585: mCompReg.registerComponent(mBinding);
586: mCompReg.registerComponent(mEngine);
587: comp = mCompReg.getComponent(BC_ID);
588: assertNotNull("Failure getting component: "
589: + "expected non-null return value, got null", comp);
590: assertEquals(
591: "Failure getting component, returned object incorrect: ",
592: mBinding, comp);
593: }
594:
595: /**
596: * Tests getComponent with a null component ID parameter. An exception
597: * is expected.
598: * @throws Exception if an unexpected error occurs.
599: */
600: public void testGetComponentBadInput() throws Exception {
601: try {
602: Component comp = null;
603: comp = mCompReg.getComponent(null);
604: fail("Expected exception not received");
605: } catch (java.lang.IllegalArgumentException ex) {
606: // Verification
607: assertTrue("Unexpected exception received: "
608: + ex.toString(), (-1 < ex.getMessage().indexOf(
609: "Null argument")));
610: }
611: }
612:
613: /**
614: * Tests getSharedLibrary with a good result.
615: * @throws Exception if an unexpected error occurs.
616: */
617: public void testGetSharedLibrary() throws Exception {
618: SharedLibrary sl1 = null;
619: SharedLibrary sl2 = null;
620: sl1 = mCompReg.getSharedLibrary(SHARED_LIBRARY_1);
621: assertNull("Failure getting shared library: "
622: + "expected null return value , got non-null", sl1);
623: mCompReg.registerSharedLibrary(mSl1);
624: mCompReg.registerSharedLibrary(mSl2);
625: sl2 = mCompReg.getSharedLibrary(SHARED_LIBRARY_2);
626: sl1 = mCompReg.getSharedLibrary(SHARED_LIBRARY_1);
627: assertNotNull("Failure getting shared library: "
628: + "expected non-null return value, got null", sl1);
629: assertEquals(
630: "Failure getting shared library, returned object incorrect: ",
631: mSl1, sl1);
632: assertNotNull("Failure getting shared library: "
633: + "expected non-null return value, got null", sl2);
634: assertEquals(
635: "Failure getting shared library, returned object incorrect: ",
636: mSl2, sl2);
637: }
638:
639: /**
640: * Tests getSharedLibrary with a null componentId parameter. An exception
641: * is expected.
642: * @throws Exception if an unexpected error occurs.
643: */
644: public void testGetSharedLibraryBadInput() throws Exception {
645: try {
646: SharedLibrary sl = null;
647: sl = mCompReg.getSharedLibrary(null);
648: fail("Expected exception not received");
649: } catch (java.lang.IllegalArgumentException ex) {
650: // Verification
651: assertTrue("Unexpected exception received: "
652: + ex.toString(), (-1 < ex.getMessage().indexOf(
653: "Null argument")));
654: }
655: }
656:
657: /**
658: * Tests getStatus with a good result.
659: * @throws Exception if an unexpected error occurs.
660: */
661: public void testgetStatusGood() throws Exception {
662: ComponentState status;
663:
664: // Register component for test.
665: mCompReg.registerComponent(mBinding);
666:
667: mBinding.setStatus(ComponentState.LOADED);
668: status = mCompReg.getStatus(BC_ID);
669: assertEquals("Incorrect status received for " + BC_ID + ": "
670: + "expected " + ComponentState.LOADED.toString()
671: + ", got " + status.toString(), status,
672: ComponentState.LOADED);
673:
674: mBinding.setStatus(ComponentState.SHUTDOWN);
675: status = mCompReg.getStatus(BC_ID);
676: assertEquals("Incorrect status received for " + BC_ID + ": "
677: + "expected " + ComponentState.SHUTDOWN.toString()
678: + ", got " + status.toString(), status,
679: ComponentState.SHUTDOWN);
680:
681: mBinding.setStatus(ComponentState.STOPPED);
682: status = mCompReg.getStatus(BC_ID);
683: assertEquals("Incorrect status received for " + BC_ID + ": "
684: + "expected " + ComponentState.STOPPED.toString()
685: + ", got " + status.toString(), status,
686: ComponentState.STOPPED);
687:
688: mBinding.setStatus(ComponentState.STARTED);
689: status = mCompReg.getStatus(BC_ID);
690: assertEquals("Incorrect status received for " + BC_ID + ": "
691: + "expected " + ComponentState.STARTED.toString()
692: + ", got " + status.toString(), status,
693: ComponentState.STARTED);
694: }
695:
696: /**
697: * Tests getStatus with a null argument. An exception is expected.
698: * @throws Exception if an unexpected error occurs.
699: */
700: public void testgetStatusBadNull() throws Exception {
701: ComponentState status;
702: try {
703: status = mCompReg.getStatus(null);
704: fail("Expected exception not received");
705: } catch (java.lang.IllegalArgumentException ex) {
706: // Verification
707: assertTrue("Unexpected exception received: "
708: + ex.toString(), (-1 < ex.getMessage().indexOf(
709: "Null argument")));
710: }
711: }
712:
713: /**
714: * Tests getStatus with a component ID that is not registered. An exception
715: * is expected.
716: * @throws Exception if an unexpected error occurs.
717: */
718: public void testgetStatusBadNotFound() throws Exception {
719: ComponentState status;
720: try {
721: status = mCompReg.getStatus(BC_ID);
722: fail("Expected exception not received");
723: } catch (javax.jbi.JBIException ex) {
724: // Verification
725: assertTrue("Unexpected exception received: "
726: + ex.toString(), (-1 < ex.getMessage().indexOf(
727: "No component"))
728: && (-1 < ex.getMessage().indexOf("is registered")));
729: }
730: }
731:
732: /**
733: * Tests isComponentRegistered with a good result.
734: * @throws Exception if an unexpected error occurs.
735: */
736: public void testIsComponentRegisteredGood() throws Exception {
737: assertFalse("Failure checking component status: "
738: + "expected false return value , got true", mCompReg
739: .isComponentRegistered(BC_ID));
740: mCompReg.registerComponent(mBinding);
741: assertTrue("Failure checking component status: "
742: + "expected true return value, got false", mCompReg
743: .isComponentRegistered(BC_ID));
744: }
745:
746: /**
747: * Tests isComponentRegistered with a null component ID parameter. An
748: * exception is expected.
749: * @throws Exception if an unexpected error occurs.
750: */
751: public void testIsComponentRegisteredBadInput() throws Exception {
752: try {
753: mCompReg.isComponentRegistered(null);
754: fail("Expected exception not received");
755: } catch (java.lang.IllegalArgumentException ex) {
756: // Verification
757: assertTrue("Unexpected exception received: "
758: + ex.toString(), (-1 < ex.getMessage().indexOf(
759: "Null argument")));
760: }
761: }
762:
763: /**
764: * Tests isSharedLibraryRegistered with a good result.
765: * @throws Exception if an unexpected error occurs.
766: */
767: public void testIsSharedLibraryRegisteredGood() throws Exception {
768: assertFalse("Failure checking shared library status: "
769: + "expected false return value , got true", mCompReg
770: .isSharedLibraryRegistered(SHARED_LIBRARY_1));
771: mCompReg.registerSharedLibrary(mSl1);
772: assertTrue("Failure checking shared library status: "
773: + "expected true return value, got false", mCompReg
774: .isSharedLibraryRegistered(SHARED_LIBRARY_1));
775: }
776:
777: /**
778: * Tests isSharedLibraryRegistered with a null shared library name
779: * parameter. An exception is expected.
780: * @throws Exception if an unexpected error occurs.
781: */
782: public void testIsSharedLibraryRegisteredBadInput()
783: throws Exception {
784: try {
785: mCompReg.isSharedLibraryRegistered(null);
786: fail("Expected exception not received");
787: } catch (java.lang.IllegalArgumentException ex) {
788: // Verification
789: assertTrue("Unexpected exception received: "
790: + ex.toString(), (-1 < ex.getMessage().indexOf(
791: "Null argument")));
792: }
793: }
794:
795: /**
796: * Tests unregisterComponent with a good result.
797: * @throws Exception if an unexpected error occurs.
798: */
799: public void testUnregisterComponentGood() throws Exception {
800: mCompReg.registerComponent(mEngine);
801: mCompReg.registerComponent(mBinding);
802: mCompReg.unregisterComponent(BC_ID);
803: assertFalse("Failure unregistering binding", mCompReg
804: .isComponentRegistered(BC_ID));
805: mCompReg.unregisterComponent(SE_ID);
806: assertFalse("Failure unregistering engine", mCompReg
807: .isComponentRegistered(SE_ID));
808: }
809:
810: /**
811: * Tests unregisterComponent with a null component ID parameter. An
812: * exception is expected.
813: * @throws Exception if an unexpected error occurs.
814: */
815: public void testUnregisterComponentBadInput() throws Exception {
816: try {
817: mCompReg.unregisterComponent(null);
818: fail("Expected exception not received");
819: } catch (java.lang.IllegalArgumentException ex) {
820: // Verification
821: assertTrue("Unexpected exception received: "
822: + ex.toString(), (-1 < ex.getMessage().indexOf(
823: "Null argument")));
824: }
825: }
826:
827: /**
828: * Tests unregisterComponent with a component ID that is not registered.
829: * An exception is expected.
830: * @throws Exception if an unexpected error occurs.
831: */
832: public void testUnregisterComponentBadNotRegistered()
833: throws Exception {
834: try {
835: mCompReg.unregisterComponent(BC_ID);
836: fail("Expected exception not received");
837: } catch (javax.jbi.JBIException ex) {
838: // Verification
839: assertTrue("Unexpected exception received: "
840: + ex.toString(), (-1 < ex.getMessage().indexOf(
841: "No component")));
842: }
843: }
844:
845: /**
846: * Tests unregisterSharedLibrary with a good result.
847: * @throws Exception if an unexpected error occurs.
848: */
849: public void testUnregisterSharedLibraryGood() throws Exception {
850: mCompReg.registerSharedLibrary(mSl1);
851: mCompReg.unregisterSharedLibrary(SHARED_LIBRARY_1);
852: assertFalse("Failure unregistering shared library", mCompReg
853: .isSharedLibraryRegistered(SHARED_LIBRARY_1));
854: }
855:
856: /**
857: * Tests unregisterSharedLibrary with a null shared library name parameter.
858: * An exception is expected.
859: * @throws Exception if an unexpected error occurs.
860: */
861: public void testUnregisterSharedLibraryBadInput() throws Exception {
862: try {
863: mCompReg.unregisterSharedLibrary(null);
864: fail("Expected exception not received");
865: } catch (java.lang.IllegalArgumentException ex) {
866: // Verification
867: assertTrue("Unexpected exception received: "
868: + ex.toString(), (-1 < ex.getMessage().indexOf(
869: "Null argument")));
870: }
871: }
872:
873: /**
874: * Tests unregisterSharedLibrary with a shared library name that is not
875: * registered. An exception is expected.
876: * @throws Exception if an unexpected error occurs.
877: */
878: public void testUnregisterSharedLibraryBadNotRegistered()
879: throws Exception {
880: try {
881: mCompReg.unregisterSharedLibrary(SHARED_LIBRARY_1);
882: fail("Expected exception not received");
883: } catch (javax.jbi.JBIException ex) {
884: // Verification
885: assertTrue("Unexpected exception received: "
886: + ex.toString(), (-1 < ex.getMessage().indexOf(
887: "No Shared Library")));
888: }
889: }
890:
891: }
|