定时器 ,周期性的统计分析品牌维度
This commit is contained in:
@@ -32,7 +32,7 @@ class CustomerProfileStatisticSchedulerIntegrationTest {
|
||||
@Test
|
||||
void testRealDatabaseOperation() {
|
||||
// 准备测试数据
|
||||
LocalDateTime testDate = LocalDateTime.of(2025, 9, 9, 10, 0, 0);
|
||||
LocalDateTime testDate = LocalDateTime.of(2025, 7, 8, 10, 0, 0);
|
||||
|
||||
// 执行数据生成
|
||||
int count = scheduler.generateCustomerProfileDataForDate(testDate);
|
||||
@@ -59,7 +59,7 @@ class CustomerProfileStatisticSchedulerIntegrationTest {
|
||||
assertNotNull(latestRecord.getEntityPrice(), "价格情感不应为空");
|
||||
assertNotNull(latestRecord.getEntityPower(), "动力情感不应为空");
|
||||
|
||||
System.out.println("成功生成并保存了 " + count + " 条记录");
|
||||
System.out.println("成功生成并保存了 " + count + " 条记录"+" , 累计总数记录数: "+savedRecords.size());
|
||||
System.out.println("最新记录详情:");
|
||||
System.out.println("客户姓名: " + latestRecord.getClientName());
|
||||
System.out.println("门店: " + latestRecord.getDealerName());
|
||||
|
||||
@@ -1,162 +0,0 @@
|
||||
package com.rj.scheduler;
|
||||
|
||||
import com.rj.entity.CustomerProfileAnalysis;
|
||||
import com.rj.service.biz.ICustomerProfileAnalysisService;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
* CustomerProfileStatisticScheduler 测试类
|
||||
*
|
||||
* @author 李中华
|
||||
* @date 2025/1/3
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class CustomerProfileStatisticSchedulerTest {
|
||||
|
||||
@Mock
|
||||
private ICustomerProfileAnalysisService customerProfileAnalysisService;
|
||||
|
||||
@InjectMocks
|
||||
private CustomerProfileMockInsertDataScheduler scheduler;
|
||||
|
||||
@Test
|
||||
void testGenerateCustomerProfileDataForDate() {
|
||||
// 准备测试数据
|
||||
LocalDateTime testDate = LocalDateTime.of(2025, 8, 3, 10, 0, 0);
|
||||
|
||||
// 模拟Service返回成功
|
||||
when(customerProfileAnalysisService.saveCustomerProfileAnalysis(any(CustomerProfileAnalysis.class)))
|
||||
.thenReturn(true);
|
||||
|
||||
// 执行测试
|
||||
int result = scheduler.generateCustomerProfileDataForDate(testDate);
|
||||
|
||||
// 验证结果
|
||||
assertTrue(result > 0, "应该生成至少一条记录");
|
||||
assertTrue(result <= 50, "生成记录数不应超过50条");
|
||||
|
||||
// 验证Service被调用
|
||||
verify(customerProfileAnalysisService, atLeastOnce())
|
||||
.saveCustomerProfileAnalysis(any(CustomerProfileAnalysis.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCustomerProfileAnalysisDataIntegrity() {
|
||||
// 准备测试数据
|
||||
LocalDateTime testDate = LocalDateTime.of(2025, 1, 3, 10, 0, 0);
|
||||
|
||||
// 模拟Service返回成功
|
||||
when(customerProfileAnalysisService.saveCustomerProfileAnalysis(any(CustomerProfileAnalysis.class)))
|
||||
.thenAnswer(invocation -> {
|
||||
CustomerProfileAnalysis analysis = invocation.getArgument(0);
|
||||
|
||||
// 验证新字段不为空
|
||||
assertNotNull(analysis.getDealerName(), "经销商门店名称不应为空");
|
||||
assertNotNull(analysis.getProjectId(), "项目ID不应为空");
|
||||
assertNotNull(analysis.getProjectName(), "项目名称不应为空");
|
||||
assertNotNull(analysis.getSalesPersonId(), "销售顾问ID不应为空");
|
||||
assertNotNull(analysis.getSalesPersonName(), "销售顾问姓名不应为空");
|
||||
|
||||
// 验证字段格式
|
||||
assertTrue(analysis.getDealerName().length() > 0, "经销商门店名称长度应大于0");
|
||||
assertTrue(analysis.getProjectName().length() > 0, "项目名称长度应大于0");
|
||||
assertTrue(analysis.getSalesPersonName().length() > 0, "销售顾问姓名长度应大于0");
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
// 执行测试
|
||||
int result = scheduler.generateCustomerProfileDataForDate(testDate);
|
||||
|
||||
// 验证结果
|
||||
assertTrue(result > 0, "应该生成至少一条记录");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testManualGenerateData() {
|
||||
// 准备测试数据
|
||||
LocalDateTime testDate = LocalDateTime.of(2025, 1, 3, 10, 0, 0);
|
||||
|
||||
// 模拟Service返回成功
|
||||
when(customerProfileAnalysisService.saveCustomerProfileAnalysis(any(CustomerProfileAnalysis.class)))
|
||||
.thenReturn(true);
|
||||
|
||||
// 执行测试
|
||||
int result = scheduler.manualGenerateData(testDate);
|
||||
|
||||
// 验证结果
|
||||
assertTrue(result > 0, "手动生成应该返回成功记录数");
|
||||
|
||||
// 验证Service被调用
|
||||
verify(customerProfileAnalysisService, atLeastOnce())
|
||||
.saveCustomerProfileAnalysis(any(CustomerProfileAnalysis.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenerateCustomerProfileDataForDateWithException() {
|
||||
// 准备测试数据
|
||||
LocalDateTime testDate = LocalDateTime.of(2025, 1, 3, 10, 0, 0);
|
||||
|
||||
// 模拟Service抛出异常
|
||||
when(customerProfileAnalysisService.saveCustomerProfileAnalysis(any(CustomerProfileAnalysis.class)))
|
||||
.thenThrow(new RuntimeException("数据库连接失败"));
|
||||
|
||||
// 执行测试并验证异常
|
||||
assertThrows(RuntimeException.class, () -> {
|
||||
scheduler.generateCustomerProfileDataForDate(testDate);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDataGenerationWithMockService() {
|
||||
// 准备测试数据
|
||||
LocalDateTime testDate = LocalDateTime.of(2025, 1, 3, 10, 0, 0);
|
||||
|
||||
// 模拟Service返回成功,并验证数据内容
|
||||
when(customerProfileAnalysisService.saveCustomerProfileAnalysis(any(CustomerProfileAnalysis.class)))
|
||||
.thenAnswer(invocation -> {
|
||||
CustomerProfileAnalysis analysis = invocation.getArgument(0);
|
||||
|
||||
// 验证所有新字段都有值
|
||||
assertNotNull(analysis.getDealerName(), "经销商门店名称不应为空");
|
||||
assertNotNull(analysis.getProjectId(), "项目ID不应为空");
|
||||
assertNotNull(analysis.getProjectName(), "项目名称不应为空");
|
||||
assertNotNull(analysis.getSalesPersonId(), "销售顾问ID不应为空");
|
||||
assertNotNull(analysis.getSalesPersonName(), "销售顾问姓名不应为空");
|
||||
|
||||
// 验证情感分析字段
|
||||
assertNotNull(analysis.getEntityBrand(), "品牌情感不应为空");
|
||||
assertNotNull(analysis.getEntityPrice(), "价格情感不应为空");
|
||||
assertNotNull(analysis.getEntityPower(), "动力情感不应为空");
|
||||
assertNotNull(analysis.getEntitySafety(), "安全情感不应为空");
|
||||
|
||||
// 验证备注字段包含新信息
|
||||
assertNotNull(analysis.getNotes(), "备注不应为空");
|
||||
assertTrue(analysis.getNotes().contains(analysis.getDealerName()), "备注应包含门店名称");
|
||||
assertTrue(analysis.getNotes().contains(analysis.getProjectName()), "备注应包含项目名称");
|
||||
assertTrue(analysis.getNotes().contains(analysis.getSalesPersonName()), "备注应包含销售顾问姓名");
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
// 执行测试
|
||||
int result = scheduler.generateCustomerProfileDataForDate(testDate);
|
||||
|
||||
// 验证结果
|
||||
assertTrue(result > 0, "应该生成至少一条记录");
|
||||
|
||||
// 验证Service被调用
|
||||
verify(customerProfileAnalysisService, atLeastOnce())
|
||||
.saveCustomerProfileAnalysis(any(CustomerProfileAnalysis.class));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user