Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MeterSphere
metersphere
提交
8d90e427
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,发现更多精彩内容 >>
提交
8d90e427
编写于
3月 31, 2021
作者:
C
Captain.B
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'origin/v1.8' into v1.8
上级
71c51217
a21c611d
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
116 addition
and
133 deletion
+116
-133
backend/src/main/java/io/metersphere/api/dto/automation/parse/MsJmeterParser.java
.../metersphere/api/dto/automation/parse/MsJmeterParser.java
+3
-0
backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java
...pi/dto/definition/request/sampler/MsHTTPSamplerProxy.java
+4
-6
backend/src/main/java/org/apache/jmeter/assertions/JSONPathAssertion.java
.../java/org/apache/jmeter/assertions/JSONPathAssertion.java
+91
-112
frontend/src/business/components/api/automation/scenario/EnvSelect.vue
...business/components/api/automation/scenario/EnvSelect.vue
+17
-14
frontend/src/business/components/xpack
frontend/src/business/components/xpack
+1
-1
未找到文件。
backend/src/main/java/io/metersphere/api/dto/automation/parse/MsJmeterParser.java
浏览文件 @
8d90e427
...
...
@@ -214,6 +214,8 @@ public class MsJmeterParser extends ApiImportAbstractParser<ScenarioImport> {
samplerProxy
.
getBody
().
setKvs
(
keyValues
);
}
samplerProxy
.
setProtocol
(
RequestType
.
HTTP
);
samplerProxy
.
setConnectTimeout
(
source
.
getConnectTimeout
()+
""
);
samplerProxy
.
setResponseTimeout
(
source
.
getResponseTimeout
()+
""
);
samplerProxy
.
setPort
(
source
.
getPropertyAsString
(
"HTTPSampler.port"
));
samplerProxy
.
setDomain
(
source
.
getDomain
());
if
(
source
.
getArguments
()
!=
null
)
{
...
...
@@ -239,6 +241,7 @@ public class MsJmeterParser extends ApiImportAbstractParser<ScenarioImport> {
samplerProxy
.
setMethod
(
source
.
getMethod
());
if
(
this
.
getUrl
(
source
)
!=
null
)
{
samplerProxy
.
setUrl
(
this
.
getUrl
(
source
));
samplerProxy
.
setPath
(
null
);
}
samplerProxy
.
setId
(
UUID
.
randomUUID
().
toString
());
samplerProxy
.
setType
(
"HTTPSamplerProxy"
);
...
...
backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java
浏览文件 @
8d90e427
...
...
@@ -91,9 +91,6 @@ public class MsHTTPSamplerProxy extends MsTestElement {
@JSONField
(
ordinal
=
36
)
private
MsAuthManager
authManager
;
@JSONField
(
ordinal
=
37
)
private
boolean
urlOrPath
;
@Override
public
void
toHashTree
(
HashTree
tree
,
List
<
MsTestElement
>
hashTree
,
ParameterConfig
config
)
{
// 非导出操作,且不是启用状态则跳过执行
...
...
@@ -198,10 +195,11 @@ public class MsHTTPSamplerProxy extends MsTestElement {
}
URL
urlObject
=
new
URL
(
url
);
sampler
.
setDomain
(
URLDecoder
.
decode
(
urlObject
.
getHost
(),
"UTF-8"
));
if
(
urlObject
.
getPort
()
>
0
&&
urlObject
.
getPort
()
!=
10990
&&
StringUtils
.
isNotEmpty
(
this
.
getPort
())
&&
this
.
getPort
().
startsWith
(
"${"
))
{
sampler
.
setPort
(
urlObject
.
getPort
());
}
else
{
if
(
urlObject
.
getPort
()
>
0
&&
urlObject
.
getPort
()
==
10990
&&
StringUtils
.
isNotEmpty
(
this
.
getPort
())
&&
this
.
getPort
().
startsWith
(
"${"
))
{
sampler
.
setProperty
(
"HTTPSampler.port"
,
this
.
getPort
());
}
else
{
sampler
.
setPort
(
urlObject
.
getPort
());
}
sampler
.
setProtocol
(
urlObject
.
getProtocol
());
String
envPath
=
StringUtils
.
equals
(
urlObject
.
getPath
(),
"/"
)
?
""
:
urlObject
.
getPath
();
...
...
backend/src/main/java/org/apache/jmeter/assertions/JSONPathAssertion.java
浏览文件 @
8d90e427
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package
org.apache.jmeter.assertions
;
import
com.jayway.jsonpath.JsonPath
;
import
com.jayway.jsonpath.Predicate
;
import
java.io.Serializable
;
import
java.text.DecimalFormat
;
import
java.util.Map
;
import
java.util.function.Supplier
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jayway.jsonpath.JsonPath
;
import
net.minidev.json.JSONArray
;
import
net.minidev.json.JSONObject
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.jmeter.samplers.SampleResult
;
import
org.apache.jmeter.testelement.AbstractTestElement
;
...
...
@@ -34,12 +24,6 @@ import org.apache.oro.text.regex.Pattern;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* This is main class for JSONPath Assertion which verifies assertion on
* previous sample result using JSON path expression
*
* @since 4.0
*/
public
class
JSONPathAssertion
extends
AbstractTestElement
implements
Serializable
,
Assertion
,
ThreadListener
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
JSONPathAssertion
.
class
);
private
static
final
long
serialVersionUID
=
2L
;
...
...
@@ -49,119 +33,118 @@ public class JSONPathAssertion extends AbstractTestElement implements Serializab
public
static
final
String
EXPECT_NULL
=
"EXPECT_NULL"
;
public
static
final
String
INVERT
=
"INVERT"
;
public
static
final
String
ISREGEX
=
"ISREGEX"
;
private
static
ThreadLocal
<
DecimalFormat
>
decimalFormatter
=
ThreadLocal
.
withInitial
(
JSONPathAssertion:
:
createDecimalFormat
);
private
static
ThreadLocal
<
DecimalFormat
>
decimalFormatter
=
ThreadLocal
.
withInitial
(
JSONPathAssertion:
:
createDecimalFormat
);
public
String
getOption
()
{
return
getPropertyAsString
(
"ASS_OPTION"
);
public
JSONPathAssertion
()
{
}
private
static
DecimalFormat
createDecimalFormat
()
{
DecimalFormat
decimalFormatter
=
new
DecimalFormat
(
"#.#"
);
decimalFormatter
.
setMaximumFractionDigits
(
340
);
// java.text.DecimalFormat.DOUBLE_FRACTION_DIGITS == 340
decimalFormatter
.
setMaximumFractionDigits
(
340
);
decimalFormatter
.
setMinimumFractionDigits
(
1
);
return
decimalFormatter
;
}
public
String
getOption
()
{
return
getPropertyAsString
(
"ASS_OPTION"
);
}
public
String
getJsonPath
()
{
return
getPropertyAsString
(
JSONPATH
);
return
this
.
getPropertyAsString
(
"JSON_PATH"
);
}
public
void
setJsonPath
(
String
jsonPath
)
{
setProperty
(
JSONPATH
,
jsonPath
);
this
.
setProperty
(
"JSON_PATH"
,
jsonPath
);
}
public
String
getExpectedValue
()
{
return
getPropertyAsString
(
EXPECTEDVALUE
);
return
this
.
getPropertyAsString
(
"EXPECTED_VALUE"
);
}
public
void
setExpectedValue
(
String
expectedValue
)
{
setProperty
(
EXPECTEDVALUE
,
expectedValue
);
this
.
setProperty
(
"EXPECTED_VALUE"
,
expectedValue
);
}
public
void
setJsonValidationBool
(
boolean
jsonValidation
)
{
setProperty
(
JSONVALIDATION
,
jsonValidation
);
this
.
setProperty
(
"JSONVALIDATION"
,
jsonValidation
);
}
public
void
setExpectNull
(
boolean
val
)
{
setProperty
(
EXPECT_NULL
,
val
);
this
.
setProperty
(
"EXPECT_NULL"
,
val
);
}
public
boolean
isExpectNull
()
{
return
getPropertyAsBoolean
(
EXPECT_NULL
);
return
this
.
getPropertyAsBoolean
(
"EXPECT_NULL"
);
}
public
boolean
isJsonValidationBool
()
{
return
getPropertyAsBoolean
(
JSONVALIDATION
);
return
this
.
getPropertyAsBoolean
(
"JSONVALIDATION"
);
}
public
void
setInvert
(
boolean
invert
)
{
setProperty
(
INVERT
,
invert
);
this
.
setProperty
(
"INVERT"
,
invert
);
}
public
boolean
isInvert
()
{
return
getPropertyAsBoolean
(
INVERT
);
return
this
.
getPropertyAsBoolean
(
"INVERT"
);
}
public
void
setIsRegex
(
boolean
flag
)
{
setProperty
(
ISREGEX
,
flag
);
this
.
setProperty
(
"ISREGEX"
,
flag
);
}
public
boolean
isUseRegex
()
{
return
getPropertyAsBoolean
(
ISREGEX
,
true
);
return
this
.
getPropertyAsBoolean
(
"ISREGEX"
,
true
);
}
private
void
doAssert
(
String
jsonString
)
{
Object
value
=
JsonPath
.
read
(
jsonString
,
getJsonPath
());
if
(!
isJsonValidationBool
())
{
return
;
}
if
(
value
instanceof
JSONArray
)
{
if
(
arrayMatched
((
JSONArray
)
value
))
{
return
;
}
}
else
{
if
((
isExpectNull
()
&&
value
==
null
)
||
isEquals
(
value
))
{
Object
value
=
JsonPath
.
read
(
jsonString
,
this
.
getJsonPath
(),
new
Predicate
[
0
]);
if
(
this
.
isJsonValidationBool
())
{
if
(
value
instanceof
JSONArray
)
{
if
(
this
.
arrayMatched
((
JSONArray
)
value
))
{
return
;
}
}
else
if
(
this
.
isExpectNull
()
&&
value
==
null
||
this
.
isEquals
(
value
))
{
return
;
}
}
if
(
isExpectNull
())
{
throw
new
IllegalStateException
(
String
.
format
(
"Value expected to be null, but found '%s'"
,
value
));
}
else
{
String
msg
;
if
(
isUseRegex
())
{
msg
=
"Value expected to match regexp '%s', but it did not match: '%s'"
;
if
(
this
.
isExpectNull
())
{
throw
new
IllegalStateException
(
String
.
format
(
"Value expected to be null, but found '%s'"
,
value
));
}
else
{
msg
=
"Value expected to be '%s', but found '%s'"
;
String
msg
;
if
(
this
.
isUseRegex
())
{
msg
=
"Value expected to match regexp '%s', but it did not match: '%s'"
;
}
else
{
msg
=
"Value expected to be '%s', but found '%s'"
;
}
throw
new
IllegalStateException
(
String
.
format
(
msg
,
this
.
getExpectedValue
(),
objectToString
(
value
)));
}
throw
new
IllegalStateException
(
String
.
format
(
msg
,
getExpectedValue
(),
objectToString
(
value
)));
}
}
private
boolean
arrayMatched
(
JSONArray
value
)
{
if
(
value
.
isEmpty
()
&&
"[]"
.
equals
(
getExpectedValue
()))
{
if
(
value
.
isEmpty
()
&&
"[]"
.
equals
(
this
.
getExpectedValue
()))
{
return
true
;
}
}
else
{
Object
[]
var2
=
value
.
toArray
();
int
var3
=
var2
.
length
;
for
(
Object
subj
:
value
.
toArray
())
{
if
((
subj
==
null
&&
isExpectNull
())
||
isEquals
(
subj
))
{
return
true
;
for
(
int
var4
=
0
;
var4
<
var3
;
++
var4
)
{
Object
subj
=
var2
[
var4
];
if
(
subj
==
null
&&
this
.
isExpectNull
()
||
this
.
isEquals
(
subj
))
{
return
true
;
}
}
}
return
isEquals
(
value
);
return
this
.
isEquals
(
value
);
}
}
private
boolean
isEquals
(
Object
subj
)
{
String
str
=
objectToString
(
subj
);
if
(
isUseRegex
())
{
Pattern
pattern
=
JMeterUtils
.
getPatternCache
().
getPattern
(
getExpectedValue
());
if
(
this
.
isUseRegex
())
{
Pattern
pattern
=
JMeterUtils
.
getPatternCache
().
getPattern
(
this
.
getExpectedValue
());
return
JMeterUtils
.
getMatcher
().
matches
(
str
,
pattern
);
}
else
{
if
(
StringUtils
.
isNotEmpty
(
getOption
()))
{
...
...
@@ -182,47 +165,46 @@ public class JSONPathAssertion extends AbstractTestElement implements Serializab
}
return
refFlag
;
}
return
str
.
equals
(
getExpectedValue
());
return
str
.
equals
(
this
.
getExpectedValue
());
}
}
@Override
public
AssertionResult
getResult
(
SampleResult
samplerResult
)
{
AssertionResult
result
=
new
AssertionResult
(
getName
());
AssertionResult
result
=
new
AssertionResult
(
this
.
getName
());
String
responseData
=
samplerResult
.
getResponseDataAsString
();
if
(
responseData
.
isEmpty
())
{
return
result
.
setResultForNull
();
}
result
.
setFailure
(
false
);
result
.
setFailureMessage
(
""
);
if
(!
isInvert
())
{
try
{
doAssert
(
responseData
);
}
catch
(
Exception
e
)
{
log
.
debug
(
"Assertion failed"
,
e
);
result
.
setFailure
(
true
);
result
.
setFailureMessage
(
e
.
getMessage
());
}
}
else
{
try
{
doAssert
(
responseData
);
result
.
setFailure
(
true
);
if
(
isJsonValidationBool
())
{
if
(
isExpectNull
())
{
result
.
setFailureMessage
(
"Failed that JSONPath "
+
getJsonPath
()
+
" not matches null"
);
result
.
setFailure
(
false
);
result
.
setFailureMessage
(
""
);
if
(!
this
.
isInvert
())
{
try
{
this
.
doAssert
(
responseData
);
}
catch
(
Exception
var6
)
{
log
.
debug
(
"Assertion failed"
,
var6
);
result
.
setFailure
(
true
);
result
.
setFailureMessage
(
var6
.
getMessage
());
}
}
else
{
try
{
this
.
doAssert
(
responseData
);
result
.
setFailure
(
true
);
if
(
this
.
isJsonValidationBool
())
{
if
(
this
.
isExpectNull
())
{
result
.
setFailureMessage
(
"Failed that JSONPath "
+
this
.
getJsonPath
()
+
" not matches null"
);
}
else
{
result
.
setFailureMessage
(
"Failed that JSONPath "
+
this
.
getJsonPath
()
+
" not matches "
+
this
.
getExpectedValue
());
}
}
else
{
result
.
setFailureMessage
(
"Failed that JSONPath
"
+
getJsonPath
()
+
" not matches "
+
getExpectedValue
());
result
.
setFailureMessage
(
"Failed that JSONPath
not exists: "
+
this
.
getJsonPath
());
}
}
else
{
result
.
setFailureMessage
(
"Failed that JSONPath not exists: "
+
getJsonPath
()
);
}
catch
(
Exception
var5
)
{
log
.
debug
(
"Assertion failed, as expected"
,
var5
);
}
}
catch
(
Exception
e
)
{
log
.
debug
(
"Assertion failed, as expected"
,
e
);
}
return
result
;
}
return
result
;
}
public
static
String
objectToString
(
Object
subj
)
{
...
...
@@ -230,22 +212,19 @@ public class JSONPathAssertion extends AbstractTestElement implements Serializab
if
(
subj
==
null
)
{
str
=
"null"
;
}
else
if
(
subj
instanceof
Map
)
{
//noinspection unchecked
str
=
new
JSONObject
((
Map
<
String
,
Object
>)
subj
).
toJSONString
();
}
else
if
(
subj
instanceof
Double
||
subj
instanceof
Float
)
{
str
=
decimalFormatter
.
get
().
format
(
subj
);
}
else
{
str
=
(
new
JSONObject
((
Map
)
subj
)).
toJSONString
();
}
else
if
(!(
subj
instanceof
Double
)
&&
!(
subj
instanceof
Float
))
{
str
=
subj
.
toString
();
}
else
{
str
=
((
DecimalFormat
)
decimalFormatter
.
get
()).
format
(
subj
);
}
return
str
;
}
@Override
public
void
threadStarted
()
{
// nothing to do on thread start
}
@Override
public
void
threadFinished
()
{
decimalFormatter
.
remove
();
}
...
...
frontend/src/business/components/api/automation/scenario/EnvSelect.vue
浏览文件 @
8d90e427
...
...
@@ -54,20 +54,23 @@
methods
:
{
init
()
{
this
.
projectIds
.
forEach
(
id
=>
{
let
item
=
{
id
:
id
,
envs
:
[],
selectEnv
:
""
};
this
.
data
.
push
(
item
);
this
.
result
=
this
.
$get
(
'
/api/environment/list/
'
+
id
,
res
=>
{
let
envs
=
res
.
data
;
envs
.
forEach
(
environment
=>
{
parseEnvironment
(
environment
);
});
// 固定环境列表渲染顺序
let
temp
=
this
.
data
.
find
(
dt
=>
dt
.
id
===
id
);
temp
.
envs
=
envs
;
let
envId
=
this
.
envMap
.
get
(
id
);
// 选中环境是否存在
temp
.
selectEnv
=
envs
.
filter
(
e
=>
e
.
id
===
envId
).
length
===
0
?
null
:
envId
;
})
const
project
=
this
.
projectList
.
find
(
p
=>
p
.
id
===
id
);
if
(
project
)
{
let
item
=
{
id
:
id
,
envs
:
[],
selectEnv
:
""
};
this
.
data
.
push
(
item
);
this
.
result
=
this
.
$get
(
'
/api/environment/list/
'
+
id
,
res
=>
{
let
envs
=
res
.
data
;
envs
.
forEach
(
environment
=>
{
parseEnvironment
(
environment
);
});
// 固定环境列表渲染顺序
let
temp
=
this
.
data
.
find
(
dt
=>
dt
.
id
===
id
);
temp
.
envs
=
envs
;
let
envId
=
this
.
envMap
.
get
(
id
);
// 选中环境是否存在
temp
.
selectEnv
=
envs
.
filter
(
e
=>
e
.
id
===
envId
).
length
===
0
?
null
:
envId
;
})
}
})
},
open
()
{
...
...
xpack
@
07951ba1
比较
a37e6bb5
...
07951ba1
Subproject commit
a37e6bb56ffaa7ecc4ee128640e9415304ad41b6
Subproject commit
07951ba17aef6f29e50cfd68e40de3266f9a60cd
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录