package com.baiyue.lastleg.schema; import org.junit.jupiter.api.Test; import org.springframework.core.io.ClassPathResource; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import static org.assertj.core.api.Assertions.assertThat; class LastlegOrderDetailSchemaContractTest { @Test void orderDetailHasCustomerIsolationInBaselineAndCleanInitialization() throws Exception { String baseline = new ClassPathResource("db/lastleg.sql") .getContentAsString(StandardCharsets.UTF_8); String unified = Files.readString(Path.of("..", "deploy", "sql", "海外区域统一增量-MySQL8.sql"), StandardCharsets.UTF_8); String service = Files.readString(Path.of("src", "main", "java", "com", "baiyue", "lastleg", "service", "LastlegOrderService.java"), StandardCharsets.UTF_8); assertThat(baseline) .contains("CREATE TABLE IF NOT EXISTS ll_order_detail") .contains("customer_id VARCHAR(128) NOT NULL COMMENT '客户数据隔离键'") .contains("KEY idx_ll_detail_customer_order(customer_id,order_id,id)"); assertThat(unified) .contains("CREATE TABLE ll_order_detail") .contains("customer_id varchar(128)") .contains("KEY idx_ll_detail_customer_order (customer_id,order_id,id)") .doesNotContain("UPDATE ll_order_detail", "ALTER TABLE ll_order_detail"); assertThat(service) .contains(".eq(LastlegOrderDetail::getCustomerId, order.getCustomerId())") .contains(".eq(LastlegOrderStatusHistory::getCustomerId, order.getCustomerId())"); } }