|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+package com.ruoyi.framework.config;
|
|
|
2
|
+
|
|
|
3
|
+import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
4
|
+import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
|
5
|
+
|
|
|
6
|
+import com.ruoyi.common.core.domain.model.LoginUser;
|
|
|
7
|
+import org.junit.jupiter.api.DisplayName;
|
|
|
8
|
+import org.junit.jupiter.api.Test;
|
|
|
9
|
+
|
|
|
10
|
+@DisplayName("FastJson2JsonRedisSerializer")
|
|
|
11
|
+class FastJson2JsonRedisSerializerTest
|
|
|
12
|
+{
|
|
|
13
|
+ private static final String LEGACY_LOGIN_USER_JSON =
|
|
|
14
|
+ "{\"@type\":\"com.ruoyi.common.core.domain.model.LoginUser\",\"browser\":\"Chrome 148\","
|
|
|
15
|
+ + "\"deptId\":103L,\"expireTime\":1780467419148,\"ipaddr\":\"115.238.57.190\","
|
|
|
16
|
+ + "\"loginLocation\":\"XX XX\",\"loginTime\":1780465619148,\"os\":\"Windows10\","
|
|
|
17
|
+ + "\"permissions\":Set[\"*:*:*\"],\"token\":\"22e5d643-b819-4e3a-bb97-0fd65739ff51\","
|
|
|
18
|
+ + "\"user\":{\"admin\":true,\"createBy\":\"admin\",\"createTime\":\"2026-05-09 10:26:46\","
|
|
|
19
|
+ + "\"delFlag\":\"0\",\"dept\":{\"ancestors\":\"0,100,101\",\"children\":[],"
|
|
|
20
|
+ + "\"deptId\":103L,\"deptName\":\"研发部门\",\"leader\":\"若依\",\"orderNum\":1,"
|
|
|
21
|
+ + "\"params\":{\"@type\":\"java.util.HashMap\"},\"parentId\":101L,\"status\":\"0\"},"
|
|
|
22
|
+ + "\"deptId\":103L,\"email\":\"ry@163.com\",\"loginDate\":\"2026-06-03 13:46:16\","
|
|
|
23
|
+ + "\"loginIp\":\"115.238.57.190\",\"nickName\":\"超级管理员\","
|
|
|
24
|
+ + "\"params\":{\"@type\":\"java.util.HashMap\"},\"phonenumber\":\"15888888888\","
|
|
|
25
|
+ + "\"pwdUpdateDate\":\"2026-05-09 10:26:46\",\"remark\":\"管理员\","
|
|
|
26
|
+ + "\"roles\":[{\"admin\":true,\"dataScope\":\"1\",\"deptCheckStrictly\":false,"
|
|
|
27
|
+ + "\"flag\":false,\"menuCheckStrictly\":false,"
|
|
|
28
|
+ + "\"params\":{\"@type\":\"java.util.HashMap\"},\"roleId\":1L,\"roleKey\":\"admin\","
|
|
|
29
|
+ + "\"roleName\":\"超级管理员\",\"roleSort\":1,\"status\":\"0\"}],"
|
|
|
30
|
+ + "\"sex\":\"1\",\"status\":\"0\",\"userId\":1L,\"userName\":\"admin\"},"
|
|
|
31
|
+ + "\"userId\":1L,\"username\":\"admin\"}";
|
|
|
32
|
+
|
|
|
33
|
+ @Test
|
|
|
34
|
+ @DisplayName("反序列化含 admin 字段的历史 LoginUser 缓存")
|
|
|
35
|
+ void deserializeLegacyLoginUserWithAdminField()
|
|
|
36
|
+ {
|
|
|
37
|
+ FastJson2JsonRedisSerializer<LoginUser> serializer = new FastJson2JsonRedisSerializer<>(LoginUser.class);
|
|
|
38
|
+ LoginUser loginUser = serializer.deserialize(LEGACY_LOGIN_USER_JSON.getBytes(FastJson2JsonRedisSerializer.DEFAULT_CHARSET));
|
|
|
39
|
+ assertNotNull(loginUser);
|
|
|
40
|
+ assertEquals(1L, loginUser.getUserId());
|
|
|
41
|
+ assertNotNull(loginUser.getUser());
|
|
|
42
|
+ assertEquals("admin", loginUser.getUser().getUserName());
|
|
|
43
|
+ assertEquals("22e5d643-b819-4e3a-bb97-0fd65739ff51", loginUser.getToken());
|
|
|
44
|
+ }
|
|
|
45
|
+}
|