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