mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
资金管理移除充值相关内容、新增优惠活动相关接口、软件购买增加对应产品的优惠活动赠送时间
This commit is contained in:
-87
@@ -1,87 +0,0 @@
|
||||
package com.cf.imes.module.system.controller.admin.funds.manualadjust;
|
||||
|
||||
import com.cf.imes.framework.common.pojo.PageResult;
|
||||
import com.cf.imes.module.system.controller.admin.funds.manualadjust.vo.ManualAdjustAccountBalancePageReqVO;
|
||||
import com.cf.imes.module.system.controller.admin.funds.manualadjust.vo.ManualAdjustAccountBalanceRespVO;
|
||||
import com.cf.imes.module.system.controller.admin.funds.manualadjust.vo.ManualAdjustAccountBalanceSaveReqVO;
|
||||
import com.cf.imes.module.system.enums.pay.AdjustTypeEnum;
|
||||
import com.cf.imes.module.system.service.funds.manualadjust.ManualAdjustAccountBalanceService;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
/**
|
||||
* @author Gqr
|
||||
* @since 2025/10/27 14:31
|
||||
*/
|
||||
@WebMvcTest(controllers = ManualAdjustAccountBalanceController.class, excludeAutoConfiguration = SecurityAutoConfiguration.class)
|
||||
public class ManualAdjustAccountBalanceControllerTest {
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@MockitoBean
|
||||
private ManualAdjustAccountBalanceService manualAdjustAccountBalanceService;
|
||||
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@Test
|
||||
void testCreateAjustment() throws Exception {
|
||||
ManualAdjustAccountBalanceSaveReqVO reqVO = new ManualAdjustAccountBalanceSaveReqVO();
|
||||
reqVO.setOrganId(1L);
|
||||
reqVO.setAdjustType(1);
|
||||
reqVO.setRechargeAmount(new BigDecimal("100"));
|
||||
reqVO.setGiftAmount(new BigDecimal("20"));
|
||||
|
||||
when(manualAdjustAccountBalanceService.createAjustment(any())).thenReturn(123L);
|
||||
|
||||
mockMvc.perform(put("/system/balance/manualadjust")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(objectMapper.writeValueAsString(reqVO)))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.data").value(123));
|
||||
|
||||
verify(manualAdjustAccountBalanceService).createAjustment(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetAdjustPage() throws Exception {
|
||||
ManualAdjustAccountBalancePageReqVO pageReqVO = new ManualAdjustAccountBalancePageReqVO();
|
||||
pageReqVO.setPageNo(1);
|
||||
pageReqVO.setPageSize(10);
|
||||
|
||||
ManualAdjustAccountBalanceRespVO respVO = new ManualAdjustAccountBalanceRespVO();
|
||||
respVO.setOrganName("测试组织");
|
||||
respVO.setAdjustType(AdjustTypeEnum.INCREASE.getType());
|
||||
|
||||
PageResult<ManualAdjustAccountBalanceRespVO> pageResult = new PageResult<>(
|
||||
Collections.singletonList(respVO), 1L);
|
||||
|
||||
when(manualAdjustAccountBalanceService.getPage(any())).thenReturn(pageResult);
|
||||
|
||||
mockMvc.perform(get("/system/balance/manualadjust/page")
|
||||
.param("pageNo", "1")
|
||||
.param("pageSize", "10"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.data.list[0].organName").value("测试组织"))
|
||||
.andExpect(jsonPath("$.data.total").value(1));
|
||||
|
||||
verify(manualAdjustAccountBalanceService).getPage(any());
|
||||
}
|
||||
}
|
||||
+164
@@ -0,0 +1,164 @@
|
||||
//package com.cf.imes.module.system.controller.admin.funds.recharge;
|
||||
//
|
||||
//import com.cf.imes.framework.common.pojo.PageResult;
|
||||
//import com.cf.imes.module.system.controller.admin.funds.recharge.vo.RechargePageReqVO;
|
||||
//import com.cf.imes.module.system.controller.admin.funds.recharge.vo.RechargeSaveReqVO;
|
||||
//import com.cf.imes.module.system.dal.dataobject.funds.recharge.GiftMoneyDetailsDO;
|
||||
//import com.cf.imes.module.system.enums.recharge.RechargeGiftTypeEnum;
|
||||
//import com.cf.imes.module.system.enums.recharge.RechargeTypeEnum;
|
||||
//import com.cf.imes.module.system.service.funds.recharge.RechargeActiveService;
|
||||
//import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
//import org.junit.jupiter.api.Test;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
|
||||
//import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
//import org.springframework.http.MediaType;
|
||||
//import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||
//import org.springframework.test.web.servlet.MockMvc;
|
||||
//
|
||||
//import java.math.BigDecimal;
|
||||
//import java.time.LocalDateTime;
|
||||
//import java.util.List;
|
||||
//
|
||||
//import static org.mockito.ArgumentMatchers.any;
|
||||
//import static org.mockito.ArgumentMatchers.anyLong;
|
||||
//import static org.mockito.Mockito.doNothing;
|
||||
//import static org.mockito.Mockito.times;
|
||||
//import static org.mockito.Mockito.verify;
|
||||
//import static org.mockito.Mockito.when;
|
||||
//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
||||
//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
|
||||
//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
//
|
||||
///**
|
||||
// * @author Gqr
|
||||
// * @since 2025/10/27 9:29
|
||||
// */
|
||||
//@WebMvcTest(controllers = RechargeActiveController.class, excludeAutoConfiguration = SecurityAutoConfiguration.class)
|
||||
//class RechargeActiveControllerTest {
|
||||
// @Autowired
|
||||
// private MockMvc mockMvc;
|
||||
//
|
||||
// @MockitoBean
|
||||
// private RechargeActiveService rechargeActiveService;
|
||||
//
|
||||
// @Autowired
|
||||
// private ObjectMapper objectMapper;
|
||||
//
|
||||
// @Test
|
||||
// void testCreateRechargeActive() throws Exception {
|
||||
// RechargeSaveReqVO vo = new RechargeSaveReqVO();
|
||||
// vo.setActivityName("充值活动");
|
||||
// vo.setRechargeGiftType(RechargeGiftTypeEnum.EVERY_X_GIVE_X.getStatus());
|
||||
// vo.setRechargeType(RechargeTypeEnum.ALIPAY.getStatus());
|
||||
// vo.setRechargeAmount(BigDecimal.valueOf(100));
|
||||
// vo.setGiftAmount(BigDecimal.valueOf(100));
|
||||
// LocalDateTime now = LocalDateTime.now();
|
||||
// vo.setStartTime(now);
|
||||
// vo.setEndTime(now);
|
||||
//
|
||||
// // mock Service 返回
|
||||
// when(rechargeActiveService.create(any())).thenReturn(100L);
|
||||
//
|
||||
// mockMvc.perform(put("/system/recharge-active")
|
||||
// .contentType(MediaType.APPLICATION_JSON)
|
||||
// .content(objectMapper.writeValueAsString(vo)))
|
||||
// .andExpect(status().isOk())
|
||||
// .andExpect(jsonPath("$.data").value(100));
|
||||
//
|
||||
// // 验证 Service 调用
|
||||
// verify(rechargeActiveService, times(1)).create(any());
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// void testUpdateRechargeActive() throws Exception {
|
||||
// RechargeSaveReqVO vo = new RechargeSaveReqVO();
|
||||
// vo.setId(1L);
|
||||
// vo.setActivityName("更新充值活动");
|
||||
// vo.setRechargeGiftType(RechargeGiftTypeEnum.EVERY_X_GIVE_X.getStatus());
|
||||
// vo.setRechargeType(RechargeTypeEnum.ALIPAY.getStatus());
|
||||
// vo.setRechargeAmount(BigDecimal.valueOf(100));
|
||||
// vo.setGiftAmount(BigDecimal.valueOf(100));
|
||||
// LocalDateTime now = LocalDateTime.now();
|
||||
// vo.setStartTime(now);
|
||||
// vo.setEndTime(now);
|
||||
//
|
||||
// // mock Service 返回
|
||||
// doNothing().when(rechargeActiveService).update(any());
|
||||
//
|
||||
// mockMvc.perform(post("/system/recharge-active")
|
||||
// .contentType(MediaType.APPLICATION_JSON)
|
||||
// .content(objectMapper.writeValueAsString(vo)))
|
||||
// .andExpect(status().isOk())
|
||||
// .andExpect(jsonPath("$.data").value(true));
|
||||
//
|
||||
// // 验证 Service 调用
|
||||
// verify(rechargeActiveService, times(1)).update(any());
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// void testDeleteRechargeActive() throws Exception {
|
||||
// Long id = 3L;
|
||||
// doNothing().when(rechargeActiveService).delete(anyLong());
|
||||
//
|
||||
// mockMvc.perform(delete("/system/recharge-active/{id}", id))
|
||||
// .andExpect(status().isOk())
|
||||
// .andExpect(jsonPath("$.data").value(true));
|
||||
//
|
||||
// verify(rechargeActiveService, times(1)).delete(id);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// void testGetRechargeActive() throws Exception {
|
||||
// Long id = 123L;
|
||||
// GiftMoneyDetailsDO mockDO = new GiftMoneyDetailsDO()
|
||||
// .setId(id);
|
||||
// when(rechargeActiveService.get(id)).thenReturn(mockDO);
|
||||
//
|
||||
// mockMvc.perform(get("/system/recharge-active/{id}", id))
|
||||
// .andExpect(status().isOk())
|
||||
// .andExpect(jsonPath("$.data.id").value(123L));
|
||||
//
|
||||
// verify(rechargeActiveService, times(1)).get(id);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// void testGetRechargeActivePage() throws Exception {
|
||||
// RechargePageReqVO reqVO = new RechargePageReqVO();
|
||||
// PageResult<GiftMoneyDetailsDO> mockPage = new PageResult<>();
|
||||
// mockPage.setTotal(1L);
|
||||
// mockPage.setList(List.of(new GiftMoneyDetailsDO().setId(1L)));
|
||||
// when(rechargeActiveService.getPage(any())).thenReturn(mockPage);
|
||||
//
|
||||
// mockMvc.perform(get("/system/recharge-active/page")
|
||||
// .contentType(MediaType.APPLICATION_JSON)
|
||||
// .content(objectMapper.writeValueAsString(reqVO)))
|
||||
// .andExpect(status().isOk())
|
||||
// .andExpect(jsonPath("$.data.list[0].id").value(1L));
|
||||
//
|
||||
// verify(rechargeActiveService, times(1)).getPage(any());
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// void testGetAvailableRechargeActivePage_success() throws Exception {
|
||||
// // 模拟 service 返回数据
|
||||
// GiftMoneyDetailsDO mockDO = new GiftMoneyDetailsDO();
|
||||
// mockDO.setId(1L);
|
||||
// mockDO.setRechargeAmount(new BigDecimal("50.00"));
|
||||
// mockDO.setActivityName("新人充值活动");
|
||||
//
|
||||
// when(rechargeActiveService.getAvailableRechargeActiveList())
|
||||
// .thenReturn(List.of(mockDO));
|
||||
//
|
||||
// // 发起请求
|
||||
// mockMvc.perform(get("/system/recharge-active/available")
|
||||
// .contentType(MediaType.APPLICATION_JSON))
|
||||
// .andExpect(status().isOk())
|
||||
// .andExpect(jsonPath("$.code").value(0)) // CommonResult.success 通常 code=0
|
||||
// .andExpect(jsonPath("$.data[0].activityName").value("新人充值活动"))
|
||||
// .andExpect(jsonPath("$.data[0].rechargeAmount").value(50.00));
|
||||
// }
|
||||
//}
|
||||
-164
@@ -1,164 +0,0 @@
|
||||
package com.cf.imes.module.system.controller.admin.funds.recharge;
|
||||
|
||||
import com.cf.imes.framework.common.pojo.PageResult;
|
||||
import com.cf.imes.module.system.controller.admin.funds.recharge.vo.RechargePageReqVO;
|
||||
import com.cf.imes.module.system.controller.admin.funds.recharge.vo.RechargeSaveReqVO;
|
||||
import com.cf.imes.module.system.dal.dataobject.funds.recharge.GiftMoneyDetailsDO;
|
||||
import com.cf.imes.module.system.enums.recharge.RechargeGiftTypeEnum;
|
||||
import com.cf.imes.module.system.enums.recharge.RechargeTypeEnum;
|
||||
import com.cf.imes.module.system.service.funds.recharge.RechargeActiveService;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
/**
|
||||
* @author Gqr
|
||||
* @since 2025/10/27 9:29
|
||||
*/
|
||||
@WebMvcTest(controllers = RechargeActiveController.class, excludeAutoConfiguration = SecurityAutoConfiguration.class)
|
||||
class RechargeActiveControllerTest {
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@MockitoBean
|
||||
private RechargeActiveService rechargeActiveService;
|
||||
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@Test
|
||||
void testCreateRechargeActive() throws Exception {
|
||||
RechargeSaveReqVO vo = new RechargeSaveReqVO();
|
||||
vo.setActivityName("充值活动");
|
||||
vo.setRechargeGiftType(RechargeGiftTypeEnum.EVERY_X_GIVE_X.getStatus());
|
||||
vo.setRechargeType(RechargeTypeEnum.ALIPAY.getStatus());
|
||||
vo.setRechargeAmount(BigDecimal.valueOf(100));
|
||||
vo.setGiftAmount(BigDecimal.valueOf(100));
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
vo.setStartTime(now);
|
||||
vo.setEndTime(now);
|
||||
|
||||
// mock Service 返回
|
||||
when(rechargeActiveService.create(any())).thenReturn(100L);
|
||||
|
||||
mockMvc.perform(put("/system/recharge-active")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(objectMapper.writeValueAsString(vo)))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.data").value(100));
|
||||
|
||||
// 验证 Service 调用
|
||||
verify(rechargeActiveService, times(1)).create(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUpdateRechargeActive() throws Exception {
|
||||
RechargeSaveReqVO vo = new RechargeSaveReqVO();
|
||||
vo.setId(1L);
|
||||
vo.setActivityName("更新充值活动");
|
||||
vo.setRechargeGiftType(RechargeGiftTypeEnum.EVERY_X_GIVE_X.getStatus());
|
||||
vo.setRechargeType(RechargeTypeEnum.ALIPAY.getStatus());
|
||||
vo.setRechargeAmount(BigDecimal.valueOf(100));
|
||||
vo.setGiftAmount(BigDecimal.valueOf(100));
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
vo.setStartTime(now);
|
||||
vo.setEndTime(now);
|
||||
|
||||
// mock Service 返回
|
||||
doNothing().when(rechargeActiveService).update(any());
|
||||
|
||||
mockMvc.perform(post("/system/recharge-active")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(objectMapper.writeValueAsString(vo)))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.data").value(true));
|
||||
|
||||
// 验证 Service 调用
|
||||
verify(rechargeActiveService, times(1)).update(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeleteRechargeActive() throws Exception {
|
||||
Long id = 3L;
|
||||
doNothing().when(rechargeActiveService).delete(anyLong());
|
||||
|
||||
mockMvc.perform(delete("/system/recharge-active/{id}", id))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.data").value(true));
|
||||
|
||||
verify(rechargeActiveService, times(1)).delete(id);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetRechargeActive() throws Exception {
|
||||
Long id = 123L;
|
||||
GiftMoneyDetailsDO mockDO = new GiftMoneyDetailsDO()
|
||||
.setId(id);
|
||||
when(rechargeActiveService.get(id)).thenReturn(mockDO);
|
||||
|
||||
mockMvc.perform(get("/system/recharge-active/{id}", id))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.data.id").value(123L));
|
||||
|
||||
verify(rechargeActiveService, times(1)).get(id);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetRechargeActivePage() throws Exception {
|
||||
RechargePageReqVO reqVO = new RechargePageReqVO();
|
||||
PageResult<GiftMoneyDetailsDO> mockPage = new PageResult<>();
|
||||
mockPage.setTotal(1L);
|
||||
mockPage.setList(List.of(new GiftMoneyDetailsDO().setId(1L)));
|
||||
when(rechargeActiveService.getPage(any())).thenReturn(mockPage);
|
||||
|
||||
mockMvc.perform(get("/system/recharge-active/page")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(objectMapper.writeValueAsString(reqVO)))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.data.list[0].id").value(1L));
|
||||
|
||||
verify(rechargeActiveService, times(1)).getPage(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetAvailableRechargeActivePage_success() throws Exception {
|
||||
// 模拟 service 返回数据
|
||||
GiftMoneyDetailsDO mockDO = new GiftMoneyDetailsDO();
|
||||
mockDO.setId(1L);
|
||||
mockDO.setRechargeAmount(new BigDecimal("50.00"));
|
||||
mockDO.setActivityName("新人充值活动");
|
||||
|
||||
when(rechargeActiveService.getAvailableRechargeActiveList())
|
||||
.thenReturn(List.of(mockDO));
|
||||
|
||||
// 发起请求
|
||||
mockMvc.perform(get("/system/recharge-active/available")
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(0)) // CommonResult.success 通常 code=0
|
||||
.andExpect(jsonPath("$.data[0].activityName").value("新人充值活动"))
|
||||
.andExpect(jsonPath("$.data[0].rechargeAmount").value(50.00));
|
||||
}
|
||||
}
|
||||
-55
@@ -1,55 +0,0 @@
|
||||
package com.cf.imes.module.system.controller.admin.funds.recharge;
|
||||
|
||||
import com.cf.imes.module.system.controller.admin.funds.recharge.vo.RechargeDetailsBalanceInfoRespVO;
|
||||
import com.cf.imes.module.system.service.funds.recharge.RechargeDetailsService;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
|
||||
/**
|
||||
* @author Gqr
|
||||
* @since 2025/10/27 10:56
|
||||
*/
|
||||
@WebMvcTest(controllers = RechargeDetailsController.class, excludeAutoConfiguration = SecurityAutoConfiguration.class)
|
||||
class RechargeDetailsControllerTest {
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@MockitoBean
|
||||
private RechargeDetailsService rechargeDetailsService;
|
||||
|
||||
@Test
|
||||
void testGetManageRechargeDetailsBalanceInfo_success() throws Exception {
|
||||
// 构造 mock 返回对象
|
||||
RechargeDetailsBalanceInfoRespVO respVO = new RechargeDetailsBalanceInfoRespVO();
|
||||
respVO.setRechargeAmount(new BigDecimal("100.00"));
|
||||
respVO.setRechargeUsageAmount(new BigDecimal("60.00"));
|
||||
|
||||
when(rechargeDetailsService.getManageRechargeDetailsBalanceInfo()).thenReturn(respVO);
|
||||
|
||||
// 执行 GET /recharge/balance
|
||||
mockMvc.perform(get("/system/rechargeDetails/balance")
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(0)) // CommonResult.success 通常 code = 0
|
||||
.andExpect(jsonPath("$.data.rechargeAmount").value(100.00))
|
||||
.andExpect(jsonPath("$.data.rechargeUsageAmount").value(60.00));
|
||||
|
||||
// 验证 Service 调用
|
||||
verify(rechargeDetailsService, times(1)).getManageRechargeDetailsBalanceInfo();
|
||||
}
|
||||
}
|
||||
-295
@@ -1,295 +0,0 @@
|
||||
package com.cf.imes.module.system.service.funds.manualadjust;
|
||||
|
||||
import com.cf.imes.framework.common.pojo.PageResult;
|
||||
import com.cf.imes.framework.id.core.util.SnowflakeSerialNoWorker3rd;
|
||||
import com.cf.imes.framework.test.core.ut.BaseDbAndRedisUnitTest;
|
||||
import com.cf.imes.module.system.controller.admin.funds.manualadjust.vo.ManualAdjustAccountBalancePageReqVO;
|
||||
import com.cf.imes.module.system.controller.admin.funds.manualadjust.vo.ManualAdjustAccountBalanceRespVO;
|
||||
import com.cf.imes.module.system.controller.admin.funds.manualadjust.vo.ManualAdjustAccountBalanceSaveReqVO;
|
||||
import com.cf.imes.module.system.controller.admin.funds.organamount.vo.OrganRechargeAmountRespVO;
|
||||
import com.cf.imes.module.system.dal.dataobject.funds.organamount.OrganAmountDO;
|
||||
import com.cf.imes.module.system.dal.dataobject.incomeandexpense.IncomeExpenseDetailsDO;
|
||||
import com.cf.imes.module.system.dal.dataobject.organ.OrganizationDO;
|
||||
import com.cf.imes.module.system.dal.dataobject.pay.PayOrderDO;
|
||||
import com.cf.imes.module.system.enums.pay.AdjustTypeEnum;
|
||||
import com.cf.imes.module.system.framework.snowflake.config.MybatisIdProperties;
|
||||
import com.cf.imes.module.system.service.funds.incomeandexpense.IncomeExpenseService;
|
||||
import com.cf.imes.module.system.service.funds.organamount.OrganAmountService;
|
||||
import com.cf.imes.module.system.service.organ.OrganService;
|
||||
import com.cf.imes.module.system.service.pay.PayOrderService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Collections;
|
||||
|
||||
import static com.cf.imes.framework.test.core.util.AssertUtils.assertServiceException;
|
||||
import static com.cf.imes.module.system.enums.ErrorCodeConstants.ORGAMOUNT_GIFT_INSUFFICIENT_ERROR;
|
||||
import static com.cf.imes.module.system.enums.ErrorCodeConstants.ORGAMOUNT_RECHARGE_INSUFFICIENT_ERROR;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* @author Gqr
|
||||
* @since 2025/10/27 11:57
|
||||
*/
|
||||
@Import(ManualAdjustAccountBalanceServiceImpl.class)
|
||||
public class ManualAdjustAccountBalanceServiceImplTest extends BaseDbAndRedisUnitTest {
|
||||
@Resource
|
||||
private ManualAdjustAccountBalanceService manualAdjustAccountBalanceService;
|
||||
|
||||
@MockitoBean
|
||||
private OrganService organService;
|
||||
|
||||
@MockitoBean
|
||||
private OrganAmountService organAmountService;
|
||||
|
||||
@MockitoBean
|
||||
private IncomeExpenseService incomeExpenseService;
|
||||
|
||||
@MockitoBean
|
||||
private MybatisIdProperties mybatisIdProperties;
|
||||
|
||||
@MockitoBean
|
||||
private PayOrderService payOrderService;
|
||||
|
||||
@MockitoBean
|
||||
private SnowflakeSerialNoWorker3rd snowflakeSerialNoWorker3rd;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
when(mybatisIdProperties.getWorkerId()).thenReturn(1L);
|
||||
when(mybatisIdProperties.getDatacenterId()).thenReturn(1L);
|
||||
when(snowflakeSerialNoWorker3rd.nextSerialNo()).thenReturn("SN-001");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreateAdjustment_Increase() {
|
||||
// 模拟请求参数(调增)
|
||||
ManualAdjustAccountBalanceSaveReqVO reqVO = new ManualAdjustAccountBalanceSaveReqVO();
|
||||
reqVO.setOrganId(100L);
|
||||
reqVO.setAdjustType(AdjustTypeEnum.INCREASE.getType());
|
||||
reqVO.setRechargeAmount(new BigDecimal("100.00"));
|
||||
reqVO.setGiftAmount(new BigDecimal("20.00"));
|
||||
reqVO.setRemark("调增测试");
|
||||
|
||||
// 模拟依赖返回
|
||||
OrganAmountDO organAmountDO = new OrganAmountDO();
|
||||
organAmountDO.setAmount(new BigDecimal("500.00"));
|
||||
organAmountDO.setGiftAmount(new BigDecimal("100.00"));
|
||||
when(organAmountService.validOrganAmount(100L)).thenReturn(organAmountDO);
|
||||
|
||||
OrganRechargeAmountRespVO rechargeRespVO = new OrganRechargeAmountRespVO();
|
||||
rechargeRespVO.setAmount(new BigDecimal("600.00"));
|
||||
rechargeRespVO.setGiftAmount(new BigDecimal("120.00"));
|
||||
rechargeRespVO.setAvailableAmount(new BigDecimal("720.00"));
|
||||
when(organAmountService.recharge(eq(100L), any(), any())).thenReturn(rechargeRespVO);
|
||||
|
||||
when(incomeExpenseService.createDetail(any())).thenReturn(1L);
|
||||
|
||||
// 执行方法
|
||||
Long result = manualAdjustAccountBalanceService.createAjustment(reqVO);
|
||||
|
||||
// 验证逻辑
|
||||
assertEquals(1L, result);
|
||||
verify(organService).validOrgan(100L);
|
||||
verify(payOrderService).createPayOrder(any(PayOrderDO.class));
|
||||
verify(incomeExpenseService).createDetail(any(IncomeExpenseDetailsDO.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreateAdjustment_Decrease() {
|
||||
// 模拟请求参数(调减)
|
||||
ManualAdjustAccountBalanceSaveReqVO reqVO = new ManualAdjustAccountBalanceSaveReqVO();
|
||||
reqVO.setOrganId(200L);
|
||||
reqVO.setAdjustType(AdjustTypeEnum.DECREASE.getType());
|
||||
reqVO.setRechargeAmount(new BigDecimal("50.00"));
|
||||
reqVO.setGiftAmount(new BigDecimal("10.00"));
|
||||
reqVO.setRemark("调减测试");
|
||||
|
||||
// 模拟依赖返回
|
||||
OrganAmountDO organAmountDO = new OrganAmountDO();
|
||||
organAmountDO.setAmount(new BigDecimal("500.00"));
|
||||
organAmountDO.setGiftAmount(new BigDecimal("100.00"));
|
||||
when(organAmountService.validOrganAmount(200L)).thenReturn(organAmountDO);
|
||||
|
||||
OrganRechargeAmountRespVO rechargeRespVO = new OrganRechargeAmountRespVO();
|
||||
rechargeRespVO.setAmount(new BigDecimal("450.00"));
|
||||
rechargeRespVO.setGiftAmount(new BigDecimal("90.00"));
|
||||
rechargeRespVO.setAvailableAmount(new BigDecimal("540.00"));
|
||||
when(organAmountService.recharge(eq(200L), any(), any())).thenReturn(rechargeRespVO);
|
||||
|
||||
when(incomeExpenseService.createDetail(any())).thenReturn(2L);
|
||||
|
||||
// 执行方法
|
||||
Long result = manualAdjustAccountBalanceService.createAjustment(reqVO);
|
||||
|
||||
// 验证逻辑
|
||||
assertEquals(2L, result);
|
||||
verify(organService).validOrgan(200L);
|
||||
verify(payOrderService).createPayOrder(any(PayOrderDO.class));
|
||||
verify(incomeExpenseService).createDetail(any(IncomeExpenseDetailsDO.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreateAdjustment_Decrease_RechargeInsufficient() {
|
||||
// given
|
||||
ManualAdjustAccountBalanceSaveReqVO reqVO = new ManualAdjustAccountBalanceSaveReqVO();
|
||||
reqVO.setOrganId(300L);
|
||||
reqVO.setAdjustType(AdjustTypeEnum.DECREASE.getType());
|
||||
reqVO.setRechargeAmount(new BigDecimal("200.00")); // 想减200
|
||||
reqVO.setGiftAmount(null);
|
||||
|
||||
OrganAmountDO organAmountDO = new OrganAmountDO();
|
||||
organAmountDO.setAmount(new BigDecimal("100.00")); // 实际余额只有100,不够减
|
||||
organAmountDO.setGiftAmount(new BigDecimal("50.00"));
|
||||
when(organAmountService.validOrganAmount(300L)).thenReturn(organAmountDO);
|
||||
|
||||
// 余额不足
|
||||
assertServiceException(() -> manualAdjustAccountBalanceService.createAjustment(reqVO), ORGAMOUNT_RECHARGE_INSUFFICIENT_ERROR);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreateAdjustment_Decrease_GiftInsufficient() {
|
||||
// given
|
||||
ManualAdjustAccountBalanceSaveReqVO reqVO = new ManualAdjustAccountBalanceSaveReqVO();
|
||||
reqVO.setOrganId(400L);
|
||||
reqVO.setAdjustType(AdjustTypeEnum.DECREASE.getType());
|
||||
reqVO.setRechargeAmount(null);
|
||||
reqVO.setGiftAmount(new BigDecimal("30.00")); // 想减30赠送金
|
||||
|
||||
OrganAmountDO organAmountDO = new OrganAmountDO();
|
||||
organAmountDO.setAmount(new BigDecimal("100.00"));
|
||||
organAmountDO.setGiftAmount(new BigDecimal("10.00")); // 实际赠送金只有10,不够减
|
||||
when(organAmountService.validOrganAmount(400L)).thenReturn(organAmountDO);
|
||||
|
||||
// 赠送金不足
|
||||
assertServiceException(() -> manualAdjustAccountBalanceService.createAjustment(reqVO), ORGAMOUNT_GIFT_INSUFFICIENT_ERROR);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreateAdjustment_Decrease_GiftAmountNull() {
|
||||
// given
|
||||
ManualAdjustAccountBalanceSaveReqVO reqVO = new ManualAdjustAccountBalanceSaveReqVO();
|
||||
reqVO.setOrganId(600L);
|
||||
reqVO.setAdjustType(AdjustTypeEnum.DECREASE.getType());
|
||||
reqVO.setRechargeAmount(new BigDecimal("50.00")); // 有充值金额
|
||||
reqVO.setGiftAmount(null); // giftAmount 为 null
|
||||
|
||||
OrganAmountDO organAmountDO = new OrganAmountDO();
|
||||
organAmountDO.setAmount(new BigDecimal("100.00"));
|
||||
organAmountDO.setGiftAmount(new BigDecimal("100.00"));
|
||||
when(organAmountService.validOrganAmount(600L)).thenReturn(organAmountDO);
|
||||
|
||||
OrganRechargeAmountRespVO respVO = new OrganRechargeAmountRespVO();
|
||||
respVO.setAmount(new BigDecimal("50.00"));
|
||||
respVO.setGiftAmount(new BigDecimal("100.00"));
|
||||
respVO.setAvailableAmount(new BigDecimal("150.00"));
|
||||
when(organAmountService.recharge(eq(600L), any(), any())).thenReturn(respVO);
|
||||
when(incomeExpenseService.createDetail(any())).thenReturn(10L);
|
||||
|
||||
// when
|
||||
Long result = manualAdjustAccountBalanceService.createAjustment(reqVO);
|
||||
|
||||
// then
|
||||
assertEquals(10L, result);
|
||||
verify(payOrderService).createPayOrder(any(PayOrderDO.class));
|
||||
verify(incomeExpenseService).createDetail(any(IncomeExpenseDetailsDO.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreateAdjustment_Decrease_RechargeAmountNull() {
|
||||
// given
|
||||
ManualAdjustAccountBalanceSaveReqVO reqVO = new ManualAdjustAccountBalanceSaveReqVO();
|
||||
reqVO.setOrganId(600L);
|
||||
reqVO.setAdjustType(AdjustTypeEnum.DECREASE.getType());
|
||||
reqVO.setRechargeAmount(null); // rechargeAmount 为 null
|
||||
reqVO.setGiftAmount(new BigDecimal("50.00"));
|
||||
|
||||
OrganAmountDO organAmountDO = new OrganAmountDO();
|
||||
organAmountDO.setAmount(new BigDecimal("100.00"));
|
||||
organAmountDO.setGiftAmount(new BigDecimal("100.00"));
|
||||
when(organAmountService.validOrganAmount(600L)).thenReturn(organAmountDO);
|
||||
|
||||
OrganRechargeAmountRespVO respVO = new OrganRechargeAmountRespVO();
|
||||
respVO.setAmount(new BigDecimal("50.00"));
|
||||
respVO.setGiftAmount(new BigDecimal("100.00"));
|
||||
respVO.setAvailableAmount(new BigDecimal("150.00"));
|
||||
when(organAmountService.recharge(eq(600L), any(), any())).thenReturn(respVO);
|
||||
when(incomeExpenseService.createDetail(any())).thenReturn(10L);
|
||||
|
||||
// when
|
||||
Long result = manualAdjustAccountBalanceService.createAjustment(reqVO);
|
||||
|
||||
// then
|
||||
assertEquals(10L, result);
|
||||
verify(payOrderService, never()).createPayOrder(any(PayOrderDO.class));
|
||||
verify(incomeExpenseService).createDetail(any(IncomeExpenseDetailsDO.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetPage_WithNonNullOrgan() {
|
||||
// given
|
||||
ManualAdjustAccountBalancePageReqVO pageReqVO = new ManualAdjustAccountBalancePageReqVO();
|
||||
|
||||
IncomeExpenseDetailsDO detailsDO = new IncomeExpenseDetailsDO();
|
||||
detailsDO.setIncomeExpenseType(AdjustTypeEnum.INCREASE.getType()); // 假设 1 -> 调增
|
||||
detailsDO.setOrganId(100L);
|
||||
|
||||
PageResult<IncomeExpenseDetailsDO> mockPageResult = new PageResult<>(Collections.singletonList(detailsDO), 1L);
|
||||
when(incomeExpenseService.selectAdjustPage(pageReqVO)).thenReturn(mockPageResult);
|
||||
|
||||
OrganizationDO organ = new OrganizationDO();
|
||||
organ.setName("测试组织");
|
||||
when(organService.getOrganWithDeleted(100L)).thenReturn(organ);
|
||||
|
||||
// when
|
||||
PageResult<ManualAdjustAccountBalanceRespVO> result = manualAdjustAccountBalanceService.getPage(pageReqVO);
|
||||
|
||||
// then
|
||||
assertEquals(1, result.getList().size());
|
||||
ManualAdjustAccountBalanceRespVO respVO = result.getList().get(0);
|
||||
assertEquals("测试组织", respVO.getOrganName());
|
||||
assertEquals(AdjustTypeEnum.INCREASE.getType(), respVO.getAdjustType());
|
||||
|
||||
verify(incomeExpenseService).selectAdjustPage(pageReqVO);
|
||||
verify(organService).getOrganWithDeleted(100L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetPage_WithNullOrgan() {
|
||||
// given
|
||||
ManualAdjustAccountBalancePageReqVO pageReqVO = new ManualAdjustAccountBalancePageReqVO();
|
||||
|
||||
IncomeExpenseDetailsDO detailsDO = new IncomeExpenseDetailsDO();
|
||||
detailsDO.setIncomeExpenseType(AdjustTypeEnum.DECREASE.getType()); // 假设 2 -> 调减
|
||||
detailsDO.setOrganId(200L);
|
||||
|
||||
PageResult<IncomeExpenseDetailsDO> mockPageResult = new PageResult<>(Collections.singletonList(detailsDO), 1L);
|
||||
when(incomeExpenseService.selectAdjustPage(pageReqVO)).thenReturn(mockPageResult);
|
||||
|
||||
// 模拟组织为 null,覆盖 if 条件 false
|
||||
when(organService.getOrganWithDeleted(200L)).thenReturn(null);
|
||||
|
||||
// when
|
||||
PageResult<ManualAdjustAccountBalanceRespVO> result = manualAdjustAccountBalanceService.getPage(pageReqVO);
|
||||
|
||||
// then
|
||||
assertEquals(1, result.getList().size());
|
||||
ManualAdjustAccountBalanceRespVO respVO = result.getList().get(0);
|
||||
assertNull(respVO.getOrganName());
|
||||
assertEquals(AdjustTypeEnum.DECREASE.getType(), respVO.getAdjustType());
|
||||
|
||||
verify(incomeExpenseService).selectAdjustPage(pageReqVO);
|
||||
verify(organService).getOrganWithDeleted(200L);
|
||||
}
|
||||
}
|
||||
+252
@@ -0,0 +1,252 @@
|
||||
//package com.cf.imes.module.system.service.funds.recharge;
|
||||
//
|
||||
//import cn.hutool.core.bean.BeanUtil;
|
||||
//import com.cf.imes.framework.common.pojo.PageResult;
|
||||
//import com.cf.imes.framework.test.core.ut.BaseDbAndRedisUnitTest;
|
||||
//import com.cf.imes.module.system.controller.admin.funds.recharge.vo.RechargePageReqVO;
|
||||
//import com.cf.imes.module.system.controller.admin.funds.recharge.vo.RechargeSaveReqVO;
|
||||
//import com.cf.imes.module.system.dal.dataobject.funds.recharge.GiftMoneyDetailsDO;
|
||||
//import com.cf.imes.module.system.dal.mysql.funds.recharge.GiftMoneyDetailsMapper;
|
||||
//import com.cf.imes.module.system.enums.recharge.RechargeGiftTypeEnum;
|
||||
//import com.cf.imes.module.system.enums.recharge.RechargeTypeEnum;
|
||||
//import jakarta.annotation.Resource;
|
||||
//import org.junit.jupiter.api.MethodOrderer;
|
||||
//import org.junit.jupiter.api.Order;
|
||||
//import org.junit.jupiter.api.Test;
|
||||
//import org.junit.jupiter.api.TestMethodOrder;
|
||||
//import org.springframework.context.annotation.Import;
|
||||
//
|
||||
//import java.math.BigDecimal;
|
||||
//import java.time.LocalDateTime;
|
||||
//import java.util.List;
|
||||
//
|
||||
//import static com.cf.imes.framework.common.util.object.ObjectUtils.cloneIgnoreId;
|
||||
//import static com.cf.imes.framework.test.core.util.AssertUtils.assertPojoEquals;
|
||||
//import static com.cf.imes.framework.test.core.util.AssertUtils.assertServiceException;
|
||||
//import static com.cf.imes.framework.test.core.util.RandomUtils.randomPojo;
|
||||
//import static com.cf.imes.module.system.enums.ErrorCodeConstants.RECHARGE_ACTIVE_NAME_IS_EXIST;
|
||||
//import static com.cf.imes.module.system.enums.ErrorCodeConstants.RECHARGE_ACTIVE_NO_EXIST;
|
||||
//import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
//import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
//import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
//
|
||||
///**
|
||||
// * @author Gqr
|
||||
// * @since 2025/10/24 11:20
|
||||
// */
|
||||
//@Import(RechargeActiveServiceImpl.class)
|
||||
//@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
//class RechargeActiveServiceImplTest extends BaseDbAndRedisUnitTest {
|
||||
// @Resource
|
||||
// private RechargeActiveService rechargeActiveService;
|
||||
//
|
||||
// @Resource
|
||||
// private GiftMoneyDetailsMapper giftMoneyDetailsMapper;
|
||||
//
|
||||
// private static GiftMoneyDetailsDO createDO;
|
||||
//
|
||||
// @Test
|
||||
// @Order(1)
|
||||
// void testCreate() {
|
||||
// RechargeSaveReqVO reqVO = randomPojo(RechargeSaveReqVO.class, o -> {
|
||||
// o.setId(null);
|
||||
// o.setActivityName("充值送活动");
|
||||
// o.setRechargeGiftType(RechargeGiftTypeEnum.EVERY_X_GIVE_X.getStatus());
|
||||
// o.setRechargeType(RechargeTypeEnum.WECHAT_AND_ALIPAY.getStatus());
|
||||
// o.setRechargeAmount(BigDecimal.valueOf(100));
|
||||
// o.setGiftAmount(BigDecimal.valueOf(20));
|
||||
// });
|
||||
//
|
||||
// Long id = rechargeActiveService.create(reqVO);
|
||||
//
|
||||
// // 校验数据库插入结果
|
||||
// createDO = giftMoneyDetailsMapper.selectById(id);
|
||||
// assertNotNull(createDO);
|
||||
// assertEquals("充值送活动", createDO.getActivityName());
|
||||
// assertEquals(RechargeTypeEnum.WECHAT_AND_ALIPAY.getStatus(), createDO.getRechargeType());
|
||||
// assertEquals(RechargeGiftTypeEnum.EVERY_X_GIVE_X.getStatus(), createDO.getRechargeGiftType());
|
||||
// assertEquals(new BigDecimal("100.000"), createDO.getRechargeAmount());
|
||||
// assertEquals(new BigDecimal("20.000"), createDO.getGiftAmount());
|
||||
//
|
||||
// // 再次插入相同活动名称,断言异常
|
||||
// assertServiceException(() -> rechargeActiveService.create(reqVO),
|
||||
// RECHARGE_ACTIVE_NAME_IS_EXIST);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// @Order(2)
|
||||
// void testUpdate_not_exist() {
|
||||
// RechargeSaveReqVO reqVO = new RechargeSaveReqVO();
|
||||
// reqVO.setId(321L);
|
||||
//
|
||||
// assertServiceException(() -> rechargeActiveService.update(reqVO),
|
||||
// RECHARGE_ACTIVE_NO_EXIST);
|
||||
//
|
||||
// reqVO.setId(null);
|
||||
//
|
||||
// assertServiceException(() -> rechargeActiveService.update(reqVO),
|
||||
// RECHARGE_ACTIVE_NO_EXIST);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// @Order(2)
|
||||
// void testUpdate() {
|
||||
//
|
||||
// // 插入
|
||||
// createDO.setId(null);
|
||||
// createDO.setActivityName("充值送活动新");
|
||||
// createDO.setRechargeGiftType(RechargeGiftTypeEnum.EVERY_X_GIVE_X.getStatus());
|
||||
// createDO.setRechargeType(RechargeTypeEnum.WECHAT_AND_ALIPAY.getStatus());
|
||||
// createDO.setRechargeAmount(BigDecimal.valueOf(100));
|
||||
// createDO.setGiftAmount(BigDecimal.valueOf(20));
|
||||
// giftMoneyDetailsMapper.insert(createDO);
|
||||
//
|
||||
// RechargeSaveReqVO reqVO = new RechargeSaveReqVO();
|
||||
// reqVO.setId(createDO.getId());
|
||||
// reqVO.setActivityName("充值送活动");
|
||||
// assertServiceException(() -> rechargeActiveService.update(reqVO),
|
||||
// RECHARGE_ACTIVE_NAME_IS_EXIST);
|
||||
//
|
||||
// // 更新成功
|
||||
// RechargeSaveReqVO update = BeanUtil.copyProperties(createDO, RechargeSaveReqVO.class);
|
||||
// assertDoesNotThrow(() -> rechargeActiveService.update(update));
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// @Test
|
||||
// @Order(3)
|
||||
// void testGet_not_exist() {
|
||||
// assertServiceException(() -> rechargeActiveService.get(null), RECHARGE_ACTIVE_NO_EXIST);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// @Order(4)
|
||||
// void testGet() {
|
||||
// assertNotNull(rechargeActiveService.getDefaultNull(createDO.getId()));
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// @Order(5)
|
||||
// void testGetPage_success() {
|
||||
// GiftMoneyDetailsDO detail = randomPojo(GiftMoneyDetailsDO.class, o -> {
|
||||
// o.setId(null);
|
||||
// o.setActivityName("晨丰分页活动");
|
||||
// o.setRechargeGiftType(RechargeGiftTypeEnum.EVERY_X_GIVE_X.getStatus());
|
||||
// o.setRechargeType(RechargeTypeEnum.WECHAT_AND_ALIPAY.getStatus());
|
||||
// o.setRechargeAmount(BigDecimal.valueOf(100).setScale(3));
|
||||
// o.setGiftAmount(BigDecimal.valueOf(20).setScale(3));
|
||||
// });
|
||||
//
|
||||
// giftMoneyDetailsMapper.insert(detail);
|
||||
//
|
||||
// // 不匹配 ActivityName
|
||||
// giftMoneyDetailsMapper.insert(cloneIgnoreId(detail, o -> o.setActivityName("新分页活动")));
|
||||
//
|
||||
// // 不匹配 RechargeGiftType
|
||||
// giftMoneyDetailsMapper.insert(cloneIgnoreId(detail, o -> o.setRechargeGiftType(RechargeGiftTypeEnum.FULL_X_GIVE_X.getStatus())));
|
||||
//
|
||||
// // 不匹配 GiftAmount
|
||||
// giftMoneyDetailsMapper.insert(cloneIgnoreId(detail, o -> o.setGiftAmount(BigDecimal.valueOf(99))));
|
||||
//
|
||||
// // 不匹配 RechargeAmount
|
||||
// giftMoneyDetailsMapper.insert(cloneIgnoreId(detail, o -> o.setRechargeAmount(BigDecimal.valueOf(99))));
|
||||
//
|
||||
// // 被逻辑删除
|
||||
// giftMoneyDetailsMapper.insert(cloneIgnoreId(detail, o -> o.setDeleted(true)));
|
||||
//
|
||||
// // ============ 构造查询参数 ============
|
||||
// RechargePageReqVO reqVO = new RechargePageReqVO();
|
||||
// reqVO.setActivityName("晨丰");
|
||||
// reqVO.setRechargeGiftType(RechargeGiftTypeEnum.EVERY_X_GIVE_X.getStatus());
|
||||
// reqVO.setRechargeType(RechargeTypeEnum.WECHAT_AND_ALIPAY.getStatus());
|
||||
// reqVO.setRechargeAmount(BigDecimal.valueOf(100));
|
||||
// reqVO.setGiftAmount(BigDecimal.valueOf(20));
|
||||
// reqVO.setPageNo(1);
|
||||
// reqVO.setPageSize(10);
|
||||
//
|
||||
// // ============ 调用方法 ============
|
||||
// PageResult<GiftMoneyDetailsDO> pageResult = rechargeActiveService.getPage(reqVO);
|
||||
//
|
||||
// // ============ 断言结果 ============
|
||||
// assertEquals(1, pageResult.getTotal(), "分页结果数量应为1");
|
||||
// assertEquals(1, pageResult.getList().size(), "分页列表长度应为1");
|
||||
// assertPojoEquals(detail, pageResult.getList().get(0));
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// @Order(6)
|
||||
// void testDelete() {
|
||||
// assertDoesNotThrow(() -> rechargeActiveService.delete(createDO.getId()));
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// @Order(7)
|
||||
// void testDelete_not_exist() {
|
||||
// assertServiceException(() -> rechargeActiveService.delete(null), RECHARGE_ACTIVE_NO_EXIST);
|
||||
// assertServiceException(() -> rechargeActiveService.delete(321L), RECHARGE_ACTIVE_NO_EXIST);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// @Order(8)
|
||||
// void testGetAvailableRechargeActiveList() {
|
||||
// // 当前时间
|
||||
// LocalDateTime now = LocalDateTime.now();
|
||||
//
|
||||
// // 1️⃣ 有效活动(时间区间内)
|
||||
// GiftMoneyDetailsDO valid = new GiftMoneyDetailsDO();
|
||||
// valid.setActivityName("有效活动");
|
||||
// valid.setRechargeAmount(new java.math.BigDecimal("100.000"));
|
||||
// valid.setGiftAmount(new java.math.BigDecimal("10.000"));
|
||||
// valid.setRechargeGiftType(RechargeGiftTypeEnum.EVERY_X_GIVE_X.getStatus());
|
||||
// valid.setRechargeType(RechargeTypeEnum.WECHAT_AND_ALIPAY.getStatus());
|
||||
// valid.setStartTime(now.minusDays(1));
|
||||
// valid.setEndTime(now.plusDays(1));
|
||||
// valid.setDeleted(false);
|
||||
// giftMoneyDetailsMapper.insert(valid);
|
||||
//
|
||||
// // 2️⃣ 未开始活动
|
||||
// GiftMoneyDetailsDO notStarted = new GiftMoneyDetailsDO();
|
||||
// notStarted.setActivityName("未开始活动");
|
||||
// notStarted.setRechargeAmount(new java.math.BigDecimal("100.000"));
|
||||
// notStarted.setGiftAmount(new java.math.BigDecimal("10.000"));
|
||||
// notStarted.setRechargeGiftType(RechargeGiftTypeEnum.EVERY_X_GIVE_X.getStatus());
|
||||
// notStarted.setRechargeType(RechargeTypeEnum.WECHAT_AND_ALIPAY.getStatus());
|
||||
// notStarted.setStartTime(now.plusDays(1));
|
||||
// notStarted.setEndTime(now.plusDays(2));
|
||||
// notStarted.setDeleted(false);
|
||||
// giftMoneyDetailsMapper.insert(notStarted);
|
||||
//
|
||||
// // 3️⃣ 已过期活动
|
||||
// GiftMoneyDetailsDO expired = new GiftMoneyDetailsDO();
|
||||
// expired.setActivityName("已过期活动");
|
||||
// expired.setRechargeAmount(new java.math.BigDecimal("100.000"));
|
||||
// expired.setGiftAmount(new java.math.BigDecimal("10.000"));
|
||||
// expired.setRechargeGiftType(RechargeGiftTypeEnum.EVERY_X_GIVE_X.getStatus());
|
||||
// expired.setRechargeType(RechargeTypeEnum.WECHAT_AND_ALIPAY.getStatus());
|
||||
// expired.setStartTime(now.minusDays(5));
|
||||
// expired.setEndTime(now.minusDays(1));
|
||||
// expired.setDeleted(false);
|
||||
// giftMoneyDetailsMapper.insert(expired);
|
||||
//
|
||||
// // 4️⃣ 被逻辑删除的活动
|
||||
// GiftMoneyDetailsDO deleted = new GiftMoneyDetailsDO();
|
||||
// deleted.setActivityName("被删除活动");
|
||||
// deleted.setRechargeAmount(new java.math.BigDecimal("100.000"));
|
||||
// deleted.setGiftAmount(new java.math.BigDecimal("10.000"));
|
||||
// deleted.setRechargeGiftType(RechargeGiftTypeEnum.EVERY_X_GIVE_X.getStatus());
|
||||
// deleted.setRechargeType(RechargeTypeEnum.WECHAT_AND_ALIPAY.getStatus());
|
||||
// deleted.setStartTime(now.minusDays(1));
|
||||
// deleted.setEndTime(now.plusDays(1));
|
||||
// deleted.setDeleted(true);
|
||||
// giftMoneyDetailsMapper.insert(deleted);
|
||||
//
|
||||
// // 执行被测方法
|
||||
// List<GiftMoneyDetailsDO> result = rechargeActiveService.getAvailableRechargeActiveList();
|
||||
//
|
||||
// // 验证结果
|
||||
// assertEquals(1, result.size(), "只应返回一个有效活动");
|
||||
// assertEquals("有效活动", result.get(0).getActivityName());
|
||||
// }
|
||||
//
|
||||
//}
|
||||
-252
@@ -1,252 +0,0 @@
|
||||
package com.cf.imes.module.system.service.funds.recharge;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.cf.imes.framework.common.pojo.PageResult;
|
||||
import com.cf.imes.framework.test.core.ut.BaseDbAndRedisUnitTest;
|
||||
import com.cf.imes.module.system.controller.admin.funds.recharge.vo.RechargePageReqVO;
|
||||
import com.cf.imes.module.system.controller.admin.funds.recharge.vo.RechargeSaveReqVO;
|
||||
import com.cf.imes.module.system.dal.dataobject.funds.recharge.GiftMoneyDetailsDO;
|
||||
import com.cf.imes.module.system.dal.mysql.funds.recharge.GiftMoneyDetailsMapper;
|
||||
import com.cf.imes.module.system.enums.recharge.RechargeGiftTypeEnum;
|
||||
import com.cf.imes.module.system.enums.recharge.RechargeTypeEnum;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import static com.cf.imes.framework.common.util.object.ObjectUtils.cloneIgnoreId;
|
||||
import static com.cf.imes.framework.test.core.util.AssertUtils.assertPojoEquals;
|
||||
import static com.cf.imes.framework.test.core.util.AssertUtils.assertServiceException;
|
||||
import static com.cf.imes.framework.test.core.util.RandomUtils.randomPojo;
|
||||
import static com.cf.imes.module.system.enums.ErrorCodeConstants.RECHARGE_ACTIVE_NAME_IS_EXIST;
|
||||
import static com.cf.imes.module.system.enums.ErrorCodeConstants.RECHARGE_ACTIVE_NO_EXIST;
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
/**
|
||||
* @author Gqr
|
||||
* @since 2025/10/24 11:20
|
||||
*/
|
||||
@Import(RechargeActiveServiceImpl.class)
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class RechargeActiveServiceImplTest extends BaseDbAndRedisUnitTest {
|
||||
@Resource
|
||||
private RechargeActiveService rechargeActiveService;
|
||||
|
||||
@Resource
|
||||
private GiftMoneyDetailsMapper giftMoneyDetailsMapper;
|
||||
|
||||
private static GiftMoneyDetailsDO createDO;
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void testCreate() {
|
||||
RechargeSaveReqVO reqVO = randomPojo(RechargeSaveReqVO.class, o -> {
|
||||
o.setId(null);
|
||||
o.setActivityName("充值送活动");
|
||||
o.setRechargeGiftType(RechargeGiftTypeEnum.EVERY_X_GIVE_X.getStatus());
|
||||
o.setRechargeType(RechargeTypeEnum.WECHAT_AND_ALIPAY.getStatus());
|
||||
o.setRechargeAmount(BigDecimal.valueOf(100));
|
||||
o.setGiftAmount(BigDecimal.valueOf(20));
|
||||
});
|
||||
|
||||
Long id = rechargeActiveService.create(reqVO);
|
||||
|
||||
// 校验数据库插入结果
|
||||
createDO = giftMoneyDetailsMapper.selectById(id);
|
||||
assertNotNull(createDO);
|
||||
assertEquals("充值送活动", createDO.getActivityName());
|
||||
assertEquals(RechargeTypeEnum.WECHAT_AND_ALIPAY.getStatus(), createDO.getRechargeType());
|
||||
assertEquals(RechargeGiftTypeEnum.EVERY_X_GIVE_X.getStatus(), createDO.getRechargeGiftType());
|
||||
assertEquals(new BigDecimal("100.000"), createDO.getRechargeAmount());
|
||||
assertEquals(new BigDecimal("20.000"), createDO.getGiftAmount());
|
||||
|
||||
// 再次插入相同活动名称,断言异常
|
||||
assertServiceException(() -> rechargeActiveService.create(reqVO),
|
||||
RECHARGE_ACTIVE_NAME_IS_EXIST);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void testUpdate_not_exist() {
|
||||
RechargeSaveReqVO reqVO = new RechargeSaveReqVO();
|
||||
reqVO.setId(321L);
|
||||
|
||||
assertServiceException(() -> rechargeActiveService.update(reqVO),
|
||||
RECHARGE_ACTIVE_NO_EXIST);
|
||||
|
||||
reqVO.setId(null);
|
||||
|
||||
assertServiceException(() -> rechargeActiveService.update(reqVO),
|
||||
RECHARGE_ACTIVE_NO_EXIST);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void testUpdate() {
|
||||
|
||||
// 插入
|
||||
createDO.setId(null);
|
||||
createDO.setActivityName("充值送活动新");
|
||||
createDO.setRechargeGiftType(RechargeGiftTypeEnum.EVERY_X_GIVE_X.getStatus());
|
||||
createDO.setRechargeType(RechargeTypeEnum.WECHAT_AND_ALIPAY.getStatus());
|
||||
createDO.setRechargeAmount(BigDecimal.valueOf(100));
|
||||
createDO.setGiftAmount(BigDecimal.valueOf(20));
|
||||
giftMoneyDetailsMapper.insert(createDO);
|
||||
|
||||
RechargeSaveReqVO reqVO = new RechargeSaveReqVO();
|
||||
reqVO.setId(createDO.getId());
|
||||
reqVO.setActivityName("充值送活动");
|
||||
assertServiceException(() -> rechargeActiveService.update(reqVO),
|
||||
RECHARGE_ACTIVE_NAME_IS_EXIST);
|
||||
|
||||
// 更新成功
|
||||
RechargeSaveReqVO update = BeanUtil.copyProperties(createDO, RechargeSaveReqVO.class);
|
||||
assertDoesNotThrow(() -> rechargeActiveService.update(update));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void testGet_not_exist() {
|
||||
assertServiceException(() -> rechargeActiveService.get(null), RECHARGE_ACTIVE_NO_EXIST);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void testGet() {
|
||||
assertNotNull(rechargeActiveService.getDefaultNull(createDO.getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void testGetPage_success() {
|
||||
GiftMoneyDetailsDO detail = randomPojo(GiftMoneyDetailsDO.class, o -> {
|
||||
o.setId(null);
|
||||
o.setActivityName("晨丰分页活动");
|
||||
o.setRechargeGiftType(RechargeGiftTypeEnum.EVERY_X_GIVE_X.getStatus());
|
||||
o.setRechargeType(RechargeTypeEnum.WECHAT_AND_ALIPAY.getStatus());
|
||||
o.setRechargeAmount(BigDecimal.valueOf(100).setScale(3));
|
||||
o.setGiftAmount(BigDecimal.valueOf(20).setScale(3));
|
||||
});
|
||||
|
||||
giftMoneyDetailsMapper.insert(detail);
|
||||
|
||||
// 不匹配 ActivityName
|
||||
giftMoneyDetailsMapper.insert(cloneIgnoreId(detail, o -> o.setActivityName("新分页活动")));
|
||||
|
||||
// 不匹配 RechargeGiftType
|
||||
giftMoneyDetailsMapper.insert(cloneIgnoreId(detail, o -> o.setRechargeGiftType(RechargeGiftTypeEnum.FULL_X_GIVE_X.getStatus())));
|
||||
|
||||
// 不匹配 GiftAmount
|
||||
giftMoneyDetailsMapper.insert(cloneIgnoreId(detail, o -> o.setGiftAmount(BigDecimal.valueOf(99))));
|
||||
|
||||
// 不匹配 RechargeAmount
|
||||
giftMoneyDetailsMapper.insert(cloneIgnoreId(detail, o -> o.setRechargeAmount(BigDecimal.valueOf(99))));
|
||||
|
||||
// 被逻辑删除
|
||||
giftMoneyDetailsMapper.insert(cloneIgnoreId(detail, o -> o.setDeleted(true)));
|
||||
|
||||
// ============ 构造查询参数 ============
|
||||
RechargePageReqVO reqVO = new RechargePageReqVO();
|
||||
reqVO.setActivityName("晨丰");
|
||||
reqVO.setRechargeGiftType(RechargeGiftTypeEnum.EVERY_X_GIVE_X.getStatus());
|
||||
reqVO.setRechargeType(RechargeTypeEnum.WECHAT_AND_ALIPAY.getStatus());
|
||||
reqVO.setRechargeAmount(BigDecimal.valueOf(100));
|
||||
reqVO.setGiftAmount(BigDecimal.valueOf(20));
|
||||
reqVO.setPageNo(1);
|
||||
reqVO.setPageSize(10);
|
||||
|
||||
// ============ 调用方法 ============
|
||||
PageResult<GiftMoneyDetailsDO> pageResult = rechargeActiveService.getPage(reqVO);
|
||||
|
||||
// ============ 断言结果 ============
|
||||
assertEquals(1, pageResult.getTotal(), "分页结果数量应为1");
|
||||
assertEquals(1, pageResult.getList().size(), "分页列表长度应为1");
|
||||
assertPojoEquals(detail, pageResult.getList().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void testDelete() {
|
||||
assertDoesNotThrow(() -> rechargeActiveService.delete(createDO.getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void testDelete_not_exist() {
|
||||
assertServiceException(() -> rechargeActiveService.delete(null), RECHARGE_ACTIVE_NO_EXIST);
|
||||
assertServiceException(() -> rechargeActiveService.delete(321L), RECHARGE_ACTIVE_NO_EXIST);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
void testGetAvailableRechargeActiveList() {
|
||||
// 当前时间
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
// 1️⃣ 有效活动(时间区间内)
|
||||
GiftMoneyDetailsDO valid = new GiftMoneyDetailsDO();
|
||||
valid.setActivityName("有效活动");
|
||||
valid.setRechargeAmount(new java.math.BigDecimal("100.000"));
|
||||
valid.setGiftAmount(new java.math.BigDecimal("10.000"));
|
||||
valid.setRechargeGiftType(RechargeGiftTypeEnum.EVERY_X_GIVE_X.getStatus());
|
||||
valid.setRechargeType(RechargeTypeEnum.WECHAT_AND_ALIPAY.getStatus());
|
||||
valid.setStartTime(now.minusDays(1));
|
||||
valid.setEndTime(now.plusDays(1));
|
||||
valid.setDeleted(false);
|
||||
giftMoneyDetailsMapper.insert(valid);
|
||||
|
||||
// 2️⃣ 未开始活动
|
||||
GiftMoneyDetailsDO notStarted = new GiftMoneyDetailsDO();
|
||||
notStarted.setActivityName("未开始活动");
|
||||
notStarted.setRechargeAmount(new java.math.BigDecimal("100.000"));
|
||||
notStarted.setGiftAmount(new java.math.BigDecimal("10.000"));
|
||||
notStarted.setRechargeGiftType(RechargeGiftTypeEnum.EVERY_X_GIVE_X.getStatus());
|
||||
notStarted.setRechargeType(RechargeTypeEnum.WECHAT_AND_ALIPAY.getStatus());
|
||||
notStarted.setStartTime(now.plusDays(1));
|
||||
notStarted.setEndTime(now.plusDays(2));
|
||||
notStarted.setDeleted(false);
|
||||
giftMoneyDetailsMapper.insert(notStarted);
|
||||
|
||||
// 3️⃣ 已过期活动
|
||||
GiftMoneyDetailsDO expired = new GiftMoneyDetailsDO();
|
||||
expired.setActivityName("已过期活动");
|
||||
expired.setRechargeAmount(new java.math.BigDecimal("100.000"));
|
||||
expired.setGiftAmount(new java.math.BigDecimal("10.000"));
|
||||
expired.setRechargeGiftType(RechargeGiftTypeEnum.EVERY_X_GIVE_X.getStatus());
|
||||
expired.setRechargeType(RechargeTypeEnum.WECHAT_AND_ALIPAY.getStatus());
|
||||
expired.setStartTime(now.minusDays(5));
|
||||
expired.setEndTime(now.minusDays(1));
|
||||
expired.setDeleted(false);
|
||||
giftMoneyDetailsMapper.insert(expired);
|
||||
|
||||
// 4️⃣ 被逻辑删除的活动
|
||||
GiftMoneyDetailsDO deleted = new GiftMoneyDetailsDO();
|
||||
deleted.setActivityName("被删除活动");
|
||||
deleted.setRechargeAmount(new java.math.BigDecimal("100.000"));
|
||||
deleted.setGiftAmount(new java.math.BigDecimal("10.000"));
|
||||
deleted.setRechargeGiftType(RechargeGiftTypeEnum.EVERY_X_GIVE_X.getStatus());
|
||||
deleted.setRechargeType(RechargeTypeEnum.WECHAT_AND_ALIPAY.getStatus());
|
||||
deleted.setStartTime(now.minusDays(1));
|
||||
deleted.setEndTime(now.plusDays(1));
|
||||
deleted.setDeleted(true);
|
||||
giftMoneyDetailsMapper.insert(deleted);
|
||||
|
||||
// 执行被测方法
|
||||
List<GiftMoneyDetailsDO> result = rechargeActiveService.getAvailableRechargeActiveList();
|
||||
|
||||
// 验证结果
|
||||
assertEquals(1, result.size(), "只应返回一个有效活动");
|
||||
assertEquals("有效活动", result.get(0).getActivityName());
|
||||
}
|
||||
|
||||
}
|
||||
-48
@@ -1,48 +0,0 @@
|
||||
package com.cf.imes.module.system.service.funds.recharge;
|
||||
|
||||
import com.cf.imes.framework.test.core.ut.BaseDbUnitTest;
|
||||
import com.cf.imes.module.system.controller.admin.funds.recharge.vo.RechargeDetailsBalanceInfoRespVO;
|
||||
import com.cf.imes.module.system.service.funds.purchase.PurchaseService;
|
||||
import com.cf.imes.module.system.service.pay.PayOrderService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* @author Gqr
|
||||
* @since 2025/10/27 10:44
|
||||
*/
|
||||
@Import(RechargeDetailsServiceImpl.class)
|
||||
class RechargeDetailsServiceImplTest extends BaseDbUnitTest {
|
||||
@Resource
|
||||
private RechargeDetailsService detailsService;
|
||||
|
||||
@MockitoBean
|
||||
private PayOrderService payOrderService;
|
||||
|
||||
@MockitoBean
|
||||
private PurchaseService purchaseService;
|
||||
|
||||
@Test
|
||||
void testGetManageRechargeDetailsBalanceInfo() {
|
||||
// 模拟依赖返回值
|
||||
when(payOrderService.getRechargeTotalAmount()).thenReturn(new BigDecimal("200.00"));
|
||||
when(purchaseService.getTotalRechargeUsageAmount()).thenReturn(new BigDecimal("50.00"));
|
||||
|
||||
// 调用被测方法
|
||||
RechargeDetailsBalanceInfoRespVO result = detailsService.getManageRechargeDetailsBalanceInfo();
|
||||
|
||||
// 验证逻辑
|
||||
assertEquals(new BigDecimal("200.00"), result.getRechargeAmount());
|
||||
assertEquals(new BigDecimal("50.00"), result.getRechargeUsageAmount());
|
||||
verify(payOrderService).getRechargeTotalAmount();
|
||||
verify(purchaseService).getTotalRechargeUsageAmount();
|
||||
}
|
||||
}
|
||||
-29
@@ -1,29 +0,0 @@
|
||||
package com.cf.imes.module.system.validation.manualadjust;
|
||||
|
||||
import com.cf.imes.framework.test.core.ut.BaseMockitoUnitTest;
|
||||
import com.cf.imes.module.system.enums.pay.AdjustTypeEnum;
|
||||
import jakarta.validation.ConstraintValidatorContext;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Gqr
|
||||
* @since 2025/10/29 9:45
|
||||
*/
|
||||
class AdjustTypeValidatorTest extends BaseMockitoUnitTest {
|
||||
@Mock
|
||||
private ConstraintValidatorContext constraintValidatorContext;
|
||||
|
||||
@Test
|
||||
void testValid() {
|
||||
AdjustTypeValidator validator = new AdjustTypeValidator();
|
||||
assertTrue(validator.isValid(AdjustTypeEnum.INCREASE.getType(), constraintValidatorContext));
|
||||
assertTrue(validator.isValid(AdjustTypeEnum.DECREASE.getType(), constraintValidatorContext));
|
||||
assertTrue(validator.isValid(null, constraintValidatorContext));
|
||||
assertFalse(validator.isValid(100, constraintValidatorContext));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user