Merge branch 'dev' of https://github.com/fit2cloudrd/metersphere-server into dev
This commit is contained in:
commit
cf83d9efae
|
@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.*;
|
|||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
|
@ -64,7 +65,7 @@ public class APITestController {
|
|||
}
|
||||
|
||||
@PostMapping(value = "/run")
|
||||
public void run(@RequestBody SaveAPITestRequest request) {
|
||||
apiTestService.run(request);
|
||||
public String run(@RequestBody SaveAPITestRequest request) {
|
||||
return apiTestService.run(request);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
|
|||
|
||||
queue.forEach((id, sampleResults) -> {
|
||||
TestResult testResult = new TestResult();
|
||||
testResult.setId(id);
|
||||
testResult.setTestId(id);
|
||||
testResult.setTotal(sampleResults.size());
|
||||
|
||||
// key: 场景Id
|
||||
|
@ -104,7 +104,7 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
|
|||
testResult.getScenarios().addAll(scenarios.values());
|
||||
testResult.getScenarios().sort(Comparator.comparing(ScenarioResult::getOrder));
|
||||
apiTestService.changeStatus(id, APITestStatus.Completed);
|
||||
apiReportService.save(testResult);
|
||||
apiReportService.complete(testResult);
|
||||
});
|
||||
queue.clear();
|
||||
super.teardownTest(context);
|
||||
|
|
|
@ -8,7 +8,7 @@ import java.util.List;
|
|||
@Data
|
||||
public class TestResult {
|
||||
|
||||
private String id;
|
||||
private String testId;
|
||||
|
||||
private int success = 0;
|
||||
|
||||
|
|
|
@ -5,12 +5,15 @@ import io.metersphere.api.dto.APIReportResult;
|
|||
import io.metersphere.api.dto.DeleteAPIReportRequest;
|
||||
import io.metersphere.api.dto.QueryAPIReportRequest;
|
||||
import io.metersphere.api.jmeter.TestResult;
|
||||
import io.metersphere.base.domain.ApiTest;
|
||||
import io.metersphere.base.domain.ApiTestReport;
|
||||
import io.metersphere.base.domain.ApiTestWithBLOBs;
|
||||
import io.metersphere.base.domain.ApiTestReportExample;
|
||||
import io.metersphere.base.mapper.ApiTestReportMapper;
|
||||
import io.metersphere.base.mapper.ext.ExtApiTestReportMapper;
|
||||
import io.metersphere.commons.constants.APITestStatus;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.dto.DashboardTestDTO;
|
||||
import io.metersphere.i18n.Translator;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
@ -25,8 +28,6 @@ import javax.annotation.Resource;
|
|||
@Transactional(rollbackFor = Exception.class)
|
||||
public class APIReportService {
|
||||
|
||||
@Resource
|
||||
private APITestService apiTestService;
|
||||
@Resource
|
||||
private ApiTestReportMapper apiTestReportMapper;
|
||||
@Resource
|
||||
|
@ -52,24 +53,58 @@ public class APIReportService {
|
|||
apiTestReportMapper.deleteByPrimaryKey(request.getId());
|
||||
}
|
||||
|
||||
public void save(TestResult result) {
|
||||
ApiTestWithBLOBs test = apiTestService.get(result.getId());
|
||||
ApiTestReport report = new ApiTestReport();
|
||||
report.setId(UUID.randomUUID().toString());
|
||||
report.setTestId(result.getId());
|
||||
report.setName(test.getName());
|
||||
report.setDescription(test.getDescription());
|
||||
report.setContent(JSONObject.toJSONString(result));
|
||||
report.setCreateTime(System.currentTimeMillis());
|
||||
report.setUpdateTime(System.currentTimeMillis());
|
||||
report.setStatus(APITestStatus.Completed.name());
|
||||
apiTestReportMapper.insert(report);
|
||||
public void deleteByTestId(String testId) {
|
||||
ApiTestReportExample example = new ApiTestReportExample();
|
||||
example.createCriteria().andTestIdEqualTo(testId);
|
||||
apiTestReportMapper.deleteByExample(example);
|
||||
}
|
||||
|
||||
public void complete(TestResult result) {
|
||||
ApiTestReport report = getRunningReport(result.getTestId());
|
||||
if (report == null) {
|
||||
MSException.throwException(Translator.get("api_report_is_null"));
|
||||
}
|
||||
report.setContent(JSONObject.toJSONString(result));
|
||||
report.setUpdateTime(System.currentTimeMillis());
|
||||
report.setStatus(APITestStatus.Completed.name());
|
||||
apiTestReportMapper.updateByPrimaryKeySelective(report);
|
||||
}
|
||||
|
||||
public String create(ApiTest test) {
|
||||
ApiTestReport running = getRunningReport(test.getId());
|
||||
if (running != null) {
|
||||
return running.getId();
|
||||
}
|
||||
|
||||
ApiTestReport report = new ApiTestReport();
|
||||
report.setId(UUID.randomUUID().toString());
|
||||
report.setTestId(test.getId());
|
||||
report.setName(test.getName());
|
||||
report.setDescription(test.getDescription());
|
||||
report.setCreateTime(System.currentTimeMillis());
|
||||
report.setUpdateTime(System.currentTimeMillis());
|
||||
report.setStatus(APITestStatus.Running.name());
|
||||
apiTestReportMapper.insert(report);
|
||||
|
||||
return report.getId();
|
||||
}
|
||||
|
||||
public ApiTestReport getRunningReport(String testId) {
|
||||
ApiTestReportExample example = new ApiTestReportExample();
|
||||
example.createCriteria().andTestIdEqualTo(testId).andStatusEqualTo(APITestStatus.Running.name());
|
||||
List<ApiTestReport> apiTestReports = apiTestReportMapper.selectByExample(example);
|
||||
if (apiTestReports.size() > 0) {
|
||||
return apiTestReports.get(0);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public List<DashboardTestDTO> dashboardTests(String workspaceId) {
|
||||
Instant oneYearAgo = Instant.now().plus(-365, ChronoUnit.DAYS);
|
||||
long startTimestamp = oneYearAgo.toEpochMilli();
|
||||
return extApiTestReportMapper.selectDashboardTests(workspaceId, startTimestamp);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -39,6 +39,8 @@ public class APITestService {
|
|||
private FileService fileService;
|
||||
@Resource
|
||||
private JMeterService jMeterService;
|
||||
@Resource
|
||||
private APIReportService apiReportService;
|
||||
|
||||
public List<APITestResult> list(QueryAPITestRequest request) {
|
||||
return extApiTestMapper.list(request);
|
||||
|
@ -71,18 +73,23 @@ public class APITestService {
|
|||
|
||||
public void delete(DeleteAPITestRequest request) {
|
||||
deleteFileByTestId(request.getId());
|
||||
apiReportService.deleteByTestId(request.getId());
|
||||
apiTestMapper.deleteByPrimaryKey(request.getId());
|
||||
}
|
||||
|
||||
public void run(SaveAPITestRequest request) {
|
||||
public String run(SaveAPITestRequest request) {
|
||||
ApiTestFile file = getFileByTestId(request.getId());
|
||||
if (file == null) {
|
||||
MSException.throwException(Translator.get("file_cannot_be_null"));
|
||||
}
|
||||
byte[] bytes = fileService.loadFileAsBytes(file.getFileId());
|
||||
InputStream is = new ByteArrayInputStream(bytes);
|
||||
|
||||
String reportId = apiReportService.create(get(request.getId()));
|
||||
changeStatus(request.getId(), APITestStatus.Running);
|
||||
|
||||
jMeterService.run(is);
|
||||
return reportId;
|
||||
}
|
||||
|
||||
public void changeStatus(String id, APITestStatus status) {
|
||||
|
|
|
@ -78,6 +78,9 @@ public class UserService {
|
|||
userRole.setSourceId("adminSourceId");
|
||||
userRoleMapper.insertSelective(userRole);
|
||||
} else {
|
||||
// if (!map.keySet().contains("Ids")) {
|
||||
// MSException.throwException(role + " no source id");
|
||||
// }
|
||||
List<String> list = (List<String>) map.get("Ids");
|
||||
for (int j = 0; j < list.size(); j++) {
|
||||
UserRole userRole1 = new UserRole();
|
||||
|
@ -316,7 +319,7 @@ public class UserService {
|
|||
|
||||
public void setLanguage(String lang) {
|
||||
if (SessionUtils.getUser() != null) {
|
||||
UserRequest user = new UserRequest();
|
||||
User user = new User();
|
||||
user.setId(SessionUtils.getUser().getId());
|
||||
user.setLanguage(lang);
|
||||
updateUser(user);
|
||||
|
|
|
@ -5,7 +5,7 @@ CREATE TABLE IF NOT EXISTS `file_content` (
|
|||
)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARSET = utf8mb4
|
||||
COLLATE = utf8mb4_bin;
|
||||
COLLATE = utf8mb4_general_ci;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `file_metadata` (
|
||||
`id` varchar(64) NOT NULL COMMENT 'File ID',
|
||||
|
@ -18,7 +18,7 @@ CREATE TABLE IF NOT EXISTS `file_metadata` (
|
|||
)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARSET = utf8mb4
|
||||
COLLATE = utf8mb4_bin;
|
||||
COLLATE = utf8mb4_general_ci;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `load_test` (
|
||||
`id` varchar(50) NOT NULL COMMENT 'Test ID',
|
||||
|
@ -36,7 +36,7 @@ CREATE TABLE IF NOT EXISTS `load_test` (
|
|||
)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARSET = utf8mb4
|
||||
COLLATE = utf8mb4_bin;
|
||||
COLLATE = utf8mb4_general_ci;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `load_test_file` (
|
||||
`test_id` varchar(64) DEFAULT NULL,
|
||||
|
@ -58,14 +58,14 @@ CREATE TABLE IF NOT EXISTS `load_test_report` (
|
|||
)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARSET = utf8mb4
|
||||
COLLATE = utf8mb4_bin;
|
||||
COLLATE = utf8mb4_general_ci;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `load_test_report_detail` (
|
||||
`report_id` varchar(50) NOT NULL,
|
||||
`content` longtext,
|
||||
`part` bigint(11) NOT NULL,
|
||||
PRIMARY KEY (`report_id`,`part`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `load_test_report_log` (
|
||||
`id` varchar(50) NOT NULL,
|
||||
|
@ -75,7 +75,7 @@ CREATE TABLE IF NOT EXISTS `load_test_report_log` (
|
|||
`part` bigint(20) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `load_test_report_log_report_id_resource_name_index` (`report_id`,`resource_id`,`part`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ;
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `load_test_report_result` (
|
||||
`id` varchar(50) NOT NULL,
|
||||
|
@ -84,7 +84,7 @@ CREATE TABLE IF NOT EXISTS `load_test_report_result` (
|
|||
`report_value` text ,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `load_test_report_result_report_id_report_key_index` (`report_id`,`report_key`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `organization` (
|
||||
|
@ -97,7 +97,7 @@ CREATE TABLE IF NOT EXISTS `organization` (
|
|||
)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARSET = utf8mb4
|
||||
COLLATE = utf8mb4_bin;
|
||||
COLLATE = utf8mb4_general_ci;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `project` (
|
||||
`id` varchar(50) NOT NULL COMMENT 'Project ID',
|
||||
|
@ -110,7 +110,7 @@ CREATE TABLE IF NOT EXISTS `project` (
|
|||
)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARSET = utf8mb4
|
||||
COLLATE = utf8mb4_bin;
|
||||
COLLATE = utf8mb4_general_ci;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `role` (
|
||||
`id` varchar(50) NOT NULL COMMENT 'Role ID',
|
||||
|
@ -123,7 +123,7 @@ CREATE TABLE IF NOT EXISTS `role` (
|
|||
)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARSET = utf8mb4
|
||||
COLLATE = utf8mb4_bin;
|
||||
COLLATE = utf8mb4_general_ci;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `system_parameter` (
|
||||
`param_key` varchar(64) CHARACTER SET utf8mb4 NOT NULL COMMENT 'Parameter name',
|
||||
|
@ -134,7 +134,7 @@ CREATE TABLE IF NOT EXISTS `system_parameter` (
|
|||
)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARSET = utf8mb4
|
||||
COLLATE = utf8mb4_bin;
|
||||
COLLATE = utf8mb4_general_ci;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `test_resource` (
|
||||
`id` varchar(50) NOT NULL COMMENT 'Test resource ID',
|
||||
|
@ -147,7 +147,7 @@ CREATE TABLE IF NOT EXISTS `test_resource` (
|
|||
)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARSET = utf8mb4
|
||||
COLLATE = utf8mb4_bin;
|
||||
COLLATE = utf8mb4_general_ci;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `test_resource_pool` (
|
||||
`id` varchar(50) NOT NULL COMMENT 'Test resource pool ID',
|
||||
|
@ -161,13 +161,13 @@ CREATE TABLE IF NOT EXISTS `test_resource_pool` (
|
|||
)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARSET = utf8mb4
|
||||
COLLATE = utf8mb4_bin;
|
||||
COLLATE = utf8mb4_general_ci;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `user` (
|
||||
`id` varchar(50) NOT NULL COMMENT 'User ID',
|
||||
`id` varchar(50) COLLATE utf8mb4_bin NOT NULL COMMENT 'User ID',
|
||||
`name` varchar(64) NOT NULL COMMENT 'User name',
|
||||
`email` varchar(64) NOT NULL COMMENT 'E-Mail address',
|
||||
`password` varchar(256) DEFAULT NULL,
|
||||
`password` varchar(256) COLLATE utf8mb4_bin DEFAULT NULL,
|
||||
`status` varchar(50) NOT NULL COMMENT 'User status',
|
||||
`create_time` bigint(13) NOT NULL COMMENT 'Create timestamp',
|
||||
`update_time` bigint(13) NOT NULL COMMENT 'Update timestamp',
|
||||
|
@ -179,7 +179,7 @@ CREATE TABLE IF NOT EXISTS `user` (
|
|||
)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARSET = utf8mb4
|
||||
COLLATE = utf8mb4_bin;
|
||||
COLLATE = utf8mb4_general_ci;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `user_role` (
|
||||
`id` varchar(50) NOT NULL COMMENT 'ID of user''s role info',
|
||||
|
@ -192,7 +192,7 @@ CREATE TABLE IF NOT EXISTS `user_role` (
|
|||
)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARSET = utf8mb4
|
||||
COLLATE = utf8mb4_bin;
|
||||
COLLATE = utf8mb4_general_ci;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `workspace` (
|
||||
`id` varchar(50) NOT NULL COMMENT 'Workspace ID ',
|
||||
|
@ -205,7 +205,7 @@ CREATE TABLE IF NOT EXISTS `workspace` (
|
|||
)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARSET = utf8mb4
|
||||
COLLATE = utf8mb4_bin;
|
||||
COLLATE = utf8mb4_general_ci;
|
||||
|
||||
-- api start
|
||||
|
||||
|
@ -220,7 +220,7 @@ CREATE TABLE IF NOT EXISTS `api_test` (
|
|||
`create_time` bigint(13) NOT NULL COMMENT 'Create timestamp',
|
||||
`update_time` bigint(13) NOT NULL COMMENT 'Update timestamp',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `api_test_file` (
|
||||
`test_id` varchar(64) DEFAULT NULL,
|
||||
|
@ -243,7 +243,7 @@ CREATE TABLE IF NOT EXISTS `api_test_report` (
|
|||
)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARSET = utf8mb4
|
||||
COLLATE = utf8mb4_bin;
|
||||
COLLATE = utf8mb4_general_ci;
|
||||
|
||||
-- api end
|
||||
|
||||
|
@ -268,7 +268,7 @@ CREATE TABLE IF NOT EXISTS `test_plan` (
|
|||
)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARSET = utf8mb4
|
||||
COLLATE = utf8mb4_bin;
|
||||
COLLATE = utf8mb4_general_ci;
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `test_case_node` (
|
||||
|
@ -283,7 +283,7 @@ CREATE TABLE IF NOT EXISTS `test_case_node` (
|
|||
)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARSET = utf8mb4
|
||||
COLLATE = utf8mb4_bin;
|
||||
COLLATE = utf8mb4_general_ci;
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `test_case` (
|
||||
|
@ -305,7 +305,7 @@ CREATE TABLE IF NOT EXISTS `test_case` (
|
|||
)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARSET = utf8mb4
|
||||
COLLATE = utf8mb4_bin;
|
||||
COLLATE = utf8mb4_general_ci;
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `test_plan_test_case` (
|
||||
|
@ -323,7 +323,7 @@ CREATE TABLE IF NOT EXISTS `test_plan_test_case` (
|
|||
)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARSET = utf8mb4
|
||||
COLLATE = utf8mb4_bin;
|
||||
COLLATE = utf8mb4_general_ci;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `test_case_report_template` (
|
||||
`id` varchar(50) NOT NULL,
|
||||
|
@ -334,7 +334,7 @@ CREATE TABLE IF NOT EXISTS `test_case_report_template` (
|
|||
)
|
||||
ENGINE=InnoDB
|
||||
DEFAULT CHARSET=utf8mb4
|
||||
COLLATE=utf8mb4_bin;
|
||||
COLLATE=utf8mb4_general_ci;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `test_case_report` (
|
||||
`id` varchar(50) NOT NULL,
|
||||
|
@ -346,7 +346,7 @@ CREATE TABLE IF NOT EXISTS `test_case_report` (
|
|||
)
|
||||
ENGINE=InnoDB
|
||||
DEFAULT CHARSET=utf8mb4
|
||||
COLLATE=utf8mb4_bin;
|
||||
COLLATE=utf8mb4_general_ci;
|
||||
|
||||
-- track end
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ organization_does_not_belong_to_user=The current organization does not belong to
|
|||
organization_id_is_null=Organization ID cannot be null
|
||||
#api
|
||||
api_load_script_error=Load script error
|
||||
api_report_is_null="Report is null, can't update"
|
||||
#test case
|
||||
test_case_node_level=level
|
||||
test_case_node_level_tip=The node tree maximum depth is
|
||||
|
|
|
@ -37,6 +37,7 @@ organization_does_not_belong_to_user=当前组织不属于当前用户
|
|||
organization_id_is_null=组织 ID 不能为空
|
||||
#api
|
||||
api_load_script_error=读取脚本失败
|
||||
api_report_is_null="测试报告是未生成,无法更新"
|
||||
#test case
|
||||
test_case_node_level=层
|
||||
test_case_node_level_tip=模块树最大深度为
|
||||
|
|
|
@ -37,6 +37,7 @@ organization_does_not_belong_to_user=當前組織不屬於當前用戶
|
|||
organization_id_is_null=組織 ID 不能為空
|
||||
#api
|
||||
api_load_script_error=讀取腳本失敗
|
||||
api_report_is_null="測試報告是未生成,無法更新"
|
||||
#test case
|
||||
test_case_node_level=層
|
||||
test_case_node_level_tip=模塊樹最大深度為
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
<section class="report-container" v-if="this.report.testId">
|
||||
<header class="report-header">
|
||||
<span>{{report.projectName}} / </span>
|
||||
<router-link :to="path">{{report.testName}}</router-link>
|
||||
<router-link :to="path">{{report.testName}} [{{report.createTime | timestampFormatDate}}]</router-link>
|
||||
</header>
|
||||
<main>
|
||||
<main v-if="this.isCompleted">
|
||||
<div class="scenario-chart">
|
||||
<ms-metric-chart :content="content"></ms-metric-chart>
|
||||
</div>
|
||||
|
@ -59,11 +59,17 @@
|
|||
|
||||
methods: {
|
||||
getReport() {
|
||||
this.report = {};
|
||||
this.content = {};
|
||||
if (this.reportId) {
|
||||
let url = "/api/report/get/" + this.reportId;
|
||||
this.result = this.$get(url, response => {
|
||||
this.report = response.data || {};
|
||||
this.content = JSON.parse(this.report.content);
|
||||
if (this.isCompleted) {
|
||||
this.content = JSON.parse(this.report.content);
|
||||
} else {
|
||||
setTimeout(this.getReport, 2000)
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -83,6 +89,9 @@
|
|||
},
|
||||
path() {
|
||||
return "/api/test/edit?id=" + this.report.testId;
|
||||
},
|
||||
isCompleted() {
|
||||
return "Completed" === this.report.status;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,8 +96,8 @@
|
|||
show: false
|
||||
},
|
||||
data: [
|
||||
{value: this.content.success, name: this.$t('api_report.success')},
|
||||
{value: this.content.error, name: this.$t('api_report.fail')},
|
||||
{value: this.content.success},
|
||||
{value: this.content.error},
|
||||
]
|
||||
}
|
||||
]
|
||||
|
|
|
@ -120,8 +120,11 @@
|
|||
})
|
||||
},
|
||||
runTest: function () {
|
||||
this.result = this.$post("/api/run", {id: this.test.id}, () => {
|
||||
this.result = this.$post("/api/run", {id: this.test.id}, (response) => {
|
||||
this.$success(this.$t('api_test.running'));
|
||||
this.$router.push({
|
||||
path: '/api/report/view/' + response.data
|
||||
})
|
||||
});
|
||||
},
|
||||
saveRunTest: function () {
|
||||
|
|
|
@ -1,38 +1,44 @@
|
|||
<template>
|
||||
<div class="request-container">
|
||||
<div class="request-item" v-for="(request, index) in requests" :key="index" @click="select(request)"
|
||||
:class="{'selected': isSelected(request)}">
|
||||
<el-row type="flex">
|
||||
<div class="request-method">
|
||||
{{request.method}}
|
||||
</div>
|
||||
<div class="request-name">
|
||||
{{request.name}}
|
||||
</div>
|
||||
<div class="request-btn">
|
||||
<el-dropdown trigger="click" @command="handleCommand">
|
||||
<span class="el-dropdown-link el-icon-more"/>
|
||||
<el-dropdown-menu slot="dropdown">
|
||||
<el-dropdown-item :command="{type: 'copy', index: index}">
|
||||
{{$t('api_test.request.copy')}}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item :command="{type: 'delete', index: index}">
|
||||
{{$t('api_test.request.delete')}}
|
||||
</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</el-dropdown>
|
||||
</div>
|
||||
</el-row>
|
||||
</div>
|
||||
<draggable :list="requests" group="Request" class="request-draggable" ghost-class="request-ghost">
|
||||
<div class="request-item" v-for="(request, index) in requests" :key="index" @click="select(request)"
|
||||
:class="{'selected': isSelected(request)}">
|
||||
<el-row type="flex">
|
||||
<div class="request-method">
|
||||
{{request.method}}
|
||||
</div>
|
||||
<div class="request-name">
|
||||
{{request.name}}
|
||||
</div>
|
||||
<div class="request-btn">
|
||||
<el-dropdown trigger="click" @command="handleCommand">
|
||||
<span class="el-dropdown-link el-icon-more"/>
|
||||
<el-dropdown-menu slot="dropdown">
|
||||
<el-dropdown-item :command="{type: 'copy', index: index}">
|
||||
{{$t('api_test.request.copy')}}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item :command="{type: 'delete', index: index}">
|
||||
{{$t('api_test.request.delete')}}
|
||||
</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</el-dropdown>
|
||||
</div>
|
||||
</el-row>
|
||||
</div>
|
||||
</draggable>
|
||||
<el-button class="request-create" type="primary" size="mini" icon="el-icon-plus" plain @click="createRequest"/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {Request} from "../model/ScenarioModel";
|
||||
import draggable from 'vuedraggable';
|
||||
|
||||
export default {
|
||||
name: "MsApiRequestConfig",
|
||||
|
||||
components: {draggable},
|
||||
|
||||
props: {
|
||||
requests: Array,
|
||||
open: Function
|
||||
|
@ -136,4 +142,9 @@
|
|||
.request-create {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.request-ghost {
|
||||
opacity: 0.5;
|
||||
background-color: #909399;
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -3,29 +3,31 @@
|
|||
<el-aside class="scenario-aside">
|
||||
<div class="scenario-list">
|
||||
<ms-api-collapse v-model="activeName" @change="handleChange" accordion>
|
||||
<ms-api-collapse-item v-for="(scenario, index) in scenarios" :key="index"
|
||||
:title="scenario.name" :name="index">
|
||||
<template slot="title">
|
||||
<div class="scenario-name">
|
||||
{{scenario.name}}
|
||||
<span id="hint" v-if="!scenario.name">
|
||||
<draggable :list="scenarios" group="Scenario" class="scenario-draggable" ghost-class="scenario-ghost">
|
||||
<ms-api-collapse-item v-for="(scenario, index) in scenarios" :key="index"
|
||||
:title="scenario.name" :name="index">
|
||||
<template slot="title">
|
||||
<div class="scenario-name">
|
||||
{{scenario.name}}
|
||||
<span id="hint" v-if="!scenario.name">
|
||||
{{$t('api_test.scenario.config')}}
|
||||
</span>
|
||||
</div>
|
||||
<el-dropdown trigger="click" @command="handleCommand">
|
||||
<span class="el-dropdown-link el-icon-more scenario-btn"/>
|
||||
<el-dropdown-menu slot="dropdown">
|
||||
<el-dropdown-item :command="{type: 'copy', index: index}">
|
||||
{{$t('api_test.scenario.copy')}}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item :command="{type:'delete', index:index}">
|
||||
{{$t('api_test.scenario.delete')}}
|
||||
</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</el-dropdown>
|
||||
</template>
|
||||
<ms-api-request-config :requests="scenario.requests" :open="select"/>
|
||||
</ms-api-collapse-item>
|
||||
</div>
|
||||
<el-dropdown trigger="click" @command="handleCommand">
|
||||
<span class="el-dropdown-link el-icon-more scenario-btn"/>
|
||||
<el-dropdown-menu slot="dropdown">
|
||||
<el-dropdown-item :command="{type: 'copy', index: index}">
|
||||
{{$t('api_test.scenario.copy')}}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item :command="{type:'delete', index:index}">
|
||||
{{$t('api_test.scenario.delete')}}
|
||||
</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</el-dropdown>
|
||||
</template>
|
||||
<ms-api-request-config :requests="scenario.requests" :open="select"/>
|
||||
</ms-api-collapse-item>
|
||||
</draggable>
|
||||
</ms-api-collapse>
|
||||
</div>
|
||||
<el-button class="scenario-create" type="primary" size="mini" icon="el-icon-plus" plain @click="createScenario"/>
|
||||
|
@ -48,6 +50,7 @@
|
|||
import MsApiRequestForm from "./ApiRequestForm";
|
||||
import MsApiScenarioForm from "./ApiScenarioForm";
|
||||
import {Scenario, Request} from "../model/ScenarioModel";
|
||||
import draggable from 'vuedraggable';
|
||||
|
||||
export default {
|
||||
name: "MsApiScenarioConfig",
|
||||
|
@ -57,7 +60,8 @@
|
|||
MsApiScenarioForm,
|
||||
MsApiRequestForm,
|
||||
MsApiCollapse,
|
||||
MsApiCollapseItem
|
||||
MsApiCollapseItem,
|
||||
draggable
|
||||
},
|
||||
|
||||
props: {
|
||||
|
@ -183,4 +187,12 @@
|
|||
right: 0;
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
.scenario-ghost {
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
.scenario-draggable {
|
||||
background-color: #909399;
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -39,7 +39,8 @@
|
|||
default: false
|
||||
},
|
||||
index: Number,
|
||||
list: Array
|
||||
list: Array,
|
||||
callback: Function
|
||||
},
|
||||
|
||||
data() {
|
||||
|
@ -51,6 +52,7 @@
|
|||
methods: {
|
||||
add: function () {
|
||||
this.list.push(new Regex(this.regex));
|
||||
this.callback();
|
||||
},
|
||||
remove: function () {
|
||||
this.list.splice(this.index, 1);
|
||||
|
|
|
@ -21,7 +21,8 @@
|
|||
|
||||
props: {
|
||||
edit: Boolean,
|
||||
duration: ResponseTime
|
||||
duration: ResponseTime,
|
||||
callback: Function
|
||||
},
|
||||
|
||||
data() {
|
||||
|
@ -34,6 +35,7 @@
|
|||
add: function () {
|
||||
setTimeout(() => {
|
||||
this.duration.value = this.time;
|
||||
this.callback();
|
||||
})
|
||||
},
|
||||
remove: function () {
|
||||
|
|
|
@ -37,7 +37,8 @@
|
|||
name: "MsApiAssertionText",
|
||||
|
||||
props: {
|
||||
list: Array
|
||||
list: Array,
|
||||
callback: Function
|
||||
},
|
||||
|
||||
data() {
|
||||
|
@ -52,6 +53,7 @@
|
|||
methods: {
|
||||
add: function () {
|
||||
this.list.push(this.toRegex());
|
||||
this.callback();
|
||||
},
|
||||
toRegex: function () {
|
||||
let expression = "";
|
||||
|
|
|
@ -10,9 +10,10 @@
|
|||
</el-select>
|
||||
</el-col>
|
||||
<el-col :span="20">
|
||||
<ms-api-assertion-text :list="assertions.regex" v-if="type === options.TEXT"/>
|
||||
<ms-api-assertion-regex :list="assertions.regex" v-if="type === options.REGEX"/>
|
||||
<ms-api-assertion-response-time :duration="assertions.duration" v-if="type === options.RESPONSE_TIME"/>
|
||||
<ms-api-assertion-text :list="assertions.regex" v-if="type === options.TEXT" :callback="after"/>
|
||||
<ms-api-assertion-regex :list="assertions.regex" v-if="type === options.REGEX" :callback="after"/>
|
||||
<ms-api-assertion-response-time :duration="assertions.duration" v-if="type === options.RESPONSE_TIME"
|
||||
:callback="after"/>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
|
@ -41,7 +42,14 @@
|
|||
options: ASSERTION_TYPE,
|
||||
type: "",
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
after() {
|
||||
this.type = "";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
</el-select>
|
||||
</el-col>
|
||||
<el-col :span="20">
|
||||
<ms-api-extract-common :extract-type="type" :list="list" v-if="type"/>
|
||||
<ms-api-extract-common :extract-type="type" :list="list" v-if="type" :callback="after"/>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
|
@ -45,6 +45,12 @@
|
|||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
after() {
|
||||
this.type = "";
|
||||
}
|
||||
},
|
||||
|
||||
computed: {
|
||||
list() {
|
||||
switch (this.type) {
|
||||
|
|
|
@ -41,7 +41,8 @@
|
|||
default: false
|
||||
},
|
||||
index: Number,
|
||||
list: Array
|
||||
list: Array,
|
||||
callback: Function
|
||||
},
|
||||
|
||||
data() {
|
||||
|
@ -54,6 +55,7 @@
|
|||
add() {
|
||||
this.list.push(new ExtractCommon(this.extractType, this.common));
|
||||
this.clear();
|
||||
this.callback();
|
||||
},
|
||||
change(variable) {
|
||||
this.common.value = "${" + variable + "}";
|
||||
|
|
|
@ -68,20 +68,28 @@
|
|||
<el-input v-model="form.password" autocomplete="off" show-password/>
|
||||
</el-form-item>
|
||||
<div v-for="(role, index) in form.roles" :key="index">
|
||||
<el-form-item :label="'角色'+index" :required="true">
|
||||
<el-form-item :label="'角色'+index"
|
||||
:prop="'roles.' + index + '.id'"
|
||||
:rules="{required: true, message: '请选择角色', trigger: 'change'}"
|
||||
>
|
||||
<el-select v-model="role.id" placeholder="选择角色类型">
|
||||
<el-option
|
||||
v-for="item in userRole"
|
||||
v-for="item in activeRole(role)"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.id">
|
||||
:value="item.id"
|
||||
>
|
||||
{{item.name}}
|
||||
</el-option>
|
||||
</el-select>
|
||||
<el-button @click.prevent="removeRole(role)" style="margin-left: 20px;" v-if="form.roles.length > 1">删除
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
<div v-if="role.id === 'org_admin'">
|
||||
<el-form-item label="选择组织" :required="true">
|
||||
<el-form-item label="选择组织"
|
||||
:prop="'roles.' + index + '.Ids'"
|
||||
:rules="{required: true, message: '请选择组织', trigger: 'change'}"
|
||||
>
|
||||
<el-select v-model="role.Ids" placeholder="选择组织" multiple>
|
||||
<el-option
|
||||
v-for="item in form.orgList"
|
||||
|
@ -93,7 +101,10 @@
|
|||
</el-form-item>
|
||||
</div>
|
||||
<div v-if="role.id === 'test_manager'">
|
||||
<el-form-item label="选择工作空间" :required="true">
|
||||
<el-form-item label="选择工作空间"
|
||||
:prop="'roles.' + index + '.Ids'"
|
||||
:rules="{required: true, message: '请选择工作空间', trigger: 'change'}"
|
||||
>
|
||||
<el-select v-model="role.Ids" placeholder="选择工作空间" multiple>
|
||||
<el-option
|
||||
v-for="item in form.wsList"
|
||||
|
@ -105,7 +116,10 @@
|
|||
</el-form-item>
|
||||
</div>
|
||||
<div v-if="role.id ==='test_user'">
|
||||
<el-form-item label="选择工作空间" :required="true">
|
||||
<el-form-item label="选择工作空间"
|
||||
:prop="'roles.' + index + '.Ids'"
|
||||
:rules="{required: true, message: '请选择工作空间', trigger: 'change'}"
|
||||
>
|
||||
<el-select v-model="role.Ids" placeholder="选择工作空间" multiple>
|
||||
<el-option
|
||||
v-for="item in form.wsList"
|
||||
|
@ -117,7 +131,10 @@
|
|||
</el-form-item>
|
||||
</div>
|
||||
<div v-if="role.id ==='test_viewer'">
|
||||
<el-form-item label="选择工作空间" :required="true">
|
||||
<el-form-item label="选择工作空间"
|
||||
:prop="'roles.' + index + '.Ids'"
|
||||
:rules="{required: true, message: '请选择工作空间', trigger: 'change'}"
|
||||
>
|
||||
<el-select v-model="role.Ids" placeholder="选择工作空间" multiple>
|
||||
<el-option
|
||||
v-for="item in form.wsList"
|
||||
|
@ -132,7 +149,7 @@
|
|||
|
||||
<el-form-item>
|
||||
<template>
|
||||
<el-button type="success" style="width: 100%;" @click="addRole()">添加角色</el-button>
|
||||
<el-button type="success" style="width: 100%;" @click="addRole('createUserForm')" :disabled="btnAddRole">添加角色</el-button>
|
||||
</template>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
@ -160,10 +177,13 @@
|
|||
<el-input v-model="form.phone" autocomplete="off"/>
|
||||
</el-form-item>
|
||||
<div v-for="(role, index) in form.roles" :key="index">
|
||||
<el-form-item :label="'角色'+index" :required="true">
|
||||
<el-form-item :label="'角色'+index"
|
||||
:prop="'roles.' + index + '.id'"
|
||||
:rules="{required: true, message: '请选择角色', trigger: 'change'}"
|
||||
>
|
||||
<el-select v-model="role.id" placeholder="选择角色类型">
|
||||
<el-option
|
||||
v-for="item in userRole"
|
||||
v-for="item in activeRole(role)"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.id">
|
||||
|
@ -173,7 +193,10 @@
|
|||
</el-button>
|
||||
</el-form-item>
|
||||
<div v-if="role.id === 'org_admin'">
|
||||
<el-form-item label="选择组织" :required="true">
|
||||
<el-form-item label="选择组织"
|
||||
:prop="'roles.' + index + '.Ids'"
|
||||
:rules="{required: true, message: '请选择组织', trigger: 'change'}"
|
||||
>
|
||||
<el-select v-model="role.Ids" placeholder="选择组织" multiple>
|
||||
<el-option
|
||||
v-for="item in form.orgList"
|
||||
|
@ -185,7 +208,10 @@
|
|||
</el-form-item>
|
||||
</div>
|
||||
<div v-if="role.id === 'test_manager'">
|
||||
<el-form-item label="选择工作空间" :required="true">
|
||||
<el-form-item label="选择工作空间"
|
||||
:prop="'roles.' + index + '.Ids'"
|
||||
:rules="{required: true, message: '请选择工作空间', trigger: 'change'}"
|
||||
>
|
||||
<el-select v-model="role.Ids" placeholder="选择工作空间" multiple>
|
||||
<el-option
|
||||
v-for="item in form.wsList"
|
||||
|
@ -197,7 +223,10 @@
|
|||
</el-form-item>
|
||||
</div>
|
||||
<div v-if="role.id ==='test_user'">
|
||||
<el-form-item label="选择工作空间" :required="true">
|
||||
<el-form-item label="选择工作空间"
|
||||
:prop="'roles.' + index + '.Ids'"
|
||||
:rules="{required: true, message: '请选择工作空间', trigger: 'change'}"
|
||||
>
|
||||
<el-select v-model="role.Ids" placeholder="选择工作空间" multiple>
|
||||
<el-option
|
||||
v-for="item in form.wsList"
|
||||
|
@ -209,7 +238,10 @@
|
|||
</el-form-item>
|
||||
</div>
|
||||
<div v-if="role.id ==='test_viewer'">
|
||||
<el-form-item label="选择工作空间" :required="true">
|
||||
<el-form-item label="选择工作空间"
|
||||
:prop="'roles.' + index + '.Ids'"
|
||||
:rules="{required: true, message: '请选择工作空间', trigger: 'change'}"
|
||||
>
|
||||
<el-select v-model="role.Ids" placeholder="选择工作空间" multiple>
|
||||
<el-option
|
||||
v-for="item in form.wsList"
|
||||
|
@ -223,7 +255,7 @@
|
|||
</div>
|
||||
<el-form-item>
|
||||
<template>
|
||||
<el-button type="success" style="width: 100%;" @click="addRole()">添加角色</el-button>
|
||||
<el-button type="success" style="width: 100%;" @click="addRole('updateUserForm')" :disabled="btnAddRole">添加角色</el-button>
|
||||
</template>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
@ -286,6 +318,7 @@
|
|||
createVisible: false,
|
||||
updateVisible: false,
|
||||
editPasswordVisible: false,
|
||||
btnAddRole: false,
|
||||
multipleSelection: [],
|
||||
userRole: [],
|
||||
currentPage: 1,
|
||||
|
@ -294,11 +327,12 @@
|
|||
condition: {},
|
||||
tableData: [],
|
||||
form: {
|
||||
roles: [{}]
|
||||
roles: [{
|
||||
id: ''
|
||||
}]
|
||||
},
|
||||
checkPasswordForm: {},
|
||||
ruleForm: {},
|
||||
setAdminParam: {},
|
||||
rule: {
|
||||
id: [
|
||||
{required: true, message: this.$t('user.input_id'), trigger: 'blur'},
|
||||
|
@ -451,7 +485,8 @@
|
|||
})
|
||||
},
|
||||
handleClose() {
|
||||
this.form = {roles: [{value: ''}]};
|
||||
this.form = {roles: [{id: ''}]};
|
||||
this.btnAddRole = false;
|
||||
},
|
||||
changeSwitch(row) {
|
||||
this.$post(this.updatePath, row, () => {
|
||||
|
@ -479,16 +514,51 @@
|
|||
this.userRole = response.data;
|
||||
})
|
||||
},
|
||||
addRole() {
|
||||
let roles = this.form.roles;
|
||||
roles.push({});
|
||||
addRole(validForm) {
|
||||
this.$refs[validForm].validate(valid => {
|
||||
if (valid) {
|
||||
let roleInfo = {};
|
||||
roleInfo.selects = [];
|
||||
let ids = this.form.roles.map(r => r.id);
|
||||
ids.forEach(id => {
|
||||
roleInfo.selects.push(id);
|
||||
})
|
||||
let roles = this.form.roles;
|
||||
roles.push(roleInfo);
|
||||
if (this.form.roles.length > this.userRole.length - 1) {
|
||||
this.btnAddRole = true;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
})
|
||||
},
|
||||
removeRole(item) {
|
||||
let index = this.form.roles.indexOf(item)
|
||||
let index = this.form.roles.indexOf(item);
|
||||
if (index !== -1) {
|
||||
this.form.roles.splice(index, 1)
|
||||
}
|
||||
if (this.form.roles.length < this.userRole.length) {
|
||||
this.btnAddRole = false;
|
||||
}
|
||||
},
|
||||
activeRole(roleInfo) {
|
||||
return this.userRole.filter(function (role) {
|
||||
let value = true;
|
||||
if (!roleInfo.selects) {
|
||||
return true;
|
||||
}
|
||||
if (roleInfo.selects.length === 0) {
|
||||
value = true;
|
||||
}
|
||||
for (let i = 0; i < roleInfo.selects.length; i++) {
|
||||
if (role.id === roleInfo.selects[i]) {
|
||||
value = false;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
Loading…
Reference in New Issue