Initial source code
[oam/tr069-adapter.git] / mapper / src / test / java / org / commscope / tr069adapter / mapper / ACSNotificationHandlerImplTest.java
diff --git a/mapper/src/test/java/org/commscope/tr069adapter/mapper/ACSNotificationHandlerImplTest.java b/mapper/src/test/java/org/commscope/tr069adapter/mapper/ACSNotificationHandlerImplTest.java
new file mode 100644 (file)
index 0000000..a2e91ec
--- /dev/null
@@ -0,0 +1,178 @@
+/*\r
+ * ============LICENSE_START========================================================================\r
+ * ONAP : tr-069-adapter\r
+ * =================================================================================================\r
+ * Copyright (C) 2020 CommScope Inc Intellectual Property.\r
+ * =================================================================================================\r
+ * This tr-069-adapter software file is distributed by CommScope Inc under the Apache License,\r
+ * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You\r
+ * may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,\r
+ * either express or implied. See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ===============LICENSE_END=======================================================================\r
+ */\r
+\r
+package org.commscope.tr069adapter.mapper;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertNotNull;\r
+import static org.junit.Assert.assertNull;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.commscope.tr069adapter.acs.common.DeviceDetails;\r
+import org.commscope.tr069adapter.acs.common.DeviceInform;\r
+import org.commscope.tr069adapter.acs.common.ParameterDTO;\r
+import org.commscope.tr069adapter.acs.common.dto.TR069InformType;\r
+import org.commscope.tr069adapter.acs.common.inform.BootInform;\r
+import org.commscope.tr069adapter.acs.common.inform.BootstrapInform;\r
+import org.commscope.tr069adapter.acs.common.inform.ValueChangeInform;\r
+import org.commscope.tr069adapter.mapper.acs.impl.ACSNotificationHandlerImpl;\r
+import org.commscope.tr069adapter.mapper.boot.MapperServiceBooter;\r
+import org.commscope.tr069adapter.mapper.model.NetConfServerDetails;\r
+import org.commscope.tr069adapter.mapper.model.NetconfServerManagementError;\r
+import org.commscope.tr069adapter.mapper.netconf.NetConfServerManager;\r
+import org.junit.Test;\r
+import org.junit.runner.RunWith;\r
+import org.mockito.Mock;\r
+import org.mockito.Mockito;\r
+import org.springframework.beans.factory.annotation.Autowired;\r
+import org.springframework.boot.test.context.SpringBootTest;\r
+import org.springframework.test.context.junit4.SpringRunner;\r
+\r
+@SpringBootTest(classes = {MapperServiceBooter.class})\r
+@RunWith(SpringRunner.class)\r
+public class ACSNotificationHandlerImplTest {\r
+\r
+  @Autowired\r
+  ACSNotificationHandlerImpl aCSNotificationHandlerImpl;\r
+\r
+  @Mock\r
+  NetConfServerManager netConfServerManager;\r
+\r
+  @Test\r
+  public void testHandleBootStrapNotification() {\r
+\r
+    BootstrapInform notification = new BootstrapInform();\r
+    List<ParameterDTO> params = new ArrayList<ParameterDTO>();\r
+    ParameterDTO param = new ParameterDTO();\r
+    param.setParamName("ExpeditedEvent");\r
+    params.add(param);\r
+    notification.setDeviceDetails(getDeviceDetails());\r
+    notification.setParameters(params);\r
+    NetConfServerDetails serverInfo = new NetConfServerDetails();\r
+    serverInfo.setError(NetconfServerManagementError.SUCCESS);\r
+    Mockito.when(netConfServerManager.createNetconfServer(Mockito.anyString(), Mockito.anyString()))\r
+        .thenReturn(serverInfo);\r
+    /*\r
+     * String URI = "http://tr069adapter-netconf-server:8181/netConfServerManagerService";\r
+     * Mockito.when(netConfServerManager.getNetconfServerManagerRestUri()). thenReturn(value)\r
+     */\r
+    aCSNotificationHandlerImpl.handleNotification(notification);\r
+    assertNull(notification.getValueChangeNotification());\r
+  }\r
+\r
+  @Test\r
+  public void testHandleBootStrapNotificationNegativeScenario() {\r
+\r
+    BootstrapInform notification = new BootstrapInform();\r
+    List<ParameterDTO> params = new ArrayList<ParameterDTO>();\r
+    ParameterDTO param = new ParameterDTO();\r
+    param.setParamName("Test");\r
+    params.add(param);\r
+    notification.setDeviceDetails(getDeviceDetails());\r
+    notification.setParameters(params);\r
+    // Mockito.doReturn(null).when(netConfServerManager.createNetconfServer(Mockito.anyString(),\r
+    // Mockito.anyString()));\r
+    aCSNotificationHandlerImpl.handleNotification(notification);\r
+    assertNull(notification.getValueChangeNotification());\r
+  }\r
+\r
+  @Test\r
+  public void testHandleBootNotification() {\r
+\r
+    BootInform notification = new BootInform();\r
+    List<ParameterDTO> params = new ArrayList<ParameterDTO>();\r
+    ParameterDTO param = new ParameterDTO();\r
+    param.setParamName("Test");\r
+    params.add(param);\r
+    notification.setDeviceDetails(getDeviceDetails());\r
+    notification.setParameters(params);\r
+    aCSNotificationHandlerImpl.handleNotification(notification);\r
+    assertNull(notification.getValueChangeNotification());\r
+  }\r
+\r
+  @Test\r
+  public void testGetDeviceBootNotification() {\r
+    DeviceInform deviceInform = new DeviceInform();\r
+    deviceInform.setDeviceDetails(getDeviceDetails());\r
+    deviceInform.setParameters(getGeneralParams());\r
+\r
+    BootInform bInform =\r
+        ACSNotificationHandlerImpl.getDeviceBootNotification(deviceInform, TR069InformType.BOOT);\r
+    assertEquals("00005B9A1", bInform.getDeviceDetails().getDeviceId());\r
+    assertNotNull(bInform.getInformTypeList());\r
+    assertEquals(TR069InformType.BOOT, bInform.getInformTypeList().get(0));\r
+  }\r
+\r
+  @Test\r
+  public void testGetDeviceBooStraptNotification() {\r
+    DeviceInform deviceInform = new DeviceInform();\r
+    deviceInform.setDeviceDetails(getDeviceDetails());\r
+    deviceInform.setParameters(getGeneralParams());\r
+\r
+    BootstrapInform bsInform = ACSNotificationHandlerImpl\r
+        .getDeviceBootStrapNotification(deviceInform, TR069InformType.BOOTSTRAP);\r
+    assertEquals("00005B9A1", bsInform.getDeviceDetails().getDeviceId());\r
+    assertNotNull(bsInform.getInformTypeList());\r
+    assertEquals(TR069InformType.BOOTSTRAP, bsInform.getInformTypeList().get(0));\r
+  }\r
+\r
+  @Test\r
+  public void testGetDeviceValueChangeNotification() {\r
+    DeviceInform deviceInform = new DeviceInform();\r
+    deviceInform.setDeviceDetails(getDeviceDetails());\r
+    deviceInform.setParameters(getGeneralParams());\r
+\r
+    ValueChangeInform vInform = ACSNotificationHandlerImpl\r
+        .getDeviceValueChangeNotification(deviceInform, TR069InformType.VALUECHANGE);\r
+    assertEquals("00005B9A1", vInform.getDeviceDetails().getDeviceId());\r
+    assertNotNull(vInform.getInformTypeList());\r
+    assertEquals(TR069InformType.VALUECHANGE, vInform.getInformTypeList().get(0));\r
+  }\r
+\r
+  private DeviceDetails getDeviceDetails() {\r
+    DeviceDetails nf = new DeviceDetails();\r
+    nf.setDeviceId("00005B9A1");\r
+    nf.setDeviceTypeId(50);\r
+    nf.setOui("0005B9");\r
+    nf.setProductClass("LTE_Enterprise_C-RANSC_Cntrl");\r
+    return nf;\r
+  }\r
+\r
+  private DeviceDetails getDeviceDetailsNegativeCase() {\r
+    DeviceDetails nf = new DeviceDetails();\r
+    // nf.setDeviceId("00005B9A1");\r
+    nf.setDeviceTypeId(50);\r
+    nf.setOui("0005B9");\r
+    nf.setProductClass("LTE_Enterprise_C-RANSC_Cntrl");\r
+    return nf;\r
+  }\r
+\r
+  private ArrayList<ParameterDTO> getGeneralParams() {\r
+    ArrayList<ParameterDTO> params = new ArrayList<>();\r
+    params.add(new ParameterDTO("Device.DeviceInfo.ManufacturerOUI", "0005B9"));\r
+    params.add(new ParameterDTO("Device.DeviceInfo.ProductClass", "LTE_Enterprise_C-RANSC_Cntrl"));\r
+    params.add(new ParameterDTO("Device.DeviceInfo.HardwareVersion", "750742.00.04"));\r
+    params.add(new ParameterDTO("Device.DeviceInfo.SoftwareVersion", "4.3.00.231"));\r
+    params.add(new ParameterDTO("Device.DeviceInfo.Manufacturer", "ORAN"));\r
+    params.add(new ParameterDTO("Device.DeviceInfo.SerialNumber", "00005B9A1"));\r
+    params.add(new ParameterDTO("Device.IP.Interface.1.IPv4Address.1.IPAddress", "10.211.5.55"));\r
+    return params;\r
+  }\r
+}\r