b68b1b5668fec2dd14583d648f57481d3b486b36
[oam/tr069-adapter.git] / ves-agent / src / test / java / org / commscope / tr069adapter / vesagent / test / VESAgentServiceRestTest.java
1 /*\r
2  * ============LICENSE_START========================================================================\r
3  * ONAP : tr-069-adapter\r
4  * =================================================================================================\r
5  * Copyright (C) 2020 CommScope Inc Intellectual Property.\r
6  * =================================================================================================\r
7  * This tr-069-adapter software file is distributed by CommScope Inc under the Apache License,\r
8  * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You\r
9  * may obtain a copy of the License at\r
10  *\r
11  * http://www.apache.org/licenses/LICENSE-2.0\r
12  *\r
13  * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,\r
14  * either express or implied. See the License for the specific language governing permissions and\r
15  * limitations under the License.\r
16  * ===============LICENSE_END=======================================================================\r
17  */\r
18 \r
19 package org.commscope.tr069adapter.vesagent.test;\r
20 \r
21 import com.fasterxml.jackson.core.JsonProcessingException;\r
22 \r
23 import java.util.ArrayList;\r
24 \r
25 import org.commscope.tr069adapter.acs.common.DeviceDetails;\r
26 import org.commscope.tr069adapter.acs.common.DeviceInform;\r
27 import org.commscope.tr069adapter.acs.common.InformType;\r
28 import org.commscope.tr069adapter.acs.common.ParameterDTO;\r
29 import org.commscope.tr069adapter.acs.common.dto.TR069InformType;\r
30 import org.commscope.tr069adapter.acs.common.inform.BootstrapInform;\r
31 import org.commscope.tr069adapter.acs.common.inform.ValueChangeInform;\r
32 import org.commscope.tr069adapter.mapper.model.NetConfServerDetails;\r
33 import org.commscope.tr069adapter.mapper.model.VESNotification;\r
34 import org.commscope.tr069adapter.mapper.model.VESNotificationResponse;\r
35 import org.commscope.tr069adapter.vesagent.boot.VESAgentServiceBooter;\r
36 import org.commscope.tr069adapter.vesagent.controller.VESAgentService;\r
37 import org.commscope.tr069adapter.vesagent.exception.InvalidFaultOperationException;\r
38 import org.commscope.tr069adapter.vesagent.http.HttpRequestSender;\r
39 import org.junit.Assert;\r
40 import org.junit.Test;\r
41 import org.junit.runner.RunWith;\r
42 import org.mockito.Mockito;\r
43 import org.springframework.beans.factory.annotation.Autowired;\r
44 import org.springframework.boot.test.context.SpringBootTest;\r
45 import org.springframework.boot.test.mock.mockito.MockBean;\r
46 import org.springframework.http.HttpStatus;\r
47 import org.springframework.test.context.junit4.SpringRunner;\r
48 \r
49 @SpringBootTest(classes = {VESAgentServiceBooter.class})\r
50 @RunWith(SpringRunner.class)\r
51 // @WebMvcTest(VESAgentService.class)\r
52 public class VESAgentServiceRestTest {\r
53 \r
54   @Autowired\r
55   VESAgentService agent;\r
56 \r
57   @MockBean\r
58   HttpRequestSender sender;\r
59 \r
60   @Test\r
61   public void processPnfEventTest() throws JsonProcessingException, InvalidFaultOperationException {\r
62     VESNotificationResponse res =\r
63         new VESNotificationResponse(HttpStatus.ACCEPTED.value(), "Sucess");\r
64     Mockito.when(sender.postRequest(Mockito.anyString(), Mockito.anyString())).thenReturn(res);\r
65     VESNotification ves = new VESNotification();\r
66     ves.seteNodeBName("0005B9A1");\r
67     ves.setNetconfDetails(getNetConfDetails());\r
68     DeviceInform inform = new BootstrapInform();\r
69     inform.setDeviceDetails(getDeviceDetails());\r
70     ArrayList<InformType> list = new ArrayList<>();\r
71     list.add(TR069InformType.BOOTSTRAP);\r
72     inform.setInformTypeList(list);\r
73     inform.setParameters(getGeneralParams());\r
74     ves.setDevnotification(inform);\r
75 \r
76     VESNotificationResponse vesResponse = agent.processDeviceNotificationAsVESEvent(ves);\r
77     Assert.assertNotNull(vesResponse);\r
78     Assert.assertEquals(HttpStatus.ACCEPTED.value(), vesResponse.getStatusCode());\r
79 \r
80   }\r
81 \r
82   @Test\r
83   public void processPnfEventWhenEnbNullTest() {\r
84     try {\r
85       VESNotificationResponse res =\r
86           new VESNotificationResponse(HttpStatus.ACCEPTED.value(), "Sucess");\r
87       Mockito.when(sender.postRequest(Mockito.anyString(), Mockito.anyString())).thenReturn(res);\r
88       VESNotification ves = new VESNotification();\r
89       ves.seteNodeBName(null);\r
90       ves.setNetconfDetails(getNetConfDetails());\r
91       DeviceInform inform = new BootstrapInform();\r
92       inform.setDeviceDetails(getDeviceDetails());\r
93       ArrayList<InformType> list = new ArrayList<>();\r
94       list.add(TR069InformType.BOOTSTRAP);\r
95       inform.setInformTypeList(list);\r
96       inform.setParameters(getGeneralParams());\r
97       ves.setDevnotification(inform);\r
98 \r
99       VESNotificationResponse vesResponse = agent.processDeviceNotificationAsVESEvent(ves);\r
100       Assert.assertNotNull(vesResponse);\r
101       Assert.assertEquals(HttpStatus.ACCEPTED.value(), vesResponse.getStatusCode());\r
102       res.getStatusCode();\r
103     } catch (Exception e) {\r
104       e.printStackTrace();\r
105     }\r
106   }\r
107 \r
108   @Test\r
109   public void processFaultEventCriticalTest() {\r
110     try {\r
111       VESNotificationResponse res =\r
112           new VESNotificationResponse(HttpStatus.ACCEPTED.value(), "Sucess");\r
113       Mockito.when(sender.postRequest(Mockito.anyString(), Mockito.anyString())).thenReturn(res);\r
114       VESNotification ves = new VESNotification();\r
115       ves.seteNodeBName("0005B9A1");\r
116       ves.setNetconfDetails(getNetConfDetails());\r
117       DeviceInform inform = new ValueChangeInform();\r
118       inform.setDeviceDetails(getDeviceDetails());\r
119       ArrayList<InformType> list = new ArrayList<>();\r
120       list.add(TR069InformType.VALUECHANGE);\r
121       inform.setInformTypeList(list);\r
122       inform.setParameters(getFaultCritcalParams());\r
123       ves.setDevnotification(inform);\r
124 \r
125       VESNotificationResponse vesResponse = agent.processDeviceNotificationAsVESEvent(ves);\r
126       Assert.assertNotNull(vesResponse);\r
127       Assert.assertEquals(HttpStatus.ACCEPTED.value(), vesResponse.getStatusCode());\r
128     } catch (Exception e) {\r
129       e.printStackTrace();\r
130     }\r
131   }\r
132 \r
133   @Test\r
134   public void processFaultEventWhenEnbNullTest() {\r
135     try {\r
136       VESNotificationResponse res =\r
137           new VESNotificationResponse(HttpStatus.ACCEPTED.value(), "Sucess");\r
138       Mockito.when(sender.postRequest(Mockito.anyString(), Mockito.anyString())).thenReturn(res);\r
139       VESNotification ves = new VESNotification();\r
140       ves.seteNodeBName(null);\r
141       ves.setNetconfDetails(getNetConfDetails());\r
142       DeviceInform inform = new ValueChangeInform();\r
143       inform.setDeviceDetails(getDeviceDetails());\r
144       ArrayList<InformType> list = new ArrayList<>();\r
145       list.add(TR069InformType.VALUECHANGE);\r
146       inform.setInformTypeList(list);\r
147       inform.setParameters(getFaultCritcalParams());\r
148       ves.setDevnotification(inform);\r
149 \r
150       VESNotificationResponse vesResponse = agent.processDeviceNotificationAsVESEvent(ves);\r
151 \r
152       Assert.assertNotNull(vesResponse);\r
153       Assert.assertEquals(HttpStatus.ACCEPTED.value(), vesResponse.getStatusCode());\r
154     } catch (Exception e) {\r
155       e.printStackTrace();\r
156     }\r
157   }\r
158 \r
159   @Test\r
160   public void processFaultEventClearTest() {\r
161     try {\r
162       VESNotificationResponse res =\r
163           new VESNotificationResponse(HttpStatus.ACCEPTED.value(), "Sucess");\r
164       Mockito.when(sender.postRequest(Mockito.anyString(), Mockito.anyString())).thenReturn(res);\r
165       VESNotification ves = new VESNotification();\r
166       ves.seteNodeBName("0005B9A1");\r
167       ves.setNetconfDetails(getNetConfDetails());\r
168       DeviceInform inform = new ValueChangeInform();\r
169       inform.setDeviceDetails(getDeviceDetails());\r
170       ArrayList<InformType> list = new ArrayList<>();\r
171       list.add(TR069InformType.VALUECHANGE);\r
172       inform.setInformTypeList(list);\r
173       inform.setParameters(getFaultClearParams());\r
174       ves.setDevnotification(inform);\r
175 \r
176       VESNotificationResponse vesResponse = agent.processDeviceNotificationAsVESEvent(ves);\r
177       Assert.assertNotNull(vesResponse);\r
178       Assert.assertEquals(HttpStatus.ACCEPTED.value(), vesResponse.getStatusCode());\r
179       res.getStatusCode();\r
180     } catch (Exception e) {\r
181       e.printStackTrace();\r
182     }\r
183   }\r
184 \r
185   @Test\r
186   public void processFaultEventTimeZoneTest() {\r
187     try {\r
188       VESNotificationResponse res =\r
189           new VESNotificationResponse(HttpStatus.ACCEPTED.value(), "Sucess");\r
190       Mockito.when(sender.postRequest(Mockito.anyString(), Mockito.anyString())).thenReturn(res);\r
191       VESNotification ves = new VESNotification();\r
192       ves.seteNodeBName("0005B9A1");\r
193       ves.setNetconfDetails(getNetConfDetails());\r
194       DeviceInform inform = new ValueChangeInform();\r
195       inform.setDeviceDetails(getDeviceDetails());\r
196       ArrayList<InformType> list = new ArrayList<>();\r
197       list.add(TR069InformType.VALUECHANGE);\r
198       inform.setInformTypeList(list);\r
199       inform.setParameters(getFaultClearParams());\r
200       ves.setDevnotification(inform);\r
201 \r
202       VESNotificationResponse vesResponse = agent.processDeviceNotificationAsVESEvent(ves);\r
203       Assert.assertNotNull(vesResponse);\r
204       Assert.assertEquals(HttpStatus.ACCEPTED.value(), vesResponse.getStatusCode());\r
205       res.getStatusCode();\r
206     } catch (Exception e) {\r
207       e.printStackTrace();\r
208     }\r
209   }\r
210 \r
211   /*\r
212    * @Test public void processHBEventTest() { try { VESNotificationResponse res = new\r
213    * VESNotificationResponse(HttpStatus.ACCEPTED.value(), "Sucess");\r
214    * Mockito.when(sender.postRequest(Mockito.anyString(), Mockito.anyString())).thenReturn(res);\r
215    * VESNotification ves = new VESNotification(); ves.seteNodeBName("0005B9A1");\r
216    * ves.setNetconfDetails(getNetConfDetails()); DeviceInform inform = new PeriodicInform();\r
217    * inform.setDeviceDetails(getDeviceDetails()); ArrayList<InformType> list = new ArrayList<>();\r
218    * list.add(TR069InformType.PERIODIC); inform.setInformTypeList(list);\r
219    * inform.setParameters(getGeneralParams()); ves.setDevnotification(inform);\r
220    * \r
221    * VESNotificationResponse vesResponse = agent.processDeviceNotificationAsVESEvent(ves);\r
222    * Assert.assertNotNull(vesResponse); Assert.assertEquals(HttpStatus.ACCEPTED.value(),\r
223    * vesResponse.getStatusCode()); res.getStatusCode(); } catch (Exception e) { e.printStackTrace();\r
224    * } }\r
225    * \r
226    * @Test public void processHBEventWhenEnbNullTest() { try { VESNotificationResponse res = new\r
227    * VESNotificationResponse(HttpStatus.ACCEPTED.value(), "Sucess");\r
228    * Mockito.when(sender.postRequest(Mockito.anyString(), Mockito.anyString())).thenReturn(res);\r
229    * VESNotification ves = new VESNotification(); ves.seteNodeBName(null);\r
230    * ves.setNetconfDetails(getNetConfDetails()); DeviceInform inform = new PeriodicInform();\r
231    * inform.setDeviceDetails(getDeviceDetails()); ArrayList<InformType> list = new ArrayList<>();\r
232    * list.add(TR069InformType.PERIODIC); inform.setInformTypeList(list);\r
233    * inform.setParameters(getGeneralParams()); ves.setDevnotification(inform);\r
234    * \r
235    * VESNotificationResponse vesResponse = agent.processDeviceNotificationAsVESEvent(ves);\r
236    * Assert.assertNotNull(vesResponse); Assert.assertEquals(HttpStatus.ACCEPTED.value(),\r
237    * vesResponse.getStatusCode()); res.getStatusCode(); } catch (Exception e) { e.printStackTrace();\r
238    * } }\r
239    */\r
240   @Test\r
241   public void processOnRestartEventTest() {\r
242     try {\r
243       VESNotificationResponse res =\r
244           new VESNotificationResponse(HttpStatus.ACCEPTED.value(), "Sucess");\r
245       Mockito.when(sender.postRequest(Mockito.anyString(), Mockito.anyString())).thenReturn(res);\r
246       VESNotification ves = new VESNotification();\r
247       ves.seteNodeBName("0005B9A1");\r
248       ves.setNetconfDetails(getNetConfDetails());\r
249       VESNotificationResponse vesResponse = agent.processDeviceNotificationAsVESEvent(ves);\r
250       Assert.assertNotNull(vesResponse);\r
251       Assert.assertEquals(HttpStatus.ACCEPTED.value(), vesResponse.getStatusCode());\r
252     } catch (Exception e) {\r
253       e.printStackTrace();\r
254     }\r
255   }\r
256 \r
257   @Test\r
258   public void processOnRestartEventWhenEnbNullTest() {\r
259     try {\r
260       VESNotificationResponse res =\r
261           new VESNotificationResponse(HttpStatus.ACCEPTED.value(), "Sucess");\r
262       Mockito.when(sender.postRequest(Mockito.anyString(), Mockito.anyString())).thenReturn(res);\r
263       VESNotification ves = new VESNotification();\r
264       ves.seteNodeBName("0005B9A1");\r
265       ves.setNetconfDetails(getNetConfDetails());\r
266       ves.getNetconfDetails().setEnodeBName(null);\r
267       VESNotificationResponse vesResponse = agent.processDeviceNotificationAsVESEvent(ves);\r
268       Assert.assertNotNull(vesResponse);\r
269       Assert.assertEquals(HttpStatus.ACCEPTED.value(), vesResponse.getStatusCode());\r
270     } catch (Exception e) {\r
271       e.printStackTrace();\r
272     }\r
273   }\r
274 \r
275 \r
276   private ArrayList<ParameterDTO> getFaultClearParams() {\r
277     ArrayList<ParameterDTO> params = new ArrayList<>();\r
278     params.add(new ParameterDTO("Device.FaultMgmt.ExpeditedEvent.1.EventTime", ""));\r
279     params\r
280         .add(new ParameterDTO("Device.FaultMgmt.ExpeditedEvent.1.AlarmIdentifier", "0005B9B5-100"));\r
281     params.add(new ParameterDTO("Device.FaultMgmt.ExpeditedEvent.1.NotificationType", "NewAlarm"));\r
282     params.add(new ParameterDTO("Device.FaultMgmt.ExpeditedEvent.1.ManagedObjectInstance",\r
283         "Device.Services.FAPService.{i}.FAPControl.LTE"));\r
284     params.add(new ParameterDTO("Device.FaultMgmt.ExpeditedEvent.1.EventType", "S1 Connection"));\r
285     params.add(new ParameterDTO("Device.FaultMgmt.ExpeditedEvent.1.ProbableCause",\r
286         "S1 connection failure"));\r
287     params.add(\r
288         new ParameterDTO("Device.FaultMgmt.ExpeditedEvent.1.SpecificProblem", "Unsupported PLMN"));\r
289     params.add(new ParameterDTO("Device.FaultMgmt.ExpeditedEvent.1.PerceivedSeverity", "CLEAR"));\r
290     params.add(new ParameterDTO("Device.FaultMgmt.ExpeditedEvent.1.AdditionalText",\r
291         "S1 connection setup FAILED Addional Text"));\r
292     params.add(new ParameterDTO("Device.FaultMgmt.ExpeditedEvent.1.AdditionalInformation",\r
293         "S1 connection setup FAILED Aditional Inf"));\r
294     return params;\r
295   }\r
296 \r
297   private ArrayList<ParameterDTO> getFaultCritcalParams() {\r
298     ArrayList<ParameterDTO> params = new ArrayList<>();\r
299     params.add(new ParameterDTO("Device.FaultMgmt.ExpeditedEvent.1.EventTime", ""));\r
300     params\r
301         .add(new ParameterDTO("Device.FaultMgmt.ExpeditedEvent.1.AlarmIdentifier", "0005B9B5-100"));\r
302     params.add(new ParameterDTO("Device.FaultMgmt.ExpeditedEvent.1.NotificationType", "NewAlarm"));\r
303     params.add(new ParameterDTO("Device.FaultMgmt.ExpeditedEvent.1.ManagedObjectInstance",\r
304         "Device.Services.FAPService.{i}.FAPControl.LTE"));\r
305     params.add(new ParameterDTO("Device.FaultMgmt.ExpeditedEvent.1.EventType", "S1 Connection"));\r
306     params.add(new ParameterDTO("Device.FaultMgmt.ExpeditedEvent.1.ProbableCause",\r
307         "S1 connection failure"));\r
308     params.add(\r
309         new ParameterDTO("Device.FaultMgmt.ExpeditedEvent.1.SpecificProblem", "Unsupported PLMN"));\r
310     params.add(new ParameterDTO("Device.FaultMgmt.ExpeditedEvent.1.PerceivedSeverity", "CRITICAL"));\r
311     params.add(new ParameterDTO("Device.FaultMgmt.ExpeditedEvent.1.AdditionalText",\r
312         "S1 connection setup FAILED Addional Text"));\r
313     params.add(new ParameterDTO("Device.FaultMgmt.ExpeditedEvent.1.AdditionalInformation",\r
314         "S1 connection setup FAILED Aditional Inf | TZD=UTC+00.00"));\r
315     return params;\r
316   }\r
317 \r
318 \r
319 \r
320   private ArrayList<ParameterDTO> getGeneralParams() {\r
321     ArrayList<ParameterDTO> params = new ArrayList<>();\r
322     params.add(new ParameterDTO("Device.DeviceInfo.ManufacturerOUI", "0005B9"));\r
323     params.add(new ParameterDTO("Device.DeviceInfo.ProductClass", "LTE_Enterprise_C-RANSC_Cntrl"));\r
324     params.add(new ParameterDTO("Device.DeviceInfo.HardwareVersion", "750742.00.04"));\r
325     params.add(new ParameterDTO("Device.DeviceInfo.SoftwareVersion", "4.3.00.231"));\r
326     params.add(new ParameterDTO("Device.DeviceInfo.Manufacturer", "ORAN"));\r
327     params.add(new ParameterDTO("Device.DeviceInfo.SerialNumber", "00005B9A1"));\r
328     params.add(new ParameterDTO("Device.IP.Interface.1.IPv4Address.1.IPAddress", "10.211.5.55"));\r
329     return params;\r
330   }\r
331 \r
332   private NetConfServerDetails getNetConfDetails() {\r
333     NetConfServerDetails nf = new NetConfServerDetails();\r
334     nf.setDeviceId("00005B9A1");\r
335     nf.setEnodeBName("0005B9A1");\r
336     nf.setListenAddress("10.211.5.27");\r
337     nf.setListenPort("17830");\r
338     return nf;\r
339   }\r
340 \r
341   private DeviceDetails getDeviceDetails() {\r
342     DeviceDetails nf = new DeviceDetails();\r
343     nf.setDeviceId("00005B9A1");\r
344     nf.setDeviceTypeId(50);\r
345     nf.setOui("0005B9");\r
346     nf.setProductClass("LTE_Enterprise_C-RANSC_Cntrl");\r
347     return nf;\r
348   }\r
349 }\r