refactor(接口测试): 优化导出jmx提示信息

--bug=1011534 --user=赵勇 [接口测试] github#11734接口测试》》接口自动化测试:选择某个接口,选择【更多操作》》导出》》选择导出Jmeter】格式的,系统报错 https://www.tapd.cn/55049933/s/1123148
This commit is contained in:
fit2-zhao 2022-03-22 15:04:47 +08:00 committed by fit2-zhao
parent cddfd27811
commit 5f8f1dd0ec
7 changed files with 33 additions and 18 deletions

View File

@ -348,11 +348,15 @@ public class ApiAutomationController {
@RequiresPermissions(PermissionConstants.PROJECT_API_SCENARIO_READ_EXPORT_SCENARIO)
@MsAuditLog(module = OperLogModule.API_AUTOMATION, type = OperLogConstants.EXPORT, sourceId = "#request.id", title = "#request.name", project = "#request.projectId")
public ResponseEntity<byte[]> downloadBodyFiles(@RequestBody ApiScenarioBatchRequest request) {
try {
byte[] bytes = apiAutomationService.exportZip(request);
return ResponseEntity.ok()
.contentType(MediaType.parseMediaType("application/octet-stream"))
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + "场景JMX文件集.zip")
.body(bytes);
} catch (Exception e) {
return ResponseEntity.status(509).body(e.getMessage().getBytes());
}
}
@PostMapping(value = "/export/jmx")

View File

@ -130,7 +130,8 @@ public class MsJDBCPostProcessor extends MsTestElement {
this.initDataSource();
}
if (this.dataSource == null) {
MSException.throwException("数据源为空无法执行");
String message = "数据源为空请选择数据源";
MSException.throwException(StringUtils.isNotEmpty(this.getName()) ? this.getName() + "" + message : message);
}
}
final HashTree samplerHashTree = tree.add(jdbcPostProcessor(config));
@ -241,7 +242,7 @@ public class MsJDBCPostProcessor extends MsTestElement {
private JDBCPostProcessor jdbcPostProcessor(ParameterConfig config) {
JDBCPostProcessor jdbcPostProcessor = new JDBCPostProcessor();
jdbcPostProcessor.setEnabled(this.isEnable());
jdbcPostProcessor.setName(this.getName() == null? "JDBCPostProcessor" : this.getName());
jdbcPostProcessor.setName(this.getName() == null ? "JDBCPostProcessor" : this.getName());
jdbcPostProcessor.setProperty(TestElement.TEST_CLASS, JDBCPostProcessor.class.getName());
jdbcPostProcessor.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));

View File

@ -130,7 +130,8 @@ public class MsJDBCPreProcessor extends MsTestElement {
this.initDataSource();
}
if (this.dataSource == null) {
MSException.throwException("数据源为空无法执行");
String message = "数据源为空请选择数据源";
MSException.throwException(StringUtils.isNotEmpty(this.getName()) ? this.getName() + "" + message : message);
}
}
final HashTree samplerHashTree = tree.add(jdbcPreProcessor(config));

View File

@ -10,7 +10,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import io.metersphere.api.dto.definition.parse.JMeterScriptUtil;
import io.metersphere.api.dto.definition.request.ElementUtil;
import io.metersphere.api.dto.definition.request.ParameterConfig;
import io.metersphere.api.dto.definition.request.assertions.MsAssertions;
import io.metersphere.api.dto.scenario.DatabaseConfig;
import io.metersphere.api.dto.scenario.KeyValue;
import io.metersphere.api.dto.scenario.environment.EnvironmentConfig;
@ -145,7 +144,8 @@ public class MsJDBCSampler extends MsTestElement {
envConfig = this.initDataSource();
}
if (this.dataSource == null) {
MSException.throwException("数据源为空无法执行");
String message = "数据源为空请选择数据源";
MSException.throwException(StringUtils.isNotEmpty(this.getName()) ? this.getName() + "" + message : message);
}
}
final HashTree samplerHashTree = tree.add(jdbcSampler(config));

View File

@ -822,14 +822,11 @@ public class ApiAutomationService {
}});
testPlan.getHashTree().add(group);
}
testPlan.toHashTree(jmeterHashTree, testPlan.getHashTree(), config);
} catch (Exception ex) {
LogUtil.error(ex);
MSException.throwException(ex.getMessage());
}
testPlan.toHashTree(jmeterHashTree, testPlan.getHashTree(), config);
// 检查hashTree 准确性
return testPlan.getJmx(jmeterHashTree);
}

View File

@ -328,6 +328,7 @@ import {getGraphByCondition} from "@/network/graph";
import MsTableSearchBar from "@/business/components/common/components/MsTableSearchBar";
import MsTableAdvSearchBar from "@/business/components/common/components/search/MsTableAdvSearchBar";
import ListItemDeleteConfirm from "@/business/components/common/components/ListItemDeleteConfirm";
import {Message} from "element-ui";
const requireComponent = require.context('@/business/components/xpack/', true, /\.vue$/);
const relationshipGraphDrawer = requireComponent.keys().length > 0 ? requireComponent("./graph/RelationshipGraphDrawer.vue") : {};
@ -1231,7 +1232,16 @@ export default {
link.click();
}, error => {
this.result.loading = false;
this.$error("导出JMX文件失败");
if (error.response && error.response.status === 509) {
let reader = new FileReader();
reader.onload = function (event) {
let content = reader.result;
Message.error({message: content, showClose: true});
};
reader.readAsText(error.response.data);
} else {
this.$error("导出JMX文件失败请检查是否选择环境");
}
});
},

View File

@ -554,9 +554,6 @@ export default {
mounted() {
this.$nextTick(() => {
this.addListener();
if (!this.currentScenario.name && this.$refs.refFab) {
this.$refs.refFab.openMenu();
}
});
},
directives: {OutsideClick},
@ -740,6 +737,11 @@ export default {
if (this.operatingElements && this.operatingElements.includes(item.jmeterClazz)) {
this.buttonData.push(plugin);
}
this.$nextTick(() => {
if (!this.currentScenario.name && this.$refs.refFab) {
this.$refs.refFab.openMenu();
}
});
});
}
},