refactor(接口测试): 执行通知区分集合报告

This commit is contained in:
fit2-zhao 2024-01-18 10:36:47 +08:00 committed by Craftsman
parent 402e74c854
commit b29fa733e8
4 changed files with 43 additions and 13 deletions

View File

@ -1,6 +1,5 @@
package io.metersphere.sdk.dto.api.notice; package io.metersphere.sdk.dto.api.notice;
import io.metersphere.sdk.constants.ApiExecuteResourceType;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@ -13,13 +12,40 @@ import java.io.Serial;
public class ApiNoticeDTO implements java.io.Serializable { public class ApiNoticeDTO implements java.io.Serializable {
@Serial @Serial
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/**
private ApiExecuteResourceType resourceType; * 资源类型
*/
private String resourceType;
/**
* 资源ID
*/
private String resourceId; private String resourceId;
/**
* 报告状态
*/
private String reportStatus; private String reportStatus;
/**
* 用户ID
*/
private String userId; private String userId;
/**
* 项目ID
*/
private String projectId; private String projectId;
/**
* 环境ID
*/
private String environmentId; private String environmentId;
/**
* 报告ID
*/
private String reportId; private String reportId;
/**
* 队列ID
*/
private String queueId; private String queueId;
/**
* 报告类型
*/
private String reportType;
} }

View File

