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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=======================================================================
19 package org.commscope.tr069adapter.mapper;
21 import static org.junit.Assert.assertEquals;
22 import static org.junit.Assert.assertNotNull;
23 import static org.junit.Assert.assertNull;
25 import java.util.ArrayList;
26 import java.util.List;
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;
48 @SpringBootTest(classes = {MapperServiceBooter.class})
49 @RunWith(SpringRunner.class)
50 public class ACSNotificationHandlerImplTest {
53 ACSNotificationHandlerImpl aCSNotificationHandlerImpl;
56 NetConfServerManager netConfServerManager;
59 public void testHandleBootStrapNotification() {
61 BootstrapInform notification = new BootstrapInform();
62 List<ParameterDTO> params = new ArrayList<ParameterDTO>();
63 ParameterDTO param = new ParameterDTO();
64 param.setParamName("ExpeditedEvent");
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);
73 * String URI = "http://tr069adapter-netconf-server:8181/netConfServerManagerService";
74 * Mockito.when(netConfServerManager.getNetconfServerManagerRestUri()). thenReturn(value)
76 aCSNotificationHandlerImpl.handleNotification(notification);
77 assertNull(notification.getValueChangeNotification());
81 public void testHandleBootStrapNotificationNegativeScenario() {
83 BootstrapInform notification = new BootstrapInform();
84 List<ParameterDTO> params = new ArrayList<ParameterDTO>();
85 ParameterDTO param = new ParameterDTO();
86 param.setParamName("Test");
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());
97 public void testHandleBootNotification() {
99 BootInform notification = new BootInform();
100 List<ParameterDTO> params = new ArrayList<ParameterDTO>();
101 ParameterDTO param = new ParameterDTO();
102 param.setParamName("Test");
104 notification.setDeviceDetails(getDeviceDetails());
105 notification.setParameters(params);
106 aCSNotificationHandlerImpl.handleNotification(notification);
107 assertNull(notification.getValueChangeNotification());
111 public void testGetDeviceBootNotification() {
112 DeviceInform deviceInform = new DeviceInform();
113 deviceInform.setDeviceDetails(getDeviceDetails());
114 deviceInform.setParameters(getGeneralParams());
117 ACSNotificationHandlerImpl.getDeviceBootNotification(deviceInform, TR069InformType.BOOT);
118 assertEquals("00005B9A1", bInform.getDeviceDetails().getDeviceId());
119 assertNotNull(bInform.getInformTypeList());
120 assertEquals(TR069InformType.BOOT, bInform.getInformTypeList().get(0));
124 public void testGetDeviceBooStraptNotification() {
125 DeviceInform deviceInform = new DeviceInform();
126 deviceInform.setDeviceDetails(getDeviceDetails());
127 deviceInform.setParameters(getGeneralParams());
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));
137 public void testGetDeviceValueChangeNotification() {
138 DeviceInform deviceInform = new DeviceInform();
139 deviceInform.setDeviceDetails(getDeviceDetails());
140 deviceInform.setParameters(getGeneralParams());
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));
149 private DeviceDetails getDeviceDetails() {
150 DeviceDetails nf = new DeviceDetails();
151 nf.setDeviceId("00005B9A1");
152 nf.setDeviceTypeId(50);
154 nf.setProductClass("LTE_Enterprise_C-RANSC_Cntrl");
158 private DeviceDetails getDeviceDetailsNegativeCase() {
159 DeviceDetails nf = new DeviceDetails();
160 // nf.setDeviceId("00005B9A1");
161 nf.setDeviceTypeId(50);
163 nf.setProductClass("LTE_Enterprise_C-RANSC_Cntrl");
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"));