2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
23 package org.onap.policy.sdnr;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNotEquals;
27 import static org.junit.Assert.assertNotNull;
29 import java.util.function.BiConsumer;
30 import org.junit.Test;
32 public class PciWrapperTest {
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";
41 public void testPciWrapper() {
42 PciWrapper wrapper = new PciWrapper();
43 assertNotNull(wrapper);
44 assertNotEquals(0, wrapper.hashCode());
46 wrapper.setVersion(VERSION_19);
47 assertEquals(VERSION_19, wrapper.getVersion());
49 wrapper.setCambriaPartition(THE_EMERALD_CITY);
50 assertEquals(THE_EMERALD_CITY, wrapper.getCambriaPartition());
52 wrapper.setRpcName(TORNADO);
53 assertEquals(TORNADO, wrapper.getRpcName());
55 wrapper.setCorrelationId(YELLOW_BRICK_ROAD);
56 assertEquals(YELLOW_BRICK_ROAD, wrapper.getCorrelationId());
58 wrapper.setType(MUNCHKIN);
59 assertEquals(MUNCHKIN, wrapper.getType());
61 assertNotEquals(0, wrapper.hashCode());
63 assertEquals("PciWrapper(version=19.3.9, cambriaPartition=The ", wrapper.toString().substring(0, 48));
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());
72 assertEquals(wrapper, (Object) wrapper);
73 assertEquals(wrapper, copiedPciWrapper);
74 assertNotEquals(wrapper, null);
75 assertNotEquals(wrapper, (Object) "Hello");
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);
84 private <T> void checkField(T value, BiConsumer<PciWrapper, T> setter) {
85 PciWrapper details1 = new PciWrapper();
86 PciWrapper details2 = new PciWrapper();
88 setter.accept(details2, null);
90 setter.accept(details1, value);
91 assertNotEquals(details1, details2);
93 setter.accept(details2, value);
94 assertEquals(details1, details2);
96 setter.accept(details1, null);
97 assertNotEquals(details1, details2);