code coverage for M3
[dcaegen2/services/son-handler.git] / src / test / java / org / onap / dcaegen2 / services / sonhms / model / NotificationTest.java
1 /*******************************************************************************
2  *  ============LICENSE_START=======================================================
3  *  son-handler
4  *  ================================================================================
5  *   Copyright (C) 2019 Wipro Limited.
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
22 package org.onap.dcaegen2.services.sonhms.model;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotEquals;
26
27 import com.fasterxml.jackson.core.JsonParseException;
28 import com.fasterxml.jackson.databind.JsonMappingException;
29 import com.fasterxml.jackson.databind.ObjectMapper;
30
31 import java.io.IOException;
32 import java.util.ArrayList;
33
34 import org.junit.Test;
35 import org.onap.dcaegen2.services.sonhms.model.FapServiceList;
36 import org.onap.dcaegen2.services.sonhms.model.LteNeighborListInUseLteCell;
37 import org.onap.dcaegen2.services.sonhms.model.NeighborListInUse;
38 import org.onap.dcaegen2.services.sonhms.model.Notification;
39 import org.onap.dcaegen2.services.sonhms.model.NotificationCellConfig;
40 import org.onap.dcaegen2.services.sonhms.model.NotificationLte;
41 import org.onap.dcaegen2.services.sonhms.model.NotificationPayload;
42 import org.onap.dcaegen2.services.sonhms.model.NotificationRan;
43 import org.onap.dcaegen2.services.sonhms.model.RadioAccess;
44 import org.onap.dcaegen2.services.sonhms.model.X0005b9Lte;
45
46 public class NotificationTest {
47
48     @Test
49     public void notificationTest() {
50
51         Notification notif = new Notification();
52         LteNeighborListInUseLteCell lteNeighborListInUseLteCell = new LteNeighborListInUseLteCell("pnf1", "true",
53                 "Cell10", "true", "123456", "5", 22, "false");
54
55         ArrayList<LteNeighborListInUseLteCell> list = new ArrayList<>();
56         list.add(lteNeighborListInUseLteCell);
57
58         NeighborListInUse neighborListInUse = new NeighborListInUse(list, "1");
59
60         NotificationRan notificationRan = new NotificationRan(neighborListInUse, "Cell25");
61         NotificationLte notificationLte = new NotificationLte(notificationRan);
62         NotificationCellConfig notificationCell = new NotificationCellConfig(notificationLte);
63         X0005b9Lte lte = new X0005b9Lte(126, "pnf2");
64         FapServiceList fap = new FapServiceList("Cell1", lte, notificationCell);
65
66         ArrayList<FapServiceList> al = new ArrayList<>();
67         al.add(fap);
68
69         RadioAccess radioAccess = new RadioAccess("1", al);
70         NotificationPayload payload = new NotificationPayload(radioAccess);
71
72         notif.setRequestId("9d2d790e-a5f0-11e8-98d0-529269fb1459");
73         notif.setAai("{}");
74         notif.setAction("NeighborListModified");
75         notif.setFrom("SDNR");
76         notif.setVersion("1.0.2");
77         notif.setPayload(payload);
78         assertNotEquals("159", notif.getRequestId());
79
80         String test = "{\n" + "  \"requestID\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459\",\n" + "  \"AAI\": {},\n"
81                 + "  \"from\": \"SDNR\",\n" + "  \"version\": \"1.0.2\",\n"
82                 + "  \"Action\": \"NeighborListModified\",\n" + "  \"Payload\": {\n" + "\n" + "   \"RadioAccess\":{  \n"
83                 + "      \"FAPServiceNumberOfEntries\":\"2\",\n" + "      \"FAPServiceList\":[  \n" + "         {  \n"
84                 + "            \"alias\":\"Cell1\",\n" + "            \"X0005b9Lte\":{  \n"
85                 + "               \"phyCellIdInUse\":\"35\",\n" + "               \"pnfName\":\"DU-1\"\n"
86                 + "            },\n" + "            \"CellConfig\":{  \n" + "               \"LTE\":{  \n"
87                 + "                  \"RAN\":{  \n" + "                     \"CellIdentity\":\"Cell1\",\n"
88                 + "                     \"NeighborListInUse\":{  \n"
89                 + "                        \"LTECellNumberOfEntries\":\"2\",\n"
90                 + "                        \"LTENeighborListInUseLTECell\":[  \n" + "                           {  \n"
91                 + "                              \"pnfName\":\"DU-2\",\n"
92                 + "                              \"enable\":\"true\",\n"
93                 + "                              \"alias\":\"Cell10\",\n"
94                 + "                              \"mustInclude\":\"true\",\n"
95                 + "                              \"plmnid\":\"123456\",\n"
96                 + "                              \"cid\":\"2\",\n"
97                 + "                              \"phyCellId\":\"22\",\n"
98                 + "                              \"blacklisted\":\"false\"\n" + "                           },\n"
99                 + "                           {  \n" + "                              \"pnfName\":\"DU-3\",\n"
100                 + "                              \"enable\":\"true\",\n"
101                 + "                              \"alias\":\"Cell15\",\n"
102                 + "                              \"mustInclude\":\"true\",\n"
103                 + "                              \"plmnid\":\"123456\",\n"
104                 + "                              \"cid\":\"5\",\n"
105                 + "                              \"phyCellId\":\"24\",\n"
106                 + "                              \"blacklisted\":\"false\"\n" + "                           }\n"
107                 + "                        ]\n" + "                     }\n" + "                  }\n"
108                 + "               }\n" + "            }\n" + "         }\n" + "         ]\n" + "   }\n" + "}\n" + "}";
109
110         ObjectMapper mapper = new ObjectMapper();
111         Notification notif1 = new Notification();
112         try {
113             notif1 = mapper.readValue(test, Notification.class);
114         } catch (JsonParseException e) {
115             e.printStackTrace();
116         } catch (JsonMappingException e) {
117             e.printStackTrace();
118         } catch (IOException e) {
119             e.printStackTrace();
120         }
121
122         assertNotEquals(notif, notif1);
123         assertEquals(notif.getAction(), notif1.getAction());
124         assertEquals(notif.getAai().toString(), notif1.getAai().toString());
125
126     }
127
128 }