--- /dev/null
+/*\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 = MockMvcRequestBuilders\r
+ .post("/netConfServerManagerService/createServer").param("deviceId", "0005B9AB1")\r
+ .param("enodeBName", "0005B9AB1").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