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: * @(#)TestAdminService.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.esb.eventmanagement.impl;
030:
031: import java.io.File;
032: import java.io.FileInputStream;
033: import java.net.InetAddress;
034: import java.net.UnknownHostException;
035: import java.util.ArrayList;
036: import java.util.List;
037: import java.util.Properties;
038:
039: import javax.management.remote.*;
040: import javax.management.*;
041:
042: import com.sun.esb.eventmanagement.api.AlertPersistenceDBType;
043: import com.sun.esb.eventmanagement.impl.AlertLevelType;
044: import com.sun.esb.eventmanagement.impl.AlertRemovalPolicyType;
045: import com.sun.esb.eventmanagement.impl.EventManagementConstants;
046: import com.sun.jbi.EnvironmentContext;
047: import com.sun.jbi.management.ee.JavaEEApplicationInterceptor;
048: import com.sun.jbi.management.system.ScaffoldedEnvironmentContext;
049:
050: /**
051: */
052: public class TestEventManagementControllerMBean extends
053: junit.framework.TestCase implements EventManagementConstants {
054:
055: private static final Boolean ENABLE_PERSISTENCE_TEST_VALUE = true;
056: private static final Boolean ENABLE_POLICY_EXECUTION_TEST_VALUE = true;
057: private static final Long PERSISTED_ALERT_MAX_AGE_TEST_VALUE = 12345L;
058: private static final Long PERSISTED_ALERT_MAX_COUNT_TEST_VALUE = 54321L;
059: private static final String PERSISTED_ALERT_LEVEL_TEST_VALUE = AlertLevelType.CRITICAL
060: .getAlertLevel();
061: private static final Long PERSISTED_ALERT_REMOVAL_PROLICY_EXEC_INTERVAL_TEST_VALUE = 567890L;
062: private static final String DATABASE_JNDI_NAME__TEST_VALUE = "testJNDI";
063: private static final String DATABASE_TYPE_TEST_VALUE = AlertPersistenceDBType.ORACLE
064: .getDatabasetype();
065: private static final String DATABASE_TABLE_TEST_VALUE = "TestTable";
066:
067: private EventManagementControllerMBean mEventManagementControllerMBean;
068: private EnvironmentContext mEnvCtx;
069: private MBeanServer mMBeanServer;
070:
071: public TestEventManagementControllerMBean() throws Exception {
072:
073: mEnvCtx = new ScaffoldedEnvironmentContext();
074: mMBeanServer = mEnvCtx.getMBeanServer();
075: }
076:
077: public void setUp() throws Exception {
078: super .setUp();
079: mEventManagementControllerMBean = new EventManagementControllerMBean(
080: mEnvCtx);
081:
082: mMBeanServer.registerMBean(mEventManagementControllerMBean,
083: this .getControllerName());
084: }
085:
086: public void tearDown() throws Exception {
087: mEnvCtx.getMBeanServer().unregisterMBean(getControllerName());
088: }
089:
090: public ObjectName getControllerName() throws Exception {
091: // this name is subject to change if it need to conform to the JBI runtime MBean convention.
092: String controller = "EventManagement:name=EventManagementControllerMBean";
093: return new ObjectName(controller);
094: }
095:
096: public void testEnablePolicyExecution() throws Exception {
097: Attribute attib = new Attribute(
098: ENABLE_POLICY_EXECUTION_ATTRIBUTE_NAME,
099: ENABLE_POLICY_EXECUTION_TEST_VALUE);
100: mMBeanServer.setAttribute(getControllerName(), attib);
101: Boolean enabled = (Boolean) mMBeanServer.getAttribute(
102: getControllerName(),
103: ENABLE_POLICY_EXECUTION_ATTRIBUTE_NAME);
104: assertTrue(enabled.equals(true));
105: }
106:
107: public void testPersistedEventMaxAge() throws Exception {
108: Long testAge = this .PERSISTED_ALERT_MAX_AGE_TEST_VALUE;
109: Attribute attib = new Attribute(
110: PERSISTED_ALERT_MAX_AGE_ATTRIBUTE_NAME, testAge);
111: mMBeanServer.setAttribute(getControllerName(), attib);
112: Long returnAge = (Long) mMBeanServer.getAttribute(
113: getControllerName(),
114: PERSISTED_ALERT_MAX_AGE_ATTRIBUTE_NAME);
115: assertTrue(returnAge.equals(PERSISTED_ALERT_MAX_AGE_TEST_VALUE));
116: }
117:
118: public void testPersistedEventMaxCount() throws Exception {
119: Long testCount = this .PERSISTED_ALERT_MAX_COUNT_TEST_VALUE;
120: Attribute attib = new Attribute(
121: PERSISTED_ALERT_MAX_COUNT_ATTRIBUTE_NAME, testCount);
122: mMBeanServer.setAttribute(getControllerName(), attib);
123: Long returnCount = (Long) mMBeanServer.getAttribute(
124: getControllerName(),
125: PERSISTED_ALERT_MAX_COUNT_ATTRIBUTE_NAME);
126: assertTrue(returnCount
127: .equals(PERSISTED_ALERT_MAX_COUNT_TEST_VALUE));
128: }
129:
130: public void testPersistedEventAlertLevel() throws Exception {
131: String testLevel = this .PERSISTED_ALERT_LEVEL_TEST_VALUE;
132: Attribute attib = new Attribute(
133: PERSISTED_ALERT_LEVEL_ATTRIBUTE_NAME, testLevel);
134: mMBeanServer.setAttribute(getControllerName(), attib);
135: String returnlevel = (String) mMBeanServer.getAttribute(
136: getControllerName(),
137: PERSISTED_ALERT_LEVEL_ATTRIBUTE_NAME);
138: assertTrue(returnlevel.equals(AlertLevelType.CRITICAL
139: .getAlertLevel()));
140: }
141:
142: public void testPolicyExecutionInterval() throws Exception {
143: Long testinterval = this .PERSISTED_ALERT_REMOVAL_PROLICY_EXEC_INTERVAL_TEST_VALUE;
144: Attribute attib = new Attribute(
145: PERSISTED_ALERT_REMOVAL_PROLICY_EXEC_INTERVAL_ATTRIBUTE_NAME,
146: testinterval);
147: mMBeanServer.setAttribute(getControllerName(), attib);
148: Long returninterval = (Long) mMBeanServer
149: .getAttribute(getControllerName(),
150: PERSISTED_ALERT_REMOVAL_PROLICY_EXEC_INTERVAL_ATTRIBUTE_NAME);
151: assertTrue(returninterval
152: .equals(PERSISTED_ALERT_REMOVAL_PROLICY_EXEC_INTERVAL_TEST_VALUE));
153: }
154:
155: public void testJNDIName() throws Exception {
156: String testjndi = this .DATABASE_JNDI_NAME__TEST_VALUE;
157: Attribute attib = new Attribute(
158: DATABASE_JNDI_NAME__ATTRIBUTE_NAME, testjndi);
159: mMBeanServer.setAttribute(getControllerName(), attib);
160: String returnjndi = (String) mMBeanServer
161: .getAttribute(getControllerName(),
162: DATABASE_JNDI_NAME__ATTRIBUTE_NAME);
163: assertTrue(returnjndi.equals(DATABASE_JNDI_NAME__TEST_VALUE));
164: }
165:
166: public void testDatabaseType() throws Exception {
167: String testDBType = this .DATABASE_TYPE_TEST_VALUE;
168: Attribute attib = new Attribute(DATABASE_TYPE_ATTRIBUTE_NAME,
169: testDBType);
170: mMBeanServer.setAttribute(getControllerName(), attib);
171: String returnDBType = (String) mMBeanServer.getAttribute(
172: getControllerName(), DATABASE_TYPE_ATTRIBUTE_NAME);
173: assertTrue(returnDBType.equals(AlertPersistenceDBType.ORACLE
174: .getDatabasetype()));
175: }
176:
177: public void testDatabaseTableName() throws Exception {
178:
179: String testTableName = DATABASE_TABLE_TEST_VALUE;
180: Attribute attib = new Attribute(
181: DATABASE_ALERT_TABLE_NAME__ATTRIBUTE_NAME,
182: testTableName);
183: mMBeanServer.setAttribute(getControllerName(), attib);
184: String returnTableName = (String) mMBeanServer.getAttribute(
185: getControllerName(),
186: DATABASE_ALERT_TABLE_NAME__ATTRIBUTE_NAME);
187: assertTrue(returnTableName.equals(DATABASE_TABLE_TEST_VALUE));
188: }
189:
190: public void testAlertRemovalPolicy() throws Exception {
191:
192: ArrayList policySettingList = new ArrayList<String>();
193: policySettingList.add(AlertRemovalPolicyType.ALERTS_LEVEL
194: .getPolicyType());
195: policySettingList.add(AlertRemovalPolicyType.ALERTS_AGE
196: .getPolicyType());
197: policySettingList.add(AlertRemovalPolicyType.ALERTS_COUNT
198: .getPolicyType());
199:
200: Object[] params = { policySettingList };
201: String[] signature = { "java.util.List" };
202: mMBeanServer.invoke(getControllerName(),
203: UPDATE_PERSISTED_ALERT_REMOVAL_PROLICY_OPERATION_NAME,
204: params, signature);
205: String[] returnpolicy = (String[]) mMBeanServer
206: .invoke(
207: getControllerName(),
208: GET_LAST_PERSISTED_ALERT_REMOVAL_PROLICY_OPERATION_NAME,
209: null, null);
210: assertTrue(parsePolicy(policySettingList).equals(
211: parsePolicy(returnpolicy)));
212: }
213:
214: private String parsePolicy(List<String> policyItems) {
215: StringBuffer policyString = new StringBuffer();
216: for (String item : policyItems) {
217: policyString.append(item + " ");
218: }
219: return policyString.toString();
220: }
221:
222: private String parsePolicy(String[] policyItems) {
223: StringBuffer policyString = new StringBuffer();
224: for (String item : policyItems) {
225: policyString.append(item + " ");
226: }
227: return policyString.toString();
228: }
229:
230: }
|