|
@@ -17,8 +17,10 @@
|
|
|
|
|
|
package org.apache.dolphinscheduler.dao.mapper;
|
|
|
|
|
|
+import org.apache.dolphinscheduler.common.enums.AuditResourceType;
|
|
|
import org.apache.dolphinscheduler.dao.BaseDaoTest;
|
|
|
import org.apache.dolphinscheduler.dao.entity.AuditLog;
|
|
|
+import org.apache.dolphinscheduler.dao.entity.Project;
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
@@ -34,26 +36,41 @@ public class AuditLogMapperTest extends BaseDaoTest {
|
|
|
@Autowired
|
|
|
AuditLogMapper logMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ProjectMapper projectMapper;
|
|
|
+
|
|
|
/**
|
|
|
* insert
|
|
|
* @return
|
|
|
*/
|
|
|
- private void insertOne() {
|
|
|
+ private void insertOne(AuditResourceType resourceType) {
|
|
|
AuditLog auditLog = new AuditLog();
|
|
|
auditLog.setUserId(1);
|
|
|
auditLog.setTime(new Date());
|
|
|
- auditLog.setResourceType(0);
|
|
|
+ auditLog.setResourceType(resourceType.getCode());
|
|
|
auditLog.setOperation(0);
|
|
|
auditLog.setResourceId(0);
|
|
|
logMapper.insert(auditLog);
|
|
|
}
|
|
|
|
|
|
+ private Project insertProject() {
|
|
|
+ Project project = new Project();
|
|
|
+ project.setName("ut project");
|
|
|
+ project.setUserId(111);
|
|
|
+ project.setCode(1L);
|
|
|
+ project.setCreateTime(new Date());
|
|
|
+ project.setUpdateTime(new Date());
|
|
|
+ projectMapper.insert(project);
|
|
|
+ return project;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* test page query
|
|
|
*/
|
|
|
@Test
|
|
|
public void testQueryAuditLog() {
|
|
|
- insertOne();
|
|
|
+ insertOne(AuditResourceType.USER_MODULE);
|
|
|
+ insertOne(AuditResourceType.PROJECT_MODULE);
|
|
|
Page<AuditLog> page = new Page<>(1, 3);
|
|
|
int[] resourceType = new int[0];
|
|
|
int[] operationType = new int[0];
|
|
@@ -64,7 +81,12 @@ public class AuditLogMapperTest extends BaseDaoTest {
|
|
|
|
|
|
@Test
|
|
|
public void testQueryResourceNameByType() {
|
|
|
- String resourceName = logMapper.queryResourceNameByType("USER", 1);
|
|
|
- Assertions.assertEquals("admin", resourceName);
|
|
|
+ String resourceNameByUser = logMapper.queryResourceNameByType(AuditResourceType.USER_MODULE.getMsg(), 1);
|
|
|
+ Assertions.assertEquals("admin", resourceNameByUser);
|
|
|
+ Project project = insertProject();
|
|
|
+ String resourceNameByProject = logMapper.queryResourceNameByType(AuditResourceType.PROJECT_MODULE.getMsg(), 1);
|
|
|
+ Assertions.assertEquals(project.getName(), resourceNameByProject);
|
|
|
+ int delete = projectMapper.deleteById(project.getId());
|
|
|
+ Assertions.assertEquals(delete, 1);
|
|
|
}
|
|
|
}
|