Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MeterSphere
metersphere
提交
4e0b340c
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,发现更多精彩内容 >>
提交
4e0b340c
编写于
8月 10, 2020
作者:
C
chenjianxing
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(接口测试): 单接口调试
上级
18eb1827
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
201 addition
and
115 deletion
+201
-115
backend/src/main/java/io/metersphere/api/controller/APITestController.java
...java/io/metersphere/api/controller/APITestController.java
+7
-7
backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java
...a/io/metersphere/api/jmeter/APIBackendListenerClient.java
+24
-3
backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java
...rc/main/java/io/metersphere/api/jmeter/JMeterService.java
+9
-3
backend/src/main/java/io/metersphere/api/service/APIReportService.java
...ain/java/io/metersphere/api/service/APIReportService.java
+15
-6
backend/src/main/java/io/metersphere/api/service/APITestService.java
.../main/java/io/metersphere/api/service/APITestService.java
+24
-32
backend/src/main/java/io/metersphere/commons/constants/APITestStatus.java
.../java/io/metersphere/commons/constants/APITestStatus.java
+1
-1
backend/src/main/java/io/metersphere/commons/constants/ApiRunMode.java
...ain/java/io/metersphere/commons/constants/ApiRunMode.java
+5
-0
frontend/src/business/components/api/report/components/ScenarioResults.vue
...ness/components/api/report/components/ScenarioResults.vue
+1
-1
frontend/src/business/components/api/test/ApiTestConfig.vue
frontend/src/business/components/api/test/ApiTestConfig.vue
+32
-24
frontend/src/business/components/api/test/components/ApiScenarioConfig.vue
...ness/components/api/test/components/ApiScenarioConfig.vue
+18
-4
frontend/src/business/components/api/test/components/request/ApiHttpRequestForm.vue
...onents/api/test/components/request/ApiHttpRequestForm.vue
+13
-0
frontend/src/business/components/api/test/components/request/ApiRequestConfig.vue
...mponents/api/test/components/request/ApiRequestConfig.vue
+1
-1
frontend/src/business/components/api/test/components/request/ApiRequestForm.vue
...components/api/test/components/request/ApiRequestForm.vue
+48
-32
frontend/src/business/components/api/test/model/ScenarioModel.js
...d/src/business/components/api/test/model/ScenarioModel.js
+3
-1
未找到文件。
backend/src/main/java/io/metersphere/api/controller/APITestController.java
浏览文件 @
4e0b340c
...
...
@@ -60,13 +60,13 @@ public class APITestController {
}
@PostMapping
(
value
=
"/create"
,
consumes
=
{
"multipart/form-data"
})
public
void
create
(
@RequestPart
(
"request"
)
SaveAPITestRequest
request
,
@RequestPart
(
value
=
"file
s"
)
List
<
MultipartFile
>
files
)
{
apiTestService
.
create
(
request
,
file
s
);
public
void
create
(
@RequestPart
(
"request"
)
SaveAPITestRequest
request
,
@RequestPart
(
value
=
"file
"
)
MultipartFile
file
)
{
apiTestService
.
create
(
request
,
file
);
}
@PostMapping
(
value
=
"/update"
,
consumes
=
{
"multipart/form-data"
})
public
void
update
(
@RequestPart
(
"request"
)
SaveAPITestRequest
request
,
@RequestPart
(
value
=
"file
s"
)
List
<
MultipartFile
>
files
)
{
apiTestService
.
update
(
request
,
file
s
);
public
void
update
(
@RequestPart
(
"request"
)
SaveAPITestRequest
request
,
@RequestPart
(
value
=
"file
"
)
MultipartFile
file
)
{
apiTestService
.
update
(
request
,
file
);
}
@PostMapping
(
value
=
"/copy"
)
...
...
@@ -89,9 +89,9 @@ public class APITestController {
return
apiTestService
.
run
(
request
);
}
@PostMapping
(
value
=
"/run/
independent
"
,
consumes
=
{
"multipart/form-data"
})
public
String
run
Independent
(
@RequestBody
SaveAPITestRequest
request
,
@RequestPart
(
value
=
"files"
)
List
<
MultipartFile
>
files
)
{
return
apiTestService
.
run
Independent
(
request
,
files
);
@PostMapping
(
value
=
"/run/
debug
"
,
consumes
=
{
"multipart/form-data"
})
public
String
run
Debug
(
@RequestPart
(
"request"
)
SaveAPITestRequest
request
,
@RequestPart
(
value
=
"file"
)
MultipartFile
file
)
{
return
apiTestService
.
run
Debug
(
request
,
file
);
}
@PostMapping
(
value
=
"/import"
,
consumes
=
{
"multipart/form-data"
})
...
...
backend/src/main/java/io/metersphere/api/jmeter/APIBackendListenerClient.java
浏览文件 @
4e0b340c
...
...
@@ -2,7 +2,9 @@ package io.metersphere.api.jmeter;
import
io.metersphere.api.service.APIReportService
;
import
io.metersphere.api.service.APITestService
;
import
io.metersphere.base.domain.ApiTestReport
;
import
io.metersphere.commons.constants.APITestStatus
;
import
io.metersphere.commons.constants.ApiRunMode
;
import
io.metersphere.commons.utils.CommonBeanFactory
;
import
io.metersphere.commons.utils.LogUtil
;
import
org.apache.commons.lang3.StringUtils
;
...
...
@@ -31,12 +33,16 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
private
APIReportService
apiReportService
;
public
String
runMode
=
ApiRunMode
.
RUN
.
name
();
// 测试ID
private
String
testId
;
private
String
debugReportId
;
@Override
public
void
setupTest
(
BackendListenerContext
context
)
throws
Exception
{
this
.
testId
=
context
.
getParameter
(
TEST_ID
);
setParam
(
context
);
apiTestService
=
CommonBeanFactory
.
getBean
(
APITestService
.
class
);
if
(
apiTestService
==
null
)
{
LogUtil
.
error
(
"apiTestService is required"
);
...
...
@@ -99,8 +105,14 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
testResult
.
getScenarios
().
addAll
(
scenarios
.
values
());
testResult
.
getScenarios
().
sort
(
Comparator
.
comparing
(
ScenarioResult:
:
getId
));
apiTestService
.
changeStatus
(
testId
,
APITestStatus
.
Completed
);
apiReportService
.
complete
(
testResult
);
ApiTestReport
report
=
null
;
if
(
StringUtils
.
equals
(
this
.
runMode
,
ApiRunMode
.
DEBUG
.
name
()))
{
report
=
apiReportService
.
get
(
debugReportId
);
}
else
{
apiTestService
.
changeStatus
(
testId
,
APITestStatus
.
Completed
);
report
=
apiReportService
.
getRunningReport
(
testResult
.
getTestId
());
}
apiReportService
.
complete
(
testResult
,
report
);
queue
.
clear
();
super
.
teardownTest
(
context
);
...
...
@@ -153,6 +165,15 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
}
}
private
void
setParam
(
BackendListenerContext
context
)
{
this
.
testId
=
context
.
getParameter
(
TEST_ID
);
this
.
runMode
=
context
.
getParameter
(
"runMode"
);
this
.
debugReportId
=
context
.
getParameter
(
"debugReportId"
);
if
(
StringUtils
.
isBlank
(
this
.
runMode
))
{
this
.
runMode
=
ApiRunMode
.
RUN
.
name
();
}
}
private
ResponseAssertionResult
getResponseAssertionResult
(
AssertionResult
assertionResult
)
{
ResponseAssertionResult
responseAssertionResult
=
new
ResponseAssertionResult
();
responseAssertionResult
.
setMessage
(
assertionResult
.
getFailureMessage
());
...
...
backend/src/main/java/io/metersphere/api/jmeter/JMeterService.java
浏览文件 @
4e0b340c
package
io.metersphere.api.jmeter
;
import
io.metersphere.commons.constants.ApiRunMode
;
import
io.metersphere.commons.exception.MSException
;
import
io.metersphere.commons.utils.LogUtil
;
import
io.metersphere.config.JmeterProperties
;
import
io.metersphere.i18n.Translator
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.jmeter.config.Arguments
;
import
org.apache.jmeter.save.SaveService
;
import
org.apache.jmeter.util.JMeterUtils
;
...
...
@@ -21,7 +23,7 @@ public class JMeterService {
@Resource
private
JmeterProperties
jmeterProperties
;
public
void
run
(
String
testId
,
InputStream
is
)
{
public
void
run
(
String
testId
,
String
debugReportId
,
InputStream
is
)
{
String
JMETER_HOME
=
jmeterProperties
.
getHome
();
String
JMETER_PROPERTIES
=
JMETER_HOME
+
"/bin/jmeter.properties"
;
JMeterUtils
.
loadJMeterProperties
(
JMETER_PROPERTIES
);
...
...
@@ -29,7 +31,7 @@ public class JMeterService {
try
{
Object
scriptWrapper
=
SaveService
.
loadElement
(
is
);
HashTree
testPlan
=
getHashTree
(
scriptWrapper
);
addBackendListener
(
testId
,
testPlan
);
addBackendListener
(
testId
,
debugReportId
,
testPlan
);
LocalRunner
runner
=
new
LocalRunner
(
testPlan
);
runner
.
run
();
...
...
@@ -45,11 +47,15 @@ public class JMeterService {
return
(
HashTree
)
field
.
get
(
scriptWrapper
);
}
private
void
addBackendListener
(
String
testId
,
HashTree
testPlan
)
{
private
void
addBackendListener
(
String
testId
,
String
debugReportId
,
HashTree
testPlan
)
{
BackendListener
backendListener
=
new
BackendListener
();
backendListener
.
setName
(
testId
);
Arguments
arguments
=
new
Arguments
();
arguments
.
addArgument
(
APIBackendListenerClient
.
TEST_ID
,
testId
);
if
(
StringUtils
.
isNotBlank
(
debugReportId
))
{
arguments
.
addArgument
(
"runMode"
,
ApiRunMode
.
DEBUG
.
name
());
arguments
.
addArgument
(
"debugReportId"
,
debugReportId
);
}
backendListener
.
setArguments
(
arguments
);
backendListener
.
setClassname
(
APIBackendListenerClient
.
class
.
getCanonicalName
());
testPlan
.
add
(
testPlan
.
getArray
()[
0
],
backendListener
);
...
...
backend/src/main/java/io/metersphere/api/service/APIReportService.java
浏览文件 @
4e0b340c
...
...
@@ -10,10 +10,12 @@ import io.metersphere.base.mapper.ApiTestReportDetailMapper;
import
io.metersphere.base.mapper.ApiTestReportMapper
;
import
io.metersphere.base.mapper.ext.ExtApiTestReportMapper
;
import
io.metersphere.commons.constants.APITestStatus
;
import
io.metersphere.commons.constants.ReportTriggerMode
;
import
io.metersphere.commons.exception.MSException
;
import
io.metersphere.commons.utils.ServiceUtils
;
import
io.metersphere.dto.DashboardTestDTO
;
import
io.metersphere.i18n.Translator
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
@@ -73,8 +75,7 @@ public class APIReportService {
apiTestReportDetailMapper
.
deleteByExample
(
detailExample
);
}
public
void
complete
(
TestResult
result
)
{
ApiTestReport
report
=
getRunningReport
(
result
.
getTestId
());
public
void
complete
(
TestResult
result
,
ApiTestReport
report
)
{
if
(
report
==
null
)
{
MSException
.
throwException
(
Translator
.
get
(
"api_report_is_null"
));
}
...
...
@@ -87,10 +88,12 @@ public class APIReportService {
// report
report
.
setUpdateTime
(
System
.
currentTimeMillis
());
if
(
result
.
getError
()
>
0
)
{
report
.
setStatus
(
APITestStatus
.
Error
.
name
());
}
else
{
report
.
setStatus
(
APITestStatus
.
Success
.
name
());
if
(!
StringUtils
.
equals
(
report
.
getStatus
(),
APITestStatus
.
Debug
.
name
()))
{
if
(
result
.
getError
()
>
0
)
{
report
.
setStatus
(
APITestStatus
.
Error
.
name
());
}
else
{
report
.
setStatus
(
APITestStatus
.
Success
.
name
());
}
}
apiTestReportMapper
.
updateByPrimaryKeySelective
(
report
);
...
...
@@ -106,6 +109,12 @@ public class APIReportService {
return
report
.
getId
();
}
public
String
createDebugReport
(
ApiTest
test
)
{
ApiTestReport
report
=
buildReport
(
test
,
ReportTriggerMode
.
MANUAL
.
name
(),
APITestStatus
.
Debug
.
name
());
apiTestReportMapper
.
insert
(
report
);
return
report
.
getId
();
}
public
ApiTestReport
buildReport
(
ApiTest
test
,
String
triggerMode
,
String
status
)
{
ApiTestReport
report
=
new
ApiTestReport
();
report
.
setId
(
UUID
.
randomUUID
().
toString
());
...
...
backend/src/main/java/io/metersphere/api/service/APITestService.java
浏览文件 @
4e0b340c
...
...
@@ -12,10 +12,7 @@ import io.metersphere.base.domain.*;
import
io.metersphere.base.mapper.ApiTestFileMapper
;
import
io.metersphere.base.mapper.ApiTestMapper
;
import
io.metersphere.base.mapper.ext.ExtApiTestMapper
;
import
io.metersphere.commons.constants.APITestStatus
;
import
io.metersphere.commons.constants.FileType
;
import
io.metersphere.commons.constants.ScheduleGroup
;
import
io.metersphere.commons.constants.ScheduleType
;
import
io.metersphere.commons.constants.*
;
import
io.metersphere.commons.exception.MSException
;
import
io.metersphere.commons.utils.BeanUtils
;
import
io.metersphere.commons.utils.LogUtil
;
...
...
@@ -73,21 +70,21 @@ public class APITestService {
return
extApiTestMapper
.
list
(
request
);
}
public
void
create
(
SaveAPITestRequest
request
,
List
<
MultipartFile
>
files
)
{
if
(
file
s
==
null
||
files
.
isEmpty
()
)
{
public
void
create
(
SaveAPITestRequest
request
,
MultipartFile
file
)
{
if
(
file
==
null
)
{
throw
new
IllegalArgumentException
(
Translator
.
get
(
"file_cannot_be_null"
));
}
ApiTest
test
=
createTest
(
request
);
saveFile
(
test
.
getId
(),
file
s
);
saveFile
(
test
.
getId
(),
file
);
}
public
void
update
(
SaveAPITestRequest
request
,
List
<
MultipartFile
>
files
)
{
if
(
file
s
==
null
||
files
.
isEmpty
()
)
{
public
void
update
(
SaveAPITestRequest
request
,
MultipartFile
file
)
{
if
(
file
==
null
)
{
throw
new
IllegalArgumentException
(
Translator
.
get
(
"file_cannot_be_null"
));
}
deleteFileByTestId
(
request
.
getId
());
ApiTest
test
=
updateTest
(
request
);
saveFile
(
test
.
getId
(),
file
s
);
saveFile
(
test
.
getId
(),
file
);
}
public
void
copy
(
SaveAPITestRequest
request
)
{
...
...
@@ -157,7 +154,7 @@ public class APITestService {
String
reportId
=
apiReportService
.
create
(
apiTest
,
request
.
getTriggerMode
());
changeStatus
(
request
.
getId
(),
APITestStatus
.
Running
);
jMeterService
.
run
(
request
.
getId
(),
is
);
jMeterService
.
run
(
request
.
getId
(),
null
,
is
);
return
reportId
;
}
...
...
@@ -204,14 +201,12 @@ public class APITestService {
return
test
;
}
private
void
saveFile
(
String
testId
,
List
<
MultipartFile
>
files
)
{
files
.
forEach
(
file
->
{
final
FileMetadata
fileMetadata
=
fileService
.
saveFile
(
file
);
ApiTestFile
apiTestFile
=
new
ApiTestFile
();
apiTestFile
.
setTestId
(
testId
);
apiTestFile
.
setFileId
(
fileMetadata
.
getId
());
apiTestFileMapper
.
insert
(
apiTestFile
);
});
private
void
saveFile
(
String
testId
,
MultipartFile
file
)
{
final
FileMetadata
fileMetadata
=
fileService
.
saveFile
(
file
);
ApiTestFile
apiTestFile
=
new
ApiTestFile
();
apiTestFile
.
setTestId
(
testId
);
apiTestFile
.
setFileId
(
fileMetadata
.
getId
());
apiTestFileMapper
.
insert
(
apiTestFile
);
}
private
void
deleteFileByTestId
(
String
testId
)
{
...
...
@@ -330,13 +325,17 @@ public class APITestService {
return
schedules
;
}
public
String
run
Independent
(
SaveAPITestRequest
request
,
List
<
MultipartFile
>
files
)
{
if
(
file
s
==
null
||
files
.
isEmpty
()
)
{
public
String
run
Debug
(
SaveAPITestRequest
request
,
MultipartFile
file
)
{
if
(
file
==
null
)
{
throw
new
IllegalArgumentException
(
Translator
.
get
(
"file_cannot_be_null"
));
}
// ApiTest test = createTest(request);
// saveFile(test.getId(), files);
MultipartFile
file
=
files
.
get
(
0
);
updateTest
(
request
);
APITestResult
apiTest
=
get
(
request
.
getId
());
if
(
SessionUtils
.
getUser
()
==
null
)
{
apiTest
.
setUserId
(
request
.
getUserId
());
}
String
reportId
=
apiReportService
.
createDebugReport
(
apiTest
);
InputStream
is
=
null
;
try
{
is
=
new
ByteArrayInputStream
(
file
.
getBytes
());
...
...
@@ -344,14 +343,7 @@ public class APITestService {
LogUtil
.
error
(
e
);
}
APITestResult
apiTest
=
get
(
request
.
getId
());
if
(
SessionUtils
.
getUser
()
==
null
)
{
apiTest
.
setUserId
(
request
.
getUserId
());
}
String
reportId
=
apiReportService
.
create
(
apiTest
,
request
.
getTriggerMode
());
changeStatus
(
request
.
getId
(),
APITestStatus
.
Running
);
jMeterService
.
run
(
request
.
getId
(),
is
);
jMeterService
.
run
(
request
.
getId
(),
reportId
,
is
);
return
reportId
;
}
}
backend/src/main/java/io/metersphere/commons/constants/APITestStatus.java
浏览文件 @
4e0b340c
package
io.metersphere.commons.constants
;
public
enum
APITestStatus
{
Saved
,
Starting
,
Running
,
Reporting
,
Completed
,
Error
,
Success
Saved
,
Starting
,
Running
,
Reporting
,
Completed
,
Debug
,
Error
,
Success
}
backend/src/main/java/io/metersphere/commons/constants/ApiRunMode.java
0 → 100644
浏览文件 @
4e0b340c
package
io.metersphere.commons.constants
;
public
enum
ApiRunMode
{
RUN
,
DEBUG
}
frontend/src/business/components/api/report/components/ScenarioResults.vue
浏览文件 @
4e0b340c
...
...
@@ -32,7 +32,7 @@
components
:
{
MsScenarioResult
},
props
:
{
scenarios
:
Array
scenarios
:
Array
,
}
}
...
...
frontend/src/business/components/api/test/ApiTestConfig.vue
浏览文件 @
4e0b340c
...
...
@@ -55,7 +55,7 @@
<ms-schedule-config
:schedule=
"test.schedule"
:is-read-only=
"isReadOnly"
:save=
"saveCronExpression"
@
scheduleChange=
"saveSchedule"
:check-open=
"checkScheduleEdit"
/>
</el-row>
</el-header>
<ms-api-scenario-config
:is-read-only=
"isReadOnly"
:scenarios=
"test.scenarioDefinition"
:project-id=
"test.projectId"
ref=
"config"
/>
<ms-api-scenario-config
:
debug-report-id=
"debugReportId"
@
runDebug=
"runDebug"
:
is-read-only=
"isReadOnly"
:scenarios=
"test.scenarioDefinition"
:project-id=
"test.projectId"
ref=
"config"
/>
</el-container>
</el-card>
</div>
...
...
@@ -86,7 +86,8 @@
projects
:
[],
change
:
false
,
test
:
new
Test
(),
isReadOnly
:
false
isReadOnly
:
false
,
debugReportId
:
''
}
},
...
...
@@ -149,9 +150,12 @@
}
this
.
change
=
false
;
let
url
=
this
.
create
?
"
/api/create
"
:
"
/api/update
"
;
this
.
result
=
this
.
$request
(
this
.
getOptions
(
url
),
()
=>
{
this
.
create
=
false
;
let
jmx
=
this
.
test
.
toJMX
();
let
blob
=
new
Blob
([
jmx
.
xml
],
{
type
:
"
application/octet-stream
"
});
let
file
=
new
File
([
blob
],
jmx
.
name
);
this
.
result
=
this
.
$fileUpload
(
url
,
file
,
this
.
test
,
response
=>
{
if
(
callback
)
callback
();
this
.
create
=
false
;
});
},
saveTest
()
{
...
...
@@ -183,26 +187,6 @@
cancel
()
{
this
.
$router
.
push
(
'
/api/test/list/all
'
);
},
getOptions
(
url
)
{
let
formData
=
new
FormData
();
let
requestJson
=
JSON
.
stringify
(
this
.
test
);
formData
.
append
(
'
request
'
,
new
Blob
([
requestJson
],
{
type
:
"
application/json
"
}));
let
jmx
=
this
.
test
.
toJMX
();
let
blob
=
new
Blob
([
jmx
.
xml
],
{
type
:
"
application/octet-stream
"
});
formData
.
append
(
"
files
"
,
new
File
([
blob
],
jmx
.
name
));
return
{
method
:
'
POST
'
,
url
:
url
,
data
:
formData
,
headers
:
{
'
Content-Type
'
:
undefined
}
};
},
handleCommand
(
command
)
{
switch
(
command
)
{
case
"
report
"
:
...
...
@@ -251,6 +235,30 @@
return
false
;
}
return
true
;
},
runDebug
(
scenario
)
{
if
(
this
.
create
)
{
this
.
$warning
(
this
.
$t
(
'
api_test.environment.please_save_test
'
));
return
;
}
let
url
=
"
/api/run/debug
"
;
let
runningTest
=
new
Test
();
Object
.
assign
(
runningTest
,
this
.
test
);
runningTest
.
scenarioDefinition
=
[];
runningTest
.
scenarioDefinition
.
push
(
scenario
);
let
validator
=
runningTest
.
isValid
();
if
(
!
validator
.
isValid
)
{
this
.
$warning
(
this
.
$t
(
validator
.
info
));
return
;
}
let
jmx
=
runningTest
.
toJMX
();
let
blob
=
new
Blob
([
jmx
.
xml
],
{
type
:
"
application/octet-stream
"
});
let
file
=
new
File
([
blob
],
jmx
.
name
);
this
.
$fileUpload
(
url
,
file
,
this
.
test
,
response
=>
{
this
.
debugReportId
=
response
.
data
;
});
}
},
...
...
frontend/src/business/components/api/test/components/ApiScenarioConfig.vue
浏览文件 @
4e0b340c
...
...
@@ -36,7 +36,7 @@
<el-main
class=
"scenario-main"
>
<div
class=
"scenario-form"
>
<ms-api-scenario-form
:is-read-only=
"isReadOnly"
:scenario=
"selected"
:project-id=
"projectId"
v-if=
"isScenario"
/>
<ms-api-request-form
:is-read-only=
"isReadOnly"
:request=
"selected"
v-if=
"isRequest"
/>
<ms-api-request-form
:
debug-report-id=
"debugReportId"
@
runDebug=
"runDebug"
:
is-read-only=
"isReadOnly"
:request=
"selected"
v-if=
"isRequest"
/>
</div>
</el-main>
</el-container>
...
...
@@ -70,13 +70,15 @@
isReadOnly
:
{
type
:
Boolean
,
default
:
false
}
},
debugReportId
:
String
},
data
()
{
return
{
activeName
:
0
,
selected
:
[
Scenario
,
Request
]
selected
:
[
Scenario
,
Request
],
currentScenario
:
{}
}
},
...
...
@@ -118,9 +120,14 @@
break
;
}
},
select
:
function
(
obj
)
{
select
:
function
(
obj
,
scenario
)
{
this
.
selected
=
null
;
this
.
$nextTick
(
function
()
{
if
(
obj
instanceof
Scenario
)
{
this
.
currentScenario
=
obj
;
}
else
{
this
.
currentScenario
=
scenario
;
}
this
.
selected
=
obj
;
});
},
...
...
@@ -145,6 +152,13 @@
});
});
}
},
runDebug
(
request
)
{
let
scenario
=
new
Scenario
();
Object
.
assign
(
scenario
,
this
.
currentScenario
);
scenario
.
requests
=
[];
scenario
.
requests
.
push
(
request
);
this
.
$emit
(
'
runDebug
'
,
scenario
);
}
},
...
...
frontend/src/business/components/api/test/components/request/ApiHttpRequestForm.vue
浏览文件 @
4e0b340c
...
...
@@ -39,6 +39,8 @@
</el-switch>
</el-form-item>
<el-button
class=
"debug-button"
size=
"small"
type=
"primary"
@
click=
"runDebug"
>
{{$t('load_test.save_and_run')}}
</el-button>
<el-tabs
v-model=
"activeName"
>
<el-tab-pane
:label=
"$t('api_test.request.parameters')"
name=
"parameters"
>
<ms-api-key-value
:is-read-only=
"isReadOnly"
:items=
"request.parameters"
...
...
@@ -154,6 +156,9 @@
}
}
return
url
;
},
runDebug
()
{
this
.
$emit
(
'
runDebug
'
);
}
},
...
...
@@ -192,4 +197,12 @@
color
:
#F56C6C
;
}
.debug-button
{
margin-left
:
auto
;
display
:
block
;
/*margin-bottom: -30px;*/
margin-right
:
10px
;
z-index
:
1999
;
}
</
style
>
frontend/src/business/components/api/test/components/request/ApiRequestConfig.vue
浏览文件 @
4e0b340c
...
...
@@ -112,7 +112,7 @@
}
request
.
dubboConfig
=
this
.
scenario
.
dubboConfig
;
this
.
selected
=
request
;
this
.
$emit
(
"
select
"
,
request
);
this
.
$emit
(
"
select
"
,
request
,
this
.
scenario
);
}
},
...
...
frontend/src/business/components/api/test/components/request/ApiRequestForm.vue
浏览文件 @
4e0b340c
<
template
>
<div>
<component
:is=
"component"
:is-read-only=
"isReadOnly"
:request=
"request"
/>
<!--
<ms-scenario-results
:scenarios=
"content.scenarios"
/>
--
>
<component
@
runDebug=
"runDebug"
:is=
"component"
:is-read-only=
"isReadOnly"
:request=
"request"
/>
<ms-scenario-results
v-loading=
"debugReportLoading"
v-if=
"isCompleted"
:scenarios=
"isCompleted ? request.debugReport.scenarios : []"
/
>
</div>
</
template
>
...
...
@@ -19,12 +19,15 @@
isReadOnly
:
{
type
:
Boolean
,
default
:
false
}
},
debugReportId
:
String
},
data
()
{
return
{
reportId
:
""
,
content
:{}
content
:
{
scenarios
:[]},
debugReportLoading
:
false
,
showDebugReport
:
false
}
},
computed
:
{
...
...
@@ -38,38 +41,51 @@
name
=
"
MsApiHttpRequestForm
"
;
}
return
name
;
},
isCompleted
()
{
return
!!
this
.
request
.
debugReport
;
}
},
created
()
{
this
.
getReport
();
watch
:
{
debugReportId
()
{
this
.
getReport
();
}
},
methods
:
{
getReport
()
{
// // this.reportId = "00143d36-a58a-477e-a05a-556c1d48046c";
// if (this.reportId) {
// let url = "/api/report/get/" + this.reportId;
// this.$get(url, response => {
// let report = response.data || {};
// if (response.data) {
// // if (this.isNotRunning) {
// try {
// this.content = JSON.parse(report.content);
// } catch (e) {
// console.log(report.content)
// throw e;
// }
// // this.getFails();
// // this.loading = false;
// // }
// // else {
// // setTimeout(this.getReport, 2000)
// // }
// } else {
// this.loading = false;
// this.$error(this.$t('api_report.not_exist'));
// }
// });
// }
if
(
this
.
debugReportId
)
{
this
.
debugReportLoading
=
true
;
this
.
showDebugReport
=
true
;
this
.
request
.
debugReport
=
{};
let
url
=
"
/api/report/get/
"
+
this
.
debugReportId
;
this
.
$get
(
url
,
response
=>
{
let
report
=
response
.
data
||
{};
let
res
=
{};
if
(
response
.
data
)
{
try
{
res
=
JSON
.
parse
(
report
.
content
);
}
catch
(
e
)
{
console
.
log
(
report
.
content
)
throw
e
;
}
if
(
res
)
{
this
.
debugReportLoading
=
false
;
this
.
request
.
debugReport
=
res
;
this
.
deleteReport
(
this
.
debugReportId
)
}
else
{
setTimeout
(
this
.
getReport
,
2000
)
}
}
else
{
this
.
debugReportLoading
=
false
;
}
});
}
},
deleteReport
(
reportId
)
{
this
.
$post
(
'
/api/report/delete
'
,
{
id
:
reportId
});
},
runDebug
()
{
this
.
$emit
(
'
runDebug
'
,
this
.
request
);
}
}
}
...
...
@@ -78,7 +94,7 @@
<
style
scoped
>
.scenario-results
{
margin-top
:
15
px
;
margin-top
:
20
px
;
}
</
style
>
frontend/src/business/components/api/test/model/ScenarioModel.js
浏览文件 @
4e0b340c
...
...
@@ -297,6 +297,7 @@ export class HttpRequest extends Request {
this
.
extract
=
undefined
;
this
.
environment
=
undefined
;
this
.
useEnvironment
=
undefined
;
this
.
debugReport
=
undefined
;
this
.
set
(
options
);
this
.
sets
({
parameters
:
KeyValue
,
headers
:
KeyValue
},
options
);
...
...
@@ -370,6 +371,7 @@ export class DubboRequest extends Request {
this
.
extract
=
new
Extract
(
options
.
extract
);
// Scenario.dubboConfig
this
.
dubboConfig
=
undefined
;
this
.
debugReport
=
undefined
;
this
.
sets
({
args
:
KeyValue
,
attachmentArgs
:
KeyValue
},
options
);
}
...
...
@@ -683,7 +685,7 @@ const JMX_ASSERTION_CONDITION = {
class
JMXHttpRequest
{
constructor
(
request
,
environment
)
{
if
(
request
&&
request
instanceof
HttpRequest
&&
(
request
.
url
||
request
.
path
)
)
{
if
(
request
&&
request
instanceof
HttpRequest
)
{
this
.
useEnvironment
=
request
.
useEnvironment
;
this
.
method
=
request
.
method
;
if
(
!
request
.
useEnvironment
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录