Search in sources :

Example 1 with User

use of org.apache.dolphinscheduler.dao.entity.User in project dolphinscheduler by apache.

the class ProcessDefinitionServiceTest method testQueryProcessDefinitionById.

@Test
public void testQueryProcessDefinitionById() {
    String projectName = "project_test1";
    Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName));
    Project project = getProject(projectName);
    User loginUser = new User();
    loginUser.setId(-1);
    loginUser.setUserType(UserType.GENERAL_USER);
    Map<String, Object> result = new HashMap<>(5);
    putMsg(result, Status.PROJECT_NOT_FOUNT, projectName);
    // project check auth fail
    Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result);
    Map<String, Object> map = processDefinitionService.queryProcessDefinitionById(loginUser, "project_test1", 1);
    Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS));
    // project check auth success, instance not exist
    putMsg(result, Status.SUCCESS, projectName);
    Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result);
    Mockito.when(processDefineMapper.selectById(1)).thenReturn(null);
    Map<String, Object> instanceNotexitRes = processDefinitionService.queryProcessDefinitionById(loginUser, "project_test1", 1);
    Assert.assertEquals(Status.PROCESS_INSTANCE_NOT_EXIST, instanceNotexitRes.get(Constants.STATUS));
    // instance exit
    Mockito.when(processDefineMapper.selectById(46)).thenReturn(getProcessDefinition());
    Map<String, Object> successRes = processDefinitionService.queryProcessDefinitionById(loginUser, "project_test1", 46);
    Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS));
}
Also used : Project(org.apache.dolphinscheduler.dao.entity.Project) User(org.apache.dolphinscheduler.dao.entity.User) HashMap(java.util.HashMap) JSONObject(com.alibaba.fastjson.JSONObject) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 2 with User

use of org.apache.dolphinscheduler.dao.entity.User in project dolphinscheduler by apache.

the class ProcessDefinitionServiceTest method testVerifyProcessDefinitionName.

@Test
public void testVerifyProcessDefinitionName() {
    String projectName = "project_test1";
    Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName));
    Project project = getProject(projectName);
    User loginUser = new User();
    loginUser.setId(-1);
    loginUser.setUserType(UserType.GENERAL_USER);
    // project check auth fail
    Map<String, Object> result = new HashMap<>(5);
    putMsg(result, Status.PROJECT_NOT_FOUNT, projectName);
    Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result);
    Map<String, Object> map = processDefinitionService.verifyProcessDefinitionName(loginUser, "project_test1", "test_pdf");
    Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS));
    // project check auth success, process not exist
    putMsg(result, Status.SUCCESS, projectName);
    Mockito.when(processDefineMapper.verifyByDefineName(project.getId(), "test_pdf")).thenReturn(null);
    Map<String, Object> processNotExistRes = processDefinitionService.verifyProcessDefinitionName(loginUser, "project_test1", "test_pdf");
    Assert.assertEquals(Status.SUCCESS, processNotExistRes.get(Constants.STATUS));
    // process exist
    Mockito.when(processDefineMapper.verifyByDefineName(project.getId(), "test_pdf")).thenReturn(getProcessDefinition());
    Map<String, Object> processExistRes = processDefinitionService.verifyProcessDefinitionName(loginUser, "project_test1", "test_pdf");
    Assert.assertEquals(Status.VERIFY_PROCESS_DEFINITION_NAME_UNIQUE_ERROR, processExistRes.get(Constants.STATUS));
}
Also used : Project(org.apache.dolphinscheduler.dao.entity.Project) User(org.apache.dolphinscheduler.dao.entity.User) HashMap(java.util.HashMap) JSONObject(com.alibaba.fastjson.JSONObject) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 3 with User

use of org.apache.dolphinscheduler.dao.entity.User in project dolphinscheduler by apache.

the class ProcessDefinitionServiceTest method testImportSubProcess.

/**
 * import sub process test
 */
