This commit is contained in:
2026-08-15 10:27:15 +08:00
parent c6d7fb0d84
commit 9e7cc55eab
22 changed files with 336 additions and 34 deletions
@@ -14,6 +14,7 @@ import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import jakarta.annotation.Resource;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import java.math.BigDecimal;
@@ -25,6 +26,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
@@ -117,6 +119,37 @@ class LocationResourceServiceTest {
.containsExactly("inbound-1-p1", "inbound-1-p2");
}
@Test
void allowsReusablePalletMasterInMultipleReservationTargets() {
when(repository.findWarehouse(10001L, 88L)).thenReturn(warehouse());
when(repository.lockAvailable(10001L, 88L, 2))
.thenReturn(List.of(location(9L, "A1"), location(10L, "A2")));
when(repository.changeStatus(10001L, 88L, 9L, "AVAILABLE", "RESERVED", 0, 7L)).thenReturn(1);
when(repository.changeStatus(10001L, 88L, 10L, "AVAILABLE", "RESERVED", 0, 7L)).thenReturn(1);
var command = new ReserveCommand(10001L, 88L, "FIRSTLEG", 301L, "RK001", 7L,
LocalDateTime.now().plusMinutes(30), List.of(
new ReservationTarget(501L, "P1", "same-pallet-1"),
new ReservationTarget(501L, "P1", "same-pallet-2")));
assertThat(service.reserveAvailable(command)).hasSize(2);
verify(repository, times(2)).insertReservation(any());
}
@Test
void reservationConstraintFailureDoesNotDescribePalletAsAResource() {
when(repository.findWarehouse(10001L, 88L)).thenReturn(warehouse());
when(repository.lockAvailable(10001L, 88L, 2))
.thenReturn(List.of(location(9L, "A1"), location(10L, "A2")));
when(repository.changeStatus(10001L, 88L, 9L, "AVAILABLE", "RESERVED", 0, 7L)).thenReturn(1);
doThrow(new DataIntegrityViolationException("duplicate location reservation"))
.when(repository).insertReservation(any());
assertThatThrownBy(() -> service.reserveAvailable(reserveCommand()))
.hasMessageContaining("库位预占幂等键重复或库位已存在活动预占")
.hasMessageNotContaining("托盘");
}
@Test
void shouldHandleCase04() {
when(repository.findWarehouse(10001L, 88L)).thenReturn(warehouse());