Merge "Fix sonar issues in models: sdc to vfc"
[policy/models.git] / models-interactions / model-impl / aai / src / test / java / org / onap / policy / aai / PnfInstanceTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * aai
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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20 */
21
22 package org.onap.policy.aai;
23
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;
29
30 import org.junit.Test;
31 import org.onap.policy.aai.util.Serialization;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34
35 public class PnfInstanceTest {
36     private static final String PNF_NAME_TEST = "pnf-name-test";
37     private static final Logger logger = LoggerFactory.getLogger(PnfInstanceTest.class);
38
39     @Test
40     public void test() {
41         PnfInstance pnfInstance = new PnfInstance();
42         pnfInstance.setPnfInstanceName("pnf-instance-name-test");
43         pnfInstance.setPnfName(PNF_NAME_TEST);
44         pnfInstance.setPnfType(PnfType.ENODEB);
45         pnfInstance.setPnfSerial("pnf-serial-test");
46         assertNotNull(pnfInstance);
47         assertEquals("pnf-instance-name-test", pnfInstance.getPnfInstanceName());
48
49         PnfInstance pnfInstanceNull = new PnfInstance(null);
50         assertNotNull(pnfInstanceNull);
51
52         PnfInstance pnfInstanceClone = new PnfInstance(pnfInstance);
53         assertNotNull(pnfInstanceClone);
54
55         assertEquals(PNF_NAME_TEST, pnfInstanceClone.getPnfName());
56         assertEquals(PnfType.ENODEB, pnfInstanceClone.getPnfType());
57         assertEquals("pnf-serial-test", pnfInstanceClone.getPnfSerial());
58
59         assertEquals("PNFInstance [PNFName=pnf-name-test, PNFInstanceName=pnf-instance-name-test, PNFType=eNodeB, "
60                 + "PNFSerial=pnf-serial-test]", pnfInstanceClone.toString());
61         assertNotEquals(0, pnfInstanceClone.hashCode());
62         assertNotEquals(0, new Pnf().hashCode());
63
64         PnfInstance pnfInstanceOther0 = new PnfInstance();
65         pnfInstanceOther0.setPnfName(PNF_NAME_TEST);
66
67         PnfInstance pnfInstanceOther1 = new PnfInstance(pnfInstance);
68         pnfInstanceOther1.setPnfName("pnf-name-test-diff");
69
70         PnfInstance pnfInstanceOther2 = new PnfInstance(pnfInstance);
71         pnfInstanceOther2.setPnfInstanceName("pnf-instance-name-test-diff");
72
73         PnfInstance pnfInstanceOther3 = new PnfInstance(pnfInstance);
74         pnfInstanceOther3.setPnfName(null);
75
76         PnfInstance pnfInstanceOther4 = new PnfInstance(pnfInstance);
77         pnfInstanceOther4.setPnfSerial(null);
78
79         PnfInstance pnfInstanceOther5 = new PnfInstance(pnfInstance);
80         pnfInstanceOther5.setPnfSerial("pnf-serial-test-diff");
81
82         assertTrue(pnfInstance.equals(pnfInstance));
83         assertFalse(pnfInstance.equals(null));
84         assertFalse(pnfInstance.equals("hello"));
85         assertTrue(pnfInstance.equals(pnfInstanceClone));
86         assertFalse(pnfInstance.equals(new Pnf()));
87         assertFalse(new Pnf().equals(pnfInstance));
88         assertFalse(new Pnf().equals(pnfInstanceOther0));
89         assertFalse(pnfInstanceOther0.equals(pnfInstance));
90         assertFalse(pnfInstanceOther1.equals(pnfInstance));
91         assertFalse(pnfInstanceOther2.equals(pnfInstance));
92         assertFalse(pnfInstanceOther3.equals(pnfInstance));
93         assertFalse(pnfInstanceOther4.equals(pnfInstance));
94         assertFalse(pnfInstanceOther5.equals(pnfInstance));
95
96         logger.info(Serialization.gsonPretty.toJson(pnfInstance));
97     }
98
99 }