@ -3,6 +3,7 @@ package io.metersphere.api.listener;
import io.metersphere.api.event.ApiEventSource; import io.metersphere.api.event.ApiEventSource;
import io.metersphere.api.service.ApiReportSendNoticeService; import io.metersphere.api.service.ApiReportSendNoticeService;
import io.metersphere.api.service.queue.ApiExecutionQueueService; import io.metersphere.api.service.queue.ApiExecutionQueueService;
import io.metersphere.sdk.constants.ApiReportType;
import io.metersphere.sdk.constants.ApplicationScope; import io.metersphere.sdk.constants.ApplicationScope;
import io.metersphere.sdk.constants.KafkaTopicConstants; import io.metersphere.sdk.constants.KafkaTopicConstants;
import io.metersphere.sdk.dto.api.notice.ApiNoticeDTO; import io.metersphere.sdk.dto.api.notice.ApiNoticeDTO;
@ -11,6 +12,7 @@ import io.metersphere.sdk.util.JSON;
import io.metersphere.sdk.util.LogUtils; import io.metersphere.sdk.util.LogUtils;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.kafka.clients.consumer.ConsumerRecord; import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.annotation.KafkaListener; import org.springframework.kafka.annotation.KafkaListener;
@ -33,12 +35,15 @@ public class MessageListener {
LogUtils.info("接收到发送通知信息:", record.key()); LogUtils.info("接收到发送通知信息:", record.key());
if (ObjectUtils.isNotEmpty(record.value())) { if (ObjectUtils.isNotEmpty(record.value())) {
ApiNoticeDTO dto = JSON.parseObject(record.value(), ApiNoticeDTO.class); ApiNoticeDTO dto = JSON.parseObject(record.value(), ApiNoticeDTO.class);
apiReportSendNoticeService.sendNotice(dto);
// TODO 通知测试计划处理后续 // 集合报告不发送通知
LogUtils.info("发送通知给测试计划:", record.key()); if (!StringUtils.equalsIgnoreCase(dto.getReportType(), ApiReportType.INTEGRATED.name())) {
apiEventSource.fireEvent(ApplicationScope.API_TEST, record.value()); apiReportSendNoticeService.sendNotice(dto);
// TODO 通知测试计划处理后续
LogUtils.info("发送通知给测试计划:", record.key());
apiEventSource.fireEvent(ApplicationScope.API_TEST, record.value());
}
// TODO 串行触发下次执行 // TODO 串行触发下次执行
ExecutionQueueDetail detail = apiExecutionQueueService.getNextDetail(dto.getQueueId()); ExecutionQueueDetail detail = apiExecutionQueueService.getNextDetail(dto.getQueueId());
// TODO 调用执行方法 // TODO 调用执行方法

View File

@ -8,7 +8,6 @@ import io.metersphere.api.mapper.ApiScenarioMapper;
import io.metersphere.api.mapper.ApiTestCaseMapper; import io.metersphere.api.mapper.ApiTestCaseMapper;
import io.metersphere.project.domain.Project; import io.metersphere.project.domain.Project;
import io.metersphere.project.mapper.ProjectMapper; import io.metersphere.project.mapper.ProjectMapper;
import io.metersphere.sdk.constants.ApiExecuteResourceType;
import io.metersphere.sdk.constants.ApiReportStatus; import io.metersphere.sdk.constants.ApiReportStatus;
import io.metersphere.sdk.domain.Environment; import io.metersphere.sdk.domain.Environment;
import io.metersphere.sdk.dto.api.notice.ApiNoticeDTO; import io.metersphere.sdk.dto.api.notice.ApiNoticeDTO;
@ -55,13 +54,13 @@ public class ApiReportSendNoticeService {
BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo(); BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo();
BeanMap beanMap; BeanMap beanMap;
switch (noticeDTO.getResourceType()) { switch (noticeDTO.getResourceType()) {
case ApiExecuteResourceType.API_SCENARIO: case "API_SCENARIO":
ApiScenario scenario = apiScenarioMapper.selectByPrimaryKey(noticeDTO.getResourceId()); ApiScenario scenario = apiScenarioMapper.selectByPrimaryKey(noticeDTO.getResourceId());
beanMap = new BeanMap(scenario); beanMap = new BeanMap(scenario);
noticeType = NoticeConstants.TaskType.API_SCENARIO_TASK; noticeType = NoticeConstants.TaskType.API_SCENARIO_TASK;
reportUrl = baseSystemConfigDTO.getUrl() + "/#/api/automation/report/view/" + noticeDTO.getReportId(); reportUrl = baseSystemConfigDTO.getUrl() + "/#/api/automation/report/view/" + noticeDTO.getReportId();
break; break;
case ApiExecuteResourceType.API: case "API":
ApiDefinition definition = apiDefinitionMapper.selectByPrimaryKey(noticeDTO.getResourceId()); ApiDefinition definition = apiDefinitionMapper.selectByPrimaryKey(noticeDTO.getResourceId());
beanMap = new BeanMap(definition); beanMap = new BeanMap(definition);
noticeType = NoticeConstants.TaskType.API_DEFINITION_TASK; noticeType = NoticeConstants.TaskType.API_DEFINITION_TASK;

View File

@ -26,7 +26,7 @@ public class MessageListenerTest {
ApiNoticeDTO api = new ApiNoticeDTO(); ApiNoticeDTO api = new ApiNoticeDTO();
// Set values for the fields // Set values for the fields
api.setResourceType(ApiExecuteResourceType.API); api.setResourceType(ApiExecuteResourceType.API.name());
api.setResourceId("exampleResourceId"); api.setResourceId("exampleResourceId");
api.setReportStatus("exampleReportStatus"); api.setReportStatus("exampleReportStatus");
api.setUserId("exampleUserId"); api.setUserId("exampleUserId");
@ -42,7 +42,7 @@ public class MessageListenerTest {
ApiNoticeDTO scenario = new ApiNoticeDTO(); ApiNoticeDTO scenario = new ApiNoticeDTO();
// Set values for the fields // Set values for the fields
scenario.setResourceType(ApiExecuteResourceType.API); scenario.setResourceType(ApiExecuteResourceType.API.name());
scenario.setResourceId("exampleResourceId"); scenario.setResourceId("exampleResourceId");
scenario.setReportStatus("exampleReportStatus"); scenario.setReportStatus("exampleReportStatus");
scenario.setUserId("exampleUserId"); scenario.setUserId("exampleUserId");
@ -58,7 +58,7 @@ public class MessageListenerTest {
ApiNoticeDTO testCase = new ApiNoticeDTO(); ApiNoticeDTO testCase = new ApiNoticeDTO();
// Set values for the fields // Set values for the fields
testCase.setResourceType(ApiExecuteResourceType.API); testCase.setResourceType(ApiExecuteResourceType.API.name());
testCase.setResourceId("exampleResourceId"); testCase.setResourceId("exampleResourceId");
testCase.setReportStatus("exampleReportStatus"); testCase.setReportStatus("exampleReportStatus");
testCase.setUserId("exampleUserId"); testCase.setUserId("exampleUserId");