fix: 添加评审和报告链接,增加性能测试通知功能

This commit is contained in:
wenyann 2020-09-25 11:02:24 +08:00
parent cc364cf1fc
commit 761ceaf186
18 changed files with 139 additions and 60 deletions

View File

@ -3,7 +3,7 @@ package io.metersphere.api.jmeter;
import io.metersphere.api.service.APIReportService;
import io.metersphere.api.service.APITestService;
import io.metersphere.base.domain.ApiTestReport;
import io.metersphere.base.domain.Notice;
import io.metersphere.base.domain.NoticeDetail;
import io.metersphere.commons.constants.APITestStatus;
import io.metersphere.commons.constants.ApiRunMode;
import io.metersphere.commons.utils.CommonBeanFactory;
@ -16,7 +16,6 @@ import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.visualizers.backend.AbstractBackendListenerClient;
import org.apache.jmeter.visualizers.backend.BackendListenerContext;
import javax.annotation.Resource;
import java.io.Serializable;
import java.util.*;
@ -120,17 +119,17 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
queue.clear();
super.teardownTest(context);
NoticeService noticeService = CommonBeanFactory.getBean(NoticeService.class);
List<Notice> notice = null;
List<NoticeDetail> notice = null;
try {
notice = noticeService.queryNotice(testResult.getTestId());
} catch (Exception e) {
e.printStackTrace();
LogUtil.error(e);
}
MailService mailService = CommonBeanFactory.getBean(MailService.class);
try {
mailService.sendHtml(report.getId(), notice, report.getStatus(), "api");
} catch (Exception e) {
e.printStackTrace();
LogUtil.error(e);
}
}

View File

