1   /*** 
2    * 
3    * Copyright 2004 Protique Ltd
4    * 
5    * Licensed under the Apache License, Version 2.0 (the "License"); 
6    * you may not use this file except in compliance with the License. 
7    * You may obtain a copy of the License at 
8    * 
9    * http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS, 
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
14   * See the License for the specific language governing permissions and 
15   * limitations under the License. 
16   * 
17   **/
18  
19  package org.codehaus.activemq.capacity;
20  
21  import junit.framework.TestCase;
22  
23  /***
24   *
25   * BasicCapacityMonitorTest
26   * @version $Revision: 1.1 $
27   */
28  public class BasicCapacityMonitorTest extends TestCase {
29      public static void main(String[] args) {
30      }
31  
32      /*
33       * @see TestCase#setUp()
34       */
35      protected void setUp() throws Exception {
36          super.setUp();
37      }
38  
39      /*
40       * @see TestCase#tearDown()
41       */
42      protected void tearDown() throws Exception {
43          super.tearDown();
44      }
45  
46      /***
47       * Constructor for BasicCapacityMonitorTest.
48       * @param arg0
49       */
50      public BasicCapacityMonitorTest(String arg0) {
51          super(arg0);
52      }
53  
54      public void testCapacityMonitor() {
55          
56          int maxvalue = 1000;
57          int increment = 10;
58          BasicCapacityMonitor bcm = new BasicCapacityMonitor("test",maxvalue);
59          bcm.setRoundingFactor(5);
60          for (int i =0; i < maxvalue; i+= increment){
61              bcm.setCurrentValue(i);
62              System.out.println(i + " cap = " + bcm.getCurrentCapacity() + " , " + ((maxvalue-i)/10));
63              
64              assertTrue(bcm.getCurrentCapacity()==((maxvalue-i)/10));
65              int roundedCapacity = bcm.getRoundedCapacity();
66              System.out.println("roundec capacity = " + roundedCapacity);
67          }
68          
69      }
70  }