优化
This commit is contained in:
@@ -154,12 +154,63 @@ class ContainerServiceTest {
|
||||
when(repository.updateTransport(11L, "MSCU1234567", "V002", 2, 9L, "admin"))
|
||||
.thenReturn(1);
|
||||
|
||||
service.updateTransport(11L, 9L, "admin",
|
||||
service.updateTransport(11L, 9L, "admin", "transport-1",
|
||||
new TransportUpdateRequest("MSCU1234567", "V002", 2));
|
||||
}
|
||||
|
||||
verify(repository, org.mockito.Mockito.times(1))
|
||||
.updateTransport(11L, "MSCU1234567", "V002", 2, 9L, "admin");
|
||||
ArgumentCaptor<ContainerTransportHistoryEntity> history =
|
||||
ArgumentCaptor.forClass(ContainerTransportHistoryEntity.class);
|
||||
verify(transportHistories).insert(history.capture());
|
||||
assertThat(history.getValue().getBeforeContainerNo()).isEqualTo("MSCU1234567");
|
||||
assertThat(history.getValue().getAfterVoyageNo()).isEqualTo("V002");
|
||||
assertThat(history.getValue().getOperationId()).hasSize(64);
|
||||
assertThat(history.getValue().getRequestHash()).hasSize(64);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("运输字段没有有效变化时不递增版本且不写历史")
|
||||
void ignoresTransportNoOp() {
|
||||
ContainerBookingEntity current = booking("LOADING", 2);
|
||||
current.setVoyageNo("V002");
|
||||
when(repository.find(11L)).thenReturn(current);
|
||||
|
||||
ContainerBookingEntity result = service.updateTransport(11L, 9L, "admin", "transport-noop",
|
||||
new TransportUpdateRequest(" MSCU1234567 ", " V002 ", 2));
|
||||
|
||||
assertThat(result).isSameAs(current);
|
||||
verify(repository, never()).updateTransport(anyLong(), any(), any(), anyInt(), anyLong(), any());
|
||||
verify(transportHistories, never()).insert(any(ContainerTransportHistoryEntity.class));
|
||||
verifyNoInteractions(loadingPickService);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("运输字段精确幂等重放零新增")
|
||||
void replaysTransportWithoutSecondMutationOrHistory() {
|
||||
ContainerBookingEntity current = booking("LOADING", 2);
|
||||
ContainerBookingEntity updated = booking("LOADING", 3);
|
||||
updated.setVoyageNo("V002");
|
||||
when(repository.find(11L)).thenReturn(current, updated, updated);
|
||||
when(repository.updateTransport(11L, "MSCU1234567", "V002", 2, 9L, "admin"))
|
||||
.thenReturn(1);
|
||||
ArgumentCaptor<ContainerTransportHistoryEntity> history =
|
||||
ArgumentCaptor.forClass(ContainerTransportHistoryEntity.class);
|
||||
|
||||
TransportUpdateRequest request = new TransportUpdateRequest("MSCU1234567", "V002", 2);
|
||||
service.updateTransport(11L, 9L, "admin", "transport-replay", request);
|
||||
verify(transportHistories).insert(history.capture());
|
||||
when(transportHistories.selectOperation(eq(11L), eq(9L), anyString()))
|
||||
.thenReturn(history.getValue());
|
||||
|
||||
ContainerBookingEntity replay = service.updateTransport(
|
||||
11L, 9L, "admin", "transport-replay", request);
|
||||
|
||||
assertThat(replay.getVersion()).isEqualTo(3);
|
||||
verify(repository, org.mockito.Mockito.times(1))
|
||||
.updateTransport(11L, "MSCU1234567", "V002", 2, 9L, "admin");
|
||||
verify(transportHistories, org.mockito.Mockito.times(1))
|
||||
.insert(any(ContainerTransportHistoryEntity.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -175,7 +226,7 @@ class ContainerServiceTest {
|
||||
.thenReturn(1);
|
||||
when(smartLoadingRepository.planByBooking(11L)).thenReturn(plan);
|
||||
|
||||
service.updateTransport(11L, 9L, "admin",
|
||||
service.updateTransport(11L, 9L, "admin", "transport-2",
|
||||
new TransportUpdateRequest("MSCU1234567", "V002", 2));
|
||||
|
||||
verify(loadingPickService).beginIfReady(11L, 9L, "admin");
|
||||
@@ -195,7 +246,7 @@ class ContainerServiceTest {
|
||||
when(smartLoadingRepository.planByBooking(11L)).thenReturn(plan);
|
||||
when(loadingPickRepository.taskByPlan(31L)).thenReturn(new LoadingPickTaskEntity());
|
||||
|
||||
service.updateTransport(11L, 9L, "admin",
|
||||
service.updateTransport(11L, 9L, "admin", "transport-3",
|
||||
new TransportUpdateRequest("MSCU7654321", "V002", 2));
|
||||
|
||||
verify(loadingPickService).beginIfReady(11L, 9L, "admin");
|
||||
@@ -211,7 +262,7 @@ class ContainerServiceTest {
|
||||
when(smartLoadingRepository.planByBooking(11L)).thenReturn(plan);
|
||||
when(loadingPickRepository.taskByPlan(31L)).thenReturn(new LoadingPickTaskEntity());
|
||||
|
||||
assertThatThrownBy(() -> service.updateTransport(11L, 9L, "admin",
|
||||
assertThatThrownBy(() -> service.updateTransport(11L, 9L, "admin", "transport-4",
|
||||
new TransportUpdateRequest(null, "V002", 2)))
|
||||
.isInstanceOf(BizException.class)
|
||||
.hasMessageContaining("不能清空真实集装箱号");
|
||||
@@ -225,7 +276,7 @@ class ContainerServiceTest {
|
||||
void rejectsConfirmedUpdate() {
|
||||
when(repository.find(11L)).thenReturn(booking("COMPLETED", 2));
|
||||
|
||||
assertThatThrownBy(() -> service.updateTransport(11L, 9L, "admin",
|
||||
assertThatThrownBy(() -> service.updateTransport(11L, 9L, "admin", "transport-5",
|
||||
new TransportUpdateRequest("MSCU1234567", "V002", 2)))
|
||||
.isInstanceOf(BizException.class)
|
||||
.hasMessageContaining("全部只读");
|
||||
|
||||
@@ -42,6 +42,7 @@ import static org.mockito.ArgumentMatchers.isNull;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@DisplayName("预装与装柜清单状态服务")
|
||||
@@ -102,6 +103,25 @@ class LoadingListServiceTest {
|
||||
eq("operator"), eq("补录箱号"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotWritePlanOrHistoryWhenTransportFieldsAreUnchanged() {
|
||||
AggregateRow before = row("LOADING", 3);
|
||||
before.setContainerNo("CSLU1234567");
|
||||
before.setVoyageNo("023E");
|
||||
when(repository.aggregate(10L)).thenReturn(before);
|
||||
when(repository.preloadDetail(before)).thenReturn(
|
||||
new com.baiyue.firstleg.dto.LoadingListDtos.PreloadDetail(null, List.of(), List.of()));
|
||||
|
||||
service.updateTransport(10L, 100L, 9L, "operator", "noop-key",
|
||||
new TransportUpdateRequest(" CSLU1234567 ", " 023E ", 3, "重复保存"));
|
||||
|
||||
verify(repository, never()).updateTransport(anyLong(), org.mockito.ArgumentMatchers.anyInt(),
|
||||
any(), any(), anyLong(), any());
|
||||
verify(repository, never()).appendHistory(anyLong(), anyString(), anyString(), any(), any(),
|
||||
any(), any(), anyLong(), any(), any());
|
||||
verifyNoInteractions(loadingPickService);
|
||||
}
|
||||
|
||||
@Test
|
||||
void pushedEditingPreloadCanReceiveContainerNumber() {
|
||||
AggregateRow before = row("EDITING", 3);
|
||||
|
||||
@@ -503,6 +503,26 @@ class SmartLoadingServiceTest {
|
||||
verify(repository).updateWarehouseRemark(1L, 8L, 2, 0, "待核对外箱", 7L, "u");
|
||||
}
|
||||
|
||||
@Test
|
||||
void unchangedWarehouseRemarkDoesNotTouchPlanItemOrHistory() {
|
||||
LoadingPlanEntity plan = plan("LOADING", 2);
|
||||
LoadingPlanItemEntity line = item(8, 9, 20, 1);
|
||||
line.setWarehouseRemark("待核对外箱");
|
||||
when(repository.plan(1L)).thenReturn(plan);
|
||||
when(repository.item(1L, 8L)).thenReturn(line);
|
||||
when(repository.booking(99L)).thenReturn(booking());
|
||||
when(repository.items(1L)).thenReturn(List.of(line));
|
||||
|
||||
Plan result = service.updateWarehouseRemark(1L, 8L,
|
||||
new WarehouseRemarkRequest(" 待核对外箱 ", 2, 0, "warehouse-noop"), 7L, "u");
|
||||
|
||||
assertThat(result.version()).isEqualTo(2);
|
||||
verify(repository, never()).touch(anyLong(), anyInt(), anyLong(), anyString());
|
||||
verify(repository, never()).updateWarehouseRemark(anyLong(), anyLong(), anyInt(), anyInt(),
|
||||
any(), anyLong(), anyString());
|
||||
verify(repository, never()).insert(any(LoadingPlanHistoryEntity.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void warehouseRemarkConflictProducesNoHistory() {
|
||||
LoadingPlanEntity plan = plan("LOADING", 2);
|
||||
|
||||
Reference in New Issue
Block a user