Initial source code
[oam/tr069-adapter.git] / acs / application-booter / src / test / java / org / commscope / tr069adapter / acs / cpe / test / acsnbi / InformForwarderTest.java
diff --git a/acs/application-booter/src/test/java/org/commscope/tr069adapter/acs/cpe/test/acsnbi/InformForwarderTest.java b/acs/application-booter/src/test/java/org/commscope/tr069adapter/acs/cpe/test/acsnbi/InformForwarderTest.java
new file mode 100644 (file)
index 0000000..c042fe4
--- /dev/null
@@ -0,0 +1,99 @@
+/*\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.acs.cpe.test.acsnbi;\r
+\r
+import static org.junit.Assert.assertTrue;\r
+import static org.junit.Assert.fail;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.apache.activemq.broker.BrokerService;\r
+import org.commscope.tr069adapter.acs.booter.ACSServiceBooter;\r
+import org.commscope.tr069adapter.acs.common.DeviceInform;\r
+import org.commscope.tr069adapter.acs.common.InformType;\r
+import org.commscope.tr069adapter.acs.common.dto.TR069DeviceDetails;\r
+import org.commscope.tr069adapter.acs.common.dto.TR069InformType;\r
+import org.commscope.tr069adapter.acs.nbi.impl.DeviceInformForwarder;\r
+import org.commscope.tr069adapter.acs.nbi.util.MapperSrvcDependencyConfig;\r
+import org.junit.After;\r
+import org.junit.Test;\r
+import org.junit.runner.RunWith;\r
+import org.mockito.Mockito;\r
+import org.springframework.beans.factory.annotation.Autowired;\r
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;\r
+import org.springframework.boot.test.context.SpringBootTest;\r
+import org.springframework.boot.test.mock.mockito.MockBean;\r
+import org.springframework.test.context.ContextConfiguration;\r
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;\r
+import org.springframework.web.client.RestTemplate;\r
+\r
+@SpringBootTest(classes = {ACSServiceBooter.class})\r
+@RunWith(SpringJUnit4ClassRunner.class)\r
+@AutoConfigureMockMvc\r
+@ContextConfiguration\r
+public class InformForwarderTest {\r
+\r
+  @MockBean\r
+  MapperSrvcDependencyConfig mapperSrvcDependencyConfig;\r
+\r
+  @MockBean\r
+  RestTemplate restTemplate;\r
+\r
+  @Autowired\r
+  private DeviceInformForwarder deviceInformForwarder;\r
+\r
+  @Autowired\r
+  BrokerService broker;\r
+\r
+  @Test\r
+  public void processInformPnPTest() throws Exception {\r
+\r
+    try {\r
+\r
+      Mockito.when(restTemplate.postForEntity(Mockito.anyString(), Mockito.any(DeviceInform.class),\r
+          Mockito.any(Class.class))).thenReturn(null);\r
+\r
+      TR069DeviceDetails tr069DeviceDetails = new TR069DeviceDetails();\r
+      tr069DeviceDetails.setDeviceId("0005B9519095");\r
+      DeviceInform inform = new DeviceInform();\r
+      inform.setDeviceDetails(tr069DeviceDetails);\r
+      List<InformType> informTypeList = new ArrayList<InformType>();\r
+      informTypeList.add(TR069InformType.BOOTSTRAP);\r
+      inform.setInformTypeList(informTypeList);\r
+      deviceInformForwarder.onMessage(inform);\r
+      assertTrue(true);\r
+    } catch (Exception e) {\r
+      fail(e.getMessage());\r
+    }\r
+  }\r
+\r
+  @After\r
+  public void stopBroker() throws Exception {\r
+    try {\r
+      System.out.println("Tearing down the broker");\r
+      broker.stop();\r
+      broker.waitUntilStopped();\r
+      broker = null;\r
+    } catch (Exception e) {\r
+      e.printStackTrace();\r
+    }\r
+  }\r
+\r
+}\r