|
|
@ -17,12 +17,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.apache.dolphinscheduler.api.service; |
|
|
|
package org.apache.dolphinscheduler.api.service; |
|
|
|
|
|
|
|
|
|
|
|
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.PROJECT_OVERVIEW; |
|
|
|
import org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant; |
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
|
|
|
|
import static org.mockito.ArgumentMatchers.any; |
|
|
|
|
|
|
|
import static org.mockito.ArgumentMatchers.anyInt; |
|
|
|
|
|
|
|
import static org.mockito.ArgumentMatchers.anyLong; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.api.dto.CommandStateCount; |
|
|
|
import org.apache.dolphinscheduler.api.dto.CommandStateCount; |
|
|
|
import org.apache.dolphinscheduler.api.enums.Status; |
|
|
|
import org.apache.dolphinscheduler.api.enums.Status; |
|
|
|
import org.apache.dolphinscheduler.api.service.impl.BaseServiceImpl; |
|
|
|
import org.apache.dolphinscheduler.api.service.impl.BaseServiceImpl; |
|
|
@ -44,16 +39,7 @@ import org.apache.dolphinscheduler.dao.mapper.ProcessInstanceMapper; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper; |
|
|
|
import org.apache.dolphinscheduler.plugin.task.api.enums.ExecutionStatus; |
|
|
|
import org.apache.dolphinscheduler.plugin.task.api.enums.ExecutionStatus; |
|
|
|
import org.apache.dolphinscheduler.service.permission.ResourcePermissionCheckService; |
|
|
|
import org.apache.dolphinscheduler.api.permission.ResourcePermissionCheckService; |
|
|
|
import org.apache.dolphinscheduler.service.process.ProcessService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.text.MessageFormat; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
import java.util.Collections; |
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.junit.After; |
|
|
|
import org.junit.After; |
|
|
|
import org.junit.Assert; |
|
|
|
import org.junit.Assert; |
|
|
|
import org.junit.Before; |
|
|
|
import org.junit.Before; |
|
|
@ -67,6 +53,21 @@ import org.powermock.modules.junit4.PowerMockRunner; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.text.MessageFormat; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
import java.util.Collections; |
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
|
|
|
import java.util.HashSet; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant.PROJECT_OVERVIEW; |
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
|
|
|
|
import static org.mockito.ArgumentMatchers.any; |
|
|
|
|
|
|
|
import static org.mockito.ArgumentMatchers.anyInt; |
|
|
|
|
|
|
|
import static org.mockito.ArgumentMatchers.anyLong; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* data analysis service test |
|
|
|
* data analysis service test |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -75,6 +76,8 @@ public class DataAnalysisServiceTest { |
|
|
|
|
|
|
|
|
|
|
|
private static final Logger baseServiceLogger = LoggerFactory.getLogger(BaseServiceImpl.class); |
|
|
|
private static final Logger baseServiceLogger = LoggerFactory.getLogger(BaseServiceImpl.class); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final Logger serviceLogger = LoggerFactory.getLogger(DataAnalysisServiceImpl.class); |
|
|
|
|
|
|
|
|
|
|
|
@InjectMocks |
|
|
|
@InjectMocks |
|
|
|
private DataAnalysisServiceImpl dataAnalysisServiceImpl; |
|
|
|
private DataAnalysisServiceImpl dataAnalysisServiceImpl; |
|
|
|
|
|
|
|
|
|
|
@ -99,9 +102,6 @@ public class DataAnalysisServiceTest { |
|
|
|
@Mock |
|
|
|
@Mock |
|
|
|
TaskInstanceMapper taskInstanceMapper; |
|
|
|
TaskInstanceMapper taskInstanceMapper; |
|
|
|
|
|
|
|
|
|
|
|
@Mock |
|
|
|
|
|
|
|
ProcessService processService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Mock |
|
|
|
@Mock |
|
|
|
private ResourcePermissionCheckService resourcePermissionCheckService; |
|
|
|
private ResourcePermissionCheckService resourcePermissionCheckService; |
|
|
|
|
|
|
|
|
|
|
@ -113,6 +113,7 @@ public class DataAnalysisServiceTest { |
|
|
|
public void setUp() { |
|
|
|
public void setUp() { |
|
|
|
|
|
|
|
|
|
|
|
user = new User(); |
|
|
|
user = new User(); |
|
|
|
|
|
|
|
user.setId(1); |
|
|
|
Project project = new Project(); |
|
|
|
Project project = new Project(); |
|
|
|
project.setId(1); |
|
|
|
project.setId(1); |
|
|
|
project.setName("test"); |
|
|
|
project.setName("test"); |
|
|
@ -198,6 +199,8 @@ public class DataAnalysisServiceTest { |
|
|
|
|
|
|
|
|
|
|
|
// when general user doesn't have any task then return all count are 0
|
|
|
|
// when general user doesn't have any task then return all count are 0
|
|
|
|
user.setUserType(UserType.GENERAL_USER); |
|
|
|
user.setUserType(UserType.GENERAL_USER); |
|
|
|
|
|
|
|
Mockito.when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, 1, serviceLogger)) |
|
|
|
|
|
|
|
.thenReturn(projectIds()); |
|
|
|
Mockito.when(taskInstanceMapper.countTaskInstanceStateByProjectCodes(any(), any(), any())).thenReturn( |
|
|
|
Mockito.when(taskInstanceMapper.countTaskInstanceStateByProjectCodes(any(), any(), any())).thenReturn( |
|
|
|
Collections.emptyList()); |
|
|
|
Collections.emptyList()); |
|
|
|
result = dataAnalysisServiceImpl.countTaskStateByProject(user, 1, null, null); |
|
|
|
result = dataAnalysisServiceImpl.countTaskStateByProject(user, 1, null, null); |
|
|
@ -214,6 +217,7 @@ public class DataAnalysisServiceTest { |
|
|
|
putMsg(result, Status.SUCCESS, null); |
|
|
|
putMsg(result, Status.SUCCESS, null); |
|
|
|
Mockito.when(projectService.checkProjectAndAuth(any(), any(), anyLong(),any())).thenReturn(result); |
|
|
|
Mockito.when(projectService.checkProjectAndAuth(any(), any(), anyLong(),any())).thenReturn(result); |
|
|
|
Mockito.when(projectMapper.queryByCode(1L)).thenReturn(getProject("test")); |
|
|
|
Mockito.when(projectMapper.queryByCode(1L)).thenReturn(getProject("test")); |
|
|
|
|
|
|
|
Mockito.when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, 1, serviceLogger)).thenReturn(projectIds()); |
|
|
|
|
|
|
|
|
|
|
|
// when instanceStateCounter return null, then return nothing
|
|
|
|
// when instanceStateCounter return null, then return nothing
|
|
|
|
user.setUserType(UserType.GENERAL_USER); |
|
|
|
user.setUserType(UserType.GENERAL_USER); |
|
|
@ -259,6 +263,11 @@ public class DataAnalysisServiceTest { |
|
|
|
|
|
|
|
|
|
|
|
Mockito.when(processDefinitionMapper.countDefinitionByProjectCodes( |
|
|
|
Mockito.when(processDefinitionMapper.countDefinitionByProjectCodes( |
|
|
|
Mockito.any(Long[].class))).thenReturn(new ArrayList<DefinitionGroupByUser>()); |
|
|
|
Mockito.any(Long[].class))).thenReturn(new ArrayList<DefinitionGroupByUser>()); |
|
|
|
|
|
|
|
Mockito.when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, 1, serviceLogger)).thenReturn(projectIds()); |
|
|
|
|
|
|
|
result = dataAnalysisServiceImpl.countDefinitionByUser(user, 0); |
|
|
|
|
|
|
|
Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Mockito.when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, 1, serviceLogger)).thenReturn(Collections.emptySet()); |
|
|
|
result = dataAnalysisServiceImpl.countDefinitionByUser(user, 0); |
|
|
|
result = dataAnalysisServiceImpl.countDefinitionByUser(user, 0); |
|
|
|
Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); |
|
|
|
Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); |
|
|
|
} |
|
|
|
} |
|
|
@ -272,7 +281,7 @@ public class DataAnalysisServiceTest { |
|
|
|
CommandCount commandCount = new CommandCount(); |
|
|
|
CommandCount commandCount = new CommandCount(); |
|
|
|
commandCount.setCommandType(CommandType.START_PROCESS); |
|
|
|
commandCount.setCommandType(CommandType.START_PROCESS); |
|
|
|
commandCounts.add(commandCount); |
|
|
|
commandCounts.add(commandCount); |
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.DATA_ANALYSIS, user.getId(), PROJECT_OVERVIEW, baseServiceLogger)).thenReturn(true); |
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.DATA_ANALYSIS, user.getId(), ApiFuncIdentificationConstant.MONITOR_STATISTICS_VIEW, baseServiceLogger)).thenReturn(true); |
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.DATA_ANALYSIS, null, 0, baseServiceLogger)).thenReturn(true); |
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.DATA_ANALYSIS, null, 0, baseServiceLogger)).thenReturn(true); |
|
|
|
Mockito.when(commandMapper.countCommandState(0, null, null, new Long[]{1L})).thenReturn(commandCounts); |
|
|
|
Mockito.when(commandMapper.countCommandState(0, null, null, new Long[]{1L})).thenReturn(commandCounts); |
|
|
|
Mockito.when(errorCommandMapper.countCommandState(0, null, null, new Long[]{1L})).thenReturn(commandCounts); |
|
|
|
Mockito.when(errorCommandMapper.countCommandState(0, null, null, new Long[]{1L})).thenReturn(commandCounts); |
|
|
@ -283,6 +292,8 @@ public class DataAnalysisServiceTest { |
|
|
|
// when no command found then return all count are 0
|
|
|
|
// when no command found then return all count are 0
|
|
|
|
Mockito.when(commandMapper.countCommandState(anyInt(), any(), any(), any())).thenReturn(Collections.emptyList()); |
|
|
|
Mockito.when(commandMapper.countCommandState(anyInt(), any(), any(), any())).thenReturn(Collections.emptyList()); |
|
|
|
Mockito.when(errorCommandMapper.countCommandState(anyInt(), any(), any(), any())).thenReturn(Collections.emptyList()); |
|
|
|
Mockito.when(errorCommandMapper.countCommandState(anyInt(), any(), any(), any())).thenReturn(Collections.emptyList()); |
|
|
|
|
|
|
|
Mockito.when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, 1, serviceLogger)).thenReturn(projectIds()); |
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> result5 = dataAnalysisServiceImpl.countCommandState(user); |
|
|
|
Map<String, Object> result5 = dataAnalysisServiceImpl.countCommandState(user); |
|
|
|
assertThat(result5).containsEntry(Constants.STATUS, Status.SUCCESS); |
|
|
|
assertThat(result5).containsEntry(Constants.STATUS, Status.SUCCESS); |
|
|
|
assertThat(result5.get(Constants.DATA_LIST)).asList().extracting("errorCount").allMatch(count -> count.equals(0)); |
|
|
|
assertThat(result5.get(Constants.DATA_LIST)).asList().extracting("errorCount").allMatch(count -> count.equals(0)); |
|
|
@ -317,6 +328,12 @@ public class DataAnalysisServiceTest { |
|
|
|
.allMatch(count -> count.equals(0)); |
|
|
|
.allMatch(count -> count.equals(0)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Set<Integer> projectIds() { |
|
|
|
|
|
|
|
Set<Integer> projectIds = new HashSet<>(); |
|
|
|
|
|
|
|
projectIds.add(1); |
|
|
|
|
|
|
|
return projectIds; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* get list |
|
|
|
* get list |
|
|
|
*/ |
|
|
|
*/ |
|
|
|