Remove the unused UT code
[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
17 package org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common;
18
19 import static org.junit.Assert.assertNotNull;
20 import static org.junit.Assert.assertNull;
21 import static org.junit.Assert.assertTrue;
22
23 import java.io.File;
24 import java.io.IOException;
25 import java.lang.reflect.Constructor;
26 import java.lang.reflect.Modifier;
27 import java.util.List;
28
29 import org.junit.Before;
30 import org.junit.Test;
31
32 public class FileUtilsTest {
33
34     FileUtils fileUtils;
35
36     @Before
37     public void setUp() {
38         fileUtils.getAppAbsoluteUrl();
39     }
40
41     @Test
42     public void testGetClassPath() throws Exception {
43         assertNotNull(FileUtils.getClassPath());
44     }
45
46     @Test
47     public void testReadFileNull() throws Exception {
48         assertNotNull(FileUtils.readFile(null, null));
49     }
50
51     @Test
52     public void testReadFile() throws Exception {
53         assertNotNull(FileUtils.readFile(
54                 new File("src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/FileUtil.java"), "utf-8"));
55     }
56
57     @Test(expected = IOException.class)
58     public void testReadFileFail() throws Exception {
59         FileUtils.readFile(new File("src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/aaa.java"),
60                 "utf-8");
61     }
62
63     @Test
64     public void testWriteFile() throws Exception {
65         String filePath = "";
66         byte[] bytes = new byte[] {40, 50};
67         int b = FileUtils.writeFile(bytes, filePath);
68         assertNotNull(b);
69     }
70
71     @Test
72     public void testWriteFileSuccess() throws Exception {
73         String filePath = "src/test/java/FileTest";
74         byte[] bytes = new byte[] {40, 50};
75         int b = FileUtils.writeFile(bytes, filePath);
76         assertNotNull(b);
77     }
78
79     @Test
80     public void testListFiles() throws Exception {
81         String file = ".";
82         File f = new File(file);
83         List<File> files = FileUtils.listFiles(f);
84         assertNotNull(files);
85
86     }
87
88     // @Test(expected = FileNotFoundException.class)
89     // public void testListFilesFail() throws Exception {
90     // String file = "abc";
91     // File f = new File(file);
92     // List<File> files = FileUtils.listFiles(f);
93     // assertNotNull(files);
94     //
95     // }
96
97     @Test
98     public void testMkDirs() throws Exception {
99         File resourcesDirectory = new File("src/test/resources");
100         String path = resourcesDirectory.getAbsolutePath() + "/TestDir";
101         resourcesDirectory.getAbsolutePath();
102         FileUtils.newFloder(path);
103         FileUtils.mkDirs(path);
104         FileUtils.newFloder(path);
105     }
106
107     @Test
108     public void testDelFiles() throws Exception {
109         File resourcesDirectory = new File("src/test/resources/TestDir/Test.txt");
110         assertTrue(FileUtils.delFiles(resourcesDirectory.getAbsolutePath()));
111     }
112
113     @Test
114     public void testgetFiles() throws Exception {
115         File resourcesDirectory = new File("src/test/resources");
116         List<File> files = FileUtils.getFiles(resourcesDirectory.getAbsolutePath());
117         assertNotNull(files);
118     }
119
120     @Test
121     public void testCopy() throws Exception {
122         File oldfile = new File("");
123         File newfile = new File("");
124         FileUtils.copy(oldfile.getAbsolutePath(), newfile.getAbsolutePath(), true);
125     }
126
127     @Test
128     public void testPrivateConstructor() throws Exception {
129         Constructor constructor = FileUtils.class.getDeclaredConstructor();
130         assertTrue("Constructor  private", Modifier.isPrivate(constructor.getModifiers()));
131         constructor.setAccessible(true);
132         constructor.newInstance();
133     }
134
135     // @Test(expected = FileNotFoundException.class)
136     // public void testIsUsed() throws Exception {
137     // assertNotNull(FileUtils.isUsed("abc.txt"));
138     //
139     // }
140
141     @Test
142     public void testGetBaseFileName() throws Exception {
143         assertNotNull(FileUtils.getBaseFileName(new File("aaa.txt")));
144         assertNotNull(FileUtils.getBaseFileName(new File("aaa")));
145
146     }
147
148     @Test
149     public void testFixPath() throws Exception {
150         assertNull(FileUtils.fixPath(null));
151         assertNotNull(FileUtils.fixPath("/abc"));
152         assertNotNull(FileUtils.fixPath("/abc/"));
153         assertNotNull(FileUtils.fixPath("abc"));
154         assertNotNull(FileUtils.fixPath("abc/"));
155
156     }
157
158     @Test
159     public void testGetFiendlyPath() throws Exception {
160         assertNull(FileUtils.getFriendlyPath(null));
161         assertNotNull(FileUtils.getFriendlyPath("/abc"));
162         assertNotNull(FileUtils.getFriendlyPath("/abc/"));
163         assertNotNull(FileUtils.getFriendlyPath("abc"));
164         assertNotNull(FileUtils.getFriendlyPath("abc/"));
165
166     }
167 }