From 85d1d33bbd8f32cbf581131180d62d61a2d4b0ee Mon Sep 17 00:00:00 2001 From: YuanHu Date: Tue, 27 Mar 2018 19:39:30 +0800 Subject: Add Unit Test for FileCommonUtils Add Unit Test for FileCommonUtils Issue-ID: SDC-1078 Change-Id: Ib58fd14cf996eeea3cb8af82eb0f831d9ee40d3f Signed-off-by: YuanHu --- .../workflowdesigner/utils/FileCommonUtils.java | 2 +- .../utils/FileCommonUtilsTest.java | 30 ++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) (limited to 'sdc-workflow-designer-server/src') diff --git a/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/utils/FileCommonUtils.java b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/utils/FileCommonUtils.java index 74f9180b..d8686150 100644 --- a/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/utils/FileCommonUtils.java +++ b/sdc-workflow-designer-server/src/main/java/org/onap/sdc/workflowdesigner/utils/FileCommonUtils.java @@ -281,7 +281,7 @@ public class FileCommonUtils { sb.append(ss[i]).append(System.lineSeparator()); } - write(sb.toString(), fileName, charsetName); + write(fileName, sb.toString(), charsetName); } } diff --git a/sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/utils/FileCommonUtilsTest.java b/sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/utils/FileCommonUtilsTest.java index 39065056..aba1a319 100644 --- a/sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/utils/FileCommonUtilsTest.java +++ b/sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/utils/FileCommonUtilsTest.java @@ -14,7 +14,10 @@ package org.onap.sdc.workflowdesigner.utils; import static org.junit.Assert.assertEquals; import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; +import java.io.StringBufferInputStream; import org.junit.After; import org.junit.Before; @@ -42,6 +45,23 @@ public class FileCommonUtilsTest { */ @Test public void testReadLines() { + String fileName = "src/test/resources/workflow/template-test.bpmn20.xml"; + File file = new File(fileName); + FileInputStream ins = null; + try { + ins = new FileInputStream(file); + String[] ss = FileCommonUtils.readLines(ins); + assertEquals(false, ss.length == 0); + + FileCommonUtils.write("template-test.bpmn20.xml", ss); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + FileCommonUtils.closeInputStream(ins); + } + } /** @@ -73,6 +93,16 @@ public class FileCommonUtilsTest { */ @Test public void testSaveFile() { + String fileName = "test3.json"; + String content = "{\"aaa\": \"节点\"}"; + StringBufferInputStream ins = null; + try { + ins = new StringBufferInputStream(content); + FileCommonUtils.saveFile(ins, ".", fileName); + } catch (IOException e) { + e.printStackTrace(); + FileCommonUtils.closeInputStream(ins); + } } /** -- cgit 1.2.3-korg