修复图片下载问题
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package com.nanri.aiimage.modules.productrisk.service;
|
||||
|
||||
import com.nanri.aiimage.modules.productrisk.model.dto.ProductRiskRowDto;
|
||||
import com.nanri.aiimage.modules.productrisk.model.enums.ProductRiskCountryCode;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
class ProductRiskExcelAssemblyServiceTest {
|
||||
|
||||
private final ProductRiskExcelAssemblyService service = new ProductRiskExcelAssemblyService();
|
||||
|
||||
@Test
|
||||
void completionColumnUsesChineseValueAndCompletedStatusWinsOverFalseDone() throws Exception {
|
||||
Path xlsx = Files.createTempFile("product-risk-result-", ".xlsx");
|
||||
try {
|
||||
ProductRiskRowDto completed = row("SKU-1", "处理完成", Boolean.FALSE);
|
||||
ProductRiskRowDto running = row("SKU-2", "处理中", Boolean.FALSE);
|
||||
ProductRiskRowDto done = row("SKU-3", null, Boolean.TRUE);
|
||||
|
||||
service.writeWorkbook(
|
||||
xlsx.toFile(),
|
||||
"店铺A",
|
||||
Map.of(ProductRiskCountryCode.DE.getSheetName(), List.of(completed, running, done)));
|
||||
|
||||
try (InputStream in = Files.newInputStream(xlsx);
|
||||
Workbook workbook = new XSSFWorkbook(in)) {
|
||||
Sheet sheet = workbook.getSheet(ProductRiskCountryCode.DE.getSheetName());
|
||||
assertEquals("完成", sheet.getRow(0).getCell(3).getStringCellValue());
|
||||
assertEquals("是", sheet.getRow(1).getCell(3).getStringCellValue());
|
||||
assertNotEquals("false", sheet.getRow(1).getCell(3).getStringCellValue());
|
||||
assertEquals("否", sheet.getRow(2).getCell(3).getStringCellValue());
|
||||
assertEquals("是", sheet.getRow(3).getCell(3).getStringCellValue());
|
||||
}
|
||||
} finally {
|
||||
Files.deleteIfExists(xlsx);
|
||||
}
|
||||
}
|
||||
|
||||
private static ProductRiskRowDto row(String productAsinSku, String status, Boolean done) {
|
||||
ProductRiskRowDto row = new ProductRiskRowDto();
|
||||
row.setShopName("店铺A");
|
||||
row.setProductAsinSku(productAsinSku);
|
||||
row.setStatus(status);
|
||||
row.setDone(done);
|
||||
return row;
|
||||
}
|
||||
}
|
||||
@@ -177,6 +177,25 @@ class SimilarAsinImageEmbedderTest {
|
||||
assertNotNull(req.header("Accept-Language"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void amazonImageDownloadCandidatesTrySmallerVariantsWithinRetryBudget() {
|
||||
List<String> candidates = SimilarAsinImageEmbedder.downloadCandidates(
|
||||
"https://m.media-amazon.com/images/I/71AGS2r4JML._AC_SX679_.jpg");
|
||||
|
||||
assertEquals(List.of(
|
||||
"https://m.media-amazon.com/images/I/71AGS2r4JML._AC_SX679_.jpg",
|
||||
"https://m.media-amazon.com/images/I/71AGS2r4JML._AC_SY450_.jpg",
|
||||
"https://m.media-amazon.com/images/I/71AGS2r4JML._AC_SX425_.jpg"), candidates);
|
||||
}
|
||||
|
||||
@Test
|
||||
void downloadCandidatesLeaveNonAmazonAndUnsignedUrlsUntouched() {
|
||||
String coze = "https://lf9-bot-platform-tos-sign.coze.cn/bot-studio-bot-platform/bot_files/1/image/jpeg/2/merged_image.jpg?x-expires=1&x-signature=a";
|
||||
assertEquals(List.of(coze), SimilarAsinImageEmbedder.downloadCandidates(coze));
|
||||
assertEquals(List.of("https://cbu01.alicdn.com/O1CN01x.jpg"),
|
||||
SimilarAsinImageEmbedder.downloadCandidates("https://cbu01.alicdn.com/O1CN01x.jpg"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void buildImageRequestUsesDownloadHeadersForCozeSignedImages() {
|
||||
var req = SimilarAsinImageEmbedder.buildImageRequest(
|
||||
|
||||
Reference in New Issue
Block a user