打印箱唛修改 尾程垮桥事件提交

This commit is contained in:
2026-08-13 17:13:58 +08:00
parent b004edaf9e
commit c43d581ba6
59 changed files with 1609 additions and 96 deletions
@@ -8,6 +8,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.springframework.cloud.client.circuitbreaker.NoFallbackAvailableException;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
@@ -79,6 +80,44 @@ class InboundCartonLabelPrintServiceTest {
.isEqualTo(ResultCode.VALIDATION_FAILED);
}
@Test
void convertsCircuitBreakerFailureToServiceUnavailable() {
when(labels.list(10001L, 70001L, null)).thenReturn(batch());
when(print.generateInboundMarks(org.mockito.ArgumentMatchers.anyString(),
org.mockito.ArgumentMatchers.isNull(), org.mockito.ArgumentMatchers.any()))
.thenThrow(new NoFallbackAvailableException("print unavailable",
new IllegalStateException("down")));
assertThatThrownBy(() -> service.generate(10001L, 70001L, null, null))
.isInstanceOf(BizException.class)
.hasMessage("打印服务暂不可用,请稍后重试")
.extracting(value -> ((BizException) value).getResultCode())
.isEqualTo(ResultCode.SERVICE_UNAVAILABLE);
}
@Test
void batchCombinesSuccessfulOrdersAndReportsIsolatedFailures() {
when(labels.requireInboundIdByOrder(10001L, 60001L)).thenReturn(70001L);
when(labels.requireInboundIdByOrder(10001L, 60002L))
.thenThrow(new BizException(ResultCode.NOT_FOUND, "missing"));
when(labels.list(10001L, 70001L, null)).thenReturn(batch());
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_PDF);
when(print.generateInboundMarks(org.mockito.ArgumentMatchers.anyString(),
org.mockito.ArgumentMatchers.eq("request-batch"), org.mockito.ArgumentMatchers.any()))
.thenReturn(new ResponseEntity<>(new byte[] {1, 2, 3}, headers,
org.springframework.http.HttpStatus.OK));
ResponseEntity<byte[]> response = service.generateByOrders(
10001L, List.of(60001L, 60002L), "request-batch");
assertThat(response.getHeaders().getFirst("X-Carton-Label-Order-Count")).isEqualTo("2");
assertThat(response.getHeaders().getFirst("X-Carton-Label-Failure-Count")).isEqualTo("1");
assertThat(response.getHeaders().getFirst("X-Carton-Label-Failures")).contains("60002:A0404");
verify(print).generateInboundMarks(org.mockito.ArgumentMatchers.anyString(),
org.mockito.ArgumentMatchers.eq("request-batch"), org.mockito.ArgumentMatchers.any());
}
private InboundCartonLabels.Batch batch() {
InboundCartonLabels.Label label = new InboundCartonLabels.Label(
1L, 2L, 1, "音箱", 19, "PCHK2608040174#19-1", 19, 1,