Initial source code
[oam/tr069-adapter.git] / factory / src / test / java / com / commscope / tr069adapter / imports / FactoryDataAccesorApplicationTests.java
1 /*\r
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
10  *\r
11  * http://www.apache.org/licenses/LICENSE-2.0\r
12  *\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
17  */\r
18 \r
19 package com.commscope.tr069adapter.imports;\r
20 \r
21 import static org.junit.Assert.assertEquals;\r
22 import static org.junit.jupiter.api.Assertions.fail;\r
23 \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
36 \r
37 @RunWith(SpringRunner.class)\r
38 @SpringBootTest(classes = {FactoryDataAccesorApplication.class})\r
39 @AutoConfigureMockMvc\r
40 public class FactoryDataAccesorApplicationTests {\r
41 \r
42   private String exampleDeviceDataJson =\r
43       "{\"serialNumber\":\"0005B95196D0\",\"autenticationString\":\"abcxyz\",\"oui\":\"0005B9\",\"productClass\":\"LTE_Enterprise_C-RANSC_Cntrl\"}";\r
44 \r
45   @Autowired\r
46   private MockMvc mockMvc;\r
47 \r
48   @Test\r
49   public void basicAuthenticateTest() {\r
50 \r
51     RequestBuilder requestBuilder =\r
52         MockMvcRequestBuilders.post("/basicAuthenticate").accept(MediaType.APPLICATION_JSON)\r
53             .content(exampleDeviceDataJson).contentType(MediaType.APPLICATION_JSON);\r
54 \r
55     MvcResult result = null;\r
56     String resultString = null;\r
57     try {\r
58       result = mockMvc.perform(requestBuilder).andReturn();\r
59       resultString = result.getResponse().getContentAsString();\r
60     } catch (Exception e) {\r
61       fail(e.getMessage());\r
62     }\r
63 \r
64     assertEquals("true", resultString);\r
65   }\r
66 \r
67   @Test\r
68   public void digestAuthenticateDeviceTest() {\r
69 \r
70     RequestBuilder requestBuilder =\r
71         MockMvcRequestBuilders.post("/digestAuthenticate").accept(MediaType.APPLICATION_JSON)\r
72             .content(exampleDeviceDataJson).contentType(MediaType.APPLICATION_JSON);\r
73 \r
74     MvcResult result = null;\r
75     String resultString = null;\r
76     try {\r
77       result = mockMvc.perform(requestBuilder).andReturn();\r
78       resultString = result.getResponse().getContentAsString();\r
79     } catch (Exception e) {\r
80       fail(e.getMessage());\r
81     }\r
82 \r
83     assertEquals("true", resultString);\r
84   }\r
85 \r
86   @Test\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
91 \r
92     MvcResult result = null;\r
93     String resultString = null;\r
94     try {\r
95       result = mockMvc.perform(requestBuilder).andReturn();\r
96       resultString = result.getResponse().getContentAsString();\r
97     } catch (Exception e) {\r
98       fail(e.getMessage());\r
99     }\r
100 \r
101     assertEquals("true", resultString);\r
102   }\r
103 }\r