fix:定时,jenkins场景执行发消息报错

This commit is contained in:
wenyann 2021-04-25 17:55:11 +08:00 committed by 刘瑞斌
parent 7f33a80ad7
commit 7d9d958fcf
6 changed files with 33 additions and 25 deletions

View File

@ -237,7 +237,7 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
TestPlanApiCase testPlanApiCase = testPlanApiCaseService.getInfo(testResult.getTestId(), debugReportId); TestPlanApiCase testPlanApiCase = testPlanApiCaseService.getInfo(testResult.getTestId(), debugReportId);
String name = apiAutomationService.get(testPlanApiCase.getEnvironmentId()).getName(); String name = apiAutomationService.get(testPlanApiCase.getEnvironmentId()).getName();
//时间 //时间
Long time = apiTestCaseWithBLOBs.getUpdateTime(); Long time = apiTestCaseWithBLOBs.getCreateTime();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String executionTime = null; String executionTime = null;
String time_ = String.valueOf(time); String time_ = String.valueOf(time);
@ -250,8 +250,13 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
//报告内容 //报告内容
reportTask = new ApiTestReportVariable(); reportTask = new ApiTestReportVariable();
if (null != apiResult) {
reportTask.setStatus(apiResult.getStatus()); reportTask.setStatus(apiResult.getStatus());
reportTask.setId(apiResult.getId()); reportTask.setId(apiResult.getId());
} else {
reportTask.setStatus(testPlanApiCase.getStatus());
reportTask.setId(testPlanApiCase.getId());
}
reportTask.setTriggerMode("API"); reportTask.setTriggerMode("API");
reportTask.setName(apiTestCaseWithBLOBs.getName()); reportTask.setName(apiTestCaseWithBLOBs.getName());
reportTask.setExecutor(userName); reportTask.setExecutor(userName);
@ -280,22 +285,24 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
ApiScenarioWithBLOBs apiScenario = apiAutomationService.getDto(scenarioReport.getScenarioId()); ApiScenarioWithBLOBs apiScenario = apiAutomationService.getDto(scenarioReport.getScenarioId());
String executionEnvironment = apiScenario.getScenarioDefinition(); String executionEnvironment = apiScenario.getScenarioDefinition();
JSONObject json = JSONObject.parseObject(executionEnvironment); JSONObject json = JSONObject.parseObject(executionEnvironment);
String name = "";
if (json.getString("environmentMap").length() > 0) {
JSONObject environment = JSONObject.parseObject(json.getString("environmentMap")); JSONObject environment = JSONObject.parseObject(json.getString("environmentMap"));
String environmentId = environment.get(apiScenario.getProjectId()).toString(); String environmentId = environment.get(apiScenario.getProjectId()).toString();
String name = apiAutomationService.get(environmentId).getName(); name = apiAutomationService.get(environmentId).getName();
}
//时间 //时间
Long time = apiScenario.getUpdateTime(); Long time = scenarioReport.getUpdateTime();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String executionTime = null; String executionTime = null;
String time_ = String.valueOf(time); String time_ = String.valueOf(time);
if (!time_.equals("null")) { if (!time_.equals("null")) {
executionTime = sdf.format(new Date(Long.parseLong(time_))); executionTime = sdf.format(new Date(Long.parseLong(time_)));
} }
//执行人 //执行人
String userName = apiAutomationService.getUser(apiScenario.getUserId()).getName(); String userName = apiAutomationService.getUser(apiScenario.getUserId()).getName();
//报告内容 //报告内容
reportTask = new ApiTestReportVariable(); reportTask = new ApiTestReportVariable();
reportTask.setStatus(scenarioReport.getStatus()); reportTask.setStatus(scenarioReport.getStatus());
@ -309,7 +316,6 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
assert systemParameterService != null; assert systemParameterService != null;
BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo(); BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo();
reportUrl = baseSystemConfigDTO.getUrl() + "/#/api/automation/report"; reportUrl = baseSystemConfigDTO.getUrl() + "/#/api/automation/report";
testResult.setTestId(scenarioReport.getScenarioId()); testResult.setTestId(scenarioReport.getScenarioId());
} else { } else {
apiTestService.changeStatus(testId, APITestStatus.Completed); apiTestService.changeStatus(testId, APITestStatus.Completed);

View File

@ -41,6 +41,7 @@ public class ApiDefinitionExecResultService {
private ApiTestCaseMapper apiTestCaseMapper; private ApiTestCaseMapper apiTestCaseMapper;
@Resource @Resource
private TestCaseReviewApiCaseService testCaseReviewApiCaseService; private TestCaseReviewApiCaseService testCaseReviewApiCaseService;
@Resource @Resource
SqlSessionFactory sqlSessionFactory; SqlSessionFactory sqlSessionFactory;

View File

@ -116,6 +116,7 @@ public class TestPlanScenarioCaseService {
request.setRunMode(ApiRunMode.SCENARIO_PLAN.name()); request.setRunMode(ApiRunMode.SCENARIO_PLAN.name());
request.setId(testPlanScenarioRequest.getId()); request.setId(testPlanScenarioRequest.getId());
request.setExecuteType(ExecuteType.Saved.name()); request.setExecuteType(ExecuteType.Saved.name());
request.setTriggerMode(testPlanScenarioRequest.getTriggerMode());
return apiAutomationService.run(request); return apiAutomationService.run(request);
} }

View File

@ -178,7 +178,7 @@ export default {
' 请点击下面链接进入测试报告页面</p>\n' + ' 请点击下面链接进入测试报告页面</p>\n' +
' <a href="${url}/#/${type}/report/view/${id}">${url}/#/${type}/report/view/${id}</a>\n' + ' <a href="${url}/#/${type}/report/view/${id}">${url}/#/${type}/report/view/${id}</a>\n' +
' <p>新版接口测试报告路径</p>\n' + ' <p>新版接口测试报告路径</p>\n' +
' <a href="${url}/#/api/automation">${url}/#/api/automation</a>\n' + ' <a href="${url}/#/api/automation/report/view/">${url}/#/api/automation/report/view/${id}</a>\n' +
' </div>\n' + ' </div>\n' +
'\n' + '\n' +
'</div>\n' + '</div>\n' +
@ -186,12 +186,12 @@ export default {
'</html>', '</html>',
robotTitle: robotTitle:
"测试【任务通知】:'${executor}所执行的 ${testName} ${type}测试运行${status}\n" + "测试【任务通知】:'${executor}所执行的 ${testName} ${type}测试运行${status}\n" +
"测试环境为:${executionEnvironment}," + "测试环境为:${executionEnvironment}\n" +
"执行时间:${executionTime}\n" + "执行时间:${executionTime}\n" +
"请点击下面链接进入测试报告页面\n" + "请点击下面链接进入测试报告页面\n" +
"${url}/#/${type}/report/view/${id}" + "${url}/#/${type}/report/view/${id}" +
"新版接口测试报告路径\n" + "新版接口测试报告路径\n" +
"${url}/#/api/automation", "${url}/#/api/automation/report/view/${id}",
scheduleTask: [{ scheduleTask: [{
taskType: "scheduleTask", taskType: "scheduleTask",
event: "", event: "",

View File

@ -177,20 +177,20 @@ export default {
' 请点击下面链接进入测试报告页面</p>\n' + ' 请点击下面链接进入测试报告页面</p>\n' +
' <a href="${url}/#/${type}/report/view/${id}">${url}/#/${type}/report/view/${id}</a>\n' + ' <a href="${url}/#/${type}/report/view/${id}">${url}/#/${type}/report/view/${id}</a>\n' +
' <p>新版接口测试报告路径</p>\n' + ' <p>新版接口测试报告路径</p>\n' +
' <a href="${url}/#/api/automation">${url}/#/api/automation</a>\n' + ' <a href="${url}/#/api/automation/report/view/">${url}/#/api/automation/report/view/${id}</a>\n' +
' </div>\n' + ' </div>\n' +
'\n' + '\n' +
'</div>\n' + '</div>\n' +
'</body>\n' + '</body>\n' +
'</html>', '</html>',
robotTitle: robotTitle:
"测试【任务通知】:'${executor}所执行的 ${testName} ${type}测试运行${status}," + "测试【任务通知】:'${executor}所执行的 ${testName} ${type}测试运行${status}\n" +
"测试环境为:${executionEnvironment}," + "测试环境为:${executionEnvironment}\n" +
"执行时间:${executionTime}\n" + "执行时间:${executionTime}\n" +
"请点击下面链接进入测试报告页面\n" + "请点击下面链接进入测试报告页面\n" +
"${url}/#/${type}/report/view/${id}" + "${url}/#/${type}/report/view/${id}" +
"新版接口测试报告路径\n" + "新版接口测试报告路径\n" +
"${url}/#/api/automation", "${url}/#/api/automation/report/view/${id}",
jenkinsTask: [{ jenkinsTask: [{
taskType: "jenkinsTask", taskType: "jenkinsTask",
event: "", event: "",

View File

@ -178,20 +178,20 @@ export default {
' 请点击下面链接进入测试报告页面</p>\n' + ' 请点击下面链接进入测试报告页面</p>\n' +
' <a href="${url}/#/${type}/report/view/${id}">${url}/#/${type}/report/view/${id}</a>\n' + ' <a href="${url}/#/${type}/report/view/${id}">${url}/#/${type}/report/view/${id}</a>\n' +
' <p>新版接口测试报告路径</p>\n' + ' <p>新版接口测试报告路径</p>\n' +
' <a href="${url}/#/api/automation">${url}/#/api/automation</a>\n' + ' <a href="${url}/#/api/automation/report/view/">${url}/#/api/automation/report/view/${id}</a>\n' +
' </div>\n' + ' </div>\n' +
'\n' + '\n' +
'</div>\n' + '</div>\n' +
'</body>\n' + '</body>\n' +
'</html>', '</html>',
robotTitle: robotTitle:
"测试【任务通知】:'${executor}所执行的 ${testName} ${type}测试运行${status}," + "测试【任务通知】:'${executor}所执行的 ${testName} ${type}测试运行${status}," + "\n" +
"测试环境为:${executionEnvironment}," + "测试环境为:${executionEnvironment}" + "\n" +
"执行时间:${executionTime}\n" + "执行时间:${executionTime}" + "\n" +
"请点击下面链接进入测试报告页面\n" + "请点击下面链接进入测试报告页面" + "\n" +
"${url}/#/${type}/report/view/${id}" + "${url}/#/${type}/report/view/${id}" + "\n" +
"新版接口测试报告路径\n" + "新版接口测试报告路径" + "\n" +
"${url}/#/api/automation", "${url}/#/api/automation/report/view/${id}",
scheduleTask: [{ scheduleTask: [{
taskType: "scheduleTask", taskType: "scheduleTask",
event: "", event: "",