|
|
@ -17,13 +17,20 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.apache.dolphinscheduler.api.python; |
|
|
|
package org.apache.dolphinscheduler.api.python; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.api.enums.Status; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.api.service.ResourcesService; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.api.service.UsersService; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.api.utils.Result; |
|
|
|
import org.apache.dolphinscheduler.common.utils.CodeGenerateUtils; |
|
|
|
import org.apache.dolphinscheduler.common.utils.CodeGenerateUtils; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.Project; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.Project; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.Resource; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.TaskDefinition; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.TaskDefinition; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.User; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.spi.enums.ResourceType; |
|
|
|
import org.junit.Assert; |
|
|
|
import org.junit.Assert; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.runner.RunWith; |
|
|
|
import org.junit.runner.RunWith; |
|
|
@ -53,6 +60,12 @@ public class PythonGatewayTest { |
|
|
|
@Mock |
|
|
|
@Mock |
|
|
|
private TaskDefinitionMapper taskDefinitionMapper; |
|
|
|
private TaskDefinitionMapper taskDefinitionMapper; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Mock |
|
|
|
|
|
|
|
private ResourcesService resourcesService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Mock |
|
|
|
|
|
|
|
private UsersService usersService; |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testGetCodeAndVersion() throws CodeGenerateUtils.CodeGenerateException { |
|
|
|
public void testGetCodeAndVersion() throws CodeGenerateUtils.CodeGenerateException { |
|
|
|
Project project = getTestProject(); |
|
|
|
Project project = getTestProject(); |
|
|
@ -83,6 +96,37 @@ public class PythonGatewayTest { |
|
|
|
Assert.assertEquals((long) result.get("taskDefinitionCode"), taskDefinition.getCode()); |
|
|
|
Assert.assertEquals((long) result.get("taskDefinitionCode"), taskDefinition.getCode()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void testQueryResourcesFileInfo() { |
|
|
|
|
|
|
|
User user = getTestUser(); |
|
|
|
|
|
|
|
Mockito.when(usersService.queryUser(user.getUserName())).thenReturn(user); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Result<Object> mockResult = new Result<>(); |
|
|
|
|
|
|
|
mockResult.setCode(Status.SUCCESS.getCode()); |
|
|
|
|
|
|
|
Resource resource = getTestResource(); |
|
|
|
|
|
|
|
mockResult.setData(resource); |
|
|
|
|
|
|
|
Mockito.when(resourcesService.queryResource(user, resource.getFullName(), null, ResourceType.FILE)).thenReturn(mockResult); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> result = pythonGateway.queryResourcesFileInfo(user.getUserName(), resource.getFullName()); |
|
|
|
|
|
|
|
Assert.assertEquals((int) result.get("id"), resource.getId()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Resource getTestResource() { |
|
|
|
|
|
|
|
Resource resource = new Resource(); |
|
|
|
|
|
|
|
resource.setId(1); |
|
|
|
|
|
|
|
resource.setType(ResourceType.FILE); |
|
|
|
|
|
|
|
resource.setFullName("/dev/test.py"); |
|
|
|
|
|
|
|
return resource; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private User getTestUser() { |
|
|
|
|
|
|
|
User user = new User(); |
|
|
|
|
|
|
|
user.setId(1); |
|
|
|
|
|
|
|
user.setUserName("ut-user"); |
|
|
|
|
|
|
|
return user; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Project getTestProject() { |
|
|
|
private Project getTestProject() { |
|
|
|
Project project = new Project(); |
|
|
|
Project project = new Project(); |
|
|
|
project.setName("ut-project"); |
|
|
|
project.setName("ut-project"); |
|
|
|