feat: 接口调试部分代码
This commit is contained in:
parent
9b294a00f8
commit
683fed8ec9
|
@ -49,7 +49,6 @@ public class APITestController {
|
|||
return apiTestService.getApiTestByProjectId(projectId);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping(value = "/schedule/update")
|
||||
public void updateSchedule(@RequestBody Schedule request) {
|
||||
apiTestService.updateSchedule(request);
|
||||
|
@ -90,6 +89,11 @@ public class APITestController {
|
|||
return apiTestService.run(request);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/run/independent", consumes = {"multipart/form-data"})
|
||||
public String runIndependent(@RequestBody SaveAPITestRequest request, @RequestPart(value = "files") List<MultipartFile> files) {
|
||||
return apiTestService.runIndependent(request, files);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/import", consumes = {"multipart/form-data"})
|
||||
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
|
||||
public ApiTest testCaseImport(@RequestPart(value = "file", required = false) MultipartFile file, @RequestPart("request") ApiTestImportRequest request) {
|
||||
|
|
|
@ -101,7 +101,12 @@ public class APIReportService {
|
|||
if (running != null) {
|
||||
return running.getId();
|
||||
}
|
||||
ApiTestReport report = buildReport(test, triggerMode, APITestStatus.Running.name());
|
||||
apiTestReportMapper.insert(report);
|
||||
return report.getId();
|
||||
}
|
||||
|
||||
public ApiTestReport buildReport(ApiTest test, String triggerMode, String status) {
|
||||
ApiTestReport report = new ApiTestReport();
|
||||
report.setId(UUID.randomUUID().toString());
|
||||
report.setTestId(test.getId());
|
||||
|
@ -110,11 +115,9 @@ public class APIReportService {
|
|||
report.setDescription(test.getDescription());
|
||||
report.setCreateTime(System.currentTimeMillis());
|
||||
report.setUpdateTime(System.currentTimeMillis());
|
||||
report.setStatus(APITestStatus.Running.name());
|
||||
report.setStatus(status);
|
||||
report.setUserId(test.getUserId());
|
||||
apiTestReportMapper.insert(report);
|
||||
|
||||
return report.getId();
|
||||
return report;
|
||||
}
|
||||
|
||||
public ApiTestReport getRunningReport(String testId) {
|
||||
|
|
|
@ -37,6 +37,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -328,4 +329,29 @@ public class APITestService {
|
|||
}
|
||||
return schedules;
|
||||
}
|
||||
|
||||
public String runIndependent(SaveAPITestRequest request, List<MultipartFile> files) {
|
||||
if (files == null || files.isEmpty()) {
|
||||
throw new IllegalArgumentException(Translator.get("file_cannot_be_null"));
|
||||
}
|
||||
// ApiTest test = createTest(request);
|
||||
// saveFile(test.getId(), files);
|
||||
MultipartFile file = files.get(0);
|
||||
InputStream is = null;
|
||||
try {
|
||||
is = new ByteArrayInputStream(file.getBytes());
|
||||
} catch (IOException e) {
|
||||
LogUtil.error(e);
|
||||
}
|
||||
|
||||
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(), is);
|
||||
return reportId;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<template>
|
||||
<el-card>
|
||||
<el-card class="scenario-results">
|
||||
<div class="scenario-header">
|
||||
<el-row :gutter="10">
|
||||
<el-col :span="16">
|
||||
|
|
|
@ -1,15 +1,19 @@
|
|||
<template>
|
||||
<div>
|
||||
<component :is="component" :is-read-only="isReadOnly" :request="request"/>
|
||||
<!-- <ms-scenario-results :scenarios="content.scenarios"/>-->
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {Request, RequestFactory} from "../../model/ScenarioModel";
|
||||
import MsApiHttpRequestForm from "./ApiHttpRequestForm";
|
||||
import MsApiDubboRequestForm from "./ApiDubboRequestForm";
|
||||
import MsScenarioResults from "../../../report/components/ScenarioResults";
|
||||
|
||||
export default {
|
||||
name: "MsApiRequestForm",
|
||||
components: {MsApiDubboRequestForm, MsApiHttpRequestForm},
|
||||
components: {MsScenarioResults, MsApiDubboRequestForm, MsApiHttpRequestForm},
|
||||
props: {
|
||||
request: Request,
|
||||
isReadOnly: {
|
||||
|
@ -17,6 +21,12 @@
|
|||
default: false
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
reportId: "",
|
||||
content:{}
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
component({request: {type}}) {
|
||||
let name;
|
||||
|
@ -29,10 +39,46 @@
|
|||
}
|
||||
return name;
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.getReport();
|
||||
},
|
||||
methods: {
|
||||
getReport() {
|
||||
// // this.reportId = "00143d36-a58a-477e-a05a-556c1d48046c";
|
||||
// if (this.reportId) {
|
||||
// let url = "/api/report/get/" + this.reportId;
|
||||
// this.$get(url, response => {
|
||||
// let report = response.data || {};
|
||||
// if (response.data) {
|
||||
// // if (this.isNotRunning) {
|
||||
// try {
|
||||
// this.content = JSON.parse(report.content);
|
||||
// } catch (e) {
|
||||
// console.log(report.content)
|
||||
// throw e;
|
||||
// }
|
||||
// // this.getFails();
|
||||
// // this.loading = false;
|
||||
// // }
|
||||
// // else {
|
||||
// // setTimeout(this.getReport, 2000)
|
||||
// // }
|
||||
// } else {
|
||||
// this.loading = false;
|
||||
// this.$error(this.$t('api_report.not_exist'));
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
.scenario-results {
|
||||
margin-top: 15px;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
|
Loading…
Reference in New Issue