package com.baiyue.lastleg.appointmentplanning; import com.baiyue.common.core.api.ApiResponse; import org.junit.jupiter.api.Test; import org.springframework.web.server.ResponseStatusException; import java.util.List; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; class AppointmentContainerServiceTest { @Test void usesOneBatchedWarehouseReadAndRejectsAnUnrelatedReceivingPoint() { var mapper=mock(AppointmentContainerMapper.class);var warehouse=mock(AppointmentWarehouseClient.class); when(warehouse.catalog("token")).thenReturn(ApiResponse.success(List.of(new AppointmentWarehouseClient.Warehouse(100L,"US","US receiving","OVERSEAS","US"),new AppointmentWarehouseClient.Warehouse(200L,"OTHER","Foreign","OVERSEAS","GB")))); var row=new AppointmentContainer();row.setContainerBookingId("C1");row.setContainerNo("BOX-1");row.setOrderCount(2);row.setCustomerCount(2); when(mapper.count(anyList(),isNull(),isNull())).thenReturn(1L); when(mapper.page(anyList(),isNull(),any(),anyInt(),anyLong())).thenReturn(List.of(row)); when(mapper.warehouses(anyList(),anyList())).thenReturn(List.of(new AppointmentContainerMapper.WarehouseCount("C1","100",2,2))); var service=new AppointmentContainerService(mapper,warehouse,"token"); var page=service.page(1,20,null);assertEquals("US receiving",page.records().get(0).getWarehouses().get(0).warehouseName()); verify(mapper).warehouses(List.of("100"),List.of("C1")); assertEquals("US receiving",service.context("C1","100").warehouseName()); assertThrows(ResponseStatusException.class,()->service.context("C1","200")); row.setIncompleteScope(true);assertFalse(service.context("C1",null).canFollowup()); assertEquals("CONTAINER:C1",AppointmentContainerService.subjectKey("C1",null)); assertEquals("CONTAINER:C1:WAREHOUSE:100",AppointmentContainerService.subjectKey("C1","100")); assertThrows(ResponseStatusException.class,()->AppointmentContainerService.subjectKey("C1:WAREHOUSE:100",null)); } @Test void unavailableDirectoryDoesNotBecomeAnEmptyAuthoritativeResult() { var mapper=mock(AppointmentContainerMapper.class);var warehouse=mock(AppointmentWarehouseClient.class); when(warehouse.catalog(anyString())).thenThrow(new IllegalStateException()); var error=assertThrows(ResponseStatusException.class,()->new AppointmentContainerService(mapper,warehouse,"token").page(1,20,null)); assertEquals(503,error.getStatusCode().value());verifyNoInteractions(mapper); } }