接口定义-基本执行方法完成
This commit is contained in:
parent
e9660cdeae
commit
515c92060b
|
@ -7,6 +7,7 @@ import io.metersphere.api.dto.scenario.request.dubbo.RegistryCenter;
|
|||
import io.metersphere.api.service.APITestService;
|
||||
import io.metersphere.base.domain.ApiTest;
|
||||
import io.metersphere.base.domain.Schedule;
|
||||
import io.metersphere.commons.constants.ApiRunMode;
|
||||
import io.metersphere.commons.constants.RoleConstants;
|
||||
import io.metersphere.commons.utils.PageUtils;
|
||||
import io.metersphere.commons.utils.Pager;
|
||||
|
@ -113,12 +114,12 @@ public class APITestController {
|
|||
|
||||
@PostMapping(value = "/run")
|
||||
public String run(@RequestBody SaveAPITestRequest request) {
|
||||
return apiTestService.run(request);
|
||||
return apiTestService.run(request, ApiRunMode.RUN.name());
|
||||
}
|
||||
|
||||
@PostMapping(value = "/run/debug", consumes = {"multipart/form-data"})
|
||||
public String runDebug(@RequestPart("request") SaveAPITestRequest request, @RequestPart(value = "files") List<MultipartFile> bodyFiles) {
|
||||
return apiTestService.runDebug(request, bodyFiles);
|
||||
return apiTestService.runDebug(request, bodyFiles, ApiRunMode.DEBUG.name());
|
||||
}
|
||||
|
||||
@PostMapping(value = "/checkName")
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
package io.metersphere.api.controller;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import io.metersphere.api.dto.APIReportResult;
|
||||
import io.metersphere.api.dto.definition.ApiDefinitionRequest;
|
||||
import io.metersphere.api.dto.definition.ApiDefinitionResult;
|
||||
import io.metersphere.api.dto.definition.SaveApiDefinitionRequest;
|
||||
import io.metersphere.api.service.ApiDefinitionService;
|
||||
import io.metersphere.base.domain.ApiDefinition;
|
||||
import io.metersphere.commons.constants.RoleConstants;
|
||||
import io.metersphere.commons.utils.PageUtils;
|
||||
import io.metersphere.commons.utils.Pager;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import org.apache.shiro.authz.annotation.Logical;
|
||||
import org.apache.shiro.authz.annotation.RequiresRoles;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/api/definition")
|
||||
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER, RoleConstants.TEST_VIEWER}, logical = Logical.OR)
|
||||
public class ApiDefinitionController {
|
||||
@Resource
|
||||
private ApiDefinitionService apiDefinitionService;
|
||||
|
||||
@PostMapping("/list/{goPage}/{pageSize}")
|
||||
public Pager<List<ApiDefinitionResult>> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiDefinitionRequest request) {
|
||||
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
|
||||
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
|
||||
return PageUtils.setPageInfo(page, apiDefinitionService.list(request));
|
||||
}
|
||||
|
||||
@PostMapping(value = "/create", consumes = {"multipart/form-data"})
|
||||
public void create(@RequestPart("request") SaveApiDefinitionRequest request, @RequestPart(value = "files") List<MultipartFile> bodyFiles) {
|
||||
apiDefinitionService.create(request, bodyFiles);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/update", consumes = {"multipart/form-data"})
|
||||
public void update(@RequestPart("request") SaveApiDefinitionRequest request, @RequestPart(value = "files") List<MultipartFile> bodyFiles) {
|
||||
apiDefinitionService.update(request, bodyFiles);
|
||||
}
|
||||
|
||||
@GetMapping("/delete/{id}")
|
||||
public void delete(@PathVariable String id) {
|
||||
apiDefinitionService.delete(id);
|
||||
}
|
||||
|
||||
@PostMapping("/deleteBatch")
|
||||
public void deleteBatch(@RequestBody List<String> ids) {
|
||||
apiDefinitionService.deleteBatch(ids);
|
||||
}
|
||||
|
||||
@GetMapping("/get/{id}")
|
||||
public ApiDefinition get(@PathVariable String id) {
|
||||
return apiDefinitionService.get(id);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/run/debug", consumes = {"multipart/form-data"})
|
||||
public String runDebug(@RequestPart("request") SaveApiDefinitionRequest request, @RequestPart(value = "files") List<MultipartFile> bodyFiles) {
|
||||
return apiDefinitionService.run(request, bodyFiles);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/run", consumes = {"multipart/form-data"})
|
||||
public String run(@RequestPart("request") SaveApiDefinitionRequest request, @RequestPart(value = "files") List<MultipartFile> bodyFiles) {
|
||||
return apiDefinitionService.run(request, bodyFiles);
|
||||
}
|
||||
|
||||
@GetMapping("/report/get/{testId}/{test}")
|
||||
public APIReportResult get(@PathVariable String testId, @PathVariable String test) {
|
||||
return apiDefinitionService.getResult(testId, test);
|
||||
}
|
||||
|
||||
@GetMapping("/report/getReport/{testId}")
|
||||
public APIReportResult getReport(@PathVariable String testId) {
|
||||
return apiDefinitionService.getDbResult(testId);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
package io.metersphere.api.controller;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import io.metersphere.api.dto.APIReportResult;
|
||||
import io.metersphere.api.dto.delimit.ApiDelimitRequest;
|
||||
import io.metersphere.api.dto.delimit.ApiDelimitResult;
|
||||
import io.metersphere.api.dto.delimit.SaveApiDelimitRequest;
|
||||
import io.metersphere.api.service.ApiDelimitService;
|
||||
import io.metersphere.base.domain.ApiDelimit;
|
||||
import io.metersphere.commons.constants.RoleConstants;
|
||||
import io.metersphere.commons.utils.PageUtils;
|
||||
import io.metersphere.commons.utils.Pager;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import org.apache.shiro.authz.annotation.Logical;
|
||||
import org.apache.shiro.authz.annotation.RequiresRoles;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/api/delimit")
|
||||
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER, RoleConstants.TEST_VIEWER}, logical = Logical.OR)
|
||||
public class ApiDelimitController {
|
||||
@Resource
|
||||
private ApiDelimitService apiDelimitService;
|
||||
|
||||
@PostMapping("/list/{goPage}/{pageSize}")
|
||||
public Pager<List<ApiDelimitResult>> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiDelimitRequest request) {
|
||||
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
|
||||
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
|
||||
return PageUtils.setPageInfo(page, apiDelimitService.list(request));
|
||||
}
|
||||
|
||||
@PostMapping(value = "/create", consumes = {"multipart/form-data"})
|
||||
public void create(@RequestPart("request") SaveApiDelimitRequest request, @RequestPart(value = "file") MultipartFile file, @RequestPart(value = "files") List<MultipartFile> bodyFiles) {
|
||||
apiDelimitService.create(request, file, bodyFiles);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/update", consumes = {"multipart/form-data"})
|
||||
public void update(@RequestPart("request") SaveApiDelimitRequest request, @RequestPart(value = "file") MultipartFile file, @RequestPart(value = "files") List<MultipartFile> bodyFiles) {
|
||||
apiDelimitService.update(request, file, bodyFiles);
|
||||
}
|
||||
|
||||
@GetMapping("/delete/{id}")
|
||||
public void delete(@PathVariable String id) {
|
||||
apiDelimitService.delete(id);
|
||||
}
|
||||
|
||||
@PostMapping("/deleteBatch")
|
||||
public void deleteBatch(@RequestBody List<String> ids) {
|
||||
apiDelimitService.deleteBatch(ids);
|
||||
}
|
||||
|
||||
@GetMapping("/get/{id}")
|
||||
public ApiDelimit get(@PathVariable String id) {
|
||||
return apiDelimitService.get(id);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/run/debug", consumes = {"multipart/form-data"})
|
||||
public String runDebug(@RequestPart("request") SaveApiDelimitRequest request, @RequestPart(value = "file") MultipartFile file, @RequestPart(value = "files") List<MultipartFile> bodyFiles) {
|
||||
return apiDelimitService.run(request, file, bodyFiles);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/run", consumes = {"multipart/form-data"})
|
||||
public String run(@RequestPart("request") SaveApiDelimitRequest request, @RequestPart(value = "file") MultipartFile file, @RequestPart(value = "files") List<MultipartFile> bodyFiles) {
|
||||
return apiDelimitService.run(request, file, bodyFiles);
|
||||
}
|
||||
|
||||
@GetMapping("/report/get/{testId}/{test}")
|
||||
public APIReportResult getReport(@PathVariable String testId, @PathVariable String test) {
|
||||
return apiDelimitService.getResult(testId, test);
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package io.metersphere.api.controller;
|
||||
|
||||
import io.metersphere.api.dto.delimit.ApiModuleDTO;
|
||||
import io.metersphere.api.dto.delimit.DragModuleRequest;
|
||||
import io.metersphere.api.dto.definition.ApiModuleDTO;
|
||||
import io.metersphere.api.dto.definition.DragModuleRequest;
|
||||
import io.metersphere.api.service.ApiModuleService;
|
||||
import io.metersphere.base.domain.ApiModule;
|
||||
import io.metersphere.commons.constants.RoleConstants;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package io.metersphere.api.controller;
|
||||
|
||||
import io.metersphere.api.dto.delimit.ApiTestCaseRequest;
|
||||
import io.metersphere.api.dto.delimit.ApiTestCaseResult;
|
||||
import io.metersphere.api.dto.delimit.SaveApiTestCaseRequest;
|
||||
import io.metersphere.api.dto.definition.ApiTestCaseRequest;
|
||||
import io.metersphere.api.dto.definition.ApiTestCaseResult;
|
||||
import io.metersphere.api.dto.definition.SaveApiTestCaseRequest;
|
||||
import io.metersphere.api.service.ApiTestCaseService;
|
||||
import io.metersphere.commons.constants.RoleConstants;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package io.metersphere.api.dto.delimit;
|
||||
package io.metersphere.api.dto.definition;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
@ -6,7 +6,7 @@ import lombok.Setter;
|
|||
@Getter
|
||||
@Setter
|
||||
public class ApiComputeResult {
|
||||
private String apiDelimitId;
|
||||
private String apiDefinitionId;
|
||||
private String caseTotal;
|
||||
private String status;
|
||||
private String passRate;
|
|
@ -1,4 +1,4 @@
|
|||
package io.metersphere.api.dto.delimit;
|
||||
package io.metersphere.api.dto.definition;
|
||||
|
||||
import io.metersphere.base.domain.TestCaseWithBLOBs;
|
||||
import lombok.Getter;
|
|
@ -1,4 +1,4 @@
|
|||
package io.metersphere.api.dto.delimit;
|
||||
package io.metersphere.api.dto.definition;
|
||||
|
||||
import io.metersphere.controller.request.OrderRequest;
|
||||
import lombok.Getter;
|
||||
|
@ -9,7 +9,7 @@ import java.util.Map;
|
|||
|
||||
@Getter
|
||||
@Setter
|
||||
public class ApiDelimitRequest {
|
||||
public class ApiDefinitionRequest {
|
||||
|
||||
private String id;
|
||||
private String excludeId;
|
|
@ -1,13 +1,13 @@
|
|||
package io.metersphere.api.dto.delimit;
|
||||
package io.metersphere.api.dto.definition;
|
||||
|
||||
import io.metersphere.base.domain.ApiDelimit;
|
||||
import io.metersphere.base.domain.ApiDefinition;
|
||||
import io.metersphere.base.domain.Schedule;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
public class ApiDelimitResult extends ApiDelimit {
|
||||
public class ApiDefinitionResult extends ApiDefinition {
|
||||
|
||||
private String projectName;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package io.metersphere.api.dto.delimit;
|
||||
package io.metersphere.api.dto.definition;
|
||||
|
||||
import io.metersphere.base.domain.ApiModule;
|
||||
import lombok.Getter;
|
|
@ -1,4 +1,4 @@
|
|||
package io.metersphere.api.dto.delimit;
|
||||
package io.metersphere.api.dto.definition;
|
||||
|
||||
import io.metersphere.controller.request.OrderRequest;
|
||||
import lombok.Getter;
|
||||
|
@ -16,6 +16,6 @@ public class ApiTestCaseRequest {
|
|||
private String name;
|
||||
private String environmentId;
|
||||
private String workspaceId;
|
||||
private String apiDelimitId;
|
||||
private String apiDefinitionId;
|
||||
private List<OrderRequest> orders;
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package io.metersphere.api.dto.delimit;
|
||||
package io.metersphere.api.dto.definition;
|
||||
|
||||
import io.metersphere.base.domain.ApiTestCase;
|
||||
import lombok.Getter;
|
|
@ -1,4 +1,4 @@
|
|||
package io.metersphere.api.dto.delimit;
|
||||
package io.metersphere.api.dto.definition;
|
||||
|
||||
import io.metersphere.base.domain.ApiModule;
|
||||
import lombok.Getter;
|
|
@ -1,7 +1,8 @@
|
|||
package io.metersphere.api.dto.delimit;
|
||||
package io.metersphere.api.dto.definition;
|
||||
|
||||
import io.metersphere.api.dto.definition.response.Response;
|
||||
import io.metersphere.api.dto.scenario.Scenario;
|
||||
import io.metersphere.api.dto.scenario.request.Request;
|
||||
import io.metersphere.api.dto.delimit.response.Response;
|
||||
import io.metersphere.base.domain.Schedule;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
@ -10,7 +11,7 @@ import java.util.List;
|
|||
|
||||
@Setter
|
||||
@Getter
|
||||
public class SaveApiDelimitRequest {
|
||||
public class SaveApiDefinitionRequest {
|
||||
|
||||
private String id;
|
||||
|
||||
|
@ -30,7 +31,9 @@ public class SaveApiDelimitRequest {
|
|||
|
||||
private String modulePath;
|
||||
|
||||
private String path;
|
||||
private String method;
|
||||
|
||||
private Scenario scenario;
|
||||
|
||||
private Request request;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package io.metersphere.api.dto.delimit;
|
||||
package io.metersphere.api.dto.definition;
|
||||
|
||||
import io.metersphere.api.dto.scenario.request.Request;
|
||||
import lombok.Getter;
|
||||
|
@ -18,7 +18,7 @@ public class SaveApiTestCaseRequest {
|
|||
|
||||
private String priority;
|
||||
|
||||
private String apiDelimitId;
|
||||
private String apiDefinitionId;
|
||||
|
||||
private String description;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package io.metersphere.api.dto.delimit.response;
|
||||
package io.metersphere.api.dto.definition.response;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.alibaba.fastjson.annotation.JSONType;
|
|
@ -1,4 +1,4 @@
|
|||
package io.metersphere.api.dto.delimit.response;
|
||||
package io.metersphere.api.dto.definition.response;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.alibaba.fastjson.annotation.JSONType;
|
|
@ -11,11 +11,15 @@ public class Body {
|
|||
private String raw;
|
||||
private String format;
|
||||
private List<KeyValue> kvs;
|
||||
private Object json;
|
||||
private String xml;
|
||||
|
||||
private final static String KV = "KeyValue";
|
||||
private final static String FORM_DATA = "Form Data";
|
||||
private final static String RAW = "Raw";
|
||||
private final static String BINARY = "Binary";
|
||||
private final static String JSON = "JSON";
|
||||
private final static String XML = "XML";
|
||||
|
||||
public boolean isValid() {
|
||||
if (this.isKV()) {
|
||||
|
@ -29,7 +33,16 @@ public class Body {
|
|||
return StringUtils.equals(type, KV);
|
||||
}
|
||||
|
||||
public boolean isBinary(){
|
||||
public boolean isBinary() {
|
||||
return StringUtils.equals(type, BINARY);
|
||||
}
|
||||
|
||||
public boolean isJson() {
|
||||
return StringUtils.equals(type, JSON);
|
||||
}
|
||||
|
||||
public boolean isXml() {
|
||||
return StringUtils.equals(type, XML);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -42,6 +42,6 @@ public class HttpRequest extends Request {
|
|||
private AuthConfig authConfig;
|
||||
// 和接口定义模块用途区分
|
||||
@JSONField(ordinal = 62)
|
||||
private boolean isDelimit;
|
||||
private boolean isDefinition;
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package io.metersphere.api.jmeter;
|
|||
|
||||
import io.metersphere.api.service.APIReportService;
|
||||
import io.metersphere.api.service.APITestService;
|
||||
import io.metersphere.api.service.ApiDefinitionExecResultService;
|
||||
import io.metersphere.api.service.ApiDefinitionService;
|
||||
import io.metersphere.base.domain.ApiTestReport;
|
||||
import io.metersphere.commons.constants.APITestStatus;
|
||||
import io.metersphere.commons.constants.ApiRunMode;
|
||||
|
@ -49,6 +51,8 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
|
|||
private DingTaskService dingTaskService;
|
||||
private WxChatTaskService wxChatTaskService;
|
||||
private SystemParameterService systemParameterService;
|
||||
private ApiDefinitionService apiDefinitionService;
|
||||
private ApiDefinitionExecResultService apiDefinitionExecResultService;
|
||||
|
||||
public String runMode = ApiRunMode.RUN.name();
|
||||
|
||||
|
@ -93,6 +97,15 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
|
|||
if (systemParameterService == null) {
|
||||
LogUtil.error("systemParameterService is required");
|
||||
}
|
||||
apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class);
|
||||
if (apiDefinitionService == null) {
|
||||
LogUtil.error("apiDefinitionService is required");
|
||||
}
|
||||
apiDefinitionExecResultService = CommonBeanFactory.getBean(ApiDefinitionExecResultService.class);
|
||||
if (apiDefinitionExecResultService == null) {
|
||||
LogUtil.error("apiDefinitionExecResultService is required");
|
||||
}
|
||||
|
||||
super.setupTest(context);
|
||||
}
|
||||
|
||||
|
@ -149,6 +162,15 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
|
|||
ApiTestReport report;
|
||||
if (StringUtils.equals(this.runMode, ApiRunMode.DEBUG.name())) {
|
||||
report = apiReportService.get(debugReportId);
|
||||
} else if (StringUtils.equals(this.runMode, ApiRunMode.DELIMIT.name())) {
|
||||
// 调试操作,不需要存储结果
|
||||
if (StringUtils.isBlank(debugReportId)) {
|
||||
apiDefinitionService.addResult(testResult);
|
||||
} else {
|
||||
apiDefinitionService.addResult(testResult);
|
||||
apiDefinitionExecResultService.saveApiResult(testResult);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
apiTestService.changeStatus(testId, APITestStatus.Completed);
|
||||
report = apiReportService.getRunningReport(testResult.getTestId());
|
||||
|
|
|
@ -1,65 +0,0 @@
|
|||
package io.metersphere.api.jmeter;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import io.metersphere.base.domain.ApiDelimitExecResult;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ApiTestResult {
|
||||
|
||||
private String id;
|
||||
|
||||
private String name;
|
||||
|
||||
private long responseTime;
|
||||
|
||||
private int error = 0;
|
||||
|
||||
private int success = 0;
|
||||
|
||||
private int totalAssertions = 0;
|
||||
|
||||
private int passAssertions = 0;
|
||||
|
||||
private final List<RequestResult> requestResults = new ArrayList<>();
|
||||
|
||||
public void addRequestResult(RequestResult result) {
|
||||
requestResults.add(result);
|
||||
}
|
||||
|
||||
public ApiTestResult() {
|
||||
|
||||
}
|
||||
|
||||
public ApiTestResult(ApiDelimitExecResult result) {
|
||||
this.id = result.getId();
|
||||
this.responseTime = result.getEndTime();
|
||||
this.addRequestResult(JSON.parseObject(result.getContent(), RequestResult.class));
|
||||
}
|
||||
|
||||
public void addResponseTime(long time) {
|
||||
this.responseTime += time;
|
||||
}
|
||||
|
||||
public void addError(int count) {
|
||||
this.error += count;
|
||||
}
|
||||
|
||||
public void addSuccess() {
|
||||
this.success++;
|
||||
}
|
||||
public int getSuccess() {
|
||||
return this.success;
|
||||
}
|
||||
|
||||
public void addTotalAssertions(int count) {
|
||||
this.totalAssertions += count;
|
||||
}
|
||||
|
||||
public void addPassAssertions(int count) {
|
||||
this.passAssertions += count;
|
||||
}
|
||||
}
|
|
@ -1,165 +0,0 @@
|
|||
package io.metersphere.api.jmeter;
|
||||
|
||||
import io.metersphere.api.service.ApiDelimitExecResultService;
|
||||
import io.metersphere.api.service.ApiDelimitService;
|
||||
import io.metersphere.commons.constants.ApiRunMode;
|
||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.jmeter.assertions.AssertionResult;
|
||||
import org.apache.jmeter.samplers.SampleResult;
|
||||
import org.apache.jmeter.visualizers.backend.AbstractBackendListenerClient;
|
||||
import org.apache.jmeter.visualizers.backend.BackendListenerContext;
|
||||
import org.springframework.http.HttpMethod;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* JMeter BackendListener扩展, jmx脚本中使用
|
||||
*/
|
||||
public class DelimitBackendListenerClient extends AbstractBackendListenerClient implements Serializable {
|
||||
|
||||
public final static String TEST_ID = "ms.test.id";
|
||||
|
||||
private final List<SampleResult> queue = new ArrayList<>();
|
||||
|
||||
public String runMode = ApiRunMode.RUN.name();
|
||||
private ApiDelimitService apiDelimitService;
|
||||
private ApiDelimitExecResultService apiDelimitExecResultService;
|
||||
// 测试ID
|
||||
private String testId;
|
||||
// 运行结果报告ID
|
||||
private String reportId;
|
||||
|
||||
@Override
|
||||
public void setupTest(BackendListenerContext context) throws Exception {
|
||||
setParam(context);
|
||||
apiDelimitService = CommonBeanFactory.getBean(ApiDelimitService.class);
|
||||
if (apiDelimitService == null) {
|
||||
LogUtil.error("apiDelimitService is required");
|
||||
}
|
||||
apiDelimitExecResultService = CommonBeanFactory.getBean(ApiDelimitExecResultService.class);
|
||||
if (apiDelimitExecResultService == null) {
|
||||
LogUtil.error("apiDelimitExecResultService is required");
|
||||
}
|
||||
super.setupTest(context);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleSampleResults(List<SampleResult> sampleResults, BackendListenerContext context) {
|
||||
queue.addAll(sampleResults);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void teardownTest(BackendListenerContext context) throws Exception {
|
||||
ApiTestResult testResult = new ApiTestResult();
|
||||
testResult.setId(testId);
|
||||
queue.forEach(result -> {
|
||||
RequestResult reqResult = getRequestResult(result);
|
||||
testResult.addRequestResult(reqResult);
|
||||
testResult.addPassAssertions(reqResult.getPassAssertions());
|
||||
testResult.addTotalAssertions(reqResult.getTotalAssertions());
|
||||
});
|
||||
// 调试操作,不需要存储结果
|
||||
if (StringUtils.isBlank(reportId)) {
|
||||
apiDelimitService.addResult(testResult);
|
||||
} else {
|
||||
apiDelimitExecResultService.saveApiResult(testResult);
|
||||
}
|
||||
queue.clear();
|
||||
super.teardownTest(context);
|
||||
}
|
||||
|
||||
|
||||
private RequestResult getRequestResult(SampleResult result) {
|
||||
RequestResult reqResult = new RequestResult();
|
||||
reqResult.setName(result.getSampleLabel());
|
||||
reqResult.setUrl(result.getUrlAsString());
|
||||
reqResult.setMethod(getMethod(result));
|
||||
reqResult.setBody(result.getSamplerData());
|
||||
reqResult.setHeaders(result.getRequestHeaders());
|
||||
reqResult.setRequestSize(result.getSentBytes());
|
||||
reqResult.setStartTime(result.getStartTime());
|
||||
reqResult.setTotalAssertions(result.getAssertionResults().length);
|
||||
reqResult.setSuccess(result.isSuccessful());
|
||||
reqResult.setError(result.getErrorCount());
|
||||
for (SampleResult subResult : result.getSubResults()) {
|
||||
reqResult.getSubRequestResults().add(getRequestResult(subResult));
|
||||
}
|
||||
|
||||
ResponseResult responseResult = reqResult.getResponseResult();
|
||||
responseResult.setBody(result.getResponseDataAsString());
|
||||
responseResult.setHeaders(result.getResponseHeaders());
|
||||
responseResult.setLatency(result.getLatency());
|
||||
responseResult.setResponseCode(result.getResponseCode());
|
||||
responseResult.setResponseSize(result.getResponseData().length);
|
||||
responseResult.setResponseTime(result.getTime());
|
||||
responseResult.setResponseMessage(result.getResponseMessage());
|
||||
|
||||
if (JMeterVars.get(result.hashCode()) != null) {
|
||||
List<String> vars = new LinkedList<>();
|
||||
JMeterVars.get(result.hashCode()).entrySet().parallelStream().reduce(vars, (first, second) -> {
|
||||
first.add(second.getKey() + ":" + second.getValue());
|
||||
return first;
|
||||
}, (first, second) -> {
|
||||
if (first == second) {
|
||||
return first;
|
||||
}
|
||||
first.addAll(second);
|
||||
return first;
|
||||
});
|
||||
responseResult.setVars(StringUtils.join(vars, "\n"));
|
||||
JMeterVars.remove(result.hashCode());
|
||||
}
|
||||
for (AssertionResult assertionResult : result.getAssertionResults()) {
|
||||
ResponseAssertionResult responseAssertionResult = getResponseAssertionResult(assertionResult);
|
||||
if (responseAssertionResult.isPass()) {
|
||||
reqResult.addPassAssertions();
|
||||
}
|
||||
responseResult.getAssertions().add(responseAssertionResult);
|
||||
}
|
||||
return reqResult;
|
||||
}
|
||||
|
||||
private String getMethod(SampleResult result) {
|
||||
String body = result.getSamplerData();
|
||||
// Dubbo Protocol
|
||||
String start = "RPC Protocol: ";
|
||||
String end = "://";
|
||||
if (StringUtils.contains(body, start)) {
|
||||
return StringUtils.substringBetween(body, start, end).toUpperCase();
|
||||
} else {
|
||||
// Http Method
|
||||
String method = StringUtils.substringBefore(body, " ");
|
||||
for (HttpMethod value : HttpMethod.values()) {
|
||||
if (StringUtils.equals(method, value.name())) {
|
||||
return method;
|
||||
}
|
||||
}
|
||||
return "Request";
|
||||
}
|
||||
}
|
||||
|
||||
private void setParam(BackendListenerContext context) {
|
||||
this.testId = context.getParameter(TEST_ID);
|
||||
this.runMode = context.getParameter("runMode");
|
||||
this.reportId = context.getParameter("reportId");
|
||||
if (StringUtils.isBlank(this.runMode)) {
|
||||
this.runMode = ApiRunMode.RUN.name();
|
||||
}
|
||||
}
|
||||
|
||||
private ResponseAssertionResult getResponseAssertionResult(AssertionResult assertionResult) {
|
||||
ResponseAssertionResult responseAssertionResult = new ResponseAssertionResult();
|
||||
responseAssertionResult.setName(assertionResult.getName());
|
||||
responseAssertionResult.setPass(!assertionResult.isFailure() && !assertionResult.isError());
|
||||
|
||||
if (!responseAssertionResult.isPass()) {
|
||||
responseAssertionResult.setMessage(assertionResult.getFailureMessage());
|
||||
}
|
||||
return responseAssertionResult;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,80 +0,0 @@
|
|||
package io.metersphere.api.jmeter;
|
||||
|
||||
import io.metersphere.commons.constants.ApiRunMode;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.config.JmeterProperties;
|
||||
import io.metersphere.i18n.Translator;
|
||||
import org.apache.jmeter.config.Arguments;
|
||||
import org.apache.jmeter.save.SaveService;
|
||||
import org.apache.jmeter.util.JMeterUtils;
|
||||
import org.apache.jmeter.visualizers.backend.BackendListener;
|
||||
import org.apache.jorphan.collections.HashTree;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
@Service
|
||||
public class DelimitJMeterService {
|
||||
|
||||
@Resource
|
||||
private JmeterProperties jmeterProperties;
|
||||
|
||||
public void run(String testId, String reportId, InputStream is) {
|
||||
String home = getJmeterHome();
|
||||
String jmeterProperties = home + "/bin/jmeter.properties";
|
||||
JMeterUtils.loadJMeterProperties(jmeterProperties);
|
||||
JMeterUtils.setJMeterHome(home);
|
||||
JMeterUtils.setLocale(LocaleContextHolder.getLocale());
|
||||
|
||||
try {
|
||||
Object scriptWrapper = SaveService.loadElement(is);
|
||||
HashTree testPlan = getHashTree(scriptWrapper);
|
||||
JMeterVars.addJSR223PostProcessor(testPlan);
|
||||
addBackendListener(testId, reportId, testPlan);
|
||||
LocalRunner runner = new LocalRunner(testPlan);
|
||||
runner.run();
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e.getMessage(), e);
|
||||
MSException.throwException(Translator.get("api_load_script_error"));
|
||||
}
|
||||
}
|
||||
|
||||
public String getJmeterHome() {
|
||||
String home = getClass().getResource("/").getPath() + "jmeter";
|
||||
try {
|
||||
File file = new File(home);
|
||||
if (file.exists()) {
|
||||
return home;
|
||||
} else {
|
||||
return jmeterProperties.getHome();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return jmeterProperties.getHome();
|
||||
}
|
||||
}
|
||||
|
||||
private HashTree getHashTree(Object scriptWrapper) throws Exception {
|
||||
Field field = scriptWrapper.getClass().getDeclaredField("testPlan");
|
||||
field.setAccessible(true);
|
||||
return (HashTree) field.get(scriptWrapper);
|
||||
}
|
||||
|
||||
private void addBackendListener(String testId, String debugReportId, HashTree testPlan) {
|
||||
BackendListener backendListener = new BackendListener();
|
||||
backendListener.setName(testId);
|
||||
Arguments arguments = new Arguments();
|
||||
arguments.addArgument(DelimitBackendListenerClient.TEST_ID, testId);
|
||||
|
||||
arguments.addArgument("runMode", ApiRunMode.DEBUG.name());
|
||||
arguments.addArgument("reportId", debugReportId);
|
||||
|
||||
backendListener.setArguments(arguments);
|
||||
backendListener.setClassname(DelimitBackendListenerClient.class.getCanonicalName());
|
||||
testPlan.add(testPlan.getArray()[0], backendListener);
|
||||
}
|
||||
}
|
|
@ -90,15 +90,15 @@ public class JMXGenerator {
|
|||
});
|
||||
}
|
||||
// DUBBO Config
|
||||
if(scenario.getDubboConfig()!=null) {
|
||||
if (scenario.getDubboConfig() != null) {
|
||||
threadGroupHashTree.add(dubboConfig(scenario.getName() + "DUBBO Config", scenario.getDubboConfig()));
|
||||
}
|
||||
// 场景TCP Config
|
||||
if(scenario.getTcpConfig()!=null ) {
|
||||
if (scenario.getTcpConfig() != null) {
|
||||
threadGroupHashTree.add(tcpConfig(scenario.getName() + "TCP Config", scenario.getTcpConfig()));
|
||||
}
|
||||
// 场景断言
|
||||
if(scenario.getAssertions()!=null) {
|
||||
if (scenario.getAssertions() != null) {
|
||||
addAssertions(threadGroupHashTree, scenario.getAssertions());
|
||||
}
|
||||
// 请求
|
||||
|
@ -178,7 +178,7 @@ public class JMXGenerator {
|
|||
map.put("form", "application/x-www-form-urlencoded");
|
||||
map.put("binary", "application/octet-stream");
|
||||
String contentType = map.get(body.getFormat());
|
||||
boolean hasContentType = headers.stream().filter(KeyValue::isEnable).anyMatch(keyValue -> keyValue.getName().equals(HTTP.CONTENT_TYPE));
|
||||
boolean hasContentType = headers.stream().filter(KeyValue::isEnable).anyMatch(keyValue -> keyValue.getName() != null && keyValue.getName().equals(HTTP.CONTENT_TYPE));
|
||||
if (contentType != null && !hasContentType) {
|
||||
headers.add(new KeyValue(HTTP.CONTENT_TYPE, contentType));
|
||||
}
|
||||
|
@ -460,6 +460,9 @@ public class JMXGenerator {
|
|||
sampler.setPort(config.getHttpConfig().getPort());
|
||||
sampler.setProtocol(config.getHttpConfig().getProtocol());
|
||||
String url = config.getHttpConfig().getProtocol() + "://" + config.getHttpConfig().getSocket();
|
||||
if (request.isDefinition()) {
|
||||
url += request.getUrl();
|
||||
}
|
||||
URL urlObject = new URL(url);
|
||||
sampler.setDomain(config.getHttpConfig().getDomain());
|
||||
String envPath = StringUtils.equals(urlObject.getPath(), "/") ? "" : urlObject.getPath();
|
||||
|
@ -484,45 +487,37 @@ public class JMXGenerator {
|
|||
|
||||
// 请求参数
|
||||
if (CollectionUtils.isNotEmpty(request.getParameters())) {
|
||||
// 来自接口定义模块需要参数校验合规性
|
||||
if(request.isDelimit()){
|
||||
|
||||
}
|
||||
sampler.setArguments(httpArguments(request.getParameters()));
|
||||
}
|
||||
// rest参数处理
|
||||
if (CollectionUtils.isNotEmpty(request.getRest())) {
|
||||
// 来自接口定义模块需要参数校验合规性
|
||||
if(request.isDelimit()){
|
||||
|
||||
}
|
||||
sampler.setArguments(httpArguments(request.getRest()));
|
||||
}
|
||||
// 请求体
|
||||
if (!StringUtils.equals(request.getMethod(), "GET")) {
|
||||
List<KeyValue> body = new ArrayList<>();
|
||||
if (request.getBody().isKV()) {
|
||||
// 来自接口定义模块需要参数校验合规性
|
||||
if(request.isDelimit()){
|
||||
|
||||
}
|
||||
body = request.getBody().getKvs().stream().filter(KeyValue::isValid).collect(Collectors.toList());
|
||||
sampler.setHTTPFiles(httpFileArgs(request, testId));
|
||||
}else if (request.getBody().isBinary()){
|
||||
} else if (request.getBody().isBinary()) {
|
||||
// 上传二进制数据处理
|
||||
}
|
||||
else {
|
||||
if (StringUtils.isNotBlank(request.getBody().getRaw())) {
|
||||
// 来自接口定义模块需要参数校验合规性
|
||||
if(request.isDelimit()){
|
||||
} else if (request.getBody().isJson()) {
|
||||
|
||||
}
|
||||
} else {
|
||||
if (StringUtils.isNotBlank(request.getBody().getRaw())) {
|
||||
sampler.setPostBodyRaw(true);
|
||||
KeyValue keyValue = new KeyValue("", request.getBody().getRaw());
|
||||
keyValue.setEnable(true);
|
||||
keyValue.setEncode(false);
|
||||
body.add(keyValue);
|
||||
}
|
||||
if (StringUtils.isNotBlank(request.getBody().getXml())) {
|
||||
sampler.setPostBodyRaw(true);
|
||||
KeyValue keyValue = new KeyValue("", request.getBody().getXml());
|
||||
keyValue.setEnable(true);
|
||||
keyValue.setEncode(false);
|
||||
body.add(keyValue);
|
||||
}
|
||||
}
|
||||
sampler.setArguments(httpArguments(body));
|
||||
}
|
||||
|
@ -539,7 +534,7 @@ public class JMXGenerator {
|
|||
);
|
||||
return stringBuffer.substring(0, stringBuffer.length() - 1);
|
||||
}
|
||||
return "";
|
||||
return path;
|
||||
}
|
||||
|
||||
private Arguments httpArguments(List<KeyValue> list) {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package io.metersphere.api.jmeter;
|
||||
|
||||
import io.metersphere.api.dto.scenario.Scenario;
|
||||
import io.metersphere.commons.constants.ApiRunMode;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.config.JmeterProperties;
|
||||
|
@ -15,13 +14,12 @@ import org.apache.jorphan.collections.HashTree;
|
|||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Service
|
||||
public class JMeterService {
|
||||
|
||||
|
@ -44,12 +42,12 @@ public class JMeterService {
|
|||
return jmxGenerator.parse(testId, testName, scenarios);
|
||||
}
|
||||
|
||||
public void run(String testId, String testName, List<Scenario> scenarios, String debugReportId) {
|
||||
public void run(String testId, String testName, List<Scenario> scenarios, String debugReportId,String runMode) {
|
||||
try {
|
||||
init();
|
||||
HashTree testPlan = getHashTree(testId, testName, scenarios);
|
||||
JMeterVars.addJSR223PostProcessor(testPlan);
|
||||
addBackendListener(testId, debugReportId, testPlan);
|
||||
addBackendListener(testId, debugReportId,runMode, testPlan);
|
||||
LocalRunner runner = new LocalRunner(testPlan);
|
||||
runner.run();
|
||||
} catch (Exception e) {
|
||||
|
@ -64,6 +62,7 @@ public class JMeterService {
|
|||
LogUtil.debug(baos.toString());
|
||||
return baos.toString();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
LogUtil.warn("HashTree error, can't log jmx content");
|
||||
}
|
||||
return null;
|
||||
|
@ -83,13 +82,15 @@ public class JMeterService {
|
|||
}
|
||||
}
|
||||
|
||||
private void addBackendListener(String testId, String debugReportId, HashTree testPlan) {
|
||||
private void addBackendListener(String testId, String debugReportId,String runMode, HashTree testPlan) {
|
||||
BackendListener backendListener = new BackendListener();
|
||||
backendListener.setName(testId);
|
||||
Arguments arguments = new Arguments();
|
||||
arguments.addArgument(APIBackendListenerClient.TEST_ID, testId);
|
||||
if(StringUtils.isNotBlank(runMode)){
|
||||
arguments.addArgument("runMode", runMode);
|
||||
}
|
||||
if (StringUtils.isNotBlank(debugReportId)) {
|
||||
arguments.addArgument("runMode", ApiRunMode.DEBUG.name());
|
||||
arguments.addArgument("debugReportId", debugReportId);
|
||||
}
|
||||
backendListener.setArguments(arguments);
|
||||
|
|
|
@ -12,10 +12,7 @@ import io.metersphere.base.domain.*;
|
|||
import io.metersphere.base.mapper.ApiTestFileMapper;
|
||||
import io.metersphere.base.mapper.ApiTestMapper;
|
||||
import io.metersphere.base.mapper.ext.ExtApiTestMapper;
|
||||
import io.metersphere.commons.constants.APITestStatus;
|
||||
import io.metersphere.commons.constants.FileType;
|
||||
import io.metersphere.commons.constants.ScheduleGroup;
|
||||
import io.metersphere.commons.constants.ScheduleType;
|
||||
import io.metersphere.commons.constants.*;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.*;
|
||||
import io.metersphere.controller.request.QueryScheduleRequest;
|
||||
|
@ -34,12 +31,11 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class APITestService {
|
||||
|
@ -185,14 +181,14 @@ public class APITestService {
|
|||
}
|
||||
}
|
||||
|
||||
public String run(SaveAPITestRequest request) {
|
||||
public String run(SaveAPITestRequest request,String runMode) {
|
||||
APITestResult apiTest = get(request.getId());
|
||||
if (SessionUtils.getUser() == null) {
|
||||
apiTest.setUserId(request.getUserId());
|
||||
}
|
||||
String reportId = apiReportService.create(apiTest, request.getTriggerMode());
|
||||
changeStatus(request.getId(), APITestStatus.Running);
|
||||
jMeterService.run(request.getId(), request.getName(), request.getScenarioDefinition(), null);
|
||||
jMeterService.run(request.getId(), request.getName(), request.getScenarioDefinition(), null,runMode);
|
||||
return reportId;
|
||||
}
|
||||
|
||||
|
@ -353,7 +349,7 @@ public class APITestService {
|
|||
return schedules;
|
||||
}
|
||||
|
||||
public String runDebug(SaveAPITestRequest request, List<MultipartFile> bodyFiles) {
|
||||
public String runDebug(SaveAPITestRequest request, List<MultipartFile> bodyFiles,String runMode) {
|
||||
updateTest(request);
|
||||
APITestResult apiTest = get(request.getId());
|
||||
List<String> bodyUploadIds = new ArrayList<>(request.getBodyUploadIds());
|
||||
|
@ -364,7 +360,7 @@ public class APITestService {
|
|||
}
|
||||
String reportId = apiReportService.createDebugReport(apiTest);
|
||||
|
||||
jMeterService.run(request.getId(), request.getName(), request.getScenarioDefinition(), reportId);
|
||||
jMeterService.run(request.getId(), request.getName(), request.getScenarioDefinition(), reportId,runMode);
|
||||
return reportId;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package io.metersphere.api.service;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import io.metersphere.api.jmeter.ApiTestResult;
|
||||
import io.metersphere.base.domain.ApiDelimitExecResult;
|
||||
import io.metersphere.base.mapper.ApiDelimitExecResultMapper;
|
||||
import io.metersphere.api.jmeter.TestResult;
|
||||
import io.metersphere.base.domain.ApiDefinitionExecResult;
|
||||
import io.metersphere.base.mapper.ApiDefinitionExecResultMapper;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -14,16 +14,16 @@ import java.util.UUID;
|
|||
|
||||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class ApiDelimitExecResultService {
|
||||
public class ApiDefinitionExecResultService {
|
||||
@Resource
|
||||
private ApiDelimitExecResultMapper apiDelimitExecResultMapper;
|
||||
private ApiDefinitionExecResultMapper apiDefinitionExecResultMapper;
|
||||
|
||||
|
||||
public void saveApiResult(ApiTestResult result) {
|
||||
result.getRequestResults().forEach(item -> {
|
||||
public void saveApiResult(TestResult result) {
|
||||
result.getScenarios().get(0).getRequestResults().forEach(item -> {
|
||||
// 清理原始资源,每个执行 保留一条结果
|
||||
apiDelimitExecResultMapper.deleteByResourceId(item.getName());
|
||||
ApiDelimitExecResult saveResult = new ApiDelimitExecResult();
|
||||
apiDefinitionExecResultMapper.deleteByResourceId(item.getName());
|
||||
ApiDefinitionExecResult saveResult = new ApiDefinitionExecResult();
|
||||
saveResult.setId(UUID.randomUUID().toString());
|
||||
saveResult.setUserId(Objects.requireNonNull(SessionUtils.getUser()).getId());
|
||||
saveResult.setName(item.getUrl());
|
||||
|
@ -32,7 +32,7 @@ public class ApiDelimitExecResultService {
|
|||
saveResult.setStartTime(item.getStartTime());
|
||||
saveResult.setEndTime(item.getResponseResult().getResponseTime());
|
||||
saveResult.setStatus(item.getResponseResult().getResponseCode().equals("200") ? "success" : "error");
|
||||
apiDelimitExecResultMapper.insert(saveResult);
|
||||
apiDefinitionExecResultMapper.insert(saveResult);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -3,18 +3,19 @@ package io.metersphere.api.service;
|
|||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.metersphere.api.dto.APIReportResult;
|
||||
import io.metersphere.api.dto.delimit.ApiComputeResult;
|
||||
import io.metersphere.api.dto.delimit.ApiDelimitRequest;
|
||||
import io.metersphere.api.dto.delimit.ApiDelimitResult;
|
||||
import io.metersphere.api.dto.delimit.SaveApiDelimitRequest;
|
||||
import io.metersphere.api.jmeter.ApiTestResult;
|
||||
import io.metersphere.api.jmeter.DelimitJMeterService;
|
||||
import io.metersphere.api.parse.JmeterDocumentParser;
|
||||
import io.metersphere.api.dto.definition.ApiComputeResult;
|
||||
import io.metersphere.api.dto.definition.ApiDefinitionRequest;
|
||||
import io.metersphere.api.dto.definition.ApiDefinitionResult;
|
||||
import io.metersphere.api.dto.definition.SaveApiDefinitionRequest;
|
||||
import io.metersphere.api.dto.scenario.Scenario;
|
||||
import io.metersphere.api.jmeter.JMeterService;
|
||||
import io.metersphere.api.jmeter.TestResult;
|
||||
import io.metersphere.base.domain.*;
|
||||
import io.metersphere.base.mapper.ApiDelimitExecResultMapper;
|
||||
import io.metersphere.base.mapper.ApiDelimitMapper;
|
||||
import io.metersphere.base.mapper.ApiDefinitionExecResultMapper;
|
||||
import io.metersphere.base.mapper.ApiDefinitionMapper;
|
||||
import io.metersphere.base.mapper.ApiTestFileMapper;
|
||||
import io.metersphere.commons.constants.APITestStatus;
|
||||
import io.metersphere.commons.constants.ApiRunMode;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
|
@ -41,9 +42,9 @@ import java.util.stream.Collectors;
|
|||
|
||||
@Service
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class ApiDelimitService {
|
||||
public class ApiDefinitionService {
|
||||
@Resource
|
||||
private ApiDelimitMapper apiDelimitMapper;
|
||||
private ApiDefinitionMapper apiDefinitionMapper;
|
||||
@Resource
|
||||
private ApiTestFileMapper apiTestFileMapper;
|
||||
@Resource
|
||||
|
@ -51,21 +52,21 @@ public class ApiDelimitService {
|
|||
@Resource
|
||||
private ApiTestCaseService apiTestCaseService;
|
||||
@Resource
|
||||
private ApiDelimitExecResultMapper apiDelimitExecResultMapper;
|
||||
private ApiDefinitionExecResultMapper apiDefinitionExecResultMapper;
|
||||
@Resource
|
||||
private DelimitJMeterService jMeterService;
|
||||
private JMeterService jMeterService;
|
||||
private static Cache cache = Cache.newHardMemoryCache(0, 3600 * 24);
|
||||
|
||||
private static final String BODY_FILE_DIR = "/opt/metersphere/data/body";
|
||||
|
||||
public List<ApiDelimitResult> list(ApiDelimitRequest request) {
|
||||
public List<ApiDefinitionResult> list(ApiDefinitionRequest request) {
|
||||
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
|
||||
List<ApiDelimitResult> resList = apiDelimitMapper.list(request);
|
||||
List<ApiDefinitionResult> resList = apiDefinitionMapper.list(request);
|
||||
if (!resList.isEmpty()) {
|
||||
List<String> ids = resList.stream().map(ApiDelimitResult::getId).collect(Collectors.toList());
|
||||
List<ApiComputeResult> results = apiDelimitMapper.selectByIds(ids);
|
||||
Map<String, ApiComputeResult> resultMap = results.stream().collect(Collectors.toMap(ApiComputeResult::getApiDelimitId, Function.identity()));
|
||||
for (ApiDelimitResult res : resList) {
|
||||
List<String> ids = resList.stream().map(ApiDefinitionResult::getId).collect(Collectors.toList());
|
||||
List<ApiComputeResult> results = apiDefinitionMapper.selectByIds(ids);
|
||||
Map<String, ApiComputeResult> resultMap = results.stream().collect(Collectors.toMap(ApiComputeResult::getApiDefinitionId, Function.identity()));
|
||||
for (ApiDefinitionResult res : resList) {
|
||||
ApiComputeResult compRes = resultMap.get(res.getId());
|
||||
if (compRes != null) {
|
||||
res.setCaseTotal(compRes.getCaseTotal());
|
||||
|
@ -81,27 +82,16 @@ public class ApiDelimitService {
|
|||
return resList;
|
||||
}
|
||||
|
||||
public ApiDelimit get(String id) {
|
||||
return apiDelimitMapper.selectByPrimaryKey(id);
|
||||
public ApiDefinition get(String id) {
|
||||
return apiDefinitionMapper.selectByPrimaryKey(id);
|
||||
}
|
||||
|
||||
public void create(SaveApiDelimitRequest request, MultipartFile file, List<MultipartFile> bodyFiles) {
|
||||
public void create(SaveApiDefinitionRequest request, List<MultipartFile> bodyFiles) {
|
||||
List<String> bodyUploadIds = new ArrayList<>(request.getBodyUploadIds());
|
||||
ApiDelimit test = createTest(request, file);
|
||||
ApiDefinition test = createTest(request);
|
||||
createBodyFiles(test.getId(), bodyUploadIds, bodyFiles);
|
||||
}
|
||||
|
||||
private ApiDelimit createTest(SaveApiDelimitRequest request, MultipartFile file) {
|
||||
if (file == null) {
|
||||
throw new IllegalArgumentException(Translator.get("file_cannot_be_null"));
|
||||
}
|
||||
checkQuota();
|
||||
request.setBodyUploadIds(null);
|
||||
ApiDelimit test = createTest(request);
|
||||
saveFile(test.getId(), file);
|
||||
return test;
|
||||
}
|
||||
|
||||
private void checkQuota() {
|
||||
QuotaService quotaService = CommonBeanFactory.getBean(QuotaService.class);
|
||||
if (quotaService != null) {
|
||||
|
@ -109,17 +99,13 @@ public class ApiDelimitService {
|
|||
}
|
||||
}
|
||||
|
||||
public void update(SaveApiDelimitRequest request, MultipartFile file, List<MultipartFile> bodyFiles) {
|
||||
if (file == null) {
|
||||
throw new IllegalArgumentException(Translator.get("file_cannot_be_null"));
|
||||
}
|
||||
public void update(SaveApiDefinitionRequest request, List<MultipartFile> bodyFiles) {
|
||||
deleteFileByTestId(request.getId());
|
||||
|
||||
List<String> bodyUploadIds = new ArrayList<>(request.getBodyUploadIds());
|
||||
request.setBodyUploadIds(null);
|
||||
ApiDelimit test = updateTest(request);
|
||||
ApiDefinition test = updateTest(request);
|
||||
createBodyFiles(test.getId(), bodyUploadIds, bodyFiles);
|
||||
saveFile(test.getId(), file);
|
||||
}
|
||||
|
||||
private void createBodyFiles(String testId, List<String> bodyUploadIds, List<MultipartFile> bodyFiles) {
|
||||
|
@ -146,8 +132,8 @@ public class ApiDelimitService {
|
|||
public void delete(String apiId) {
|
||||
apiTestCaseService.checkIsRelateTest(apiId);
|
||||
deleteFileByTestId(apiId);
|
||||
apiDelimitExecResultMapper.deleteByResourceId(apiId);
|
||||
apiDelimitMapper.deleteByPrimaryKey(apiId);
|
||||
apiDefinitionExecResultMapper.deleteByResourceId(apiId);
|
||||
apiDefinitionMapper.deleteByPrimaryKey(apiId);
|
||||
deleteBodyFiles(apiId);
|
||||
}
|
||||
|
||||
|
@ -167,18 +153,18 @@ public class ApiDelimitService {
|
|||
}
|
||||
}
|
||||
|
||||
private void checkNameExist(SaveApiDelimitRequest request) {
|
||||
ApiDelimitExample example = new ApiDelimitExample();
|
||||
private void checkNameExist(SaveApiDefinitionRequest request) {
|
||||
ApiDefinitionExample example = new ApiDefinitionExample();
|
||||
example.createCriteria().andUrlEqualTo(request.getUrl()).andProjectIdEqualTo(request.getProjectId()).andIdNotEqualTo(request.getId());
|
||||
if (apiDelimitMapper.countByExample(example) > 0) {
|
||||
MSException.throwException(Translator.get("api_delimit_url_not_repeating"));
|
||||
if (apiDefinitionMapper.countByExample(example) > 0) {
|
||||
MSException.throwException(Translator.get("api_definition_url_not_repeating"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private ApiDelimit updateTest(SaveApiDelimitRequest request) {
|
||||
private ApiDefinition updateTest(SaveApiDefinitionRequest request) {
|
||||
checkNameExist(request);
|
||||
final ApiDelimit test = new ApiDelimit();
|
||||
final ApiDefinition test = new ApiDefinition();
|
||||
test.setId(request.getId());
|
||||
test.setName(request.getName());
|
||||
test.setProjectId(request.getProjectId());
|
||||
|
@ -187,24 +173,24 @@ public class ApiDelimitService {
|
|||
test.setStatus(request.getStatus());
|
||||
test.setModulePath(request.getModulePath());
|
||||
test.setModuleId(request.getModuleId());
|
||||
test.setPath(request.getPath());
|
||||
test.setMethod(request.getMethod());
|
||||
test.setUrl(request.getUrl());
|
||||
test.setDescription(request.getDescription());
|
||||
test.setResponse(JSONObject.toJSONString(request.getResponse()));
|
||||
test.setEnvironmentId(request.getEnvironmentId());
|
||||
test.setUserId(request.getUserId());
|
||||
|
||||
apiDelimitMapper.updateByPrimaryKeySelective(test);
|
||||
apiDefinitionMapper.updateByPrimaryKeySelective(test);
|
||||
return test;
|
||||
}
|
||||
|
||||
private ApiDelimit createTest(SaveApiDelimitRequest request) {
|
||||
private ApiDefinition createTest(SaveApiDefinitionRequest request) {
|
||||
checkNameExist(request);
|
||||
final ApiDelimit test = new ApiDelimit();
|
||||
final ApiDefinition test = new ApiDefinition();
|
||||
test.setId(request.getId());
|
||||
test.setName(request.getName());
|
||||
test.setUrl(request.getUrl());
|
||||
test.setPath(request.getPath());
|
||||
test.setMethod(request.getMethod());
|
||||
test.setModuleId(request.getModuleId());
|
||||
test.setProjectId(request.getProjectId());
|
||||
test.setRequest(JSONObject.toJSONString(request.getRequest()));
|
||||
|
@ -220,7 +206,7 @@ public class ApiDelimitService {
|
|||
test.setUserId(request.getUserId());
|
||||
}
|
||||
test.setDescription(request.getDescription());
|
||||
apiDelimitMapper.insert(test);
|
||||
apiDefinitionMapper.insert(test);
|
||||
return test;
|
||||
}
|
||||
|
||||
|
@ -248,57 +234,55 @@ public class ApiDelimitService {
|
|||
* 测试执行
|
||||
*
|
||||
* @param request
|
||||
* @param file
|
||||
* @param bodyFiles
|
||||
* @return
|
||||
*/
|
||||
public String run(SaveApiDelimitRequest request, MultipartFile file, List<MultipartFile> bodyFiles) {
|
||||
if (file == null) {
|
||||
throw new IllegalArgumentException(Translator.get("file_cannot_be_null"));
|
||||
}
|
||||
public String run(SaveApiDefinitionRequest request, List<MultipartFile> bodyFiles) {
|
||||
List<String> bodyUploadIds = new ArrayList<>(request.getBodyUploadIds());
|
||||
createBodyFiles(request.getId(), bodyUploadIds, bodyFiles);
|
||||
InputStream is = null;
|
||||
try {
|
||||
// 解析 xml 处理 mock 数据
|
||||
byte[] bytes = JmeterDocumentParser.parse(file.getBytes());
|
||||
is = new ByteArrayInputStream(bytes);
|
||||
} catch (IOException e) {
|
||||
LogUtil.error(e);
|
||||
}
|
||||
jMeterService.run(request.getId(), request.getReportId(), is);
|
||||
|
||||
List<Scenario> scenarios = new ArrayList<>();
|
||||
scenarios.add(request.getScenario());
|
||||
jMeterService.run(request.getId(), request.getName(), scenarios, request.getReportId(), ApiRunMode.DELIMIT.name());
|
||||
return request.getId();
|
||||
}
|
||||
|
||||
public void addResult(ApiTestResult res) {
|
||||
cache.put(res.getId(), res);
|
||||
public void addResult(TestResult res) {
|
||||
if (!res.getScenarios().isEmpty() && !res.getScenarios().get(0).getRequestResults().isEmpty()) {
|
||||
cache.put(res.getTestId(), res.getScenarios().get(0).getRequestResults().get(0));
|
||||
} else {
|
||||
MSException.throwException(Translator.get("test_not_found"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取执行结果报告
|
||||
* 获取零时执行结果报告
|
||||
*
|
||||
* @param testId
|
||||
* @param test
|
||||
* @return
|
||||
*/
|
||||
public APIReportResult getResult(String testId, String test) {
|
||||
if (test.equals("debug")) {
|
||||
Object res = cache.get(testId);
|
||||
if (res != null) {
|
||||
cache.remove(testId);
|
||||
APIReportResult reportResult = new APIReportResult();
|
||||
reportResult.setContent(JSON.toJSONString(res));
|
||||
return reportResult;
|
||||
}
|
||||
} else {
|
||||
ApiDelimitExecResult data = apiDelimitExecResultMapper.selectByResourceId(testId);
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
Object res = cache.get(testId);
|
||||
if (res != null) {
|
||||
cache.remove(testId);
|
||||
APIReportResult reportResult = new APIReportResult();
|
||||
reportResult.setContent(data.getContent());
|
||||
reportResult.setContent(JSON.toJSONString(res));
|
||||
return reportResult;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取存储执行结果报告
|
||||
*
|
||||
* @param testId
|
||||
* @return
|
||||
*/
|
||||
public APIReportResult getDbResult(String testId) {
|
||||
ApiDefinitionExecResult result = apiDefinitionExecResultMapper.selectByResourceId(testId);
|
||||
APIReportResult reportResult = new APIReportResult();
|
||||
reportResult.setContent(result.getContent());
|
||||
return reportResult;
|
||||
}
|
||||
}
|
|
@ -1,14 +1,14 @@
|
|||
package io.metersphere.api.service;
|
||||
|
||||
|
||||
import io.metersphere.api.dto.delimit.ApiDelimitRequest;
|
||||
import io.metersphere.api.dto.delimit.ApiDelimitResult;
|
||||
import io.metersphere.api.dto.delimit.ApiModuleDTO;
|
||||
import io.metersphere.api.dto.delimit.DragModuleRequest;
|
||||
import io.metersphere.base.domain.ApiDelimitExample;
|
||||
import io.metersphere.api.dto.definition.ApiDefinitionRequest;
|
||||
import io.metersphere.api.dto.definition.ApiDefinitionResult;
|
||||
import io.metersphere.api.dto.definition.ApiModuleDTO;
|
||||
import io.metersphere.api.dto.definition.DragModuleRequest;
|
||||
import io.metersphere.base.domain.ApiDefinitionExample;
|
||||
import io.metersphere.base.domain.ApiModule;
|
||||
import io.metersphere.base.domain.ApiModuleExample;
|
||||
import io.metersphere.base.mapper.ApiDelimitMapper;
|
||||
import io.metersphere.base.mapper.ApiDefinitionMapper;
|
||||
import io.metersphere.base.mapper.ApiModuleMapper;
|
||||
import io.metersphere.commons.constants.TestCaseConstants;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
|
@ -32,16 +32,16 @@ public class ApiModuleService {
|
|||
@Resource
|
||||
ApiModuleMapper apiModuleMapper;
|
||||
@Resource
|
||||
private ApiDelimitMapper apiDelimitMapper;
|
||||
private ApiDefinitionMapper apiDefinitionMapper;
|
||||
@Resource
|
||||
SqlSessionFactory sqlSessionFactory;
|
||||
|
||||
public List<ApiModuleDTO> getNodeTreeByProjectId(String projectId, String protocol) {
|
||||
ApiModuleExample apiDelimitNodeExample = new ApiModuleExample();
|
||||
apiDelimitNodeExample.createCriteria().andProjectIdEqualTo(projectId);
|
||||
apiDelimitNodeExample.createCriteria().andProtocolEqualTo(protocol);
|
||||
apiDelimitNodeExample.setOrderByClause("create_time asc");
|
||||
List<ApiModule> nodes = apiModuleMapper.selectByExample(apiDelimitNodeExample);
|
||||
ApiModuleExample apiDefinitionNodeExample = new ApiModuleExample();
|
||||
apiDefinitionNodeExample.createCriteria().andProjectIdEqualTo(projectId);
|
||||
apiDefinitionNodeExample.createCriteria().andProtocolEqualTo(protocol);
|
||||
apiDefinitionNodeExample.setOrderByClause("create_time asc");
|
||||
List<ApiModule> nodes = apiModuleMapper.selectByExample(apiDefinitionNodeExample);
|
||||
return getNodeTrees(nodes);
|
||||
}
|
||||
|
||||
|
@ -130,48 +130,48 @@ public class ApiModuleService {
|
|||
}
|
||||
}
|
||||
|
||||
private List<ApiDelimitResult> queryByModuleIds(List<String> nodeIds) {
|
||||
ApiDelimitRequest apiDelimitRequest = new ApiDelimitRequest();
|
||||
apiDelimitRequest.setModuleIds(nodeIds);
|
||||
return apiDelimitMapper.list(apiDelimitRequest);
|
||||
private List<ApiDefinitionResult> queryByModuleIds(List<String> nodeIds) {
|
||||
ApiDefinitionRequest apiDefinitionRequest = new ApiDefinitionRequest();
|
||||
apiDefinitionRequest.setModuleIds(nodeIds);
|
||||
return apiDefinitionMapper.list(apiDefinitionRequest);
|
||||
}
|
||||
|
||||
public int editNode(DragModuleRequest request) {
|
||||
request.setUpdateTime(System.currentTimeMillis());
|
||||
checkApiModuleExist(request);
|
||||
List<ApiDelimitResult> apiModule = queryByModuleIds(request.getNodeIds());
|
||||
List<ApiDefinitionResult> apiModule = queryByModuleIds(request.getNodeIds());
|
||||
|
||||
apiModule.forEach(apiDelimit -> {
|
||||
StringBuilder path = new StringBuilder(apiDelimit.getModulePath());
|
||||
apiModule.forEach(apiDefinition -> {
|
||||
StringBuilder path = new StringBuilder(apiDefinition.getModulePath());
|
||||
List<String> pathLists = Arrays.asList(path.toString().split("/"));
|
||||
pathLists.set(request.getLevel(), request.getName());
|
||||
path.delete(0, path.length());
|
||||
for (int i = 1; i < pathLists.size(); i++) {
|
||||
path = path.append("/").append(pathLists.get(i));
|
||||
}
|
||||
apiDelimit.setModulePath(path.toString());
|
||||
apiDefinition.setModulePath(path.toString());
|
||||
});
|
||||
|
||||
batchUpdateApiDelimit(apiModule);
|
||||
batchUpdateApiDefinition(apiModule);
|
||||
|
||||
return apiModuleMapper.updateByPrimaryKeySelective(request);
|
||||
}
|
||||
|
||||
public int deleteNode(List<String> nodeIds) {
|
||||
ApiDelimitExample apiDelimitExample = new ApiDelimitExample();
|
||||
apiDelimitExample.createCriteria().andModuleIdIn(nodeIds);
|
||||
apiDelimitMapper.deleteByExample(apiDelimitExample);
|
||||
ApiDefinitionExample apiDefinitionExample = new ApiDefinitionExample();
|
||||
apiDefinitionExample.createCriteria().andModuleIdIn(nodeIds);
|
||||
apiDefinitionMapper.deleteByExample(apiDefinitionExample);
|
||||
|
||||
ApiModuleExample apiDelimitNodeExample = new ApiModuleExample();
|
||||
apiDelimitNodeExample.createCriteria().andIdIn(nodeIds);
|
||||
return apiModuleMapper.deleteByExample(apiDelimitNodeExample);
|
||||
ApiModuleExample apiDefinitionNodeExample = new ApiModuleExample();
|
||||
apiDefinitionNodeExample.createCriteria().andIdIn(nodeIds);
|
||||
return apiModuleMapper.deleteByExample(apiDefinitionNodeExample);
|
||||
}
|
||||
|
||||
private void batchUpdateApiDelimit(List<ApiDelimitResult> apiModule) {
|
||||
private void batchUpdateApiDefinition(List<ApiDefinitionResult> apiModule) {
|
||||
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
||||
ApiDelimitMapper apiDelimitMapper = sqlSession.getMapper(ApiDelimitMapper.class);
|
||||
ApiDefinitionMapper apiDefinitionMapper = sqlSession.getMapper(ApiDefinitionMapper.class);
|
||||
apiModule.forEach((value) -> {
|
||||
apiDelimitMapper.updateByPrimaryKey(value);
|
||||
apiDefinitionMapper.updateByPrimaryKey(value);
|
||||
});
|
||||
sqlSession.flushStatements();
|
||||
}
|
||||
|
@ -182,13 +182,13 @@ public class ApiModuleService {
|
|||
|
||||
List<String> nodeIds = request.getNodeIds();
|
||||
|
||||
List<ApiDelimitResult> apiModule = queryByModuleIds(nodeIds);
|
||||
List<ApiDefinitionResult> apiModule = queryByModuleIds(nodeIds);
|
||||
|
||||
ApiModuleDTO nodeTree = request.getNodeTree();
|
||||
|
||||
List<ApiModule> updateNodes = new ArrayList<>();
|
||||
|
||||
buildUpdateDelimit(nodeTree, apiModule, updateNodes, "/", "0", nodeTree.getLevel());
|
||||
buildUpdateDefinition(nodeTree, apiModule, updateNodes, "/", "0", nodeTree.getLevel());
|
||||
|
||||
updateNodes = updateNodes.stream()
|
||||
.filter(item -> nodeIds.contains(item.getId()))
|
||||
|
@ -196,10 +196,10 @@ public class ApiModuleService {
|
|||
|
||||
batchUpdateModule(updateNodes);
|
||||
|
||||
batchUpdateApiDelimit(apiModule);
|
||||
batchUpdateApiDefinition(apiModule);
|
||||
}
|
||||
|
||||
private void buildUpdateDelimit(ApiModuleDTO rootNode, List<ApiDelimitResult> apiDelimits,
|
||||
private void buildUpdateDefinition(ApiModuleDTO rootNode, List<ApiDefinitionResult> apiDefinitions,
|
||||
List<ApiModule> updateNodes, String rootPath, String pId, int level) {
|
||||
|
||||
rootPath = rootPath + rootNode.getName();
|
||||
|
@ -210,13 +210,13 @@ public class ApiModuleService {
|
|||
if (rootNode.getId().equals("root")) {
|
||||
rootPath = "";
|
||||
}
|
||||
ApiModule apiDelimitNode = new ApiModule();
|
||||
apiDelimitNode.setId(rootNode.getId());
|
||||
apiDelimitNode.setLevel(level);
|
||||
apiDelimitNode.setParentId(pId);
|
||||
updateNodes.add(apiDelimitNode);
|
||||
ApiModule apiDefinitionNode = new ApiModule();
|
||||
apiDefinitionNode.setId(rootNode.getId());
|
||||
apiDefinitionNode.setLevel(level);
|
||||
apiDefinitionNode.setParentId(pId);
|
||||
updateNodes.add(apiDefinitionNode);
|
||||
|
||||
for (ApiDelimitResult item : apiDelimits) {
|
||||
for (ApiDefinitionResult item : apiDefinitions) {
|
||||
if (StringUtils.equals(item.getModuleId(), rootNode.getId())) {
|
||||
item.setModulePath(rootPath);
|
||||
}
|
||||
|
@ -225,7 +225,7 @@ public class ApiModuleService {
|
|||
List<ApiModuleDTO> children = rootNode.getChildren();
|
||||
if (children != null && children.size() > 0) {
|
||||
for (int i = 0; i < children.size(); i++) {
|
||||
buildUpdateDelimit(children.get(i), apiDelimits, updateNodes, rootPath + '/', rootNode.getId(), level + 1);
|
||||
buildUpdateDefinition(children.get(i), apiDefinitions, updateNodes, rootPath + '/', rootNode.getId(), level + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package io.metersphere.api.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.metersphere.api.dto.delimit.ApiTestCaseRequest;
|
||||
import io.metersphere.api.dto.delimit.ApiTestCaseResult;
|
||||
import io.metersphere.api.dto.delimit.SaveApiTestCaseRequest;
|
||||
import io.metersphere.api.dto.definition.ApiTestCaseRequest;
|
||||
import io.metersphere.api.dto.definition.ApiTestCaseResult;
|
||||
import io.metersphere.api.dto.definition.SaveApiTestCaseRequest;
|
||||
import io.metersphere.base.domain.*;
|
||||
import io.metersphere.base.mapper.ApiDelimitExecResultMapper;
|
||||
import io.metersphere.base.mapper.ApiDefinitionExecResultMapper;
|
||||
import io.metersphere.base.mapper.ApiTestCaseMapper;
|
||||
import io.metersphere.base.mapper.ApiTestFileMapper;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
|
@ -40,7 +40,7 @@ public class ApiTestCaseService {
|
|||
@Resource
|
||||
private FileService fileService;
|
||||
@Resource
|
||||
private ApiDelimitExecResultMapper apiDelimitExecResultMapper;
|
||||
private ApiDefinitionExecResultMapper apiDefinitionExecResultMapper;
|
||||
|
||||
private static final String BODY_FILE_DIR = "/opt/metersphere/data/body";
|
||||
|
||||
|
@ -113,7 +113,7 @@ public class ApiTestCaseService {
|
|||
|
||||
public void delete(String testId) {
|
||||
deleteFileByTestId(testId);
|
||||
apiDelimitExecResultMapper.deleteByResourceId(testId);
|
||||
apiDefinitionExecResultMapper.deleteByResourceId(testId);
|
||||
apiTestCaseMapper.deleteByPrimaryKey(testId);
|
||||
deleteBodyFiles(testId);
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ public class ApiTestCaseService {
|
|||
*/
|
||||
public void checkIsRelateTest(String apiId) {
|
||||
ApiTestCaseExample testCaseExample = new ApiTestCaseExample();
|
||||
testCaseExample.createCriteria().andApiDelimitIdEqualTo(apiId);
|
||||
testCaseExample.createCriteria().andApiDefinitionIdEqualTo(apiId);
|
||||
List<ApiTestCase> testCases = apiTestCaseMapper.selectByExample(testCaseExample);
|
||||
StringBuilder caseName = new StringBuilder();
|
||||
if (testCases.size() > 0) {
|
||||
|
@ -145,7 +145,7 @@ public class ApiTestCaseService {
|
|||
|
||||
private void checkNameExist(SaveApiTestCaseRequest request) {
|
||||
ApiTestCaseExample example = new ApiTestCaseExample();
|
||||
example.createCriteria().andNameEqualTo(request.getName()).andApiDelimitIdEqualTo(request.getApiDelimitId()).andIdNotEqualTo(request.getId());
|
||||
example.createCriteria().andNameEqualTo(request.getName()).andApiDefinitionIdEqualTo(request.getApiDefinitionId()).andIdNotEqualTo(request.getId());
|
||||
if (apiTestCaseMapper.countByExample(example) > 0) {
|
||||
MSException.throwException(Translator.get("load_test_already_exists"));
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ public class ApiTestCaseService {
|
|||
final ApiTestCase test = new ApiTestCase();
|
||||
test.setId(request.getId());
|
||||
test.setName(request.getName());
|
||||
test.setApiDelimitId(request.getApiDelimitId());
|
||||
test.setApiDefinitionId(request.getApiDefinitionId());
|
||||
test.setUpdateUserId(Objects.requireNonNull(SessionUtils.getUser()).getId());
|
||||
test.setProjectId(request.getProjectId());
|
||||
test.setRequest(JSONObject.toJSONString(request.getRequest()));
|
||||
|
@ -175,7 +175,7 @@ public class ApiTestCaseService {
|
|||
final ApiTestCase test = new ApiTestCase();
|
||||
test.setId(request.getId());
|
||||
test.setName(request.getName());
|
||||
test.setApiDelimitId(request.getApiDelimitId());
|
||||
test.setApiDefinitionId(request.getApiDefinitionId());
|
||||
test.setCreateUserId(Objects.requireNonNull(SessionUtils.getUser()).getId());
|
||||
test.setUpdateUserId(Objects.requireNonNull(SessionUtils.getUser()).getId());
|
||||
test.setProjectId(request.getProjectId());
|
||||
|
|
|
@ -5,14 +5,14 @@ import lombok.Data;
|
|||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class ApiDelimit implements Serializable {
|
||||
public class ApiDefinition implements Serializable {
|
||||
private String id;
|
||||
|
||||
private String projectId;
|
||||
|
||||
private String name;
|
||||
|
||||
private String path;
|
||||
private String method;
|
||||
|
||||
private String url;
|
||||
|
|
@ -3,14 +3,14 @@ package io.metersphere.base.domain;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ApiDelimitExample {
|
||||
public class ApiDefinitionExample {
|
||||
protected String orderByClause;
|
||||
|
||||
protected boolean distinct;
|
||||
|
||||
protected List<Criteria> oredCriteria;
|
||||
|
||||
public ApiDelimitExample() {
|
||||
public ApiDefinitionExample() {
|
||||
oredCriteria = new ArrayList<Criteria>();
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@ import lombok.Data;
|
|||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class ApiDelimitExecResult implements Serializable {
|
||||
public class ApiDefinitionExecResult implements Serializable {
|
||||
private String id;
|
||||
private String resourceId;
|
||||
private String name;
|
|
@ -14,7 +14,7 @@ public class ApiTestCase implements Serializable {
|
|||
|
||||
private String priority;
|
||||
|
||||
private String apiDelimitId;
|
||||
private String apiDefinitionId;
|
||||
|
||||
private String description;
|
||||
|
||||
|
|
|
@ -194,8 +194,8 @@ public class ApiTestCaseExample {
|
|||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andApiDelimitIdEqualTo(String value) {
|
||||
addCriterion("api_delimit_id =", value, "api_delimit_id");
|
||||
public Criteria andApiDefinitionIdEqualTo(String value) {
|
||||
addCriterion("api_definition_id =", value, "api_definition_id");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package io.metersphere.base.mapper;
|
||||
|
||||
import io.metersphere.base.domain.ApiDefinitionExecResult;
|
||||
|
||||
public interface ApiDefinitionExecResultMapper {
|
||||
|
||||
int deleteByResourceId(String id);
|
||||
|
||||
int insert(ApiDefinitionExecResult record);
|
||||
|
||||
ApiDefinitionExecResult selectByResourceId(String resourceId);
|
||||
|
||||
ApiDefinitionExecResult selectByPrimaryKey(String id);
|
||||
|
||||
}
|
|
@ -1,26 +1,26 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="io.metersphere.base.mapper.ApiDelimitExecResultMapper">
|
||||
<mapper namespace="io.metersphere.base.mapper.ApiDefinitionExecResultMapper">
|
||||
|
||||
<delete id="deleteByResourceId" parameterType="java.lang.String">
|
||||
delete from api_delimit_exec_result where resource_id = #{id,jdbcType=VARCHAR}
|
||||
delete from api_definition_exec_result where resource_id = #{id,jdbcType=VARCHAR}
|
||||
</delete>
|
||||
|
||||
<insert id="insert" parameterType="io.metersphere.base.domain.ApiDelimitExecResult">
|
||||
insert into api_delimit_exec_result
|
||||
<insert id="insert" parameterType="io.metersphere.base.domain.ApiDefinitionExecResult">
|
||||
insert into api_definition_exec_result
|
||||
(id, resource_id,name,content, status, user_id, start_time, end_time)
|
||||
values
|
||||
(#{id,jdbcType=VARCHAR}, #{resourceId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{content,jdbcType=LONGVARCHAR}, #{status,jdbcType=VARCHAR}, #{userId,jdbcType=VARCHAR},
|
||||
#{startTime,jdbcType=BIGINT}, #{endTime,jdbcType=BIGINT})
|
||||
</insert>
|
||||
|
||||
<select id="selectByResourceId" parameterType="java.lang.String" resultType="io.metersphere.base.domain.ApiDelimitExecResult">
|
||||
select * from api_delimit_exec_result
|
||||
<select id="selectByResourceId" parameterType="java.lang.String" resultType="io.metersphere.base.domain.ApiDefinitionExecResult">
|
||||
select * from api_definition_exec_result
|
||||
where resource_id = #{resourceId,jdbcType=VARCHAR}
|
||||
</select>
|
||||
|
||||
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultType="io.metersphere.base.domain.ApiDelimitExecResult">
|
||||
select * from api_delimit_exec_result
|
||||
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultType="io.metersphere.base.domain.ApiDefinitionExecResult">
|
||||
select * from api_definition_exec_result
|
||||
where id = #{id,jdbcType=VARCHAR}
|
||||
</select>
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
package io.metersphere.base.mapper;
|
||||
|
||||
import io.metersphere.api.dto.definition.ApiComputeResult;
|
||||
import io.metersphere.api.dto.definition.ApiDefinitionRequest;
|
||||
import io.metersphere.api.dto.definition.ApiDefinitionResult;
|
||||
import io.metersphere.base.domain.ApiDefinition;
|
||||
import io.metersphere.base.domain.ApiDefinitionExample;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ApiDefinitionMapper {
|
||||
|
||||
List<ApiDefinitionResult> list(@Param("request") ApiDefinitionRequest request);
|
||||
|
||||
List<ApiComputeResult> selectByIds(@Param("ids") List<String> ids);
|
||||
|
||||
long countByExample(ApiDefinitionExample example);
|
||||
|
||||
int deleteByExample(ApiDefinitionExample example);
|
||||
|
||||
int deleteByPrimaryKey(String id);
|
||||
|
||||
int insert(ApiDefinition record);
|
||||
|
||||
|
||||
List<ApiDefinition> selectByExampleWithBLOBs(ApiDefinitionExample example);
|
||||
|
||||
List<ApiDefinition> selectByExample(ApiDefinitionExample example);
|
||||
|
||||
ApiDefinition selectByPrimaryKey(String id);
|
||||
|
||||
|
||||
int updateByPrimaryKeySelective(ApiDefinition record);
|
||||
|
||||
int updateByPrimaryKeyWithBLOBs(ApiDefinition record);
|
||||
|
||||
int updateByPrimaryKey(ApiDefinition record);
|
||||
}
|
|
@ -1,21 +1,21 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="io.metersphere.base.mapper.ApiDelimitMapper">
|
||||
<resultMap id="BaseResultMap" type="io.metersphere.base.domain.ApiDelimit">
|
||||
<mapper namespace="io.metersphere.base.mapper.ApiDefinitionMapper">
|
||||
<resultMap id="BaseResultMap" type="io.metersphere.base.domain.ApiDefinition">
|
||||
<id column="id" jdbcType="VARCHAR" property="id"/>
|
||||
<result column="project_id" jdbcType="VARCHAR" property="projectId"/>
|
||||
<result column="module_id" jdbcType="VARCHAR" property="moduleId"/>
|
||||
<result column="module_path" jdbcType="VARCHAR" property="modulePath"/>
|
||||
<result column="name" jdbcType="VARCHAR" property="name"/>
|
||||
<result column="url" jdbcType="VARCHAR" property="url"/>
|
||||
<result column="path" jdbcType="VARCHAR" property="path"/>
|
||||
<result column="method" jdbcType="VARCHAR" property="method"/>
|
||||
<result column="description" jdbcType="VARCHAR" property="description"/>
|
||||
<result column="status" jdbcType="VARCHAR" property="status"/>
|
||||
<result column="user_id" jdbcType="VARCHAR" property="userId"/>
|
||||
<result column="create_time" jdbcType="BIGINT" property="createTime"/>
|
||||
<result column="update_time" jdbcType="BIGINT" property="updateTime"/>
|
||||
</resultMap>
|
||||
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="io.metersphere.base.domain.ApiDelimit">
|
||||
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="io.metersphere.base.domain.ApiDefinition">
|
||||
<result column="request" jdbcType="LONGVARCHAR" property="request"/>
|
||||
<result column="response" jdbcType="LONGVARCHAR" property="response"/>
|
||||
</resultMap>
|
||||
|
@ -80,12 +80,12 @@
|
|||
</where>
|
||||
</sql>
|
||||
<sql id="Base_Column_List">
|
||||
id, project_id, name,module_id,module_path,url ,path ,description, status, user_id, create_time, update_time
|
||||
id, project_id, name,module_id,module_path,url ,method ,description, status, user_id, create_time, update_time
|
||||
</sql>
|
||||
<sql id="Blob_Column_List">
|
||||
request
|
||||
</sql>
|
||||
<select id="selectByExampleWithBLOBs" parameterType="io.metersphere.base.domain.ApiDelimitExample"
|
||||
<select id="selectByExampleWithBLOBs" parameterType="io.metersphere.base.domain.ApiDefinitionExample"
|
||||
resultMap="ResultMapWithBLOBs">
|
||||
select
|
||||
<if test="distinct">
|
||||
|
@ -94,7 +94,7 @@
|
|||
<include refid="Base_Column_List"/>
|
||||
,
|
||||
<include refid="Blob_Column_List"/>
|
||||
from api_delimit
|
||||
from api_definition
|
||||
<if test="_parameter != null">
|
||||
<include refid="Example_Where_Clause"/>
|
||||
</if>
|
||||
|
@ -104,15 +104,15 @@
|
|||
</select>
|
||||
|
||||
|
||||
<select id="selectByIds" resultType="io.metersphere.api.dto.delimit.ApiComputeResult">
|
||||
select t1.api_delimit_id apiDelimitId,count(t1.id) caseTotal,
|
||||
<select id="selectByIds" resultType="io.metersphere.api.dto.definition.ApiComputeResult">
|
||||
select t1.api_definition_id apiDefinitionId,count(t1.id) caseTotal,
|
||||
case t2.status
|
||||
when 'success' then '通过'
|
||||
when 'error' then '未通过'
|
||||
ELSE '未执行' end as status ,
|
||||
CONCAT(FORMAT(SUM(IF(t2.`status` = 'success', 1, 0))/ COUNT(t1.id)*100, 2), '%') passRate
|
||||
from api_test_case t1 left join api_delimit_exec_result t2 on t1.id = t2.resource_id
|
||||
group by t1.api_delimit_id having t1.api_delimit_id in
|
||||
from api_test_case t1 left join api_definition_exec_result t2 on t1.id = t2.resource_id
|
||||
group by t1.api_definition_id having t1.api_definition_id in
|
||||
<foreach collection="ids" item="v" separator="," open="(" close=")">
|
||||
#{v}
|
||||
</foreach>
|
||||
|
@ -121,13 +121,13 @@
|
|||
|
||||
<sql id="combine">
|
||||
<if test='${condition}.name != null and (${name} == null or ${name} == "")'>
|
||||
and api_delimit.name
|
||||
and api_definition.name
|
||||
<include refid="condition">
|
||||
<property name="object" value="${condition}.name"/>
|
||||
</include>
|
||||
</if>
|
||||
<if test="${condition}.updateTime != null">
|
||||
and api_delimit.update_time
|
||||
and api_definition.update_time
|
||||
<include refid="condition">
|
||||
<property name="object" value="${condition}.updateTime"/>
|
||||
</include>
|
||||
|
@ -139,19 +139,19 @@
|
|||
</include>
|
||||
</if>
|
||||
<if test="${condition}.createTime != null">
|
||||
and api_delimit.create_time
|
||||
and api_definition.create_time
|
||||
<include refid="condition">
|
||||
<property name="object" value="${condition}.createTime"/>
|
||||
</include>
|
||||
</if>
|
||||
<if test="${condition}.status != null">
|
||||
and api_delimit.status
|
||||
and api_definition.status
|
||||
<include refid="condition">
|
||||
<property name="object" value="${condition}.status"/>
|
||||
</include>
|
||||
</if>
|
||||
<if test="${condition}.creator != null">
|
||||
and api_delimit.user_id
|
||||
and api_definition.user_id
|
||||
<include refid="condition">
|
||||
<property name="object" value="${condition}.creator"/>
|
||||
</include>
|
||||
|
@ -202,15 +202,15 @@
|
|||
</choose>
|
||||
</sql>
|
||||
|
||||
<select id="list" resultType="io.metersphere.api.dto.delimit.ApiDelimitResult">
|
||||
select api_delimit.id, api_delimit.project_id,
|
||||
api_delimit.name,api_delimit.url,api_delimit.module_id,api_delimit.module_path,api_delimit.path,
|
||||
api_delimit.description,api_delimit.request,api_delimit.response,api_delimit.environment_id,
|
||||
api_delimit.status, api_delimit.user_id, api_delimit.create_time, api_delimit.update_time, project.name as
|
||||
<select id="list" resultType="io.metersphere.api.dto.definition.ApiDefinitionResult">
|
||||
select api_definition.id, api_definition.project_id,
|
||||
api_definition.name,api_definition.url,api_definition.module_id,api_definition.module_path,api_definition.method,
|
||||
api_definition.description,api_definition.request,api_definition.response,api_definition.environment_id,
|
||||
api_definition.status, api_definition.user_id, api_definition.create_time, api_definition.update_time, project.name as
|
||||
project_name, user.name as user_name
|
||||
from api_delimit
|
||||
left join project on api_delimit.project_id = project.id
|
||||
left join user on api_delimit.user_id = user.id
|
||||
from api_definition
|
||||
left join project on api_definition.project_id = project.id
|
||||
left join user on api_definition.user_id = user.id
|
||||
<where>
|
||||
<if test="request.combine != null">
|
||||
<include refid="combine">
|
||||
|
@ -220,7 +220,7 @@
|
|||
</if>
|
||||
|
||||
<if test="request.name != null">
|
||||
and api_delimit.name like CONCAT('%', #{request.name},'%')
|
||||
and api_definition.name like CONCAT('%', #{request.name},'%')
|
||||
</if>
|
||||
<if test="request.workspaceId != null">
|
||||
AND project.workspace_id = #{request.workspaceId}
|
||||
|
@ -229,19 +229,19 @@
|
|||
AND project.id = #{request.projectId}
|
||||
</if>
|
||||
<if test="request.id != null">
|
||||
AND api_delimit.id = #{request.id}
|
||||
AND api_definition.id = #{request.id}
|
||||
</if>
|
||||
<if test="request.userId != null">
|
||||
AND api_delimit.user_id = #{request.userId}
|
||||
AND api_definition.user_id = #{request.userId}
|
||||
</if>
|
||||
<if test="request.moduleId != null">
|
||||
AND api_delimit.module_id = #{request.moduleId}
|
||||
AND api_definition.module_id = #{request.moduleId}
|
||||
</if>
|
||||
<if test="request.projectId != null">
|
||||
AND api_delimit.project_id = #{request.projectId}
|
||||
AND api_definition.project_id = #{request.projectId}
|
||||
</if>
|
||||
<if test="request.moduleIds != null and request.moduleIds.size() > 0">
|
||||
AND api_delimit.module_id in
|
||||
AND api_definition.module_id in
|
||||
<foreach collection="request.moduleIds" item="nodeId" separator="," open="(" close=")">
|
||||
#{nodeId}
|
||||
</foreach>
|
||||
|
@ -250,7 +250,7 @@
|
|||
<foreach collection="request.filters.entrySet()" index="key" item="values">
|
||||
|
||||
<if test="values != null and values.size() > 0">
|
||||
and api_delimit.status in
|
||||
and api_definition.status in
|
||||
<foreach collection="values" item="value" separator="," open="(" close=")">
|
||||
#{value}
|
||||
</foreach>
|
||||
|
@ -262,18 +262,18 @@
|
|||
<if test="request.orders != null and request.orders.size() > 0">
|
||||
order by
|
||||
<foreach collection="request.orders" separator="," item="order">
|
||||
api_delimit.${order.name} ${order.type}
|
||||
api_definition.${order.name} ${order.type}
|
||||
</foreach>
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="selectByExample" parameterType="io.metersphere.base.domain.ApiDelimitExample" resultMap="BaseResultMap">
|
||||
<select id="selectByExample" parameterType="io.metersphere.base.domain.ApiDefinitionExample" resultMap="BaseResultMap">
|
||||
select
|
||||
<if test="distinct">
|
||||
distinct
|
||||
</if>
|
||||
<include refid="Base_Column_List"/>
|
||||
from api_delimit
|
||||
from api_definition
|
||||
<if test="_parameter != null">
|
||||
<include refid="Example_Where_Clause"/>
|
||||
</if>
|
||||
|
@ -287,41 +287,41 @@
|
|||
<include refid="Base_Column_List"/>
|
||||
,
|
||||
<include refid="Blob_Column_List"/>
|
||||
from api_delimit
|
||||
from api_definition
|
||||
where id = #{id,jdbcType=VARCHAR}
|
||||
</select>
|
||||
<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
|
||||
delete from api_delimit
|
||||
delete from api_definition
|
||||
where id = #{id,jdbcType=VARCHAR}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteByExample" parameterType="io.metersphere.base.domain.ApiDelimitExample">
|
||||
delete from api_delimit
|
||||
<delete id="deleteByExample" parameterType="io.metersphere.base.domain.ApiDefinitionExample">
|
||||
delete from api_definition
|
||||
<if test="_parameter != null">
|
||||
<include refid="Example_Where_Clause"/>
|
||||
</if>
|
||||
</delete>
|
||||
|
||||
<insert id="insert" parameterType="io.metersphere.base.domain.ApiDelimit">
|
||||
insert into api_delimit (id, project_id, name, url,module_id,module_path,path,
|
||||
<insert id="insert" parameterType="io.metersphere.base.domain.ApiDefinition">
|
||||
insert into api_definition (id, project_id, name, url,module_id,module_path,method,
|
||||
description, status, user_id,create_time, update_time, request,response,environment_id )
|
||||
values
|
||||
(#{id,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{url,jdbcType=VARCHAR}, #{moduleId,jdbcType=VARCHAR},#{modulePath,jdbcType=VARCHAR},#{path,jdbcType=VARCHAR},
|
||||
(#{id,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{url,jdbcType=VARCHAR}, #{moduleId,jdbcType=VARCHAR},#{modulePath,jdbcType=VARCHAR},#{method,jdbcType=VARCHAR},
|
||||
#{description,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR}, #{userId,jdbcType=VARCHAR},
|
||||
#{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}, #{request,jdbcType=LONGVARCHAR},#{response,jdbcType=LONGVARCHAR},#{environmentId,jdbcType=VARCHAR}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<select id="countByExample" parameterType="io.metersphere.base.domain.ApiDelimitExample"
|
||||
<select id="countByExample" parameterType="io.metersphere.base.domain.ApiDefinitionExample"
|
||||
resultType="java.lang.Long">
|
||||
select count(*) from api_delimit
|
||||
select count(*) from api_definition
|
||||
<if test="_parameter != null">
|
||||
<include refid="Example_Where_Clause"/>
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<update id="updateByPrimaryKeySelective" parameterType="io.metersphere.base.domain.ApiDelimit">
|
||||
update api_delimit
|
||||
<update id="updateByPrimaryKeySelective" parameterType="io.metersphere.base.domain.ApiDefinition">
|
||||
update api_definition
|
||||
<set>
|
||||
<if test="projectId != null">
|
||||
project_id = #{projectId,jdbcType=VARCHAR},
|
||||
|
@ -336,8 +336,8 @@
|
|||
<if test="url != null">
|
||||
url = #{url,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
<if test="path != null">
|
||||
path = #{path,jdbcType=VARCHAR},
|
||||
<if test="method != null">
|
||||
method = #{method,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="modulePath != null">
|
||||
module_path = #{modulePath,jdbcType=VARCHAR},
|
||||
|
@ -369,8 +369,8 @@
|
|||
</set>
|
||||
where id = #{id,jdbcType=VARCHAR}
|
||||
</update>
|
||||
<update id="updateByPrimaryKeyWithBLOBs" parameterType="io.metersphere.base.domain.ApiDelimit">
|
||||
update api_delimit
|
||||
<update id="updateByPrimaryKeyWithBLOBs" parameterType="io.metersphere.base.domain.ApiDefinition">
|
||||
update api_definition
|
||||
set project_id = #{projectId,jdbcType=VARCHAR},
|
||||
name = #{name,jdbcType=VARCHAR},
|
||||
description = #{description,jdbcType=VARCHAR},
|
||||
|
@ -379,7 +379,7 @@
|
|||
module_id = #{moduleId,jdbcType=VARCHAR},
|
||||
module_path = #{modulePath,jdbcType=VARCHAR},
|
||||
url = #{url,jdbcType=VARCHAR},
|
||||
path = #{path,jdbcType=VARCHAR},
|
||||
method = #{method,jdbcType=VARCHAR},
|
||||
create_time = #{createTime,jdbcType=BIGINT},
|
||||
update_time = #{updateTime,jdbcType=BIGINT},
|
||||
request = #{request,jdbcType=LONGVARCHAR},
|
||||
|
@ -387,14 +387,14 @@
|
|||
environment_id = #{environmentId,jdbcType=VARCHAR}
|
||||
where id = #{id,jdbcType=VARCHAR}
|
||||
</update>
|
||||
<update id="updateByPrimaryKey" parameterType="io.metersphere.base.domain.ApiDelimit">
|
||||
update api_delimit
|
||||
<update id="updateByPrimaryKey" parameterType="io.metersphere.base.domain.ApiDefinition">
|
||||
update api_definition
|
||||
set project_id = #{projectId,jdbcType=VARCHAR},
|
||||
name = #{name,jdbcType=VARCHAR},
|
||||
module_id = #{moduleId,jdbcType=VARCHAR},
|
||||
url = #{url,jdbcType=VARCHAR},
|
||||
module_path = #{modulePath,jdbcType=VARCHAR},
|
||||
path = #{path,jdbcType=VARCHAR},
|
||||
method = #{method,jdbcType=VARCHAR},
|
||||
description = #{description,jdbcType=VARCHAR},
|
||||
status = #{status,jdbcType=VARCHAR},
|
||||
user_id = #{userId,jdbcType=VARCHAR},
|
|
@ -1,15 +0,0 @@
|
|||
package io.metersphere.base.mapper;
|
||||
|
||||
import io.metersphere.base.domain.ApiDelimitExecResult;
|
||||
|
||||
public interface ApiDelimitExecResultMapper {
|
||||
|
||||
int deleteByResourceId(String id);
|
||||
|
||||
int insert(ApiDelimitExecResult record);
|
||||
|
||||
ApiDelimitExecResult selectByResourceId(String resourceId);
|
||||
|
||||
ApiDelimitExecResult selectByPrimaryKey(String id);
|
||||
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
package io.metersphere.base.mapper;
|
||||
|
||||
import io.metersphere.api.dto.delimit.ApiComputeResult;
|
||||
import io.metersphere.api.dto.delimit.ApiDelimitRequest;
|
||||
import io.metersphere.api.dto.delimit.ApiDelimitResult;
|
||||
import io.metersphere.base.domain.ApiDelimit;
|
||||
import io.metersphere.base.domain.ApiDelimitExample;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ApiDelimitMapper {
|
||||
|
||||
List<ApiDelimitResult> list(@Param("request") ApiDelimitRequest request);
|
||||
|
||||
List<ApiComputeResult> selectByIds(@Param("ids") List<String> ids);
|
||||
|
||||
long countByExample(ApiDelimitExample example);
|
||||
|
||||
int deleteByExample(ApiDelimitExample example);
|
||||
|
||||
int deleteByPrimaryKey(String id);
|
||||
|
||||
int insert(ApiDelimit record);
|
||||
|
||||
|
||||
List<ApiDelimit> selectByExampleWithBLOBs(ApiDelimitExample example);
|
||||
|
||||
List<ApiDelimit> selectByExample(ApiDelimitExample example);
|
||||
|
||||
ApiDelimit selectByPrimaryKey(String id);
|
||||
|
||||
|
||||
int updateByPrimaryKeySelective(ApiDelimit record);
|
||||
|
||||
int updateByPrimaryKeyWithBLOBs(ApiDelimit record);
|
||||
|
||||
int updateByPrimaryKey(ApiDelimit record);
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package io.metersphere.base.mapper;
|
||||
|
||||
import io.metersphere.api.dto.delimit.ApiTestCaseRequest;
|
||||
import io.metersphere.api.dto.delimit.ApiTestCaseResult;
|
||||
import io.metersphere.api.dto.definition.ApiTestCaseRequest;
|
||||
import io.metersphere.api.dto.definition.ApiTestCaseResult;
|
||||
import io.metersphere.base.domain.ApiTestCase;
|
||||
import io.metersphere.base.domain.ApiTestCaseExample;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<resultMap id="BaseResultMap" type="io.metersphere.base.domain.ApiTestCase">
|
||||
<id column="id" jdbcType="VARCHAR" property="id"/>
|
||||
<result column="project_id" jdbcType="VARCHAR" property="projectId"/>
|
||||
<result column="api_delimit_id" jdbcType="VARCHAR" property="apiDelimitId"/>
|
||||
<result column="api_definition_id" jdbcType="VARCHAR" property="apiDefinitionId"/>
|
||||
<result column="name" jdbcType="VARCHAR" property="name"/>
|
||||
<result column="priority" jdbcType="VARCHAR" property="priority"/>
|
||||
<result column="description" jdbcType="VARCHAR" property="description"/>
|
||||
|
@ -78,7 +78,7 @@
|
|||
</where>
|
||||
</sql>
|
||||
<sql id="Base_Column_List">
|
||||
id, project_id, name,api_delimit_id,priority,description, create_user_id, update_user_id, create_time, update_time
|
||||
id, project_id, name,api_definition_id,priority,description, create_user_id, update_user_id, create_time, update_time
|
||||
</sql>
|
||||
<sql id="Blob_Column_List">
|
||||
request
|
||||
|
@ -145,13 +145,13 @@
|
|||
</choose>
|
||||
</sql>
|
||||
|
||||
<select id="list" resultType="io.metersphere.api.dto.delimit.ApiTestCaseResult">
|
||||
<select id="list" resultType="io.metersphere.api.dto.definition.ApiTestCaseResult">
|
||||
select atc.id, atc.project_id,
|
||||
atc.name,atc.priority,atc.api_delimit_id,T1.name as createUser ,T2.name as updateUser,
|
||||
atc.name,atc.priority,atc.api_definition_id,T1.name as createUser ,T2.name as updateUser,
|
||||
atc.description,atc.request,atc.response,atc.create_user_id,
|
||||
atc.create_time,atc.update_user_id, atc.update_time,ader.status execResult
|
||||
from api_test_case atc left join user T1 on atc.create_user_id = T1.id left join user T2 on
|
||||
atc.update_user_id = T2.id left join api_delimit_exec_result ader on atc.id = ader.resource_id
|
||||
atc.update_user_id = T2.id left join api_definition_exec_result ader on atc.id = ader.resource_id
|
||||
<where>
|
||||
<if test="request.name != null and request.name!=''">
|
||||
|
||||
|
@ -166,8 +166,8 @@
|
|||
<if test="request.projectId != null and request.projectId!=''">
|
||||
AND atc.project_id = #{request.projectId}
|
||||
</if>
|
||||
<if test="request.apiDelimitId != null and request.apiDelimitId!=''">
|
||||
AND atc.api_delimit_id = #{request.apiDelimitId}
|
||||
<if test="request.apiDefinitionId != null and request.apiDefinitionId!=''">
|
||||
AND atc.api_definition_id = #{request.apiDefinitionId}
|
||||
</if>
|
||||
</where>
|
||||
<if test="request.orders != null and request.orders.size() > 0">
|
||||
|
@ -215,10 +215,10 @@
|
|||
</delete>
|
||||
|
||||
<insert id="insert" parameterType="io.metersphere.base.domain.ApiTestCase">
|
||||
insert into api_test_case (id, project_id, name, priority,api_delimit_id,description, create_user_id, update_user_id,
|
||||
insert into api_test_case (id, project_id, name, priority,api_definition_id,description, create_user_id, update_user_id,
|
||||
create_time, update_time, request,response
|
||||
)
|
||||
values (#{id,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{priority,jdbcType=VARCHAR}, #{apiDelimitId,jdbcType=VARCHAR},#{description,jdbcType=VARCHAR},
|
||||
values (#{id,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{priority,jdbcType=VARCHAR}, #{apiDefinitionId,jdbcType=VARCHAR},#{description,jdbcType=VARCHAR},
|
||||
#{createUserId,jdbcType=VARCHAR}, #{updateUserId,jdbcType=VARCHAR},
|
||||
#{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}, #{request,jdbcType=LONGVARCHAR}, #{response,jdbcType=LONGVARCHAR})
|
||||
</insert>
|
||||
|
@ -241,8 +241,8 @@
|
|||
name = #{name,jdbcType=VARCHAR},
|
||||
</if>
|
||||
|
||||
<if test="apiDelimitId != null">
|
||||
api_delimit_id = #{apiDelimitId,jdbcType=BIGINT},
|
||||
<if test="apiDefinitionId != null">
|
||||
api_definition_id = #{apiDefinitionId,jdbcType=BIGINT},
|
||||
</if>
|
||||
<if test="priority != null">
|
||||
priority = #{priority,jdbcType=LONGVARCHAR},
|
||||
|
@ -271,7 +271,7 @@
|
|||
update api_test_case
|
||||
set project_id = #{projectId,jdbcType=VARCHAR},
|
||||
name = #{name,jdbcType=VARCHAR},
|
||||
api_delimit_id = #{apiDelimitId,jdbcType=VARCHAR},
|
||||
api_definition_id = #{apiDefinitionId,jdbcType=VARCHAR},
|
||||
priority = #{priority,jdbcType=VARCHAR},
|
||||
description = #{description,jdbcType=VARCHAR},
|
||||
update_user_id = #{updateUserId,jdbcType=VARCHAR},
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
package io.metersphere.commons.constants;
|
||||
|
||||
public enum ApiRunMode {
|
||||
RUN, DEBUG
|
||||
RUN, DEBUG,DELIMIT
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package io.metersphere.job.sechedule;
|
|||
|
||||
import io.metersphere.api.dto.SaveAPITestRequest;
|
||||
import io.metersphere.api.service.APITestService;
|
||||
import io.metersphere.notice.service.MailService;
|
||||
import io.metersphere.commons.constants.ApiRunMode;
|
||||
import io.metersphere.commons.constants.ReportTriggerMode;
|
||||
import io.metersphere.commons.constants.ScheduleGroup;
|
||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
|
@ -14,6 +14,7 @@ import org.quartz.TriggerKey;
|
|||
public class ApiTestJob extends MsScheduleJob {
|
||||
|
||||
private APITestService apiTestService;
|
||||
|
||||
public ApiTestJob() {
|
||||
apiTestService = (APITestService) CommonBeanFactory.getBean(APITestService.class);
|
||||
}
|
||||
|
@ -24,7 +25,7 @@ public class ApiTestJob extends MsScheduleJob {
|
|||
request.setId(resourceId);
|
||||
request.setUserId(userId);
|
||||
request.setTriggerMode(ReportTriggerMode.SCHEDULE.name());
|
||||
apiTestService.run(request);
|
||||
apiTestService.run(request, ApiRunMode.RUN.name());
|
||||
}
|
||||
|
||||
public static JobKey getJobKey(String testId) {
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 57d6f78efa4b0300be188e8b024511ceef0873ed
|
||||
Subproject commit 24047fea950a74f7848a9fdaa857a22b884c4ce2
|
|
@ -9,9 +9,9 @@
|
|||
<!-- 此处指定生成针对MyBatis3的DAO -->
|
||||
<context id="mysql" targetRuntime="MyBatis3">
|
||||
<!-- 字段带`,解决列表跟关键字冲突问题 -->
|
||||
<property name="autoDelimitKeywords" value="true" />
|
||||
<property name="beginningDelimiter" value="`" />
|
||||
<property name="endingDelimiter" value="`" />
|
||||
<property name="autoDefinitionKeywords" value="true" />
|
||||
<property name="beginningDefinitioner" value="`" />
|
||||
<property name="endingDefinitioner" value="`" />
|
||||
|
||||
<plugin type="org.mybatis.generator.plugins.SerializablePlugin"/>
|
||||
<plugin type="org.mybatis.generator.plugins.UnmergeableXmlMappersPlugin" />
|
||||
|
|
|
@ -169,7 +169,7 @@ test_plan_notification=Test plan notification
|
|||
task_defect_notification=Task defect notification
|
||||
task_notification=Jenkins Task notification
|
||||
task_notification_=Timing task result notification
|
||||
api_delimit_url_not_repeating=The interface request address already exists
|
||||
api_definition_url_not_repeating=The interface request address already exists
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -170,4 +170,4 @@ test_plan_notification=测试计划通知
|
|||
task_defect_notification=缺陷任务通知
|
||||
task_notification=jenkins任务通知
|
||||
task_notification_=定时任务结果通知
|
||||
api_delimit_url_not_repeating=接口请求地址已经存在
|
||||
api_definition_url_not_repeating=接口请求地址已经存在
|
|
@ -171,4 +171,4 @@ test_plan_notification=測試計畫通知
|
|||
task_defect_notification=缺陷任務通知
|
||||
task_notification=jenkins任務通知
|
||||
task_notification_=定時任務通知
|
||||
api_delimit_url_not_repeating=接口請求地址已經存在
|
||||
api_definition_url_not_repeating=接口請求地址已經存在
|
||||
|
|
|
@ -254,7 +254,7 @@ gui.quick_9=ViewResultsFullVisualizer
|
|||
# Remote hosts and RMI configuration
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
# Remote Hosts - comma delimited
|
||||
# Remote Hosts - comma definitioned
|
||||
remote_hosts=127.0.0.1
|
||||
#remote_hosts=localhost:1099,localhost:2010
|
||||
|
||||
|
@ -531,11 +531,11 @@ remote_hosts=127.0.0.1
|
|||
#jmeter.save.saveservice.timestamp_format=yyyy/MM/dd HH:mm:ss.SSS
|
||||
|
||||
# For use with Comma-separated value (CSV) files or other formats
|
||||
# where the fields' values are separated by specified delimiters.
|
||||
# where the fields' values are separated by specified definitioners.
|
||||
# Default:
|
||||
#jmeter.save.saveservice.default_delimiter=,
|
||||
#jmeter.save.saveservice.default_definitioner=,
|
||||
# For TAB, one can use:
|
||||
#jmeter.save.saveservice.default_delimiter=\t
|
||||
#jmeter.save.saveservice.default_definitioner=\t
|
||||
|
||||
# Only applies to CSV format files:
|
||||
# Print field names as first line in CSV
|
||||
|
@ -968,15 +968,15 @@ beanshell.server.file=../extras/startup.bsh
|
|||
# CSVRead configuration
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
# CSVRead delimiter setting (default ",")
|
||||
# Make sure that there are no trailing spaces or tabs after the delimiter
|
||||
# characters, or these will be included in the list of valid delimiters
|
||||
#csvread.delimiter=,
|
||||
#csvread.delimiter=;
|
||||
#csvread.delimiter=!
|
||||
#csvread.delimiter=~
|
||||
# CSVRead definitioner setting (default ",")
|
||||
# Make sure that there are no trailing spaces or tabs after the definitioner
|
||||
# characters, or these will be included in the list of valid definitioners
|
||||
#csvread.definitioner=,
|
||||
#csvread.definitioner=;
|
||||
#csvread.definitioner=!
|
||||
#csvread.definitioner=~
|
||||
# The following line has a tab after the =
|
||||
#csvread.delimiter=
|
||||
#csvread.definitioner=
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# __time() function configuration
|
||||
|
|
|
@ -254,7 +254,7 @@ gui.quick_9=ViewResultsFullVisualizer
|
|||
# Remote hosts and RMI configuration
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
# Remote Hosts - comma delimited
|
||||
# Remote Hosts - comma definitioned
|
||||
remote_hosts=127.0.0.1
|
||||
#remote_hosts=localhost:1099,localhost:2010
|
||||
|
||||
|
@ -532,11 +532,11 @@ server.rmi.ssl.disable=true
|
|||
#jmeter.save.saveservice.timestamp_format=yyyy/MM/dd HH:mm:ss.SSS
|
||||
|
||||
# For use with Comma-separated value (CSV) files or other formats
|
||||
# where the fields' values are separated by specified delimiters.
|
||||
# where the fields' values are separated by specified definitioners.
|
||||
# Default:
|
||||
#jmeter.save.saveservice.default_delimiter=,
|
||||
#jmeter.save.saveservice.default_definitioner=,
|
||||
# For TAB, one can use:
|
||||
#jmeter.save.saveservice.default_delimiter=\t
|
||||
#jmeter.save.saveservice.default_definitioner=\t
|
||||
|
||||
# Only applies to CSV format files:
|
||||
# Print field names as first line in CSV
|
||||
|
@ -969,15 +969,15 @@ beanshell.server.file=../extras/startup.bsh
|
|||
# CSVRead configuration
|
||||
#---------------------------------------------------------------------------
|
||||
|
||||
# CSVRead delimiter setting (default ",")
|
||||
# Make sure that there are no trailing spaces or tabs after the delimiter
|
||||
# characters, or these will be included in the list of valid delimiters
|
||||
#csvread.delimiter=,
|
||||
#csvread.delimiter=;
|
||||
#csvread.delimiter=!
|
||||
#csvread.delimiter=~
|
||||
# CSVRead definitioner setting (default ",")
|
||||
# Make sure that there are no trailing spaces or tabs after the definitioner
|
||||
# characters, or these will be included in the list of valid definitioners
|
||||
#csvread.definitioner=,
|
||||
#csvread.definitioner=;
|
||||
#csvread.definitioner=!
|
||||
#csvread.definitioner=~
|
||||
# The following line has a tab after the =
|
||||
#csvread.delimiter=
|
||||
#csvread.definitioner=
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# __time() function configuration
|
||||
|
|
|
@ -11,9 +11,9 @@
|
|||
@command="handleCommand">
|
||||
{{$t('commons.add')}}
|
||||
<el-dropdown-menu slot="dropdown">
|
||||
<el-dropdown-item command="debug">{{$t('api_test.delimit.request.fast_debug')}}</el-dropdown-item>
|
||||
<el-dropdown-item command="add">{{$t('api_test.delimit.request.title')}}</el-dropdown-item>
|
||||
<el-dropdown-item command="closeAll">{{$t('api_test.delimit.request.close_all_label')}}</el-dropdown-item>
|
||||
<el-dropdown-item command="debug">{{$t('api_test.definition.request.fast_debug')}}</el-dropdown-item>
|
||||
<el-dropdown-item command="add">{{$t('api_test.definition.request.title')}}</el-dropdown-item>
|
||||
<el-dropdown-item command="closeAll">{{$t('api_test.definition.request.close_all_label')}}</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</el-dropdown>
|
||||
<!-- 主框架列表 -->
|
||||
|
@ -93,7 +93,7 @@
|
|||
moduleOptions: {},
|
||||
runTestData: {},
|
||||
apiTabs: [{
|
||||
title: this.$t('api_test.delimit.api_title'),
|
||||
title: this.$t('api_test.definition.api_title'),
|
||||
name: 'default',
|
||||
type: "list",
|
||||
closable: false
|
||||
|
@ -103,8 +103,8 @@
|
|||
methods: {
|
||||
handleCommand(e) {
|
||||
if (e === "add") {
|
||||
this.currentApi = {status: "Underway", path: "GET", userId: getCurrentUser().id};
|
||||
this.handleTabsEdit(this.$t('api_test.delimit.request.title'), e);
|
||||
this.currentApi = {status: "Underway", method: "GET", userId: getCurrentUser().id};
|
||||
this.handleTabsEdit(this.$t('api_test.definition.request.title'), e);
|
||||
}
|
||||
else if (e === "test") {
|
||||
this.handleTabsEdit(this.$t("commons.api"), e);
|
||||
|
@ -116,7 +116,7 @@
|
|||
this.apiTabs.push(tabs);
|
||||
}
|
||||
else {
|
||||
this.handleTabsEdit(this.$t('api_test.delimit.request.fast_debug'), "debug");
|
||||
this.handleTabsEdit(this.$t('api_test.definition.request.fast_debug'), "debug");
|
||||
}
|
||||
},
|
||||
handleTabsEdit(targetName, action) {
|
||||
|
@ -137,7 +137,7 @@
|
|||
this.apiTabs = tabs.filter(tab => tab.name !== targetName);
|
||||
} else {
|
||||
if (targetName === undefined || targetName === null) {
|
||||
targetName = this.$t('api_test.delimit.request.title');
|
||||
targetName = this.$t('api_test.definition.request.title');
|
||||
}
|
||||
let newTabName = getUUID().substring(0, 8);
|
||||
this.apiTabs.push({
|
|
@ -27,7 +27,7 @@
|
|||
</el-col>
|
||||
<el-col :span="4">
|
||||
<div>
|
||||
<el-select size="small" :placeholder="$t('api_test.delimit.request.grade_info')" v-model="priorityValue"
|
||||
<el-select size="small" :placeholder="$t('api_test.definition.request.grade_info')" v-model="priorityValue"
|
||||
class="ms-api-header-select" @change="getApiTest">
|
||||
<el-option v-for="grd in priority" :key="grd.id" :label="grd.name" :value="grd.id"/>
|
||||
</el-select>
|
||||
|
@ -35,8 +35,8 @@
|
|||
</el-col>
|
||||
<el-col :span="4">
|
||||
<div>
|
||||
<el-select :disabled="isReadOnly" v-model="envValue" size="small" class="ms-api-header-select"
|
||||
:placeholder="$t('api_test.delimit.request.run_env')"
|
||||
<el-select :disabled="isReadOnly" v-model="environment" size="small" class="ms-api-header-select"
|
||||
:placeholder="$t('api_test.definition.request.run_env')"
|
||||
@change="environmentChange" clearable>
|
||||
<el-option v-for="(environment, index) in environments" :key="index"
|
||||
:label="environment.name + (environment.config.httpConfig.socket ? (': ' + environment.config.httpConfig.protocol + '://' + environment.config.httpConfig.socket) : '')"
|
||||
|
@ -56,20 +56,20 @@
|
|||
</el-col>
|
||||
<el-col :span="3">
|
||||
<div class="ms-api-header-select">
|
||||
<el-input size="small" :placeholder="$t('api_test.delimit.request.select_case')"
|
||||
<el-input size="small" :placeholder="$t('api_test.definition.request.select_case')"
|
||||
v-model="name" @blur="getApiTest"/>
|
||||
</div>
|
||||
</el-col>
|
||||
<el-col :span="2">
|
||||
<!--<div class="ms-api-header-select">-->
|
||||
<!--<el-button size="small" style="background-color: #783887;color: white" @click="createCase">-->
|
||||
<!--+{{$t('api_test.delimit.request.case')}}-->
|
||||
<!--+{{$t('api_test.definition.request.case')}}-->
|
||||
<!--</el-button>-->
|
||||
<!--</div>-->
|
||||
|
||||
<el-dropdown size="small" split-button type="primary" class="ms-api-header-select" @click="createCase"
|
||||
@command="handleCommand">
|
||||
+{{$t('api_test.delimit.request.case')}}
|
||||
+{{$t('api_test.definition.request.case')}}
|
||||
<el-dropdown-menu slot="dropdown">
|
||||
<el-dropdown-item command="run">{{$t('commons.test')}}</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
|
@ -144,11 +144,11 @@
|
|||
<!-- 请求参数-->
|
||||
<el-collapse-transition>
|
||||
<div v-if="item.active">
|
||||
<p class="tip">{{$t('api_test.delimit.request.req_param')}} </p>
|
||||
<p class="tip">{{$t('api_test.definition.request.req_param')}} </p>
|
||||
|
||||
<ms-api-request-form :is-read-only="isReadOnly" :request="item.test.request"/>
|
||||
|
||||
<p class="tip">{{$t('api_test.delimit.request.assertions_rule')}} </p>
|
||||
<p class="tip">{{$t('api_test.definition.request.assertions_rule')}} </p>
|
||||
|
||||
<ms-api-assertions :request="item.test.request" :is-read-only="isReadOnly"
|
||||
:assertions="item.test.request.assertions"/>
|
||||
|
@ -164,10 +164,14 @@
|
|||
</el-main>
|
||||
|
||||
</el-container>
|
||||
|
||||
<!-- 执行组件 -->
|
||||
<ms-run :debug="false" :environment="environment" :reportId="reportId" :run-data="runData"
|
||||
@runRefresh="runRefresh" ref="runTest"/>
|
||||
|
||||
</div>
|
||||
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import MsTag from "../../../common/components/MsTag";
|
||||
import MsTipButton from "../../../common/components/MsTipButton";
|
||||
|
@ -176,8 +180,9 @@
|
|||
import {downloadFile, getUUID} from "@/common/js/utils";
|
||||
import {parseEnvironment} from "../model/EnvironmentModel";
|
||||
import ApiEnvironmentConfig from "../../test/components/ApiEnvironmentConfig";
|
||||
import {PRIORITY,RESULT_MAP} from "../model/JsonData";
|
||||
import {PRIORITY, RESULT_MAP} from "../model/JsonData";
|
||||
import MsApiAssertions from "./assertion/ApiAssertions";
|
||||
import MsRun from "./Run";
|
||||
|
||||
export default {
|
||||
name: 'ApiCaseList',
|
||||
|
@ -186,7 +191,8 @@
|
|||
MsTipButton,
|
||||
MsApiRequestForm,
|
||||
ApiEnvironmentConfig,
|
||||
MsApiAssertions
|
||||
MsApiAssertions,
|
||||
MsRun
|
||||
},
|
||||
props: {
|
||||
api: {
|
||||
|
@ -200,7 +206,6 @@
|
|||
grades: [],
|
||||
environments: [],
|
||||
environment: {},
|
||||
envValue: {},
|
||||
name: "",
|
||||
priorityValue: "",
|
||||
isReadOnly: false,
|
||||
|
@ -208,6 +213,8 @@
|
|||
priority: PRIORITY,
|
||||
apiCaseList: [],
|
||||
loading: false,
|
||||
runData: [],
|
||||
reportId: "",
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -246,49 +253,41 @@
|
|||
this.apiCaseList = [];
|
||||
this.$emit('apiCaseClose');
|
||||
},
|
||||
getReport(id) {
|
||||
let url = "/api/delimit/report/get/" + id + "/run";
|
||||
this.$get(url, response => {
|
||||
if (response.data) {
|
||||
this.loading = false;
|
||||
this.$success(this.$t('schedule.event_success'));
|
||||
this.$emit('refresh');
|
||||
} else {
|
||||
setTimeout(this.getReport, 2000)
|
||||
}
|
||||
});
|
||||
},
|
||||
runCase(row) {
|
||||
if (!this.environment) {
|
||||
this.$warning(this.$t('api_test.environment.select_environment'));
|
||||
return;
|
||||
}
|
||||
row.request = row.test.request;
|
||||
let url = "/api/delimit/run";
|
||||
let bodyFiles = this.getBodyUploadFiles(row);
|
||||
let env = this.environment.config.httpConfig.socket ? (this.environment.config.httpConfig.protocol + '://' + this.environment.config.httpConfig.socket) : '';
|
||||
if (env.endsWith("/")) {
|
||||
env = env.substr(0, env.length - 1);
|
||||
this.runData = [];
|
||||
if (row) {
|
||||
row.test.request.url = this.api.url;
|
||||
row.test.request.method = this.api.method;
|
||||
row.test.request.name = row.id;
|
||||
this.loading = true;
|
||||
this.runData.push(row.test.request);
|
||||
/*触发执行操作*/
|
||||
this.reportId = getUUID().substring(0, 8);
|
||||
} else {
|
||||
if (this.apiCaseList.length > 0) {
|
||||
this.apiCaseList.forEach(item => {
|
||||
if (item.type != "create") {
|
||||
item.test.request.name = item.id;
|
||||
this.runData.push(item.test.request);
|
||||
}
|
||||
})
|
||||
this.loading = true;
|
||||
/*触发执行操作*/
|
||||
this.reportId = getUUID().substring(0, 8);
|
||||
} else {
|
||||
this.$warning("没有可执行的用例!");
|
||||
}
|
||||
}
|
||||
let sendUrl = this.api.url;
|
||||
if (!sendUrl.startsWith("/")) {
|
||||
sendUrl = "/" + sendUrl;
|
||||
}
|
||||
row.test.request.url = env + sendUrl;
|
||||
row.test.request.path = this.api.path;
|
||||
row.test.request.name = row.id;
|
||||
row.test.request.connectTimeout = "6000";
|
||||
row.test.request.responseTimeout = "0";
|
||||
row.reportId = "run";
|
||||
this.loading = true;
|
||||
let jmx = row.test.toJMX();
|
||||
let blob = new Blob([jmx.xml], {type: "application/octet-stream"});
|
||||
let file = new File([blob], jmx.name);
|
||||
this.$fileUpload(url, file, bodyFiles, row, response => {
|
||||
this.getReport(row.id);
|
||||
}, erro => {
|
||||
this.loading = false;
|
||||
});
|
||||
},
|
||||
runRefresh(data) {
|
||||
this.loading = false;
|
||||
this.$success(this.$t('schedule.event_success'));
|
||||
this.getApiTest();
|
||||
this.$emit('refresh');
|
||||
},
|
||||
deleteCase(index, row) {
|
||||
this.$get('/api/testcase/delete/' + row.id, () => {
|
||||
|
@ -316,7 +315,7 @@
|
|||
let request = {};
|
||||
if (row) {
|
||||
request = row.request;
|
||||
obj.apiDelimitId = row.apiDelimitId;
|
||||
obj.apiDefinitionId = row.apiDefinitionId;
|
||||
} else {
|
||||
request: new RequestFactory(JSON.parse(this.api.request))
|
||||
}
|
||||
|
@ -350,7 +349,7 @@
|
|||
getApiTest() {
|
||||
let condition = {};
|
||||
condition.projectId = this.api.projectId;
|
||||
condition.apiDelimitId = this.api.id;
|
||||
condition.apiDefinitionId = this.api.id;
|
||||
condition.priority = this.priorityValue;
|
||||
condition.name = this.name;
|
||||
this.$post("/api/testcase/list", condition, response => {
|
||||
|
@ -359,7 +358,6 @@
|
|||
test.test = new Test({request: new RequestFactory(JSON.parse(test.request))});
|
||||
}
|
||||
this.apiCaseList = response.data;
|
||||
|
||||
});
|
||||
},
|
||||
validate(row) {
|
||||
|
@ -374,9 +372,9 @@
|
|||
}
|
||||
let bodyFiles = this.getBodyUploadFiles(row);
|
||||
row.test.request.url = this.api.url;
|
||||
row.test.request.path = this.api.path;
|
||||
row.test.request.method = this.api.method;
|
||||
row.projectId = this.api.projectId;
|
||||
row.apiDelimitId = row.apiDelimitId || this.api.id;
|
||||
row.apiDefinitionId = row.apiDefinitionId || this.api.id;
|
||||
row.request = row.test.request;
|
||||
let jmx = row.test.toJMX();
|
||||
let blob = new Blob([jmx.xml], {type: "application/octet-stream"});
|
||||
|
@ -400,7 +398,6 @@
|
|||
let hasEnvironment = false;
|
||||
for (let i in this.environments) {
|
||||
if (this.environments[i].id === this.api.environmentId) {
|
||||
this.environment = this.environments[i];
|
||||
hasEnvironment = true;
|
||||
break;
|
||||
}
|
|
@ -39,9 +39,9 @@
|
|||
}
|
||||
});
|
||||
if (this.currentApi != null && this.currentApi.id != null) {
|
||||
this.reqUrl = "/api/delimit/update";
|
||||
this.reqUrl = "/api/definition/update";
|
||||
} else {
|
||||
this.reqUrl = "/api/delimit/create";
|
||||
this.reqUrl = "/api/definition/create";
|
||||
this.currentApi.id = getUUID().substring(0, 8);
|
||||
}
|
||||
},
|
||||
|
@ -49,14 +49,11 @@
|
|||
runTest(data) {
|
||||
data.projectId = this.currentProject.id;
|
||||
data.request = data.test.request;
|
||||
data.response = data.test.response;
|
||||
let bodyFiles = this.getBodyUploadFiles(data);
|
||||
let jmx = data.test.toJMX();
|
||||
let blob = new Blob([jmx.xml], {type: "application/octet-stream"});
|
||||
let file = new File([blob], jmx.name);
|
||||
|
||||
this.$fileUpload(this.reqUrl, file, bodyFiles, data, () => {
|
||||
this.$fileUpload(this.reqUrl, null, bodyFiles, data, () => {
|
||||
this.$success(this.$t('commons.save_success'));
|
||||
this.reqUrl = "/api/delimit/update";
|
||||
this.reqUrl = "/api/definition/update";
|
||||
this.$emit('runTest', data);
|
||||
});
|
||||
},
|
||||
|
@ -66,12 +63,10 @@
|
|||
data.request = data.test.request;
|
||||
data.response = data.test.response;
|
||||
let bodyFiles = this.getBodyUploadFiles(data);
|
||||
let jmx = data.test.toJMX();
|
||||
let blob = new Blob([jmx.xml], {type: "application/octet-stream"});
|
||||
let file = new File([blob], jmx.name);
|
||||
this.$fileUpload(this.reqUrl, file, bodyFiles, data, () => {
|
||||
|
||||
this.$fileUpload(this.reqUrl, null, bodyFiles, data, () => {
|
||||
this.$success(this.$t('commons.save_success'));
|
||||
this.reqUrl = "/api/delimit/update";
|
||||
this.reqUrl = "/api/definition/update";
|
||||
this.$emit('saveApi', data);
|
||||
});
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
<el-card class="card-content">
|
||||
<template v-slot:header>
|
||||
<ms-table-header :showCreate="false" :condition.sync="condition" @search="search"
|
||||
:title="$t('api_test.delimit.api_title')"/>
|
||||
:title="$t('api_test.definition.api_title')"/>
|
||||
</template>
|
||||
<el-table border :data="tableData" row-key="id" class="test-content adjust-table"
|
||||
@select-all="handleSelectAll"
|
||||
|
@ -16,11 +16,11 @@
|
|||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column prop="name" :label="$t('api_test.delimit.api_name')" show-overflow-tooltip/>
|
||||
<el-table-column prop="name" :label="$t('api_test.definition.api_name')" show-overflow-tooltip/>
|
||||
<el-table-column
|
||||
prop="status"
|
||||
column-key="api_status"
|
||||
:label="$t('api_test.delimit.api_status')"
|
||||
:label="$t('api_test.definition.api_status')"
|
||||
show-overflow-tooltip>
|
||||
<template v-slot:default="scope">
|
||||
<ms-tag v-if="scope.row.status == 'Prepare'" type="info"
|
||||
|
@ -33,12 +33,12 @@
|
|||
</el-table-column>
|
||||
|
||||
<el-table-column
|
||||
prop="path"
|
||||
:label="$t('api_test.delimit.api_type')"
|
||||
prop="method"
|
||||
:label="$t('api_test.definition.api_type')"
|
||||
show-overflow-tooltip>
|
||||
<template v-slot:default="scope" class="request-method">
|
||||
<el-tag size="mini"
|
||||
:style="{'background-color': getColor(true, scope.row.path)}" class="api-el-tag"> {{ scope.row.path
|
||||
:style="{'background-color': getColor(true, scope.row.method)}" class="api-el-tag"> {{ scope.row.method
|
||||
}}
|
||||
</el-tag>
|
||||
</template>
|
||||
|
@ -46,15 +46,15 @@
|
|||
|
||||
<el-table-column
|
||||
prop="url"
|
||||
:label="$t('api_test.delimit.api_path')"
|
||||
:label="$t('api_test.definition.api_path')"
|
||||
show-overflow-tooltip/>
|
||||
|
||||
<el-table-column
|
||||
prop="userName"
|
||||
:label="$t('api_test.delimit.api_principal')"
|
||||
:label="$t('api_test.definition.api_principal')"
|
||||
show-overflow-tooltip/>
|
||||
|
||||
<el-table-column width="160" :label="$t('api_test.delimit.api_last_time')" prop="updateTime">
|
||||
<el-table-column width="160" :label="$t('api_test.definition.api_last_time')" prop="updateTime">
|
||||
<template v-slot:default="scope">
|
||||
<span>{{ scope.row.updateTime | timestampFormatDate }}</span>
|
||||
</template>
|
||||
|
@ -62,17 +62,17 @@
|
|||
|
||||
<el-table-column
|
||||
prop="caseTotal"
|
||||
:label="$t('api_test.delimit.api_case_number')"
|
||||
:label="$t('api_test.definition.api_case_number')"
|
||||
show-overflow-tooltip/>
|
||||
|
||||
<el-table-column
|
||||
prop="caseStatus"
|
||||
:label="$t('api_test.delimit.api_case_status')"
|
||||
:label="$t('api_test.definition.api_case_status')"
|
||||
show-overflow-tooltip/>
|
||||
|
||||
<el-table-column
|
||||
prop="casePassingRate"
|
||||
:label="$t('api_test.delimit.api_case_passing_rate')"
|
||||
:label="$t('api_test.definition.api_case_passing_rate')"
|
||||
show-overflow-tooltip/>
|
||||
|
||||
|
||||
|
@ -134,7 +134,7 @@
|
|||
moduleId: "",
|
||||
deletePath: "/test/case/delete",
|
||||
selectRows: new Set(),
|
||||
buttons: [{name: this.$t('api_test.delimit.request.batch_delete'), handleClick: this.handleDeleteBatch}],
|
||||
buttons: [{name: this.$t('api_test.definition.request.batch_delete'), handleClick: this.handleDeleteBatch}],
|
||||
methodColorMap: new Map(API_METHOD_COLOUR),
|
||||
tableData: [],
|
||||
currentPage: 1,
|
||||
|
@ -169,7 +169,7 @@
|
|||
if (this.currentProject != null) {
|
||||
this.condition.projectId = this.currentProject.id;
|
||||
}
|
||||
this.result = this.$post("/api/delimit/list/" + this.currentPage + "/" + this.pageSize, this.condition, response => {
|
||||
this.result = this.$post("/api/definition/list/" + this.currentPage + "/" + this.pageSize, this.condition, response => {
|
||||
this.total = response.data.itemCount;
|
||||
this.tableData = response.data.listObject;
|
||||
});
|
||||
|
@ -222,12 +222,12 @@
|
|||
this.$emit('editApi', row);
|
||||
},
|
||||
handleDeleteBatch() {
|
||||
this.$alert(this.$t('api_test.delimit.request.delete_confirm') + "?", '', {
|
||||
this.$alert(this.$t('api_test.definition.request.delete_confirm') + "?", '', {
|
||||
confirmButtonText: this.$t('commons.confirm'),
|
||||
callback: (action) => {
|
||||
if (action === 'confirm') {
|
||||
let ids = Array.from(this.selectRows).map(row => row.id);
|
||||
this.$post('/api/delimit/deleteBatch/', ids, () => {
|
||||
this.$post('/api/definition/deleteBatch/', ids, () => {
|
||||
this.selectRows.clear();
|
||||
this.initApiTable();
|
||||
this.$success(this.$t('commons.delete_success'));
|
||||
|
@ -241,7 +241,7 @@
|
|||
this.isHide = false;
|
||||
},
|
||||
handleDelete(testCase) {
|
||||
this.$get('/api/delimit/delete/' + testCase.id, () => {
|
||||
this.$get('/api/definition/delete/' + testCase.id, () => {
|
||||
this.$success(this.$t('commons.delete_success'));
|
||||
this.initApiTable();
|
||||
});
|
|
@ -0,0 +1,102 @@
|
|||
<template>
|
||||
<editor v-model="formatData" :lang="mode" @init="editorInit" :theme="theme" :height="height"/>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {formatHtml, formatJson, formatXml} from "../../../../../common/js/format-utils";
|
||||
import toDiffableHtml from 'diffable-html';
|
||||
|
||||
export default {
|
||||
name: "MsCodeEdit",
|
||||
components: {editor: require('vue2-ace-editor')},
|
||||
data() {
|
||||
return {
|
||||
formatData: ''
|
||||
}
|
||||
},
|
||||
props: {
|
||||
height: [String, Number],
|
||||
data: {
|
||||
type: String
|
||||
},
|
||||
theme: {
|
||||
type: String,
|
||||
default() {
|
||||
return 'chrome'
|
||||
}
|
||||
},
|
||||
init: {
|
||||
type: Function
|
||||
},
|
||||
readOnly: {
|
||||
type: Boolean,
|
||||
default() {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
mode: {
|
||||
type: String,
|
||||
default() {
|
||||
return 'text';
|
||||
}
|
||||
},
|
||||
modes: {
|
||||
type: Array,
|
||||
default() {
|
||||
return ['text', 'json', 'xml', 'html'];
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.format();
|
||||
},
|
||||
watch: {
|
||||
formatData() {
|
||||
this.$emit('update:data', this.formatData);
|
||||
},
|
||||
mode() {
|
||||
this.format();
|
||||
},
|
||||
data() {
|
||||
this.formatData = this.data;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
editorInit: function (editor) {
|
||||
require('brace/ext/language_tools') //language extension prerequsite...
|
||||
this.modes.forEach(mode => {
|
||||
require('brace/mode/' + mode); //language
|
||||
});
|
||||
require('brace/theme/' + this.theme)
|
||||
require('brace/snippets/javascript') //snippet
|
||||
if (this.readOnly) {
|
||||
editor.setReadOnly(true);
|
||||
}
|
||||
if (this.init) {
|
||||
this.init(editor);
|
||||
}
|
||||
},
|
||||
format() {
|
||||
switch (this.mode) {
|
||||
case 'json':
|
||||
this.formatData = formatJson(this.data);
|
||||
break;
|
||||
case 'html':
|
||||
this.formatData = toDiffableHtml(this.data);
|
||||
break;
|
||||
case 'xml':
|
||||
this.formatData = formatXml(this.data);
|
||||
break;
|
||||
default:
|
||||
if (this.data) {
|
||||
this.formatData = this.data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
|
@ -0,0 +1,106 @@
|
|||
<template>
|
||||
<div></div>
|
||||
</template>
|
||||
<script>
|
||||
import {Scenario} from "../model/ApiTestModel";
|
||||
import {getUUID} from "@/common/js/utils";
|
||||
|
||||
export default {
|
||||
name: 'MsRun',
|
||||
components: {},
|
||||
props: {
|
||||
environment: Object,
|
||||
debug: Boolean,
|
||||
reportId: String,
|
||||
runData: Array,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
result: {},
|
||||
loading: false,
|
||||
runId: "",
|
||||
}
|
||||
},
|
||||
|
||||
watch: {
|
||||
// 初始化
|
||||
reportId() {
|
||||
this.run()
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
getResult() {
|
||||
if (this.runId) {
|
||||
let url = "";
|
||||
if (this.debug) {
|
||||
url = "/api/definition/report/get/" + this.runId + "/" + "debug";
|
||||
} else {
|
||||
url = "/api/definition/report/get/" + this.runId + "/" + "run";
|
||||
}
|
||||
this.$get(url, response => {
|
||||
if (response.data) {
|
||||
let data = JSON.parse(response.data.content);
|
||||
this.$emit('runRefresh', data);
|
||||
} else {
|
||||
setTimeout(this.getResult, 2000);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
getBodyUploadFiles(obj) {
|
||||
let bodyUploadFiles = [];
|
||||
obj.bodyUploadIds = [];
|
||||
this.runData.forEach(request => {
|
||||
if (request.body) {
|
||||
request.body.kvs.forEach(param => {
|
||||
if (param.files) {
|
||||
param.files.forEach(item => {
|
||||
if (item.file) {
|
||||
let fileId = getUUID().substring(0, 8);
|
||||
item.name = item.file.name;
|
||||
item.id = fileId;
|
||||
obj.bodyUploadIds.push(fileId);
|
||||
bodyUploadFiles.push(item.file);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
return bodyUploadFiles;
|
||||
},
|
||||
run() {
|
||||
let reqObj = {};
|
||||
let scenario = new Scenario({requests: this.runData});
|
||||
let url = "";
|
||||
let reportId = getUUID().substring(0, 8);
|
||||
let bodyFiles = this.getBodyUploadFiles(reqObj);
|
||||
scenario.requests.forEach(item => {
|
||||
if (this.environment != null) {
|
||||
item.useEnvironment = true;
|
||||
scenario.environmentId = this.environment.id;
|
||||
}
|
||||
item.definition = true;
|
||||
});
|
||||
scenario.name = reportId;
|
||||
scenario.dubboConfig = null;
|
||||
scenario.tcpConfig = null;
|
||||
reqObj.name = reportId;
|
||||
reqObj.scenario = scenario;
|
||||
reqObj.id = reportId;
|
||||
if (this.debug) {
|
||||
url = "/api/definition/run/debug";
|
||||
} else {
|
||||
reqObj.reportId = "run";
|
||||
url = "/api/definition/run";
|
||||
}
|
||||
this.$fileUpload(url, null, bodyFiles, reqObj, response => {
|
||||
this.runId = response.data;
|
||||
this.getResult();
|
||||
}, erro => {
|
||||
this.$emit('runRefresh', {});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
|
@ -1,14 +1,14 @@
|
|||
<template xmlns:v-slot="http://www.w3.org/1999/XSL/Transform">
|
||||
<el-tabs v-model="activeName">
|
||||
<!-- 认证-->
|
||||
<el-tab-pane :label="$t('api_test.delimit.request.verified')" name="verified">
|
||||
<el-tab-pane :label="$t('api_test.definition.request.verified')" name="verified">
|
||||
|
||||
<el-form :model="authConfig" size="small" :rules="rule"
|
||||
ref="authConfig">
|
||||
|
||||
<el-form-item :label="$t('api_test.delimit.request.verification_method')" prop="verification">
|
||||
<el-form-item :label="$t('api_test.definition.request.verification_method')" prop="verification">
|
||||
<el-select v-model="authConfig.verification"
|
||||
:placeholder="$t('api_test.delimit.request.verification_method')" filterable size="small">
|
||||
:placeholder="$t('api_test.definition.request.verification_method')" filterable size="small">
|
||||
<el-option
|
||||
v-for="item in options"
|
||||
:key="item.name"
|
||||
|
@ -36,13 +36,13 @@
|
|||
</el-tab-pane>
|
||||
|
||||
<!--加密-->
|
||||
<el-tab-pane :label="$t('api_test.delimit.request.encryption')" name="encryption">
|
||||
<el-tab-pane :label="$t('api_test.definition.request.encryption')" name="encryption">
|
||||
<el-form :model="authConfig" size="small" :rules="rule"
|
||||
ref="authConfig">
|
||||
|
||||
<el-form-item :label="$t('api_test.delimit.request.encryption')" prop="encryption">
|
||||
<el-form-item :label="$t('api_test.definition.request.encryption')" prop="encryption">
|
||||
<el-select v-model="authConfig.isEncrypt"
|
||||
:placeholder="$t('api_test.delimit.request.verification_method')" filterable size="small">
|
||||
:placeholder="$t('api_test.definition.request.verification_method')" filterable size="small">
|
||||
<el-option
|
||||
v-for="item in encryptOptions"
|
||||
:key="item.id"
|
|
@ -1,5 +1,5 @@
|
|||
<template>
|
||||
<el-dialog :close-on-click-modal="false" :title="$t('api_test.delimit.request.title')" :visible.sync="httpVisible"
|
||||
<el-dialog :close-on-click-modal="false" :title="$t('api_test.definition.request.title')" :visible.sync="httpVisible"
|
||||
width="45%"
|
||||
:destroy-on-close="true">
|
||||
<el-form :model="httpForm" label-position="right" label-width="80px" size="small" :rules="rule" ref="httpForm">
|
||||
|
@ -8,16 +8,16 @@
|
|||
</el-form-item>
|
||||
|
||||
<el-form-item :label="$t('api_report.request')" prop="url">
|
||||
<el-input :placeholder="$t('api_test.delimit.request.path_info')" v-model="httpForm.url"
|
||||
<el-input :placeholder="$t('api_test.definition.request.path_info')" v-model="httpForm.url"
|
||||
class="ms-http-input" size="small">
|
||||
<el-select v-model="httpForm.path" slot="prepend" style="width: 100px" size="small">
|
||||
<el-select v-model="httpForm.method" slot="prepend" style="width: 100px" size="small">
|
||||
<el-option v-for="item in options" :key="item.id" :label="item.label" :value="item.id"/>
|
||||
</el-select>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('api_test.delimit.request.responsible')" prop="userId">
|
||||
<el-form-item :label="$t('api_test.definition.request.responsible')" prop="userId">
|
||||
<el-select v-model="httpForm.userId"
|
||||
:placeholder="$t('api_test.delimit.request.responsible')" filterable size="small"
|
||||
:placeholder="$t('api_test.definition.request.responsible')" filterable size="small"
|
||||
style="width: 100%">
|
||||
<el-option
|
||||
v-for="item in maintainerOptions"
|
||||
|
@ -68,7 +68,7 @@
|
|||
{required: true, message: this.$t('test_track.case.input_name'), trigger: 'blur'},
|
||||
{max: 50, message: this.$t('test_track.length_less_than') + '50', trigger: 'blur'}
|
||||
],
|
||||
url: [{required: true, message: this.$t('api_test.delimit.request.path_info'), trigger: 'blur'}],
|
||||
url: [{required: true, message: this.$t('api_test.definition.request.path_info'), trigger: 'blur'}],
|
||||
userId: [{required: true, message: this.$t('test_track.case.input_maintainer'), trigger: 'change'}],
|
||||
},
|
||||
value: REQ_METHOD[0].id,
|
||||
|
@ -80,16 +80,16 @@
|
|||
this.$refs['httpForm'].validate((valid) => {
|
||||
if (valid) {
|
||||
let bodyFiles = [];
|
||||
let url = "/api/delimit/create";
|
||||
let url = "/api/definition/create";
|
||||
let test = new Test();
|
||||
this.httpForm.bodyUploadIds = [];
|
||||
this.httpForm.request = test.request;
|
||||
this.httpForm.request.url = this.httpForm.url;
|
||||
this.httpForm.request.path = this.httpForm.path;
|
||||
this.httpForm.request.method = this.httpForm.method;
|
||||
this.httpForm.projectId = this.projectId;
|
||||
this.httpForm.id = test.id;
|
||||
if (this.currentModule != null) {
|
||||
this.httpForm.modulePath = this.currentModule.path != undefined ? this.currentModule.path : null;
|
||||
this.httpForm.modulePath = this.currentModule.method != undefined ? this.currentModule.method : null;
|
||||
this.httpForm.moduleId = this.currentModule.id;
|
||||
}
|
||||
let jmx = test.toJMX();
|
||||
|
@ -113,7 +113,7 @@
|
|||
}
|
||||
,
|
||||
open(currentModule, projectId) {
|
||||
this.httpForm = {path: REQ_METHOD[0].id, userId: getCurrentUser().id};
|
||||
this.httpForm = {method: REQ_METHOD[0].id, userId: getCurrentUser().id};
|
||||
this.currentModule = currentModule;
|
||||
this.projectId = projectId;
|
||||
this.getMaintainerOptions();
|
|
@ -1,28 +1,28 @@
|
|||
<template>
|
||||
<div>
|
||||
<el-radio-group v-model="body.type" size="mini">
|
||||
<el-radio :disabled="isReadOnly" :label="type.KV">
|
||||
{{ $t('api_test.delimit.request.body_form_data') }}
|
||||
<el-radio :disabled="isReadOnly" :label="type.KV" @change="modeChange">
|
||||
{{ $t('api_test.definition.request.body_form_data') }}
|
||||
</el-radio>
|
||||
|
||||
<el-radio :disabled="isReadOnly" :label="type.WWW_FORM">
|
||||
{{ $t('api_test.delimit.request.body_x_www_from_urlencoded') }}
|
||||
<el-radio :disabled="isReadOnly" :label="type.WWW_FORM" @change="modeChange">
|
||||
{{ $t('api_test.definition.request.body_x_www_from_urlencoded') }}
|
||||
</el-radio>
|
||||
|
||||
<el-radio :disabled="isReadOnly" :label="type.JSON">
|
||||
{{ $t('api_test.delimit.request.body_json') }}
|
||||
<el-radio :disabled="isReadOnly" :label="type.JSON" @change="modeChange">
|
||||
{{ $t('api_test.definition.request.body_json') }}
|
||||
</el-radio>
|
||||
|
||||
<el-radio :disabled="isReadOnly" :label="type.XML">
|
||||
{{ $t('api_test.delimit.request.body_xml') }}
|
||||
<el-radio :disabled="isReadOnly" :label="type.XML" @change="modeChange">
|
||||
{{ $t('api_test.definition.request.body_xml') }}
|
||||
</el-radio>
|
||||
|
||||
<el-radio :disabled="isReadOnly" :label="type.RAW">
|
||||
{{ $t('api_test.delimit.request.body_raw') }}
|
||||
<el-radio :disabled="isReadOnly" :label="type.RAW" @change="modeChange">
|
||||
{{ $t('api_test.definition.request.body_raw') }}
|
||||
</el-radio>
|
||||
|
||||
<el-radio :disabled="isReadOnly" :label="type.BINARY">
|
||||
{{ $t('api_test.delimit.request.body_binary') }}
|
||||
<el-radio :disabled="isReadOnly" :label="type.BINARY" @change="modeChange">
|
||||
{{ $t('api_test.definition.request.body_binary') }}
|
||||
</el-radio>
|
||||
</el-radio-group>
|
||||
|
||||
|
@ -40,9 +40,17 @@
|
|||
type="body"
|
||||
v-if="body.type == 'WWW_FORM'"/>
|
||||
|
||||
<div class="body-raw" v-if="body.type == 'JSON'">
|
||||
<ms-json-code-edit @json-change="jsonChange" @onError="jsonError" :value="body.json" ref="jsonCodeEdit"/>
|
||||
</div>
|
||||
|
||||
<div class="body-raw" v-if="body.type == 'XML'">
|
||||
<ms-code-edit :read-only="isReadOnly" :data.sync="body.xml" :modes="modes" ref="codeEdit"/>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="body-raw" v-if="body.type == 'Raw'">
|
||||
<ms-json-code-edit v-if="body.format=='json'" @json-change="jsonChange" @onError="jsonError" :value="body.json" ref="jsonCodeEdit"/>
|
||||
<ms-code-edit v-else :mode="body.format" :read-only="isReadOnly" :data.sync="body.raw" :modes="modes" ref="codeEdit"/>
|
||||
<ms-code-edit :read-only="isReadOnly" :data.sync="body.raw" :modes="modes" ref="codeEdit"/>
|
||||
</div>
|
||||
|
||||
<ms-api-binary-variable :is-read-only="isReadOnly"
|
||||
|
@ -86,7 +94,6 @@
|
|||
default: false
|
||||
}
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
type: BODY_TYPE,
|
||||
|
@ -96,7 +103,18 @@
|
|||
|
||||
methods: {
|
||||
modeChange(mode) {
|
||||
this.body.format = mode;
|
||||
switch (this.body.type) {
|
||||
case "JSON":
|
||||
return this.body.format = "json";
|
||||
case "XML":
|
||||
return this.body.format = "xml";
|
||||
case "WWW_FORM":
|
||||
return this.body.format = "form";
|
||||
case "BINARY":
|
||||
return this.body.format = "binary";
|
||||
default:
|
||||
return this.body.format = mode;
|
||||
}
|
||||
},
|
||||
jsonChange(json) {
|
||||
this.body.json = json;
|
|
@ -20,9 +20,9 @@
|
|||
</el-form-item>
|
||||
|
||||
<el-form-item :label="$t('api_report.request')" prop="url">
|
||||
<el-input :placeholder="$t('api_test.delimit.request.path_info')" v-model="httpForm.url"
|
||||
<el-input :placeholder="$t('api_test.definition.request.path_info')" v-model="httpForm.url"
|
||||
class="ms-http-input" size="small" style="margin-top: 5px">
|
||||
<el-select v-model="httpForm.path" slot="prepend" style="width: 100px" size="small">
|
||||
<el-select v-model="httpForm.method" slot="prepend" style="width: 100px" size="small">
|
||||
<el-option v-for="item in reqOptions" :key="item.id" :label="item.label" :value="item.id"/>
|
||||
</el-select>
|
||||
</el-input>
|
||||
|
@ -36,9 +36,9 @@
|
|||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item :label="$t('api_test.delimit.request.responsible')" prop="userId">
|
||||
<el-form-item :label="$t('api_test.definition.request.responsible')" prop="userId">
|
||||
<el-select v-model="httpForm.userId"
|
||||
:placeholder="$t('api_test.delimit.request.responsible')" filterable size="small"
|
||||
:placeholder="$t('api_test.definition.request.responsible')" filterable size="small"
|
||||
class="ms-http-input">
|
||||
<el-option
|
||||
v-for="item in maintainerOptions"
|
||||
|
@ -59,12 +59,12 @@
|
|||
</el-form-item>
|
||||
|
||||
<!-- HTTP 请求参数 -->
|
||||
<p class="tip">{{$t('api_test.delimit.request.req_param')}} </p>
|
||||
<p class="tip">{{$t('api_test.definition.request.req_param')}} </p>
|
||||
<ms-api-request-form :request="test.request" :isShowEnable="isShowEnable"/>
|
||||
</el-form>
|
||||
|
||||
<!-- 响应内容-->
|
||||
<p class="tip">{{$t('api_test.delimit.request.res_param')}} </p>
|
||||
<p class="tip">{{$t('api_test.definition.request.res_param')}} </p>
|
||||
<ms-response-text :response="test.response"></ms-response-text>
|
||||
</el-card>
|
||||
</div>
|
||||
|
@ -86,7 +86,7 @@
|
|||
{required: true, message: this.$t('test_track.case.input_name'), trigger: 'blur'},
|
||||
{max: 50, message: this.$t('test_track.length_less_than') + '50', trigger: 'blur'}
|
||||
],
|
||||
url: [{required: true, message: this.$t('api_test.delimit.request.path_info'), trigger: 'blur'}],
|
||||
url: [{required: true, message: this.$t('api_test.definition.request.path_info'), trigger: 'blur'}],
|
||||
userId: [{required: true, message: this.$t('test_track.case.input_maintainer'), trigger: 'change'}],
|
||||
moduleId: [{required: true, message: this.$t('test_track.case.input_module'), trigger: 'change'}],
|
||||
status: [{required: true, message: this.$t('commons.please_select'), trigger: 'change'}],
|
||||
|
@ -124,7 +124,7 @@
|
|||
setParameter() {
|
||||
this.httpForm.test = this.test;
|
||||
this.httpForm.test.request.url = this.httpForm.url;
|
||||
this.httpForm.test.request.path = this.httpForm.path;
|
||||
this.httpForm.test.request.method = this.httpForm.method;
|
||||
this.httpForm.modulePath = this.getPath(this.httpForm.moduleId);
|
||||
},
|
||||
saveApi() {
|
|
@ -6,9 +6,9 @@
|
|||
<p class="tip">{{$t('test_track.plan_view.base_info')}} </p>
|
||||
|
||||
<el-form-item :label="$t('api_report.request')" prop="url">
|
||||
<el-input :placeholder="$t('api_test.delimit.request.path_all_info')" v-model="debugForm.url"
|
||||
<el-input :placeholder="$t('api_test.definition.request.path_all_info')" v-model="debugForm.url"
|
||||
class="ms-http-input" size="small">
|
||||
<el-select v-model="debugForm.path" slot="prepend" style="width: 100px" size="small">
|
||||
<el-select v-model="debugForm.method" slot="prepend" style="width: 100px" size="small">
|
||||
<el-option v-for="item in reqOptions" :key="item.id" :label="item.label" :value="item.id"/>
|
||||
</el-select>
|
||||
</el-input>
|
||||
|
@ -19,19 +19,22 @@
|
|||
@command="handleCommand" size="small">
|
||||
{{$t('commons.test')}}
|
||||
<el-dropdown-menu slot="dropdown">
|
||||
<el-dropdown-item command="save_as">{{$t('api_test.delimit.request.save_as')}}</el-dropdown-item>
|
||||
<el-dropdown-item command="save_as">{{$t('api_test.definition.request.save_as')}}</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</el-dropdown>
|
||||
</el-form-item>
|
||||
|
||||
<p class="tip">{{$t('api_test.delimit.request.req_param')}} </p>
|
||||
<p class="tip">{{$t('api_test.definition.request.req_param')}} </p>
|
||||
<!-- HTTP 请求参数 -->
|
||||
<ms-api-request-form :request="test.request"/>
|
||||
|
||||
</el-form>
|
||||
<!-- HTTP 请求返回数据 -->
|
||||
<p class="tip">{{$t('api_test.delimit.request.res_param')}} </p>
|
||||
<p class="tip">{{$t('api_test.definition.request.res_param')}} </p>
|
||||
<ms-request-result-tail v-loading="loading" :response="responseData" ref="debugResult"/>
|
||||
|
||||
<!-- 执行组件 -->
|
||||
<ms-run :debug="true" :reportId="reportId" :run-data="runData" @runRefresh="runRefresh" ref="runTest"/>
|
||||
</el-card>
|
||||
</div>
|
||||
</template>
|
||||
|
@ -43,6 +46,7 @@
|
|||
import MsRequestMetric from "../response/RequestMetric";
|
||||
import {getUUID, getCurrentUser} from "@/common/js/utils";
|
||||
import MsResponseText from "../response/ResponseText";
|
||||
import MsRun from "../Run";
|
||||
|
||||
|
||||
import {REQ_METHOD} from "../../model/JsonData";
|
||||
|
@ -50,19 +54,21 @@
|
|||
|
||||
export default {
|
||||
name: "ApiConfig",
|
||||
components: {MsRequestResultTail, MsResponseResult, MsApiRequestForm, MsRequestMetric, MsResponseText},
|
||||
components: {MsRequestResultTail, MsResponseResult, MsApiRequestForm, MsRequestMetric, MsResponseText, MsRun},
|
||||
data() {
|
||||
return {
|
||||
rules: {
|
||||
path: [{required: true, message: this.$t('test_track.case.input_maintainer'), trigger: 'change'}],
|
||||
url: [{required: true, message: this.$t('api_test.delimit.request.path_all_info'), trigger: 'blur'}],
|
||||
method: [{required: true, message: this.$t('test_track.case.input_maintainer'), trigger: 'change'}],
|
||||
url: [{required: true, message: this.$t('api_test.definition.request.path_all_info'), trigger: 'blur'}],
|
||||
},
|
||||
debugForm: {path: REQ_METHOD[0].id},
|
||||
debugForm: {method: REQ_METHOD[0].id},
|
||||
options: [],
|
||||
responseData: {type: 'HTTP', responseResult: {}, subRequestResults: []},
|
||||
loading: false,
|
||||
debugResultId: "",
|
||||
test: new Test(),
|
||||
runData: [],
|
||||
reportId: "",
|
||||
reqOptions: REQ_METHOD,
|
||||
}
|
||||
},
|
||||
|
@ -79,59 +85,24 @@
|
|||
this.runDebug();
|
||||
}
|
||||
},
|
||||
getBodyUploadFiles(data) {
|
||||
let bodyUploadFiles = [];
|
||||
data.bodyUploadIds = [];
|
||||
let request = data.request;
|
||||
if (request.body) {
|
||||
request.body.kvs.forEach(param => {
|
||||
if (param.files) {
|
||||
param.files.forEach(item => {
|
||||
if (item.file) {
|
||||
let fileId = getUUID().substring(0, 8);
|
||||
item.name = item.file.name;
|
||||
item.id = fileId;
|
||||
data.bodyUploadIds.push(fileId);
|
||||
bodyUploadFiles.push(item.file);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
return bodyUploadFiles;
|
||||
},
|
||||
runDebug() {
|
||||
this.$refs['debugForm'].validate((valid) => {
|
||||
if (valid) {
|
||||
this.loading = true;
|
||||
let url = "/api/delimit/run/debug";
|
||||
let bodyFiles = this.getBodyUploadFiles(this.test);
|
||||
this.test.request.url = this.debugForm.url;
|
||||
this.test.request.path = this.debugForm.path;
|
||||
this.test.id = getUUID().substring(0, 8);
|
||||
let jmx = this.test.toJMX();
|
||||
let blob = new Blob([jmx.xml], {type: "application/octet-stream"});
|
||||
let file = new File([blob], jmx.name);
|
||||
this.$fileUpload(url, file, bodyFiles, this.test, response => {
|
||||
this.debugResultId = response.data;
|
||||
});
|
||||
this.test.request.method = this.debugForm.method;
|
||||
this.test.request.name = getUUID().substring(0, 8);
|
||||
this.runData = [];
|
||||
this.runData.push(this.test.request);
|
||||
/*触发执行操作*/
|
||||
this.reportId = getUUID().substring(0, 8);
|
||||
}
|
||||
})
|
||||
},
|
||||
getResult() {
|
||||
if (this.debugResultId) {
|
||||
let url = "/api/delimit/report/get/" + this.debugResultId + "/" + "debug";
|
||||
this.$get(url, response => {
|
||||
if (response.data) {
|
||||
let testResult = JSON.parse(response.data.content);
|
||||
this.responseData = testResult.requestResults[0];
|
||||
this.loading = false;
|
||||
this.$refs.debugResult.reload();
|
||||
} else {
|
||||
setTimeout(this.getResult, 2000)
|
||||
}
|
||||
});
|
||||
}
|
||||
runRefresh(data) {
|
||||
this.responseData = data;
|
||||
this.loading = false;
|
||||
this.$refs.debugResult.reload();
|
||||
},
|
||||
saveAs() {
|
||||
this.$refs['debugForm'].validate((valid) => {
|
|
@ -8,7 +8,7 @@
|
|||
</el-tab-pane>
|
||||
|
||||
<!--query 参数-->
|
||||
<el-tab-pane :label="$t('api_test.delimit.request.query_param')" name="parameters">
|
||||
<el-tab-pane :label="$t('api_test.definition.request.query_param')" name="parameters">
|
||||
<ms-api-variable :is-read-only="isReadOnly"
|
||||
:parameters="request.parameters"
|
||||
:environment="request.environment"
|
||||
|
@ -16,7 +16,7 @@
|
|||
</el-tab-pane>
|
||||
|
||||
<!--REST 参数-->
|
||||
<el-tab-pane :label="$t('api_test.delimit.request.rest_param')" name="rest">
|
||||
<el-tab-pane :label="$t('api_test.definition.request.rest_param')" name="rest">
|
||||
<ms-api-key-value :is-read-only="isReadOnly" :isShowEnable="isShowEnable" :suggestions="headerSuggestions"
|
||||
:items="request.rest"/>
|
||||
</el-tab-pane>
|
||||
|
@ -29,7 +29,7 @@
|
|||
:environment="request.environment"/>
|
||||
</el-tab-pane>
|
||||
<!-- 认证配置 -->
|
||||
<el-tab-pane :label="$t('api_test.delimit.request.auth_config')" name="authConfig">
|
||||
<el-tab-pane :label="$t('api_test.definition.request.auth_config')" name="authConfig">
|
||||
<ms-api-auth-config :request="request" :is-read-only="isReadOnly" :auth-config="request.authConfig"/>
|
||||
</el-tab-pane>
|
||||
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
data() {
|
||||
return {
|
||||
isCodeEditAlive: true
|
||||
isCodeEditAlive: true,
|
||||
}
|
||||
},
|
||||
|
|
@ -2,17 +2,17 @@
|
|||
<div class="text-container">
|
||||
|
||||
<el-tabs v-model="activeName" v-show="isActive">
|
||||
<el-tab-pane :label="$t('api_test.delimit.request.response_header')" name="headers" class="pane">
|
||||
<el-tab-pane :label="$t('api_test.definition.request.response_header')" name="headers" class="pane">
|
||||
<pre>{{ response.headers }}</pre>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane :label="$t('api_test.delimit.request.response_body')" name="body" class="pane">
|
||||
<el-tab-pane :label="$t('api_test.definition.request.response_body')" name="body" class="pane">
|
||||
<ms-code-edit :mode="mode" :read-only="true" :modes="modes" :data.sync="response.body" ref="codeEdit"/>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="Cookie" name="cookie" class="pane cookie">
|
||||
<pre>{{response.cookies}}</pre>
|
||||
</el-tab-pane>
|
||||
|
||||
<el-tab-pane :label="$t('api_test.delimit.request.console')" name="console" class="pane">
|
||||
<el-tab-pane :label="$t('api_test.definition.request.console')" name="console" class="pane">
|
||||
<pre>{{response.console}}</pre>
|
||||
</el-tab-pane>
|
||||
|
||||
|
@ -27,7 +27,7 @@
|
|||
|
||||
<script>
|
||||
import MsAssertionResults from "./AssertionResults";
|
||||
import MsCodeEdit from "../../../../common/components/MsCodeEdit";
|
||||
import MsCodeEdit from "../MsCodeEdit";
|
||||
import MsDropdown from "../../../../common/components/MsDropdown";
|
||||
import {BODY_FORMAT} from "../../model/ApiTestModel";
|
||||
|
||||
|
@ -41,7 +41,7 @@
|
|||
},
|
||||
|
||||
props: {
|
||||
response: Object
|
||||
response: Object,
|
||||
},
|
||||
|
||||
data() {
|
||||
|
@ -52,11 +52,7 @@
|
|||
mode: BODY_FORMAT.TEXT
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
active() {
|
||||
console.log(this.response.body);
|
||||
},
|
||||
modeChange(mode) {
|
||||
this.mode = mode;
|
||||
}
|
|
@ -4,17 +4,17 @@
|
|||
|
||||
<el-collapse-transition>
|
||||
<el-tabs v-model="activeName" v-show="isActive">
|
||||
<el-tab-pane :label="$t('api_test.delimit.request.response_header')" name="headers" class="pane">
|
||||
<el-tab-pane :label="$t('api_test.definition.request.response_header')" name="headers" class="pane">
|
||||
<ms-api-key-value :isShowEnable="false" :suggestions="headerSuggestions"
|
||||
:items="response.headers"/>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane :label="$t('api_test.delimit.request.response_body')" name="body" class="pane">
|
||||
<el-tab-pane :label="$t('api_test.definition.request.response_body')" name="body" class="pane">
|
||||
<ms-api-body
|
||||
:body="response.body"
|
||||
:extract="response.extract"/>
|
||||
</el-tab-pane>
|
||||
|
||||
<el-tab-pane :label="$t('api_test.delimit.request.status_code')" name="status_code" class="pane">
|
||||
<el-tab-pane :label="$t('api_test.definition.request.status_code')" name="status_code" class="pane">
|
||||
<ms-api-key-value :isShowEnable="false" :suggestions="headerSuggestions"
|
||||
:items="response.statusCode"/>
|
||||
</el-tab-pane>
|
|
@ -7,8 +7,8 @@
|
|||
|
||||
<p class="tip">{{$t('test_track.plan_view.base_info')}} </p>
|
||||
<!-- 请求方法 -->
|
||||
<el-form-item :label="$t('api_report.request')" prop="path">
|
||||
<el-select v-model="api.path" style="width: 100px" size="small">
|
||||
<el-form-item :label="$t('api_report.request')" prop="method">
|
||||
<el-select v-model="api.method" style="width: 100px" size="small">
|
||||
<el-option v-for="item in reqOptions" :key="item.id" :label="item.label" :value="item.id"/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
@ -16,7 +16,7 @@
|
|||
<!-- 执行环境 -->
|
||||
<el-form-item prop="environmentId">
|
||||
<el-select v-model="api.environmentId" size="small" class="ms-htt-width"
|
||||
:placeholder="$t('api_test.delimit.request.run_env')"
|
||||
:placeholder="$t('api_test.definition.request.run_env')"
|
||||
@change="environmentChange" clearable>
|
||||
<el-option v-for="(environment, index) in environments" :key="index"
|
||||
:label="environment.name + (environment.config.httpConfig.socket ? (': ' + environment.config.httpConfig.protocol + '://' + environment.config.httpConfig.socket) : '')"
|
||||
|
@ -36,7 +36,7 @@
|
|||
|
||||
<!-- 请求地址 -->
|
||||
<el-form-item prop="url">
|
||||
<el-input :placeholder="$t('api_test.delimit.request.path_info')" v-model="api.url" class="ms-htt-width"
|
||||
<el-input :placeholder="$t('api_test.definition.request.path_info')" v-model="api.url" class="ms-htt-width"
|
||||
size="small" :disabled="false"/>
|
||||
</el-form-item>
|
||||
|
||||
|
@ -46,25 +46,25 @@
|
|||
@command="handleCommand" size="small">
|
||||
{{$t('commons.test')}}
|
||||
<el-dropdown-menu slot="dropdown">
|
||||
<el-dropdown-item command="load_case">{{$t('api_test.delimit.request.load_case')}}
|
||||
<el-dropdown-item command="load_case">{{$t('api_test.definition.request.load_case')}}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item command="save_as_case">{{$t('api_test.delimit.request.save_as_case')}}
|
||||
<el-dropdown-item command="save_as_case">{{$t('api_test.definition.request.save_as_case')}}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item command="update_api">{{$t('api_test.delimit.request.update_api')}}</el-dropdown-item>
|
||||
<el-dropdown-item command="save_as_api">{{$t('api_test.delimit.request.save_as')}}</el-dropdown-item>
|
||||
<el-dropdown-item command="update_api">{{$t('api_test.definition.request.update_api')}}</el-dropdown-item>
|
||||
<el-dropdown-item command="save_as_api">{{$t('api_test.definition.request.save_as')}}</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</el-dropdown>
|
||||
|
||||
</el-form-item>
|
||||
|
||||
<p class="tip">{{$t('api_test.delimit.request.req_param')}} </p>
|
||||
<p class="tip">{{$t('api_test.definition.request.req_param')}} </p>
|
||||
<!-- HTTP 请求参数 -->
|
||||
<ms-api-request-form :request="api.request"/>
|
||||
|
||||
</el-form>
|
||||
<!--返回结果-->
|
||||
<!-- HTTP 请求返回数据 -->
|
||||
<p class="tip">{{$t('api_test.delimit.request.res_param')}} </p>
|
||||
<p class="tip">{{$t('api_test.definition.request.res_param')}} </p>
|
||||
<ms-request-result-tail :response="responseData" ref="runResult"/>
|
||||
|
||||
</el-card>
|
||||
|
@ -78,6 +78,9 @@
|
|||
|
||||
<!-- 环境 -->
|
||||
<api-environment-config ref="environmentConfig" @close="environmentConfigClose"/>
|
||||
<!-- 执行组件 -->
|
||||
<ms-run :debug="false" :environment="api.environment" :reportId="reportId" :run-data="runData"
|
||||
@runRefresh="runRefresh" ref="runTest"/>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
@ -88,10 +91,11 @@
|
|||
import MsApiCaseList from "../ApiCaseList";
|
||||
import MsContainer from "../../../../common/components/MsContainer";
|
||||
import MsBottomContainer from "../BottomContainer";
|
||||
import {RequestFactory, Test} from "../../model/ApiTestModel";
|
||||
import {RequestFactory, Scenario} from "../../model/ApiTestModel";
|
||||
import {parseEnvironment} from "../../model/EnvironmentModel";
|
||||
import ApiEnvironmentConfig from "../../../test/components/ApiEnvironmentConfig";
|
||||
import MsRequestResultTail from "../response/RequestResultTail";
|
||||
import MsRun from "../Run";
|
||||
|
||||
import {REQ_METHOD} from "../../model/JsonData";
|
||||
|
||||
|
@ -103,7 +107,8 @@
|
|||
MsContainer,
|
||||
MsBottomContainer,
|
||||
MsRequestResultTail,
|
||||
ApiEnvironmentConfig
|
||||
ApiEnvironmentConfig,
|
||||
MsRun
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
|
@ -116,10 +121,12 @@
|
|||
reqOptions: REQ_METHOD,
|
||||
environments: [],
|
||||
rules: {
|
||||
path: [{required: true, message: this.$t('test_track.case.input_maintainer'), trigger: 'change'}],
|
||||
url: [{required: true, message: this.$t('api_test.delimit.request.path_info'), trigger: 'blur'}],
|
||||
environmentId: [{required: true, message: this.$t('api_test.delimit.request.run_env'), trigger: 'change'}],
|
||||
}
|
||||
method: [{required: true, message: this.$t('test_track.case.input_maintainer'), trigger: 'change'}],
|
||||
url: [{required: true, message: this.$t('api_test.definition.request.path_info'), trigger: 'blur'}],
|
||||
environmentId: [{required: true, message: this.$t('api_test.definition.request.run_env'), trigger: 'change'}],
|
||||
},
|
||||
runData: [],
|
||||
reportId: "",
|
||||
}
|
||||
},
|
||||
props: {apiData: {}, currentProject: {}},
|
||||
|
@ -142,46 +149,19 @@
|
|||
this.$refs['apiData'].validate((valid) => {
|
||||
if (valid) {
|
||||
this.loading = true;
|
||||
let url = "/api/delimit/run";
|
||||
let bodyFiles = this.getBodyUploadFiles();
|
||||
let env = this.api.environment.config.httpConfig.socket ? (this.api.environment.config.httpConfig.protocol + '://' + this.api.environment.config.httpConfig.socket) : '';
|
||||
if (env.endsWith("/")) {
|
||||
env = env.substr(0, env.length - 1);
|
||||
}
|
||||
let sendUrl = this.api.url;
|
||||
if (!sendUrl.startsWith("/")) {
|
||||
sendUrl = "/" + sendUrl;
|
||||
}
|
||||
this.api.test.request.url = env + sendUrl;
|
||||
this.api.test.request.path = this.api.path;
|
||||
this.api.test.request.url = this.api.url;
|
||||
this.api.test.request.method = this.api.method;
|
||||
this.api.test.request.name = this.api.id;
|
||||
this.api.reportId = "run";
|
||||
let jmx = this.api.test.toJMX();
|
||||
let blob = new Blob([jmx.xml], {type: "application/octet-stream"});
|
||||
let file = new File([blob], jmx.name);
|
||||
this.$fileUpload(url, file, bodyFiles, this.api, response => {
|
||||
this.getResult();
|
||||
}, erro => {
|
||||
this.loading = false;
|
||||
});
|
||||
this.runData = [];
|
||||
this.runData.push(this.api.test.request);
|
||||
/*触发执行操作*/
|
||||
this.reportId = getUUID().substring(0, 8);
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
getResult() {
|
||||
if (this.api.id) {
|
||||
let url = "/api/delimit/report/get/" + this.api.id + "/run";
|
||||
this.$get(url, response => {
|
||||
if (response.data) {
|
||||
let testResult = JSON.parse(response.data.content);
|
||||
this.responseData = testResult;
|
||||
this.loading = false;
|
||||
this.$refs.runResult.reload();
|
||||
} else {
|
||||
setTimeout(this.getResult, 2000)
|
||||
}
|
||||
});
|
||||
}
|
||||
runRefresh(data) {
|
||||
this.responseData = data;
|
||||
this.loading = false;
|
||||
},
|
||||
saveAs() {
|
||||
this.$emit('saveAs', this.api);
|
||||
|
@ -219,14 +199,14 @@
|
|||
this.loaded = false;
|
||||
let testCase = {};
|
||||
testCase.request = this.api.request;
|
||||
testCase.apiDelimitId = this.api.id;
|
||||
testCase.apiDefinitionId = this.api.id;
|
||||
testCase.priority = "P0";
|
||||
this.$refs.caseList.createCase(testCase);
|
||||
},
|
||||
saveAsApi() {
|
||||
let data = {};
|
||||
data.request = JSON.stringify(this.api.request);
|
||||
data.path = this.api.path;
|
||||
data.method = this.api.method;
|
||||
data.url = this.api.url;
|
||||
data.status = this.api.status;
|
||||
data.userId = this.api.userId;
|
||||
|
@ -234,7 +214,7 @@
|
|||
this.$emit('saveAsApi', data);
|
||||
},
|
||||
updateApi() {
|
||||
let url = "/api/delimit/update";
|
||||
let url = "/api/definition/update";
|
||||
let bodyFiles = this.getBodyUploadFiles();
|
||||
let jmx = this.api.test.toJMX();
|
||||
let blob = new Blob([jmx.xml], {type: "application/octet-stream"});
|
||||
|
@ -294,6 +274,15 @@
|
|||
environmentConfigClose() {
|
||||
this.getEnvironments();
|
||||
},
|
||||
getResult() {
|
||||
let url = "/api/definition/report/getReport/" + this.api.id;
|
||||
this.$get(url, response => {
|
||||
if (response.data) {
|
||||
let data = JSON.parse(response.data.content);
|
||||
this.responseData = data;
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.api = this.apiData;
|
|
@ -358,8 +358,8 @@ export class HttpRequest extends Request {
|
|||
this.useEnvironment = options.useEnvironment;
|
||||
this.debugReport = undefined;
|
||||
this.doMultipartPost = options.doMultipartPost;
|
||||
this.connectTimeout = options.connectTimeout || 60 * 1000;
|
||||
this.responseTimeout = options.responseTimeout;
|
||||
this.connectTimeout = options.connectTimeout || 10 * 1000;
|
||||
this.responseTimeout = options.responseTimeout || 10 * 1000;
|
||||
this.followRedirects = options.followRedirects === undefined ? true : options.followRedirects;
|
||||
|
||||
this.sets({parameters: KeyValue, rest: KeyValue, headers: KeyValue}, options);
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue