Source Code Cross Referenced for TestComponentOperation.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) 


001:        /*
002:         * BEGIN_HEADER - DO NOT EDIT
003:         *
004:         * The contents of this file are subject to the terms
005:         * of the Common Development and Distribution License
006:         * (the "License").  You may not use this file except
007:         * in compliance with the License.
008:         *
009:         * You can obtain a copy of the license at
010:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011:         * See the License for the specific language governing
012:         * permissions and limitations under the License.
013:         *
014:         * When distributing Covered Code, include this CDDL
015:         * HEADER in each file and include the License file at
016:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017:         * If applicable add the following below this CDDL HEADER,
018:         * with the fields enclosed by brackets "[]" replaced with
019:         * your own identifying information: Portions Copyright
020:         * [year] [name of copyright owner]
021:         */
022:
023:        /*
024:         * @(#)TestComponentOperation.java
025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026:         *
027:         * END_HEADER - DO NOT EDIT
028:         */
029:        package com.sun.jbi.framework;
030:
031:        import com.sun.jbi.management.ComponentInstallationContext;
032:
033:        import java.util.ArrayList;
034:
035:        /**
036:         * Tests for the ComponentOperation class.
037:         *
038:         * @author Sun Microsystems, Inc.
039:         */
040:        public class TestComponentOperation extends junit.framework.TestCase {
041:            /**
042:             * OperationCounter.
043:             */
044:            private OperationCounter mCounter;
045:
046:            /**
047:             * ComponentOperation (extends Operation).
048:             */
049:            private ComponentOperation mOperation;
050:
051:            /**
052:             * Helper class to setup environment for testing.
053:             */
054:            private EnvironmentSetup mSetup;
055:
056:            /**
057:             * Instance of the EnvironmentContext class.
058:             */
059:            private EnvironmentContext mContext;
060:
061:            /**
062:             * Local instance of the ComponentInstallationContext class.
063:             */
064:            private ComponentInstallationContext mBindingContext;
065:
066:            /**
067:             * Local instance of the ComponentInstallationContext class.
068:             */
069:            private ComponentInstallationContext mEngineContext;
070:
071:            /**
072:             * Instance of the ComponentFramework class.
073:             */
074:            private ComponentFramework mCompFW;
075:
076:            /**
077:             * Instance of the ComponentRegistry class.
078:             */
079:            private ComponentRegistry mCompReg;
080:
081:            /**
082:             * Instance of Component for the binding.
083:             */
084:            private Component mBinding;
085:
086:            /**
087:             * Instance of Component for the engine.
088:             */
089:            private Component mEngine;
090:
091:            /**
092:             * Local instance of the binding bootstrap class path array.
093:             */
094:            private ArrayList mBindingBootClassPath;
095:
096:            /**
097:             * Local instance of the binding lifecycle class path array.
098:             */
099:            private ArrayList mBindingLifeClassPath;
100:
101:            /**
102:             * Local instance of the engine bootstrap class path array.
103:             */
104:            private ArrayList mEngineBootClassPath;
105:
106:            /**
107:             * Local instance of the engine lifecycle class path array.
108:             */
109:            private ArrayList mEngineLifeClassPath;
110:
111:            /**
112:             * Install root for components.
113:             */
114:            private String mInstallRoot;
115:
116:            /**
117:             * Constant for invalid operation value.
118:             */
119:            private static final int BAD_OPER = 999999;
120:
121:            /**
122:             * The constructor for this testcase, forwards the test name to
123:             * the jUnit TestCase base class.
124:             * @param aTestName String with the name of this test.
125:             */
126:            public TestComponentOperation(String aTestName) {
127:                super (aTestName);
128:            }
129:
130:            /**
131:             * Setup for the test. This creates objects needed for the test.
132:             * @throws Exception when set up fails for any reason.
133:             */
134:            public void setUp() throws Exception {
135:                super .setUp();
136:                mCounter = new OperationCounter();
137:                String srcroot = System.getProperty("junit.srcroot") + "/";
138:                mInstallRoot = srcroot;
139:
140:                // Create and initialize the EnvironmentContext. Create, initialize,
141:                // and start up the Component Registry and Component Framework.
142:
143:                mSetup = new EnvironmentSetup();
144:                mContext = mSetup.getEnvironmentContext();
145:                mSetup.startup(true, true);
146:                mCompFW = mContext.getComponentFramework();
147:                mCompReg = mContext.getComponentRegistry();
148:
149:                // Create binding class path / class name lists
150:
151:                mBindingBootClassPath = new ArrayList();
152:                mBindingBootClassPath.add(srcroot
153:                        + Constants.BC_BOOTSTRAP_CLASS_PATH);
154:                mBindingLifeClassPath = new ArrayList();
155:                mBindingLifeClassPath.add(Constants.BC_LIFECYCLE_CLASS_PATH);
156:
157:                // Create engine class path lists
158:
159:                mEngineBootClassPath = new ArrayList();
160:                mEngineBootClassPath.add(srcroot
161:                        + Constants.SE_BOOTSTRAP_CLASS_PATH);
162:                mEngineLifeClassPath = new ArrayList();
163:                mEngineLifeClassPath.add(Constants.SE_LIFECYCLE_CLASS_PATH);
164:
165:                // Install a test binding and a test engine
166:
167:                mBindingContext = new ComponentInstallationContext(
168:                        Constants.BC_NAME,
169:                        ComponentInstallationContext.BINDING,
170:                        Constants.BC_LIFECYCLE_CLASS_NAME,
171:                        mBindingLifeClassPath, null);
172:                mBindingContext.setInstallRoot(mInstallRoot);
173:                mBindingContext.setIsInstall(true);
174:                mCompFW.loadBootstrap(mBindingContext,
175:                        Constants.BC_BOOTSTRAP_CLASS_NAME,
176:                        mBindingBootClassPath, null);
177:                mCompFW.installComponent(mBindingContext);
178:                mBinding = mCompReg.getComponent(Constants.BC_NAME);
179:                mEngineContext = new ComponentInstallationContext(
180:                        Constants.SE_NAME, ComponentInstallationContext.ENGINE,
181:                        Constants.SE_LIFECYCLE_CLASS_NAME,
182:                        mEngineLifeClassPath, null);
183:                mEngineContext.setInstallRoot(mInstallRoot);
184:                mEngineContext.setIsInstall(true);
185:                mCompFW.loadBootstrap(mEngineContext,
186:                        Constants.SE_BOOTSTRAP_CLASS_NAME,
187:                        mEngineBootClassPath, null);
188:                mCompFW.installComponent(mEngineContext);
189:                mEngine = mCompReg.getComponent(Constants.SE_NAME);
190:            }
191:
192:            /**
193:             * Cleanup for the test.
194:             * @throws Exception when tearDown fails for any reason.
195:             */
196:            public void tearDown() throws Exception {
197:                super .tearDown();
198:                mSetup.shutdown(true, true);
199:            }
200:
201:            // =============================  test methods ================================
202:
203:            /**
204:             * Tests constructor with bad operation parameter. An exception is expected.
205:             * @throws Exception if an unexpected error occurs.
206:             */
207:            public void testConstructorBadOperation() throws Exception {
208:                try {
209:                    mOperation = new ComponentOperation(mCounter, mBinding,
210:                            BAD_OPER);
211:                    fail("Expected exception not received");
212:                } catch (java.lang.IllegalArgumentException ex) {
213:                    // Verification
214:                    assertTrue("Unexpected exception received: "
215:                            + ex.toString(), (-1 < ex.getMessage().indexOf(
216:                            "Invalid argument")));
217:                }
218:            }
219:
220:            /**
221:             * Tests constructor with null component parameter. An exception is
222:             * expected.
223:             * @throws Exception if an unexpected error occurs.
224:             */
225:            public void testConstructorNullComponent() throws Exception {
226:                try {
227:                    mOperation = new ComponentOperation(mCounter, null,
228:                            ComponentOperation.STARTUP);
229:                    fail("Expected exception not received");
230:                } catch (java.lang.IllegalArgumentException ex) {
231:                    // Verification
232:                    assertTrue("Unexpected exception received: "
233:                            + ex.toString(), (-1 < ex.getMessage().indexOf(
234:                            "Null argument")));
235:                }
236:            }
237:
238:            /**
239:             * Tests getComponent.
240:             * @throws Exception if an unexpected error occurs.
241:             */
242:            public void testGetComponent() throws Exception {
243:                mOperation = new ComponentOperation(mCounter, mBinding,
244:                        ComponentOperation.STARTUP);
245:                // Verification
246:                assertSame("Wrong result received: ", mBinding, mOperation
247:                        .getComponent());
248:            }
249:
250:            /**
251:             * Tests getOperation.
252:             * @throws Exception if an unexpected error occurs.
253:             */
254:            public void testGetOperation() throws Exception {
255:                mOperation = new ComponentOperation(mCounter, mBinding,
256:                        ComponentOperation.STARTUP);
257:                // Verification
258:                assertEquals("Wrong result received: ", new Integer(
259:                        ComponentOperation.STARTUP), new Integer(mOperation
260:                        .getOperation()));
261:            }
262:
263:            /**
264:             * Tests an INITIALIZE operation on a binding component.
265:             * @throws Throwable if an unexpected error occurs.
266:             */
267:            public void testProcessInitializeBinding() throws Throwable {
268:                Object bcInstance = mBinding.getLifeCycleInstance(true);
269:                mOperation = new ComponentOperation(mCounter, mBinding,
270:                        ComponentOperation.INITIALIZE);
271:
272:                mOperation.process(null);
273:                assertTrue("Failed to initialize binding", mBinding.isStopped());
274:            }
275:
276:            /**
277:             * Tests a STARTUP operation on a binding component.
278:             * @throws Throwable if an unexpected error occurs.
279:             */
280:            public void testProcessStartupBinding() throws Throwable {
281:                mOperation = new ComponentOperation(mCounter, mBinding,
282:                        ComponentOperation.STARTUP);
283:
284:                mOperation.process(null);
285:                assertTrue("Failed to startup binding", mBinding.isStarted());
286:            }
287:
288:            /**
289:             * Tests a SHUTDOWN operation on a binding component.
290:             * @throws Throwable if an unexpected error occurs.
291:             */
292:            public void testProcessShutdownBinding() throws Throwable {
293:                mCompFW.startComponent(mBinding);
294:                mOperation = new ComponentOperation(mCounter, mBinding,
295:                        ComponentOperation.SHUTDOWN);
296:
297:                mOperation.process(null);
298:                assertTrue("Failed to shutdown binding", mBinding.isInstalled());
299:            }
300:
301:            /**
302:             * Tests an INITIALIZE operation on a service engine.
303:             * @throws Throwable if an unexpected error occurs.
304:             */
305:            public void testProcessInitializeEngine() throws Throwable {
306:
307:                Object seInstance = mEngine.getLifeCycleInstance(true);
308:
309:                mOperation = new ComponentOperation(mCounter, mEngine,
310:                        ComponentOperation.INITIALIZE);
311:
312:                mOperation.process(null);
313:                assertTrue("Failed to initialize engine", mEngine.isStopped());
314:            }
315:
316:            /**
317:             * Tests a STARTUP operation on a service engine.
318:             * @throws Throwable if an unexpected error occurs.
319:             */
320:            public void testProcessStartupEngine() throws Throwable {
321:                mOperation = new ComponentOperation(mCounter, mEngine,
322:                        ComponentOperation.STARTUP);
323:
324:                mOperation.process(null);
325:                assertTrue("Failed to startup engine", mEngine.isStarted());
326:            }
327:
328:            /**
329:             * Tests a SHUTDOWN operation on a service engine.
330:             * @throws Throwable if an unexpected error occurs.
331:             */
332:            public void testProcessShutdownEngine() throws Throwable {
333:                mCompFW.startComponent(mEngine);
334:                mOperation = new ComponentOperation(mCounter, mEngine,
335:                        ComponentOperation.SHUTDOWN);
336:
337:                mOperation.process(null);
338:                assertTrue("Failed to shutdown engine", mEngine.isInstalled());
339:            }
340:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.