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: * @(#)TestStatisticsBaseImpl.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.util.monitoring;
030:
031: import com.sun.jbi.monitoring.StatisticsBase;
032:
033: /**
034: * Tests for the StatisticsBaseImpl class.
035: *
036: * @author Sun Microsystems, Inc.
037: */
038: public class TestStatisticsBaseImpl extends junit.framework.TestCase {
039: /**
040: * Statistics base object.
041: */
042: private StatisticsBase mStatsBase;
043:
044: /**
045: * Key value for base object.
046: */
047: private static final String BASE_KEY = "Base";
048:
049: /**
050: * Key value for child object.
051: */
052: private static final String CHILD_KEY_1 = "Child_1";
053:
054: /**
055: * Key value for child object.
056: */
057: private static final String CHILD_KEY_2 = "Child_2";
058:
059: /**
060: * Key value for parent object.
061: */
062: private static final String PARENT_KEY = "Parent";
063:
064: /**
065: * The constructor for this testcase, forwards the test name to
066: * the jUnit TestCase base class.
067: * @param aTestName String with the name of this test.
068: */
069: public TestStatisticsBaseImpl(String aTestName) {
070: super (aTestName);
071: }
072:
073: /**
074: * Setup for the test.
075: * @throws Exception when set up fails for any reason.
076: */
077: public void setUp() throws Exception {
078: super .setUp();
079: mStatsBase = new StatisticsBaseImpl(BASE_KEY);
080: }
081:
082: /**
083: * Cleanup for the test.
084: * @throws Exception when tearDown fails for any reason.
085: */
086: public void tearDown() throws Exception {
087: super .tearDown();
088: }
089:
090: // ============================= test methods ================================
091:
092: /**
093: * Test the addChild/getChild methods.
094: * @throws Exception if an unexpected error occurs.
095: */
096: public void testAddGetChild() throws Exception {
097: // Create child objects for test
098: StatisticsBaseImpl child1 = new StatisticsBaseImpl(CHILD_KEY_1);
099: StatisticsBaseImpl child2 = new StatisticsBaseImpl(CHILD_KEY_2);
100:
101: // Retrieve nonexistent child object
102: assertNull("getChild returned object: ", mStatsBase
103: .getChild(CHILD_KEY_1));
104:
105: // Add and retrieve one child object
106: mStatsBase.addChild(child1);
107: assertSame("getChild returned wrong object: ", mStatsBase
108: .getChild(CHILD_KEY_1), child1);
109:
110: // Add and retrieve second child object
111: mStatsBase.addChild(child2);
112: assertSame("getChild returned wrong object: ", mStatsBase
113: .getChild(CHILD_KEY_1), child1);
114: assertSame("getChild returned wrong object", mStatsBase
115: .getChild(CHILD_KEY_2), child2);
116: }
117:
118: /**
119: * Test the set/getParent methods.
120: * @throws Exception if an unexpected error occurs.
121: */
122: public void testSetGetParent() throws Exception {
123: // Create parent object for test
124: StatisticsBaseImpl parent = new StatisticsBaseImpl(PARENT_KEY);
125:
126: // Set parent object
127: mStatsBase.setParent(parent);
128: assertSame("getParent returned wrong object: ", mStatsBase
129: .getParent(), parent);
130:
131: // Make sure child gets right parent
132: StatisticsBaseImpl child = new StatisticsBaseImpl(CHILD_KEY_1);
133: mStatsBase.addChild(child);
134: assertSame("getParent returned wrong object: ", child
135: .getParent(), mStatsBase);
136: }
137:
138: /**
139: * Test the getKey method.
140: * @throws Exception if an unexpected error occurs.
141: */
142: public void testGetKey() throws Exception {
143: assertEquals("getKey returned wrong key value: ", mStatsBase
144: .getKey(), BASE_KEY);
145: }
146:
147: /**
148: * Test the getChildren method.
149: * @throws Exception if an unexpected error occurs.
150: */
151: public void testGetChildren() throws Exception {
152: int count = 0;
153:
154: // Create child objects for test
155: StatisticsBaseImpl child1 = new StatisticsBaseImpl(CHILD_KEY_1);
156: StatisticsBaseImpl child2 = new StatisticsBaseImpl(CHILD_KEY_2);
157:
158: // Retrieve nonexistent children
159: assertEquals("getChildren returned wrong number of objects: ",
160: new Integer(mStatsBase.getChildren().size()),
161: new Integer(count));
162:
163: // Add and retrieve one child object
164: mStatsBase.addChild(child1);
165: ++count;
166: assertEquals("getChildren returned wrong number of objects: ",
167: new Integer(mStatsBase.getChildren().size()),
168: new Integer(count));
169: assertTrue("getChildren returned wrong objects", mStatsBase
170: .getChildren().contains(child1));
171:
172: // Add and retrieve second child object
173: mStatsBase.addChild(child2);
174: ++count;
175: assertEquals("getChildren returned wrong number of objects: ",
176: new Integer(mStatsBase.getChildren().size()),
177: new Integer(count));
178: assertTrue("getChildren returned wrong objects", mStatsBase
179: .getChildren().contains(child1));
180: assertTrue("getChildren returned wrong objects", mStatsBase
181: .getChildren().contains(child2));
182: }
183:
184: /**
185: * Test the setEnabled, setDisabled, and isEnabled methods.
186: * @throws Exception if an unexpected error occurs.
187: */
188: public void testEnabled() throws Exception {
189: assertTrue("isEnabled() returned wrong value on new object: ",
190: mStatsBase.isEnabled());
191: mStatsBase.setDisabled();
192: assertFalse(
193: "isEnabled() returned wrong value after setDisabled(): ",
194: mStatsBase.isEnabled());
195: mStatsBase.setEnabled();
196: assertTrue(
197: "isEnabled() returned wrong value after setEnabled(): ",
198: mStatsBase.isEnabled());
199:
200: // Make sure child gets right setting
201: StatisticsBaseImpl child = new StatisticsBaseImpl(CHILD_KEY_1);
202: mStatsBase.addChild(child);
203: assertTrue("isEnabled() returned wrong value on new object: ",
204: child.isEnabled());
205: mStatsBase.setDisabled();
206: assertFalse(
207: "isEnabled() returned wrong value for child after setDisabled(): ",
208: child.isEnabled());
209: mStatsBase.setEnabled();
210: assertTrue(
211: "isEnabled() returned wrong value for child after setEnabled(): ",
212: child.isEnabled());
213: }
214:
215: /**
216: * Test the registerMBean/unregisterMBean methods.
217: * @throws Exception if an unexpected error occurs.
218: */
219: public void testRegisterUnregisterMBean() throws Exception {
220: // Not yet implemented
221: ;
222: }
223: }
|