Commit 6f66d78865633908ec912071f3d1368a7017cc5e
1 parent
21201e12
test: 修复时间精度差异并恢复时间字段断言
统一持久化测试的时间精度,固定 OAuth2 生成时间并校验过期时长。 恢复数据库、Redis、日志清理及支付提交中的时间字段断言。
Showing
7 changed files
with
59 additions
and
53 deletions
yudao-module-infra/src/test/java/cn/iocoder/yudao/module/infra/service/job/JobLogServiceImplTest.java
| ... | ... | @@ -101,7 +101,7 @@ public class JobLogServiceImplTest extends BaseDbUnitTest { |
| 101 | 101 | JobLogDO log01 = randomPojo(JobLogDO.class, o -> o.setCreateTime(addTime(Duration.ofDays(-3)))) |
| 102 | 102 | .setExecuteIndex(1); |
| 103 | 103 | jobLogMapper.insert(log01); |
| 104 | - JobLogDO log02 = randomPojo(JobLogDO.class, o -> o.setCreateTime(addTime(Duration.ofDays(-1)))) | |
| 104 | + JobLogDO log02 = randomPojo(JobLogDO.class, o -> o.setCreateTime(addTime(Duration.ofDays(-1)).withNano(0))) | |
| 105 | 105 | .setExecuteIndex(1); |
| 106 | 106 | jobLogMapper.insert(log02); |
| 107 | 107 | // 准备参数 |
| ... | ... | @@ -114,8 +114,7 @@ public class JobLogServiceImplTest extends BaseDbUnitTest { |
| 114 | 114 | assertEquals(1, count); |
| 115 | 115 | List<JobLogDO> logs = jobLogMapper.selectList(); |
| 116 | 116 | assertEquals(1, logs.size()); |
| 117 | - // TODO @芋艿:createTime updateTime 被屏蔽,仅 win11 会复现,建议后续修复。 | |
| 118 | - assertPojoEquals(log02, logs.get(0), "createTime", "updateTime"); | |
| 117 | + assertPojoEquals(log02, logs.get(0)); | |
| 119 | 118 | } |
| 120 | 119 | |
| 121 | 120 | @Test | ... | ... |
yudao-module-infra/src/test/java/cn/iocoder/yudao/module/infra/service/logger/ApiAccessLogServiceImplTest.java
| ... | ... | @@ -79,7 +79,7 @@ public class ApiAccessLogServiceImplTest extends BaseDbUnitTest { |
| 79 | 79 | // mock 数据 |
| 80 | 80 | ApiAccessLogDO log01 = randomPojo(ApiAccessLogDO.class, o -> o.setCreateTime(addTime(Duration.ofDays(-3)))); |
| 81 | 81 | apiAccessLogMapper.insert(log01); |
| 82 | - ApiAccessLogDO log02 = randomPojo(ApiAccessLogDO.class, o -> o.setCreateTime(addTime(Duration.ofDays(-1)))); | |
| 82 | + ApiAccessLogDO log02 = randomPojo(ApiAccessLogDO.class, o -> o.setCreateTime(addTime(Duration.ofDays(-1)).withNano(0))); | |
| 83 | 83 | apiAccessLogMapper.insert(log02); |
| 84 | 84 | // 准备参数 |
| 85 | 85 | Integer exceedDay = 2; |
| ... | ... | @@ -91,8 +91,7 @@ public class ApiAccessLogServiceImplTest extends BaseDbUnitTest { |
| 91 | 91 | assertEquals(1, count); |
| 92 | 92 | List<ApiAccessLogDO> logs = apiAccessLogMapper.selectList(); |
| 93 | 93 | assertEquals(1, logs.size()); |
| 94 | - // TODO @芋艿:createTime updateTime 被屏蔽,仅 win11 会复现,建议后续修复。 | |
| 95 | - assertPojoEquals(log02, logs.get(0), "createTime", "updateTime"); | |
| 94 | + assertPojoEquals(log02, logs.get(0)); | |
| 96 | 95 | } |
| 97 | 96 | |
| 98 | 97 | @Test | ... | ... |
yudao-module-infra/src/test/java/cn/iocoder/yudao/module/infra/service/logger/ApiErrorLogServiceImplTest.java
| ... | ... | @@ -145,7 +145,7 @@ public class ApiErrorLogServiceImplTest extends BaseDbUnitTest { |
| 145 | 145 | // mock 数据 |
| 146 | 146 | ApiErrorLogDO log01 = randomPojo(ApiErrorLogDO.class, o -> o.setCreateTime(addTime(Duration.ofDays(-3)))); |
| 147 | 147 | apiErrorLogMapper.insert(log01); |
| 148 | - ApiErrorLogDO log02 = randomPojo(ApiErrorLogDO.class, o -> o.setCreateTime(addTime(Duration.ofDays(-1)))); | |
| 148 | + ApiErrorLogDO log02 = randomPojo(ApiErrorLogDO.class, o -> o.setCreateTime(addTime(Duration.ofDays(-1)).withNano(0))); | |
| 149 | 149 | apiErrorLogMapper.insert(log02); |
| 150 | 150 | // 准备参数 |
| 151 | 151 | Integer exceedDay = 2; |
| ... | ... | @@ -157,8 +157,7 @@ public class ApiErrorLogServiceImplTest extends BaseDbUnitTest { |
| 157 | 157 | assertEquals(1, count); |
| 158 | 158 | List<ApiErrorLogDO> logs = apiErrorLogMapper.selectList(); |
| 159 | 159 | assertEquals(1, logs.size()); |
| 160 | - // TODO @芋艿:createTime updateTime 被屏蔽,仅 win11 会复现,建议后续修复。 | |
| 161 | - assertPojoEquals(log02, logs.get(0), "createTime", "updateTime"); | |
| 160 | + assertPojoEquals(log02, logs.get(0)); | |
| 162 | 161 | } |
| 163 | 162 | |
| 164 | 163 | } | ... | ... |
yudao-module-pay/src/test/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceTest.java
| ... | ... | @@ -340,7 +340,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { |
| 340 | 340 | |
| 341 | 341 | // mock 数据(order) |
| 342 | 342 | PayOrderDO order = randomPojo(PayOrderDO.class, o -> o.setStatus(PayOrderStatusEnum.WAITING.getStatus()) |
| 343 | - .setAppId(1L).setExpireTime(addTime(Duration.ofDays(1)))); | |
| 343 | + .setAppId(1L).setExpireTime(addTime(Duration.ofDays(1)).withNano(0))); | |
| 344 | 344 | orderMapper.insert(order); |
| 345 | 345 | // 准备参数 |
| 346 | 346 | PayOrderSubmitReqVO reqVO = randomPojo(PayOrderSubmitReqVO.class, o -> o.setId(order.getId()) |
| ... | ... | @@ -363,11 +363,9 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { |
| 363 | 363 | when(client.unifiedOrder(argThat(payOrderUnifiedReqDTO -> { |
| 364 | 364 | assertNotNull(payOrderUnifiedReqDTO.getOutTradeNo()); |
| 365 | 365 | assertThat(payOrderUnifiedReqDTO) |
| 366 | -// .extracting("subject", "body", "notifyUrl", "returnUrl", "price", "expireTime") // TODO @芋艿:win11 下,时间不太准 | |
| 367 | - .extracting("subject", "body", "notifyUrl", "returnUrl", "price") | |
| 366 | + .extracting("subject", "body", "notifyUrl", "returnUrl", "price", "expireTime") | |
| 368 | 367 | .containsExactly(order.getSubject(), order.getBody(), "http://127.0.0.1/10", |
| 369 | -// reqVO.getReturnUrl(), order.getPrice(), order.getExpireTime()); | |
| 370 | - reqVO.getReturnUrl(), order.getPrice()); | |
| 368 | + reqVO.getReturnUrl(), order.getPrice(), order.getExpireTime()); | |
| 371 | 369 | return true; |
| 372 | 370 | }))).thenReturn(unifiedOrderResp); |
| 373 | 371 | |
| ... | ... | @@ -396,7 +394,7 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { |
| 396 | 394 | |
| 397 | 395 | // mock 数据(order) |
| 398 | 396 | PayOrderDO order = randomPojo(PayOrderDO.class, o -> o.setStatus(PayOrderStatusEnum.WAITING.getStatus()) |
| 399 | - .setAppId(1L).setExpireTime(addTime(Duration.ofDays(1)))); | |
| 397 | + .setAppId(1L).setExpireTime(addTime(Duration.ofDays(1)).withNano(0))); | |
| 400 | 398 | orderMapper.insert(order); |
| 401 | 399 | // 准备参数 |
| 402 | 400 | PayOrderSubmitReqVO reqVO = randomPojo(PayOrderSubmitReqVO.class, o -> o.setId(order.getId()) |
| ... | ... | @@ -419,11 +417,9 @@ public class PayOrderServiceTest extends BaseDbAndRedisUnitTest { |
| 419 | 417 | when(client.unifiedOrder(argThat(payOrderUnifiedReqDTO -> { |
| 420 | 418 | assertNotNull(payOrderUnifiedReqDTO.getOutTradeNo()); |
| 421 | 419 | assertThat(payOrderUnifiedReqDTO) |
| 422 | -// .extracting("subject", "body", "notifyUrl", "returnUrl", "price", "expireTime") // TODO @芋艿:win11 下,时间不太准 | |
| 423 | - .extracting("subject", "body", "notifyUrl", "returnUrl", "price") | |
| 420 | + .extracting("subject", "body", "notifyUrl", "returnUrl", "price", "expireTime") | |
| 424 | 421 | .containsExactly(order.getSubject(), order.getBody(), "http://127.0.0.1/10", |
| 425 | -// reqVO.getReturnUrl(), order.getPrice(), order.getExpireTime()); | |
| 426 | - reqVO.getReturnUrl(), order.getPrice()); | |
| 422 | + reqVO.getReturnUrl(), order.getPrice(), order.getExpireTime()); | |
| 427 | 423 | return true; |
| 428 | 424 | }))).thenReturn(unifiedOrderResp); |
| 429 | 425 | ... | ... |
yudao-module-system/src/test/java/cn/iocoder/yudao/module/system/service/oauth2/OAuth2ApproveServiceImplTest.java
| ... | ... | @@ -202,7 +202,7 @@ public class OAuth2ApproveServiceImplTest extends BaseDbUnitTest { |
| 202 | 202 | String clientId = randomString(); |
| 203 | 203 | // mock 数据 |
| 204 | 204 | OAuth2ApproveDO approve = randomPojo(OAuth2ApproveDO.class).setUserId(userId) |
| 205 | - .setUserType(userType).setClientId(clientId).setExpiresTime(LocalDateTimeUtil.offset(LocalDateTime.now(), 1L, ChronoUnit.DAYS)); | |
| 205 | + .setUserType(userType).setClientId(clientId).setExpiresTime(LocalDateTimeUtil.offset(LocalDateTime.now(), 1L, ChronoUnit.DAYS).withNano(0)); | |
| 206 | 206 | oauth2ApproveMapper.insert(approve); // 未过期 |
| 207 | 207 | oauth2ApproveMapper.insert(ObjectUtil.clone(approve).setId(null) |
| 208 | 208 | .setExpiresTime(LocalDateTimeUtil.offset(LocalDateTime.now(), -1L, ChronoUnit.DAYS))); // 已过期 |
| ... | ... | @@ -211,8 +211,7 @@ public class OAuth2ApproveServiceImplTest extends BaseDbUnitTest { |
| 211 | 211 | List<OAuth2ApproveDO> result = oauth2ApproveService.getApproveList(userId, userType, clientId); |
| 212 | 212 | // 断言 |
| 213 | 213 | assertEquals(1, result.size()); |
| 214 | - // TODO @芋艿:expiresTime 被屏蔽,仅 win11 会复现,建议后续修复。 | |
| 215 | - assertPojoEquals(approve, result.get(0), "expiresTime"); | |
| 214 | + assertPojoEquals(approve, result.get(0)); | |
| 216 | 215 | } |
| 217 | 216 | |
| 218 | 217 | @Test | ... | ... |
yudao-module-system/src/test/java/cn/iocoder/yudao/module/system/service/oauth2/OAuth2CodeServiceImplTest.java
| ... | ... | @@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2CodeDO; |
| 8 | 8 | import cn.iocoder.yudao.module.system.dal.mysql.oauth2.OAuth2CodeMapper; |
| 9 | 9 | import org.assertj.core.util.Lists; |
| 10 | 10 | import org.junit.jupiter.api.Test; |
| 11 | +import org.mockito.MockedStatic; | |
| 11 | 12 | import org.springframework.context.annotation.Import; |
| 12 | 13 | |
| 13 | 14 | import jakarta.annotation.Resource; |
| ... | ... | @@ -20,6 +21,8 @@ import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; |
| 20 | 21 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.OAUTH2_CODE_EXPIRE; |
| 21 | 22 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.OAUTH2_CODE_NOT_EXISTS; |
| 22 | 23 | import static org.junit.jupiter.api.Assertions.*; |
| 24 | +import static org.mockito.Mockito.CALLS_REAL_METHODS; | |
| 25 | +import static org.mockito.Mockito.mockStatic; | |
| 23 | 26 | |
| 24 | 27 | /** |
| 25 | 28 | * {@link OAuth2CodeServiceImpl} 的单元测试类 |
| ... | ... | @@ -44,20 +47,25 @@ class OAuth2CodeServiceImplTest extends BaseDbUnitTest { |
| 44 | 47 | List<String> scopes = Lists.newArrayList("read", "write"); |
| 45 | 48 | String redirectUri = randomString(); |
| 46 | 49 | String state = randomString(); |
| 50 | + LocalDateTime now = LocalDateTime.now().withNano(0); | |
| 47 | 51 | |
| 48 | 52 | // 调用 |
| 49 | - OAuth2CodeDO codeDO = oauth2CodeService.createAuthorizationCode(userId, userType, clientId, | |
| 50 | - scopes, redirectUri, state); | |
| 53 | + OAuth2CodeDO codeDO; | |
| 54 | + try (MockedStatic<LocalDateTime> mockedTime = mockStatic(LocalDateTime.class, CALLS_REAL_METHODS)) { | |
| 55 | + mockedTime.when(LocalDateTime::now).thenReturn(now); | |
| 56 | + codeDO = oauth2CodeService.createAuthorizationCode(userId, userType, clientId, | |
| 57 | + scopes, redirectUri, state); | |
| 58 | + } | |
| 51 | 59 | // 断言 |
| 52 | 60 | OAuth2CodeDO dbCodeDO = oauth2CodeMapper.selectByCode(codeDO.getCode()); |
| 53 | - // TODO @芋艿:expiresTime 被屏蔽,仅 win11 会复现,建议后续修复。 | |
| 54 | - assertPojoEquals(codeDO, dbCodeDO, "expiresTime", "createTime", "updateTime", "deleted"); | |
| 61 | + assertPojoEquals(codeDO, dbCodeDO, "createTime", "updateTime", "deleted"); | |
| 55 | 62 | assertEquals(userId, codeDO.getUserId()); |
| 56 | 63 | assertEquals(userType, codeDO.getUserType()); |
| 57 | 64 | assertEquals(clientId, codeDO.getClientId()); |
| 58 | 65 | assertEquals(scopes, codeDO.getScopes()); |
| 59 | 66 | assertEquals(redirectUri, codeDO.getRedirectUri()); |
| 60 | 67 | assertEquals(state, codeDO.getState()); |
| 68 | + assertEquals(now.plusMinutes(5), codeDO.getExpiresTime()); | |
| 61 | 69 | assertFalse(DateUtils.isExpired(codeDO.getExpiresTime())); |
| 62 | 70 | } |
| 63 | 71 | |
| ... | ... | @@ -88,13 +96,12 @@ class OAuth2CodeServiceImplTest extends BaseDbUnitTest { |
| 88 | 96 | String code = "test_code"; |
| 89 | 97 | // mock 数据 |
| 90 | 98 | OAuth2CodeDO codeDO = randomPojo(OAuth2CodeDO.class).setCode(code) |
| 91 | - .setExpiresTime(LocalDateTime.now().plusDays(1)); | |
| 99 | + .setExpiresTime(LocalDateTime.now().plusDays(1).withNano(0)); | |
| 92 | 100 | oauth2CodeMapper.insert(codeDO); |
| 93 | 101 | |
| 94 | 102 | // 调用 |
| 95 | 103 | OAuth2CodeDO result = oauth2CodeService.consumeAuthorizationCode(code); |
| 96 | - // TODO @芋艿:expiresTime 被屏蔽,仅 win11 会复现,建议后续修复。 | |
| 97 | - assertPojoEquals(codeDO, result, "expiresTime"); | |
| 104 | + assertPojoEquals(codeDO, result); | |
| 98 | 105 | assertNull(oauth2CodeMapper.selectByCode(code)); |
| 99 | 106 | } |
| 100 | 107 | ... | ... |
yudao-module-system/src/test/java/cn/iocoder/yudao/module/system/service/oauth2/OAuth2TokenServiceImplTest.java
| ... | ... | @@ -19,6 +19,7 @@ import cn.iocoder.yudao.module.system.service.user.AdminUserService; |
| 19 | 19 | import jakarta.annotation.Resource; |
| 20 | 20 | import org.assertj.core.util.Lists; |
| 21 | 21 | import org.junit.jupiter.api.Test; |
| 22 | +import org.mockito.MockedStatic; | |
| 22 | 23 | import org.springframework.context.annotation.Import; |
| 23 | 24 | import org.springframework.test.context.bean.override.mockito.MockitoBean; |
| 24 | 25 | |
| ... | ... | @@ -31,6 +32,8 @@ import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServic |
| 31 | 32 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; |
| 32 | 33 | import static org.junit.jupiter.api.Assertions.*; |
| 33 | 34 | import static org.mockito.ArgumentMatchers.eq; |
| 35 | +import static org.mockito.Mockito.CALLS_REAL_METHODS; | |
| 36 | +import static org.mockito.Mockito.mockStatic; | |
| 34 | 37 | import static org.mockito.Mockito.when; |
| 35 | 38 | |
| 36 | 39 | /** |
| ... | ... | @@ -65,6 +68,7 @@ public class OAuth2TokenServiceImplTest extends BaseDbAndRedisUnitTest { |
| 65 | 68 | Integer userType = UserTypeEnum.ADMIN.getValue(); |
| 66 | 69 | String clientId = randomString(); |
| 67 | 70 | List<String> scopes = Lists.newArrayList("read", "write"); |
| 71 | + LocalDateTime now = LocalDateTime.now().withNano(0); | |
| 68 | 72 | // mock 方法 |
| 69 | 73 | OAuth2ClientDO clientDO = randomPojo(OAuth2ClientDO.class).setClientId(clientId) |
| 70 | 74 | .setAccessTokenValiditySeconds(30).setRefreshTokenValiditySeconds(60); |
| ... | ... | @@ -74,11 +78,14 @@ public class OAuth2TokenServiceImplTest extends BaseDbAndRedisUnitTest { |
| 74 | 78 | when(adminUserService.getUser(userId)).thenReturn(user); |
| 75 | 79 | |
| 76 | 80 | // 调用 |
| 77 | - OAuth2AccessTokenDO accessTokenDO = oauth2TokenService.createAccessToken(userId, userType, clientId, scopes); | |
| 81 | + OAuth2AccessTokenDO accessTokenDO; | |
| 82 | + try (MockedStatic<LocalDateTime> mockedTime = mockStatic(LocalDateTime.class, CALLS_REAL_METHODS)) { | |
| 83 | + mockedTime.when(LocalDateTime::now).thenReturn(now); | |
| 84 | + accessTokenDO = oauth2TokenService.createAccessToken(userId, userType, clientId, scopes); | |
| 85 | + } | |
| 78 | 86 | // 断言访问令牌 |
| 79 | 87 | OAuth2AccessTokenDO dbAccessTokenDO = oauth2AccessTokenMapper.selectByAccessToken(accessTokenDO.getAccessToken()); |
| 80 | - // TODO @芋艿:expiresTime 被屏蔽,仅 win11 会复现,建议后续修复。 | |
| 81 | - assertPojoEquals(accessTokenDO, dbAccessTokenDO, "expiresTime", "createTime", "updateTime", "deleted"); | |
| 88 | + assertPojoEquals(accessTokenDO, dbAccessTokenDO, "createTime", "updateTime", "deleted"); | |
| 82 | 89 | assertEquals(userId, accessTokenDO.getUserId()); |
| 83 | 90 | assertEquals(userType, accessTokenDO.getUserType()); |
| 84 | 91 | assertEquals(2, accessTokenDO.getUserInfo().size()); |
| ... | ... | @@ -86,14 +93,15 @@ public class OAuth2TokenServiceImplTest extends BaseDbAndRedisUnitTest { |
| 86 | 93 | assertEquals(user.getDeptId().toString(), accessTokenDO.getUserInfo().get("deptId")); |
| 87 | 94 | assertEquals(clientId, accessTokenDO.getClientId()); |
| 88 | 95 | assertEquals(scopes, accessTokenDO.getScopes()); |
| 96 | + assertEquals(now.plusSeconds(30), accessTokenDO.getExpiresTime()); | |
| 89 | 97 | assertFalse(DateUtils.isExpired(accessTokenDO.getExpiresTime())); |
| 90 | 98 | // 断言访问令牌的缓存 |
| 91 | 99 | OAuth2AccessTokenDO redisAccessTokenDO = oauth2AccessTokenRedisDAO.get(accessTokenDO.getAccessToken()); |
| 92 | - // TODO @芋艿:expiresTime 被屏蔽,仅 win11 会复现,建议后续修复。 | |
| 93 | - assertPojoEquals(accessTokenDO, redisAccessTokenDO, "expiresTime", "createTime", "updateTime", "deleted"); | |
| 100 | + assertPojoEquals(accessTokenDO, redisAccessTokenDO, "createTime", "updateTime", "deleted"); | |
| 94 | 101 | // 断言刷新令牌 |
| 95 | 102 | OAuth2RefreshTokenDO refreshTokenDO = oauth2RefreshTokenMapper.selectList().get(0); |
| 96 | 103 | assertPojoEquals(accessTokenDO, refreshTokenDO, "id", "expiresTime", "createTime", "updateTime", "deleted"); |
| 104 | + assertEquals(now.plusSeconds(60), refreshTokenDO.getExpiresTime()); | |
| 97 | 105 | assertFalse(DateUtils.isExpired(refreshTokenDO.getExpiresTime())); |
| 98 | 106 | } |
| 99 | 107 | |
| ... | ... | @@ -153,6 +161,7 @@ public class OAuth2TokenServiceImplTest extends BaseDbAndRedisUnitTest { |
| 153 | 161 | // 准备参数 |
| 154 | 162 | String refreshToken = randomString(); |
| 155 | 163 | String clientId = randomString(); |
| 164 | + LocalDateTime now = LocalDateTime.now().withNano(0); | |
| 156 | 165 | // mock 方法 |
| 157 | 166 | OAuth2ClientDO clientDO = randomPojo(OAuth2ClientDO.class).setClientId(clientId) |
| 158 | 167 | .setAccessTokenValiditySeconds(30); |
| ... | ... | @@ -174,28 +183,31 @@ public class OAuth2TokenServiceImplTest extends BaseDbAndRedisUnitTest { |
| 174 | 183 | when(adminUserService.getUser(refreshTokenDO.getUserId())).thenReturn(user); |
| 175 | 184 | |
| 176 | 185 | // 调用 |
| 177 | - OAuth2AccessTokenDO newAccessTokenDO = oauth2TokenService.refreshAccessToken(refreshToken, clientId); | |
| 186 | + OAuth2AccessTokenDO newAccessTokenDO; | |
| 187 | + try (MockedStatic<LocalDateTime> mockedTime = mockStatic(LocalDateTime.class, CALLS_REAL_METHODS)) { | |
| 188 | + mockedTime.when(LocalDateTime::now).thenReturn(now); | |
| 189 | + newAccessTokenDO = oauth2TokenService.refreshAccessToken(refreshToken, clientId); | |
| 190 | + } | |
| 178 | 191 | // 断言,老的访问令牌被删除 |
| 179 | 192 | assertNull(oauth2AccessTokenMapper.selectByAccessToken(accessTokenDO.getAccessToken())); |
| 180 | 193 | assertNull(oauth2AccessTokenRedisDAO.get(accessTokenDO.getAccessToken())); |
| 181 | 194 | // 断言,新的访问令牌 |
| 182 | 195 | OAuth2AccessTokenDO dbAccessTokenDO = oauth2AccessTokenMapper.selectByAccessToken(newAccessTokenDO.getAccessToken()); |
| 183 | - // TODO @芋艿:expiresTime 被屏蔽,仅 win11 会复现,建议后续修复。 | |
| 184 | - assertPojoEquals(newAccessTokenDO, dbAccessTokenDO, "expiresTime", "createTime", "updateTime", "deleted"); | |
| 196 | + assertPojoEquals(newAccessTokenDO, dbAccessTokenDO, "createTime", "updateTime", "deleted"); | |
| 185 | 197 | assertPojoEquals(newAccessTokenDO, refreshTokenDO, "id", "expiresTime", "createTime", "updateTime", "deleted", |
| 186 | 198 | "creator", "updater"); |
| 199 | + assertEquals(now.plusSeconds(30), newAccessTokenDO.getExpiresTime()); | |
| 187 | 200 | assertFalse(DateUtils.isExpired(newAccessTokenDO.getExpiresTime())); |
| 188 | 201 | // 断言,新的访问令牌的缓存 |
| 189 | 202 | OAuth2AccessTokenDO redisAccessTokenDO = oauth2AccessTokenRedisDAO.get(newAccessTokenDO.getAccessToken()); |
| 190 | - // TODO @芋艿:expiresTime 被屏蔽,仅 win11 会复现,建议后续修复。 | |
| 191 | - assertPojoEquals(newAccessTokenDO, redisAccessTokenDO, "expiresTime", "createTime", "updateTime", "deleted"); | |
| 203 | + assertPojoEquals(newAccessTokenDO, redisAccessTokenDO, "createTime", "updateTime", "deleted"); | |
| 192 | 204 | } |
| 193 | 205 | |
| 194 | 206 | @Test |
| 195 | 207 | public void testGetAccessToken() { |
| 196 | 208 | // mock 数据(访问令牌) |
| 197 | 209 | OAuth2AccessTokenDO accessTokenDO = randomPojo(OAuth2AccessTokenDO.class) |
| 198 | - .setExpiresTime(LocalDateTime.now().plusDays(1)); | |
| 210 | + .setExpiresTime(LocalDateTime.now().plusDays(1).withNano(0)); | |
| 199 | 211 | oauth2AccessTokenMapper.insert(accessTokenDO); |
| 200 | 212 | // 准备参数 |
| 201 | 213 | String accessToken = accessTokenDO.getAccessToken(); |
| ... | ... | @@ -203,11 +215,9 @@ public class OAuth2TokenServiceImplTest extends BaseDbAndRedisUnitTest { |
| 203 | 215 | // 调用 |
| 204 | 216 | OAuth2AccessTokenDO result = oauth2TokenService.getAccessToken(accessToken); |
| 205 | 217 | // 断言 |
| 206 | - // TODO @芋艿:expiresTime 被屏蔽,仅 win11 会复现,建议后续修复。 | |
| 207 | - assertPojoEquals(accessTokenDO, result, "expiresTime", "createTime", "updateTime", "deleted", | |
| 218 | + assertPojoEquals(accessTokenDO, result, "createTime", "updateTime", "deleted", | |
| 208 | 219 | "creator", "updater"); |
| 209 | - // TODO @芋艿:expiresTime 被屏蔽,仅 win11 会复现,建议后续修复。 | |
| 210 | - assertPojoEquals(accessTokenDO, oauth2AccessTokenRedisDAO.get(accessToken), "expiresTime", "createTime", "updateTime", "deleted", | |
| 220 | + assertPojoEquals(accessTokenDO, oauth2AccessTokenRedisDAO.get(accessToken), "createTime", "updateTime", "deleted", | |
| 211 | 221 | "creator", "updater"); |
| 212 | 222 | } |
| 213 | 223 | |
| ... | ... | @@ -253,7 +263,7 @@ public class OAuth2TokenServiceImplTest extends BaseDbAndRedisUnitTest { |
| 253 | 263 | public void testCheckAccessToken_success() { |
| 254 | 264 | // mock 数据(访问令牌) |
| 255 | 265 | OAuth2AccessTokenDO accessTokenDO = randomPojo(OAuth2AccessTokenDO.class) |
| 256 | - .setExpiresTime(LocalDateTime.now().plusDays(1)); | |
| 266 | + .setExpiresTime(LocalDateTime.now().plusDays(1).withNano(0)); | |
| 257 | 267 | oauth2AccessTokenMapper.insert(accessTokenDO); |
| 258 | 268 | // 准备参数 |
| 259 | 269 | String accessToken = accessTokenDO.getAccessToken(); |
| ... | ... | @@ -261,8 +271,7 @@ public class OAuth2TokenServiceImplTest extends BaseDbAndRedisUnitTest { |
| 261 | 271 | // 调研,并断言 |
| 262 | 272 | OAuth2AccessTokenDO result = oauth2TokenService.getAccessToken(accessToken); |
| 263 | 273 | // 断言 |
| 264 | - // TODO @芋艿:expiresTime 被屏蔽,仅 win11 会复现,建议后续修复。 | |
| 265 | - assertPojoEquals(accessTokenDO, result, "expiresTime", "createTime", "updateTime", "deleted", | |
| 274 | + assertPojoEquals(accessTokenDO, result, "createTime", "updateTime", "deleted", | |
| 266 | 275 | "creator", "updater"); |
| 267 | 276 | } |
| 268 | 277 | |
| ... | ... | @@ -276,7 +285,7 @@ public class OAuth2TokenServiceImplTest extends BaseDbAndRedisUnitTest { |
| 276 | 285 | public void testRemoveAccessToken_success() { |
| 277 | 286 | // mock 数据(访问令牌) |
| 278 | 287 | OAuth2AccessTokenDO accessTokenDO = randomPojo(OAuth2AccessTokenDO.class) |
| 279 | - .setExpiresTime(LocalDateTime.now().plusDays(1)); | |
| 288 | + .setExpiresTime(LocalDateTime.now().plusDays(1).withNano(0)); | |
| 280 | 289 | oauth2AccessTokenMapper.insert(accessTokenDO); |
| 281 | 290 | // mock 数据(刷新令牌) |
| 282 | 291 | OAuth2RefreshTokenDO refreshTokenDO = randomPojo(OAuth2RefreshTokenDO.class) |
| ... | ... | @@ -284,8 +293,7 @@ public class OAuth2TokenServiceImplTest extends BaseDbAndRedisUnitTest { |
| 284 | 293 | oauth2RefreshTokenMapper.insert(refreshTokenDO); |
| 285 | 294 | // 调用 |
| 286 | 295 | OAuth2AccessTokenDO result = oauth2TokenService.removeAccessToken(accessTokenDO.getAccessToken()); |
| 287 | - // TODO @芋艿:expiresTime 被屏蔽,仅 win11 会复现,建议后续修复。 | |
| 288 | - assertPojoEquals(accessTokenDO, result, "expiresTime", "createTime", "updateTime", "deleted", | |
| 296 | + assertPojoEquals(accessTokenDO, result, "createTime", "updateTime", "deleted", | |
| 289 | 297 | "creator", "updater"); |
| 290 | 298 | // 断言数据 |
| 291 | 299 | assertNull(oauth2AccessTokenMapper.selectByAccessToken(accessTokenDO.getAccessToken())); |
| ... | ... | @@ -301,7 +309,7 @@ public class OAuth2TokenServiceImplTest extends BaseDbAndRedisUnitTest { |
| 301 | 309 | o.setUserId(10L); |
| 302 | 310 | o.setUserType(1); |
| 303 | 311 | o.setClientId("test_client"); |
| 304 | - o.setExpiresTime(LocalDateTime.now().plusDays(1)); | |
| 312 | + o.setExpiresTime(LocalDateTime.now().plusDays(1).withNano(0)); | |
| 305 | 313 | }); |
| 306 | 314 | oauth2AccessTokenMapper.insert(dbAccessToken); |
| 307 | 315 | // 测试 userId 不匹配 |
| ... | ... | @@ -323,8 +331,7 @@ public class OAuth2TokenServiceImplTest extends BaseDbAndRedisUnitTest { |
| 323 | 331 | // 断言 |
| 324 | 332 | assertEquals(1, pageResult.getTotal()); |
| 325 | 333 | assertEquals(1, pageResult.getList().size()); |
| 326 | - // TODO @芋艿:expiresTime 被屏蔽,仅 win11 会复现,建议后续修复。 | |
| 327 | - assertPojoEquals(dbAccessToken, pageResult.getList().get(0), "expiresTime"); | |
| 334 | + assertPojoEquals(dbAccessToken, pageResult.getList().get(0)); | |
| 328 | 335 | } |
| 329 | 336 | |
| 330 | 337 | } | ... | ... |