fix: 解决冲突

This commit is contained in:
chenjianxing 2020-08-05 13:10:24 +08:00
commit ff7d0e0343
13 changed files with 148 additions and 33 deletions

View File

@ -44,18 +44,7 @@ public class MsParser extends ApiImportAbstractParser {
requestTmpObject.keySet().forEach(key -> requestObject.put(key, requestTmpObject.get(key))); requestTmpObject.keySet().forEach(key -> requestObject.put(key, requestTmpObject.get(key)));
requestObject.put("name", requestName); requestObject.put("name", requestName);
JSONArray bodies = requestObject.getJSONArray("body"); parseBody(requestObject);
if (StringUtils.equalsIgnoreCase(requestObject.getString("method"), HttpMethod.POST.name()) && bodies != null) {
StringBuilder bodyStr = new StringBuilder();
for (int i = 0; i < bodies.size(); i++) {
String body = bodies.getString(i);
bodyStr.append(body);
}
JSONObject bodyObject = new JSONObject();
bodyObject.put("raw", bodyStr);
bodyObject.put("type", MsRequestBodyType.RAW.value());
requestObject.put("body", bodyObject);
}
requestsObjects.add(requestObject); requestsObjects.add(requestObject);
}); });
scenario.put("requests", requestsObjects); scenario.put("requests", requestsObjects);
@ -66,4 +55,39 @@ public class MsParser extends ApiImportAbstractParser {
return result.toJSONString(); return result.toJSONString();
} }
} }
private void parseBody(JSONObject requestObject) {
if (requestObject.containsKey("body")) {
Object body = requestObject.get("body");
if (body instanceof JSONArray) {
JSONArray bodies = requestObject.getJSONArray("body");
if (StringUtils.equalsIgnoreCase(requestObject.getString("method"), HttpMethod.POST.name()) && bodies != null) {
StringBuilder bodyStr = new StringBuilder();
for (int i = 0; i < bodies.size(); i++) {
String tmp = bodies.getString(i);
bodyStr.append(tmp);
}
JSONObject bodyObject = new JSONObject();
bodyObject.put("raw", bodyStr);
bodyObject.put("type", MsRequestBodyType.RAW.value());
requestObject.put("body", bodyObject);
}
} else if (body instanceof JSONObject) {
JSONObject bodyObj = requestObject.getJSONObject("body");
if (StringUtils.equalsIgnoreCase(requestObject.getString("method"), HttpMethod.POST.name()) && bodyObj != null) {
JSONArray kvs = new JSONArray();
bodyObj.keySet().forEach(key -> {
JSONObject kv = new JSONObject();
kv.put("name", key);
kv.put("value", bodyObj.getString(key));
kvs.add(kv);
});
JSONObject bodyRes = new JSONObject();
bodyRes.put("kvs", kvs);
bodyRes.put("type", MsRequestBodyType.KV.value());
requestObject.put("body", bodyRes);
}
}
}
}
} }

View File

@ -165,11 +165,17 @@
#{value} #{value}
</foreach> </foreach>
</when> </when>
<otherwise> <when test="key=='method'">
and test_case.method in and test_case.method in
<foreach collection="values" item="value" separator="," open="(" close=")"> <foreach collection="values" item="value" separator="," open="(" close=")">
#{value} #{value}
</foreach> </foreach>
</when>
<otherwise>
and test_plan_test_case.status in
<foreach collection="values" item="value" separator="," open="(" close=")">
#{value}
</foreach>
</otherwise> </otherwise>
</choose> </choose>
</if> </if>

View File

@ -1,5 +1,48 @@
package io.metersphere.commons.constants; package io.metersphere.commons.constants;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class TestCaseConstants { public class TestCaseConstants {
public static final int MAX_NODE_DEPTH = 5; public static final int MAX_NODE_DEPTH = 5;
public enum Type {
Functional("functional"), Performance("performance"), Aapi("api");
private String value;
Type(String value) {
this.value = value;
}
public String getValue() {
return this.value;
}
public static List<String> getValues() {
List<Type> types = Arrays.asList(Type.values());
return types.stream().map(Type::getValue).collect(Collectors.toList());
}
}
public enum Method {
Manual("manual"), Auto("auto");
private String value;
Method(String value) {
this.value = value;
}
public String getValue() {
return this.value;
}
public static List<String> getValues() {
List<Method> types = Arrays.asList(Method.values());
return types.stream().map(Method::getValue).collect(Collectors.toList());
}
}
} }

