|
|
@@ -0,0 +1,421 @@
|
|
|
+package com.train.service.impl;
|
|
|
+
|
|
|
+import com.train.common.Result;
|
|
|
+import com.train.entity.TrainPractitionerProfile;
|
|
|
+import com.train.entity.TrainPromotionRecord;
|
|
|
+import com.train.mapper.TrainCreditLedgerMapper;
|
|
|
+import com.train.mapper.TrainEvalRecordMapper;
|
|
|
+import com.train.mapper.TrainPractitionerProfileMapper;
|
|
|
+import com.train.mapper.TrainPromotionRecordMapper;
|
|
|
+import com.train.mapper.TrainPromotionRuleMapper;
|
|
|
+import com.train.mapper.TrainServiceOrderMapper;
|
|
|
+import com.train.service.BadgeService;
|
|
|
+import com.train.service.PractitionerService;
|
|
|
+import com.train.service.PromotionService;
|
|
|
+import com.train.service.RoleGuard;
|
|
|
+import org.junit.jupiter.api.BeforeEach;
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+import org.springframework.test.util.ReflectionTestUtils;
|
|
|
+
|
|
|
+import java.lang.reflect.Field;
|
|
|
+import java.lang.reflect.InvocationTargetException;
|
|
|
+import java.lang.reflect.Method;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
+import static org.junit.jupiter.api.Assertions.assertFalse;
|
|
|
+import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
|
+import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
+import static org.mockito.ArgumentMatchers.any;
|
|
|
+import static org.mockito.ArgumentMatchers.anyLong;
|
|
|
+import static org.mockito.Mockito.atMost;
|
|
|
+import static org.mockito.Mockito.mock;
|
|
|
+import static org.mockito.Mockito.verify;
|
|
|
+import static org.mockito.Mockito.when;
|
|
|
+
|
|
|
+/**
|
|
|
+ * {@code train.promo.unlock} 契约级边界单测(TDD-RED,S-train-37;TC-1037、TC-3005)。
|
|
|
+ *
|
|
|
+ * <p>需求锚点:docs/tdd/SRS.md §5.5「场景定义 §2 域六 P3-S1(Must)」——晋升成功即时解锁服务范围/
|
|
|
+ * 派单权限并同步资质闸口;与资质闸口联动即时生效(worker 可接范围扩大)。TC-1037 Given 人员晋升成功;
|
|
|
+ * When 触发;Then 解锁服务范围/派单权限即时生效。TC-3005 要求解锁即时生效、晋升履历沉淀档案。</p>
|
|
|
+ *
|
|
|
+ * <p>只写测试、不改任何 src/main。当前实现现状(RED 根因):
|
|
|
+ * 晋升域仅暴露只读判定 {@link PromotionServiceImpl#unlockCheck(Long, Map)}(派单资质闸口,
|
|
|
+ * 2 入参 userId/body,返回 allowed/reason),<b>没有</b>「晋升成功 → 即时写解锁」的可执行契约入口,
|
|
|
+ * 无法表达 replay/key/payload 幂等语义;{@link TrainPromotionRecord} 亦无 version 字段支撑并发
|
|
|
+ * 解锁乐观锁;所有错误语义走 {@code Result.error}(code=500),未区分 C404/C403/C4092/C422。
|
|
|
+ * 故本类边界用例预期为 RED(至少 1 条断言失败)。</p>
|
|
|
+ *
|
|
|
+ * <p>期望契约入口(GREEN 实现按此签名或等价;本测试按参数类型反射调用):
|
|
|
+ * {@code Result<Map<String,Object>> unlock(Boolean isAdmin, Long userId, Boolean replay,
|
|
|
+ * String key, Map<String,Object> payload)}——首个 Boolean=操作人管理员标识,Long=晋升人员/
|
|
|
+ * 记录 ID,第二个 Boolean=幂等重放标识,String=幂等键 key,Map=载荷 payload。
|
|
|
+ * 成功 Result.data 须含 {@code replay}(幂等重放标识)、{@code recordId}/{@code authLevel} 等。</p>
|
|
|
+ *
|
|
|
+ * <p>契约错误码({@code Result.code}):</p>
|
|
|
+ * <ul>
|
|
|
+ * <li>C4092 = 4092 同幂等键但载荷不一致(解锁范围/认证等级/操作人变化)</li>
|
|
|
+ * <li>C422 = 422 乐观锁冲突(解锁须写晋升记录,version 不匹配/影响 0 行须报错)</li>
|
|
|
+ * <li>C404 = 404 待解锁的晋升记录/档案不存在</li>
|
|
|
+ * <li>C403 = 403 非授权操作人触发解锁</li>
|
|
|
+ * </ul>
|
|
|
+ *
|
|
|
+ * <p>说明:本仓后端模块为 train-backend(无字面量 train-impl 子模块),测试按既有契约单测惯例落在
|
|
|
+ * train-backend/src/test/java/com/train/service/impl/,与同池 S-train-35/36 等契约测试同目录;
|
|
|
+ * 当前契约层尚未落地(SRS 全键「⏳未契约化·契约先行待落地」),错误码直接以 Result.code 表达。</p>
|
|
|
+ */
|
|
|
+class TrainPromoUnlockContractTest {
|
|
|
+
|
|
|
+ private static final int CODE_OK = 200;
|
|
|
+ private static final int CODE_SAME_KEY_DIFF_PAYLOAD = 4092;
|
|
|
+ private static final int CODE_VERSION_CONFLICT = 422;
|
|
|
+ private static final int CODE_NOT_FOUND = 404;
|
|
|
+ private static final int CODE_FORBIDDEN = 403;
|
|
|
+
|
|
|
+ private static final Long USER_ID = 5001L;
|
|
|
+ private static final Long RECORD_ID = 8001L;
|
|
|
+ private static final String IDEMPOTENCY_KEY = "PROMO-UNLOCK-5001-T2-2026Q4";
|
|
|
+
|
|
|
+ /** 期望解锁执行入口的方法名关键字(GREEN 实现可任选其一,但须含 unlock) */
|
|
|
+ private static final String[] ENTRY_NAME_KEYS = {"unlock", "grant", "scope"};
|
|
|
+
|
|
|
+ private PromotionServiceImpl service;
|
|
|
+ private TrainPromotionRuleMapper ruleMapper;
|
|
|
+ private TrainPromotionRecordMapper recordMapper;
|
|
|
+ private TrainPractitionerProfileMapper profileMapper;
|
|
|
+ private TrainServiceOrderMapper orderMapper;
|
|
|
+ private TrainCreditLedgerMapper ledgerMapper;
|
|
|
+ private TrainEvalRecordMapper evalMapper;
|
|
|
+ private PractitionerService practitionerService;
|
|
|
+ private BadgeService badgeService;
|
|
|
+ private RoleGuard roleGuard;
|
|
|
+ private PromotionService self;
|
|
|
+ private TrainPractitionerProfile profile;
|
|
|
+
|
|
|
+ @BeforeEach
|
|
|
+ void setUp() {
|
|
|
+ service = new PromotionServiceImpl();
|
|
|
+ ruleMapper = mock(TrainPromotionRuleMapper.class);
|
|
|
+ recordMapper = mock(TrainPromotionRecordMapper.class);
|
|
|
+ profileMapper = mock(TrainPractitionerProfileMapper.class);
|
|
|
+ orderMapper = mock(TrainServiceOrderMapper.class);
|
|
|
+ ledgerMapper = mock(TrainCreditLedgerMapper.class);
|
|
|
+ evalMapper = mock(TrainEvalRecordMapper.class);
|
|
|
+ practitionerService = mock(PractitionerService.class);
|
|
|
+ badgeService = mock(BadgeService.class);
|
|
|
+ roleGuard = mock(RoleGuard.class);
|
|
|
+ self = mock(PromotionService.class);
|
|
|
+
|
|
|
+ ReflectionTestUtils.setField(service, "trainPromotionRuleMapper", ruleMapper);
|
|
|
+ ReflectionTestUtils.setField(service, "trainPromotionRecordMapper", recordMapper);
|
|
|
+ ReflectionTestUtils.setField(service, "trainPractitionerProfileMapper", profileMapper);
|
|
|
+ ReflectionTestUtils.setField(service, "trainServiceOrderMapper", orderMapper);
|
|
|
+ ReflectionTestUtils.setField(service, "trainCreditLedgerMapper", ledgerMapper);
|
|
|
+ ReflectionTestUtils.setField(service, "trainEvalRecordMapper", evalMapper);
|
|
|
+ ReflectionTestUtils.setField(service, "practitionerService", practitionerService);
|
|
|
+ ReflectionTestUtils.setField(service, "badgeService", badgeService);
|
|
|
+ ReflectionTestUtils.setField(service, "roleGuard", roleGuard);
|
|
|
+ ReflectionTestUtils.setField(service, "self", self);
|
|
|
+
|
|
|
+ // 管理员默认放行;越权用例单独 stub requireAdminRole(false)
|
|
|
+ when(roleGuard.requireAdminRole(true)).thenReturn(null);
|
|
|
+ when(roleGuard.requireAdminRole(false)).thenReturn("需要管理员权限");
|
|
|
+
|
|
|
+ profile = profile("T2", "active");
|
|
|
+ when(profileMapper.selectOne(any())).thenReturn(profile);
|
|
|
+ when(recordMapper.selectById(anyLong())).thenReturn(promotedRecord());
|
|
|
+ when(recordMapper.updateById(any(TrainPromotionRecord.class))).thenReturn(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static TrainPractitionerProfile profile(String authLevel, String status) {
|
|
|
+ TrainPractitionerProfile p = new TrainPractitionerProfile();
|
|
|
+ p.setId(9001L);
|
|
|
+ p.setUserId(USER_ID);
|
|
|
+ p.setDisplayName("李*四");
|
|
|
+ p.setAuthLevel(authLevel);
|
|
|
+ p.setStatus(status);
|
|
|
+ p.setDeleted(0);
|
|
|
+ return p;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static TrainPromotionRecord promotedRecord() {
|
|
|
+ TrainPromotionRecord rec = new TrainPromotionRecord();
|
|
|
+ rec.setId(RECORD_ID);
|
|
|
+ rec.setUserId(USER_ID);
|
|
|
+ rec.setAuthLevel("T2");
|
|
|
+ rec.setStatus("promoted");
|
|
|
+ rec.setPass(1);
|
|
|
+ rec.setDeleted(0);
|
|
|
+ return rec;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Map<String, Object> unlockPayload(String authLevel, String serviceScope) {
|
|
|
+ Map<String, Object> payload = new HashMap<String, Object>();
|
|
|
+ payload.put("authLevel", authLevel);
|
|
|
+ payload.put("serviceScope", serviceScope);
|
|
|
+ return payload;
|
|
|
+ }
|
|
|
+
|
|
|
+ // ==================== 对照基线(当前只读判定已覆盖,作为 RED 的对照) ====================
|
|
|
+
|
|
|
+ /** 对照:资质已生效且已认证 T2,只读判定应放行。 */
|
|
|
+ @Test
|
|
|
+ void unlockCheckQualifiedProfileReturnsAllowed() {
|
|
|
+ Result<Map<String, Object>> r = service.unlockCheck(USER_ID, new HashMap<String, Object>());
|
|
|
+
|
|
|
+ assertEquals(CODE_OK, r.getCode());
|
|
|
+ assertEquals(Boolean.TRUE, r.getData().get("allowed"));
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 对照:已生效但未认证,只读判定应拒绝(reason=未认证)。 */
|
|
|
+ @Test
|
|
|
+ void unlockCheckNotCertifiedProfileReturnsNotAllowed() {
|
|
|
+ profile.setAuthLevel("none");
|
|
|
+
|
|
|
+ Result<Map<String, Object>> r = service.unlockCheck(USER_ID, new HashMap<String, Object>());
|
|
|
+
|
|
|
+ assertEquals(CODE_OK, r.getCode());
|
|
|
+ assertEquals(Boolean.FALSE, r.getData().get("allowed"));
|
|
|
+ assertEquals("未认证", r.getData().get("reason"));
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 对照:资质未生效(status=pending),只读判定应拒绝。 */
|
|
|
+ @Test
|
|
|
+ void unlockCheckPendingProfileReturnsNotAllowed() {
|
|
|
+ profile.setStatus("pending");
|
|
|
+
|
|
|
+ Result<Map<String, Object>> r = service.unlockCheck(USER_ID, new HashMap<String, Object>());
|
|
|
+
|
|
|
+ assertEquals(CODE_OK, r.getCode());
|
|
|
+ assertFalse(Boolean.TRUE.equals(r.getData().get("allowed")));
|
|
|
+ assertEquals("资质未生效", r.getData().get("reason"));
|
|
|
+ }
|
|
|
+
|
|
|
+ // ==================== 边界 0:幂等重放 replay=true ====================
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 契约入口:晋升成功后的「即时解锁」须暴露可显式表达 replay/key/payload 的 Result 入口,
|
|
|
+ * 否则调用方无法声明幂等重放,也无法在同键异载荷时返回 C4092。
|
|
|
+ * 当前仅有只读 unlockCheck(userId, body) 2 入参,无法满足。
|
|
|
+ */
|
|
|
+ @Test
|
|
|
+ void unlockEntryMustAcceptReplayKeyAndPayload() {
|
|
|
+ Method entry = findUnlockExecutionEntry();
|
|
|
+ assertNotNull(entry,
|
|
|
+ "train.promo.unlock 契约要求暴露「晋升成功即时解锁」的可执行入口"
|
|
|
+ + "(Result 返回,含 replay 布尔入参 + String 幂等键 key + Map 载荷 payload),"
|
|
|
+ + "以支持 replay=true 与同键异载荷 C4092;当前仅有只读 unlockCheck(Long,Map),无法表达幂等重放");
|
|
|
+
|
|
|
+ assertTrue(hasBooleanParam(entry),
|
|
|
+ "解锁入口须有 replay 布尔入参以表达幂等重放;当前入口不支持 replay=true");
|
|
|
+ assertTrue(hasParamOfTypes(entry, String.class, Map.class),
|
|
|
+ "解锁入口须同时接收幂等键 key(String) 与载荷 payload(Map);当前入口不支持");
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 同幂等键同载荷以 replay=true 重放,须显式标记 replay=true 且返回同一解锁结果,不得二次写晋升记录。 */
|
|
|
+ @Test
|
|
|
+ void replaySameKeySamePayloadFlagsReplayAndSkipsSecondWrite() throws Exception {
|
|
|
+ Method entry = requireUnlockEntry();
|
|
|
+ Map<String, Object> payload = unlockPayload("T2", "dispatch:T2,nationwide");
|
|
|
+
|
|
|
+ Result<Map<String, Object>> first = invokeUnlock(entry, true, false,
|
|
|
+ IDEMPOTENCY_KEY, payload, USER_ID, RECORD_ID);
|
|
|
+ Result<Map<String, Object>> replay = invokeUnlock(entry, true, true,
|
|
|
+ IDEMPOTENCY_KEY, payload, USER_ID, RECORD_ID);
|
|
|
+
|
|
|
+ assertEquals(CODE_OK, first.getCode());
|
|
|
+ assertEquals(CODE_OK, replay.getCode());
|
|
|
+ assertNotNull(replay.getData());
|
|
|
+ assertEquals(Boolean.TRUE, replay.getData().get("replay"),
|
|
|
+ "同幂等键同载荷 replay=true 重放须在 Result.data 中显式标识 replay=true,"
|
|
|
+ + "供调用方区分首次解锁与幂等回放");
|
|
|
+ assertEquals(first.getData().get("recordId"), replay.getData().get("recordId"),
|
|
|
+ "幂等重放须返回同一晋升记录,不得新建解锁记录");
|
|
|
+ verify(recordMapper, atMost(1)).updateById(any(TrainPromotionRecord.class));
|
|
|
+ }
|
|
|
+
|
|
|
+ // ==================== 边界 1:同键异载荷 C4092 ====================
|
|
|
+
|
|
|
+ /** 同一幂等键携带不同载荷(另一解锁范围/认证等级)重放必须返回 C4092,禁止静默按 200 复用。 */
|
|
|
+ @Test
|
|
|
+ void sameKeyDifferentPayloadReturnsC4092() throws Exception {
|
|
|
+ Method entry = requireUnlockEntry();
|
|
|
+
|
|
|
+ Result<Map<String, Object>> first = invokeUnlock(entry, true, false,
|
|
|
+ IDEMPOTENCY_KEY, unlockPayload("T2", "dispatch:T2,nationwide"), USER_ID, RECORD_ID);
|
|
|
+ Result<Map<String, Object>> conflict = invokeUnlock(entry, true, false,
|
|
|
+ IDEMPOTENCY_KEY, unlockPayload("T3", "dispatch:T3,nationwide"), USER_ID, RECORD_ID);
|
|
|
+
|
|
|
+ assertEquals(CODE_OK, first.getCode());
|
|
|
+ assertEquals(CODE_SAME_KEY_DIFF_PAYLOAD, conflict.getCode(),
|
|
|
+ "同一幂等键 " + IDEMPOTENCY_KEY + " 携带不同解锁载荷(T2→T3 / 服务范围变化)重放必须返回 "
|
|
|
+ + "C4092(" + CODE_SAME_KEY_DIFF_PAYLOAD + "),禁止静默按 200 复用既有解锁结果");
|
|
|
+ }
|
|
|
+
|
|
|
+ // ==================== 边界 2:乐观锁冲突 C422 ====================
|
|
|
+
|
|
|
+ /** 晋升记录实体须有 version 字段支撑并发解锁的乐观锁 C422。 */
|
|
|
+ @Test
|
|
|
+ void unlockRecordEntityMustHaveVersionField() {
|
|
|
+ Field version = findField(TrainPromotionRecord.class, "version");
|
|
|
+ assertNotNull(version,
|
|
|
+ "train_promotion_record 实体必须声明 version 字段以支撑并发解锁冲突 C422("
|
|
|
+ + CODE_VERSION_CONFLICT + ");当前实体无 version");
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 并发解锁更新影响 0 行(版本不匹配/丢失更新)必须返回 C422,不得静默按 200 成功。 */
|
|
|
+ @Test
|
|
|
+ void staleVersionUnlockReturnsC422() throws Exception {
|
|
|
+ Method entry = requireUnlockEntry();
|
|
|
+ when(recordMapper.updateById(any(TrainPromotionRecord.class))).thenReturn(0);
|
|
|
+
|
|
|
+ Result<Map<String, Object>> r = invokeUnlock(entry, true, false,
|
|
|
+ IDEMPOTENCY_KEY, unlockPayload("T2", "dispatch:T2,nationwide"), USER_ID, RECORD_ID);
|
|
|
+
|
|
|
+ assertEquals(CODE_VERSION_CONFLICT, r.getCode(),
|
|
|
+ "解锁更新晋升记录影响 0 行(乐观锁冲突/并发丢失更新)必须返回 C422("
|
|
|
+ + CODE_VERSION_CONFLICT + "),不得忽略 updateById 影响行数按 200 成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ // ==================== 边界 3:不存在 C404 ====================
|
|
|
+
|
|
|
+ /** 待解锁的晋升记录不存在 → C404,而非笼统的 500。 */
|
|
|
+ @Test
|
|
|
+ void nonExistentPromotionRecordReturns404() throws Exception {
|
|
|
+ Method entry = requireUnlockEntry();
|
|
|
+ when(recordMapper.selectById(anyLong())).thenReturn(null);
|
|
|
+
|
|
|
+ Result<Map<String, Object>> r = invokeUnlock(entry, true, false,
|
|
|
+ IDEMPOTENCY_KEY, unlockPayload("T2", "dispatch:T2,nationwide"), USER_ID, RECORD_ID);
|
|
|
+
|
|
|
+ assertEquals(CODE_NOT_FOUND, r.getCode(),
|
|
|
+ "待解锁的晋升记录不存在时必须返回 C404(" + CODE_NOT_FOUND + "),不得降级为笼统的 500");
|
|
|
+ }
|
|
|
+
|
|
|
+ // ==================== 边界 4:越权 C403 ====================
|
|
|
+
|
|
|
+ /** 非授权操作人触发解锁 → C403,而非笼统的 500。 */
|
|
|
+ @Test
|
|
|
+ void nonAdminUnlockReturns403() throws Exception {
|
|
|
+ Method entry = requireUnlockEntry();
|
|
|
+
|
|
|
+ Result<Map<String, Object>> r = invokeUnlock(entry, false, false,
|
|
|
+ IDEMPOTENCY_KEY, unlockPayload("T2", "dispatch:T2,nationwide"), USER_ID, RECORD_ID);
|
|
|
+
|
|
|
+ assertEquals(CODE_FORBIDDEN, r.getCode(),
|
|
|
+ "非授权操作人触发晋升解锁必须返回 C403(" + CODE_FORBIDDEN + "),不得降级为笼统的 500");
|
|
|
+ }
|
|
|
+
|
|
|
+ // ==================== helpers ====================
|
|
|
+
|
|
|
+ /** 在晋升服务接口与实现上查找「即时解锁」契约入口(按方法名关键字 + Result 返回 + replay/key/payload 形态)。 */
|
|
|
+ private static Method findUnlockExecutionEntry() {
|
|
|
+ for (Class<?> type : new Class<?>[]{PromotionService.class, PromotionServiceImpl.class}) {
|
|
|
+ for (Method m : type.getMethods()) {
|
|
|
+ if (!Result.class.isAssignableFrom(m.getReturnType())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String name = m.getName().toLowerCase();
|
|
|
+ boolean nameMatch = false;
|
|
|
+ for (String key : ENTRY_NAME_KEYS) {
|
|
|
+ if (name.contains(key)) {
|
|
|
+ nameMatch = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (nameMatch && hasBooleanParam(m) && hasParamOfTypes(m, String.class, Map.class)) {
|
|
|
+ return m;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 取契约入口;缺失时给出明确契约断言信息(使边界用例稳定为 RED 而非 NPE)。 */
|
|
|
+ private Method requireUnlockEntry() {
|
|
|
+ Method entry = findUnlockExecutionEntry();
|
|
|
+ assertNotNull(entry,
|
|
|
+ "train.promo.unlock 契约要求暴露「晋升成功即时解锁」可执行入口"
|
|
|
+ + "(Result 返回,含 replay/key/payload),当前仅有只读 unlockCheck(Long,Map),无法执行解锁");
|
|
|
+ return entry;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 按参数类型反射调用解锁入口(契约签名见类 Javadoc):Boolean#0=isAdmin,Long#0=userId,
|
|
|
+ * Boolean#1=replay,String=key,Map=payload,Long#1=recordId。
|
|
|
+ */
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ private Result<Map<String, Object>> invokeUnlock(Method entry, boolean isAdmin, boolean replay,
|
|
|
+ String key, Map<String, Object> payload, Long userId, Long recordId) throws Exception {
|
|
|
+ Class<?>[] pts = entry.getParameterTypes();
|
|
|
+ Object[] args = new Object[pts.length];
|
|
|
+ int boolIdx = 0;
|
|
|
+ int longIdx = 0;
|
|
|
+ for (int i = 0; i < pts.length; i++) {
|
|
|
+ Class<?> t = pts[i];
|
|
|
+ if (boolean.class.equals(t) || Boolean.class.equals(t)) {
|
|
|
+ args[i] = (boolIdx++ == 0) ? Boolean.valueOf(isAdmin) : Boolean.valueOf(replay);
|
|
|
+ } else if (String.class.equals(t)) {
|
|
|
+ args[i] = key;
|
|
|
+ } else if (Map.class.isAssignableFrom(t)) {
|
|
|
+ args[i] = payload;
|
|
|
+ } else if (long.class.equals(t) || Long.class.equals(t)) {
|
|
|
+ args[i] = (longIdx++ == 0) ? userId : recordId;
|
|
|
+ } else if (int.class.equals(t) || Integer.class.equals(t)) {
|
|
|
+ args[i] = Integer.valueOf(1);
|
|
|
+ } else {
|
|
|
+ args[i] = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ return (Result<Map<String, Object>>) entry.invoke(service, args);
|
|
|
+ } catch (InvocationTargetException e) {
|
|
|
+ Throwable cause = e.getCause();
|
|
|
+ if (cause instanceof Exception) {
|
|
|
+ throw (Exception) cause;
|
|
|
+ }
|
|
|
+ throw e;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static boolean hasBooleanParam(Method m) {
|
|
|
+ for (Class<?> t : m.getParameterTypes()) {
|
|
|
+ if (boolean.class.equals(t) || Boolean.class.equals(t)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static boolean hasParamOfTypes(Method m, Class<?>... types) {
|
|
|
+ boolean allFound = true;
|
|
|
+ for (Class<?> t : types) {
|
|
|
+ boolean found = false;
|
|
|
+ for (Class<?> pt : m.getParameterTypes()) {
|
|
|
+ if (t.equals(pt)) {
|
|
|
+ found = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!found) {
|
|
|
+ allFound = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return allFound;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Field findField(Class<?> type, String name) {
|
|
|
+ Class<?> c = type;
|
|
|
+ while (c != null) {
|
|
|
+ try {
|
|
|
+ return c.getDeclaredField(name);
|
|
|
+ } catch (NoSuchFieldException ignored) {
|
|
|
+ c = c.getSuperclass();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|