优化
This commit is contained in:
+60
@@ -0,0 +1,60 @@
|
||||
package com.baiyue.lastleg.inboundplan.pda.gateway;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.client.MockRestServiceServer;
|
||||
import org.springframework.web.client.RestClient;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.springframework.test.web.client.match.MockRestRequestMatchers.header;
|
||||
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
|
||||
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
|
||||
|
||||
class HttpDomesticLoadingEvidenceGatewayTest {
|
||||
private HttpDomesticLoadingEvidenceGateway gateway;
|
||||
private MockRestServiceServer server;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
RestClient.Builder builder = RestClient.builder();
|
||||
server = MockRestServiceServer.bindTo(builder).build();
|
||||
gateway = new HttpDomesticLoadingEvidenceGateway();
|
||||
ReflectionTestUtils.setField(gateway, "client", builder.baseUrl("http://domestic-file").build());
|
||||
ReflectionTestUtils.setField(gateway, "internalToken", "internal-token");
|
||||
}
|
||||
|
||||
@Test
|
||||
void downloadsImageFromDomesticFileService() {
|
||||
server.expect(requestTo("http://domestic-file/internal/file/v1/loading-evidence/8/9/content"))
|
||||
.andExpect(header("X-Internal-Service-Token", "internal-token"))
|
||||
.andRespond(withSuccess("photo-bytes".getBytes(), MediaType.IMAGE_JPEG)
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=seal.jpg"));
|
||||
|
||||
DomesticLoadingEvidenceGateway.DownloadedFile result = gateway.download(8L, 9L);
|
||||
|
||||
assertThat(result.content()).containsExactly("photo-bytes".getBytes());
|
||||
assertThat(result.fileName()).isEqualTo("seal.jpg");
|
||||
assertThat(result.contentType()).isEqualTo(MediaType.IMAGE_JPEG_VALUE);
|
||||
server.verify();
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsBusinessErrorEnvelopeReturnedWithHttp200() {
|
||||
server.expect(requestTo("http://domestic-file/internal/file/v1/loading-evidence/8/9/content"))
|
||||
.andRespond(withSuccess("{\"code\":\"S0500\",\"message\":\"Internal server error\"}",
|
||||
MediaType.APPLICATION_JSON));
|
||||
|
||||
assertThatThrownBy(() -> gateway.download(8L, 9L))
|
||||
.isInstanceOfSatisfying(ResponseStatusException.class, error -> {
|
||||
assertThat(error.getStatusCode()).isEqualTo(HttpStatus.SERVICE_UNAVAILABLE);
|
||||
assertThat(error.getReason()).isEqualTo("国内装柜照片返回内容无效");
|
||||
});
|
||||
server.verify();
|
||||
}
|
||||
}
|
||||
+36
-2
@@ -215,7 +215,7 @@ class InboundPlanServiceTest {
|
||||
when(orderMapper.lockOrder("100", 2L)).thenReturn(List.of(source));
|
||||
when(orderMapper.findOrderType("100", 2L)).thenReturn("ONE_CLICK_DROPSHIP");
|
||||
when(dropshipOrders.palletSnapshots("100", 2L)).thenReturn(List.of(
|
||||
new DropshipPalletSnapshot("DP-260914-0001", 10L, List.of())));
|
||||
new DropshipPalletSnapshot("DP-260914-0001", 33L, List.of())));
|
||||
|
||||
ResponseStatusException error = assertThrows(ResponseStatusException.class, () -> service.convertManual(
|
||||
new ManualInboundPlanRequest("100", 2L, 0,
|
||||
@@ -233,7 +233,7 @@ class InboundPlanServiceTest {
|
||||
when(orderMapper.lockOrder("100", 2L)).thenReturn(List.of(source));
|
||||
when(orderMapper.findOrderType("100", 2L)).thenReturn("ONE_CLICK_DROPSHIP");
|
||||
when(dropshipOrders.palletSnapshots("100", 2L)).thenReturn(List.of(
|
||||
new DropshipPalletSnapshot("DP-260914-0001", 10L, List.of())));
|
||||
new DropshipPalletSnapshot("DP-260914-0001", 33L, List.of())));
|
||||
when(orderMapper.markPlannedManual(eq("100"), eq(2L), any(), eq(1), eq(false), eq(0), any()))
|
||||
.thenReturn(1);
|
||||
|
||||
@@ -246,6 +246,40 @@ class InboundPlanServiceTest {
|
||||
verify(palletMapper).insert(any(InboundPlanPallet.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void oneClickDropshipManualPlanPreservesUnevenFrozenPalletPackageCounts() {
|
||||
SourceOrderSnapshot source = new SourceOrderSnapshot(2L, "100", "MSCU6639870", "RK-2",
|
||||
"PENDING_ASSIGNMENT", null, new BigDecimal("3.3651"), 20, 3,
|
||||
"193000000000200003", "US-LAX-01", "洛杉矶仓", null,
|
||||
"193000000000200003", null, "洛杉矶仓", 1, 0, false, 0);
|
||||
when(orderMapper.lockOrder("100", 2L)).thenReturn(List.of(source));
|
||||
when(orderMapper.findOrderType("100", 2L)).thenReturn("ONE_CLICK_DROPSHIP");
|
||||
when(dropshipOrders.palletSnapshots("100", 2L)).thenReturn(List.of(
|
||||
new DropshipPalletSnapshot("DP-260915-0092", 10L, List.of()),
|
||||
new DropshipPalletSnapshot("DP-260915-0093", 3L, List.of()),
|
||||
new DropshipPalletSnapshot("DP-260915-0094", 7L, List.of())));
|
||||
when(orderMapper.markPlannedManual(eq("100"), eq(2L), any(), eq(3), eq(false), eq(0), any()))
|
||||
.thenReturn(1);
|
||||
|
||||
var result = service.convertManual(new ManualInboundPlanRequest("100", 2L, 0,
|
||||
3, "WOOD", false, false, false, null), "dropship-uneven-pallet-counts", "900");
|
||||
|
||||
ArgumentCaptor<InboundPlanPallet> pallets = ArgumentCaptor.forClass(InboundPlanPallet.class);
|
||||
ArgumentCaptor<InboundPlanPalletAllocation> allocations =
|
||||
ArgumentCaptor.forClass(InboundPlanPalletAllocation.class);
|
||||
verify(palletMapper, times(3)).insert(pallets.capture());
|
||||
verify(allocationMapper, times(3)).insert(allocations.capture());
|
||||
assertEquals(List.of("DP-260915-0092", "DP-260915-0093", "DP-260915-0094"),
|
||||
pallets.getAllValues().stream().map(InboundPlanPallet::getSourcePalletNo).toList());
|
||||
assertEquals(List.of("WOOD", "WOOD", "WOOD"),
|
||||
pallets.getAllValues().stream().map(InboundPlanPallet::getPalletType).toList());
|
||||
assertEquals(List.of(10, 3, 7), allocations.getAllValues().stream()
|
||||
.map(InboundPlanPalletAllocation::getPlannedPackageCount).toList());
|
||||
assertEquals(new BigDecimal("3.3651"), allocations.getAllValues().stream()
|
||||
.map(InboundPlanPalletAllocation::getAllocatedVolumeCbm).reduce(BigDecimal.ZERO, BigDecimal::add));
|
||||
assertEquals(3, result.palletCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
void containerConversionBindsRealWarehousePalletsBackToSignedManualPlanBeforeReceiving() {
|
||||
InboundPlan plan = existingPlan("100", 2L, "IP-MANUAL");
|
||||
|
||||
+3
-1
@@ -38,6 +38,7 @@ class PdaOperationsOpenApiContractTest {
|
||||
assertNoServerOwnedFields(DispatchPdaRequests.CompletePicking.class);
|
||||
assertNoServerOwnedFields(DispatchPdaRequests.Depart.class);
|
||||
assertNoServerOwnedFields(DeliveryRequests.PdaPick.class);
|
||||
assertNoServerOwnedFields(DeliveryRequests.PdaPalletPick.class);
|
||||
assertNoServerOwnedFields(DeliveryRequests.PdaComplete.class);
|
||||
}
|
||||
|
||||
@@ -77,9 +78,10 @@ class PdaOperationsOpenApiContractTest {
|
||||
"/api/pda/v1/last-leg/outbound-tasks/resolve/{businessNo}:",
|
||||
"/api/pda/v1/last-leg/outbound-tasks/{taskNo}:",
|
||||
"/api/pda/v1/last-leg/outbound-tasks/{taskNo}/pick:",
|
||||
"/api/pda/v1/last-leg/outbound-tasks/{taskNo}/pallets/{palletNo}/pick:",
|
||||
"/api/pda/v1/last-leg/outbound-tasks/{taskNo}/complete:");
|
||||
for (String path : paths) assertTrue(yaml.contains(path), path);
|
||||
assertEquals(33, paths.size());
|
||||
assertEquals(34, paths.size());
|
||||
assertTrue(yaml.contains("enum: [LOCATION, PALLET]"));
|
||||
assertTrue(yaml.contains("enum: [APPROVE, REWORK]"));
|
||||
assertTrue(yaml.contains("Warehouse 权威实物托盘码"));
|
||||
|
||||
+3
@@ -49,6 +49,8 @@ class PdaOutboundDispatchContractTest {
|
||||
.noneMatch(component -> "warehouseId".equals(component.getName()) || "customerId".equals(component.getName())));
|
||||
assertTrue(Arrays.stream(DeliveryRequests.PdaPick.class.getRecordComponents())
|
||||
.noneMatch(component -> "warehouseId".equals(component.getName()) || "customerId".equals(component.getName())));
|
||||
assertTrue(Arrays.stream(DeliveryRequests.PdaPalletPick.class.getRecordComponents())
|
||||
.noneMatch(component -> "warehouseId".equals(component.getName()) || "customerId".equals(component.getName())));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -86,6 +88,7 @@ class PdaOutboundDispatchContractTest {
|
||||
assertTrue(yaml.contains("/api/pda/v1/last-leg/dispatches:"));
|
||||
assertTrue(yaml.contains("/api/pda/v1/last-leg/dispatches/{dispatchNo}/depart:"));
|
||||
assertTrue(yaml.contains("/api/pda/v1/last-leg/outbound-tasks/{taskNo}/complete:"));
|
||||
assertTrue(yaml.contains("/api/pda/v1/last-leg/outbound-tasks/{taskNo}/pallets/{palletNo}/pick:"));
|
||||
assertFalse(yaml.contains("name: customerId"));
|
||||
assertFalse(yaml.contains("name: warehouseId"));
|
||||
assertFalse(yaml.contains("/api/pda/v1/last-leg/delivery"));
|
||||
|
||||
Reference in New Issue
Block a user