5d627a906e6a0116c7895f82a4bf3a14b0ff2d81
[policy/drools-applications.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * Copyright (C) 2018 Ericsson. All rights reserved.
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  * ============LICENSE_END=========================================================
17  */
18 package org.onap.policy.controlloop.policy;
19
20 import static org.junit.Assert.*;
21
22 import org.junit.Test;
23
24 public class OperationsAccumulateParamsTest {
25
26         @Test
27         public void testConstructor() {
28                 OperationsAccumulateParams operationsAccumulateParams = new OperationsAccumulateParams();
29                 assertNull(operationsAccumulateParams.getPeriod());
30                 assertNull(operationsAccumulateParams.getLimit());
31         }
32
33         @Test
34         public void testConstructorOperationsAccumulateParams() {
35                 String period = "15m";
36                 Integer limit = 10;
37                 OperationsAccumulateParams operationsAccumulateParams1 = new OperationsAccumulateParams(period, limit);
38                 OperationsAccumulateParams operationsAccumulateParams2 = new OperationsAccumulateParams(operationsAccumulateParams1);
39                 assertEquals(period, operationsAccumulateParams1.getPeriod());
40                 assertEquals(limit, operationsAccumulateParams2.getLimit());            
41         }
42
43         @Test
44         public void testOperationsAccumulateParamsStringInteger() {
45                 String period = "15m";
46                 Integer limit = 10;
47                 OperationsAccumulateParams operationsAccumulateParams = new OperationsAccumulateParams(period, limit);
48                 assertEquals(period, operationsAccumulateParams.getPeriod());
49                 assertEquals(limit, operationsAccumulateParams.getLimit());     
50         }
51
52         @Test
53         public void testSetAndGetPeriod() {
54                 String period = "15m";
55                 OperationsAccumulateParams operationsAccumulateParams = new OperationsAccumulateParams();
56                 operationsAccumulateParams.setPeriod(period);
57                 assertEquals(period, operationsAccumulateParams.getPeriod());   
58         }
59
60         @Test
61         public void testSetLimit() {
62                 Integer limit = 10;
63                 OperationsAccumulateParams operationsAccumulateParams = new OperationsAccumulateParams();
64                 operationsAccumulateParams.setLimit(limit);
65                 assertEquals(limit, operationsAccumulateParams.getLimit());     }
66
67         @Test
68         public void testToString() {
69                 String period = "15m";
70                 Integer limit = 10;
71                 OperationsAccumulateParams operationsAccumulateParams = new OperationsAccumulateParams(period, limit);
72                 assertEquals("OperationsAccumulateParams [period=15m, limit=10]", operationsAccumulateParams.toString());
73         }
74
75         @Test
76         public void testEqualsAndHashCode() {
77                 String period = "15m";
78                 Integer limit = 10;
79                 OperationsAccumulateParams operationsAccumulateParams1 = new OperationsAccumulateParams();      
80                 OperationsAccumulateParams operationsAccumulateParams2 = new OperationsAccumulateParams();      
81                 
82                 assertTrue(operationsAccumulateParams1.equals(operationsAccumulateParams2));
83                 
84                 operationsAccumulateParams1.setPeriod(period);
85                 assertFalse(operationsAccumulateParams1.equals(operationsAccumulateParams2));
86                 operationsAccumulateParams2.setPeriod(period);
87                 assertTrue(operationsAccumulateParams1.equals(operationsAccumulateParams2));
88                 assertEquals(operationsAccumulateParams1.hashCode(), operationsAccumulateParams2.hashCode());
89                 
90                 operationsAccumulateParams1.setLimit(limit);;
91                 assertFalse(operationsAccumulateParams1.equals(operationsAccumulateParams2));
92                 operationsAccumulateParams2.setLimit(limit);
93                 assertTrue(operationsAccumulateParams1.equals(operationsAccumulateParams2));
94                 assertEquals(operationsAccumulateParams1.hashCode(), operationsAccumulateParams2.hashCode());
95         }
96         
97         
98         @Test
99         public void testEqualsSameObject(){
100                 OperationsAccumulateParams operationsAccumulateParams = new OperationsAccumulateParams();       
101                 assertTrue(operationsAccumulateParams.equals(operationsAccumulateParams));
102         }
103         
104         @Test
105         public void testEqualsNull(){
106                 OperationsAccumulateParams operationsAccumulateParams = new OperationsAccumulateParams();       
107                 assertFalse(operationsAccumulateParams.equals(null));
108         }
109         
110         @Test
111         public void testEqualsInstanceOfDiffClass(){
112                 OperationsAccumulateParams operationsAccumulateParams = new OperationsAccumulateParams();       
113                 assertFalse(operationsAccumulateParams.equals(""));
114         }
115
116 }