优化
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("全部只读");
|
||||
|
||||
Reference in New Issue
Block a user