This commit is contained in:
2026-08-11 09:25:41 +08:00
parent 66b3a0cc9b
commit 540a6f5d88
18 changed files with 757 additions and 90 deletions
@@ -85,7 +85,7 @@ class LoadingDeliveryServiceTest {
when(repository.claimOperation(anyLong(), anyLong(), anyLong(), anyString(), anyString(), anyString())).thenReturn(true);
when(repository.findInbound(10, 20)).thenReturn(new Snapshot(20L, 10L, "INBOUNDED", 3));
when(repository.completionTarget(10, 20)).thenReturn(new CompletionTarget(
20L, 21L, 20L, "INBOUNDED", 3, "LOADING", 1));
20L, null, 20L, "LOADING", 3, "LOADING", 3));
LoadingPickItemMapper.InboundProgress progress = mock(LoadingPickItemMapper.InboundProgress.class);
when(progress.getExpectedCount()).thenReturn(5);
when(progress.getPickedCount()).thenReturn(5);
@@ -114,10 +114,18 @@ class LoadingDeliveryServiceTest {
verify(repository).completeLoadedChild(10, 20, 7, 3);
verify(repository).aggregateRootLoaded(10, 20, 7);
verify(histories).insert(argThat((InboundStatusHistoryEntity history) ->
Long.valueOf(21L).equals(history.getInboundId())));
Long.valueOf(20L).equals(history.getInboundId())));
verify(repository, never()).completeLoading(anyLong(), anyLong(), anyLong(), anyInt());
}
@Test
void keepsHistoricalLoadedChildAsCompletionTarget() {
CompletionTarget historical = new CompletionTarget(
20L, 21L, 20L, "INBOUNDED", 3, "LOADING", 1);
assertThat(historical.completionInboundId()).isEqualTo(21L);
}
@Test
void rejectsCompletionWhenEvidenceIsIncomplete() {
when(repository.claimOperation(anyLong(), anyLong(), anyLong(), anyString(), anyString(), anyString())).thenReturn(true);
@@ -62,11 +62,9 @@ class PdaPickSettlementServiceTest {
service.settle(1L, 9L, "operator");
verify(splits).cloneChildWithPurpose(eq(10001L), eq(31L), eq(31L), anyLong(),
eq(1001L), eq("ORDER-LOADED"), eq("IN-001-1"), eq(8),
eq(1), eq("LOADED"), eq(9L), eq("operator"));
verify(splits).cloneChildWithPurpose(eq(10001L), eq(31L), eq(31L), anyLong(),
eq(1002L), eq("ORDER-REMAINDER"), eq("IN-001-2"), eq(12),
eq(2), eq("REMAINDER"), eq(9L), eq("operator"));
eq(1002L), eq("ORDER-REMAINDER"), eq("IN-001-1"), eq(12),
eq(1), eq("REMAINDER"), eq(9L), eq("operator"));
verify(splits).markSourceLoaded(10001L, 31L, 8, 9L, 3);
verify(allocations).consume(10001L, 31L, 1L, 8);
verify(warehouse).settle(eq("internal-token"), org.mockito.ArgumentMatchers.argThat(request ->
request.warehouseId() == 701L && request.sourceBusinessId() == 31L
@@ -115,7 +113,7 @@ class PdaPickSettlementServiceTest {
}
@Test
void fullyPickedInboundCreatesLoadedChildAndReleasesAllResources() {
void fullyPickedInboundKeepsSourceAsLoadedSliceAndReleasesAllResources() {
LoadingPickItemEntity item = item(11L, 21L, 31L, 41L, 20, 20, "PICKED");
resolved(List.of(item));
when(splits.lockParent(31L)).thenReturn(parent(20));
@@ -132,9 +130,9 @@ class PdaPickSettlementServiceTest {
verify(allocations).consume(10001L, 31L, 1L, 10);
verify(allocations).consume(10001L, 31L, 2L, 10);
verify(splits).cloneChildWithPurpose(eq(10001L), eq(31L), eq(31L), anyLong(),
eq(1001L), eq("ORDER-LOADED"), anyString(), eq(20),
anyInt(), eq("LOADED"), eq(9L), eq("operator"));
verify(splits, never()).cloneChildWithPurpose(anyLong(), anyLong(), anyLong(), anyLong(),
anyLong(), anyString(), anyString(), anyInt(), anyInt(), anyString(), anyLong(), anyString());
verify(splits).markSourceLoaded(10001L, 31L, 20, 9L, 3);
verify(warehouse).settle(eq("internal-token"), org.mockito.ArgumentMatchers.argThat(request ->
request.targetBusinessId() == 0L && request.targetPackageCount() == 0
&& request.releasedReservationIds().equals(List.of(91L, 92L))
@@ -168,8 +166,9 @@ class PdaPickSettlementServiceTest {
service.settle(1L, 9L, "operator");
verify(splits).cloneChildWithPurpose(eq(10001L), eq(31L), eq(31L), anyLong(),
eq(1001L), eq("ORDER-LOADED"), anyString(), eq(20), anyInt(), eq("LOADED"), eq(9L), eq("operator"));
verify(splits).markSourceLoaded(10001L, 31L, 20, 9L, 3);
verify(splits, never()).cloneChildWithPurpose(anyLong(), anyLong(), anyLong(), anyLong(),
anyLong(), anyString(), anyString(), anyInt(), anyInt(), anyString(), anyLong(), anyString());
}
@Test
@@ -188,7 +187,7 @@ class PdaPickSettlementServiceTest {
service.settle(1L, 9L, "operator");
verify(splits).markRootSplit(10001L, 31L, 9L, 3);
verify(splits).markSourceLoaded(10001L, 31L, 20, 9L, 3);
}
@Test
@@ -240,9 +239,8 @@ class PdaPickSettlementServiceTest {
verify(orderSplits, times(2)).split(eq("internal-token"), eq(9L),
org.mockito.ArgumentMatchers.argThat(request -> request.idempotencyKey().equals("pda-task-1")));
verify(splits).cloneChildWithPurpose(eq(10001L), eq(31L), eq(31L), anyLong(),
eq(1001L), eq("ORDER-LOADED"), anyString(), eq(20), anyInt(), eq("LOADED"),
eq(9L), eq("operator"));
verify(splits, never()).cloneChildWithPurpose(anyLong(), anyLong(), anyLong(), anyLong(),
anyLong(), anyString(), anyString(), anyInt(), anyInt(), anyString(), anyLong(), anyString());
}
private void resolved(List<LoadingPickItemEntity> items) {
@@ -261,10 +259,10 @@ class PdaPickSettlementServiceTest {
when(orderSplits.split(eq("internal-token"), eq(9L), any())).thenAnswer(invocation -> {
OrderFulfillmentSplitClient.CreateRequest request = invocation.getArgument(2);
OrderFulfillmentSplitClient.Child loaded = new OrderFulfillmentSplitClient.Child(
1001L, "ORDER-LOADED", 1, "LOADED", request.loadedPackageCount(),
request.sourceOrderId(), "ORDER-001", null, "LOADED", request.loadedPackageCount(),
request.sourceOrderId(), request.loadingPlanId(), request.containerBookingId());
OrderFulfillmentSplitClient.Child remainder = request.remainingPackageCount() == 0 ? null
: new OrderFulfillmentSplitClient.Child(1002L, "ORDER-REMAINDER", 2, "REMAINDER",
: new OrderFulfillmentSplitClient.Child(1002L, "ORDER-REMAINDER", 1, "REMAINDER",
request.remainingPackageCount(), request.sourceOrderId(), request.loadingPlanId(),
request.containerBookingId());
return ApiResponse.success(new OrderFulfillmentSplitClient.Response(
@@ -279,15 +277,18 @@ class PdaPickSettlementServiceTest {
when(splits.cloneChildWithPurpose(eq(10001L), eq(31L), eq(31L), anyLong(), anyLong(), anyString(), anyString(), anyInt(),
anyInt(), anyString(), eq(9L), eq("operator"))).thenReturn(1);
when(splits.insertBatchWithChildren(anyLong(), eq(10001L), eq(31L), anyString(), eq(31L), anyString(), eq(3),
anyInt(), anyLong(), any(), anyInt(), anyInt(), eq(701L), eq(801L), anyString(), eq(9L), eq("operator"))).thenReturn(1);
anyInt(), org.mockito.ArgumentMatchers.isNull(), any(), anyInt(), anyInt(), eq(701L), eq(801L),
anyString(), eq(9L), eq("operator"))).thenReturn(1);
when(splits.cloneMeasurement(eq(10001L), eq(31L), eq(61L), anyLong(), anyLong(), anyLong(),
anyInt(), eq(9L))).thenReturn(1);
when(splits.insertSplitItem(anyLong(), eq(10001L), anyLong(), eq(31L), anyLong(), anyInt(),
eq(41L), eq(61L), eq(51L), anyInt())).thenReturn(1);
when(splits.cloneMeasurementItem(eq(10001L), eq(61L), eq(51L), anyLong(), anyLong(), anyLong(),
anyInt(), anyInt())).thenReturn(1);
when(splits.updateMeasurementItemForLoaded(eq(10001L), eq(51L), anyInt())).thenReturn(1);
when(splits.updateMeasurementForLoaded(eq(10001L), eq(31L), eq(61L), anyInt())).thenReturn(1);
when(splits.normalizeChildMetrics(eq(10001L), anyLong(), anyLong())).thenReturn(1);
when(splits.markRootSplit(10001L, 31L, 9L, 3)).thenReturn(1);
when(splits.markSourceLoaded(eq(10001L), eq(31L), anyInt(), eq(9L), eq(3))).thenReturn(1);
when(splits.applyBatch(eq(10001L), anyLong())).thenReturn(1);
when(splits.insertHistory(anyLong(), eq(10001L), anyLong(), anyString(), anyString(), eq(9L),
eq("operator"), anyString())).thenReturn(1);