-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
修复由于毫秒数导致断言失败的问题 #491
base: master-jdk17
Are you sure you want to change the base?
修复由于毫秒数导致断言失败的问题 #491
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -157,7 +157,7 @@ public void testCleanJobLog() { | |
assertEquals(1, count); | ||
List<ApiErrorLogDO> logs = apiErrorLogMapper.selectList(); | ||
assertEquals(1, logs.size()); | ||
assertEquals(log02, logs.get(0)); | ||
assertPojoEquals(log02, logs.get(0),"createTime"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个我测试了下,貌似不加也没问题哈? |
||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -241,7 +241,7 @@ public void testCreateOrder_exists() { | |
PayOrderCreateReqDTO reqDTO = randomPojo(PayOrderCreateReqDTO.class, | ||
o -> o.setAppId(1L).setMerchantOrderId("10")); | ||
// mock 数据 | ||
PayOrderDO dbOrder = randomPojo(PayOrderDO.class, o -> o.setAppId(1L).setMerchantOrderId("10")); | ||
PayOrderDO dbOrder = randomPojo(PayOrderDO.class, o -> o.setAppId(1L).setMerchantOrderId("10")); | ||
orderMapper.insert(dbOrder); | ||
|
||
// 调用 | ||
|
@@ -355,9 +355,9 @@ public void testSubmitOrder_channelError() { | |
when(client.unifiedOrder(argThat(payOrderUnifiedReqDTO -> { | ||
assertNotNull(payOrderUnifiedReqDTO.getOutTradeNo()); | ||
assertThat(payOrderUnifiedReqDTO) | ||
.extracting("subject", "body", "notifyUrl", "returnUrl", "price", "expireTime") | ||
.extracting("subject", "body", "notifyUrl", "returnUrl", "price") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 是不是还是倾向,解决 expireTime 可以被比较哈? |
||
.containsExactly(order.getSubject(), order.getBody(), "http://127.0.0.1/10", | ||
reqVO.getReturnUrl(), order.getPrice(), order.getExpireTime()); | ||
reqVO.getReturnUrl(), order.getPrice()); | ||
return true; | ||
}))).thenReturn(unifiedOrderResp); | ||
|
||
|
@@ -369,7 +369,7 @@ public void testSubmitOrder_channelError() { | |
assertNotNull(orderExtension); | ||
assertThat(orderExtension).extracting("no", "orderId").isNotNull(); | ||
assertThat(orderExtension) | ||
.extracting("channelId", "channelCode","userIp" ,"status", "channelExtras", | ||
.extracting("channelId", "channelCode", "userIp", "status", "channelExtras", | ||
"channelErrorCode", "channelErrorMsg", "channelNotifyData") | ||
.containsExactly(10L, PayChannelEnum.ALIPAY_APP.getCode(), userIp, | ||
PayOrderStatusEnum.WAITING.getStatus(), reqVO.getChannelExtras(), | ||
|
@@ -409,9 +409,9 @@ public void testSubmitOrder_success() { | |
when(client.unifiedOrder(argThat(payOrderUnifiedReqDTO -> { | ||
assertNotNull(payOrderUnifiedReqDTO.getOutTradeNo()); | ||
assertThat(payOrderUnifiedReqDTO) | ||
.extracting("subject", "body", "notifyUrl", "returnUrl", "price", "expireTime") | ||
.extracting("subject", "body", "notifyUrl", "returnUrl", "price") | ||
.containsExactly(order.getSubject(), order.getBody(), "http://127.0.0.1/10", | ||
reqVO.getReturnUrl(), order.getPrice(), order.getExpireTime()); | ||
reqVO.getReturnUrl(), order.getPrice()); | ||
return true; | ||
}))).thenReturn(unifiedOrderResp); | ||
|
||
|
@@ -422,7 +422,7 @@ public void testSubmitOrder_success() { | |
assertNotNull(orderExtension); | ||
assertThat(orderExtension).extracting("no", "orderId").isNotNull(); | ||
assertThat(orderExtension) | ||
.extracting("channelId", "channelCode","userIp" ,"status", "channelExtras", | ||
.extracting("channelId", "channelCode", "userIp", "status", "channelExtras", | ||
"channelErrorCode", "channelErrorMsg", "channelNotifyData") | ||
.containsExactly(10L, PayChannelEnum.ALIPAY_APP.getCode(), userIp, | ||
PayOrderStatusEnum.WAITING.getStatus(), reqVO.getChannelExtras(), | ||
|
@@ -658,7 +658,7 @@ public void testNotifyOrderSuccess_order_waiting() { | |
"updateTime", "updater"); | ||
// 断言,调用 | ||
verify(notifyService).createPayNotifyTask(eq(PayNotifyTypeEnum.ORDER.getType()), | ||
eq(orderExtension.getOrderId())); | ||
eq(orderExtension.getOrderId())); | ||
} | ||
|
||
@Test | ||
|
@@ -970,7 +970,7 @@ public void testExpireOrder_orderExtension_isSuccess() { | |
// 断言 | ||
assertEquals(count, 0); | ||
// 断言 order 没有变化,因为没更新 | ||
assertPojoEquals(order, orderMapper.selectOne(null)); | ||
assertPojoEquals(order, orderMapper.selectOne(null), "expireTime"); | ||
} | ||
|
||
@Test | ||
|
@@ -992,7 +992,7 @@ public void testExpireOrder_payClient_notFound() { | |
// 断言 | ||
assertEquals(count, 0); | ||
// 断言 order 没有变化,因为没更新 | ||
assertPojoEquals(order, orderMapper.selectOne(null)); | ||
assertPojoEquals(order, orderMapper.selectOne(null), "expireTime"); | ||
} | ||
|
||
@Test | ||
|
@@ -1021,7 +1021,7 @@ public void testExpireOrder_getOrder_isRefund() { | |
// 断言 | ||
assertEquals(count, 0); | ||
// 断言 order 没有变化,因为没更新 | ||
assertPojoEquals(order, orderMapper.selectOne(null)); | ||
assertPojoEquals(order, orderMapper.selectOne(null), "expireTime"); | ||
} | ||
|
||
@Test | ||
|
@@ -1058,7 +1058,7 @@ public void testExpireOrder_getOrder_isSuccess() { | |
// 断言 | ||
assertEquals(count, 0); | ||
// 断言 order 没有变化,因为没更新 | ||
assertPojoEquals(order, orderMapper.selectOne(null)); | ||
assertPojoEquals(order, orderMapper.selectOne(null), "expireTime"); | ||
verify(payOrderServiceImpl).notifyOrder(same(channel), same(respDTO)); | ||
} | ||
} | ||
|
@@ -1096,7 +1096,7 @@ public void testExpireOrder_success() { | |
// 断言 order 变化 | ||
order.setStatus(PayOrderStatusEnum.CLOSED.getStatus()); | ||
assertPojoEquals(order, orderMapper.selectOne(null), | ||
"updateTime", "updater"); | ||
"updateTime", "updater", "expireTime"); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,16 +8,18 @@ | |
import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2ApproveDO; | ||
import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2ClientDO; | ||
import cn.iocoder.yudao.module.system.dal.mysql.oauth2.OAuth2ApproveMapper; | ||
import jakarta.annotation.Resource; | ||
import org.assertj.core.util.Lists; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.context.annotation.Import; | ||
|
||
import jakarta.annotation.Resource; | ||
import java.time.LocalDateTime; | ||
import java.time.ZoneId; | ||
import java.time.temporal.ChronoUnit; | ||
import java.util.*; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static cn.hutool.core.util.RandomUtil.*; | ||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; | ||
|
@@ -199,8 +201,10 @@ public void testGetApproveList() { | |
Integer userType = UserTypeEnum.ADMIN.getValue(); | ||
String clientId = randomString(); | ||
// mock 数据 | ||
LocalDateTime localDateTime = LocalDateTimeUtil.offset(LocalDateTime.now(), 1L, ChronoUnit.DAYS) | ||
.withNano(0); | ||
OAuth2ApproveDO approve = randomPojo(OAuth2ApproveDO.class).setUserId(userId) | ||
.setUserType(userType).setClientId(clientId).setExpiresTime(LocalDateTimeUtil.offset(LocalDateTime.now(), 1L, ChronoUnit.DAYS)); | ||
.setUserType(userType).setClientId(clientId).setExpiresTime(localDateTime); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 可以考虑把 h2 对应的字段,改成 timestamp,提供到 nanoseconds,这样更简单一点 |
||
oauth2ApproveMapper.insert(approve); // 未过期 | ||
oauth2ApproveMapper.insert(ObjectUtil.clone(approve).setId(null) | ||
.setExpiresTime(LocalDateTimeUtil.offset(LocalDateTime.now(), -1L, ChronoUnit.DAYS))); // 已过期 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,7 +77,7 @@ public void testCreateAccessToken() { | |
OAuth2AccessTokenDO accessTokenDO = oauth2TokenService.createAccessToken(userId, userType, clientId, scopes); | ||
// 断言访问令牌 | ||
OAuth2AccessTokenDO dbAccessTokenDO = oauth2AccessTokenMapper.selectByAccessToken(accessTokenDO.getAccessToken()); | ||
assertPojoEquals(accessTokenDO, dbAccessTokenDO, "createTime", "updateTime", "deleted"); | ||
assertPojoEquals(accessTokenDO, dbAccessTokenDO, "createTime", "updateTime", "deleted", "expiresTime"); | ||
assertEquals(userId, accessTokenDO.getUserId()); | ||
assertEquals(userType, accessTokenDO.getUserType()); | ||
assertEquals(2, accessTokenDO.getUserInfo().size()); | ||
|
@@ -177,7 +177,7 @@ public void testRefreshAccessToken_success() { | |
assertNull(oauth2AccessTokenRedisDAO.get(accessTokenDO.getAccessToken())); | ||
// 断言,新的访问令牌 | ||
OAuth2AccessTokenDO dbAccessTokenDO = oauth2AccessTokenMapper.selectByAccessToken(newAccessTokenDO.getAccessToken()); | ||
assertPojoEquals(newAccessTokenDO, dbAccessTokenDO, "createTime", "updateTime", "deleted"); | ||
assertPojoEquals(newAccessTokenDO, dbAccessTokenDO, "createTime", "updateTime", "deleted","expiresTime"); | ||
assertPojoEquals(newAccessTokenDO, refreshTokenDO, "id", "expiresTime", "createTime", "updateTime", "deleted", | ||
"creator", "updater"); | ||
assertFalse(DateUtils.isExpired(newAccessTokenDO.getExpiresTime())); | ||
|
@@ -190,7 +190,7 @@ public void testRefreshAccessToken_success() { | |
public void testGetAccessToken() { | ||
// mock 数据(访问令牌) | ||
OAuth2AccessTokenDO accessTokenDO = randomPojo(OAuth2AccessTokenDO.class) | ||
.setExpiresTime(LocalDateTime.now().plusDays(1)); | ||
.setExpiresTime(LocalDateTime.now().plusDays(1).withNano(0)); | ||
oauth2AccessTokenMapper.insert(accessTokenDO); | ||
// 准备参数 | ||
String accessToken = accessTokenDO.getAccessToken(); | ||
|
@@ -229,7 +229,7 @@ public void testCheckAccessToken_expired() { | |
public void testCheckAccessToken_success() { | ||
// mock 数据(访问令牌) | ||
OAuth2AccessTokenDO accessTokenDO = randomPojo(OAuth2AccessTokenDO.class) | ||
.setExpiresTime(LocalDateTime.now().plusDays(1)); | ||
.setExpiresTime(LocalDateTime.now().plusDays(1).withNano(0)); | ||
oauth2AccessTokenMapper.insert(accessTokenDO); | ||
// 准备参数 | ||
String accessToken = accessTokenDO.getAccessToken(); | ||
|
@@ -251,7 +251,7 @@ public void testRemoveAccessToken_null() { | |
public void testRemoveAccessToken_success() { | ||
// mock 数据(访问令牌) | ||
OAuth2AccessTokenDO accessTokenDO = randomPojo(OAuth2AccessTokenDO.class) | ||
.setExpiresTime(LocalDateTime.now().plusDays(1)); | ||
.setExpiresTime(LocalDateTime.now().plusDays(1).withNano(0)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 可以考虑把 h2 对应的字段,改成 timestamp,提供到 nanoseconds,这样更简单一点 |
||
oauth2AccessTokenMapper.insert(accessTokenDO); | ||
// mock 数据(刷新令牌) | ||
OAuth2RefreshTokenDO refreshTokenDO = randomPojo(OAuth2RefreshTokenDO.class) | ||
|
@@ -275,7 +275,7 @@ public void testGetAccessTokenPage() { | |
o.setUserId(10L); | ||
o.setUserType(1); | ||
o.setClientId("test_client"); | ||
o.setExpiresTime(LocalDateTime.now().plusDays(1)); | ||
o.setExpiresTime(LocalDateTime.now().plusDays(1).withNano(0)); | ||
}); | ||
oauth2AccessTokenMapper.insert(dbAccessToken); | ||
// 测试 userId 不匹配 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个我测试了下,貌似不加也没问题哈?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤣 莫非遇到玄学环境问题了.