This commit is contained in:
shiziyuan9527 2020-09-27 18:43:44 +08:00
commit 95293a7377
5 changed files with 349 additions and 299 deletions

View File

@ -4,8 +4,10 @@ import io.metersphere.base.domain.ApiTestReport;
import io.metersphere.base.domain.LoadTestWithBLOBs;
import io.metersphere.base.domain.SystemParameter;
import io.metersphere.base.domain.TestCaseWithBLOBs;
import io.metersphere.commons.constants.APITestStatus;
import io.metersphere.commons.constants.NoticeConstants;
import io.metersphere.commons.constants.ParamConstants;
import io.metersphere.commons.constants.PerformanceTestStatus;
import io.metersphere.commons.utils.EncryptUtils;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.dto.BaseSystemConfigDTO;
@ -46,12 +48,13 @@ public class MailService {
context.put("title", "Performance" + Translator.get("timing_task_result_notification"));
context.put("testName", loadTest.getName());
context.put("id", loadTest.getId());
context.put("type", "performance");
context.put("url", baseSystemConfigDTO.getUrl());
String performanceTemplate = "";
try {
if (status.equals("Completed")) {
if (StringUtils.equals(status, PerformanceTestStatus.Completed.name())) {
performanceTemplate = IOUtils.toString(this.getClass().getResource("/mail/successPerformance.html"), StandardCharsets.UTF_8);
} else if (status.equals("Error")) {
} else if (StringUtils.equals(status, PerformanceTestStatus.Error.name())) {
performanceTemplate = IOUtils.toString(this.getClass().getResource("/mail/failPerformance.html"), StandardCharsets.UTF_8);
}
sendHtmlTimeTasks(noticeList, status, context, performanceTemplate);
@ -65,14 +68,14 @@ public class MailService {
Map<String, String> context = new HashMap<>();
context.put("title", "api" + Translator.get("timing_task_result_notification"));
context.put("testName", apiTestReport.getName());
context.put("type", "Api");
context.put("type", "api");
context.put("url", baseSystemConfigDTO.getUrl());
context.put("id", apiTestReport.getId());
String apiTemplate = "";
try {
if (apiTestReport.getStatus().equals("Success")) {
if (StringUtils.equals(APITestStatus.Success.name(), apiTestReport.getStatus())) {
apiTemplate = IOUtils.toString(this.getClass().getResource("/mail/success.html"), StandardCharsets.UTF_8);
} else if (apiTestReport.getStatus().equals("Error")) {
} else if (StringUtils.equals(APITestStatus.Error.name(), apiTestReport.getStatus())) {
apiTemplate = IOUtils.toString(this.getClass().getResource("/mail/fail.html"), StandardCharsets.UTF_8);
}
sendHtmlTimeTasks(noticeList, apiTestReport.getStatus(), context, apiTemplate);
@ -183,17 +186,21 @@ public class MailService {
javaMailSender.setDefaultEncoding("UTF-8");
javaMailSender.setProtocol("smtps");
for (SystemParameter p : paramList) {
if (p.getParamKey().equals("smtp.host")) {
switch (p.getParamKey()) {
case "smtp.host":
javaMailSender.setHost(p.getParamValue());
}
if (p.getParamKey().equals("smtp.port")) {
break;
case "smtp.port":
javaMailSender.setPort(Integer.parseInt(p.getParamValue()));
}
if (p.getParamKey().equals("smtp.account")) {
break;
case "smtp.account":
javaMailSender.setUsername(p.getParamValue());
}
if (p.getParamKey().equals("smtp.password")) {
break;
case "smtp.password":
javaMailSender.setPassword(EncryptUtils.aesDecrypt(p.getParamValue()).toString());
break;
default:
break;
}
}
Properties props = new Properties();
@ -223,10 +230,10 @@ public class MailService {
List<String> failEmailList = new ArrayList<>();
if (noticeList.size() > 0) {
for (NoticeDetail n : noticeList) {
if (n.getEnable().equals("true") && n.getEvent().equals(NoticeConstants.EXECUTE_SUCCESSFUL)) {
if (StringUtils.equals(n.getEnable(), "true") && StringUtils.equals(n.getEvent(), NoticeConstants.EXECUTE_SUCCESSFUL)) {
successEmailList = userService.queryEmail(n.getNames());
}
if (n.getEnable().equals("true") && n.getEvent().equals(NoticeConstants.EXECUTE_FAILED)) {
if (StringUtils.equals(n.getEnable(), "true") && StringUtils.equals(n.getEvent(), NoticeConstants.EXECUTE_FAILED)) {
failEmailList = userService.queryEmail(n.getNames());
}
}
@ -234,7 +241,7 @@ public class MailService {
LogUtil.error("Recipient information is empty");
}
if (status.equals("Success") || status.equals("Completed")) {
if (StringUtils.equalsAny(status, PerformanceTestStatus.Completed.name(), APITestStatus.Success.name())) {
recipientEmails = successEmailList.toArray(new String[0]);
} else {
recipientEmails = failEmailList.toArray(new String[0]);

View File

@ -355,50 +355,45 @@ public class TestCaseNodeService {
}
public Map<String, String> createNodeByTestCases(List<TestCaseWithBLOBs> testCases, String projectId) {
List<TestCaseNodeDTO> nodeTrees = getNodeTreeByProjectId(projectId);
Map<String, String> pathMap = new HashMap<>();
List<String> nodePaths = testCases.stream()
.map(TestCase::getNodePath)
.collect(Collectors.toList());
nodePaths.forEach(path -> {
return this.createNodes(nodePaths, projectId);
}
if (path == null) {
public Map<String, String> createNodes(List<String> nodePaths, String projectId) {
List<TestCaseNodeDTO> nodeTrees = getNodeTreeByProjectId(projectId);
Map<String, String> pathMap = new HashMap<>();
for(String item : nodePaths){
if (item == null) {
throw new ExcelException(Translator.get("test_case_module_not_null"));
}
List<String> nodeNameList = new ArrayList<>(Arrays.asList(path.split("/")));
Iterator<String> pathIterator = nodeNameList.iterator();
List<String> nodeNameList = new ArrayList<>(Arrays.asList(item.split("/")));
Iterator<String> itemIterator = nodeNameList.iterator();
Boolean hasNode = false;
String rootNodeName = null;
if (nodeNameList.size() <= 1) {
throw new ExcelException(Translator.get("test_case_create_module_fail") + ":" + path);
throw new ExcelException(Translator.get("test_case_create_module_fail") + ":" + item);
} else {
pathIterator.next();
pathIterator.remove();
rootNodeName = pathIterator.next().trim();
itemIterator.next();
itemIterator.remove();
rootNodeName = itemIterator.next().trim();
//原来没有新建的树nodeTrees也不包含
for (TestCaseNodeDTO nodeTree : nodeTrees) {
if (StringUtils.equals(rootNodeName, nodeTree.getName())) {
hasNode = true;
createNodeByPathIterator(pathIterator, "/" + rootNodeName, nodeTree,
createNodeByPathIterator(itemIterator, "/" + rootNodeName, nodeTree,
pathMap, projectId, 2);
}
;
}
}
if (!hasNode) {
createNodeByPath(pathIterator, rootNodeName, null, projectId, 1, "", pathMap);
createNodeByPath(itemIterator, rootNodeName, null, projectId, 1, "", pathMap);
}
}
});
return pathMap;
}

View File

@ -284,6 +284,9 @@ public class TestCaseService {
errList.add(excelErrData);
excelResponse.setErrList(errList);
} else {
if (!xmindParser.getNodePaths().isEmpty()) {
testCaseNodeService.createNodes(xmindParser.getNodePaths(), projectId);
}
if (!xmindParser.getTestCase().isEmpty()) {
this.saveImportData(xmindParser.getTestCase(), projectId);
xmindParser.clear();

View File

@ -40,6 +40,9 @@ public class XmindCaseParser {
// 案例详情重写了hashCode方法去重用
private List<TestCaseExcelData> compartDatas;
// 记录没有用例的目录
private List<String> nodePaths;
public XmindCaseParser(TestCaseService testCaseService, String userId, String projectId, Set<String> testCaseNames) {
this.testCaseService = testCaseService;
this.maintainer = userId;
@ -48,6 +51,7 @@ public class XmindCaseParser {
testCases = new LinkedList<>();
compartDatas = new ArrayList<>();
process = new StringBuffer();
nodePaths = new ArrayList<>();
}
// 这里清理是为了 加快jvm 回收
@ -55,26 +59,55 @@ public class XmindCaseParser {
compartDatas.clear();
testCases.clear();
testCaseNames.clear();
nodePaths.clear();
}
public List<TestCaseWithBLOBs> getTestCase() {
return this.testCases;
}
public List<String> getNodePaths() {
return this.nodePaths;
}
private final Map<String, String> caseTypeMap = ImmutableMap.of("功能测试", "functional", "性能测试", "performance", "接口测试", "api");
public void validate() {
nodePaths.forEach(nodePath -> {
String[] nodes = nodePath.split("/");
if (nodes.length > TestCaseConstants.MAX_NODE_DEPTH + 1) {
process.append(Translator.get("test_case_node_level_tip") +
TestCaseConstants.MAX_NODE_DEPTH + Translator.get("test_case_node_level") + "; ");
}
for (int i = 0; i < nodes.length; i++) {
if (i != 0 && StringUtils.equals(nodes[i].trim(), "")) {
process.append(Translator.get("module_not_null") + "; ");
break;
}
}
});
}
// 递归处理案例数据
private void recursion(StringBuffer processBuffer, Attached parent, int level, String nodePath, List<Attached> attacheds) {
private void recursion(StringBuffer processBuffer, Attached parent, int level, List<Attached> attacheds) {
for (Attached item : attacheds) {
if (isAvailable(item.getTitle(), "(?:tc|tc:|tc)")) { // 用例
item.setParent(parent);
this.newTestCase(item.getTitle(), parent.getPath(), item.getChildren() != null ? item.getChildren().getAttached() : null);
} else {
nodePath = parent.getPath() + "/" + item.getTitle();
String nodePath = parent.getPath() + "/" + item.getTitle();
item.setPath(nodePath);
if (item.getChildren() != null && !item.getChildren().getAttached().isEmpty()) {
item.setParent(parent);
recursion(processBuffer, item, level + 1, nodePath, item.getChildren().getAttached());
if (item.getChildren() != null && !item.getChildren().getAttached().isEmpty()) {
recursion(processBuffer, item, level + 1, item.getChildren().getAttached());
} else {
if (!nodePath.startsWith("/")) {
nodePath = "/" + nodePath;
}
if (nodePath.endsWith("/")) {
nodePath = nodePath.substring(0, nodePath.length() - 1);
}
nodePaths.add(nodePath); // 没有用例的路径
}
}
}
@ -243,11 +276,12 @@ public class XmindCaseParser {
item.setPath(item.getTitle());
if (item.getChildren() != null && !item.getChildren().getAttached().isEmpty()) {
item.setPath(item.getTitle());
recursion(processBuffer, item, 1, item.getPath(), item.getChildren().getAttached());
recursion(processBuffer, item, 1, item.getChildren().getAttached());
}
}
}
}
this.validate();
} catch (Exception ex) {
processBuffer.append(Translator.get("incorrect_format"));
LogUtil.error(ex.getMessage());

View File

@ -12,7 +12,9 @@
<el-input :disabled="isReadOnly" v-model="form.cronValue" class="inp"
:placeholder="$t('schedule.please_input_cron_expression')"/>
<!-- <el-button type="primary" @click="showCronDialog">{{$t('schedule.generate_expression')}}</el-button>-->
<el-button :disabled="isReadOnly" type="primary" @click="saveCron">{{ $t('commons.save') }}</el-button>
<el-button :disabled="isReadOnly" type="primary" @click="saveCron">{{ $t('commons.save')
}}
</el-button>
</el-form-item>
<el-form-item>
<el-link :disabled="isReadOnly" type="primary" @click="showCronDialog">
@ -21,8 +23,10 @@
</el-form-item>
<crontab-result :ex="form.cronValue" ref="crontabResult"/>
</el-form>
<el-dialog width="60%" :title="$t('schedule.generate_expression')" :visible.sync="showCron" :modal="false">
<crontab @hide="showCron=false" @fill="crontabFill" :expression="schedule.value" ref="crontab"/>
<el-dialog width="60%" :title="$t('schedule.generate_expression')" :visible.sync="showCron"
:modal="false">
<crontab @hide="showCron=false" @fill="crontabFill" :expression="schedule.value"
ref="crontab"/>
</el-dialog>
</el-tab-pane>
<el-tab-pane :label="$t('schedule.task_notification')" name="second">
@ -42,11 +46,12 @@
<el-table-column
prop="name"
:label="$t('schedule.receiver')"
width="200"
width="240"
>
<template v-slot:default="{row}">
<el-select v-model="row.names" filterable multiple :placeholder="$t('commons.please_select')"
@click.native="userList()">
<el-select v-model="row.names" filterable multiple
:placeholder="$t('commons.please_select')"
@click.native="userList()" style="width: 100%;">
<el-option
v-for="item in options"
:key="item.id"
@ -88,16 +93,16 @@
<script>
import Crontab from "../cron/Crontab";
import CrontabResult from "../cron/CrontabResult";
import {cronValidate} from "@/common/js/cron";
import {listenGoBack, removeGoBackListener} from "@/common/js/utils";
import Crontab from "../cron/Crontab";
import CrontabResult from "../cron/CrontabResult";
import {cronValidate} from "@/common/js/cron";
import {listenGoBack, removeGoBackListener} from "@/common/js/utils";
function defaultCustomValidate() {
function defaultCustomValidate() {
return {pass: true};
}
}
export default {
export default {
name: "MsScheduleEdit",
components: {CrontabResult, Crontab},
props: {
@ -255,18 +260,24 @@ export default {
return time2 - time1;
}
}
}
}
</script>
<style scoped>
.inp {
.inp {
width: 50%;
margin-right: 20px;
}
}
.el-form-item {
.el-form-item {
margin-bottom: 10px;
}
}
/deep/ .el-select__tags {
flex-wrap: unset;
overflow: auto;
}
</style>