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: * @(#)TestMessageServiceStatistics.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.messaging;
030:
031: /**
032: * Tests for MessageServiceStatistics.
033: *
034: * @author Sun Microsystems, Inc.
035: */
036: public class TestMessageServiceStatistics extends
037: junit.framework.TestCase {
038: /**
039: * Instance of MessageServiceStatistics.
040: */
041: private MessageServiceStatistics mStats;
042:
043: /**
044: * The constructor for this testcase, forwards the test name to
045: * the jUnit TestCase base class.
046: * @param aTestName String with the name of this test.
047: */
048: public TestMessageServiceStatistics(String aTestName) {
049: super (aTestName);
050: }
051:
052: /**
053: * Setup for the test. This creates the MessageServiceStatistics instance
054: * and other objects needed for the tests.
055: * @throws Exception when set up fails for any reason.
056: */
057: public void setUp() throws Exception {
058: super .setUp();
059:
060: mStats = new MessageServiceStatistics(null, "MessageService");
061: }
062:
063: /**
064: * Cleanup for the test.
065: * @throws Exception when tearDown fails for any reason.
066: */
067: public void tearDown() throws Exception {
068: super .tearDown();
069: }
070:
071: // ============================= test methods ================================
072:
073: /**
074: * Tests get/setLastRestartTime.
075: * @throws Exception if an unexpected error occurs.
076: */
077: public void testLastRestartTime() {
078: java.util.Date d = new java.util.Date();
079: mStats.setLastRestartTime(d);
080: assertEquals("Failure on set/getLastRestartTime: ", d, mStats
081: .getLastRestartTime());
082: }
083:
084: /**
085: * Tests get/increment/decrementRegisteredEndpoints.
086: * @throws Exception if an unexpected error occurs.
087: */
088: public void testRegisteredEndpoints() throws Exception {
089: int n = 0;
090: assertEquals("Failure on getRegisteredEndpoints: ",
091: new Integer(n), new Integer(mStats
092: .getRegisteredEndpoints()));
093: mStats.incrementRegisteredEndpoints();
094: ++n;
095: assertEquals("Failure on incrementRegisteredEndpoints: ",
096: new Integer(n), new Integer(mStats
097: .getRegisteredEndpoints()));
098: mStats.decrementRegisteredEndpoints();
099: --n;
100: assertEquals("Failure on decrementRegisteredEndpoints: ",
101: new Integer(n), new Integer(mStats
102: .getRegisteredEndpoints()));
103: }
104:
105: /**
106: * Tests get/increment/decrementRegisteredServices.
107: * @throws Exception if an unexpected error occurs.
108: */
109: public void testRegisteredServices() throws Exception {
110: int n = 0;
111: assertEquals("Failure on getRegisteredServices: ", new Integer(
112: n), new Integer(mStats.getRegisteredServices()));
113: mStats.incrementRegisteredServices();
114: ++n;
115: assertEquals("Failure on incrementRegisteredServices: ",
116: new Integer(n), new Integer(mStats
117: .getRegisteredServices()));
118: mStats.decrementRegisteredServices();
119: --n;
120: assertEquals("Failure on decrementRegisteredServices: ",
121: new Integer(n), new Integer(mStats
122: .getRegisteredServices()));
123: }
124:
125: /**
126: * Test resetStatistics.
127: * @throws Exception if an unexpected error occurs.
128: */
129: public void testResetStatistics() {
130: // First, populate all the fields with values. These methods are all
131: // tested in other junit tests so they are assumed to work here.
132:
133: mStats.incrementRegisteredEndpoints();
134: mStats.incrementRegisteredServices();
135: mStats.getMessagingStatisticsInstance()
136: .incrementActiveExchanges();
137:
138: // Now reset all the fields, then check to see if they all got reset.
139:
140: mStats.resetStatistics();
141: assertEquals("RegisteredEndpoints not reset", new Integer(0),
142: new Integer(mStats.getRegisteredEndpoints()));
143: assertEquals("RegisteredServices not reset", new Integer(0),
144: new Integer(mStats.getRegisteredServices()));
145: assertEquals("ActiveExchanges not reset", new Integer(0),
146: mStats.getMessagingStatisticsInstance()
147: .getActiveExchanges());
148: }
149: }
|