Add Unit Test for FileCommonUtils 63/39063/1
authorYuanHu <yuan.hu1@zte.com.cn>
Tue, 27 Mar 2018 11:39:30 +0000 (19:39 +0800)
committerYuanHu <yuan.hu1@zte.com.cn>
Tue, 27 Mar 2018 11:39:30 +0000 (19:39 +0800)
Add Unit Test for FileCommonUtils

Issue-ID: SDC-1078

Change-Id: Ib58fd14cf996eeea3cb8af82eb0f831d9ee40d3f
Signed-off-by: YuanHu <yuan.hu1@zte.com.cn>
sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/utils/FileCommonUtils.java
sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/utils/FileCommonUtilsTest.java

index 74f9180..d868615 100644 (file)
@@ -281,7 +281,7 @@ public class FileCommonUtils {
       sb.append(ss[i]).append(System.lineSeparator());
     }
 
-    write(sb.toString(), fileName, charsetName);
+    write(fileName, sb.toString(), charsetName);
   }
 
 }
index 3906505..aba1a31 100644 (file)
@@ -14,7 +14,10 @@ package org.onap.sdc.workflowdesigner.utils;
 import static org.junit.Assert.assertEquals;\r
 \r
 import java.io.File;\r
+import java.io.FileInputStream;\r
+import java.io.FileNotFoundException;\r
 import java.io.IOException;\r
+import java.io.StringBufferInputStream;\r
 \r
 import org.junit.After;\r
 import org.junit.Before;\r
@@ -42,6 +45,23 @@ public class FileCommonUtilsTest {
    */\r
   @Test\r
   public void testReadLines() {\r
+    String fileName = "src/test/resources/workflow/template-test.bpmn20.xml";\r
+    File file = new File(fileName);\r
+    FileInputStream ins = null;\r
+    try {\r
+      ins = new FileInputStream(file);\r
+      String[] ss = FileCommonUtils.readLines(ins);\r
+      assertEquals(false, ss.length == 0);\r
+      \r
+      FileCommonUtils.write("template-test.bpmn20.xml", ss);\r
+    } catch (FileNotFoundException e) {\r
+      e.printStackTrace();\r
+    } catch (IOException e) {\r
+      e.printStackTrace();\r
+    } finally {\r
+      FileCommonUtils.closeInputStream(ins);\r
+    }\r
+\r
   }\r
 \r
   /**\r
@@ -73,6 +93,16 @@ public class FileCommonUtilsTest {
    */\r
   @Test\r
   public void testSaveFile() {\r
+    String fileName = "test3.json";\r
+    String content = "{\"aaa\": \"节点\"}";\r
+    StringBufferInputStream ins = null;\r
+    try {\r
+      ins = new StringBufferInputStream(content);\r
+      FileCommonUtils.saveFile(ins, ".", fileName);\r
+    } catch (IOException e) {\r
+      e.printStackTrace();\r
+      FileCommonUtils.closeInputStream(ins);\r
+    }\r
   }\r
 \r
   /**\r