|
|
|
@ -32,12 +32,15 @@ import org.apache.dolphinscheduler.api.enums.Status;
|
|
|
|
|
import org.apache.dolphinscheduler.api.exceptions.ServiceException; |
|
|
|
|
import org.apache.dolphinscheduler.api.permission.ResourcePermissionCheckService; |
|
|
|
|
import org.apache.dolphinscheduler.api.service.impl.DataAnalysisServiceImpl; |
|
|
|
|
import org.apache.dolphinscheduler.api.utils.PageInfo; |
|
|
|
|
import org.apache.dolphinscheduler.api.vo.TaskInstanceCountVO; |
|
|
|
|
import org.apache.dolphinscheduler.common.constants.Constants; |
|
|
|
|
import org.apache.dolphinscheduler.common.enums.AuthorizationType; |
|
|
|
|
import org.apache.dolphinscheduler.common.enums.CommandType; |
|
|
|
|
import org.apache.dolphinscheduler.common.enums.UserType; |
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.Command; |
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.CommandCount; |
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.ErrorCommand; |
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount; |
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.Project; |
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.User; |
|
|
|
@ -70,6 +73,9 @@ import org.mockito.quality.Strictness;
|
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* data analysis service test |
|
|
|
|
*/ |
|
|
|
@ -110,13 +116,17 @@ public class DataAnalysisServiceTest {
|
|
|
|
|
|
|
|
|
|
private User user; |
|
|
|
|
|
|
|
|
|
private Project project; |
|
|
|
|
|
|
|
|
|
@BeforeEach |
|
|
|
|
public void setUp() { |
|
|
|
|
|
|
|
|
|
user = new User(); |
|
|
|
|
user.setUserType(UserType.ADMIN_USER); |
|
|
|
|
user.setId(1); |
|
|
|
|
Project project = new Project(); |
|
|
|
|
project = new Project(); |
|
|
|
|
project.setId(1); |
|
|
|
|
project.setCode(1); |
|
|
|
|
project.setName("test"); |
|
|
|
|
resultMap = new HashMap<>(); |
|
|
|
|
|
|
|
|
@ -285,6 +295,66 @@ public class DataAnalysisServiceTest {
|
|
|
|
|
.allMatch(count -> count.equals(0)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testListPendingCommands() { |
|
|
|
|
IPage<Command> page = new Page<>(1, 10); |
|
|
|
|
page.setTotal(2L); |
|
|
|
|
page.setRecords(getList()); |
|
|
|
|
when(commandMapper.queryCommandPage(any())).thenReturn(page); |
|
|
|
|
PageInfo<Command> list1 = dataAnalysisServiceImpl.listPendingCommands(user, 1L, 1, 10); |
|
|
|
|
assertThat(list1.getTotal()).isEqualTo(2); |
|
|
|
|
user.setUserType(UserType.GENERAL_USER); |
|
|
|
|
when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, 1, |
|
|
|
|
serviceLogger)) |
|
|
|
|
.thenReturn(projectIds()); |
|
|
|
|
PageInfo<Command> list2 = dataAnalysisServiceImpl.listPendingCommands(user, 1L, 1, 10); |
|
|
|
|
assertThat(list2.getTotal()).isEqualTo(0); |
|
|
|
|
when(projectMapper.selectBatchIds(any())).thenReturn(Collections.singletonList(project)); |
|
|
|
|
when(processDefinitionMapper.queryDefinitionCodeListByProjectCodes(any())) |
|
|
|
|
.thenReturn(Collections.singletonList(1L)); |
|
|
|
|
when(commandMapper.queryCommandPageByIds(any(), any())).thenReturn(page); |
|
|
|
|
PageInfo<Command> list3 = dataAnalysisServiceImpl.listPendingCommands(user, 1L, 1, 10); |
|
|
|
|
assertThat(list3.getTotal()).isEqualTo(2); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testListErrorCommand() { |
|
|
|
|
IPage<ErrorCommand> page = new Page<>(1, 10); |
|
|
|
|
page.setTotal(2L); |
|
|
|
|
page.setRecords(getErrorList()); |
|
|
|
|
when(errorCommandMapper.queryErrorCommandPage(any())).thenReturn(page); |
|
|
|
|
PageInfo<ErrorCommand> list1 = dataAnalysisServiceImpl.listErrorCommand(user, 1L, 1, 10); |
|
|
|
|
assertThat(list1.getTotal()).isEqualTo(2); |
|
|
|
|
user.setUserType(UserType.GENERAL_USER); |
|
|
|
|
when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.PROJECTS, 1, |
|
|
|
|
serviceLogger)) |
|
|
|
|
.thenReturn(projectIds()); |
|
|
|
|
PageInfo<ErrorCommand> list2 = dataAnalysisServiceImpl.listErrorCommand(user, 1L, 1, 10); |
|
|
|
|
assertThat(list2.getTotal()).isEqualTo(0); |
|
|
|
|
when(projectMapper.selectBatchIds(any())).thenReturn(Collections.singletonList(project)); |
|
|
|
|
when(processDefinitionMapper.queryDefinitionCodeListByProjectCodes(any())) |
|
|
|
|
.thenReturn(Collections.singletonList(1L)); |
|
|
|
|
when(errorCommandMapper.queryErrorCommandPageByIds(any(), any())).thenReturn(page); |
|
|
|
|
PageInfo<ErrorCommand> list3 = dataAnalysisServiceImpl.listErrorCommand(user, 1L, 1, 10); |
|
|
|
|
assertThat(list3.getTotal()).isEqualTo(2); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private List<Command> getList() { |
|
|
|
|
List<Command> commandList = new ArrayList<>(); |
|
|
|
|
Command command = new Command(); |
|
|
|
|
command.setId(1); |
|
|
|
|
commandList.add(command); |
|
|
|
|
return commandList; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private List<ErrorCommand> getErrorList() { |
|
|
|
|
List<ErrorCommand> commandList = new ArrayList<>(); |
|
|
|
|
ErrorCommand command = new ErrorCommand(); |
|
|
|
|
command.setId(1); |
|
|
|
|
commandList.add(command); |
|
|
|
|
return commandList; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Set<Integer> projectIds() { |
|
|
|
|
Set<Integer> projectIds = new HashSet<>(); |
|
|
|
|
projectIds.add(1); |
|
|
|
|