提交
This commit is contained in:
+21
@@ -10,6 +10,7 @@ import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
class FleetPickupMapperTest {
|
||||
JdbcTemplate db;FleetPickupMapper mapper;
|
||||
/** 每个用例建立独立数据库,通过真实 Mapper 验证取货只读来源投影。 */
|
||||
@BeforeEach void setup() throws Exception {
|
||||
var ds=new JdbcDataSource();ds.setURL("jdbc:h2:mem:pickup_"+System.nanoTime()+";MODE=MySQL;DB_CLOSE_DELAY=-1");db=new JdbcTemplate(ds);
|
||||
db.execute("CREATE TABLE ll_warehouse_transfer_order(id BIGINT PRIMARY KEY,customer_id VARCHAR(64),transfer_no VARCHAR(64),inbound_code VARCHAR(64),lastleg_order_no VARCHAR(64),operating_warehouse_id VARCHAR(64),delivery_address VARCHAR(500),pickup_contact_name VARCHAR(100),pickup_contact_phone VARCHAR(40),package_count INT,estimated_arrival_at TIMESTAMP,status VARCHAR(32),delivery_method VARCHAR(40),created_at TIMESTAMP)");
|
||||
@@ -23,6 +24,26 @@ class FleetPickupMapperTest {
|
||||
var factory=new MybatisSqlSessionFactoryBean();factory.setDataSource(ds);factory.setConfiguration(config);
|
||||
mapper=new SqlSessionTemplate(factory.getObject()).getMapper(FleetPickupMapper.class);
|
||||
}
|
||||
/** 释放隔离库,避免完整回归累积 H2 内存。 */
|
||||
@AfterEach void close() { if(db!=null)db.execute("SHUTDOWN"); }
|
||||
/** 显式列投影保留车队全部资格和展示字段,不依赖转运实体映射。 */
|
||||
@Test void sourceProjectionPreservesPickupFactsAndCustomerScope() {
|
||||
var source=mapper.lockSource("C1","WT-1");
|
||||
assertThat(source.getId()).isEqualTo(1L);
|
||||
assertThat(source.getCustomerId()).isEqualTo("C1");
|
||||
assertThat(source.getTransferNo()).isEqualTo("WT-1");
|
||||
assertThat(source.getInboundCode()).isEqualTo("WT-1");
|
||||
assertThat(source.getLastlegOrderNo()).isEqualTo("LL-1");
|
||||
assertThat(source.getOperatingWarehouseId()).isEqualTo("100");
|
||||
assertThat(source.getDeliveryAddress()).isEqualTo("Ontario Test Address");
|
||||
assertThat(source.getPickupContactName()).isEqualTo("Contact");
|
||||
assertThat(source.getPickupContactPhone()).isEqualTo("0000000000");
|
||||
assertThat(source.getPackageCount()).isEqualTo(5);
|
||||
assertThat(source.getStatus()).isEqualTo("WAIT_PDA_RECEIVING");
|
||||
assertThat(source.getDeliveryMethod()).isEqualTo("WAREHOUSE_PICKUP");
|
||||
assertThat(mapper.lockSource("C2","WT-1")).isNull();
|
||||
assertThat(mapper.source("C1","WT-1").getId()).isEqualTo(source.getId());
|
||||
}
|
||||
@Test void candidateQualificationPaginationAndCustomerScopeUseActualSql() {
|
||||
assertThat(mapper.countCandidates(null)).isEqualTo(2);
|
||||
assertThat(mapper.candidates(null,1,0)).extracting(FleetPickupModels.Candidate::transferNo).containsExactly("WT-1");
|
||||
|
||||
+13
-11
@@ -4,7 +4,6 @@ import com.baiyue.lastleg.fleet.driver.*;
|
||||
import com.baiyue.lastleg.fleet.reporting.*;
|
||||
import com.baiyue.lastleg.fleet.trip.*;
|
||||
import com.baiyue.lastleg.masterdata.vehicle.application.port.out.VehicleRepository;
|
||||
import com.baiyue.lastleg.transfer.entity.WarehouseTransferOrder;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
@@ -16,7 +15,7 @@ import static org.mockito.ArgumentMatchers.*;
|
||||
|
||||
class FleetPickupServiceTest {
|
||||
FleetPickupRepository repository;FleetTripService trips;FleetPickupService service;
|
||||
TripOperationsEvidenceGateway files;FleetTripEntity trip;WarehouseTransferOrder source;FleetPickupTask task;
|
||||
TripOperationsEvidenceGateway files;FleetTripEntity trip;FleetPickupSource source;FleetPickupTask task;
|
||||
final Map<String,String> commands=new HashMap<>();
|
||||
@BeforeEach void setup() {
|
||||
repository=mock(FleetPickupRepository.class);trips=mock(FleetTripService.class);files=mock(TripOperationsEvidenceGateway.class);
|
||||
@@ -30,15 +29,18 @@ class FleetPickupServiceTest {
|
||||
doAnswer(c->{commands.put(c.getArgument(1),c.getArgument(2));return null;}).when(repository).command(anyString(),anyString(),anyString());
|
||||
doAnswer(c->{trip.setRecordVersion(trip.getRecordVersion()+1);return null;}).when(trips).recordExecution(any(),anyLong(),anyString(),anyString(),anyString());
|
||||
}
|
||||
@Test void pickupMustArriveBeforePdaAndWrongWarehouseCannotRead() {
|
||||
when(repository.pdaSource("100","WT-1")).thenReturn(source);
|
||||
assertThatThrownBy(()->service.requireMeasuringSource("100","WT-1")).hasMessageContaining("先完成车辆取货送仓");
|
||||
task.setStatus("ARRIVED");assertThat(service.requireMeasuringSource("100","WT-1")).isSameAs(source);
|
||||
assertThatThrownBy(()->service.requireMeasuringSource("200","WT-1")).isInstanceOf(ResponseStatusException.class);
|
||||
/** 原单所属域锁定来源后,车队仅以该来源核对真实送仓事实。 */
|
||||
@Test void pickupMustArriveBeforePda() {
|
||||
assertThatThrownBy(()->service.requireArrived(1L,"WAREHOUSE_PICKUP","WT-1","WT-1")).hasMessageContaining("先完成车辆取货送仓");
|
||||
task.setStatus("ARRIVED");
|
||||
assertThatCode(()->service.requireArrived(1L,"WAREHOUSE_PICKUP","WT-1","WT-1")).doesNotThrowAnyException();
|
||||
assertThatThrownBy(()->service.requireArrived(2L,"WAREHOUSE_PICKUP","WT-2","WT-2")).hasMessageContaining("先完成车辆取货送仓");
|
||||
}
|
||||
/** 客户自送和已有库存转运沿本域原测量资格,不要求不存在的取货任务。 */
|
||||
@Test void selfDeliveryKeepsOriginalMeasurementPath() {
|
||||
source.setDeliveryMethod("CUSTOMER_DELIVERY");when(repository.pdaSource("100","WT-1")).thenReturn(source);
|
||||
assertThat(service.requireMeasuringSource("100","WT-1")).isSameAs(source);verify(repository,never()).task(anyLong());
|
||||
assertThatCode(()->service.requireArrived(1L,"CUSTOMER_DELIVERY","WT-1","WT-1")).doesNotThrowAnyException();
|
||||
assertThatCode(()->service.requireArrived(1L,"WAREHOUSE_PICKUP","WT-1","ORIGINAL-INBOUND")).doesNotThrowAnyException();
|
||||
verify(repository,never()).task(anyLong());
|
||||
}
|
||||
@Test void cannotScheduleSelfDeliveryOrAnotherWarehouseOrDuplicateSource() {
|
||||
var plan=new FleetPickupModels.Create(List.of(new FleetPickupModels.Source("C1","WT-1")),Instant.now(),Instant.now().plusSeconds(7200),null,"create-key-1");
|
||||
@@ -98,8 +100,8 @@ class FleetPickupServiceTest {
|
||||
verify(trips,never()).recordExecution(any(),anyLong(),anyString(),anyString(),anyString());
|
||||
}
|
||||
/** 构造有业务含义的原转运单,箱唛与库存由原链路持有。 */
|
||||
static WarehouseTransferOrder source(long id,String customer,String number,String warehouse) {
|
||||
var row=new WarehouseTransferOrder();row.setId(id);row.setCustomerId(customer);row.setTransferNo(number);row.setInboundCode(number);
|
||||
static FleetPickupSource source(long id,String customer,String number,String warehouse) {
|
||||
var row=new FleetPickupSource();row.setId(id);row.setCustomerId(customer);row.setTransferNo(number);row.setInboundCode(number);
|
||||
row.setOperatingWarehouseId(warehouse);row.setDeliveryMethod("WAREHOUSE_PICKUP");row.setStatus("WAIT_PDA_RECEIVING");row.setPackageCount(5);
|
||||
row.setDeliveryAddress("1580 S Grove Ave, Ontario, CA 91761");row.setPickupContactName("取货测试联系人");row.setPickupContactPhone("0000000000");return row;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user