Unit Test for 'FileCommonUtils'.
[sdc/sdc-workflow-designer.git] / sdc-workflow-designer-server / src / test / java / org / onap / sdc / workflowdesigner / utils / FileCommonUtilsTest.java
1 /**
2  * Copyright (c) 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
13 package org.onap.sdc.workflowdesigner.utils;
14
15 import static org.junit.Assert.assertEquals;
16
17 import java.io.File;
18 import java.io.IOException;
19
20 import org.junit.After;
21 import org.junit.Before;
22 import org.junit.Test;
23
24 /**
25  *
26  */
27 public class FileCommonUtilsTest {
28
29   /**
30    * @throws java.lang.Exception
31    */
32   @Before
33   public void setUp() throws Exception {}
34
35   /**
36    * @throws java.lang.Exception
37    */
38   @After
39   public void tearDown() throws Exception {}
40
41   /**
42    * Test method for {@link org.onap.sdc.workflowdesigner.utils.FileCommonUtils#readString(String)}
43    * 
44    */
45   @Test
46   public final void readStringString() {
47     String fileName = "src\\test\\resources\\workflow\\template-test.bpmn20.xml";
48     File file = new File(fileName);
49     if (file.exists()) {
50       try {
51         String s = FileCommonUtils.readString(fileName);
52         FileCommonUtils.write("test.xml", s);
53         assertEquals(s.isEmpty(), false);
54       } catch (IOException e) {
55       }
56     }
57   }
58
59
60   /**
61    * Test method for
62    * {@link org.onap.sdc.workflowdesigner.utils.FileCommonUtils#write(String, String)}
63    * 
64    */
65   @Test
66   public final void writeStringString() {
67     String fileName = "test.json";
68     String content = "{\"aaa\": \"节点\"}";
69
70     try {
71       FileCommonUtils.write(fileName, content);
72       String s = FileCommonUtils.readString(fileName);
73       assertEquals(s, content);
74     } catch (IOException e) {
75     }
76   }
77
78   /**
79    * Test method for
80    * {@link org.onap.sdc.workflowdesigner.utils.FileCommonUtils#writetoAbsoluteFile(String, String, String)}
81    * 
82    */
83   @Test
84   public final void saveFileStringStringString() {
85     String fileName = "test1.json";
86     String content = "{\"aaa\": \"节点\"}";
87
88     try {
89       FileCommonUtils.writetoAbsoluteFile(".", fileName, content);
90       String s = FileCommonUtils.readString(fileName);
91       assertEquals(s, content);
92     } catch (IOException e) {
93     }
94   }
95
96 }