@ -1,8 +1,9 @@
package io.metersphere.base.domain;
import java.io.Serializable;
import lombok.Data;
import java.io.Serializable;
@Data
public class Notice implements Serializable {
private String event;
@ -15,9 +16,5 @@ public class Notice implements Serializable {
private String enable;
private String[] names;
private String[] emails;
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,20 @@
package io.metersphere.base.domain;
import lombok.Data;
@Data
public class NoticeDetail extends Notice {
private String[] names;
private String[] emails;
private String event;
private String testId;
private String name;
private String email;
private String enable;
}

View File

@ -1,8 +1,7 @@
package io.metersphere.notice.controller;
import io.metersphere.base.domain.Notice;
import io.metersphere.base.domain.NoticeDetail;
import io.metersphere.notice.controller.request.NoticeRequest;
import io.metersphere.notice.service.MailService;
import io.metersphere.notice.service.NoticeService;
import org.springframework.web.bind.annotation.*;
@ -21,7 +20,7 @@ public class NoticeController {
}
@GetMapping("/query/{testId}")
public List<Notice> queryNotice(@PathVariable String testId) {
public List<NoticeDetail> queryNotice(@PathVariable String testId) {
return noticeService.queryNotice(testId);
}

View File

@ -1,12 +1,13 @@
package io.metersphere.notice.controller.request;
import io.metersphere.base.domain.Notice;
import io.metersphere.base.domain.NoticeDetail;
import lombok.Data;
import java.util.List;
@Data
public class NoticeRequest extends Notice {
public class NoticeRequest extends NoticeDetail {
private String testId;
private List<Notice> notices;
private List<NoticeDetail> notices;
}

View File

@ -1,12 +1,13 @@
package io.metersphere.notice.service;
import io.metersphere.api.dto.APIReportResult;
import io.metersphere.base.domain.Notice;
import io.metersphere.base.domain.NoticeDetail;
import io.metersphere.base.domain.SystemParameter;
import io.metersphere.base.domain.TestCaseWithBLOBs;
import io.metersphere.commons.constants.ParamConstants;
import io.metersphere.commons.utils.EncryptUtils;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.dto.BaseSystemConfigDTO;
import io.metersphere.dto.LoadTestDTO;
import io.metersphere.i18n.Translator;
import io.metersphere.service.SystemParameterService;
@ -37,7 +38,9 @@ public class MailService {
@Resource
private SystemParameterService systemParameterService;
public void sendHtml(String id, List<Notice> notice, String status, String type) {
public void sendHtml(String id, List<NoticeDetail> notice, String status, String type) {
BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo();
JavaMailSenderImpl javaMailSender = getMailSender();
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
String testName = "";
@ -47,16 +50,19 @@ public class MailService {
} else if (type.equals("performance")) {
LoadTestDTO performanceResult = apiAndPerformanceHelper.getPerformance(id);
testName = performanceResult.getName();
status = performanceResult.getStatus();
}
Map<String, String> context = new HashMap<>();
context.put("title", type + Translator.get("timing_task_result_notification"));
context.put("testName", testName);
context.put("url", baseSystemConfigDTO.getUrl());
context.put("id", id);
context.put("type", type);
try {
String failTemplate = IOUtils.toString(this.getClass().getResource("/mail/fail.html"), StandardCharsets.UTF_8);
String successTemplate = IOUtils.toString(this.getClass().getResource("/mail/success.html"), StandardCharsets.UTF_8);
String successPerformanceTemplate = IOUtils.toString(this.getClass().getResource("/mail/successPerformance.html"), StandardCharsets.UTF_8);
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
helper.setFrom(javaMailSender.getUsername());
@ -65,7 +71,7 @@ public class MailService {
List<String> successEmailList = new ArrayList<>();
List<String> failEmailList = new ArrayList<>();
if (notice.size() > 0) {
for (Notice n : notice) {
for (NoticeDetail n : notice) {
if (n.getEnable().equals("true") && n.getEvent().equals("执行成功")) {
successEmailList = userService.queryEmail(n.getNames());
}
@ -80,6 +86,9 @@ public class MailService {
if (status.equals("Success")) {
users = successEmailList.toArray(new String[0]);
helper.setText(getContent(successTemplate, context), true);
} else if (status.equals("Starting") && type.equals("performance")) {
users = successEmailList.toArray(new String[0]);
helper.setText(getContent(successPerformanceTemplate, context), true);
} else {
users = failEmailList.toArray(new String[0]);
helper.setText(getContent(failTemplate, context), true);
@ -108,6 +117,7 @@ public class MailService {
public void sendHtml(List<String> userIds, String type, SaveTestCaseReviewRequest reviewRequest, SaveCommentRequest request, TestCaseWithBLOBs testCaseWithBLOBs) {
BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo();
Long startTime = reviewRequest.getCreateTime();
Long endTime = reviewRequest.getEndTime();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@ -132,6 +142,8 @@ public class MailService {
context.put("description", request.getDescription());
context.put("start", start);
context.put("end", end);
context.put("url", baseSystemConfigDTO.getUrl());
context.put("id", reviewRequest.getId());
try {
String reviewerTemplate = IOUtils.toString(this.getClass().getResource("/mail/reviewer.html"), StandardCharsets.UTF_8);

View File

@ -1,15 +1,14 @@
package io.metersphere.notice.service;
import io.metersphere.base.domain.Notice;
import io.metersphere.base.domain.NoticeDetail;
import io.metersphere.base.domain.NoticeExample;
import io.metersphere.base.mapper.NoticeMapper;
import io.metersphere.notice.controller.request.NoticeRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@Service
@ -66,17 +65,17 @@ public class NoticeService {
}
}
public List<Notice> queryNotice(String id) {
public List<NoticeDetail> queryNotice(String id) {
NoticeExample example = new NoticeExample();
example.createCriteria().andTestIdEqualTo(id);
List<Notice> notices = noticeMapper.selectByExample(example);
List<Notice> notice = new ArrayList<>();
List<NoticeDetail> notice = new ArrayList<>();
List<String> success = new ArrayList<>();
List<String> fail = new ArrayList<>();
String[] successArray = new String[success.size()];
String[] failArray = new String[fail.size()];
Notice notice1 = new Notice();
Notice notice2 = new Notice();
NoticeDetail notice1 = new NoticeDetail();
NoticeDetail notice2 = new NoticeDetail();
if (notices.size() > 0) {
for (Notice n : notices) {
if (n.getEvent().equals("执行成功")) {

View File

@ -237,19 +237,6 @@ public class PerformanceTestService {
}
startEngine(loadTest, engine, request.getTriggerMode());
/* if (request.getTriggerMode().equals("SCHEDULE")) {
List<Notice> notice = null;
try {
notice = noticeService.queryNotice(request.getId());
} catch (Exception e) {
e.printStackTrace();
}
try {
mailService.sendHtml(engine.getReportId(), notice, "status", "performance");
} catch (Exception e) {
e.printStackTrace();
}
}*/
return engine.getReportId();
}
@ -317,6 +304,19 @@ public class PerformanceTestService {
reportResult.setReportKey(ReportKeys.ResultStatus.name());
reportResult.setReportValue("Ready"); // 初始化一个 result_status, 这个值用在data-streaming中
loadTestReportResultMapper.insertSelective(reportResult);
if (triggerMode.equals("SCHEDULE")) {
List<NoticeDetail> notice = null;
try {
notice = noticeService.queryNotice(loadTest.getId());
} catch (Exception e) {
LogUtil.error(e);
}
try {
mailService.sendHtml(engine.getReportId(), notice, loadTest.getStatus(), "performance");
} catch (Exception e) {
LogUtil.error(e);
}
}
} catch (MSException e) {
LogUtil.error(e);
loadTest.setStatus(PerformanceTestStatus.Error.name());

View File

@ -155,5 +155,5 @@ email_subject=Metersphere timing task result notification
import_xmind_count_error=The number of use cases imported into the mind map cannot exceed 500
import_xmind_not_found=Test case not found
license_valid_license_error=Authorization authentication failed
timing_task_result_notification="Timing task result notification"
test_review_task_notice="Test review task notice"
timing_task_result_notification=Timing task result notification
test_review_task_notice=Test review task notice

View File

@ -155,7 +155,7 @@ email_subject=MeterSphere定时任务结果通知
import_xmind_count_error=思维导图导入用例数量不能超过 500 条
license_valid_license_error=授权认证失败
import_xmind_not_found=未找到测试用例
timing_task_result_notification="定时任务结果通知"
test_review_task_notice="测试评审任务通知"
timing_task_result_notification=定时任务结果通知
test_review_task_notice=测试评审任务通知

View File

@ -156,5 +156,5 @@ license_valid_license_code=授權碼已經存在
email_subject=MeterSphere定時任務結果通知
import_xmind_count_error=思維導圖導入用例數量不能超過 500 條
import_xmind_not_found=未找到测试用例
timing_task_result_notification="定時任務結果通知"
test_review_task_notice="測試評審任務通知"
timing_task_result_notification=定時任務結果通知
test_review_task_notice=測試評審任務通知

View File

@ -4,9 +4,13 @@
<meta charset="UTF-8">
<title>MeterSphere</title>
</head>
<body style="text-align: left">
<body>
<div>
<p>${maintainer} 发起的</p><br/> ${testCaseName} </p><br/>添加评论:${description} </p>
<p style="text-align: left"> ${maintainer} 发起的<br/>
${testCaseName}<br/>
添加评论:${description}<br/>
点击下面链接进入用例评审页面</p>
<a href="${url}/#/track/review/view">${url}/#/track/review/view</a>
</div>
</body>
</html>

View File

@ -4,9 +4,15 @@
<meta charset="UTF-8">
<title>MeterSphere</title>
</head>
<body style="text-align: left">
<body>
<div>
<p>${creator} 发起的:</p><br/>${reviewName} </p><br/>计划开始时间是 ${start}, 计划结束时间为 ${end} 已完成</p>
<p style="text-align: left">${creator} 发起的:<br>
${reviewName}<br>
计划开始时间是:${start}<br>
计划结束时间为:${end}<br>
已完成<br>
点击下面链接进入用例评审页面</p>
<a href="${url}/#/track/review/view">${url}/#/track/review/view</a>
</div>
</body>
</html>

View File

@ -4,12 +4,21 @@
<meta charset="UTF-8">
<title>MeterSphere</title>
</head>
<body style="text-align: left">
<body>
<div>
<h3>${title}</h3>
<p>尊敬的用户:您好,
<p><br/>
<p>您所执行的 ${testName} 运行失败</p>
<div style="text-align: left">
<h3>${title}</h3>
</div>
<div style="text-align: left">
<p>尊敬的用户:</p>
<p style="margin-left: 60px">您好:
</div>
<div style="margin-left: 100px">
<p>您所执行的 ${testName} 运行失败<br/>
请点击下面链接进入测试报告页面</p>
<a href="${url}/#/${type}/report/view/${id}">${url}/#/${type}/report/view/${id}</a>
</div>
</div>
</body>
</html>

View File

@ -4,9 +4,15 @@
<meta charset="UTF-8">
<title>MeterSphere</title>
</head>
<body style="text-align: left">
<body>
<div>
<p>${creator} 发起的:</p><br/>${reviewName} </p><br/>计划开始时间是 ${start},计划结束时间为 ${end} 请跟进</p>
<p style="text-align: left">${creator} 发起的:<br>
${reviewName}<br>
计划开始时间是:${start}<br>
计划结束时间为:${end}<br>
请跟进<br>
点击下面链接进入评审页面进行审核</p>
<a href="${url}/#/track/review/view/${id}">${url}/#/track/review/view/${id}</a>
</div>
</body>
</html>

View File

@ -5,11 +5,17 @@
<title>MeterSphere</title>
</head>
<body style="text-align: left">
<div>
<div style="text-align: left">
<h3>${title}</h3>
<p>尊敬的用户:您好,
<p><br/>
<p>您所执行的 ${testName} 运行成功</p>
</div>
<div style="text-align: left">
<p>尊敬的用户:</p>
<p style="margin-left: 60px">您好:
</div>
<div style="margin-left: 100px">
<p>您所执行的 ${testName} 运行成功<br/>
请点击下面链接进入测试报告页面</p>
<a href="${url}/#/${type}/report/view/${id}">${url}/#/${type}/report/view/${id}</a>
</div>
</body>
</html>

View File

@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>MeterSphere</title>
</head>
<body style="text-align: left">
<div style="text-align: left">
<h3>${title}</h3>
</div>
<div style="text-align: left">
<p>尊敬的用户:</p>
<p style="margin-left: 60px">您好:
</div>
<div style="margin-left: 100px">
<p>您所执行的 ${testName} 性能测试已完成<br/>
请点击下面链接进入测试报告页面</p>
<a href="${url}/#/${type}/report/view/${id}">${url}/#/${type}/report/view/${id}</a>
</div>
</body>
</html>