tj
2025-06-05 2d549a04870d1315868a7cf19952b64e8071e711
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package com.cloudroam.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cloudroam.mapper.LogMapper;
import com.cloudroam.model.LogDO;
import com.cloudroam.service.LogService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.transaction.annotation.Transactional;
 
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
 
 
@SpringBootTest
@Transactional
@Rollback
@ActiveProfiles("test")
public class LogServiceImplTest {
 
    @Autowired
    private LogService logService;
 
    @Autowired
    private LogMapper logMapper;
 
    @Test
    public void getLogs() {
        String message = "put your face to the light!";
        String authority = "查看lin的信息";
        Integer userId = 100;
        String userName = "pedro";
        String method = "GET";
        String path = "/";
        Integer status = 200;
//        logService.createLog(message, authority, userId, userName, method, path, status);
 
        IPage<LogDO> iPage = logService.getLogPage(0, 10, null, null, null);
        assertTrue(iPage.getSize() > 0);
    }
 
    @Test
    public void searchLogs() {
        String message = "put your face to the light!";
        String authority = "查看lin的信息";
        Integer userId = 100;
        String userName = "pedro";
        String method = "GET";
        String path = "/";
        Integer status = 200;
//        logService.createLog(message, authority, userId, userName, method, path, status);
 
        IPage<LogDO> iPage = logService.searchLogPage(0, 10, null, "put", null, null);
        assertTrue(iPage.getSize() > 0);
    }
 
    @Test
    public void getUserNames() {
        String message = "put your face to the light!";
        String authority = "查看lin的信息";
        Integer userId = 100;
        String userName = "pedro";
        String method = "GET";
        String path = "/";
        Integer status = 200;
//        logService.createLog(message, authority, userId, userName, method, path, status);
 
        IPage<String> iPage = logService.getUserNamePage(0, 10);
        assertTrue(iPage.getRecords().size() > 0);
    }
 
    @Test
    public void createOneLog() {
        String message = "put your face to the light!";
        String permission = "查看lin的信息";
        Integer userId = 100;
        String userName = "pedro";
        String method = "GET";
        String path = "/";
        Integer status = 200;
//        logService.createLog(message, permission, userId, userName, method, path, status);
 
        QueryWrapper<LogDO> condition = new QueryWrapper<>();
        condition.eq("message", message);
        LogDO logDO = logMapper.selectOne(condition);
 
        assertEquals(logDO.getPermission(), permission);
    }
}