View File

@ -41,16 +41,20 @@ public class TestCaseDataListener extends EasyExcelListener<TestCaseExcelData> {
String[] nodes = nodePath.split("/"); String[] nodes = nodePath.split("/");
if (nodes.length > TestCaseConstants.MAX_NODE_DEPTH + 1) { if (nodes.length > TestCaseConstants.MAX_NODE_DEPTH + 1) {
stringBuilder.append(Translator.get("test_case_node_level_tip") + stringBuilder.append(Translator.get("test_case_node_level_tip") +
TestCaseConstants.MAX_NODE_DEPTH + Translator.get("test_case_node_level")); TestCaseConstants.MAX_NODE_DEPTH + Translator.get("test_case_node_level") + "; ");
} }
for (int i = 0; i < nodes.length; i++) { for (int i = 0; i < nodes.length; i++) {
if (i != 0 && StringUtils.equals(nodes[i].trim(), "")) { if (i != 0 && StringUtils.equals(nodes[i].trim(), "")) {
stringBuilder.append(Translator.get("module_not_null")); stringBuilder.append(Translator.get("module_not_null") + "; ");
break; break;
} }
} }
} }
if (StringUtils.equals(data.getType(), TestCaseConstants.Type.Functional.getValue()) && StringUtils.equals(data.getMethod(), TestCaseConstants.Method.Auto.getValue())) {
stringBuilder.append(Translator.get("functional_method_tip") + "; ");
}
if (!userIds.contains(data.getMaintainer())) { if (!userIds.contains(data.getMaintainer())) {
stringBuilder.append(Translator.get("user_not_exists") + "" + data.getMaintainer() + "; "); stringBuilder.append(Translator.get("user_not_exists") + "" + data.getMaintainer() + "; ");
} }

View File

