Merge feat/process-modeler: 修 ArchUnit 棘轮(wftemplates SQL 收口 WfTemplatePickerService)+计划红线
Some checks failed
ci / build-test-parity (push) Has been cancelled
Some checks failed
ci / build-test-parity (push) Has been cancelled
修复 7524e5f 阶段2 merge 引入的 platform-app ArchitectureRulesTest 失败:
ProcessModelerController 直注 JdbcTemplate 违反棘轮,SQL 收口新建 WfTemplatePickerService;
全 reactor mvn clean install 独立验证真绿(ArchitectureRulesTest 6/6)。
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -368,4 +368,4 @@ commit:`test(modeler): 流程Modeler live e2e(改存量/新建/走查 3 场景
|
|||||||
|
|
||||||
## 红线提醒(执行中不可越)
|
## 红线提醒(执行中不可越)
|
||||||
|
|
||||||
**生产 8089 不对外**(T1.6 评审:门在网关的前提=flowable-service 网络隔离,阶段 3 部署门验收清单显式检查,deploy/nginx/compose 不得暴露 8089);flowable `databaseSchemaUpdate=false` 不动(act_re_model 已存在无需 DDL;审计表走 Flyway V4 是平台表非引擎表);保真层 `com.dsasp.*` 不改(BasePropertiesConverter 只读对齐,不重构);XML 解析一律钉 JDK 解析器(xerces 击穿前科);JDK 21;部署门只落网关(flowable-service 裸 8089 无安全栈);每 task TDD、每阶段对抗自查后才合 main。
|
**每阶段合 main 前必须全 reactor `mvn clean install` 真绿**(模块级 `mvn -pl` 跑不到 platform-app 的 ArchitectureRulesTest,阶段2 wftemplates 给 @RestController 注 JdbcTemplate 触棘轮就是模块级漏过、全 reactor 才 catch;且判绿看 `BUILD SUCCESS` 字样,勿信 `| tail` 后的 `$?`=tail 退出码);控制器新增 SQL 一律收口 Service(ArchUnit 棘轮禁 @RestController 直用 JdbcTemplate);**生产 8089 不对外**(T1.6 评审:门在网关的前提=flowable-service 网络隔离,阶段 3 部署门验收清单显式检查,deploy/nginx/compose 不得暴露 8089);flowable `databaseSchemaUpdate=false` 不动(act_re_model 已存在无需 DDL;审计表走 Flyway V4 是平台表非引擎表);保真层 `com.dsasp.*` 不改(BasePropertiesConverter 只读对齐,不重构);XML 解析一律钉 JDK 解析器(xerces 击穿前科);JDK 21;部署门只落网关(flowable-service 裸 8089 无安全栈);每 task TDD、每阶段对抗自查后才合 main。
|
||||||
|
|||||||
@@ -0,0 +1,80 @@
|
|||||||
|
package com.eip4.platform.flowgateway.aggregate;
|
||||||
|
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
import org.springframework.jdbc.core.RowMapper;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* wftemplate 选择器数据源:为在线流程 Modeler 的办理人/会签 formKey 下拉提供 {@code {id,name}} 列表。
|
||||||
|
*
|
||||||
|
* <p><b>为何是 Service 而非控制器直查</b>:{@code @RestController} 直持 {@link JdbcTemplate} 拼 SQL 会让
|
||||||
|
* 现代层退化成第二个「SQL 散落层」(架构棘轮 {@code 控制器不得新增直用JdbcTemplate} 禁止新增此类),
|
||||||
|
* 故 SQL 收口到本 Service,控制器只保留超管门 + 透传。</p>
|
||||||
|
*
|
||||||
|
* <p><b>名称来源实证(information_schema)</b>:{@code view_wftemplate}(1016 行已迁移)<b>无独立名称列</b>
|
||||||
|
* (仅 {@code view_wftemplate_id CHAR + xml + isactive + 审计列}),{@code <form>} 根标签也无 title/name
|
||||||
|
* 属性(0/1016);唯一人类可读名来自 XML 的 {@code entityid} → {@code sys_entity.name}(378 模板带 entityid,
|
||||||
|
* 339 解析出中文名,如「通知管理」)。故 name = 解析出的实体名,无则回退 id;{@code view_wftemplate_id} 是
|
||||||
|
* CHAR 补白列 → RowMapper 内 trim。读库异常降级({@code degraded:true}),不 500 阻断设计器。</p>
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class WfTemplatePickerService {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(WfTemplatePickerService.class);
|
||||||
|
|
||||||
|
/** 选择器 SQL:view_wftemplate_id + entityid→sys_entity.name(LEFT JOIN + 正则抽 entityid),isactive=1,名称升序。 */
|
||||||
|
static final String WFTEMPLATES_SQL =
|
||||||
|
"SELECT t.view_wftemplate_id AS id, se.name AS name "
|
||||||
|
+ "FROM view_wftemplate t "
|
||||||
|
+ "LEFT JOIN sys_entity se "
|
||||||
|
+ " ON se.sys_entity_id = substring(CAST(t.xml AS text) FROM 'entityid=\"([0-9a-fA-F-]+)\"') "
|
||||||
|
+ "WHERE t.isactive = 1 "
|
||||||
|
+ "ORDER BY se.name NULLS LAST, t.view_wftemplate_id";
|
||||||
|
|
||||||
|
/** 单行 → {@code {id(trim 补白),name(实体名,空则回退 id)}}。 */
|
||||||
|
static final RowMapper<Map<String, Object>> WFTEMPLATE_ROW = (rs, rowNum) -> {
|
||||||
|
String id = rs.getString("id");
|
||||||
|
if (id != null) {
|
||||||
|
id = id.trim();
|
||||||
|
}
|
||||||
|
String name = rs.getString("name");
|
||||||
|
Map<String, Object> row = new LinkedHashMap<>();
|
||||||
|
row.put("id", id);
|
||||||
|
row.put("name", (name != null && !name.isBlank()) ? name : id);
|
||||||
|
return row;
|
||||||
|
};
|
||||||
|
|
||||||
|
private final JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
|
public WfTemplatePickerService(JdbcTemplate jdbcTemplate) {
|
||||||
|
this.jdbcTemplate = jdbcTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 选择器列表。正常 → {@code {templates:[{id,name}]}};读库异常降级 → {@code {templates:[], degraded:true}}
|
||||||
|
* (正常路径<b>不带</b> degraded 键,前端可据此区分「真无模板」与「读库失败」并提示重试)。
|
||||||
|
*/
|
||||||
|
public Map<String, Object> listTemplates() {
|
||||||
|
List<Map<String, Object>> templates;
|
||||||
|
boolean degraded = false;
|
||||||
|
try {
|
||||||
|
templates = jdbcTemplate.query(WFTEMPLATES_SQL, WFTEMPLATE_ROW);
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
log.warn("view_wftemplate 选择器读取降级为空列表: {}", e.toString());
|
||||||
|
templates = List.of();
|
||||||
|
degraded = true;
|
||||||
|
}
|
||||||
|
Map<String, Object> resp = new LinkedHashMap<>();
|
||||||
|
resp.put("templates", templates);
|
||||||
|
if (degraded) {
|
||||||
|
resp.put("degraded", true);
|
||||||
|
}
|
||||||
|
return resp;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,15 +1,10 @@
|
|||||||
package com.eip4.platform.flowgateway.web;
|
package com.eip4.platform.flowgateway.web;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
|
||||||
import org.springframework.jdbc.core.RowMapper;
|
|
||||||
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
@@ -22,6 +17,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
|
|
||||||
import com.eip4.platform.auth.security.AuthPrincipal;
|
import com.eip4.platform.auth.security.AuthPrincipal;
|
||||||
import com.eip4.platform.auth.security.EngineContextBinder;
|
import com.eip4.platform.auth.security.EngineContextBinder;
|
||||||
|
import com.eip4.platform.flowgateway.aggregate.WfTemplatePickerService;
|
||||||
import com.eip4.platform.flowgateway.client.FlowableClient;
|
import com.eip4.platform.flowgateway.client.FlowableClient;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
@@ -43,42 +39,13 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
|||||||
@RequestMapping("/api/workflow")
|
@RequestMapping("/api/workflow")
|
||||||
public class ProcessModelerController {
|
public class ProcessModelerController {
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(ProcessModelerController.class);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* formKey 选择器数据源:{@code view_wftemplate}(1016 行已迁移)。<b>实证(information_schema)</b>:
|
|
||||||
* 表无独立名称列(仅 {@code view_wftemplate_id CHAR + xml + isactive + 审计列}),{@code <form>} 根标签
|
|
||||||
* 也无 title/name 属性(0/1016);唯一人类可读名来自 XML 的 {@code entityid} → {@code sys_entity.name}
|
|
||||||
* (378 模板带 entityid,339 解析出中文名,如「通知管理」)。故 name = 解析出的实体名,无则回退 id。
|
|
||||||
* {@code view_wftemplate_id} 是 CHAR 补白列 → RowMapper 内 trim。
|
|
||||||
*/
|
|
||||||
static final String WFTEMPLATES_SQL =
|
|
||||||
"SELECT t.view_wftemplate_id AS id, se.name AS name "
|
|
||||||
+ "FROM view_wftemplate t "
|
|
||||||
+ "LEFT JOIN sys_entity se "
|
|
||||||
+ " ON se.sys_entity_id = substring(CAST(t.xml AS text) FROM 'entityid=\"([0-9a-fA-F-]+)\"') "
|
|
||||||
+ "WHERE t.isactive = 1 "
|
|
||||||
+ "ORDER BY se.name NULLS LAST, t.view_wftemplate_id";
|
|
||||||
|
|
||||||
/** 单行 → {@code {id(trim 补白),name(实体名,空则回退 id)}}。 */
|
|
||||||
static final RowMapper<Map<String, Object>> WFTEMPLATE_ROW = (rs, rowNum) -> {
|
|
||||||
String id = rs.getString("id");
|
|
||||||
if (id != null) {
|
|
||||||
id = id.trim();
|
|
||||||
}
|
|
||||||
String name = rs.getString("name");
|
|
||||||
Map<String, Object> row = new LinkedHashMap<>();
|
|
||||||
row.put("id", id);
|
|
||||||
row.put("name", (name != null && !name.isBlank()) ? name : id);
|
|
||||||
return row;
|
|
||||||
};
|
|
||||||
|
|
||||||
private final FlowableClient flowableClient;
|
private final FlowableClient flowableClient;
|
||||||
private final JdbcTemplate jdbcTemplate;
|
private final WfTemplatePickerService wfTemplatePickerService;
|
||||||
|
|
||||||
public ProcessModelerController(FlowableClient flowableClient, JdbcTemplate jdbcTemplate) {
|
public ProcessModelerController(FlowableClient flowableClient,
|
||||||
|
WfTemplatePickerService wfTemplatePickerService) {
|
||||||
this.flowableClient = flowableClient;
|
this.flowableClient = flowableClient;
|
||||||
this.jdbcTemplate = jdbcTemplate;
|
this.wfTemplatePickerService = wfTemplatePickerService;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------- 存量流程源载入(T1.6)
|
// ---------------------------------------------------------------- 存量流程源载入(T1.6)
|
||||||
@@ -194,31 +161,17 @@ public class ProcessModelerController {
|
|||||||
// ---------------------------------------------------------------- formKey 选择器数据源(T2.2)
|
// ---------------------------------------------------------------- formKey 选择器数据源(T2.2)
|
||||||
|
|
||||||
@Operation(summary = "wftemplate 选择器数据源(超管)",
|
@Operation(summary = "wftemplate 选择器数据源(超管)",
|
||||||
description = "超管门后读业务库 view_wftemplate(isactive=1) → {templates:[{id,name}]},供办理人/会签 formKey"
|
description = "超管门后经 WfTemplatePickerService 读业务库 view_wftemplate(isactive=1) → {templates:[{id,name}]},"
|
||||||
+ " 下拉选择。name 取 XML entityid→sys_entity.name(无则回退 id),view_wftemplate_id 去 CHAR 补白。"
|
+ "供办理人/会签 formKey 下拉选择。name 取 XML entityid→sys_entity.name(无则回退 id),"
|
||||||
+ "读库异常降级为空列表(不 500 阻断设计器)。")
|
+ "view_wftemplate_id 去 CHAR 补白。读库异常降级 {templates:[], degraded:true}(不 500 阻断设计器)。")
|
||||||
@GetMapping("/wftemplates")
|
@GetMapping("/wftemplates")
|
||||||
public ResponseEntity<Map<String, Object>> wftemplates(@AuthenticationPrincipal AuthPrincipal principal) {
|
public ResponseEntity<Map<String, Object>> wftemplates(@AuthenticationPrincipal AuthPrincipal principal) {
|
||||||
ResponseEntity<Map<String, Object>> denied = requireSuperAdmin(principal);
|
ResponseEntity<Map<String, Object>> denied = requireSuperAdmin(principal);
|
||||||
if (denied != null) {
|
if (denied != null) {
|
||||||
return denied;
|
return denied;
|
||||||
}
|
}
|
||||||
List<Map<String, Object>> templates;
|
// SQL 收口 WfTemplatePickerService(@Service):@RestController 不得直用 JdbcTemplate(架构棘轮)。
|
||||||
boolean degraded = false;
|
return ResponseEntity.ok(wfTemplatePickerService.listTemplates());
|
||||||
try {
|
|
||||||
templates = jdbcTemplate.query(WFTEMPLATES_SQL, WFTEMPLATE_ROW);
|
|
||||||
} catch (RuntimeException e) {
|
|
||||||
log.warn("view_wftemplate 选择器读取降级为空列表: {}", e.toString());
|
|
||||||
templates = List.of();
|
|
||||||
degraded = true;
|
|
||||||
}
|
|
||||||
Map<String, Object> resp = new LinkedHashMap<>();
|
|
||||||
resp.put("templates", templates);
|
|
||||||
if (degraded) {
|
|
||||||
// 降级标记:正常路径不带此键,前端可据此区分「真无模板」与「读库失败」并提示重试。
|
|
||||||
resp.put("degraded", true);
|
|
||||||
}
|
|
||||||
return ResponseEntity.ok(resp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------- 超管门
|
// ---------------------------------------------------------------- 超管门
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
|
|||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -25,8 +24,6 @@ import org.springframework.core.MethodParameter;
|
|||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
|
||||||
import org.springframework.jdbc.core.RowMapper;
|
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||||
import org.springframework.web.bind.support.WebDataBinderFactory;
|
import org.springframework.web.bind.support.WebDataBinderFactory;
|
||||||
@@ -35,6 +32,7 @@ import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
|||||||
import org.springframework.web.method.support.ModelAndViewContainer;
|
import org.springframework.web.method.support.ModelAndViewContainer;
|
||||||
|
|
||||||
import com.eip4.platform.auth.security.AuthPrincipal;
|
import com.eip4.platform.auth.security.AuthPrincipal;
|
||||||
|
import com.eip4.platform.flowgateway.aggregate.WfTemplatePickerService;
|
||||||
import com.eip4.platform.flowgateway.client.FlowRemoteException;
|
import com.eip4.platform.flowgateway.client.FlowRemoteException;
|
||||||
import com.eip4.platform.flowgateway.client.FlowServiceUnavailableException;
|
import com.eip4.platform.flowgateway.client.FlowServiceUnavailableException;
|
||||||
import com.eip4.platform.flowgateway.client.FlowableClient;
|
import com.eip4.platform.flowgateway.client.FlowableClient;
|
||||||
@@ -48,9 +46,9 @@ import com.eip4.platform.flowgateway.web.ProcessModelerController;
|
|||||||
class ProcessModelerControllerTest {
|
class ProcessModelerControllerTest {
|
||||||
|
|
||||||
private final FlowableClient flowableClient = mock(FlowableClient.class);
|
private final FlowableClient flowableClient = mock(FlowableClient.class);
|
||||||
private final JdbcTemplate jdbcTemplate = mock(JdbcTemplate.class);
|
private final WfTemplatePickerService wfTemplatePickerService = mock(WfTemplatePickerService.class);
|
||||||
private final ProcessModelerController controller =
|
private final ProcessModelerController controller =
|
||||||
new ProcessModelerController(flowableClient, jdbcTemplate);
|
new ProcessModelerController(flowableClient, wfTemplatePickerService);
|
||||||
|
|
||||||
/** 真实形态:中文 key + 冒号分隔的 procDefId。 */
|
/** 真实形态:中文 key + 冒号分隔的 procDefId。 */
|
||||||
private static final String CN_PROCDEF = "总包合同交底:3:abc123";
|
private static final String CN_PROCDEF = "总包合同交底:3:abc123";
|
||||||
@@ -330,56 +328,28 @@ class ProcessModelerControllerTest {
|
|||||||
.andExpect(jsonPath("$.error").value("FLOW_REMOTE_ERROR"));
|
.andExpect(jsonPath("$.error").value("FLOW_REMOTE_ERROR"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- wftemplates 选择器数据源:超管读库 trim CHAR 补白 + 无实体名回退 id;非超管 403 零读库 ----
|
// ---- wftemplates 选择器:控制器只验门 + 透传 WfTemplatePickerService 结果(SQL/trim/降级细节在 WfTemplatePickerServiceTest)----
|
||||||
|
|
||||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
|
||||||
@Test
|
@Test
|
||||||
void wftemplates_超管_读库trim补白并回退id() {
|
void wftemplates_超管_透传service结果200() {
|
||||||
// mock JdbcTemplate 反射调真实 RowMapper:第一行有实体名(取名+trim补白),第二行无名(回退 trim 后的 id)
|
Map<String, Object> downstream = Map.of("templates",
|
||||||
when(jdbcTemplate.query(anyString(), any(RowMapper.class))).thenAnswer(inv -> {
|
List.of(Map.of("id", "wft-0001", "name", "通知管理")));
|
||||||
RowMapper<Map<String, Object>> rm = inv.getArgument(1);
|
when(wfTemplatePickerService.listTemplates()).thenReturn(downstream);
|
||||||
ResultSet named = mock(ResultSet.class);
|
|
||||||
when(named.getString("id")).thenReturn("wft-0001 "); // CHAR(36) 补白
|
|
||||||
when(named.getString("name")).thenReturn("通知管理");
|
|
||||||
ResultSet unnamed = mock(ResultSet.class);
|
|
||||||
when(unnamed.getString("id")).thenReturn("wft-0002 ");
|
|
||||||
when(unnamed.getString("name")).thenReturn(null); // 无 entityid/实体名 → 回退 id
|
|
||||||
return List.of(rm.mapRow(named, 0), rm.mapRow(unnamed, 1));
|
|
||||||
});
|
|
||||||
|
|
||||||
ResponseEntity<Map<String, Object>> resp = controller.wftemplates(admin());
|
ResponseEntity<Map<String, Object>> resp = controller.wftemplates(admin());
|
||||||
|
|
||||||
assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.OK);
|
assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||||
List<Map<String, Object>> templates = (List<Map<String, Object>>) resp.getBody().get("templates");
|
assertThat(resp.getBody()).isEqualTo(downstream);
|
||||||
assertThat(templates).hasSize(2);
|
verify(wfTemplatePickerService).listTemplates();
|
||||||
assertThat(templates.get(0)).containsEntry("id", "wft-0001").containsEntry("name", "通知管理");
|
|
||||||
assertThat(templates.get(1)).containsEntry("id", "wft-0002").containsEntry("name", "wft-0002");
|
|
||||||
// 正常路径不带 degraded 键(与降级分支区分)
|
|
||||||
assertThat(resp.getBody()).doesNotContainKey("degraded");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
|
||||||
@Test
|
@Test
|
||||||
void wftemplates_非超管_403且不读库() {
|
void wftemplates_非超管_403且不调service() {
|
||||||
ResponseEntity<Map<String, Object>> resp = controller.wftemplates(normalUser());
|
ResponseEntity<Map<String, Object>> resp = controller.wftemplates(normalUser());
|
||||||
|
|
||||||
assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
|
assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
|
||||||
assertThat(resp.getBody()).containsEntry("status", 1).containsEntry("msg", "仅系统管理员可用");
|
assertThat(resp.getBody()).containsEntry("status", 1).containsEntry("msg", "仅系统管理员可用");
|
||||||
verify(jdbcTemplate, never()).query(anyString(), any(RowMapper.class));
|
verify(wfTemplatePickerService, never()).listTemplates();
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
|
||||||
@Test
|
|
||||||
void wftemplates_读库异常_降级空列表带degraded标记不500() {
|
|
||||||
when(jdbcTemplate.query(anyString(), any(RowMapper.class)))
|
|
||||||
.thenThrow(new org.springframework.dao.DataAccessResourceFailureException("db down"));
|
|
||||||
|
|
||||||
ResponseEntity<Map<String, Object>> resp = controller.wftemplates(admin());
|
|
||||||
|
|
||||||
assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.OK);
|
|
||||||
List<Map<String, Object>> templates = (List<Map<String, Object>>) resp.getBody().get("templates");
|
|
||||||
assertThat(templates).isEmpty();
|
|
||||||
assertThat(resp.getBody()).containsEntry("degraded", true); // 降级分支带标记(正常路径无此键)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- PUT 路由胶水(M-3):MockMvc 真走 PUT /api/workflow/models/{id},验路径匹配 + @PathVariable 绑定 + 200 透传 ----
|
// ---- PUT 路由胶水(M-3):MockMvc 真走 PUT /api/workflow/models/{id},验路径匹配 + @PathVariable 绑定 + 200 透传 ----
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package com.eip4.platform.flowgateway;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.dao.DataAccessResourceFailureException;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
import org.springframework.jdbc.core.RowMapper;
|
||||||
|
|
||||||
|
import com.eip4.platform.flowgateway.aggregate.WfTemplatePickerService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* wftemplate 选择器 Service 单测:RowMapper trim CHAR 补白 + 无实体名回退 id + 读库异常降级。
|
||||||
|
* SQL 收口到本 Service(@RestController 不得直用 JdbcTemplate,架构棘轮),故这些细节从控制器测试搬到这里。
|
||||||
|
*/
|
||||||
|
class WfTemplatePickerServiceTest {
|
||||||
|
|
||||||
|
private final JdbcTemplate jdbcTemplate = mock(JdbcTemplate.class);
|
||||||
|
private final WfTemplatePickerService service = new WfTemplatePickerService(jdbcTemplate);
|
||||||
|
|
||||||
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
|
@Test
|
||||||
|
void listTemplates_trim补白并回退id_正常不带degraded() {
|
||||||
|
// mock JdbcTemplate 反射调真实 RowMapper:第一行有实体名(取名+trim补白),第二行无名(回退 trim 后的 id)
|
||||||
|
when(jdbcTemplate.query(anyString(), any(RowMapper.class))).thenAnswer(inv -> {
|
||||||
|
RowMapper<Map<String, Object>> rm = inv.getArgument(1);
|
||||||
|
ResultSet named = mock(ResultSet.class);
|
||||||
|
when(named.getString("id")).thenReturn("wft-0001 "); // CHAR(36) 补白
|
||||||
|
when(named.getString("name")).thenReturn("通知管理");
|
||||||
|
ResultSet unnamed = mock(ResultSet.class);
|
||||||
|
when(unnamed.getString("id")).thenReturn("wft-0002 ");
|
||||||
|
when(unnamed.getString("name")).thenReturn(null); // 无 entityid/实体名 → 回退 id
|
||||||
|
return List.of(rm.mapRow(named, 0), rm.mapRow(unnamed, 1));
|
||||||
|
});
|
||||||
|
|
||||||
|
Map<String, Object> resp = service.listTemplates();
|
||||||
|
|
||||||
|
List<Map<String, Object>> templates = (List<Map<String, Object>>) resp.get("templates");
|
||||||
|
assertThat(templates).hasSize(2);
|
||||||
|
assertThat(templates.get(0)).containsEntry("id", "wft-0001").containsEntry("name", "通知管理");
|
||||||
|
assertThat(templates.get(1)).containsEntry("id", "wft-0002").containsEntry("name", "wft-0002");
|
||||||
|
assertThat(resp).doesNotContainKey("degraded"); // 正常路径不带 degraded 键
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
|
@Test
|
||||||
|
void listTemplates_读库异常_降级空列表带degraded不抛() {
|
||||||
|
when(jdbcTemplate.query(anyString(), any(RowMapper.class)))
|
||||||
|
.thenThrow(new DataAccessResourceFailureException("db down"));
|
||||||
|
|
||||||
|
Map<String, Object> resp = service.listTemplates();
|
||||||
|
|
||||||
|
List<Map<String, Object>> templates = (List<Map<String, Object>>) resp.get("templates");
|
||||||
|
assertThat(templates).isEmpty();
|
||||||
|
assertThat(resp).containsEntry("degraded", true); // 降级分支带标记(正常路径无此键)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user