aboutsummaryrefslogtreecommitdiffstats
path: root/deprecated-workflow-designer/sdc-workflow-designer-server/src/test/java/org/onap/sdc/workflowdesigner/utils/FileCommonUtilsTest.java
blob: 0abddfff08097b48b9fcd5e43a345a5b9642a1ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/**
 * Copyright (c) 2017-2018 ZTE Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the Apache License, Version 2.0
 * and the Eclipse Public License v1.0 which both accompany this distribution,
 * and are available at http://www.eclipse.org/legal/epl-v10.html
 * and http://www.apache.org/licenses/LICENSE-2.0
 *
 * Contributors:
 *     ZTE - initial API and implementation and/or initial documentation
 */
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;
import org.junit.Test;

/**
 *
 */
public class FileCommonUtilsTest {

  /**
   * @throws java.lang.Exception
   */
  @Before
  public void setUp() throws Exception {}

  /**
   * @throws java.lang.Exception
   */
  @After
  public void tearDown() throws Exception {}

  /**
   * Test method for {@link org.onap.sdc.workflowdesigner.utils.FileCommonUtils#readLines(java.io.InputStream)}.
   */
  @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);
    }

  }

  /**
   * Test method for {@link org.onap.sdc.workflowdesigner.utils.FileCommonUtils#readString(java.io.InputStream)}.
   */
  @Test
  public void testReadStringInputStream() {
  }

  /**
   * Test method for {@link org.onap.sdc.workflowdesigner.utils.FileCommonUtils#readString(java.lang.String)}.
   */
  @Test
  public void testReadStringString() {
    String fileName = "src/test/resources/workflow/template-test.bpmn20.xml";
    File file = new File(fileName);
    if (file.exists()) {
      try {
        String s = FileCommonUtils.readString(fileName);
        FileCommonUtils.write("test.xml", s);
        assertEquals(s.isEmpty(), false);
      } catch (IOException e) {
      }
    }
  }

  /**
   * Test method for {@link org.onap.sdc.workflowdesigner.utils.FileCommonUtils#saveFile(java.io.InputStream, java.lang.String, java.lang.String)}.
   */
  @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);
    }
  }

  /**
   * Test method for {@link org.onap.sdc.workflowdesigner.utils.FileCommonUtils#writetoAbsoluteFile(java.lang.String, java.lang.String, java.lang.String)}.
   */
  @Test
  public void testWritetoAbsoluteFileStringStringString() {
    String fileName = "test1.json";
    String content = "{\"aaa\": \"节点\"}";

    try {
      FileCommonUtils.writetoAbsoluteFile(".", fileName, content);
      String s = FileCommonUtils.readString(fileName);
      assertEquals(s, content);
    } catch (IOException e) {
    }
  }

  /**
   * Test method for {@link org.onap.sdc.workflowdesigner.utils.FileCommonUtils#writetoAbsoluteFile(java.lang.String, java.lang.String, java.lang.String, java.lang.String)}.
   */
  @Test
  public void testWritetoAbsoluteFileStringStringStringString() {
  }

  /**
   * Test method for {@link org.onap.sdc.workflowdesigner.utils.FileCommonUtils#write(java.lang.String, java.lang.String)}.
   */
  @Test
  public void testWriteStringString() {
    String fileName = "test.json";
    String content = "{\"aaa\": \"节点\"}";

    try {
      FileCommonUtils.write(fileName, content);
      String s = FileCommonUtils.readString(fileName);
      assertEquals(s, content);
    } catch (IOException e) {
    }
  }

  /**
   * Test method for {@link org.onap.sdc.workflowdesigner.utils.FileCommonUtils#write(java.lang.String, java.lang.String, java.lang.String, java.lang.String)}.
   */
  @Test
  public void testWriteStringStringStringString() {
  }

  /**
   * Test method for {@link org.onap.sdc.workflowdesigner.utils.FileCommonUtils#write(java.lang.String, java.lang.String, java.lang.String)}.
   */
  @Test
  public void testWriteStringStringString() {
  }

  /**
   * Test method for {@link org.onap.sdc.workflowdesigner.utils.FileCommonUtils#write(java.lang.String, java.lang.String[])}.
   */
  @Test
  public void testWriteStringStringArray() {
  }

  /**
   * Test method for {@link org.onap.sdc.workflowdesigner.utils.FileCommonUtils#write(java.lang.String, java.lang.String[], java.lang.String)}.
   */
  @Test
  public void testWriteStringStringArrayString() {
  }

}