2 * Copyright (c) 2017-2018 ZTE Corporation.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the Apache License, Version 2.0
5 * and the Eclipse Public License v1.0 which both accompany this distribution,
6 * and are available at http://www.eclipse.org/legal/epl-v10.html
7 * and http://www.apache.org/licenses/LICENSE-2.0
10 * ZTE - initial API and implementation and/or initial documentation
12 package org.onap.sdc.workflowdesigner.utils;
14 import static org.junit.Assert.assertEquals;
17 import java.io.FileInputStream;
18 import java.io.FileNotFoundException;
19 import java.io.IOException;
20 import java.io.StringBufferInputStream;
22 import org.junit.After;
23 import org.junit.Before;
24 import org.junit.Test;
29 public class FileCommonUtilsTest {
32 * @throws java.lang.Exception
35 public void setUp() throws Exception {}
38 * @throws java.lang.Exception
41 public void tearDown() throws Exception {}
44 * Test method for {@link org.onap.sdc.workflowdesigner.utils.FileCommonUtils#readLines(java.io.InputStream)}.
47 public void testReadLines() {
48 String fileName = "src/test/resources/workflow/template-test.bpmn20.xml";
49 File file = new File(fileName);
50 FileInputStream ins = null;
52 ins = new FileInputStream(file);
53 String[] ss = FileCommonUtils.readLines(ins);
54 assertEquals(false, ss.length == 0);
56 FileCommonUtils.write("template-test.bpmn20.xml", ss);
57 } catch (FileNotFoundException e) {
59 } catch (IOException e) {
62 FileCommonUtils.closeInputStream(ins);
68 * Test method for {@link org.onap.sdc.workflowdesigner.utils.FileCommonUtils#readString(java.io.InputStream)}.
71 public void testReadStringInputStream() {
75 * Test method for {@link org.onap.sdc.workflowdesigner.utils.FileCommonUtils#readString(java.lang.String)}.
78 public void testReadStringString() {
79 String fileName = "src/test/resources/workflow/template-test.bpmn20.xml";
80 File file = new File(fileName);
83 String s = FileCommonUtils.readString(fileName);
84 FileCommonUtils.write("test.xml", s);
85 assertEquals(s.isEmpty(), false);
86 } catch (IOException e) {
92 * Test method for {@link org.onap.sdc.workflowdesigner.utils.FileCommonUtils#saveFile(java.io.InputStream, java.lang.String, java.lang.String)}.
95 public void testSaveFile() {
96 String fileName = "test3.json";
97 String content = "{\"aaa\": \"节点\"}";
98 StringBufferInputStream ins = null;
100 ins = new StringBufferInputStream(content);
101 FileCommonUtils.saveFile(ins, ".", fileName);
102 } catch (IOException e) {
104 FileCommonUtils.closeInputStream(ins);
109 * Test method for {@link org.onap.sdc.workflowdesigner.utils.FileCommonUtils#writetoAbsoluteFile(java.lang.String, java.lang.String, java.lang.String)}.
112 public void testWritetoAbsoluteFileStringStringString() {
113 String fileName = "test1.json";
114 String content = "{\"aaa\": \"节点\"}";
117 FileCommonUtils.writetoAbsoluteFile(".", fileName, content);
118 String s = FileCommonUtils.readString(fileName);
119 assertEquals(s, content);
120 } catch (IOException e) {
125 * Test method for {@link org.onap.sdc.workflowdesigner.utils.FileCommonUtils#writetoAbsoluteFile(java.lang.String, java.lang.String, java.lang.String, java.lang.String)}.
128 public void testWritetoAbsoluteFileStringStringStringString() {
132 * Test method for {@link org.onap.sdc.workflowdesigner.utils.FileCommonUtils#write(java.lang.String, java.lang.String)}.
135 public void testWriteStringString() {
136 String fileName = "test.json";
137 String content = "{\"aaa\": \"节点\"}";
140 FileCommonUtils.write(fileName, content);
141 String s = FileCommonUtils.readString(fileName);
142 assertEquals(s, content);
143 } catch (IOException e) {
148 * Test method for {@link org.onap.sdc.workflowdesigner.utils.FileCommonUtils#write(java.lang.String, java.lang.String, java.lang.String, java.lang.String)}.
151 public void testWriteStringStringStringString() {
155 * Test method for {@link org.onap.sdc.workflowdesigner.utils.FileCommonUtils#write(java.lang.String, java.lang.String, java.lang.String)}.
158 public void testWriteStringStringString() {
162 * Test method for {@link org.onap.sdc.workflowdesigner.utils.FileCommonUtils#write(java.lang.String, java.lang.String[])}.
165 public void testWriteStringStringArray() {
169 * Test method for {@link org.onap.sdc.workflowdesigner.utils.FileCommonUtils#write(java.lang.String, java.lang.String[], java.lang.String)}.
172 public void testWriteStringStringArrayString() {