@Test
public void testImportSubProcess() {
    User loginUser = new User();
    loginUser.setId(1);
    loginUser.setUserType(UserType.ADMIN_USER);
    Project testProject = getProject("test");
    // Recursive subprocess sub2 process in sub1 process and sub1process in top process
    String topProcessJson = "{\"globalParams\":[]," + "\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-38634\",\"name\":\"shell1\"," + "\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"#!/bin/bash\\necho \\\"shell-1\\\"\"}," + "\"description\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\"," + "\"retryInterval\":\"1\",\"timeout\":{\"strategy\":\"\",\"interval\":null,\"enable\":false}," + "\"taskInstancePriority\":\"MEDIUM\",\"workerGroupId\":-1,\"preTasks\":[]}," + "{\"type\":\"SUB_PROCESS\",\"id\":\"tasks-44207\",\"name\":\"shell-4\"," + "\"params\":{\"processDefinitionId\":39},\"description\":\"\",\"runFlag\":\"NORMAL\"," + "\"dependence\":{},\"timeout\":{\"strategy\":\"\",\"interval\":null,\"enable\":false}," + "\"taskInstancePriority\":\"MEDIUM\",\"workerGroupId\":-1," + "\"preTasks\":[\"shell1\"]}],\"tenantId\":1,\"timeout\":0}";
    String sub1ProcessJson = "{\"globalParams\":[],\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-84090\"," + "\"name\":\"shell-4\",\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"#!/bin/bash\\necho \\\"shell-4\\\"\"}," + "\"description\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\"," + "\"retryInterval\":\"1\",\"timeout\":{\"strategy\":\"\",\"interval\":null,\"enable\":false}," + "\"taskInstancePriority\":\"MEDIUM\",\"workerGroupId\":-1,\"preTasks\":[]},{\"type\":\"SUB_PROCESS\"," + "\"id\":\"tasks-87364\",\"name\":\"shell-5\"," + "\"params\":{\"processDefinitionId\":46},\"description\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{}," + "\"timeout\":{\"strategy\":\"\",\"interval\":null,\"enable\":false},\"taskInstancePriority\":\"MEDIUM\"," + "\"workerGroupId\":-1,\"preTasks\":[\"shell-4\"]}],\"tenantId\":1,\"timeout\":0}";
    String sub2ProcessJson = "{\"globalParams\":[]," + "\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-52423\",\"name\":\"shell-5\"," + "\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"echo \\\"shell-5\\\"\"},\"description\":\"\"," + "\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\",\"retryInterval\":\"1\"," + "\"timeout\":{\"strategy\":\"\",\"interval\":null,\"enable\":false},\"taskInstancePriority\":\"MEDIUM\",\"workerGroupId\":-1," + "\"preTasks\":[]}],\"tenantId\":1,\"timeout\":0}";
    JSONObject jsonObject = JSONUtils.parseObject(topProcessJson);
    JSONArray jsonArray = (JSONArray) jsonObject.get("tasks");
    String originSubJson = jsonArray.toString();
    Map<Integer, Integer> subProcessIdMap = new HashMap<>(20);
    ProcessDefinition shellDefinition1 = new ProcessDefinition();
    shellDefinition1.setId(39);
    shellDefinition1.setName("shell-4");
    shellDefinition1.setProjectId(2);
    shellDefinition1.setProcessDefinitionJson(sub1ProcessJson);
    ProcessDefinition shellDefinition2 = new ProcessDefinition();
    shellDefinition2.setId(46);
    shellDefinition2.setName("shell-5");
    shellDefinition2.setProjectId(2);
    shellDefinition2.setProcessDefinitionJson(sub2ProcessJson);
    Mockito.when(processDefineMapper.queryByDefineId(39)).thenReturn(shellDefinition1);
    Mockito.when(processDefineMapper.queryByDefineId(46)).thenReturn(shellDefinition2);
    Mockito.when(processDefineMapper.queryByDefineName(testProject.getId(), "shell-5")).thenReturn(null);
    Mockito.when(processDefineMapper.queryByDefineName(testProject.getId(), "shell-4")).thenReturn(null);
    Mockito.when(processDefineMapper.queryByDefineName(testProject.getId(), "testProject")).thenReturn(shellDefinition2);
    processDefinitionService.importSubProcess(loginUser, testProject, jsonArray, subProcessIdMap);
    String correctSubJson = jsonArray.toString();
    Assert.assertEquals(originSubJson, correctSubJson);
}
Also used : Project(org.apache.dolphinscheduler.dao.entity.Project) User(org.apache.dolphinscheduler.dao.entity.User) JSONObject(com.alibaba.fastjson.JSONObject) HashMap(java.util.HashMap) JSONArray(com.alibaba.fastjson.JSONArray) ProcessDefinition(org.apache.dolphinscheduler.dao.entity.ProcessDefinition) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 4 with User

use of org.apache.dolphinscheduler.dao.entity.User in project dolphinscheduler by apache.

the class ProcessDefinitionServiceTest method testCopyProcessDefinition.

