lrj
昨天 9f8395fab13ca4b230a0f7d62636e209745c91d4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.rongyichuang;
 
import com.rongyichuang.activity.dto.ActivityResponse;
import com.rongyichuang.activity.service.ActivityService;
import com.rongyichuang.activity.repository.ActivityRepository;
import com.rongyichuang.activity.entity.Activity;
import com.rongyichuang.common.dto.PageRequest;
import com.rongyichuang.common.dto.PageResponse;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.Page;
 
@SpringBootTest
public class TestActivityServiceTest {
 
    @Autowired
    private ActivityService activityService;
    
    @Autowired
    private ActivityRepository activityRepository;
 
    @Test
    public void testFindCompetitions() {
        try {
            System.out.println("=== 测试ActivityService.findCompetitions ===");
            
            // 先直接测试Repository
            System.out.println("\n=== 直接测试Repository ===");
            Page<Activity> activities = activityRepository.findByPidAndStateOrderByCreateTimeDesc(0L, 1, 
                org.springframework.data.domain.PageRequest.of(0, 10));
            System.out.println("Repository查询结果数量: " + activities.getContent().size());
            System.out.println("Repository总记录数: " + activities.getTotalElements());
            
            if (activities.getContent().size() > 0) {
                Activity firstActivity = activities.getContent().get(0);
                System.out.println("第一个Activity - ID: " + firstActivity.getId() + 
                                 ", 名称: " + firstActivity.getName() + 
                                 ", 状态: " + firstActivity.getState() + 
                                 ", PID: " + firstActivity.getPid());
                
                // 测试ActivityResponse构造
                try {
                    ActivityResponse response = new ActivityResponse(firstActivity);
                    System.out.println("  -> 转换成功: " + response.getName());
                } catch (Exception e) {
                    System.out.println("  -> 转换失败: " + e.getMessage());
                    e.printStackTrace();
                }
            }
            
            System.out.println("\n=== 测试Service方法 ===");
            PageRequest pageRequest = new PageRequest(1, 10);
            PageResponse<ActivityResponse> result = activityService.findActivities(pageRequest, null);
            
            System.out.println("总记录数: " + result.getTotalElements());
            System.out.println("当前页: " + result.getPage());
            System.out.println("页大小: " + result.getSize());
            System.out.println("内容数量: " + result.getContent().size());
            
        } catch (Exception e) {
            System.out.println("测试失败: " + e.getMessage());
            e.printStackTrace();
        }
    }
}