Source Code Cross Referenced for TestEventForwarderConfiguration.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.File;
032:        import java.io.FileInputStream;
033:        import java.io.FileNotFoundException;
034:        import java.io.FileOutputStream;
035:        import java.io.IOException;
036:        import java.util.ArrayList;
037:        import java.util.Iterator;
038:        import java.util.List;
039:        import java.util.Properties;
040:        import java.util.concurrent.ExecutorService;
041:        import java.util.concurrent.Executors;
042:
043:        import javax.management.Attribute;
044:        import javax.management.AttributeNotFoundException;
045:        import javax.management.InstanceNotFoundException;
046:        import javax.management.InvalidAttributeValueException;
047:        import javax.management.ListenerNotFoundException;
048:        import javax.management.MBeanException;
049:        import javax.management.MBeanServerConnection;
050:        import javax.management.MalformedObjectNameException;
051:        import javax.management.Notification;
052:        import javax.management.NotificationListener;
053:        import javax.management.ObjectName;
054:        import javax.management.ReflectionException;
055:        import javax.management.openmbean.CompositeData;
056:        import javax.management.remote.JMXConnector;
057:        import javax.management.remote.JMXConnectorFactory;
058:        import javax.management.remote.JMXServiceURL;
059:
060:        public class TestEventForwarderConfiguration {
061:
062:            private static final String PERSISTENCE_ENABLED_PROP = "PersistenceEnabled";
063:            private static final String PERSISTENCE_ENABLED_DEFUALT_VAL = "false";
064:
065:            private static final String JOURNAL_ENABLED_PROP = "journalEnabled";
066:            private static final String JOURNAL_ENABLED_DEFUALT_VAL = "false";
067:
068:            private static final String POLICY_EXEC_ENABLED_PROP = "PersistencePolicyExecEnabled";
069:            private static final String POLICY_EXEC_ENABLED_DEFUALT_VAL = "false";
070:            private static final String POLICY_EXEC_ENABLED_TEST_VAL = "true";
071:
072:            private static final String ALERT_COUNT_PROP = "PersistenceAlertCount";
073:            private static final String ALERT_COUNT_DEFUALT_VAL = "-1";
074:            private static final String ALERT_COUNT_TEST_VAL = "100";
075:
076:            private static final String ALERT_AGE_PROP = "PersistenceAlertAge";
077:            private static final String ALERT_AGE_DEFUALT_VAL = "-1";
078:            private static final String ALERT_AGE_TEST_VAL = "100000";
079:
080:            private static final String ALERT_LEVEL_PROP = "PersistenceAlertLevel";
081:            private static final String ALERT_LEVEL_DEFUALT_VAL = "NONE";
082:            private static final String ALERT_LEVEL_TEST_VAL = "FATAL";
083:
084:            private static final String POLICY_EXEC_INTERVAL_PROP = "PersistencePolicyExecInterval";
085:            private static final String POLICY_EXEC_INTERVAL_DEFUALT_VAL = "600000";
086:            private static final String POLICY_EXEC_INTERVAL_TEST_VAL = "6000000";
087:
088:            private static final String DATABASE_TYPE_PROP = "DatabaseType";
089:            private static final String DATABASE_TYPE_DEFUALT_VAL = "DERBY";
090:            private static final String DATABASE_TYPE_TEST_VAL = "ORACLE";
091:
092:            private static final String DB_JNDI_NAME_PROP = "DBJndiName";
093:            private static final String DB_JNDI_NAME_DEFUALT_VAL = "AlertPersistenceDB";
094:            private static final String DB_JNDI_NAME_TEST_VAL = "TestAlertPersistenceDB";
095:
096:            private static final String ALERT_TABLE_PROP = "AlertTableName";
097:            private static final String ALERT_TABLE_TEST_VAL = "AlertTest";
098:
099:            private static final String PERSISTENCE_ENABLED_ATTRIBUTE_NAME = "alertsPersistenceEnabled";
100:            private static final String JOURNAL_ENABLED_ATTRIBUTE_NAME = "alertsJournalEnabled";
101:            private static final String ENABLE_PERSISTENCE_ATTRIBUTE_NAME = "enableTargetPersistence";
102:            private static final String ENABLE_POLICY_EXECUTION_ATTRIBUTE_NAME = "enablePolicyExcution";
103:            private static final String PERSISTED_ALERT_MAX_AGE_ATTRIBUTE_NAME = "persistedAlertMaxAge";
104:            private static final String PERSISTED_ALERT_MAX_COUNT_ATTRIBUTE_NAME = "persistedAlertMaxCount";
105:            private static final String PERSISTED_ALERT_LEVEL_ATTRIBUTE_NAME = "persistedAlertLevel";
106:            private static final String PERSISTED_ALERT_REMOVAL_PROLICY_EXEC_INTERVAL_ATTRIBUTE_NAME = "persistedAlertsRemovalPolicyExecInterval";
107:            private static final String MAX_CACHESIZE_ATTRIBUTE_NAME = "maxInMemoryEventCacheSize";
108:            private static final String DATABASE_ALERT_TABLE_NAME__ATTRIBUTE_NAME = "alertTableName";
109:            private static final String CURRENT_PERSISTED_EVENT_COUNT_ATTRIBUTE_NAME = "CurrentPersistedEventsCount";
110:            private static final String DATABASE_JNDI_NAME_ATTRIBUTE_NAME = "DBJndiName";
111:            private static final String DATABASE_TYPE_ATTRIBUTE_NAME = "DBType";
112:            private static final String TARGET_CHECK_INTERVAL_ATTRIBUTE_NAME = "tergetCheckInterval";
113:
114:            private static final String EVENTMANAGEMENT_CONTROL_MBEAN_NAME = "EventManagement:name=EventManagementControllerMBean";
115:            private static final String DISABLE_PERSISTENCE_OPERATION = "disableAlertsPersistence";
116:
117:            private MBeanServerConnection mCASMBeanServerConnection;
118:            private static final String RESULT_PREFIX = "##### Result of ";
119:            private static final String JBI_INSTALL_ROOT_ATTRIBUTE_NAME = "JBIInstallRoot";
120:
121:            private static final String USER = "jmx.user";
122:            private static final String PASSWORD = "jmx.password";
123:            private static final String PROVIDER = "jmx.provider";
124:            private static final String TARGET = "target";
125:            private static final String INSTANCE_NAME = "instance.target.name";
126:            private static final String INSTANCE_JMX_PORT = "instance.jmx.port";
127:
128:            //    private ObjectName mForwarderObjectName;
129:            private ObjectName mForwarderControllerObjectName;
130:            private int failureCount;
131:            private String mDasEMConfigFile;
132:            private String mDasInstanceConfigFile;
133:
134:            public TestEventForwarderConfiguration(String aJmxURL)
135:                    throws Exception {
136:                System.setProperty(USER, "admin");
137:                System.setProperty(PASSWORD, "adminadmin");
138:                System.setProperty(PROVIDER, aJmxURL);
139:                System.setProperty(TARGET, "server");
140:
141:                getMBeanServerConnections();
142:                getObjectNames();
143:                getJBIRootIntsall();
144:            }
145:
146:            public TestEventForwarderConfiguration() throws Exception {
147:                getMBeanServerConnections();
148:                getObjectNames();
149:                getJBIRootIntsall();
150:
151:            }
152:
153:            private void getMBeanServerConnections() throws Exception {
154:
155:                java.util.Map<String, String[]> env = new java.util.HashMap<String, String[]>();
156:                String user = System.getProperty(USER);
157:                String pass = System.getProperty(PASSWORD);
158:                String[] credentials = new String[] { user, pass };
159:                env.put("jmx.remote.credentials", credentials);
160:
161:                String jmxProvider = System.getProperty(PROVIDER);
162:                JMXServiceURL casJmxServiceUrl = new JMXServiceURL(jmxProvider);
163:                JMXConnector connector = JMXConnectorFactory.connect(
164:                        casJmxServiceUrl, env);
165:                mCASMBeanServerConnection = connector
166:                        .getMBeanServerConnection();
167:
168:            }
169:
170:            private void getJBIRootIntsall() {
171:
172:                try {
173:                    String jbiRoot = (String) mCASMBeanServerConnection
174:                            .getAttribute(mForwarderControllerObjectName,
175:                                    JBI_INSTALL_ROOT_ATTRIBUTE_NAME);
176:                    mDasEMConfigFile = jbiRoot + File.separator
177:                            + "eventmanagement.properties";
178:                    mDasInstanceConfigFile = jbiRoot
179:                            + File.separator
180:                            + "../../../../nodeagents/agent1/instance1/jbi/config/eventmanagement.properties";
181:                } catch (InstanceNotFoundException e) {
182:                    System.out.println("Mbean with object name '"
183:                            + EVENTMANAGEMENT_CONTROL_MBEAN_NAME
184:                            + "' instance not found : \n" + e);
185:                    failureCount++;
186:                } catch (MBeanException e) {
187:                    System.out.println("Mbean with object name '"
188:                            + EVENTMANAGEMENT_CONTROL_MBEAN_NAME
189:                            + "' getAttribute" + " mathod throw exception: \n"
190:                            + e);
191:                    failureCount++;
192:                } catch (ReflectionException e) {
193:                    System.out.println("Mbean with object name '"
194:                            + EVENTMANAGEMENT_CONTROL_MBEAN_NAME
195:                            + "' reflection exception: \n" + e);
196:                    failureCount++;
197:                } catch (IOException e) {
198:                    System.out
199:                            .println("communication to Mbean with object name '"
200:                                    + EVENTMANAGEMENT_CONTROL_MBEAN_NAME
201:                                    + "' failed\n" + e);
202:                    failureCount++;
203:                } catch (AttributeNotFoundException e) {
204:                    System.out
205:                            .println("Mbean with object name '"
206:                                    + EVENTMANAGEMENT_CONTROL_MBEAN_NAME
207:                                    + "' does not have attribute named 'enableTargetPersistence'");
208:                    failureCount++;
209:                }
210:            }
211:
212:            private void getObjectNames() {
213:                try {
214:                    mForwarderControllerObjectName = new ObjectName(
215:                            this .EVENTMANAGEMENT_CONTROL_MBEAN_NAME);
216:                } catch (MalformedObjectNameException e) {
217:                    System.out.println(EVENTMANAGEMENT_CONTROL_MBEAN_NAME
218:                            + "is invalid object name");
219:                    failureCount++;
220:                } catch (NullPointerException e) {
221:                    failureCount++;
222:                }
223:
224:            }
225:
226:            private void disablePersistence() {
227:                try {
228:                    mCASMBeanServerConnection.invoke(
229:                            mForwarderControllerObjectName,
230:                            DISABLE_PERSISTENCE_OPERATION, null, null);
231:
232:                } catch (InstanceNotFoundException e) {
233:                    System.out.println("Mbean with object name '"
234:                            + EVENTMANAGEMENT_CONTROL_MBEAN_NAME
235:                            + "' instance not found : \n" + e);
236:                    failureCount++;
237:                } catch (MBeanException e) {
238:                    System.out.println("Mbean with object name '"
239:                            + EVENTMANAGEMENT_CONTROL_MBEAN_NAME + "' "
240:                            + DISABLE_PERSISTENCE_OPERATION
241:                            + " mathod throw exception: \n" + e);
242:                    failureCount++;
243:                } catch (ReflectionException e) {
244:                    System.out.println("Mbean with object name '"
245:                            + EVENTMANAGEMENT_CONTROL_MBEAN_NAME
246:                            + "' reflection exception: \n" + e);
247:                    failureCount++;
248:                } catch (IOException e) {
249:                    System.out
250:                            .println("communication to Mbean with object name '"
251:                                    + EVENTMANAGEMENT_CONTROL_MBEAN_NAME
252:                                    + "' failed\n" + e);
253:                    failureCount++;
254:                }
255:            }
256:
257:            private void verifyEventConfiguration(Properties aTestProps,
258:                    boolean isDAS, boolean aTestData) {
259:
260:                if (isDAS && !aTestData) {
261:                    verifyDASDefaultEventConfiguration(aTestProps);
262:                } else if (isDAS && aTestData) {
263:                    verifyDASTestEventConfiguration(aTestProps);
264:                } else if (!isDAS && !aTestData) {
265:                    verifyInstanceDefaultEventConfiguration(aTestProps);
266:                } else if (isDAS && !aTestData) {
267:                    verifyInstanceTestEventConfiguration(aTestProps);
268:                }
269:            }
270:
271:            private void verifyDASDefaultEventConfiguration(
272:                    Properties aTestProps) {
273:                System.out
274:                        .println("verifying 'server' default configuration data");
275:                checkEventConfigurationElement(PERSISTENCE_ENABLED_PROP,
276:                        PERSISTENCE_ENABLED_DEFUALT_VAL, (String) aTestProps
277:                                .get(PERSISTENCE_ENABLED_PROP));
278:
279:                checkEventConfigurationElement(JOURNAL_ENABLED_PROP,
280:                        JOURNAL_ENABLED_DEFUALT_VAL, (String) aTestProps
281:                                .get(JOURNAL_ENABLED_PROP));
282:
283:                checkEventConfigurationElement(POLICY_EXEC_ENABLED_PROP,
284:                        POLICY_EXEC_ENABLED_DEFUALT_VAL, (String) aTestProps
285:                                .get(POLICY_EXEC_ENABLED_PROP));
286:
287:                checkEventConfigurationElement(ALERT_COUNT_PROP,
288:                        ALERT_COUNT_DEFUALT_VAL, (String) aTestProps
289:                                .get(ALERT_COUNT_PROP));
290:
291:                checkEventConfigurationElement(ALERT_AGE_PROP,
292:                        ALERT_AGE_DEFUALT_VAL, (String) aTestProps
293:                                .get(ALERT_AGE_PROP));
294:
295:                checkEventConfigurationElement(ALERT_LEVEL_PROP,
296:                        ALERT_LEVEL_DEFUALT_VAL, (String) aTestProps
297:                                .get(ALERT_LEVEL_PROP));
298:
299:                checkEventConfigurationElement(POLICY_EXEC_INTERVAL_PROP,
300:                        POLICY_EXEC_INTERVAL_DEFUALT_VAL, (String) aTestProps
301:                                .get(POLICY_EXEC_INTERVAL_PROP));
302:
303:                checkEventConfigurationElement(DATABASE_TYPE_PROP,
304:                        DATABASE_TYPE_DEFUALT_VAL, (String) aTestProps
305:                                .get(DATABASE_TYPE_PROP));
306:
307:                checkEventConfigurationElement(DB_JNDI_NAME_PROP,
308:                        DB_JNDI_NAME_DEFUALT_VAL, (String) aTestProps
309:                                .get(DB_JNDI_NAME_PROP));
310:
311:                checkEventConfigurationElement(ALERT_LEVEL_PROP,
312:                        ALERT_LEVEL_DEFUALT_VAL, (String) aTestProps
313:                                .get(ALERT_LEVEL_PROP));
314:
315:            }
316:
317:            private void verifyDASTestEventConfiguration(Properties aTestProps) {
318:                System.out
319:                        .println("verifying 'server' test configuration data");
320:
321:                checkEventConfigurationElement(POLICY_EXEC_ENABLED_PROP,
322:                        POLICY_EXEC_ENABLED_TEST_VAL, (String) aTestProps
323:                                .get(POLICY_EXEC_ENABLED_PROP));
324:
325:                checkEventConfigurationElement(ALERT_COUNT_PROP,
326:                        ALERT_COUNT_TEST_VAL, (String) aTestProps
327:                                .get(ALERT_COUNT_PROP));
328:
329:                checkEventConfigurationElement(ALERT_AGE_PROP,
330:                        ALERT_AGE_TEST_VAL, (String) aTestProps
331:                                .get(ALERT_AGE_PROP));
332:
333:                checkEventConfigurationElement(ALERT_LEVEL_PROP,
334:                        ALERT_LEVEL_TEST_VAL, (String) aTestProps
335:                                .get(ALERT_LEVEL_PROP));
336:
337:                checkEventConfigurationElement(POLICY_EXEC_INTERVAL_PROP,
338:                        POLICY_EXEC_INTERVAL_TEST_VAL, (String) aTestProps
339:                                .get(POLICY_EXEC_INTERVAL_PROP));
340:
341:                checkEventConfigurationElement(DATABASE_TYPE_PROP,
342:                        DATABASE_TYPE_TEST_VAL, (String) aTestProps
343:                                .get(DATABASE_TYPE_PROP));
344:
345:                checkEventConfigurationElement(DB_JNDI_NAME_PROP,
346:                        DB_JNDI_NAME_TEST_VAL, (String) aTestProps
347:                                .get(DB_JNDI_NAME_PROP));
348:
349:                checkEventConfigurationElement(ALERT_LEVEL_PROP,
350:                        ALERT_LEVEL_TEST_VAL, (String) aTestProps
351:                                .get(ALERT_LEVEL_PROP));
352:
353:                checkEventConfigurationElement(ALERT_TABLE_PROP,
354:                        ALERT_TABLE_TEST_VAL, (String) aTestProps
355:                                .get(ALERT_TABLE_PROP));
356:
357:            }
358:
359:            private void verifyInstanceDefaultEventConfiguration(
360:                    Properties aTestProps) {
361:                System.out
362:                        .println("verifying 'instance1' default configuration data");
363:                checkEventConfigurationElement(PERSISTENCE_ENABLED_PROP,
364:                        PERSISTENCE_ENABLED_DEFUALT_VAL, (String) aTestProps
365:                                .get(PERSISTENCE_ENABLED_PROP));
366:
367:                checkEventConfigurationElement(DATABASE_TYPE_PROP,
368:                        DATABASE_TYPE_DEFUALT_VAL, (String) aTestProps
369:                                .get(DATABASE_TYPE_PROP));
370:
371:                checkEventConfigurationElement(DB_JNDI_NAME_PROP,
372:                        DB_JNDI_NAME_DEFUALT_VAL, (String) aTestProps
373:                                .get(DB_JNDI_NAME_PROP));
374:
375:            }
376:
377:            private void verifyInstanceTestEventConfiguration(
378:                    Properties aTestProps) {
379:                System.out
380:                        .println("verifying 'instance1' test configuration data");
381:
382:                checkEventConfigurationElement(PERSISTENCE_ENABLED_PROP,
383:                        PERSISTENCE_ENABLED_DEFUALT_VAL, (String) aTestProps
384:                                .get(PERSISTENCE_ENABLED_PROP));
385:
386:                checkEventConfigurationElement(DATABASE_TYPE_PROP,
387:                        DATABASE_TYPE_TEST_VAL, (String) aTestProps
388:                                .get(DATABASE_TYPE_PROP));
389:
390:                checkEventConfigurationElement(DB_JNDI_NAME_PROP,
391:                        DB_JNDI_NAME_TEST_VAL, (String) aTestProps
392:                                .get(DB_JNDI_NAME_PROP));
393:
394:                checkEventConfigurationElement(ALERT_TABLE_PROP,
395:                        ALERT_TABLE_TEST_VAL, (String) aTestProps
396:                                .get(ALERT_TABLE_PROP));
397:
398:            }
399:
400:            private void checkEventConfigurationElement(String elementName,
401:                    String expectedValue, String returnValue) {
402:                if (expectedValue.trim().equals(returnValue.trim())) {
403:                    System.out.println(" element " + elementName
404:                            + " value : equal to " + expectedValue + " (OK)");
405:                } else {
406:                    System.out.println(" element " + elementName
407:                            + " expected value = " + expectedValue + " found "
408:                            + returnValue);
409:                    failureCount++;
410:
411:                }
412:            }
413:
414:            private Properties getConfigurationProperties(String aConfigFilePath) {
415:                File fIn = new File(aConfigFilePath);
416:                System.out.println(fIn.getAbsolutePath());
417:                Properties lprops = new Properties();
418:                if (fIn.exists() == false) {
419:                    return lprops;
420:                }
421:                try {
422:                    FileInputStream fis = new FileInputStream(fIn);
423:                    lprops.load(fis);
424:                } catch (Exception e) {
425:                    System.out.println(" fail to get configuration file from  "
426:                            + fIn.getAbsolutePath() + "\n with error "
427:                            + e.getMessage());
428:                    e.printStackTrace();
429:                    failureCount++;
430:                }
431:                return lprops;
432:
433:            }
434:
435:            private void updateConfigurationProperties() {
436:
437:                setConfigurationAttribute(
438:                        PERSISTED_ALERT_MAX_AGE_ATTRIBUTE_NAME, new Long(
439:                                ALERT_AGE_TEST_VAL));
440:
441:                setConfigurationAttribute(
442:                        PERSISTED_ALERT_MAX_COUNT_ATTRIBUTE_NAME, new Long(
443:                                ALERT_COUNT_TEST_VAL));
444:
445:                setConfigurationAttribute(PERSISTED_ALERT_LEVEL_ATTRIBUTE_NAME,
446:                        ALERT_LEVEL_TEST_VAL);
447:
448:                setConfigurationAttribute(
449:                        PERSISTED_ALERT_REMOVAL_PROLICY_EXEC_INTERVAL_ATTRIBUTE_NAME,
450:                        new Long(POLICY_EXEC_INTERVAL_TEST_VAL));
451:
452:                setConfigurationAttribute(DATABASE_JNDI_NAME_ATTRIBUTE_NAME,
453:                        DB_JNDI_NAME_TEST_VAL);
454:
455:                setConfigurationAttribute(DATABASE_TYPE_ATTRIBUTE_NAME,
456:                        DATABASE_TYPE_TEST_VAL);
457:
458:                setConfigurationAttribute(
459:                        DATABASE_ALERT_TABLE_NAME__ATTRIBUTE_NAME,
460:                        ALERT_TABLE_TEST_VAL);
461:
462:                setConfigurationAttribute(
463:                        ENABLE_POLICY_EXECUTION_ATTRIBUTE_NAME, new Boolean(
464:                                POLICY_EXEC_ENABLED_TEST_VAL));
465:
466:            }
467:
468:            private void setConfigurationAttribute(String aAttributeName,
469:                    Object aAttributeValue) {
470:                Attribute lAttribute = new Attribute(aAttributeName,
471:                        aAttributeValue);
472:                try {
473:                    mCASMBeanServerConnection.setAttribute(
474:                            mForwarderControllerObjectName, lAttribute);
475:                } catch (InstanceNotFoundException e) {
476:                    System.out.println("Mbean with object name '"
477:                            + EVENTMANAGEMENT_CONTROL_MBEAN_NAME
478:                            + "' instance not found : \n" + e);
479:                    failureCount++;
480:                } catch (MBeanException e) {
481:                    System.out.println("Mbean with object name '"
482:                            + EVENTMANAGEMENT_CONTROL_MBEAN_NAME
483:                            + "' setAttribute" + " mathod throw exception: \n"
484:                            + e);
485:                    failureCount++;
486:                } catch (ReflectionException e) {
487:                    System.out.println("Mbean with object name '"
488:                            + EVENTMANAGEMENT_CONTROL_MBEAN_NAME
489:                            + "' reflection exception: \n" + e);
490:                    failureCount++;
491:                } catch (IOException e) {
492:                    System.out
493:                            .println("communication to Mbean with object name '"
494:                                    + EVENTMANAGEMENT_CONTROL_MBEAN_NAME
495:                                    + "' failed\n" + e);
496:                    failureCount++;
497:                } catch (AttributeNotFoundException e) {
498:                    System.out
499:                            .println("Mbean with object name '"
500:                                    + EVENTMANAGEMENT_CONTROL_MBEAN_NAME
501:                                    + "' does not have attribute named 'enableTargetPersistence'");
502:                    failureCount++;
503:                } catch (InvalidAttributeValueException e) {
504:                    System.out
505:                            .println("Mbean with object name '"
506:                                    + EVENTMANAGEMENT_CONTROL_MBEAN_NAME
507:                                    + "' attribute named 'enableTargetPersistence' is not boolean type");
508:                    failureCount++;
509:                }
510:
511:            }
512:
513:            private void restoreDefaultConfigurationProperties(
514:                    Properties aDefaultServerProp) {
515:
516:                setConfigurationAttribute(
517:                        ENABLE_POLICY_EXECUTION_ATTRIBUTE_NAME, new Boolean(
518:                                POLICY_EXEC_ENABLED_DEFUALT_VAL));
519:
520:                setConfigurationAttribute(
521:                        PERSISTED_ALERT_MAX_AGE_ATTRIBUTE_NAME, new Long(
522:                                ALERT_AGE_DEFUALT_VAL));
523:
524:                setConfigurationAttribute(
525:                        PERSISTED_ALERT_MAX_COUNT_ATTRIBUTE_NAME, new Long(
526:                                ALERT_COUNT_DEFUALT_VAL));
527:
528:                setConfigurationAttribute(PERSISTED_ALERT_LEVEL_ATTRIBUTE_NAME,
529:                        ALERT_LEVEL_DEFUALT_VAL);
530:
531:                setConfigurationAttribute(
532:                        PERSISTED_ALERT_REMOVAL_PROLICY_EXEC_INTERVAL_ATTRIBUTE_NAME,
533:                        new Long(POLICY_EXEC_INTERVAL_DEFUALT_VAL));
534:
535:                setConfigurationAttribute(DATABASE_JNDI_NAME_ATTRIBUTE_NAME,
536:                        DB_JNDI_NAME_DEFUALT_VAL);
537:
538:                setConfigurationAttribute(DATABASE_TYPE_ATTRIBUTE_NAME,
539:                        DATABASE_TYPE_DEFUALT_VAL);
540:
541:                setConfigurationAttribute(
542:                        DATABASE_ALERT_TABLE_NAME__ATTRIBUTE_NAME,
543:                        aDefaultServerProp.getProperty(ALERT_TABLE_PROP));
544:
545:            }
546:
547:            private void runTest() {
548:                disablePersistence();
549:                System.out
550:                        .println("DAS default event configuration properties");
551:                Properties lDefaultServerProp = getConfigurationProperties(mDasEMConfigFile);
552:                verifyDASDefaultEventConfiguration(lDefaultServerProp);
553:                System.out
554:                        .println("Instance default event configuration properties");
555:                Properties lDefaultInstanceProp = getConfigurationProperties(mDasInstanceConfigFile);
556:                verifyInstanceDefaultEventConfiguration(lDefaultInstanceProp);
557:                System.out
558:                        .println("Update event configuration test properties");
559:                updateConfigurationProperties();
560:                System.out.println("DAS test event configuration properties");
561:                Properties lTestServerProp = getConfigurationProperties(mDasEMConfigFile);
562:                verifyDASTestEventConfiguration(lTestServerProp);
563:                System.out
564:                        .println("Instance test event configuration properties");
565:                Properties lTestInstanceProp = getConfigurationProperties(mDasInstanceConfigFile);
566:                verifyInstanceTestEventConfiguration(lTestInstanceProp);
567:                restoreDefaultConfigurationProperties(lDefaultServerProp);
568:
569:                if (failureCount == 0) {
570:                    System.out.println(RESULT_PREFIX
571:                            + " test event forwarding configuration passed");
572:                } else {
573:                    System.out.println(RESULT_PREFIX
574:                            + " test event forwarding configuration failed");
575:                }
576:            }
577:
578:            public static void main(String[] args) {
579:                TestEventForwarderConfiguration test;
580:                try {
581:                    // use the following for standalone java test program
582:                    //	        test = new TestEventForwarderConfiguration("service:jmx:rmi:///jndi/rmi://RDamir-gx280xp.stc.com:8689/management/rmi-jmx-connector");
583:                    test = new TestEventForwarderConfiguration();
584:                    test.runTest();
585:                } catch (Exception e) {
586:                    System.out.println("unable to initailze test - "
587:                            + e.getMessage());
588:                }
589:            }
590:
591:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.