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 com.commscope.tr069adapter.imports;
\r
21 import static org.junit.Assert.assertEquals;
\r
22 import static org.junit.jupiter.api.Assertions.fail;
\r
24 import org.commscope.tr069adapter.factory.FactoryDataAccesorApplication;
\r
25 import org.junit.Test;
\r
26 import org.junit.runner.RunWith;
\r
27 import org.springframework.beans.factory.annotation.Autowired;
\r
28 import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
\r
29 import org.springframework.boot.test.context.SpringBootTest;
\r
30 import org.springframework.http.MediaType;
\r
31 import org.springframework.test.context.junit4.SpringRunner;
\r
32 import org.springframework.test.web.servlet.MockMvc;
\r
33 import org.springframework.test.web.servlet.MvcResult;
\r
34 import org.springframework.test.web.servlet.RequestBuilder;
\r
35 import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
\r
37 @RunWith(SpringRunner.class)
\r
38 @SpringBootTest(classes = {FactoryDataAccesorApplication.class})
\r
39 @AutoConfigureMockMvc
\r
40 public class FactoryDataAccesorApplicationTests {
\r
42 private String exampleDeviceDataJson =
\r
43 "{\"serialNumber\":\"0005B95196D0\",\"autenticationString\":\"abcxyz\",\"oui\":\"0005B9\",\"productClass\":\"LTE_Enterprise_C-RANSC_Cntrl\"}";
\r
46 private MockMvc mockMvc;
\r
49 public void basicAuthenticateTest() {
\r
51 RequestBuilder requestBuilder =
\r
52 MockMvcRequestBuilders.post("/basicAuthenticate").accept(MediaType.APPLICATION_JSON)
\r
53 .content(exampleDeviceDataJson).contentType(MediaType.APPLICATION_JSON);
\r
55 MvcResult result = null;
\r
56 String resultString = null;
\r
58 result = mockMvc.perform(requestBuilder).andReturn();
\r
59 resultString = result.getResponse().getContentAsString();
\r
60 } catch (Exception e) {
\r
61 fail(e.getMessage());
\r
64 assertEquals("true", resultString);
\r
68 public void digestAuthenticateDeviceTest() {
\r
70 RequestBuilder requestBuilder =
\r
71 MockMvcRequestBuilders.post("/digestAuthenticate").accept(MediaType.APPLICATION_JSON)
\r
72 .content(exampleDeviceDataJson).contentType(MediaType.APPLICATION_JSON);
\r
74 MvcResult result = null;
\r
75 String resultString = null;
\r
77 result = mockMvc.perform(requestBuilder).andReturn();
\r
78 resultString = result.getResponse().getContentAsString();
\r
79 } catch (Exception e) {
\r
80 fail(e.getMessage());
\r
83 assertEquals("true", resultString);
\r
87 public void validateDeviceOUIPCTest() {
\r
88 RequestBuilder requestBuilder =
\r
89 MockMvcRequestBuilders.post("/validateDevice").accept(MediaType.APPLICATION_JSON)
\r
90 .content(exampleDeviceDataJson).contentType(MediaType.APPLICATION_JSON);
\r
92 MvcResult result = null;
\r
93 String resultString = null;
\r
95 result = mockMvc.perform(requestBuilder).andReturn();
\r
96 resultString = result.getResponse().getContentAsString();
\r
97 } catch (Exception e) {
\r
98 fail(e.getMessage());
\r
101 assertEquals("true", resultString);
\r