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.config;
21 import static org.junit.Assert.assertEquals;
22 import static org.junit.jupiter.api.Assertions.fail;
24 import org.commscope.tr069adapter.config.repository.ConfigurationDataRepository;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.mockito.Mockito;
28 import org.springframework.beans.factory.annotation.Autowired;
29 import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
30 import org.springframework.boot.test.context.SpringBootTest;
31 import org.springframework.boot.test.mock.mockito.MockBean;
32 import org.springframework.http.MediaType;
33 import org.springframework.mock.web.MockHttpServletResponse;
34 import org.springframework.mock.web.MockMultipartFile;
35 import org.springframework.test.context.junit4.SpringRunner;
36 import org.springframework.test.web.servlet.MockMvc;
37 import org.springframework.test.web.servlet.MvcResult;
38 import org.springframework.test.web.servlet.RequestBuilder;
39 import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
40 import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
42 @RunWith(SpringRunner.class)
43 @SpringBootTest(classes = {ConfigDataServiceApplication.class}) // , args = "--schemas-dir
44 // test-schemas --debug true
45 // --starting-port 17830")
47 public class ConfugurationDataControllerTests {
50 private MockMvc mockMvc;
53 ConfigurationDataRepository configDataRepository;
56 public void getMessageTest() {
57 RequestBuilder requestBuilder =
58 MockMvcRequestBuilders.get("/isActive").accept(MediaType.APPLICATION_JSON);
60 MvcResult result = null;
61 String resultString = null;
63 result = mockMvc.perform(requestBuilder).andReturn();
64 resultString = result.getResponse().getContentAsString();
65 } catch (Exception e) {
69 assertEquals("Application is running", resultString);
73 public void uploadMultipleFilesTest() {
74 MockMultipartFile multiFile =
75 new MockMultipartFile("files", ConfigDataTestsUtils.CONFIG_FILE_NAME,
76 MediaType.APPLICATION_XML_VALUE, ConfigDataTestsUtils.getFileContent().getBytes());
77 MockHttpServletRequestBuilder requestBuilder =
78 MockMvcRequestBuilders.multipart("/importConfig").file(multiFile);// .contentType(MediaType.MULTIPART_FORM_DATA_VALUE);
80 MvcResult result = null;
81 String resultString = null;
83 result = mockMvc.perform(requestBuilder).andReturn();
84 MockHttpServletResponse response = result.getResponse();
85 resultString = response.getContentAsString();
86 } catch (Exception e) {
90 String expectedResult =
91 "File " + ConfigDataTestsUtils.CONFIG_FILE_NAME + " imported successfully";
92 assertEquals(expectedResult, resultString);
96 public void viewConfigurationDataTest() {
97 Mockito.when(configDataRepository.findByMacId(ConfigDataTestsUtils.macId))
98 .thenReturn(ConfigDataTestsUtils.getConfigFileContent());
100 MockHttpServletRequestBuilder requestBuilder =
101 MockMvcRequestBuilders.post("/getConfig").param("macId", "0005B95196D0")
102 .param("swVersion", "4.5").param("hwVersion", "1.1").accept(MediaType.APPLICATION_JSON);
104 MvcResult result = null;
106 result = mockMvc.perform(requestBuilder).andReturn();
107 MockHttpServletResponse response = result.getResponse();
108 assertEquals(200, response.getStatus());
109 } catch (Exception e) {
110 fail(e.getMessage());