Development of NETCONF RPCs for tr-069 adapter to
[oam/tr069-adapter.git] / netconf-server / src / test / java / org / commscope / tr069adapter / netconf / restapi / NetConfServerManagerRestApiTest.java
index 2060974..652f945 100644 (file)
-/*\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.netconf.restapi;\r
-\r
-import static org.junit.jupiter.api.Assertions.assertEquals;\r
-\r
-import org.commscope.tr069adapter.netconf.boot.NetConfServiceBooter;\r
-import org.commscope.tr069adapter.netconf.dao.NetConfServerDetailsRepository;\r
-import org.commscope.tr069adapter.netconf.entity.NetConfServerDetailsEntity;\r
-import org.commscope.tr069adapter.netconf.server.NetConfServerManagerImpl;\r
-import org.junit.FixMethodOrder;\r
-import org.junit.jupiter.api.Test;\r
-import org.junit.jupiter.api.extension.ExtendWith;\r
-import org.junit.runners.MethodSorters;\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.http.HttpStatus;\r
-import org.springframework.http.MediaType;\r
-import org.springframework.mock.web.MockHttpServletResponse;\r
-import org.springframework.test.context.junit.jupiter.SpringExtension;\r
-import org.springframework.test.web.servlet.MockMvc;\r
-import org.springframework.test.web.servlet.MvcResult;\r
-import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;\r
-import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;\r
-\r
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)\r
-@ExtendWith(SpringExtension.class)\r
-@SpringBootTest(classes = {NetConfServiceBooter.class},\r
-    args = "--schemas-dir test-schemas --debug true --starting-port 17830")\r
-@AutoConfigureMockMvc\r
-public class NetConfServerManagerRestApiTest {\r
-\r
-  @Autowired\r
-  private MockMvc mockMvc;\r
-\r
-  @MockBean\r
-  NetConfServerDetailsRepository netconfDAO;\r
-\r
-  @Autowired\r
-  NetConfServerManagerImpl manager;\r
-\r
-  @Test\r
-  public void createNetconfServer() throws Exception {\r
-\r
-    NetConfServerDetailsEntity entity = new NetConfServerDetailsEntity();\r
-    entity.setDeviceId("0005B9AB1");\r
-    entity.setEnodeBName("0005B9AB1");\r
-    entity.setId(1l);\r
-    entity.setListenPort("17830");\r
-\r
-    MockHttpServletRequestBuilder requestBuilder =\r
-        MockMvcRequestBuilders.post("/netConfServerManagerService/createServer")\r
-            .param("deviceId", "0005B9AB1").param("enodeBName", "0005B9AB1")\r
-            .param("swVersion", "4.4.3").param("hwVersion", "*").accept(MediaType.APPLICATION_JSON);\r
-    MvcResult result = mockMvc.perform(requestBuilder).andReturn();\r
-\r
-    MockHttpServletResponse response = result.getResponse();\r
-\r
-    assertEquals(HttpStatus.OK.value(), response.getStatus());\r
-\r
-  }\r
-\r
-  @Test\r
-  public void listNetconfServers() throws Exception {\r
-\r
-    MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders\r
-        .get("/netConfServerManagerService/listServers").accept(MediaType.APPLICATION_JSON);\r
-    MvcResult result = mockMvc.perform(requestBuilder).andReturn();\r
-    MockHttpServletResponse response = result.getResponse();\r
-\r
-    assertEquals(HttpStatus.OK.value(), response.getStatus());\r
-\r
-  }\r
-\r
-  @Test\r
-  public void restartServersOnStartup() {\r
-    boolean result = false;\r
-    try {\r
-      manager.restartServers();\r
-      result = true;\r
-    } catch (Exception e) {\r
-      assertEquals(false, result); // if no exception\r
-    }\r
-    assertEquals(true, result); // if no exception\r
-\r
-  }\r
-}\r
+/*
+ * ============LICENSE_START========================================================================
+ * ONAP : tr-069-adapter
+ * =================================================================================================
+ * Copyright (C) 2020 CommScope Inc Intellectual Property.
+ * =================================================================================================
+ * This tr-069-adapter software file is distributed by CommScope Inc under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You
+ * may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ===============LICENSE_END=======================================================================
+ */
+
+package org.commscope.tr069adapter.netconf.restapi;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.commscope.tr069adapter.netconf.boot.NetConfServiceBooter;
+import org.commscope.tr069adapter.netconf.dao.NetConfServerDetailsRepository;
+import org.commscope.tr069adapter.netconf.entity.NetConfServerDetailsEntity;
+import org.commscope.tr069adapter.netconf.server.NetConfServerManagerImpl;
+import org.junit.FixMethodOrder;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.runners.MethodSorters;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
+import org.springframework.mock.web.MockHttpServletResponse;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.MvcResult;
+import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
+import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
+
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+@ExtendWith(SpringExtension.class)
+@SpringBootTest(classes = {NetConfServiceBooter.class},
+    args = "--schemas-dir test-schemas --debug true --starting-port 17830")
+@AutoConfigureMockMvc
+public class NetConfServerManagerRestApiTest {
+
+  @Autowired
+  private MockMvc mockMvc;
+
+  @MockBean
+  NetConfServerDetailsRepository netconfDAO;
+
+  @Autowired
+  NetConfServerManagerImpl manager;
+
+  @Test
+  public void createNetconfServer() throws Exception {
+
+    NetConfServerDetailsEntity entity = new NetConfServerDetailsEntity();
+    entity.setDeviceId("0005B9AB1");
+    entity.setEnodeBName("0005B9AB1");
+    entity.setId(1l);
+    entity.setListenPort("17830");
+
+    MockHttpServletRequestBuilder requestBuilder =
+        MockMvcRequestBuilders.post("/netConfServerManagerService/createServer")
+            .param("deviceId", "0005B9AB1").param("enodeBName", "0005B9AB1")
+            .param("swVersion", "4.4.3").param("hwVersion", "*").accept(MediaType.APPLICATION_JSON);
+    MvcResult result = mockMvc.perform(requestBuilder).andReturn();
+
+    MockHttpServletResponse response = result.getResponse();
+
+    assertEquals(HttpStatus.OK.value(), response.getStatus());
+
+  }
+
+  @Test
+  public void listNetconfServers() throws Exception {
+
+    MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders
+        .get("/netConfServerManagerService/listServers").accept(MediaType.APPLICATION_JSON);
+    MvcResult result = mockMvc.perform(requestBuilder).andReturn();
+    MockHttpServletResponse response = result.getResponse();
+
+    assertEquals(HttpStatus.OK.value(), response.getStatus());
+
+  }
+
+  @Test
+  public void restartServersOnStartup() {
+    boolean result = false;
+    try {
+      manager.restartServers();
+      result = true;
+    } catch (Exception e) {
+      assertEquals(false, result); // if no exception
+    }
+    assertEquals(true, result); // if no exception
+
+  }
+}