Source Code Cross Referenced for TestEventForwarder.java in  » ESB » open-esb » java4ant » 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 » java4ant 
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:         * @(#)TestEventForwarderMBean.java
025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026:         *
027:         * END_HEADER - DO NOT EDIT
028:         */
029:        package java4ant;
030:
031:        import java.io.IOException;
032:        import java.util.ArrayList;
033:        import java.util.Iterator;
034:        import java.util.List;
035:        import java.util.Properties;
036:        import java.util.concurrent.ExecutorService;
037:        import java.util.concurrent.Executors;
038:
039:        import javax.management.Attribute;
040:        import javax.management.AttributeNotFoundException;
041:        import javax.management.InstanceNotFoundException;
042:        import javax.management.InvalidAttributeValueException;
043:        import javax.management.ListenerNotFoundException;
044:        import javax.management.MBeanException;
045:        import javax.management.MBeanServerConnection;
046:        import javax.management.MalformedObjectNameException;
047:        import javax.management.Notification;
048:        import javax.management.NotificationListener;
049:        import javax.management.ObjectName;
050:        import javax.management.ReflectionException;
051:        import javax.management.openmbean.CompositeData;
052:        import javax.management.remote.JMXConnector;
053:        import javax.management.remote.JMXConnectorFactory;
054:        import javax.management.remote.JMXServiceURL;
055:
056:        import com.sun.enterprise.deployment.backend.DeploymentStatus;
057:
058:        public class TestEventForwarder implements  NotificationListener {
059:
060:            private static final String EVENT_TYPE_ALERT = "Alert";
061:            private static final String SERVER_TYPE_INTEGRATION = "INTEGRATION";
062:            private static final String PHOST_COMPDATA_ELEMENT = "EVENTPHYSICALHOST";
063:            private static final String SERVERTYPE_COMPDATA_ELEMENT = "EVENTSERVERTYPE";
064:            private static final String COMPONENTTYPE_TEST_VALUE = "EventManagement";
065:            private static final String COMPONENTTYPE_COMPDATA_ELEMENT = "EVENTCOMPONENTTYPE";
066:            private static final String TYPE_COMPDATA_ELEMENT = "EVENTTYPE";
067:            private static final String SEVERITY_COMPDATA_ELEMENT = "EVENTSEVERITY";
068:            private static final int SEVERITY_TEST_VALUE = 1;
069:            private static final String MSGCODE_TEST_VALUE = "CUSTOM-00001";
070:            private static final String MSGCODE_COMPDATA_ELEMENT = "EVENTMESSAGECODE";
071:            private static final String MSGDETAILS_TEST_VALUE = "This is single event test";
072:            private static final String MSGDETAILS_COMPDATA_ELEMENT = "EVENTMESSAGEDETAILS";
073:
074:            private static final String FORWARDER_MBEAN_NAME = "EventManagement:name=EventForwarderMBean";
075:            private static final String EVENTMANAGEMENT_CHANNEL_MBEAN_NAME = "EventManagement:name=EventManagementChannelSupportMBean";
076:            private static final String GF_CONFIG_MBEAN_NAME = "com.sun.appserv:type=applications,category=config";
077:
078:            private static final String DATABASE_ALERT_TABLE_NAME__ATTRIBUTE_NAME = "alertTableName";
079:            private static final String EVENT_TEST_OPERATION = "testSendEvent";
080:            private static final String DATABASE_TYPE_ATTRIBUTE_NAME = "DBType";
081:
082:            private static final String AVAILABILITY_ENABLED = "availabilityenabled";
083:            private static final String DEFAULT_ENABLE = "true";
084:            private static final String ARCHIVE_NAME = "archiveName";
085:            private static final String NAME = "name";
086:            private static final String TYPE = "type";
087:            private static final String APP_NAME = "TestEventManagement";
088:            private static final String APP_TYPE = "web";
089:
090:            private static final String DATABASE_TYPE_TEST_VALUE = "ORACLE";
091:            private static final String DATABASE_TABLE_TEST_VALUE = "TestTable";
092:
093:            private MBeanServerConnection mCASMBeanServerConnection;
094:            private MBeanServerConnection mInstanceMBeanServerConnection;
095:            private static final String RESULT_PREFIX = "##### Result of ";
096:
097:            private static final String USER = "jmx.user";
098:            private static final String PASSWORD = "jmx.password";
099:            private static final String PROVIDER = "jmx.provider";
100:            private static final String TARGET = "target";
101:            private static final String SUPPORT_APP_LOC = "test.support.app";
102:            private static final String INSTANCE_NAME = "instance.target.name";
103:            private static final String INSTANCE_JMX_PORT = "instance.jmx.port";
104:
105:            private ObjectName mForwarderObjectName;
106:            private ObjectName mForwarderSupportObjectName;
107:            private ObjectName mConfigObjectName;
108:            private CompositeData event;
109:            private int failureCount;
110:            private ExecutorService mExecutorService;
111:            private NotificationListener mNotificationListener;
112:            private boolean exit = false;
113:
114:            public TestEventForwarder(String aJmxURL, String aSupportAppLocation)
115:                    throws Exception {
116:                System.setProperty(USER, "admin");
117:                System.setProperty(PASSWORD, "adminadmin");
118:                System.setProperty(PROVIDER, aJmxURL);
119:                System.setProperty(TARGET, "server");
120:                //        System.setProperty(INSTANCE_NAME, "instance1");
121:                //        System.setProperty(INSTANCE_JMX_PORT, "8690");
122:                System.setProperty(SUPPORT_APP_LOC, aSupportAppLocation);
123:
124:                getMBeanServerConnections();
125:                getObjectNames();
126:                mNotificationListener = new EventHandler();
127:                mExecutorService = Executors.newFixedThreadPool(2);
128:
129:            }
130:
131:            public TestEventForwarder() throws Exception {
132:                getMBeanServerConnections();
133:                getObjectNames();
134:                mNotificationListener = new EventHandler();
135:                mExecutorService = Executors.newFixedThreadPool(2);
136:
137:            }
138:
139:            private void getMBeanServerConnections() throws Exception {
140:
141:                java.util.Map<String, String[]> env = new java.util.HashMap<String, String[]>();
142:                String user = System.getProperty(USER);
143:                String pass = System.getProperty(PASSWORD);
144:                String[] credentials = new String[] { user, pass };
145:                env.put("jmx.remote.credentials", credentials);
146:
147:                String jmxProvider = System.getProperty(PROVIDER);
148:                JMXServiceURL casJmxServiceUrl = new JMXServiceURL(jmxProvider);
149:                JMXConnector connector = JMXConnectorFactory.connect(
150:                        casJmxServiceUrl, env);
151:                mCASMBeanServerConnection = connector
152:                        .getMBeanServerConnection();
153:                boolean isInstanceTest = System.getProperty(INSTANCE_NAME) != null ? true
154:                        : false;
155:
156:                if (isInstanceTest) {
157:                    // get connection to instance1
158:                    JMXServiceURL instnaceJmxURL = new JMXServiceURL(
159:                            constructInstanceJmxURL(jmxProvider));
160:
161:                    JMXConnector instanceConnector = JMXConnectorFactory
162:                            .connect(instnaceJmxURL, env);
163:                    mInstanceMBeanServerConnection = instanceConnector
164:                            .getMBeanServerConnection();
165:                    System.out.println("get mbean connection to  "
166:                            + System.getProperty(INSTANCE_NAME));
167:                }
168:            }
169:
170:            private String constructInstanceJmxURL(String jmxProvider) {
171:                String urlPostFix = "/management/rmi-jmx-connector";
172:                String subURL = jmxProvider.substring(0, jmxProvider
173:                        .indexOf(urlPostFix));
174:                int portNumberSepIndex = subURL.lastIndexOf(":");
175:                String portNumber = subURL.substring(portNumberSepIndex + 1);
176:                String instanceJMXUrl = jmxProvider.replace(portNumber, System
177:                        .getProperty(INSTANCE_JMX_PORT));
178:                return instanceJMXUrl;
179:
180:            }
181:
182:            private void getObjectNames() {
183:                try {
184:                    mForwarderObjectName = new ObjectName(FORWARDER_MBEAN_NAME);
185:                } catch (MalformedObjectNameException e) {
186:                    System.out.println(FORWARDER_MBEAN_NAME
187:                            + "is invalid object name");
188:                } catch (NullPointerException e) {
189:                }
190:                try {
191:                    mForwarderSupportObjectName = new ObjectName(
192:                            EVENTMANAGEMENT_CHANNEL_MBEAN_NAME);
193:                } catch (MalformedObjectNameException e) {
194:                    System.out.println(EVENTMANAGEMENT_CHANNEL_MBEAN_NAME
195:                            + "is invalid object name");
196:                    failureCount++;
197:                } catch (NullPointerException e) {
198:                    failureCount++;
199:                }
200:
201:                try {
202:                    mConfigObjectName = new ObjectName(GF_CONFIG_MBEAN_NAME);
203:                } catch (MalformedObjectNameException e) {
204:                    System.out.println(GF_CONFIG_MBEAN_NAME
205:                            + "is invalid object name");
206:                    failureCount++;
207:                } catch (NullPointerException e) {
208:                    failureCount++;
209:                }
210:            }
211:
212:            private void disablePersistence() {
213:                try {
214:                    Attribute persistenceAttribute = new Attribute(
215:                            "enableTargetPersistence", false);
216:                    mCASMBeanServerConnection.setAttribute(
217:                            mForwarderObjectName, persistenceAttribute);
218:                } catch (InstanceNotFoundException e) {
219:                    System.out.println("Mbean with object name '"
220:                            + FORWARDER_MBEAN_NAME
221:                            + "' instance not found : \n" + e);
222:                    failureCount++;
223:                } catch (MBeanException e) {
224:                    System.out.println("Mbean with object name '"
225:                            + FORWARDER_MBEAN_NAME + "' "
226:                            + EVENT_TEST_OPERATION
227:                            + " mathod throw exception: \n" + e);
228:                    failureCount++;
229:                } catch (ReflectionException e) {
230:                    System.out.println("Mbean with object name '"
231:                            + FORWARDER_MBEAN_NAME
232:                            + "' reflection exception: \n" + e);
233:                    failureCount++;
234:                } catch (IOException e) {
235:                    System.out
236:                            .println("communication to Mbean with object name '"
237:                                    + FORWARDER_MBEAN_NAME + "' failed\n" + e);
238:                    failureCount++;
239:                } catch (AttributeNotFoundException e) {
240:                    System.out
241:                            .println("Mbean with object name '"
242:                                    + FORWARDER_MBEAN_NAME
243:                                    + "' does not have attribute named 'enableTargetPersistence'");
244:                    failureCount++;
245:                } catch (InvalidAttributeValueException e) {
246:                    System.out
247:                            .println("Mbean with object name '"
248:                                    + FORWARDER_MBEAN_NAME
249:                                    + "' attribute named 'enableTargetPersistence' is not boolean type");
250:                    failureCount++;
251:                }
252:
253:            }
254:
255:            private boolean addEventListener() {
256:                boolean added = false;
257:                // add the inner classs as a listener
258:                try {
259:                    mCASMBeanServerConnection.addNotificationListener(
260:                            mForwarderSupportObjectName, mNotificationListener,
261:                            null, new Object());
262:                    System.out.println("Added notification listener ");
263:                    return true;
264:                } catch (InstanceNotFoundException e) {
265:                    System.out.println("Mbean with object name '"
266:                            + EVENTMANAGEMENT_CHANNEL_MBEAN_NAME
267:                            + "' instance not found : \n" + e);
268:                    failureCount++;
269:                    return added;
270:                } catch (IOException e) {
271:                    System.out
272:                            .println("communication to Mbean with object name '"
273:                                    + EVENTMANAGEMENT_CHANNEL_MBEAN_NAME
274:                                    + "' failed\n" + e);
275:                    failureCount++;
276:                    return added;
277:                }
278:
279:            }
280:
281:            private void testSendEvent()
282:
283:            {
284:                MBeanServerConnection aMBeanServerConnection = null;
285:                String serverName = null;
286:                if (System.getProperty(INSTANCE_NAME) == null) {
287:                    serverName = System.getProperty(TARGET);
288:                    aMBeanServerConnection = mCASMBeanServerConnection;
289:                } else {
290:                    serverName = System.getProperty(INSTANCE_NAME);
291:                    aMBeanServerConnection = this .mInstanceMBeanServerConnection;
292:                }
293:
294:                Object[] params = { MSGDETAILS_TEST_VALUE, SEVERITY_TEST_VALUE };
295:                String[] signature = { "java.lang.String", "java.lang.Integer" };
296:                try {
297:                    aMBeanServerConnection.invoke(mForwarderObjectName,
298:                            EVENT_TEST_OPERATION, params, signature);
299:                    System.out.println("Invoked test send event");
300:                } catch (InstanceNotFoundException e) {
301:                    System.out.println(serverName
302:                            + " - Mbean with object name '"
303:                            + FORWARDER_MBEAN_NAME
304:                            + "' instance not found : \n" + e);
305:                    failureCount++;
306:                    return;
307:                } catch (MBeanException e) {
308:                    System.out.println(serverName
309:                            + " - Mbean with object name '"
310:                            + FORWARDER_MBEAN_NAME + "' "
311:                            + EVENT_TEST_OPERATION
312:                            + " mathod throw exception: \n" + e);
313:                    failureCount++;
314:                    return;
315:                } catch (ReflectionException e) {
316:                    System.out.println(serverName
317:                            + " - Mbean with object name '"
318:                            + FORWARDER_MBEAN_NAME
319:                            + "' reflection exception: \n" + e);
320:                    failureCount++;
321:                    return;
322:                } catch (IOException e) {
323:                    System.out.println(serverName
324:                            + " - communication to Mbean with object name '"
325:                            + FORWARDER_MBEAN_NAME + "' failed\n" + e);
326:                    failureCount++;
327:                    return;
328:                }
329:                int count = 0;
330:                try {
331:                    while (!exit && count < 100) {
332:                        Thread.currentThread().sleep(1000);
333:                    }
334:                } catch (InterruptedException e) {
335:                    System.out.println(" sleep was interrupted\n" + e);
336:                }
337:
338:                if (event == null) {
339:                    exit = true;
340:                    System.out.println(" ERROR: no event received");
341:                    removeNotifoicationListener();
342:                    failureCount++;
343:                    return;
344:                }
345:
346:                verifyEvent(System.getProperty(INSTANCE_NAME) == null);
347:            }
348:
349:            private void verifyEvent(boolean isDAS) {
350:                System.out.println("verifying received event data");
351:                String serverName = isDAS == true ? System.getProperty(TARGET)
352:                        : System.getProperty(INSTANCE_NAME);
353:                checkEventElement("Physical Host Name", serverName,
354:                        (String) event.get(PHOST_COMPDATA_ELEMENT));
355:                checkEventElement("Server Type", SERVER_TYPE_INTEGRATION,
356:                        (String) event.get(SERVERTYPE_COMPDATA_ELEMENT));
357:                checkEventElement("Component Type", COMPONENTTYPE_TEST_VALUE,
358:                        (String) event.get(COMPONENTTYPE_COMPDATA_ELEMENT));
359:                checkEventElement("event Type", EVENT_TYPE_ALERT,
360:                        (String) event.get(TYPE_COMPDATA_ELEMENT));
361:                checkEventElement("Severity value", (SEVERITY_TEST_VALUE + ""),
362:                        (String) event.get(SEVERITY_COMPDATA_ELEMENT));
363:                checkEventElement("Message Code", MSGCODE_TEST_VALUE,
364:                        (String) event.get(MSGCODE_COMPDATA_ELEMENT));
365:                checkEventElement("Message Details", MSGDETAILS_TEST_VALUE,
366:                        (String) event.get(MSGDETAILS_COMPDATA_ELEMENT));
367:
368:            }
369:
370:            private void checkEventElement(String elementName,
371:                    String expectedValue, String returnValue) {
372:                if (expectedValue.trim().equals(returnValue.trim())) {
373:                    System.out.println(" element " + elementName
374:                            + " value : equal to " + expectedValue + " (OK)");
375:                } else {
376:                    System.out.println(" element " + elementName
377:                            + " expected value = " + expectedValue + " found "
378:                            + returnValue);
379:                    failureCount++;
380:
381:                }
382:            }
383:
384:            public void handleNotification(Notification notification,
385:                    Object handback) {
386:                event = (CompositeData) notification.getUserData();
387:                exit = true;
388:            }
389:
390:            private void removeNotifoicationListener() {
391:                // add this class as a listener
392:                try {
393:                    mCASMBeanServerConnection.removeNotificationListener(
394:                            mForwarderSupportObjectName, mNotificationListener);
395:                    System.out.println("Removed notification listener ");
396:                } catch (InstanceNotFoundException e) {
397:                    System.out.println("Mbean with object name '"
398:                            + EVENTMANAGEMENT_CHANNEL_MBEAN_NAME
399:                            + "' instance not found : \n" + e);
400:                    failureCount++;
401:                    return;
402:                } catch (IOException e) {
403:                    System.out
404:                            .println("communication to Mbean with object name '"
405:                                    + EVENTMANAGEMENT_CHANNEL_MBEAN_NAME
406:                                    + "' failed\n" + e);
407:                    failureCount++;
408:                    return;
409:                } catch (ListenerNotFoundException e) {
410:                    System.out
411:                            .println("should not get here as this class is the listener");
412:                    failureCount++;
413:                    return;
414:                }
415:
416:            }
417:
418:            private boolean deploySupportApp() {
419:                String webappLocation = System.getProperty(SUPPORT_APP_LOC);
420:                String[] targets = new String[] { System.getProperty(TARGET) };
421:                Properties deploymentProperties = new Properties();
422:                deploymentProperties.setProperty(ARCHIVE_NAME, webappLocation);
423:                deploymentProperties.setProperty(AVAILABILITY_ENABLED,
424:                        DEFAULT_ENABLE);
425:
426:                Object[] params = new Object[2];
427:                params[0] = deploymentProperties;
428:                params[1] = targets;
429:
430:                String[] signatures = new String[2];
431:                signatures[0] = "java.util.Properties";
432:                // [Ljava.lang.String;
433:                signatures[1] = targets.getClass().getName();
434:
435:                try {
436:                    DeploymentStatus deploymentStatus = (DeploymentStatus) mCASMBeanServerConnection
437:                            .invoke(mConfigObjectName, "deploy", params,
438:                                    signatures);
439:                    if (deploymentStatus.getStatus() == DeploymentStatus.FAILURE) {
440:                        System.out
441:                                .println("test support application failed to deploy\n"
442:                                        + prepareDeploymentResult(deploymentStatus));
443:                        failureCount++;
444:                        return false;
445:                    }
446:                    if (deploymentStatus.getStatus() == DeploymentStatus.NOTINITIALIZED) {
447:                        System.out
448:                                .println("deployment of test support application not initialized\n"
449:                                        + prepareDeploymentResult(deploymentStatus));
450:                        failureCount++;
451:                        return false;
452:                    }
453:                    if (deploymentStatus.getStatus() == DeploymentStatus.SUCCESS) {
454:                        System.out
455:                                .println("deployment of test support application successful");
456:                    }
457:                    if (deploymentStatus.getStatus() == DeploymentStatus.WARNING) {
458:                        System.out
459:                                .println("deployment of test support application successful with warning"
460:                                        + prepareDeploymentResult(deploymentStatus));
461:                    }
462:                } catch (InstanceNotFoundException e) {
463:                    System.out.println("Mbean with object name '"
464:                            + GF_CONFIG_MBEAN_NAME
465:                            + "' instance not found : \n" + e);
466:                    failureCount++;
467:                    return false;
468:                } catch (MBeanException e) {
469:                    System.out.println("Mbean with object name '"
470:                            + GF_CONFIG_MBEAN_NAME + "' "
471:                            + EVENT_TEST_OPERATION
472:                            + " mathod throw exception: \n" + e);
473:                    failureCount++;
474:                    return false;
475:                } catch (ReflectionException e) {
476:                    System.out.println("Mbean with object name '"
477:                            + GF_CONFIG_MBEAN_NAME
478:                            + "' reflection exception: \n" + e);
479:                    failureCount++;
480:                    return false;
481:                } catch (IOException e) {
482:                    System.out
483:                            .println("communication to Mbean with object name '"
484:                                    + GF_CONFIG_MBEAN_NAME + "' failed\n" + e);
485:                    failureCount++;
486:                    return false;
487:                }
488:                return true;
489:            }
490:
491:            private boolean undeploySupportApp() {
492:                String[] targets = new String[] { System.getProperty(TARGET) };
493:                Properties deploymentProperties = new Properties();
494:                deploymentProperties.setProperty(NAME, APP_NAME);
495:                deploymentProperties.setProperty(TYPE, APP_TYPE);
496:
497:                Object[] params = new Object[2];
498:                params[0] = deploymentProperties;
499:                params[1] = targets;
500:
501:                String[] signatures = new String[2];
502:                signatures[0] = "java.util.Properties";
503:                // [Ljava.lang.String;
504:                signatures[1] = targets.getClass().getName();
505:
506:                try {
507:                    DeploymentStatus deploymentStatus = (DeploymentStatus) mCASMBeanServerConnection
508:                            .invoke(mConfigObjectName, "undeploy", params,
509:                                    signatures);
510:                    if (deploymentStatus.getStatus() == DeploymentStatus.FAILURE) {
511:                        System.out
512:                                .println("test support application failed to undeploy\n"
513:                                        + prepareDeploymentResult(deploymentStatus));
514:                        failureCount++;
515:                        return false;
516:                    }
517:                    if (deploymentStatus.getStatus() == DeploymentStatus.NOTINITIALIZED) {
518:                        System.out
519:                                .println("undeployment of test support application not initialized\n"
520:                                        + prepareDeploymentResult(deploymentStatus));
521:                        failureCount++;
522:                        return false;
523:                    }
524:                    if (deploymentStatus.getStatus() == DeploymentStatus.SUCCESS) {
525:                        System.out
526:                                .println("undeployment of test support application successful");
527:                    }
528:                    if (deploymentStatus.getStatus() == DeploymentStatus.WARNING) {
529:                        System.out
530:                                .println("undeployment of test support application successful with warning\n"
531:                                        + prepareDeploymentResult(deploymentStatus));
532:                    }
533:                } catch (InstanceNotFoundException e) {
534:                    System.out.println("Mbean with object name '"
535:                            + GF_CONFIG_MBEAN_NAME
536:                            + "' instance not found : \n" + e);
537:                    failureCount++;
538:                    return false;
539:                } catch (MBeanException e) {
540:                    System.out.println("Mbean with object name '"
541:                            + GF_CONFIG_MBEAN_NAME + "' "
542:                            + EVENT_TEST_OPERATION
543:                            + " mathod throw exception: \n" + e);
544:                    failureCount++;
545:                    return false;
546:                } catch (ReflectionException e) {
547:                    System.out.println("Mbean with object name '"
548:                            + GF_CONFIG_MBEAN_NAME
549:                            + "' reflection exception: \n" + e);
550:                    failureCount++;
551:                    return false;
552:                } catch (IOException e) {
553:                    System.out
554:                            .println("communication to Mbean with object name '"
555:                                    + GF_CONFIG_MBEAN_NAME + "' failed\n" + e);
556:                    failureCount++;
557:                    return false;
558:                }
559:                return true;
560:            }
561:
562:            private String prepareDeploymentResult(
563:                    DeploymentStatus deploymentStatus) {
564:                List<String> statusMessages = new ArrayList<String>();
565:
566:                String stageStatusMessage = deploymentStatus
567:                        .getStageStatusMessage();
568:                if ((stageStatusMessage != null)
569:                        && (stageStatusMessage.trim().length() > 0)) {
570:                    statusMessages.add("Main (Un)Deployment Stage Status is: "
571:                            + stageStatusMessage);
572:                }
573:
574:                DeploymentStatus statusElement = null;
575:                Iterator<DeploymentStatus> iterator = deploymentStatus
576:                        .getSubStages();
577:                int index = 0;
578:                while ((iterator != null) && (iterator.hasNext())) {
579:                    statusElement = (DeploymentStatus) iterator.next();
580:                    if (statusElement != null) {
581:                        if (statusElement.getStageIdentifier() != null) {
582:                            //logger.finest("Stage "+(++index)+" :"+statusElement.getStageIdentifier());
583:                        }
584:                        if (statusElement.getStageStatusMessage() != null) {
585:                            String statusMessage = statusElement
586:                                    .getStageStatusMessage();
587:                            String message = "Stage " + (++index)
588:                                    + " Status is: " + statusMessage;
589:                            //logger.finest(message);
590:                            if ((statusMessage != null)
591:                                    && (statusMessage.trim().length() > 0)) {
592:                                statusMessages.add(message);
593:                            }
594:                        }
595:                    }
596:                }
597:                StringBuffer result = new StringBuffer();
598:                for (String statusMessage : statusMessages) {
599:                    result.append(statusMessage + "\n");
600:                }
601:                return result.toString();
602:            }
603:
604:            private void tearDown() {
605:                removeNotifoicationListener();
606:                undeploySupportApp();
607:            }
608:
609:            private class EventHandler implements  Runnable,
610:                    NotificationListener {
611:                public void run() {
612:                    try {
613:                        while (!exit) {
614:                            Thread.currentThread().wait(100);
615:                        }
616:                    } catch (InterruptedException e) {
617:                    }
618:                }
619:
620:                public void handleNotification(Notification notification,
621:                        Object handback) {
622:                    event = (CompositeData) notification.getUserData();
623:                    exit = true;
624:                }
625:
626:            }
627:
628:            private void runTest() {
629:                disablePersistence();
630:                deploySupportApp();
631:                if (addEventListener()) {
632:                    testSendEvent();
633:                }
634:                if (failureCount == 0) {
635:                    System.out.println(RESULT_PREFIX
636:                            + " test event forwarding passed");
637:                } else {
638:                    System.out.println(RESULT_PREFIX
639:                            + " test event forwarding failed");
640:
641:                }
642:                tearDown();
643:            }
644:
645:            public static void main(String[] args) {
646:                TestEventForwarder test;
647:                try {
648:                    // use the following for standalone java test program
649:                    //				test = new TestEventForwarder("service:jmx:rmi:///jndi/rmi://RDamir-tecra.stc.com:8689/management/rmi-jmx-connector",
650:                    //				"C:/cygwin/bld/open-esb/runtime/esb-manage/bld/test-classes/dist/TestEventManagement.war");
651:                    test = new TestEventForwarder();
652:                    test.runTest();
653:                } catch (Exception e) {
654:                    System.out.println("unable to initailze test - "
655:                            + e.getMessage());
656:                }
657:
658:            }
659:
660:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.