diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionLogMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionLogMapper.xml index f051aa7eca..673a266bc2 100644 --- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionLogMapper.xml +++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionLogMapper.xml @@ -51,7 +51,7 @@ from t_ds_task_definition_log WHERE 1 = 1 - + and (code = #{item.code} diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapper.xml index 5c4f46d23c..2556b3742c 100644 --- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapper.xml +++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapper.xml @@ -54,7 +54,7 @@ JOIN t_ds_user tu on tu.id=td.user_id where 1 = 1 - and td.project_id in + and td.project_code in #{i} @@ -85,7 +85,7 @@ delete from t_ds_task_definition diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionLogMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionLogMapperTest.java index 3e471cb6ce..42c32f6602 100644 --- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionLogMapperTest.java +++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionLogMapperTest.java @@ -18,9 +18,14 @@ package org.apache.dolphinscheduler.dao.mapper; import org.apache.dolphinscheduler.common.enums.TaskType; +import org.apache.dolphinscheduler.dao.entity.Project; +import org.apache.dolphinscheduler.dao.entity.TaskDefinition; import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog; +import org.apache.dolphinscheduler.dao.entity.User; +import java.util.ArrayList; import java.util.Date; +import java.util.List; import org.junit.Assert; import org.junit.Test; @@ -37,17 +42,29 @@ import org.springframework.transaction.annotation.Transactional; @Rollback(true) public class TaskDefinitionLogMapperTest { - @Autowired TaskDefinitionLogMapper taskDefinitionLogMapper; + @Autowired + TaskDefinitionMapper taskDefinitionMapper; + + @Autowired + UserMapper userMapper; + + @Autowired + ProjectMapper projectMapper; + public TaskDefinitionLog insertOne() { + return insertOne(99); + } + + public TaskDefinitionLog insertOne(int userId) { TaskDefinitionLog taskDefinition = new TaskDefinitionLog(); taskDefinition.setCode(888888L); taskDefinition.setName("unit-test"); - taskDefinition.setProjectCode(111111L); + taskDefinition.setProjectCode(1L); taskDefinition.setTaskType(TaskType.SHELL); - taskDefinition.setUserId(99); + taskDefinition.setUserId(userId); taskDefinition.setVersion(1); taskDefinition.setCreateTime(new Date()); taskDefinition.setUpdateTime(new Date()); @@ -60,4 +77,59 @@ public class TaskDefinitionLogMapperTest { TaskDefinitionLog taskDefinitionLog = insertOne(); Assert.assertNotEquals(taskDefinitionLog.getId(), 0); } + + @Test + public void testQueryByDefinitionName() { + User user = new User(); + user.setUserName("un"); + userMapper.insert(user); + User un = userMapper.queryByUserNameAccurately("un"); + + Project project = new Project(); + project.setCode(1L); + project.setCreateTime(new Date()); + project.setUpdateTime(new Date()); + projectMapper.insert(project); + + TaskDefinitionLog taskDefinitionLog = insertOne(un.getId()); + + List taskDefinitionLogs = taskDefinitionLogMapper + .queryByDefinitionName(taskDefinitionLog.getProjectCode(), taskDefinitionLog.getName()); + Assert.assertNotEquals(taskDefinitionLogs.size(), 0); + } + + @Test + public void testQueryMaxVersionForDefinition() { + TaskDefinitionLog taskDefinitionLog = insertOne(); + int version = taskDefinitionLogMapper + .queryMaxVersionForDefinition(taskDefinitionLog.getCode()); + Assert.assertNotEquals(version, 0); + } + + @Test + public void testQueryByDefinitionCodeAndVersion() { + TaskDefinitionLog taskDefinitionLog = insertOne(); + TaskDefinitionLog tdl = taskDefinitionLogMapper + .queryByDefinitionCodeAndVersion(taskDefinitionLog.getCode(), taskDefinitionLog.getVersion()); + Assert.assertNotNull(tdl); + } + + @Test + public void testQueryByTaskDefinitions() { + TaskDefinition taskDefinition = new TaskDefinition(); + taskDefinition.setCode(888888L); + taskDefinition.setName("unit-test"); + taskDefinition.setProjectCode(1L); + taskDefinition.setTaskType(TaskType.SHELL); + taskDefinition.setUserId(1); + taskDefinition.setResourceIds("1"); + taskDefinition.setVersion(1); + ArrayList taskDefinitions = new ArrayList<>(); + taskDefinitions.add(taskDefinition); + + TaskDefinitionLog taskDefinitionLog = insertOne(); + List taskDefinitionLogs = taskDefinitionLogMapper.queryByTaskDefinitions(taskDefinitions); + Assert.assertNotEquals(taskDefinitionLogs.size(), 0); + } + } diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapperTest.java index b891cef1e1..946ed82fe1 100644 --- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapperTest.java +++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapperTest.java @@ -18,9 +18,14 @@ package org.apache.dolphinscheduler.dao.mapper; import org.apache.dolphinscheduler.common.enums.TaskType; +import org.apache.dolphinscheduler.dao.entity.DefinitionGroupByUser; +import org.apache.dolphinscheduler.dao.entity.Project; import org.apache.dolphinscheduler.dao.entity.TaskDefinition; +import org.apache.dolphinscheduler.dao.entity.User; import java.util.Date; +import java.util.List; +import java.util.Map; import org.junit.Assert; import org.junit.Test; @@ -40,13 +45,24 @@ public class TaskDefinitionMapperTest { @Autowired TaskDefinitionMapper taskDefinitionMapper; + @Autowired + UserMapper userMapper; + + @Autowired + ProjectMapper projectMapper; + public TaskDefinition insertOne() { + return insertOne(99); + } + + public TaskDefinition insertOne(int userId) { TaskDefinition taskDefinition = new TaskDefinition(); taskDefinition.setCode(888888L); taskDefinition.setName("unit-test"); - taskDefinition.setProjectCode(111111L); + taskDefinition.setProjectCode(1L); taskDefinition.setTaskType(TaskType.SHELL); - taskDefinition.setUserId(99); + taskDefinition.setUserId(userId); + taskDefinition.setResourceIds("1"); taskDefinition.setVersion(1); taskDefinition.setCreateTime(new Date()); taskDefinition.setUpdateTime(new Date()); @@ -59,4 +75,102 @@ public class TaskDefinitionMapperTest { TaskDefinition taskDefinition = insertOne(); Assert.assertNotEquals(taskDefinition.getId(), 0); } + + @Test + public void testQueryByDefinitionName() { + TaskDefinition taskDefinition = insertOne(); + TaskDefinition result = taskDefinitionMapper.queryByDefinitionName(taskDefinition.getProjectCode() + , taskDefinition.getName()); + + Assert.assertNotNull(result); + } + + @Test + public void testQueryByDefinitionId() { + + User user = new User(); + user.setUserName("un"); + userMapper.insert(user); + User un = userMapper.queryByUserNameAccurately("un"); + + Project project = new Project(); + project.setCode(1L); + project.setCreateTime(new Date()); + project.setUpdateTime(new Date()); + projectMapper.insert(project); + + TaskDefinition taskDefinition = insertOne(un.getId()); + TaskDefinition td = taskDefinitionMapper.queryByDefinitionName(taskDefinition.getProjectCode() + , taskDefinition.getName()); + TaskDefinition result = taskDefinitionMapper.queryByDefinitionId(td.getId()); + Assert.assertNotNull(result); + + } + + @Test + public void testQueryByDefinitionCode() { + TaskDefinition taskDefinition = insertOne(); + TaskDefinition result = taskDefinitionMapper.queryByDefinitionCode(taskDefinition.getCode()); + Assert.assertNotNull(result); + + } + + @Test + public void testQueryAllDefinitionList() { + TaskDefinition taskDefinition = insertOne(); + List taskDefinitions = taskDefinitionMapper.queryAllDefinitionList(taskDefinition.getProjectCode()); + Assert.assertNotEquals(taskDefinitions.size(), 0); + + } + + @Test + public void testQueryDefinitionListByIdList() { + TaskDefinition taskDefinition = insertOne(); + List taskDefinitions = taskDefinitionMapper.queryDefinitionListByIdList(new Integer[]{taskDefinition.getId()}); + Assert.assertNotEquals(taskDefinitions.size(), 0); + + } + + @Test + public void testCountDefinitionGroupByUser() { + User user = new User(); + user.setUserName("un"); + userMapper.insert(user); + User un = userMapper.queryByUserNameAccurately("un"); + TaskDefinition taskDefinition = insertOne(un.getId()); + + List users = taskDefinitionMapper.countDefinitionGroupByUser(new Long[]{taskDefinition.getProjectCode()}); + Assert.assertNotEquals(users.size(), 0); + + } + + @Test + public void testListResources() { + TaskDefinition taskDefinition = insertOne(); + List> maps = taskDefinitionMapper.listResources(); + Assert.assertNotEquals(maps.size(), 0); + + } + + @Test + public void testListResourcesByUser() { + User user = new User(); + user.setUserName("un"); + userMapper.insert(user); + User un = userMapper.queryByUserNameAccurately("un"); + TaskDefinition taskDefinition = insertOne(un.getId()); + + List> maps = taskDefinitionMapper.listResourcesByUser(taskDefinition.getUserId()); + Assert.assertNotEquals(maps.size(), 0); + + } + + @Test + public void testDeleteByCode() { + TaskDefinition taskDefinition = insertOne(); + int i = taskDefinitionMapper.deleteByCode(taskDefinition.getCode()); + Assert.assertNotEquals(i, 0); + + } + } diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/UdfFuncMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/UdfFuncMapperTest.java index ca672e0281..be31df8422 100644 --- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/UdfFuncMapperTest.java +++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/UdfFuncMapperTest.java @@ -195,18 +195,6 @@ public class UdfFuncMapperTest { Assert.assertEquals(delete, 1); } - /** - * test query - */ - @Test - public void testQuery() { - //insertOne - UdfFunc udfFunc = insertOne(); - //query - List udfFuncList = udfFuncMapper.selectList(null); - Assert.assertNotEquals(udfFuncList.size(), 0); - } - /** * test query udf by ids */