Development of NETCONF RPCs for tr-069 adapter to
[oam/tr069-adapter.git] / mapper / src / test / java / org / commscope / tr069adapter / mapper / ACSNotificationHandlerImplTest.java
1 /*
2  * ============LICENSE_START========================================================================
3  * ONAP : tr-069-adapter
4  * =================================================================================================
5  * Copyright (C) 2020 CommScope Inc Intellectual Property.
6  * =================================================================================================
7  * This tr-069-adapter software file is distributed by CommScope Inc under the Apache License,
8  * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You
9  * may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14  * either express or implied. See the License for the specific language governing permissions and
15  * limitations under the License.
16  * ===============LICENSE_END=======================================================================
17  */
18
19 package org.commscope.tr069adapter.mapper;
20
21 import static org.junit.Assert.assertEquals;
22 import static org.junit.Assert.assertNotNull;
23 import static org.junit.Assert.assertNull;
24
25 import java.util.ArrayList;
26 import java.util.List;
27
28 import org.commscope.tr069adapter.acs.common.DeviceDetails;
29 import org.commscope.tr069adapter.acs.common.DeviceInform;
30 import org.commscope.tr069adapter.acs.common.ParameterDTO;
31 import org.commscope.tr069adapter.acs.common.dto.TR069InformType;
32 import org.commscope.tr069adapter.acs.common.inform.BootInform;
33 import org.commscope.tr069adapter.acs.common.inform.BootstrapInform;
34 import org.commscope.tr069adapter.acs.common.inform.ValueChangeInform;
35 import org.commscope.tr069adapter.mapper.acs.impl.ACSNotificationHandlerImpl;
36 import org.commscope.tr069adapter.mapper.boot.MapperServiceBooter;
37 import org.commscope.tr069adapter.mapper.model.NetConfServerDetails;
38 import org.commscope.tr069adapter.mapper.model.NetconfServerManagementError;
39 import org.commscope.tr069adapter.mapper.netconf.NetConfServerManager;
40 import org.junit.Test;
41 import org.junit.runner.RunWith;
42 import org.mockito.Mock;
43 import org.mockito.Mockito;
44 import org.springframework.beans.factory.annotation.Autowired;
45 import org.springframework.boot.test.context.SpringBootTest;
46 import org.springframework.test.context.junit4.SpringRunner;
47
48 @SpringBootTest(classes = {MapperServiceBooter.class})
49 @RunWith(SpringRunner.class)
50 public class ACSNotificationHandlerImplTest {
51
52   @Autowired
53   ACSNotificationHandlerImpl aCSNotificationHandlerImpl;
54
55   @Mock
56   NetConfServerManager netConfServerManager;
57
58   @Test
59   public void testHandleBootStrapNotification() {
60
61     BootstrapInform notification = new BootstrapInform();
62     List<ParameterDTO> params = new ArrayList<ParameterDTO>();
63     ParameterDTO param = new ParameterDTO();
64     param.setParamName("ExpeditedEvent");
65     params.add(param);
66     notification.setDeviceDetails(getDeviceDetails());
67     notification.setParameters(params);
68     NetConfServerDetails serverInfo = new NetConfServerDetails();
69     serverInfo.setError(NetconfServerManagementError.SUCCESS);
70     Mockito.when(netConfServerManager.createNetconfServer(Mockito.anyString(), Mockito.anyString(),
71         Mockito.anyString(), Mockito.anyString())).thenReturn(serverInfo);
72     /*
73      * String URI = "http://tr069adapter-netconf-server:8181/netConfServerManagerService";
74      * Mockito.when(netConfServerManager.getNetconfServerManagerRestUri()). thenReturn(value)
75      */
76     aCSNotificationHandlerImpl.handleNotification(notification);
77     assertNull(notification.getValueChangeNotification());
78   }
79
80   @Test
81   public void testHandleBootStrapNotificationNegativeScenario() {
82
83     BootstrapInform notification = new BootstrapInform();
84     List<ParameterDTO> params = new ArrayList<ParameterDTO>();
85     ParameterDTO param = new ParameterDTO();
86     param.setParamName("Test");
87     params.add(param);
88     notification.setDeviceDetails(getDeviceDetails());
89     notification.setParameters(params);
90     // Mockito.doReturn(null).when(netConfServerManager.createNetconfServer(Mockito.anyString(),
91     // Mockito.anyString()));
92     aCSNotificationHandlerImpl.handleNotification(notification);
93     assertNull(notification.getValueChangeNotification());
94   }
95
96   @Test
97   public void testHandleBootNotification() {
98
99     BootInform notification = new BootInform();
100     List<ParameterDTO> params = new ArrayList<ParameterDTO>();
101     ParameterDTO param = new ParameterDTO();
102     param.setParamName("Test");
103     params.add(param);
104     notification.setDeviceDetails(getDeviceDetails());
105     notification.setParameters(params);
106     aCSNotificationHandlerImpl.handleNotification(notification);
107     assertNull(notification.getValueChangeNotification());
108   }
109
110   @Test
111   public void testGetDeviceBootNotification() {
112     DeviceInform deviceInform = new DeviceInform();
113     deviceInform.setDeviceDetails(getDeviceDetails());
114     deviceInform.setParameters(getGeneralParams());
115
116     BootInform bInform =
117         ACSNotificationHandlerImpl.getDeviceBootNotification(deviceInform, TR069InformType.BOOT);
118     assertEquals("00005B9A1", bInform.getDeviceDetails().getDeviceId());
119     assertNotNull(bInform.getInformTypeList());
120     assertEquals(TR069InformType.BOOT, bInform.getInformTypeList().get(0));
121   }
122
123   @Test
124   public void testGetDeviceBooStraptNotification() {
125     DeviceInform deviceInform = new DeviceInform();
126     deviceInform.setDeviceDetails(getDeviceDetails());
127     deviceInform.setParameters(getGeneralParams());
128
129     BootstrapInform bsInform = ACSNotificationHandlerImpl
130         .getDeviceBootStrapNotification(deviceInform, TR069InformType.BOOTSTRAP);
131     assertEquals("00005B9A1", bsInform.getDeviceDetails().getDeviceId());
132     assertNotNull(bsInform.getInformTypeList());
133     assertEquals(TR069InformType.BOOTSTRAP, bsInform.getInformTypeList().get(0));
134   }
135
136   @Test
137   public void testGetDeviceValueChangeNotification() {
138     DeviceInform deviceInform = new DeviceInform();
139     deviceInform.setDeviceDetails(getDeviceDetails());
140     deviceInform.setParameters(getGeneralParams());
141
142     ValueChangeInform vInform = ACSNotificationHandlerImpl
143         .getDeviceValueChangeNotification(deviceInform, TR069InformType.VALUECHANGE);
144     assertEquals("00005B9A1", vInform.getDeviceDetails().getDeviceId());
145     assertNotNull(vInform.getInformTypeList());
146     assertEquals(TR069InformType.VALUECHANGE, vInform.getInformTypeList().get(0));
147   }
148
149   private DeviceDetails getDeviceDetails() {
150     DeviceDetails nf = new DeviceDetails();
151     nf.setDeviceId("00005B9A1");
152     nf.setDeviceTypeId(50);
153     nf.setOui("0005B9");
154     nf.setProductClass("LTE_Enterprise_C-RANSC_Cntrl");
155     return nf;
156   }
157
158   private DeviceDetails getDeviceDetailsNegativeCase() {
159     DeviceDetails nf = new DeviceDetails();
160     // nf.setDeviceId("00005B9A1");
161     nf.setDeviceTypeId(50);
162     nf.setOui("0005B9");
163     nf.setProductClass("LTE_Enterprise_C-RANSC_Cntrl");
164     return nf;
165   }
166
167   private ArrayList<ParameterDTO> getGeneralParams() {
168     ArrayList<ParameterDTO> params = new ArrayList<>();
169     params.add(new ParameterDTO("Device.DeviceInfo.ManufacturerOUI", "0005B9"));
170     params.add(new ParameterDTO("Device.DeviceInfo.ProductClass", "LTE_Enterprise_C-RANSC_Cntrl"));
171     params.add(new ParameterDTO("Device.DeviceInfo.HardwareVersion", "750742.00.04"));
172     params.add(new ParameterDTO("Device.DeviceInfo.SoftwareVersion", "4.3.00.231"));
173     params.add(new ParameterDTO("Device.DeviceInfo.Manufacturer", "ORAN"));
174     params.add(new ParameterDTO("Device.DeviceInfo.SerialNumber", "00005B9A1"));
175     params.add(new ParameterDTO("Device.IP.Interface.1.IPv4Address.1.IPAddress", "10.211.5.55"));
176     return params;
177   }
178 }