Adjust sparky parent pom
[aai/sparky-be.git] / sparkybe-onap-service / src / test / java / org / onap / aai / sparky / analytics / HistoricalCounterTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 Amdocs
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.aai.sparky.analytics;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertTrue;
26
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.onap.aai.sparky.analytics.HistoricalCounter;
30
31 public class HistoricalCounterTest {
32         
33         
34         private HistoricalCounter historicalCounter;
35         private HistoricalCounter historicalCount; 
36         @Before
37           public void init() throws Exception {
38              historicalCounter = new HistoricalCounter(true);
39              historicalCount = new HistoricalCounter(false); 
40           }
41         
42         @Test 
43         public void successfullInitialization() {
44                 assertEquals(-1, historicalCounter.getMin(),0);
45                 assertEquals(0, historicalCounter.getMax(),0);
46                 assertEquals(0, historicalCounter.getNumSamples(),0);
47                 assertEquals(0, historicalCounter.getNumSamples(),0);
48                 assertEquals(0.0, historicalCounter.getValue(),0);
49                 assertEquals(0, historicalCounter.getAvg(),0);
50                 assertTrue(historicalCounter.isSingleValue());
51                 
52         }
53         
54         @Test 
55         public void updateValuesAndReset() {
56                 historicalCounter.update(-1);
57                 assertEquals(0, historicalCounter.getValue(),0);
58                 historicalCounter.update(10);
59                 assertEquals(10, historicalCounter.getValue(),0);
60                 historicalCounter.reset();
61                 assertEquals(-1, historicalCounter.getMin(),0);
62             assertEquals(0, historicalCounter.getMax(),0);
63                 assertEquals(0, historicalCounter.getNumSamples(),0);
64                 assertEquals(0, historicalCounter.getNumSamples(),0);
65                 assertEquals(0.0, historicalCounter.getValue(),0);
66                 
67         }
68         
69         @Test 
70         public void updateValues() {
71                 historicalCount.update(2);
72                 assertEquals(2, historicalCount.getMin(),0);
73                 historicalCount.setMin(10);
74                 historicalCount.update(3);
75                 assertEquals(3, historicalCount.getMin(),0);
76                 historicalCount.setMax(1);
77                 historicalCount.update(4);
78                 assertEquals(4, historicalCount.getMax(),0);
79                 historicalCount.setTotalOfSamples(10);
80                 historicalCount.setNumSamples(2);
81                 assertEquals(5, historicalCount.getAvg(),0);
82                 historicalCount.setTotalOfSamples(10);
83                 assertEquals(10, historicalCount.getTotalOfSamples(),0);
84                 historicalCount.setMaintainSingleValue(true);
85                 assertTrue(historicalCounter.isSingleValue());
86                 
87         }
88                 
89                 
90
91 }