Use lombok annotations for sdnr, simulators
[policy/models.git] / models-interactions / model-impl / sdnr / src / test / java / org / onap / policy / sdnr / PciWrapperTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * sdnr
4  * ================================================================================
5  * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2019 Nordix Foundation.
7  * Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.sdnr;
24
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNotEquals;
27 import static org.junit.Assert.assertNotNull;
28
29 import java.util.function.BiConsumer;
30 import org.junit.Test;
31
32 public class PciWrapperTest {
33
34     private static final String YELLOW_BRICK_ROAD = "YellowBrickRoad";
35     private static final String TORNADO = "Tornado";
36     private static final String THE_EMERALD_CITY = "The Emerald City";
37     private static final String MUNCHKIN = "Munchkin";
38     private static final String VERSION_19 = "19.3.9";
39
40     @Test
41     public void testPciWrapper() {
42         PciWrapper wrapper = new PciWrapper();
43         assertNotNull(wrapper);
44         assertNotEquals(0, wrapper.hashCode());
45
46         wrapper.setVersion(VERSION_19);
47         assertEquals(VERSION_19, wrapper.getVersion());
48
49         wrapper.setCambriaPartition(THE_EMERALD_CITY);
50         assertEquals(THE_EMERALD_CITY, wrapper.getCambriaPartition());
51
52         wrapper.setRpcName(TORNADO);
53         assertEquals(TORNADO, wrapper.getRpcName());
54
55         wrapper.setCorrelationId(YELLOW_BRICK_ROAD);
56         assertEquals(YELLOW_BRICK_ROAD, wrapper.getCorrelationId());
57
58         wrapper.setType(MUNCHKIN);
59         assertEquals(MUNCHKIN, wrapper.getType());
60
61         assertNotEquals(0, wrapper.hashCode());
62
63         assertEquals("PciWrapper(version=19.3.9, cambriaPartition=The ", wrapper.toString().substring(0, 48));
64
65         PciWrapper copiedPciWrapper = new PciWrapper();
66         copiedPciWrapper.setVersion(wrapper.getVersion());
67         copiedPciWrapper.setCambriaPartition(wrapper.getCambriaPartition());
68         copiedPciWrapper.setRpcName(wrapper.getRpcName());
69         copiedPciWrapper.setCorrelationId(wrapper.getCorrelationId());
70         copiedPciWrapper.setType(wrapper.getType());
71
72         assertEquals(wrapper, (Object) wrapper);
73         assertEquals(wrapper, copiedPciWrapper);
74         assertNotEquals(wrapper, null);
75         assertNotEquals(wrapper, (Object) "Hello");
76
77         checkField(VERSION_19, PciWrapper::setVersion);
78         checkField(THE_EMERALD_CITY, PciWrapper::setCambriaPartition);
79         checkField(TORNADO, PciWrapper::setRpcName);
80         checkField(YELLOW_BRICK_ROAD, PciWrapper::setCorrelationId);
81         checkField(MUNCHKIN, PciWrapper::setType);
82     }
83
84     private <T> void checkField(T value, BiConsumer<PciWrapper, T> setter) {
85         PciWrapper details1 = new PciWrapper();
86         PciWrapper details2 = new PciWrapper();
87
88         setter.accept(details2, null);
89
90         setter.accept(details1, value);
91         assertNotEquals(details1, details2);
92
93         setter.accept(details2, value);
94         assertEquals(details1, details2);
95
96         setter.accept(details1, null);
97         assertNotEquals(details1, details2);
98     }
99 }