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 autovalue.shaded.org.apache.commons.lang.ObjectUtils;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.onap.vnfsdk.marketplace.filemanage.http.ToolUtil;
36 public class FileManageTest {
39 public void testCreateFileManager() {
40 new MockUp<FileManagerFactory>() {
42 private FileManagerType getType() {
43 return FileManagerType.FTP;
46 FileManager manager = FileManagerFactory.createFileManager();
52 public void testFileManagerFactoryConstructor() {
54 Constructor<FileManagerFactory> constructor = FileManagerFactory.class.getDeclaredConstructor();
55 assertTrue(Modifier.isPrivate(constructor.getModifiers()));
56 } catch (NoSuchMethodException e) {
62 public void createTestFile() throws IOException
64 String srcPath = "." + File.separator + "srcPathForTest";
65 String dstPath = "." + File.separator + "dstPathForTest";
66 String testFilePath = srcPath + File.separator + "fileForTest";
67 File src = new File(srcPath);
68 File dst = new File(dstPath);
69 File testFile = new File(testFilePath);
72 testFile.createNewFile();
76 public void testDelete() throws IOException {
77 new MockUp<FileManagerFactory>() {
79 private FileManagerType getType() {
80 return FileManagerType.HTTP;
83 new MockUp<ToolUtil>() {
85 private String getHttpServerAbsolutePath() {
90 FileManager ManagerImpl = FileManagerFactory.createFileManager();
91 String dstPath = "./dstPathForTest";
93 assertEquals(true,ManagerImpl.delete(dstPath));
97 public void testUpload() throws IOException {
98 new MockUp<FileManagerFactory>() {
100 private FileManagerType getType() {
101 return FileManagerType.HTTP;
104 new MockUp<ToolUtil>() {
106 private String getHttpServerAbsolutePath() {
111 FileManager ManagerImpl = FileManagerFactory.createFileManager();
112 String srcPath = "./srcPathForTest";
113 String dstPath = "./dstPathForTest";
115 assertEquals(true,ManagerImpl.upload(srcPath, dstPath) );
117 File srcDir = new File(srcPath);
120 ManagerImpl.delete(srcPath);
123 assertEquals(false,ManagerImpl.upload(srcPath, dstPath) );