8b2fe27b8ecaf7f82919eef108a44e9e41891267
[oam/tr069-adapter.git] / config-data / src / test / java / com / commscope / tr069adapter / config / ConfigDataApplicationTests.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.config;\r
20 \r
21 import java.io.BufferedReader;\r
22 import java.io.FileReader;\r
23 import java.io.IOException;\r
24 \r
25 import org.commscope.tr069adapter.acs.common.dto.ConfigurationData;\r
26 import org.commscope.tr069adapter.config.model.ConfigFileContent;\r
27 import org.springframework.web.client.RestTemplate;\r
28 \r
29 public class ConfigDataApplicationTests {\r
30 \r
31   public static final String SERVER_URI = "http://localhost:9000/";\r
32   public static final String macId = "mac2";\r
33 \r
34   public static void main(String args[]) {\r
35 \r
36     testSaveConfigurationFileContent();\r
37     testGetConfigurationData();\r
38     System.out.println("SUCCESSFUL");\r
39   }\r
40 \r
41   private static void testSaveConfigurationFileContent() {\r
42     System.out.println("\n*******Strating test testSaveConfigurationFileContent*******\n");\r
43     RestTemplate restTemplate = new RestTemplate();\r
44 \r
45     String fileContent = readFile("ss.xml");\r
46     ConfigFileContent configFleContent = new ConfigFileContent();\r
47 \r
48     configFleContent.setMacId(macId);\r
49     configFleContent.setFileContent(fileContent);\r
50 \r
51     String response =\r
52         restTemplate.postForObject(SERVER_URI + "/create", configFleContent, String.class);\r
53     System.out.println("Saved");\r
54     // printEmpData(response);\r
55     System.out.println("\n*******Test testGetConfigurationData completed*******\n");\r
56   }\r
57 \r
58   private static void testGetConfigurationData() {\r
59     System.out.println("\n*******Strating test testSaveConfigurationFileContent*******\n");\r
60     RestTemplate restTemplate = new RestTemplate();\r
61 \r
62     ConfigurationData configData =\r
63         restTemplate.getForObject(SERVER_URI + "/getConfig/" + macId, ConfigurationData.class);\r
64 \r
65     if (null == configData) {\r
66       System.out.println("No configuration data exist for device " + macId);\r
67     } else {\r
68       System.out.println(\r
69           "\n***************Configuration data for device " + macId + "***************\n\n");\r
70       System.out.println(configData.getParameterMONameValueMap());\r
71     }\r
72     // printConfigData(configData);\r
73     System.out.println("\n*******Test testGetConfigurationData completed*******\n");\r
74   }\r
75 \r
76   public static String readFile(String completeFilePath) {\r
77     BufferedReader reader = null;\r
78     String line = null;\r
79     StringBuilder stringBuilder = new StringBuilder();\r
80     String ls = "\n";\r
81 \r
82     try {\r
83       reader = new BufferedReader(new FileReader(completeFilePath));\r
84 \r
85       while ((line = reader.readLine()) != null) {\r
86         stringBuilder.append(line);\r
87         stringBuilder.append(ls);\r
88       }\r
89 \r
90       return stringBuilder.toString();\r
91     } catch (Exception ex) {\r
92       return null;\r
93     } finally {\r
94       if (null != reader) {\r
95         try {\r
96           reader.close();\r
97         } catch (IOException e) {\r
98         }\r
99       }\r
100     }\r
101   }\r
102 }\r