summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGao Weitao <victor.gao@huawei.com>2018-03-20 12:21:14 +0000
committerGerrit Code Review <gerrit@onap.org>2018-03-20 12:21:14 +0000
commitb11aaf8cbd6fefdfafbe5b435818cb7ccac2278f (patch)
treeecb67042b310f5fd1ef88889d8b7af9373165d36
parente9b1aa33239c115d4d6c5731e608aaacd9536223 (diff)
parent064c184a26cd8385c91de65afc4bf43b9907ab9d (diff)
Merge "Add UT for FileUtils.java"
-rw-r--r--juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/FileTest1
-rw-r--r--juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/FileUtilsTest.java115
2 files changed, 95 insertions, 21 deletions
diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/FileTest b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/FileTest
new file mode 100644
index 0000000..1117cee
--- /dev/null
+++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/FileTest
@@ -0,0 +1 @@
+(2 \ No newline at end of file
diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/FileUtilsTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/FileUtilsTest.java
index 422888b..9fc383e 100644
--- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/FileUtilsTest.java
+++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/FileUtilsTest.java
@@ -13,78 +13,118 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import java.util.List;
+
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
-import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.FileUtils;
public class FileUtilsTest {
FileUtils fileUtils;
+
@Before
- public void setUp(){
+ public void setUp() {
fileUtils.getAppAbsoluteUrl();
}
@Test
+ public void testGetClassPath() throws Exception {
+ assertNotNull(FileUtils.getClassPath());
+ }
+
+ @Test
+ public void testReadFileNull() throws Exception {
+ assertNotNull(FileUtils.readFile(null, null));
+ }
+
+ @Test
+ public void testReadFile() throws Exception {
+ assertNotNull(FileUtils.readFile(
+ new File("src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/FileUtil.java"), "utf-8"));
+ }
+
+ @Test(expected = IOException.class)
+ public void testReadFileFail() throws Exception {
+ FileUtils.readFile(new File("src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/aaa.java"),
+ "utf-8");
+ }
+
+ @Test
public void testWriteFile() throws Exception {
- ClassLoader classLoader = getClass().getClassLoader();
- File file = new File(classLoader.getResource("").getFile());
String filePath = "";
- byte[] bytes = new byte[] {40,50};
- int b = fileUtils.writeFile(bytes, filePath);
+ byte[] bytes = new byte[] {40, 50};
+ int b = FileUtils.writeFile(bytes, filePath);
assertNotNull(b);
}
+
@Test
- @Ignore
- public void testReadFile() throws Exception {
- ClassLoader classLoader = getClass().getClassLoader();
- File f = new File(classLoader.getResource("").getFile());
- System.out.println(f.isAbsolute());
- String charsetName = "UTF-8";
- byte[] b = fileUtils.readFile(f, charsetName);
+ public void testWriteFileSuccess() throws Exception {
+ String filePath = "src/test/java/FileTest";
+ byte[] bytes = new byte[] {40, 50};
+ int b = FileUtils.writeFile(bytes, filePath);
assertNotNull(b);
}
+
@Test
public void testListFiles() throws Exception {
String file = ".";
File f = new File(file);
- List<File> files = fileUtils.listFiles(f);
+ List<File> files = FileUtils.listFiles(f);
assertNotNull(files);
}
+
+ @Test(expected = FileNotFoundException.class)
+ public void testListFilesFail() throws Exception {
+ String file = "abc";
+ File f = new File(file);
+ List<File> files = FileUtils.listFiles(f);
+ assertNotNull(files);
+
+ }
+
@Test
public void testMkDirs() throws Exception {
File resourcesDirectory = new File("src/test/resources");
- String path = resourcesDirectory.getAbsolutePath()+"/TestDir";
+ String path = resourcesDirectory.getAbsolutePath() + "/TestDir";
resourcesDirectory.getAbsolutePath();
- fileUtils.mkDirs(path);
+ FileUtils.newFloder(path);
+ FileUtils.mkDirs(path);
+ FileUtils.newFloder(path);
}
+
@Test
public void testDelFiles() throws Exception {
File resourcesDirectory = new File("src/test/resources/TestDir/Test.txt");
- assertTrue(fileUtils.delFiles(resourcesDirectory.getAbsolutePath()));
+ assertTrue(FileUtils.delFiles(resourcesDirectory.getAbsolutePath()));
}
+
@Test
public void testgetFiles() throws Exception {
File resourcesDirectory = new File("src/test/resources");
- List<File> files = fileUtils.getFiles(resourcesDirectory.getAbsolutePath());
+ List<File> files = FileUtils.getFiles(resourcesDirectory.getAbsolutePath());
assertNotNull(files);
}
+
@Test
public void testCopy() throws Exception {
File oldfile = new File("");
File newfile = new File("");
- fileUtils.copy(oldfile.getAbsolutePath(), newfile.getAbsolutePath(), true);
+ FileUtils.copy(oldfile.getAbsolutePath(), newfile.getAbsolutePath(), true);
}
+
@Test
public void testPrivateConstructor() throws Exception {
Constructor constructor = FileUtils.class.getDeclaredConstructor();
@@ -92,4 +132,37 @@ public class FileUtilsTest {
constructor.setAccessible(true);
constructor.newInstance();
}
+
+ @Test(expected = FileNotFoundException.class)
+ public void testIsUsed() throws Exception {
+ assertNotNull(FileUtils.isUsed("abc.txt"));
+
+ }
+
+ @Test
+ public void testGetBaseFileName() throws Exception {
+ assertNotNull(FileUtils.getBaseFileName(new File("aaa.txt")));
+ assertNotNull(FileUtils.getBaseFileName(new File("aaa")));
+
+ }
+
+ @Test
+ public void testFixPath() throws Exception {
+ assertNull(FileUtils.fixPath(null));
+ assertNotNull(FileUtils.fixPath("/abc"));
+ assertNotNull(FileUtils.fixPath("/abc/"));
+ assertNotNull(FileUtils.fixPath("abc"));
+ assertNotNull(FileUtils.fixPath("abc/"));
+
+ }
+
+ @Test
+ public void testGetFiendlyPath() throws Exception {
+ assertNull(FileUtils.getFriendlyPath(null));
+ assertNotNull(FileUtils.getFriendlyPath("/abc"));
+ assertNotNull(FileUtils.getFriendlyPath("/abc/"));
+ assertNotNull(FileUtils.getFriendlyPath("abc"));
+ assertNotNull(FileUtils.getFriendlyPath("abc/"));
+
+ }
}