|
|
|
@ -19,7 +19,6 @@ package org.apache.dolphinscheduler.api.service;
|
|
|
|
|
|
|
|
|
|
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.permission.ResourcePermissionCheckService; |
|
|
|
|
import org.apache.dolphinscheduler.api.service.impl.BaseServiceImpl; |
|
|
|
@ -27,7 +26,6 @@ import org.apache.dolphinscheduler.api.service.impl.ResourcesServiceImpl;
|
|
|
|
|
import org.apache.dolphinscheduler.api.utils.PageInfo; |
|
|
|
|
import org.apache.dolphinscheduler.api.utils.Result; |
|
|
|
|
import org.apache.dolphinscheduler.common.constants.Constants; |
|
|
|
|
import org.apache.dolphinscheduler.common.enums.AuthorizationType; |
|
|
|
|
import org.apache.dolphinscheduler.common.enums.UserType; |
|
|
|
|
import org.apache.dolphinscheduler.common.utils.FileUtils; |
|
|
|
|
import org.apache.dolphinscheduler.common.utils.PropertyUtils; |
|
|
|
@ -41,6 +39,7 @@ import org.apache.dolphinscheduler.dao.mapper.ResourceUserMapper;
|
|
|
|
|
import org.apache.dolphinscheduler.dao.mapper.TenantMapper; |
|
|
|
|
import org.apache.dolphinscheduler.dao.mapper.UdfFuncMapper; |
|
|
|
|
import org.apache.dolphinscheduler.dao.mapper.UserMapper; |
|
|
|
|
import org.apache.dolphinscheduler.service.storage.StorageEntity; |
|
|
|
|
import org.apache.dolphinscheduler.service.storage.StorageOperate; |
|
|
|
|
import org.apache.dolphinscheduler.spi.enums.ResourceType; |
|
|
|
|
|
|
|
|
@ -145,11 +144,6 @@ public class ResourcesServiceTest {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testCreateResource() { |
|
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, |
|
|
|
|
null, 1, ApiFuncIdentificationConstant.FILE_UPLOAD, serviceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, |
|
|
|
|
null, 1, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
|
|
Mockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(false); |
|
|
|
|
User user = new User(); |
|
|
|
|
user.setId(1); |
|
|
|
@ -158,10 +152,10 @@ public class ResourcesServiceTest {
|
|
|
|
|
// CURRENT_LOGIN_USER_TENANT_NOT_EXIST
|
|
|
|
|
MockMultipartFile mockMultipartFile = new MockMultipartFile("test.pdf", "test.pdf", "pdf", "test".getBytes()); |
|
|
|
|
Mockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true); |
|
|
|
|
Mockito.when(userMapper.selectById(1)).thenReturn(getUser()); |
|
|
|
|
Mockito.when(userMapper.selectById(user.getId())).thenReturn(getUser()); |
|
|
|
|
Mockito.when(tenantMapper.queryById(1)).thenReturn(null); |
|
|
|
|
Result result = resourcesService.createResource(user, "ResourcesServiceTest", "ResourcesServiceTest", |
|
|
|
|
ResourceType.FILE, mockMultipartFile, -1, "/"); |
|
|
|
|
ResourceType.FILE, mockMultipartFile, "/"); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.CURRENT_LOGIN_USER_TENANT_NOT_EXIST.getMsg(), result.getMsg()); |
|
|
|
|
// set tenant for user
|
|
|
|
@ -171,7 +165,7 @@ public class ResourcesServiceTest {
|
|
|
|
|
// HDFS_NOT_STARTUP
|
|
|
|
|
Mockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(false); |
|
|
|
|
result = resourcesService.createResource(user, "ResourcesServiceTest", "ResourcesServiceTest", |
|
|
|
|
ResourceType.FILE, null, -1, "/"); |
|
|
|
|
ResourceType.FILE, null, "/"); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.STORAGE_NOT_STARTUP.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
@ -179,7 +173,7 @@ public class ResourcesServiceTest {
|
|
|
|
|
mockMultipartFile = new MockMultipartFile("test.pdf", "".getBytes()); |
|
|
|
|
Mockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true); |
|
|
|
|
result = resourcesService.createResource(user, "ResourcesServiceTest", "ResourcesServiceTest", |
|
|
|
|
ResourceType.FILE, mockMultipartFile, -1, "/"); |
|
|
|
|
ResourceType.FILE, mockMultipartFile, "/"); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.RESOURCE_FILE_IS_EMPTY.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
@ -188,47 +182,33 @@ public class ResourcesServiceTest {
|
|
|
|
|
Mockito.when(Files.getFileExtension("test.pdf")).thenReturn("pdf"); |
|
|
|
|
Mockito.when(Files.getFileExtension("ResourcesServiceTest.jar")).thenReturn("jar"); |
|
|
|
|
result = resourcesService.createResource(user, "ResourcesServiceTest.jar", "ResourcesServiceTest", |
|
|
|
|
ResourceType.FILE, mockMultipartFile, -1, "/"); |
|
|
|
|
ResourceType.FILE, mockMultipartFile, "/"); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.RESOURCE_SUFFIX_FORBID_CHANGE.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
|
// UDF_RESOURCE_SUFFIX_NOT_JAR
|
|
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, |
|
|
|
|
null, 1, ApiFuncIdentificationConstant.UDF_UPLOAD, serviceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, |
|
|
|
|
null, 1, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
|
|
mockMultipartFile = new MockMultipartFile("ResourcesServiceTest.pdf", "ResourcesServiceTest.pdf", |
|
|
|
|
"pdf", "test".getBytes()); |
|
|
|
|
Mockito.when(Files.getFileExtension("ResourcesServiceTest.pdf")).thenReturn("pdf"); |
|
|
|
|
result = resourcesService.createResource(user, "ResourcesServiceTest.pdf", "ResourcesServiceTest", |
|
|
|
|
ResourceType.UDF, mockMultipartFile, -1, "/"); |
|
|
|
|
ResourceType.UDF, mockMultipartFile, "/"); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.UDF_RESOURCE_SUFFIX_NOT_JAR.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
|
// FULL_FILE_NAME_TOO_LONG
|
|
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, |
|
|
|
|
null, 1, ApiFuncIdentificationConstant.FILE_UPLOAD, serviceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, |
|
|
|
|
null, 1, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
|
|
String tooLongFileName = getRandomStringWithLength(Constants.RESOURCE_FULL_NAME_MAX_LENGTH) + ".pdf"; |
|
|
|
|
mockMultipartFile = new MockMultipartFile(tooLongFileName, tooLongFileName, "pdf", "test".getBytes()); |
|
|
|
|
Mockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true); |
|
|
|
|
Mockito.when(Files.getFileExtension(tooLongFileName)).thenReturn("pdf"); |
|
|
|
|
// '/databasePath/tenantCode/RESOURCE/'
|
|
|
|
|
Mockito.when(storageOperate.getResDir("123")).thenReturn("/dolphinscheduler/123/resources/"); |
|
|
|
|
result = resourcesService.createResource(user, tooLongFileName, tooLongFileName, ResourceType.FILE, |
|
|
|
|
mockMultipartFile, -1, "/"); |
|
|
|
|
mockMultipartFile, "/"); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.RESOURCE_FULL_NAME_TOO_LONG_ERROR.getMsg(), result.getMsg()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testCreateDirecotry() { |
|
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, |
|
|
|
|
null, 1, ApiFuncIdentificationConstant.FOLDER_ONLINE_CREATE, serviceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, |
|
|
|
|
null, 1, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
|
|
Mockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(false); |
|
|
|
|
User user = new User(); |
|
|
|
|
user.setId(1); |
|
|
|
@ -239,23 +219,18 @@ public class ResourcesServiceTest {
|
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.STORAGE_NOT_STARTUP.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
|
// PARENT_RESOURCE_NOT_EXIST
|
|
|
|
|
// RESOURCE_EXIST
|
|
|
|
|
user.setId(1); |
|
|
|
|
user.setTenantId(1); |
|
|
|
|
Mockito.when(tenantMapper.queryById(1)).thenReturn(getTenant()); |
|
|
|
|
Mockito.when(userMapper.selectById(user.getId())).thenReturn(getUser()); |
|
|
|
|
Mockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true); |
|
|
|
|
Mockito.when(resourcesMapper.selectById(Mockito.anyInt())).thenReturn(null); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, |
|
|
|
|
null, 1, ApiFuncIdentificationConstant.FOLDER_ONLINE_CREATE, serviceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, |
|
|
|
|
null, 1, serviceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, |
|
|
|
|
null, 1, ApiFuncIdentificationConstant.FILE_RENAME, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
|
|
result = resourcesService.createDirectory(user, "directoryTest", "directory test", ResourceType.FILE, 1, "/"); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.PARENT_RESOURCE_NOT_EXIST.getMsg(), result.getMsg()); |
|
|
|
|
// RESOURCE_EXIST
|
|
|
|
|
Mockito.when(storageOperate.getResDir("123")).thenReturn("/dolphinscheduler/123/resources/"); |
|
|
|
|
try { |
|
|
|
|
Mockito.when(storageOperate.exists("/dolphinscheduler/123/resources/directoryTest")).thenReturn(true); |
|
|
|
|
} catch (IOException e) { |
|
|
|
|
logger.error(e.getMessage(), e); |
|
|
|
|
} |
|
|
|
|
Mockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true); |
|
|
|
|
Mockito.when(resourcesMapper.existResource("/directoryTest", 0)).thenReturn(true); |
|
|
|
|
result = resourcesService.createDirectory(user, "directoryTest", "directory test", ResourceType.FILE, -1, "/"); |
|
|
|
@ -272,131 +247,126 @@ public class ResourcesServiceTest {
|
|
|
|
|
@Test |
|
|
|
|
public void testUpdateResource() { |
|
|
|
|
|
|
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, |
|
|
|
|
null, 1, ApiFuncIdentificationConstant.FILE_UPDATE, serviceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, |
|
|
|
|
new Object[]{1}, 1, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
|
|
Mockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(false); |
|
|
|
|
User user = new User(); |
|
|
|
|
user.setId(1); |
|
|
|
|
user.setUserType(UserType.GENERAL_USER); |
|
|
|
|
user.setTenantId(1); |
|
|
|
|
|
|
|
|
|
Mockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(false); |
|
|
|
|
Mockito.when(userMapper.selectById(user.getId())).thenReturn(getUser()); |
|
|
|
|
Mockito.when(tenantMapper.queryById(1)).thenReturn(getTenant()); |
|
|
|
|
Mockito.when(storageOperate.getResDir("123")).thenReturn("/dolphinscheduler/123/resources/"); |
|
|
|
|
|
|
|
|
|
// HDFS_NOT_STARTUP
|
|
|
|
|
Result result = resourcesService.updateResource(user, 1, "ResourcesServiceTest", "ResourcesServiceTest", |
|
|
|
|
ResourceType.FILE, null); |
|
|
|
|
Result result = resourcesService.updateResource(user, "ResourcesServiceTest", |
|
|
|
|
"123", "ResourcesServiceTest", "", ResourceType.FILE, null); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.STORAGE_NOT_STARTUP.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
|
// RESOURCE_NOT_EXIST
|
|
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, |
|
|
|
|
null, 1, ApiFuncIdentificationConstant.FILE_UPDATE, serviceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, |
|
|
|
|
new Object[]{0}, 1, serviceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(resourcesMapper.selectById(1)).thenReturn(getResource()); |
|
|
|
|
Mockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true); |
|
|
|
|
result = resourcesService.updateResource(user, 0, "ResourcesServiceTest", "ResourcesServiceTest", |
|
|
|
|
ResourceType.FILE, null); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.RESOURCE_NOT_EXIST.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
|
// USER_NO_OPERATION_PERM
|
|
|
|
|
user.setId(2); |
|
|
|
|
Mockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true); |
|
|
|
|
user.setUserType(UserType.GENERAL_USER); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, |
|
|
|
|
null, 2, ApiFuncIdentificationConstant.FILE_UPDATE, serviceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, |
|
|
|
|
new Object[]{1}, 2, serviceLogger)).thenReturn(false); |
|
|
|
|
result = resourcesService.updateResource(user, 1, "ResourcesServiceTest", "ResourcesServiceTest", |
|
|
|
|
ResourceType.FILE, null); |
|
|
|
|
// tenant who have access to resource is 123,
|
|
|
|
|
Tenant tenantWNoPermission = new Tenant(); |
|
|
|
|
tenantWNoPermission.setTenantCode("321"); |
|
|
|
|
Mockito.when(tenantMapper.queryById(1)).thenReturn(tenantWNoPermission); |
|
|
|
|
result = resourcesService.updateResource(user, |
|
|
|
|
"/dolphinscheduler/123/resources/ResourcesServiceTest", |
|
|
|
|
"123", |
|
|
|
|
"ResourcesServiceTest", "", ResourceType.FILE, null); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.NO_CURRENT_OPERATING_PERMISSION.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
|
// RESOURCE_NOT_EXIST
|
|
|
|
|
user.setId(1); |
|
|
|
|
Mockito.when(userMapper.selectById(1)).thenReturn(getUser()); |
|
|
|
|
// SUCCESS
|
|
|
|
|
Mockito.when(tenantMapper.queryById(1)).thenReturn(getTenant()); |
|
|
|
|
Mockito.when(storageOperate.getFileName(Mockito.any(), Mockito.any(), Mockito.anyString())).thenReturn("test1"); |
|
|
|
|
|
|
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.UDF_FILE, null, |
|
|
|
|
1, ApiFuncIdentificationConstant.UDF_UPDATE, serviceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.UDF_FILE, new Object[]{1}, |
|
|
|
|
1, serviceLogger)).thenReturn(true); |
|
|
|
|
try { |
|
|
|
|
Mockito.when(storageOperate.exists(Mockito.any(), Mockito.any())).thenReturn(false); |
|
|
|
|
Mockito.when(storageOperate.exists(Mockito.any())).thenReturn(false); |
|
|
|
|
} catch (IOException e) { |
|
|
|
|
logger.error(e.getMessage(), e); |
|
|
|
|
} |
|
|
|
|
result = resourcesService.updateResource(user, 1, "ResourcesServiceTest1.jar", "ResourcesServiceTest", |
|
|
|
|
ResourceType.UDF, null); |
|
|
|
|
Assertions.assertEquals(Status.RESOURCE_NOT_EXIST.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
|
// SUCCESS
|
|
|
|
|
user.setId(1); |
|
|
|
|
Mockito.when(tenantMapper.queryById(1)).thenReturn(getTenant()); |
|
|
|
|
try { |
|
|
|
|
Mockito.when(storageOperate.exists(Mockito.any(), Mockito.any())).thenReturn(true); |
|
|
|
|
} catch (IOException e) { |
|
|
|
|
logger.error(e.getMessage(), e); |
|
|
|
|
Mockito.when(storageOperate.getFileStatus("/dolphinscheduler/123/resources/ResourcesServiceTest", |
|
|
|
|
"/dolphinscheduler/123/resources/", |
|
|
|
|
"123", ResourceType.FILE)).thenReturn(getStorageEntityResource()); |
|
|
|
|
result = resourcesService.updateResource(user, "/dolphinscheduler/123/resources/ResourcesServiceTest", |
|
|
|
|
"123", |
|
|
|
|
"ResourcesServiceTest", "", ResourceType.FILE, null); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.SUCCESS.getMsg(), result.getMsg()); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
logger.error(e.getMessage() + " Resource path: {}", "/dolphinscheduler/123/resources/ResourcesServiceTest", |
|
|
|
|
e); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, null, |
|
|
|
|
1, ApiFuncIdentificationConstant.FILE_UPDATE, serviceLogger)).thenReturn(true); |
|
|
|
|
Mockito.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); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.SUCCESS.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
|
// Tests for udf resources.
|
|
|
|
|
// RESOURCE_EXIST
|
|
|
|
|
Mockito.when(resourcesMapper.existResource("/ResourcesServiceTest1.jar", 0)).thenReturn(true); |
|
|
|
|
result = resourcesService.updateResource(user, 1, "ResourcesServiceTest1.jar", "ResourcesServiceTest", |
|
|
|
|
ResourceType.FILE, null); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.RESOURCE_EXIST.getMsg(), result.getMsg()); |
|
|
|
|
// USER_NOT_EXIST
|
|
|
|
|
try { |
|
|
|
|
Mockito.when(storageOperate.exists("/dolphinscheduler/123/resources/ResourcesServiceTest2.jar")) |
|
|
|
|
.thenReturn(true); |
|
|
|
|
} catch (IOException e) { |
|
|
|
|
logger.error("error occurred when checking resource: " |
|
|
|
|
+ "/dolphinscheduler/123/resources/ResourcesServiceTest2.jar"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Mockito.when(userMapper.selectById(Mockito.anyInt())).thenReturn(null); |
|
|
|
|
result = resourcesService.updateResource(user, 1, "ResourcesServiceTest1.jar", "ResourcesServiceTest", |
|
|
|
|
ResourceType.UDF, null); |
|
|
|
|
try { |
|
|
|
|
Mockito.when(storageOperate.getFileStatus("/dolphinscheduler/123/resources/ResourcesServiceTest1.jar", |
|
|
|
|
"/dolphinscheduler/123/resources/", |
|
|
|
|
"123", ResourceType.UDF)).thenReturn(getStorageEntityUdfResource()); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
logger.error(e.getMessage() + " Resource path: {}", |
|
|
|
|
"/dolphinscheduler/123/resources/ResourcesServiceTest1.jar", e); |
|
|
|
|
} |
|
|
|
|
result = resourcesService.updateResource(user, "/dolphinscheduler/123/resources/ResourcesServiceTest1.jar", |
|
|
|
|
"123", "ResourcesServiceTest2.jar", "", ResourceType.UDF, null); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertTrue(Status.USER_NOT_EXIST.getCode() == result.getCode()); |
|
|
|
|
Assertions.assertEquals(Status.RESOURCE_EXIST.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
|
// TENANT_NOT_EXIST
|
|
|
|
|
Mockito.when(userMapper.selectById(1)).thenReturn(getUser()); |
|
|
|
|
Mockito.when(tenantMapper.queryById(Mockito.anyInt())).thenReturn(null); |
|
|
|
|
result = resourcesService.updateResource(user, 1, "ResourcesServiceTest1.jar", "ResourcesServiceTest", |
|
|
|
|
ResourceType.UDF, null); |
|
|
|
|
result = resourcesService.updateResource(user, "ResourcesServiceTest1.jar", |
|
|
|
|
"", "ResourcesServiceTest", "", ResourceType.UDF, null); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.CURRENT_LOGIN_USER_TENANT_NOT_EXIST.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
|
// SUCCESS
|
|
|
|
|
Mockito.when(tenantMapper.queryById(1)).thenReturn(getTenant()); |
|
|
|
|
|
|
|
|
|
result = resourcesService.updateResource(user, 1, "ResourcesServiceTest1.jar", "ResourcesServiceTest1.jar", |
|
|
|
|
ResourceType.UDF, null); |
|
|
|
|
result = resourcesService.updateResource(user, "/dolphinscheduler/123/resources/ResourcesServiceTest1.jar", |
|
|
|
|
"123", "ResourcesServiceTest1.jar", "", ResourceType.UDF, null); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.SUCCESS.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testQueryResourceListPaging() { |
|
|
|
|
User loginUser = new User(); |
|
|
|
|
loginUser.setId(1); |
|
|
|
|
loginUser.setTenantId(1); |
|
|
|
|
loginUser.setTenantCode("tenant1"); |
|
|
|
|
loginUser.setUserType(UserType.ADMIN_USER); |
|
|
|
|
IPage<Resource> resourcePage = new Page<>(1, 10); |
|
|
|
|
resourcePage.setTotal(1); |
|
|
|
|
resourcePage.setRecords(getResourceList()); |
|
|
|
|
|
|
|
|
|
Mockito.when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.RESOURCE_FILE_ID, |
|
|
|
|
1, resourceLogger)).thenReturn(getSetIds()); |
|
|
|
|
List<StorageEntity> mockResList = new ArrayList<StorageEntity>(); |
|
|
|
|
mockResList.add(getStorageEntityResource()); |
|
|
|
|
List<User> mockUserList = new ArrayList<User>(); |
|
|
|
|
mockUserList.add(getUser()); |
|
|
|
|
Mockito.when(userMapper.selectList(null)).thenReturn(mockUserList); |
|
|
|
|
Mockito.when(userMapper.selectById(getUser().getId())).thenReturn(getUser()); |
|
|
|
|
Mockito.when(tenantMapper.queryById(getUser().getTenantId())).thenReturn(getTenant()); |
|
|
|
|
Mockito.when(storageOperate.getResDir("123")).thenReturn("/dolphinscheduler/123/resources/"); |
|
|
|
|
|
|
|
|
|
Mockito.when( |
|
|
|
|
resourcesMapper.queryResourcePaging(Mockito.any(Page.class), eq(-1), eq(0), eq("test"), Mockito.any())) |
|
|
|
|
.thenReturn(resourcePage); |
|
|
|
|
Result result = resourcesService.queryResourceListPaging(loginUser, -1, ResourceType.FILE, "test", 1, 10); |
|
|
|
|
try { |
|
|
|
|
Mockito.when(storageOperate.listFilesStatus("/dolphinscheduler/123/resources/", |
|
|
|
|
"/dolphinscheduler/123/resources/", |
|
|
|
|
"123", ResourceType.FILE)).thenReturn(mockResList); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
logger.error("QueryResourceListPaging Error"); |
|
|
|
|
} |
|
|
|
|
Result result = resourcesService.queryResourceListPaging(loginUser, "", "", |
|
|
|
|
ResourceType.FILE, "Test", 1, 10); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.SUCCESS.getCode(), (int) result.getCode()); |
|
|
|
|
PageInfo pageInfo = (PageInfo) result.getData(); |
|
|
|
@ -410,30 +380,33 @@ public class ResourcesServiceTest {
|
|
|
|
|
loginUser.setId(0); |
|
|
|
|
loginUser.setUserType(UserType.ADMIN_USER); |
|
|
|
|
|
|
|
|
|
Mockito.when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.RESOURCE_FILE_ID, |
|
|
|
|
0, resourceLogger)).thenReturn(getSetIds()); |
|
|
|
|
Mockito.when(resourcesMapper.selectBatchIds(Mockito.anySet())).thenReturn(getResourceList()); |
|
|
|
|
|
|
|
|
|
Map<String, Object> result = resourcesService.queryResourceList(loginUser, ResourceType.FILE); |
|
|
|
|
Mockito.when(userMapper.selectList(null)).thenReturn(Arrays.asList(loginUser)); |
|
|
|
|
Mockito.when(userMapper.selectById(loginUser.getId())).thenReturn(loginUser); |
|
|
|
|
Mockito.when(tenantMapper.queryById(Mockito.anyInt())).thenReturn(getTenant()); |
|
|
|
|
Mockito.when(storageOperate.getResDir("123")).thenReturn("/dolphinscheduler/123/resources/"); |
|
|
|
|
Mockito.when(storageOperate.listFilesStatusRecursively("/dolphinscheduler/123/resources/", |
|
|
|
|
"/dolphinscheduler/123/resources/", |
|
|
|
|
"123", |
|
|
|
|
ResourceType.FILE)).thenReturn(Arrays.asList(getStorageEntityResource())); |
|
|
|
|
Map<String, Object> result = resourcesService.queryResourceList(loginUser, ResourceType.FILE, ""); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); |
|
|
|
|
List<Resource> resourceList = (List<Resource>) result.get(Constants.DATA_LIST); |
|
|
|
|
Assertions.assertTrue(CollectionUtils.isNotEmpty(resourceList)); |
|
|
|
|
|
|
|
|
|
// test udf
|
|
|
|
|
Mockito.when(resourcePermissionCheckService.userOwnedResourceIdsAcquisition(AuthorizationType.UDF_FILE, 0, |
|
|
|
|
resourceLogger)).thenReturn(getSetIds()); |
|
|
|
|
Mockito.when(resourcesMapper.selectBatchIds(Mockito.anySet())) |
|
|
|
|
.thenReturn(Arrays.asList(getResource(11, ResourceType.UDF), |
|
|
|
|
getResource(10, ResourceType.UDF), getResource(9, ResourceType.UDF), |
|
|
|
|
getResource(8, ResourceType.UDF))); |
|
|
|
|
|
|
|
|
|
Mockito.when(storageOperate.getUdfDir("123")).thenReturn("/dolphinscheduler/123/udfs/"); |
|
|
|
|
Mockito.when(storageOperate.listFilesStatusRecursively("/dolphinscheduler/123/udfs/", |
|
|
|
|
"/dolphinscheduler/123/udfs/", |
|
|
|
|
"123", |
|
|
|
|
ResourceType.UDF)) |
|
|
|
|
.thenReturn(Arrays.asList(getStorageEntityUdfResource())); |
|
|
|
|
loginUser.setUserType(UserType.GENERAL_USER); |
|
|
|
|
result = resourcesService.queryResourceList(loginUser, ResourceType.UDF); |
|
|
|
|
result = resourcesService.queryResourceList(loginUser, ResourceType.UDF, ""); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); |
|
|
|
|
resourceList = (List<Resource>) result.get(Constants.DATA_LIST); |
|
|
|
|
Assertions.assertTrue(resourceList.size() == 4); |
|
|
|
|
Assertions.assertTrue(CollectionUtils.isNotEmpty(resourceList)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@ -443,59 +416,34 @@ public class ResourcesServiceTest {
|
|
|
|
|
loginUser.setId(0); |
|
|
|
|
loginUser.setUserType(UserType.GENERAL_USER); |
|
|
|
|
Mockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(false); |
|
|
|
|
Mockito.when(resourcesMapper.selectById(1)).thenReturn(getResource()); |
|
|
|
|
Mockito.when(tenantMapper.queryById(1)).thenReturn(getTenant()); |
|
|
|
|
|
|
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, null, |
|
|
|
|
0, ApiFuncIdentificationConstant.FILE_DELETE, serviceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, |
|
|
|
|
new Object[]{1}, |
|
|
|
|
0, serviceLogger)).thenReturn(true); |
|
|
|
|
try { |
|
|
|
|
// HDFS_NOT_STARTUP
|
|
|
|
|
Result result = resourcesService.delete(loginUser, 1); |
|
|
|
|
Result result = resourcesService.delete(loginUser, "", ""); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.STORAGE_NOT_STARTUP.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
|
// RESOURCE_NOT_EXIST
|
|
|
|
|
Mockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true); |
|
|
|
|
Mockito.when(resourcesMapper.selectById(1)).thenReturn(getResource()); |
|
|
|
|
|
|
|
|
|
Mockito.when( |
|
|
|
|
resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, null, |
|
|
|
|
0, ApiFuncIdentificationConstant.FILE_DELETE, serviceLogger)) |
|
|
|
|
.thenReturn(true); |
|
|
|
|
|
|
|
|
|
result = resourcesService.delete(loginUser, 2); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.RESOURCE_NOT_EXIST.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
|
// USER_NO_OPERATION_PERM
|
|
|
|
|
result = resourcesService.delete(loginUser, 2); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.RESOURCE_NOT_EXIST.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
|
// TENANT_NOT_EXIST
|
|
|
|
|
Mockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true); |
|
|
|
|
loginUser.setUserType(UserType.ADMIN_USER); |
|
|
|
|
loginUser.setTenantId(2); |
|
|
|
|
Mockito.when(userMapper.selectById(Mockito.anyInt())).thenReturn(loginUser); |
|
|
|
|
Mockito.when( |
|
|
|
|
resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, null, |
|
|
|
|
0, ApiFuncIdentificationConstant.FILE_DELETE, serviceLogger)) |
|
|
|
|
.thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, |
|
|
|
|
new Object[]{1}, |
|
|
|
|
0, serviceLogger)).thenReturn(true); |
|
|
|
|
result = resourcesService.delete(loginUser, 1); |
|
|
|
|
Mockito.when(userMapper.selectById(loginUser.getId())).thenReturn(loginUser); |
|
|
|
|
result = resourcesService.delete(loginUser, "", ""); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.CURRENT_LOGIN_USER_TENANT_NOT_EXIST.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
|
// RESOURCE_NOT_EXIST
|
|
|
|
|
Mockito.when(tenantMapper.queryById(Mockito.anyInt())).thenReturn(getTenant()); |
|
|
|
|
Mockito.when(storageOperate.getFileStatus("/dolphinscheduler/123/resources/ResourcesServiceTest", |
|
|
|
|
null, "123", null)) |
|
|
|
|
.thenReturn(getStorageEntityResource()); |
|
|
|
|
result = resourcesService.delete(loginUser, "/dolphinscheduler/123/resources/ResNotExist", "123"); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.RESOURCE_NOT_EXIST.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
|
// SUCCESS
|
|
|
|
|
loginUser.setTenantId(1); |
|
|
|
|
Mockito.when(processDefinitionMapper.listResources()).thenReturn(getResources()); |
|
|
|
|
Mockito.when(resourcesMapper.deleteIds(Mockito.any())).thenReturn(1); |
|
|
|
|
Mockito.when(resourceUserMapper.deleteResourceUserArray(Mockito.anyInt(), Mockito.any())).thenReturn(1); |
|
|
|
|
result = resourcesService.delete(loginUser, 1); |
|
|
|
|
result = resourcesService.delete(loginUser, "/dolphinscheduler/123/resources/ResourcesServiceTest", |
|
|
|
|
"123"); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.SUCCESS.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
@ -508,29 +456,19 @@ public class ResourcesServiceTest {
|
|
|
|
|
@Test |
|
|
|
|
public void testVerifyResourceName() { |
|
|
|
|
|
|
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, null, |
|
|
|
|
1, ApiFuncIdentificationConstant.FILE_RENAME, serviceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, null, |
|
|
|
|
1, serviceLogger)).thenReturn(true); |
|
|
|
|
User user = new User(); |
|
|
|
|
user.setId(1); |
|
|
|
|
user.setUserType(UserType.GENERAL_USER); |
|
|
|
|
Mockito.when(resourcesMapper.existResource("/ResourcesServiceTest.jar", 0)).thenReturn(true); |
|
|
|
|
try { |
|
|
|
|
Mockito.when(storageOperate.exists("/ResourcesServiceTest.jar")).thenReturn(true); |
|
|
|
|
} catch (IOException e) { |
|
|
|
|
logger.error("error occurred when checking resource: /ResourcesServiceTest.jar\""); |
|
|
|
|
} |
|
|
|
|
Result result = resourcesService.verifyResourceName("/ResourcesServiceTest.jar", ResourceType.FILE, user); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.RESOURCE_EXIST.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
|
// TENANT_NOT_EXIST
|
|
|
|
|
Mockito.when(tenantMapper.queryById(1)).thenReturn(getTenant()); |
|
|
|
|
String unExistFullName = "/test.jar"; |
|
|
|
|
|
|
|
|
|
result = resourcesService.verifyResourceName("/test.jar", ResourceType.FILE, user); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.CURRENT_LOGIN_USER_TENANT_NOT_EXIST.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
|
// RESOURCE_FILE_EXIST
|
|
|
|
|
user.setTenantId(1); |
|
|
|
|
|
|
|
|
|
result = resourcesService.verifyResourceName("/ResourcesServiceTest.jar", ResourceType.FILE, user); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertTrue(Status.RESOURCE_EXIST.getCode() == result.getCode()); |
|
|
|
@ -544,123 +482,89 @@ public class ResourcesServiceTest {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testReadResource() { |
|
|
|
|
|
|
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, null, |
|
|
|
|
1, ApiFuncIdentificationConstant.FILE_VIEW, serviceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, |
|
|
|
|
new Object[]{1}, |
|
|
|
|
1, serviceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(false); |
|
|
|
|
|
|
|
|
|
// HDFS_NOT_STARTUP
|
|
|
|
|
Result result = resourcesService.readResource(getUser(), 1, 1, 10); |
|
|
|
|
Result result = resourcesService.readResource(getUser(), "", "", 1, 10); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.STORAGE_NOT_STARTUP.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
|
// RESOURCE_NOT_EXIST
|
|
|
|
|
Mockito.when(resourcesMapper.selectById(1)).thenReturn(getResource()); |
|
|
|
|
Mockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, null, |
|
|
|
|
1, ApiFuncIdentificationConstant.FILE_VIEW, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
|
|
result = resourcesService.readResource(getUser(), 2, 1, 10); |
|
|
|
|
Mockito.when(userMapper.selectById(getUser().getId())).thenReturn(getUser()); |
|
|
|
|
Mockito.when(tenantMapper.queryById(getUser().getTenantId())).thenReturn(getTenant()); |
|
|
|
|
result = resourcesService.readResource(getUser(), "", "", 1, 10); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.RESOURCE_NOT_EXIST.getMsg(), result.getMsg()); |
|
|
|
|
Assertions.assertEquals(Status.RESOURCE_FILE_NOT_EXIST.getCode(), (int) result.getCode()); |
|
|
|
|
|
|
|
|
|
// RESOURCE_SUFFIX_NOT_SUPPORT_VIEW
|
|
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, null, |
|
|
|
|
1, ApiFuncIdentificationConstant.FILE_VIEW, serviceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, |
|
|
|
|
new Object[]{1}, |
|
|
|
|
1, serviceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(FileUtils.getResourceViewSuffixes()).thenReturn("class"); |
|
|
|
|
Mockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true); |
|
|
|
|
result = resourcesService.readResource(getUser(), 1, 1, 10); |
|
|
|
|
result = resourcesService.readResource(getUser(), "", "", 1, 10); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.RESOURCE_SUFFIX_NOT_SUPPORT_VIEW.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
|
// USER_NOT_EXIST
|
|
|
|
|
Mockito.when(userMapper.selectById(getUser().getId())).thenReturn(null); |
|
|
|
|
Mockito.when(FileUtils.getResourceViewSuffixes()).thenReturn("jar"); |
|
|
|
|
Mockito.when(Files.getFileExtension("ResourcesServiceTest.jar")).thenReturn("jar"); |
|
|
|
|
result = resourcesService.readResource(getUser(), 1, 1, 10); |
|
|
|
|
result = resourcesService.readResource(getUser(), "", "", 1, 10); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.USER_NOT_EXIST.getCode(), (int) result.getCode()); |
|
|
|
|
|
|
|
|
|
// TENANT_NOT_EXIST
|
|
|
|
|
Mockito.when(userMapper.selectById(1)).thenReturn(getUser()); |
|
|
|
|
result = resourcesService.readResource(getUser(), 1, 1, 10); |
|
|
|
|
Mockito.when(userMapper.selectById(getUser().getId())).thenReturn(getUser()); |
|
|
|
|
Mockito.when(tenantMapper.queryById(getUser().getTenantId())).thenReturn(null); |
|
|
|
|
result = resourcesService.readResource(getUser(), "", "", 1, 10); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.CURRENT_LOGIN_USER_TENANT_NOT_EXIST.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
|
// RESOURCE_FILE_NOT_EXIST
|
|
|
|
|
Mockito.when(tenantMapper.queryById(1)).thenReturn(getTenant()); |
|
|
|
|
|
|
|
|
|
result = resourcesService.readResource(getUser(), 1, 1, 10); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.RESOURCE_FILE_NOT_EXIST.getCode(), (int) result.getCode()); |
|
|
|
|
|
|
|
|
|
// SUCCESS
|
|
|
|
|
Mockito.when(userMapper.selectById(getUser().getId())).thenReturn(getUser()); |
|
|
|
|
Mockito.when(tenantMapper.queryById(getUser().getTenantId())).thenReturn(getTenant()); |
|
|
|
|
try { |
|
|
|
|
Mockito.when(storageOperate.exists(Mockito.any(), Mockito.any())).thenReturn(true); |
|
|
|
|
Mockito.when(storageOperate.exists(Mockito.any())).thenReturn(true); |
|
|
|
|
Mockito.when(storageOperate.vimFile(Mockito.any(), Mockito.any(), eq(1), eq(10))).thenReturn(getContent()); |
|
|
|
|
} catch (IOException e) { |
|
|
|
|
logger.error("storage error", e); |
|
|
|
|
} |
|
|
|
|
result = resourcesService.readResource(getUser(), 1, 1, 10); |
|
|
|
|
Mockito.when(Files.getFileExtension("test.jar")).thenReturn("jar"); |
|
|
|
|
result = resourcesService.readResource(getUser(), "test.jar", "", 1, 10); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.SUCCESS.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testOnlineCreateResource() { |
|
|
|
|
|
|
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, null, |
|
|
|
|
1, ApiFuncIdentificationConstant.FILE_ONLINE_CREATE, serviceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, null, |
|
|
|
|
1, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
|
|
Mockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(false); |
|
|
|
|
User user = getUser(); |
|
|
|
|
user.setId(1); |
|
|
|
|
Mockito.when(userMapper.selectById(user.getId())).thenReturn(getUser()); |
|
|
|
|
Mockito.when(tenantMapper.queryById(1)).thenReturn(getTenant()); |
|
|
|
|
|
|
|
|
|
// HDFS_NOT_STARTUP
|
|
|
|
|
Result result = resourcesService.onlineCreateResource(user, ResourceType.FILE, "test", "jar", "desc", "content", |
|
|
|
|
-1, "/"); |
|
|
|
|
"/"); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.STORAGE_NOT_STARTUP.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
|
// RESOURCE_SUFFIX_NOT_SUPPORT_VIEW
|
|
|
|
|
Mockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true); |
|
|
|
|
Mockito.when(FileUtils.getResourceViewSuffixes()).thenReturn("class"); |
|
|
|
|
result = resourcesService.onlineCreateResource(user, ResourceType.FILE, "test", "jar", "desc", "content", -1, |
|
|
|
|
result = resourcesService.onlineCreateResource(user, ResourceType.FILE, "test", "jar", "desc", "content", |
|
|
|
|
"/"); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.RESOURCE_SUFFIX_NOT_SUPPORT_VIEW.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
|
// RuntimeException
|
|
|
|
|
try { |
|
|
|
|
Mockito.when(FileUtils.getResourceViewSuffixes()).thenReturn("jar"); |
|
|
|
|
Mockito.when(tenantMapper.queryById(1)).thenReturn(getTenant()); |
|
|
|
|
result = resourcesService.onlineCreateResource(user, ResourceType.FILE, "test", "jar", "desc", "content", |
|
|
|
|
-1, "/"); |
|
|
|
|
} catch (RuntimeException ex) { |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.RESOURCE_NOT_EXIST.getMsg(), ex.getMessage()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// SUCCESS
|
|
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, null, |
|
|
|
|
1, ApiFuncIdentificationConstant.FILE_RENAME, serviceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, null, |
|
|
|
|
1, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
|
|
Mockito.when(FileUtils.getResourceViewSuffixes()).thenReturn("jar"); |
|
|
|
|
Mockito.when(storageOperate.getResDir("123")).thenReturn("/dolphinscheduler/123/resources/"); |
|
|
|
|
Mockito.when(FileUtils.getUploadFilename(Mockito.anyString(), Mockito.anyString())).thenReturn("test"); |
|
|
|
|
Mockito.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", |
|
|
|
|
"/"); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.SUCCESS.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@ -684,141 +588,138 @@ public class ResourcesServiceTest {
|
|
|
|
|
Resource dir2 = new Resource(); |
|
|
|
|
dir2.setFullName(resourceDir); |
|
|
|
|
dir2.setUserId(user.getId()); |
|
|
|
|
Mockito.when(resourcesMapper.queryResource(dir1.getFullName(), ResourceType.FILE.ordinal())) |
|
|
|
|
.thenReturn(Collections.singletonList(dir1)); |
|
|
|
|
Mockito.when(resourcesMapper.queryResource(resourceDir, ResourceType.FILE.ordinal())).thenReturn(null); |
|
|
|
|
|
|
|
|
|
Tenant tenant = getTenant(); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck( |
|
|
|
|
AuthorizationType.RESOURCE_FILE_ID, null, 1, ApiFuncIdentificationConstant.FOLDER_ONLINE_CREATE, |
|
|
|
|
serviceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck( |
|
|
|
|
AuthorizationType.RESOURCE_FILE_ID, null, 1, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
|
|
Mockito.when(storageOperate.getDir(ResourceType.FILE, "123")).thenReturn("/dolphinscheduler/123/resources/"); |
|
|
|
|
Mockito.when(storageOperate.getResDir("123")).thenReturn("/dolphinscheduler/123/resources/"); |
|
|
|
|
Mockito.when(FileUtils.getUploadFilename(Mockito.anyString(), Mockito.anyString())).thenReturn("test"); |
|
|
|
|
Mockito.when(FileUtils.writeContent2File(Mockito.anyString(), Mockito.anyString())).thenReturn(true); |
|
|
|
|
try { |
|
|
|
|
Mockito.when(storageOperate.mkdir(tenant.getTenantCode(), null)).thenReturn(true); |
|
|
|
|
Mockito.when(storageOperate.mkdir("123", "/dolphinscheduler/123/resources" + dir1Path)).thenReturn(true); |
|
|
|
|
Mockito.when(storageOperate.mkdir("123", "/dolphinscheduler/123/resources" + dir2Path)).thenReturn(true); |
|
|
|
|
} catch (IOException e) { |
|
|
|
|
logger.error("storage error", e); |
|
|
|
|
logger.error("create resource directory {} failed", fullName); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck( |
|
|
|
|
AuthorizationType.RESOURCE_FILE_ID, null, 1, ApiFuncIdentificationConstant.FILE_ONLINE_CREATE, |
|
|
|
|
serviceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck( |
|
|
|
|
AuthorizationType.RESOURCE_FILE_ID, null, 1, serviceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck( |
|
|
|
|
AuthorizationType.RESOURCE_FILE_ID, null, 1, ApiFuncIdentificationConstant.FILE_RENAME, serviceLogger)) |
|
|
|
|
.thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck( |
|
|
|
|
AuthorizationType.RESOURCE_FILE_ID, null, 1, serviceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(tenantMapper.queryById(1)).thenReturn(getTenant()); |
|
|
|
|
Mockito.when(FileUtils.getUploadFilename(Mockito.anyString(), Mockito.anyString())).thenReturn("test"); |
|
|
|
|
Mockito.when(FileUtils.writeContent2File(Mockito.anyString(), Mockito.anyString())).thenReturn(true); |
|
|
|
|
|
|
|
|
|
Mockito.when(userMapper.selectById(user.getId())).thenReturn(getUser()); |
|
|
|
|
Mockito.when(tenantMapper.queryById(user.getTenantId())).thenReturn(getTenant()); |
|
|
|
|
Result<Object> result = resourcesService.onlineCreateOrUpdateResourceWithDir(user, fullName, desc, content); |
|
|
|
|
Assertions.assertEquals(Status.SUCCESS.getMsg(), result.getMsg()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testQueryResourcesFileInfo() { |
|
|
|
|
User user = getUser(); |
|
|
|
|
String userName = "test-user"; |
|
|
|
|
Mockito.when(userMapper.queryByUserNameAccurately(userName)).thenReturn(user); |
|
|
|
|
Resource file = new Resource(); |
|
|
|
|
file.setFullName("/dir/file1.py"); |
|
|
|
|
file.setId(1); |
|
|
|
|
Mockito.when(resourcesMapper.queryResource(file.getFullName(), ResourceType.FILE.ordinal())) |
|
|
|
|
.thenReturn(Collections.singletonList(file)); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck( |
|
|
|
|
AuthorizationType.RESOURCE_FILE_ID, null, user.getId(), ApiFuncIdentificationConstant.FILE_VIEW, |
|
|
|
|
serviceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck( |
|
|
|
|
AuthorizationType.RESOURCE_FILE_ID, new Object[]{file.getId()}, user.getId(), serviceLogger)) |
|
|
|
|
.thenReturn(true); |
|
|
|
|
Resource result = resourcesService.queryResourcesFileInfo(userName, file.getFullName()); |
|
|
|
|
Assertions.assertEquals(file.getFullName(), result.getFullName()); |
|
|
|
|
} |
|
|
|
|
// TODO: revise this testcase after modifying PythonGateway.java
|
|
|
|
|
// @Test
|
|
|
|
|
// public void testQueryResourcesFileInfo() {
|
|
|
|
|
// User user = getUser();
|
|
|
|
|
// String userName = "test-user";
|
|
|
|
|
// Mockito.when(userMapper.queryByUserNameAccurately(userName)).thenReturn(user);
|
|
|
|
|
// Resource file = new Resource();
|
|
|
|
|
// file.setFullName("/dir/file1.py");
|
|
|
|
|
// file.setId(1);
|
|
|
|
|
// Mockito.when(resourcesMapper.queryResource(file.getFullName(), ResourceType.FILE.ordinal()))
|
|
|
|
|
// .thenReturn(Collections.singletonList(file));
|
|
|
|
|
// Mockito.when(resourcePermissionCheckService.operationPermissionCheck(
|
|
|
|
|
// AuthorizationType.RESOURCE_FILE_ID, null, user.getId(), ApiFuncIdentificationConstant.FILE_VIEW,
|
|
|
|
|
// serviceLogger)).thenReturn(true);
|
|
|
|
|
// Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(
|
|
|
|
|
// AuthorizationType.RESOURCE_FILE_ID, new Object[]{file.getId()}, user.getId(), serviceLogger))
|
|
|
|
|
// .thenReturn(true);
|
|
|
|
|
// Mockito.when(userMapper.selectById(1)).thenReturn(getUser());
|
|
|
|
|
// Mockito.when(tenantMapper.queryById(1)).thenReturn(getTenant());
|
|
|
|
|
// Resource result = resourcesService.queryResourcesFileInfo(userName, file.getFullName());
|
|
|
|
|
// Assertions.assertEquals(file.getFullName(), result.getFullName());
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testUpdateResourceContent() { |
|
|
|
|
Mockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(false); |
|
|
|
|
|
|
|
|
|
// HDFS_NOT_STARTUP
|
|
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, null, |
|
|
|
|
1, ApiFuncIdentificationConstant.FILE_UPDATE, serviceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, |
|
|
|
|
new Object[]{1}, |
|
|
|
|
1, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
|
|
Result result = resourcesService.updateResourceContent(getUser(), 1, "content"); |
|
|
|
|
Result result = resourcesService.updateResourceContent(getUser(), "", "", "content"); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.STORAGE_NOT_STARTUP.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
|
// RESOURCE_NOT_EXIST
|
|
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, null, |
|
|
|
|
1, ApiFuncIdentificationConstant.FILE_UPDATE, serviceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true); |
|
|
|
|
Mockito.when(resourcesMapper.selectById(1)).thenReturn(getResource()); |
|
|
|
|
result = resourcesService.updateResourceContent(getUser(), 2, "content"); |
|
|
|
|
Mockito.when(userMapper.selectById(getUser().getId())).thenReturn(getUser()); |
|
|
|
|
Mockito.when(tenantMapper.queryById(1)).thenReturn(getTenant()); |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
Mockito.when(storageOperate.getFileStatus("/dolphinscheduler/123/resources/ResourcesServiceTest.jar", |
|
|
|
|
"", |
|
|
|
|
"123", ResourceType.FILE)).thenReturn(null); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
logger.error(e.getMessage() + " Resource path: {}", "", e); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
result = resourcesService.updateResourceContent(getUser(), |
|
|
|
|
"/dolphinscheduler/123/resources/ResourcesServiceTest.jar", |
|
|
|
|
"123", "content"); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.RESOURCE_NOT_EXIST.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
|
// RESOURCE_SUFFIX_NOT_SUPPORT_VIEW
|
|
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, null, |
|
|
|
|
1, ApiFuncIdentificationConstant.FILE_UPDATE, serviceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, |
|
|
|
|
new Object[]{1}, |
|
|
|
|
1, serviceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true); |
|
|
|
|
Mockito.when(FileUtils.getResourceViewSuffixes()).thenReturn("class"); |
|
|
|
|
result = resourcesService.updateResourceContent(getUser(), 1, "content"); |
|
|
|
|
try { |
|
|
|
|
Mockito.when(storageOperate.getFileStatus("", "", "123", ResourceType.FILE)) |
|
|
|
|
.thenReturn(getStorageEntityResource()); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
logger.error(e.getMessage() + " Resource path: {}", "", e); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
result = resourcesService.updateResourceContent(getUser(), "", "123", "content"); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.RESOURCE_SUFFIX_NOT_SUPPORT_VIEW.getMsg(), result.getMsg()); |
|
|
|
|
|
|
|
|
|
// USER_NOT_EXIST
|
|
|
|
|
Mockito.when(FileUtils.getResourceViewSuffixes()).thenReturn("jar"); |
|
|
|
|
Mockito.when(Files.getFileExtension("ResourcesServiceTest.jar")).thenReturn("jar"); |
|
|
|
|
result = resourcesService.updateResourceContent(getUser(), 1, "content"); |
|
|
|
|
Mockito.when(userMapper.selectById(getUser().getId())).thenReturn(null); |
|
|
|
|
result = resourcesService.updateResourceContent(getUser(), "", "123", "content"); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertTrue(Status.USER_NOT_EXIST.getCode() == result.getCode()); |
|
|
|
|
|
|
|
|
|
// TENANT_NOT_EXIST
|
|
|
|
|
Mockito.when(userMapper.selectById(1)).thenReturn(getUser()); |
|
|
|
|
result = resourcesService.updateResourceContent(getUser(), 1, "content"); |
|
|
|
|
Mockito.when(userMapper.selectById(getUser().getId())).thenReturn(getUser()); |
|
|
|
|
Mockito.when(tenantMapper.queryById(1)).thenReturn(null); |
|
|
|
|
result = resourcesService.updateResourceContent(getUser(), "", "123", "content"); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertTrue(Status.CURRENT_LOGIN_USER_TENANT_NOT_EXIST.getCode() == result.getCode()); |
|
|
|
|
|
|
|
|
|
// SUCCESS
|
|
|
|
|
try { |
|
|
|
|
Mockito.when(storageOperate.getFileStatus("/dolphinscheduler/123/resources/ResourcesServiceTest.jar", |
|
|
|
|
"", |
|
|
|
|
"123", ResourceType.FILE)).thenReturn(getStorageEntityResource()); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
logger.error(e.getMessage() + " Resource path: {}", "", e); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Mockito.when(Files.getFileExtension(Mockito.anyString())).thenReturn("jar"); |
|
|
|
|
Mockito.when(FileUtils.getResourceViewSuffixes()).thenReturn("jar"); |
|
|
|
|
Mockito.when(userMapper.selectById(getUser().getId())).thenReturn(getUser()); |
|
|
|
|
Mockito.when(tenantMapper.queryById(1)).thenReturn(getTenant()); |
|
|
|
|
Mockito.when(FileUtils.getUploadFilename(Mockito.anyString(), Mockito.anyString())).thenReturn("test"); |
|
|
|
|
Mockito.when(FileUtils.writeContent2File(Mockito.anyString(), Mockito.anyString())).thenReturn(true); |
|
|
|
|
result = resourcesService.updateResourceContent(getUser(), 1, "content"); |
|
|
|
|
result = resourcesService.updateResourceContent(getUser(), |
|
|
|
|
"/dolphinscheduler/123/resources/ResourcesServiceTest.jar", |
|
|
|
|
"123", "content"); |
|
|
|
|
logger.info(result.toString()); |
|
|
|
|
Assertions.assertEquals(Status.SUCCESS.getMsg(), result.getMsg()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testDownloadResource() { |
|
|
|
|
|
|
|
|
|
Mockito.when(resourcePermissionCheckService.operationPermissionCheck(AuthorizationType.RESOURCE_FILE_ID, null, |
|
|
|
|
1, ApiFuncIdentificationConstant.FILE_DOWNLOAD, serviceLogger)).thenReturn(true); |
|
|
|
|
Mockito.when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.RESOURCE_FILE_ID, |
|
|
|
|
new Object[]{1}, |
|
|
|
|
1, serviceLogger)).thenReturn(true); |
|
|
|
|
|
|
|
|
|
Mockito.when(PropertyUtils.getResUploadStartupState()).thenReturn(true); |
|
|
|
|
Mockito.when(tenantMapper.queryById(1)).thenReturn(getTenant()); |
|
|
|
|
Mockito.when(userMapper.selectById(1)).thenReturn(getUser()); |
|
|
|
|
org.springframework.core.io.Resource resourceMock = Mockito.mock(org.springframework.core.io.Resource.class); |
|
|
|
|
try { |
|
|
|
|
// resource null
|
|
|
|
|
org.springframework.core.io.Resource resource = resourcesService.downloadResource(getUser(), 1); |
|
|
|
|
org.springframework.core.io.Resource resource = resourcesService.downloadResource(getUser(), ""); |
|
|
|
|
Assertions.assertNull(resource); |
|
|
|
|
|
|
|
|
|
Mockito.when(resourcesMapper.selectById(1)).thenReturn(getResource()); |
|
|
|
|
Mockito.when(org.apache.dolphinscheduler.api.utils.FileUtils.file2Resource(Mockito.any())) |
|
|
|
|
.thenReturn(resourceMock); |
|
|
|
|
resource = resourcesService.downloadResource(getUser(), 1); |
|
|
|
|
resource = resourcesService.downloadResource(getUser(), ""); |
|
|
|
|
Assertions.assertNotNull(resource); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
logger.error("DownloadResource error", e); |
|
|
|
@ -1016,7 +917,6 @@ public class ResourcesServiceTest {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Resource getResource() { |
|
|
|
|
|
|
|
|
|
Resource resource = new Resource(); |
|
|
|
|
resource.setPid(-1); |
|
|
|
|
resource.setUserId(1); |
|
|
|
@ -1027,6 +927,19 @@ public class ResourcesServiceTest {
|
|
|
|
|
return resource; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private StorageEntity getStorageEntityResource() { |
|
|
|
|
StorageEntity entity = new StorageEntity(); |
|
|
|
|
entity.setAlias("ResourcesServiceTest"); |
|
|
|
|
entity.setFileName("ResourcesServiceTest"); |
|
|
|
|
entity.setDirectory(false); |
|
|
|
|
entity.setDescription(""); |
|
|
|
|
entity.setUserName("123"); |
|
|
|
|
entity.setType(ResourceType.FILE); |
|
|
|
|
entity.setFullName("/dolphinscheduler/123/resources/ResourcesServiceTest"); |
|
|
|
|
|
|
|
|
|
return entity; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Resource getResource(int resourceId) { |
|
|
|
|
|
|
|
|
|
Resource resource = new Resource(); |
|
|
|
@ -1064,6 +977,19 @@ public class ResourcesServiceTest {
|
|
|
|
|
return resource; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private StorageEntity getStorageEntityUdfResource() { |
|
|
|
|
StorageEntity entity = new StorageEntity(); |
|
|
|
|
entity.setAlias("ResourcesServiceTest1.jar"); |
|
|
|
|
entity.setFileName("ResourcesServiceTest1.jar"); |
|
|
|
|
entity.setDirectory(false); |
|
|
|
|
entity.setDescription(""); |
|
|
|
|
entity.setUserName("123"); |
|
|
|
|
entity.setType(ResourceType.UDF); |
|
|
|
|
entity.setFullName("/dolphinscheduler/123/resources/ResourcesServiceTest1.jar"); |
|
|
|
|
|
|
|
|
|
return entity; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private UdfFunc getUdfFunc() { |
|
|
|
|
|
|
|
|
|
UdfFunc udfFunc = new UdfFunc(); |
|
|
|
|