feat(接口测试): 提供实时查询公共脚本信息的接口
--bug=1046248 --user=陈建星 【项目设置】公共脚本修改,场景内引用脚步未同步更新 https://www.tapd.cn/55049933/s/1592053
This commit is contained in:
parent
78106dd94c
commit
234f41d052
|
@ -6,6 +6,7 @@ import io.metersphere.api.service.ApiExecuteService;
|
||||||
import io.metersphere.api.service.ApiTestService;
|
import io.metersphere.api.service.ApiTestService;
|
||||||
import io.metersphere.jmeter.mock.Mock;
|
import io.metersphere.jmeter.mock.Mock;
|
||||||
import io.metersphere.plugin.api.dto.ApiPluginSelectOption;
|
import io.metersphere.plugin.api.dto.ApiPluginSelectOption;
|
||||||
|
import io.metersphere.project.dto.CommonScriptInfo;
|
||||||
import io.metersphere.project.dto.customfunction.request.CustomFunctionRunRequest;
|
import io.metersphere.project.dto.customfunction.request.CustomFunctionRunRequest;
|
||||||
import io.metersphere.project.dto.environment.EnvironmentConfig;
|
import io.metersphere.project.dto.environment.EnvironmentConfig;
|
||||||
import io.metersphere.sdk.constants.PermissionConstants;
|
import io.metersphere.sdk.constants.PermissionConstants;
|
||||||
|
@ -151,4 +152,16 @@ public class ApiTestController {
|
||||||
}
|
}
|
||||||
apiTestService.download(path.asText(), response);
|
apiTestService.download(path.asText(), response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/common-script/{scriptId}")
|
||||||
|
@Operation(summary = "获取最新的公共脚本信息")
|
||||||
|
@RequiresPermissions(value = {
|
||||||
|
PermissionConstants.PROJECT_API_DEFINITION_READ,
|
||||||
|
PermissionConstants.PROJECT_API_DEFINITION_CASE_READ,
|
||||||
|
PermissionConstants.PROJECT_API_DEBUG_READ,
|
||||||
|
PermissionConstants.PROJECT_API_SCENARIO_READ
|
||||||
|
}, logical = Logical.OR)
|
||||||
|
public CommonScriptInfo getCommonScriptInfo(@PathVariable String scriptId) {
|
||||||
|
return apiTestService.getCommonScriptInfo(scriptId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,9 +7,13 @@ import io.metersphere.plugin.api.dto.ApiPluginOptionsRequest;
|
||||||
import io.metersphere.plugin.api.dto.ApiPluginSelectOption;
|
import io.metersphere.plugin.api.dto.ApiPluginSelectOption;
|
||||||
import io.metersphere.plugin.api.spi.AbstractApiPlugin;
|
import io.metersphere.plugin.api.spi.AbstractApiPlugin;
|
||||||
import io.metersphere.plugin.api.spi.AbstractProtocolPlugin;
|
import io.metersphere.plugin.api.spi.AbstractProtocolPlugin;
|
||||||
|
import io.metersphere.project.api.KeyValueParam;
|
||||||
|
import io.metersphere.project.dto.CommonScriptInfo;
|
||||||
|
import io.metersphere.project.dto.customfunction.CustomFunctionDTO;
|
||||||
import io.metersphere.project.dto.environment.EnvironmentConfig;
|
import io.metersphere.project.dto.environment.EnvironmentConfig;
|
||||||
import io.metersphere.project.mapper.ExtEnvironmentMapper;
|
import io.metersphere.project.mapper.ExtEnvironmentMapper;
|
||||||
import io.metersphere.project.mapper.ExtProjectMapper;
|
import io.metersphere.project.mapper.ExtProjectMapper;
|
||||||
|
import io.metersphere.project.service.CustomFunctionService;
|
||||||
import io.metersphere.project.service.EnvironmentService;
|
import io.metersphere.project.service.EnvironmentService;
|
||||||
import io.metersphere.project.service.ProjectApplicationService;
|
import io.metersphere.project.service.ProjectApplicationService;
|
||||||
import io.metersphere.sdk.constants.ProjectApplicationType;
|
import io.metersphere.sdk.constants.ProjectApplicationType;
|
||||||
|
@ -17,6 +21,7 @@ import io.metersphere.sdk.constants.StorageType;
|
||||||
import io.metersphere.sdk.domain.Environment;
|
import io.metersphere.sdk.domain.Environment;
|
||||||
import io.metersphere.sdk.file.FileRequest;
|
import io.metersphere.sdk.file.FileRequest;
|
||||||
import io.metersphere.sdk.util.BeanUtils;
|
import io.metersphere.sdk.util.BeanUtils;
|
||||||
|
import io.metersphere.sdk.util.JSON;
|
||||||
import io.metersphere.sdk.util.LogUtils;
|
import io.metersphere.sdk.util.LogUtils;
|
||||||
import io.metersphere.system.domain.TestResourcePool;
|
import io.metersphere.system.domain.TestResourcePool;
|
||||||
import io.metersphere.system.dto.ProtocolDTO;
|
import io.metersphere.system.dto.ProtocolDTO;
|
||||||
|
@ -59,6 +64,8 @@ public class ApiTestService {
|
||||||
private ProjectApplicationService projectApplicationService;
|
private ProjectApplicationService projectApplicationService;
|
||||||
@Resource
|
@Resource
|
||||||
private FileService fileService;
|
private FileService fileService;
|
||||||
|
@Resource
|
||||||
|
private CustomFunctionService customFunctionService;
|
||||||
|
|
||||||
public List<ProtocolDTO> getProtocols(String orgId) {
|
public List<ProtocolDTO> getProtocols(String orgId) {
|
||||||
List<ProtocolDTO> protocols = apiPluginService.getProtocols(orgId);
|
List<ProtocolDTO> protocols = apiPluginService.getProtocols(orgId);
|
||||||
|
@ -158,4 +165,20 @@ public class ApiTestService {
|
||||||
response.getOutputStream().write(content);
|
response.getOutputStream().write(content);
|
||||||
response.getOutputStream().flush();
|
response.getOutputStream().flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CommonScriptInfo getCommonScriptInfo(String scriptId) {
|
||||||
|
CustomFunctionDTO customFunctionDTO = customFunctionService.get(scriptId);
|
||||||
|
if (customFunctionDTO == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
CommonScriptInfo commonScriptInfo = new CommonScriptInfo();
|
||||||
|
commonScriptInfo.setScriptLanguage(customFunctionDTO.getType());
|
||||||
|
commonScriptInfo.setScript(customFunctionDTO.getScript());
|
||||||
|
commonScriptInfo.setName(customFunctionDTO.getName());
|
||||||
|
commonScriptInfo.setId(customFunctionDTO.getId());
|
||||||
|
if (StringUtils.isNotBlank(customFunctionDTO.getParams())) {
|
||||||
|
commonScriptInfo.setParams(JSON.parseArray(customFunctionDTO.getParams(), KeyValueParam.class));
|
||||||
|
}
|
||||||
|
return commonScriptInfo;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -6,11 +6,16 @@ import io.metersphere.api.service.BaseResourcePoolTestService;
|
||||||
import io.metersphere.plugin.api.dto.ApiPluginSelectOption;
|
import io.metersphere.plugin.api.dto.ApiPluginSelectOption;
|
||||||
import io.metersphere.project.api.KeyValueParam;
|
import io.metersphere.project.api.KeyValueParam;
|
||||||
import io.metersphere.project.constants.ScriptLanguageType;
|
import io.metersphere.project.constants.ScriptLanguageType;
|
||||||
|
import io.metersphere.project.domain.CustomFunction;
|
||||||
import io.metersphere.project.domain.ProjectTestResourcePool;
|
import io.metersphere.project.domain.ProjectTestResourcePool;
|
||||||
import io.metersphere.project.domain.ProjectTestResourcePoolExample;
|
import io.metersphere.project.domain.ProjectTestResourcePoolExample;
|
||||||
|
import io.metersphere.project.dto.CommonScriptInfo;
|
||||||
|
import io.metersphere.project.dto.customfunction.request.CustomFunctionRequest;
|
||||||
import io.metersphere.project.dto.customfunction.request.CustomFunctionRunRequest;
|
import io.metersphere.project.dto.customfunction.request.CustomFunctionRunRequest;
|
||||||
import io.metersphere.project.dto.environment.EnvironmentConfig;
|
import io.metersphere.project.dto.environment.EnvironmentConfig;
|
||||||
import io.metersphere.project.mapper.ProjectTestResourcePoolMapper;
|
import io.metersphere.project.mapper.ProjectTestResourcePoolMapper;
|
||||||
|
import io.metersphere.project.service.CustomFunctionService;
|
||||||
|
import io.metersphere.sdk.constants.InternalUser;
|
||||||
import io.metersphere.sdk.constants.PermissionConstants;
|
import io.metersphere.sdk.constants.PermissionConstants;
|
||||||
import io.metersphere.sdk.constants.SessionConstants;
|
import io.metersphere.sdk.constants.SessionConstants;
|
||||||
import io.metersphere.sdk.domain.Environment;
|
import io.metersphere.sdk.domain.Environment;
|
||||||
|
@ -35,6 +40,7 @@ import java.io.FileInputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import static io.metersphere.sdk.constants.InternalUserRole.ADMIN;
|
import static io.metersphere.sdk.constants.InternalUserRole.ADMIN;
|
||||||
import static io.metersphere.system.controller.handler.result.MsHttpResultCode.NOT_FOUND;
|
import static io.metersphere.system.controller.handler.result.MsHttpResultCode.NOT_FOUND;
|
||||||
|
@ -58,6 +64,7 @@ public class ApiTestControllerTests extends BaseTest {
|
||||||
protected static final String PLUGIN_SCRIPT = "plugin/script/{0}";
|
protected static final String PLUGIN_SCRIPT = "plugin/script/{0}";
|
||||||
protected static final String ENV_LIST = "env-list/{0}";
|
protected static final String ENV_LIST = "env-list/{0}";
|
||||||
protected static final String ENVIRONMENT = "environment/{0}";
|
protected static final String ENVIRONMENT = "environment/{0}";
|
||||||
|
protected static final String COMMON_SCRIPT = "common-script/{scriptId}";
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private BaseResourcePoolTestService baseResourcePoolTestService;
|
private BaseResourcePoolTestService baseResourcePoolTestService;
|
||||||
|
@ -69,6 +76,8 @@ public class ApiTestControllerTests extends BaseTest {
|
||||||
private BaseEnvTestService baseEnvTestService;
|
private BaseEnvTestService baseEnvTestService;
|
||||||
@Resource
|
@Resource
|
||||||
private ProjectTestResourcePoolMapper projectTestResourcePoolMapper;
|
private ProjectTestResourcePoolMapper projectTestResourcePoolMapper;
|
||||||
|
@Resource
|
||||||
|
private CustomFunctionService customFunctionService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getBasePath() {
|
protected String getBasePath() {
|
||||||
|
@ -227,6 +236,35 @@ public class ApiTestControllerTests extends BaseTest {
|
||||||
Assertions.assertNull(environmentConfig.getAssertionConfig());
|
Assertions.assertNull(environmentConfig.getAssertionConfig());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getCommonScriptInfo() throws Exception {
|
||||||
|
MvcResult mvcResult = this.requestGetAndReturn(COMMON_SCRIPT, "111");
|
||||||
|
Assertions.assertNull(parseResponse(mvcResult).get("data"));
|
||||||
|
|
||||||
|
// 创建测试数据
|
||||||
|
CustomFunctionRequest request = new CustomFunctionRequest();
|
||||||
|
request.setProjectId(DEFAULT_PROJECT_ID);
|
||||||
|
request.setName(UUID.randomUUID().toString());
|
||||||
|
request.setStatus("UNDERWAY");
|
||||||
|
request.setScript("script");
|
||||||
|
// 执行方法调用
|
||||||
|
request.setName(UUID.randomUUID().toString());
|
||||||
|
CustomFunction customFunction = customFunctionService.add(request, InternalUser.ADMIN.getValue());
|
||||||
|
mvcResult = this.requestGetAndReturn(COMMON_SCRIPT, customFunction.getId());
|
||||||
|
CommonScriptInfo resultData = getResultData(mvcResult, CommonScriptInfo.class);
|
||||||
|
|
||||||
|
Assertions.assertEquals(resultData.getScript(), request.getScript());
|
||||||
|
Assertions.assertEquals(resultData.getName(), request.getName());
|
||||||
|
|
||||||
|
// @@校验权限
|
||||||
|
requestGetPermissionsTest(new ArrayList<>() {{
|
||||||
|
add(PermissionConstants.PROJECT_API_DEFINITION_READ);
|
||||||
|
add(PermissionConstants.PROJECT_API_DEFINITION_CASE_READ);
|
||||||
|
add(PermissionConstants.PROJECT_API_DEBUG_READ);
|
||||||
|
add(PermissionConstants.PROJECT_API_SCENARIO_READ);
|
||||||
|
}}, COMMON_SCRIPT, "11");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getPoolOption() throws Exception {
|
public void getPoolOption() throws Exception {
|
||||||
// @@请求成功
|
// @@请求成功
|
||||||
|
|
|
@ -65,7 +65,7 @@ public class CustomFunctionController {
|
||||||
@RequiresPermissions(PermissionConstants.PROJECT_CUSTOM_FUNCTION_READ)
|
@RequiresPermissions(PermissionConstants.PROJECT_CUSTOM_FUNCTION_READ)
|
||||||
@CheckOwner(resourceId = "#id", resourceType = "custom_function")
|
@CheckOwner(resourceId = "#id", resourceType = "custom_function")
|
||||||
public CustomFunctionDTO get(@PathVariable String id) {
|
public CustomFunctionDTO get(@PathVariable String id) {
|
||||||
return customFunctionService.get(id);
|
return customFunctionService.getWithCheck(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/add")
|
@PostMapping("/add")
|
||||||
|
|
|
@ -83,7 +83,7 @@ public class CustomFunctionService {
|
||||||
list.forEach(item -> handleCustomFunctionBlob(item.getId(), item));
|
list.forEach(item -> handleCustomFunctionBlob(item.getId(), item));
|
||||||
}
|
}
|
||||||
|
|
||||||
public CustomFunctionDTO get(String id) {
|
public CustomFunctionDTO getWithCheck(String id) {
|
||||||
CustomFunction customFunction = checkCustomFunction(id);
|
CustomFunction customFunction = checkCustomFunction(id);
|
||||||
CustomFunctionDTO customFunctionDTO = new CustomFunctionDTO();
|
CustomFunctionDTO customFunctionDTO = new CustomFunctionDTO();
|
||||||
handleCustomFunctionBlob(id, customFunctionDTO);
|
handleCustomFunctionBlob(id, customFunctionDTO);
|
||||||
|
@ -91,6 +91,17 @@ public class CustomFunctionService {
|
||||||
return customFunctionDTO;
|
return customFunctionDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CustomFunctionDTO get(String id) {
|
||||||
|
CustomFunction customFunction = customFunctionMapper.selectByPrimaryKey(id);
|
||||||
|
if (customFunction == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
CustomFunctionDTO customFunctionDTO = new CustomFunctionDTO();
|
||||||
|
handleCustomFunctionBlob(id, customFunctionDTO);
|
||||||
|
BeanUtils.copyBean(customFunctionDTO, customFunction);
|
||||||
|
return customFunctionDTO;
|
||||||
|
}
|
||||||
|
|
||||||
public void handleCustomFunctionBlob(String id, CustomFunctionDTO customFunctionDTO) {
|
public void handleCustomFunctionBlob(String id, CustomFunctionDTO customFunctionDTO) {
|
||||||
Optional<CustomFunctionBlob> customFunctionBlobOptional = Optional.ofNullable(customFunctionBlobMapper.selectByPrimaryKey(id));
|
Optional<CustomFunctionBlob> customFunctionBlobOptional = Optional.ofNullable(customFunctionBlobMapper.selectByPrimaryKey(id));
|
||||||
customFunctionBlobOptional.ifPresent(blob -> {
|
customFunctionBlobOptional.ifPresent(blob -> {
|
||||||
|
|
Loading…
Reference in New Issue