feat(接口定义): 另存新用例 TAG问题修复

This commit is contained in:
fit2-zhao 2021-01-20 14:53:34 +08:00
parent 0070123bef
commit 91ded7f5ba
4 changed files with 47 additions and 40 deletions

View File

@ -8,7 +8,7 @@ import org.apache.commons.lang3.StringUtils;
@Data @Data
public class MsExtractCommon extends MsExtractType{ public class MsExtractCommon extends MsExtractType{
private String variable; private String variable;
private String value; // value: ${variable} private String value;
private String expression; private String expression;
private String description; private String description;
private boolean multipleMatching; private boolean multipleMatching;

View File

@ -417,19 +417,34 @@ public class ApiTestCaseService {
List<ApiTestCaseWithBLOBs> bloBs = apiTestCaseMapper.selectByExampleWithBLOBs(apiDefinitionExample); List<ApiTestCaseWithBLOBs> bloBs = apiTestCaseMapper.selectByExampleWithBLOBs(apiDefinitionExample);
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
ApiTestCaseMapper batchMapper = sqlSession.getMapper(ApiTestCaseMapper.class); ApiTestCaseMapper batchMapper = sqlSession.getMapper(ApiTestCaseMapper.class);
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
bloBs.forEach(apiTestCase -> { bloBs.forEach(apiTestCase -> {
MsHTTPSamplerProxy req = JSON.parseObject(apiTestCase.getRequest(), MsHTTPSamplerProxy.class); MsHTTPSamplerProxy req = JSON.parseObject(apiTestCase.getRequest(), MsHTTPSamplerProxy.class);
try {
JSONObject element = JSON.parseObject(apiTestCase.getRequest());
if (element != null && StringUtils.isNotEmpty(element.getString("hashTree"))) {
LinkedList<MsTestElement> elements = mapper.readValue(element.getString("hashTree"), new TypeReference<LinkedList<MsTestElement>>() {
});
req.setHashTree(elements);
}
if (StringUtils.isNotEmpty(request.getMethod())) { if (StringUtils.isNotEmpty(request.getMethod())) {
req.setMethod(request.getMethod()); req.setMethod(request.getMethod());
} }
if (StringUtils.isNotEmpty(request.getPath())) { if (StringUtils.isNotEmpty(request.getPath())) {
req.setPath(request.getPath()); req.setPath(request.getPath());
} }
} catch (Exception e) {
e.printStackTrace();
LogUtil.error(e.getMessage());
}
String requestStr = JSON.toJSONString(req); String requestStr = JSON.toJSONString(req);
apiTestCase.setRequest(requestStr); apiTestCase.setRequest(requestStr);
batchMapper.updateByPrimaryKeySelective(apiTestCase); batchMapper.updateByPrimaryKeySelective(apiTestCase);
}); });
sqlSession.flushStatements(); sqlSession.flushStatements();
} }
} }

View File

