495d9f13492c659d45cb080d7fcedc42fadb22c3
[policy/drools-applications.git] / controlloop / common / model-impl / aai / src / test / java / org / onap / policy / aai / PnfInstanceTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * aai
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
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.aai;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNotEquals;
26 import static org.junit.Assert.assertNotNull;
27 import static org.junit.Assert.assertTrue;
28
29 import org.junit.AfterClass;
30 import org.junit.BeforeClass;
31 import org.junit.Test;
32 import org.onap.policy.aai.util.Serialization;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35
36 public class PnfInstanceTest {
37     private static final Logger logger = LoggerFactory.getLogger(PnfInstanceTest.class);
38
39     @BeforeClass
40     public static void setUpBeforeClass() throws Exception {}
41
42     @AfterClass
43     public static void tearDownAfterClass() throws Exception {}
44
45     @Test
46     public void test() {
47         PnfInstance pnfInstance = new PnfInstance();
48         pnfInstance.setPnfInstanceName("pnf-instance-name-test");
49         pnfInstance.setPnfName("pnf-name-test");
50         pnfInstance.setPnfType(PnfType.ENODEB);
51         pnfInstance.setPnfSerial("pnf-serial-test");
52         assertNotNull(pnfInstance);
53         assertEquals("pnf-instance-name-test", pnfInstance.getPnfInstanceName());
54
55         PnfInstance pnfInstanceNull = new PnfInstance(null);
56         assertNotNull(pnfInstanceNull);
57
58         PnfInstance pnfInstanceClone = new PnfInstance(pnfInstance);
59         assertNotNull(pnfInstanceClone);
60
61         assertEquals("pnf-name-test", pnfInstanceClone.getPnfName());
62         assertEquals(PnfType.ENODEB, pnfInstanceClone.getPnfType());
63         assertEquals("pnf-serial-test", pnfInstanceClone.getPnfSerial());
64
65         assertEquals("PNFInstance [PNFName=pnf-name-test, PNFInstanceName=pnf-instance-name-test, PNFType=eNodeB, "
66                 + "PNFSerial=pnf-serial-test]", pnfInstanceClone.toString());
67         assertNotEquals(0, pnfInstanceClone.hashCode());
68         assertNotEquals(0, new Pnf().hashCode());
69
70         PnfInstance pnfInstanceOther0 = new PnfInstance();
71         pnfInstanceOther0.setPnfName("pnf-name-test");
72
73         PnfInstance pnfInstanceOther1 = new PnfInstance(pnfInstance);
74         pnfInstanceOther1.setPnfName("pnf-name-test-diff");
75
76         PnfInstance pnfInstanceOther2 = new PnfInstance(pnfInstance);
77         pnfInstanceOther2.setPnfInstanceName("pnf-instance-name-test-diff");
78
79         PnfInstance pnfInstanceOther3 = new PnfInstance(pnfInstance);
80         pnfInstanceOther3.setPnfName(null);
81
82         PnfInstance pnfInstanceOther4 = new PnfInstance(pnfInstance);
83         pnfInstanceOther4.setPnfSerial(null);
84
85         PnfInstance pnfInstanceOther5 = new PnfInstance(pnfInstance);
86         pnfInstanceOther5.setPnfSerial("pnf-serial-test-diff");
87
88         assertTrue(pnfInstance.equals(pnfInstance));
89         assertFalse(pnfInstance.equals(null));
90         assertFalse(pnfInstance.equals("hello"));
91         assertTrue(pnfInstance.equals(pnfInstanceClone));
92         assertFalse(pnfInstance.equals(new Pnf()));
93         assertFalse(new Pnf().equals(pnfInstance));
94         assertFalse(new Pnf().equals(pnfInstanceOther0));
95         assertFalse(pnfInstanceOther0.equals(pnfInstance));
96         assertFalse(pnfInstanceOther1.equals(pnfInstance));
97         assertFalse(pnfInstanceOther2.equals(pnfInstance));
98         assertFalse(pnfInstanceOther3.equals(pnfInstance));
99         assertFalse(pnfInstanceOther4.equals(pnfInstance));
100         assertFalse(pnfInstanceOther5.equals(pnfInstance));
101
102         logger.info(Serialization.gsonPretty.toJson(pnfInstance));
103     }
104
105 }