0001: /*
0002: * BEGIN_HEADER - DO NOT EDIT
0003: *
0004: * The contents of this file are subject to the terms
0005: * of the Common Development and Distribution License
0006: * (the "License"). You may not use this file except
0007: * in compliance with the License.
0008: *
0009: * You can obtain a copy of the license at
0010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
0011: * See the License for the specific language governing
0012: * permissions and limitations under the License.
0013: *
0014: * When distributing Covered Code, include this CDDL
0015: * HEADER in each file and include the License file at
0016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
0017: * If applicable add the following below this CDDL HEADER,
0018: * with the fields enclosed by brackets "[]" replaced with
0019: * your own identifying information: Portions Copyright
0020: * [year] [name of copyright owner]
0021: */
0022:
0023: /*
0024: * @(#)TestComponent.java
0025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
0026: *
0027: * END_HEADER - DO NOT EDIT
0028: */
0029: package com.sun.jbi.framework;
0030:
0031: import com.sun.jbi.ComponentState;
0032: import com.sun.jbi.ComponentType;
0033: import com.sun.jbi.JBIProvider;
0034:
0035: import java.io.ByteArrayInputStream;
0036: import java.io.File;
0037:
0038: import java.net.URL;
0039: import java.net.URLClassLoader;
0040:
0041: import java.util.ArrayList;
0042: import java.util.List;
0043: import java.util.logging.Level;
0044: import java.util.logging.Logger;
0045: import java.util.Properties;
0046:
0047: import javax.management.ObjectName;
0048:
0049: /**
0050: * Tests for the Component class.
0051: *
0052: * @author Sun Microsystems, Inc.
0053: */
0054: public class TestComponent extends junit.framework.TestCase {
0055: /**
0056: * Value of the $SRCROOT environment variable
0057: */
0058: private String mSrcroot;
0059:
0060: /**
0061: * EnvironmentContext
0062: */
0063: private EnvironmentContext mEnvironmentContext;
0064:
0065: /**
0066: * Component
0067: */
0068: private Component mComponent;
0069:
0070: /**
0071: * Component Description
0072: */
0073: private String mComponentDesc;
0074:
0075: /**
0076: * Component Name
0077: */
0078: private String mComponentName;
0079:
0080: /**
0081: * Component Root directory
0082: */
0083: private String mInstallRoot;
0084:
0085: /**
0086: * Workspace Root directory
0087: */
0088: private String mWorkspaceRoot;
0089:
0090: /**
0091: * Bootstrap class instance
0092: */
0093: private Object mBootstrapClass;
0094:
0095: /**
0096: * Bootstrap class loader
0097: */
0098: private ClassLoader mBootstrapClassLoader;
0099:
0100: /**
0101: * Bootstrap class name
0102: */
0103: private String mBootstrapClassName;
0104:
0105: /**
0106: * Bootstrap class path element list
0107: */
0108: private ArrayList mBootstrapClassPath;
0109:
0110: /**
0111: * Life cycle class instance
0112: */
0113: private Object mLifeCycleClass;
0114:
0115: /**
0116: * Life cycle class loader
0117: */
0118: private ClassLoader mLifeCycleClassLoader;
0119:
0120: /**
0121: * Life cycle class name
0122: */
0123: private String mComponentClassName;
0124:
0125: /**
0126: * Component runtime class path element list
0127: */
0128: private ArrayList mClassPathElements;
0129:
0130: /**
0131: * Component runtime class path
0132: */
0133: private String mClassPath;
0134:
0135: /**
0136: * Shared Library list
0137: */
0138: private ArrayList mSharedLibList;
0139:
0140: /**
0141: * The constructor for this testcase, forwards the test name to
0142: * the jUnit TestCase base class.
0143: * @param aTestName String with the name of this test.
0144: */
0145: public TestComponent(String aTestName) {
0146: super (aTestName);
0147: }
0148:
0149: /**
0150: * Setup for the test. This creates the ComponentRegistry instance
0151: * and other objects needed for the tests.
0152: * @throws Exception when set up fails for any reason.
0153: */
0154: public void setUp() throws Exception {
0155: super .setUp();
0156: mSrcroot = System.getProperty("junit.srcroot") + "/";
0157: mEnvironmentContext = new EnvironmentContext(
0158: new ScaffoldPlatformContext(), new JBIFramework(),
0159: new Properties());
0160: mEnvironmentContext.setRegistry(new ScaffoldRegistry(
0161: mEnvironmentContext));
0162: mComponent = new Component();
0163: ArrayList cp;
0164: File dir;
0165: URL[] urls;
0166: Class c;
0167:
0168: mBootstrapClassName = "com.sun.jbi.framework.BindingBootstrap";
0169: cp = new ArrayList();
0170: cp
0171: .add(mSrcroot
0172: + "runtime/framework/bld/com/sun/jbi/framework");
0173: mBootstrapClassPath = cp;
0174: dir = new File((String) cp.get(0));
0175: urls = new URL[1];
0176: urls[0] = dir.toURL();
0177: mBootstrapClassLoader = new URLClassLoader(urls);
0178: c = mBootstrapClassLoader.loadClass(mBootstrapClassName);
0179: mBootstrapClass = c.newInstance();
0180:
0181: mComponentDesc = "Test Component 1";
0182: mComponentName = "Comp1";
0183: mInstallRoot = mSrcroot
0184: + "runtime/framework/bld/Comp1/install_root";
0185: mWorkspaceRoot = mSrcroot
0186: + "runtime/framework/bld/Comp1/install_root/work";
0187:
0188: mComponentClassName = "com.sun.jbi.framework.Binding";
0189: cp = new ArrayList();
0190: cp
0191: .add(mSrcroot
0192: + "runtime/framework/bld/com/sun/jbi/framework");
0193: cp.add(mSrcroot
0194: + "runtime/framework/regress/com/sun/jbi/framework");
0195: mClassPathElements = cp;
0196: mClassPath = (String) cp.get(0) + File.pathSeparator
0197: + (String) cp.get(1);
0198: dir = new File((String) cp.get(0));
0199: urls = new URL[1];
0200: urls[0] = dir.toURL();
0201: mLifeCycleClassLoader = new URLClassLoader(urls);
0202: c = mLifeCycleClassLoader.loadClass(mComponentClassName);
0203: mLifeCycleClass = c.newInstance();
0204:
0205: mSharedLibList = new ArrayList();
0206: mSharedLibList.add("SharedLibrary1");
0207: mSharedLibList.add("SharedLibrary2");
0208: }
0209:
0210: /**
0211: * Cleanup for the test.
0212: * @throws Exception when tearDown fails for any reason.
0213: */
0214: public void tearDown() throws Exception {
0215: super .tearDown();
0216: }
0217:
0218: // ============================= test methods ================================
0219:
0220: /**
0221: * Test the addServiceUnit/getServiceUnit methods.
0222: * @throws Exception if an unexpected error occurs.
0223: */
0224: public void testAddGetServiceUnit() throws Exception {
0225: ServiceUnit su1 = new ServiceUnit("TestSA1", "TestSU1",
0226: "jbi/deployment/su1");
0227:
0228: mComponent.addServiceUnit(su1);
0229: assertSame("Failure adding/getting ServiceUnit: ", mComponent
0230: .getServiceUnit("TestSU1"), su1);
0231: }
0232:
0233: /**
0234: * Test the isServiceUnitRegistered method.
0235: * @throws Exception if an unexpected error occurs.
0236: */
0237: public void testIsServiceUnitRegistered() throws Exception {
0238: assertFalse("Incorrect result from isServiceUnitRegistered: "
0239: + "got true, expected false", mComponent
0240: .isServiceUnitRegistered("TestSU1"));
0241:
0242: ServiceUnit su1 = new ServiceUnit("TestSA1", "TestSU1",
0243: "jbi/deployment/su1");
0244:
0245: mComponent.addServiceUnit(su1);
0246: assertTrue("Incorrect result from isServiceUnitRegistered: "
0247: + "got false, expected true", mComponent
0248: .isServiceUnitRegistered("TestSU1"));
0249: }
0250:
0251: /**
0252: * Test the addServiceUnit method with a duplicate Service Unit name.
0253: * An exception is expected.
0254: * @throws Exception if an unexpected error occurs.
0255: */
0256: public void testAddServiceUnitBadDuplicate() throws Exception {
0257: ServiceUnit su1 = new ServiceUnit("TestSA1", "TestSU1",
0258: "jbi/deployment/su1");
0259: ServiceUnit su2 = new ServiceUnit("TestSA2", "TestSU1",
0260: "jbi/deployment/su2");
0261:
0262: mComponent.addServiceUnit(su1);
0263: try {
0264: mComponent.addServiceUnit(su2);
0265: fail("Expected exception not received");
0266: } catch (javax.jbi.JBIException ex) {
0267: // Verification
0268: assertTrue(
0269: "Incorrect exception received: " + ex.toString(),
0270: (-1 < ex.getMessage().indexOf("already exists for")));
0271: }
0272: }
0273:
0274: /**
0275: * Test the addServiceUnit method with a null Service Unit. An exception
0276: * is expected.
0277: * @throws Exception if an unexpected error occurs.
0278: */
0279: public void testAddServiceUnitBadNull() throws Exception {
0280: try {
0281: mComponent.addServiceUnit(null);
0282: fail("Expected exception not received");
0283: } catch (java.lang.IllegalArgumentException ex) {
0284: // Verification
0285: assertTrue(
0286: "Incorrect exception received: " + ex.toString(),
0287: (-1 < ex.getMessage().indexOf("Null argument")));
0288: }
0289: }
0290:
0291: /**
0292: * Test the get and set methods for the Bootstrap Class Name.
0293: * @throws Exception if an unexpected error occurs.
0294: */
0295: public void testGetSetBootstrapClassName() throws Exception {
0296: mComponent.setBootstrapClassName(mBootstrapClassName);
0297: assertEquals("Failure setting/getting BootstrapClassName: ",
0298: mBootstrapClassName, mComponent.getBootstrapClassName());
0299: }
0300:
0301: /**
0302: * Test the get and set methods for the Bootstrap Class Path Elements.
0303: * @throws Exception if an unexpected error occurs.
0304: */
0305: public void testGetSetBootstrapClassPathElements() throws Exception {
0306: mComponent.setBootstrapClassPathElements(mBootstrapClassPath);
0307: assertEquals(
0308: "Failure getting/setting BootstrapClassPathElements: ",
0309: mBootstrapClassPath, mComponent
0310: .getBootstrapClassPathElements());
0311: }
0312:
0313: /**
0314: * Test the get and clear methods for the Bootstrap Instance.
0315: * @throws Exception if an unexpected error occurs.
0316: */
0317: public void testGetClearBootstrapInstance() throws Exception {
0318: // Set bootstrap class name and class path elements for test.
0319: mComponent.setBootstrapClassName(mBootstrapClassName);
0320: mComponent.setBootstrapClassPathElements(mBootstrapClassPath);
0321: Object instance;
0322:
0323: // This should return a null value.
0324: instance = mComponent.getBootstrapInstance(false);
0325: assertEquals("Failure on getBootstrapInstance(false): ", null,
0326: instance);
0327:
0328: // This should return a non-null value.
0329: instance = mComponent.getBootstrapInstance(true);
0330: assertNotNull("Failure on getBootstrapInstance(true): "
0331: + "expected a non-null value, got a null", instance);
0332: assertTrue(
0333: "Failure on getBootstrapInstance(true): "
0334: + "expected an instance of "
0335: + mBootstrapClassName + ", got an instance of "
0336: + instance.getClass().getName(),
0337: instance instanceof com.sun.jbi.framework.BindingBootstrap);
0338:
0339: // This should clear the value that was set.
0340: mComponent.clearBootstrapInstance();
0341: instance = mComponent.getBootstrapInstance(false);
0342: assertNull("Failure on clearBootstrapInstance(): "
0343: + "instance pointer was not cleared, value is still "
0344: + instance, instance);
0345: }
0346:
0347: /**
0348: * Test the getBootstrapInstance with a bad class name to cause a
0349: * class loading failure.
0350: * @throws Exception if an unexpected error occurs.
0351: */
0352: public void testGetBootstrapInstanceBadNotFound() throws Exception {
0353: // Set bootstrap class name and class path elements for test.
0354: mComponent
0355: .setBootstrapClassName("com.sun.jbi.framework.nonexistent");
0356: mComponent.setBootstrapClassPathElements(mBootstrapClassPath);
0357: Object instance;
0358:
0359: // This should fail with a JBIException.
0360: try {
0361: instance = mComponent.getBootstrapInstance(true);
0362: fail("Expected exception not received");
0363: } catch (javax.jbi.JBIException ex) {
0364: // Verification
0365: assertTrue(
0366: "Incorrect exception received: " + ex.toString(),
0367: ((-1 < ex.getMessage().indexOf("was not found")))
0368: && ((-1 < ex.getMessage().indexOf(
0369: "Required class"))));
0370: }
0371: }
0372:
0373: /**
0374: * Test the getBootstrapInstance with a class that does not implement
0375: * the required interfaces to cause a class loading failure.
0376: * @throws Exception if an unexpected error occurs.
0377: */
0378: public void testGetBootstrapInstanceBadClassInvalid()
0379: throws Exception {
0380: // Set bootstrap class name and class path elements for test.
0381: mComponent
0382: .setBootstrapClassName("com.sun.jbi.framework.Component");
0383: mComponent.setBootstrapClassPathElements(mBootstrapClassPath);
0384: Object instance;
0385:
0386: // This should fail with a JBIException.
0387: try {
0388: instance = mComponent.getBootstrapInstance(true);
0389: fail("Expected exception not received");
0390: } catch (javax.jbi.JBIException ex) {
0391: // Verification
0392: assertTrue(
0393: "Incorrect exception received: " + ex.toString(),
0394: ((-1 < ex.getMessage()
0395: .indexOf("does not implement")))
0396: && ((-1 < ex.getMessage().indexOf(
0397: "required interface"))));
0398: }
0399: }
0400:
0401: /**
0402: * Test the get and set methods for the component class name.
0403: * @throws Exception if an unexpected error occurs.
0404: */
0405: public void testGetSetComponentClassName() throws Exception {
0406: mComponent.setComponentClassName(mComponentClassName);
0407: assertEquals("Failure getting/setting LifeCycleClassName: ",
0408: mComponentClassName, mComponent.getComponentClassName());
0409: }
0410:
0411: /**
0412: * Test the get and set methods for the component class path elements.
0413: * @throws Exception if an unexpected error occurs.
0414: */
0415: public void testGetSetComponentClassPathElements() throws Exception {
0416: mComponent.setComponentClassPathElements(mClassPathElements);
0417: assertEquals(
0418: "Failure getting/setting ComponentClassPathElements: ",
0419: mClassPathElements, mComponent
0420: .getComponentClassPathElements());
0421: }
0422:
0423: /**
0424: * Test the getComponentClassPathAsString method.
0425: * @throws Exception if an unexpected error occurs.
0426: */
0427: public void testGetComponentClassPathAsString() throws Exception {
0428: mComponent.setComponentClassPathElements(mClassPathElements);
0429: assertEquals("Failure getting ComponentClassPath: ",
0430: mClassPath, mComponent.getComponentClassPathAsString());
0431: }
0432:
0433: /**
0434: * Test the getComponentInstance method.
0435: * @throws Exception if an unexpected error occurs.
0436: */
0437: public void testGetComponentInstance() throws Exception {
0438: // Set component name.
0439: mComponent.setName(mComponentName);
0440: // Set lifecycle class name and class path elements for test.
0441: mComponent.setComponentClassName(mComponentClassName);
0442: mComponent.setComponentClassPathElements(mClassPathElements);
0443: Object instance;
0444:
0445: // This should return a null value.
0446: instance = mComponent.getLifeCycleInstance(false);
0447: assertNull("Failure on getLifeCycleInstance(false): "
0448: + "expected a null value, got " + instance, instance);
0449: instance = mComponent.getComponentInstance();
0450: assertNull("Failure on getComponentInstance(): "
0451: + "expected a null value, got " + instance, instance);
0452:
0453: // This should return a non-null value.
0454: instance = mComponent.getLifeCycleInstance(true);
0455: assertNotNull("Failure on getLifeCycleInstance(true): "
0456: + "expected a non-null value, got a null", instance);
0457: assertTrue(
0458: "Failure on getLifeCycleInstance(true): "
0459: + "expected an instance of javax.jbi.component.ComponentLifeCycle"
0460: + ", got an instance of "
0461: + instance.getClass().getName(),
0462: instance instanceof javax.jbi.component.ComponentLifeCycle);
0463:
0464: instance = mComponent.getComponentInstance();
0465: assertNotNull("Failure on getComponentInstance(): "
0466: + "expected a non-null value, got a null", instance);
0467: assertTrue(
0468: "Failure on getComponentInstance(): "
0469: + "expected an instance of javax.jbi.component.Component"
0470: + ", got an instance of "
0471: + instance.getClass().getName(),
0472: instance instanceof javax.jbi.component.Component);
0473:
0474: // This should clear the value that was set.
0475: mComponent.clearLifeCycleInstance();
0476: assertNull("Failure on clearLifeCycleInstance(): "
0477: + "instance pointer was not cleared, value is still "
0478: + mComponent.getComponentInstance(), mComponent
0479: .getComponentInstance());
0480: }
0481:
0482: /**
0483: * Test the get and set methods for the component type.
0484: * @throws Exception if an unexpected error occurs.
0485: */
0486: public void testGetSetComponentType() throws Exception {
0487: mComponent.setComponentType(ComponentType.BINDING);
0488: assertEquals("Failure getting/setting ComponentType: ",
0489: ComponentType.BINDING, mComponent.getComponentType());
0490: mComponent.setComponentType(ComponentType.ENGINE);
0491: assertEquals("Failure getting/setting ComponentType: ",
0492: ComponentType.ENGINE, mComponent.getComponentType());
0493: }
0494:
0495: /**
0496: * Test the getComponentTypeAsString method.
0497: * @throws Exception if an unexpected error occurs.
0498: */
0499: public void testGetComponentTypeAsString() throws Exception {
0500: mComponent.setComponentType(ComponentType.BINDING);
0501: assertEquals("Failure getting ComponentType: ", "Binding",
0502: mComponent.getComponentTypeAsString());
0503: mComponent.setComponentType(ComponentType.ENGINE);
0504: assertEquals("Failure getting/setting ComponentType: ",
0505: "Engine", mComponent.getComponentTypeAsString());
0506: }
0507:
0508: /**
0509: * Test the get and set methods for the context.
0510: * @throws Exception if an unexpected error occurs.
0511: */
0512: public void testGetSetContext() throws Exception {
0513: ComponentContext context = new ComponentContext(mComponent,
0514: mEnvironmentContext);
0515: mComponent.setContext(context);
0516: assertEquals("Failure getting/setting Context: ", context,
0517: mComponent.getContext());
0518: }
0519:
0520: /**
0521: * Test the get and set methods for the component description.
0522: * @throws Exception if an unexpected error occurs.
0523: */
0524: public void testGetSetDescription() throws Exception {
0525: mComponent.setDescription(mComponentDesc);
0526: assertEquals("Failure getting/setting Description: ",
0527: mComponentDesc, mComponent.getDescription());
0528: }
0529:
0530: /**
0531: * Test the get and set methods for the Deployer MBean name.
0532: * @throws Exception if an unexpected error occurs.
0533: */
0534: public void testGetSetDeployerMBeanName() throws Exception {
0535: javax.management.ObjectName mbn = new javax.management.ObjectName(
0536: "jbi:type=deployer");
0537: mComponent.setDeployerMBeanName(mbn);
0538: assertEquals("Failure getting/setting Deployer MBean Name: ",
0539: mbn, mComponent.getDeployerMBeanName());
0540: }
0541:
0542: /**
0543: * Test the get and set methods for the Deployer instance.
0544: * @throws Exception if an unexpected error occurs.
0545: */
0546: public void testGetSetDeployerInstance() throws Exception {
0547: // Set component name.
0548: mComponent.setName(mComponentName);
0549: // Set component class name and class path elements for test.
0550: mComponent.setComponentClassName(mComponentClassName);
0551: mComponent.setComponentClassPathElements(mClassPathElements);
0552: // Get a component instance for the test.
0553: Object instance = mComponent.getLifeCycleInstance(true);
0554:
0555: // Now the real test.
0556: Deployer dep = new Deployer(mComponent);
0557: mComponent.setDeployerInstance(dep);
0558: assertSame("Failure getting/setting Deployer instance: ", dep,
0559: mComponent.getDeployerInstance());
0560: }
0561:
0562: /**
0563: * Test the get and set methods for the desired state.
0564: * @throws Exception if an unexpected error occurs.
0565: */
0566: public void testGetSetDesiredState() throws Exception {
0567: assertEquals("Initial state incorrect: ",
0568: ComponentState.UNKNOWN, mComponent.getDesiredState());
0569: mComponent.setDesiredState(ComponentState.STOPPED);
0570: assertEquals("Failure getting/setting stopped state: ",
0571: ComponentState.STOPPED, mComponent.getDesiredState());
0572: mComponent.setDesiredState(ComponentState.STARTED);
0573: assertEquals("Failure getting/setting started state: ",
0574: ComponentState.STARTED, mComponent.getDesiredState());
0575: mComponent.setDesiredState(ComponentState.SHUTDOWN);
0576: assertEquals("Failure getting/setting shutdown state: ",
0577: ComponentState.SHUTDOWN, mComponent.getDesiredState());
0578:
0579: // This should fail with a runtime exception
0580: try {
0581: mComponent.setDesiredState(ComponentState.UNKNOWN);
0582: fail("Expected exception not received");
0583: } catch (java.lang.IllegalArgumentException ex) {
0584: // Verification
0585: assertTrue(
0586: "Incorrect exception received: " + ex.toString(),
0587: (-1 < ex.getMessage().indexOf("state")));
0588: }
0589: }
0590:
0591: /**
0592: * Test the get and set methods for the Extension MBean name.
0593: * @throws Exception if an unexpected error occurs.
0594: */
0595: public void testGetSetExtensionMBeanName() throws Exception {
0596: javax.management.ObjectName mbn = new javax.management.ObjectName(
0597: "jbi:type=extension");
0598: mComponent.setExtensionMBeanName(mbn);
0599: assertEquals("Failure getting/setting extension MBean Name: ",
0600: mbn, mComponent.getExtensionMBeanName());
0601: }
0602:
0603: /**
0604: * Test the get and set methods for the Installation Descriptor.
0605: * @throws Exception if an unexpected error occurs.
0606: */
0607: public void testGetSetInstallationDescriptor() throws Exception {
0608: String id = "<bogus installation descriptor/>";
0609: mComponent.setInstallationDescriptor(id);
0610: assertEquals("Failure getting/setting Installer MBean Name: ",
0611: id, mComponent.getInstallationDescriptor());
0612: }
0613:
0614: /**
0615: * Test the get and set methods for the Installer MBean name.
0616: * @throws Exception if an unexpected error occurs.
0617: */
0618: public void testGetSetInstallerMBeanName() throws Exception {
0619: javax.management.ObjectName mbn = new javax.management.ObjectName(
0620: "jbi:type=installer");
0621: mComponent.setInstallerMBeanName(mbn);
0622: assertEquals("Failure getting/setting Installer MBean Name: ",
0623: mbn, mComponent.getInstallerMBeanName());
0624: }
0625:
0626: /**
0627: * Test the get and set methods for the component install root directory.
0628: * @throws Exception if an unexpected error occurs.
0629: */
0630: public void testGetSetInstallRoot() throws Exception {
0631: mComponent.setInstallRoot(mInstallRoot);
0632: // convert backslashes to slashes, so Cygwin is happy
0633: String expected = mInstallRoot.replace('\\', '/');
0634: String actual = mComponent.getInstallRoot().replace('\\', '/');
0635: assertEquals("Failure getting/setting ComponentRoot: ",
0636: expected, actual);
0637: }
0638:
0639: /**
0640: * Test the getLifeCycleInstance and clearLifeCycleInstance methods.
0641: * @throws Exception if an unexpected error occurs.
0642: */
0643: public void testGetClearLifeCycleInstance() throws Exception {
0644: // Set component name.
0645: mComponent.setName(mComponentName);
0646: // Set lifecycle class name and class path elements for test.
0647: mComponent.setComponentClassName(mComponentClassName);
0648: mComponent.setComponentClassPathElements(mClassPathElements);
0649: Object instance;
0650:
0651: // This should return a null value.
0652: instance = mComponent.getLifeCycleInstance(false);
0653: assertNull("Failure on getLifeCycleInstance(false): "
0654: + "expected a null value, got " + instance, instance);
0655:
0656: // This should return a non-null value.
0657: instance = mComponent.getLifeCycleInstance(true);
0658: assertNotNull("Failure on getLifeCycleInstance(true): "
0659: + "expected a non-null value, got a null", instance);
0660: assertTrue("Failure on getLifeCycleInstance(true): "
0661: + "expected an instance of " + mComponentClassName
0662: + ", got an instance of "
0663: + instance.getClass().getName(),
0664: instance instanceof com.sun.jbi.framework.Binding);
0665:
0666: // This should clear the value that was set.
0667: mComponent.clearLifeCycleInstance();
0668: instance = mComponent.getLifeCycleInstance(false);
0669: assertNull("Failure on clearLifeCycleInstance(): "
0670: + "instance pointer was not cleared, value is still "
0671: + instance, instance);
0672: }
0673:
0674: /**
0675: * Test the getLifeCycleInstance with a bad classpath to cause a
0676: * class loading failure.
0677: * @throws Exception if an unexpected error occurs.
0678: */
0679: public void testGetLifeCycleInstanceBadNotFound() throws Exception {
0680: // Set lifecycle class name and class path elements for test.
0681: mComponent
0682: .setComponentClassName("com.sun.jbi.framework.nonexistent");
0683: mComponent.setComponentClassPathElements(mClassPathElements);
0684: Object instance;
0685:
0686: // This should fail with a JBIException.
0687: try {
0688: instance = mComponent.getLifeCycleInstance(true);
0689: fail("Expected exception not received");
0690: } catch (javax.jbi.JBIException ex) {
0691: // Verification
0692: assertTrue(
0693: "Incorrect exception received: " + ex.toString(),
0694: ((-1 < ex.getMessage().indexOf("was not found")))
0695: && ((-1 < ex.getMessage().indexOf(
0696: "Required class"))));
0697: }
0698: }
0699:
0700: /**
0701: * Test the getLifeCycleInstance with a class that does not implement
0702: * the required interfaces to cause a class loading failure.
0703: * @throws Exception if an unexpected error occurs.
0704: */
0705: public void testGetLifeCycleInstanceBadClassInvalid()
0706: throws Exception {
0707: // Set bootstrap class name and class path elements for test.
0708: mComponent
0709: .setComponentClassName("com.sun.jbi.framework.Component");
0710: mComponent.setComponentClassPathElements(mClassPathElements);
0711: Object instance;
0712:
0713: // This should fail with a JBIException.
0714: try {
0715: instance = mComponent.getLifeCycleInstance(true);
0716: fail("Expected exception not received");
0717: } catch (javax.jbi.JBIException ex) {
0718: // Verification
0719: assertTrue(
0720: "Incorrect exception received: " + ex.toString(),
0721: ((-1 < ex.getMessage()
0722: .indexOf("does not implement")))
0723: && ((-1 < ex.getMessage().indexOf(
0724: "required interface"))));
0725: }
0726: }
0727:
0728: /**
0729: * Test the get and set methods for the LifeCycle MBean name.
0730: * @throws Exception if an unexpected error occurs.
0731: */
0732: public void testGetSetLifeCycleMBeanName() throws Exception {
0733: javax.management.ObjectName mbn = new javax.management.ObjectName(
0734: "jbi:type=lifecycle");
0735: mComponent.setLifeCycleMBeanName(mbn);
0736: assertEquals("Failure getting/setting LifeCycle MBean Name: ",
0737: mbn, mComponent.getLifeCycleMBeanName());
0738: }
0739:
0740: /**
0741: * Test the get and set methods for the Configuration MBean name.
0742: * @throws Exception if an unexpected error occurs.
0743: */
0744: public void testGetSetConfigurationMBeanName() throws Exception {
0745: javax.management.ObjectName mbn = new javax.management.ObjectName(
0746: "jbi:type=configuration");
0747: mComponent.setConfigurationMBeanName(mbn);
0748: assertEquals(
0749: "Failure getting/setting Configuration MBean Name: ",
0750: mbn, mComponent.getConfigurationMBeanName());
0751: }
0752:
0753: /**
0754: * Test the getLoggerInstance/setLoggerInstance methods.
0755: * @throws Exception if an unexpected error occurs.
0756: */
0757: public void testGetSetLoggerInstance() throws Exception {
0758: mComponent.setInstallRoot(mInstallRoot);
0759: mComponent.setName(mComponentName);
0760: ComponentLogger cl = new ComponentLogger(mComponent);
0761: mComponent.setLoggerInstance(cl);
0762: assertSame("Failure getting/setting Logger MBean Instance: ",
0763: cl, mComponent.getLoggerInstance());
0764: mComponent.setLoggerInstance(null);
0765: assertNull("Failure clearing Logger MBean Instance: ",
0766: mComponent.getLoggerInstance());
0767: }
0768:
0769: /**
0770: * Test the getLoggerMBeanName/setLoggerMBeanName methods.
0771: * @throws Exception if an unexpected error occurs.
0772: */
0773: public void testGetSetLoggerMBeanName() throws Exception {
0774: javax.management.ObjectName mbn = new javax.management.ObjectName(
0775: "jbi:type=logger");
0776: mComponent.setLoggerMBeanName(mbn);
0777: assertEquals("Failure getting/setting Logger MBean Name: ",
0778: mbn, mComponent.getLoggerMBeanName());
0779: }
0780:
0781: /**
0782: * Test the get and set methods for the component name.
0783: * @throws Exception if an unexpected error occurs.
0784: */
0785: public void testGetSetName() throws Exception {
0786: mComponent.setName(mComponentName);
0787: assertEquals("Failure getting/setting Name: ", mComponentName,
0788: mComponent.getName());
0789: }
0790:
0791: /**
0792: * Test the getServiceUnitList method.
0793: * @throws Exception if an unexpected error occurs.
0794: */
0795: public void testGetServiceUnitList() throws Exception {
0796: ServiceUnit su1 = new ServiceUnit("TestSA1", "TestSU1",
0797: "jbi/deployment/su1");
0798: ServiceUnit su2 = new ServiceUnit("TestSA2", "TestSU2",
0799: "jbi/deployment/su2");
0800: ArrayList suList = new ArrayList();
0801:
0802: assertEquals("Failure getting ServiceUnitList: ",
0803: suList.size(), mComponent.getServiceUnitList().size());
0804:
0805: suList.add(su1);
0806: mComponent.addServiceUnit(su1);
0807: assertTrue("Failure getting ServiceUnitList: expected true",
0808: mComponent.getServiceUnitList().contains(su1));
0809: assertEquals("Failure getting ServiceUnitList: ",
0810: suList.size(), mComponent.getServiceUnitList().size());
0811:
0812: suList.add(su2);
0813: mComponent.addServiceUnit(su2);
0814: assertTrue("Failure getting ServiceUnitList: expected true",
0815: mComponent.getServiceUnitList().contains(su2));
0816: assertEquals("Failure getting ServiceUnitList: ",
0817: suList.size(), mComponent.getServiceUnitList().size());
0818: }
0819:
0820: /**
0821: * Test the getServiceUnitManager method.
0822: * @throws Exception if an unexpected error occurs.
0823: */
0824: public void testGetServiceUnitManager() throws Exception {
0825: Object instance;
0826:
0827: // This should return a null value.
0828: instance = mComponent.getServiceUnitManager();
0829: assertNull("Failure on getServiceUnitManager(): "
0830: + "expected a null value, got a non-null", instance);
0831:
0832: // Now load the life cycle class.
0833: mComponent.setName(mComponentName);
0834: mComponent.setComponentClassName(mComponentClassName);
0835: mComponent.setComponentClassPathElements(mClassPathElements);
0836: mComponent.getLifeCycleInstance(true);
0837:
0838: // This should return a non-null value.
0839: instance = mComponent.getServiceUnitManager();
0840: assertNotNull("Failure on getServiceUnitManager(): "
0841: + "expected a non-null value, got a null", instance);
0842: String sumName = javax.jbi.component.ServiceUnitManager.class
0843: .getName();
0844: assertTrue(
0845: "Failure on getServiceUnitManager(): "
0846: + "expected an instance of " + sumName
0847: + ", got an instance of "
0848: + instance.getClass().getName(),
0849: instance instanceof javax.jbi.component.ServiceUnitManager);
0850: }
0851:
0852: /**
0853: * Test the get and set methods for the Shared Library ID list.
0854: * @throws Exception if an unexpected error occurs.
0855: */
0856: public void testGetSetSharedLibraryNames() throws Exception {
0857: mComponent.setSharedLibraryNames(mSharedLibList);
0858: assertEquals(
0859: "Failure getting/setting Shared Library ID list: ",
0860: mSharedLibList, mComponent.getSharedLibraryNames());
0861: }
0862:
0863: /**
0864: * Test the get and set methods for the Statistics instance.
0865: * @throws Exception if an unexpected error occurs.
0866: */
0867: public void testGetSetClearStatisticsInstance() throws Exception {
0868: ComponentStatistics cs = new ComponentStatistics(mComponent
0869: .getName());
0870: mComponent.setStatisticsInstance(cs);
0871: assertSame("Failure getting/setting Statistics Instance: ", cs,
0872: mComponent.getStatisticsInstance());
0873: mComponent.clearStatisticsInstance();
0874: assertNull("Failure clearing Statistics Instance: ", mComponent
0875: .getStatisticsInstance());
0876: }
0877:
0878: /**
0879: * Test the get and set methods for the Statistics MBean name.
0880: * @throws Exception if an unexpected error occurs.
0881: */
0882: public void testGetSetStatisticsMBeanName() throws Exception {
0883: javax.management.ObjectName mbn = new javax.management.ObjectName(
0884: "jbi:type=statistics");
0885: mComponent.setStatisticsMBeanName(mbn);
0886: assertEquals("Failure getting/setting Statistics MBean Name: ",
0887: mbn, mComponent.getStatisticsMBeanName());
0888: }
0889:
0890: /**
0891: * Test the get and set methods for the component status.
0892: * @throws Exception if an unexpected error occurs.
0893: */
0894: public void testGetSetStatus() throws Exception {
0895: mComponent.setStatus(ComponentState.LOADED);
0896: assertEquals("Failure getting/setting loaded status: ",
0897: ComponentState.LOADED, mComponent.getStatus());
0898: mComponent.setStatus(ComponentState.SHUTDOWN);
0899: assertEquals("Failure getting/setting installed status: ",
0900: ComponentState.SHUTDOWN, mComponent.getStatus());
0901: mComponent.setStatus(ComponentState.STOPPED);
0902: assertEquals("Failure getting/setting stopped status: ",
0903: ComponentState.STOPPED, mComponent.getStatus());
0904: mComponent.setStatus(ComponentState.STARTED);
0905: assertEquals("Failure getting/setting started status: ",
0906: ComponentState.STARTED, mComponent.getStatus());
0907: }
0908:
0909: /**
0910: * Test the getStatusAsString method.
0911: * @throws Exception if an unexpected error occurs.
0912: */
0913: public void testGetStatusAsString() throws Exception {
0914: mComponent.setLoaded();
0915: assertEquals("Failure getting loaded status: ",
0916: ComponentState.LOADED.toString(), mComponent
0917: .getStatusAsString());
0918: mComponent.setShutdown();
0919: assertEquals("Failure getting shutdown status: ",
0920: ComponentState.SHUTDOWN.toString(), mComponent
0921: .getStatusAsString());
0922: mComponent.setStopped();
0923: assertEquals("Failure getting stopped status: ",
0924: ComponentState.STOPPED.toString(), mComponent
0925: .getStatusAsString());
0926: mComponent.setStarted();
0927: assertEquals("Failure getting started status: ",
0928: ComponentState.STARTED.toString(), mComponent
0929: .getStatusAsString());
0930: }
0931:
0932: /**
0933: * Test the get and set methods for the workspace root directory.
0934: * @throws Exception if an unexpected error occurs.
0935: */
0936: public void testGetSetWorkspaceRoot() throws Exception {
0937: mComponent.setWorkspaceRoot(mWorkspaceRoot);
0938: // convert backslashes to slashes, so Cygwin is happy
0939: String expected = mWorkspaceRoot.replace('\\', '/');
0940: String actual = mComponent.getWorkspaceRoot()
0941: .replace('\\', '/');
0942: assertEquals("Failure getting/setting WorkspaceRoot: ",
0943: expected, actual);
0944: }
0945:
0946: /**
0947: * Test the isBinding and setComponentTypeBinding methods.
0948: * @throws Exception if an unexpected error occurs.
0949: */
0950: public void testIsBinding() throws Exception {
0951: mComponent.setComponentTypeBinding();
0952: assertTrue("Failure in isBinding: expected true, got false",
0953: mComponent.isBinding());
0954: mComponent.setComponentTypeEngine();
0955: assertFalse("Failure in isBinding: expected false, got true",
0956: mComponent.isBinding());
0957: }
0958:
0959: /**
0960: * Test the isBootstrapClassLoaderSelfFirst and
0961: * setBootstrapClassLoaderSelfFirst methods.
0962: * @throws Exception if an unexpected error occurs.
0963: */
0964: public void testIsBootstrapClassLoaderSelfFirst() throws Exception {
0965: mComponent.setBootstrapClassLoaderSelfFirst(true);
0966: assertTrue("Failure in isBootstrapClassLoaderSelfFirst: "
0967: + "expected true, got false", mComponent
0968: .isBootstrapClassLoaderSelfFirst());
0969: mComponent.setBootstrapClassLoaderSelfFirst(false);
0970: assertFalse("Failure in isBootstrapClassLoaderSelfFirst: "
0971: + "expected false, got true", mComponent
0972: .isBootstrapClassLoaderSelfFirst());
0973: }
0974:
0975: /**
0976: * Test the isBootstrapCleanUpNeeded and setBootstrapCleanUpNeeded methods.
0977: * @throws Exception if an unexpected error occurs.
0978: */
0979: public void testIsBootstrapCleanUpNeeded() throws Exception {
0980: mComponent.setBootstrapCleanUpNeeded(true);
0981: assertTrue("Failure in isBootstrapCleanUpNeeded: "
0982: + "expected true, got false", mComponent
0983: .isBootstrapCleanUpNeeded());
0984: mComponent.setBootstrapCleanUpNeeded(false);
0985: assertFalse("Failure in isBootstrapCleanUpNeeded: "
0986: + "expected false, got true", mComponent
0987: .isBootstrapCleanUpNeeded());
0988: }
0989:
0990: /**
0991: * Test the isBusy/setBusy/setBusyForce/clearBusy methods.
0992: * @throws Exception if an unexpected error occurs.
0993: */
0994: public void testIsSetClearBusy() throws Exception {
0995: // The component is not busy, this will return false
0996: assertFalse("Failure in isBusy: expected false, got true",
0997: mComponent.isBusy());
0998:
0999: // Set the busy flag, this will succeed
1000: mComponent.setBusy();
1001: assertTrue("Failure in setBusy: expected true, got false",
1002: mComponent.isBusy());
1003:
1004: // Try to set the busy flag again. This will fail.
1005: try {
1006: mComponent.setBusy();
1007: fail("Expected exception not received");
1008: } catch (javax.jbi.JBIException ex) {
1009: // Verification
1010: assertTrue(
1011: "Incorrect exception received: " + ex.toString(),
1012: (-1 < ex.getMessage().indexOf("JBIFW2011")));
1013: }
1014:
1015: // Forcefully set the busy flag. This will succeed.
1016: mComponent.setBusyForce();
1017: assertTrue("Failure in setBusyForce: expected true, got false",
1018: mComponent.isBusy());
1019:
1020: // Clear the busy flag, this will succeed.
1021: mComponent.clearBusy();
1022: assertFalse("Failure in clearBusy: expected false, got true",
1023: mComponent.isBusy());
1024: }
1025:
1026: /**
1027: * Test the isComponentClassLoaderSelfFirst and
1028: * setComponentClassLoaderSelfFirst methods.
1029: * @throws Exception if an unexpected error occurs.
1030: */
1031: public void testIsComponentClassLoaderSelfFirst() throws Exception {
1032: mComponent.setComponentClassLoaderSelfFirst(true);
1033: assertTrue("Failure in isComponentClassLoaderSelfFirst: "
1034: + "expected true, got false", mComponent
1035: .isComponentClassLoaderSelfFirst());
1036: assertTrue("Failure in isClassLoaderSelfFirst: "
1037: + "expected true, got false", mComponent
1038: .isClassLoaderSelfFirst());
1039: mComponent.setComponentClassLoaderSelfFirst(false);
1040: assertFalse("Failure in isComponentClassLoaderSelfFirst: "
1041: + "expected false, got true", mComponent
1042: .isComponentClassLoaderSelfFirst());
1043: assertFalse("Failure in isClassLoaderSelfFirst: "
1044: + "expected false, got true", mComponent
1045: .isClassLoaderSelfFirst());
1046: }
1047:
1048: /**
1049: * Test the isEngine method.
1050: * @throws Exception if an unexpected error occurs.
1051: */
1052: public void testIsEngine() throws Exception {
1053: mComponent.setComponentTypeEngine();
1054: assertTrue("Failure in isEngine: expected true, got false",
1055: mComponent.isEngine());
1056: mComponent.setComponentTypeBinding();
1057: assertFalse("Failure in isEngine: expected false, got true",
1058: mComponent.isEngine());
1059: }
1060:
1061: /**
1062: * Test the isInitialized method.
1063: * @throws Exception if an unexpected error occurs.
1064: */
1065: public void testIsInitialized() throws Exception {
1066: mComponent.setStatus(ComponentState.LOADED);
1067: assertFalse(
1068: "Failure in isInitialized: expected false, got true",
1069: mComponent.isInitialized());
1070: mComponent.setStatus(ComponentState.SHUTDOWN);
1071: assertFalse(
1072: "Failure in isInitialized: expected false, got true",
1073: mComponent.isInitialized());
1074: mComponent.setStatus(ComponentState.STOPPED);
1075: assertTrue(
1076: "Failure in isInitialized: expected true, got false",
1077: mComponent.isInitialized());
1078: mComponent.setStatus(ComponentState.STARTED);
1079: assertFalse(
1080: "Failure in isInitialized: expected false, got true",
1081: mComponent.isInitialized());
1082: }
1083:
1084: /**
1085: * Test the isInstalled method.
1086: * @throws Exception if an unexpected error occurs.
1087: */
1088: public void testIsInstalled() throws Exception {
1089: mComponent.setStatus(ComponentState.LOADED);
1090: assertFalse("Failure in isInstalled: expected false, got true",
1091: mComponent.isInstalled());
1092: mComponent.setStatus(ComponentState.SHUTDOWN);
1093: assertTrue("Failure in isInstalled: expected true, got false",
1094: mComponent.isInstalled());
1095: mComponent.setStatus(ComponentState.STOPPED);
1096: assertFalse("Failure in isInstalled: expected false, got true",
1097: mComponent.isInstalled());
1098: mComponent.setStatus(ComponentState.STARTED);
1099: assertFalse("Failure in isInstalled: expected false, got true",
1100: mComponent.isInstalled());
1101: }
1102:
1103: /**
1104: * Test the isLoaded method.
1105: * @throws Exception if an unexpected error occurs.
1106: */
1107: public void testIsLoaded() throws Exception {
1108: mComponent.setStatus(ComponentState.LOADED);
1109: assertTrue("Failure in isLoaded: expected true, got false",
1110: mComponent.isLoaded());
1111: mComponent.setStatus(ComponentState.SHUTDOWN);
1112: assertFalse("Failure in isLoaded: expected false, got true",
1113: mComponent.isLoaded());
1114: mComponent.setStatus(ComponentState.STOPPED);
1115: assertFalse("Failure in isLoaded: expected false, got true",
1116: mComponent.isLoaded());
1117: mComponent.setStatus(ComponentState.STARTED);
1118: assertFalse("Failure in isLoaded: expected false, got true",
1119: mComponent.isLoaded());
1120: }
1121:
1122: /**
1123: * Test the isShutDown method.
1124: * @throws Exception if an unexpected error occurs.
1125: */
1126: public void testIsShutDown() throws Exception {
1127: mComponent.setStatus(ComponentState.LOADED);
1128: assertFalse("Failure in isShutDown: expected false, got true",
1129: mComponent.isShutDown());
1130: mComponent.setStatus(ComponentState.SHUTDOWN);
1131: assertTrue("Failure in isShutDown: expected true, got false",
1132: mComponent.isShutDown());
1133: mComponent.setStatus(ComponentState.STOPPED);
1134: assertFalse("Failure in isShutDown: expected false, got true",
1135: mComponent.isShutDown());
1136: mComponent.setStatus(ComponentState.STARTED);
1137: assertFalse("Failure in isShutDown: expected false, got true",
1138: mComponent.isShutDown());
1139: }
1140:
1141: /**
1142: * Test the isStarted method.
1143: * @throws Exception if an unexpected error occurs.
1144: */
1145: public void testIsStarted() throws Exception {
1146: mComponent.setStatus(ComponentState.LOADED);
1147: assertFalse("Failure in isStarted: expected false, got true",
1148: mComponent.isStarted());
1149: mComponent.setStatus(ComponentState.SHUTDOWN);
1150: assertFalse("Failure in isStarted: expected false, got true",
1151: mComponent.isStarted());
1152: mComponent.setStatus(ComponentState.STOPPED);
1153: assertFalse("Failure in isStarted: expected false, got true",
1154: mComponent.isStarted());
1155: mComponent.setStatus(ComponentState.STARTED);
1156: assertTrue("Failure in isStarted: expected true, got false",
1157: mComponent.isStarted());
1158: }
1159:
1160: /**
1161: * Test the isStopped method.
1162: * @throws Exception if an unexpected error occurs.
1163: */
1164: public void testIsStopped() throws Exception {
1165: mComponent.setStatus(ComponentState.LOADED);
1166: assertFalse("Failure in isStopped: expected false, got true",
1167: mComponent.isStopped());
1168: mComponent.setStatus(ComponentState.SHUTDOWN);
1169: assertFalse("Failure in isStopped: expected false, got true",
1170: mComponent.isStopped());
1171: mComponent.setStatus(ComponentState.STOPPED);
1172: assertTrue("Failure in isStopped: expected true, got false",
1173: mComponent.isStopped());
1174: mComponent.setStatus(ComponentState.STARTED);
1175: assertFalse("Failure in isStopped: expected false, got true",
1176: mComponent.isStopped());
1177: }
1178:
1179: /**
1180: * Test the isObserver/setObserver methods.
1181: * @throws Exception if an unexpected error occurs.
1182: */
1183: public void testIsSetObserver() throws Exception {
1184: // The first time, this will check for Observer in the installation
1185: // desriptor. However, in test mode, this should always fail.
1186: assertFalse("Failure in isObserver: expected false, got true",
1187: mComponent.isObserver());
1188:
1189: // Set the Observer flag to true, this will succeed
1190: mComponent.setObserver(true);
1191: assertTrue("Failure in setObserver: expected true, got false",
1192: mComponent.isObserver());
1193:
1194: // Set the Observer flag to false, this will succeed
1195: mComponent.setObserver(false);
1196: assertFalse("Failure in setObserver: expected false, got true",
1197: mComponent.isObserver());
1198: }
1199:
1200: /**
1201: * Test the isUpdating/setUpdating/clearUpdating methods.
1202: * @throws Exception if an unexpected error occurs.
1203: */
1204: public void testIsSetClearUpdating() throws Exception {
1205: // The updating flag has not been set.
1206: assertFalse("Failure in isUpdating: expected false, got true",
1207: mComponent.isUpdating());
1208:
1209: // Set the updating flag. This will succeed.
1210: mComponent.setUpdating();
1211: assertTrue("Failure in setUpdating: expected true, got false",
1212: mComponent.isUpdating());
1213:
1214: // Clear the updating flag. This will succeed.
1215: mComponent.clearUpdating();
1216: assertFalse(
1217: "Failure in clearUpdating: expected false, got true",
1218: mComponent.isUpdating());
1219:
1220: // Now set the busy flag before trying to set the updating flag. This
1221: // should fail.
1222: mComponent.setBusy();
1223: try {
1224: mComponent.setUpdating();
1225: fail("Expected exception not received");
1226: } catch (javax.jbi.JBIException ex) {
1227: // Verification
1228: assertTrue(
1229: "Incorrect exception received: " + ex.toString(),
1230: (-1 < ex.getMessage().indexOf("JBIFW2011")));
1231: }
1232: }
1233:
1234: /**
1235: * Test the removeServiceUnit method.
1236: * @throws Exception if an unexpected error occurs.
1237: */
1238: public void testRemoveServiceUnit() throws Exception {
1239: ServiceUnit su1 = new ServiceUnit("TestSA1", "TestSU1",
1240: "jbi/deployment/su1");
1241: ServiceUnit su2 = new ServiceUnit("TestSA2", "TestSU2",
1242: "jbi/deployment/su2");
1243: ArrayList suList = new ArrayList();
1244:
1245: suList.add(su2);
1246: suList.add(su1);
1247: mComponent.addServiceUnit(su1);
1248: mComponent.addServiceUnit(su2);
1249:
1250: mComponent.removeServiceUnit("TestSU2");
1251: assertFalse("Failure removing ServiceUnit: expected false",
1252: mComponent.getServiceUnitList().contains(su2));
1253: assertEquals("Failure adding/getting ServiceUnit: ", 1,
1254: mComponent.getServiceUnitList().size());
1255:
1256: mComponent.removeServiceUnit("TestSU1");
1257: assertFalse("Failure removing ServiceUnit: expected false",
1258: mComponent.getServiceUnitList().contains(su1));
1259: assertEquals("Failure adding/getting ServiceUnit: ", 0,
1260: mComponent.getServiceUnitList().size());
1261: }
1262:
1263: /**
1264: * Test the removeServiceUnit method with a non-existent Service Unit name.
1265: * An exception is expected.
1266: * @throws Exception if an unexpected error occurs.
1267: */
1268: public void testRemoveServiceUnitBadNotFound() throws Exception {
1269: try {
1270: mComponent.removeServiceUnit("noname");
1271: fail("Expected exception not received");
1272: } catch (javax.jbi.JBIException ex) {
1273: // Verification
1274: assertTrue(
1275: "Incorrect exception received: " + ex.toString(),
1276: (-1 < ex.getMessage().indexOf("not found for")));
1277: }
1278: }
1279:
1280: /**
1281: * Test the setShutdown method.
1282: * @throws Exception if an unexpected error occurs.
1283: */
1284: public void testSetShutdown() throws Exception {
1285: // Set LOADED component to SHUTDOWN. This is allowed.
1286: mComponent.setStatus(ComponentState.LOADED);
1287: mComponent.setShutdown();
1288: assertEquals("Failure in setShutdown: state set to "
1289: + mComponent.getStatusAsString(), mComponent
1290: .getStatus(), ComponentState.SHUTDOWN);
1291:
1292: // Set STOPPED component to SHUTDOWN. This is allowed.
1293: mComponent.setStatus(ComponentState.STOPPED);
1294: mComponent.setShutdown();
1295: assertEquals("Failure in setShutdown: state set to "
1296: + mComponent.getStatusAsString(), mComponent
1297: .getStatus(), ComponentState.SHUTDOWN);
1298:
1299: // Set STARTED component to SHUTDOWN. This is not allowed.
1300: try {
1301: mComponent.setStatus(ComponentState.STARTED);
1302: mComponent.setShutdown();
1303: fail("Expected exception not received");
1304: } catch (java.lang.IllegalStateException ex) {
1305: // Verification
1306: assertTrue(
1307: "Incorrect exception received: " + ex.toString(),
1308: (-1 < ex.getMessage()
1309: .indexOf("state cannot change")));
1310: }
1311: }
1312:
1313: /**
1314: * Test the setLoaded method.
1315: * @throws Exception if an unexpected error occurs.
1316: */
1317: public void testSetLoaded() throws Exception {
1318: // Set unset state to LOADED. This is allowed.
1319: mComponent.setLoaded();
1320: assertEquals("Failure in setLoaded: state set to "
1321: + mComponent.getStatusAsString(), mComponent
1322: .getStatus(), ComponentState.LOADED);
1323:
1324: // Set SHUTDOWN component to LOADED. This is allowed.
1325: mComponent.setStatus(ComponentState.SHUTDOWN);
1326: mComponent.setLoaded();
1327: assertEquals("Failure in setLoaded: state set to "
1328: + mComponent.getStatusAsString(), mComponent
1329: .getStatus(), ComponentState.LOADED);
1330:
1331: // Set STOPPED component to LOADED. This is not allowed.
1332: try {
1333: mComponent.setStatus(ComponentState.STOPPED);
1334: mComponent.setLoaded();
1335: fail("Expected exception not received");
1336: } catch (java.lang.IllegalStateException ex) {
1337: // Verification
1338: assertTrue(
1339: "Incorrect exception received: " + ex.toString(),
1340: (-1 < ex.getMessage()
1341: .indexOf("state cannot change")));
1342: }
1343:
1344: // Set STARTED component to LOADED. This is not allowed.
1345: try {
1346: mComponent.setStatus(ComponentState.STARTED);
1347: mComponent.setLoaded();
1348: fail("Expected exception not received");
1349: } catch (java.lang.IllegalStateException ex) {
1350: // Verification
1351: assertTrue(
1352: "Incorrect exception received: " + ex.toString(),
1353: (-1 < ex.getMessage()
1354: .indexOf("state cannot change")));
1355: }
1356: }
1357:
1358: /**
1359: * Test the setStarted method.
1360: * @throws Exception if an unexpected error occurs.
1361: */
1362: public void testSetStarted() throws Exception {
1363: // Set LOADED component to STARTED. This is not allowed.
1364: try {
1365: mComponent.setStatus(ComponentState.LOADED);
1366: mComponent.setStarted();
1367: fail("Expected exception not received");
1368: } catch (java.lang.IllegalStateException ex) {
1369: // Verification
1370: assertTrue(
1371: "Incorrect exception received: " + ex.toString(),
1372: (-1 < ex.getMessage()
1373: .indexOf("state cannot change")));
1374: }
1375:
1376: // Set SHUTDOWN component to STARTED. This is not allowed.
1377: try {
1378: mComponent.setStatus(ComponentState.SHUTDOWN);
1379: mComponent.setStarted();
1380: fail("Expected exception not received");
1381: } catch (java.lang.IllegalStateException ex) {
1382: // Verification
1383: assertTrue(
1384: "Incorrect exception received: " + ex.toString(),
1385: (-1 < ex.getMessage()
1386: .indexOf("state cannot change")));
1387: }
1388:
1389: // Set STOPPED component to STARTED. This is allowed.
1390: mComponent.setStatus(ComponentState.STOPPED);
1391: mComponent.setStarted();
1392: assertEquals("Failure in setStarted: state set to "
1393: + mComponent.getStatusAsString(), mComponent
1394: .getStatus(), ComponentState.STARTED);
1395: }
1396:
1397: /**
1398: * Test the setStopped method.
1399: * @throws Exception if an unexpected error occurs.
1400: */
1401: public void testSetStopped() throws Exception {
1402: // Set LOADED component to STOPPED. This is not allowed.
1403: try {
1404: mComponent.setStatus(ComponentState.LOADED);
1405: mComponent.setStopped();
1406: fail("Expected exception not received");
1407: } catch (java.lang.IllegalStateException ex) {
1408: // Verification
1409: assertTrue(
1410: "Incorrect exception received: " + ex.toString(),
1411: (-1 < ex.getMessage()
1412: .indexOf("state cannot change")));
1413: }
1414:
1415: // Set SHUTDOWN component to STOPPED. This is allowed.
1416: mComponent.setStatus(ComponentState.SHUTDOWN);
1417: mComponent.setStopped();
1418: assertEquals("Failure in setStopped: state set to "
1419: + mComponent.getStatusAsString(), mComponent
1420: .getStatus(), ComponentState.STOPPED);
1421:
1422: // Set STARTED component to STOPPED. This is allowed.
1423: mComponent.setStatus(ComponentState.STARTED);
1424: mComponent.setStopped();
1425: assertEquals("Failure in setStopped: state set to "
1426: + mComponent.getStatusAsString(), mComponent
1427: .getStatus(), ComponentState.STOPPED);
1428: }
1429:
1430: }
|