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.netconf.restapi;
21 import static org.junit.jupiter.api.Assertions.assertEquals;
23 import org.commscope.tr069adapter.netconf.boot.NetConfServiceBooter;
24 import org.commscope.tr069adapter.netconf.dao.NetConfServerDetailsRepository;
25 import org.commscope.tr069adapter.netconf.entity.NetConfServerDetailsEntity;
26 import org.commscope.tr069adapter.netconf.server.NetConfServerManagerImpl;
27 import org.junit.FixMethodOrder;
28 import org.junit.jupiter.api.Test;
29 import org.junit.jupiter.api.extension.ExtendWith;
30 import org.junit.runners.MethodSorters;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
33 import org.springframework.boot.test.context.SpringBootTest;
34 import org.springframework.boot.test.mock.mockito.MockBean;
35 import org.springframework.http.HttpStatus;
36 import org.springframework.http.MediaType;
37 import org.springframework.mock.web.MockHttpServletResponse;
38 import org.springframework.test.context.junit.jupiter.SpringExtension;
39 import org.springframework.test.web.servlet.MockMvc;
40 import org.springframework.test.web.servlet.MvcResult;
41 import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
42 import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
44 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
45 @ExtendWith(SpringExtension.class)
46 @SpringBootTest(classes = {NetConfServiceBooter.class},
47 args = "--schemas-dir test-schemas --debug true --starting-port 17830")
49 public class NetConfServerManagerRestApiTest {
52 private MockMvc mockMvc;
55 NetConfServerDetailsRepository netconfDAO;
58 NetConfServerManagerImpl manager;
61 public void createNetconfServer() throws Exception {
63 NetConfServerDetailsEntity entity = new NetConfServerDetailsEntity();
64 entity.setDeviceId("0005B9AB1");
65 entity.setEnodeBName("0005B9AB1");
67 entity.setListenPort("17830");
69 MockHttpServletRequestBuilder requestBuilder =
70 MockMvcRequestBuilders.post("/netConfServerManagerService/createServer")
71 .param("deviceId", "0005B9AB1").param("enodeBName", "0005B9AB1")
72 .param("swVersion", "4.4.3").param("hwVersion", "*").accept(MediaType.APPLICATION_JSON);
73 MvcResult result = mockMvc.perform(requestBuilder).andReturn();
75 MockHttpServletResponse response = result.getResponse();
77 assertEquals(HttpStatus.OK.value(), response.getStatus());
82 public void listNetconfServers() throws Exception {
84 MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders
85 .get("/netConfServerManagerService/listServers").accept(MediaType.APPLICATION_JSON);
86 MvcResult result = mockMvc.perform(requestBuilder).andReturn();
87 MockHttpServletResponse response = result.getResponse();
89 assertEquals(HttpStatus.OK.value(), response.getStatus());
94 public void restartServersOnStartup() {
95 boolean result = false;
97 manager.restartServers();
99 } catch (Exception e) {
100 assertEquals(false, result); // if no exception
102 assertEquals(true, result); // if no exception