Browse Source

refactor dao interface for mybatisplus (#895)

* update english documents

* refactor zk client

* update documents

* update zkclient

* update zkclient

* update documents

* add architecture-design

* change i18n

* update i18n

* update english documents

* add architecture-design

* update english documents

* update en-US documents

* add architecture-design

* update demo site

* add mybatis plus model

* modify mybatisplus

* modify mybatisplus

* change interface by mybatisplus

* add unit test
pull/2/head
bao liang 5 years ago committed by lgcareer
parent
commit
46672d6be5
  1. 17
      escheduler-api/src/main/java/cn/escheduler/api/service/DataAnalysisService.java
  2. 2
      escheduler-api/src/main/java/cn/escheduler/api/service/ProjectService.java
  3. 2
      escheduler-common/src/main/resources/zookeeper.properties
  4. 11
      escheduler-dao/src/main/java/cn/escheduler/dao/App.java
  5. 12
      escheduler-dao/src/main/java/cn/escheduler/dao/ProcessDao.java
  6. 17
      escheduler-dao/src/main/java/cn/escheduler/dao/config/MybatisPlusConfig.java
  7. 59
      escheduler-dao/src/main/java/cn/escheduler/dao/config/YmlConfig.java
  8. 36
      escheduler-dao/src/main/java/cn/escheduler/dao/mapper/ProcessDefinitionMapper.java
  9. 3
      escheduler-dao/src/main/java/cn/escheduler/dao/mapper/ProjectMapper.java
  10. 28
      escheduler-dao/src/main/java/cn/escheduler/dao/mapper/ResourceUserMapper.java
  11. 44
      escheduler-dao/src/main/resources/application.yml
  12. 2
      escheduler-dao/src/main/resources/cn.escheduler.dao.mapper/ErrorCommandMapper.xml
  13. 9
      escheduler-dao/src/main/resources/cn.escheduler.dao.mapper/ProcessDefinitionMapper.xml
  14. 2
      escheduler-dao/src/main/resources/cn.escheduler.dao.mapper/ProjectMapper.xml
  15. 91
      escheduler-dao/src/test/java/cn/escheduler/dao/mapper/DataSourceUserMapperTest.java
  16. 113
      escheduler-dao/src/test/java/cn/escheduler/dao/mapper/ErrorCommandMapperTest.java
  17. 23
      escheduler-dao/src/test/java/cn/escheduler/dao/mapper/ProcessDefinitionMapperTest.java
  18. 117
      escheduler-dao/src/test/java/cn/escheduler/dao/mapper/ProcessInstanceMapMapperTest.java
  19. 124
      escheduler-dao/src/test/java/cn/escheduler/dao/mapper/ProcessInstanceMapperTest.java
  20. 56
      escheduler-dao/src/test/java/cn/escheduler/dao/mapper/ProjectMapperTest.java
  21. 36
      escheduler-dao/src/test/java/cn/escheduler/dao/mapper/ProjectUserMapperTest.java
  22. 40
      escheduler-dao/src/test/java/cn/escheduler/dao/mapper/QueueMapperTest.java
  23. 52
      escheduler-dao/src/test/java/cn/escheduler/dao/mapper/ResourceMapperTest.java
  24. 32
      escheduler-dao/src/test/java/cn/escheduler/dao/mapper/ResourceUserMapperTest.java
  25. 44
      escheduler-dao/src/test/java/cn/escheduler/dao/mapper/ScheduleMapperTest.java
  26. 32
      escheduler-dao/src/test/java/cn/escheduler/dao/mapper/SessionMapperTest.java
  27. 64
      escheduler-dao/src/test/java/cn/escheduler/dao/mapper/TaskInstanceMapperTest.java
  28. 36
      escheduler-dao/src/test/java/cn/escheduler/dao/mapper/UDFUserMapperTest.java

17
escheduler-api/src/main/java/cn/escheduler/api/service/DataAnalysisService.java

@ -27,6 +27,7 @@ import cn.escheduler.common.enums.UserType;
import cn.escheduler.common.queue.ITaskQueue;
import cn.escheduler.common.queue.TaskQueueFactory;
import cn.escheduler.common.utils.DateUtils;
import cn.escheduler.dao.ProcessDao;
import cn.escheduler.dao.entity.*;
import cn.escheduler.dao.mapper.*;
import org.apache.commons.lang3.StringUtils;
@ -67,6 +68,9 @@ public class DataAnalysisService {
@Autowired
TaskInstanceMapper taskInstanceMapper;
@Autowired
ProcessDao processDao;
/**
* statistical task instance status data
*
@ -179,8 +183,11 @@ public class DataAnalysisService {
public Map<String,Object> countDefinitionByUser(User loginUser, int projectId) {
Map<String, Object> result = new HashMap<>();
Integer[] projectIdArray = new Integer[1];
projectIdArray[0] = projectId;
List<DefinitionGroupByUser> defineGroupByUsers = processDefinitionMapper.countDefinitionGroupByUser(
loginUser.getId(), loginUser.getUserType(), String.valueOf(projectId));
loginUser.getId(), projectIdArray);
DefineUserDto dto = new DefineUserDto(defineGroupByUsers);
result.put(Constants.DATA_LIST, dto);
@ -252,8 +259,8 @@ public class DataAnalysisService {
if(projectId !=0){
projectIds.add(projectId);
}else if(loginUser.getUserType() == UserType.GENERAL_USER){
List<Project> authedProjectList = projectMapper.queryAuthedProjectListByUserId(loginUser.getId());
for(Project project : authedProjectList){
List<Project> projects = processDao.getProjectListHavePerm(loginUser.getId());
for(Project project : projects){
projectIds.add(project.getId());
}
}
@ -385,9 +392,7 @@ public class DataAnalysisService {
}
if (tasksKillIds.length != 0){
taskKillCount = taskInstanceMapper.countTask(
loginUser.getId(),loginUser.getUserType(),String.valueOf(projectId),
StringUtils.join(tasksKillIds, ","));
taskKillCount = taskInstanceMapper.countTask(loginUser.getId(),loginUser.getUserType(),projectId, tasksKillIds);
}

2
escheduler-api/src/main/java/cn/escheduler/api/service/ProjectService.java

@ -368,7 +368,7 @@ public class ProjectService extends BaseService{
}
/**
* query all project list
* query all project list that have one or more process definitions.
* @return
*/
public Map<String, Object> queryAllProjectList() {

2
escheduler-common/src/main/resources/zookeeper.properties

@ -1,5 +1,5 @@
#zookeeper cluster. multiple are separated by commas. eg. 192.168.xx.xx:2181,192.168.xx.xx:2181,192.168.xx.xx:2181
zookeeper.quorum=localhost:2181
zookeeper.quorum=192.168.220.188:2181
#escheduler root directory
zookeeper.escheduler.root=/escheduler

11
escheduler-dao/src/main/java/cn/escheduler/dao/App.java

@ -0,0 +1,11 @@
package cn.escheduler.dao;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class App {
public static void main(String[] args){
SpringApplication.run(App.class);
}
}

12
escheduler-dao/src/main/java/cn/escheduler/dao/ProcessDao.java

@ -101,6 +101,9 @@ public class ProcessDao extends AbstractBaseDao {
@Autowired
private TenantMapper tenantMapper;
@Autowired
private ProjectMapper projectMapper;
/**
* task queue impl
*/
@ -1760,5 +1763,14 @@ public class ProcessDao extends AbstractBaseDao {
return taskWorkerGroupId;
}
public List<Project> getProjectListHavePerm(int userId){
List<Project> createProjects = projectMapper.queryProjectCreatedByUser(userId);
List<Project> authedProjects = projectMapper.queryAuthedProjectListByUserId(userId);
createProjects.addAll(authedProjects);
return createProjects;
}
}

17
escheduler-dao/src/main/java/cn/escheduler/dao/config/MybatisPlusConfig.java

@ -0,0 +1,17 @@
package cn.escheduler.dao.config;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
@MapperScan("cn.escheduler.*.mapper")
public class MybatisPlusConfig {
@Bean
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor();
}
}

59
escheduler-dao/src/main/java/cn/escheduler/dao/config/YmlConfig.java

@ -0,0 +1,59 @@
package cn.escheduler.dao.config;
import org.yaml.snakeyaml.*;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* Created by qiaozhanwei on 2019/9/17.
*/
public class YmlConfig {
private static Map<String,String> allMap=new HashMap<String,String>();
static {
Yaml yaml = new Yaml();
InputStream inputStream = YmlConfig.class.getResourceAsStream("/application.yml");
Iterator<Object> result = yaml.loadAll(inputStream).iterator();
while(result.hasNext()){
Map map=(Map)result.next();
iteratorYml( map,null);
}
}
public static void main(String[] args) {
String ss = allMap.get("spring.datasource.url");
System.out.println(ss);
}
public static void iteratorYml(Map map,String key){
Iterator iterator = map.entrySet().iterator();
while(iterator.hasNext()){
Map.Entry entry = (Map.Entry) iterator.next();
Object key2 = entry.getKey();
Object value = entry.getValue();
if(value instanceof LinkedHashMap){
if(key==null){
iteratorYml((Map)value,key2.toString());
}else{
iteratorYml((Map)value,key+"."+key2.toString());
}
}
if(value instanceof String){
if(key==null){
allMap.put(key2.toString(), value.toString());
}
if(key!=null){
allMap.put(key+"."+key2.toString(), value.toString());
}
}
}
}
}

36
escheduler-dao/src/main/java/cn/escheduler/dao/mapper/ProcessDefinitionMapper.java

@ -44,7 +44,39 @@ public interface ProcessDefinitionMapper extends BaseMapper<ProcessDefinition> {
List<DefinitionGroupByUser> countDefinitionGroupByUser(
@Param("userId") Integer userId,
@Param("userType") UserType userType,
@Param("projectIds") String projectIds);
@Param("projectIds") Integer[] projectIds);
/**
* update receivers and cc by definition id
* @param receivers
* @param receiversCc
* @param processDefinitionId
* @return
*/
@UpdateProvider(type = ProcessDefinitionMapperProvider.class, method = "updateReceiversAndCcById")
int updateReceiversAndCcById(@Param("receivers") String receivers,
@Param("receiversCc") String receiversCc,
@Param("processDefinitionId") int processDefinitionId);
/**
* query all
* @return
*/
@Results(value = {@Result(property = "id", column = "id", id = true, javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "name", column = "name", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "version", column = "version", javaType = Integer.class, jdbcType = JdbcType.TINYINT),
@Result(property = "releaseState", column = "release_state", typeHandler = EnumOrdinalTypeHandler.class, javaType = ReleaseState.class, jdbcType = JdbcType.TINYINT),
@Result(property = "projectId", column = "project_id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "userId", column = "user_id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "desc", column = "desc", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "createTime", column = "create_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE),
@Result(property = "updateTime", column = "update_time", javaType = Timestamp.class, jdbcType = JdbcType.DATE),
@Result(property = "flag", column = "flag", typeHandler = EnumOrdinalTypeHandler.class, javaType = Flag.class, jdbcType = JdbcType.TINYINT),
@Result(property = "userName", column = "user_name", javaType = String.class, jdbcType = JdbcType.VARCHAR),
@Result(property = "timeout", column = "timeout", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "tenantId", column = "tenant_id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
@Result(property = "projectName", column = "project_name", javaType = String.class, jdbcType = JdbcType.VARCHAR)
})
@SelectProvider(type = ProcessDefinitionMapperProvider.class, method = "queryAll")
List<ProcessDefinition> queryAll();
}

3
escheduler-dao/src/main/java/cn/escheduler/dao/mapper/ProjectMapper.java

@ -17,6 +17,7 @@
package cn.escheduler.dao.mapper;
import cn.escheduler.dao.entity.Project;
import com.amazonaws.services.dynamodbv2.model.transform.ProjectionJsonUnmarshaller;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Param;
@ -36,7 +37,7 @@ public interface ProjectMapper extends BaseMapper<Project> {
IPage<Project> queryAllProjectListPaging(IPage<Project> page,
@Param("searchName") String searchName);
List<Integer> queryProjectCreatedByUser(@Param("userId") int userId);
List<Project> queryProjectCreatedByUser(@Param("userId") int userId);
List<Project> queryAuthedProjectListByUserId(@Param("userId") int userId);

28
escheduler-dao/src/main/java/cn/escheduler/dao/mapper/ResourceUserMapper.java

@ -0,0 +1,28 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.dao.mapper;
import cn.escheduler.dao.entity.ResourcesUser;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
public interface ResourceUserMapper extends BaseMapper<ResourcesUser> {
int deleteResourceUser(@Param("userId") int userId,
@Param("resourceId") int resourceId);
}

44
escheduler-dao/src/main/resources/application.yml

@ -0,0 +1,44 @@
# mysql
spring:
datasource:
driver-class-name: org.postgresql.Driver
# driver-class-name: com.mysql.jdbc.Driver
url: jdbc:postgresql://192.168.220.154:5432/escheduler
# url: jdbc:mysql://192.168.220.188:3306/escheduler_new?useUnicode=true&characterEncoding=UTF-8
username: root
password: root@123
# platform:
continue-on-error: true
#mybatis
mybatis-plus:
mapper-locations: classpath*:/cn.escheduler.dao.mapper/*.xml
typeEnumsPackage: cn.escheduler.*.enums
#实体扫描,多个package用逗号或者分号分隔
typeAliasesPackage: cn.escheduler.dao.entity
global-config:
#数据库相关配置
db-config:
#主键类型 AUTO:"数据库ID自增", INPUT:"用户输入ID", ID_WORKER:"全局唯一ID (数字类型唯一ID)", UUID:"全局唯一ID UUID";
id-type: AUTO
#字段策略 IGNORED:"忽略判断",NOT_NULL:"非 NULL 判断"),NOT_EMPTY:"非空判断"
field-strategy: NOT_NULL
#驼峰下划线转换
column-underline: true
logic-delete-value: -1
logic-not-delete-value: 0
banner: false
#原生配置
configuration:
map-underscore-to-camel-case: true
cache-enabled: false
call-setters-on-nulls: true
jdbc-type-for-null: 'null'
# Logger Config
logging:
level:
cn.escheduler.dao: debug

2
escheduler-dao/src/main/resources/cn.escheduler.dao.mapper/ErrorCommandMapper.xml

@ -5,7 +5,7 @@
select cmd.command_type as commandType, count(1) as count
from t_escheduler_error_command cmd, t_escheduler_process_definition process
where cmd.process_definition_id = process.id
<if test="projectIdArray != null and projectIdString.length != 0">
<if test="projectIdArray != null and projectIdArray.length != 0">
and process.project_id in
<foreach collection="projectIdArray" index="index" item="i" open="(" close=")" separator=",">
#{i}

9
escheduler-dao/src/main/resources/cn.escheduler.dao.mapper/ProcessDefinitionMapper.xml

@ -43,10 +43,13 @@
FROM t_escheduler_process_definition td
JOIN t_escheduler_user tu on tu.id=td.user_id
where 1 = 1
<if test="projectIds != null and projectIds != ''">
and td.project_id in (#{projectIds})
<if test="projectIds != null and projectIds.length != 0">
and td.project_id in
<foreach collection="projectIds" index="index" item="i" open="(" separator="," close=")">
#{i}
</foreach>
</if>
group by td.user_id
group by td.user_id,tu.user_name
</select>

2
escheduler-dao/src/main/resources/cn.escheduler.dao.mapper/ProjectMapper.xml

@ -56,7 +56,7 @@
from t_escheduler_project
where flag=1 and user_id <![CDATA[ <> ]]> #{userId}
</select>
<select id="queryProjectCreatedByUser" resultType="java.lang.Integer">
<select id="queryProjectCreatedByUser" resultType="cn.escheduler.dao.entity.Project">
select *
from t_escheduler_project
where user_id = #{userId}

91
escheduler-dao/src/test/java/cn/escheduler/dao/mapper/DataSourceUserMapperTest.java

@ -0,0 +1,91 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.dao.mapper;
import cn.escheduler.dao.entity.DatasourceUser;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Date;
import java.util.List;
@RunWith(SpringRunner.class)
@SpringBootTest
public class DataSourceUserMapperTest {
@Autowired
DataSourceUserMapper dataSourceUserMapper;
private DatasourceUser insertOne(){
//insertOne
DatasourceUser dataSourceUser = new DatasourceUser();
dataSourceUser.setUserId(4);
dataSourceUser.setDatasourceId(1010);
dataSourceUser.setPerm(7);
dataSourceUser.setUpdateTime(new Date());
dataSourceUser.setCreateTime(new Date());
return dataSourceUser;
}
@Test
public void testUpdate(){
//insertOne
DatasourceUser dataSourceUser = insertOne();
//update
dataSourceUser.setUpdateTime(new Date());
int update = dataSourceUserMapper.updateById(dataSourceUser);
Assert.assertEquals(update, 1);
dataSourceUserMapper.deleteById(dataSourceUser.getId());
}
@Test
public void testDelete(){
DatasourceUser dataSourceUser = insertOne();
int delete = dataSourceUserMapper.deleteById(dataSourceUser.getId());
Assert.assertEquals(delete, 1);
}
@Test
public void testQuery() {
DatasourceUser dataSourceUser = insertOne();
//query
List<DatasourceUser> dataSources = dataSourceUserMapper.selectList(null);
Assert.assertNotEquals(dataSources.size(), 0);
dataSourceUserMapper.deleteById(dataSourceUser.getId());
}
@Test
public void testDeleteByUserId() {
DatasourceUser dataSourceUser = insertOne();
int delete = dataSourceUserMapper.deleteByUserId(dataSourceUser.getUserId());
Assert.assertNotEquals(delete, 0);
}
@Test
public void testDeleteByDatasourceId() {
DatasourceUser dataSourceUser = insertOne();
int delete = dataSourceUserMapper.deleteByDatasourceId(dataSourceUser.getDatasourceId());
Assert.assertNotEquals(delete, 0);
}
}

113
escheduler-dao/src/test/java/cn/escheduler/dao/mapper/ErrorCommandMapperTest.java

@ -0,0 +1,113 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.dao.mapper;
import cn.escheduler.common.enums.CommandType;
import cn.escheduler.dao.entity.CommandCount;
import cn.escheduler.dao.entity.ErrorCommand;
import cn.escheduler.dao.entity.ProcessDefinition;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Date;
import java.util.List;
@RunWith(SpringRunner.class)
@SpringBootTest
public class ErrorCommandMapperTest {
@Autowired
ErrorCommandMapper errorCommandMapper;
@Autowired
ProcessDefinitionMapper processDefinitionMapper;
private ErrorCommand insertOne(){
//insertOne
ErrorCommand errorCommand = new ErrorCommand();
errorCommand.setId(10101);
errorCommand.setCommandType(CommandType.START_PROCESS);
errorCommand.setUpdateTime(new Date());
errorCommand.setStartTime(new Date());
errorCommandMapper.insert(errorCommand);
return errorCommand;
}
@Test
public void testUpdate(){
//insertOne
ErrorCommand errorCommand = insertOne();
//update
errorCommand.setUpdateTime(new Date());
int update = errorCommandMapper.updateById(errorCommand);
Assert.assertEquals(update, 1);
errorCommandMapper.deleteById(errorCommand.getId());
}
@Test
public void testDelete(){
ErrorCommand errorCommand = insertOne();
int delete = errorCommandMapper.deleteById(errorCommand.getId());
Assert.assertEquals(delete, 1);
}
@Test
public void testQuery() {
errorCommandMapper.delete(null);
ErrorCommand errorCommand = insertOne();
ProcessDefinition processDefinition = new ProcessDefinition();
processDefinition.setName("def 1");
processDefinition.setProjectId(1010);
processDefinition.setUserId(101);
processDefinition.setUpdateTime(new Date());
processDefinition.setCreateTime(new Date());
processDefinitionMapper.insert(processDefinition);
errorCommand.setProcessDefinitionId(processDefinition.getId());
errorCommandMapper.updateById(errorCommand);
List<CommandCount> commandCounts = errorCommandMapper.countCommandState(
null,
null,
new Integer[0]
);
Integer[] projectIdArray = new Integer[2];
projectIdArray[0] = processDefinition.getProjectId();
projectIdArray[1] = 200;
List<CommandCount> commandCounts2 = errorCommandMapper.countCommandState(
null,
null,
projectIdArray
);
errorCommandMapper.deleteById(errorCommand.getId());
processDefinitionMapper.deleteById(processDefinition.getId());
Assert.assertNotEquals(commandCounts.size(), 0);
Assert.assertNotEquals(commandCounts2.size(), 0);
}
}

23
escheduler-dao/src/test/java/cn/escheduler/dao/mapper/ProcessDefinitionMapperTest.java

@ -172,5 +172,28 @@ public class ProcessDefinitionMapperTest {
@Test
public void testCountDefinitionGroupByUser() {
User user= new User();
user.setUserName("user1");
user.setUserPassword("1");
user.setEmail("xx@123.com");
user.setUserType(UserType.GENERAL_USER);
user.setCreateTime(new Date());
user.setTenantId(1);
user.setUpdateTime(new Date());
userMapper.insert(user);
ProcessDefinition processDefinition = insertOne();
processDefinition.setUserId(user.getId());
processDefinitionMapper.updateById(processDefinition);
Integer[] projectIds = new Integer[1];
projectIds[0] = processDefinition.getProjectId();
List<DefinitionGroupByUser> processDefinitions = processDefinitionMapper.countDefinitionGroupByUser(
processDefinition.getUserId(),
projectIds
);
processDefinitionMapper.deleteById(processDefinition.getId());
Assert.assertNotEquals(processDefinitions.size(), 0);
}
}

117
escheduler-dao/src/test/java/cn/escheduler/dao/mapper/ProcessInstanceMapMapperTest.java

@ -0,0 +1,117 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.dao.mapper;
import cn.escheduler.dao.entity.ProcessDefinition;
import cn.escheduler.dao.entity.ProcessInstanceMap;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Date;
import java.util.List;
@RunWith(SpringRunner.class)
@SpringBootTest
public class ProcessInstanceMapMapperTest {
@Autowired
ProcessInstanceMapMapper processInstanceMapMapper;
private ProcessInstanceMap insertOne(){
//insertOne
ProcessInstanceMap processInstanceMap = new ProcessInstanceMap();
processInstanceMap.setProcessInstanceId(0);
processInstanceMap.setParentTaskInstanceId(0);
processInstanceMap.setParentProcessInstanceId(0);
processInstanceMapMapper.insert(processInstanceMap);
return processInstanceMap;
}
@Test
public void testUpdate(){
//insertOne
ProcessInstanceMap processInstanceMap = insertOne();
//update
processInstanceMap.setParentProcessInstanceId(1);
int update = processInstanceMapMapper.updateById(processInstanceMap);
Assert.assertEquals(update, 1);
processInstanceMapMapper.deleteById(processInstanceMap.getId());
}
@Test
public void testDelete(){
ProcessInstanceMap processInstanceMap = insertOne();
int delete = processInstanceMapMapper.deleteById(processInstanceMap.getId());
Assert.assertEquals(delete, 1);
}
@Test
public void testQuery() {
ProcessInstanceMap processInstanceMap = insertOne();
//query
List<ProcessInstanceMap> dataSources = processInstanceMapMapper.selectList(null);
Assert.assertNotEquals(dataSources.size(), 0);
processInstanceMapMapper.deleteById(processInstanceMap.getId());
}
@Test
public void testQueryByParentId() {
ProcessInstanceMap processInstanceMap = insertOne();
processInstanceMap.setParentProcessInstanceId(100);
processInstanceMapMapper.updateById(processInstanceMap);
ProcessInstanceMap map =
processInstanceMapMapper.queryByParentId(processInstanceMap.getParentProcessInstanceId(), processInstanceMap.getParentTaskInstanceId());
Assert.assertNotEquals(map, null);
processInstanceMapMapper.deleteById(processInstanceMap.getId());
}
@Test
public void testQueryBySubProcessId() {
ProcessInstanceMap processInstanceMap = insertOne();
processInstanceMap.setProcessInstanceId(100);
processInstanceMapMapper.updateById(processInstanceMap);
ProcessInstanceMap map =
processInstanceMapMapper.queryBySubProcessId(
processInstanceMap.getProcessInstanceId() );
Assert.assertNotEquals(map, null);
processInstanceMapMapper.deleteById(processInstanceMap.getId());
}
@Test
public void testDeleteByParentProcessId() {
ProcessInstanceMap processInstanceMap = insertOne();
processInstanceMap.setParentProcessInstanceId(100);
processInstanceMapMapper.updateById(processInstanceMap);
int delete = processInstanceMapMapper.deleteByParentProcessId(
processInstanceMap.getParentProcessInstanceId()
);
Assert.assertEquals(delete, 1);
}
}

124
escheduler-dao/src/test/java/cn/escheduler/dao/mapper/ProcessInstanceMapperTest.java

@ -0,0 +1,124 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.dao.mapper;
import cn.escheduler.dao.entity.ProcessInstance;
import cn.escheduler.dao.entity.ProcessInstanceMap;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.List;
@RunWith(SpringRunner.class)
@SpringBootTest
public class ProcessInstanceMapperTest {
@Autowired
ProcessInstanceMapper processInstanceMapper;
private ProcessInstance insertOne(){
//insertOne
ProcessInstance processInstanceMap = new ProcessInstance();
processInstanceMapper.insert(processInstanceMap);
return processInstanceMap;
}
@Test
public void testUpdate(){
//insertOne
ProcessInstance processInstanceMap = insertOne();
//update
int update = processInstanceMapper.updateById(processInstanceMap);
Assert.assertEquals(update, 1);
processInstanceMapper.deleteById(processInstanceMap.getId());
}
@Test
public void testDelete(){
ProcessInstance processInstanceMap = insertOne();
int delete = processInstanceMapper.deleteById(processInstanceMap.getId());
Assert.assertEquals(delete, 1);
}
@Test
public void testQuery() {
ProcessInstance processInstanceMap = insertOne();
//query
List<ProcessInstance> dataSources = processInstanceMapper.selectList(null);
Assert.assertNotEquals(dataSources.size(), 0);
processInstanceMapper.deleteById(processInstanceMap.getId());
}
@Test
public void testQueryDetailById() {
}
@Test
public void testQueryByHostAndStatus() {
}
@Test
public void testQueryProcessInstanceListPaging() {
}
@Test
public void testSetFailoverByHostAndStateArray() {
}
@Test
public void testUpdateProcessInstanceByState() {
}
@Test
public void testQueryByTaskId() {
}
@Test
public void testCountInstanceStateByUser() {
}
@Test
public void testQuerySubIdListByParentId() {
}
@Test
public void testQueryByProcessDefineId() {
}
@Test
public void testQueryByScheduleTime() {
}
@Test
public void testQueryLastSchedulerProcess() {
}
@Test
public void testQueryLastRunningProcess() {
}
@Test
public void testQueryLastManualProcess() {
}
}

56
escheduler-dao/src/test/java/cn/escheduler/dao/mapper/ProjectMapperTest.java

@ -0,0 +1,56 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.dao.mapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class ProjectMapperTest {
@Test
public void testQueryDetailById() {
}
@Test
public void testQueryProjectByName() {
}
@Test
public void testQueryProjectListPaging() {
}
@Test
public void testQueryAllProjectListPaging() {
}
@Test
public void testQueryProjectCreatedByUser() {
}
@Test
public void testQueryAuthedProjectListByUserId() {
}
@Test
public void testQueryProjectExceptUserId() {
}
}

36
escheduler-dao/src/test/java/cn/escheduler/dao/mapper/ProjectUserMapperTest.java

@ -0,0 +1,36 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.dao.mapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class ProjectUserMapperTest {
@Test
public void testDeleteProjectRelation() {
}
@Test
public void testQueryProjectRelation() {
}
}

40
escheduler-dao/src/test/java/cn/escheduler/dao/mapper/QueueMapperTest.java

@ -0,0 +1,40 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.dao.mapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class QueueMapperTest {
@Test
public void testQueryQueuePaging() {
}
@Test
public void testQueryByQueue() {
}
@Test
public void testQueryByQueueName() {
}
}

52
escheduler-dao/src/test/java/cn/escheduler/dao/mapper/ResourceMapperTest.java

@ -0,0 +1,52 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.dao.mapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class ResourceMapperTest {
@Test
public void testQueryResourceList() {
}
@Test
public void testQueryResourcePaging() {
}
@Test
public void testQueryResourceListAuthored() {
}
@Test
public void testQueryAuthorizedResourceList() {
}
@Test
public void testQueryResourceExceptUserId() {
}
@Test
public void testQueryTenantCodeByResourceName() {
}
}

32
escheduler-dao/src/test/java/cn/escheduler/dao/mapper/ResourceUserMapperTest.java

@ -0,0 +1,32 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.dao.mapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class ResourceUserMapperTest {
@Test
public void testDeleteResourceUser() {
}
}

44
escheduler-dao/src/test/java/cn/escheduler/dao/mapper/ScheduleMapperTest.java

@ -0,0 +1,44 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.dao.mapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class ScheduleMapperTest {
@Test
public void testQueryByProcessDefineIdPaging() {
}
@Test
public void testQuerySchedulerListByProjectName() {
}
@Test
public void testSelectAllByProcessDefineArray() {
}
@Test
public void testQueryByProcessDefinitionId() {
}
}

32
escheduler-dao/src/test/java/cn/escheduler/dao/mapper/SessionMapperTest.java

@ -0,0 +1,32 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.dao.mapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class SessionMapperTest {
@Test
public void testQueryByUserId() {
}
}

64
escheduler-dao/src/test/java/cn/escheduler/dao/mapper/TaskInstanceMapperTest.java

@ -0,0 +1,64 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.dao.mapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class TaskInstanceMapperTest {
@Test
public void testQueryTaskByProcessIdAndState() {
}
@Test
public void testQueryById() {
}
@Test
public void testFindValidTaskListByProcessId() {
}
@Test
public void testQueryByHostAndStatus() {
}
@Test
public void testSetFailoverByHostAndStateArray() {
}
@Test
public void testQueryByInstanceIdAndName() {
}
@Test
public void testCountTask() {
}
@Test
public void testCountTaskInstanceStateByUser() {
}
@Test
public void testQueryTaskInstanceListPaging() {
}
}

36
escheduler-dao/src/test/java/cn/escheduler/dao/mapper/UDFUserMapperTest.java

@ -0,0 +1,36 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.dao.mapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class UDFUserMapperTest {
@Test
public void testDeleteByUserId() {
}
@Test
public void testDeleteByUdfFuncId() {
}
}
Loading…
Cancel
Save