|
|
@@ -0,0 +1,44 @@
|
|
|
+package com.ruoyi.system.mapper;
|
|
|
+
|
|
|
+import org.apache.ibatis.builder.xml.XMLMapperBuilder;
|
|
|
+import org.apache.ibatis.session.Configuration;
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+
|
|
|
+import java.io.InputStream;
|
|
|
+
|
|
|
+import static org.junit.jupiter.api.Assertions.assertFalse;
|
|
|
+import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 摊位资料审核列表 filter 片段渲染回归:status 基础条件与动态条件之间必须保留分隔空白。
|
|
|
+ */
|
|
|
+class StallQualificationMapperXmlTest {
|
|
|
+
|
|
|
+ private Configuration loadMapper() throws Exception {
|
|
|
+ String resource = "mapper/chanting/StallQualificationMapper.xml";
|
|
|
+ Configuration configuration = new Configuration();
|
|
|
+ try (InputStream input = getClass().getClassLoader().getResourceAsStream(resource)) {
|
|
|
+ new XMLMapperBuilder(input, configuration, resource, configuration.getSqlFragments()).parse();
|
|
|
+ }
|
|
|
+ return configuration;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void filterKeepsSeparatorBetweenBaseAndDynamicConditions() throws Exception {
|
|
|
+ Configuration configuration = loadMapper();
|
|
|
+ String namespace = "com.ruoyi.system.mapper.StallQualificationMapper.";
|
|
|
+ String sql = configuration.getMappedStatement(namespace + "selectApplications")
|
|
|
+ .getBoundSql(java.util.Map.of("status", 1, "limit", 10, "offset", 0)).getSql();
|
|
|
+ System.out.println("RENDERED SQL >>> " + sql + " <<<");
|
|
|
+ String collapsed = sql.replaceAll("\\s+", " ").toLowerCase();
|
|
|
+ assertFalse(collapsed.contains("0and"), "条件之间丢失分隔空白: " + collapsed);
|
|
|
+ assertTrue(collapsed.contains("status != 0 and status = ?"), collapsed);
|
|
|
+ assertTrue(collapsed.contains("limit ? offset ?"), collapsed);
|
|
|
+
|
|
|
+ String withStore = configuration.getMappedStatement(namespace + "selectApplications")
|
|
|
+ .getBoundSql(java.util.Map.of("status", 2, "storeId", 7L, "limit", 10, "offset", 0)).getSql();
|
|
|
+ String collapsedStore = withStore.replaceAll("\\s+", " ").toLowerCase();
|
|
|
+ assertFalse(collapsedStore.contains("?and"), "动态条件之间丢失分隔空白: " + collapsedStore);
|
|
|
+ assertTrue(collapsedStore.contains("and store_id = ?"), collapsedStore);
|
|
|
+ }
|
|
|
+}
|