Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
loongten
metersphere
Commits
f641f6f6
Commit
f641f6f6
authored
3 years ago
by
song-tianyang
Committed by
CountryBuilder
3 years ago
Browse files
Options
Download
Email Patches
Plain Diff
refactor(接口测试): 修复Mock期望可以使用JMeter函数提示对问题
修复Mock期望可以使用JMeter函数提示对问题
parent
1a8d6bf0
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
backend/src/main/java/io/metersphere/api/mock/utils/MockApiUtils.java
+10
-7
...main/java/io/metersphere/api/mock/utils/MockApiUtils.java
backend/src/main/java/io/metersphere/api/mock/utils/MockScriptEngineUtils.java
+1
-1
.../io/metersphere/api/mock/utils/MockScriptEngineUtils.java
backend/src/main/java/io/metersphere/api/service/MockConfigService.java
+0
-133
...in/java/io/metersphere/api/service/MockConfigService.java
frontend/src/business/components/api/automation/scenario/component/ComponentConfig.vue
+40
-42
...nts/api/automation/scenario/component/ComponentConfig.vue
frontend/src/business/components/common/json-schema/schema/editor/mock/MockComplete.vue
+5
-2
...ts/common/json-schema/schema/editor/mock/MockComplete.vue
frontend/src/business/components/xpack
+1
-1
frontend/src/business/components/xpack
frontend/src/i18n/en-US.js
+1
-0
frontend/src/i18n/en-US.js
frontend/src/i18n/zh-CN.js
+1
-0
frontend/src/i18n/zh-CN.js
frontend/src/i18n/zh-TW.js
+1
-0
frontend/src/i18n/zh-TW.js
with
60 additions
and
186 deletions
+60
-186
backend/src/main/java/io/metersphere/api/mock/utils/MockApiUtils.java
+
10
-
7
View file @
f641f6f6
...
...
@@ -146,7 +146,7 @@ public class MockApiUtils {
return
returnJson
;
}
public
static
JSONObject
parseJsonSchema
(
JSONObject
bodyReturnObj
)
{
public
static
JSONObject
parseJsonSchema
(
JSONObject
bodyReturnObj
,
boolean
useJMeterFunc
)
{
JSONObject
returnObj
=
new
JSONObject
();
if
(
bodyReturnObj
==
null
)
{
return
returnObj
;
...
...
@@ -157,7 +157,7 @@ public class MockApiUtils {
try
{
JsonSchemaReturnObj
obj
=
bodyReturnObj
.
getObject
(
key
,
JsonSchemaReturnObj
.
class
);
if
(
StringUtils
.
equals
(
"object"
,
obj
.
getType
()))
{
JSONObject
itemObj
=
parseJsonSchema
(
obj
.
getProperties
());
JSONObject
itemObj
=
parseJsonSchema
(
obj
.
getProperties
()
,
useJMeterFunc
);
if
(!
itemObj
.
isEmpty
())
{
returnObj
.
put
(
key
,
itemObj
);
}
...
...
@@ -167,13 +167,16 @@ public class MockApiUtils {
if
(
itemObj
.
containsKey
(
"type"
))
{
if
(
StringUtils
.
equals
(
"object"
,
itemObj
.
getString
(
"type"
))
&&
itemObj
.
containsKey
(
"properties"
))
{
JSONObject
arrayObj
=
itemObj
.
getJSONObject
(
"properties"
);
JSONObject
parseObj
=
parseJsonSchema
(
arrayObj
);
JSONObject
parseObj
=
parseJsonSchema
(
arrayObj
,
useJMeterFunc
);
JSONArray
array
=
new
JSONArray
();
array
.
add
(
parseObj
);
returnObj
.
put
(
key
,
array
);
}
else
if
(
StringUtils
.
equals
(
"string"
,
itemObj
.
getString
(
"type"
))
&&
itemObj
.
containsKey
(
"mock"
))
{
JsonSchemaReturnObj
arrayObj
=
JSONObject
.
toJavaObject
(
itemObj
,
JsonSchemaReturnObj
.
class
);
String
value
=
getMockValues
(
arrayObj
.
getMockValue
());
String
value
=
arrayObj
.
getMockValue
();
if
(
useJMeterFunc
){
value
=
getMockValues
(
arrayObj
.
getMockValue
());
}
JSONArray
array
=
new
JSONArray
();
array
.
add
(
value
);
returnObj
.
put
(
key
,
array
);
...
...
@@ -184,7 +187,7 @@ public class MockApiUtils {
String
values
=
obj
.
getMockValue
();
if
(
StringUtils
.
isEmpty
(
values
))
{
values
=
""
;
}
else
{
}
else
if
(
useJMeterFunc
)
{
try
{
values
=
values
.
startsWith
(
"@"
)
?
ScriptEngineUtils
.
buildFunctionCallString
(
values
)
:
values
;
}
catch
(
Exception
e
)
{
...
...
@@ -254,7 +257,7 @@ public class MockApiUtils {
if
(
bodyObj
.
containsKey
(
"jsonSchema"
)
&&
bodyObj
.
getJSONObject
(
"jsonSchema"
).
containsKey
(
"properties"
))
{
String
bodyRetunStr
=
bodyObj
.
getJSONObject
(
"jsonSchema"
).
getJSONObject
(
"properties"
).
toJSONString
();
JSONObject
bodyReturnObj
=
JSONObject
.
parseObject
(
bodyRetunStr
);
JSONObject
returnObj
=
MockApiUtils
.
parseJsonSchema
(
bodyReturnObj
);
JSONObject
returnObj
=
MockApiUtils
.
parseJsonSchema
(
bodyReturnObj
,
false
);
returnStr
=
returnObj
.
toJSONString
();
}
}
else
{
...
...
@@ -379,7 +382,7 @@ public class MockApiUtils {
if
(
bodyObj
.
containsKey
(
"jsonSchema"
)
&&
bodyObj
.
getJSONObject
(
"jsonSchema"
).
containsKey
(
"properties"
))
{
String
bodyRetunStr
=
bodyObj
.
getJSONObject
(
"jsonSchema"
).
getJSONObject
(
"properties"
).
toJSONString
();
JSONObject
bodyReturnObj
=
JSONObject
.
parseObject
(
bodyRetunStr
);
JSONObject
returnObj
=
MockApiUtils
.
parseJsonSchema
(
bodyReturnObj
);
JSONObject
returnObj
=
MockApiUtils
.
parseJsonSchema
(
bodyReturnObj
,
false
);
returnStr
=
returnObj
.
toJSONString
();
}
}
else
{
...
...
This diff is collapsed.
Click to expand it.
backend/src/main/java/io/metersphere/api/mock/utils/MockScriptEngineUtils.java
+
1
-
1
View file @
f641f6f6
...
...
@@ -257,7 +257,7 @@ public class MockScriptEngineUtils {
LogUtil
.
error
(
e
);
}
}
if
(
StringUtils
.
isEmpty
(
value
))
{
if
(
StringUtils
.
isEmpty
(
value
)
||
StringUtils
.
equals
(
value
,
"null"
)
)
{
value
=
paramKey
;
}
return
value
;
...
...
This diff is collapsed.
Click to expand it.
backend/src/main/java/io/metersphere/api/service/MockConfigService.java
+
0
-
133
View file @
f641f6f6
...
...
@@ -782,139 +782,6 @@ public class MockConfigService {
return
returnStr
;
}
public
String
updateHttpServletResponse
(
List
<
ApiDefinitionWithBLOBs
>
apis
,
HttpServletResponse
response
)
{
String
returnStr
=
""
;
try
{
if
(
CollectionUtils
.
isEmpty
(
apis
))
{
response
.
setStatus
(
404
);
}
else
{
for
(
ApiDefinitionWithBLOBs
api
:
apis
)
{
int
status
=
404
;
if
(
api
.
getResponse
()
!=
null
)
{
JSONObject
respObj
=
JSONObject
.
parseObject
(
api
.
getResponse
());
if
(
respObj
.
containsKey
(
"headers"
))
{
JSONArray
headersArr
=
respObj
.
getJSONArray
(
"headers"
);
for
(
int
i
=
0
;
i
<
headersArr
.
size
();
i
++)
{
JSONObject
obj
=
headersArr
.
getJSONObject
(
i
);
if
(
obj
.
containsKey
(
"name"
)
&&
obj
.
containsKey
(
"value"
)
&&
StringUtils
.
isNotEmpty
(
obj
.
getString
(
"name"
)))
{
response
.
setHeader
(
obj
.
getString
(
"name"
),
obj
.
getString
(
"value"
));
}
}
}
if
(
respObj
.
containsKey
(
"statusCode"
))
{
JSONArray
statusCodeArr
=
respObj
.
getJSONArray
(
"statusCode"
);
for
(
int
i
=
0
;
i
<
statusCodeArr
.
size
();
i
++)
{
JSONObject
obj
=
statusCodeArr
.
getJSONObject
(
i
);
if
(
obj
.
containsKey
(
"name"
)
&&
obj
.
containsKey
(
"value"
)
&&
StringUtils
.
isNotEmpty
(
obj
.
getString
(
"name"
)))
{
// response.setHeader(obj.getString("name"), obj.getString("value"));
try
{
status
=
Integer
.
parseInt
(
obj
.
getString
(
"name"
));
}
catch
(
Exception
e
)
{
}
}
}
}
if
(
respObj
.
containsKey
(
"body"
))
{
JSONObject
bodyObj
=
respObj
.
getJSONObject
(
"body"
);
if
(
bodyObj
.
containsKey
(
"type"
))
{
String
type
=
bodyObj
.
getString
(
"type"
);
if
(
StringUtils
.
equals
(
type
,
"JSON"
))
{
//判断是否是JsonSchema
boolean
isJsonSchema
=
false
;
if
(
bodyObj
.
containsKey
(
"format"
))
{
String
foramtValue
=
String
.
valueOf
(
bodyObj
.
get
(
"format"
));
if
(
StringUtils
.
equals
(
"JSON-SCHEMA"
,
foramtValue
))
{
isJsonSchema
=
true
;
}
}
if
(
isJsonSchema
)
{
if
(
bodyObj
.
containsKey
(
"jsonSchema"
)
&&
bodyObj
.
getJSONObject
(
"jsonSchema"
).
containsKey
(
"properties"
))
{
String
bodyRetunStr
=
bodyObj
.
getJSONObject
(
"jsonSchema"
).
getJSONObject
(
"properties"
).
toJSONString
();
JSONObject
bodyReturnObj
=
JSONObject
.
parseObject
(
bodyRetunStr
);
JSONObject
returnObj
=
MockApiUtils
.
parseJsonSchema
(
bodyReturnObj
);
returnStr
=
returnObj
.
toJSONString
();
}
}
else
{
if
(
bodyObj
.
containsKey
(
"raw"
))
{
returnStr
=
bodyObj
.
getString
(
"raw"
);
}
}
}
else
if
(
StringUtils
.
equalsAny
(
type
,
"XML"
,
"Raw"
))
{
if
(
bodyObj
.
containsKey
(
"raw"
))
{
String
raw
=
bodyObj
.
getString
(
"raw"
);
returnStr
=
raw
;
}
}
else
if
(
StringUtils
.
equalsAny
(
type
,
"Form Data"
,
"WWW_FORM"
))
{
Map
<
String
,
String
>
paramMap
=
new
LinkedHashMap
<>();
if
(
bodyObj
.
containsKey
(
"kvs"
))
{
JSONArray
bodyParamArr
=
new
JSONArray
();
JSONArray
kvsArr
=
bodyObj
.
getJSONArray
(
"kvs"
);
for
(
int
i
=
0
;
i
<
kvsArr
.
size
();
i
++)
{
JSONObject
kv
=
kvsArr
.
getJSONObject
(
i
);
if
(
kv
.
containsKey
(
"name"
))
{
String
values
=
kv
.
getString
(
"value"
);
if
(
StringUtils
.
isEmpty
(
values
))
{
values
=
""
;
}
else
{
try
{
values
=
values
.
startsWith
(
"@"
)
?
ScriptEngineUtils
.
buildFunctionCallString
(
values
)
:
values
;
}
catch
(
Exception
e
)
{
}
}
paramMap
.
put
(
kv
.
getString
(
"name"
),
values
);
}
}
}
returnStr
=
JSONObject
.
toJSONString
(
paramMap
);
//Binary的先不处理
// } else if (StringUtils.equals(type, "BINARY")) {
// Map<String, String> paramMap = new LinkedHashMap<>();
// if (bodyObj.containsKey("binary")) {
// JSONArray kvsArr = bodyObj.getJSONArray("kvs");
// for (int i = 0; i < kvsArr.size(); i++) {
// JSONObject kv = kvsArr.getJSONObject(i);
// if (kv.containsKey("description") && kv.containsKey("files")) {
// String name = kv.getString("description");
// JSONArray fileArr = kv.getJSONArray("files");
// String allValue = "";
// for (int j = 0; j < fileArr.size(); j++) {
// JSONObject fileObj = fileArr.getJSONObject(j);
// if (fileObj.containsKey("name")) {
// String values = fileObj.getString("name");
// if (StringUtils.isEmpty(values)) {
// values = "";
// } else {
// try {
// values = values.startsWith("@") ? ScriptEngineUtils.buildFunctionCallString(values) : values;
// } catch (Exception e) {
// }
// }
//
// allValue += values + " ;";
// }
// }
// paramMap.put(name, allValue);
// }
// }
// }
// returnStr = JSONObject.toJSONString(paramMap);
}
}
}
}
if
(
StringUtils
.
isNotEmpty
(
returnStr
)
&&
status
==
404
)
{
status
=
200
;
}
response
.
setStatus
(
status
);
}
}
}
catch
(
Exception
e
)
{
LogUtil
.
error
(
e
);
}
return
returnStr
;
}
public
MockExpectConfigWithBLOBs
findMockExpectConfigById
(
String
id
)
{
return
mockExpectConfigMapper
.
selectByPrimaryKey
(
id
);
}
...
...
This diff is collapsed.
Click to expand it.
frontend/src/business/components/api/automation/scenario/component/ComponentConfig.vue
+
40
-
42
View file @
f641f6f6
<
template
>
<div
class=
"request-form"
>
<keep-alive>
<component
v-bind:is=
"component"
:isMax=
"isMax"
:show-btn=
"showBtn"
:show-version =
"showVersion"
:expandedNode=
"expandedNode"
:scenario=
"scenario"
:controller=
"scenario"
:timer=
"scenario"
:assertions=
"scenario"
:extract=
"scenario"
:jsr223-processor=
"scenario"
:request=
"scenario"
:currentScenario=
"currentScenario"
:currentEnvironmentId=
"currentEnvironmentId"
:node=
"node"
:draggable=
"draggable"
:title=
"title"
:color=
"titleColor"
:response=
"response"
:environment-type=
"environmentType"
:environment-group-id=
"envGroupId"
:background-color=
"backgroundColor"
:project-list=
"projectList"
:env-map=
"envMap"
:message=
"message"
:api-id=
"apiId"
:scenario-definition=
"scenarioDefinition"
:if-from-variable-advance=
"ifFromVariableAdvance"
@
suggestClick=
"suggestClick(node)"
@
remove=
"remove"
@
runScenario=
"runScenario"
@
stopScenario=
"stopScenario"
@
copyRow=
"copyRow"
@
refReload=
"refReload"
@
openScenario=
"openScenario"
@
setDomain=
"setDomain"
@
savePreParams=
"savePreParams"
@
editScenarioAdvance=
"editScenarioAdvance"
/>
</keep-alive>
<component
v-bind:is=
"component"
:isMax=
"isMax"
:show-btn=
"showBtn"
:show-version=
"showVersion"
:expandedNode=
"expandedNode"
:scenario=
"scenario"
:controller=
"scenario"
:timer=
"scenario"
:assertions=
"scenario"
:extract=
"scenario"
:jsr223-processor=
"scenario"
:request=
"scenario"
:currentScenario=
"currentScenario"
:currentEnvironmentId=
"currentEnvironmentId"
:node=
"node"
:draggable=
"draggable"
:title=
"title"
:color=
"titleColor"
:response=
"response"
:environment-type=
"environmentType"
:environment-group-id=
"envGroupId"
:background-color=
"backgroundColor"
:project-list=
"projectList"
:env-map=
"envMap"
:message=
"message"
:api-id=
"apiId"
:scenario-definition=
"scenarioDefinition"
:if-from-variable-advance=
"ifFromVariableAdvance"
@
suggestClick=
"suggestClick(node)"
@
remove=
"remove"
@
runScenario=
"runScenario"
@
stopScenario=
"stopScenario"
@
copyRow=
"copyRow"
@
refReload=
"refReload"
@
openScenario=
"openScenario"
@
setDomain=
"setDomain"
@
savePreParams=
"savePreParams"
@
editScenarioAdvance=
"editScenarioAdvance"
/>
</div>
</
template
>
...
...
This diff is collapsed.
Click to expand it.
frontend/src/business/components/common/json-schema/schema/editor/mock/MockComplete.vue
+
5
-
2
View file @
f641f6f6
...
...
@@ -67,8 +67,11 @@
},
methods
:
{
funcSearch
(
queryString
,
cb
)
{
let
funcs
=
MOCKJS_FUNC
.
concat
(
JMETER_FUNC
);
let
results
=
queryString
?
funcs
.
filter
(
this
.
funcFilter
(
queryString
))
:
funcs
;
let
results
=
[];
if
(
!
this
.
showMockVars
){
let
funcs
=
MOCKJS_FUNC
.
concat
(
JMETER_FUNC
);
results
=
queryString
?
funcs
.
filter
(
this
.
funcFilter
(
queryString
))
:
funcs
;
}
// 调用 callback 返回建议列表的数据
cb
(
results
);
},
...
...
This diff is collapsed.
Click to expand it.
xpack
@
fe459365
Compare
f12e0406
...
fe459365
Subproject commit f
12e04064dc1288becfa63c48c4db59dc5322292
Subproject commit f
e4593657ec9d2733ad31057fa636a3562e38230
This diff is collapsed.
Click to expand it.
frontend/src/i18n/en-US.js
+
1
-
0
View file @
f641f6f6
...
...
@@ -3056,6 +3056,7 @@ export default {
error_report_library
:
{
name
:
"
Error report
"
,
assertion
:
"
Error code assertion
"
,
tips
:
"
Tips: Use error report in
\"
Project Settings - Project environment-Assertions
\"
"
,
use_error_report
:
"
Use error code
"
,
use_desc
:
"
In case of conflict between error code and error assertions, it is treated as error code
"
,
option
:
{
...
...
This diff is collapsed.
Click to expand it.
frontend/src/i18n/zh-CN.js
+
1
-
0
View file @
f641f6f6
...
...
@@ -3060,6 +3060,7 @@ export default {
error_report_library
:
{
name
:
"
误报库
"
,
assertion
:
"
误报断言
"
,
tips
:
"
注:在
\"
项目设置-设置环境-全局断言
\"
中启用误报将进行以下规则匹配
"
,
use_error_report
:
"
启用误报
"
,
use_desc
:
"
失败断言与误报规则冲突时统一处理为误报
"
,
option
:
{
...
...
This diff is collapsed.
Click to expand it.
frontend/src/i18n/zh-TW.js
+
1
-
0
View file @
f641f6f6
...
...
@@ -3059,6 +3059,7 @@ export default {
error_report_library
:
{
name
:
"
誤報庫
"
,
assertion
:
"
誤報斷言
"
,
tips
:
"
注:在
\"
項目設置-設置環境-全局斷言
\"
中啟用誤報將進行以下規則匹配
"
,
use_error_report
:
"
啟用誤報
"
,
use_desc
:
"
失敗斷言與誤報規則衝突時統一處理為誤報
"
,
option
:
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment