0abddfff08097b48b9fcd5e43a345a5b9642a1ab
[sdc/sdc-workflow-designer.git] /
1 /**
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
8  *
9  * Contributors:
10  *     ZTE - initial API and implementation and/or initial documentation
11  */
12 package org.onap.sdc.workflowdesigner.utils;
13
14 import static org.junit.Assert.assertEquals;
15
16 import java.io.File;
17 import java.io.FileInputStream;
18 import java.io.FileNotFoundException;
19 import java.io.IOException;
20 import java.io.StringBufferInputStream;
21
22 import org.junit.After;
23 import org.junit.Before;
24 import org.junit.Test;
25
26 /**
27  *
28  */
29 public class FileCommonUtilsTest {
30
31   /**
32    * @throws java.lang.Exception
33    */
34   @Before
35   public void setUp() throws Exception {}
36
37   /**
38    * @throws java.lang.Exception
39    */
40   @After
41   public void tearDown() throws Exception {}
42
43   /**
44    * Test method for {@link org.onap.sdc.workflowdesigner.utils.FileCommonUtils#readLines(java.io.InputStream)}.
45    */
46   @Test
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;
51     try {
52       ins = new FileInputStream(file);
53       String[] ss = FileCommonUtils.readLines(ins);
54       assertEquals(false, ss.length == 0);
55       
56       FileCommonUtils.write("template-test.bpmn20.xml", ss);
57     } catch (FileNotFoundException e) {
58       e.printStackTrace();
59     } catch (IOException e) {
60       e.printStackTrace();
61     } finally {
62       FileCommonUtils.closeInputStream(ins);
63     }
64
65   }
66
67   /**
68    * Test method for {@link org.onap.sdc.workflowdesigner.utils.FileCommonUtils#readString(java.io.InputStream)}.
69    */
70   @Test
71   public void testReadStringInputStream() {
72   }
73
74   /**
75    * Test method for {@link org.onap.sdc.workflowdesigner.utils.FileCommonUtils#readString(java.lang.String)}.
76    */
77   @Test
78   public void testReadStringString() {
79     String fileName = "src/test/resources/workflow/template-test.bpmn20.xml";
80     File file = new File(fileName);
81     if (file.exists()) {
82       try {
83         String s = FileCommonUtils.readString(fileName);
84         FileCommonUtils.write("test.xml", s);
85         assertEquals(s.isEmpty(), false);
86       } catch (IOException e) {
87       }
88     }
89   }
90
91   /**
92    * Test method for {@link org.onap.sdc.workflowdesigner.utils.FileCommonUtils#saveFile(java.io.InputStream, java.lang.String, java.lang.String)}.
93    */
94   @Test
95   public void testSaveFile() {
96     String fileName = "test3.json";
97     String content = "{\"aaa\": \"节点\"}";
98     StringBufferInputStream ins = null;
99     try {
100       ins = new StringBufferInputStream(content);
101       FileCommonUtils.saveFile(ins, ".", fileName);
102     } catch (IOException e) {
103       e.printStackTrace();
104       FileCommonUtils.closeInputStream(ins);
105     }
106   }
107
108   /**
109    * Test method for {@link org.onap.sdc.workflowdesigner.utils.FileCommonUtils#writetoAbsoluteFile(java.lang.String, java.lang.String, java.lang.String)}.
110    */
111   @Test
112   public void testWritetoAbsoluteFileStringStringString() {
113     String fileName = "test1.json";
114     String content = "{\"aaa\": \"节点\"}";
115
116     try {
117       FileCommonUtils.writetoAbsoluteFile(".", fileName, content);
118       String s = FileCommonUtils.readString(fileName);
119       assertEquals(s, content);
120     } catch (IOException e) {
121     }
122   }
123
124   /**
125    * Test method for {@link org.onap.sdc.workflowdesigner.utils.FileCommonUtils#writetoAbsoluteFile(java.lang.String, java.lang.String, java.lang.String, java.lang.String)}.
126    */
127   @Test
128   public void testWritetoAbsoluteFileStringStringStringString() {
129   }
130
131   /**
132    * Test method for {@link org.onap.sdc.workflowdesigner.utils.FileCommonUtils#write(java.lang.String, java.lang.String)}.
133    */
134   @Test
135   public void testWriteStringString() {
136     String fileName = "test.json";
137     String content = "{\"aaa\": \"节点\"}";
138
139     try {
140       FileCommonUtils.write(fileName, content);
141       String s = FileCommonUtils.readString(fileName);
142       assertEquals(s, content);
143     } catch (IOException e) {
144     }
145   }
146
147   /**
148    * Test method for {@link org.onap.sdc.workflowdesigner.utils.FileCommonUtils#write(java.lang.String, java.lang.String, java.lang.String, java.lang.String)}.
149    */
150   @Test
151   public void testWriteStringStringStringString() {
152   }
153
154   /**
155    * Test method for {@link org.onap.sdc.workflowdesigner.utils.FileCommonUtils#write(java.lang.String, java.lang.String, java.lang.String)}.
156    */
157   @Test
158   public void testWriteStringStringString() {
159   }
160
161   /**
162    * Test method for {@link org.onap.sdc.workflowdesigner.utils.FileCommonUtils#write(java.lang.String, java.lang.String[])}.
163    */
164   @Test
165   public void testWriteStringStringArray() {
166   }
167
168   /**
169    * Test method for {@link org.onap.sdc.workflowdesigner.utils.FileCommonUtils#write(java.lang.String, java.lang.String[], java.lang.String)}.
170    */
171   @Test
172   public void testWriteStringStringArrayString() {
173   }
174
175 }