Source Code Cross Referenced for TestComponentFramework.java in  » ESB » open-esb » com » sun » jbi » framework » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ESB » open esb » com.sun.jbi.framework 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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:         * @(#)TestComponentFramework.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.ByteArrayInputStream;
0034:        import java.io.File;
0035:        import java.util.ArrayList;
0036:        import java.util.List;
0037:        import java.util.ListIterator;
0038:
0039:        import javax.management.ObjectName;
0040:
0041:        import javax.xml.parsers.DocumentBuilder;
0042:        import javax.xml.parsers.DocumentBuilderFactory;
0043:
0044:        import org.w3c.dom.Document;
0045:        import org.w3c.dom.DocumentFragment;
0046:
0047:        /**
0048:         * Tests for the ComponentFramework.
0049:         *
0050:         * @author Sun Microsystems, Inc.
0051:         */
0052:        public class TestComponentFramework extends junit.framework.TestCase {
0053:            /**
0054:             * Current test name.
0055:             */
0056:            private String mTestName;
0057:
0058:            /**
0059:             * Helper class to setup environment for testing.
0060:             */
0061:            private EnvironmentSetup mSetup;
0062:
0063:            /**
0064:             * Instance of the EnvironmentContext class
0065:             */
0066:            private EnvironmentContext mContext;
0067:
0068:            /**
0069:             * Local instance of the ComponentInstallationContext class
0070:             */
0071:            private ComponentInstallationContext mBindingContext;
0072:
0073:            /**
0074:             * Local instance of the ComponentInstallationContext class
0075:             */
0076:            private ComponentInstallationContext mEngineContext;
0077:
0078:            /**
0079:             * Instance of the ComponentFramework class
0080:             */
0081:            private ComponentFramework mCompFW;
0082:
0083:            /**
0084:             * Local instance of the ComponentRegistry class
0085:             */
0086:            private ComponentRegistry mCompReg;
0087:
0088:            /**
0089:             * Local instance of the binding bootstrap class path array
0090:             */
0091:            private ArrayList mBindingBootClassPath;
0092:
0093:            /**
0094:             * Local instance of the binding lifecycle class path array
0095:             */
0096:            private ArrayList mBindingLifeClassPath;
0097:
0098:            /**
0099:             * Local instance of the engine bootstrap class path array
0100:             */
0101:            private ArrayList mEngineBootClassPath;
0102:
0103:            /**
0104:             * Local instance of the engine lifecycle class path array
0105:             */
0106:            private ArrayList mEngineLifeClassPath;
0107:
0108:            /**
0109:             * Installation root directory for components.
0110:             */
0111:            private String mInstallRoot;
0112:
0113:            /**
0114:             * Workspace root directory for components.
0115:             */
0116:            private String mWorkspaceRoot;
0117:
0118:            /**
0119:             * Local instance of the SharedLibrary element list
0120:             */
0121:            private ArrayList mSl1Elements;
0122:
0123:            /**
0124:             * Local instance of the SharedLibrary element list
0125:             */
0126:            private ArrayList mSl2Elements;
0127:
0128:            /**
0129:             * The constructor for this testcase, forwards the test name to
0130:             * the jUnit TestCase base class.
0131:             * @param aTestName String with the name of this test.
0132:             */
0133:            public TestComponentFramework(String aTestName) {
0134:                super (aTestName);
0135:                mTestName = aTestName;
0136:            }
0137:
0138:            /**
0139:             * Setup for the test. This creates the ComponentRegistry instance
0140:             * and other objects needed for the tests.
0141:             * @throws Exception when set up fails for any reason.
0142:             */
0143:            public void setUp() throws Exception {
0144:                super .setUp();
0145:                System.err.println("***** START of test " + mTestName);
0146:                String srcroot = System.getProperty("junit.srcroot") + "/";
0147:                srcroot = srcroot.replace('\\', '/');
0148:
0149:                // Set up directories for component tests. Note that the current
0150:                // working directory is where these are set up. The test always
0151:                // runs in the $SRCROOT/runtime/framework directory.
0152:
0153:                mInstallRoot = "bld";
0154:                mWorkspaceRoot = "bld/workspace";
0155:                File f = new File(mWorkspaceRoot);
0156:                if (f.exists()) {
0157:                    File[] fl = f.listFiles();
0158:                    if (null != fl) {
0159:                        for (int i = 0; i < fl.length; i++) {
0160:                            fl[i].delete();
0161:                        }
0162:                    }
0163:                } else {
0164:                    f.mkdir();
0165:                }
0166:
0167:                // Create and initialize the EnvironmentContext. Create, initialize,
0168:                // and start up the Component Registry and Framework.
0169:
0170:                mSetup = new EnvironmentSetup();
0171:                mContext = mSetup.getEnvironmentContext();
0172:                mSetup.startup(true, true);
0173:                mCompReg = mContext.getComponentRegistry();
0174:                mCompFW = mContext.getComponentFramework();
0175:
0176:                // Create binding class path / class name lists
0177:
0178:                mBindingBootClassPath = new ArrayList();
0179:                mBindingBootClassPath.add(srcroot
0180:                        + Constants.BC_BOOTSTRAP_CLASS_PATH);
0181:                mBindingLifeClassPath = new ArrayList();
0182:                mBindingLifeClassPath.add(Constants.BC_LIFECYCLE_CLASS_PATH);
0183:
0184:                // Create engine class path lists
0185:
0186:                mEngineBootClassPath = new ArrayList();
0187:                mEngineBootClassPath.add(srcroot
0188:                        + Constants.SE_BOOTSTRAP_CLASS_PATH);
0189:                mEngineLifeClassPath = new ArrayList();
0190:                mEngineLifeClassPath.add(Constants.SE_LIFECYCLE_CLASS_PATH);
0191:
0192:                // Create two SharedLibrary instances
0193:
0194:                mSl1Elements = new ArrayList();
0195:                mSl1Elements.add(srcroot + "antbld/lib/jbi.jar");
0196:                mSl1Elements.add(srcroot
0197:                        + "framework/bld/src/com/sun/jbi/framework");
0198:
0199:                mSl2Elements = new ArrayList();
0200:                mSl2Elements.add(srcroot + "antbld/lib/jbi_ri_rt.jar");
0201:
0202:                // Create installation contexts for the Binding and Engine
0203:
0204:                mBindingContext = new ComponentInstallationContext(
0205:                        Constants.BC_NAME,
0206:                        ComponentInstallationContext.BINDING,
0207:                        Constants.BC_LIFECYCLE_CLASS_NAME,
0208:                        mBindingLifeClassPath, null);
0209:                mBindingContext.setInstallRoot(mInstallRoot);
0210:                mBindingContext.setWorkspaceRoot(mWorkspaceRoot);
0211:                mBindingContext.setDescription(Constants.BC_DESCRIPTION);
0212:
0213:                mEngineContext = new ComponentInstallationContext(
0214:                        Constants.SE_NAME, ComponentInstallationContext.ENGINE,
0215:                        Constants.SE_LIFECYCLE_CLASS_NAME,
0216:                        mEngineLifeClassPath, null);
0217:                mEngineContext.setInstallRoot(mInstallRoot);
0218:                mEngineContext.setWorkspaceRoot(mWorkspaceRoot);
0219:                mEngineContext.setDescription(Constants.SE_DESCRIPTION);
0220:            }
0221:
0222:            /**
0223:             * Cleanup for the test.
0224:             * @throws Exception when tearDown fails for any reason.
0225:             */
0226:            public void tearDown() throws Exception {
0227:                super .tearDown();
0228:                mSetup.shutdown(true, true);
0229:                System.err.println("***** END of test " + mTestName);
0230:            }
0231:
0232:            // =============================  test methods ================================
0233:
0234:            /**
0235:             * Tests loadBootstrap with a good result.
0236:             * @throws Exception if an unexpected error occurs.
0237:             */
0238:
0239:            public void testLoadBootstrapBindingGood() throws Exception {
0240:                ObjectName mbn;
0241:
0242:                // First test loading the bootstrap for an install.
0243:
0244:                mBindingContext.setIsInstall(true);
0245:                mbn = mCompFW.loadBootstrap(mBindingContext,
0246:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
0247:                        mBindingBootClassPath, null);
0248:
0249:                // The component should now be in LOADED state, and should have an
0250:                // InstallerMBean registered.
0251:
0252:                assertTrue("Failure loading BC", mCompReg.getComponent(
0253:                        Constants.BC_NAME).isLoaded());
0254:                assertTrue("Failure registering InstallerMBean", mContext
0255:                        .getMBeanServer().isRegistered(mbn));
0256:
0257:                // Now test loading the bootstrap for an uninstall.
0258:
0259:                mCompReg.getComponent(Constants.BC_NAME).setShutdown();
0260:                mBindingContext.setIsInstall(false);
0261:                mbn = mCompFW.loadBootstrap(mBindingContext,
0262:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
0263:                        mBindingBootClassPath, null);
0264:                assertNotNull("Failure loading for uninstall", mCompReg
0265:                        .getComponent(Constants.BC_NAME).getBootstrapInstance(
0266:                                false));
0267:                assertTrue("Failure registering InstallerMBean", mContext
0268:                        .getMBeanServer().isRegistered(mbn));
0269:            }
0270:
0271:            /**
0272:             * Tests loadBootstrap with a null ComponentInstallationContext parameter.
0273:             * An exception is expected.
0274:             * @throws Exception if an unexpected error occurs.
0275:             */
0276:            public void testLoadBootstrapBindingBadNullInstallationContext()
0277:                    throws Exception {
0278:                try {
0279:                    mCompFW.loadBootstrap(null,
0280:                            Constants.BC_BOOTSTRAP_CLASS_NAME,
0281:                            mBindingBootClassPath, 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("installContext")));
0288:                }
0289:            }
0290:
0291:            /**
0292:             * Tests loadBootstrap with a null bootstrap class name parameter. An
0293:             * exception is expected.
0294:             * @throws Exception if an unexpected error occurs.
0295:             */
0296:            public void testLoadBootstrapBindingBadNullBootstrapClassName()
0297:                    throws Exception {
0298:                try {
0299:                    mCompFW.loadBootstrap(mBindingContext, null,
0300:                            mBindingBootClassPath, null);
0301:                    fail("Expected exception not received");
0302:                } catch (java.lang.IllegalArgumentException ex) {
0303:                    // Verification
0304:                    assertTrue(
0305:                            "Incorrect exception received: " + ex.toString(),
0306:                            (-1 < ex.getMessage().indexOf("bootClassName")));
0307:                }
0308:            }
0309:
0310:            /**
0311:             * Tests loadBootstrap with an empty bootstrap class name parameter. An
0312:             * exception is expected.
0313:             * @throws Exception if an unexpected error occurs.
0314:             */
0315:            public void testLoadBootstrapBindingBadEmptyBootstrapClassName()
0316:                    throws Exception {
0317:                try {
0318:                    mCompFW.loadBootstrap(mBindingContext, "",
0319:                            mBindingBootClassPath, null);
0320:                    fail("Expected exception not received");
0321:                } catch (java.lang.IllegalArgumentException ex) {
0322:                    // Verification
0323:                    assertTrue(
0324:                            "Incorrect exception received: " + ex.toString(),
0325:                            (-1 < ex.getMessage().indexOf("bootClassName")));
0326:                }
0327:            }
0328:
0329:            /**
0330:             * Tests loadBootstrap with a null bootstrap class path parameter. An
0331:             * exception is expected.
0332:             * @throws Exception if an unexpected error occurs.
0333:             */
0334:            public void testLoadBootstrapBindingBadNullBootstrapClassPath()
0335:                    throws Exception {
0336:                try {
0337:                    mCompFW.loadBootstrap(mBindingContext,
0338:                            Constants.BC_BOOTSTRAP_CLASS_NAME, null, null);
0339:                    fail("Expected exception not received");
0340:                } catch (java.lang.IllegalArgumentException ex) {
0341:                    // Verification
0342:                    assertTrue(
0343:                            "Incorrect exception received: " + ex.toString(),
0344:                            (-1 < ex.getMessage().indexOf(
0345:                                    "bootClassPathElements")));
0346:                }
0347:            }
0348:
0349:            /**
0350:             * Tests loadBootstrap with an empty bootstrap class path parameter. An
0351:             * exception is expected.
0352:             * @throws Exception if an unexpected error occurs.
0353:             */
0354:            public void testLoadBootstrapBindingBadEmptyBootstrapClassPath()
0355:                    throws Exception {
0356:                ArrayList emptyList = new ArrayList();
0357:                try {
0358:                    mCompFW.loadBootstrap(mBindingContext,
0359:                            Constants.BC_BOOTSTRAP_CLASS_NAME, emptyList, null);
0360:                    fail("Expected exception not received");
0361:                } catch (java.lang.IllegalArgumentException ex) {
0362:                    // Verification
0363:                    assertTrue(
0364:                            "Incorrect exception received: " + ex.toString(),
0365:                            (-1 < ex.getMessage().indexOf(
0366:                                    "bootClassPathElements")));
0367:                }
0368:            }
0369:
0370:            /**
0371:             * Tests loadBootstrap with a duplicate component name specified. An
0372:             * exception is expected.
0373:             * @throws Exception if an unexpected error occurs.
0374:             */
0375:            public void testLoadBootstrapBindingBadDuplicate() throws Exception {
0376:                try {
0377:                    // Pre-install the component so that the second load will fail.
0378:                    mBindingContext.setIsInstall(true);
0379:                    mCompFW.loadBootstrap(mBindingContext,
0380:                            Constants.BC_BOOTSTRAP_CLASS_NAME,
0381:                            mBindingBootClassPath, null);
0382:                    mCompFW.installComponent(mBindingContext);
0383:                    mCompFW.loadBootstrap(mBindingContext,
0384:                            Constants.BC_BOOTSTRAP_CLASS_NAME,
0385:                            mBindingBootClassPath, null);
0386:                    fail("Expected exception not received");
0387:                } catch (javax.jbi.JBIException ex) {
0388:                    // Verification
0389:                    assertTrue(
0390:                            "Incorrect exception received: " + ex.toString(),
0391:                            (-1 < ex.getMessage().indexOf("already registered")));
0392:                }
0393:            }
0394:
0395:            /**
0396:             * Tests loadBootstrap with a required Shared Library missing. An
0397:             * exception is expected.
0398:             * @throws Exception if an unexpected error occurs.
0399:             */
0400:            public void testLoadBootstrapBindingBadMissingSharedLibrary()
0401:                    throws Exception {
0402:                // Create a list of Shared Library IDs that are not installed.
0403:                ArrayList slList = new ArrayList();
0404:                slList.add(Constants.SL_1_NAME);
0405:                slList.add(Constants.SL_2_NAME);
0406:                try {
0407:                    mBindingContext.setIsInstall(true);
0408:                    mCompFW.loadBootstrap(mBindingContext,
0409:                            Constants.BC_BOOTSTRAP_CLASS_NAME,
0410:                            mBindingBootClassPath, slList);
0411:                    fail("Expected exception not received");
0412:                } catch (javax.jbi.JBIException ex) {
0413:                    // Verification
0414:                    assertTrue(
0415:                            "Incorrect exception received: " + ex.toString(),
0416:                            (-1 < ex.getMessage().indexOf("must be installed")));
0417:                }
0418:            }
0419:
0420:            /**
0421:             * Tests loadBootstrap with a bad bootstrap class name. The bootstrap
0422:             * class will not be found when an attempt is made to load it. An
0423:             * exception is expected.
0424:             * @throws Exception if an unexpected error occurs.
0425:             */
0426:            public void testLoadBootstrapBindingBadBootstrapNotFound()
0427:                    throws Exception {
0428:                try {
0429:                    mBindingContext.setIsInstall(true);
0430:                    mCompFW.loadBootstrap(mBindingContext,
0431:                            "bad.bootstrap.class.name", mBindingBootClassPath,
0432:                            null);
0433:                    fail("Expected exception not received");
0434:                } catch (javax.jbi.JBIException ex) {
0435:                    // Verification
0436:                    assertTrue(
0437:                            "Incorrect exception received: " + ex.toString(),
0438:                            (-1 < ex.getCause().getMessage().indexOf(
0439:                                    "could not be loaded")));
0440:                }
0441:            }
0442:
0443:            /**
0444:             * Tests loadBootstrap with a binding that throws an exception from its
0445:             * bootstrap init() method.
0446:             * @throws Exception if an unexpected error occurs
0447:             */
0448:            public void testLoadBootstrapBindingBadBootstrapInitException()
0449:                    throws Exception {
0450:                mBindingContext
0451:                        .setComponentName(Constants.BC_NAME_BAD_BOOTSTRAP_INIT);
0452:                mBindingContext.setIsInstall(true);
0453:                try {
0454:                    mCompFW.loadBootstrap(mBindingContext,
0455:                            Constants.BC_BOOTSTRAP_CLASS_NAME,
0456:                            mBindingBootClassPath, null);
0457:                    fail("Expected exception not received");
0458:                } catch (javax.jbi.JBIException ex) {
0459:                    // Verification
0460:                    assertTrue(
0461:                            "Incorrect exception received: " + ex.toString(),
0462:                            (-1 < ex.getMessage().indexOf(
0463:                                    "bootstrap init failed")));
0464:                }
0465:            }
0466:
0467:            /**
0468:             * Tests loadBootstrap with a binding that throws an exception from its
0469:             * bootstrap init() method and from its bootstrap cleanUp() method.
0470:             * @throws Exception if an unexpected error occurs
0471:             */
0472:            public void testLoadBootstrapBindingBadBootstrapInitCleanUpException()
0473:                    throws Exception {
0474:                mBindingContext
0475:                        .setComponentName(Constants.BC_NAME_BAD_BOOTSTRAP_INIT_CLEANUP);
0476:                mBindingContext.setIsInstall(true);
0477:                try {
0478:                    mCompFW.loadBootstrap(mBindingContext,
0479:                            Constants.BC_BOOTSTRAP_CLASS_NAME,
0480:                            mBindingBootClassPath, null);
0481:                    fail("Expected exception not received");
0482:                } catch (javax.jbi.JBIException ex) {
0483:                    // Verification
0484:                    assertTrue(
0485:                            "Incorrect exception received: " + ex.toString(),
0486:                            (-1 < ex.getMessage().indexOf(
0487:                                    "bootstrap init failed")));
0488:                    assertTrue(
0489:                            "Incorrect exception received: " + ex.toString(),
0490:                            (-1 < ex.getMessage().indexOf(
0491:                                    "bootstrap cleanup failed")));
0492:                }
0493:            }
0494:
0495:            /**
0496:             * Tests loadBootstrap for an uninstall with a non-existent component.
0497:             * @throws Exception if an unexpected error occurs
0498:             */
0499:            public void testLoadBootstrapBindingBadNotInstalled()
0500:                    throws Exception {
0501:                try {
0502:                    mBindingContext.setIsInstall(false);
0503:                    mCompFW.loadBootstrap(mBindingContext,
0504:                            Constants.BC_BOOTSTRAP_CLASS_NAME,
0505:                            mBindingBootClassPath, null);
0506:                    fail("Expected exception not received");
0507:                } catch (javax.jbi.JBIException ex) {
0508:                    // Verification
0509:                    assertTrue(
0510:                            "Incorrect exception received: " + ex.toString(),
0511:                            ((-1 < ex.getMessage().indexOf("failed")) && (-1 < ex
0512:                                    .getMessage().indexOf("not installed"))));
0513:                }
0514:            }
0515:
0516:            /**
0517:             * Tests loadBootstrap for an uninstall with a loaded component.
0518:             * @throws Exception if an unexpected error occurs
0519:             */
0520:            public void testLoadBootstrapBindingBadLoaded() throws Exception {
0521:                mBindingContext.setIsInstall(true);
0522:                mCompFW.loadBootstrap(mBindingContext,
0523:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
0524:                        mBindingBootClassPath, null);
0525:                try {
0526:                    mBindingContext.setIsInstall(false);
0527:                    mCompFW.loadBootstrap(mBindingContext,
0528:                            Constants.BC_BOOTSTRAP_CLASS_NAME,
0529:                            mBindingBootClassPath, null);
0530:                    fail("Expected exception not received");
0531:                } catch (javax.jbi.JBIException ex) {
0532:                    // Verification
0533:                    assertTrue(
0534:                            "Incorrect exception received: " + ex.toString(),
0535:                            ((-1 < ex.getMessage().indexOf("failed")) && (-1 < ex
0536:                                    .getMessage().indexOf("not installed"))));
0537:                }
0538:            }
0539:
0540:            /**
0541:             * Tests loadBootstrap with a good result.
0542:             * @throws Exception if an unexpected error occurs.
0543:             */
0544:            public void testLoadBootstrapEngineGood() throws Exception {
0545:                // Test loading for an install
0546:
0547:                mEngineContext.setIsInstall(true);
0548:                mCompFW.loadBootstrap(mEngineContext,
0549:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
0550:                        mEngineBootClassPath, null);
0551:                assertTrue("Failure loading for install", mCompReg
0552:                        .getComponent(Constants.SE_NAME).isLoaded());
0553:
0554:                // Test loading for an uninstall
0555:
0556:                mCompReg.getComponent(Constants.SE_NAME).setShutdown();
0557:                mEngineContext.setIsInstall(false);
0558:                mCompFW.loadBootstrap(mEngineContext,
0559:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
0560:                        mEngineBootClassPath, null);
0561:                assertNotNull("Failure loading for uninstall", mCompReg
0562:                        .getComponent(Constants.SE_NAME).getBootstrapInstance(
0563:                                false));
0564:            }
0565:
0566:            /**
0567:             * Tests loadBootstrap with a null ComponentInstallationContext parameter.
0568:             * An exception is expected.
0569:             * @throws Exception if an unexpected error occurs.
0570:             */
0571:            public void testLoadBootstrapEngineBadNullInstallationContext()
0572:                    throws Exception {
0573:                try {
0574:                    mCompFW.loadBootstrap(null,
0575:                            Constants.SE_BOOTSTRAP_CLASS_NAME,
0576:                            mEngineBootClassPath, null);
0577:                    fail("Expected exception not received");
0578:                } catch (java.lang.IllegalArgumentException ex) {
0579:                    // Verification
0580:                    assertTrue(
0581:                            "Incorrect exception received: " + ex.toString(),
0582:                            (-1 < ex.getMessage().indexOf("installContext")));
0583:                }
0584:            }
0585:
0586:            /**
0587:             * Tests loadBootstrap with a null bootstrap class name parameter. An
0588:             * exception is expected.
0589:             * @throws Exception if an unexpected error occurs.
0590:             */
0591:            public void testLoadBootstrapEngineBadNullBootstrapClassName()
0592:                    throws Exception {
0593:                try {
0594:                    mCompFW.loadBootstrap(mEngineContext, null,
0595:                            mEngineBootClassPath, null);
0596:                    fail("Expected exception not received");
0597:                } catch (java.lang.IllegalArgumentException ex) {
0598:                    // Verification
0599:                    assertTrue(
0600:                            "Incorrect exception received: " + ex.toString(),
0601:                            (-1 < ex.getMessage().indexOf("bootClassName")));
0602:                }
0603:            }
0604:
0605:            /**
0606:             * Tests loadBootstrap with an empty bootstrap class name parameter. An
0607:             * exception is expected.
0608:             * @throws Exception if an unexpected error occurs.
0609:             */
0610:            public void testLoadBootstrapEngineBadEmptyBootstrapClassName()
0611:                    throws Exception {
0612:                try {
0613:                    mCompFW.loadBootstrap(mEngineContext, "",
0614:                            mEngineBootClassPath, null);
0615:                    fail("Expected exception not received");
0616:                } catch (java.lang.IllegalArgumentException ex) {
0617:                    // Verification
0618:                    assertTrue(
0619:                            "Incorrect exception received: " + ex.toString(),
0620:                            (-1 < ex.getMessage().indexOf("bootClassName")));
0621:                }
0622:            }
0623:
0624:            /**
0625:             * Tests loadBootstrap with a null bootstrap class path parameter. An
0626:             * exception is expected.
0627:             * @throws Exception if an unexpected error occurs.
0628:             */
0629:            public void testLoadBootstrapEngineBadNullBootstrapClassPath()
0630:                    throws Exception {
0631:                try {
0632:                    mCompFW.loadBootstrap(mEngineContext,
0633:                            Constants.SE_BOOTSTRAP_CLASS_NAME, null, null);
0634:                    fail("Expected exception not received");
0635:                } catch (java.lang.IllegalArgumentException ex) {
0636:                    // Verification
0637:                    assertTrue(
0638:                            "Incorrect exception received: " + ex.toString(),
0639:                            (-1 < ex.getMessage().indexOf(
0640:                                    "bootClassPathElements")));
0641:                }
0642:            }
0643:
0644:            /**
0645:             * Tests loadBootstrap with an empty bootstrap class path parameter. An
0646:             * exception is expected.
0647:             * @throws Exception if an unexpected error occurs.
0648:             */
0649:            public void testLoadBootstrapEngineBadEmptyBootstrapClassPath()
0650:                    throws Exception {
0651:                ArrayList emptyList = new ArrayList();
0652:                try {
0653:                    mCompFW.loadBootstrap(mEngineContext,
0654:                            Constants.SE_BOOTSTRAP_CLASS_NAME, emptyList, null);
0655:                    fail("Expected exception not received");
0656:                } catch (java.lang.IllegalArgumentException ex) {
0657:                    // Verification
0658:                    assertTrue(
0659:                            "Incorrect exception received: " + ex.toString(),
0660:                            (-1 < ex.getMessage().indexOf(
0661:                                    "bootClassPathElements")));
0662:                }
0663:            }
0664:
0665:            /**
0666:             * Tests loadBootstrap with a duplicate component name specified. An
0667:             * exception is expected.
0668:             * @throws Exception if an unexpected error occurs.
0669:             */
0670:            public void testLoadBootstrapEngineBadDuplicate() throws Exception {
0671:                try {
0672:                    // Pre-install the component so that the second load will fail.
0673:                    mEngineContext.setIsInstall(true);
0674:                    mCompFW.loadBootstrap(mEngineContext,
0675:                            Constants.SE_BOOTSTRAP_CLASS_NAME,
0676:                            mEngineBootClassPath, null);
0677:                    mCompFW.installComponent(mEngineContext);
0678:                    mCompFW.loadBootstrap(mEngineContext,
0679:                            Constants.SE_BOOTSTRAP_CLASS_NAME,
0680:                            mEngineBootClassPath, null);
0681:                    fail("Expected exception not received");
0682:                } catch (javax.jbi.JBIException ex) {
0683:                    // Verification
0684:                    assertTrue(
0685:                            "Incorrect exception received: " + ex.toString(),
0686:                            (-1 < ex.getMessage().indexOf("already registered")));
0687:                }
0688:            }
0689:
0690:            /**
0691:             * Tests loadBootstrap with a required Shared Library missing. An
0692:             * exception is expected.
0693:             * @throws Exception if an unexpected error occurs.
0694:             */
0695:            public void testLoadBootstrapEngineBadMissingSharedLibrary()
0696:                    throws Exception {
0697:                // Create a list of Shared Library IDs that are not installed.
0698:                ArrayList slList = new ArrayList();
0699:                slList.add(Constants.SL_1_NAME);
0700:                slList.add(Constants.SL_2_NAME);
0701:                try {
0702:                    mEngineContext.setIsInstall(true);
0703:                    mCompFW.loadBootstrap(mEngineContext,
0704:                            Constants.SE_BOOTSTRAP_CLASS_NAME,
0705:                            mEngineBootClassPath, slList);
0706:                    fail("Expected exception not received");
0707:                } catch (javax.jbi.JBIException ex) {
0708:                    // Verification
0709:                    assertTrue(
0710:                            "Incorrect exception received: " + ex.toString(),
0711:                            (-1 < ex.getMessage().indexOf("must be installed")));
0712:                }
0713:            }
0714:
0715:            /**
0716:             * Tests loadBootstrap with a bad bootstrap class name. The bootstrap
0717:             * class will not be found when an attempt is made to load it. An
0718:             * exception is expected.
0719:             * @throws Exception if an unexpected error occurs.
0720:             */
0721:            public void testLoadBootstrapEngineBadBootstrapNotFound()
0722:                    throws Exception {
0723:                try {
0724:                    mEngineContext.setIsInstall(true);
0725:                    mCompFW.loadBootstrap(mEngineContext,
0726:                            "bad.bootstrap.class.name", mEngineBootClassPath,
0727:                            null);
0728:                    fail("Expected exception not received");
0729:                } catch (javax.jbi.JBIException ex) {
0730:                    // Verification
0731:                    assertTrue(
0732:                            "Incorrect exception received: " + ex.toString(),
0733:                            (-1 < ex.getCause().getMessage().indexOf(
0734:                                    "could not be loaded")));
0735:                }
0736:            }
0737:
0738:            /**
0739:             * Tests loadBootstrap with an engine that throws an exception from its
0740:             * bootstrap init() method.
0741:             * @throws Exception if an unexpected error occurs
0742:             */
0743:            public void testLoadBootstrapEngineBadBootstrapInitException()
0744:                    throws Exception {
0745:                mEngineContext
0746:                        .setComponentName(Constants.SE_NAME_BAD_BOOTSTRAP_INIT);
0747:                mEngineContext.setIsInstall(true);
0748:                try {
0749:                    mCompFW.loadBootstrap(mEngineContext,
0750:                            Constants.SE_BOOTSTRAP_CLASS_NAME,
0751:                            mEngineBootClassPath, null);
0752:                    fail("Expected exception not received");
0753:                } catch (javax.jbi.JBIException ex) {
0754:                    // Verification
0755:                    assertTrue(
0756:                            "Incorrect exception received: " + ex.toString(),
0757:                            (-1 < ex.getMessage().indexOf(
0758:                                    "bootstrap init failed")));
0759:                }
0760:            }
0761:
0762:            /**
0763:             * Tests loadBootstrap with an engine that throws an exception from its
0764:             * bootstrap init() method and from its bootstrap cleanUp() method.
0765:             * @throws Exception if an unexpected error occurs
0766:             */
0767:            public void testLoadBootstrapEngineBadBootstrapInitCleanUpException()
0768:                    throws Exception {
0769:                mEngineContext
0770:                        .setComponentName(Constants.SE_NAME_BAD_BOOTSTRAP_INIT_CLEANUP);
0771:                mEngineContext.setIsInstall(true);
0772:                try {
0773:                    mCompFW.loadBootstrap(mEngineContext,
0774:                            Constants.SE_BOOTSTRAP_CLASS_NAME,
0775:                            mEngineBootClassPath, null);
0776:                    fail("Expected exception not received");
0777:                } catch (javax.jbi.JBIException ex) {
0778:                    // Verification
0779:                    assertTrue(
0780:                            "Incorrect exception received: " + ex.toString(),
0781:                            (-1 < ex.getMessage().indexOf(
0782:                                    "bootstrap init failed")));
0783:                    assertTrue(
0784:                            "Incorrect exception received: " + ex.toString(),
0785:                            (-1 < ex.getMessage().indexOf(
0786:                                    "bootstrap cleanup failed")));
0787:                }
0788:            }
0789:
0790:            /**
0791:             * Tests loadBootstrap with for an uninstall with a non-existent component.
0792:             * @throws Exception if an unexpected error occurs
0793:             */
0794:            public void testLoadBootstrapEngineBadNotInstalled()
0795:                    throws Exception {
0796:                try {
0797:                    mEngineContext.setIsInstall(false);
0798:                    mCompFW.loadBootstrap(mEngineContext,
0799:                            Constants.SE_BOOTSTRAP_CLASS_NAME,
0800:                            mEngineBootClassPath, null);
0801:                    fail("Expected exception not received");
0802:                } catch (javax.jbi.JBIException ex) {
0803:                    // Verification
0804:                    assertTrue(
0805:                            "Incorrect exception received: " + ex.toString(),
0806:                            ((-1 < ex.getMessage().indexOf("failed")) && (-1 < ex
0807:                                    .getMessage().indexOf("not installed"))));
0808:                }
0809:            }
0810:
0811:            /**
0812:             * Tests loadBootstrap with for an uninstall with a loaded component.
0813:             * @throws Exception if an unexpected error occurs
0814:             */
0815:            public void testLoadBootstrapEngineBadLoaded() throws Exception {
0816:                mEngineContext.setIsInstall(true);
0817:                mCompFW.loadBootstrap(mEngineContext,
0818:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
0819:                        mEngineBootClassPath, null);
0820:                try {
0821:                    mEngineContext.setIsInstall(false);
0822:                    mCompFW.loadBootstrap(mEngineContext,
0823:                            Constants.SE_BOOTSTRAP_CLASS_NAME,
0824:                            mEngineBootClassPath, null);
0825:                    fail("Expected exception not received");
0826:                } catch (javax.jbi.JBIException ex) {
0827:                    // Verification
0828:                    assertTrue(
0829:                            "Incorrect exception received: " + ex.toString(),
0830:                            ((-1 < ex.getMessage().indexOf("failed")) && (-1 < ex
0831:                                    .getMessage().indexOf("not installed"))));
0832:                }
0833:            }
0834:
0835:            /**
0836:             * Tests getInstallerConfigurationMBeanName for a BC with a good result.
0837:             * @throws Exception if an unexpected error occurs.
0838:             */
0839:
0840:            public void testGetInstallerConfigurationMBeanNameGoodBinding()
0841:                    throws Exception {
0842:                ObjectName objectName;
0843:
0844:                // Load the bootstrap for install.
0845:                mBindingContext.setIsInstall(true);
0846:                mCompFW.loadBootstrap(mBindingContext,
0847:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
0848:                        mBindingBootClassPath, null);
0849:
0850:                // Get the installer configuration MBean object name
0851:                objectName = mCompFW
0852:                        .getInstallerConfigurationMBeanName(Constants.BC_NAME);
0853:                assertNotNull(
0854:                        "Failure getting InstallerConfigurationMBean name",
0855:                        objectName);
0856:
0857:                // Now load the bootstrap for uninstall.
0858:                mCompReg.getComponent(Constants.BC_NAME).setShutdown();
0859:                mBindingContext.setIsInstall(false);
0860:                mCompFW.loadBootstrap(mBindingContext,
0861:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
0862:                        mBindingBootClassPath, null);
0863:
0864:                // Get the installer configuration MBean object name
0865:                objectName = mCompFW
0866:                        .getInstallerConfigurationMBeanName(Constants.BC_NAME);
0867:                assertNotNull(
0868:                        "Failure getting InstallerConfigurationMBean name",
0869:                        objectName);
0870:            }
0871:
0872:            /**
0873:             * Tests getInstallerConfigurationMBeanName for a BC with a bad result.
0874:             * @throws Exception if an unexpected error occurs.
0875:             */
0876:
0877:            public void testGetInstallerConfigurationMBeanNameBadBinding()
0878:                    throws Exception {
0879:                ObjectName objectName;
0880:
0881:                // Try to get the installer configuration MBean object name for
0882:                // a BC that is not in the registry.
0883:                try {
0884:                    objectName = mCompFW
0885:                            .getInstallerConfigurationMBeanName(Constants.BC_NAME);
0886:                    fail("Expected exception not received");
0887:                } catch (javax.jbi.JBIException ex) {
0888:                    // Verification
0889:                    assertTrue(
0890:                            "Incorrect exception received: " + ex.toString(),
0891:                            (-1 < ex.getMessage().indexOf("not found")));
0892:                }
0893:            }
0894:
0895:            /**
0896:             * Tests getInstallerConfigurationMBeanName for an SE with a good result.
0897:             * @throws Exception if an unexpected error occurs.
0898:             */
0899:
0900:            public void testGetInstallerConfigurationMBeanNameGoodEngine()
0901:                    throws Exception {
0902:                ObjectName objectName;
0903:
0904:                // Load the bootstrap for install.
0905:                mEngineContext.setIsInstall(true);
0906:                mCompFW.loadBootstrap(mEngineContext,
0907:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
0908:                        mEngineBootClassPath, null);
0909:
0910:                // Get the installer configuration MBean object name
0911:                objectName = mCompFW
0912:                        .getInstallerConfigurationMBeanName(Constants.SE_NAME);
0913:                assertNotNull(
0914:                        "Failure getting InstallerConfigurationMBean name",
0915:                        objectName);
0916:
0917:                // Now load the bootstrap for uninstall.
0918:                mCompReg.getComponent(Constants.SE_NAME).setShutdown();
0919:                mEngineContext.setIsInstall(false);
0920:                mCompFW.loadBootstrap(mEngineContext,
0921:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
0922:                        mEngineBootClassPath, null);
0923:
0924:                // Get the installer configuration MBean object name
0925:                objectName = mCompFW
0926:                        .getInstallerConfigurationMBeanName(Constants.SE_NAME);
0927:                assertNotNull(
0928:                        "Failure getting InstallerConfigurationMBean name",
0929:                        objectName);
0930:            }
0931:
0932:            /**
0933:             * Tests getInstallerConfigurationMBeanName for an SE with a bad result.
0934:             * @throws Exception if an unexpected error occurs.
0935:             */
0936:
0937:            public void testGetInstallerConfigurationMBeanNameBadEngine()
0938:                    throws Exception {
0939:                ObjectName objectName;
0940:
0941:                // Try to get the installer configuration MBean object name for
0942:                // an SE that is not in the registry.
0943:                try {
0944:                    objectName = mCompFW
0945:                            .getInstallerConfigurationMBeanName(Constants.SE_NAME);
0946:                    fail("Expected exception not received");
0947:                } catch (javax.jbi.JBIException ex) {
0948:                    // Verification
0949:                    assertTrue(
0950:                            "Incorrect exception received: " + ex.toString(),
0951:                            (-1 < ex.getMessage().indexOf("not found")));
0952:                }
0953:            }
0954:
0955:            /**
0956:             * Tests installComponent for a BC with a good result.
0957:             * @throws Exception if an unexpected error occurs.
0958:             */
0959:            public void testInstallBindingGood() throws Exception {
0960:                mBindingContext.setIsInstall(true);
0961:                mCompFW.loadBootstrap(mBindingContext,
0962:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
0963:                        mBindingBootClassPath, null);
0964:                mCompFW.installComponent(mBindingContext);
0965:                Component comp = mCompReg.getComponent(Constants.BC_NAME);
0966:                assertTrue(
0967:                        "Got wrong status for binding. Expected installed, got "
0968:                                + comp.getStatusAsString(), comp.isInstalled());
0969:
0970:                // Verify that all the MBeans were created and registered
0971:                assertTrue("LifeCycleMBean not created for binding", mContext
0972:                        .getMBeanServer().isRegistered(
0973:                                comp.getLifeCycleMBeanName()));
0974:                assertTrue("DeployerMBean not created for binding", mContext
0975:                        .getMBeanServer().isRegistered(
0976:                                comp.getDeployerMBeanName()));
0977:                assertTrue("StatisticsMBean not created for binding", mContext
0978:                        .getMBeanServer().isRegistered(
0979:                                comp.getStatisticsMBeanName()));
0980:                assertTrue("LoggerMBean not created for binding", mContext
0981:                        .getMBeanServer().isRegistered(
0982:                                comp.getLoggerMBeanName()));
0983:                assertTrue("ConfigurationMBean not created for binding",
0984:                        mContext.getMBeanServer().isRegistered(
0985:                                comp.getConfigurationMBeanName()));
0986:            }
0987:
0988:            /**
0989:             * Tests installComponent with a modified class path and a good result.
0990:             * @throws Exception if an unexpected error occurs.
0991:             */
0992:            public void testInstallBindingGoodModifiedClassPath()
0993:                    throws Exception {
0994:                mBindingContext
0995:                        .setComponentName(Constants.BC_NAME_BOOTSTRAP_MODIFY_CLASS_PATH);
0996:                mBindingContext
0997:                        .setComponentClassName(Constants.BC_LIFECYCLE_CLASS_NAME_ALTERNATE);
0998:                mBindingContext.setIsInstall(true);
0999:                mCompFW.loadBootstrap(mBindingContext,
1000:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
1001:                        mBindingBootClassPath, null);
1002:                mCompFW.installComponent(mBindingContext);
1003:                Component comp = mCompReg
1004:                        .getComponent(Constants.BC_NAME_BOOTSTRAP_MODIFY_CLASS_PATH);
1005:                assertTrue(
1006:                        "Got wrong status for binding. Expected installed, got "
1007:                                + comp.getStatusAsString(), comp.isInstalled());
1008:                Object instance = comp.getLifeCycleInstance(true);
1009:                assertTrue("Got wrong instance type of life cycle class: "
1010:                        + "Expected "
1011:                        + Constants.BC_LIFECYCLE_CLASS_NAME_ALTERNATE
1012:                        + ", got " + instance.getClass().getName(),
1013:                        instance instanceof  testbinding.Binding);
1014:            }
1015:
1016:            /**
1017:             * Tests installComponent with a null ComponentInstallationContext.
1018:             * An exception is expected.
1019:             * @throws Exception if an unexpected error occurs.
1020:             */
1021:            public void testInstallBindingBadNullInstallationContext()
1022:                    throws Exception {
1023:                try {
1024:                    mCompFW.installComponent(null);
1025:                    fail("Expected exception not received");
1026:                } catch (java.lang.IllegalArgumentException ex) {
1027:                    // Verification
1028:                    assertTrue(
1029:                            "Incorrect exception received: " + ex.toString(),
1030:                            (-1 < ex.getMessage().indexOf("installContext")));
1031:                }
1032:            }
1033:
1034:            /**
1035:             * Tests installComponent with a component name that was never loaded. An
1036:             * exception is expected.
1037:             * @throws Exception if an unexpected error occurs.
1038:             */
1039:            public void testInstallBindingBadNotLoaded() throws Exception {
1040:                try {
1041:                    mCompFW.installComponent(mBindingContext);
1042:                    fail("Expected exception not received");
1043:                } catch (javax.jbi.JBIException ex) {
1044:                    // Verification
1045:                    assertTrue(
1046:                            "Incorrect exception received: " + ex.toString(),
1047:                            (-1 < ex.getMessage()
1048:                                    .indexOf("not yet been loaded")));
1049:                }
1050:            }
1051:
1052:            /**
1053:             * Tests installComponent with a component whose bootstrap class is no longer
1054:             * loaded. An exception is expected.
1055:             * @throws Exception if an unexpected error occurs.
1056:             */
1057:            public void testInstallBindingBadBootstrapNotLoaded()
1058:                    throws Exception {
1059:                mBindingContext.setIsInstall(true);
1060:                mCompFW.loadBootstrap(mBindingContext,
1061:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
1062:                        mBindingBootClassPath, null);
1063:                mCompReg.getComponent(Constants.BC_NAME)
1064:                        .clearBootstrapInstance();
1065:                try {
1066:                    mCompFW.installComponent(mBindingContext);
1067:                    fail("Expected exception not received");
1068:                } catch (javax.jbi.JBIException ex) {
1069:                    // Verification
1070:                    assertTrue(
1071:                            "Incorrect exception received: " + ex.toString(),
1072:                            (-1 < ex.getMessage()
1073:                                    .indexOf("has not been loaded")));
1074:                }
1075:            }
1076:
1077:            /**
1078:             * Tests installComponent with a binding whose bootstrap onInstall() method
1079:             * throws an exception. 
1080:             * @throws Exception if an unexpected error occurs.
1081:             */
1082:            public void testInstallBindingBadOnInstallException()
1083:                    throws Exception {
1084:                mBindingContext
1085:                        .setComponentName(Constants.BC_NAME_BAD_BOOTSTRAP_ONINSTALL);
1086:                mBindingContext.setIsInstall(true);
1087:                mCompFW.loadBootstrap(mBindingContext,
1088:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
1089:                        mBindingBootClassPath, null);
1090:                try {
1091:                    mCompFW.installComponent(mBindingContext);
1092:                    fail("Expected exception not received");
1093:                } catch (javax.jbi.JBIException ex) {
1094:                    // Verification
1095:                    assertTrue(
1096:                            "Incorrect exception received: " + ex.toString(),
1097:                            (-1 < ex.getMessage().indexOf(
1098:                                    "bootstrap onInstall()")));
1099:                }
1100:            }
1101:
1102:            /**
1103:             * Tests installComponent with a binding whose bootstrap cleanUp() method
1104:             * throws an exception. 
1105:             * @throws Exception if an unexpected error occurs.
1106:             */
1107:            public void testInstallBindingBadCleanUpException()
1108:                    throws Exception {
1109:                mBindingContext
1110:                        .setComponentName(Constants.BC_NAME_BAD_BOOTSTRAP_INSTALL_CLEANUP);
1111:                mBindingContext.setIsInstall(true);
1112:                mCompFW.loadBootstrap(mBindingContext,
1113:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
1114:                        mBindingBootClassPath, null);
1115:                try {
1116:                    mCompFW.installComponent(mBindingContext);
1117:                    fail("Expected exception not received");
1118:                } catch (com.sun.jbi.framework.FrameworkWarningException ex) {
1119:                    // Verification
1120:                    assertTrue(
1121:                            "Incorrect exception received: " + ex.toString(),
1122:                            (-1 < ex.getMessage()
1123:                                    .indexOf("bootstrap cleanUp()")));
1124:                }
1125:            }
1126:
1127:            /**
1128:             * Tests installComponent with a binding whose bootstrap onInstall() and
1129:             * cleanUp() methods both throw exceptions. The client should see the
1130:             * onInstall() exception, not the cleanUp() exception. The cleanUp()
1131:             * exception should be logged.
1132:             * @throws Exception if an unexpected error occurs.
1133:             */
1134:            public void testInstallBindingBadOnInstallCleanupExceptions()
1135:                    throws Exception {
1136:                mBindingContext
1137:                        .setComponentName(Constants.BC_NAME_BAD_BOOTSTRAP_ONINSTALL_CLEANUP);
1138:                mBindingContext.setIsInstall(true);
1139:                mCompFW.loadBootstrap(mBindingContext,
1140:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
1141:                        mBindingBootClassPath, null);
1142:                try {
1143:                    mCompFW.installComponent(mBindingContext);
1144:                    fail("Expected exception not received");
1145:                } catch (javax.jbi.JBIException ex) {
1146:                    // Verification
1147:                    assertTrue(
1148:                            "Incorrect exception received: " + ex.toString(),
1149:                            (-1 < ex.getMessage().indexOf(
1150:                                    "bootstrap onInstall()")));
1151:                }
1152:            }
1153:
1154:            /**
1155:             * Tests installComponent with a bad life cycle class name. The life cycle
1156:             * class will not be found when an attempt is made to load it. An
1157:             * exception is expected.
1158:             * @throws Exception if an unexpected error occurs.
1159:             */
1160:            public void testInstallBindingBadLifeCycleNotFound()
1161:                    throws Exception {
1162:                mBindingContext
1163:                        .setComponentClassName("bad.life.cycle.class.name");
1164:                mBindingContext.setIsInstall(true);
1165:                mCompFW.loadBootstrap(mBindingContext,
1166:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
1167:                        mBindingBootClassPath, null);
1168:                try {
1169:                    mCompFW.installComponent(mBindingContext);
1170:                    fail("Expected exception not received");
1171:                } catch (javax.jbi.JBIException ex) {
1172:                    // Verification
1173:                    assertTrue(
1174:                            "Incorrect exception received: " + ex.toString(),
1175:                            (-1 < ex.getCause().getMessage().indexOf(
1176:                                    "could not be loaded")));
1177:                }
1178:            }
1179:
1180:            /**
1181:             * Tests installComponent with a binding that returns null from its
1182:             * getLifeCycle() method.
1183:             * @throws Exception if an unexpected error occurs.
1184:             */
1185:            public void testInstallBindingBadGetLifeCycleNull()
1186:                    throws Exception {
1187:                mBindingContext
1188:                        .setComponentClassName(Constants.BC_LIFECYCLE_CLASS_NAME_NULL_GET_LIFECYCLE);
1189:                mBindingContext.setIsInstall(true);
1190:                mCompFW.loadBootstrap(mBindingContext,
1191:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
1192:                        mBindingBootClassPath, null);
1193:                try {
1194:                    mCompFW.installComponent(mBindingContext);
1195:                    fail("Expected exception not received");
1196:                } catch (javax.jbi.JBIException ex) {
1197:                    // Verification
1198:                    assertTrue(
1199:                            "Incorrect exception received: " + ex.toString(),
1200:                            (-1 < ex.getCause().getMessage().indexOf(
1201:                                    "JBIFW2010")));
1202:                }
1203:            }
1204:
1205:            /**
1206:             * Tests installComponent with a binding that throws an exception from its
1207:             * getLifeCycle() method.
1208:             * @throws Exception if an unexpected error occurs.
1209:             */
1210:            public void testInstallBindingBadGetLifeCycleException()
1211:                    throws Exception {
1212:                mBindingContext
1213:                        .setComponentClassName(Constants.BC_LIFECYCLE_CLASS_NAME_BAD_GET_LIFECYCLE);
1214:                mBindingContext.setIsInstall(true);
1215:                mCompFW.loadBootstrap(mBindingContext,
1216:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
1217:                        mBindingBootClassPath, null);
1218:                try {
1219:                    mCompFW.installComponent(mBindingContext);
1220:                    fail("Expected exception not received");
1221:                } catch (javax.jbi.JBIException ex) {
1222:                    // Verification
1223:                    assertTrue(
1224:                            "Incorrect exception received: " + ex.toString(),
1225:                            (-1 < ex.getCause().getMessage().indexOf(
1226:                                    "JBIFW2009")));
1227:                }
1228:            }
1229:
1230:            /**
1231:             * Tests installComponent with a good result. 
1232:             * @throws Exception if an unexpected error occurs.
1233:             */
1234:            public void testInstallEngineGood() throws Exception {
1235:                mEngineContext.setIsInstall(true);
1236:                mCompFW.loadBootstrap(mEngineContext,
1237:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
1238:                        mEngineBootClassPath, null);
1239:                mCompFW.installComponent(mEngineContext);
1240:                Component comp = mCompReg.getComponent(Constants.SE_NAME);
1241:                assertTrue(
1242:                        "Got wrong status for engine. Expected installed, got "
1243:                                + comp.getStatusAsString(), comp.isInstalled());
1244:
1245:                // Verify that all the MBeans were created and registered
1246:                assertTrue("LifeCycleMBean not created for engine", mContext
1247:                        .getMBeanServer().isRegistered(
1248:                                comp.getLifeCycleMBeanName()));
1249:                assertTrue("DeployerMBean not created for engine", mContext
1250:                        .getMBeanServer().isRegistered(
1251:                                comp.getDeployerMBeanName()));
1252:                assertTrue("StatisticsMBean not created for engine", mContext
1253:                        .getMBeanServer().isRegistered(
1254:                                comp.getStatisticsMBeanName()));
1255:                assertTrue("LoggerMBean not created for engine", mContext
1256:                        .getMBeanServer().isRegistered(
1257:                                comp.getLoggerMBeanName()));
1258:
1259:                assertTrue("ConfigurationMBean not created for engine",
1260:                        mContext.getMBeanServer().isRegistered(
1261:                                comp.getConfigurationMBeanName()));
1262:            }
1263:
1264:            /**
1265:             * Tests installComponent with a modified class path and a good result.
1266:             * @throws Exception if an unexpected error occurs.
1267:             */
1268:            public void testInstallEngineGoodModifiedClassPath()
1269:                    throws Exception {
1270:                mEngineContext
1271:                        .setComponentName(Constants.SE_NAME_BOOTSTRAP_MODIFY_CLASS_PATH);
1272:                mEngineContext
1273:                        .setComponentClassName(Constants.SE_LIFECYCLE_CLASS_NAME_ALTERNATE);
1274:                mEngineContext.setIsInstall(true);
1275:                mCompFW.loadBootstrap(mEngineContext,
1276:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
1277:                        mEngineBootClassPath, null);
1278:                mCompFW.installComponent(mEngineContext);
1279:                Component comp = mCompReg
1280:                        .getComponent(Constants.SE_NAME_BOOTSTRAP_MODIFY_CLASS_PATH);
1281:                assertTrue(
1282:                        "Got wrong status for engine. Expected installed, got "
1283:                                + comp.getStatusAsString(), comp.isInstalled());
1284:                Object instance = comp.getLifeCycleInstance(true);
1285:                assertTrue("Got wrong instance type of life cycle class. "
1286:                        + "Expected "
1287:                        + Constants.SE_LIFECYCLE_CLASS_NAME_ALTERNATE
1288:                        + ", got " + instance.getClass().getName(),
1289:                        instance instanceof  testengine.Engine);
1290:            }
1291:
1292:            /**
1293:             * Tests installComponent with a null ComponentInstallationContext. An exception
1294:             * is expected.
1295:             * @throws Exception if an unexpected error occurs.
1296:             */
1297:            public void testInstallEngineBadNullInstallationContext()
1298:                    throws Exception {
1299:                try {
1300:                    mCompFW.installComponent(null);
1301:                    fail("Expected exception not received");
1302:                } catch (java.lang.IllegalArgumentException ex) {
1303:                    // Verification
1304:                    assertTrue(
1305:                            "Incorrect exception received: " + ex.toString(),
1306:                            (-1 < ex.getMessage().indexOf("installContext")));
1307:                }
1308:            }
1309:
1310:            /**
1311:             * Tests installComponent with a component name that was never loaded. An
1312:             * exception is expected.
1313:             * @throws Exception if an unexpected error occurs.
1314:             */
1315:            public void testInstallEngineBadNotLoaded() throws Exception {
1316:                try {
1317:                    mCompFW.installComponent(mEngineContext);
1318:                    fail("Expected exception not received");
1319:                } catch (javax.jbi.JBIException ex) {
1320:                    // Verification
1321:                    assertTrue(
1322:                            "Incorrect exception received: " + ex.toString(),
1323:                            (-1 < ex.getMessage()
1324:                                    .indexOf("not yet been loaded")));
1325:                }
1326:            }
1327:
1328:            /**
1329:             * Tests installComponent with a component whose bootstrap class is no longer
1330:             * loaded. An exception is expected.
1331:             * @throws Exception if an unexpected error occurs.
1332:             */
1333:            public void testInstallEngineBadBootstrapNotLoaded()
1334:                    throws Exception {
1335:                mEngineContext.setIsInstall(true);
1336:                mCompFW.loadBootstrap(mEngineContext,
1337:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
1338:                        mEngineBootClassPath, null);
1339:                mCompReg.getComponent(Constants.SE_NAME)
1340:                        .clearBootstrapInstance();
1341:                try {
1342:                    mCompFW.installComponent(mEngineContext);
1343:                    fail("Expected exception not received");
1344:                } catch (javax.jbi.JBIException ex) {
1345:                    // Verification
1346:                    assertTrue(
1347:                            "Incorrect exception received: " + ex.toString(),
1348:                            (-1 < ex.getMessage()
1349:                                    .indexOf("has not been loaded")));
1350:                }
1351:            }
1352:
1353:            /**
1354:             * Tests installComponent with an engine whose bootstrap onInstall() method
1355:             * throws an exception. 
1356:             * @throws Exception if an unexpected error occurs.
1357:             */
1358:            public void testInstallEngineBadOnInstallException()
1359:                    throws Exception {
1360:                mEngineContext
1361:                        .setComponentName(Constants.SE_NAME_BAD_BOOTSTRAP_ONINSTALL);
1362:                mEngineContext.setIsInstall(true);
1363:                mCompFW.loadBootstrap(mEngineContext,
1364:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
1365:                        mEngineBootClassPath, null);
1366:                try {
1367:                    mCompFW.installComponent(mEngineContext);
1368:                    fail("Expected exception not received");
1369:                } catch (javax.jbi.JBIException ex) {
1370:                    // Verification
1371:                    assertTrue(
1372:                            "Incorrect exception received: " + ex.toString(),
1373:                            (-1 < ex.getMessage().indexOf(
1374:                                    "bootstrap onInstall()")));
1375:                }
1376:            }
1377:
1378:            /**
1379:             * Tests installComponent with an engine whose bootstrap cleanUp() method
1380:             * throws an exception. 
1381:             * @throws Exception if an unexpected error occurs.
1382:             */
1383:            public void testInstallEngineBadCleanUpException() throws Exception {
1384:                mEngineContext
1385:                        .setComponentName(Constants.SE_NAME_BAD_BOOTSTRAP_INSTALL_CLEANUP);
1386:                mEngineContext.setIsInstall(true);
1387:                mCompFW.loadBootstrap(mEngineContext,
1388:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
1389:                        mEngineBootClassPath, null);
1390:                try {
1391:                    mCompFW.installComponent(mEngineContext);
1392:                    fail("Expected exception not received");
1393:                } catch (com.sun.jbi.framework.FrameworkWarningException ex) {
1394:                    // Verification
1395:                    assertTrue(
1396:                            "Incorrect exception received: " + ex.toString(),
1397:                            (-1 < ex.getMessage()
1398:                                    .indexOf("bootstrap cleanUp()")));
1399:                }
1400:            }
1401:
1402:            /**
1403:             * Tests installComponent with an engine whose bootstrap onInstall() and
1404:             * cleanUp() methods both throw exceptions. The client should see the
1405:             * onInstall() exception, not the cleanUp() exception. The cleanUp()
1406:             * exception should be logged.
1407:             * @throws Exception if an unexpected error occurs.
1408:             */
1409:            public void testInstallEngineBadOnInstallCleanUpExceptions()
1410:                    throws Exception {
1411:                mEngineContext
1412:                        .setComponentName(Constants.SE_NAME_BAD_BOOTSTRAP_ONINSTALL_CLEANUP);
1413:                mEngineContext.setIsInstall(true);
1414:                mCompFW.loadBootstrap(mEngineContext,
1415:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
1416:                        mEngineBootClassPath, null);
1417:                try {
1418:                    mCompFW.installComponent(mEngineContext);
1419:                    fail("Expected exception not received");
1420:                } catch (javax.jbi.JBIException ex) {
1421:                    // Verification
1422:                    assertTrue(
1423:                            "Incorrect exception received: " + ex.toString(),
1424:                            (-1 < ex.getMessage().indexOf(
1425:                                    "bootstrap onInstall()")));
1426:                }
1427:            }
1428:
1429:            /**
1430:             * Tests installComponent with a bad life cycle class name. The life cycle
1431:             * class will not be found when an attempt is made to load it. An
1432:             * exception is expected.
1433:             * @throws Exception if an unexpected error occurs.
1434:             */
1435:            public void testInstallEngineBadLifeCycleNotFound()
1436:                    throws Exception {
1437:                mEngineContext
1438:                        .setComponentClassName("bad.life.cycle.class.name");
1439:                mEngineContext.setIsInstall(true);
1440:                mCompFW.loadBootstrap(mEngineContext,
1441:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
1442:                        mEngineBootClassPath, null);
1443:                try {
1444:                    mCompFW.installComponent(mEngineContext);
1445:                    fail("Expected exception not received");
1446:                } catch (javax.jbi.JBIException ex) {
1447:                    // Verification
1448:                    assertTrue(
1449:                            "Incorrect exception received: " + ex.toString(),
1450:                            (-1 < ex.getCause().getMessage().indexOf(
1451:                                    "could not be loaded")));
1452:                }
1453:            }
1454:
1455:            /**
1456:             * Tests installComponent with an engine that returns null from its
1457:             * getLifeCycle() method.
1458:             * @throws Exception if an unexpected error occurs.
1459:             */
1460:            public void testInstallEngineBadGetLifeCycleNull() throws Exception {
1461:                mEngineContext
1462:                        .setComponentClassName(Constants.SE_LIFECYCLE_CLASS_NAME_NULL_GET_LIFECYCLE);
1463:                mEngineContext.setIsInstall(true);
1464:                mCompFW.loadBootstrap(mEngineContext,
1465:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
1466:                        mEngineBootClassPath, null);
1467:                try {
1468:                    mCompFW.installComponent(mEngineContext);
1469:                    fail("Expected exception not received");
1470:                } catch (javax.jbi.JBIException ex) {
1471:                    // Verification
1472:                    assertTrue(
1473:                            "Incorrect exception received: " + ex.toString(),
1474:                            (-1 < ex.getCause().getMessage().indexOf(
1475:                                    "JBIFW2010")));
1476:                }
1477:            }
1478:
1479:            /**
1480:             * Tests installComponent with an engine that throws an exception from its
1481:             * getLifeCycle() method.
1482:             * @throws Exception if an unexpected error occurs.
1483:             */
1484:            public void testInstallEngineBadGetLifeCycleException()
1485:                    throws Exception {
1486:                mEngineContext
1487:                        .setComponentClassName(Constants.SE_LIFECYCLE_CLASS_NAME_BAD_GET_LIFECYCLE);
1488:                mEngineContext.setIsInstall(true);
1489:                mCompFW.loadBootstrap(mEngineContext,
1490:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
1491:                        mEngineBootClassPath, null);
1492:                try {
1493:                    mCompFW.installComponent(mEngineContext);
1494:                    fail("Expected exception not received");
1495:                } catch (javax.jbi.JBIException ex) {
1496:                    // Verification
1497:                    assertTrue(
1498:                            "Incorrect exception received: " + ex.toString(),
1499:                            (-1 < ex.getCause().getMessage().indexOf(
1500:                                    "JBIFW2009")));
1501:                }
1502:            }
1503:
1504:            /**
1505:             * Tests installSharedLibrary with a good result.
1506:             * @throws Exception if an unexpected error occurs.
1507:             */
1508:            public void testInstallSharedLibraryGood() throws Exception {
1509:                mCompFW.installSharedLibrary(Constants.SL_1_NAME,
1510:                        Constants.SL_1_DESC, Constants.SL_1_ROOT, false,
1511:                        mSl1Elements);
1512:                assertNotNull("Failure installing Shared Library", mCompReg
1513:                        .getSharedLibrary(Constants.SL_1_NAME));
1514:
1515:            }
1516:
1517:            /**
1518:             * Tests installSharedLibrary with a null name.
1519:             * @throws Exception if an unexpected error occurs.
1520:             */
1521:            public void testInstallSharedLibraryBadNullName() throws Exception {
1522:                try {
1523:                    mCompFW.installSharedLibrary(null, Constants.SL_1_DESC,
1524:                            Constants.SL_1_ROOT, false, mSl1Elements);
1525:                    fail("Expected exception not received");
1526:                } catch (java.lang.IllegalArgumentException ex) {
1527:                    // Verification
1528:                    assertTrue(
1529:                            "Incorrect exception received: " + ex.toString(),
1530:                            (-1 < ex.getMessage().indexOf("Null argument")));
1531:                }
1532:            }
1533:
1534:            /**
1535:             * Tests installSharedLibrary with an empty name.
1536:             * @throws Exception if an unexpected error occurs.
1537:             */
1538:            public void testInstallSharedLibraryBadEmptyName() throws Exception {
1539:                try {
1540:                    mCompFW.installSharedLibrary("", Constants.SL_1_DESC,
1541:                            Constants.SL_1_ROOT, false, mSl1Elements);
1542:                    fail("Expected exception not received");
1543:                } catch (java.lang.IllegalArgumentException ex) {
1544:                    // Verification
1545:                    assertTrue(
1546:                            "Incorrect exception received: " + ex.toString(),
1547:                            (-1 < ex.getMessage().indexOf(
1548:                                    "Empty string argument")));
1549:                }
1550:            }
1551:
1552:            /**
1553:             * Tests installSharedLibrary with a null component root.
1554:             * @throws Exception if an unexpected error occurs.
1555:             */
1556:            public void testInstallSharedLibraryBadNullComponentRoot()
1557:                    throws Exception {
1558:                try {
1559:                    mCompFW.installSharedLibrary(Constants.SL_1_NAME,
1560:                            Constants.SL_1_DESC, null, false, mSl1Elements);
1561:                    fail("Expected exception not received");
1562:                } catch (java.lang.IllegalArgumentException ex) {
1563:                    // Verification
1564:                    assertTrue(
1565:                            "Incorrect exception received: " + ex.toString(),
1566:                            (-1 < ex.getMessage().indexOf("Null argument")));
1567:                }
1568:            }
1569:
1570:            /**
1571:             * Tests installSharedLibrary with an empty component root.
1572:             * @throws Exception if an unexpected error occurs.
1573:             */
1574:            public void testInstallSharedLibraryBadEmptyComponentRoot()
1575:                    throws Exception {
1576:                try {
1577:                    mCompFW.installSharedLibrary(Constants.SL_1_NAME,
1578:                            Constants.SL_1_DESC, "", false, mSl1Elements);
1579:                    fail("Expected exception not received");
1580:                } catch (java.lang.IllegalArgumentException ex) {
1581:                    // Verification
1582:                    assertTrue(
1583:                            "Incorrect exception received: " + ex.toString(),
1584:                            (-1 < ex.getMessage().indexOf(
1585:                                    "Empty string argument")));
1586:                }
1587:            }
1588:
1589:            /**
1590:             * Tests installSharedLibrary with a null class path.
1591:             * @throws Exception if an unexpected error occurs.
1592:             */
1593:            public void testInstallSharedLibraryBadNullClassPath()
1594:                    throws Exception {
1595:                try {
1596:                    mCompFW.installSharedLibrary(Constants.SL_1_NAME,
1597:                            Constants.SL_1_DESC, Constants.SL_1_ROOT, false,
1598:                            null);
1599:                    fail("Expected exception not received");
1600:                } catch (java.lang.IllegalArgumentException ex) {
1601:                    // Verification
1602:                    assertTrue(
1603:                            "Incorrect exception received: " + ex.toString(),
1604:                            (-1 < ex.getMessage().indexOf("Null argument")));
1605:                }
1606:            }
1607:
1608:            /**
1609:             * Tests installSharedLibrary with an empty class path.
1610:             * @throws Exception if an unexpected error occurs.
1611:             */
1612:            public void testInstallSharedLibraryBadEmptyClassPath()
1613:                    throws Exception {
1614:                try {
1615:                    mCompFW.installSharedLibrary(Constants.SL_1_NAME,
1616:                            Constants.SL_1_DESC, Constants.SL_1_ROOT, false,
1617:                            new ArrayList());
1618:                    fail("Expected exception not received");
1619:                } catch (java.lang.IllegalArgumentException ex) {
1620:                    // Verification
1621:                    assertTrue(
1622:                            "Incorrect exception received: " + ex.toString(),
1623:                            (-1 < ex.getMessage()
1624:                                    .indexOf("Empty list argument")));
1625:                }
1626:            }
1627:
1628:            /**
1629:             * Tests installSharedLibrary with a duplicate component name.
1630:             * @throws Exception if an unexpected error occurs.
1631:             */
1632:            public void testInstallSharedLibraryBadDuplicate() throws Exception {
1633:                mCompFW.installSharedLibrary(Constants.SL_1_NAME,
1634:                        Constants.SL_1_DESC, Constants.SL_1_ROOT, false,
1635:                        mSl1Elements);
1636:                try {
1637:                    mCompFW.installSharedLibrary(Constants.SL_1_NAME,
1638:                            Constants.SL_1_DESC, Constants.SL_1_ROOT, false,
1639:                            mSl1Elements);
1640:                    fail("Expected exception not received");
1641:                } catch (javax.jbi.JBIException ex) {
1642:                    // Verification
1643:                    assertTrue(
1644:                            "Incorrect exception received: " + ex.toString(),
1645:                            (-1 < ex.getMessage().indexOf("already registered")));
1646:                }
1647:            }
1648:
1649:            /**
1650:             * Tests uninstallComponent with a good result.
1651:             * @throws Exception if an unexpected error occurs.
1652:             */
1653:            public void testUninstallBindingGood() throws Exception {
1654:                mBindingContext.setIsInstall(true);
1655:                mCompFW.loadBootstrap(mBindingContext,
1656:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
1657:                        mBindingBootClassPath, null);
1658:                mCompFW.installComponent(mBindingContext);
1659:                mBindingContext.setIsInstall(false);
1660:                Component comp = mCompReg.getComponent(Constants.BC_NAME);
1661:                ObjectName lcmb = comp.getLifeCycleMBeanName();
1662:                ObjectName dmb = comp.getDeployerMBeanName();
1663:                ObjectName smb = comp.getStatisticsMBeanName();
1664:                ObjectName lmb = comp.getLoggerMBeanName();
1665:                ObjectName ccmb = comp.getConfigurationMBeanName();
1666:                mCompFW.loadBootstrap(mBindingContext,
1667:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
1668:                        mBindingBootClassPath, null);
1669:                mCompFW.uninstallComponent(mBindingContext, false);
1670:                assertTrue("Binding " + Constants.BC_NAME
1671:                        + " is still registered", comp.isLoaded());
1672:
1673:                // Verify that all the MBeans were destroyed and unregistered
1674:                assertFalse("LifeCycleMBean not removed for binding", mContext
1675:                        .getMBeanServer().isRegistered(lcmb));
1676:                assertFalse("DeployerMBean not removed for binding", mContext
1677:                        .getMBeanServer().isRegistered(dmb));
1678:                assertFalse("StatisticsMBean not removed for binding", mContext
1679:                        .getMBeanServer().isRegistered(smb));
1680:                assertFalse("LoggerMBean not removed for binding", mContext
1681:                        .getMBeanServer().isRegistered(lmb));
1682:                assertFalse("ConfigurationMBean not removed for engine",
1683:                        mContext.getMBeanServer().isRegistered(ccmb));
1684:            }
1685:
1686:            /**
1687:             * Tests uninstallComponent with a null ComponentInstallationContext
1688:             * parameter. An exception is expected.
1689:             * @throws Exception if an unexpected error occurs.
1690:             */
1691:            public void testUninstallBindingBadNullInstallationContext()
1692:                    throws Exception {
1693:                try {
1694:                    mCompFW.uninstallComponent(null, false);
1695:                    fail("Expected exception not received");
1696:                } catch (java.lang.IllegalArgumentException ex) {
1697:                    // Verification
1698:                    assertTrue(
1699:                            "Incorrect exception received: " + ex.toString(),
1700:                            (-1 < ex.getMessage().indexOf("Null argument")));
1701:                }
1702:            }
1703:
1704:            /**
1705:             * Tests uninstallComponent with an nonexistent binding. An exception is
1706:             * expected.
1707:             * @throws Exception if an unexpected error occurs.
1708:             */
1709:            public void testUninstallBindingBadNotFound() throws Exception {
1710:                try {
1711:                    mCompFW.uninstallComponent(mBindingContext, false);
1712:                    fail("Expected exception not received");
1713:                } catch (javax.jbi.JBIException ex) {
1714:                    // Verification
1715:                    assertTrue(
1716:                            "Incorrect exception received: " + ex.toString(),
1717:                            (-1 < ex.getMessage().indexOf(
1718:                                    "no Binding installed")));
1719:                }
1720:            }
1721:
1722:            /**
1723:             * Tests uninstallComponent with binding whose bootstrap onUninstall() method
1724:             * throws an exception.
1725:             * @throws Exception if an unexpected error occurs.
1726:             */
1727:            public void testUninstallBindingBadOnUninstallException()
1728:                    throws Exception {
1729:                mBindingContext
1730:                        .setComponentName(Constants.BC_NAME_BAD_BOOTSTRAP_ONUNINSTALL);
1731:                mBindingContext.setIsInstall(true);
1732:                mCompFW.loadBootstrap(mBindingContext,
1733:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
1734:                        mBindingBootClassPath, null);
1735:                mCompFW.installComponent(mBindingContext);
1736:                mBindingContext.setIsInstall(false);
1737:                mCompFW.loadBootstrap(mBindingContext,
1738:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
1739:                        mBindingBootClassPath, null);
1740:                try {
1741:                    mCompFW.uninstallComponent(mBindingContext, false);
1742:                    fail("Expected exception not received");
1743:                } catch (javax.jbi.JBIException ex) {
1744:                    // Verification
1745:                    assertTrue(
1746:                            "Incorrect exception received: " + ex.toString(),
1747:                            (-1 < ex.getMessage().indexOf(
1748:                                    "bootstrap onUninstall()")));
1749:                }
1750:            }
1751:
1752:            /**
1753:             * Tests uninstallComponent with binding whose bootstrap cleanUp() method
1754:             * throws an exception.
1755:             * @throws Exception if an unexpected error occurs.
1756:             */
1757:            public void testUninstallBindingBadCleanUpException()
1758:                    throws Exception {
1759:                mBindingContext
1760:                        .setComponentName(Constants.BC_NAME_BAD_BOOTSTRAP_UNINSTALL_CLEANUP);
1761:                mBindingContext.setIsInstall(true);
1762:                mCompFW.loadBootstrap(mBindingContext,
1763:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
1764:                        mBindingBootClassPath, null);
1765:                mCompFW.installComponent(mBindingContext);
1766:                mBindingContext.setIsInstall(false);
1767:                mCompFW.loadBootstrap(mBindingContext,
1768:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
1769:                        mBindingBootClassPath, null);
1770:                try {
1771:                    mCompFW.uninstallComponent(mBindingContext, false);
1772:                    fail("Expected exception not received");
1773:                } catch (com.sun.jbi.framework.FrameworkWarningException ex) {
1774:                    // Verification
1775:                    assertTrue(
1776:                            "Incorrect exception received: " + ex.toString(),
1777:                            (-1 < ex.getMessage()
1778:                                    .indexOf("bootstrap cleanUp()")));
1779:                }
1780:            }
1781:
1782:            /**
1783:             * Tests uninstallComponent with binding whose bootstrap onUninstall() and
1784:             * cleanUp() methods both throw exceptions. The client should see the
1785:             * onUninstall() exception, not the cleanUp() exception. The cleanUp()
1786:             * exception is only logged.
1787:             * @throws Exception if an unexpected error occurs.
1788:             */
1789:            public void testUninstallBindingBadOnUninstallCleanUpExceptions()
1790:                    throws Exception {
1791:                mBindingContext
1792:                        .setComponentName(Constants.BC_NAME_BAD_BOOTSTRAP_ONUNINSTALL_CLEANUP);
1793:                mBindingContext.setIsInstall(true);
1794:                mCompFW.loadBootstrap(mBindingContext,
1795:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
1796:                        mBindingBootClassPath, null);
1797:                mCompFW.installComponent(mBindingContext);
1798:                mBindingContext.setIsInstall(false);
1799:                mCompFW.loadBootstrap(mBindingContext,
1800:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
1801:                        mBindingBootClassPath, null);
1802:                try {
1803:                    mCompFW.uninstallComponent(mBindingContext, false);
1804:                    fail("Expected exception not received");
1805:                } catch (javax.jbi.JBIException ex) {
1806:                    // Verification
1807:                    assertTrue(
1808:                            "Incorrect exception received: " + ex.toString(),
1809:                            (-1 < ex.getMessage().indexOf(
1810:                                    "bootstrap onUninstall()")));
1811:                }
1812:            }
1813:
1814:            /**
1815:             * Tests uninstallComponent with the binding started. An exception
1816:             * is expected.
1817:             * @throws Exception if an unexpected error occurs.
1818:             */
1819:            public void testUninstallBindingBadStarted() throws Exception {
1820:                // Load, install, and start the binding.
1821:
1822:                mBindingContext.setIsInstall(true);
1823:                mCompFW.loadBootstrap(mBindingContext,
1824:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
1825:                        mBindingBootClassPath, null);
1826:                mCompFW.installComponent(mBindingContext);
1827:                Component comp = mCompReg.getComponent(Constants.BC_NAME);
1828:                mCompFW.startComponent(comp);
1829:                mBindingContext.setIsInstall(false);
1830:                mCompFW.loadBootstrap(mBindingContext,
1831:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
1832:                        mBindingBootClassPath, null);
1833:                try {
1834:                    mCompFW.uninstallComponent(mBindingContext, false);
1835:                    fail("Expected exception not received");
1836:                } catch (javax.jbi.JBIException ex) {
1837:                    // Verification
1838:                    assertTrue(
1839:                            "Incorrect exception received: " + ex.toString(),
1840:                            (-1 < ex.getMessage().indexOf("is still running")));
1841:                }
1842:            }
1843:
1844:            /**
1845:             * Tests uninstallComponent with the binding stopped. An exception
1846:             * is expected.
1847:             * @throws Exception if an unexpected error occurs.
1848:             */
1849:            public void testUninstallBindingBadStopped() throws Exception {
1850:                // Load, install, start, and stop the binding.
1851:
1852:                mBindingContext.setIsInstall(true);
1853:                mCompFW.loadBootstrap(mBindingContext,
1854:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
1855:                        mBindingBootClassPath, null);
1856:                mCompFW.installComponent(mBindingContext);
1857:                Component comp = mCompReg.getComponent(Constants.BC_NAME);
1858:                mCompFW.startComponent(comp);
1859:                mCompFW.stopComponent(comp);
1860:                mBindingContext.setIsInstall(false);
1861:                mCompFW.loadBootstrap(mBindingContext,
1862:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
1863:                        mBindingBootClassPath, null);
1864:                try {
1865:                    mCompFW.uninstallComponent(mBindingContext, false);
1866:                    fail("Expected exception not received");
1867:                } catch (javax.jbi.JBIException ex) {
1868:                    // Verification
1869:                    assertTrue(
1870:                            "Incorrect exception received: " + ex.toString(),
1871:                            (-1 < ex.getMessage().indexOf("is stopped")));
1872:                }
1873:            }
1874:
1875:            /**
1876:             * Tests uninstallComponent with a binding that still has SUs deployed to it.
1877:             * An exception is expected.
1878:             * @throws Exception if an unexpected error occurs.
1879:             */
1880:            public void testUninstallBindingBadDeployed() throws Exception {
1881:                // Install the binding.
1882:
1883:                mBindingContext.setIsInstall(true);
1884:                mCompFW.loadBootstrap(mBindingContext,
1885:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
1886:                        mBindingBootClassPath, null);
1887:                mCompFW.installComponent(mBindingContext);
1888:
1889:                // Now fake up a deployment.
1890:
1891:                ServiceUnit su1 = new ServiceUnit("ServiceAssembly1",
1892:                        "ServiceUnit1", "sus/ServiceUnit1");
1893:                mCompReg.getComponent(Constants.BC_NAME).addServiceUnit(su1);
1894:
1895:                // Try to uninstall. This should fail.
1896:
1897:                mBindingContext.setIsInstall(false);
1898:                mCompFW.loadBootstrap(mBindingContext,
1899:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
1900:                        mBindingBootClassPath, null);
1901:                try {
1902:                    mCompFW.uninstallComponent(mBindingContext, false);
1903:                    fail("Expected exception not received");
1904:                } catch (javax.jbi.JBIException ex) {
1905:                    // Verification
1906:                    assertTrue(
1907:                            "Incorrect exception received: " + ex.toString(),
1908:                            (-1 < ex.getMessage().indexOf("JBIFW1118")));
1909:                }
1910:            }
1911:
1912:            /**
1913:             * Tests uninstallComponent with good results.
1914:             * @throws Exception if an unexpected error occurs.
1915:             */
1916:            public void testUninstallEngineGood() throws Exception {
1917:                mEngineContext.setIsInstall(true);
1918:                mCompFW.loadBootstrap(mEngineContext,
1919:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
1920:                        mEngineBootClassPath, null);
1921:                mCompFW.installComponent(mEngineContext);
1922:                mEngineContext.setIsInstall(false);
1923:                Component comp = mCompReg.getComponent(Constants.SE_NAME);
1924:                ObjectName lcmb = comp.getLifeCycleMBeanName();
1925:                ObjectName dmb = comp.getDeployerMBeanName();
1926:                ObjectName smb = comp.getStatisticsMBeanName();
1927:                ObjectName lmb = comp.getLoggerMBeanName();
1928:                ObjectName ccmb = comp.getConfigurationMBeanName();
1929:
1930:                mCompFW.loadBootstrap(mEngineContext,
1931:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
1932:                        mEngineBootClassPath, null);
1933:                mCompFW.uninstallComponent(mEngineContext, false);
1934:                assertTrue("Engine " + Constants.SE_NAME
1935:                        + " is still registered", comp.isLoaded());
1936:
1937:                // Verify that all the MBeans were destroyed and unregistered
1938:                assertFalse("LifeCycleMBean not removed for engine", mContext
1939:                        .getMBeanServer().isRegistered(lcmb));
1940:                assertFalse("DeployerMBean not removed for engine", mContext
1941:                        .getMBeanServer().isRegistered(dmb));
1942:                assertFalse("StatisticsMBean not removed for engine", mContext
1943:                        .getMBeanServer().isRegistered(smb));
1944:                assertFalse("LoggerMBean not removed for engine", mContext
1945:                        .getMBeanServer().isRegistered(lmb));
1946:                assertFalse("ConfigurationMBean not removed for engine",
1947:                        mContext.getMBeanServer().isRegistered(ccmb));
1948:            }
1949:
1950:            /**
1951:             * Tests uninstallComponent with a null ComponentInstallationContext
1952:             * parameter. An exception is expected.
1953:             * @throws Exception if an unexpected error occurs.
1954:             */
1955:            public void testUninstallEngineBadNullInstallationContext()
1956:                    throws Exception {
1957:                try {
1958:                    mCompFW.uninstallComponent(null, false);
1959:                    fail("Expected exception not received");
1960:                } catch (java.lang.IllegalArgumentException ex) {
1961:                    // Verification
1962:                    assertTrue(
1963:                            "Incorrect exception received: " + ex.toString(),
1964:                            (-1 < ex.getMessage().indexOf("Null argument")));
1965:                }
1966:            }
1967:
1968:            /**
1969:             * Tests uninstallComponent with an nonexistent engine. An exception is
1970:             * expected.
1971:             * @throws Exception if an unexpected error occurs.
1972:             */
1973:            public void testUninstallEngineBadNotFound() throws Exception {
1974:                try {
1975:                    mCompFW.uninstallComponent(mEngineContext, false);
1976:                    fail("Expected exception not received");
1977:                } catch (javax.jbi.JBIException ex) {
1978:                    // Verification
1979:                    assertTrue(
1980:                            "Incorrect exception received: " + ex.toString(),
1981:                            (-1 < ex.getMessage().indexOf("no Engine")));
1982:                }
1983:            }
1984:
1985:            /**
1986:             * Tests uninstallComponent with an engine whose bootstrap onUninstall()
1987:             * method throws an exception.
1988:             * @throws Exception if an unexpected error occurs.
1989:             */
1990:            public void testUninstallEngineBadOnUninstallException()
1991:                    throws Exception {
1992:                mEngineContext
1993:                        .setComponentName(Constants.SE_NAME_BAD_BOOTSTRAP_ONUNINSTALL);
1994:                mEngineContext.setIsInstall(true);
1995:                mCompFW.loadBootstrap(mEngineContext,
1996:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
1997:                        mEngineBootClassPath, null);
1998:                mCompFW.installComponent(mEngineContext);
1999:                mEngineContext.setIsInstall(false);
2000:                mCompFW.loadBootstrap(mEngineContext,
2001:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
2002:                        mEngineBootClassPath, null);
2003:                try {
2004:                    mCompFW.uninstallComponent(mEngineContext, false);
2005:                    fail("Expected exception not received");
2006:                } catch (javax.jbi.JBIException ex) {
2007:                    // Verification
2008:                    assertTrue(
2009:                            "Incorrect exception received: " + ex.toString(),
2010:                            (-1 < ex.getMessage().indexOf(
2011:                                    "bootstrap onUninstall()")));
2012:                }
2013:            }
2014:
2015:            /**
2016:             * Tests uninstallComponent with an engine whose bootstrap cleanUp()
2017:             * method throws an exception.
2018:             * @throws Exception if an unexpected error occurs.
2019:             */
2020:            public void testUninstallEngineBadCleanUpException()
2021:                    throws Exception {
2022:                mEngineContext
2023:                        .setComponentName(Constants.SE_NAME_BAD_BOOTSTRAP_UNINSTALL_CLEANUP);
2024:                mEngineContext.setIsInstall(true);
2025:                mCompFW.loadBootstrap(mEngineContext,
2026:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
2027:                        mEngineBootClassPath, null);
2028:                mCompFW.installComponent(mEngineContext);
2029:                mEngineContext.setIsInstall(false);
2030:                mCompFW.loadBootstrap(mEngineContext,
2031:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
2032:                        mEngineBootClassPath, null);
2033:                try {
2034:                    mCompFW.uninstallComponent(mEngineContext, false);
2035:                    fail("Expected exception not received");
2036:                } catch (com.sun.jbi.framework.FrameworkWarningException ex) {
2037:                    // Verification
2038:                    assertTrue(
2039:                            "Incorrect exception received: " + ex.toString(),
2040:                            (-1 < ex.getMessage()
2041:                                    .indexOf("bootstrap cleanUp()")));
2042:                }
2043:            }
2044:
2045:            /**
2046:             * Tests uninstallComponent with an engine whose bootstrap onUninstall() and
2047:             * cleanUp() methods both throw exceptions. The client should see the
2048:             * onUninstall() exception, not the cleanUp() exception. The cleanUp()
2049:             * exception is only logged.
2050:             * @throws Exception if an unexpected error occurs.
2051:             */
2052:            public void testUninstallEngineBadOnUninstallCleanupExceptions()
2053:                    throws Exception {
2054:                mEngineContext
2055:                        .setComponentName(Constants.SE_NAME_BAD_BOOTSTRAP_ONUNINSTALL_CLEANUP);
2056:                mEngineContext.setIsInstall(true);
2057:                mCompFW.loadBootstrap(mEngineContext,
2058:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
2059:                        mEngineBootClassPath, null);
2060:                mCompFW.installComponent(mEngineContext);
2061:                mEngineContext.setIsInstall(false);
2062:                mCompFW.loadBootstrap(mEngineContext,
2063:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
2064:                        mEngineBootClassPath, null);
2065:                try {
2066:                    mCompFW.uninstallComponent(mEngineContext, false);
2067:                    fail("Expected exception not received");
2068:                } catch (javax.jbi.JBIException ex) {
2069:                    // Verification
2070:                    assertTrue(
2071:                            "Incorrect exception received: " + ex.toString(),
2072:                            (-1 < ex.getMessage().indexOf(
2073:                                    "bootstrap onUninstall()")));
2074:                }
2075:            }
2076:
2077:            /**
2078:             * Tests uninstallComponent with the engine started. An exception
2079:             * is expected.
2080:             * @throws Exception if an unexpected error occurs.
2081:             */
2082:            public void testUninstallEngineBadStarted() throws Exception {
2083:                // Load, install, and start the engine.
2084:
2085:                mEngineContext.setIsInstall(true);
2086:                mCompFW.loadBootstrap(mEngineContext,
2087:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
2088:                        mEngineBootClassPath, null);
2089:                mCompFW.installComponent(mEngineContext);
2090:                Component comp = mCompReg.getComponent(Constants.SE_NAME);
2091:                mCompFW.startComponent(comp);
2092:                mEngineContext.setIsInstall(false);
2093:                mCompFW.loadBootstrap(mEngineContext,
2094:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
2095:                        mEngineBootClassPath, null);
2096:                try {
2097:                    mCompFW.uninstallComponent(mEngineContext, false);
2098:                    fail("Expected exception not received");
2099:                } catch (javax.jbi.JBIException ex) {
2100:                    // Verification
2101:                    assertTrue(
2102:                            "Incorrect exception received: " + ex.toString(),
2103:                            (-1 < ex.getMessage().indexOf("is still running")));
2104:                }
2105:            }
2106:
2107:            /**
2108:             * Tests uninstallComponent with the engine stopped. An exception
2109:             * is expected.
2110:             * @throws Exception if an unexpected error occurs.
2111:             */
2112:            public void testUninstallEngineBadStopped() throws Exception {
2113:                // Load, install, start, and stop the engine.
2114:
2115:                mEngineContext.setIsInstall(true);
2116:                mCompFW.loadBootstrap(mEngineContext,
2117:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
2118:                        mEngineBootClassPath, null);
2119:                mCompFW.installComponent(mEngineContext);
2120:                Component comp = mCompReg.getComponent(Constants.SE_NAME);
2121:                mCompFW.startComponent(comp);
2122:                mCompFW.stopComponent(comp);
2123:                mEngineContext.setIsInstall(false);
2124:                mCompFW.loadBootstrap(mEngineContext,
2125:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
2126:                        mEngineBootClassPath, null);
2127:                try {
2128:                    mCompFW.uninstallComponent(mEngineContext, false);
2129:                    fail("Expected exception not received");
2130:                } catch (javax.jbi.JBIException ex) {
2131:                    // Verification
2132:                    assertTrue(
2133:                            "Incorrect exception received: " + ex.toString(),
2134:                            (-1 < ex.getMessage().indexOf("is stopped")));
2135:                }
2136:            }
2137:
2138:            /**
2139:             * Tests uninstallComponent with an engine that still has SUs deployed.
2140:             * An exception is expected.
2141:             * @throws Exception if an unexpected error occurs.
2142:             */
2143:            public void testUninstallEngineBadDeployed() throws Exception {
2144:                // Install the engine.
2145:
2146:                mEngineContext.setIsInstall(true);
2147:                mCompFW.loadBootstrap(mEngineContext,
2148:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
2149:                        mEngineBootClassPath, null);
2150:                mCompFW.installComponent(mEngineContext);
2151:
2152:                // Now fake up a deployment.
2153:
2154:                ServiceUnit su1 = new ServiceUnit("ServiceAssembly1",
2155:                        "ServiceUnit1", "sus/ServiceUnit1");
2156:                mCompReg.getComponent(Constants.SE_NAME).addServiceUnit(su1);
2157:
2158:                // Try to uninstall. This should fail.
2159:
2160:                mEngineContext.setIsInstall(false);
2161:                mCompFW.loadBootstrap(mEngineContext,
2162:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
2163:                        mEngineBootClassPath, null);
2164:                try {
2165:                    mCompFW.uninstallComponent(mEngineContext, false);
2166:                    fail("Expected exception not received");
2167:                } catch (javax.jbi.JBIException ex) {
2168:                    // Verification
2169:                    assertTrue(
2170:                            "Incorrect exception received: " + ex.toString(),
2171:                            (-1 < ex.getMessage().indexOf("JBIFW1118")));
2172:                }
2173:            }
2174:
2175:            /**
2176:             * Tests uninstallComponent with the force option with a component that
2177:             * throws an exception in its onUninstall() method.
2178:             * @throws Exception if an unexpected error occurs.
2179:             */
2180:            public void testUninstallForceGoodOnUninstallException()
2181:                    throws Exception {
2182:                // Install the engine.
2183:
2184:                mEngineContext
2185:                        .setComponentName(Constants.SE_NAME_BAD_BOOTSTRAP_ONUNINSTALL);
2186:                mEngineContext.setIsInstall(true);
2187:                mCompFW.loadBootstrap(mEngineContext,
2188:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
2189:                        mEngineBootClassPath, null);
2190:                mCompFW.installComponent(mEngineContext);
2191:                Component comp = mCompReg
2192:                        .getComponent(Constants.SE_NAME_BAD_BOOTSTRAP_ONUNINSTALL);
2193:                ObjectName lcmb = comp.getLifeCycleMBeanName();
2194:                ObjectName dmb = comp.getDeployerMBeanName();
2195:                ObjectName smb = comp.getStatisticsMBeanName();
2196:                ObjectName lmb = comp.getLoggerMBeanName();
2197:
2198:                // Try to uninstall. This should fail.
2199:
2200:                mEngineContext.setIsInstall(false);
2201:                mCompFW.loadBootstrap(mEngineContext,
2202:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
2203:                        mEngineBootClassPath, null);
2204:                try {
2205:                    mCompFW.uninstallComponent(mEngineContext, false);
2206:                    fail("Expected exception not received");
2207:                } catch (javax.jbi.JBIException ex) {
2208:                    // Verification
2209:                    assertTrue(
2210:                            "Incorrect exception received: " + ex.toString(),
2211:                            (-1 < ex.getMessage().indexOf("JBIFW1117")));
2212:                }
2213:
2214:                // Try to uninstall with force set. This should succeed.
2215:
2216:                mCompFW.uninstallComponent(mEngineContext, true);
2217:                assertTrue("Engine "
2218:                        + Constants.SE_NAME_BAD_BOOTSTRAP_ONUNINSTALL
2219:                        + " is still registered", comp.isLoaded());
2220:
2221:                // Verify that all the MBeans were destroyed and unregistered
2222:                assertFalse("LifeCycleMBean not removed for engine", mContext
2223:                        .getMBeanServer().isRegistered(lcmb));
2224:                assertFalse("DeployerMBean not removed for engine", mContext
2225:                        .getMBeanServer().isRegistered(dmb));
2226:                assertFalse("StatisticsMBean not removed for engine", mContext
2227:                        .getMBeanServer().isRegistered(smb));
2228:                assertFalse("LoggerMBean not removed for engine", mContext
2229:                        .getMBeanServer().isRegistered(lmb));
2230:            }
2231:
2232:            /**
2233:             * Tests uninstallComponent with the force option with a component that
2234:             * throws an exception in its cleanUp() method.
2235:             * @throws Exception if an unexpected error occurs.
2236:             */
2237:            public void testUninstallForceGoodCleanUpException()
2238:                    throws Exception {
2239:                // Install the engine.
2240:
2241:                mEngineContext
2242:                        .setComponentName(Constants.SE_NAME_BAD_BOOTSTRAP_UNINSTALL_CLEANUP);
2243:                mEngineContext.setIsInstall(true);
2244:                mCompFW.loadBootstrap(mEngineContext,
2245:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
2246:                        mEngineBootClassPath, null);
2247:                mCompFW.installComponent(mEngineContext);
2248:                Component comp = mCompReg
2249:                        .getComponent(Constants.SE_NAME_BAD_BOOTSTRAP_UNINSTALL_CLEANUP);
2250:                ObjectName lcmb = comp.getLifeCycleMBeanName();
2251:                ObjectName dmb = comp.getDeployerMBeanName();
2252:                ObjectName smb = comp.getStatisticsMBeanName();
2253:                ObjectName lmb = comp.getLoggerMBeanName();
2254:
2255:                // Try to uninstall. This should fail.
2256:
2257:                mEngineContext.setIsInstall(false);
2258:                mCompFW.loadBootstrap(mEngineContext,
2259:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
2260:                        mEngineBootClassPath, null);
2261:                try {
2262:                    mCompFW.uninstallComponent(mEngineContext, false);
2263:                    fail("Expected exception not received");
2264:                } catch (javax.jbi.JBIException ex) {
2265:                    // Verification
2266:                    assertTrue(
2267:                            "Incorrect exception received: " + ex.toString(),
2268:                            (-1 < ex.getMessage().indexOf("JBIFW1121")));
2269:                }
2270:
2271:                // Try to uninstall with force set. This should succeed.
2272:
2273:                mCompFW.uninstallComponent(mEngineContext, true);
2274:                assertTrue("Engine "
2275:                        + Constants.SE_NAME_BAD_BOOTSTRAP_UNINSTALL_CLEANUP
2276:                        + " is still registered", comp.isLoaded());
2277:
2278:                // Verify that all the MBeans were destroyed and unregistered
2279:                assertFalse("LifeCycleMBean not removed for engine", mContext
2280:                        .getMBeanServer().isRegistered(lcmb));
2281:                assertFalse("DeployerMBean not removed for engine", mContext
2282:                        .getMBeanServer().isRegistered(dmb));
2283:                assertFalse("StatisticsMBean not removed for engine", mContext
2284:                        .getMBeanServer().isRegistered(smb));
2285:                assertFalse("LoggerMBean not removed for engine", mContext
2286:                        .getMBeanServer().isRegistered(lmb));
2287:            }
2288:
2289:            /**
2290:             * Tests uninstallComponent with the force option with a component that
2291:             * throws an exception in both its onUninstall() and its cleanUp() methods.
2292:             * @throws Exception if an unexpected error occurs.
2293:             */
2294:            public void testUninstallForceGoodOnUninstallCleanUpException()
2295:                    throws Exception {
2296:                // Install the engine.
2297:
2298:                mEngineContext
2299:                        .setComponentName(Constants.SE_NAME_BAD_BOOTSTRAP_ONUNINSTALL_CLEANUP);
2300:                mEngineContext.setIsInstall(true);
2301:                mCompFW.loadBootstrap(mEngineContext,
2302:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
2303:                        mEngineBootClassPath, null);
2304:                mCompFW.installComponent(mEngineContext);
2305:                Component comp = mCompReg
2306:                        .getComponent(Constants.SE_NAME_BAD_BOOTSTRAP_ONUNINSTALL_CLEANUP);
2307:                ObjectName lcmb = comp.getLifeCycleMBeanName();
2308:                ObjectName dmb = comp.getDeployerMBeanName();
2309:                ObjectName smb = comp.getStatisticsMBeanName();
2310:                ObjectName lmb = comp.getLoggerMBeanName();
2311:
2312:                // Try to uninstall. This should fail.
2313:
2314:                mEngineContext.setIsInstall(false);
2315:                mCompFW.loadBootstrap(mEngineContext,
2316:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
2317:                        mEngineBootClassPath, null);
2318:                try {
2319:                    mCompFW.uninstallComponent(mEngineContext, false);
2320:                    fail("Expected exception not received");
2321:                } catch (javax.jbi.JBIException ex) {
2322:                    // Verification
2323:                    assertTrue(
2324:                            "Incorrect exception received: " + ex.toString(),
2325:                            (-1 < ex.getMessage().indexOf("JBIFW1117")));
2326:                }
2327:
2328:                // Try to uninstall with force set. This should succeed.
2329:
2330:                mCompFW.uninstallComponent(mEngineContext, true);
2331:                assertTrue("Engine "
2332:                        + Constants.SE_NAME_BAD_BOOTSTRAP_ONUNINSTALL_CLEANUP
2333:                        + " is still registered", comp.isLoaded());
2334:
2335:                // Verify that all the MBeans were destroyed and unregistered
2336:                assertFalse("LifeCycleMBean not removed for engine", mContext
2337:                        .getMBeanServer().isRegistered(lcmb));
2338:                assertFalse("DeployerMBean not removed for engine", mContext
2339:                        .getMBeanServer().isRegistered(dmb));
2340:                assertFalse("StatisticsMBean not removed for engine", mContext
2341:                        .getMBeanServer().isRegistered(smb));
2342:                assertFalse("LoggerMBean not removed for engine", mContext
2343:                        .getMBeanServer().isRegistered(lmb));
2344:            }
2345:
2346:            /**
2347:             * Tests uninstallSharedLibrary with a good result.
2348:             * @throws Exception if an unexpected error occurs.
2349:             */
2350:            public void testUninstallSharedLibraryGood() throws Exception {
2351:                mCompFW.installSharedLibrary(Constants.SL_1_NAME,
2352:                        Constants.SL_1_DESC, Constants.SL_1_ROOT, false,
2353:                        mSl1Elements);
2354:                mCompFW.uninstallSharedLibrary(Constants.SL_1_NAME);
2355:                assertFalse("Failure uninstalling Shared Library", mCompReg
2356:                        .isComponentRegistered(Constants.SL_1_NAME));
2357:            }
2358:
2359:            /**
2360:             * Tests uninstallSharedLibrary with dependent components that are
2361:             * already shutdown.
2362:             * @throws Exception if an unexpected error occurs.
2363:             */
2364:            public void testUninstallSharedLibraryGoodDependents()
2365:                    throws Exception {
2366:                mCompFW.installSharedLibrary(Constants.SL_1_NAME,
2367:                        Constants.SL_1_DESC, Constants.SL_1_ROOT, false,
2368:                        mSl1Elements);
2369:
2370:                mCompFW.installSharedLibrary(Constants.SL_2_NAME,
2371:                        Constants.SL_2_DESC, Constants.SL_2_ROOT, false,
2372:                        mSl2Elements);
2373:
2374:                ArrayList slList1 = new ArrayList();
2375:                slList1.add(Constants.SL_1_NAME);
2376:
2377:                ArrayList slList2 = new ArrayList();
2378:                slList2.add(Constants.SL_1_NAME);
2379:                slList2.add(Constants.SL_2_NAME);
2380:
2381:                mBindingContext.setIsInstall(true);
2382:                mCompFW.loadBootstrap(mBindingContext,
2383:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
2384:                        mBindingBootClassPath, slList1);
2385:                mCompFW.installComponent(mBindingContext);
2386:                mEngineContext.setIsInstall(true);
2387:                mCompFW.loadBootstrap(mEngineContext,
2388:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
2389:                        mEngineBootClassPath, slList2);
2390:                mCompFW.installComponent(mEngineContext);
2391:
2392:                try {
2393:                    mCompFW.uninstallSharedLibrary(Constants.SL_1_NAME);
2394:                    fail("Expected exception not received");
2395:                } catch (javax.jbi.JBIException ex) {
2396:                    // Verification
2397:                    assertFalse("Failure uninstalling Shared Library", mCompReg
2398:                            .isComponentRegistered(Constants.SL_1_NAME));
2399:                    assertTrue(
2400:                            "Incorrect exception received: " + ex.toString(),
2401:                            (-1 < ex.getMessage().indexOf("reinstalled")));
2402:                }
2403:
2404:                try {
2405:                    mCompFW.uninstallSharedLibrary(Constants.SL_2_NAME);
2406:                    fail("Expected exception not received");
2407:                } catch (javax.jbi.JBIException ex) {
2408:                    // Verification
2409:                    assertFalse("Failure uninstalling Shared Library", mCompReg
2410:                            .isComponentRegistered(Constants.SL_2_NAME));
2411:                    assertTrue(
2412:                            "Incorrect exception received: " + ex.toString(),
2413:                            (-1 < ex.getMessage().indexOf("reinstalled")));
2414:                }
2415:            }
2416:
2417:            /**
2418:             * Tests uninstallSharedLibrary with a nonexistent Shared Library.
2419:             * @throws Exception if an unexpected error occurs.
2420:             */
2421:            public void testUninstallSharedLibraryBadNotFound()
2422:                    throws Exception {
2423:                try {
2424:                    mCompFW.uninstallSharedLibrary(Constants.SL_1_NAME);
2425:                    fail("Expected exception not received");
2426:                } catch (javax.jbi.JBIException ex) {
2427:                    // Verification
2428:                    assertTrue(
2429:                            "Incorrect exception received: " + ex.toString(),
2430:                            (-1 < ex.getMessage().indexOf("No Shared Library")));
2431:                }
2432:            }
2433:
2434:            /**
2435:             * Tests uninstallSharedLibrary with dependent components that are
2436:             * either running or stopped. This will fail because all dependent
2437:             * components must be shutdown before the uninstall will proceed.
2438:             * @throws Exception if an unexpected error occurs.
2439:             */
2440:            public void testUninstallSharedLibraryBadDependents()
2441:                    throws Exception {
2442:                mCompFW.installSharedLibrary(Constants.SL_1_NAME,
2443:                        Constants.SL_1_DESC, Constants.SL_1_ROOT, false,
2444:                        mSl1Elements);
2445:
2446:                mCompFW.installSharedLibrary(Constants.SL_2_NAME,
2447:                        Constants.SL_2_DESC, Constants.SL_2_ROOT, false,
2448:                        mSl2Elements);
2449:
2450:                ArrayList slList1 = new ArrayList();
2451:                slList1.add(Constants.SL_1_NAME);
2452:
2453:                ArrayList slList2 = new ArrayList();
2454:                slList2.add(Constants.SL_1_NAME);
2455:                slList2.add(Constants.SL_2_NAME);
2456:
2457:                mBindingContext.setIsInstall(true);
2458:                mCompFW.loadBootstrap(mBindingContext,
2459:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
2460:                        mBindingBootClassPath, slList1);
2461:                mCompFW.installComponent(mBindingContext);
2462:                Component bc = mCompReg.getComponent(Constants.BC_NAME);
2463:                mCompFW.startComponent(bc);
2464:                mEngineContext.setIsInstall(true);
2465:                mCompFW.loadBootstrap(mEngineContext,
2466:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
2467:                        mEngineBootClassPath, slList2);
2468:                mCompFW.installComponent(mEngineContext);
2469:                Component se = mCompReg.getComponent(Constants.SE_NAME);
2470:                mCompFW.startComponent(se);
2471:                mCompFW.stopComponent(se);
2472:                try {
2473:                    mCompFW.uninstallSharedLibrary(Constants.SL_1_NAME);
2474:                    fail("Expected exception not received");
2475:                } catch (javax.jbi.JBIException ex) {
2476:                    // Verification
2477:                    assertTrue(
2478:                            "Incorrect exception received: " + ex.toString(),
2479:                            (-1 < ex.getMessage()
2480:                                    .indexOf("Unable to uninstall")));
2481:                }
2482:                try {
2483:                    mCompFW.uninstallSharedLibrary(Constants.SL_2_NAME);
2484:                    fail("Expected exception not received");
2485:                } catch (javax.jbi.JBIException ex) {
2486:                    // Verification
2487:                    assertTrue(
2488:                            "Incorrect exception received: " + ex.toString(),
2489:                            (-1 < ex.getMessage()
2490:                                    .indexOf("Unable to uninstall")));
2491:                }
2492:            }
2493:
2494:            /**
2495:             * Tests unloadBootstrap with a null component name. An exception is
2496:             * expected.
2497:             * @throws Exception if an unexpected error occurs.
2498:             */
2499:            public void testUnloadBootstrapBadNullComponentName()
2500:                    throws Exception {
2501:                try {
2502:                    mCompFW.unloadBootstrap(null);
2503:                    fail("Expected exception not received");
2504:                } catch (java.lang.IllegalArgumentException ex) {
2505:                    // Verification
2506:                    assertTrue(
2507:                            "Incorrect exception received: " + ex.toString(),
2508:                            (-1 < ex.getMessage().indexOf("componentName")));
2509:                }
2510:            }
2511:
2512:            /**
2513:             * Tests unloadBootstrap with an empty component name. An exception is
2514:             * expected.
2515:             * @throws Exception if an unexpected error occurs.
2516:             */
2517:            public void testUnloadBootstrapBadEmptyComponentName()
2518:                    throws Exception {
2519:                try {
2520:                    mCompFW.unloadBootstrap("");
2521:                    fail("Expected exception not received");
2522:                } catch (java.lang.IllegalArgumentException ex) {
2523:                    // Verification
2524:                    assertTrue(
2525:                            "Incorrect exception received: " + ex.toString(),
2526:                            (-1 < ex.getMessage().indexOf("componentName")));
2527:                }
2528:            }
2529:
2530:            /**
2531:             * Tests unloadBootstrap for a binding with good results.
2532:             * @throws Exception if an unexpected error occurs.
2533:             */
2534:            public void testUnloadBootstrapBindingGood() throws Exception {
2535:                ObjectName mbn;
2536:
2537:                // First test with no install action. In this case, the component
2538:                // should not be registered.
2539:
2540:                mBindingContext.setIsInstall(true);
2541:                mbn = mCompFW.loadBootstrap(mBindingContext,
2542:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
2543:                        mBindingBootClassPath, null);
2544:                mCompFW.unloadBootstrap(Constants.BC_NAME);
2545:                assertFalse("Binding " + Constants.BC_NAME
2546:                        + " should not be registered", mCompReg
2547:                        .isComponentRegistered(Constants.BC_NAME));
2548:                assertFalse("InstallerMBean should no longer be registered",
2549:                        mContext.getMBeanServer().isRegistered(mbn));
2550:
2551:                // Now test with an install action. In this case, the component
2552:                // should be registered and in SHUTDOWN state.
2553:
2554:                mBindingContext.setIsInstall(true);
2555:                mbn = mCompFW.loadBootstrap(mBindingContext,
2556:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
2557:                        mBindingBootClassPath, null);
2558:                mCompFW.installComponent(mBindingContext);
2559:                mCompFW.unloadBootstrap(Constants.BC_NAME);
2560:                assertTrue("Binding " + Constants.BC_NAME
2561:                        + " should be registered", mCompReg
2562:                        .isComponentRegistered(Constants.BC_NAME));
2563:                assertTrue("Binding " + Constants.BC_NAME
2564:                        + " should be in SHUTDOWN state", mCompReg
2565:                        .getComponent(Constants.BC_NAME).isInstalled());
2566:                assertFalse("InstallerMBean should no longer be registered",
2567:                        mContext.getMBeanServer().isRegistered(mbn));
2568:
2569:                // Now test with an uninstall action. In this case, the component
2570:                // should not be registered.
2571:
2572:                mBindingContext.setIsInstall(false);
2573:                mbn = mCompFW.loadBootstrap(mBindingContext,
2574:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
2575:                        mBindingBootClassPath, null);
2576:                mCompFW.uninstallComponent(mBindingContext, false);
2577:                mCompFW.unloadBootstrap(Constants.BC_NAME);
2578:                assertFalse("Binding " + Constants.BC_NAME
2579:                        + " is still registered", mCompReg
2580:                        .isComponentRegistered(Constants.BC_NAME));
2581:                assertFalse("InstallerMBean should no longer be registered",
2582:                        mContext.getMBeanServer().isRegistered(mbn));
2583:            }
2584:
2585:            /**
2586:             * Tests unloadBootstrap for an engine with good results.
2587:             * @throws Exception if an unexpected error occurs.
2588:             */
2589:            public void testUnloadBootstrapEngineGood() throws Exception {
2590:                ObjectName mbn;
2591:
2592:                // First test with no install action. In this case, the component
2593:                // should not be registered.
2594:
2595:                mEngineContext.setIsInstall(true);
2596:                mbn = mCompFW.loadBootstrap(mEngineContext,
2597:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
2598:                        mEngineBootClassPath, null);
2599:                mCompFW.unloadBootstrap(Constants.SE_NAME);
2600:                assertFalse("Engine " + Constants.SE_NAME
2601:                        + " should not be registered", mCompReg
2602:                        .isComponentRegistered(Constants.SE_NAME));
2603:                assertFalse("InstallerMBean should no longer be registered",
2604:                        mContext.getMBeanServer().isRegistered(mbn));
2605:
2606:                // Now test with an install action. In this case, the component
2607:                // should be registered and in SHUTDOWN state.
2608:
2609:                mEngineContext.setIsInstall(true);
2610:                mbn = mCompFW.loadBootstrap(mEngineContext,
2611:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
2612:                        mEngineBootClassPath, null);
2613:                mCompFW.installComponent(mEngineContext);
2614:                mCompFW.unloadBootstrap(Constants.SE_NAME);
2615:                assertTrue("Engine " + Constants.SE_NAME
2616:                        + " should be registered", mCompReg
2617:                        .isComponentRegistered(Constants.SE_NAME));
2618:                assertTrue("Engine " + Constants.SE_NAME
2619:                        + " should be in SHUTDOWN state", mCompReg
2620:                        .getComponent(Constants.SE_NAME).isInstalled());
2621:                assertFalse("InstallerMBean should no longer be registered",
2622:                        mContext.getMBeanServer().isRegistered(mbn));
2623:
2624:                // Now test with an uninstall action. In this case, the component
2625:                // should not be registered.
2626:
2627:                mEngineContext.setIsInstall(false);
2628:                mbn = mCompFW.loadBootstrap(mEngineContext,
2629:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
2630:                        mEngineBootClassPath, null);
2631:                mCompFW.uninstallComponent(mEngineContext, false);
2632:                mCompFW.unloadBootstrap(Constants.SE_NAME);
2633:                assertFalse("Engine " + Constants.SE_NAME
2634:                        + " is still registered", mCompReg
2635:                        .isComponentRegistered(Constants.SE_NAME));
2636:                assertFalse("InstallerMBean should no longer be registered",
2637:                        mContext.getMBeanServer().isRegistered(mbn));
2638:            }
2639:
2640:            /**
2641:             * Tests startComponent with a good result.
2642:             * @throws Exception if an unexpected error occurs.
2643:             */
2644:            public void testStartBindingGood() throws Exception {
2645:                mBindingContext.setIsInstall(true);
2646:                mCompFW.loadBootstrap(mBindingContext,
2647:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
2648:                        mBindingBootClassPath, null);
2649:                mCompFW.installComponent(mBindingContext);
2650:                Component binding = mCompReg.getComponent(Constants.BC_NAME);
2651:                mCompFW.startComponent(binding);
2652:                assertTrue("Failure starting BC", binding.isStarted());
2653:            }
2654:
2655:            /**
2656:             * Tests startComponent with a binding that is already started.
2657:             * @throws Exception if an unexpected error occurs.
2658:             */
2659:            public void testStartBindingAlreadyStarted() throws Exception {
2660:                mBindingContext.setIsInstall(true);
2661:                mCompFW.loadBootstrap(mBindingContext,
2662:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
2663:                        mBindingBootClassPath, null);
2664:                mCompFW.installComponent(mBindingContext);
2665:                Component comp = mCompReg.getComponent(Constants.BC_NAME);
2666:                mCompFW.startComponent(comp);
2667:
2668:                // repeated life cycle operations should be a NOP
2669:                mCompFW.startComponent(comp);
2670:            }
2671:
2672:            /**
2673:             * Tests startComponent with a required Shared Library missing. An
2674:             * exception is expected.
2675:             * @throws Exception if an unexpected error occurs.
2676:             */
2677:            public void testStartBindingBadMissingSharedLibrary()
2678:                    throws Exception {
2679:                // Install the Shared Libraries required by the binding.
2680:
2681:                mCompFW.installSharedLibrary(Constants.SL_1_NAME,
2682:                        Constants.SL_1_DESC, Constants.SL_1_ROOT, false,
2683:                        mSl1Elements);
2684:                mCompFW.installSharedLibrary(Constants.SL_2_NAME,
2685:                        Constants.SL_2_DESC, Constants.SL_2_ROOT, false,
2686:                        mSl2Elements);
2687:
2688:                // Create the list of Shared Library IDs required by the binding.
2689:
2690:                ArrayList slList = new ArrayList();
2691:                slList.add(Constants.SL_1_NAME);
2692:                slList.add(Constants.SL_2_NAME);
2693:
2694:                // Load, install, start, and shutdown the binding.
2695:
2696:                mBindingContext.setIsInstall(true);
2697:                mCompFW.loadBootstrap(mBindingContext,
2698:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
2699:                        mBindingBootClassPath, slList);
2700:                mCompFW.installComponent(mBindingContext);
2701:                Component comp = mCompReg.getComponent(Constants.BC_NAME);
2702:                mCompFW.startComponent(comp);
2703:                mCompFW.shutdownComponent(comp);
2704:
2705:                // Uninstall one of the Shared Libraries.
2706:
2707:                try {
2708:                    mCompFW.uninstallSharedLibrary(Constants.SL_1_NAME);
2709:                } catch (javax.jbi.JBIException ex) {
2710:                    assertTrue(
2711:                            "Incorrect exception received: " + ex.toString(),
2712:                            (-1 < ex.getMessage().indexOf("reinstalled")));
2713:                }
2714:
2715:                // Attempt to start the binding. This should fail.
2716:                try {
2717:                    mCompFW.startComponent(comp);
2718:                } catch (javax.jbi.JBIException ex) {
2719:                    // Verification
2720:                    assertTrue(
2721:                            "Incorrect exception received: " + ex.toString(),
2722:                            (-1 < ex.getMessage().indexOf(
2723:                                    "must be installed first")));
2724:                    assertTrue(
2725:                            "Incorrect exception received: " + ex.toString(),
2726:                            (-1 < ex.getMessage().indexOf(Constants.SL_1_NAME)));
2727:                    assertTrue(
2728:                            "Incorrect exception received: " + ex.toString(),
2729:                            (-1 == ex.getMessage().indexOf(Constants.SL_2_NAME)));
2730:                }
2731:
2732:                // Uninstall the other Shared Library.
2733:
2734:                try {
2735:                    mCompFW.uninstallSharedLibrary(Constants.SL_2_NAME);
2736:                } catch (javax.jbi.JBIException ex) {
2737:                    assertTrue(
2738:                            "Incorrect exception received: " + ex.toString(),
2739:                            (-1 < ex.getMessage().indexOf("reinstalled")));
2740:                }
2741:
2742:                // Attempt to start the binding. This should fail.
2743:                try {
2744:                    mCompFW.startComponent(comp);
2745:                } catch (javax.jbi.JBIException ex) {
2746:                    // Verification
2747:                    assertTrue(
2748:                            "Incorrect exception received: " + ex.toString(),
2749:                            (-1 < ex.getMessage().indexOf(
2750:                                    "must be installed first")));
2751:                    assertTrue(
2752:                            "Incorrect exception received: " + ex.toString(),
2753:                            (-1 < ex.getMessage().indexOf(Constants.SL_1_NAME)));
2754:                    assertTrue(
2755:                            "Incorrect exception received: " + ex.toString(),
2756:                            (-1 < ex.getMessage().indexOf(Constants.SL_2_NAME)));
2757:                }
2758:
2759:            }
2760:
2761:            /**
2762:             * Tests startComponent with a binding whose init() method always throws
2763:             * an exception.
2764:             * @throws Exception if an unexpected error occurs.
2765:             */
2766:            public void testStartBindingBadInitException() throws Exception {
2767:                mBindingContext.setComponentName(Constants.BC_NAME_BAD_INIT);
2768:                mBindingContext.setIsInstall(true);
2769:                mCompFW.loadBootstrap(mBindingContext,
2770:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
2771:                        mBindingBootClassPath, null);
2772:
2773:                // The install will throw an exception due to the init() method
2774:                // throwing an exception. Catch it here and ignore it (if it's
2775:                // what we expect). The install still succeeded; calling init()
2776:                // happens after the installation has effectively finished.
2777:                try {
2778:                    mCompFW.installComponent(mBindingContext);
2779:                } catch (javax.jbi.JBIException ex) {
2780:                    assertTrue(
2781:                            "Incorrect exception received: " + ex.toString(),
2782:                            (-1 < ex.getMessage().indexOf(
2783:                                    "cannot be initialized")));
2784:                }
2785:
2786:                // The init() method of this BC always throws an exception.
2787:
2788:                Component comp = mCompReg
2789:                        .getComponent(Constants.BC_NAME_BAD_INIT);
2790:                try {
2791:                    mCompFW.startComponent(comp);
2792:                    fail("Expected exception not received");
2793:                } catch (javax.jbi.JBIException ex) {
2794:                    // Verification
2795:                    assertTrue(
2796:                            "Incorrect exception received: " + ex.toString(),
2797:                            (-1 < ex.getMessage().indexOf(
2798:                                    "cannot be initialized")));
2799:                }
2800:            }
2801:
2802:            /**
2803:             * Tests startComponent with a binding whose start() method always throws
2804:             * an exception.
2805:             * @throws Exception if an unexpected error occurs.
2806:             */
2807:            public void testStartBindingBadStartException() throws Exception {
2808:                mBindingContext.setComponentName(Constants.BC_NAME_BAD_START);
2809:                mBindingContext.setIsInstall(true);
2810:                mCompFW.loadBootstrap(mBindingContext,
2811:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
2812:                        mBindingBootClassPath, null);
2813:                mCompFW.installComponent(mBindingContext);
2814:                Component comp = mCompReg
2815:                        .getComponent(Constants.BC_NAME_BAD_START);
2816:
2817:                // The start() method of this BC always throws an exception.
2818:
2819:                try {
2820:                    mCompFW.startComponent(comp);
2821:                    fail("Expected exception not received");
2822:                } catch (javax.jbi.JBIException ex) {
2823:                    // Verification
2824:                    assertTrue(
2825:                            "Incorrect exception received: " + ex.toString(),
2826:                            (-1 < ex.getMessage().indexOf("cannot be started")));
2827:                }
2828:            }
2829:
2830:            /**
2831:             * Tests startComponent with a good result.
2832:             * @throws Exception if an unexpected error occurs.
2833:             */
2834:            public void testStartEngineGood() throws Exception {
2835:                mEngineContext.setIsInstall(true);
2836:                mCompFW.loadBootstrap(mEngineContext,
2837:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
2838:                        mEngineBootClassPath, null);
2839:                mCompFW.installComponent(mEngineContext);
2840:                Component engine = mCompReg.getComponent(Constants.SE_NAME);
2841:                mCompFW.startComponent(engine);
2842:                assertTrue("Failure starting SE", engine.isStarted());
2843:            }
2844:
2845:            /**
2846:             * Tests startComponent with a engine that is already started.
2847:             * @throws Exception if an unexpected error occurs.
2848:             */
2849:            public void testStartEngineAlreadyStarted() throws Exception {
2850:                mEngineContext.setIsInstall(true);
2851:                mCompFW.loadBootstrap(mEngineContext,
2852:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
2853:                        mEngineBootClassPath, null);
2854:                mCompFW.installComponent(mEngineContext);
2855:                Component comp = mCompReg.getComponent(Constants.SE_NAME);
2856:                mCompFW.startComponent(comp);
2857:
2858:                // repeated life cycle operations should be a NOP
2859:                mCompFW.startComponent(comp);
2860:            }
2861:
2862:            /**
2863:             * Tests startComponent with a required Shared Library missing. An
2864:             * exception is expected.
2865:             * @throws Exception if an unexpected error occurs.
2866:             */
2867:            public void testStartEngineBadMissingSharedLibrary()
2868:                    throws Exception {
2869:                // Install the Shared Libraries required by the engine.
2870:
2871:                mCompFW.installSharedLibrary(Constants.SL_1_NAME,
2872:                        Constants.SL_1_DESC, Constants.SL_1_ROOT, false,
2873:                        mSl1Elements);
2874:                mCompFW.installSharedLibrary(Constants.SL_2_NAME,
2875:                        Constants.SL_2_DESC, Constants.SL_2_ROOT, false,
2876:                        mSl2Elements);
2877:
2878:                // Create the list of Shared Library IDs required by the engine.
2879:
2880:                ArrayList slList = new ArrayList();
2881:                slList.add(Constants.SL_1_NAME);
2882:                slList.add(Constants.SL_2_NAME);
2883:
2884:                // Load, install, start, and shutdown the engine.
2885:
2886:                mEngineContext.setIsInstall(true);
2887:                mCompFW.loadBootstrap(mEngineContext,
2888:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
2889:                        mEngineBootClassPath, slList);
2890:                mCompFW.installComponent(mEngineContext);
2891:                Component comp = mCompReg.getComponent(Constants.SE_NAME);
2892:                mCompFW.startComponent(comp);
2893:                mCompFW.shutdownComponent(comp);
2894:
2895:                // Uninstall one of the Shared Libraries.
2896:
2897:                try {
2898:                    mCompFW.uninstallSharedLibrary(Constants.SL_1_NAME);
2899:                } catch (javax.jbi.JBIException ex) {
2900:                    assertTrue(
2901:                            "Incorrect exception received: " + ex.toString(),
2902:                            (-1 < ex.getMessage().indexOf("reinstalled")));
2903:                }
2904:
2905:                // Attempt to start the engine. This should fail.
2906:                try {
2907:                    mCompFW.startComponent(comp);
2908:                } catch (javax.jbi.JBIException ex) {
2909:                    // Verification
2910:                    assertTrue(
2911:                            "Incorrect exception received: " + ex.toString(),
2912:                            (-1 < ex.getMessage().indexOf(
2913:                                    "must be installed first")));
2914:                    assertTrue(
2915:                            "Incorrect exception received: " + ex.toString(),
2916:                            (-1 < ex.getMessage().indexOf(Constants.SL_1_NAME)));
2917:                    assertTrue(
2918:                            "Incorrect exception received: " + ex.toString(),
2919:                            (-1 == ex.getMessage().indexOf(Constants.SL_2_NAME)));
2920:                }
2921:
2922:                // Uninstall the other Shared Library.
2923:
2924:                try {
2925:                    mCompFW.uninstallSharedLibrary(Constants.SL_2_NAME);
2926:                } catch (javax.jbi.JBIException ex) {
2927:                    assertTrue(
2928:                            "Incorrect exception received: " + ex.toString(),
2929:                            (-1 < ex.getMessage().indexOf("reinstalled")));
2930:                }
2931:
2932:                // Attempt to start the engine. This should fail.
2933:                try {
2934:                    mCompFW.startComponent(comp);
2935:                } catch (javax.jbi.JBIException ex) {
2936:                    // Verification
2937:                    assertTrue(
2938:                            "Incorrect exception received: " + ex.toString(),
2939:                            (-1 < ex.getMessage().indexOf(
2940:                                    "must be installed first")));
2941:                    assertTrue(
2942:                            "Incorrect exception received: " + ex.toString(),
2943:                            (-1 < ex.getMessage().indexOf(Constants.SL_1_NAME)));
2944:                    assertTrue(
2945:                            "Incorrect exception received: " + ex.toString(),
2946:                            (-1 < ex.getMessage().indexOf(Constants.SL_2_NAME)));
2947:                }
2948:
2949:            }
2950:
2951:            /**
2952:             * Tests startComponent with an engine whose init() method always throws
2953:             * an exception.
2954:             * @throws Exception if an unexpected error occurs.
2955:             */
2956:            public void testStartEngineBadInitException() throws Exception {
2957:                mEngineContext.setComponentName(Constants.SE_NAME_BAD_INIT);
2958:                mEngineContext.setIsInstall(true);
2959:                mCompFW.loadBootstrap(mEngineContext,
2960:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
2961:                        mEngineBootClassPath, null);
2962:
2963:                // The install will throw an exception due to the init() method
2964:                // throwing an exception. Catch it here and ignore it (if it's
2965:                // what we expect). The install still succeeded; calling init()
2966:                // happens after the installation has effectively finished.
2967:                try {
2968:                    mCompFW.installComponent(mEngineContext);
2969:                } catch (javax.jbi.JBIException ex) {
2970:                    assertTrue(
2971:                            "Incorrect exception received: " + ex.toString(),
2972:                            (-1 < ex.getMessage().indexOf(
2973:                                    "cannot be initialized")));
2974:                }
2975:
2976:                // The start() method of this SE always throws an exception.
2977:
2978:                Component comp = mCompReg
2979:                        .getComponent(Constants.SE_NAME_BAD_INIT);
2980:                try {
2981:                    mCompFW.startComponent(comp);
2982:                    fail("Expected exception not received");
2983:                } catch (javax.jbi.JBIException ex) {
2984:                    // Verification
2985:                    assertTrue(
2986:                            "Incorrect exception received: " + ex.toString(),
2987:                            (-1 < ex.getMessage().indexOf(
2988:                                    "cannot be initialized")));
2989:                }
2990:            }
2991:
2992:            /**
2993:             * Tests startComponent with an engine whose start() method always throws
2994:             * an exception.
2995:             * @throws Exception if an unexpected error occurs.
2996:             */
2997:            public void testStartEngineBadStartException() throws Exception {
2998:                mEngineContext.setComponentName(Constants.SE_NAME_BAD_START);
2999:                mEngineContext.setIsInstall(true);
3000:                mCompFW.loadBootstrap(mEngineContext,
3001:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
3002:                        mEngineBootClassPath, null);
3003:                mCompFW.installComponent(mEngineContext);
3004:                Component comp = mCompReg
3005:                        .getComponent(Constants.SE_NAME_BAD_START);
3006:
3007:                // The start() method of this SE always throws an exception.
3008:
3009:                try {
3010:                    mCompFW.startComponent(comp);
3011:                    fail("Expected exception not received");
3012:                } catch (javax.jbi.JBIException ex) {
3013:                    // Verification
3014:                    assertTrue(
3015:                            "Incorrect exception received: " + ex.toString(),
3016:                            (-1 < ex.getMessage().indexOf("cannot be started")));
3017:                }
3018:            }
3019:
3020:            /**
3021:             * Tests stopComponent with a good result.
3022:             * @throws Exception if an unexpected error occurs.
3023:             */
3024:            public void testStopBindingGood() throws Exception {
3025:                mBindingContext.setIsInstall(true);
3026:                mCompFW.loadBootstrap(mBindingContext,
3027:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
3028:                        mBindingBootClassPath, null);
3029:                mCompFW.installComponent(mBindingContext);
3030:                Component binding = mCompReg.getComponent(Constants.BC_NAME);
3031:                mCompFW.startComponent(binding);
3032:                mCompFW.stopComponent(binding);
3033:                assertTrue("Failure stopping Binding Component", binding
3034:                        .isInitialized());
3035:            }
3036:
3037:            /**
3038:             * Tests stopComponent with a binding that is not active. An exception
3039:             * is expected.
3040:             * @throws Exception if an unexpected error occurs.
3041:             */
3042:            public void testStopBindingBadNotActive() throws Exception {
3043:                mBindingContext.setIsInstall(true);
3044:                mCompFW.loadBootstrap(mBindingContext,
3045:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
3046:                        mBindingBootClassPath, null);
3047:                mCompFW.installComponent(mBindingContext);
3048:                Component binding = mCompReg.getComponent(Constants.BC_NAME);
3049:                try {
3050:                    mCompFW.stopComponent(binding);
3051:                    fail("Expected exception not received");
3052:                } catch (javax.jbi.JBIException ex) {
3053:                    // Verification
3054:                    assertTrue(
3055:                            "Incorrect exception received: " + ex.toString(),
3056:                            (-1 < ex.getMessage().indexOf("not active")));
3057:                }
3058:            }
3059:
3060:            /**
3061:             * Tests stopComponent with a binding that is already stopped.
3062:             * @throws Exception if an unexpected error occurs.
3063:             */
3064:            public void testStopBindingAlreadyStopped() throws Exception {
3065:                mBindingContext.setIsInstall(true);
3066:                mCompFW.loadBootstrap(mBindingContext,
3067:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
3068:                        mBindingBootClassPath, null);
3069:                mCompFW.installComponent(mBindingContext);
3070:                Component binding = mCompReg.getComponent(Constants.BC_NAME);
3071:                mCompFW.startComponent(binding);
3072:                mCompFW.stopComponent(binding);
3073:
3074:                // repeated life cycle operations should be a NOP
3075:                mCompFW.stopComponent(binding);
3076:            }
3077:
3078:            /**
3079:             * Tests stopComponent with a binding whose stop() method always throws
3080:             * an exception.
3081:             * @throws Exception if an unexpected error occurs.
3082:             */
3083:            public void testStopBindingBadStopException() throws Exception {
3084:                mBindingContext.setComponentName(Constants.BC_NAME_BAD_STOP);
3085:                mBindingContext.setIsInstall(true);
3086:                mCompFW.loadBootstrap(mBindingContext,
3087:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
3088:                        mBindingBootClassPath, null);
3089:                mCompFW.installComponent(mBindingContext);
3090:                Component binding = mCompReg
3091:                        .getComponent(Constants.BC_NAME_BAD_STOP);
3092:                mCompFW.startComponent(binding);
3093:
3094:                // The stop() method of this BC always throws an exception.
3095:
3096:                try {
3097:                    mCompFW.stopComponent(binding);
3098:                    fail("Expected exception not received");
3099:                } catch (javax.jbi.JBIException ex) {
3100:                    // Verification
3101:                    assertTrue(
3102:                            "Incorrect exception received: " + ex.toString(),
3103:                            (-1 < ex.getMessage().indexOf("cannot be stopped")));
3104:                }
3105:            }
3106:
3107:            /**
3108:             * Tests stopComponent with a good result.
3109:             * @throws Exception if an unexpected error occurs.
3110:             */
3111:            public void testStopEngineGood() throws Exception {
3112:                mEngineContext.setIsInstall(true);
3113:                mCompFW.loadBootstrap(mEngineContext,
3114:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
3115:                        mEngineBootClassPath, null);
3116:                mCompFW.installComponent(mEngineContext);
3117:                Component engine = mCompReg.getComponent(Constants.SE_NAME);
3118:                mCompFW.startComponent(engine);
3119:                mCompFW.stopComponent(engine);
3120:                assertTrue("Failure stopping Service Engine", engine
3121:                        .isInitialized());
3122:            }
3123:
3124:            /**
3125:             * Tests stopComponent with an engine that is not active. An exception
3126:             * is expected.
3127:             * @throws Exception if an unexpected error occurs.
3128:             */
3129:            public void testStopEngineBadNotActive() throws Exception {
3130:                mEngineContext.setIsInstall(true);
3131:                mCompFW.loadBootstrap(mEngineContext,
3132:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
3133:                        mEngineBootClassPath, null);
3134:                mCompFW.installComponent(mEngineContext);
3135:                Component engine = mCompReg.getComponent(Constants.SE_NAME);
3136:                try {
3137:                    mCompFW.stopComponent(engine);
3138:                    fail("Expected exception not received");
3139:                } catch (javax.jbi.JBIException ex) {
3140:                    // Verification
3141:                    assertTrue(
3142:                            "Incorrect exception received: " + ex.toString(),
3143:                            (-1 < ex.getMessage().indexOf("not active")));
3144:                }
3145:            }
3146:
3147:            /**
3148:             * Tests stopComponent with an engine that is already stopped.
3149:             * @throws Exception if an unexpected error occurs.
3150:             */
3151:            public void testStopEngineAlreadyStopped() throws Exception {
3152:                mEngineContext.setIsInstall(true);
3153:                mCompFW.loadBootstrap(mEngineContext,
3154:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
3155:                        mEngineBootClassPath, null);
3156:                mCompFW.installComponent(mEngineContext);
3157:                Component engine = mCompReg.getComponent(Constants.SE_NAME);
3158:                mCompFW.startComponent(engine);
3159:                mCompFW.stopComponent(engine);
3160:
3161:                // repeated life cycle operations should be a NOP
3162:                mCompFW.stopComponent(engine);
3163:            }
3164:
3165:            /**
3166:             * Tests stopComponent with an engine whose stop() method always throws
3167:             * an exception.
3168:             * @throws Exception if an unexpected error occurs.
3169:             */
3170:            public void testStopEngineBadStopException() throws Exception {
3171:                mEngineContext.setComponentName(Constants.SE_NAME_BAD_STOP);
3172:                mEngineContext.setIsInstall(true);
3173:                mCompFW.loadBootstrap(mEngineContext,
3174:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
3175:                        mEngineBootClassPath, null);
3176:                mCompFW.installComponent(mEngineContext);
3177:                Component engine = mCompReg
3178:                        .getComponent(Constants.SE_NAME_BAD_STOP);
3179:                mCompFW.startComponent(engine);
3180:
3181:                // The stop() method of this SE always throws an exception.
3182:
3183:                try {
3184:                    mCompFW.stopComponent(engine);
3185:                    fail("Expected exception not received");
3186:                } catch (javax.jbi.JBIException ex) {
3187:                    // Verification
3188:                    assertTrue(
3189:                            "Incorrect exception received: " + ex.toString(),
3190:                            (-1 < ex.getMessage().indexOf("cannot be stopped")));
3191:                }
3192:            }
3193:
3194:            /**
3195:             * Tests shutdownComponent with a good result.
3196:             * @throws Exception if an unexpected error occurs.
3197:             */
3198:            public void testShutdownBindingGood() throws Exception {
3199:                mBindingContext.setIsInstall(true);
3200:                mCompFW.loadBootstrap(mBindingContext,
3201:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
3202:                        mBindingBootClassPath, null);
3203:                mCompFW.installComponent(mBindingContext);
3204:                Component binding = mCompReg.getComponent(Constants.BC_NAME);
3205:                mCompFW.startComponent(binding);
3206:                mCompFW.stopComponent(binding);
3207:                mCompFW.shutdownComponent(binding);
3208:                assertFalse("Failure shutting down Binding Component", binding
3209:                        .isInitialized());
3210:            }
3211:
3212:            /**
3213:             * Tests shutdownComponent with a binding that is not active.
3214:             * @throws Exception if an unexpected error occurs.
3215:             */
3216:            public void testShutdownBindingNotActive() throws Exception {
3217:                mBindingContext.setIsInstall(true);
3218:                mCompFW.loadBootstrap(mBindingContext,
3219:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
3220:                        mBindingBootClassPath, null);
3221:                mCompFW.installComponent(mBindingContext);
3222:                Component binding = mCompReg.getComponent(Constants.BC_NAME);
3223:                mCompFW.startComponent(binding);
3224:                mCompFW.shutdownComponent(binding);
3225:
3226:                // repeated life cycle operations should be a NOP
3227:                mCompFW.shutdownComponent(binding);
3228:            }
3229:
3230:            /**
3231:             * Tests shutdownComponent with a binding whose stop() method always
3232:             * throws an exception.
3233:             * @throws Exception if an unexpected error occurs.
3234:             */
3235:            public void testShutdownBindingBadStopException() throws Exception {
3236:                mBindingContext.setComponentName(Constants.BC_NAME_BAD_STOP);
3237:                mBindingContext.setIsInstall(true);
3238:                mCompFW.loadBootstrap(mBindingContext,
3239:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
3240:                        mBindingBootClassPath, null);
3241:                mCompFW.installComponent(mBindingContext);
3242:                Component binding = mCompReg
3243:                        .getComponent(Constants.BC_NAME_BAD_STOP);
3244:                mCompFW.startComponent(binding);
3245:
3246:                // The stop() method of this BC always throws an exception.
3247:
3248:                try {
3249:                    mCompFW.shutdownComponent(binding);
3250:                    fail("Expected exception not received");
3251:                } catch (javax.jbi.JBIException ex) {
3252:                    // Verification
3253:                    assertTrue(
3254:                            "Incorrect exception received: " + ex.toString(),
3255:                            (-1 < ex.getMessage().indexOf("stop() method")));
3256:                }
3257:            }
3258:
3259:            /**
3260:             * Tests shutdownComponent with a binding whose shutDown() method always
3261:             * throws an exception.
3262:             * @throws Exception if an unexpected error occurs.
3263:             */
3264:            public void testShutdownBindingBadShutdownException()
3265:                    throws Exception {
3266:                mBindingContext
3267:                        .setComponentName(Constants.BC_NAME_BAD_SHUTDOWN);
3268:                mBindingContext.setIsInstall(true);
3269:                mCompFW.loadBootstrap(mBindingContext,
3270:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
3271:                        mBindingBootClassPath, null);
3272:                mCompFW.installComponent(mBindingContext);
3273:                Component binding = mCompReg
3274:                        .getComponent(Constants.BC_NAME_BAD_SHUTDOWN);
3275:                mCompFW.startComponent(binding);
3276:
3277:                // The shutDown() method of this BC always throws an exception.
3278:
3279:                try {
3280:                    mCompFW.shutdownComponent(binding);
3281:                    fail("Expected exception not received");
3282:                } catch (javax.jbi.JBIException ex) {
3283:                    // Verification
3284:                    assertTrue(
3285:                            "Incorrect exception received: " + ex.toString(),
3286:                            (-1 < ex.getMessage().indexOf("shutDown() method")));
3287:                }
3288:            }
3289:
3290:            /**
3291:             * Tests shutdownComponent force=true with a binding whose stop() method
3292:             * always throws an exception.
3293:             * @throws Exception if an unexpected error occurs.
3294:             */
3295:            public void testShutdownBindingForceStopException()
3296:                    throws Exception {
3297:                mBindingContext.setComponentName(Constants.BC_NAME_BAD_STOP);
3298:                mBindingContext.setIsInstall(true);
3299:                mCompFW.loadBootstrap(mBindingContext,
3300:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
3301:                        mBindingBootClassPath, null);
3302:                mCompFW.installComponent(mBindingContext);
3303:                Component binding = mCompReg
3304:                        .getComponent(Constants.BC_NAME_BAD_STOP);
3305:                mCompFW.startComponent(binding);
3306:
3307:                // The stop() method of this BC always throws an exception.
3308:
3309:                mCompFW.shutdownComponent(binding, true);
3310:                assertFalse("Failure on forced shutdown of Binding Component",
3311:                        binding.isInitialized());
3312:            }
3313:
3314:            /**
3315:             * Tests shutdownComponent force=true with a binding whose shutDown()
3316:             * method always throws an exception.
3317:             * @throws Exception if an unexpected error occurs.
3318:             */
3319:            public void testShutdownBindingForceShutdownException()
3320:                    throws Exception {
3321:                mBindingContext
3322:                        .setComponentName(Constants.BC_NAME_BAD_SHUTDOWN);
3323:                mBindingContext.setIsInstall(true);
3324:                mCompFW.loadBootstrap(mBindingContext,
3325:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
3326:                        mBindingBootClassPath, null);
3327:                mCompFW.installComponent(mBindingContext);
3328:                Component binding = mCompReg
3329:                        .getComponent(Constants.BC_NAME_BAD_SHUTDOWN);
3330:                mCompFW.startComponent(binding);
3331:
3332:                // The shutDown() method of this BC always throws an exception.
3333:
3334:                mCompFW.shutdownComponent(binding, true);
3335:                assertFalse("Failure on forced shutdown of Binding Component",
3336:                        binding.isInitialized());
3337:            }
3338:
3339:            /**
3340:             * Tests shutdownComponent with a good result.
3341:             * @throws Exception if an unexpected error occurs.
3342:             */
3343:            public void testShutdownEngineGood() throws Exception {
3344:                mEngineContext.setIsInstall(true);
3345:                mCompFW.loadBootstrap(mEngineContext,
3346:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
3347:                        mEngineBootClassPath, null);
3348:                mCompFW.installComponent(mEngineContext);
3349:                Component engine = mCompReg.getComponent(Constants.SE_NAME);
3350:                mCompFW.startComponent(engine);
3351:                mCompFW.stopComponent(engine);
3352:                mCompFW.shutdownComponent(engine);
3353:                assertFalse("Failure shutting down Service Engine", engine
3354:                        .isInitialized());
3355:            }
3356:
3357:            /**
3358:             * Tests shutdownComponent with an engine that is not active.
3359:             * @throws Exception if an unexpected error occurs.
3360:             */
3361:            public void testShutdownEngineAlreadyShutdown() throws Exception {
3362:                mEngineContext.setIsInstall(true);
3363:                mCompFW.loadBootstrap(mEngineContext,
3364:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
3365:                        mEngineBootClassPath, null);
3366:                mCompFW.installComponent(mEngineContext);
3367:                Component engine = mCompReg.getComponent(Constants.SE_NAME);
3368:                mCompFW.startComponent(engine);
3369:                mCompFW.shutdownComponent(engine);
3370:
3371:                // repeated life cycle operations should be a NOP
3372:                mCompFW.shutdownComponent(engine);
3373:            }
3374:
3375:            /**
3376:             * Tests shutdownComponent with an engine whose stop() method always throws
3377:             * an exception.
3378:             * @throws Exception if an unexpected error occurs.
3379:             */
3380:            public void testShutdownEngineBadStopException() throws Exception {
3381:                mEngineContext.setComponentName(Constants.SE_NAME_BAD_STOP);
3382:                mEngineContext.setIsInstall(true);
3383:                mCompFW.loadBootstrap(mEngineContext,
3384:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
3385:                        mEngineBootClassPath, null);
3386:                mCompFW.installComponent(mEngineContext);
3387:                Component engine = mCompReg
3388:                        .getComponent(Constants.SE_NAME_BAD_STOP);
3389:                mCompFW.startComponent(engine);
3390:
3391:                // The stop() method of this SE always throws an exception.
3392:
3393:                try {
3394:                    mCompFW.shutdownComponent(engine);
3395:                    fail("Expected exception not received");
3396:                } catch (javax.jbi.JBIException ex) {
3397:                    // Verification
3398:                    assertTrue(
3399:                            "Incorrect exception received: " + ex.toString(),
3400:                            (-1 < ex.getMessage().indexOf("stop() method")));
3401:                }
3402:            }
3403:
3404:            /**
3405:             * Tests shutdownComponent with an engine whose shutDown() method always
3406:             * throws an exception.
3407:             * @throws Exception if an unexpected error occurs.
3408:             */
3409:            public void testShutdownEngineBadShutdownException()
3410:                    throws Exception {
3411:                mEngineContext.setComponentName(Constants.SE_NAME_BAD_SHUTDOWN);
3412:                mEngineContext.setIsInstall(true);
3413:                mCompFW.loadBootstrap(mEngineContext,
3414:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
3415:                        mEngineBootClassPath, null);
3416:                mCompFW.installComponent(mEngineContext);
3417:                Component engine = mCompReg
3418:                        .getComponent(Constants.SE_NAME_BAD_SHUTDOWN);
3419:                mCompFW.startComponent(engine);
3420:
3421:                // The shutDown() method of this SE always throws an exception.
3422:
3423:                try {
3424:                    mCompFW.shutdownComponent(engine);
3425:                    fail("Expected exception not received");
3426:                } catch (javax.jbi.JBIException ex) {
3427:                    // Verification
3428:                    assertTrue(
3429:                            "Incorrect exception received: " + ex.toString(),
3430:                            (-1 < ex.getMessage().indexOf("shutDown() method")));
3431:                }
3432:            }
3433:
3434:            /**
3435:             * Tests shutdownComponent force=true with an engine whose stop() method
3436:             * always throws an exception.
3437:             * @throws Exception if an unexpected error occurs.
3438:             */
3439:            public void testShutdownEngineForceStopException() throws Exception {
3440:                mEngineContext.setComponentName(Constants.SE_NAME_BAD_STOP);
3441:                mEngineContext.setIsInstall(true);
3442:                mCompFW.loadBootstrap(mEngineContext,
3443:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
3444:                        mEngineBootClassPath, null);
3445:                mCompFW.installComponent(mEngineContext);
3446:                Component engine = mCompReg
3447:                        .getComponent(Constants.SE_NAME_BAD_STOP);
3448:                mCompFW.startComponent(engine);
3449:
3450:                // The stop() method of this SE always throws an exception.
3451:
3452:                mCompFW.shutdownComponent(engine, true);
3453:                assertFalse("Failure on forced shutdown of Service Engine",
3454:                        engine.isInitialized());
3455:            }
3456:
3457:            /**
3458:             * Tests shutdownComponent force=true with an engine whose shutDown()
3459:             * method always throws an exception.
3460:             * @throws Exception if an unexpected error occurs.
3461:             */
3462:            public void testShutdownEngineForceShutdownException()
3463:                    throws Exception {
3464:                mEngineContext.setComponentName(Constants.SE_NAME_BAD_SHUTDOWN);
3465:                mEngineContext.setIsInstall(true);
3466:                mCompFW.loadBootstrap(mEngineContext,
3467:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
3468:                        mEngineBootClassPath, null);
3469:                mCompFW.installComponent(mEngineContext);
3470:                Component engine = mCompReg
3471:                        .getComponent(Constants.SE_NAME_BAD_SHUTDOWN);
3472:                mCompFW.startComponent(engine);
3473:
3474:                // The shutDown() method of this SE always throws an exception.
3475:
3476:                mCompFW.shutdownComponent(engine, true);
3477:                assertFalse("Failure on forced shutdown of Service Engine",
3478:                        engine.isInitialized());
3479:            }
3480:
3481:            /**
3482:             * Tests startService with a BC that times out in its init() method and
3483:             * an SE that times out on its start() method.
3484:             * @throws Exception if an unexpected error occurs.
3485:             */
3486:            public void testStartServiceTimeout() throws Exception {
3487:                // Install a BC that times out in its init() method
3488:
3489:                mBindingContext = new ComponentInstallationContext(
3490:                        Constants.BC_NAME_TIMEOUT_INIT,
3491:                        ComponentInstallationContext.BINDING,
3492:                        Constants.BC_LIFECYCLE_CLASS_NAME,
3493:                        mBindingLifeClassPath, null);
3494:                mBindingContext.setInstallRoot(mInstallRoot);
3495:                mBindingContext.setIsInstall(true);
3496:                mCompFW.loadBootstrap(mBindingContext,
3497:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
3498:                        mBindingBootClassPath, null);
3499:                mCompFW.installComponent(mBindingContext);
3500:                Component binding = mCompReg
3501:                        .getComponent(Constants.BC_NAME_TIMEOUT_INIT);
3502:
3503:                // Install a SE that times out in its start() method
3504:
3505:                mEngineContext = new ComponentInstallationContext(
3506:                        Constants.SE_NAME_TIMEOUT_START,
3507:                        ComponentInstallationContext.ENGINE,
3508:                        Constants.SE_LIFECYCLE_CLASS_NAME,
3509:                        mEngineLifeClassPath, null);
3510:                mEngineContext.setInstallRoot(mInstallRoot);
3511:                mEngineContext.setIsInstall(true);
3512:                mCompFW.loadBootstrap(mEngineContext,
3513:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
3514:                        mEngineBootClassPath, null);
3515:                mCompFW.installComponent(mEngineContext);
3516:                Component engine = mCompReg
3517:                        .getComponent(Constants.SE_NAME_TIMEOUT_START);
3518:
3519:                // Stop the ComponentFramework and verify that the components are
3520:                // both shut down
3521:
3522:                mCompFW.stopService();
3523:                assertTrue("Failed to shut down Binding Component, state is "
3524:                        + binding.getStatusAsString() + ", should be SHUTDOWN",
3525:                        binding.isShutDown());
3526:                assertTrue("Failed to shut down Service Engine, state is "
3527:                        + engine.getStatusAsString() + ", should be SHUTDOWN",
3528:                        engine.isShutDown());
3529:
3530:                // Set the timeout value so that the components will time out, and
3531:                // set the startup type to ALL so that both components will be started.
3532:
3533:                mContext.setComponentTimeout(1000);
3534:                mCompFW.setStartup(ComponentFramework.STARTUP_ALL);
3535:
3536:                // Now start the ComponentFramework and verify that the BC and SE both
3537:                // timed out
3538:
3539:                mCompFW.startService();
3540:                mCompFW.ready(true);
3541:                assertTrue(
3542:                        "Failed to timeout on init of Binding Component, state is "
3543:                                + binding.getStatusAsString()
3544:                                + ", should be SHUTDOWN", binding.isShutDown());
3545:                assertTrue(
3546:                        "Failed to timeout on start of Service Engine, state is "
3547:                                + engine.getStatusAsString()
3548:                                + ", should be STOPPED", engine.isStopped());
3549:
3550:                // Reset the timeout value
3551:
3552:                mContext.setComponentTimeout(0);
3553:            }
3554:
3555:            /**
3556:             * Tests stopService with a good result.
3557:             * @throws Exception if an unexpected error occurs.
3558:             */
3559:            public void testStopServiceGood() throws Exception {
3560:                // Install and start a BC and an SE
3561:
3562:                mBindingContext.setIsInstall(true);
3563:                mCompFW.loadBootstrap(mBindingContext,
3564:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
3565:                        mBindingBootClassPath, null);
3566:                mCompFW.installComponent(mBindingContext);
3567:                Component binding = mCompReg.getComponent(Constants.BC_NAME);
3568:                mCompFW.startComponent(binding);
3569:                assertTrue("Failure starting Binding Component", binding
3570:                        .isStarted());
3571:
3572:                mEngineContext.setIsInstall(true);
3573:                mCompFW.loadBootstrap(mEngineContext,
3574:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
3575:                        mEngineBootClassPath, null);
3576:                mCompFW.installComponent(mEngineContext);
3577:                Component engine = mCompReg.getComponent(Constants.SE_NAME);
3578:                mCompFW.startComponent(engine);
3579:                assertTrue("Failure starting Service Engine", engine
3580:                        .isStarted());
3581:
3582:                // Now stop the ComponentFramework and verify that the BC and SE
3583:                // were both shutdown
3584:
3585:                mCompFW.stopService();
3586:                assertTrue("Failed to shutdown Binding Component", binding
3587:                        .isInstalled());
3588:                assertTrue("Failed to shutdown Service Engine", engine
3589:                        .isInstalled());
3590:            }
3591:
3592:            /**
3593:             * Tests stopService with a BC that times out in its stop() method and
3594:             * an SE that times out on its shutDown().
3595:             * @throws Exception if an unexpected error occurs.
3596:             */
3597:            public void testStopServiceTimeout() throws Exception {
3598:                // Install and start a BC and an SE
3599:
3600:                mBindingContext
3601:                        .setComponentName(Constants.BC_NAME_TIMEOUT_STOP);
3602:                mBindingContext.setIsInstall(true);
3603:                mCompFW.loadBootstrap(mBindingContext,
3604:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
3605:                        mBindingBootClassPath, null);
3606:                mCompFW.installComponent(mBindingContext);
3607:                Component binding = mCompReg
3608:                        .getComponent(Constants.BC_NAME_TIMEOUT_STOP);
3609:                mCompFW.startComponent(binding);
3610:                assertTrue("Failure starting Binding Component", binding
3611:                        .isStarted());
3612:
3613:                mEngineContext
3614:                        .setComponentName(Constants.SE_NAME_TIMEOUT_SHUTDOWN);
3615:                mEngineContext.setIsInstall(true);
3616:                mCompFW.loadBootstrap(mEngineContext,
3617:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
3618:                        mEngineBootClassPath, null);
3619:                mCompFW.installComponent(mEngineContext);
3620:                Component engine = mCompReg
3621:                        .getComponent(Constants.SE_NAME_TIMEOUT_SHUTDOWN);
3622:                mCompFW.startComponent(engine);
3623:                assertTrue("Failure starting Service Engine", engine
3624:                        .isStarted());
3625:
3626:                // Now stop the ComponentFramework and verify that the BC and SE
3627:                // both timed out
3628:
3629:                mCompFW.stopService();
3630:                assertTrue("Failed to timeout Binding Component, state is "
3631:                        + binding.getStatusAsString() + ", should be STARTED",
3632:                        binding.isStarted());
3633:                assertTrue("Failed to timeout Service Engine, state is "
3634:                        + engine.getStatusAsString() + ", should be STOPPED",
3635:                        engine.isStopped());
3636:            }
3637:
3638:            /**
3639:             * Tests stopService with a BC that times out in its shutDown() method,
3640:             * an SE that shuts down normally.
3641:             * @throws Exception if an unexpected error occurs.
3642:             */
3643:            public void testStopServiceMixed() throws Exception {
3644:                // Install and start a BC and an SE
3645:
3646:                mBindingContext
3647:                        .setComponentName(Constants.BC_NAME_TIMEOUT_SHUTDOWN);
3648:                mBindingContext.setIsInstall(true);
3649:                mCompFW.loadBootstrap(mBindingContext,
3650:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
3651:                        mBindingBootClassPath, null);
3652:                mCompFW.installComponent(mBindingContext);
3653:                Component binding = mCompReg
3654:                        .getComponent(Constants.BC_NAME_TIMEOUT_SHUTDOWN);
3655:                mCompFW.startComponent(binding);
3656:                assertTrue("Failure starting Binding Component", binding
3657:                        .isStarted());
3658:
3659:                mEngineContext.setIsInstall(true);
3660:                mCompFW.loadBootstrap(mEngineContext,
3661:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
3662:                        mEngineBootClassPath, null);
3663:                mCompFW.installComponent(mEngineContext);
3664:                Component engine = mCompReg.getComponent(Constants.SE_NAME);
3665:                mCompFW.startComponent(engine);
3666:                assertTrue("Failure starting Service Engine", engine
3667:                        .isStarted());
3668:
3669:                // Now stop the ComponentFramework and verify that the BC timed out
3670:                // and the SE shutdown successfully.
3671:
3672:                mCompFW.stopService();
3673:                assertTrue("Failed to timeout Binding Component, state is "
3674:                        + binding.getStatusAsString() + ", should be STOPPED",
3675:                        binding.isStopped());
3676:                assertTrue("Failed to shutdown Service Engine, state is "
3677:                        + engine.getStatusAsString() + ", should be installed",
3678:                        engine.isInstalled());
3679:            }
3680:
3681:            /**
3682:             * Tests getComponentInstance with a good result.
3683:             * @throws Exception if an unexpected error occurs.
3684:             */
3685:            public void testGetComponentInstanceGood() throws Exception {
3686:                javax.jbi.component.Component instance = null;
3687:
3688:                // Test that a null is returned when the component does not exist
3689:                instance = mCompFW.getComponentInstance(Constants.BC_NAME);
3690:                assertNull("Failure getting component instance: "
3691:                        + "expected a null return value , got " + instance,
3692:                        instance);
3693:
3694:                // Install a good binding
3695:                mBindingContext.setIsInstall(true);
3696:                mCompFW.loadBootstrap(mBindingContext,
3697:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
3698:                        mBindingBootClassPath, null);
3699:                mCompFW.installComponent(mBindingContext);
3700:
3701:                // Test that a null is returned when the component does not exist
3702:                instance = mCompFW.getComponentInstance(Constants.BC_NAME);
3703:                assertNull("Failure getting component instance: "
3704:                        + "expected a null return value , got " + instance,
3705:                        instance);
3706:
3707:                // Start it so that the component instance is created
3708:                Component comp = mCompReg.getComponent(Constants.BC_NAME);
3709:                mCompFW.startComponent(comp);
3710:
3711:                // Test that a valid instance returned when the component exists
3712:                instance = mCompFW.getComponentInstance(Constants.BC_NAME);
3713:                assertNotNull("Failure getting component instance: "
3714:                        + "expected a non null return value , got " + instance,
3715:                        instance);
3716:
3717:                // Shut it down so that the component instance is removed
3718:                comp = mCompReg.getComponent(Constants.BC_NAME);
3719:                mCompFW.shutdownComponent(comp);
3720:
3721:                // Test that a null is returned when the component does not exist
3722:                instance = mCompFW.getComponentInstance(Constants.BC_NAME);
3723:                assertNull("Failure getting component instance: "
3724:                        + "expected a null return value , got " + instance,
3725:                        instance);
3726:            }
3727:
3728:            /**
3729:             * Tests getDeployerInstance with a good result.
3730:             * @throws Exception if an unexpected error occurs.
3731:             */
3732:            public void testGetDeployerInstanceGood() throws Exception {
3733:                com.sun.jbi.framework.DeployerMBean instance = null;
3734:
3735:                // Test that a null is returned when the component does not exist
3736:                instance = mCompFW.getDeployerInstance(Constants.BC_NAME);
3737:                assertNull("Failure getting deployer instance: "
3738:                        + "expected a null return value , got " + instance,
3739:                        instance);
3740:
3741:                // Install a good binding
3742:                mBindingContext.setIsInstall(true);
3743:                mCompFW.loadBootstrap(mBindingContext,
3744:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
3745:                        mBindingBootClassPath, null);
3746:                mCompFW.installComponent(mBindingContext);
3747:
3748:                // Start it so that the deployer instance is created
3749:                Component comp = mCompReg.getComponent(Constants.BC_NAME);
3750:                mCompFW.startComponent(comp);
3751:
3752:                // Test that a valid instance returned when the component exists
3753:                instance = mCompFW.getDeployerInstance(Constants.BC_NAME);
3754:                assertNotNull("Failure getting deployer instance: "
3755:                        + "expected a non null return value , got " + instance,
3756:                        instance);
3757:            }
3758:
3759:            /**
3760:             * Tests validateComponentForUpgrade with a good result.
3761:             * @throws Exception if an unexpected error occurs.
3762:             */
3763:            public void testValidateComponentForUpgradeGood() throws Exception {
3764:                boolean supported;
3765:
3766:                // Install a good binding
3767:                mBindingContext.setIsInstall(true);
3768:                mCompFW.loadBootstrap(mBindingContext,
3769:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
3770:                        mBindingBootClassPath, null);
3771:                mCompFW.installComponent(mBindingContext);
3772:
3773:                // Now validate for upgrade with a bootstrap class that supports upgrade
3774:                supported = mCompFW.validateComponentForUpgrade(
3775:                        mBindingContext,
3776:                        Constants.BC_BOOTSTRAP_CLASS_NAME_UPGRADE,
3777:                        mBindingBootClassPath, null);
3778:
3779:                // Verify that upgrade support was detected
3780:                assertTrue("Upgrade method should have been found: ", supported);
3781:
3782:                // Install a good engine that does not support upgrade
3783:                mEngineContext.setIsInstall(true);
3784:                mCompFW.loadBootstrap(mEngineContext,
3785:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
3786:                        mEngineBootClassPath, null);
3787:                mCompFW.installComponent(mEngineContext);
3788:
3789:                // Now validate for upgrade using the same install context
3790:                supported = mCompFW.validateComponentForUpgrade(mEngineContext,
3791:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
3792:                        mEngineBootClassPath, null);
3793:
3794:                // Verify that upgrade support was not detected
3795:                assertFalse("Upgrade method should not have been found: ",
3796:                        supported);
3797:            }
3798:
3799:            /**
3800:             * Tests validateComponentForUpgrade with additional Shared Libraries with
3801:             * a good result.
3802:             * @throws Exception if an unexpected error occurs.
3803:             */
3804:            public void testValidateComponentForUpgradeGoodSharedLibraries()
3805:                    throws Exception {
3806:                boolean supported;
3807:
3808:                // Install a good binding
3809:                mBindingContext.setIsInstall(true);
3810:                mCompFW.loadBootstrap(mBindingContext,
3811:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
3812:                        mBindingBootClassPath, null);
3813:                mCompFW.installComponent(mBindingContext);
3814:
3815:                // Now install the required shared libraries
3816:                mCompFW.installSharedLibrary(Constants.SL_1_NAME,
3817:                        Constants.SL_1_DESC, Constants.SL_1_ROOT, false,
3818:                        mSl1Elements);
3819:                mCompFW.installSharedLibrary(Constants.SL_2_NAME,
3820:                        Constants.SL_2_DESC, Constants.SL_2_ROOT, false,
3821:                        mSl2Elements);
3822:
3823:                // Create a list of Shared Library IDs to add
3824:                ArrayList slList = new ArrayList();
3825:                slList.add(Constants.SL_1_NAME);
3826:                slList.add(Constants.SL_2_NAME);
3827:
3828:                // Now validate for upgrade with a bootstrap class that supports upgrade
3829:                // and with new Shared Libraries required
3830:                supported = mCompFW.validateComponentForUpgrade(
3831:                        mBindingContext,
3832:                        Constants.BC_BOOTSTRAP_CLASS_NAME_UPGRADE,
3833:                        mBindingBootClassPath, slList);
3834:
3835:                // Verify that upgrade support was detected
3836:                assertTrue("Upgrade method should have been found: ", supported);
3837:            }
3838:
3839:            /**
3840:             * Tests validateComponentForUpgrade with a null ComponentInstallationContext
3841:             * parameter. An exception is expected.
3842:             * @throws Exception if an unexpected error occurs.
3843:             */
3844:            public void testValidateComponentForUpgradeBadNullInstallationContext()
3845:                    throws Exception {
3846:                try {
3847:                    mCompFW.validateComponentForUpgrade(null,
3848:                            Constants.BC_BOOTSTRAP_CLASS_NAME_UPGRADE,
3849:                            mBindingBootClassPath, null);
3850:                    fail("Expected exception not received");
3851:                } catch (java.lang.IllegalArgumentException ex) {
3852:                    // Verification
3853:                    assertTrue(
3854:                            "Incorrect exception received: " + ex.toString(),
3855:                            (-1 < ex.getMessage().indexOf("installContext")));
3856:                }
3857:            }
3858:
3859:            /**
3860:             * Tests validateComponentForUpgrade with a null bootstrap class name
3861:             * parameter. An exception is expected.
3862:             * @throws Exception if an unexpected error occurs.
3863:             */
3864:            public void testValidateComponentForUpgradeBadNullBootClassName()
3865:                    throws Exception {
3866:                try {
3867:                    mCompFW.validateComponentForUpgrade(mBindingContext, null,
3868:                            mBindingBootClassPath, null);
3869:                    fail("Expected exception not received");
3870:                } catch (java.lang.IllegalArgumentException ex) {
3871:                    // Verification
3872:                    assertTrue(
3873:                            "Incorrect exception received: " + ex.toString(),
3874:                            (-1 < ex.getMessage().indexOf("bootClassName")));
3875:                }
3876:            }
3877:
3878:            /**
3879:             * Tests validateComponentForUpgrade with an empty bootstrap class name
3880:             * parameter. An exception is expected.
3881:             * @throws Exception if an unexpected error occurs.
3882:             */
3883:            public void testValidateComponentForUpgradeBadEmptyBootClassName()
3884:                    throws Exception {
3885:                try {
3886:                    mCompFW.validateComponentForUpgrade(mBindingContext, "",
3887:                            mBindingBootClassPath, null);
3888:                    fail("Expected exception not received");
3889:                } catch (java.lang.IllegalArgumentException ex) {
3890:                    // Verification
3891:                    assertTrue(
3892:                            "Incorrect exception received: " + ex.toString(),
3893:                            (-1 < ex.getMessage().indexOf("bootClassName")));
3894:                }
3895:            }
3896:
3897:            /**
3898:             * Tests validateComponentForUpgrade with a null bootstrap class path element
3899:             * list parameter. An exception is expected.
3900:             * @throws Exception if an unexpected error occurs.
3901:             */
3902:            public void testValidateComponentForUpgradeBadNullBootClassPathElementList()
3903:                    throws Exception {
3904:                try {
3905:                    mCompFW.validateComponentForUpgrade(mBindingContext,
3906:                            Constants.BC_BOOTSTRAP_CLASS_NAME_UPGRADE, null,
3907:                            null);
3908:                    fail("Expected exception not received");
3909:                } catch (java.lang.IllegalArgumentException ex) {
3910:                    // Verification
3911:                    assertTrue(
3912:                            "Incorrect exception received: " + ex.toString(),
3913:                            (-1 < ex.getMessage().indexOf(
3914:                                    "bootClassPathElements")));
3915:                }
3916:            }
3917:
3918:            /**
3919:             * Tests validateComponentForUpgrade with an empty bootstrap class path
3920:             * element list parameter. An exception is expected.
3921:             * @throws Exception if an unexpected error occurs.
3922:             */
3923:            public void testValidateComponentForUpgradeBadEmptyBootClassPathElementList()
3924:                    throws Exception {
3925:                try {
3926:                    mCompFW.validateComponentForUpgrade(mBindingContext,
3927:                            Constants.BC_BOOTSTRAP_CLASS_NAME_UPGRADE,
3928:                            new ArrayList(), null);
3929:                    fail("Expected exception not received");
3930:                } catch (java.lang.IllegalArgumentException ex) {
3931:                    // Verification
3932:                    assertTrue(
3933:                            "Incorrect exception received: " + ex.toString(),
3934:                            (-1 < ex.getMessage().indexOf(
3935:                                    "bootClassPathElements")));
3936:                }
3937:            }
3938:
3939:            /**
3940:             * Tests validateComponentForUpgrade with a non-existent component.
3941:             * An exception is expected.
3942:             * @throws Exception if an unexpected error occurs.
3943:             */
3944:            public void testValidateComponentForUpgradeBadNotFound()
3945:                    throws Exception {
3946:                try {
3947:                    mCompFW.validateComponentForUpgrade(mBindingContext,
3948:                            Constants.BC_BOOTSTRAP_CLASS_NAME_UPGRADE,
3949:                            mBindingBootClassPath, null);
3950:                    fail("Expected exception not received");
3951:                } catch (javax.jbi.JBIException ex) {
3952:                    // Verification
3953:                    assertTrue(
3954:                            "Incorrect exception received: " + ex.toString(),
3955:                            (-1 < ex.getMessage().indexOf("JBIFW1185")));
3956:                }
3957:            }
3958:
3959:            /**
3960:             * Tests validateComponentForUpgrade with a running component.
3961:             * An exception is expected.
3962:             * @throws Exception if an unexpected error occurs.
3963:             */
3964:            public void testValidateComponentForUpgradeBadNotShutDown()
3965:                    throws Exception {
3966:                // Install a good binding and start it
3967:                mBindingContext.setIsInstall(true);
3968:                mCompFW.loadBootstrap(mBindingContext,
3969:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
3970:                        mBindingBootClassPath, null);
3971:                mCompFW.installComponent(mBindingContext);
3972:                Component comp = mCompReg.getComponent(Constants.BC_NAME);
3973:                mCompFW.startComponent(comp);
3974:
3975:                try {
3976:                    mCompFW.validateComponentForUpgrade(mBindingContext,
3977:                            Constants.BC_BOOTSTRAP_CLASS_NAME_UPGRADE,
3978:                            mBindingBootClassPath, null);
3979:                    fail("Expected exception not received");
3980:                } catch (javax.jbi.JBIException ex) {
3981:                    // Verification
3982:                    assertTrue(
3983:                            "Incorrect exception received: " + ex.toString(),
3984:                            (-1 < ex.getMessage().indexOf("JBIFW1186")));
3985:                }
3986:            }
3987:
3988:            /**
3989:             * Tests validateComponentForUpgrade with a busy component. An exception
3990:             * is expected.
3991:             * @throws Exception if an unexpected error occurs.
3992:             */
3993:            public void testValidateComponentForUpgradeBadBusy()
3994:                    throws Exception {
3995:                // Install a good binding
3996:                mBindingContext.setIsInstall(true);
3997:                mCompFW.loadBootstrap(mBindingContext,
3998:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
3999:                        mBindingBootClassPath, null);
4000:                mCompFW.installComponent(mBindingContext);
4001:                // Set the component to a busy state
4002:                Component comp = mCompReg.getComponent(Constants.BC_NAME);
4003:                comp.setBusy();
4004:
4005:                // Now validate for update using the same install context
4006:                try {
4007:                    mCompFW.validateComponentForUpgrade(mBindingContext,
4008:                            Constants.BC_BOOTSTRAP_CLASS_NAME_UPGRADE,
4009:                            mBindingBootClassPath, null);
4010:                    fail("Expected exception not received");
4011:                } catch (javax.jbi.JBIException ex) {
4012:                    // Verification
4013:                    assertTrue(
4014:                            "Incorrect exception received: " + ex.toString(),
4015:                            (-1 < ex.getMessage().indexOf("JBIFW2011")));
4016:                }
4017:            }
4018:
4019:            /**
4020:             * Tests validateComponentForUpgrade with a missing shared library. An
4021:             * exception is expected.
4022:             * @throws Exception if an unexpected error occurs.
4023:             */
4024:            public void testValidateComponentForUpgradeBadMissingSharedLibrary()
4025:                    throws Exception {
4026:                // Create a list of Shared Library IDs that are not installed.
4027:                ArrayList slList = new ArrayList();
4028:                slList.add(Constants.SL_1_NAME);
4029:                slList.add(Constants.SL_2_NAME);
4030:
4031:                // Install a good binding
4032:                mBindingContext.setIsInstall(true);
4033:                mCompFW.loadBootstrap(mBindingContext,
4034:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
4035:                        mBindingBootClassPath, null);
4036:                mCompFW.installComponent(mBindingContext);
4037:
4038:                // Now validate for update using the same install context. This should
4039:                // fail due to missing shared libraries.
4040:                try {
4041:                    mCompFW.validateComponentForUpgrade(mBindingContext,
4042:                            Constants.BC_BOOTSTRAP_CLASS_NAME_UPGRADE,
4043:                            mBindingBootClassPath, slList);
4044:                    fail("Expected exception not received");
4045:                } catch (javax.jbi.JBIException ex) {
4046:                    // Verification
4047:                    assertTrue("Incorrect exception message received: "
4048:                            + ex.toString(), (-1 < ex.getMessage().indexOf(
4049:                            "JBIFW1195")));
4050:                    assertTrue("Incorrect exception message received: "
4051:                            + ex.toString(), (-1 < ex.getMessage().indexOf(
4052:                            Constants.SL_1_NAME)));
4053:                    assertTrue("Incorrect exception message received: "
4054:                            + ex.toString(), (-1 < ex.getMessage().indexOf(
4055:                            Constants.SL_2_NAME)));
4056:                }
4057:            }
4058:
4059:            /**
4060:             * Tests validateComponentForUpgrade with a bootstrap class loading failure.
4061:             * An exception is expected.
4062:             * @throws Exception if an unexpected error occurs.
4063:             */
4064:            public void testValidateComponentForUpgradeBadBootstrapClassNotFound()
4065:                    throws Exception {
4066:                // Install a good binding
4067:                mBindingContext.setIsInstall(true);
4068:                mCompFW.loadBootstrap(mBindingContext,
4069:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
4070:                        mBindingBootClassPath, null);
4071:                mCompFW.installComponent(mBindingContext);
4072:
4073:                // Now validate for update. This should fail with a bootstrap class load
4074:                // error
4075:                try {
4076:                    mCompFW.validateComponentForUpgrade(mBindingContext,
4077:                            "bad.bootstrap.class", mBindingBootClassPath, null);
4078:                    fail("Expected exception not received");
4079:                } catch (javax.jbi.JBIException ex) {
4080:                    // Verification
4081:                    assertTrue(
4082:                            "Incorrect exception received: " + ex.toString(),
4083:                            (-1 < ex.getMessage().indexOf("JBIFW2004")));
4084:                    assertTrue(
4085:                            "Incorrect exception received: " + ex.toString(),
4086:                            (-1 < ex.getMessage()
4087:                                    .indexOf("bad.bootstrap.class")));
4088:                }
4089:            }
4090:
4091:            /**
4092:             * Tests validateComponentForUpgrade with a component class loading failure.
4093:             * An exception is expected.
4094:             * @throws Exception if an unexpected error occurs.
4095:             */
4096:            public void testValidateComponentForUpgradeBadComponentClassNotFound()
4097:                    throws Exception {
4098:                // Install a good binding
4099:                mBindingContext.setIsInstall(true);
4100:                mCompFW.loadBootstrap(mBindingContext,
4101:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
4102:                        mBindingBootClassPath, null);
4103:                mCompFW.installComponent(mBindingContext);
4104:
4105:                // Change the component class name in the installation context to
4106:                // force a class loading failure
4107:                mBindingContext.setComponentClassName("bad.component.class");
4108:
4109:                // Now validate for update. This should fail with a component class load
4110:                // error
4111:                try {
4112:                    mCompFW.validateComponentForUpgrade(mBindingContext,
4113:                            Constants.BC_BOOTSTRAP_CLASS_NAME_UPGRADE,
4114:                            mBindingBootClassPath, null);
4115:                    fail("Expected exception not received");
4116:                } catch (javax.jbi.JBIException ex) {
4117:                    // Verification
4118:                    assertTrue(
4119:                            "Incorrect exception received: " + ex.toString(),
4120:                            (-1 < ex.getMessage().indexOf("JBIFW2004")));
4121:                    assertTrue(
4122:                            "Incorrect exception received: " + ex.toString(),
4123:                            (-1 < ex.getMessage()
4124:                                    .indexOf("bad.component.class")));
4125:                }
4126:            }
4127:
4128:            /**
4129:             * Tests cancelComponentUpgrade with a good result.
4130:             * @throws Exception if an unexpected error occurs.
4131:             */
4132:            public void testCancelComponentUpgradeGood() throws Exception {
4133:                // Install a good binding
4134:                mBindingContext.setIsInstall(true);
4135:                mCompFW.loadBootstrap(mBindingContext,
4136:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
4137:                        mBindingBootClassPath, null);
4138:                mCompFW.installComponent(mBindingContext);
4139:
4140:                // Now validate for upgrade with a bootstrap class that supports upgrade
4141:                mCompFW.validateComponentForUpgrade(mBindingContext,
4142:                        Constants.BC_BOOTSTRAP_CLASS_NAME_UPGRADE,
4143:                        mBindingBootClassPath, null);
4144:
4145:                // Now cancel the upgrade
4146:                mCompFW.cancelComponentUpgrade(Constants.BC_NAME);
4147:
4148:                // Verification
4149:                Component comp = mCompReg.getComponent(Constants.BC_NAME);
4150:                assertFalse("cancelComponentUpgrade failed to reset busy flag",
4151:                        comp.isBusy());
4152:                assertFalse(
4153:                        "cancelComponentUpgrade failed to reset updating flag",
4154:                        comp.isUpdating());
4155:            }
4156:
4157:            /**
4158:             * Tests cancelComponentUpgrade with a null component name parameter. An
4159:             * exception is expected.
4160:             * @throws Exception if an unexpected error occurs.
4161:             */
4162:            public void testCancelComponentUpgradeBadNullComponentName()
4163:                    throws Exception {
4164:                try {
4165:                    mCompFW.cancelComponentUpgrade(null);
4166:                    fail("Expected exception not received");
4167:                } catch (java.lang.IllegalArgumentException ex) {
4168:                    // Verification
4169:                    assertTrue(
4170:                            "Incorrect exception received: " + ex.toString(),
4171:                            (-1 < ex.getMessage().indexOf("componentName")));
4172:                }
4173:            }
4174:
4175:            /**
4176:             * Tests cancelComponentUpgrade with an empty component name parameter. An
4177:             * exception is expected.
4178:             * @throws Exception if an unexpected error occurs.
4179:             */
4180:            public void testCancelComponentUpgradeBadEmptyComponentName()
4181:                    throws Exception {
4182:                try {
4183:                    mCompFW.cancelComponentUpgrade("");
4184:                    fail("Expected exception not received");
4185:                } catch (java.lang.IllegalArgumentException ex) {
4186:                    // Verification
4187:                    assertTrue(
4188:                            "Incorrect exception received: " + ex.toString(),
4189:                            (-1 < ex.getMessage().indexOf("componentName")));
4190:                }
4191:            }
4192:
4193:            /**
4194:             * Tests cancelComponentUpgrade with a non-existent component. An exception
4195:             * is expected.
4196:             * @throws Exception if an unexpected error occurs.
4197:             */
4198:            public void testCancelComponentUpgradeBadNotFound()
4199:                    throws Exception {
4200:                try {
4201:                    mCompFW.cancelComponentUpgrade(Constants.BC_NAME);
4202:                    fail("Expected exception not received");
4203:                } catch (javax.jbi.JBIException ex) {
4204:                    // Verification
4205:                    assertTrue(
4206:                            "Incorrect exception received: " + ex.toString(),
4207:                            (-1 < ex.getMessage().indexOf("JBIFW1189")));
4208:                }
4209:            }
4210:
4211:            /**
4212:             * Tests upgradeComponent with a good result.
4213:             * @throws Exception if an unexpected error occurs.
4214:             */
4215:            public void testUpgradeComponentGood() throws Exception {
4216:                File f;
4217:
4218:                // Install a good binding that supports upgrade
4219:                mBindingContext.setIsInstall(true);
4220:                mCompFW.loadBootstrap(mBindingContext,
4221:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
4222:                        mBindingBootClassPath, null);
4223:                mCompFW.installComponent(mBindingContext);
4224:                Component comp = mCompReg.getComponent(Constants.BC_NAME);
4225:
4226:                // Add an SU to this component (this is a shortcut to deployment).
4227:                String suPath = mInstallRoot + "/" + Constants.SU_NAME;
4228:                f = new File(suPath);
4229:                if (f.exists()) {
4230:                    File[] fl = f.listFiles();
4231:                    if (null != fl) {
4232:                        for (int i = 0; i < fl.length; i++) {
4233:                            fl[i].delete();
4234:                        }
4235:                    }
4236:                } else {
4237:                    f.mkdir();
4238:                }
4239:                ServiceUnit su = new ServiceUnit(Constants.SA_NAME,
4240:                        Constants.SU_NAME, suPath, Constants.BC_NAME);
4241:                comp.addServiceUnit(su);
4242:
4243:                // Now validate for upgrade with a bootstrap class that supports upgrade
4244:                mCompFW.validateComponentForUpgrade(mBindingContext,
4245:                        Constants.BC_BOOTSTRAP_CLASS_NAME_UPGRADE,
4246:                        mBindingBootClassPath, null);
4247:
4248:                // Now upgrade using the same install context
4249:                System.setProperty(Constants.PROPERTY_COMPONENT_NAME,
4250:                        mBindingContext.getComponentName());
4251:                mCompFW.upgradeComponent(mBindingContext,
4252:                        Constants.BC_BOOTSTRAP_CLASS_NAME_UPGRADE,
4253:                        mBindingBootClassPath, null);
4254:
4255:                // Verification
4256:                comp = mCompReg.getComponent(Constants.BC_NAME);
4257:                assertEquals("Component instance not updated: ",
4258:                        Constants.BC_BOOTSTRAP_CLASS_NAME_UPGRADE, comp
4259:                                .getBootstrapClassName());
4260:
4261:                f = new File(mWorkspaceRoot + "/"
4262:                        + Constants.UPGRADED_FILE_NAME);
4263:                assertTrue("Component's upgrade method failed to write file "
4264:                        + f.getAbsolutePath(), f.exists());
4265:
4266:                f = new File(suPath + "/" + Constants.UPGRADED_FILE_NAME);
4267:                assertTrue("Component's upgrade method failed to write file "
4268:                        + f.getAbsolutePath(), f.exists());
4269:
4270:                // Make sure the component will start, stop, and shut down
4271:                try {
4272:                    mCompFW.startComponent(comp);
4273:                } catch (javax.jbi.JBIException ex) {
4274:                    fail(ex.getMessage());
4275:                }
4276:                try {
4277:                    mCompFW.stopComponent(comp);
4278:                } catch (javax.jbi.JBIException ex) {
4279:                    fail(ex.getMessage());
4280:                }
4281:                try {
4282:                    mCompFW.shutdownComponent(comp);
4283:                } catch (javax.jbi.JBIException ex) {
4284:                    fail(ex.getMessage());
4285:                }
4286:            }
4287:
4288:            /**
4289:             * Tests upgradeComponent with a good result with a new shared library.
4290:             * @throws Exception if an unexpected error occurs.
4291:             */
4292:            public void testUpgradeComponentGoodSharedLibrary()
4293:                    throws Exception {
4294:                // Install a good binding that supports upgrade
4295:                mBindingContext.setIsInstall(true);
4296:                mCompFW.loadBootstrap(mBindingContext,
4297:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
4298:                        mBindingBootClassPath, null);
4299:                mCompFW.installComponent(mBindingContext);
4300:
4301:                // Now install the required shared libraries
4302:                mCompFW.installSharedLibrary(Constants.SL_1_NAME,
4303:                        Constants.SL_1_DESC, Constants.SL_1_ROOT, false,
4304:                        mSl1Elements);
4305:
4306:                // Create the list of Shared Library IDs to add
4307:                ArrayList slList = new ArrayList();
4308:                slList.add(Constants.SL_1_NAME);
4309:
4310:                // Now validate for upgrade with a bootstrap class that supports upgrade
4311:                // and with the new shared library required
4312:                mCompFW.validateComponentForUpgrade(mBindingContext,
4313:                        Constants.BC_BOOTSTRAP_CLASS_NAME_UPGRADE,
4314:                        mBindingBootClassPath, slList);
4315:
4316:                // Now upgrade using the same install context
4317:                System.setProperty(Constants.PROPERTY_COMPONENT_NAME,
4318:                        mBindingContext.getComponentName());
4319:                mCompFW.upgradeComponent(mBindingContext,
4320:                        Constants.BC_BOOTSTRAP_CLASS_NAME_UPGRADE,
4321:                        mBindingBootClassPath, slList);
4322:
4323:                // Verification
4324:                Component comp = mCompReg.getComponent(Constants.BC_NAME);
4325:                assertEquals(
4326:                        "Component instance bootstrap class name not updated: ",
4327:                        Constants.BC_BOOTSTRAP_CLASS_NAME_UPGRADE, comp
4328:                                .getBootstrapClassName());
4329:                assertEquals(
4330:                        "Component instance shared library count not same: ",
4331:                        slList.size(), comp.getSharedLibraryNames().size());
4332:                assertTrue("Component instance shared library list not same: ",
4333:                        comp.getSharedLibraryNames().containsAll(slList));
4334:            }
4335:
4336:            /**
4337:             * Tests upgradeComponent with a good result with a changed bootstrap
4338:             * class path.
4339:             * @throws Exception if an unexpected error occurs.
4340:             */
4341:            public void testUpgradeComponentGoodBootstrapClassPath()
4342:                    throws Exception {
4343:                // Install a good binding that supports upgrade
4344:                mBindingContext.setIsInstall(true);
4345:                mCompFW.loadBootstrap(mBindingContext,
4346:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
4347:                        mBindingBootClassPath, null);
4348:                mCompFW.installComponent(mBindingContext);
4349:
4350:                // Add an element to the bootstrap class path list
4351:                mBindingBootClassPath.add(mInstallRoot);
4352:
4353:                // Now validate for upgrade with a bootstrap class that supports upgrade
4354:                // and with the new bootstrap class path
4355:                mCompFW.validateComponentForUpgrade(mBindingContext,
4356:                        Constants.BC_BOOTSTRAP_CLASS_NAME_UPGRADE,
4357:                        mBindingBootClassPath, null);
4358:
4359:                // Now upgrade using the same install context
4360:                System.setProperty(Constants.PROPERTY_COMPONENT_NAME,
4361:                        mBindingContext.getComponentName());
4362:                mCompFW.upgradeComponent(mBindingContext,
4363:                        Constants.BC_BOOTSTRAP_CLASS_NAME_UPGRADE,
4364:                        mBindingBootClassPath, null);
4365:
4366:                // Verification
4367:                Component comp = mCompReg.getComponent(Constants.BC_NAME);
4368:                assertEquals(
4369:                        "Component instance bootstrap class name not updated: ",
4370:                        Constants.BC_BOOTSTRAP_CLASS_NAME_UPGRADE, comp
4371:                                .getBootstrapClassName());
4372:                assertEquals(
4373:                        "Component instance bootstrap class path count not same: ",
4374:                        mBindingBootClassPath.size(), comp
4375:                                .getBootstrapClassPathElements().size());
4376:                int i = 0;
4377:                for (String cp : comp.getBootstrapClassPathElements()) {
4378:                    assertEquals(
4379:                            "Component instance bootstrap class path not same: ",
4380:                            cp, (String) mBindingBootClassPath.get(i++));
4381:                }
4382:            }
4383:
4384:            /**
4385:             * Tests upgradeComponent with a good result with a changed component
4386:             * class path.
4387:             * @throws Exception if an unexpected error occurs.
4388:             */
4389:            public void testUpgradeComponentGoodComponentClassPath()
4390:                    throws Exception {
4391:                // Install a good binding that supports upgrade
4392:                mBindingContext.setIsInstall(true);
4393:                mCompFW.loadBootstrap(mBindingContext,
4394:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
4395:                        mBindingBootClassPath, null);
4396:                mCompFW.installComponent(mBindingContext);
4397:
4398:                // Add an element to the component class path list. We have to replace
4399:                // forward slashes with File.separatorChar to comply with the JSR208
4400:                // defined interface for setClassPathElements().
4401:                mBindingLifeClassPath = new ArrayList();
4402:                mBindingLifeClassPath.add(Constants.BC_LIFECYCLE_CLASS_PATH
4403:                        .replace('/', File.separatorChar));
4404:                mBindingLifeClassPath.add(Constants.BC_LIFECYCLE_CLASS_PATH_NEW
4405:                        .replace('/', File.separatorChar));
4406:                mBindingContext.setClassPathElements(mBindingLifeClassPath);
4407:
4408:                // Now validate for upgrade with a bootstrap class that supports upgrade
4409:                // and with the new bootstrap class path
4410:                mCompFW.validateComponentForUpgrade(mBindingContext,
4411:                        Constants.BC_BOOTSTRAP_CLASS_NAME_UPGRADE,
4412:                        mBindingBootClassPath, null);
4413:
4414:                // Now upgrade using the same install context
4415:                System.setProperty(Constants.PROPERTY_COMPONENT_NAME,
4416:                        mBindingContext.getComponentName());
4417:                mCompFW.upgradeComponent(mBindingContext,
4418:                        Constants.BC_BOOTSTRAP_CLASS_NAME_UPGRADE,
4419:                        mBindingBootClassPath, null);
4420:
4421:                // Verification
4422:                Component comp = mCompReg.getComponent(Constants.BC_NAME);
4423:                assertEquals(
4424:                        "Component instance bootstrap class name not updated: ",
4425:                        Constants.BC_BOOTSTRAP_CLASS_NAME_UPGRADE, comp
4426:                                .getBootstrapClassName());
4427:                assertEquals(
4428:                        "Component instance component class path count not same: ",
4429:                        mBindingLifeClassPath.size(), comp
4430:                                .getComponentClassPathElements().size());
4431:
4432:                // Verifying the class path is a little more tricky. What's stored in
4433:                // the Component instance is an absolute path, while what's passed in
4434:                // to ComponentInstallationContext.setClassPathElements() is a relative
4435:                // path. So, check to make sure the relative path is contained in the
4436:                // corresponding absolute path.
4437:                int i = 0;
4438:                for (String cp : comp.getComponentClassPathElements()) {
4439:                    assertTrue(
4440:                            "Component instance component class path not same: "
4441:                                    + cp + " and "
4442:                                    + mBindingLifeClassPath.get(i), (-1 < cp
4443:                                    .indexOf((String) mBindingLifeClassPath
4444:                                            .get(i))));
4445:                    i++;
4446:                }
4447:            }
4448:
4449:            /**
4450:             * Tests upgradeComponent with a good result with a changed component
4451:             * description.
4452:             * @throws Exception if an unexpected error occurs.
4453:             */
4454:            public void testUpgradeComponentGoodDescription() throws Exception {
4455:                // Install a good binding that supports upgrade
4456:                mBindingContext.setIsInstall(true);
4457:                mCompFW.loadBootstrap(mBindingContext,
4458:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
4459:                        mBindingBootClassPath, null);
4460:                mCompFW.installComponent(mBindingContext);
4461:
4462:                // Change the component description
4463:                String newDesc = "This is an upgraded binding component";
4464:                mBindingContext.setDescription(newDesc);
4465:
4466:                // Now validate for upgrade with a bootstrap class that supports upgrade
4467:                mCompFW.validateComponentForUpgrade(mBindingContext,
4468:                        Constants.BC_BOOTSTRAP_CLASS_NAME_UPGRADE,
4469:                        mBindingBootClassPath, null);
4470:
4471:                // Now upgrade using the same install context
4472:                System.setProperty(Constants.PROPERTY_COMPONENT_NAME,
4473:                        mBindingContext.getComponentName());
4474:                mCompFW.upgradeComponent(mBindingContext,
4475:                        Constants.BC_BOOTSTRAP_CLASS_NAME_UPGRADE,
4476:                        mBindingBootClassPath, null);
4477:
4478:                // Verification
4479:                Component comp = mCompReg.getComponent(Constants.BC_NAME);
4480:                assertEquals(
4481:                        "Component instance bootstrap class name not updated: ",
4482:                        Constants.BC_BOOTSTRAP_CLASS_NAME_UPGRADE, comp
4483:                                .getBootstrapClassName());
4484:                assertEquals("Component description not same: ", newDesc, comp
4485:                        .getDescription());
4486:            }
4487:
4488:            /**
4489:             * Tests upgradeComponent with a good result with a changed bootstrap
4490:             * class loader self-first setting.
4491:             * @throws Exception if an unexpected error occurs.
4492:             */
4493:            public void testUpgradeComponentGoodBootstrapSelfFirst()
4494:                    throws Exception {
4495:                // Install a good binding that supports upgrade
4496:                mBindingContext.setIsInstall(true);
4497:                mCompFW.loadBootstrap(mBindingContext,
4498:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
4499:                        mBindingBootClassPath, null);
4500:                mCompFW.installComponent(mBindingContext);
4501:
4502:                // Change the bootstrap class loading to self-first
4503:                mBindingContext.setBootstrapClassLoaderSelfFirst();
4504:
4505:                // Now validate for upgrade with a bootstrap class that supports upgrade
4506:                mCompFW.validateComponentForUpgrade(mBindingContext,
4507:                        Constants.BC_BOOTSTRAP_CLASS_NAME_UPGRADE,
4508:                        mBindingBootClassPath, null);
4509:
4510:                // Now upgrade using the same install context
4511:                System.setProperty(Constants.PROPERTY_COMPONENT_NAME,
4512:                        mBindingContext.getComponentName());
4513:                mCompFW.upgradeComponent(mBindingContext,
4514:                        Constants.BC_BOOTSTRAP_CLASS_NAME_UPGRADE,
4515:                        mBindingBootClassPath, null);
4516:
4517:                // Verification
4518:                Component comp = mCompReg.getComponent(Constants.BC_NAME);
4519:                assertEquals(
4520:                        "Component instance bootstrap class name not updated: ",
4521:                        Constants.BC_BOOTSTRAP_CLASS_NAME_UPGRADE, comp
4522:                                .getBootstrapClassName());
4523:                assertTrue("Bootstrap class loader not self-first", comp
4524:                        .isBootstrapClassLoaderSelfFirst());
4525:            }
4526:
4527:            /**
4528:             * Tests upgradeComponent with a good result with a changed component
4529:             * class loader self-first setting.
4530:             * @throws Exception if an unexpected error occurs.
4531:             */
4532:            public void testUpgradeComponentGoodComponentSelfFirst()
4533:                    throws Exception {
4534:                // Install a good binding that supports upgrade
4535:                mBindingContext.setIsInstall(true);
4536:                mCompFW.loadBootstrap(mBindingContext,
4537:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
4538:                        mBindingBootClassPath, null);
4539:                mCompFW.installComponent(mBindingContext);
4540:
4541:                // Change the component class loading to self-first
4542:                mBindingContext.setComponentClassLoaderSelfFirst();
4543:
4544:                // Now validate for upgrade with a bootstrap class that supports upgrade
4545:                mCompFW.validateComponentForUpgrade(mBindingContext,
4546:                        Constants.BC_BOOTSTRAP_CLASS_NAME_UPGRADE,
4547:                        mBindingBootClassPath, null);
4548:
4549:                // Now upgrade using the same install context
4550:                System.setProperty(Constants.PROPERTY_COMPONENT_NAME,
4551:                        mBindingContext.getComponentName());
4552:                mCompFW.upgradeComponent(mBindingContext,
4553:                        Constants.BC_BOOTSTRAP_CLASS_NAME_UPGRADE,
4554:                        mBindingBootClassPath, null);
4555:
4556:                // Verification
4557:                Component comp = mCompReg.getComponent(Constants.BC_NAME);
4558:                assertEquals(
4559:                        "Component instance bootstrap class name not updated: ",
4560:                        Constants.BC_BOOTSTRAP_CLASS_NAME_UPGRADE, comp
4561:                                .getBootstrapClassName());
4562:                assertTrue("Component class loader not self-first", comp
4563:                        .isComponentClassLoaderSelfFirst());
4564:            }
4565:
4566:            /**
4567:             * Tests upgradeComponent with a null ComponentInstallationContext
4568:             * parameter. An exception is expected.
4569:             * @throws Exception if an unexpected error occurs.
4570:             */
4571:            public void testUpgradeComponentBadNullInstallationContext()
4572:                    throws Exception {
4573:                try {
4574:                    mCompFW.upgradeComponent(null,
4575:                            Constants.BC_BOOTSTRAP_CLASS_NAME,
4576:                            mBindingBootClassPath, null);
4577:                    fail("Expected exception not received");
4578:                } catch (java.lang.IllegalArgumentException ex) {
4579:                    // Verification
4580:                    assertTrue(
4581:                            "Incorrect exception received: " + ex.toString(),
4582:                            (-1 < ex.getMessage().indexOf("installContext")));
4583:                }
4584:            }
4585:
4586:            /**
4587:             * Tests upgradeComponent with a null bootstrap class name parameter.
4588:             * An exception is expected.
4589:             * @throws Exception if an unexpected error occurs.
4590:             */
4591:            public void testUpgradeComponentBadNullBootClassName()
4592:                    throws Exception {
4593:                try {
4594:                    mCompFW.upgradeComponent(mBindingContext, null,
4595:                            mBindingBootClassPath, null);
4596:                    fail("Expected exception not received");
4597:                } catch (java.lang.IllegalArgumentException ex) {
4598:                    // Verification
4599:                    assertTrue(
4600:                            "Incorrect exception received: " + ex.toString(),
4601:                            (-1 < ex.getMessage().indexOf("bootClassName")));
4602:                }
4603:            }
4604:
4605:            /**
4606:             * Tests upgradeComponent with an empty bootstrap class name parameter.
4607:             * An exception is expected.
4608:             * @throws Exception if an unexpected error occurs.
4609:             */
4610:            public void testUpgradeComponentBadEmptyBootClassName()
4611:                    throws Exception {
4612:                try {
4613:                    mCompFW.upgradeComponent(mBindingContext, "",
4614:                            mBindingBootClassPath, null);
4615:                    fail("Expected exception not received");
4616:                } catch (java.lang.IllegalArgumentException ex) {
4617:                    // Verification
4618:                    assertTrue(
4619:                            "Incorrect exception received: " + ex.toString(),
4620:                            (-1 < ex.getMessage().indexOf("bootClassName")));
4621:                }
4622:            }
4623:
4624:            /**
4625:             * Tests upgradeComponent with a null bootstrap class path element
4626:             * list parameter. An exception is expected.
4627:             * @throws Exception if an unexpected error occurs.
4628:             */
4629:            public void testUpgradeComponentBadNullBootClassPathElementList()
4630:                    throws Exception {
4631:                try {
4632:                    mCompFW.upgradeComponent(mBindingContext,
4633:                            Constants.BC_BOOTSTRAP_CLASS_NAME, null, null);
4634:                    fail("Expected exception not received");
4635:                } catch (java.lang.IllegalArgumentException ex) {
4636:                    // Verification
4637:                    assertTrue(
4638:                            "Incorrect exception received: " + ex.toString(),
4639:                            (-1 < ex.getMessage().indexOf(
4640:                                    "bootClassPathElements")));
4641:                }
4642:            }
4643:
4644:            /**
4645:             * Tests upgradeComponent with an empty bootstrap class path element list
4646:             * parameter. An exception is expected.
4647:             * @throws Exception if an unexpected error occurs.
4648:             */
4649:            public void testUpgradeComponentBadEmptyBootClassPathElementList()
4650:                    throws Exception {
4651:                try {
4652:                    mCompFW.upgradeComponent(mBindingContext,
4653:                            Constants.BC_BOOTSTRAP_CLASS_NAME, new ArrayList(),
4654:                            null);
4655:                    fail("Expected exception not received");
4656:                } catch (java.lang.IllegalArgumentException ex) {
4657:                    // Verification
4658:                    assertTrue(
4659:                            "Incorrect exception received: " + ex.toString(),
4660:                            (-1 < ex.getMessage().indexOf(
4661:                                    "bootClassPathElements")));
4662:                }
4663:            }
4664:
4665:            /**
4666:             * Tests upgradeComponent with a non-existent component.
4667:             * An exception is expected.
4668:             * @throws Exception if an unexpected error occurs.
4669:             */
4670:            public void testUpgradeComponentBadNotFound() throws Exception {
4671:                try {
4672:                    mCompFW.upgradeComponent(mBindingContext,
4673:                            Constants.BC_BOOTSTRAP_CLASS_NAME,
4674:                            mBindingBootClassPath, null);
4675:                    fail("Expected exception not received");
4676:                } catch (javax.jbi.JBIException ex) {
4677:                    // Verification
4678:                    assertTrue(
4679:                            "Incorrect exception received: " + ex.toString(),
4680:                            (-1 < ex.getMessage().indexOf("JBIFW1185")));
4681:                }
4682:            }
4683:
4684:            /**
4685:             * Tests upgradeComponent without first calling
4686:             * validateComponentForUpgrade(). An exception is expected.
4687:             * @throws Exception if an unexpected error occurs.
4688:             */
4689:            public void testUpgradeComponentBadNoValidate() throws Exception {
4690:                // Install a good binding
4691:                mBindingContext.setIsInstall(true);
4692:                mCompFW.loadBootstrap(mBindingContext,
4693:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
4694:                        mBindingBootClassPath, null);
4695:                mCompFW.installComponent(mBindingContext);
4696:
4697:                // Now upgrade without calling validateComponentForUpgrade() first.
4698:                try {
4699:                    mCompFW.upgradeComponent(mBindingContext,
4700:                            Constants.BC_BOOTSTRAP_CLASS_NAME,
4701:                            mBindingBootClassPath, null);
4702:                    fail("Expected exception not received");
4703:                } catch (javax.jbi.JBIException ex) {
4704:                    // Verification
4705:                    assertTrue(
4706:                            "Incorrect exception received: " + ex.toString(),
4707:                            (-1 < ex.getMessage().indexOf("JBIFW1188")));
4708:                }
4709:            }
4710:
4711:            /**
4712:             * Tests upgradeComponent with a missing shared library. An exception is
4713:             * expected.
4714:             * @throws Exception if an unexpected error occurs.
4715:             */
4716:            public void testUpgradeComponentBadMissingSharedLibrary()
4717:                    throws Exception {
4718:                // Install a good binding
4719:                mBindingContext.setIsInstall(true);
4720:                mCompFW.loadBootstrap(mBindingContext,
4721:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
4722:                        mBindingBootClassPath, null);
4723:                mCompFW.installComponent(mBindingContext);
4724:
4725:                // Now install the newly required shared libraries
4726:                mCompFW.installSharedLibrary(Constants.SL_1_NAME,
4727:                        Constants.SL_1_DESC, Constants.SL_1_ROOT, false,
4728:                        mSl1Elements);
4729:                mCompFW.installSharedLibrary(Constants.SL_2_NAME,
4730:                        Constants.SL_2_DESC, Constants.SL_2_ROOT, false,
4731:                        mSl2Elements);
4732:
4733:                // Create a list of Shared Library IDs to add
4734:                ArrayList slList = new ArrayList();
4735:                slList.add(Constants.SL_1_NAME);
4736:                slList.add(Constants.SL_2_NAME);
4737:
4738:                // Now validate for upgrade with a bootstrap class that supports upgrade
4739:                mCompFW.validateComponentForUpgrade(mBindingContext,
4740:                        Constants.BC_BOOTSTRAP_CLASS_NAME_UPGRADE,
4741:                        mBindingBootClassPath, slList);
4742:
4743:                // Now uninstall one of the shared libraries to force the upgrade to
4744:                // fail
4745:                mCompFW.uninstallSharedLibrary(Constants.SL_1_NAME);
4746:
4747:                // Now upgrade using the same install context. This should fail because
4748:                // one of the shared libraries is now missing.
4749:                try {
4750:                    System.setProperty(Constants.PROPERTY_COMPONENT_NAME,
4751:                            mBindingContext.getComponentName());
4752:                    mCompFW.upgradeComponent(mBindingContext,
4753:                            Constants.BC_BOOTSTRAP_CLASS_NAME_UPGRADE,
4754:                            mBindingBootClassPath, slList);
4755:
4756:                    fail("Expected exception not received");
4757:                } catch (javax.jbi.JBIException ex) {
4758:                    // Verification
4759:                    assertTrue("Incorrect exception message received: "
4760:                            + ex.toString(), (-1 < ex.getMessage().indexOf(
4761:                            "JBIFW1195")));
4762:                    assertTrue("Incorrect exception message received: "
4763:                            + ex.toString(), (-1 < ex.getMessage().indexOf(
4764:                            Constants.SL_1_NAME)));
4765:                    assertTrue("Incorrect exception message received: "
4766:                            + ex.toString(), (-1 == ex.getMessage().indexOf(
4767:                            Constants.SL_2_NAME)));
4768:
4769:                    Component comp = mCompReg.getComponent(Constants.BC_NAME);
4770:                    assertEquals("Component instance not restored: ",
4771:                            Constants.BC_BOOTSTRAP_CLASS_NAME, comp
4772:                                    .getBootstrapClassName());
4773:                }
4774:            }
4775:
4776:            /**
4777:             * Tests upgradeComponent with a failure loading the bootstrap class. An
4778:             * exception is expected.
4779:             * @throws Exception if an unexpected error occurs.
4780:             */
4781:            public void testUpgradeComponentBadBootstrapLoadFailed()
4782:                    throws Exception {
4783:                // Install a good binding
4784:                mBindingContext.setIsInstall(true);
4785:                mCompFW.loadBootstrap(mBindingContext,
4786:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
4787:                        mBindingBootClassPath, null);
4788:                mCompFW.installComponent(mBindingContext);
4789:
4790:                // Now validate for upgrade using the same install context
4791:                mCompFW.validateComponentForUpgrade(mBindingContext,
4792:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
4793:                        mBindingBootClassPath, null);
4794:
4795:                // Now upgrade using the same install context but a different bootstrap
4796:                // class name. This should fail because the bootstrap class cannot be
4797:                // loaded.
4798:                try {
4799:                    System.setProperty(Constants.PROPERTY_COMPONENT_NAME,
4800:                            mBindingContext.getComponentName());
4801:                    mCompFW.upgradeComponent(mBindingContext,
4802:                            "bad.bootstrap.class", mBindingBootClassPath, null);
4803:                    fail("Expected exception not received");
4804:                } catch (javax.jbi.JBIException ex) {
4805:                    // Verification
4806:                    assertTrue("Incorrect exception message received: "
4807:                            + ex.toString(), (-1 < ex.getMessage().indexOf(
4808:                            "JBIFW1192")));
4809:                    assertTrue("Incorrect exception message received: "
4810:                            + ex.toString(), (-1 < ex.getMessage().indexOf(
4811:                            "JBIFW2002")));
4812:
4813:                    Component comp = mCompReg.getComponent(Constants.BC_NAME);
4814:                    assertEquals("Component instance not restored: ",
4815:                            Constants.BC_BOOTSTRAP_CLASS_NAME, comp
4816:                                    .getBootstrapClassName());
4817:                }
4818:            }
4819:
4820:            /**
4821:             * Tests upgradeComponent with a failure in the component's upgrade method.
4822:             * An exception is expected.
4823:             * @throws Exception if an unexpected error occurs.
4824:             */
4825:            public void testUpgradeComponentBadUpgradeMethodFailed()
4826:                    throws Exception {
4827:                // Install a binding with a bad upgrade method
4828:                mBindingContext
4829:                        .setComponentName(Constants.BC_NAME_BAD_BOOTSTRAP_UPGRADE);
4830:                mBindingContext.setIsInstall(true);
4831:                mCompFW.loadBootstrap(mBindingContext,
4832:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
4833:                        mBindingBootClassPath, null);
4834:                mCompFW.installComponent(mBindingContext);
4835:
4836:                // Now validate for upgrade
4837:                mCompFW.validateComponentForUpgrade(mBindingContext,
4838:                        Constants.BC_BOOTSTRAP_CLASS_NAME_UPGRADE,
4839:                        mBindingBootClassPath, null);
4840:
4841:                // Now upgrade using the same install context. This should fail because
4842:                // the component's upgrade method will throw an exception.
4843:                try {
4844:                    System.setProperty(Constants.PROPERTY_COMPONENT_NAME,
4845:                            mBindingContext.getComponentName());
4846:                    mCompFW.upgradeComponent(mBindingContext,
4847:                            Constants.BC_BOOTSTRAP_CLASS_NAME_UPGRADE,
4848:                            mBindingBootClassPath, null);
4849:                    fail("Expected exception not received");
4850:                } catch (javax.jbi.JBIException ex) {
4851:                    // Verification
4852:                    assertTrue("Incorrect exception message received: "
4853:                            + ex.toString(), (-1 < ex.getMessage().indexOf(
4854:                            "JBIFW1193")));
4855:
4856:                    Component comp = mCompReg
4857:                            .getComponent(Constants.BC_NAME_BAD_BOOTSTRAP_UPGRADE);
4858:                    assertEquals("Component instance not restored: ",
4859:                            Constants.BC_BOOTSTRAP_CLASS_NAME, comp
4860:                                    .getBootstrapClassName());
4861:                }
4862:            }
4863:
4864:            /**
4865:             * Test an install with pre-defined logger names in the installation
4866:             * descriptor extension.
4867:             * @throws Exception if an unexpected error occurs.
4868:             */
4869:            public void testInstallComponentGoodLoggerNames() throws Exception {
4870:                // Create an XML document for the test.
4871:                String logName = "com.sun.jbi.testbinding.LifeCycle";
4872:                String displayName = "Life Cycle";
4873:                String xmlString = "<logging:Logging>"
4874:                        + "<logging:logger displayName=\"" + displayName
4875:                        + "\">" + logName + "</logging:logger>"
4876:                        + "</logging:Logging>";
4877:                DocumentFragment extension = createDocumentFragment(xmlString);
4878:
4879:                mBindingContext.setIsInstall(true);
4880:                mBindingContext.setInstallationDescriptorExtension(extension);
4881:                mCompFW.loadBootstrap(mBindingContext,
4882:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
4883:                        mBindingBootClassPath, null);
4884:                mCompFW.installComponent(mBindingContext);
4885:                Component comp = mCompReg.getComponent(Constants.BC_NAME);
4886:                assertTrue(
4887:                        "Got wrong status for binding. Expected installed, got "
4888:                                + comp.getStatusAsString(), comp.isInstalled());
4889:
4890:                // Verify that the Logger MBean was created and registered
4891:                assertTrue("LoggerMBean not created for binding", mContext
4892:                        .getMBeanServer().isRegistered(
4893:                                comp.getLoggerMBeanName()));
4894:
4895:                // Verify that the logger names were picked up.
4896:                String[] names = comp.getLoggerInstance().getLoggerNames();
4897:                assertEquals("Top-level logger not registered",
4898:                        Constants.BC_NAME, names[0]);
4899:                assertEquals("Pre-defined logger not registered",
4900:                        Constants.BC_NAME + "." + logName, names[1]);
4901:            }
4902:
4903:            /**
4904:             * Test an upgrade with pre-defined logger names in the installation
4905:             * descriptor extension.
4906:             * @throws Exception if an unexpected error occurs.
4907:             */
4908:            public void testUpgradeComponentGoodLoggerNames() throws Exception {
4909:                // Install a good binding that supports upgrade
4910:                mBindingContext.setIsInstall(true);
4911:                mCompFW.loadBootstrap(mBindingContext,
4912:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
4913:                        mBindingBootClassPath, null);
4914:                mCompFW.installComponent(mBindingContext);
4915:
4916:                // Add an installation descriptor extension with a logger name defined.
4917:                String logName = "com.sun.jbi.testbinding.LifeCycle";
4918:                String displayName = "Life Cycle";
4919:                String xmlString = "<logging:Logging>"
4920:                        + "<logging:logger displayName=\"" + displayName
4921:                        + "\">" + logName + "</logging:logger>"
4922:                        + "</logging:Logging>";
4923:                DocumentFragment extension = createDocumentFragment(xmlString);
4924:                mBindingContext.setInstallationDescriptorExtension(extension);
4925:
4926:                // Now validate for upgrade with a bootstrap class that supports upgrade
4927:                mCompFW.validateComponentForUpgrade(mBindingContext,
4928:                        Constants.BC_BOOTSTRAP_CLASS_NAME_UPGRADE,
4929:                        mBindingBootClassPath, null);
4930:
4931:                // Now upgrade using the same install context
4932:                System.setProperty(Constants.PROPERTY_COMPONENT_NAME,
4933:                        mBindingContext.getComponentName());
4934:                mCompFW.upgradeComponent(mBindingContext,
4935:                        Constants.BC_BOOTSTRAP_CLASS_NAME_UPGRADE,
4936:                        mBindingBootClassPath, null);
4937:
4938:                // Verification
4939:                Component comp = mCompReg.getComponent(Constants.BC_NAME);
4940:                assertEquals(
4941:                        "Component instance bootstrap class name not updated: ",
4942:                        Constants.BC_BOOTSTRAP_CLASS_NAME_UPGRADE, comp
4943:                                .getBootstrapClassName());
4944:
4945:                // Verify that the Logger MBean was created and registered
4946:                assertTrue("LoggerMBean not created for binding", mContext
4947:                        .getMBeanServer().isRegistered(
4948:                                comp.getLoggerMBeanName()));
4949:
4950:                // Verify that the logger names were picked up.
4951:                String[] names = comp.getLoggerInstance().getLoggerNames();
4952:                assertEquals("Top-level logger not registered",
4953:                        Constants.BC_NAME, names[0]);
4954:                assertEquals("Pre-defined logger not registered",
4955:                        Constants.BC_NAME + "." + logName, names[1]);
4956:            }
4957:
4958:            /**
4959:             * Utility method to create a document from an XML string provided by
4960:             * the caller, and then return the first child as a document fragment.
4961:             * @param xmlString an XML node in a String.
4962:             * @return the provided node as a DocumentFragment.
4963:             * @throws Exception if an unexpected error occurs.
4964:             */
4965:            private DocumentFragment createDocumentFragment(String xmlString)
4966:                    throws Exception {
4967:                Document doc = null;
4968:                DocumentFragment frag = null;
4969:
4970:                // Add a standard header to the XML string.
4971:
4972:                String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
4973:                        + xmlString;
4974:
4975:                // Create a DOM Document from the XML string.
4976:
4977:                ByteArrayInputStream xmlStream = new ByteArrayInputStream(xml
4978:                        .getBytes());
4979:                try {
4980:                    DocumentBuilder docBuilder = DocumentBuilderFactory
4981:                            .newInstance().newDocumentBuilder();
4982:                    docBuilder.setErrorHandler(new SAXErrorHandler());
4983:                    doc = docBuilder.parse(xmlStream);
4984:                } catch (javax.xml.parsers.ParserConfigurationException pcEx) {
4985:                    fail("Unexpected exception received: " + pcEx.toString());
4986:                } catch (org.xml.sax.SAXParseException spEx) {
4987:                    fail("Unexpected exception received: " + spEx.toString());
4988:                } catch (org.xml.sax.SAXException saxEx) {
4989:                    fail("Unexpected exception received: " + saxEx.toString());
4990:                }
4991:
4992:                frag = doc.createDocumentFragment();
4993:                frag.appendChild(doc.getFirstChild());
4994:                return frag;
4995:            }
4996:
4997:            /**
4998:             * This class provides the error handler for the SAX parser.
4999:             * @author Sun Microsystems, Inc.
5000:             */
5001:            class SAXErrorHandler implements  org.xml.sax.ErrorHandler {
5002:                /**
5003:                 * This is a callback from the XML parser used to handle warnings.
5004:                 * @param aSaxException SAXParseException is the warning.
5005:                 * @throws org.xml.sax.SAXException when finished logging.
5006:                 */
5007:                public void warning(org.xml.sax.SAXParseException aSaxException)
5008:                        throws org.xml.sax.SAXException {
5009:                    throw aSaxException;
5010:                }
5011:
5012:                /**
5013:                 * This is a callback from the XML parser used to handle errors.
5014:                 * @param aSaxException SAXParseException is the error.
5015:                 * @throws org.xml.sax.SAXException when finished logging.
5016:                 */
5017:                public void error(org.xml.sax.SAXParseException aSaxException)
5018:                        throws org.xml.sax.SAXException {
5019:                    throw aSaxException;
5020:                }
5021:
5022:                /**
5023:                 * This is a callback from the XML parser used to handle fatal errors.
5024:                 * @param aSaxException SAXParseException is the error.
5025:                 * @throws org.xml.sax.SAXException when finished logging.
5026:                 */
5027:                public void fatalError(
5028:                        org.xml.sax.SAXParseException aSaxException)
5029:                        throws org.xml.sax.SAXException {
5030:                    throw aSaxException;
5031:                }
5032:            }
5033:
5034:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.