This commit is contained in:
2026-08-07 20:07:30 +08:00
parent c698290106
commit c4b0972dc9
31 changed files with 1089 additions and 204 deletions
@@ -10,6 +10,7 @@ import org.springframework.http.MediaType;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
@@ -71,4 +72,15 @@ class PlatformMeasurementImageControllerContractTest {
assertThatThrownBy(() -> controller.upload(malformed, 10001L, 88L, file))
.isInstanceOf(BizException.class);
}
@Test
void thumbnailUsesViewPermission() throws Exception {
Method method = PlatformMeasurementImageController.class.getDeclaredMethod("thumbnail",
AuthenticatedUser.class, long.class, long.class, long.class);
assertThat(method.getAnnotation(GetMapping.class).value())
.containsExactly("/{tenantId}/{inboundId}/{fileId}/thumbnail");
assertThat(method.getAnnotation(PreAuthorize.class).value())
.isEqualTo("hasAuthority('platform:firstleg:inbound:measure:view')");
}
}
@@ -20,6 +20,10 @@ import jakarta.annotation.Resource;
import java.nio.file.Path;
import java.math.BigDecimal;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import javax.imageio.ImageIO;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -137,6 +141,38 @@ class MeasurementImageServiceEvidenceTest {
ordered.verify(storage).delete(object.getObjectKey());
}
@Test
void deletesWeightImageThroughTheSameOwnedFileBoundary() {
FileObjectEntity object = measurementEvidence();
object.setBusinessType("INBOUND_WEIGHT_IMAGE");
when(files.selectOne(any())).thenReturn(object);
when(files.updateById(object)).thenReturn(1);
when(files.deleteById(41L)).thenReturn(1);
service.deleteMeasurementEvidence(11L, 21L, 41L, 31L);
verify(storage).delete(object.getObjectKey());
}
@Test
void createsBoundedJpegThumbnail() throws Exception {
FileObjectEntity object = measurementEvidence();
object.setOriginalName("weight.png");
object.setContentType(MediaType.IMAGE_PNG_VALUE);
when(files.selectOne(any())).thenReturn(object);
BufferedImage source = new BufferedImage(1200, 800, BufferedImage.TYPE_INT_RGB);
ByteArrayOutputStream image = new ByteArrayOutputStream();
ImageIO.write(source, "png", image);
when(storage.read(object.getObjectKey())).thenReturn(image.toByteArray());
MeasurementImageService.Download result = service.thumbnail(11L, 21L, 41L);
BufferedImage thumbnail = ImageIO.read(new java.io.ByteArrayInputStream(result.content()));
assertThat(result.contentType()).isEqualTo(MediaType.IMAGE_JPEG_VALUE);
assertThat(thumbnail.getWidth()).isEqualTo(480);
assertThat(thumbnail.getHeight()).isEqualTo(320);
}
@Test
void doesNotDeleteStoredContentWhenLogicalDeleteLosesTheRace() {
FileObjectEntity object = measurementEvidence();