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: * @(#)TestDeployer.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.management.ComponentInstallationContext;
0032:
0033: import java.io.File;
0034: import java.net.URL;
0035: import java.util.ArrayList;
0036:
0037: import javax.jbi.management.DeploymentException;
0038: import com.sun.jbi.ServiceUnitState;
0039:
0040: /**
0041: * Tests for the Deployer.
0042: *
0043: * @author Sun Microsystems, Inc.
0044: */
0045: public class TestDeployer extends junit.framework.TestCase {
0046: /**
0047: * Current test name.
0048: */
0049: private String mTestName;
0050:
0051: /**
0052: * Current SRCROOT path.
0053: */
0054: private String mSrcroot;
0055:
0056: /**
0057: * Helper class to setup environment for testing.
0058: */
0059: private EnvironmentSetup mSetup;
0060:
0061: /**
0062: * Instance of the EnvironmentContext class.
0063: */
0064: private EnvironmentContext mContext;
0065:
0066: /**
0067: * Instance of Component.
0068: */
0069: private Component mComponent;
0070:
0071: /**
0072: * Local instance of the ComponentInstallationContext class.
0073: */
0074: private ComponentInstallationContext mInstallContext;
0075:
0076: /**
0077: * Instance of the ComponentFramework class.
0078: */
0079: private ComponentFramework mCompFW;
0080:
0081: /**
0082: * Local instance of the ComponentRegistry class.
0083: */
0084: private ComponentRegistry mCompReg;
0085:
0086: /**
0087: * Local instance of the Deployer class.
0088: */
0089: private Deployer mDeployer;
0090:
0091: /**
0092: * Service Unit root file path.
0093: */
0094: private String mServiceUnitRoot;
0095:
0096: /**
0097: * Constant for Service Assembly zip path.
0098: */
0099: public static final String SA_ZIP_PATH = "framework/regress/data/junit/";
0100:
0101: /**
0102: * Constant for Service Assembly zip name.
0103: */
0104: public static final String SA_ZIP_NAME = "Test_SA.zip";
0105:
0106: /**
0107: * Constant for Service Unit zip name.
0108: */
0109: public static final String SU_ZIP_NAME = "Test_SA_SU1.zip";
0110:
0111: /**
0112: * The constructor for this testcase, forwards the test name to
0113: * the jUnit TestCase base class.
0114: * @param aTestName String with the name of this test.
0115: */
0116: public TestDeployer(String aTestName) {
0117: super (aTestName);
0118: mTestName = aTestName;
0119: }
0120:
0121: /**
0122: * Setup for the test. This creates the ComponentRegistry instance
0123: * and other objects needed for the tests.
0124: * @throws Exception when set up fails for any reason.
0125: */
0126: public void setUp() throws Exception {
0127: super .setUp();
0128: System.err.println("***** START of test " + mTestName);
0129: mSrcroot = System.getProperty("junit.srcroot") + "/";
0130:
0131: // Create and initialize the EnvironmentContext. Create, initialize,
0132: // and start up the Component Registry and Framework.
0133:
0134: mSetup = new EnvironmentSetup();
0135: mContext = mSetup.getEnvironmentContext();
0136: mSetup.startup(true, true);
0137: mCompReg = mContext.getComponentRegistry();
0138: mCompFW = mContext.getComponentFramework();
0139:
0140: // Create component class path lists
0141:
0142: ArrayList bootstrapClassPath = new ArrayList();
0143: bootstrapClassPath.add(mSrcroot
0144: + Constants.BC_BOOTSTRAP_CLASS_PATH);
0145: ArrayList componentClassPath = new ArrayList();
0146: componentClassPath.add(Constants.BC_LIFECYCLE_CLASS_PATH);
0147:
0148: // Create installation context.
0149:
0150: mInstallContext = new ComponentInstallationContext(
0151: Constants.BC_NAME,
0152: ComponentInstallationContext.BINDING,
0153: Constants.BC_LIFECYCLE_CLASS_NAME, componentClassPath,
0154: null);
0155: mInstallContext.setInstallRoot(mSrcroot);
0156: mInstallContext.setIsInstall(true);
0157:
0158: // Install the component.
0159:
0160: mCompFW.loadBootstrap(mInstallContext,
0161: Constants.BC_BOOTSTRAP_CLASS_NAME, bootstrapClassPath,
0162: null);
0163: mCompFW.installComponent(mInstallContext);
0164:
0165: // Get the Component instance.
0166:
0167: mComponent = mCompReg.getComponent(Constants.BC_NAME);
0168:
0169: // Create a Deployer instance
0170:
0171: mDeployer = new Deployer(mCompReg
0172: .getComponent(Constants.BC_NAME));
0173: mComponent.setDeployerInstance(mDeployer);
0174:
0175: // Start the component
0176:
0177: mCompFW.startComponent(mComponent);
0178:
0179: // Set the service unit root path
0180:
0181: mServiceUnitRoot = mSrcroot + Constants.SU_ROOT;
0182: }
0183:
0184: /**
0185: * Cleanup for the test.
0186: * @throws Exception when tearDown fails for any reason.
0187: */
0188: public void tearDown() throws Exception {
0189: super .tearDown();
0190: mSetup.shutdown(true, true);
0191: System.err.println("***** END of test " + mTestName);
0192: }
0193:
0194: // ============================= test methods ================================
0195:
0196: /**
0197: * Tests deploy with a good result.
0198: * @throws Exception if an unexpected error occurs.
0199: */
0200:
0201: public void testDeployGood() throws Exception {
0202: String msg = mDeployer.deploy(Constants.SU_NAME,
0203: Constants.SU_ROOT);
0204: assertNotNull("Failure deploying Service Unit", msg);
0205: assertTrue("Failure deploying Service Unit", (-1 < msg
0206: .indexOf(Constants.SU_NAME)));
0207: }
0208:
0209: /**
0210: * Tests deploy with a null Service Unit name parameter.
0211: * An exception is expected.
0212: * @throws Exception if an unexpected error occurs.
0213: */
0214: public void testDeployBadNullServiceUnitName() throws Exception {
0215: try {
0216: mDeployer.deploy(null, Constants.SU_ROOT);
0217: fail("Expected exception not received");
0218: } catch (java.lang.IllegalArgumentException ex) {
0219: // Verification
0220: assertTrue(
0221: "Incorrect exception received: " + ex.toString(),
0222: (-1 < ex.getMessage().indexOf("serviceUnitName")));
0223: }
0224: }
0225:
0226: /**
0227: * Tests deploy with a null Service Unit root path parameter.
0228: * An exception is expected.
0229: * @throws Exception if an unexpected error occurs.
0230: */
0231: public void testDeployBadNullServiceUnitRootPath() throws Exception {
0232: try {
0233: mDeployer.deploy(Constants.SU_NAME, null);
0234: fail("Expected exception not received");
0235: } catch (java.lang.IllegalArgumentException ex) {
0236: // Verification
0237: assertTrue(
0238: "Incorrect exception received: " + ex.toString(),
0239: (-1 < ex.getMessage()
0240: .indexOf("serviceUnitRootPath")));
0241: }
0242: }
0243:
0244: /**
0245: * Tests deploy with a Service Unit that has already been deployed.
0246: * An exception is expected.
0247: * @throws Exception if an unexpected error occurs.
0248: */
0249: public void testDeployBadAlreadyDeployed() throws Exception {
0250: // First deploy and register the SU
0251:
0252: mDeployer.deploy(Constants.SU_NAME, Constants.SU_ROOT);
0253: mCompReg.registerServiceUnit(Constants.BC_NAME,
0254: Constants.SA_NAME, Constants.SU_NAME, mServiceUnitRoot);
0255:
0256: // Try to deploy again
0257:
0258: try {
0259: mDeployer.deploy(Constants.SU_NAME, Constants.SU_ROOT);
0260: fail("Expected exception not received");
0261: } catch (DeploymentException ex) {
0262: // Verification
0263: assertTrue(
0264: "Incorrect exception received: " + ex.toString(),
0265: (-1 < ex.getMessage().indexOf("JBIFW2451")));
0266: }
0267: }
0268:
0269: /**
0270: * Tests deploy with component that is not started.
0271: * An exception is expected.
0272: * @throws Exception if an unexpected error occurs.
0273: */
0274: public void testDeployBadComponentNotStarted() throws Exception {
0275: // Stop the component
0276:
0277: mCompFW.stopComponent(mComponent);
0278:
0279: // Attempt to deploy the SU. This should fail.
0280: try {
0281: mDeployer.deploy(Constants.SU_NAME, Constants.SU_ROOT);
0282: fail("Expected exception not received");
0283: } catch (DeploymentException ex) {
0284: // Verification
0285: assertTrue(
0286: "Incorrect exception received: " + ex.toString(),
0287: (-1 < ex.getMessage().indexOf(Constants.SU_NAME)));
0288: assertTrue(
0289: "Incorrect exception received: " + ex.toString(),
0290: (-1 < ex.getMessage().indexOf("JBIFW2462")));
0291: }
0292: }
0293:
0294: /**
0295: * Tests deploy with an exception from the deploy method.
0296: * An exception is expected.
0297: * @throws Exception if an unexpected error occurs.
0298: */
0299: public void testDeployBadException() throws Exception {
0300: try {
0301: mDeployer.deploy(Constants.SU_NAME_DEPLOY_EXCEPTION,
0302: Constants.SU_ROOT);
0303: fail("Expected exception not received");
0304: } catch (DeploymentException ex) {
0305: // Verification
0306: assertTrue(
0307: "Incorrect exception received: " + ex.toString(),
0308: (-1 < ex.getMessage().indexOf("failed to deploy")));
0309: }
0310: }
0311:
0312: /**
0313: * Tests deploy with a missing ServiceUnitManager. An exception is
0314: * expected.
0315: * @throws Exception if an unexpected error occurs.
0316: */
0317: public void testDeployBadNoSuMgr() throws Exception {
0318: mDeployer.setServiceUnitManager(null);
0319: try {
0320: mDeployer.deploy(Constants.SU_NAME, Constants.SU_ROOT);
0321: fail("Expected exception not received");
0322: } catch (DeploymentException ex) {
0323: // Verification
0324: assertTrue(
0325: "Incorrect exception received: " + ex.toString(),
0326: (-1 < ex.getMessage().indexOf("JBIFW2463")));
0327: }
0328: }
0329:
0330: /**
0331: * Tests deploy with a timeout on the deploy method.
0332: * An exception is expected.
0333: * @throws Exception if an unexpected error occurs.
0334: */
0335: public void testDeployBadTimeout() throws Exception {
0336: try {
0337: mDeployer.deploy(Constants.SU_NAME_DEPLOY_TIMEOUT,
0338: Constants.SU_ROOT);
0339: fail("Expected exception not received");
0340: } catch (DeploymentException ex) {
0341: // Verification
0342: assertTrue(
0343: "Incorrect exception received: " + ex.toString(),
0344: (-1 < ex.getMessage().indexOf("JBIFW2461")));
0345: assertTrue(
0346: "Incorrect exception received: " + ex.toString(),
0347: (-1 < ex.getMessage().indexOf(
0348: Constants.SU_NAME_DEPLOY_TIMEOUT)));
0349: }
0350: }
0351:
0352: /**
0353: * Tests getDeployments with a good result.
0354: * @throws Exception if an unexpected error occurs.
0355: */
0356:
0357: public void testGetDeploymentsGood() throws Exception {
0358: // First test with no deployments
0359:
0360: String[] deployments = mDeployer.getDeployments();
0361: assertEquals("Failure on getDeployments: ", 0,
0362: deployments.length);
0363:
0364: // Now test with one deployment
0365:
0366: mDeployer.deploy(Constants.SU_NAME, Constants.SU_ROOT);
0367: mCompReg.registerServiceUnit(Constants.BC_NAME,
0368: Constants.SA_NAME, Constants.SU_NAME, mServiceUnitRoot);
0369:
0370: deployments = mDeployer.getDeployments();
0371: assertEquals("Failure on getDeployments: ", 1,
0372: deployments.length);
0373: assertEquals("Failure on getDeployments: ", Constants.SU_NAME,
0374: deployments[0]);
0375: }
0376:
0377: /**
0378: * Tests getServiceUnitState with a good result.
0379: * @throws Exception if an unexpected error occurs.
0380: */
0381: public void testGetServiceUnitStateGood() throws Exception {
0382: mDeployer.deploy(Constants.SU_NAME, Constants.SU_ROOT);
0383: mCompReg.registerServiceUnit(Constants.BC_NAME,
0384: Constants.SA_NAME, Constants.SU_NAME, mServiceUnitRoot);
0385: ServiceUnit su = mComponent.getServiceUnit(Constants.SU_NAME);
0386:
0387: ServiceUnitState state = mDeployer
0388: .getServiceUnitState(Constants.SU_NAME);
0389: assertEquals("Failure on getServiceUnitState: ", su.getState(),
0390: state);
0391: }
0392:
0393: /**
0394: * Tests getServiceUnitState with a null Service Unit name.
0395: * An exception is expected.
0396: * @throws Exception if an unexpected error occurs.
0397: */
0398: public void testGetServiceUnitStateBadNullServiceUnitName()
0399: throws Exception {
0400: try {
0401: ServiceUnitState state = mDeployer
0402: .getServiceUnitState(null);
0403: fail("Expected exception not received");
0404: } catch (java.lang.IllegalArgumentException ex) {
0405: // Verification
0406: assertTrue(
0407: "Incorrect exception received: " + ex.toString(),
0408: (-1 < ex.getMessage().indexOf("serviceUnitName")));
0409: }
0410: }
0411:
0412: /**
0413: * Tests getServiceUnitState with a non-existent SU.
0414: * @throws Exception if an unexpected error occurs.
0415: */
0416: public void testGetServiceUnitStateBadServiceUnitNotDeployed()
0417: throws Exception {
0418: ServiceUnitState state = mDeployer
0419: .getServiceUnitState(Constants.SU_NAME);
0420: assertEquals("Failure on getServiceUnitState: ",
0421: ServiceUnitState.UNKNOWN, state);
0422: }
0423:
0424: /**
0425: * Tests isDeployed with a good result.
0426: * @throws Exception if an unexpected error occurs.
0427: */
0428:
0429: public void testIsDeployedGood() throws Exception {
0430: // First test with SU not deployed
0431:
0432: assertFalse("Failure on isDeployed: ", mDeployer
0433: .isDeployed(Constants.SU_NAME));
0434:
0435: // Now test with SU deployed
0436:
0437: String msg = mDeployer.deploy(Constants.SU_NAME,
0438: Constants.SU_ROOT);
0439: mCompReg.registerServiceUnit(Constants.BC_NAME,
0440: Constants.SA_NAME, Constants.SU_NAME, mServiceUnitRoot);
0441:
0442: assertTrue("Failure on isDeployed: ", mDeployer
0443: .isDeployed(Constants.SU_NAME));
0444: }
0445:
0446: /**
0447: * Tests isDeployed with a null Service Unit name parameter.
0448: * An exception is expected.
0449: * @throws Exception if an unexpected error occurs.
0450: */
0451: public void testIsDeployedBadNullServiceUnitName() throws Exception {
0452: try {
0453: mDeployer.isDeployed(null);
0454: fail("Expected exception not received");
0455: } catch (java.lang.IllegalArgumentException ex) {
0456: // Verification
0457: assertTrue(
0458: "Incorrect exception received: " + ex.toString(),
0459: (-1 < ex.getMessage().indexOf("serviceUnitName")));
0460: }
0461: }
0462:
0463: /**
0464: * Tests init with a good result.
0465: * @throws Exception if an unexpected error occurs.
0466: */
0467:
0468: public void testInitGood() throws Exception {
0469: // Deploy the SU
0470:
0471: mDeployer.deploy(Constants.SU_NAME, Constants.SU_ROOT);
0472: mCompReg.registerServiceUnit(Constants.BC_NAME,
0473: Constants.SA_NAME, Constants.SU_NAME, mServiceUnitRoot);
0474: ServiceUnit su = mComponent.getServiceUnit(Constants.SU_NAME);
0475:
0476: // Test the init
0477:
0478: mDeployer.init(Constants.SU_NAME, Constants.SU_ROOT);
0479: assertEquals("Failure on init: ", ServiceUnitState.STOPPED, su
0480: .getState());
0481: assertEquals("Failure on init: ", ServiceUnitState.STOPPED, su
0482: .getDesiredState());
0483:
0484: // Test the init again, this one's a no-op
0485:
0486: mDeployer.init(Constants.SU_NAME, Constants.SU_ROOT);
0487: assertEquals("Failure on init: ", ServiceUnitState.STOPPED, su
0488: .getState());
0489: assertEquals("Failure on init: ", ServiceUnitState.STOPPED, su
0490: .getDesiredState());
0491: }
0492:
0493: /**
0494: * Tests init with a null Service Unit name parameter.
0495: * An exception is expected.
0496: * @throws Exception if an unexpected error occurs.
0497: */
0498: public void testInitBadNullServiceUnitName() throws Exception {
0499: try {
0500: mDeployer.init(null, Constants.SU_ROOT);
0501: fail("Expected exception not received");
0502: } catch (java.lang.IllegalArgumentException ex) {
0503: // Verification
0504: assertTrue(
0505: "Incorrect exception received: " + ex.toString(),
0506: (-1 < ex.getMessage().indexOf("serviceUnitName")));
0507: }
0508: }
0509:
0510: /**
0511: * Tests init with a null Service Unit root path parameter.
0512: * An exception is expected.
0513: * @throws Exception if an unexpected error occurs.
0514: */
0515: public void testInitBadNullServiceUnitRoot() throws Exception {
0516: try {
0517: mDeployer.init(Constants.SU_NAME, null);
0518: fail("Expected exception not received");
0519: } catch (java.lang.IllegalArgumentException ex) {
0520: // Verification
0521: assertTrue(
0522: "Incorrect exception received: " + ex.toString(),
0523: (-1 < ex.getMessage()
0524: .indexOf("serviceUnitRootPath")));
0525: }
0526: }
0527:
0528: /**
0529: * Tests init with a Service Unit that is not deployed.
0530: * An exception is expected.
0531: * @throws Exception if an unexpected error occurs.
0532: */
0533: public void testInitBadServiceUnitNotDeployed() throws Exception {
0534: try {
0535: mDeployer.init(Constants.SU_NAME, Constants.SU_ROOT);
0536: fail("Expected exception not received");
0537: } catch (DeploymentException ex) {
0538: // Verification
0539: assertTrue(
0540: "Incorrect exception received: " + ex.toString(),
0541: (-1 < ex.getMessage().indexOf(Constants.SU_NAME)));
0542: assertTrue(
0543: "Incorrect exception received: " + ex.toString(),
0544: (-1 < ex.getMessage().indexOf("JBIFW2450")));
0545: }
0546: }
0547:
0548: /**
0549: * Tests init with a Service Unit that is started.
0550: * An exception is expected.
0551: * @throws Exception if an unexpected error occurs.
0552: */
0553: public void testInitBadServiceUnitStarted() throws Exception {
0554: // Deploy the SU, initialize it, and start it
0555:
0556: mDeployer.deploy(Constants.SU_NAME, Constants.SU_ROOT);
0557: mCompReg.registerServiceUnit(Constants.BC_NAME,
0558: Constants.SA_NAME, Constants.SU_NAME, mServiceUnitRoot);
0559: ServiceUnit su = mComponent.getServiceUnit(Constants.SU_NAME);
0560: mDeployer.init(Constants.SU_NAME, Constants.SU_ROOT);
0561: mDeployer.start(Constants.SU_NAME);
0562:
0563: // This init will fail
0564:
0565: try {
0566: mDeployer.init(Constants.SU_NAME, Constants.SU_ROOT);
0567: fail("Expected exception not received");
0568: } catch (DeploymentException ex) {
0569: // Verification
0570: assertTrue(
0571: "Incorrect exception received: " + ex.toString(),
0572: (-1 < ex.getMessage().indexOf(Constants.SU_NAME)));
0573: assertTrue(
0574: "Incorrect exception received: " + ex.toString(),
0575: (-1 < ex.getMessage().indexOf("JBIFW2452")));
0576: assertEquals("Failure on init: ", ServiceUnitState.STARTED,
0577: su.getDesiredState());
0578: }
0579: }
0580:
0581: /**
0582: * Tests init with a component that is not started.
0583: * An exception is expected.
0584: * @throws Exception if an unexpected error occurs.
0585: */
0586: public void testInitBadComponentNotStarted() throws Exception {
0587: // Deploy the SU
0588:
0589: mDeployer.deploy(Constants.SU_NAME, Constants.SU_ROOT);
0590: mCompReg.registerServiceUnit(Constants.BC_NAME,
0591: Constants.SA_NAME, Constants.SU_NAME, mServiceUnitRoot);
0592: ServiceUnit su = mComponent.getServiceUnit(Constants.SU_NAME);
0593:
0594: // Stop the component
0595:
0596: mCompFW.stopComponent(mComponent);
0597:
0598: // Attempt to init the SU. This should fail.
0599: try {
0600: mDeployer.init(Constants.SU_NAME, Constants.SU_ROOT);
0601: fail("Expected exception not received");
0602: } catch (DeploymentException ex) {
0603: // Verification
0604: assertTrue(
0605: "Incorrect exception received: " + ex.toString(),
0606: (-1 < ex.getMessage().indexOf(Constants.SU_NAME)));
0607: assertTrue(
0608: "Incorrect exception received: " + ex.toString(),
0609: (-1 < ex.getMessage().indexOf("JBIFW2462")));
0610: assertEquals("Failure on init: ",
0611: ServiceUnitState.SHUTDOWN, su.getDesiredState());
0612: }
0613: }
0614:
0615: /**
0616: * Tests init with an exception from the init method.
0617: * An exception is expected.
0618: * @throws Exception if an unexpected error occurs.
0619: */
0620: public void testInitBadException() throws Exception {
0621: // Deploy the SU
0622:
0623: mDeployer.deploy(Constants.SU_NAME_INIT_EXCEPTION,
0624: Constants.SU_ROOT);
0625: mCompReg.registerServiceUnit(Constants.BC_NAME,
0626: Constants.SA_NAME, Constants.SU_NAME_INIT_EXCEPTION,
0627: mServiceUnitRoot);
0628: ServiceUnit su = mComponent
0629: .getServiceUnit(Constants.SU_NAME_INIT_EXCEPTION);
0630:
0631: // This init will fail
0632:
0633: try {
0634: mDeployer.init(Constants.SU_NAME_INIT_EXCEPTION,
0635: Constants.SU_ROOT);
0636: fail("Expected exception not received");
0637: } catch (DeploymentException ex) {
0638: // Verification
0639: assertTrue(
0640: "Incorrect exception received: " + ex.toString(),
0641: (-1 < ex.getMessage().indexOf(
0642: "failed to initialize")));
0643: assertEquals("Failure on init: ", ServiceUnitState.STOPPED,
0644: su.getDesiredState());
0645: }
0646: }
0647:
0648: /**
0649: * Tests init with a timeout on the init method.
0650: * An exception is expected.
0651: * @throws Exception if an unexpected error occurs.
0652: */
0653: public void testInitBadTimeout() throws Exception {
0654: // Deploy the SU
0655:
0656: mDeployer.deploy(Constants.SU_NAME_INIT_TIMEOUT,
0657: Constants.SU_ROOT);
0658: mCompReg.registerServiceUnit(Constants.BC_NAME,
0659: Constants.SA_NAME, Constants.SU_NAME_INIT_TIMEOUT,
0660: mServiceUnitRoot);
0661: ServiceUnit su = mComponent
0662: .getServiceUnit(Constants.SU_NAME_INIT_TIMEOUT);
0663:
0664: // This init will time out
0665:
0666: try {
0667: mDeployer.init(Constants.SU_NAME_INIT_TIMEOUT,
0668: Constants.SU_ROOT);
0669: fail("Expected exception not received");
0670: } catch (DeploymentException ex) {
0671: // Verification
0672: assertTrue(
0673: "Incorrect exception received: " + ex.toString(),
0674: (-1 < ex.getMessage().indexOf(
0675: Constants.SU_NAME_INIT_TIMEOUT)));
0676: assertTrue(
0677: "Incorrect exception received: " + ex.toString(),
0678: (-1 < ex.getMessage().indexOf("JBIFW2461")));
0679: assertEquals("Failure on init: ", ServiceUnitState.STOPPED,
0680: su.getDesiredState());
0681: }
0682: }
0683:
0684: /**
0685: * Tests start with a good result.
0686: * @throws Exception if an unexpected error occurs.
0687: */
0688:
0689: public void testStartGood() throws Exception {
0690: // Deploy the SU and initialize it
0691:
0692: mDeployer.deploy(Constants.SU_NAME, Constants.SU_ROOT);
0693: mCompReg.registerServiceUnit(Constants.BC_NAME,
0694: Constants.SA_NAME, Constants.SU_NAME, mServiceUnitRoot);
0695: ServiceUnit su = mComponent.getServiceUnit(Constants.SU_NAME);
0696: mDeployer.init(Constants.SU_NAME, Constants.SU_ROOT);
0697:
0698: // Test the start
0699:
0700: mDeployer.start(Constants.SU_NAME);
0701: assertEquals("Failure on start: ", ServiceUnitState.STARTED, su
0702: .getState());
0703:
0704: // Test the start again, this is a no-op
0705:
0706: mDeployer.start(Constants.SU_NAME);
0707: assertEquals("Failure on start: ", ServiceUnitState.STARTED, su
0708: .getState());
0709: assertEquals("Failure on start: ", ServiceUnitState.STARTED, su
0710: .getDesiredState());
0711: }
0712:
0713: /**
0714: * Tests start with a null Service Unit name parameter.
0715: * An exception is expected.
0716: * @throws Exception if an unexpected error occurs.
0717: */
0718: public void testStartBadNullServiceUnitName() throws Exception {
0719: try {
0720: mDeployer.start(null);
0721: fail("Expected exception not received");
0722: } catch (java.lang.IllegalArgumentException ex) {
0723: // Verification
0724: assertTrue(
0725: "Incorrect exception received: " + ex.toString(),
0726: (-1 < ex.getMessage().indexOf("serviceUnitName")));
0727: }
0728: }
0729:
0730: /**
0731: * Tests start with a Service Unit that is not deployed.
0732: * An exception is expected.
0733: * @throws Exception if an unexpected error occurs.
0734: */
0735: public void testStartBadServiceUnitNotDeployed() throws Exception {
0736: try {
0737: mDeployer.start(Constants.SU_NAME);
0738: fail("Expected exception not received");
0739: } catch (DeploymentException ex) {
0740: // Verification
0741: assertTrue(
0742: "Incorrect exception received: " + ex.toString(),
0743: (-1 < ex.getMessage().indexOf(Constants.SU_NAME)));
0744: assertTrue(
0745: "Incorrect exception received: " + ex.toString(),
0746: (-1 < ex.getMessage().indexOf("JBIFW2450")));
0747: }
0748: }
0749:
0750: /**
0751: * Tests start with a Service Unit that is not initialized.
0752: * An exception is expected.
0753: * @throws Exception if an unexpected error occurs.
0754: */
0755: public void testStartBadServiceUnitNotInitialized()
0756: throws Exception {
0757: // Deploy the SU
0758:
0759: mDeployer.deploy(Constants.SU_NAME, Constants.SU_ROOT);
0760: mCompReg.registerServiceUnit(Constants.BC_NAME,
0761: Constants.SA_NAME, Constants.SU_NAME, mServiceUnitRoot);
0762: ServiceUnit su = mComponent.getServiceUnit(Constants.SU_NAME);
0763:
0764: // This start will fail
0765:
0766: try {
0767: mDeployer.start(Constants.SU_NAME);
0768: fail("Expected exception not received");
0769: } catch (DeploymentException ex) {
0770: // Verification
0771: assertTrue(
0772: "Incorrect exception received: " + ex.toString(),
0773: (-1 < ex.getMessage().indexOf(Constants.SU_NAME)));
0774: assertTrue(
0775: "Incorrect exception received: " + ex.toString(),
0776: (-1 < ex.getMessage().indexOf("JBIFW2453")));
0777: assertEquals("Failure on start: ",
0778: ServiceUnitState.SHUTDOWN, su.getDesiredState());
0779: }
0780: }
0781:
0782: /**
0783: * Tests start with a component that is not started.
0784: * An exception is expected.
0785: * @throws Exception if an unexpected error occurs.
0786: */
0787: public void testStartBadComponentNotStarted() throws Exception {
0788: // Deploy the SU
0789:
0790: mDeployer.deploy(Constants.SU_NAME, Constants.SU_ROOT);
0791: mCompReg.registerServiceUnit(Constants.BC_NAME,
0792: Constants.SA_NAME, Constants.SU_NAME, mServiceUnitRoot);
0793: ServiceUnit su = mComponent.getServiceUnit(Constants.SU_NAME);
0794:
0795: // Stop the component
0796:
0797: mCompFW.stopComponent(mComponent);
0798:
0799: // Attempt to start the SU. This should fail.
0800: try {
0801: mDeployer.start(Constants.SU_NAME);
0802: fail("Expected exception not received");
0803: } catch (DeploymentException ex) {
0804: // Verification
0805: assertTrue(
0806: "Incorrect exception received: " + ex.toString(),
0807: (-1 < ex.getMessage().indexOf(Constants.SU_NAME)));
0808: assertTrue(
0809: "Incorrect exception received: " + ex.toString(),
0810: (-1 < ex.getMessage().indexOf("JBIFW2462")));
0811: assertEquals("Failure on start: ",
0812: ServiceUnitState.SHUTDOWN, su.getDesiredState());
0813: }
0814: }
0815:
0816: /**
0817: * Tests start with an exception from the start method.
0818: * An exception is expected.
0819: * @throws Exception if an unexpected error occurs.
0820: */
0821: public void testStartBadException() throws Exception {
0822: // Deploy the SU and initialize it
0823:
0824: mDeployer.deploy(Constants.SU_NAME_START_EXCEPTION,
0825: Constants.SU_ROOT);
0826: mCompReg.registerServiceUnit(Constants.BC_NAME,
0827: Constants.SA_NAME, Constants.SU_NAME_START_EXCEPTION,
0828: mServiceUnitRoot);
0829: ServiceUnit su = mComponent
0830: .getServiceUnit(Constants.SU_NAME_START_EXCEPTION);
0831: mDeployer.init(Constants.SU_NAME_START_EXCEPTION,
0832: Constants.SU_ROOT);
0833:
0834: // Test the start, this will fail
0835:
0836: try {
0837: mDeployer.start(Constants.SU_NAME_START_EXCEPTION);
0838: fail("Expected exception not received");
0839: } catch (DeploymentException ex) {
0840: // Verification
0841: assertTrue(
0842: "Incorrect exception received: " + ex.toString(),
0843: (-1 < ex.getMessage().indexOf("failed to start")));
0844: assertEquals("Failure on start: ",
0845: ServiceUnitState.STARTED, su.getDesiredState());
0846: }
0847: }
0848:
0849: /**
0850: * Tests start with a timeout on the start method.
0851: * An exception is expected.
0852: * @throws Exception if an unexpected error occurs.
0853: */
0854: public void testStartBadTimeout() throws Exception {
0855: // Deploy the SU and initialize it
0856:
0857: mDeployer.deploy(Constants.SU_NAME_START_TIMEOUT,
0858: Constants.SU_ROOT);
0859: mCompReg.registerServiceUnit(Constants.BC_NAME,
0860: Constants.SA_NAME, Constants.SU_NAME_START_TIMEOUT,
0861: mServiceUnitRoot);
0862: ServiceUnit su = mComponent
0863: .getServiceUnit(Constants.SU_NAME_START_TIMEOUT);
0864: mDeployer.init(Constants.SU_NAME_START_TIMEOUT,
0865: Constants.SU_ROOT);
0866:
0867: // Test the start, this will time out
0868:
0869: try {
0870: mDeployer.start(Constants.SU_NAME_START_TIMEOUT);
0871: fail("Expected exception not received");
0872: } catch (DeploymentException ex) {
0873: // Verification
0874: assertTrue(
0875: "Incorrect exception received: " + ex.toString(),
0876: (-1 < ex.getMessage().indexOf(
0877: Constants.SU_NAME_START_TIMEOUT)));
0878: assertTrue(
0879: "Incorrect exception received: " + ex.toString(),
0880: (-1 < ex.getMessage().indexOf("JBIFW2461")));
0881: assertEquals("Failure on start: ",
0882: ServiceUnitState.STARTED, su.getDesiredState());
0883: }
0884: }
0885:
0886: /**
0887: * Tests stop with a good result.
0888: * @throws Exception if an unexpected error occurs.
0889: */
0890:
0891: public void testStopGood() throws Exception {
0892: // Deploy the SU and initialize and start it
0893:
0894: mDeployer.deploy(Constants.SU_NAME, Constants.SU_ROOT);
0895: mCompReg.registerServiceUnit(Constants.BC_NAME,
0896: Constants.SA_NAME, Constants.SU_NAME, mServiceUnitRoot);
0897: ServiceUnit su = mComponent.getServiceUnit(Constants.SU_NAME);
0898: mDeployer.init(Constants.SU_NAME, Constants.SU_ROOT);
0899: mDeployer.start(Constants.SU_NAME);
0900:
0901: // Test the stop
0902:
0903: mDeployer.stop(Constants.SU_NAME);
0904: assertEquals("Failure on stop: ", ServiceUnitState.STOPPED, su
0905: .getState());
0906: assertEquals("Failure on stop: ", ServiceUnitState.STOPPED, su
0907: .getDesiredState());
0908:
0909: // Test the stop again, this is a no-op
0910:
0911: mDeployer.stop(Constants.SU_NAME);
0912: assertEquals("Failure on stop: ", ServiceUnitState.STOPPED, su
0913: .getState());
0914: assertEquals("Failure on stop: ", ServiceUnitState.STOPPED, su
0915: .getDesiredState());
0916: }
0917:
0918: /**
0919: * Tests stop with a null Service Unit name parameter.
0920: * An exception is expected.
0921: * @throws Exception if an unexpected error occurs.
0922: */
0923: public void testStopBadNullServiceUnitName() throws Exception {
0924: try {
0925: mDeployer.stop(null);
0926: fail("Expected exception not received");
0927: } catch (java.lang.IllegalArgumentException ex) {
0928: // Verification
0929: assertTrue(
0930: "Incorrect exception received: " + ex.toString(),
0931: (-1 < ex.getMessage().indexOf("serviceUnitName")));
0932: }
0933: }
0934:
0935: /**
0936: * Tests stop with a Service Unit that is not deployed.
0937: * An exception is expected.
0938: * @throws Exception if an unexpected error occurs.
0939: */
0940: public void testStopBadServiceUnitNotDeployed() throws Exception {
0941: try {
0942: mDeployer.stop(Constants.SU_NAME);
0943: fail("Expected exception not received");
0944: } catch (DeploymentException ex) {
0945: // Verification
0946: assertTrue(
0947: "Incorrect exception received: " + ex.toString(),
0948: (-1 < ex.getMessage().indexOf(Constants.SU_NAME)));
0949: assertTrue(
0950: "Incorrect exception received: " + ex.toString(),
0951: (-1 < ex.getMessage().indexOf("JBIFW2450")));
0952: }
0953: }
0954:
0955: /**
0956: * Tests stop with a Service Unit that is not initialized.
0957: * An exception is expected.
0958: * @throws Exception if an unexpected error occurs.
0959: */
0960: public void testStopBadServiceUnitNotInitialized() throws Exception {
0961: // Deploy the SU
0962:
0963: mDeployer.deploy(Constants.SU_NAME, Constants.SU_ROOT);
0964: mCompReg.registerServiceUnit(Constants.BC_NAME,
0965: Constants.SA_NAME, Constants.SU_NAME, mServiceUnitRoot);
0966: ServiceUnit su = mComponent.getServiceUnit(Constants.SU_NAME);
0967:
0968: // This stop will fail
0969:
0970: try {
0971: mDeployer.stop(Constants.SU_NAME);
0972: fail("Expected exception not received");
0973: } catch (DeploymentException ex) {
0974: // Verification
0975: assertTrue(
0976: "Incorrect exception received: " + ex.toString(),
0977: (-1 < ex.getMessage().indexOf(Constants.SU_NAME)));
0978: assertTrue(
0979: "Incorrect exception received: " + ex.toString(),
0980: (-1 < ex.getMessage().indexOf("JBIFW2454")));
0981: assertEquals("Failure on stop: ",
0982: ServiceUnitState.SHUTDOWN, su.getDesiredState());
0983: }
0984: }
0985:
0986: /**
0987: * Tests stop with a component that is not started.
0988: * An exception is expected.
0989: * @throws Exception if an unexpected error occurs.
0990: */
0991: public void testStopBadComponentNotStarted() throws Exception {
0992: // Deploy the SU
0993:
0994: mDeployer.deploy(Constants.SU_NAME, Constants.SU_ROOT);
0995: mCompReg.registerServiceUnit(Constants.BC_NAME,
0996: Constants.SA_NAME, Constants.SU_NAME, mServiceUnitRoot);
0997: ServiceUnit su = mComponent.getServiceUnit(Constants.SU_NAME);
0998:
0999: // Stop the component
1000:
1001: mCompFW.stopComponent(mComponent);
1002:
1003: // Attempt to stop the SU. This should fail.
1004: try {
1005: mDeployer.stop(Constants.SU_NAME);
1006: fail("Expected exception not received");
1007: } catch (DeploymentException ex) {
1008: // Verification
1009: assertTrue(
1010: "Incorrect exception received: " + ex.toString(),
1011: (-1 < ex.getMessage().indexOf(Constants.SU_NAME)));
1012: assertTrue(
1013: "Incorrect exception received: " + ex.toString(),
1014: (-1 < ex.getMessage().indexOf("JBIFW2462")));
1015: assertEquals("Failure on stop: ",
1016: ServiceUnitState.SHUTDOWN, su.getDesiredState());
1017: }
1018: }
1019:
1020: /**
1021: * Tests stop with an exception from the stop method.
1022: * An exception is expected.
1023: * @throws Exception if an unexpected error occurs.
1024: */
1025: public void testStopBadException() throws Exception {
1026: // Deploy the SU and initialize and start it
1027:
1028: mDeployer.deploy(Constants.SU_NAME_STOP_EXCEPTION,
1029: Constants.SU_ROOT);
1030: mCompReg.registerServiceUnit(Constants.BC_NAME,
1031: Constants.SA_NAME, Constants.SU_NAME_STOP_EXCEPTION,
1032: mServiceUnitRoot);
1033: ServiceUnit su = mComponent
1034: .getServiceUnit(Constants.SU_NAME_STOP_EXCEPTION);
1035: mDeployer.init(Constants.SU_NAME_STOP_EXCEPTION,
1036: Constants.SU_ROOT);
1037: mDeployer.start(Constants.SU_NAME_STOP_EXCEPTION);
1038:
1039: // Test the stop, this will fail
1040:
1041: try {
1042: mDeployer.stop(Constants.SU_NAME_STOP_EXCEPTION);
1043: fail("Expected exception not received");
1044: } catch (DeploymentException ex) {
1045: // Verification
1046: assertTrue(
1047: "Incorrect exception received: " + ex.toString(),
1048: (-1 < ex.getMessage().indexOf("failed to stop")));
1049: assertEquals("Failure on stop: ", ServiceUnitState.STOPPED,
1050: su.getDesiredState());
1051: }
1052: }
1053:
1054: /**
1055: * Tests stop with a timeout on the stop method.
1056: * An exception is expected.
1057: * @throws Exception if an unexpected error occurs.
1058: */
1059: public void testStopBadTimeout() throws Exception {
1060: // Deploy the SU and initialize and start it
1061:
1062: mDeployer.deploy(Constants.SU_NAME_STOP_TIMEOUT,
1063: Constants.SU_ROOT);
1064: mCompReg.registerServiceUnit(Constants.BC_NAME,
1065: Constants.SA_NAME, Constants.SU_NAME_STOP_TIMEOUT,
1066: mServiceUnitRoot);
1067: ServiceUnit su = mComponent
1068: .getServiceUnit(Constants.SU_NAME_STOP_TIMEOUT);
1069: mDeployer.init(Constants.SU_NAME_STOP_TIMEOUT,
1070: Constants.SU_ROOT);
1071: mDeployer.start(Constants.SU_NAME_STOP_TIMEOUT);
1072:
1073: // Test the stop, this will time out
1074:
1075: try {
1076: mDeployer.stop(Constants.SU_NAME_STOP_TIMEOUT);
1077: fail("Expected exception not received");
1078: } catch (DeploymentException ex) {
1079: // Verification
1080: assertTrue(
1081: "Incorrect exception received: " + ex.toString(),
1082: (-1 < ex.getMessage().indexOf(
1083: Constants.SU_NAME_STOP_TIMEOUT)));
1084: assertTrue(
1085: "Incorrect exception received: " + ex.toString(),
1086: (-1 < ex.getMessage().indexOf("JBIFW2461")));
1087: assertEquals("Failure on stop: ", ServiceUnitState.STOPPED,
1088: su.getDesiredState());
1089: }
1090: }
1091:
1092: /**
1093: * Tests shutdown with a good result.
1094: * @throws Exception if an unexpected error occurs.
1095: */
1096:
1097: public void testShutDownGood() throws Exception {
1098: // Deploy the SU and initialize, start, and stop it
1099:
1100: mDeployer.deploy(Constants.SU_NAME, Constants.SU_ROOT);
1101: mCompReg.registerServiceUnit(Constants.BC_NAME,
1102: Constants.SA_NAME, Constants.SU_NAME, mServiceUnitRoot);
1103: ServiceUnit su = mComponent.getServiceUnit(Constants.SU_NAME);
1104: mDeployer.init(Constants.SU_NAME, Constants.SU_ROOT);
1105: mDeployer.start(Constants.SU_NAME);
1106: mDeployer.stop(Constants.SU_NAME);
1107:
1108: // Test the shutdown
1109:
1110: mDeployer.shutDown(Constants.SU_NAME);
1111: assertEquals("Failure on shutDown: ",
1112: ServiceUnitState.SHUTDOWN, su.getState());
1113: assertEquals("Failure on shutDown: ",
1114: ServiceUnitState.SHUTDOWN, su.getDesiredState());
1115:
1116: // Test the shutdown again, this is a no-op
1117:
1118: mDeployer.shutDown(Constants.SU_NAME);
1119: assertEquals("Failure on shutDown: ",
1120: ServiceUnitState.SHUTDOWN, su.getState());
1121: assertEquals("Failure on shutDown: ",
1122: ServiceUnitState.SHUTDOWN, su.getDesiredState());
1123: }
1124:
1125: /**
1126: * Tests shutDown with a null Service Unit name parameter.
1127: * An exception is expected.
1128: * @throws Exception if an unexpected error occurs.
1129: */
1130: public void testShutDownBadNullServiceUnitName() throws Exception {
1131: try {
1132: mDeployer.shutDown(null);
1133: fail("Expected exception not received");
1134: } catch (java.lang.IllegalArgumentException ex) {
1135: // Verification
1136: assertTrue(
1137: "Incorrect exception received: " + ex.toString(),
1138: (-1 < ex.getMessage().indexOf("serviceUnitName")));
1139: }
1140: }
1141:
1142: /**
1143: * Tests shutDown with a Service Unit that is not deployed.
1144: * An exception is expected.
1145: * @throws Exception if an unexpected error occurs.
1146: */
1147: public void testShutDownBadServiceUnitNotDeployed()
1148: throws Exception {
1149: try {
1150: mDeployer.shutDown(Constants.SU_NAME);
1151: fail("Expected exception not received");
1152: } catch (DeploymentException ex) {
1153: // Verification
1154: assertTrue(
1155: "Incorrect exception received: " + ex.toString(),
1156: (-1 < ex.getMessage().indexOf(Constants.SU_NAME)));
1157: assertTrue(
1158: "Incorrect exception received: " + ex.toString(),
1159: (-1 < ex.getMessage().indexOf("JBIFW2450")));
1160: }
1161: }
1162:
1163: /**
1164: * Tests shutdown with a Service Unit that is not stopped.
1165: * @throws Exception if an unexpected error occurs.
1166: */
1167:
1168: public void testShutDownBadNotStopped() throws Exception {
1169: // Deploy the SU and initialize and start it
1170:
1171: mDeployer.deploy(Constants.SU_NAME, Constants.SU_ROOT);
1172: mCompReg.registerServiceUnit(Constants.BC_NAME,
1173: Constants.SA_NAME, Constants.SU_NAME, mServiceUnitRoot);
1174: ServiceUnit su = mComponent.getServiceUnit(Constants.SU_NAME);
1175: mDeployer.init(Constants.SU_NAME, Constants.SU_ROOT);
1176: mDeployer.start(Constants.SU_NAME);
1177:
1178: // Test the shutdown
1179:
1180: try {
1181: mDeployer.shutDown(Constants.SU_NAME);
1182: fail("Expected exception not received");
1183: } catch (DeploymentException ex) {
1184: // Verification
1185: assertTrue(
1186: "Incorrect exception received: " + ex.toString(),
1187: (-1 < ex.getMessage().indexOf(Constants.SU_NAME)));
1188: assertTrue(
1189: "Incorrect exception received: " + ex.toString(),
1190: (-1 < ex.getMessage().indexOf("JBIFW2455")));
1191: assertEquals("Failure on shutDown: ",
1192: ServiceUnitState.STARTED, su.getDesiredState());
1193: }
1194: }
1195:
1196: /**
1197: * Tests shutdown with a component that is not started.
1198: * An exception is expected.
1199: * @throws Exception if an unexpected error occurs.
1200: */
1201: public void testShutDownBadComponentNotStarted() throws Exception {
1202: // Deploy the SU
1203:
1204: mDeployer.deploy(Constants.SU_NAME, Constants.SU_ROOT);
1205: mCompReg.registerServiceUnit(Constants.BC_NAME,
1206: Constants.SA_NAME, Constants.SU_NAME, mServiceUnitRoot);
1207: ServiceUnit su = mComponent.getServiceUnit(Constants.SU_NAME);
1208:
1209: // Stop the component
1210:
1211: mCompFW.stopComponent(mComponent);
1212:
1213: // Attempt to shut down the SU. This should fail.
1214: try {
1215: mDeployer.shutDown(Constants.SU_NAME);
1216: fail("Expected exception not received");
1217: } catch (DeploymentException ex) {
1218: // Verification
1219: assertTrue(
1220: "Incorrect exception received: " + ex.toString(),
1221: (-1 < ex.getMessage().indexOf(Constants.SU_NAME)));
1222: assertTrue(
1223: "Incorrect exception received: " + ex.toString(),
1224: (-1 < ex.getMessage().indexOf("JBIFW2462")));
1225: assertEquals("Failure on shutDown: ",
1226: ServiceUnitState.SHUTDOWN, su.getDesiredState());
1227: }
1228: }
1229:
1230: /**
1231: * Tests shutDown with an exception from the shutDown method.
1232: * An exception is expected.
1233: * @throws Exception if an unexpected error occurs.
1234: */
1235: public void testShutDownBadException() throws Exception {
1236:
1237: // Deploy the SU and initialize it
1238:
1239: mDeployer.deploy(Constants.SU_NAME_SHUTDOWN_EXCEPTION,
1240: Constants.SU_ROOT);
1241: mCompReg.registerServiceUnit(Constants.BC_NAME,
1242: Constants.SA_NAME,
1243: Constants.SU_NAME_SHUTDOWN_EXCEPTION, mServiceUnitRoot);
1244: ServiceUnit su = mComponent
1245: .getServiceUnit(Constants.SU_NAME_SHUTDOWN_EXCEPTION);
1246: mDeployer.init(Constants.SU_NAME_SHUTDOWN_EXCEPTION,
1247: Constants.SU_ROOT);
1248:
1249: // Test the shutdown, this will fail
1250:
1251: try {
1252: mDeployer.shutDown(Constants.SU_NAME_SHUTDOWN_EXCEPTION);
1253: fail("Expected exception not received");
1254: } catch (DeploymentException ex) {
1255: // Verification
1256: assertTrue(
1257: "Incorrect exception received: " + ex.toString(),
1258: (-1 < ex.getMessage()
1259: .indexOf("failed to shut down")));
1260: assertEquals("Failure on shutDown: ",
1261: ServiceUnitState.SHUTDOWN, su.getDesiredState());
1262: }
1263: }
1264:
1265: /**
1266: * Tests shutDown with a timeout on the shutDown method.
1267: * An exception is expected.
1268: * @throws Exception if an unexpected error occurs.
1269: */
1270: public void testShutDownBadTimeout() throws Exception {
1271:
1272: // Deploy the SU and initialize it.
1273:
1274: mDeployer.deploy(Constants.SU_NAME_SHUTDOWN_TIMEOUT,
1275: Constants.SU_ROOT);
1276: mCompReg.registerServiceUnit(Constants.BC_NAME,
1277: Constants.SA_NAME, Constants.SU_NAME_SHUTDOWN_TIMEOUT,
1278: mServiceUnitRoot);
1279: ServiceUnit su = mComponent
1280: .getServiceUnit(Constants.SU_NAME_SHUTDOWN_TIMEOUT);
1281: mDeployer.init(Constants.SU_NAME_SHUTDOWN_TIMEOUT,
1282: Constants.SU_ROOT);
1283:
1284: // Test the shutdown, this will time out
1285:
1286: try {
1287: mDeployer.shutDown(Constants.SU_NAME_SHUTDOWN_TIMEOUT);
1288: fail("Expected exception not received");
1289: } catch (DeploymentException ex) {
1290: // Verification
1291: assertTrue(
1292: "Incorrect exception received: " + ex.toString(),
1293: (-1 < ex.getMessage().indexOf(
1294: Constants.SU_NAME_SHUTDOWN_TIMEOUT)));
1295: assertTrue(
1296: "Incorrect exception received: " + ex.toString(),
1297: (-1 < ex.getMessage().indexOf("JBIFW2461")));
1298: assertEquals("Failure on shutDown: ",
1299: ServiceUnitState.SHUTDOWN, su.getDesiredState());
1300: }
1301: }
1302:
1303: /**
1304: * Tests forced shutdown with a Service Unit that is not stopped.
1305: * @throws Exception if an unexpected error occurs.
1306: */
1307:
1308: public void testShutDownForceGoodNotStopped() throws Exception {
1309: // Deploy the SU and initialize and start it
1310:
1311: mDeployer.deploy(Constants.SU_NAME, Constants.SU_ROOT);
1312: mCompReg.registerServiceUnit(Constants.BC_NAME,
1313: Constants.SA_NAME, Constants.SU_NAME, mServiceUnitRoot);
1314: ServiceUnit su = mComponent.getServiceUnit(Constants.SU_NAME);
1315: mDeployer.init(Constants.SU_NAME, Constants.SU_ROOT);
1316: mDeployer.start(Constants.SU_NAME);
1317:
1318: // Test the shutdown
1319:
1320: mDeployer.shutDown(Constants.SU_NAME, true);
1321: assertEquals("Failure on shutDown: ",
1322: ServiceUnitState.SHUTDOWN, su.getState());
1323: assertEquals("Failure on shutDown: ",
1324: ServiceUnitState.SHUTDOWN, su.getDesiredState());
1325: }
1326:
1327: /**
1328: * Tests forced shutDown with an exception from the shutDown method.
1329: * @throws Exception if an unexpected error occurs.
1330: */
1331: public void testShutDownForceGoodException() throws Exception {
1332:
1333: // Deploy the SU and initialize it
1334:
1335: mDeployer.deploy(Constants.SU_NAME_SHUTDOWN_EXCEPTION,
1336: Constants.SU_ROOT);
1337: mCompReg.registerServiceUnit(Constants.BC_NAME,
1338: Constants.SA_NAME,
1339: Constants.SU_NAME_SHUTDOWN_EXCEPTION, mServiceUnitRoot);
1340: ServiceUnit su = mComponent
1341: .getServiceUnit(Constants.SU_NAME_SHUTDOWN_EXCEPTION);
1342: mDeployer.init(Constants.SU_NAME_SHUTDOWN_EXCEPTION,
1343: Constants.SU_ROOT);
1344:
1345: // Test the shutdown
1346:
1347: mDeployer.shutDown(Constants.SU_NAME_SHUTDOWN_EXCEPTION, true);
1348: assertEquals("Failure on shutDown: ",
1349: ServiceUnitState.SHUTDOWN, su.getState());
1350: assertEquals("Failure on shutDown: ",
1351: ServiceUnitState.SHUTDOWN, su.getDesiredState());
1352: }
1353:
1354: /**
1355: * Tests forced shutDown with a timeout on the shutDown method.
1356: * @throws Exception if an unexpected error occurs.
1357: */
1358: public void testShutDownForceGoodTimeout() throws Exception {
1359:
1360: // Deploy the SU and initialize it.
1361:
1362: mDeployer.deploy(Constants.SU_NAME_SHUTDOWN_TIMEOUT,
1363: Constants.SU_ROOT);
1364: mCompReg.registerServiceUnit(Constants.BC_NAME,
1365: Constants.SA_NAME, Constants.SU_NAME_SHUTDOWN_TIMEOUT,
1366: mServiceUnitRoot);
1367: ServiceUnit su = mComponent
1368: .getServiceUnit(Constants.SU_NAME_SHUTDOWN_TIMEOUT);
1369: mDeployer.init(Constants.SU_NAME_SHUTDOWN_TIMEOUT,
1370: Constants.SU_ROOT);
1371:
1372: // Test the shutdown
1373:
1374: mDeployer.shutDown(Constants.SU_NAME_SHUTDOWN_TIMEOUT, true);
1375: assertEquals("Failure on shutDown: ",
1376: ServiceUnitState.SHUTDOWN, su.getState());
1377: assertEquals("Failure on shutDown: ",
1378: ServiceUnitState.SHUTDOWN, su.getDesiredState());
1379: }
1380:
1381: /**
1382: * Tests undeploy with a good result.
1383: * @throws Exception if an unexpected error occurs.
1384: */
1385:
1386: public void testUndeployGood() throws Exception {
1387: // First deploy and register the SU
1388:
1389: mDeployer.deploy(Constants.SU_NAME, Constants.SU_ROOT);
1390: mCompReg.registerServiceUnit(Constants.BC_NAME,
1391: Constants.SA_NAME, Constants.SU_NAME, mServiceUnitRoot);
1392:
1393: // Now undeploy the SU
1394:
1395: String msg = mDeployer.undeploy(Constants.SU_NAME,
1396: Constants.SU_ROOT);
1397: assertNotNull("Failure undeploying Service Unit", msg);
1398: assertTrue("Failure undeploying Service Unit", (-1 < msg
1399: .indexOf(Constants.SU_NAME)));
1400: }
1401:
1402: /**
1403: * Tests undeploy with a null Service Unit name parameter.
1404: * An exception is expected.
1405: * @throws Exception if an unexpected error occurs.
1406: */
1407: public void testUndeployBadNullServiceUnitName() throws Exception {
1408: try {
1409: mDeployer.undeploy(null, Constants.SU_ROOT);
1410: fail("Expected exception not received");
1411: } catch (java.lang.IllegalArgumentException ex) {
1412: // Verification
1413: assertTrue(
1414: "Incorrect exception received: " + ex.toString(),
1415: (-1 < ex.getMessage().indexOf("serviceUnitName")));
1416: }
1417: }
1418:
1419: /**
1420: * Tests undeploy with a null Service Unit root path parameter.
1421: * An exception is expected.
1422: * @throws Exception if an unexpected error occurs.
1423: */
1424: public void testUndeployBadNullServiceUnitRootPath()
1425: throws Exception {
1426: try {
1427: mDeployer.undeploy(Constants.SU_NAME, null);
1428: fail("Expected exception not received");
1429: } catch (java.lang.IllegalArgumentException ex) {
1430: // Verification
1431: assertTrue(
1432: "Incorrect exception received: " + ex.toString(),
1433: (-1 < ex.getMessage()
1434: .indexOf("serviceUnitRootPath")));
1435: }
1436: }
1437:
1438: /**
1439: * Tests undeploy with a Service Unit that is not deployed.
1440: * An exception is expected.
1441: * @throws Exception if an unexpected error occurs.
1442: */
1443: public void testUndeployBadNotDeployed() throws Exception {
1444: try {
1445: mDeployer.undeploy(Constants.SU_NAME, Constants.SU_ROOT);
1446: fail("Expected exception not received");
1447: } catch (DeploymentException ex) {
1448: // Verification
1449: assertTrue(
1450: "Incorrect exception received: " + ex.toString(),
1451: (-1 < ex.getMessage().indexOf(Constants.SU_NAME)));
1452: assertTrue(
1453: "Incorrect exception received: " + ex.toString(),
1454: (-1 < ex.getMessage().indexOf("JBIFW2450")));
1455: }
1456: }
1457:
1458: /**
1459: * Tests undeploy with a Service Unit that is not shut down.
1460: * An exception is expected.
1461: * @throws Exception if an unexpected error occurs.
1462: */
1463: public void testUndeployBadNotShutDown() throws Exception {
1464: // First deploy and register the SU
1465:
1466: mDeployer.deploy(Constants.SU_NAME, Constants.SU_ROOT);
1467: mCompReg.registerServiceUnit(Constants.BC_NAME,
1468: Constants.SA_NAME, Constants.SU_NAME, mServiceUnitRoot);
1469:
1470: // Now initialize the SU
1471:
1472: mDeployer.init(Constants.SU_NAME, Constants.SU_ROOT);
1473:
1474: // Now undeploy the SU. This should fail.
1475:
1476: try {
1477: mDeployer.undeploy(Constants.SU_NAME, Constants.SU_ROOT);
1478: fail("Expected exception not received");
1479: } catch (DeploymentException ex) {
1480: // Verification
1481: assertTrue(
1482: "Incorrect exception received: " + ex.toString(),
1483: (-1 < ex.getMessage().indexOf(Constants.SU_NAME)));
1484: assertTrue(
1485: "Incorrect exception received: " + ex.toString(),
1486: (-1 < ex.getMessage().indexOf("JBIFW2456")));
1487: }
1488:
1489: // Now start the SU
1490:
1491: mDeployer.start(Constants.SU_NAME);
1492:
1493: // Now undeploy the SU. This should fail.
1494:
1495: try {
1496: mDeployer.undeploy(Constants.SU_NAME, Constants.SU_ROOT);
1497: fail("Expected exception not received");
1498: } catch (DeploymentException ex) {
1499: // Verification
1500: assertTrue(
1501: "Incorrect exception received: " + ex.toString(),
1502: (-1 < ex.getMessage().indexOf(Constants.SU_NAME)));
1503: assertTrue(
1504: "Incorrect exception received: " + ex.toString(),
1505: (-1 < ex.getMessage().indexOf("JBIFW2456")));
1506: }
1507: }
1508:
1509: /**
1510: * Tests undeploy with component that is not started.
1511: * An exception is expected.
1512: * @throws Exception if an unexpected error occurs.
1513: */
1514: public void testUndeployBadComponentNotStarted() throws Exception {
1515: // First deploy and register the SU
1516:
1517: mDeployer.deploy(Constants.SU_NAME, Constants.SU_ROOT);
1518: mCompReg.registerServiceUnit(Constants.BC_NAME,
1519: Constants.SA_NAME, Constants.SU_NAME, mServiceUnitRoot);
1520:
1521: // Stop the component
1522:
1523: mCompFW.stopComponent(mComponent);
1524:
1525: // Attempt to undeploy the SU. This should fail.
1526: try {
1527: mDeployer.undeploy(Constants.SU_NAME, Constants.SU_ROOT);
1528: fail("Expected exception not received");
1529: } catch (DeploymentException ex) {
1530: // Verification
1531: assertTrue(
1532: "Incorrect exception received: " + ex.toString(),
1533: (-1 < ex.getMessage().indexOf(Constants.SU_NAME)));
1534: assertTrue(
1535: "Incorrect exception received: " + ex.toString(),
1536: (-1 < ex.getMessage().indexOf("JBIFW2462")));
1537: }
1538: }
1539:
1540: /**
1541: * Tests undeploy with an exception from the undeploy method.
1542: * An exception is expected.
1543: * @throws Exception if an unexpected error occurs.
1544: */
1545: public void testUndeployBadException() throws Exception {
1546: // First deploy and register the SU
1547:
1548: mDeployer.deploy(Constants.SU_NAME_UNDEPLOY_EXCEPTION,
1549: Constants.SU_ROOT);
1550: mCompReg.registerServiceUnit(Constants.BC_NAME,
1551: Constants.SA_NAME,
1552: Constants.SU_NAME_UNDEPLOY_EXCEPTION, mServiceUnitRoot);
1553:
1554: // Now undeploy the SU
1555:
1556: try {
1557: mDeployer.undeploy(Constants.SU_NAME_UNDEPLOY_EXCEPTION,
1558: Constants.SU_ROOT);
1559: fail("Expected exception not received");
1560: } catch (DeploymentException ex) {
1561: // Verification
1562: assertTrue(
1563: "Incorrect exception received: " + ex.toString(),
1564: (-1 < ex.getMessage().indexOf("failed to undeploy")));
1565: }
1566: }
1567:
1568: /**
1569: * Tests undeploy with a timeout on the undeploy method.
1570: * An exception is expected.
1571: * @throws Exception if an unexpected error occurs.
1572: */
1573: public void testUndeployBadTimeout() throws Exception {
1574: // First deploy and register the SU
1575:
1576: mDeployer.deploy(Constants.SU_NAME_UNDEPLOY_TIMEOUT,
1577: Constants.SU_ROOT);
1578: mCompReg.registerServiceUnit(Constants.BC_NAME,
1579: Constants.SA_NAME, Constants.SU_NAME_UNDEPLOY_TIMEOUT,
1580: mServiceUnitRoot);
1581:
1582: // Now undeploy the SU
1583:
1584: try {
1585: mDeployer.undeploy(Constants.SU_NAME_UNDEPLOY_TIMEOUT,
1586: Constants.SU_ROOT);
1587: fail("Expected exception not received");
1588: } catch (DeploymentException ex) {
1589: // Verification
1590: assertTrue(
1591: "Incorrect exception received: " + ex.toString(),
1592: (-1 < ex.getMessage().indexOf(
1593: Constants.SU_NAME_UNDEPLOY_TIMEOUT)));
1594: assertTrue(
1595: "Incorrect exception received: " + ex.toString(),
1596: (-1 < ex.getMessage().indexOf("JBIFW2461")));
1597: }
1598: }
1599:
1600: /**
1601: * Tests forced undeploy with good results.
1602: * @throws Exception if an unexpected error occurs.
1603: */
1604:
1605: public void testUndeployForceGood() throws Exception {
1606: // First deploy and register the SU
1607:
1608: mDeployer.deploy(Constants.SU_NAME, Constants.SU_ROOT);
1609: mCompReg.registerServiceUnit(Constants.BC_NAME,
1610: Constants.SA_NAME, Constants.SU_NAME, mServiceUnitRoot);
1611:
1612: // Now undeploy the SU
1613:
1614: String msg = mDeployer.undeploy(Constants.SU_NAME,
1615: Constants.SU_ROOT, true);
1616: assertNotNull("Failure undeploying Service Unit", msg);
1617: assertTrue("Failure undeploying Service Unit", (-1 < msg
1618: .indexOf("SUCCESS")));
1619: }
1620:
1621: /**
1622: * Tests forced undeploy with component that is not started.
1623: * @throws Exception if an unexpected error occurs.
1624: */
1625:
1626: public void testUndeployForceGoodComponentNotStarted()
1627: throws Exception {
1628: // First deploy and register the SU
1629:
1630: mDeployer.deploy(Constants.SU_NAME, Constants.SU_ROOT);
1631: mCompReg.registerServiceUnit(Constants.BC_NAME,
1632: Constants.SA_NAME, Constants.SU_NAME, mServiceUnitRoot);
1633:
1634: // Stop the component
1635:
1636: mCompFW.stopComponent(mComponent);
1637:
1638: // Now undeploy the SU
1639:
1640: String msg = mDeployer.undeploy(Constants.SU_NAME,
1641: Constants.SU_ROOT, true);
1642: assertNotNull("Failure undeploying Service Unit", msg);
1643: assertTrue("Failure undeploying Service Unit", (-1 < msg
1644: .indexOf("SUCCESS")));
1645: }
1646:
1647: /**
1648: * Tests forced undeploy with an exception in the SU manager.
1649: * @throws Exception if an unexpected error occurs.
1650: */
1651:
1652: public void testUndeployForceGoodException() throws Exception {
1653: // First deploy and register the SU
1654:
1655: mDeployer.deploy(Constants.SU_NAME_UNDEPLOY_EXCEPTION,
1656: Constants.SU_ROOT);
1657: mCompReg.registerServiceUnit(Constants.BC_NAME,
1658: Constants.SA_NAME,
1659: Constants.SU_NAME_UNDEPLOY_EXCEPTION, mServiceUnitRoot);
1660:
1661: // Now undeploy the SU
1662:
1663: String msg = mDeployer.undeploy(
1664: Constants.SU_NAME_UNDEPLOY_EXCEPTION,
1665: Constants.SU_ROOT, true);
1666: assertNotNull("Failure undeploying Service Unit", msg);
1667: assertTrue("Failure undeploying Service Unit", (-1 < msg
1668: .indexOf("SUCCESS")));
1669: }
1670:
1671: /**
1672: * Tests forced undeploy with a timeout in the SU manager.
1673: * @throws Exception if an unexpected error occurs.
1674: */
1675:
1676: public void testUndeployForceGoodTimeout() throws Exception {
1677: // First deploy and register the SU
1678:
1679: mDeployer.deploy(Constants.SU_NAME_UNDEPLOY_TIMEOUT,
1680: Constants.SU_ROOT);
1681: mCompReg.registerServiceUnit(Constants.BC_NAME,
1682: Constants.SA_NAME, Constants.SU_NAME_UNDEPLOY_TIMEOUT,
1683: mServiceUnitRoot);
1684:
1685: // Now undeploy the SU
1686:
1687: String msg = mDeployer.undeploy(
1688: Constants.SU_NAME_UNDEPLOY_TIMEOUT, Constants.SU_ROOT,
1689: true);
1690: assertNotNull("Failure undeploying Service Unit", msg);
1691: assertTrue("Failure undeploying Service Unit", (-1 < msg
1692: .indexOf("SUCCESS")));
1693: }
1694:
1695: /**
1696: * Tests forced undeploy with a Service Unit that is not shut down.
1697: * An exception is expected.
1698: * @throws Exception if an unexpected error occurs.
1699: */
1700: public void testUndeployForceBadNotShutDown() throws Exception {
1701: // First deploy and register the SU
1702:
1703: mDeployer.deploy(Constants.SU_NAME, Constants.SU_ROOT);
1704: mCompReg.registerServiceUnit(Constants.BC_NAME,
1705: Constants.SA_NAME, Constants.SU_NAME, mServiceUnitRoot);
1706:
1707: // Now initialize the SU
1708:
1709: mDeployer.init(Constants.SU_NAME, Constants.SU_ROOT);
1710:
1711: // Now undeploy the SU. This should fail.
1712:
1713: try {
1714: mDeployer.undeploy(Constants.SU_NAME, Constants.SU_ROOT,
1715: true);
1716: fail("Expected exception not received");
1717: } catch (DeploymentException ex) {
1718: // Verification
1719: assertTrue(
1720: "Incorrect exception received: " + ex.toString(),
1721: (-1 < ex.getMessage().indexOf(Constants.SU_NAME)));
1722: assertTrue(
1723: "Incorrect exception received: " + ex.toString(),
1724: (-1 < ex.getMessage().indexOf("JBIFW2456")));
1725: }
1726:
1727: // Now start the SU
1728:
1729: mDeployer.start(Constants.SU_NAME);
1730:
1731: // Now undeploy the SU. This should fail.
1732:
1733: try {
1734: mDeployer.undeploy(Constants.SU_NAME, Constants.SU_ROOT,
1735: true);
1736: fail("Expected exception not received");
1737: } catch (DeploymentException ex) {
1738: // Verification
1739: assertTrue(
1740: "Incorrect exception received: " + ex.toString(),
1741: (-1 < ex.getMessage().indexOf(Constants.SU_NAME)));
1742: assertTrue(
1743: "Incorrect exception received: " + ex.toString(),
1744: (-1 < ex.getMessage().indexOf("JBIFW2456")));
1745: }
1746: }
1747:
1748: }
|