9e68a7389d9c4471bc4ffff0db0ad17284855225
[policy/drools-applications.git] / controlloop / common / policy-yaml / src / test / java / org / onap / policy / controlloop / policy / OperationsAccumulateParamsTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * Copyright (C) 2018 Ericsson. All rights reserved.
4  * Modifications Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  * 
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  * 
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  * ============LICENSE_END=========================================================
18  */
19
20 package org.onap.policy.controlloop.policy;
21
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertFalse;
24 import static org.junit.Assert.assertNull;
25 import static org.junit.Assert.assertTrue;
26
27 import org.junit.Test;
28
29 public class OperationsAccumulateParamsTest {
30
31     @Test
32     public void testConstructor() {
33         OperationsAccumulateParams operationsAccumulateParams = new OperationsAccumulateParams();
34         assertNull(operationsAccumulateParams.getPeriod());
35         assertNull(operationsAccumulateParams.getLimit());
36     }
37
38     @Test
39     public void testConstructorOperationsAccumulateParams() {
40         String period = "15m";
41         Integer limit = 10;
42         OperationsAccumulateParams operationsAccumulateParams1 = 
43                         new OperationsAccumulateParams(period, limit);
44         OperationsAccumulateParams operationsAccumulateParams2 = 
45                         new OperationsAccumulateParams(operationsAccumulateParams1);
46         assertEquals(period, operationsAccumulateParams1.getPeriod());
47         assertEquals(limit, operationsAccumulateParams2.getLimit());
48     }
49
50     @Test
51     public void testOperationsAccumulateParamsStringInteger() {
52         String period = "15m";
53         Integer limit = 10;
54         OperationsAccumulateParams operationsAccumulateParams = new OperationsAccumulateParams(period, limit);
55         assertEquals(period, operationsAccumulateParams.getPeriod());
56         assertEquals(limit, operationsAccumulateParams.getLimit());
57     }
58
59     @Test
60     public void testSetAndGetPeriod() {
61         String period = "15m";
62         OperationsAccumulateParams operationsAccumulateParams = new OperationsAccumulateParams();
63         operationsAccumulateParams.setPeriod(period);
64         assertEquals(period, operationsAccumulateParams.getPeriod());
65     }
66
67     @Test
68     public void testSetLimit() {
69         Integer limit = 10;
70         OperationsAccumulateParams operationsAccumulateParams = new OperationsAccumulateParams();
71         operationsAccumulateParams.setLimit(limit);
72         assertEquals(limit, operationsAccumulateParams.getLimit());
73     }
74
75     @Test
76     public void testToString() {
77         String period = "15m";
78         Integer limit = 10;
79         OperationsAccumulateParams operationsAccumulateParams = new OperationsAccumulateParams(period, limit);
80         assertEquals("OperationsAccumulateParams [period=15m, limit=10]", operationsAccumulateParams.toString());
81     }
82
83     @Test
84     public void testEqualsAndHashCode() {
85         final String period = "15m";
86         final Integer limit = 10;
87         OperationsAccumulateParams operationsAccumulateParams1 = new OperationsAccumulateParams();
88         OperationsAccumulateParams operationsAccumulateParams2 = new OperationsAccumulateParams();
89
90         assertTrue(operationsAccumulateParams1.equals(operationsAccumulateParams2));
91
92         operationsAccumulateParams1.setPeriod(period);
93         assertFalse(operationsAccumulateParams1.equals(operationsAccumulateParams2));
94         operationsAccumulateParams2.setPeriod(period);
95         assertTrue(operationsAccumulateParams1.equals(operationsAccumulateParams2));
96         assertEquals(operationsAccumulateParams1.hashCode(), operationsAccumulateParams2.hashCode());
97
98         operationsAccumulateParams1.setLimit(limit);;
99         assertFalse(operationsAccumulateParams1.equals(operationsAccumulateParams2));
100         operationsAccumulateParams2.setLimit(limit);
101         assertTrue(operationsAccumulateParams1.equals(operationsAccumulateParams2));
102         assertEquals(operationsAccumulateParams1.hashCode(), operationsAccumulateParams2.hashCode());
103     }
104
105
106     @Test
107     public void testEqualsSameObject() {
108         OperationsAccumulateParams operationsAccumulateParams = new OperationsAccumulateParams();
109         assertTrue(operationsAccumulateParams.equals(operationsAccumulateParams));
110     }
111
112     @Test
113     public void testEqualsNull() {
114         OperationsAccumulateParams operationsAccumulateParams = new OperationsAccumulateParams();
115         assertFalse(operationsAccumulateParams.equals(null));
116     }
117
118     @Test
119     public void testEqualsInstanceOfDiffClass() {
120         OperationsAccumulateParams operationsAccumulateParams = new OperationsAccumulateParams();
121         assertFalse(operationsAccumulateParams.equals(""));
122     }
123
124 }