Initial source code
[oam/tr069-adapter.git] / config-data / src / test / java / com / commscope / tr069adapter / config / ConfigDataApplicationTests.java
diff --git a/config-data/src/test/java/com/commscope/tr069adapter/config/ConfigDataApplicationTests.java b/config-data/src/test/java/com/commscope/tr069adapter/config/ConfigDataApplicationTests.java
new file mode 100644 (file)
index 0000000..89b8ab9
--- /dev/null
@@ -0,0 +1,102 @@
+/*\r
+ * ============LICENSE_START========================================================================\r
+ * ONAP : tr-069-adapter\r
+ * =================================================================================================\r
+ * Copyright (C) 2020 CommScope Inc Intellectual Property.\r
+ * =================================================================================================\r
+ * This tr-069-adapter software file is distributed by CommScope Inc under the Apache License,\r
+ * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You\r
+ * may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,\r
+ * either express or implied. See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ===============LICENSE_END=======================================================================\r
+ */\r
+\r
+package com.commscope.tr069adapter.config;\r
+\r
+import java.io.BufferedReader;\r
+import java.io.FileReader;\r
+import java.io.IOException;\r
+\r
+import org.commscope.tr069adapter.config.dto.ConfigurationData;\r
+import org.commscope.tr069adapter.config.model.ConfigFileContent;\r
+import org.springframework.web.client.RestTemplate;\r
+\r
+public class ConfigDataApplicationTests {\r
+\r
+  public static final String SERVER_URI = "http://localhost:9000/";\r
+  public static final String macId = "mac2";\r
+\r
+  public static void main(String args[]) {\r
+\r
+    testSaveConfigurationFileContent();\r
+    testGetConfigurationData();\r
+    System.out.println("SUCCESSFUL");\r
+  }\r
+\r
+  private static void testSaveConfigurationFileContent() {\r
+    System.out.println("\n*******Strating test testSaveConfigurationFileContent*******\n");\r
+    RestTemplate restTemplate = new RestTemplate();\r
+\r
+    String fileContent = readFile("ss.xml");\r
+    ConfigFileContent configFleContent = new ConfigFileContent();\r
+\r
+    configFleContent.setMacId(macId);\r
+    configFleContent.setFileContent(fileContent);\r
+\r
+    String response =\r
+        restTemplate.postForObject(SERVER_URI + "/create", configFleContent, String.class);\r
+    System.out.println("Saved");\r
+    // printEmpData(response);\r
+    System.out.println("\n*******Test testGetConfigurationData completed*******\n");\r
+  }\r
+\r
+  private static void testGetConfigurationData() {\r
+    System.out.println("\n*******Strating test testSaveConfigurationFileContent*******\n");\r
+    RestTemplate restTemplate = new RestTemplate();\r
+\r
+    ConfigurationData configData =\r
+        restTemplate.getForObject(SERVER_URI + "/getConfig/" + macId, ConfigurationData.class);\r
+\r
+    if (null == configData) {\r
+      System.out.println("No configuration data exist for device " + macId);\r
+    } else {\r
+      System.out.println(\r
+          "\n***************Configuration data for device " + macId + "***************\n\n");\r
+      System.out.println(configData.getParameterMONameValueMap());\r
+    }\r
+    // printConfigData(configData);\r
+    System.out.println("\n*******Test testGetConfigurationData completed*******\n");\r
+  }\r
+\r
+  public static String readFile(String completeFilePath) {\r
+    BufferedReader reader = null;\r
+    String line = null;\r
+    StringBuilder stringBuilder = new StringBuilder();\r
+    String ls = "\n";\r
+\r
+    try {\r
+      reader = new BufferedReader(new FileReader(completeFilePath));\r
+\r
+      while ((line = reader.readLine()) != null) {\r
+        stringBuilder.append(line);\r
+        stringBuilder.append(ls);\r
+      }\r
+\r
+      return stringBuilder.toString();\r
+    } catch (Exception ex) {\r
+      return null;\r
+    } finally {\r
+      if (null != reader) {\r
+        try {\r
+          reader.close();\r
+        } catch (IOException e) {\r
+        }\r
+      }\r
+    }\r
+  }\r
+}\r