2 * ============LICENSE_START========================================================================
\r
3 * ONAP : tr-069-adapter
\r
4 * =================================================================================================
\r
5 * Copyright (C) 2020 CommScope Inc Intellectual Property.
\r
6 * =================================================================================================
\r
7 * This tr-069-adapter software file is distributed by CommScope Inc under the Apache License,
\r
8 * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You
\r
9 * may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
\r
14 * either express or implied. See the License for the specific language governing permissions and
\r
15 * limitations under the License.
\r
16 * ===============LICENSE_END=======================================================================
\r
19 package org.commscope.tr069adapter.config;
\r
21 import static org.junit.Assert.assertEquals;
\r
22 import static org.junit.Assert.assertThat;
\r
23 import static org.junit.jupiter.api.Assertions.fail;
\r
24 import org.commscope.tr069adapter.config.repository.ConfigurationDataRepository;
\r
25 import org.hamcrest.CoreMatchers;
\r
26 import org.junit.Test;
\r
27 import org.junit.runner.RunWith;
\r
28 import org.mockito.Mockito;
\r
29 import org.springframework.beans.factory.annotation.Autowired;
\r
30 import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
\r
31 import org.springframework.boot.test.context.SpringBootTest;
\r
32 import org.springframework.boot.test.mock.mockito.MockBean;
\r
33 import org.springframework.http.HttpStatus;
\r
34 import org.springframework.http.MediaType;
\r
35 import org.springframework.mock.web.MockHttpServletResponse;
\r
36 import org.springframework.mock.web.MockMultipartFile;
\r
37 import org.springframework.test.context.junit4.SpringRunner;
\r
38 import org.springframework.test.web.servlet.MockMvc;
\r
39 import org.springframework.test.web.servlet.MvcResult;
\r
40 import org.springframework.test.web.servlet.RequestBuilder;
\r
41 import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
\r
42 import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
\r
44 @RunWith(SpringRunner.class)
\r
45 @SpringBootTest(classes = {ConfigDataServiceApplication.class}) // , args = "--schemas-dir
\r
46 // test-schemas --debug true
\r
47 // --starting-port 17830")
\r
48 @AutoConfigureMockMvc
\r
49 public class ConfugurationDataControllerTests {
\r
52 private MockMvc mockMvc;
\r
55 ConfigurationDataRepository configDataRepository;
\r
58 public void getMessageTest() {
\r
59 RequestBuilder requestBuilder =
\r
60 MockMvcRequestBuilders.get("/isActive").accept(MediaType.APPLICATION_JSON);
\r
62 MvcResult result = null;
\r
63 String resultString = null;
\r
65 result = mockMvc.perform(requestBuilder).andReturn();
\r
66 resultString = result.getResponse().getContentAsString();
\r
67 } catch (Exception e) {
\r
68 fail(e.getMessage());
\r
71 assertEquals("Application is running", resultString);
\r
75 public void uploadMultipleFilesTest() {
\r
76 MockMultipartFile multiFile =
\r
77 new MockMultipartFile("files", ConfigDataTestsUtils.CONFIG_FILE_NAME,
\r
78 MediaType.APPLICATION_XML_VALUE, ConfigDataTestsUtils.getFileContent().getBytes());
\r
79 MockHttpServletRequestBuilder requestBuilder =
\r
80 MockMvcRequestBuilders.multipart("/importConfig").file(multiFile);// .contentType(MediaType.MULTIPART_FORM_DATA_VALUE);
\r
82 MvcResult result = null;
\r
83 String resultString = null;
\r
85 result = mockMvc.perform(requestBuilder).andReturn();
\r
86 MockHttpServletResponse response = result.getResponse();
\r
87 resultString = response.getContentAsString();
\r
88 } catch (Exception e) {
\r
89 fail(e.getMessage());
\r
92 String expectedResult =
\r
93 "File " + ConfigDataTestsUtils.CONFIG_FILE_NAME + " imported successfully";
\r
94 assertEquals(expectedResult, resultString);
\r
98 public void viewConfigurationDataTest() {
\r
99 Mockito.when(configDataRepository.findByMacId(ConfigDataTestsUtils.macId))
\r
100 .thenReturn(ConfigDataTestsUtils.getConfigFileContent());
\r
102 MockHttpServletRequestBuilder requestBuilder =
\r
103 MockMvcRequestBuilders.post("/getConfig").param("macId", "0005B95196D0")
\r
104 .param("swVersion", "4.5").param("hwVersion", "1.1").accept(MediaType.APPLICATION_JSON);
\r
106 MvcResult result = null;
\r
108 result = mockMvc.perform(requestBuilder).andReturn();
\r
109 MockHttpServletResponse response = result.getResponse();
\r
110 assertEquals(200, response.getStatus());
\r
111 } catch (Exception e) {
\r
112 fail(e.getMessage());
\r