2 * Copyright 2017 Huawei Technologies Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.openo.nfvo.jujuvnfmadapter.common;
18 import static org.junit.Assert.*;
21 import java.lang.reflect.Constructor;
22 import java.lang.reflect.Modifier;
23 import java.util.List;
24 import org.junit.Before;
25 import org.junit.Ignore;
26 import org.junit.Test;
28 public class FileUtilsTest {
33 fileUtils.getAppAbsoluteUrl();
37 public void testWriteFile() throws Exception {
38 ClassLoader classLoader = getClass().getClassLoader();
39 File file = new File(classLoader.getResource("").getFile());
41 byte[] bytes = new byte[] {40,50};
42 int b = fileUtils.writeFile(bytes, filePath);
47 public void testReadFile() throws Exception {
48 ClassLoader classLoader = getClass().getClassLoader();
49 File f = new File(classLoader.getResource("").getFile());
50 System.out.println(f.isAbsolute());
51 String charsetName = "UTF-8";
52 byte[] b = fileUtils.readFile(f, charsetName);
56 public void testListFiles() throws Exception {
58 File f = new File(file);
59 List<File> files = fileUtils.listFiles(f);
64 public void testMkDirs() throws Exception {
65 File resourcesDirectory = new File("src/test/resources");
66 String path = resourcesDirectory.getAbsolutePath()+"/TestDir";
67 resourcesDirectory.getAbsolutePath();
68 fileUtils.mkDirs(path);
71 public void testDelFiles() throws Exception {
72 File resourcesDirectory = new File("src/test/resources/TestDir/Test.txt");
73 assertTrue(fileUtils.delFiles(resourcesDirectory.getAbsolutePath()));
76 public void testgetFiles() throws Exception {
77 File resourcesDirectory = new File("src/test/resources");
78 List<File> files = fileUtils.getFiles(resourcesDirectory.getAbsolutePath());
82 public void testCopy() throws Exception {
83 File oldfile = new File("");
84 File newfile = new File("");
85 fileUtils.copy(oldfile.getAbsolutePath(), newfile.getAbsolutePath(), true);
88 public void testPrivateConstructor() throws Exception {
89 Constructor constructor = FileUtils.class.getDeclaredConstructor();
90 assertTrue("Constructor private", Modifier.isPrivate(constructor.getModifiers()));
91 constructor.setAccessible(true);
92 constructor.newInstance();