fix(接口测试): 接口导入数据解析错误问题修复
--bug=1017815 --user=赵勇 【接口测试】接口自动化-导入场景报错 https://www.tapd.cn/55049933/s/1258533
This commit is contained in:
parent
de1bbdd03c
commit
f8d25edef4
|
@ -37,7 +37,7 @@ public class MsDefinitionParser extends MsAbstractParser<ApiDefinitionImport> {
|
||||||
if (this.projectId == null) {
|
if (this.projectId == null) {
|
||||||
MSException.throwException("wrong format");
|
MSException.throwException("wrong format");
|
||||||
}
|
}
|
||||||
if (testObject.get("projectName") != null || testObject.get("projectId") != null) {// metersphere 格式导入
|
if (testObject.opt("projectName") != null || testObject.opt("projectId") != null) {// metersphere 格式导入
|
||||||
return parseMsFormat(testStr, request);
|
return parseMsFormat(testStr, request);
|
||||||
} else { // chrome 插件录制格式导入
|
} else { // chrome 插件录制格式导入
|
||||||
request.setPlatform(ApiImportPlatform.Plugin.name());
|
request.setPlatform(ApiImportPlatform.Plugin.name());
|
||||||
|
|
|
@ -52,8 +52,6 @@ public class ApiDefinitionController {
|
||||||
@Resource
|
@Resource
|
||||||
private ApiDefinitionService apiDefinitionService;
|
private ApiDefinitionService apiDefinitionService;
|
||||||
@Resource
|
@Resource
|
||||||
private ApiTestCaseService apiTestCaseService;
|
|
||||||
@Resource
|
|
||||||
private EsbApiParamService esbApiParamService;
|
private EsbApiParamService esbApiParamService;
|
||||||
@Resource
|
@Resource
|
||||||
private EsbImportService esbImportService;
|
private EsbImportService esbImportService;
|
||||||
|
@ -67,12 +65,6 @@ public class ApiDefinitionController {
|
||||||
@PostMapping("/list/{goPage}/{pageSize}")
|
@PostMapping("/list/{goPage}/{pageSize}")
|
||||||
@RequiresPermissions("PROJECT_API_DEFINITION:READ")
|
@RequiresPermissions("PROJECT_API_DEFINITION:READ")
|
||||||
public Pager<List<ApiDefinitionResult>> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiDefinitionRequest request) {
|
public Pager<List<ApiDefinitionResult>> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiDefinitionRequest request) {
|
||||||
if (request.getToBeUpdated() != null && request.getToBeUpdated()) {
|
|
||||||
Long toBeUpdatedTime = apiTestCaseService.getToBeUpdatedTime(request.getProjectId());
|
|
||||||
if (toBeUpdatedTime != null) {
|
|
||||||
request.setToBeUpdateTime(toBeUpdatedTime);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
apiDefinitionService.checkFilterHasCoverage(request);
|
apiDefinitionService.checkFilterHasCoverage(request);
|
||||||
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
|
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
|
||||||
return PageUtils.setPageInfo(page, apiDefinitionService.list(request));
|
return PageUtils.setPageInfo(page, apiDefinitionService.list(request));
|
||||||
|
|
|
@ -16,6 +16,8 @@ import org.apache.commons.lang3.StringUtils;
|
||||||
import org.python.core.Options;
|
import org.python.core.Options;
|
||||||
import org.python.util.PythonInterpreter;
|
import org.python.util.PythonInterpreter;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.boot.ApplicationArguments;
|
||||||
|
import org.springframework.boot.ApplicationRunner;
|
||||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||||
import org.springframework.context.ApplicationListener;
|
import org.springframework.context.ApplicationListener;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
@ -23,7 +25,7 @@ import org.springframework.stereotype.Component;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class ApiAppStartListener implements ApplicationListener<ApplicationReadyEvent> {
|
public class ApiAppStartListener implements ApplicationRunner {
|
||||||
@Resource
|
@Resource
|
||||||
private BaseScheduleService scheduleService;
|
private BaseScheduleService scheduleService;
|
||||||
@Resource
|
@Resource
|
||||||
|
@ -49,7 +51,7 @@ public class ApiAppStartListener implements ApplicationListener<ApplicationReady
|
||||||
private int quartzThreadCount;
|
private int quartzThreadCount;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
|
public void run(ApplicationArguments args) throws Exception {
|
||||||
LogUtil.info("================= API 应用启动 =================");
|
LogUtil.info("================= API 应用启动 =================");
|
||||||
System.setProperty("jmeter.home", jmeterHome);
|
System.setProperty("jmeter.home", jmeterHome);
|
||||||
|
|
||||||
|
@ -69,7 +71,10 @@ public class ApiAppStartListener implements ApplicationListener<ApplicationReady
|
||||||
initPythonEnv();
|
initPythonEnv();
|
||||||
|
|
||||||
//检查状态为开启的TCP-Mock服务端口
|
//检查状态为开启的TCP-Mock服务端口
|
||||||
|
LogUtil.info("starting check mock ");
|
||||||
mockConfigService.initMockTcpService();
|
mockConfigService.initMockTcpService();
|
||||||
|
|
||||||
|
LogUtil.info("starting quartz");
|
||||||
StringBuffer buffer = new StringBuffer("定时任务相关设置:");
|
StringBuffer buffer = new StringBuffer("定时任务相关设置:");
|
||||||
buffer.append("quartz.acquireTriggersWithinLock :")
|
buffer.append("quartz.acquireTriggersWithinLock :")
|
||||||
.append(acquireTriggersWithinLock).append("\n")
|
.append(acquireTriggersWithinLock).append("\n")
|
||||||
|
@ -83,6 +88,7 @@ public class ApiAppStartListener implements ApplicationListener<ApplicationReady
|
||||||
LogUtil.info(buffer.toString());
|
LogUtil.info(buffer.toString());
|
||||||
scheduleService.startEnableSchedules(ScheduleGroup.API_SCENARIO_TEST);
|
scheduleService.startEnableSchedules(ScheduleGroup.API_SCENARIO_TEST);
|
||||||
scheduleService.startEnableSchedules(ScheduleGroup.SWAGGER_IMPORT);
|
scheduleService.startEnableSchedules(ScheduleGroup.SWAGGER_IMPORT);
|
||||||
|
LogUtil.info("Startup complete");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -172,6 +172,13 @@ public class ApiDefinitionService {
|
||||||
private static final String SCHEDULE = "schedule";
|
private static final String SCHEDULE = "schedule";
|
||||||
|
|
||||||
public List<ApiDefinitionResult> list(ApiDefinitionRequest request) {
|
public List<ApiDefinitionResult> list(ApiDefinitionRequest request) {
|
||||||
|
// 来自工作台条件
|
||||||
|
if (BooleanUtils.isTrue(request.getToBeUpdated())) {
|
||||||
|
Long toBeUpdatedTime = apiTestCaseService.getToBeUpdatedTime(request.getProjectId());
|
||||||
|
if (toBeUpdatedTime != null) {
|
||||||
|
request.setToBeUpdateTime(toBeUpdatedTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
request = this.initRequest(request, true, true);
|
request = this.initRequest(request, true, true);
|
||||||
List<ApiDefinitionResult> resList = extApiDefinitionMapper.list(request);
|
List<ApiDefinitionResult> resList = extApiDefinitionMapper.list(request);
|
||||||
buildUserInfo(resList);
|
buildUserInfo(resList);
|
||||||
|
@ -1427,7 +1434,7 @@ public class ApiDefinitionService {
|
||||||
|
|
||||||
private boolean setImportHashTree(ApiDefinitionWithBLOBs apiDefinition) {
|
private boolean setImportHashTree(ApiDefinitionWithBLOBs apiDefinition) {
|
||||||
String request = apiDefinition.getRequest();
|
String request = apiDefinition.getRequest();
|
||||||
MsHTTPSamplerProxy msHTTPSamplerProxy = JSON.parseObject(request, MsHTTPSamplerProxy.class);
|
MsHTTPSamplerProxy msHTTPSamplerProxy = JSONUtil.parseObject(request, MsHTTPSamplerProxy.class);
|
||||||
boolean createCase = CollectionUtils.isNotEmpty(msHTTPSamplerProxy.getHeaders());
|
boolean createCase = CollectionUtils.isNotEmpty(msHTTPSamplerProxy.getHeaders());
|
||||||
if (CollectionUtils.isNotEmpty(msHTTPSamplerProxy.getArguments()) && !createCase) {
|
if (CollectionUtils.isNotEmpty(msHTTPSamplerProxy.getArguments()) && !createCase) {
|
||||||
createCase = true;
|
createCase = true;
|
||||||
|
@ -2209,15 +2216,15 @@ public class ApiDefinitionService {
|
||||||
return extApiDefinitionMapper.selectEffectiveIdByProjectIdAndHaveNotCase(projectId);
|
return extApiDefinitionMapper.selectEffectiveIdByProjectIdAndHaveNotCase(projectId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ApiDefinitionWithBLOBs> preparedUrl(String projectId, String method, String baseUrlSuffix,String mockApiResourceId) {
|
public List<ApiDefinitionWithBLOBs> preparedUrl(String projectId, String method, String baseUrlSuffix, String mockApiResourceId) {
|
||||||
if (StringUtils.isEmpty(baseUrlSuffix)) {
|
if (StringUtils.isEmpty(baseUrlSuffix)) {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
} else {
|
} else {
|
||||||
String apiId = this.getApiIdFromMockApiResourceId(mockApiResourceId,projectId);
|
String apiId = this.getApiIdFromMockApiResourceId(mockApiResourceId, projectId);
|
||||||
ApiDefinitionExample example = new ApiDefinitionExample();
|
ApiDefinitionExample example = new ApiDefinitionExample();
|
||||||
ApiDefinitionExample.Criteria criteria = example.createCriteria();
|
ApiDefinitionExample.Criteria criteria = example.createCriteria();
|
||||||
criteria.andMethodEqualTo(method).andProjectIdEqualTo(projectId).andStatusNotEqualTo("Trash").andProtocolEqualTo("HTTP").andLatestEqualTo(true);
|
criteria.andMethodEqualTo(method).andProjectIdEqualTo(projectId).andStatusNotEqualTo("Trash").andProtocolEqualTo("HTTP").andLatestEqualTo(true);
|
||||||
if(StringUtils.isNotBlank(apiId)){
|
if (StringUtils.isNotBlank(apiId)) {
|
||||||
criteria.andIdEqualTo(apiId);
|
criteria.andIdEqualTo(apiId);
|
||||||
}
|
}
|
||||||
List<ApiDefinition> apiList = apiDefinitionMapper.selectByExample(example);
|
List<ApiDefinition> apiList = apiDefinitionMapper.selectByExample(example);
|
||||||
|
@ -2274,19 +2281,19 @@ public class ApiDefinitionService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getApiIdFromMockApiResourceId(String mockApiResourceId,String projectId) {
|
private String getApiIdFromMockApiResourceId(String mockApiResourceId, String projectId) {
|
||||||
String returnId = null;
|
String returnId = null;
|
||||||
ApiDefinition apiDefinition = this.get(mockApiResourceId);
|
ApiDefinition apiDefinition = this.get(mockApiResourceId);
|
||||||
if(apiDefinition == null){
|
if (apiDefinition == null) {
|
||||||
ApiTestCase testCase = apiTestCaseMapper.selectByPrimaryKey(mockApiResourceId);
|
ApiTestCase testCase = apiTestCaseMapper.selectByPrimaryKey(mockApiResourceId);
|
||||||
if(testCase != null){
|
if (testCase != null) {
|
||||||
if(StringUtils.equals(testCase.getProjectId(),projectId) && !StringUtils.equals(testCase.getStatus(),"Trash")){
|
if (StringUtils.equals(testCase.getProjectId(), projectId) && !StringUtils.equals(testCase.getStatus(), "Trash")) {
|
||||||
returnId = testCase.getApiDefinitionId();
|
returnId = testCase.getApiDefinitionId();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else {
|
} else {
|
||||||
if(StringUtils.equals(apiDefinition.getProjectId(),projectId) && !StringUtils.equals(apiDefinition.getStatus(),"Trash") && apiDefinition.getLatest()){
|
if (StringUtils.equals(apiDefinition.getProjectId(), projectId) && !StringUtils.equals(apiDefinition.getStatus(), "Trash") && apiDefinition.getLatest()) {
|
||||||
returnId = mockApiResourceId;
|
returnId = mockApiResourceId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return returnId;
|
return returnId;
|
||||||
|
|
|
@ -250,7 +250,7 @@
|
||||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||||
<level>INFO</level>
|
<level>INFO</level>
|
||||||
</filter>
|
</filter>
|
||||||
<File>${logging.file.path}/ms-jmeter-run-log.log</File>
|
<File>${logging.file.path}/ms-jmeter-run.log</File>
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
<FileNamePattern>${logging.file.path}/history/ms-jmeter-run-log.%d{yyyyMMdd}-%i.log
|
<FileNamePattern>${logging.file.path}/history/ms-jmeter-run-log.%d{yyyyMMdd}-%i.log
|
||||||
</FileNamePattern>
|
</FileNamePattern>
|
||||||
|
|
|
@ -748,6 +748,7 @@ export default {
|
||||||
this.apiDefaultTab = activeName
|
this.apiDefaultTab = activeName
|
||||||
this.apiTabs = tabs.filter(tab => tab.name !== targetName);
|
this.apiTabs = tabs.filter(tab => tab.name !== targetName);
|
||||||
this.$refs.mainTabs.$children = [];
|
this.$refs.mainTabs.$children = [];
|
||||||
|
this.$refs.apiDefList[0].refreshTable();
|
||||||
},
|
},
|
||||||
//创建左侧树的根目录模块
|
//创建左侧树的根目录模块
|
||||||
createRootModel() {
|
createRootModel() {
|
||||||
|
|
|
@ -175,8 +175,12 @@ export default {
|
||||||
}
|
}
|
||||||
|
|
||||||
:deep(.el-icon-close:hover) {
|
:deep(.el-icon-close:hover) {
|
||||||
font-size: 30px;
|
font-size: 18px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
:deep(.fulls-screen-btn) {
|
||||||
|
position: fixed !important;
|
||||||
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -491,7 +491,7 @@ export default {
|
||||||
},
|
},
|
||||||
singleRun(data) {
|
singleRun(data) {
|
||||||
let methods = ["SQL", "DUBBO", "dubbo://", "TCP"];
|
let methods = ["SQL", "DUBBO", "dubbo://", "TCP"];
|
||||||
if (data.apiMethod && methods.indexOf(data.apiMethod) === -1 && !this.environment) {
|
if (data.apiMethod && methods.indexOf(data.apiMethod) === -1 && this.environment === undefined) {
|
||||||
this.$warning(this.$t('api_test.environment.select_environment'));
|
this.$warning(this.$t('api_test.environment.select_environment'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -573,7 +573,7 @@ export default {
|
||||||
},
|
},
|
||||||
singleRun(row) {
|
singleRun(row) {
|
||||||
let methods = ["SQL", "DUBBO", "dubbo://", "TCP"];
|
let methods = ["SQL", "DUBBO", "dubbo://", "TCP"];
|
||||||
if (row.apiMethod && methods.indexOf(row.apiMethod) === -1 && !this.environment) {
|
if (row.apiMethod && methods.indexOf(row.apiMethod) === -1 && this.environment === undefined) {
|
||||||
this.$warning(this.$t('api_test.environment.select_environment'));
|
this.$warning(this.$t('api_test.environment.select_environment'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -746,6 +746,20 @@ export default {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
refreshTable() {
|
||||||
|
this.initTableCondition();
|
||||||
|
if (this.condition.projectId) {
|
||||||
|
this.result = getDefinitionPage(this.currentPage, this.pageSize, this.condition).then(response => {
|
||||||
|
getProtocolFilter(this.condition.protocol);
|
||||||
|
this.total = response.data.itemCount;
|
||||||
|
this.tableData = response.data.listObject;
|
||||||
|
this.historyData();
|
||||||
|
if (this.$refs.table) {
|
||||||
|
this.$refs.table.clearSelection();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
initTable(currentProtocol) {
|
initTable(currentProtocol) {
|
||||||
this.initTableCondition(currentProtocol);
|
this.initTableCondition(currentProtocol);
|
||||||
if (this.condition.projectId) {
|
if (this.condition.projectId) {
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
package io.metersphere.commons.utils;
|
package io.metersphere.commons.utils;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||||
|
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.JavaType;
|
import com.fasterxml.jackson.databind.JavaType;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||||
import com.fasterxml.jackson.databind.type.CollectionType;
|
import com.fasterxml.jackson.databind.type.CollectionType;
|
||||||
import com.fasterxml.jackson.databind.type.TypeFactory;
|
import com.fasterxml.jackson.databind.type.TypeFactory;
|
||||||
|
|
||||||
|
@ -19,6 +22,10 @@ public class JSON {
|
||||||
|
|
||||||
static {
|
static {
|
||||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
// 自动检测所有类的全部属性
|
||||||
|
objectMapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
|
||||||
|
// 如果一个对象中没有任何的属性,那么在序列化的时候就会报错
|
||||||
|
objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String toJSONString(Object value) {
|
public static String toJSONString(Object value) {
|
||||||
|
|
Loading…
Reference in New Issue