Update gvnfm-driver .gitreview file
[vfc/nfvo/driver/vnfm/gvnfm.git] / juju / juju-vnfmadapter / Juju-vnfmadapterService / service / src / test / java / org / openo / nfvo / jujuvnfmadapter / common / FileUtilsTest.java
1 /*
2  * Copyright 2017 Huawei Technologies Co., Ltd.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.openo.nfvo.jujuvnfmadapter.common;
17
18 import static org.junit.Assert.*;
19
20 import java.io.File;
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;
27
28 public class FileUtilsTest {
29
30     FileUtils fileUtils;
31     @Before
32     public void setUp(){
33         fileUtils.getAppAbsoluteUrl();
34     }
35
36     @Test
37     public void testWriteFile() throws Exception {
38         ClassLoader classLoader = getClass().getClassLoader();
39         File file = new File(classLoader.getResource("").getFile());
40         String filePath = "";
41         byte[] bytes =  new byte[] {40,50};
42         int b = fileUtils.writeFile(bytes, filePath);
43         assertNotNull(b);
44     }
45     @Test
46     @Ignore
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);
53         assertNotNull(b);
54     }
55     @Test
56     public void testListFiles() throws Exception {
57         String file = ".";
58         File f = new File(file);
59         List<File> files = fileUtils.listFiles(f);
60         assertNotNull(files);
61
62     }
63     @Test
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);
69     }
70     @Test
71     public void testDelFiles() throws Exception {
72         File resourcesDirectory = new File("src/test/resources/TestDir/Test.txt");
73         assertTrue(fileUtils.delFiles(resourcesDirectory.getAbsolutePath()));
74     }
75     @Test
76     public void testgetFiles() throws Exception {
77         File resourcesDirectory = new File("src/test/resources");
78         List<File> files = fileUtils.getFiles(resourcesDirectory.getAbsolutePath());
79         assertNotNull(files);
80     }
81     @Test
82     public void testCopy() throws Exception {
83         File oldfile = new File("");
84         File newfile = new File("");
85         fileUtils.copy(oldfile.getAbsolutePath(), newfile.getAbsolutePath(), true);
86     }
87     @Test
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();
93     }
94 }