项目结构类名称优化
This commit is contained in:
@@ -2,7 +2,7 @@ package com.label.integration;
|
||||
|
||||
import com.label.AbstractIntegrationTest;
|
||||
import com.label.service.RedisService;
|
||||
import com.label.util.RedisKeyManager;
|
||||
import com.label.util.RedisUtil;
|
||||
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -48,11 +48,11 @@ public class ExportIntegrationTest extends AbstractIntegrationTest {
|
||||
"SELECT id FROM sys_user WHERE username = 'admin'", Long.class);
|
||||
|
||||
// 伪造 Redis Token
|
||||
redisService.hSetAll(RedisKeyManager.tokenKey(ADMIN_TOKEN),
|
||||
redisService.hSetAll(RedisUtil.tokenKey(ADMIN_TOKEN),
|
||||
Map.of("userId", userId.toString(), "role", "ADMIN",
|
||||
"companyId", companyId.toString(), "username", "admin"),
|
||||
3600L);
|
||||
redisService.hSetAll(RedisKeyManager.tokenKey(ANNOTATOR_TOKEN),
|
||||
redisService.hSetAll(RedisUtil.tokenKey(ANNOTATOR_TOKEN),
|
||||
Map.of("userId", "3", "role", "ANNOTATOR",
|
||||
"companyId", companyId.toString(), "username", "annotator01"),
|
||||
3600L);
|
||||
@@ -93,8 +93,8 @@ public class ExportIntegrationTest extends AbstractIntegrationTest {
|
||||
|
||||
@AfterEach
|
||||
void cleanupTokens() {
|
||||
redisService.delete(RedisKeyManager.tokenKey(ADMIN_TOKEN));
|
||||
redisService.delete(RedisKeyManager.tokenKey(ANNOTATOR_TOKEN));
|
||||
redisService.delete(RedisUtil.tokenKey(ADMIN_TOKEN));
|
||||
redisService.delete(RedisUtil.tokenKey(ANNOTATOR_TOKEN));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ 权限测试 --
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.label.integration;
|
||||
|
||||
import com.label.AbstractIntegrationTest;
|
||||
import com.label.service.RedisService;
|
||||
import com.label.util.RedisKeyManager;
|
||||
import com.label.util.RedisUtil;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -68,11 +68,11 @@ public class MultiTenantIsolationTest extends AbstractIntegrationTest {
|
||||
Long.class, companyBId);
|
||||
|
||||
// 伪造 Redis Token
|
||||
redisService.hSetAll(RedisKeyManager.tokenKey(TOKEN_A),
|
||||
redisService.hSetAll(RedisUtil.tokenKey(TOKEN_A),
|
||||
Map.of("userId", adminAId.toString(), "role", "ADMIN",
|
||||
"companyId", companyAId.toString(), "username", "admin"),
|
||||
3600L);
|
||||
redisService.hSetAll(RedisKeyManager.tokenKey(TOKEN_B),
|
||||
redisService.hSetAll(RedisUtil.tokenKey(TOKEN_B),
|
||||
Map.of("userId", adminBId.toString(), "role", "ADMIN",
|
||||
"companyId", companyBId.toString(), "username", "admin_b"),
|
||||
3600L);
|
||||
@@ -96,8 +96,8 @@ public class MultiTenantIsolationTest extends AbstractIntegrationTest {
|
||||
|
||||
@AfterEach
|
||||
void cleanupTokensAndCompanyB() {
|
||||
redisService.delete(RedisKeyManager.tokenKey(TOKEN_A));
|
||||
redisService.delete(RedisKeyManager.tokenKey(TOKEN_B));
|
||||
redisService.delete(RedisUtil.tokenKey(TOKEN_A));
|
||||
redisService.delete(RedisUtil.tokenKey(TOKEN_B));
|
||||
// 清理公司 B 的数据(sys_company 不在 cleanData TRUNCATE 范围内)
|
||||
jdbcTemplate.execute("DELETE FROM sys_user WHERE username = 'admin_b'");
|
||||
jdbcTemplate.execute("DELETE FROM sys_company WHERE company_code = 'TESTB'");
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.label.integration;
|
||||
import com.label.AbstractIntegrationTest;
|
||||
import com.label.common.result.Result;
|
||||
import com.label.service.RedisService;
|
||||
import com.label.util.RedisKeyManager;
|
||||
import com.label.util.RedisUtil;
|
||||
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
@@ -85,7 +85,7 @@ public class ShiroFilterIntegrationTest extends AbstractIntegrationTest {
|
||||
reviewerData.put("role", "REVIEWER");
|
||||
reviewerData.put("companyId", "1");
|
||||
reviewerData.put("username", "reviewer01");
|
||||
redisService.hSetAll(RedisKeyManager.tokenKey(REVIEWER_TOKEN), reviewerData, 3600L);
|
||||
redisService.hSetAll(RedisUtil.tokenKey(REVIEWER_TOKEN), reviewerData, 3600L);
|
||||
|
||||
// ANNOTATOR Token:companyId=1, userId=3
|
||||
Map<String, String> annotatorData = new HashMap<>();
|
||||
@@ -93,13 +93,13 @@ public class ShiroFilterIntegrationTest extends AbstractIntegrationTest {
|
||||
annotatorData.put("role", "ANNOTATOR");
|
||||
annotatorData.put("companyId", "1");
|
||||
annotatorData.put("username", "annotator01");
|
||||
redisService.hSetAll(RedisKeyManager.tokenKey(ANNOTATOR_TOKEN), annotatorData, 3600L);
|
||||
redisService.hSetAll(RedisUtil.tokenKey(ANNOTATOR_TOKEN), annotatorData, 3600L);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void cleanupTokens() {
|
||||
redisService.delete(RedisKeyManager.tokenKey(REVIEWER_TOKEN));
|
||||
redisService.delete(RedisKeyManager.tokenKey(ANNOTATOR_TOKEN));
|
||||
redisService.delete(RedisUtil.tokenKey(REVIEWER_TOKEN));
|
||||
redisService.delete(RedisUtil.tokenKey(ANNOTATOR_TOKEN));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ 测试用例 --
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.label.integration;
|
||||
|
||||
import com.label.AbstractIntegrationTest;
|
||||
import com.label.service.RedisService;
|
||||
import com.label.util.RedisKeyManager;
|
||||
import com.label.util.RedisUtil;
|
||||
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -46,20 +46,20 @@ public class SourceIntegrationTest extends AbstractIntegrationTest {
|
||||
@BeforeEach
|
||||
void setupTokens() {
|
||||
// uploader01 token (userId=4 from init.sql seed)
|
||||
redisService.hSetAll(RedisKeyManager.tokenKey(UPLOADER_TOKEN),
|
||||
redisService.hSetAll(RedisUtil.tokenKey(UPLOADER_TOKEN),
|
||||
Map.of("userId", "4", "role", "UPLOADER", "companyId", "1", "username", "uploader01"),
|
||||
3600L);
|
||||
// admin token (userId=1 from init.sql seed)
|
||||
redisService.hSetAll(RedisKeyManager.tokenKey(ADMIN_TOKEN),
|
||||
redisService.hSetAll(RedisUtil.tokenKey(ADMIN_TOKEN),
|
||||
Map.of("userId", "1", "role", "ADMIN", "companyId", "1", "username", "admin"),
|
||||
3600L);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void cleanupTokens() {
|
||||
redisService.delete(RedisKeyManager.tokenKey(UPLOADER_TOKEN));
|
||||
redisService.delete(RedisKeyManager.tokenKey(UPLOADER2_TOKEN));
|
||||
redisService.delete(RedisKeyManager.tokenKey(ADMIN_TOKEN));
|
||||
redisService.delete(RedisUtil.tokenKey(UPLOADER_TOKEN));
|
||||
redisService.delete(RedisUtil.tokenKey(UPLOADER2_TOKEN));
|
||||
redisService.delete(RedisUtil.tokenKey(ADMIN_TOKEN));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ 权限测试 --
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.label.integration;
|
||||
|
||||
import com.label.AbstractIntegrationTest;
|
||||
import com.label.service.RedisService;
|
||||
import com.label.util.RedisKeyManager;
|
||||
import com.label.util.RedisUtil;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -46,7 +46,7 @@ public class SysConfigIntegrationTest extends AbstractIntegrationTest {
|
||||
"SELECT id FROM sys_user WHERE username = 'admin'", Long.class);
|
||||
|
||||
// 伪造 Redis Token
|
||||
redisService.hSetAll(RedisKeyManager.tokenKey(ADMIN_TOKEN),
|
||||
redisService.hSetAll(RedisUtil.tokenKey(ADMIN_TOKEN),
|
||||
Map.of("userId", adminUserId.toString(), "role", "ADMIN",
|
||||
"companyId", companyId.toString(), "username", "admin"),
|
||||
3600L);
|
||||
@@ -54,7 +54,7 @@ public class SysConfigIntegrationTest extends AbstractIntegrationTest {
|
||||
|
||||
@AfterEach
|
||||
void cleanupTokens() {
|
||||
redisService.delete(RedisKeyManager.tokenKey(ADMIN_TOKEN));
|
||||
redisService.delete(RedisUtil.tokenKey(ADMIN_TOKEN));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ 测试 1: 公司配置覆盖全局 --
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.label.integration;
|
||||
|
||||
import com.label.AbstractIntegrationTest;
|
||||
import com.label.service.RedisService;
|
||||
import com.label.util.RedisKeyManager;
|
||||
import com.label.util.RedisUtil;
|
||||
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -61,7 +61,7 @@ public class TaskClaimConcurrencyTest extends AbstractIntegrationTest {
|
||||
tokens.add(token);
|
||||
// 所有 Token 使用 userId=3(annotator01),这在真实场景不会发生
|
||||
// 但在测试中用于验证并发锁机制(redis key 基于 taskId,不是 userId)
|
||||
redisService.hSetAll(RedisKeyManager.tokenKey(token),
|
||||
redisService.hSetAll(RedisUtil.tokenKey(token),
|
||||
Map.of("userId", String.valueOf(i + 100), // 假设 userId > 100 不存在,但不影响锁逻辑
|
||||
"role", "ANNOTATOR", "companyId", "1", "username", "annotator" + i),
|
||||
3600L);
|
||||
@@ -70,9 +70,9 @@ public class TaskClaimConcurrencyTest extends AbstractIntegrationTest {
|
||||
|
||||
@AfterEach
|
||||
void cleanup() {
|
||||
tokens.forEach(token -> redisService.delete(RedisKeyManager.tokenKey(token)));
|
||||
tokens.forEach(token -> redisService.delete(RedisUtil.tokenKey(token)));
|
||||
if (taskId != null) {
|
||||
redisService.delete(RedisKeyManager.taskClaimKey(taskId));
|
||||
redisService.delete(RedisUtil.taskClaimKey(taskId));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.label.integration;
|
||||
|
||||
import com.label.AbstractIntegrationTest;
|
||||
import com.label.service.RedisService;
|
||||
import com.label.util.RedisKeyManager;
|
||||
import com.label.util.RedisUtil;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -46,7 +46,7 @@ public class VideoCallbackIdempotencyTest extends AbstractIntegrationTest {
|
||||
"SELECT id FROM sys_user WHERE username = 'admin'", Long.class);
|
||||
|
||||
// 伪造 Redis Token
|
||||
redisService.hSetAll(RedisKeyManager.tokenKey(ADMIN_TOKEN),
|
||||
redisService.hSetAll(RedisUtil.tokenKey(ADMIN_TOKEN),
|
||||
Map.of("userId", adminUserId.toString(), "role", "ADMIN",
|
||||
"companyId", companyId.toString(), "username", "admin"),
|
||||
3600L);
|
||||
@@ -72,7 +72,7 @@ public class VideoCallbackIdempotencyTest extends AbstractIntegrationTest {
|
||||
|
||||
@AfterEach
|
||||
void cleanupTokens() {
|
||||
redisService.delete(RedisKeyManager.tokenKey(ADMIN_TOKEN));
|
||||
redisService.delete(RedisUtil.tokenKey(ADMIN_TOKEN));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ 测试 1: 幂等性 --
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.label.common.shiro.TokenPrincipal;
|
||||
import com.label.common.shiro.UserRealm;
|
||||
import com.label.config.ShiroConfig;
|
||||
import com.label.service.RedisService;
|
||||
import com.label.util.RedisKeyManager;
|
||||
import com.label.util.RedisUtil;
|
||||
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.mgt.DefaultSecurityManager;
|
||||
@@ -56,7 +56,7 @@ class TokenFilterTest {
|
||||
ReflectionTestUtils.setField(filter, "authEnabled", true);
|
||||
ReflectionTestUtils.setField(filter, "tokenTtlSeconds", 7200L);
|
||||
String token = "valid-token";
|
||||
when(redisService.hGetAll(RedisKeyManager.tokenKey(token))).thenReturn(Map.of(
|
||||
when(redisService.hGetAll(RedisUtil.tokenKey(token))).thenReturn(Map.of(
|
||||
"userId", "10",
|
||||
"role", "ADMIN",
|
||||
"companyId", "20",
|
||||
@@ -73,7 +73,7 @@ class TokenFilterTest {
|
||||
assertThat(response.getStatus()).isEqualTo(200);
|
||||
assertThat(chain.principal).isInstanceOf(TokenPrincipal.class);
|
||||
assertThat(chain.roleChecked).isTrue();
|
||||
verify(redisService).expire(RedisKeyManager.tokenKey(token), 7200L);
|
||||
verify(redisService).expire(RedisUtil.tokenKey(token), 7200L);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user