Update gvnfm-driver .gitreview file
[vfc/nfvo/driver/vnfm/gvnfm.git] / juju / juju-vnfmadapter / Juju-vnfmadapterService / service / src / test / java / org / onap / vfc / nfvo / vnfm / gvnfm / 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.onap.vfc.nfvo.vnfm.gvnfm.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 import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.FileUtils;
28
29 public class FileUtilsTest {
30
31     FileUtils fileUtils;
32     @Before
33     public void setUp(){
34         fileUtils.getAppAbsoluteUrl();
35     }
36
37     @Test
38     public void testWriteFile() throws Exception {
39         ClassLoader classLoader = getClass().getClassLoader();
40         File file = new File(classLoader.getResource("").getFile());
41         String filePath = "";
42         byte[] bytes =  new byte[] {40,50};
43         int b = fileUtils.writeFile(bytes, filePath);
44         assertNotNull(b);
45     }
46     @Test
47     @Ignore
48     public void testReadFile() throws Exception {
49         ClassLoader classLoader = getClass().getClassLoader();
50         File f = new File(classLoader.getResource("").getFile());
51         System.out.println(f.isAbsolute());
52         String charsetName = "UTF-8";
53         byte[] b = fileUtils.readFile(f, charsetName);
54         assertNotNull(b);
55     }
56     @Test
57     public void testListFiles() throws Exception {
58         String file = ".";
59         File f = new File(file);
60         List<File> files = fileUtils.listFiles(f);
61         assertNotNull(files);
62
63     }
64     @Test
65     public void testMkDirs() throws Exception {
66         File resourcesDirectory = new File("src/test/resources");
67         String path = resourcesDirectory.getAbsolutePath()+"/TestDir";
68         resourcesDirectory.getAbsolutePath();
69         fileUtils.mkDirs(path);
70     }
71     @Test
72     public void testDelFiles() throws Exception {
73         File resourcesDirectory = new File("src/test/resources/TestDir/Test.txt");
74         assertTrue(fileUtils.delFiles(resourcesDirectory.getAbsolutePath()));
75     }
76     @Test
77     public void testgetFiles() throws Exception {
78         File resourcesDirectory = new File("src/test/resources");
79         List<File> files = fileUtils.getFiles(resourcesDirectory.getAbsolutePath());
80         assertNotNull(files);
81     }
82     @Test
83     public void testCopy() throws Exception {
84         File oldfile = new File("");
85         File newfile = new File("");
86         fileUtils.copy(oldfile.getAbsolutePath(), newfile.getAbsolutePath(), true);
87     }
88     @Test
89     public void testPrivateConstructor() throws Exception {
90         Constructor constructor = FileUtils.class.getDeclaredConstructor();
91         assertTrue("Constructor  private", Modifier.isPrivate(constructor.getModifiers()));
92         constructor.setAccessible(true);
93         constructor.newInstance();
94     }
95 }