refactor(接口测试): 优化映射标签名称避免和源数据冲突

This commit is contained in:
fit2-zhao 2023-10-26 16:52:28 +08:00 committed by Craftsman
parent cd31a793be
commit d6aff9f192
9 changed files with 19 additions and 34 deletions

View File

@ -1,6 +1,6 @@
package io.metersphere.listener; package io.metersphere.listener;
import io.metersphere.api.event.APIEventSource; import io.metersphere.api.event.ApiEventSource;
import io.metersphere.plan.listener.ExecEventListener; import io.metersphere.plan.listener.ExecEventListener;
import io.metersphere.system.service.PluginLoadService; import io.metersphere.system.service.PluginLoadService;
import io.metersphere.sdk.util.CommonBeanFactory; import io.metersphere.sdk.util.CommonBeanFactory;
@ -21,7 +21,7 @@ public class AppStartListener implements ApplicationRunner {
LogUtils.info("================= 应用启动 ================="); LogUtils.info("================= 应用启动 =================");
// 注册所有监听源 // 注册所有监听源
LogUtils.info("初始化接口事件源"); LogUtils.info("初始化接口事件源");
APIEventSource apiEventSource = CommonBeanFactory.getBean(APIEventSource.class); ApiEventSource apiEventSource = CommonBeanFactory.getBean(ApiEventSource.class);
LogUtils.info("初始化性能测试事件源"); LogUtils.info("初始化性能测试事件源");
//LoadEventSource loadEventSource = CommonBeanFactory.getBean(LoadEventSource.class); //LoadEventSource loadEventSource = CommonBeanFactory.getBean(LoadEventSource.class);
//todo: 注册其他事件源 //todo: 注册其他事件源

View File

@ -14,15 +14,12 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
@Data @Data
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "polymorphicName")
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
public abstract class TestElementDTO implements Serializable { public abstract class TestElementDTO implements Serializable {
@Serial @Serial
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
// 组件类型
private String type;
// 当前组件唯一标示 // 当前组件唯一标示
private String uuid; private String uuid;
@ -41,18 +38,6 @@ public abstract class TestElementDTO implements Serializable {
// 子组件 // 子组件
private LinkedList<TestElementDTO> children; private LinkedList<TestElementDTO> children;
/**
* 预加载数据
*/
public void preload(List<TestElementDTO> children, BaseConfigDTO config) throws Exception {
PluginLogUtils.info("TestElementDTO preload");
if (children != null && !children.isEmpty()) {
for (TestElementDTO el : children) {
el.preload(el.children, config);
}
}
}
/** /**
* 自组件重新这个方法 * 自组件重新这个方法
*/ */

View File

@ -1,8 +1,8 @@
package io.metersphere.api.controller; package io.metersphere.api.controller;
import io.metersphere.api.dto.definition.ApiDefinitionDTO; import io.metersphere.api.dto.definition.ApiDefinitionDTO;
import io.metersphere.api.service.APIDefinitionLogService; import io.metersphere.api.service.ApiDefinitionLogService;
import io.metersphere.api.service.APIDefinitionService; import io.metersphere.api.service.ApiDefinitionService;
import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.system.log.annotation.Log; import io.metersphere.system.log.annotation.Log;
import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.log.constants.OperationLogType;
@ -22,12 +22,12 @@ import java.util.List;
@RequestMapping(value = "/api/definition") @RequestMapping(value = "/api/definition")
public class ApiDefinitionController { public class ApiDefinitionController {
@Resource @Resource
private APIDefinitionService apiDefinitionService; private ApiDefinitionService apiDefinitionService;
@PostMapping(value = "/add", consumes = MediaType.APPLICATION_JSON_VALUE) @PostMapping(value = "/add", consumes = MediaType.APPLICATION_JSON_VALUE)
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_READ_ADD_API) @RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_READ_ADD_API)
// 添加接口Log示例 // 添加接口Log示例
@Log(type = OperationLogType.ADD, expression = "#msClass.addLog(#request)", msClass = APIDefinitionLogService.class) @Log(type = OperationLogType.ADD, expression = "#msClass.addLog(#request)", msClass = ApiDefinitionLogService.class)
public ApiDefinitionDTO add(@Validated({Created.class}) @RequestBody ApiDefinitionDTO request, public ApiDefinitionDTO add(@Validated({Created.class}) @RequestBody ApiDefinitionDTO request,
@RequestParam(value = "files") List<MultipartFile> bodyFiles) { @RequestParam(value = "files") List<MultipartFile> bodyFiles) {
return apiDefinitionService.create(request, bodyFiles); return apiDefinitionService.create(request, bodyFiles);
@ -36,7 +36,7 @@ public class ApiDefinitionController {
@PostMapping(value = "/update", consumes = MediaType.APPLICATION_JSON_VALUE) @PostMapping(value = "/update", consumes = MediaType.APPLICATION_JSON_VALUE)
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_READ_ADD_API) @RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_READ_ADD_API)
// 添加修改Log示例 // 添加修改Log示例
@Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#request)", msClass = APIDefinitionLogService.class) @Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#request)", msClass = ApiDefinitionLogService.class)
public ApiDefinitionDTO update(@Validated({Updated.class}) @RequestBody ApiDefinitionDTO request) { public ApiDefinitionDTO update(@Validated({Updated.class}) @RequestBody ApiDefinitionDTO request) {
return request; return request;
} }
@ -44,20 +44,20 @@ public class ApiDefinitionController {
@PostMapping(value = "/batch-update", consumes = MediaType.APPLICATION_JSON_VALUE) @PostMapping(value = "/batch-update", consumes = MediaType.APPLICATION_JSON_VALUE)
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_READ_ADD_API) @RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_READ_ADD_API)
// 添加修改Log示例 // 添加修改Log示例
@Log(type = OperationLogType.UPDATE, expression = "#msClass.batchUpdateLog(#ids)", msClass = APIDefinitionLogService.class) @Log(type = OperationLogType.UPDATE, expression = "#msClass.batchUpdateLog(#ids)", msClass = ApiDefinitionLogService.class)
public ApiDefinitionDTO batchUpdate(@RequestBody List<String> ids) { public ApiDefinitionDTO batchUpdate(@RequestBody List<String> ids) {
return null; return null;
} }
@PostMapping(value = "/delete") @PostMapping(value = "/delete")
@RequiresPermissions(PermissionConstants.PROJECT_API_REPORT_READ_DELETE) @RequiresPermissions(PermissionConstants.PROJECT_API_REPORT_READ_DELETE)
@Log(type = OperationLogType.DELETE, expression = "#msClass.delLog(#id)", msClass = APIDefinitionLogService.class) @Log(type = OperationLogType.DELETE, expression = "#msClass.delLog(#id)", msClass = ApiDefinitionLogService.class)
public void batchDelete(@RequestBody String id) { public void batchDelete(@RequestBody String id) {
} }
@PostMapping(value = "/batch-del") @PostMapping(value = "/batch-del")
@RequiresPermissions(PermissionConstants.PROJECT_API_REPORT_READ_DELETE) @RequiresPermissions(PermissionConstants.PROJECT_API_REPORT_READ_DELETE)
@Log(type = OperationLogType.DELETE, expression = "#msClass.batchDelLog(#ids)", msClass = APIDefinitionLogService.class) @Log(type = OperationLogType.DELETE, expression = "#msClass.batchDelLog(#ids)", msClass = ApiDefinitionLogService.class)
public void batchDelete(@RequestBody List<String> ids) { public void batchDelete(@RequestBody List<String> ids) {
apiDefinitionService.batchDelete(ids); apiDefinitionService.batchDelete(ids);
} }

View File

@ -6,7 +6,7 @@ import io.metersphere.sdk.listener.EventSource;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Component @Component
public class APIEventSource implements EventSource { public class ApiEventSource implements EventSource {
private EventListener<Event> listener; private EventListener<Event> listener;
@Override @Override

View File

@ -16,7 +16,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
@Service @Service
public class APIDefinitionLogService { public class ApiDefinitionLogService {
@Resource @Resource
private ApiDefinitionMapper apiDefinitionMapper; private ApiDefinitionMapper apiDefinitionMapper;

View File

@ -14,7 +14,7 @@ import org.springframework.web.multipart.MultipartFile;
import java.util.List; import java.util.List;
@Service @Service
public class APIDefinitionService { public class ApiDefinitionService {
@Resource @Resource
private ApiDefinitionMapper apiDefinitionMapper; private ApiDefinitionMapper apiDefinitionMapper;

View File

@ -5,7 +5,7 @@ import io.metersphere.system.service.CleanupProjectResourceService;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Component @Component
public class CleanupAPIResourceService implements CleanupProjectResourceService { public class CleanupApiResourceService implements CleanupProjectResourceService {
@Override @Override
public void deleteResources(String projectId) { public void deleteResources(String projectId) {

View File

@ -1,6 +1,6 @@
package io.metersphere.api.controller; package io.metersphere.api.controller;
import io.metersphere.api.service.CleanupAPIResourceService; import io.metersphere.api.service.CleanupApiResourceService;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.junit.jupiter.api.MethodOrderer; import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Order;
@ -15,7 +15,7 @@ import org.springframework.boot.test.context.SpringBootTest;
@AutoConfigureMockMvc @AutoConfigureMockMvc
public class CleanupResourceTests { public class CleanupResourceTests {
@Resource @Resource
private CleanupAPIResourceService resourceService; private CleanupApiResourceService resourceService;
@Test @Test
@Order(1) @Order(1)

View File

@ -1,6 +1,6 @@
package io.metersphere.api.controller; package io.metersphere.api.controller;
import io.metersphere.api.event.APIEventSource; import io.metersphere.api.event.ApiEventSource;
import io.metersphere.sdk.listener.Event; import io.metersphere.sdk.listener.Event;
import io.metersphere.sdk.listener.EventListener; import io.metersphere.sdk.listener.EventListener;
import io.metersphere.sdk.util.CommonBeanFactory; import io.metersphere.sdk.util.CommonBeanFactory;
@ -23,7 +23,7 @@ public class EventSourceTests {
public void eventSourceTest() throws Exception { public void eventSourceTest() throws Exception {
// 注册所有监听源 // 注册所有监听源
LogUtils.info("初始化接口事件源"); LogUtils.info("初始化接口事件源");
APIEventSource apiEventSource = CommonBeanFactory.getBean(APIEventSource.class); ApiEventSource apiEventSource = CommonBeanFactory.getBean(ApiEventSource.class);
assert apiEventSource != null; assert apiEventSource != null;
apiEventSource.addListener(new EventListener<Event>() { apiEventSource.addListener(new EventListener<Event>() {
@Override @Override