-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea234ab
commit 4ced332
Showing
4 changed files
with
78 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
muyun-boot/src/test/java/net/ximatai/muyun/test/fileserver/TestFileDownload.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package net.ximatai.muyun.test.fileserver; | ||
|
||
import io.quarkus.test.common.QuarkusTestResource; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import jakarta.inject.Inject; | ||
import net.ximatai.muyun.fileserver.FileServerConfig; | ||
import net.ximatai.muyun.fileserver.IFileService; | ||
import net.ximatai.muyun.test.testcontainers.PostgresTestResource; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
|
||
@QuarkusTest | ||
@QuarkusTestResource(value = PostgresTestResource.class, restrictToAnnotatedClass = true) | ||
public class TestFileDownload { | ||
|
||
@Inject | ||
IFileService service; | ||
|
||
@Inject | ||
FileServerConfig config; | ||
|
||
String fileName; | ||
String fileContent; | ||
File tempFile; | ||
|
||
@BeforeEach | ||
public void setup() throws IOException { | ||
fileName = "ZZZZZZ.txt"; | ||
fileContent = "hello world"; | ||
tempFile = File.createTempFile(fileName.split("\\.")[0], fileName.split("\\.")[1]); | ||
FileOutputStream fos = new FileOutputStream(tempFile); | ||
fos.write(fileContent.getBytes()); | ||
fos.close(); | ||
} | ||
|
||
@Test | ||
void testFileDownload() throws InterruptedException { | ||
String id = service.save(tempFile, fileName).split("@")[0]; | ||
Thread.sleep(1000); | ||
File file = service.get(id); | ||
String filePath = file.getAbsolutePath(); | ||
System.out.println(filePath); | ||
// 错误原因: 目标目录中已经存在了同名文件,导致无法创建目标文件的副本 | ||
File file2 = service.get(id); | ||
String filePath2 = file2.getAbsolutePath(); | ||
System.out.println(filePath2); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
muyun-boot/src/test/java/net/ximatai/muyun/test/fileserver/TestTempFile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package net.ximatai.muyun.test.fileserver; | ||
|
||
import io.quarkus.test.common.QuarkusTestResource; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import net.ximatai.muyun.test.testcontainers.PostgresTestResource; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
@QuarkusTest | ||
@QuarkusTestResource(value = PostgresTestResource.class, restrictToAnnotatedClass = true) | ||
public class TestTempFile { | ||
|
||
@Test | ||
public void test() throws IOException { | ||
String fileName = "MaNing.txt"; | ||
File tempFile = File.createTempFile(fileName.split("\\.")[0], "." + fileName.split("\\.")[1]); | ||
} | ||
} |