@ -415,7 +415,7 @@ public class TestCaseNodeService {
List<TestCaseNode> updateNodes = new ArrayList<>(); List<TestCaseNode> updateNodes = new ArrayList<>();
buildUpdateTestCase(nodeTree, testCases, updateNodes, "/", null, 1); buildUpdateTestCase(nodeTree, testCases, updateNodes, "/", "0", 1);
updateNodes = updateNodes.stream() updateNodes = updateNodes.stream()
.filter(item -> nodeIds.contains(item.getId())) .filter(item -> nodeIds.contains(item.getId()))

View File

@ -9,6 +9,7 @@ import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.*; import io.metersphere.base.mapper.*;
import io.metersphere.base.mapper.ext.ExtTestCaseMapper; import io.metersphere.base.mapper.ext.ExtTestCaseMapper;
import io.metersphere.commons.constants.RoleConstants; import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.commons.constants.TestCaseConstants;
import io.metersphere.commons.exception.MSException; import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.user.SessionUser; import io.metersphere.commons.user.SessionUser;
import io.metersphere.commons.utils.BeanUtils; import io.metersphere.commons.utils.BeanUtils;
@ -309,8 +310,8 @@ public class TestCaseService {
private List<TestCaseExcelData> generateExportTemplate() { private List<TestCaseExcelData> generateExportTemplate() {
List<TestCaseExcelData> list = new ArrayList<>(); List<TestCaseExcelData> list = new ArrayList<>();
StringBuilder path = new StringBuilder(""); StringBuilder path = new StringBuilder("");
List<String> types = Arrays.asList("functional", "performance", "api"); List<String> types = TestCaseConstants.Type.getValues();
List<String> methods = Arrays.asList("manual", "auto"); List<String> methods = TestCaseConstants.Method.getValues();
SessionUser user = SessionUtils.getUser(); SessionUser user = SessionUtils.getUser();
for (int i = 1; i <= 5; i++) { for (int i = 1; i <= 5; i++) {
TestCaseExcelData data = new TestCaseExcelData(); TestCaseExcelData data = new TestCaseExcelData();
@ -318,8 +319,13 @@ public class TestCaseService {
path.append("/" + Translator.get("module") + i); path.append("/" + Translator.get("module") + i);
data.setNodePath(path.toString()); data.setNodePath(path.toString());
data.setPriority("P" + i % 4); data.setPriority("P" + i % 4);
data.setType(types.get(i % 3)); String type = types.get(i % 3);
data.setMethod(methods.get(i % 2)); data.setType(type);
if (StringUtils.equals(TestCaseConstants.Type.Functional.getValue(), type)) {
data.setMethod(TestCaseConstants.Method.Manual.getValue());
} else {
data.setMethod(methods.get(i % 2));
}
data.setPrerequisite(Translator.get("preconditions_optional")); data.setPrerequisite(Translator.get("preconditions_optional"));
data.setStepDesc("1. " + Translator.get("step_tip_separate") + data.setStepDesc("1. " + Translator.get("step_tip_separate") +
"\n2. " + Translator.get("step_tip_order") + "\n3. " + Translator.get("step_tip_optional")); "\n2. " + Translator.get("step_tip_order") + "\n3. " + Translator.get("step_tip_optional"));

View File

@ -117,6 +117,7 @@ plan_name_already_exists=Test plan name already exists
test_case_already_exists_excel=There are duplicate test cases in the import file test_case_already_exists_excel=There are duplicate test cases in the import file
test_case_module_already_exists=The module name already exists at the same level test_case_module_already_exists=The module name already exists at the same level
api_test_name_already_exists=Test name already exists api_test_name_already_exists=Test name already exists
functional_method_tip=Functional test not support auto method
#ldap #ldap
ldap_url_is_null=LDAP address is empty ldap_url_is_null=LDAP address is empty

View File

@ -117,6 +117,7 @@ plan_name_already_exists=测试计划名称已存在
test_case_already_exists_excel=导入文件中存在重复用例 test_case_already_exists_excel=导入文件中存在重复用例
test_case_module_already_exists=同层级下已存在该模块名称 test_case_module_already_exists=同层级下已存在该模块名称
api_test_name_already_exists=测试名称已经存在 api_test_name_already_exists=测试名称已经存在
functional_method_tip=功能测试不支持自动方式
#ldap #ldap
ldap_url_is_null=LDAP地址为空 ldap_url_is_null=LDAP地址为空

View File

@ -117,6 +117,7 @@ plan_name_already_exists=測試計劃名稱已存在
test_case_already_exists_excel=導入文件中存在重復用例 test_case_already_exists_excel=導入文件中存在重復用例
test_case_module_already_exists=同層級下已存在該模塊名稱 test_case_module_already_exists=同層級下已存在該模塊名稱
api_test_name_already_exists=測試名稱已經存在 api_test_name_already_exists=測試名稱已經存在
functional_method_tip=功能測試不支持自動方式
#ldap #ldap
ldap_url_is_null=LDAP地址為空 ldap_url_is_null=LDAP地址為空

View File

@ -1,11 +1,11 @@
<template> <template>
<div class="schedule-config"> <div class="schedule-config">
<div> <div>
<span class="cron-ico"> <span class="cron-ico" @click="scheduleEdit">
<i class="el-icon-date" size="small"></i> <i class="el-icon-date" size="small"></i>
<span class="character" @click="scheduleEdit">SCHEDULER</span> <span class="character">SCHEDULER</span>
</span> </span>
<el-switch :disabled="!schedule.value && isReadOnly" v-model="schedule.enable" @change="scheduleChange"/> <el-switch :disabled="!schedule.value || isReadOnly" v-model="schedule.enable" @change="scheduleChange"/>
<ms-schedule-edit :is-read-only="isReadOnly" :schedule="schedule" :save="save" :custom-validate="customValidate" ref="scheduleEdit"/> <ms-schedule-edit :is-read-only="isReadOnly" :schedule="schedule" :save="save" :custom-validate="customValidate" ref="scheduleEdit"/>
<crontab-result v-show="false" :ex="schedule.value" ref="crontabResult" @resultListChange="resultListChange"/> <crontab-result v-show="false" :ex="schedule.value" ref="crontabResult" @resultListChange="resultListChange"/>
</div> </div>

View File

@ -39,9 +39,25 @@
@confirm="submit('form')"/> @confirm="submit('form')"/>
</template> </template>
</el-dialog> </el-dialog>
<el-dialog :title="$t('workspace.update')" :visible.sync="dialogWsUpdateVisible" width="30%">
<el-form :model="form" :rules="rules" ref="form" label-position="right" label-width="100px" size="small">
<el-form-item :label="$t('commons.name')" prop="name">
<el-input v-model="form.name" autocomplete="off"/>
</el-form-item>
<el-form-item :label="$t('commons.description')" prop="description">
<el-input type="textarea" v-model="form.description"></el-input>
</el-form-item>
</el-form>
<template v-slot:footer>
<ms-dialog-footer
@cancel="dialogWsUpdateVisible = false"
@confirm="submit('form')"/>
</template>
</el-dialog>
<!-- dialog of workspace member --> <!-- dialog of workspace member -->
<el-dialog :visible.sync="dialogWsMemberVisible" width="70%" :destroy-on-close="true" @close="closeMemberFunc" class="dialog-css"> <el-dialog :visible.sync="dialogWsMemberVisible" width="70%" :destroy-on-close="true" @close="closeMemberFunc"
class="dialog-css">
<ms-table-header :condition.sync="dialogCondition" @create="addMember" @search="dialogSearch" <ms-table-header :condition.sync="dialogCondition" @create="addMember" @search="dialogSearch"
:create-tip="$t('member.create')" :title="$t('commons.member')"/> :create-tip="$t('member.create')" :title="$t('commons.member')"/>
<!-- organization member table --> <!-- organization member table -->
@ -201,8 +217,13 @@
} }
this.$post("/workspace/" + saveType, this.form, () => { this.$post("/workspace/" + saveType, this.form, () => {
this.dialogWsAddVisible = false; this.dialogWsAddVisible = false;
this.dialogWsUpdateVisible = false;
this.list(); this.list();
Message.success(this.$t('commons.save_success')); if (saveType == 'add') {
Message.success(this.$t('commons.save_success'));
} else if (saveType == 'update') {
Message.success(this.$t('commons.modify_success'));
}
}); });
} else { } else {
return false; return false;
@ -210,7 +231,7 @@
}); });
}, },
edit(row) { edit(row) {
this.dialogWsAddVisible = true; this.dialogWsUpdateVisible = true;
this.form = Object.assign({}, row); this.form = Object.assign({}, row);
}, },
handleDelete(workspace) { handleDelete(workspace) {
@ -423,6 +444,7 @@
return { return {
result: {}, result: {},
dialogWsAddVisible: false, dialogWsAddVisible: false,
dialogWsUpdateVisible: false,
dialogWsMemberVisible: false, dialogWsMemberVisible: false,
dialogWsMemberAddVisible: false, dialogWsMemberAddVisible: false,
dialogWsMemberUpdateVisible: false, dialogWsMemberUpdateVisible: false,

View File

@ -369,7 +369,7 @@
{required: true, message: this.$t('user.input_email'), trigger: 'blur'}, {required: true, message: this.$t('user.input_email'), trigger: 'blur'},
{ {
required: true, required: true,
pattern: /^([A-Za-z0-9_\-.])+@([A-Za-z0-9]+\.)+[A-Za-z]{2,6}$/, pattern: /^[a-zA-Z0-9_._-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/,
message: this.$t('user.email_format_is_incorrect'), message: this.$t('user.email_format_is_incorrect'),
trigger: 'blur' trigger: 'blur'
} }

View File

@ -107,6 +107,16 @@ export default {
}, },
methods: { methods: {
handleDragEnd(draggingNode, dropNode, dropType, ev) { handleDragEnd(draggingNode, dropNode, dropType, ev) {
let param = this.buildParam(draggingNode, dropNode, dropType);
console.log(this.treeNodes);
this.$post("/case/node/drag", param, () => {
draggingNode.data.level = param.level;
this.refreshTable();
}, (error) => {
this.refreshNode();
});
},
buildParam(draggingNode, dropNode, dropType) {
let param = {}; let param = {};
param.id = draggingNode.data.id; param.id = draggingNode.data.id;
param.name = draggingNode.data.name; param.name = draggingNode.data.name;
@ -115,7 +125,7 @@ export default {
param.parentId = dropNode.data.id; param.parentId = dropNode.data.id;
param.level = dropNode.data.level + 1; param.level = dropNode.data.level + 1;
} else { } else {
if (dropNode.parent.id === 0) { if (!dropNode.parent.id || dropNode.parent.id === 0) {
param.parentId = 0; param.parentId = 0;
param.level = 1; param.level = 1;
} else { } else {
@ -135,12 +145,9 @@ export default {
} }
} }
} }
param.nodeIds = nodeIds; param.nodeIds = nodeIds;
this.$post("/case/node/drag", param, () => { return param;
this.refreshTable();
}, (error) => {
this.refreshNode();
});
}, },
refreshTable() { refreshTable() {
this.$emit('refreshTable'); this.$emit('refreshTable');