@ -86,7 +86,7 @@
singleLoading: false, singleLoading: false,
singleRunId: "", singleRunId: "",
runData: [], runData: [],
batchData: [], selectdCases: [],
reportId: "", reportId: "",
projectId: "", projectId: "",
testCaseId: "", testCaseId: "",
@ -128,8 +128,6 @@
this.projectId = getCurrentProjectID(); this.projectId = getCurrentProjectID();
if (this.createCase) { if (this.createCase) {
this.sysAddition(); this.sysAddition();
} else {
this.getApiTest();
} }
}, },
computed: { computed: {
@ -153,11 +151,19 @@
this.condition.projectId = this.projectId; this.condition.projectId = this.projectId;
this.condition.apiDefinitionId = this.api.id; this.condition.apiDefinitionId = this.api.id;
this.$post("/api/testcase/list", this.condition, response => { this.$post("/api/testcase/list", this.condition, response => {
for (let index in response.data) {
let test = response.data[index];
test.request = JSON.parse(test.request);
}
this.apiCaseList = response.data; this.apiCaseList = response.data;
this.apiCaseList.forEach(apiCase => {
if (apiCase.tags && apiCase.tags.length > 0) {
apiCase.tags = JSON.parse(apiCase.tags);
this.$set(apiCase, 'selected', false);
}
if (Object.prototype.toString.call(apiCase.request).match(/\[object (\w+)\]/)[1].toLowerCase() != 'object') {
apiCase.request = JSON.parse(apiCase.request);
}
if (!apiCase.request.hashTree) {
apiCase.request.hashTree = [];
}
})
this.addCase(); this.addCase();
}); });
}, },
@ -200,24 +206,22 @@
this.condition.apiDefinitionId = this.api.id; this.condition.apiDefinitionId = this.api.id;
} }
this.result = this.$post("/api/testcase/list", this.condition, response => { this.result = this.$post("/api/testcase/list", this.condition, response => {
for (let index in response.data) {
let test = response.data[index];
test.request = JSON.parse(test.request);
if (!test.request.hashTree) {
test.request.hashTree = [];
}
}
this.apiCaseList = response.data; this.apiCaseList = response.data;
if (addCase && this.apiCaseList.length == 0 && !this.loaded) {
this.addCase();
}
this.apiCaseList.forEach(apiCase => { this.apiCaseList.forEach(apiCase => {
if (apiCase.tags && apiCase.tags.length > 0) { if (apiCase.tags && apiCase.tags.length > 0) {
apiCase.tags = JSON.parse(apiCase.tags); apiCase.tags = JSON.parse(apiCase.tags);
this.$set(apiCase, 'selected', false); this.$set(apiCase, 'selected', false);
} }
if (Object.prototype.toString.call(apiCase.request).match(/\[object (\w+)\]/)[1].toLowerCase() != 'object') {
apiCase.request = JSON.parse(apiCase.request);
}
if (!apiCase.request.hashTree) {
apiCase.request.hashTree = [];
}
}) })
if (addCase && this.apiCaseList.length == 0 && !this.loaded) {
this.addCase();
}
}); });
} }
}, },
@ -293,11 +297,11 @@
if (this.apiCaseList.length > 0) { if (this.apiCaseList.length > 0) {
this.apiCaseList.forEach(item => { this.apiCaseList.forEach(item => {
if (item.selected && item.id) { if (item.selected && item.id) {
this.batchData.push(item.id); this.selectdCases.push(item.id);
} }
}) })
} }
if (this.batchData.length == 0) { if (this.selectdCases.length == 0) {
this.$warning("请选择用例!"); this.$warning("请选择用例!");
return; return;
} }
@ -306,7 +310,7 @@
batchEdit(form) { batchEdit(form) {
let param = {}; let param = {};
param[form.type] = form.value; param[form.type] = form.value;
param.ids = this.batchData; param.ids = this.selectdCases;
param.projectId = getCurrentProjectID(); param.projectId = getCurrentProjectID();
if (this.api) { if (this.api) {
param.protocol = this.api.protocol; param.protocol = this.api.protocol;
@ -316,6 +320,7 @@
param = Object.assign(param, this.condition); param = Object.assign(param, this.condition);
this.$post('/api/testcase/batch/editByParam', param, () => { this.$post('/api/testcase/batch/editByParam', param, () => {
this.$success(this.$t('commons.save_success')); this.$success(this.$t('commons.save_success'));
this.selectdCases = [];
this.getApiTest(); this.getApiTest();
}); });
}, },

View File

@ -413,19 +413,6 @@
this.initTable(); this.initTable();
}); });
return; return;
// }
// this.$alert(this.$t('api_test.definition.request.delete_confirm') + ' ' + apiCase.name + " ", '', {
// confirmButtonText: this.$t('commons.confirm'),
// callback: (action) => {
// if (action === 'confirm') {
// let ids = [apiCase.id];
// this.$post('/api/testcase/removeToGc/', ids, () => {
// this.$success(this.$t('commons.delete_success'));
// this.initTable();
// });
// }
// }
// });
}, },
setEnvironment(data) { setEnvironment(data) {
this.environmentId = data.id; this.environmentId = data.id;