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