From 2ba69e9a32aba78d2dd41b7d6e85c9ed3db36d8f Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Wed, 25 Nov 2020 18:52:33 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=8E=A5=E5=8F=A3=E5=AE=9A=E4=B9=89):=20?= =?UTF-8?q?=E5=AE=8C=E6=88=90JDBC=E5=BF=AB=E6=8D=B7=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../request/sampler/MsJDBCSampler.java | 64 ++++----- .../api/definition/components/Run.vue | 1 - .../components/debug/DebugJdbcPage.vue | 41 +----- .../request/database/BasisParameters.vue | 14 +- .../components/response/RequestResultTail.vue | 3 +- .../components/response/ResponseResult.vue | 19 ++- .../components/response/SqlResultTable.vue | 121 ++++++++++++++++++ 7 files changed, 190 insertions(+), 73 deletions(-) create mode 100644 frontend/src/business/components/api/definition/components/response/SqlResultTable.vue diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java index a140c867e1..c37cc2a3c0 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java @@ -14,7 +14,6 @@ import org.apache.jmeter.protocol.jdbc.sampler.JDBCSampler; import org.apache.jmeter.save.SaveService; import org.apache.jmeter.testelement.TestElement; import org.apache.jorphan.collections.HashTree; -import org.apache.jorphan.collections.ListedHashTree; import java.util.List; @@ -40,10 +39,9 @@ public class MsJDBCSampler extends MsTestElement { private String environmentId; public void toHashTree(HashTree tree, List hashTree) { - final HashTree samplerHashTree = new ListedHashTree(); - samplerHashTree.add(jdbcDataSource()); - samplerHashTree.add(arguments(this.getName() + " Variables", this.getVariables())); - tree.set(jdbcSampler(), samplerHashTree); + final HashTree samplerHashTree = tree.add(jdbcSampler()); + tree.add(jdbcDataSource()); + tree.add(arguments(this.getName() + " Variables", this.getVariables())); if (CollectionUtils.isNotEmpty(hashTree)) { hashTree.forEach(el -> { el.toHashTree(samplerHashTree, el.getHashTree()); @@ -53,13 +51,15 @@ public class MsJDBCSampler extends MsTestElement { private Arguments arguments(String name, List variables) { Arguments arguments = new Arguments(); - arguments.setEnabled(true); - arguments.setName(name); - arguments.setProperty(TestElement.TEST_CLASS, Arguments.class.getName()); - arguments.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("ArgumentsPanel")); - variables.stream().filter(KeyValue::isValid).filter(KeyValue::isEnable).forEach(keyValue -> - arguments.addArgument(keyValue.getName(), keyValue.getValue(), "=") - ); + if (!variables.isEmpty()) { + arguments.setEnabled(true); + arguments.setName(name); + arguments.setProperty(TestElement.TEST_CLASS, Arguments.class.getName()); + arguments.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("ArgumentsPanel")); + variables.stream().filter(KeyValue::isValid).filter(KeyValue::isEnable).forEach(keyValue -> + arguments.addArgument(keyValue.getName(), keyValue.getValue(), "=") + ); + } return arguments; } @@ -69,13 +69,13 @@ public class MsJDBCSampler extends MsTestElement { sampler.setProperty(TestElement.TEST_CLASS, JDBCSampler.class.getName()); sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI")); // request.getDataSource() 是ID,需要转换为Name - sampler.setDataSource(this.dataSource.getName()); - sampler.setQuery(this.getQuery()); - sampler.setQueryTimeout(String.valueOf(this.getQueryTimeout())); - sampler.setResultVariable(this.getResultVariable()); - sampler.setVariableNames(this.getVariableNames()); - sampler.setResultSetHandler("Store as String"); - sampler.setQueryType("Callable Statement"); + sampler.setProperty("dataSource", this.dataSource.getName()); + sampler.setProperty("query", this.getQuery()); + sampler.setProperty("queryTimeout", String.valueOf(this.getQueryTimeout())); + sampler.setProperty("resultVariable", this.getResultVariable()); + sampler.setProperty("variableNames", this.getVariableNames()); + sampler.setProperty("resultSetHandler", "Store as String"); + sampler.setProperty("queryType", "Callable Statement"); return sampler; } @@ -85,19 +85,19 @@ public class MsJDBCSampler extends MsTestElement { dataSourceElement.setName(this.getName() + " JDBCDataSource"); dataSourceElement.setProperty(TestElement.TEST_CLASS, DataSourceElement.class.getName()); dataSourceElement.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI")); - dataSourceElement.setAutocommit(true); - dataSourceElement.setKeepAlive(true); - dataSourceElement.setPreinit(true); - dataSourceElement.setDataSource(dataSource.getName()); - dataSourceElement.setDbUrl(dataSource.getDbUrl()); - dataSourceElement.setDriver(dataSource.getDriver()); - dataSourceElement.setUsername(dataSource.getUsername()); - dataSourceElement.setPassword(dataSource.getPassword()); - dataSourceElement.setPoolMax(String.valueOf(dataSource.getPoolMax())); - dataSourceElement.setTimeout(String.valueOf(dataSource.getTimeout())); - dataSourceElement.setConnectionAge("5000"); - dataSourceElement.setTrimInterval("60000"); - dataSourceElement.setTransactionIsolation("DEFAULT"); + dataSourceElement.setProperty("autocommit", true); + dataSourceElement.setProperty("keepAlive", true); + dataSourceElement.setProperty("preinit", false); + dataSourceElement.setProperty("dataSource", dataSource.getName()); + dataSourceElement.setProperty("dbUrl", dataSource.getDbUrl()); + dataSourceElement.setProperty("driver", dataSource.getDriver()); + dataSourceElement.setProperty("username", dataSource.getUsername()); + dataSourceElement.setProperty("password", dataSource.getPassword()); + dataSourceElement.setProperty("poolMax", dataSource.getPoolMax()); + dataSourceElement.setProperty("timeout", String.valueOf(dataSource.getTimeout())); + dataSourceElement.setProperty("connectionAge", 5000); + dataSourceElement.setProperty("trimInterval", 6000); + dataSourceElement.setProperty("transactionIsolation", "DEFAULT"); return dataSourceElement; } } diff --git a/frontend/src/business/components/api/definition/components/Run.vue b/frontend/src/business/components/api/definition/components/Run.vue index d77f1d3e25..80d0292a58 100644 --- a/frontend/src/business/components/api/definition/components/Run.vue +++ b/frontend/src/business/components/api/definition/components/Run.vue @@ -96,7 +96,6 @@ this.runData.forEach(item => { threadGroup.hashTree.push(item); }) - console.log(testPlan) let reqObj = {id: this.reportId, testElement: testPlan}; let bodyFiles = this.getBodyUploadFiles(reqObj); let url = ""; diff --git a/frontend/src/business/components/api/definition/components/debug/DebugJdbcPage.vue b/frontend/src/business/components/api/definition/components/debug/DebugJdbcPage.vue index b3089b10fb..2743bd88ee 100644 --- a/frontend/src/business/components/api/definition/components/debug/DebugJdbcPage.vue +++ b/frontend/src/business/components/api/definition/components/debug/DebugJdbcPage.vue @@ -12,12 +12,12 @@

{{$t('api_test.definition.request.req_param')}}

- +

{{$t('api_test.definition.request.res_param')}}

- + @@ -64,20 +64,7 @@ } }, created() { - switch (this.currentProtocol) { - case Request.TYPES.SQL: - this.request = createComponent("JDBCSampler"); - break; - case Request.TYPES.DUBBO: - this.request = createComponent("JDBCSampler"); - break; - case Request.TYPES.TCP: - this.request = createComponent("TCPSampler"); - break; - default: - this.createHttp(); - break; - } + this.request = createComponent("JDBCSampler"); }, watch: { debugResultId() { @@ -89,14 +76,10 @@ if (e === "save_as") { this.saveAs(); } else { - this.runDebug(); + this.$refs['requestForm'].validate(); } }, - createHttp() { - let header = createComponent("HeaderManager"); - this.request = createComponent("HTTPSamplerProxy"); - this.request.hashTree = [header]; - }, + runDebug() { this.loading = true; this.request.name = getUUID().substring(0, 8); @@ -111,18 +94,8 @@ this.$refs.debugResult.reload(); }, saveAs() { - this.$refs['debugForm'].validate((valid) => { - if (valid) { - this.debugForm.request = JSON.stringify(this.request); - this.debugForm.userId = getCurrentUser().id; - this.debugForm.status = "Underway"; - this.debugForm.protocol = this.currentProtocol; - this.$emit('saveAs', this.debugForm); - } - else { - return false; - } - }) + let obj = {request: JSON.stringify(this.request)}; + this.$emit('saveAs', obj); } } } diff --git a/frontend/src/business/components/api/definition/components/request/database/BasisParameters.vue b/frontend/src/business/components/api/definition/components/request/database/BasisParameters.vue index 48d13b2f95..cd31818877 100644 --- a/frontend/src/business/components/api/definition/components/request/database/BasisParameters.vue +++ b/frontend/src/business/components/api/definition/components/request/database/BasisParameters.vue @@ -3,7 +3,7 @@
- + @@ -131,6 +131,10 @@ databaseConfigsOptions: [], isReloadData: false, activeName: "variables", + rules: { + environmentId: [{required: true, message: this.$t('test_track.case.input_maintainer'), trigger: 'change'}], + dataSource: [{required: true, message: this.$t('api_test.request.sql.dataSource'), trigger: 'change'}], + }, } }, created() { @@ -168,12 +172,16 @@ this.isReloadData = false }) }, - validateApi() { + validate() { if (this.currentProject === null) { this.$error(this.$t('api_test.select_project'), 2000); return; } - this.$refs['basicForm'].validate(); + this.$refs['request'].validate((valid) => { + if (valid) { + this.$emit('callback'); + } + }) }, saveApi() { this.basisData.method = this.basisData.protocol; diff --git a/frontend/src/business/components/api/definition/components/response/RequestResultTail.vue b/frontend/src/business/components/api/definition/components/response/RequestResultTail.vue index 9fdc9debaf..4e411e5d34 100644 --- a/frontend/src/business/components/api/definition/components/response/RequestResultTail.vue +++ b/frontend/src/business/components/api/definition/components/response/RequestResultTail.vue @@ -1,7 +1,7 @@ @@ -14,6 +14,7 @@ components: {MsRequestMetric, MsResponseResult}, props: { response: Object, + currentProtocol: String, }, data() { diff --git a/frontend/src/business/components/api/definition/components/response/ResponseResult.vue b/frontend/src/business/components/api/definition/components/response/ResponseResult.vue index ef13553503..8a0a36c8e9 100644 --- a/frontend/src/business/components/api/definition/components/response/ResponseResult.vue +++ b/frontend/src/business/components/api/definition/components/response/ResponseResult.vue @@ -6,7 +6,8 @@
{{ response.responseResult.headers }}
- + +
{{response.cookies}}
@@ -27,7 +28,9 @@ @@ -39,6 +42,7 @@ import MsCodeEdit from "../MsCodeEdit"; import MsDropdown from "../../../../common/components/MsDropdown"; import {BODY_FORMAT} from "../../model/ApiTestModel"; + import MsSqlResultTable from "./SqlResultTable"; export default { name: "MsResponseResult", @@ -47,10 +51,12 @@ MsDropdown, MsCodeEdit, MsAssertionResults, + MsSqlResultTable }, props: { response: Object, + currentProtocol: String, }, data() { @@ -58,12 +64,16 @@ isActive: true, activeName: "headers", modes: ['text', 'json', 'xml', 'html'], + sqlModes: ['text', 'table'], mode: BODY_FORMAT.TEXT } }, methods: { modeChange(mode) { this.mode = mode; + }, + sqlModeChange(mode) { + this.mode = mode; } }, mounted() { @@ -73,6 +83,11 @@ if (this.response.headers.indexOf("Content-Type: application/json") > 0) { this.mode = BODY_FORMAT.JSON; } + }, + computed: { + isSqlType() { + return (this.currentProtocol === "SQL" && this.response.responseResult.responseCode === '200' && this.mode ==='table'); + } } } diff --git a/frontend/src/business/components/api/definition/components/response/SqlResultTable.vue b/frontend/src/business/components/api/definition/components/response/SqlResultTable.vue new file mode 100644 index 0000000000..5406710eef --- /dev/null +++ b/frontend/src/business/components/api/definition/components/response/SqlResultTable.vue @@ -0,0 +1,121 @@ + + + + +