From 7e7e80cfdb7a33d6f86926b451b34498a3aaab0f Mon Sep 17 00:00:00 2001 From: yuanx Date: Tue, 30 Jun 2020 11:39:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DDefaultFastFileStorageClient?= =?UTF-8?q?=E4=B8=8D=E5=85=BC=E5=AE=B9=E7=A9=BA=E6=89=A9=E5=B1=95=E5=90=8D?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加针对DefaultFastFileStorageClient的空扩展名文件上传的测试 --- .../service/DefaultFastFileStorageClient.java | 1 - .../service/FastFileStorageClientTest.java | 30 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/github/tobato/fastdfs/service/DefaultFastFileStorageClient.java b/src/main/java/com/github/tobato/fastdfs/service/DefaultFastFileStorageClient.java index 78168dc..5074283 100644 --- a/src/main/java/com/github/tobato/fastdfs/service/DefaultFastFileStorageClient.java +++ b/src/main/java/com/github/tobato/fastdfs/service/DefaultFastFileStorageClient.java @@ -105,7 +105,6 @@ public StorePath uploadImageAndCrtThumbImage(InputStream inputStream, @Override public StorePath uploadFile(FastFile fastFile) { Validate.notNull(fastFile.getInputStream(), "上传文件流不能为空"); - Validate.notBlank(fastFile.getFileExtName(), "文件扩展名不能为空"); // 获取存储节点 StorageNode client = getStorageNode(fastFile.getGroupName()); // 上传文件 diff --git a/src/test/java/com/github/tobato/fastdfs/service/FastFileStorageClientTest.java b/src/test/java/com/github/tobato/fastdfs/service/FastFileStorageClientTest.java index 97c9e04..b619abe 100644 --- a/src/test/java/com/github/tobato/fastdfs/service/FastFileStorageClientTest.java +++ b/src/test/java/com/github/tobato/fastdfs/service/FastFileStorageClientTest.java @@ -9,6 +9,7 @@ import com.github.tobato.fastdfs.domain.fdfs.StorePath; import com.github.tobato.fastdfs.domain.fdfs.ThumbImageConfig; import org.apache.commons.io.FilenameUtils; +import org.apache.logging.log4j.util.Strings; import org.junit.Test; import org.junit.runner.RunWith; import org.slf4j.Logger; @@ -23,9 +24,11 @@ import java.io.InputStream; import java.util.HashSet; import java.util.Set; +import java.util.Collections; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; /** * FastFileStorageClient客户端 @@ -89,6 +92,33 @@ public void testUploadFileWithoutMetaData() { storageClient.deleteFile(path.getFullPath()); } + /** + * 测试上传文件的时候不提供后缀名称 + */ + @Test + public void testUploadWithoutExtName() { + // null扩展名的文件 + LOGGER.debug("##上传具有null扩展名的文件..##"); + RandomTextFile file = new RandomTextFile(); + file.setFileExtName(null); + assertNull(file.getFileExtName()); + + StorePath path = storageClient.uploadFile(file.getInputStream(), + file.getFileSize(), file.getFileExtName(), Collections.emptySet()); + assertNotNull(path); + LOGGER.debug("上传文件 result={}", path); + // 空字串扩展名文件 + LOGGER.debug("##上传具有空字符串扩展名的文件..##"); + file = new RandomTextFile(); + file.setFileExtName(Strings.EMPTY); + assertEquals(Strings.EMPTY, file.getFileExtName()); + + path = storageClient.uploadFile(file.getInputStream(), + file.getFileSize(), file.getFileExtName(), Collections.emptySet()); + assertNotNull(path); + LOGGER.debug("上传文件 result={}", path); + } + /** * 上传图片,并且生成缩略图 *