暂存提交
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package com.baiyue.file.controller;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class QualificationFileContractTest {
|
||||
|
||||
@Test
|
||||
void fileServiceExposesTheOnlyPublicMultipartUploadEntry() {
|
||||
RequestMapping baseMapping = QualificationFileController.class.getAnnotation(RequestMapping.class);
|
||||
assertTrue(Arrays.asList(baseMapping.value())
|
||||
.contains("/api/merchant/v1/files/qualifications"));
|
||||
|
||||
boolean hasMultipartPost = Arrays.stream(QualificationFileController.class.getDeclaredMethods())
|
||||
.map(method -> method.getAnnotation(PostMapping.class))
|
||||
.filter(java.util.Objects::nonNull)
|
||||
.flatMap(mapping -> Arrays.stream(mapping.consumes()))
|
||||
.anyMatch(MediaType.MULTIPART_FORM_DATA_VALUE::equals);
|
||||
|
||||
assertTrue(hasMultipartPost, "企业资质真实上传入口必须保持 multipart/form-data 契约");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.baiyue.file.service;
|
||||
|
||||
import com.baiyue.common.core.exception.BizException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class LocalQualificationStorageTest {
|
||||
|
||||
@TempDir
|
||||
Path storageRoot;
|
||||
|
||||
@Test
|
||||
void storeReturnsFileServiceUrlBackedByARealTenantFile() throws Exception {
|
||||
var storage = new LocalQualificationStorage(storageRoot.toString());
|
||||
byte[] png = {(byte) 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x01};
|
||||
var upload = new MockMultipartFile("file", "license.png", "image/png", png);
|
||||
|
||||
var stored = storage.store(10001L, upload);
|
||||
|
||||
assertTrue(stored.documentUrl().matches(
|
||||
"/api/merchant/v1/files/qualifications/[0-9a-f-]{36}\\.png"));
|
||||
assertTrue(Files.isRegularFile(stored.path()));
|
||||
assertEquals(stored.path().toAbsolutePath(),
|
||||
storage.load(10001L, stored.fileName()).getFile().toPath().toAbsolutePath());
|
||||
}
|
||||
|
||||
@Test
|
||||
void legacySeedPathCannotBePretendedToBeAStoredFile() {
|
||||
var storage = new LocalQualificationStorage(storageRoot.toString());
|
||||
|
||||
assertThrows(BizException.class,
|
||||
() -> storage.load(10001L, "demo-business-license.jpg"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user