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.
17 package org.onap.vnfsdk.marketplace.filemanage;
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertNull;
21 import static org.junit.Assert.assertTrue;
24 import java.io.IOException;
25 import java.lang.reflect.Constructor;
26 import java.lang.reflect.Modifier;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.onap.vnfsdk.marketplace.filemanage.http.ToolUtil;
35 public class FileManageTest {
38 public void testCreateFileManager() {
39 new MockUp<FileManagerFactory>() {
41 private FileManagerType getType() {
42 return FileManagerType.ftp;
45 FileManager manager = FileManagerFactory.createFileManager();
51 public void testFileManagerFactoryConstructor() {
53 Constructor<FileManagerFactory> constructor = FileManagerFactory.class.getDeclaredConstructor();
54 assertTrue(Modifier.isPrivate(constructor.getModifiers()));
55 } catch (NoSuchMethodException e) {
61 public void createTestFile() throws IOException
63 String srcPath = "." + File.separator + "srcPathForTest";
64 String dstPath = "." + File.separator + "dstPathForTest";
65 String testFilePath = srcPath + File.separator + "fileForTest";
66 File src = new File(srcPath);
67 File dst = new File(dstPath);
68 File testFile = new File(testFilePath);
71 testFile.createNewFile();
75 public void testDelete() throws IOException {
76 new MockUp<FileManagerFactory>() {
78 private FileManagerType getType() {
79 return FileManagerType.http;
82 new MockUp<ToolUtil>() {
84 private String getHttpServerAbsolutePath() {
89 FileManager ManagerImpl = FileManagerFactory.createFileManager();
90 String dstPath = "./dstPathForTest";
92 assertEquals(ManagerImpl.delete(dstPath), true);
96 public void testUpload() throws IOException {
97 new MockUp<FileManagerFactory>() {
99 private FileManagerType getType() {
100 return FileManagerType.http;
103 new MockUp<ToolUtil>() {
105 private String getHttpServerAbsolutePath() {
110 FileManager ManagerImpl = FileManagerFactory.createFileManager();
111 String srcPath = "./srcPathForTest";
112 String dstPath = "./dstPathForTest";
114 assertEquals(ManagerImpl.upload(srcPath, dstPath), true);
116 File srcDir = new File(srcPath);
119 ManagerImpl.delete(srcPath);
122 assertEquals(ManagerImpl.upload(srcPath, dstPath), false);