Source Code Cross Referenced for TestComponentInstallationContext.java in  » ESB » open-esb » com » sun » jbi » management » 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.management 
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:         * @(#)TestComponentInstallationContext.java
025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026:         *
027:         * END_HEADER - DO NOT EDIT
028:         */
029:        package com.sun.jbi.management;
030:
031:        import java.io.File;
032:        import java.util.ArrayList;
033:        import java.util.Iterator;
034:        import java.util.List;
035:
036:        /**
037:         * Tests for the ComponentInstallationContext class.
038:         *
039:         * @author Sun Microsystems, Inc.
040:         */
041:        public class TestComponentInstallationContext extends
042:                junit.framework.TestCase {
043:            /**
044:             * Component Installation Context.
045:             */
046:            private ComponentInstallationContext mContext;
047:
048:            /**
049:             * Component class name.
050:             */
051:            private String mClassName;
052:
053:            /**
054:             * Component class path elements.
055:             */
056:            private List mClassPathElements;
057:
058:            /**
059:             * Component Context.
060:             */
061:            private javax.jbi.component.ComponentContext mComponentContext;
062:
063:            /**
064:             * Component name.
065:             */
066:            private String mComponentName;
067:
068:            /**
069:             * Component type.
070:             */
071:            private int mComponentType;
072:
073:            /**
074:             * Component description.
075:             */
076:            private String mDescription;
077:
078:            /**
079:             * Installation descriptor extension data.
080:             */
081:            private org.w3c.dom.DocumentFragment mExtensionData;
082:
083:            /**
084:             * Component install root directory.
085:             */
086:            private String mInstallRoot;
087:
088:            /**
089:             * Component work root directory
090:             */
091:            private String mWorkspaceRoot;
092:
093:            /**
094:             * JBI root directory
095:             */
096:            private String mJbiRoot;
097:
098:            /**
099:             * Current test name
100:             */
101:            private String mTestName;
102:
103:            /**
104:             * The constructor for this testcase, forwards the test name to
105:             * the jUnit TestCase base class.
106:             * @param aTestName String with the name of this test.
107:             */
108:            public TestComponentInstallationContext(String aTestName) {
109:                super (aTestName);
110:                mTestName = aTestName;
111:            }
112:
113:            /**
114:             * Setup for the test. This creates the ComponentInstallationContext
115:             * instance and other objects needed for the tests. It serves to test the
116:             * ComponentInstallationContext constructor.
117:             * @throws Exception when set up fails for any reason.
118:             */
119:            public void setUp() throws Exception {
120:                super .setUp();
121:                System.err.println("***** START of test " + mTestName);
122:
123:                // Create a ComponentInstallationContext instance
124:
125:                mComponentName = "AcmeSMTPBinding";
126:                mComponentType = com.sun.jbi.component.InstallationContext.BINDING;
127:                mClassName = "com.acme.smtp.BindingRuntime";
128:                mClassPathElements = new ArrayList();
129:                mClassPathElements.add("lib" + File.separator + "binding.jar");
130:                mClassPathElements.add("classes");
131:                mClassPathElements.add("lib" + File.separator + "acmeSMTP.jar");
132:                mExtensionData = buildExtensionData();
133:
134:                mContext = new ComponentInstallationContext(mComponentName,
135:                        mComponentType, mClassName, mClassPathElements,
136:                        mExtensionData);
137:
138:                // Set other fields used by tests
139:
140:                mComponentContext = null;
141:                mDescription = "Acme SMTP JBI Binding Component";
142:
143:                mJbiRoot = File.separator + "sun" + File.separator + "as8"
144:                        + File.separator + "domains" + File.separator
145:                        + "domain1" + File.separator + "jbi" + File.separator
146:                        + "bindings";
147:                mInstallRoot = mJbiRoot + File.separator + mComponentName;
148:                mWorkspaceRoot = mInstallRoot + File.separator + "workspace";
149:            }
150:
151:            /**
152:             * Cleanup for the test.
153:             * @throws Exception when tearDown fails for any reason.
154:             */
155:            public void tearDown() throws Exception {
156:                super .tearDown();
157:                System.err.println("***** END of test " + mTestName);
158:            }
159:
160:            // =============================  test methods ================================
161:
162:            /**
163:             * Test the method for getting the class path elements list.
164:             * @throws Exception if an unexpected error occurs.
165:             */
166:            public void testGetClassPathElements() {
167:                System.err
168:                        .println("mClassPathElements = " + mClassPathElements);
169:                assertEquals("Failure on getClassPathElements(): ",
170:                        mClassPathElements, mContext.getClassPathElements());
171:            }
172:
173:            /**
174:             * Test the method for setting the class path elements list.
175:             * @throws Exception if an unexpected error occurs.
176:             */
177:            public void testSetClassPathElements() {
178:                List classPathElements = convertPathList(mContext
179:                        .getClassPathElements());
180:                classPathElements.add("lib" + File.separator + "extra.jar");
181:                classPathElements.add("lib" + File.separator + "acmeExtra.jar");
182:                System.err.println("classPathElements = " + classPathElements);
183:                mContext.setClassPathElements(classPathElements);
184:                assertEquals("Failure on setClassPathElements(): ",
185:                        classPathElements, convertPathList(mContext
186:                                .getClassPathElements()));
187:            }
188:
189:            /**
190:             * Test the method for setting the class path elements list with a null
191:             * argument. An exception is expected.
192:             * @throws Exception if an unexpected error occurs.
193:             */
194:            public void testSetClassPathElementsBadNull() {
195:                List classPathElements = null;
196:                System.err.println("classPathElements = " + classPathElements);
197:                try {
198:                    mContext.setClassPathElements(classPathElements);
199:                    fail("Expected exception not received");
200:                } catch (IllegalArgumentException ex) {
201:                    // Verification
202:                    assertTrue(
203:                            "Incorrect exception received: " + ex.toString(),
204:                            (-1 < ex.getMessage().indexOf("JBIMA0701")));
205:                }
206:            }
207:
208:            /**
209:             * Test the method for setting the class path elements list with an empty
210:             * argument. An exception is expected.
211:             * @throws Exception if an unexpected error occurs.
212:             */
213:            public void testSetClassPathElementsBadEmpty() {
214:                List classPathElements = new ArrayList();
215:                System.err.println("classPathElements = " + classPathElements);
216:                try {
217:                    mContext.setClassPathElements(classPathElements);
218:                    fail("Expected exception not received");
219:                } catch (IllegalArgumentException ex) {
220:                    // Verification
221:                    assertTrue(
222:                            "Incorrect exception received: " + ex.toString(),
223:                            (-1 < ex.getMessage().indexOf("JBIMA0702")));
224:                }
225:            }
226:
227:            /**
228:             * Test the method for setting the class path elements list with an absolute
229:             * path in the argument. An exception is expected.
230:             * @throws Exception if an unexpected error occurs.
231:             */
232:            public void testSetClassPathElementsBadAbsolute() {
233:
234:                List classPathElements = new ArrayList();
235:                String prefix;
236:                if (File.separator.equals("\\")) {
237:                    prefix = "C:" + File.separator;
238:                } else {
239:                    prefix = File.separator;
240:                }
241:                classPathElements.add(prefix + "lib" + File.separator
242:                        + "extra.jar");
243:                System.err.println("classPathElements = " + classPathElements);
244:                try {
245:                    mContext.setClassPathElements(classPathElements);
246:                    fail("Expected exception not received");
247:                } catch (IllegalArgumentException ex) {
248:                    // Verification
249:                    assertTrue(
250:                            "Incorrect exception received: " + ex.toString(),
251:                            (-1 < ex.getMessage().indexOf("JBIMA0703")));
252:                }
253:            }
254:
255:            /**
256:             * Test the method for setting the class path elements list with invalid
257:             * separators in the argument. An exception is expected.
258:             * @throws Exception if an unexpected error occurs.
259:             */
260:            public void testSetClassPathElementsBadSeparators() {
261:
262:                List classPathElements = new ArrayList();
263:                String sep = File.separator.equals("/") ? "\\" : "/";
264:                classPathElements.add("lib" + sep + "extra.jar");
265:                System.err.println("classPathElements = " + classPathElements);
266:                try {
267:                    mContext.setClassPathElements(classPathElements);
268:                    fail("Expected exception not received");
269:                } catch (IllegalArgumentException ex) {
270:                    // Verification
271:                    assertTrue(
272:                            "Incorrect exception received: " + ex.toString(),
273:                            (-1 < ex.getMessage().indexOf("JBIMA0704")));
274:                }
275:            }
276:
277:            /**
278:             * Test the methods for setting and getting the component class name.
279:             * @throws Exception if an unexpected error occurs.
280:             */
281:            public void testSetGetComponentClassName() throws Exception {
282:                System.err.println("mClassName = " + mClassName);
283:                mContext.setComponentClassName(mClassName);
284:                assertEquals("Failure on getComponentClassName(): ",
285:                        mClassName, mContext.getComponentClassName());
286:            }
287:
288:            /**
289:             * Test the method for setting and getting the component name.
290:             * @throws Exception if an unexpected error occurs.
291:             */
292:            public void testSetGetComponentName() throws Exception {
293:                System.err.println("mComponentName = " + mComponentName);
294:                mContext.setComponentName(mComponentName);
295:                assertEquals("Failure on getComponentName(): ", mComponentName,
296:                        mContext.getComponentName());
297:            }
298:
299:            /**
300:             * Test the methods for setting and getting the component context.
301:             * @throws Exception if an unexpected error occurs.
302:             */
303:            public void testSetGetContext() throws Exception {
304:                System.err.println("mComponentContext = " + mComponentContext);
305:                mContext.setContext(mComponentContext);
306:                assertSame("Failure on setContext()/getContext(): ",
307:                        mComponentContext, mContext.getContext());
308:            }
309:
310:            /**
311:             * Test the methods for setting and getting the component description.
312:             * @throws Exception if an unexpected error occurs.
313:             */
314:            public void testSetGetDescription() throws Exception {
315:                System.err.println("mDescription = " + mDescription);
316:                mContext.setDescription(mDescription);
317:                assertEquals("Failure on set/getDescription(): ", mDescription,
318:                        mContext.getDescription());
319:            }
320:
321:            /**
322:             * Test the method for getting the installation descriptor extension data.
323:             * @throws Exception if an unexpected error occurs.
324:             */
325:            public void testGetInstallationDescriptorExtension()
326:                    throws Exception {
327:                System.err.println("mExtensionData = ");
328:                printExtensionData(mExtensionData);
329:                System.err.println("");
330:                assertSame("Failure on getInstallationDescriptorExtension(): ",
331:                        mExtensionData, mContext
332:                                .getInstallationDescriptorExtension());
333:            }
334:
335:            /**
336:             * Test the method for setting the installation descriptor extension data.
337:             * @throws Exception if an unexpected error occurs.
338:             */
339:            public void testSetInstallationDescriptorExtension()
340:                    throws Exception {
341:                System.err.println("mExtensionData = ");
342:                printExtensionData(mExtensionData);
343:                System.err.println("");
344:                mContext.setInstallationDescriptorExtension(mExtensionData);
345:                assertSame("Failure on setInstallationDescriptorExtension(): ",
346:                        mExtensionData, mContext
347:                                .getInstallationDescriptorExtension());
348:            }
349:
350:            /**
351:             * Test the methods for setting/getting the component install root.
352:             * @throws Exception if an unexpected error occurs.
353:             */
354:            public void testSetGetInstallRoot() throws Exception {
355:                System.err.println("mInstallRoot = " + mInstallRoot);
356:                mContext.setInstallRoot(mInstallRoot);
357:                assertEquals("Failure on setInstallRoot()/getInstallRoot(): ",
358:                        mInstallRoot, mContext.getInstallRoot());
359:            }
360:
361:            /**
362:             * Test the methods for setting and getting the component work root
363:             * directory.
364:             * @throws Exception if an unexpected error occurs.
365:             */
366:            public void testSetGetWorkspaceRoot() throws Exception {
367:                System.err.println("mWorkspaceRoot = " + mWorkspaceRoot);
368:                mContext.setWorkspaceRoot(mWorkspaceRoot);
369:                assertEquals(
370:                        "Failure on getWorkspaceRoot() after setWorkspaceRoot(): ",
371:                        mWorkspaceRoot, mContext.getWorkspaceRoot());
372:            }
373:
374:            /**
375:             * Test the method for testing for a binding component type.
376:             * @throws Exception if an unexpected error occurs.
377:             */
378:            public void testIsBinding() throws Exception {
379:                assertTrue("Failure on isBinding(): ", mContext.isBinding());
380:            }
381:
382:            /**
383:             * Test the methods for setting/testing the self-first flag for the
384:             * bootstrap class loader.
385:             * @throws Exception if an unexpected error occurs.
386:             */
387:            public void testSetIsBootstrapClassLoaderSelfFirst()
388:                    throws Exception {
389:                assertFalse("Failure on isBootstrapClassLoaderSelfFirst() "
390:                        + "after constructor: ", mContext
391:                        .isBootstrapClassLoaderSelfFirst());
392:
393:                mContext.setBootstrapClassLoaderSelfFirst();
394:                assertTrue("Failure on isBootstrapClassLoaderSelfFirst() "
395:                        + "after setBootstrapClassLoaderSelfFirst(): ",
396:                        mContext.isBootstrapClassLoaderSelfFirst());
397:
398:            }
399:
400:            /**
401:             * Test the methods for setting/testing the self-first flag for the
402:             * component class loader.
403:             * @throws Exception if an unexpected error occurs.
404:             */
405:            public void testSetIsComponentClassLoaderSelfFirst()
406:                    throws Exception {
407:                assertFalse("Failure on isComponentClassLoaderSelfFirst() "
408:                        + "after constructor: ", mContext
409:                        .isComponentClassLoaderSelfFirst());
410:
411:                mContext.setComponentClassLoaderSelfFirst();
412:                assertTrue("Failure on isComponentClassLoaderSelfFirst() "
413:                        + "after setComponentClassLoaderSelfFirst(): ",
414:                        mContext.isComponentClassLoaderSelfFirst());
415:
416:            }
417:
418:            /**
419:             * Test the method for testing for an engine component type.
420:             * @throws Exception if an unexpected error occurs.
421:             */
422:            public void testIsEngine() throws Exception {
423:                assertFalse("Failure on isEngine(): ", mContext.isEngine());
424:            }
425:
426:            /**
427:             * Test the method for determining installation/uninstallation.
428:             * @throws Exception if an unexpected error occurs.
429:             */
430:            public void testIsInstall() throws Exception {
431:                mContext.setIsInstall(true);
432:                assertTrue("Failure on isInstall() after setIsInstall(true): ",
433:                        mContext.isInstall());
434:
435:                mContext.setIsInstall(false);
436:                assertFalse(
437:                        "Failure on isInstall() after setIsInstall(false): ",
438:                        mContext.isInstall());
439:            }
440:
441:            /**
442:             * Private method to construct DocumentFragment for extension data.
443:             * @throws Exception if an unexpected error occurs.
444:             */
445:            private org.w3c.dom.DocumentFragment buildExtensionData()
446:                    throws Exception {
447:                javax.xml.parsers.DocumentBuilderFactory docBuilderFactory = javax.xml.parsers.DocumentBuilderFactory
448:                        .newInstance();
449:                javax.xml.parsers.DocumentBuilder docBuilder = docBuilderFactory
450:                        .newDocumentBuilder();
451:
452:                org.w3c.dom.Document doc = docBuilder.newDocument();
453:                org.w3c.dom.DocumentFragment frag = doc
454:                        .createDocumentFragment();
455:                org.w3c.dom.Text text1 = doc.createTextNode("409");
456:                org.w3c.dom.Element element1 = doc.createElement("acmePort");
457:                element1.appendChild(text1);
458:                org.w3c.dom.Text text2 = doc.createTextNode("localhost");
459:                org.w3c.dom.Element element2 = doc.createElement("acmeHost");
460:                element2.appendChild(text2);
461:                frag.appendChild(element1);
462:                frag.appendChild(element2);
463:
464:                return frag;
465:            }
466:
467:            /**
468:             * Private method to print a DocumentFragment to System.out.
469:             * @throws Exception if an unexpected error occurs.
470:             */
471:            private void printExtensionData(
472:                    org.w3c.dom.DocumentFragment fragment) throws Exception {
473:                javax.xml.transform.TransformerFactory tFactory = javax.xml.transform.TransformerFactory
474:                        .newInstance();
475:                javax.xml.transform.Transformer transformer = tFactory
476:                        .newTransformer();
477:
478:                javax.xml.transform.dom.DOMSource source = new javax.xml.transform.dom.DOMSource(
479:                        fragment);
480:                javax.xml.transform.stream.StreamResult result = new javax.xml.transform.stream.StreamResult(
481:                        System.err);
482:                transformer.transform(source, result);
483:            }
484:
485:            /**
486:             * Convert a file path specification to the platform-specific form by using
487:             * the value of File.separator. Internally all paths are stored in Unix
488:             * form using the forward slash ('/') as the separator.
489:             * @param path the file path specification to be converted.
490:             * @return the converted file path.
491:             */
492:            private String convertPath(String path) {
493:                String retPath;
494:                if (File.separator.equals("\\")) {
495:                    System.err.println("converting '" + path
496:                            + "' to Windows form");
497:                    retPath = path.replace('/', File.separatorChar);
498:                } else {
499:                    retPath = path;
500:                }
501:                return retPath;
502:            }
503:
504:            /**
505:             * Convert a list of file path specifications to the platform-specific form
506:             * by using the value of File.separator. Internally all paths are stored in
507:             * Unix form using the forward slash ('/') as the separator.
508:             * @param pathList the list of file path specifications to be converted.
509:             * @return a list of String objects containing converted file paths.
510:             */
511:            private List convertPathList(List pathList) {
512:                List retList;
513:                if (File.separator.equals("\\")) {
514:                    retList = new ArrayList();
515:                    Iterator i = pathList.iterator();
516:                    while (i.hasNext()) {
517:                        String e = ((String) i.next()).replace('/',
518:                                File.separatorChar);
519:                        System.err.println("new value is '" + e + "'");
520:                        retList.add(e);
521:                    }
522:                } else {
523:                    retList = pathList;
524:                }
525:                return retList;
526:            }
527:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.