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.onap.vfc.nfvo.vnfm.gvnfm.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;
 
  27 import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.FileUtils;
 
  29 public class FileUtilsTest {
 
  34         fileUtils.getAppAbsoluteUrl();
 
  38     public void testWriteFile() throws Exception {
 
  39         ClassLoader classLoader = getClass().getClassLoader();
 
  40         File file = new File(classLoader.getResource("").getFile());
 
  42         byte[] bytes =  new byte[] {40,50};
 
  43         int b = fileUtils.writeFile(bytes, filePath);
 
  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);
 
  57     public void testListFiles() throws Exception {
 
  59         File f = new File(file);
 
  60         List<File> files = fileUtils.listFiles(f);
 
  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);
 
  72     public void testDelFiles() throws Exception {
 
  73         File resourcesDirectory = new File("src/test/resources/TestDir/Test.txt");
 
  74         assertTrue(fileUtils.delFiles(resourcesDirectory.getAbsolutePath()));
 
  77     public void testgetFiles() throws Exception {
 
  78         File resourcesDirectory = new File("src/test/resources");
 
  79         List<File> files = fileUtils.getFiles(resourcesDirectory.getAbsolutePath());
 
  83     public void testCopy() throws Exception {
 
  84         File oldfile = new File("");
 
  85         File newfile = new File("");
 
  86         fileUtils.copy(oldfile.getAbsolutePath(), newfile.getAbsolutePath(), true);
 
  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();