|
|
@ -19,11 +19,14 @@ package org.apache.dolphinscheduler.api.service; |
|
|
|
|
|
|
|
|
|
|
|
import static org.mockito.ArgumentMatchers.eq; |
|
|
|
import static org.mockito.ArgumentMatchers.eq; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.api.constants.ApiFuncIdentificationConstant; |
|
|
|
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.ResourcesServiceImpl; |
|
|
|
import org.apache.dolphinscheduler.api.service.impl.ResourcesServiceImpl; |
|
|
|
import org.apache.dolphinscheduler.api.utils.PageInfo; |
|
|
|
import org.apache.dolphinscheduler.api.utils.PageInfo; |
|
|
|
import org.apache.dolphinscheduler.api.utils.Result; |
|
|
|
import org.apache.dolphinscheduler.api.utils.Result; |
|
|
|
import org.apache.dolphinscheduler.common.Constants; |
|
|
|
import org.apache.dolphinscheduler.common.Constants; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.common.enums.AuthorizationType; |
|
|
|
import org.apache.dolphinscheduler.common.enums.UserType; |
|
|
|
import org.apache.dolphinscheduler.common.enums.UserType; |
|
|
|
import org.apache.dolphinscheduler.common.storage.StorageOperate; |
|
|
|
import org.apache.dolphinscheduler.common.storage.StorageOperate; |
|
|
|
import org.apache.dolphinscheduler.common.utils.FileUtils; |
|
|
|
import org.apache.dolphinscheduler.common.utils.FileUtils; |
|
|
@ -38,6 +41,7 @@ import org.apache.dolphinscheduler.dao.mapper.ResourceUserMapper; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.TenantMapper; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.TenantMapper; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.UdfFuncMapper; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.UdfFuncMapper; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.UserMapper; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.UserMapper; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.service.permission.ResourcePermissionCheckService; |
|
|
|
import org.apache.dolphinscheduler.spi.enums.ResourceType; |
|
|
|
import org.apache.dolphinscheduler.spi.enums.ResourceType; |
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.collections.CollectionUtils; |
|
|
|
import org.apache.commons.collections.CollectionUtils; |
|
|
@ -47,9 +51,11 @@ import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashMap; |
|
|
|
|
|
|
|
import java.util.HashSet; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Random; |
|
|
|
import java.util.Random; |
|
|
|
|
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
|
|
|
|
import org.junit.Assert; |
|
|
|
import org.junit.Assert; |
|
|
|
import org.junit.Before; |
|
|
|
import org.junit.Before; |
|
|
@ -106,6 +112,12 @@ public class ResourcesServiceTest { |
|
|
|
@Mock |
|
|
|
@Mock |
|
|
|
private ResourceUserMapper resourceUserMapper; |
|
|
|
private ResourceUserMapper resourceUserMapper; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Mock |
|
|
|
|
|
|
|
private ResourcePermissionCheckService resourcePermissionCheckService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final Logger serviceLogger = LoggerFactory.getLogger(BaseServiceImpl.class); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Before |
|
|
|
@Before |
|
|
|
public void setUp() { |
|
|
|
public void setUp() { |
|
|
|
// PowerMockito.mockStatic(HadoopUtils.class);
|
|
|
|
// PowerMockito.mockStatic(HadoopUtils.class);
|
|
|
@ -125,8 +137,13 @@ public class ResourcesServiceTest { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testCreateResource() { |
|
|
|
public void testCreateResource() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 1, ApiFuncIdentificationConstant.FILE_ONLINE_CREATE, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, null, 1, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
|
|
|
|
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(false); |
|
|
|
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(false); |
|
|
|
User user = new User(); |
|
|
|
User user = new User(); |
|
|
|
|
|
|
|
user.setId(1); |
|
|
|
|
|
|
|
user.setUserType(UserType.GENERAL_USER); |
|
|
|
//HDFS_NOT_STARTUP
|
|
|
|
//HDFS_NOT_STARTUP
|
|
|
|
Result result = resourcesService.createResource(user, "ResourcesServiceTest", "ResourcesServiceTest", ResourceType.FILE, null, -1, "/"); |
|
|
|
Result result = resourcesService.createResource(user, "ResourcesServiceTest", "ResourcesServiceTest", ResourceType.FILE, null, -1, "/"); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
@ -148,6 +165,9 @@ public class ResourcesServiceTest { |
|
|
|
Assert.assertEquals(Status.RESOURCE_SUFFIX_FORBID_CHANGE.getMsg(), result.getMsg()); |
|
|
|
Assert.assertEquals(Status.RESOURCE_SUFFIX_FORBID_CHANGE.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
|
|
|
//UDF_RESOURCE_SUFFIX_NOT_JAR
|
|
|
|
//UDF_RESOURCE_SUFFIX_NOT_JAR
|
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 1, ApiFuncIdentificationConstant.UDF_FOLDER_ONLINE_CREATE, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, null, 1, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
|
|
|
|
mockMultipartFile = new MockMultipartFile("ResourcesServiceTest.pdf", "ResourcesServiceTest.pdf", "pdf", "test".getBytes()); |
|
|
|
mockMultipartFile = new MockMultipartFile("ResourcesServiceTest.pdf", "ResourcesServiceTest.pdf", "pdf", "test".getBytes()); |
|
|
|
PowerMockito.when(Files.getFileExtension("ResourcesServiceTest.pdf")).thenReturn("pdf"); |
|
|
|
PowerMockito.when(Files.getFileExtension("ResourcesServiceTest.pdf")).thenReturn("pdf"); |
|
|
|
result = resourcesService.createResource(user, "ResourcesServiceTest.pdf", "ResourcesServiceTest", ResourceType.UDF, mockMultipartFile, -1, "/"); |
|
|
|
result = resourcesService.createResource(user, "ResourcesServiceTest.pdf", "ResourcesServiceTest", ResourceType.UDF, mockMultipartFile, -1, "/"); |
|
|
@ -155,6 +175,9 @@ public class ResourcesServiceTest { |
|
|
|
Assert.assertEquals(Status.UDF_RESOURCE_SUFFIX_NOT_JAR.getMsg(), result.getMsg()); |
|
|
|
Assert.assertEquals(Status.UDF_RESOURCE_SUFFIX_NOT_JAR.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
|
|
|
//FULL_FILE_NAME_TOO_LONG
|
|
|
|
//FULL_FILE_NAME_TOO_LONG
|
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 1, ApiFuncIdentificationConstant.FILE_ONLINE_CREATE, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, null, 1, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
|
|
|
|
String tooLongFileName = getRandomStringWithLength(Constants.RESOURCE_FULL_NAME_MAX_LENGTH) + ".pdf"; |
|
|
|
String tooLongFileName = getRandomStringWithLength(Constants.RESOURCE_FULL_NAME_MAX_LENGTH) + ".pdf"; |
|
|
|
mockMultipartFile = new MockMultipartFile(tooLongFileName, tooLongFileName, "pdf", "test".getBytes()); |
|
|
|
mockMultipartFile = new MockMultipartFile(tooLongFileName, tooLongFileName, "pdf", "test".getBytes()); |
|
|
|
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true); |
|
|
|
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true); |
|
|
@ -166,9 +189,13 @@ public class ResourcesServiceTest { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testCreateDirecotry() { |
|
|
|
public void testCreateDirecotry() { |
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 1, ApiFuncIdentificationConstant.FOLDER_ONLINE_CREATE, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, null, 1, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
|
|
|
|
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(false); |
|
|
|
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(false); |
|
|
|
User user = new User(); |
|
|
|
User user = new User(); |
|
|
|
|
|
|
|
user.setId(1); |
|
|
|
|
|
|
|
user.setUserType(UserType.GENERAL_USER); |
|
|
|
//HDFS_NOT_STARTUP
|
|
|
|
//HDFS_NOT_STARTUP
|
|
|
|
Result result = resourcesService.createDirectory(user, "directoryTest", "directory test", ResourceType.FILE, -1, "/"); |
|
|
|
Result result = resourcesService.createDirectory(user, "directoryTest", "directory test", ResourceType.FILE, -1, "/"); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
@ -181,6 +208,10 @@ public class ResourcesServiceTest { |
|
|
|
Mockito.when(tenantMapper.queryById(1)).thenReturn(getTenant()); |
|
|
|
Mockito.when(tenantMapper.queryById(1)).thenReturn(getTenant()); |
|
|
|
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true); |
|
|
|
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true); |
|
|
|
Mockito.when(resourcesMapper.selectById(Mockito.anyInt())).thenReturn(null); |
|
|
|
Mockito.when(resourcesMapper.selectById(Mockito.anyInt())).thenReturn(null); |
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 1, ApiFuncIdentificationConstant.FOLDER_ONLINE_CREATE, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, null, 1, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 1, ApiFuncIdentificationConstant.FILE_RENAME, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
|
|
|
|
result = resourcesService.createDirectory(user, "directoryTest", "directory test", ResourceType.FILE, 1, "/"); |
|
|
|
result = resourcesService.createDirectory(user, "directoryTest", "directory test", ResourceType.FILE, 1, "/"); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
Assert.assertEquals(Status.PARENT_RESOURCE_NOT_EXIST.getMsg(), result.getMsg()); |
|
|
|
Assert.assertEquals(Status.PARENT_RESOURCE_NOT_EXIST.getMsg(), result.getMsg()); |
|
|
@ -196,14 +227,21 @@ public class ResourcesServiceTest { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testUpdateResource() { |
|
|
|
public void testUpdateResource() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 1, ApiFuncIdentificationConstant.FILE_UPDATE, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, new Object[]{1}, 1, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
|
|
|
|
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(false); |
|
|
|
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(false); |
|
|
|
User user = new User(); |
|
|
|
User user = new User(); |
|
|
|
|
|
|
|
user.setId(1); |
|
|
|
|
|
|
|
user.setUserType(UserType.GENERAL_USER); |
|
|
|
//HDFS_NOT_STARTUP
|
|
|
|
//HDFS_NOT_STARTUP
|
|
|
|
Result result = resourcesService.updateResource(user, 1, "ResourcesServiceTest", "ResourcesServiceTest", ResourceType.FILE, null); |
|
|
|
Result result = resourcesService.updateResource(user, 1, "ResourcesServiceTest", "ResourcesServiceTest", ResourceType.FILE, null); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
Assert.assertEquals(Status.STORAGE_NOT_STARTUP.getMsg(), result.getMsg()); |
|
|
|
Assert.assertEquals(Status.STORAGE_NOT_STARTUP.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
|
|
|
//RESOURCE_NOT_EXIST
|
|
|
|
//RESOURCE_NOT_EXIST
|
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 1, ApiFuncIdentificationConstant.FILE_UPDATE, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, new Object[]{0}, 1, serviceLogger)).thenReturn(true); |
|
|
|
Mockito.when(resourcesMapper.selectById(1)).thenReturn(getResource()); |
|
|
|
Mockito.when(resourcesMapper.selectById(1)).thenReturn(getResource()); |
|
|
|
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true); |
|
|
|
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true); |
|
|
|
result = resourcesService.updateResource(user, 0, "ResourcesServiceTest", "ResourcesServiceTest", ResourceType.FILE, null); |
|
|
|
result = resourcesService.updateResource(user, 0, "ResourcesServiceTest", "ResourcesServiceTest", ResourceType.FILE, null); |
|
|
@ -211,6 +249,10 @@ public class ResourcesServiceTest { |
|
|
|
Assert.assertEquals(Status.RESOURCE_NOT_EXIST.getMsg(), result.getMsg()); |
|
|
|
Assert.assertEquals(Status.RESOURCE_NOT_EXIST.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
|
|
|
//USER_NO_OPERATION_PERM
|
|
|
|
//USER_NO_OPERATION_PERM
|
|
|
|
|
|
|
|
user.setId(2); |
|
|
|
|
|
|
|
user.setUserType(UserType.GENERAL_USER); |
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 2, ApiFuncIdentificationConstant.FILE_UPDATE, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, new Object[]{1}, 2, serviceLogger)).thenReturn(true); |
|
|
|
result = resourcesService.updateResource(user, 1, "ResourcesServiceTest", "ResourcesServiceTest", ResourceType.FILE, null); |
|
|
|
result = resourcesService.updateResource(user, 1, "ResourcesServiceTest", "ResourcesServiceTest", ResourceType.FILE, null); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
Assert.assertEquals(Status.USER_NO_OPERATION_PERM.getMsg(), result.getMsg()); |
|
|
|
Assert.assertEquals(Status.USER_NO_OPERATION_PERM.getMsg(), result.getMsg()); |
|
|
@ -221,6 +263,8 @@ public class ResourcesServiceTest { |
|
|
|
Mockito.when(tenantMapper.queryById(1)).thenReturn(getTenant()); |
|
|
|
Mockito.when(tenantMapper.queryById(1)).thenReturn(getTenant()); |
|
|
|
PowerMockito.when(storageOperate.getFileName(Mockito.any(), Mockito.any(), Mockito.anyString())).thenReturn("test1"); |
|
|
|
PowerMockito.when(storageOperate.getFileName(Mockito.any(), Mockito.any(), Mockito.anyString())).thenReturn("test1"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 1, ApiFuncIdentificationConstant.UDF_UPDATE, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, new Object[]{1}, 1, serviceLogger)).thenReturn(true); |
|
|
|
try { |
|
|
|
try { |
|
|
|
Mockito.when(storageOperate.exists(Mockito.any(), Mockito.any())).thenReturn(false); |
|
|
|
Mockito.when(storageOperate.exists(Mockito.any(), Mockito.any())).thenReturn(false); |
|
|
|
} catch (IOException e) { |
|
|
|
} catch (IOException e) { |
|
|
@ -239,6 +283,8 @@ public class ResourcesServiceTest { |
|
|
|
logger.error(e.getMessage(), e); |
|
|
|
logger.error(e.getMessage(), e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 1, ApiFuncIdentificationConstant.FILE_UPDATE, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, new Object[]{1}, 1, serviceLogger)).thenReturn(true); |
|
|
|
result = resourcesService.updateResource(user, 1, "ResourcesServiceTest.jar", "ResourcesServiceTest", ResourceType.FILE, null); |
|
|
|
result = resourcesService.updateResource(user, 1, "ResourcesServiceTest.jar", "ResourcesServiceTest", ResourceType.FILE, null); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
Assert.assertEquals(Status.SUCCESS.getMsg(), result.getMsg()); |
|
|
|
Assert.assertEquals(Status.SUCCESS.getMsg(), result.getMsg()); |
|
|
@ -249,6 +295,8 @@ public class ResourcesServiceTest { |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
Assert.assertEquals(Status.RESOURCE_EXIST.getMsg(), result.getMsg()); |
|
|
|
Assert.assertEquals(Status.RESOURCE_EXIST.getMsg(), result.getMsg()); |
|
|
|
//USER_NOT_EXIST
|
|
|
|
//USER_NOT_EXIST
|
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 1, ApiFuncIdentificationConstant.UDF_UPDATE, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, new Object[]{1}, 1, serviceLogger)).thenReturn(true); |
|
|
|
Mockito.when(userMapper.selectById(Mockito.anyInt())).thenReturn(null); |
|
|
|
Mockito.when(userMapper.selectById(Mockito.anyInt())).thenReturn(null); |
|
|
|
result = resourcesService.updateResource(user, 1, "ResourcesServiceTest1.jar", "ResourcesServiceTest", ResourceType.UDF, null); |
|
|
|
result = resourcesService.updateResource(user, 1, "ResourcesServiceTest1.jar", "ResourcesServiceTest", ResourceType.UDF, null); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
@ -279,13 +327,17 @@ public class ResourcesServiceTest { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testQueryResourceListPaging() { |
|
|
|
public void testQueryResourceListPaging() { |
|
|
|
User loginUser = new User(); |
|
|
|
User loginUser = new User(); |
|
|
|
|
|
|
|
loginUser.setId(1); |
|
|
|
loginUser.setUserType(UserType.ADMIN_USER); |
|
|
|
loginUser.setUserType(UserType.ADMIN_USER); |
|
|
|
IPage<Resource> resourcePage = new Page<>(1, 10); |
|
|
|
IPage<Resource> resourcePage = new Page<>(1, 10); |
|
|
|
resourcePage.setTotal(1); |
|
|
|
resourcePage.setTotal(1); |
|
|
|
resourcePage.setRecords(getResourceList()); |
|
|
|
resourcePage.setRecords(getResourceList()); |
|
|
|
|
|
|
|
|
|
|
|
Mockito.when(resourcesMapper.queryResourcePaging(Mockito.any(Page.class), |
|
|
|
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 1, ApiFuncIdentificationConstant.FILE_VIEW, serviceLogger)).thenReturn(true); |
|
|
|
eq(0), eq(-1), eq(0), eq("test"), Mockito.any())).thenReturn(resourcePage); |
|
|
|
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, null, 0, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.RESOURCE_FILE_ID, 1, serviceLogger)).thenReturn(getSetIds()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Mockito.when(resourcesMapper.queryResourcePaging(Mockito.any(Page.class), eq(-1), eq(0), eq(1), eq("test"), Mockito.any())).thenReturn(resourcePage); |
|
|
|
Result result = resourcesService.queryResourceListPaging(loginUser, -1, ResourceType.FILE, "test", 1, 10); |
|
|
|
Result result = resourcesService.queryResourceListPaging(loginUser, -1, ResourceType.FILE, "test", 1, 10); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
Assert.assertEquals(Status.SUCCESS.getCode(), (int) result.getCode()); |
|
|
|
Assert.assertEquals(Status.SUCCESS.getCode(), (int) result.getCode()); |
|
|
@ -299,6 +351,11 @@ public class ResourcesServiceTest { |
|
|
|
User loginUser = new User(); |
|
|
|
User loginUser = new User(); |
|
|
|
loginUser.setId(0); |
|
|
|
loginUser.setId(0); |
|
|
|
loginUser.setUserType(UserType.ADMIN_USER); |
|
|
|
loginUser.setUserType(UserType.ADMIN_USER); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 0, ApiFuncIdentificationConstant.FILE_VIEW, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, null, 0, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.RESOURCE_FILE_ID, 0, serviceLogger)).thenReturn(getSetIds()); |
|
|
|
|
|
|
|
|
|
|
|
Mockito.when(resourcesMapper.queryResourceListAuthored(0, 0)).thenReturn(getResourceList()); |
|
|
|
Mockito.when(resourcesMapper.queryResourceListAuthored(0, 0)).thenReturn(getResourceList()); |
|
|
|
Map<String, Object> result = resourcesService.queryResourceList(loginUser, ResourceType.FILE); |
|
|
|
Map<String, Object> result = resourcesService.queryResourceList(loginUser, ResourceType.FILE); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
@ -307,6 +364,9 @@ public class ResourcesServiceTest { |
|
|
|
Assert.assertTrue(CollectionUtils.isNotEmpty(resourceList)); |
|
|
|
Assert.assertTrue(CollectionUtils.isNotEmpty(resourceList)); |
|
|
|
|
|
|
|
|
|
|
|
// test udf
|
|
|
|
// test udf
|
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 0, ApiFuncIdentificationConstant.UDF_FILE_VIEW, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, null, 0, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.RESOURCE_FILE_ID, 0, serviceLogger)).thenReturn(getSetIds()); |
|
|
|
loginUser.setUserType(UserType.GENERAL_USER); |
|
|
|
loginUser.setUserType(UserType.GENERAL_USER); |
|
|
|
Mockito.when(resourceUserMapper.queryResourcesIdListByUserIdAndPerm(0, 0)) |
|
|
|
Mockito.when(resourceUserMapper.queryResourcesIdListByUserIdAndPerm(0, 0)) |
|
|
|
.thenReturn(Arrays.asList(Integer.valueOf(10), Integer.valueOf(11))); |
|
|
|
.thenReturn(Arrays.asList(Integer.valueOf(10), Integer.valueOf(11))); |
|
|
@ -325,9 +385,13 @@ public class ResourcesServiceTest { |
|
|
|
|
|
|
|
|
|
|
|
User loginUser = new User(); |
|
|
|
User loginUser = new User(); |
|
|
|
loginUser.setId(0); |
|
|
|
loginUser.setId(0); |
|
|
|
|
|
|
|
loginUser.setUserType(UserType.GENERAL_USER); |
|
|
|
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(false); |
|
|
|
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(false); |
|
|
|
|
|
|
|
Mockito.when(resourcesMapper.selectById(1)).thenReturn(getResource()); |
|
|
|
Mockito.when(tenantMapper.queryById(1)).thenReturn(getTenant()); |
|
|
|
Mockito.when(tenantMapper.queryById(1)).thenReturn(getTenant()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 0, ApiFuncIdentificationConstant.FILE_DELETE, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, new Object[]{1}, 0, serviceLogger)).thenReturn(true); |
|
|
|
try { |
|
|
|
try { |
|
|
|
// HDFS_NOT_STARTUP
|
|
|
|
// HDFS_NOT_STARTUP
|
|
|
|
Result result = resourcesService.delete(loginUser, 1); |
|
|
|
Result result = resourcesService.delete(loginUser, 1); |
|
|
@ -337,6 +401,9 @@ public class ResourcesServiceTest { |
|
|
|
//RESOURCE_NOT_EXIST
|
|
|
|
//RESOURCE_NOT_EXIST
|
|
|
|
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true); |
|
|
|
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true); |
|
|
|
Mockito.when(resourcesMapper.selectById(1)).thenReturn(getResource()); |
|
|
|
Mockito.when(resourcesMapper.selectById(1)).thenReturn(getResource()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 0, ApiFuncIdentificationConstant.FILE_DELETE, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, new Object[]{2}, 0, serviceLogger)).thenReturn(true); |
|
|
|
result = resourcesService.delete(loginUser, 2); |
|
|
|
result = resourcesService.delete(loginUser, 2); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
Assert.assertEquals(Status.RESOURCE_NOT_EXIST.getMsg(), result.getMsg()); |
|
|
|
Assert.assertEquals(Status.RESOURCE_NOT_EXIST.getMsg(), result.getMsg()); |
|
|
@ -350,6 +417,8 @@ public class ResourcesServiceTest { |
|
|
|
loginUser.setUserType(UserType.ADMIN_USER); |
|
|
|
loginUser.setUserType(UserType.ADMIN_USER); |
|
|
|
loginUser.setTenantId(2); |
|
|
|
loginUser.setTenantId(2); |
|
|
|
Mockito.when(userMapper.selectById(Mockito.anyInt())).thenReturn(loginUser); |
|
|
|
Mockito.when(userMapper.selectById(Mockito.anyInt())).thenReturn(loginUser); |
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 0, ApiFuncIdentificationConstant.FILE_DELETE, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, new Object[]{1}, 0, serviceLogger)).thenReturn(true); |
|
|
|
result = resourcesService.delete(loginUser, 1); |
|
|
|
result = resourcesService.delete(loginUser, 1); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
Assert.assertEquals(Status.CURRENT_LOGIN_USER_TENANT_NOT_EXIST.getMsg(), result.getMsg()); |
|
|
|
Assert.assertEquals(Status.CURRENT_LOGIN_USER_TENANT_NOT_EXIST.getMsg(), result.getMsg()); |
|
|
@ -373,8 +442,11 @@ public class ResourcesServiceTest { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testVerifyResourceName() { |
|
|
|
public void testVerifyResourceName() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 1, ApiFuncIdentificationConstant.FILE_RENAME, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, null, 1, serviceLogger)).thenReturn(true); |
|
|
|
User user = new User(); |
|
|
|
User user = new User(); |
|
|
|
user.setId(1); |
|
|
|
user.setId(1); |
|
|
|
|
|
|
|
user.setUserType(UserType.GENERAL_USER); |
|
|
|
Mockito.when(resourcesMapper.existResource("/ResourcesServiceTest.jar", 0)).thenReturn(true); |
|
|
|
Mockito.when(resourcesMapper.existResource("/ResourcesServiceTest.jar", 0)).thenReturn(true); |
|
|
|
Result result = resourcesService.verifyResourceName("/ResourcesServiceTest.jar", ResourceType.FILE, user); |
|
|
|
Result result = resourcesService.verifyResourceName("/ResourcesServiceTest.jar", ResourceType.FILE, user); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
@ -414,37 +486,43 @@ public class ResourcesServiceTest { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testReadResource() { |
|
|
|
public void testReadResource() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 1, ApiFuncIdentificationConstant.FILE_VIEW, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, new Object[]{1}, 1, serviceLogger)).thenReturn(true); |
|
|
|
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(false); |
|
|
|
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(false); |
|
|
|
|
|
|
|
|
|
|
|
//HDFS_NOT_STARTUP
|
|
|
|
//HDFS_NOT_STARTUP
|
|
|
|
Result result = resourcesService.readResource(1, 1, 10); |
|
|
|
Result result = resourcesService.readResource(getUser(), 1, 1, 10); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
Assert.assertEquals(Status.STORAGE_NOT_STARTUP.getMsg(), result.getMsg()); |
|
|
|
Assert.assertEquals(Status.STORAGE_NOT_STARTUP.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
|
|
|
//RESOURCE_NOT_EXIST
|
|
|
|
//RESOURCE_NOT_EXIST
|
|
|
|
Mockito.when(resourcesMapper.selectById(1)).thenReturn(getResource()); |
|
|
|
Mockito.when(resourcesMapper.selectById(1)).thenReturn(getResource()); |
|
|
|
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true); |
|
|
|
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true); |
|
|
|
result = resourcesService.readResource(2, 1, 10); |
|
|
|
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 1, ApiFuncIdentificationConstant.FILE_VIEW, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, new Object[]{2}, 1, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
result = resourcesService.readResource(getUser(), 2, 1, 10); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
Assert.assertEquals(Status.RESOURCE_NOT_EXIST.getMsg(), result.getMsg()); |
|
|
|
Assert.assertEquals(Status.RESOURCE_NOT_EXIST.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
|
|
|
//RESOURCE_SUFFIX_NOT_SUPPORT_VIEW
|
|
|
|
//RESOURCE_SUFFIX_NOT_SUPPORT_VIEW
|
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 1, ApiFuncIdentificationConstant.FILE_VIEW, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, new Object[]{1}, 1, serviceLogger)).thenReturn(true); |
|
|
|
PowerMockito.when(FileUtils.getResourceViewSuffixes()).thenReturn("class"); |
|
|
|
PowerMockito.when(FileUtils.getResourceViewSuffixes()).thenReturn("class"); |
|
|
|
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true); |
|
|
|
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true); |
|
|
|
result = resourcesService.readResource(1, 1, 10); |
|
|
|
result = resourcesService.readResource(getUser(), 1, 1, 10); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
Assert.assertEquals(Status.RESOURCE_SUFFIX_NOT_SUPPORT_VIEW.getMsg(), result.getMsg()); |
|
|
|
Assert.assertEquals(Status.RESOURCE_SUFFIX_NOT_SUPPORT_VIEW.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
|
|
|
//USER_NOT_EXIST
|
|
|
|
//USER_NOT_EXIST
|
|
|
|
PowerMockito.when(FileUtils.getResourceViewSuffixes()).thenReturn("jar"); |
|
|
|
PowerMockito.when(FileUtils.getResourceViewSuffixes()).thenReturn("jar"); |
|
|
|
PowerMockito.when(Files.getFileExtension("ResourcesServiceTest.jar")).thenReturn("jar"); |
|
|
|
PowerMockito.when(Files.getFileExtension("ResourcesServiceTest.jar")).thenReturn("jar"); |
|
|
|
result = resourcesService.readResource(1, 1, 10); |
|
|
|
result = resourcesService.readResource(getUser(), 1, 1, 10); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
Assert.assertEquals(Status.USER_NOT_EXIST.getCode(), (int) result.getCode()); |
|
|
|
Assert.assertEquals(Status.USER_NOT_EXIST.getCode(), (int) result.getCode()); |
|
|
|
|
|
|
|
|
|
|
|
//TENANT_NOT_EXIST
|
|
|
|
//TENANT_NOT_EXIST
|
|
|
|
Mockito.when(userMapper.selectById(1)).thenReturn(getUser()); |
|
|
|
Mockito.when(userMapper.selectById(1)).thenReturn(getUser()); |
|
|
|
result = resourcesService.readResource(1, 1, 10); |
|
|
|
result = resourcesService.readResource(getUser(), 1, 1, 10); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
Assert.assertEquals(Status.CURRENT_LOGIN_USER_TENANT_NOT_EXIST.getMsg(), result.getMsg()); |
|
|
|
Assert.assertEquals(Status.CURRENT_LOGIN_USER_TENANT_NOT_EXIST.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
|
|
@ -455,7 +533,7 @@ public class ResourcesServiceTest { |
|
|
|
} catch (IOException e) { |
|
|
|
} catch (IOException e) { |
|
|
|
logger.error("hadoop error", e); |
|
|
|
logger.error("hadoop error", e); |
|
|
|
} |
|
|
|
} |
|
|
|
result = resourcesService.readResource(1, 1, 10); |
|
|
|
result = resourcesService.readResource(getUser(), 1, 1, 10); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
Assert.assertEquals(Status.RESOURCE_FILE_NOT_EXIST.getCode(), (int) result.getCode()); |
|
|
|
Assert.assertEquals(Status.RESOURCE_FILE_NOT_EXIST.getCode(), (int) result.getCode()); |
|
|
|
|
|
|
|
|
|
|
@ -467,7 +545,7 @@ public class ResourcesServiceTest { |
|
|
|
} catch (IOException e) { |
|
|
|
} catch (IOException e) { |
|
|
|
logger.error("storage error", e); |
|
|
|
logger.error("storage error", e); |
|
|
|
} |
|
|
|
} |
|
|
|
result = resourcesService.readResource(1, 1, 10); |
|
|
|
result = resourcesService.readResource(getUser(), 1, 1, 10); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
Assert.assertEquals(Status.SUCCESS.getMsg(), result.getMsg()); |
|
|
|
Assert.assertEquals(Status.SUCCESS.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
|
|
@ -476,10 +554,14 @@ public class ResourcesServiceTest { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testOnlineCreateResource() { |
|
|
|
public void testOnlineCreateResource() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 1, ApiFuncIdentificationConstant.FILE_ONLINE_CREATE, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, null, 1, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
|
|
|
|
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(false); |
|
|
|
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(false); |
|
|
|
PowerMockito.when(storageOperate.getResourceFileName(Mockito.anyString(), eq("hdfsdDir"))).thenReturn("hdfsDir"); |
|
|
|
PowerMockito.when(storageOperate.getResourceFileName(Mockito.anyString(), eq("hdfsdDir"))).thenReturn("hdfsDir"); |
|
|
|
PowerMockito.when(storageOperate.getUdfDir("udfDir")).thenReturn("udfDir"); |
|
|
|
PowerMockito.when(storageOperate.getUdfDir("udfDir")).thenReturn("udfDir"); |
|
|
|
User user = getUser(); |
|
|
|
User user = getUser(); |
|
|
|
|
|
|
|
user.setId(1); |
|
|
|
//HDFS_NOT_STARTUP
|
|
|
|
//HDFS_NOT_STARTUP
|
|
|
|
Result result = resourcesService.onlineCreateResource(user, ResourceType.FILE, "test", "jar", "desc", "content", -1, "/"); |
|
|
|
Result result = resourcesService.onlineCreateResource(user, ResourceType.FILE, "test", "jar", "desc", "content", -1, "/"); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
@ -503,6 +585,9 @@ public class ResourcesServiceTest { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//SUCCESS
|
|
|
|
//SUCCESS
|
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 1, ApiFuncIdentificationConstant.FILE_RENAME, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, null, 1, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
|
|
|
|
Mockito.when(FileUtils.getUploadFilename(Mockito.anyString(), Mockito.anyString())).thenReturn("test"); |
|
|
|
Mockito.when(FileUtils.getUploadFilename(Mockito.anyString(), Mockito.anyString())).thenReturn("test"); |
|
|
|
PowerMockito.when(FileUtils.writeContent2File(Mockito.anyString(), Mockito.anyString())).thenReturn(true); |
|
|
|
PowerMockito.when(FileUtils.writeContent2File(Mockito.anyString(), Mockito.anyString())).thenReturn(true); |
|
|
|
result = resourcesService.onlineCreateResource(user, ResourceType.FILE, "test", "jar", "desc", "content", -1, "/"); |
|
|
|
result = resourcesService.onlineCreateResource(user, ResourceType.FILE, "test", "jar", "desc", "content", -1, "/"); |
|
|
@ -516,34 +601,41 @@ public class ResourcesServiceTest { |
|
|
|
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(false); |
|
|
|
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(false); |
|
|
|
|
|
|
|
|
|
|
|
// HDFS_NOT_STARTUP
|
|
|
|
// HDFS_NOT_STARTUP
|
|
|
|
Result result = resourcesService.updateResourceContent(1, "content"); |
|
|
|
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 1, ApiFuncIdentificationConstant.FILE_UPDATE, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, new Object[]{1}, 1, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Result result = resourcesService.updateResourceContent(getUser(), 1, "content"); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
Assert.assertEquals(Status.STORAGE_NOT_STARTUP.getMsg(), result.getMsg()); |
|
|
|
Assert.assertEquals(Status.STORAGE_NOT_STARTUP.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
|
|
|
//RESOURCE_NOT_EXIST
|
|
|
|
//RESOURCE_NOT_EXIST
|
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 1, ApiFuncIdentificationConstant.FILE_UPDATE, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, new Object[]{2}, 1, serviceLogger)).thenReturn(true); |
|
|
|
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true); |
|
|
|
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true); |
|
|
|
Mockito.when(resourcesMapper.selectById(1)).thenReturn(getResource()); |
|
|
|
Mockito.when(resourcesMapper.selectById(1)).thenReturn(getResource()); |
|
|
|
result = resourcesService.updateResourceContent(2, "content"); |
|
|
|
result = resourcesService.updateResourceContent(getUser(), 2, "content"); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
Assert.assertEquals(Status.RESOURCE_NOT_EXIST.getMsg(), result.getMsg()); |
|
|
|
Assert.assertEquals(Status.RESOURCE_NOT_EXIST.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
|
|
|
//RESOURCE_SUFFIX_NOT_SUPPORT_VIEW
|
|
|
|
//RESOURCE_SUFFIX_NOT_SUPPORT_VIEW
|
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 1, ApiFuncIdentificationConstant.FILE_UPDATE, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, new Object[]{1}, 1, serviceLogger)).thenReturn(true); |
|
|
|
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true); |
|
|
|
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true); |
|
|
|
PowerMockito.when(FileUtils.getResourceViewSuffixes()).thenReturn("class"); |
|
|
|
PowerMockito.when(FileUtils.getResourceViewSuffixes()).thenReturn("class"); |
|
|
|
result = resourcesService.updateResourceContent(1, "content"); |
|
|
|
result = resourcesService.updateResourceContent(getUser(), 1, "content"); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
Assert.assertEquals(Status.RESOURCE_SUFFIX_NOT_SUPPORT_VIEW.getMsg(), result.getMsg()); |
|
|
|
Assert.assertEquals(Status.RESOURCE_SUFFIX_NOT_SUPPORT_VIEW.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
|
|
|
//USER_NOT_EXIST
|
|
|
|
//USER_NOT_EXIST
|
|
|
|
PowerMockito.when(FileUtils.getResourceViewSuffixes()).thenReturn("jar"); |
|
|
|
PowerMockito.when(FileUtils.getResourceViewSuffixes()).thenReturn("jar"); |
|
|
|
PowerMockito.when(Files.getFileExtension("ResourcesServiceTest.jar")).thenReturn("jar"); |
|
|
|
PowerMockito.when(Files.getFileExtension("ResourcesServiceTest.jar")).thenReturn("jar"); |
|
|
|
result = resourcesService.updateResourceContent(1, "content"); |
|
|
|
result = resourcesService.updateResourceContent(getUser(), 1, "content"); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
Assert.assertTrue(Status.USER_NOT_EXIST.getCode() == result.getCode()); |
|
|
|
Assert.assertTrue(Status.USER_NOT_EXIST.getCode() == result.getCode()); |
|
|
|
|
|
|
|
|
|
|
|
//TENANT_NOT_EXIST
|
|
|
|
//TENANT_NOT_EXIST
|
|
|
|
Mockito.when(userMapper.selectById(1)).thenReturn(getUser()); |
|
|
|
Mockito.when(userMapper.selectById(1)).thenReturn(getUser()); |
|
|
|
result = resourcesService.updateResourceContent(1, "content"); |
|
|
|
result = resourcesService.updateResourceContent(getUser(), 1, "content"); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
Assert.assertTrue(Status.CURRENT_LOGIN_USER_TENANT_NOT_EXIST.getCode() == result.getCode()); |
|
|
|
Assert.assertTrue(Status.CURRENT_LOGIN_USER_TENANT_NOT_EXIST.getCode() == result.getCode()); |
|
|
|
|
|
|
|
|
|
|
@ -551,7 +643,7 @@ public class ResourcesServiceTest { |
|
|
|
Mockito.when(tenantMapper.queryById(1)).thenReturn(getTenant()); |
|
|
|
Mockito.when(tenantMapper.queryById(1)).thenReturn(getTenant()); |
|
|
|
Mockito.when(FileUtils.getUploadFilename(Mockito.anyString(), Mockito.anyString())).thenReturn("test"); |
|
|
|
Mockito.when(FileUtils.getUploadFilename(Mockito.anyString(), Mockito.anyString())).thenReturn("test"); |
|
|
|
PowerMockito.when(FileUtils.writeContent2File(Mockito.anyString(), Mockito.anyString())).thenReturn(true); |
|
|
|
PowerMockito.when(FileUtils.writeContent2File(Mockito.anyString(), Mockito.anyString())).thenReturn(true); |
|
|
|
result = resourcesService.updateResourceContent(1, "content"); |
|
|
|
result = resourcesService.updateResourceContent(getUser(), 1, "content"); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
|
Assert.assertEquals(Status.SUCCESS.getMsg(), result.getMsg()); |
|
|
|
Assert.assertEquals(Status.SUCCESS.getMsg(), result.getMsg()); |
|
|
|
} |
|
|
|
} |
|
|
@ -559,18 +651,21 @@ public class ResourcesServiceTest { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testDownloadResource() { |
|
|
|
public void testDownloadResource() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PowerMockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, 1, ApiFuncIdentificationConstant.FILE_DOWNLOAD, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, new Object[]{1}, 1, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
|
|
|
|
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true); |
|
|
|
PowerMockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true); |
|
|
|
Mockito.when(tenantMapper.queryById(1)).thenReturn(getTenant()); |
|
|
|
Mockito.when(tenantMapper.queryById(1)).thenReturn(getTenant()); |
|
|
|
Mockito.when(userMapper.selectById(1)).thenReturn(getUser()); |
|
|
|
Mockito.when(userMapper.selectById(1)).thenReturn(getUser()); |
|
|
|
org.springframework.core.io.Resource resourceMock = Mockito.mock(org.springframework.core.io.Resource.class); |
|
|
|
org.springframework.core.io.Resource resourceMock = Mockito.mock(org.springframework.core.io.Resource.class); |
|
|
|
try { |
|
|
|
try { |
|
|
|
//resource null
|
|
|
|
//resource null
|
|
|
|
org.springframework.core.io.Resource resource = resourcesService.downloadResource(1); |
|
|
|
org.springframework.core.io.Resource resource = resourcesService.downloadResource(getUser(), 1); |
|
|
|
Assert.assertNull(resource); |
|
|
|
Assert.assertNull(resource); |
|
|
|
|
|
|
|
|
|
|
|
Mockito.when(resourcesMapper.selectById(1)).thenReturn(getResource()); |
|
|
|
Mockito.when(resourcesMapper.selectById(1)).thenReturn(getResource()); |
|
|
|
PowerMockito.when(org.apache.dolphinscheduler.api.utils.FileUtils.file2Resource(Mockito.any())).thenReturn(resourceMock); |
|
|
|
PowerMockito.when(org.apache.dolphinscheduler.api.utils.FileUtils.file2Resource(Mockito.any())).thenReturn(resourceMock); |
|
|
|
resource = resourcesService.downloadResource(1); |
|
|
|
resource = resourcesService.downloadResource(getUser(), 1); |
|
|
|
Assert.assertNotNull(resource); |
|
|
|
Assert.assertNotNull(resource); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("DownloadResource error", e); |
|
|
|
logger.error("DownloadResource error", e); |
|
|
@ -589,6 +684,7 @@ public class ResourcesServiceTest { |
|
|
|
// test admin user
|
|
|
|
// test admin user
|
|
|
|
List<Integer> resIds = new ArrayList<>(); |
|
|
|
List<Integer> resIds = new ArrayList<>(); |
|
|
|
resIds.add(1); |
|
|
|
resIds.add(1); |
|
|
|
|
|
|
|
Mockito.when(resourcePermissionCheckService.functionDisabled()).thenReturn(true); |
|
|
|
Mockito.when(resourcesMapper.queryResourceExceptUserId(userId)).thenReturn(getResourceList()); |
|
|
|
Mockito.when(resourcesMapper.queryResourceExceptUserId(userId)).thenReturn(getResourceList()); |
|
|
|
Map<String, Object> result = resourcesService.authorizeResourceTree(user, userId); |
|
|
|
Map<String, Object> result = resourcesService.authorizeResourceTree(user, userId); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
@ -617,6 +713,7 @@ public class ResourcesServiceTest { |
|
|
|
// test admin user
|
|
|
|
// test admin user
|
|
|
|
List<Integer> resIds = new ArrayList<>(); |
|
|
|
List<Integer> resIds = new ArrayList<>(); |
|
|
|
resIds.add(1); |
|
|
|
resIds.add(1); |
|
|
|
|
|
|
|
Mockito.when(resourcePermissionCheckService.functionDisabled()).thenReturn(true); |
|
|
|
Mockito.when(resourcesMapper.queryResourceExceptUserId(userId)).thenReturn(getResourceList()); |
|
|
|
Mockito.when(resourcesMapper.queryResourceExceptUserId(userId)).thenReturn(getResourceList()); |
|
|
|
Mockito.when(resourceUserMapper.queryResourcesIdListByUserIdAndPerm(Mockito.anyInt(), Mockito.anyInt())).thenReturn(resIds); |
|
|
|
Mockito.when(resourceUserMapper.queryResourcesIdListByUserIdAndPerm(Mockito.anyInt(), Mockito.anyInt())).thenReturn(resIds); |
|
|
|
Mockito.when(resourcesMapper.queryResourceListById(Mockito.any())).thenReturn(getSingleResourceList()); |
|
|
|
Mockito.when(resourcesMapper.queryResourceListById(Mockito.any())).thenReturn(getSingleResourceList()); |
|
|
@ -645,6 +742,7 @@ public class ResourcesServiceTest { |
|
|
|
int userId = 3; |
|
|
|
int userId = 3; |
|
|
|
|
|
|
|
|
|
|
|
// test admin user
|
|
|
|
// test admin user
|
|
|
|
|
|
|
|
Mockito.when(resourcePermissionCheckService.functionDisabled()).thenReturn(true); |
|
|
|
Mockito.when(udfFunctionMapper.queryUdfFuncExceptUserId(userId)).thenReturn(getUdfFuncList()); |
|
|
|
Mockito.when(udfFunctionMapper.queryUdfFuncExceptUserId(userId)).thenReturn(getUdfFuncList()); |
|
|
|
Mockito.when(udfFunctionMapper.queryAuthedUdfFunc(userId)).thenReturn(getSingleUdfFuncList()); |
|
|
|
Mockito.when(udfFunctionMapper.queryAuthedUdfFunc(userId)).thenReturn(getSingleUdfFuncList()); |
|
|
|
Map<String, Object> result = resourcesService.unauthorizedUDFFunction(user, userId); |
|
|
|
Map<String, Object> result = resourcesService.unauthorizedUDFFunction(user, userId); |
|
|
@ -671,6 +769,7 @@ public class ResourcesServiceTest { |
|
|
|
int userId = 3; |
|
|
|
int userId = 3; |
|
|
|
|
|
|
|
|
|
|
|
// test admin user
|
|
|
|
// test admin user
|
|
|
|
|
|
|
|
Mockito.when(resourcePermissionCheckService.functionDisabled()).thenReturn(true); |
|
|
|
Mockito.when(udfFunctionMapper.queryAuthedUdfFunc(userId)).thenReturn(getUdfFuncList()); |
|
|
|
Mockito.when(udfFunctionMapper.queryAuthedUdfFunc(userId)).thenReturn(getUdfFuncList()); |
|
|
|
Map<String, Object> result = resourcesService.authorizedUDFFunction(user, userId); |
|
|
|
Map<String, Object> result = resourcesService.authorizedUDFFunction(user, userId); |
|
|
|
logger.info(result.toString()); |
|
|
|
logger.info(result.toString()); |
|
|
@ -699,6 +798,7 @@ public class ResourcesServiceTest { |
|
|
|
// test admin user
|
|
|
|
// test admin user
|
|
|
|
List<Integer> resIds = new ArrayList<>(); |
|
|
|
List<Integer> resIds = new ArrayList<>(); |
|
|
|
resIds.add(1); |
|
|
|
resIds.add(1); |
|
|
|
|
|
|
|
Mockito.when(resourcePermissionCheckService.functionDisabled()).thenReturn(true); |
|
|
|
Mockito.when(resourceUserMapper.queryResourcesIdListByUserIdAndPerm(Mockito.anyInt(), Mockito.anyInt())).thenReturn(resIds); |
|
|
|
Mockito.when(resourceUserMapper.queryResourcesIdListByUserIdAndPerm(Mockito.anyInt(), Mockito.anyInt())).thenReturn(resIds); |
|
|
|
Mockito.when(resourcesMapper.queryResourceListById(Mockito.any())).thenReturn(getResourceList()); |
|
|
|
Mockito.when(resourcesMapper.queryResourceListById(Mockito.any())).thenReturn(getResourceList()); |
|
|
|
Map<String, Object> result = resourcesService.authorizedFile(user, userId); |
|
|
|
Map<String, Object> result = resourcesService.authorizedFile(user, userId); |
|
|
@ -745,6 +845,13 @@ public class ResourcesServiceTest { |
|
|
|
return resources; |
|
|
|
return resources; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Set<Integer> getSetIds() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Set<Integer> resources = new HashSet<>(); |
|
|
|
|
|
|
|
resources.add(1); |
|
|
|
|
|
|
|
return resources; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private List<Resource> getSingleResourceList() { |
|
|
|
private List<Resource> getSingleResourceList() { |
|
|
|
return Collections.singletonList(getResource(1)); |
|
|
|
return Collections.singletonList(getResource(1)); |
|
|
|
} |
|
|
|
} |
|
|
@ -834,6 +941,7 @@ public class ResourcesServiceTest { |
|
|
|
private User getUser() { |
|
|
|
private User getUser() { |
|
|
|
User user = new User(); |
|
|
|
User user = new User(); |
|
|
|
user.setId(1); |
|
|
|
user.setId(1); |
|
|
|
|
|
|
|
user.setUserType(UserType.GENERAL_USER); |
|
|
|
user.setTenantId(1); |
|
|
|
user.setTenantId(1); |
|
|
|
user.setTenantCode("tenantCode"); |
|
|
|
user.setTenantCode("tenantCode"); |
|
|
|
return user; |
|
|
|
return user; |
|
|
|