test: 完善测试例
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package cn.celess.blog.service.fileserviceimpl;
|
package cn.celess.blog.service.fileserviceimpl;
|
||||||
|
|
||||||
import cn.celess.blog.BaseTest;
|
import cn.celess.blog.BaseTest;
|
||||||
|
import cn.celess.blog.entity.model.FileInfo;
|
||||||
import cn.celess.blog.entity.model.FileResponse;
|
import cn.celess.blog.entity.model.FileResponse;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -11,19 +12,49 @@ import org.springframework.test.context.ActiveProfiles;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@ActiveProfiles("prod")
|
|
||||||
public class QiniuFileServiceImplTest extends BaseTest {
|
public class QiniuFileServiceImplTest extends BaseTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
QiniuFileServiceImpl qiniuFileService;
|
QiniuFileServiceImpl qiniuFileService;
|
||||||
|
private String fileName;
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
@Test
|
@Test
|
||||||
public void uploadFile() {
|
public void uploadFile() {
|
||||||
|
fileName = null;
|
||||||
|
File file = createFile();
|
||||||
|
FileResponse fileResponse = qiniuFileService.uploadFile(new FileInputStream(file), file.getName());
|
||||||
|
assertEquals(file.getName(), fileResponse.key);
|
||||||
|
assertEquals("qiniu", fileResponse.bucket);
|
||||||
|
assertNotNull(fileResponse.hash);
|
||||||
|
fileName = fileResponse.key;
|
||||||
|
|
||||||
|
qiniuFileService.deleteFile(fileName);
|
||||||
|
|
||||||
|
file.deleteOnExit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getFileList() {
|
||||||
|
List<FileInfo> fileList = qiniuFileService.getFileList();
|
||||||
|
fileList.forEach(fileInfo -> {
|
||||||
|
assertNotNull(fileInfo.key);
|
||||||
|
assertNotNull(fileInfo.hash);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void deleteFile() {
|
||||||
|
uploadFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SneakyThrows
|
||||||
|
private File createFile() {
|
||||||
String fileName = "test." + randomStr(3);
|
String fileName = "test." + randomStr(3);
|
||||||
File file = new File(fileName);
|
File file = new File(fileName);
|
||||||
if (!file.exists() && file.createNewFile()) {
|
if (!file.exists() && file.createNewFile()) {
|
||||||
@@ -36,15 +67,6 @@ public class QiniuFileServiceImplTest extends BaseTest {
|
|||||||
outputStream.flush();
|
outputStream.flush();
|
||||||
outputStream.close();
|
outputStream.close();
|
||||||
}
|
}
|
||||||
FileResponse fileResponse = qiniuFileService.uploadFile(new FileInputStream(file), fileName);
|
return file;
|
||||||
assertEquals(fileName, fileResponse.key);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getFileList() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void deleteFile() {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user