This commit is contained in:
2026-08-15 11:05:58 +08:00
parent c4282020b5
commit 557ab75319
50 changed files with 591 additions and 394 deletions
@@ -25,12 +25,18 @@ class PlatformMasterDataControllerContractTest {
try (var factory = Validation.buildDefaultValidatorFactory()) {
var validator = factory.getValidator();
for (String type : java.util.List.of(
"CUSTOMER", "SUPPLIER", "BOTH", "CARRIER", "CUSTOMS_BROKER", "SHIPPER", "CONSIGNEE")) {
"CUSTOMER", "CARRIER", "SHIPPER", "CONSIGNEE")) {
var query = new com.baiyue.warehouse.dto.MasterDataQueries.PartnerPageQuery(
1, 20, null, type, null, null);
assertThat(validator.validate(query)).isEmpty();
}
for (String removed : java.util.List.of("SUPPLIER", "CUSTOMS_BROKER", "BOTH")) {
var query = new com.baiyue.warehouse.dto.MasterDataQueries.PartnerPageQuery(
1, 20, null, removed, null, null);
assertThat(validator.validate(query)).isNotEmpty();
}
var invalid = new com.baiyue.warehouse.dto.MasterDataQueries.PartnerPageQuery(
1, 20, null, "UNKNOWN", null, null);
assertThat(validator.validate(invalid))
@@ -8,18 +8,14 @@ import static org.assertj.core.api.Assertions.assertThat;
class PartnerMapperContractTest {
@Test
void bothTypeRequiresCustomerAndSupplierAssociations() throws Exception {
void typeFilterUsesOnlyStablePartnerTypeAssociation() throws Exception {
Select select = PartnerMapper.class.getDeclaredMethod("selectPartnerPageByType",
Page.class, Long.class, String.class, String.class, String.class)
.getAnnotation(Select.class);
String sql = String.join("\n", select.value());
assertThat(sql)
.contains("<when test=\"type == 'BOTH'\">")
.contains("customer_type.partner_type = 'CUSTOMER'")
.contains("supplier_type.partner_type = 'SUPPLIER'")
.contains("<otherwise>")
.contains("pt.partner_type = #{type}");
assertThat(sql).contains("pt.partner_type = #{type}")
.doesNotContain("type == 'BOTH'", "supplier_type.partner_type = 'SUPPLIER'");
}
@Test
@@ -89,7 +89,7 @@ class PartnerRepositoryTest {
PartnerEntity customerA = new PartnerEntity();
customerA.setId(7L); customerA.setTenantId(10001L); customerA.setPartnerType("CUSTOMER");
PartnerEntity customerB = new PartnerEntity();
customerB.setId(7L); customerB.setTenantId(10002L); customerB.setPartnerType("SUPPLIER");
customerB.setId(7L); customerB.setTenantId(10002L); customerB.setPartnerType("SHIPPER");
Page<PartnerEntity> source = new Page<>(1, 20);
source.setRecords(List.of(customerA, customerB));
source.setTotal(2);
@@ -98,14 +98,14 @@ class PartnerRepositoryTest {
PartnerTypeEntity typeA = new PartnerTypeEntity();
typeA.setTenantId(10001L); typeA.setPartnerId(7L); typeA.setPartnerType("CUSTOMER");
PartnerTypeEntity typeB = new PartnerTypeEntity();
typeB.setTenantId(10002L); typeB.setPartnerId(7L); typeB.setPartnerType("SUPPLIER");
typeB.setTenantId(10002L); typeB.setPartnerId(7L); typeB.setPartnerType("SHIPPER");
when(mapper.selectTypes(List.of(10001L, 10002L), List.of(7L, 7L)))
.thenReturn(List.of(typeA, typeB));
repository.page(null, new PartnerPageQuery(1, 20, null, null, null, null));
assertThat(customerA.getTypes()).containsExactly("CUSTOMER");
assertThat(customerB.getTypes()).containsExactly("SUPPLIER");
assertThat(customerB.getTypes()).containsExactly("SHIPPER");
}
@Test