From 0899186dc653584a861e7b3ead62fdcd5bc7a481 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Sat, 22 Jan 2022 15:23:39 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E7=AC=A6=E5=90=88=E8=AF=AF=E6=8A=A5=E8=A6=81=E6=B1=82=E7=9A=84?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=A1=88=E4=BE=8B=E6=89=A7=E8=A1=8C=E6=97=B6?= =?UTF-8?q?=E5=B0=86=E7=8A=B6=E6=80=81=E7=A0=81=E7=9A=84=E9=A2=9C=E8=89=B2?= =?UTF-8?q?=E4=B8=8E=E8=AF=AF=E6=8A=A5=E9=A2=9C=E8=89=B2=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E5=8C=B9=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1009864 --user=宋天阳 【误报库】接口执行结果为误报时,状态码颜色不对 https://www.tapd.cn/55049933/s/1096230 --- .../ApiDefinitionExecResultService.java | 9 ++- .../api/service/ShareInfoService.java | 56 ++++++++++--------- .../components/response/RequestMetric.vue | 6 +- .../comonents/api/TestPlanApiCaseList.vue | 5 +- .../comonents/api/TestPlanApiScenarioList.vue | 2 +- 5 files changed, 43 insertions(+), 35 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java index b21c61aab2..db75119473 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionExecResultService.java @@ -211,13 +211,14 @@ public class ApiDefinitionExecResultService { for (RequestResult item : requestResults) { if (!StringUtils.startsWithAny(item.getName(), "PRE_PROCESSOR_ENV_", "POST_PROCESSOR_ENV_")) { + //对响应内容进行进一步解析。如果有附加信息(比如误报库信息),则根据附加信息内的数据进行其他判读 + RequestResultExpandDTO expandDTO = ResponseUtil.parseByRequestResult(item); + ApiDefinitionExecResult reportResult = this.save(item, dto.getReportId(), dto.getConsole(), countExpectProcessResultCount, dto.getRunMode(), dto.getTestId(), isFirst); String status = item.isSuccess() ? "success" : "error"; if (reportResult != null) { status = reportResult.getStatus(); } - //对响应内容进行进一步解析。如果有附加信息(比如误报库信息),则根据附加信息内的数据进行其他判读 - RequestResultExpandDTO expandDTO = ResponseUtil.parseByRequestResult(item); if (MapUtils.isNotEmpty(expandDTO.getAttachInfoMap())) { status = expandDTO.getStatus(); } @@ -345,11 +346,9 @@ public class ApiDefinitionExecResultService { if (StringUtils.isEmpty(saveResult.getActuator())) { saveResult.setActuator("LOCAL"); } - - String status = item.isSuccess() ? ExecuteResult.success.name() : ExecuteResult.error.name(); - //对响应内容进行进一步解析。如果有附加信息(比如误报库信息),则根据附加信息内的数据进行其他判读 RequestResultExpandDTO expandDTO = ResponseUtil.parseByRequestResult(item); + String status = item.isSuccess() ? ExecuteResult.success.name() : ExecuteResult.error.name(); if (MapUtils.isNotEmpty(expandDTO.getAttachInfoMap())) { status = expandDTO.getStatus(); saveResult.setContent(JSON.toJSONString(expandDTO)); diff --git a/backend/src/main/java/io/metersphere/api/service/ShareInfoService.java b/backend/src/main/java/io/metersphere/api/service/ShareInfoService.java index 0e7921ed98..7c876d290f 100644 --- a/backend/src/main/java/io/metersphere/api/service/ShareInfoService.java +++ b/backend/src/main/java/io/metersphere/api/service/ShareInfoService.java @@ -50,9 +50,9 @@ public class ShareInfoService { if (request.getProjectId() == null) { List shareIdList = this.selectShareIdByShareInfoId(request.getShareId()); request.setApiIdList(shareIdList); - if(shareIdList.isEmpty()){ + if (shareIdList.isEmpty()) { return new ArrayList<>(); - }else { + } else { return extShareInfoMapper.findApiDocumentSimpleInfoByRequest(request); } } else { @@ -100,14 +100,14 @@ public class ShareInfoService { if (apiModel.getRequest() != null) { JSONObject requestObj = this.genJSONObject(apiModel.getRequest()); - if(requestObj!=null){ + if (requestObj != null) { if (requestObj.containsKey("headers")) { JSONArray requestHeadDataArr = new JSONArray(); //head赋值 JSONArray headArr = requestObj.getJSONArray("headers"); for (int index = 0; index < headArr.size(); index++) { JSONObject headObj = headArr.getJSONObject(index); - if (headObj.containsKey("name") && headObj.containsKey("value")) { + if (headObj != null && headObj.containsKey("name") && headObj.containsKey("value")) { requestHeadDataArr.add(headObj); } } @@ -116,20 +116,20 @@ public class ShareInfoService { //url参数赋值 JSONArray urlParamArr = new JSONArray(); if (requestObj.containsKey("arguments")) { - try{ + try { JSONArray headArr = requestObj.getJSONArray("arguments"); for (int index = 0; index < headArr.size(); index++) { - JSONObject headObj = headArr.getJSONObject(index); - if (headObj.containsKey("name") && headObj.containsKey("value")) { - urlParamArr.add(headObj); - } + JSONObject headObj = headArr.getJSONObject(index); + if (headObj.containsKey("name") && headObj.containsKey("value")) { + urlParamArr.add(headObj); + } } - }catch (Exception e){ + } catch (Exception e) { } } if (requestObj.containsKey("rest")) { - try{ + try { //urlParam -- rest赋值 JSONArray headArr = requestObj.getJSONArray("rest"); for (int index = 0; index < headArr.size(); index++) { @@ -138,13 +138,13 @@ public class ShareInfoService { urlParamArr.add(headObj); } } - }catch (Exception e){ + } catch (Exception e) { } } apiInfoDTO.setUrlParams(urlParamArr.toJSONString()); //请求体参数类型 if (requestObj.containsKey("body")) { - try{ + try { JSONObject bodyObj = requestObj.getJSONObject("body"); if (bodyObj.containsKey("type")) { String type = bodyObj.getString("type"); @@ -168,7 +168,7 @@ public class ShareInfoService { if (isJsonSchema) { apiInfoDTO.setRequestBodyParamType("JSON-SCHEMA"); apiInfoDTO.setJsonSchemaBody(bodyObj); - if(bodyObj.containsKey("jsonSchema")){ + if (bodyObj.containsKey("jsonSchema")) { JSONObject jsonSchemaObj = bodyObj.getJSONObject("jsonSchema"); apiInfoDTO.setRequestPreviewData(JSON.parse(JSONSchemaGenerator.getJson(jsonSchemaObj.toJSONString()))); } @@ -195,7 +195,7 @@ public class ShareInfoService { JSONObject kv = kvsArr.getJSONObject(i); if (kv.containsKey("name")) { String value = ""; - if(kv.containsKey("value")){ + if (kv.containsKey("value")) { value = String.valueOf(kv.get("value")); } bodyParamArr.add(kv); @@ -238,7 +238,7 @@ public class ShareInfoService { } } } - }catch (Exception e){ + } catch (Exception e) { } @@ -249,8 +249,8 @@ public class ShareInfoService { //赋值响应头 if (apiModel.getResponse() != null) { JSONObject responseJsonObj = this.genJSONObject(apiModel.getResponse()); - if (responseJsonObj!=null && responseJsonObj.containsKey("headers")) { - try{ + if (responseJsonObj != null && responseJsonObj.containsKey("headers")) { + try { JSONArray responseHeadDataArr = new JSONArray(); JSONArray headArr = responseJsonObj.getJSONArray("headers"); for (int index = 0; index < headArr.size(); index++) { @@ -260,12 +260,12 @@ public class ShareInfoService { } } apiInfoDTO.setResponseHead(responseHeadDataArr.toJSONString()); - }catch (Exception e){ + } catch (Exception e) { } } // 赋值响应体 - if (responseJsonObj!=null && responseJsonObj.containsKey("body")) { + if (responseJsonObj != null && responseJsonObj.containsKey("body")) { try { JSONObject bodyObj = responseJsonObj.getJSONObject("body"); if (bodyObj.containsKey("type")) { @@ -343,13 +343,13 @@ public class ShareInfoService { } } } - }catch (Exception e){ + } catch (Exception e) { } } // 赋值响应码 - if (responseJsonObj!=null && responseJsonObj.containsKey("statusCode")) { + if (responseJsonObj != null && responseJsonObj.containsKey("statusCode")) { try { JSONArray responseStatusDataArr = new JSONArray(); JSONArray statusArr = responseJsonObj.getJSONArray("statusCode"); @@ -360,13 +360,13 @@ public class ShareInfoService { } } apiInfoDTO.setResponseCode(responseStatusDataArr.toJSONString()); - }catch (Exception e){ + } catch (Exception e) { } } } } - if(!previewJsonArray.isEmpty()){ + if (!previewJsonArray.isEmpty()) { apiInfoDTO.setRequestPreviewData(previewJsonArray); } apiInfoDTO.setSelectedFlag(true); @@ -375,9 +375,9 @@ public class ShareInfoService { private JSONObject genJSONObject(String request) { JSONObject returnObj = null; - try{ + try { returnObj = JSONObject.parseObject(request); - }catch (Exception e){ + } catch (Exception e) { } return returnObj; } @@ -417,6 +417,7 @@ public class ShareInfoService { /** * 生成分享连接 * 如果该数据有连接则,返回已有的连接,不做有效期判断 + * * @param request * @return */ @@ -504,12 +505,13 @@ public class ShareInfoService { * 若在当前类中调用请使用如下方式调用,否则该方法的事务注解不生效 * ShareInfoService shareInfoService = CommonBeanFactory.getBean(ShareInfoService.class); * shareInfoService.validateExpired(shareInfo); + * * @param shareInfo */ @Transactional(propagation = Propagation.NOT_SUPPORTED) public void validateExpired(ShareInfo shareInfo) { // 有效期24小时 - if (shareInfo == null || System.currentTimeMillis() - shareInfo.getUpdateTime() > 1000*60*60*24) { + if (shareInfo == null || System.currentTimeMillis() - shareInfo.getUpdateTime() > 1000 * 60 * 60 * 24) { shareInfoMapper.deleteByPrimaryKey(shareInfo.getId()); MSException.throwException("连接已失效,请重新获取!"); } diff --git a/frontend/src/business/components/api/definition/components/response/RequestMetric.vue b/frontend/src/business/components/api/definition/components/response/RequestMetric.vue index 59eeba2f02..e2f0a9a21d 100644 --- a/frontend/src/business/components/api/definition/components/response/RequestMetric.vue +++ b/frontend/src/business/components/api/definition/components/response/RequestMetric.vue @@ -7,7 +7,11 @@ v-if="responseResult.responseCode" :content="responseResult.responseCode" placement="top"> -
+ +
+ {{ responseResult && responseResult.responseCode ? responseResult.responseCode : '0' }} +
+
{{ responseResult && responseResult.responseCode ? responseResult.responseCode : '0' }}
diff --git a/frontend/src/business/components/track/plan/view/comonents/api/TestPlanApiCaseList.vue b/frontend/src/business/components/track/plan/view/comonents/api/TestPlanApiCaseList.vue index 8da94f18cd..13819b4847 100644 --- a/frontend/src/business/components/track/plan/view/comonents/api/TestPlanApiCaseList.vue +++ b/frontend/src/business/components/track/plan/view/comonents/api/TestPlanApiCaseList.vue @@ -134,7 +134,10 @@ - + +
diff --git a/frontend/src/business/components/track/plan/view/comonents/api/TestPlanApiScenarioList.vue b/frontend/src/business/components/track/plan/view/comonents/api/TestPlanApiScenarioList.vue index 56ad7ca862..1389c7a92a 100644 --- a/frontend/src/business/components/track/plan/view/comonents/api/TestPlanApiScenarioList.vue +++ b/frontend/src/business/components/track/plan/view/comonents/api/TestPlanApiScenarioList.vue @@ -142,7 +142,7 @@ {{ $t('api_test.automation.fail') }} - + {{ $t('error_report_library.option.name') }}