2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2019 Nordix Foundation.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.aai;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertNotEquals;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertTrue;
30 import org.junit.AfterClass;
31 import org.junit.BeforeClass;
32 import org.junit.Test;
33 import org.onap.policy.aai.util.Serialization;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
37 public class PnfInstanceTest {
38 private static final Logger logger = LoggerFactory.getLogger(PnfInstanceTest.class);
41 public static void setUpBeforeClass() throws Exception {}
44 public static void tearDownAfterClass() throws Exception {}
48 PnfInstance pnfInstance = new PnfInstance();
49 pnfInstance.setPnfInstanceName("pnf-instance-name-test");
50 pnfInstance.setPnfName("pnf-name-test");
51 pnfInstance.setPnfType(PnfType.ENODEB);
52 pnfInstance.setPnfSerial("pnf-serial-test");
53 assertNotNull(pnfInstance);
54 assertEquals("pnf-instance-name-test", pnfInstance.getPnfInstanceName());
56 PnfInstance pnfInstanceNull = new PnfInstance(null);
57 assertNotNull(pnfInstanceNull);
59 PnfInstance pnfInstanceClone = new PnfInstance(pnfInstance);
60 assertNotNull(pnfInstanceClone);
62 assertEquals("pnf-name-test", pnfInstanceClone.getPnfName());
63 assertEquals(PnfType.ENODEB, pnfInstanceClone.getPnfType());
64 assertEquals("pnf-serial-test", pnfInstanceClone.getPnfSerial());
66 assertEquals("PNFInstance [PNFName=pnf-name-test, PNFInstanceName=pnf-instance-name-test, PNFType=eNodeB, "
67 + "PNFSerial=pnf-serial-test]", pnfInstanceClone.toString());
68 assertNotEquals(0, pnfInstanceClone.hashCode());
69 assertNotEquals(0, new Pnf().hashCode());
71 PnfInstance pnfInstanceOther0 = new PnfInstance();
72 pnfInstanceOther0.setPnfName("pnf-name-test");
74 PnfInstance pnfInstanceOther1 = new PnfInstance(pnfInstance);
75 pnfInstanceOther1.setPnfName("pnf-name-test-diff");
77 PnfInstance pnfInstanceOther2 = new PnfInstance(pnfInstance);
78 pnfInstanceOther2.setPnfInstanceName("pnf-instance-name-test-diff");
80 PnfInstance pnfInstanceOther3 = new PnfInstance(pnfInstance);
81 pnfInstanceOther3.setPnfName(null);
83 PnfInstance pnfInstanceOther4 = new PnfInstance(pnfInstance);
84 pnfInstanceOther4.setPnfSerial(null);
86 PnfInstance pnfInstanceOther5 = new PnfInstance(pnfInstance);
87 pnfInstanceOther5.setPnfSerial("pnf-serial-test-diff");
89 assertTrue(pnfInstance.equals(pnfInstance));
90 assertFalse(pnfInstance.equals(null));
91 assertFalse(pnfInstance.equals("hello"));
92 assertTrue(pnfInstance.equals(pnfInstanceClone));
93 assertFalse(pnfInstance.equals(new Pnf()));
94 assertFalse(new Pnf().equals(pnfInstance));
95 assertFalse(new Pnf().equals(pnfInstanceOther0));
96 assertFalse(pnfInstanceOther0.equals(pnfInstance));
97 assertFalse(pnfInstanceOther1.equals(pnfInstance));
98 assertFalse(pnfInstanceOther2.equals(pnfInstance));
99 assertFalse(pnfInstanceOther3.equals(pnfInstance));
100 assertFalse(pnfInstanceOther4.equals(pnfInstance));
101 assertFalse(pnfInstanceOther5.equals(pnfInstance));
103 logger.info(Serialization.gsonPretty.toJson(pnfInstance));