41 lines
2.0 KiB
Java
41 lines
2.0 KiB
Java
package com.baiyue.lastleg.delivery;
|
|
|
|
import com.baiyue.lastleg.dropship.mapper.DropshipOrderProfileMapper;
|
|
import org.apache.ibatis.annotations.Select;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
|
class DropshipOutboundCandidateMapperContractTest {
|
|
@Test
|
|
void candidateQueryIsSingleStatementAndFailsClosedOnEveryEligibilityFact() throws Exception {
|
|
String sql = select("listOutboundCandidates", String.class, String.class);
|
|
for (String token : new String[] {"p.customer_id=#{customerId}", "p.status='ACTIVE'",
|
|
"o.order_type='ONE_CLICK_DROPSHIP'", "COALESCE(o.detained,0)=0", "pos.status='OCCUPIED'",
|
|
"pos.available_packages>0", "s.package_count>0", "c.status='AVAILABLE'",
|
|
"ll_dispatch_pallet_lock", "ll_warehouse_transfer_inventory_allocation",
|
|
"ll_outbound_pallet_item", "pos.overseas_warehouse_id=#{warehouseId}", "LIMIT 500"}) {
|
|
assertTrue(sql.contains(token), token);
|
|
}
|
|
assertTrue(sql.contains("LEAST(pos.available_packages,s.package_count"));
|
|
}
|
|
|
|
@Test
|
|
void creationLockUsesTheSameEligibilityContractAndLocksOneSkuDimension() throws Exception {
|
|
String sql = select("lockOutboundCandidate", String.class, Long.class, String.class);
|
|
assertTrue(sql.contains("AND pos.id=#{positionId}"));
|
|
assertTrue(sql.contains("AND s.sku_code=#{skuCode}"));
|
|
assertTrue(sql.contains("LIMIT 1 FOR UPDATE"));
|
|
assertTrue(sql.contains("ll_dispatch_pallet_lock"));
|
|
assertTrue(sql.contains("ll_outbound_pallet_item"));
|
|
}
|
|
|
|
private String select(String method, Class<?>... parameterTypes) throws Exception {
|
|
Select annotation = DropshipOrderProfileMapper.class.getMethod(method, parameterTypes)
|
|
.getAnnotation(Select.class);
|
|
assertNotNull(annotation);
|
|
return String.join("", annotation.value());
|
|
}
|
|
}
|