未验证 提交 e6a9556e 编写于 作者: B BugKing 提交者: GitHub

Merge pull request #2445 from metersphere/dev

合并dev
......@@ -14,13 +14,14 @@ import io.metersphere.commons.utils.JsonPathUtils;
import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.i18n.Translator;
import org.apache.commons.lang3.StringUtils;
import org.json.XML;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.*;
import java.util.*;
import java.util.stream.Collectors;
......@@ -410,10 +411,39 @@ public class MockConfigService {
e.printStackTrace();
}
return object;
} else {
Enumeration<String> paramNameItor = request.getParameterNames();
} else if (StringUtils.equalsIgnoreCase("text/xml", request.getContentType())) {
String xmlString = this.readXml(request);
System.out.println(xmlString);
org.json.JSONObject xmlJSONObj = XML.toJSONObject(xmlString);
String jsonStr = xmlJSONObj.toString();
JSONObject object = null;
try {
object = JSONObject.parseObject(jsonStr);
} catch (Exception e) {
}
return object;
} else if (StringUtils.equalsIgnoreCase("application/x-www-form-urlencoded", request.getContentType())) {
JSONObject object = new JSONObject();
Enumeration<String> paramNameItor = request.getParameterNames();
while (paramNameItor.hasMoreElements()) {
String key = paramNameItor.nextElement();
String value = request.getParameter(key);
object.put(key, value);
}
return object;
} else {
JSONObject object = new JSONObject();
String bodyParam = this.readBody(request);
if (!StringUtils.isEmpty(bodyParam)) {
try {
object = JSONObject.parseObject(bodyParam);
} catch (Exception e) {
e.printStackTrace();
}
}
Enumeration<String> paramNameItor = request.getParameterNames();
while (paramNameItor.hasMoreElements()) {
String key = paramNameItor.nextElement();
String value = request.getParameter(key);
......@@ -423,40 +453,103 @@ public class MockConfigService {
}
}
private String readXml(HttpServletRequest request) {
{
String inputLine = null;
// 接收到的数据
StringBuffer recieveData = new StringBuffer();
BufferedReader in = null;
try {
in = new BufferedReader(new InputStreamReader(
request.getInputStream(), "UTF-8"));
while ((inputLine = in.readLine()) != null) {
recieveData.append(inputLine);
}
} catch (IOException e) {
} finally {
try {
if (null != in) {
in.close();
}
} catch (IOException e) {
}
}
return recieveData.toString();
}
}
private String readBody(HttpServletRequest request) {
String result = "";
try {
InputStream inputStream = request.getInputStream();
ByteArrayOutputStream outSteam = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len;
while ((len = inputStream.read(buffer)) != -1) {
outSteam.write(buffer, 0, len);
}
outSteam.close();
inputStream.close();
result = new String(outSteam.toByteArray(), "UTF-8");
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
public JSONObject getSendRestParamMapByIdAndUrl(ApiDefinitionWithBLOBs api, String urlParams) {
// ApiDefinitionWithBLOBs api = apiDefinitionMapper.selectByPrimaryKey(apiId);
JSONObject returnJson = new JSONObject();
if (api != null) {
String path = api.getPath();
if (path.startsWith("/")) {
path = path.substring(1);
}
String[] pathArr = path.split("/");
List<String> sendParams = new ArrayList<>();
for (String param : pathArr) {
String[] sendParamArr = urlParams.split("/");
//获取 url的<参数名-参数值>,通过匹配api的接口设置和实际发送的url
for (int i = 0; i < pathArr.length; i++) {
String param = pathArr[i];
if (param.startsWith("{") && param.endsWith("}")) {
param = param.substring(1, param.length() - 1);
sendParams.add(param);
}
}
try {
JSONObject requestJson = JSONObject.parseObject(api.getRequest());
if (requestJson.containsKey("rest")) {
JSONArray jsonArray = requestJson.getJSONArray("rest");
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject object = jsonArray.getJSONObject(i);
if (object.containsKey("name") && object.containsKey("enable") && object.getBoolean("enable")) {
String name = object.getString("name");
if (sendParams.contains(name)) {
String value = "";
if (object.containsKey("value")) {
value = object.getString("value");
}
returnJson.put(name, value);
}
}
String value = "";
if (sendParamArr.length > i) {
value = sendParamArr[i];
}
returnJson.put(param, value);
}
} catch (Exception e) {
e.printStackTrace();
}
// List<String> sendParams = new ArrayList<>();
// for (String param : pathArr) {
// if (param.startsWith("{") && param.endsWith("}")) {
// param = param.substring(1, param.length() - 1);
// sendParams.add(param);
// }
// }
// try {
// JSONObject requestJson = JSONObject.parseObject(api.getRequest());
// if (requestJson.containsKey("rest")) {
// JSONArray jsonArray = requestJson.getJSONArray("rest");
// for (int i = 0; i < jsonArray.size(); i++) {
// JSONObject object = jsonArray.getJSONObject(i);
// if (object.containsKey("name") && object.containsKey("enable") && object.getBoolean("enable")) {
// String name = object.getString("name");
// if (sendParams.contains(name)) {
// String value = "";
// if (object.containsKey("value")) {
// value = object.getString("value");
// }
// returnJson.put(name, value);
// }
// }
// }
// }
// } catch (Exception e) {
// e.printStackTrace();
// }
}
return returnJson;
}
......@@ -577,7 +670,8 @@ public class MockConfigService {
return this.assemblyMockConfingResponse(configList);
}
public String checkReturnWithMockExpectByBodyParam(String method, String projectId, HttpServletRequest request, HttpServletResponse response) {
public String checkReturnWithMockExpectByBodyParam(String method, String projectId, HttpServletRequest
request, HttpServletResponse response) {
String returnStr = "";
String urlSuffix = this.getUrlSuffix(projectId, request);
List<ApiDefinitionWithBLOBs> aualifiedApiList = apiDefinitionService.preparedUrl(projectId, method, urlSuffix, urlSuffix);
......@@ -599,7 +693,8 @@ public class MockConfigService {
return returnStr;
}
public String checkReturnWithMockExpectByUrlParam(String get, String projectId, HttpServletRequest request, HttpServletResponse response) {
public String checkReturnWithMockExpectByUrlParam(String get, String projectId, HttpServletRequest
request, HttpServletResponse response) {
String returnStr = "";
String urlSuffix = this.getUrlSuffix(projectId, request);
List<ApiDefinitionWithBLOBs> aualifiedApiList = apiDefinitionService.preparedUrl(projectId, "GET", null, urlSuffix);
......
......@@ -32,7 +32,7 @@
</template>
</ms-table-column>
<field-custom-data-table-item :scene="scene"/>
<!-- <field-custom-data-table-item :scene="scene"/>-->
<ms-table-column
:label="$t('api_test.definition.document.table_coloum.is_required')"
......
......@@ -30,7 +30,7 @@
return {
editor: ClassicEditor,
editorConfig: {
toolbar: [ 'heading', '|', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'blockQuote' ,'insertTable', 'imageUpload', '|','undo', 'redo'],
toolbar: [ 'heading', '|', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'blockQuote' ,'insertTable', '|','undo', 'redo'],
// ckfinder: {
// uploadUrl: `/image/uploadCkEditor?imgPath=${JSON.stringify(this.imagePath)}`
// },
......
......@@ -7,11 +7,11 @@
<el-dropdown-menu>
<el-dropdown-item command="STEP">
<div>{{ $t('test_track.case.step_describe') }}</div>
<div>{{ $t('test_track.case.text_describe_tip') }}</div>
<div>{{ $t('test_track.case.step_describe_tip') }}</div>
</el-dropdown-item>
<el-dropdown-item command="TEXT">
<div>{{ $t('test_track.case.text_describe') }}</div>
<div>{{ $t('test_track.case.change_type_tip') }}</div>
<div>{{ $t('test_track.case.text_describe_tip') }}</div>
</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
......
......@@ -63,6 +63,7 @@
</el-row>
<el-form ref="customFieldForm"
v-if="isCustomFiledActive"
class="case-form">
<el-row>
<el-col :span="7" v-for="(item, index) in testCaseTemplate.customFields" :key="index">
......@@ -181,6 +182,7 @@ export default {
comments: [],
testCaseTemplate: {},
formLabelWidth: "100px",
isCustomFiledActive: false
};
},
props: {
......@@ -352,6 +354,7 @@ export default {
}
this.testCase = item;
parseCustomField(this.testCase, this.testCaseTemplate, null, null, buildTestCaseOldFields(this.testCase));
this.isCustomFiledActive = true;
if (!this.testCase.actualResult) {
// 如果没值,使用模板的默认值
this.testCase.actualResult = this.testCaseTemplate.actualResult;
......
......@@ -78,6 +78,7 @@
</el-row>
<el-form ref="customFieldForm"
v-if="isCustomFiledActive"
class="case-form">
<el-row>
<el-col :span="7" v-for="(item, index) in testCaseTemplate.customFields" :key="index">
......@@ -187,7 +188,8 @@ export default {
testCaseTemplate: {},
hasTapdId: false,
hasZentaoId: false,
formLabelWidth: '100px'
formLabelWidth: '100px',
isCustomFiledActive: false
};
},
props: {
......@@ -302,6 +304,7 @@ export default {
item.stepModel = 'STEP';
}
parseCustomField(item, this.testCaseTemplate, null, null, buildTestCaseOldFields(item));
this.isCustomFiledActive = true;
this.testCase = item;
if (!this.testCase.actualResult) {
// 如果没值,使用模板的默认值
......
......@@ -1250,10 +1250,10 @@ export default {
step_info: "Step Info",
other_info: "Other Info",
step_describe: "Step Describe",
step_describe_tip: "Applicable to every step of the test scenario, there are clear test steps, expected results",
text_describe: "Text Describe",
text_describe_tip: "For simple test scenarios, there are no clear test steps",
change_type: "Change Type",
change_type_tip: "Applicable to every step of the test scenario, there are clear test steps, expected results",
minder_create_tip: "failed, unable to create its parent module in minder",
check_select: "Please check the case",
export_all_cases: 'Are you sure you want to export all use cases?',
......
......@@ -1255,10 +1255,10 @@ export default {
step_info: "步骤信息",
other_info: "其他信息",
step_describe: "步骤描述",
step_describe_tip: "适用于需要每一个步骤进行测试的场景,有明确的测试步骤、预期结果",
text_describe: "文本描述",
text_describe_tip: "使用于简单的测试场景,没有明确的测试步骤",
change_type: "更改类型",
change_type_tip: "适用于需要每一个步骤进行测试的场景,有明确的测试步骤、预期结果",
minder_create_tip: "失败, 无法在脑图创建其父模块",
check_select: "请勾选用例",
export_all_cases: '确定要导出全部用例吗?',
......
......@@ -1255,10 +1255,10 @@ export default {
step_info: "步驟信息",
other_info: "其他信息",
step_describe: "步驟描述",
step_describe_tip: "適用於需要每一個步驟進行測試的場景,有明確的測試步驟、預期結果",
text_describe: "文本描述",
text_describe_tip: "使用於簡單的測試場景,沒有明確的測試步驟",
change_type: "更改類型",
change_type_tip: "適用於需要每一個步驟進行測試的場景,有明確的測試步驟、預期結果",
minder_create_tip: "失敗, 無法在腦圖創建其父模塊",
check_select: "請勾選用例",
export_all_cases: '確定要導出全部用例嗎?',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册