Merge remote-tracking branch 'origin/test' into test
This commit is contained in:
+65
@@ -0,0 +1,65 @@
|
||||
package com.baiyue.lastleg.returnreceipt.service;
|
||||
|
||||
import com.baiyue.lastleg.returnreceipt.mapper.ReturnInventoryMovementMapper;
|
||||
import org.apache.ibatis.builder.annotation.MapperAnnotationBuilder;
|
||||
import org.apache.ibatis.session.Configuration;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Map;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class ReturnInventoryMovementSqlTest {
|
||||
@Test
|
||||
void unionSourceColumnsHaveExplicitMatchingCollationsInBothBaselinesAndMigration() throws Exception {
|
||||
Map<String, List<String>> fields = Map.of(
|
||||
"ll_return_order", List.of("customer_id", "overseas_warehouse_id"),
|
||||
"ll_return_order_item", List.of("sku_code", "product_name_zh"),
|
||||
"ll_return_receipt", List.of("receipt_no"),
|
||||
"ll_return_receipt_item", List.of("sku_code"),
|
||||
"ll_return_inventory_carton", List.of("customer_id", "overseas_warehouse_id", "carton_mark"),
|
||||
"ll_return_inventory_carton_item", List.of("sku_code", "product_name_zh"),
|
||||
"ll_return_inventory_outbound_movement", List.of("customer_id", "overseas_warehouse_id", "sku_code", "product_name_zh", "outbound_no"),
|
||||
"ll_return_sku_conversion", List.of("customer_id", "overseas_warehouse_id", "old_sku_code", "new_sku_code", "product_name_zh", "relabel_no"));
|
||||
for (Path file : List.of(Path.of("src/main/resources/db/lastleg.sql"),
|
||||
Path.of("../deploy/sql/海外区域统一增量-MySQL8.sql"),
|
||||
Path.of("../deploy/sql/migrations/overseas/baiyue_lastleg/V23__align_return_movement_collation.sql"))) {
|
||||
String sql = Files.readString(file);
|
||||
for (var entry : fields.entrySet()) {
|
||||
var block = Pattern.compile("(?s)(?:CREATE TABLE (?:IF NOT EXISTS )?|ALTER TABLE )" + entry.getKey() + "\\b.*?;").matcher(sql);
|
||||
assertTrue(block.find(), file + ": " + entry.getKey());
|
||||
for (String column : entry.getValue()) {
|
||||
assertTrue(Pattern.compile("(?i)\\b" + column + "\\s+varchar\\(\\d+\\) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci").matcher(block.group()).find(),
|
||||
file + ": " + entry.getKey() + "." + column);
|
||||
}
|
||||
}
|
||||
}
|
||||
String standalone = Files.readString(Path.of("src/main/resources/db/return-sku-conversion.sql"));
|
||||
for (String column : fields.get("ll_return_sku_conversion"))
|
||||
assertTrue(Pattern.compile("\\b" + column + "\\s+VARCHAR\\(\\d+\\) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci").matcher(standalone).find());
|
||||
}
|
||||
|
||||
@Test
|
||||
void countAndPageKeepOriginalProjectionAndScopeFilters() {
|
||||
Configuration configuration = new Configuration();
|
||||
new MapperAnnotationBuilder(configuration, ReturnInventoryMovementMapper.class).parse();
|
||||
Map<String, Object> params = Map.of("customerId", "CUSTOMER", "warehouseId", "WAREHOUSE",
|
||||
"skuCode", "SKU", "offset", 0L, "size", 20L);
|
||||
for (String method : new String[]{"platformCount", "platformPage"}) {
|
||||
var boundSql = configuration.getMappedStatement(ReturnInventoryMovementMapper.class.getName() + "." + method)
|
||||
.getBoundSql(params);
|
||||
String sql = boundSql.getSql();
|
||||
assertEquals(7, sql.split("UNION ALL", -1).length);
|
||||
assertTrue(!sql.contains("CONVERT("));
|
||||
assertTrue(sql.contains("m.customerId=?"));
|
||||
assertTrue(sql.contains("m.overseasWarehouseId=?"));
|
||||
assertTrue(sql.contains("m.skuCode LIKE CONCAT('%',?,'%')"));
|
||||
assertEquals(method.equals("platformPage") ? 5 : 3, boundSql.getParameterMappings().size());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user