|
|
@@ -20,6 +20,7 @@ import java.util.Map;
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
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.mock;
|
|
|
@@ -106,11 +107,21 @@ class TrainScoreEntryContractTest {
|
|
|
/** 除学员维外还须携带批次(cohort/refId)入参并写入记录;当前 submitTraining 无批次维度。 */
|
|
|
@Test
|
|
|
void scoreEntryMustAssociateCohortBatch() {
|
|
|
- Method contract = findEntryWithCohort();
|
|
|
- assertNotNull(contract,
|
|
|
+ Method entry = findTrainingEntry();
|
|
|
+ assertNotNull(entry,
|
|
|
"train.score.entry 契约要求成绩与【学员 + 批次(cohort/refId)】双维关联落库:"
|
|
|
- + "需 EvalService 暴露带批次入参(≥3 个 Long 参数)且返回 Result 的录入入口;"
|
|
|
- + "当前 submitTraining(Long,Long,Integer,Integer) 无批次入参且未写 TrainEvalRecord.refId");
|
|
|
+ + "需 EvalService.submitTraining 暴露返回 Result 的录入入口;"
|
|
|
+ + "当前 EvalService 无 submitTraining 录入方法");
|
|
|
+ int longCount = 0;
|
|
|
+ for (Class<?> p : entry.getParameterTypes()) {
|
|
|
+ if (Long.class.equals(p) || Long.TYPE.equals(p)) {
|
|
|
+ longCount++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ assertEquals(3, longCount,
|
|
|
+ "train.score.entry 契约要求成绩与【学员 + 批次(cohort/refId)】双维关联落库:"
|
|
|
+ + "需 submitTraining 带批次入参(≥3 个 Long 参数:operatorId/targetUserId/cohortId);"
|
|
|
+ + "当前 submitTraining(Long,Long,Integer,Integer) 仅 2 个 Long 参数,无批次维度且未写 TrainEvalRecord.refId");
|
|
|
}
|
|
|
|
|
|
// ==================== 边界 0 补强:幂等重放 replay=true ====================
|
|
|
@@ -118,10 +129,19 @@ class TrainScoreEntryContractTest {
|
|
|
/** 契约要求 replay=true 的幂等重放入口(带 replay 标识与 key),否则重复录入会重复插记录。 */
|
|
|
@Test
|
|
|
void replayTrueRequiresIdempotencyEntry() {
|
|
|
- Method contract = findResultEntryWithReplay();
|
|
|
- assertNotNull(contract,
|
|
|
+ Method entry = findTrainingEntry();
|
|
|
+ assertNotNull(entry,
|
|
|
"train.score.entry(TC-1016) 幂等重放 replay=true 要求录入入口携带 replay/key/payload:"
|
|
|
- + "需 EvalService 暴露返回 Result 且带 Boolean replay 入参的方法;"
|
|
|
+ + "需 EvalService.submitTraining 暴露返回 Result 的录入入口;"
|
|
|
+ + "当前 EvalService 无 submitTraining 录入方法");
|
|
|
+ boolean replay = false;
|
|
|
+ for (Class<?> p : entry.getParameterTypes()) {
|
|
|
+ if (Boolean.class.equals(p) || Boolean.TYPE.equals(p)) {
|
|
|
+ replay = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ assertTrue(replay,
|
|
|
+ "train.score.entry(TC-1016) 幂等重放 replay=true 要求 submitTraining 携带 Boolean replay 入参;"
|
|
|
+ "当前 submitTraining 无 replay/key,重复提交将重复插入成绩记录");
|
|
|
}
|
|
|
|
|
|
@@ -130,10 +150,24 @@ class TrainScoreEntryContractTest {
|
|
|
/** 同一 (学员,批次) 幂等键携带不同分值须返回 C4092,禁止静默覆盖旧成绩。 */
|
|
|
@Test
|
|
|
void sameKeyDifferentPayloadReturnsC4092() {
|
|
|
- Method contract = findResultEntryWithReplayAndPayload();
|
|
|
- assertNotNull(contract,
|
|
|
+ Method entry = findTrainingEntry();
|
|
|
+ assertNotNull(entry,
|
|
|
"同一成绩幂等键携带不同 score 载荷必须返回 C4092(" + CODE_SAME_KEY_DIFF_PAYLOAD
|
|
|
- + ") 冲突,禁止静默覆盖;当前 EvalService 无携带 replay/key/payload 的 Result 录入入口");
|
|
|
+ + ") 冲突,禁止静默覆盖;当前 EvalService 无 submitTraining 录入入口");
|
|
|
+ boolean replay = false;
|
|
|
+ boolean payload = false;
|
|
|
+ for (Class<?> p : entry.getParameterTypes()) {
|
|
|
+ if (Boolean.class.equals(p) || Boolean.TYPE.equals(p)) {
|
|
|
+ replay = true;
|
|
|
+ }
|
|
|
+ if (String.class.equals(p) || Map.class.equals(p)) {
|
|
|
+ payload = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ assertTrue(replay && payload && entry.getParameterCount() >= 5,
|
|
|
+ "同一成绩幂等键携带不同 score 载荷必须返回 C4092(" + CODE_SAME_KEY_DIFF_PAYLOAD
|
|
|
+ + ") 冲突,禁止静默覆盖;需 submitTraining 携带 replay/key/payload 入参(≥5 参数);"
|
|
|
+ + "当前 EvalService 无携带 replay/key/payload 的 Result 录入入口");
|
|
|
}
|
|
|
|
|
|
// ==================== 边界 2:乐观锁冲突 C422 ====================
|
|
|
@@ -205,64 +239,20 @@ class TrainScoreEntryContractTest {
|
|
|
|
|
|
// ==================== 反射辅助 ====================
|
|
|
|
|
|
- /** 带批次入参(≥3 个 Long 参数)且返回 Result 的成绩录入入口。 */
|
|
|
- private static Method findEntryWithCohort() {
|
|
|
+ /**
|
|
|
+ * 定位成绩录入入口 {@code EvalService.submitTraining}(train.score.entry 被测面,E3 培训考核成绩)。
|
|
|
+ * 精确按方法名收窄,杜绝 submitCoach / submitOrgPerformance(train.eval.coach / train.eval.performance,
|
|
|
+ * 亦带 Boolean replay 与多 Long 参数)被误判为 score.entry 入口造成假绿。
|
|
|
+ */
|
|
|
+ private static Method findTrainingEntry() {
|
|
|
for (Method m : EvalService.class.getMethods()) {
|
|
|
- if (!Result.class.isAssignableFrom(m.getReturnType())) {
|
|
|
+ if (!"submitTraining".equals(m.getName())) {
|
|
|
continue;
|
|
|
}
|
|
|
- int longCount = 0;
|
|
|
- for (Class<?> p : m.getParameterTypes()) {
|
|
|
- if (Long.class.equals(p) || Long.TYPE.equals(p)) {
|
|
|
- longCount++;
|
|
|
- }
|
|
|
- }
|
|
|
- if (longCount >= 3) {
|
|
|
- return m;
|
|
|
- }
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- /** 返回 Result、带 Boolean replay 入参且语义确为「成绩录入」的入口。
|
|
|
- * 收窄匹配避免 adminList(Long, Boolean, Map) 等管理查询接口被误判为 replay 入口造成假绿。 */
|
|
|
- private static Method findResultEntryWithReplay() {
|
|
|
- for (Method m : EvalService.class.getMethods()) {
|
|
|
if (!Result.class.isAssignableFrom(m.getReturnType())) {
|
|
|
continue;
|
|
|
}
|
|
|
- String name = m.getName().toLowerCase();
|
|
|
- if (!(name.contains("score") || name.contains("submit") || name.contains("entry"))) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- for (Class<?> p : m.getParameterTypes()) {
|
|
|
- if (Boolean.class.equals(p) || Boolean.TYPE.equals(p)) {
|
|
|
- return m;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- /** 返回 Result、带 Boolean replay 与 String key/payload 且总参数 ≥5 的录入入口。 */
|
|
|
- private static Method findResultEntryWithReplayAndPayload() {
|
|
|
- for (Method m : EvalService.class.getMethods()) {
|
|
|
- if (!Result.class.isAssignableFrom(m.getReturnType()) || m.getParameterCount() < 5) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- boolean replay = false;
|
|
|
- boolean payload = false;
|
|
|
- for (Class<?> p : m.getParameterTypes()) {
|
|
|
- if (Boolean.class.equals(p) || Boolean.TYPE.equals(p)) {
|
|
|
- replay = true;
|
|
|
- }
|
|
|
- if (String.class.equals(p) || Map.class.equals(p)) {
|
|
|
- payload = true;
|
|
|
- }
|
|
|
- }
|
|
|
- if (replay && payload) {
|
|
|
- return m;
|
|
|
- }
|
|
|
+ return m;
|
|
|
}
|
|
|
return null;
|
|
|
}
|