Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MeterSphere
metersphere
提交
6923eb10
M
metersphere
项目概览
MeterSphere
/
metersphere
上一次同步 3 年多
通知
25
Star
1
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
metersphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6923eb10
编写于
4月 19, 2021
作者:
F
fit2-zhao
提交者:
fit2-zhao
4月 19, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(接口自动化): JDBC 请求数据源选择优化
上级
195a7158
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
116 addition
and
38 deletion
+116
-38
backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java
...pi/dto/definition/request/sampler/MsHTTPSamplerProxy.java
+5
-3
backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java
...ere/api/dto/definition/request/sampler/MsJDBCSampler.java
+56
-1
frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue
...onents/api/automation/scenario/component/ApiComponent.vue
+17
-3
frontend/src/business/components/api/definition/components/request/database/BasisParameters.vue
...efinition/components/request/database/BasisParameters.vue
+38
-31
未找到文件。
backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java
浏览文件 @
6923eb10
...
@@ -490,9 +490,11 @@ public class MsHTTPSamplerProxy extends MsTestElement {
...
@@ -490,9 +490,11 @@ public class MsHTTPSamplerProxy extends MsTestElement {
}
}
// 环境中请求头
// 环境中请求头
Arguments
arguments
=
arguments
(
httpConfig
.
getHeaders
());
if
(
httpConfig
!=
null
)
{
if
(
arguments
!=
null
)
{
Arguments
arguments
=
arguments
(
httpConfig
.
getHeaders
());
tree
.
add
(
ParameterConfig
.
valueSupposeMock
(
arguments
));
if
(
arguments
!=
null
)
{
tree
.
add
(
ParameterConfig
.
valueSupposeMock
(
arguments
));
}
}
}
return
httpConfig
;
return
httpConfig
;
}
}
...
...
backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java
浏览文件 @
6923eb10
...
@@ -32,7 +32,9 @@ import org.apache.jmeter.save.SaveService;
...
@@ -32,7 +32,9 @@ import org.apache.jmeter.save.SaveService;
import
org.apache.jmeter.testelement.TestElement
;
import
org.apache.jmeter.testelement.TestElement
;
import
org.apache.jorphan.collections.HashTree
;
import
org.apache.jorphan.collections.HashTree
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.List
;
import
java.util.stream.Collectors
;
@Data
@Data
@EqualsAndHashCode
(
callSuper
=
true
)
@EqualsAndHashCode
(
callSuper
=
true
)
...
@@ -71,9 +73,43 @@ public class MsJDBCSampler extends MsTestElement {
...
@@ -71,9 +73,43 @@ public class MsJDBCSampler extends MsTestElement {
if
(
this
.
getReferenced
()
!=
null
&&
MsTestElementConstants
.
REF
.
name
().
equals
(
this
.
getReferenced
()))
{
if
(
this
.
getReferenced
()
!=
null
&&
MsTestElementConstants
.
REF
.
name
().
equals
(
this
.
getReferenced
()))
{
this
.
setRefElement
();
this
.
setRefElement
();
}
}
if
(
StringUtils
.
isNotEmpty
(
dataSourceId
))
{
if
(
config
.
getConfig
()
==
null
)
{
// 单独接口执行
this
.
setProjectId
(
config
.
getProjectId
());
config
.
setConfig
(
getEnvironmentConfig
(
useEnvironment
));
}
// 数据兼容处理
if
(
config
.
getConfig
()
!=
null
&&
StringUtils
.
isNotEmpty
(
this
.
getProjectId
())
&&
config
.
getConfig
().
containsKey
(
this
.
getProjectId
()))
{
// 1.8 之后 当前正常数据
}
else
if
(
config
.
getConfig
()
!=
null
&&
config
.
getConfig
().
containsKey
(
getParentProjectId
()))
{
// 1.8 前后 混合数据
this
.
setProjectId
(
getParentProjectId
());
}
else
{
// 1.8 之前 数据
if
(
config
.
getConfig
()
!=
null
)
{
if
(
config
.
getConfig
().
containsKey
(
"historyProjectID"
))
{
this
.
setProjectId
(
"historyProjectID"
);
}
else
{
// 测试计划执行
Iterator
<
String
>
it
=
config
.
getConfig
().
keySet
().
iterator
();
if
(
it
.
hasNext
())
{
this
.
setProjectId
(
it
.
next
());
}
}
}
}
// 自选了数据源
if
(
config
.
isEffective
(
this
.
getProjectId
())
&&
CollectionUtils
.
isNotEmpty
(
config
.
getConfig
().
get
(
this
.
getProjectId
()).
getDatabaseConfigs
())
&&
isDataSource
(
config
.
getConfig
().
get
(
this
.
getProjectId
()).
getDatabaseConfigs
()))
{
this
.
dataSource
=
null
;
this
.
dataSource
=
null
;
this
.
initDataSource
();
this
.
initDataSource
();
}
else
{
this
.
dataSource
=
null
;
// 取当前环境下默认的一个数据源
if
(
config
.
isEffective
(
this
.
getProjectId
())
&&
CollectionUtils
.
isNotEmpty
(
config
.
getConfig
().
get
(
this
.
getProjectId
()).
getDatabaseConfigs
()))
{
this
.
dataSource
=
config
.
getConfig
().
get
(
this
.
getProjectId
()).
getDatabaseConfigs
().
get
(
0
);
}
}
}
if
(
this
.
dataSource
==
null
)
{
if
(
this
.
dataSource
==
null
)
{
MSException
.
throwException
(
"数据源为空无法执行"
);
MSException
.
throwException
(
"数据源为空无法执行"
);
...
@@ -91,6 +127,25 @@ public class MsJDBCSampler extends MsTestElement {
...
@@ -91,6 +127,25 @@ public class MsJDBCSampler extends MsTestElement {
}
}
}
}
private
boolean
isDataSource
(
List
<
DatabaseConfig
>
databaseConfigs
)
{
List
<
String
>
ids
=
databaseConfigs
.
stream
().
map
(
DatabaseConfig:
:
getId
).
collect
(
Collectors
.
toList
());
if
(
StringUtils
.
isNotEmpty
(
this
.
dataSourceId
)
&&
ids
.
contains
(
this
.
dataSourceId
))
{
return
true
;
}
return
false
;
}
private
String
getParentProjectId
()
{
MsTestElement
parent
=
this
.
getParent
();
while
(
parent
!=
null
)
{
if
(
StringUtils
.
isNotBlank
(
parent
.
getProjectId
()))
{
return
parent
.
getProjectId
();
}
parent
=
parent
.
getParent
();
}
return
""
;
}
private
void
setRefElement
()
{
private
void
setRefElement
()
{
try
{
try
{
ApiDefinitionService
apiDefinitionService
=
CommonBeanFactory
.
getBean
(
ApiDefinitionService
.
class
);
ApiDefinitionService
apiDefinitionService
=
CommonBeanFactory
.
getBean
(
ApiDefinitionService
.
class
);
...
...
frontend/src/business/components/api/automation/scenario/component/ApiComponent.vue
浏览文件 @
6923eb10
...
@@ -41,11 +41,11 @@
...
@@ -41,11 +41,11 @@
:request=
"request"
:request=
"request"
:showScript=
"false"
:showScript=
"false"
ref=
"esbDefinition"
/>
ref=
"esbDefinition"
/>
<ms-tcp-basis-parameters
v-if=
"(request.protocol==='TCP'|| request.type==='TCPSampler')&&request.esbDataStruct==null "
<ms-tcp-basis-parameters
v-if=
"(request.protocol==='TCP'|| request.type==='TCPSampler')&&
request.esbDataStruct==null "
:request=
"request"
:request=
"request"
:showScript=
"false"
/>
:showScript=
"false"
/>
<ms-sql-basis-parameters
v-if=
"request.protocol==='SQL'|| request.type==='JDBCSampler'"
<ms-sql-basis-parameters
v-if=
"request.protocol==='SQL'|| request.type==='JDBCSampler'"
:request=
"request"
:request=
"request"
:is-scenario=
"true"
:environment=
"environment"
:showScript=
"false"
/>
:showScript=
"false"
/>
<ms-dubbo-basis-parameters
v-if=
"request.protocol==='DUBBO' || request.protocol==='dubbo://'|| request.type==='DubboSampler'"
<ms-dubbo-basis-parameters
v-if=
"request.protocol==='DUBBO' || request.protocol==='dubbo://'|| request.type==='DubboSampler'"
:request=
"request"
:request=
"request"
...
@@ -64,7 +64,7 @@
...
@@ -64,7 +64,7 @@
</el-tabs>
</el-tabs>
</div>
</div>
<div
v-else-if=
"showXpackCompnent&&request.backEsbDataStruct != null"
>
<div
v-else-if=
"showXpackCompnent&&request.backEsbDataStruct != null"
>
<esb-definition-response
v-xpack
v-if=
"showXpackCompnent"
:currentProtocol=
"request.protocol"
:request=
"request"
:is-api-component=
"false"
<esb-definition-response
v-xpack
v-if=
"showXpackCompnent"
:currentProtocol=
"request.protocol"
:request=
"request"
:is-api-component=
"false"
:show-options-button=
"false"
:show-header=
"true"
:result=
"request.requestResult"
/>
:show-options-button=
"false"
:show-header=
"true"
:result=
"request.requestResult"
/>
</div>
</div>
<div
v-else
>
<div
v-else
>
...
@@ -134,6 +134,7 @@
...
@@ -134,6 +134,7 @@
runData
:
[],
runData
:
[],
isShowInput
:
false
,
isShowInput
:
false
,
showXpackCompnent
:
false
,
showXpackCompnent
:
false
,
environment
:
{},
}
}
},
},
created
()
{
created
()
{
...
@@ -162,6 +163,12 @@
...
@@ -162,6 +163,12 @@
if
(
requireComponent
!=
null
&&
JSON
.
stringify
(
esbDefinition
)
!=
'
{}
'
&&
JSON
.
stringify
(
esbDefinitionResponse
)
!=
'
{}
'
)
{
if
(
requireComponent
!=
null
&&
JSON
.
stringify
(
esbDefinition
)
!=
'
{}
'
&&
JSON
.
stringify
(
esbDefinitionResponse
)
!=
'
{}
'
)
{
this
.
showXpackCompnent
=
true
;
this
.
showXpackCompnent
=
true
;
}
}
this
.
getEnvironments
();
},
watch
:
{
envMap
()
{
this
.
getEnvironments
();
}
},
},
computed
:
{
computed
:
{
displayColor
()
{
displayColor
()
{
...
@@ -219,6 +226,13 @@
...
@@ -219,6 +226,13 @@
},
},
},
},
methods
:
{
methods
:
{
getEnvironments
()
{
this
.
environment
=
{};
let
id
=
this
.
envMap
.
get
(
this
.
request
.
projectId
);
this
.
$get
(
'
/api/environment/get/
'
+
id
,
response
=>
{
this
.
environment
=
response
.
data
;
});
},
remove
()
{
remove
()
{
this
.
$emit
(
'
remove
'
,
this
.
request
,
this
.
node
);
this
.
$emit
(
'
remove
'
,
this
.
request
,
this
.
node
);
},
},
...
...
frontend/src/business/components/api/definition/components/request/database/BasisParameters.vue
浏览文件 @
6923eb10
...
@@ -6,12 +6,12 @@
...
@@ -6,12 +6,12 @@
<el-form
:model=
"request"
:rules=
"rules"
ref=
"request"
label-width=
"100px"
:disabled=
"isReadOnly"
style=
"margin: 10px"
>
<el-form
:model=
"request"
:rules=
"rules"
ref=
"request"
label-width=
"100px"
:disabled=
"isReadOnly"
style=
"margin: 10px"
>
<el-row>
<el-row>
<el-col
:span=
"8"
>
<el-col
:span=
"8"
>
<el-form-item
prop=
"environmentId"
:label=
"$t('api_test.definition.request.run_env')"
>
<el-form-item
prop=
"environmentId"
div
v-if=
"!isScenario"
:label=
"$t('api_test.definition.request.run_env')"
>
<el-select
v-model=
"request.environmentId"
size=
"small"
class=
"ms-htt-width"
<el-select
v-model=
"request.environmentId"
size=
"small"
class=
"ms-htt-width"
:placeholder=
"$t('api_test.definition.request.run_env')"
:placeholder=
"$t('api_test.definition.request.run_env')"
@
change=
"environmentChange"
clearable
>
@
change=
"environmentChange"
clearable
>
<el-option
v-for=
"(environment, index) in environments"
:key=
"index"
<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) : '')
"
:label=
"environment.name"
:value=
"environment.id"
/>
:value=
"environment.id"
/>
<el-button
class=
"environment-button"
size=
"small"
type=
"primary"
@
click=
"openEnvironmentConfig"
>
<el-button
class=
"environment-button"
size=
"small"
type=
"primary"
@
click=
"openEnvironmentConfig"
>
{{
$t
(
'
api_test.environment.environment_config
'
)
}}
{{
$t
(
'
api_test.environment.environment_config
'
)
}}
...
@@ -63,24 +63,6 @@
...
@@ -63,24 +63,6 @@
</el-tabs>
</el-tabs>
</el-form>
</el-form>
</div>
</div>
<!--<div v-if="showScript">-->
<!--<div v-for="row in request.hashTree" :key="row.id" v-loading="isReloadData" style="margin-left: 20px;width: 100%">-->
<!--<!– 前置脚本 –>-->
<!--<ms-jsr233-processor v-if="row.label ==='JSR223 PreProcessor'" @copyRow="copyRow" @remove="remove" :is-read-only="false" :title="$t('api_test.definition.request.pre_script')" style-type="color: #B8741A;background-color: #F9F1EA"-->
<!--:jsr223-processor="row"/>-->
<!--<!–后置脚本–>-->
<!--<ms-jsr233-processor v-if="row.label ==='JSR223 PostProcessor'" @copyRow="copyRow" @remove="remove" :is-read-only="false" :title="$t('api_test.definition.request.post_script')" style-type="color: #783887;background-color: #F2ECF3"-->
<!--:jsr223-processor="row"/>-->
<!--<!–断言规则–>-->
<!--<div style="margin-top: 10px">-->
<!--<ms-api-assertions v-if="row.type==='Assertions'" @copyRow="copyRow" @remove="remove" :is-read-only="isReadOnly" :assertions="row"/>-->
<!--</div>-->
<!--<!–提取规则–>-->
<!--<div style="margin-top: 10px">-->
<!--<ms-api-extract :is-read-only="isReadOnly" @copyRow="copyRow" @remove="remove" v-if="row.type==='Extract'" :extract="row"/>-->
<!--</div>-->
<!--</div>-->
<!--</div>-->
</el-col>
</el-col>
<el-col
:span=
"3"
class=
"ms-left-cell"
v-if=
"showScript"
>
<el-col
:span=
"3"
class=
"ms-left-cell"
v-if=
"showScript"
>
...
@@ -126,6 +108,11 @@
...
@@ -126,6 +108,11 @@
request
:
{},
request
:
{},
basisData
:
{},
basisData
:
{},
moduleOptions
:
Array
,
moduleOptions
:
Array
,
environment
:
{},
//来自场景选择的环境
isScenario
:
{
type
:
Boolean
,
default
:
false
,
},
showScript
:
{
showScript
:
{
type
:
Boolean
,
type
:
Boolean
,
default
:
true
,
default
:
true
,
...
@@ -138,18 +125,24 @@
...
@@ -138,18 +125,24 @@
data
()
{
data
()
{
return
{
return
{
environments
:
[],
environments
:
[],
currentEnvironment
:
{},
databaseConfigsOptions
:
[],
databaseConfigsOptions
:
[],
isReloadData
:
false
,
isReloadData
:
false
,
activeName
:
"
variables
"
,
activeName
:
"
variables
"
,
rules
:
{
rules
:
{
environmentId
:
[{
required
:
true
,
message
:
this
.
$t
(
'
api_test.definition.request.run_env
'
),
trigger
:
'
change
'
}],
dataSourceId
:
[{
required
:
true
,
message
:
this
.
$t
(
'
api_test.request.sql.dataSource
'
),
trigger
:
'
blur
'
}],
},
},
}
}
},
},
watch
:
{
watch
:
{
'
request.dataSourceId
'
()
{
'
request.dataSourceId
'
()
{
this
.
setDataSource
();
this
.
setDataSource
();
},
environment
:
{
handler
:
function
()
{
this
.
initDataSource
();
},
deep
:
true
}
}
},
},
created
()
{
created
()
{
...
@@ -212,7 +205,6 @@
...
@@ -212,7 +205,6 @@
runTest
()
{
runTest
()
{
},
},
getEnvironments
()
{
getEnvironments
()
{
this
.
environments
=
[];
this
.
environments
=
[];
let
id
=
this
.
request
.
projectId
?
this
.
request
.
projectId
:
this
.
projectId
;
let
id
=
this
.
request
.
projectId
?
this
.
request
.
projectId
:
this
.
projectId
;
...
@@ -242,20 +234,35 @@
...
@@ -242,20 +234,35 @@
},
},
initDataSource
()
{
initDataSource
()
{
let
flag
=
false
;
let
flag
=
false
;
for
(
let
i
in
this
.
environments
)
{
if
(
this
.
isScenario
&&
this
.
environment
)
{
if
(
this
.
environments
[
i
].
id
===
this
.
request
.
environmentId
)
{
this
.
request
.
environmentId
=
this
.
environment
.
id
;
this
.
databaseConfigsOptions
=
[];
this
.
databaseConfigsOptions
=
[];
this
.
environments
[
i
].
config
.
databaseConfigs
.
forEach
(
item
=>
{
if
(
this
.
environment
.
config
)
{
if
(
item
.
id
===
this
.
request
.
dataSourceId
)
{
let
config
=
JSON
.
parse
(
this
.
environment
.
config
);
flag
=
true
;
config
.
databaseConfigs
.
forEach
(
item
=>
{
if
(
item
.
id
!==
this
.
request
.
dataSourceId
)
{
this
.
request
.
dataSourceId
=
item
.
id
;
}
}
flag
=
true
;
this
.
databaseConfigsOptions
.
push
(
item
);
this
.
databaseConfigsOptions
.
push
(
item
);
});
});
break
;
}
}
else
{
for
(
let
i
in
this
.
environments
)
{
if
(
this
.
environments
[
i
].
id
===
this
.
request
.
environmentId
)
{
this
.
databaseConfigsOptions
=
[];
this
.
environments
[
i
].
config
.
databaseConfigs
.
forEach
(
item
=>
{
if
(
item
.
id
===
this
.
request
.
dataSourceId
)
{
flag
=
true
;
}
this
.
databaseConfigsOptions
.
push
(
item
);
});
break
;
}
}
}
}
}
if
(
!
flag
)
{
if
(
!
flag
)
{
this
.
request
.
dataSourceId
=
undefined
;
this
.
request
.
dataSourceId
=
""
;
}
}
},
},
setDataSource
()
{
setDataSource
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录