@Test
public void testCopyProcessDefinition() throws Exception {
    String projectName = "project_test1";
    Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName));
    Project project = getProject(projectName);
    User loginUser = new User();
    loginUser.setId(-1);
    loginUser.setUserType(UserType.GENERAL_USER);
    Map<String, Object> result = new HashMap<>(5);
    // project check auth success, instance not exist
    putMsg(result, Status.SUCCESS, projectName);
    Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result);
    ProcessDefinition definition = getProcessDefinition();
    definition.setLocations("{\"tasks-36196\":{\"name\":\"ssh_test1\",\"targetarr\":\"\",\"x\":141,\"y\":70}}");
    definition.setProcessDefinitionJson("{\"globalParams\":[]," + "\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-36196\",\"name\":\"ssh_test1\"," + "\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"aa=\\\"1234\\\"\\necho ${aa}\"},\"desc\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{}," + "\"maxRetryTimes\":\"0\",\"retryInterval\":\"1\",\"timeout\":{\"strategy\":\"\",\"interval\":null,\"enable\":false}," + "\"taskInstancePriority\":\"MEDIUM\",\"workerGroupId\":-1,\"preTasks\":[]}],\"tenantId\":-1,\"timeout\":0}");
    definition.setConnects("[]");
    // instance exit
    Mockito.when(processDefineMapper.selectById(46)).thenReturn(definition);
    Map<String, Object> createProcessResult = new HashMap<>(5);
    putMsg(result, Status.SUCCESS);
    Mockito.when(processDefinitionService.createProcessDefinition(loginUser, definition.getProjectName(), definition.getName(), definition.getProcessDefinitionJson(), definition.getDescription(), definition.getLocations(), definition.getConnects())).thenReturn(createProcessResult);
    Map<String, Object> successRes = processDefinitionService.copyProcessDefinition(loginUser, "project_test1", 46);
    Assert.assertEquals(Status.SUCCESS, successRes.get(Constants.STATUS));
}
Also used : Project(org.apache.dolphinscheduler.dao.entity.Project) User(org.apache.dolphinscheduler.dao.entity.User) HashMap(java.util.HashMap) JSONObject(com.alibaba.fastjson.JSONObject) ProcessDefinition(org.apache.dolphinscheduler.dao.entity.ProcessDefinition) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 5 with User

use of org.apache.dolphinscheduler.dao.entity.User in project dolphinscheduler by apache.

the class ProcessDefinitionServiceTest method testReleaseProcessDefinition.

@Test
public void testReleaseProcessDefinition() {
    String projectName = "project_test1";
    Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName));
    Project project = getProject(projectName);
    User loginUser = new User();
    loginUser.setId(-1);
    loginUser.setUserType(UserType.GENERAL_USER);
    // project check auth fail
    Map<String, Object> result = new HashMap<>(5);
    putMsg(result, Status.PROJECT_NOT_FOUNT, projectName);
    Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectName)).thenReturn(result);
    Map<String, Object> map = processDefinitionService.releaseProcessDefinition(loginUser, "project_test1", 6, ReleaseState.OFFLINE.getCode());
    Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS));
    // project check auth success, processs definition online
    putMsg(result, Status.SUCCESS, projectName);
    Mockito.when(processDefineMapper.selectById(46)).thenReturn(getProcessDefinition());
    Mockito.when(processDefineMapper.updateById(getProcessDefinition())).thenReturn(1);
    Map<String, Object> onlineRes = processDefinitionService.releaseProcessDefinition(loginUser, "project_test1", 46, ReleaseState.ONLINE.getCode());
    Assert.assertEquals(Status.SUCCESS, onlineRes.get(Constants.STATUS));
    // release error code
    Map<String, Object> failRes = processDefinitionService.releaseProcessDefinition(loginUser, "project_test1", 46, 2);
    Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, failRes.get(Constants.STATUS));
}
Also used : Project(org.apache.dolphinscheduler.dao.entity.Project) User(org.apache.dolphinscheduler.dao.entity.User) HashMap(java.util.HashMap) JSONObject(com.alibaba.fastjson.JSONObject) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

User (org.apache.dolphinscheduler.dao.entity.User)123 Test (org.junit.Test)90 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)39 Project (org.apache.dolphinscheduler.dao.entity.Project)28 ArrayList (java.util.ArrayList)22 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)17 IPage (com.baomidou.mybatisplus.core.metadata.IPage)16 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)16 List (java.util.List)15 HashMap (java.util.HashMap)14 UDFUser (org.apache.dolphinscheduler.dao.entity.UDFUser)14 JSONObject (com.alibaba.fastjson.JSONObject)13 Date (java.util.Date)13 UdfFunc (org.apache.dolphinscheduler.dao.entity.UdfFunc)13 ProcessDefinition (org.apache.dolphinscheduler.dao.entity.ProcessDefinition)11 PageInfo (org.apache.dolphinscheduler.api.utils.PageInfo)10 Resource (org.apache.dolphinscheduler.dao.entity.Resource)10 Result (org.apache.dolphinscheduler.api.utils.Result)9 ProjectUser (org.apache.dolphinscheduler.dao.entity.ProjectUser)9 Schedule (org.apache.dolphinscheduler.dao.entity.Schedule)7