Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
holmes
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
QA
holmes
Commits
0897055e
Commit
0897055e
authored
Apr 02, 2021
by
黎博
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新一大波
parent
bfba25e9
Changes
27
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
27 changed files
with
754 additions
and
279 deletions
+754
-279
pom.xml
pom.xml
+6
-0
SingleTestcaseExecution.java
...ain/java/cn/qg/holmes/common/SingleTestcaseExecution.java
+0
-29
TestExecutionController.java
...cn/qg/holmes/controller/auto/TestExecutionController.java
+28
-0
Interface.java
src/main/java/cn/qg/holmes/entity/auto/Interface.java
+30
-0
Project.java
src/main/java/cn/qg/holmes/entity/auto/Project.java
+24
-0
Scene.java
src/main/java/cn/qg/holmes/entity/auto/Scene.java
+25
-0
SceneTestcase.java
src/main/java/cn/qg/holmes/entity/auto/SceneTestcase.java
+30
-0
Testcase.java
src/main/java/cn/qg/holmes/entity/auto/Testcase.java
+4
-1
InterfaceMapper.java
src/main/java/cn/qg/holmes/mapper/auto/InterfaceMapper.java
+7
-0
ProjectMapper.java
src/main/java/cn/qg/holmes/mapper/auto/ProjectMapper.java
+7
-0
SceneMapper.java
src/main/java/cn/qg/holmes/mapper/auto/SceneMapper.java
+7
-0
SceneTestcaseMapper.java
...in/java/cn/qg/holmes/mapper/auto/SceneTestcaseMapper.java
+7
-0
TestcaseMapper.java
src/main/java/cn/qg/holmes/mapper/auto/TestcaseMapper.java
+7
-0
AutoUtilsService.java
...main/java/cn/qg/holmes/service/auto/AutoUtilsService.java
+15
-0
InterfaceService.java
...main/java/cn/qg/holmes/service/auto/InterfaceService.java
+7
-0
ProjectService.java
src/main/java/cn/qg/holmes/service/auto/ProjectService.java
+7
-0
SceneService.java
src/main/java/cn/qg/holmes/service/auto/SceneService.java
+7
-0
SceneTestcaseService.java
.../java/cn/qg/holmes/service/auto/SceneTestcaseService.java
+9
-0
TestcaseService.java
src/main/java/cn/qg/holmes/service/auto/TestcaseService.java
+9
-0
AutoUtilsServiceImpl.java
.../cn/qg/holmes/service/auto/impl/AutoUtilsServiceImpl.java
+127
-0
InterfaceServiceImpl.java
.../cn/qg/holmes/service/auto/impl/InterfaceServiceImpl.java
+11
-0
ProjectServiceImpl.java
...va/cn/qg/holmes/service/auto/impl/ProjectServiceImpl.java
+11
-0
SceneServiceImpl.java
...java/cn/qg/holmes/service/auto/impl/SceneServiceImpl.java
+12
-0
SceneTestcaseServiceImpl.java
...qg/holmes/service/auto/impl/SceneTestcaseServiceImpl.java
+107
-0
TestcaseServiceImpl.java
...a/cn/qg/holmes/service/auto/impl/TestcaseServiceImpl.java
+92
-0
BankCardUtils.java
src/main/java/cn/qg/holmes/utils/BankCardUtils.java
+3
-2
HttpClientUtils.java
src/main/java/cn/qg/holmes/utils/HttpClientUtils.java
+155
-247
No files found.
pom.xml
View file @
0897055e
...
@@ -123,6 +123,12 @@
...
@@ -123,6 +123,12 @@
<version>
7.3.0
</version>
<version>
7.3.0
</version>
</dependency>
</dependency>
<dependency>
<groupId>
com.jayway.jsonpath
</groupId>
<artifactId>
json-path
</artifactId>
<version>
2.5.0
</version>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
...
...
src/main/java/cn/qg/holmes/common/SingleTestcaseExecution.java
deleted
100644 → 0
View file @
bfba25e9
package
cn
.
qg
.
holmes
.
common
;
import
cn.qg.holmes.entity.auto.Testcase
;
import
org.testng.annotations.AfterClass
;
import
org.testng.annotations.BeforeClass
;
import
org.testng.annotations.Test
;
/**
* 单接口用例执行器
* @author libo
*/
public
class
SingleTestcaseExecution
{
Testcase
testcase
;
SingleTestcaseExecution
(
Testcase
testcase
)
{
this
.
testcase
=
testcase
;
}
@BeforeClass
()
public
void
beforeClass
()
{}
@Test
public
void
executeTestcase
()
{}
@AfterClass
()
public
void
afterClass
()
{}
}
src/main/java/cn/qg/holmes/controller/auto/TestExecutionController.java
0 → 100644
View file @
0897055e
package
cn
.
qg
.
holmes
.
controller
.
auto
;
import
cn.qg.holmes.service.auto.SceneTestcaseService
;
import
cn.qg.holmes.service.auto.TestcaseService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
@CrossOrigin
@RestController
@RequestMapping
(
"/execute"
)
public
class
TestExecutionController
{
@Autowired
TestcaseService
testcaseService
;
@Autowired
SceneTestcaseService
sceneTestcaseService
;
@GetMapping
(
"/testcase"
)
public
void
testSingleTestcase
(
@RequestParam
Integer
testcaseId
)
{
testcaseService
.
singleTestcaseExecutor
(
testcaseId
);
}
@GetMapping
(
"/scene"
)
public
void
testScene
(
@RequestParam
Integer
sceneId
)
{
sceneTestcaseService
.
executeSceneTestcase
(
sceneId
);
}
}
src/main/java/cn/qg/holmes/entity/auto/Interface.java
0 → 100644
View file @
0897055e
package
cn
.
qg
.
holmes
.
entity
.
auto
;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
lombok.Data
;
import
java.util.Date
;
/**
* 接口实体类
*/
@Data
public
class
Interface
{
@TableId
(
type
=
IdType
.
AUTO
)
private
Integer
id
;
private
String
name
;
private
String
url
;
private
String
method
;
private
String
headers
;
private
String
paramType
;
private
String
requestTemplate
;
private
String
responseTemplate
;
private
String
author
;
private
Integer
projectId
;
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
private
Date
createTime
;
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
private
Date
updateTime
;
}
src/main/java/cn/qg/holmes/entity/auto/Project.java
0 → 100644
View file @
0897055e
package
cn
.
qg
.
holmes
.
entity
.
auto
;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
lombok.Data
;
import
java.util.Date
;
/**
* 项目实体类
*/
@Data
public
class
Project
{
@TableId
(
type
=
IdType
.
AUTO
)
private
Integer
id
;
private
String
name
;
private
String
key
;
private
String
domain
;
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
private
Date
createTime
;
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
private
Date
updateTime
;
}
src/main/java/cn/qg/holmes/entity/auto/Scene.java
0 → 100644
View file @
0897055e
package
cn
.
qg
.
holmes
.
entity
.
auto
;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
lombok.Data
;
import
java.util.Date
;
/**
* 场景实体类
*/
@Data
@TableName
(
"scene"
)
public
class
Scene
{
@TableId
(
type
=
IdType
.
AUTO
)
private
Integer
id
;
private
String
name
;
private
Integer
projectId
;
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
private
Date
createTime
;
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
private
Date
updateTime
;
}
src/main/java/cn/qg/holmes/entity/auto/SceneTestcase.java
0 → 100644
View file @
0897055e
package
cn
.
qg
.
holmes
.
entity
.
auto
;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
lombok.Data
;
import
java.util.Date
;
@Data
@TableName
(
"scene_testcase"
)
public
class
SceneTestcase
{
@TableId
(
type
=
IdType
.
AUTO
)
private
Integer
id
;
private
Integer
sceneId
;
private
Integer
interfaceId
;
private
String
preAction
;
private
String
postAction
;
private
String
headers
;
private
String
parameters
;
private
String
variables
;
private
String
extract
;
private
String
validate
;
private
Integer
sequence
;
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
private
Date
createTime
;
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
private
Date
updateTime
;
}
src/main/java/cn/qg/holmes/entity/auto/Testcase.java
View file @
0897055e
...
@@ -16,11 +16,14 @@ import java.util.Date;
...
@@ -16,11 +16,14 @@ import java.util.Date;
public
class
Testcase
{
public
class
Testcase
{
@TableId
(
type
=
IdType
.
AUTO
)
@TableId
(
type
=
IdType
.
AUTO
)
private
Integer
id
;
private
Integer
id
;
private
String
name
;
private
Integer
interfaceId
;
private
Integer
interfaceId
;
private
String
preAction
;
private
String
preAction
;
private
String
postAction
;
private
String
postAction
;
private
String
headers
;
private
String
headers
;
private
String
parameter
;
private
String
parameters
;
private
String
variables
;
private
String
extract
;
private
String
validate
;
private
String
validate
;
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
private
Date
createTime
;
private
Date
createTime
;
...
...
src/main/java/cn/qg/holmes/mapper/auto/InterfaceMapper.java
0 → 100644
View file @
0897055e
package
cn
.
qg
.
holmes
.
mapper
.
auto
;
import
cn.qg.holmes.entity.auto.Interface
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
public
interface
InterfaceMapper
extends
BaseMapper
<
Interface
>
{
}
src/main/java/cn/qg/holmes/mapper/auto/ProjectMapper.java
0 → 100644
View file @
0897055e
package
cn
.
qg
.
holmes
.
mapper
.
auto
;
import
cn.qg.holmes.entity.auto.Project
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
public
interface
ProjectMapper
extends
BaseMapper
<
Project
>
{
}
src/main/java/cn/qg/holmes/mapper/auto/SceneMapper.java
0 → 100644
View file @
0897055e
package
cn
.
qg
.
holmes
.
mapper
.
auto
;
import
cn.qg.holmes.entity.auto.Scene
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
public
interface
SceneMapper
extends
BaseMapper
<
Scene
>
{
}
src/main/java/cn/qg/holmes/mapper/auto/SceneTestcaseMapper.java
0 → 100644
View file @
0897055e
package
cn
.
qg
.
holmes
.
mapper
.
auto
;
import
cn.qg.holmes.entity.auto.SceneTestcase
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
public
interface
SceneTestcaseMapper
extends
BaseMapper
<
SceneTestcase
>
{
}
src/main/java/cn/qg/holmes/mapper/auto/TestcaseMapper.java
0 → 100644
View file @
0897055e
package
cn
.
qg
.
holmes
.
mapper
.
auto
;
import
cn.qg.holmes.entity.auto.Testcase
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
public
interface
TestcaseMapper
extends
BaseMapper
<
Testcase
>
{
}
src/main/java/cn/qg/holmes/service/auto/AutoUtilsService.java
0 → 100644
View file @
0897055e
package
cn
.
qg
.
holmes
.
service
.
auto
;
import
java.util.List
;
import
java.util.Map
;
public
interface
AutoUtilsService
{
Map
<
String
,
String
>
replaceHeaders
(
String
headers
,
String
variables
);
Map
<
String
,
String
>
replaceParameters
(
String
parameters
,
String
variables
);
boolean
extractResponse
(
String
response
,
String
extract
);
boolean
assertResponse
(
String
response
,
List
<
Map
>
validateList
);
}
src/main/java/cn/qg/holmes/service/auto/InterfaceService.java
0 → 100644
View file @
0897055e
package
cn
.
qg
.
holmes
.
service
.
auto
;
import
cn.qg.holmes.entity.auto.Interface
;
import
com.baomidou.mybatisplus.extension.service.IService
;
public
interface
InterfaceService
extends
IService
<
Interface
>
{
}
src/main/java/cn/qg/holmes/service/auto/ProjectService.java
0 → 100644
View file @
0897055e
package
cn
.
qg
.
holmes
.
service
.
auto
;
import
cn.qg.holmes.entity.auto.Project
;
import
com.baomidou.mybatisplus.extension.service.IService
;
public
interface
ProjectService
extends
IService
<
Project
>
{
}
src/main/java/cn/qg/holmes/service/auto/SceneService.java
0 → 100644
View file @
0897055e
package
cn
.
qg
.
holmes
.
service
.
auto
;
import
cn.qg.holmes.entity.auto.Scene
;
import
com.baomidou.mybatisplus.extension.service.IService
;
public
interface
SceneService
extends
IService
<
Scene
>
{
}
src/main/java/cn/qg/holmes/service/auto/SceneTestcaseService.java
0 → 100644
View file @
0897055e
package
cn
.
qg
.
holmes
.
service
.
auto
;
import
cn.qg.holmes.entity.auto.SceneTestcase
;
import
com.baomidou.mybatisplus.extension.service.IService
;
public
interface
SceneTestcaseService
extends
IService
<
SceneTestcase
>
{
void
executeSceneTestcase
(
Integer
sceneId
);
}
src/main/java/cn/qg/holmes/service/auto/TestcaseService.java
0 → 100644
View file @
0897055e
package
cn
.
qg
.
holmes
.
service
.
auto
;
import
cn.qg.holmes.entity.auto.Testcase
;
import
com.baomidou.mybatisplus.extension.service.IService
;
public
interface
TestcaseService
extends
IService
<
Testcase
>
{
String
singleTestcaseExecutor
(
Integer
testcaseId
);
}
src/main/java/cn/qg/holmes/service/auto/impl/AutoUtilsServiceImpl.java
0 → 100644
View file @
0897055e
package
cn
.
qg
.
holmes
.
service
.
auto
.
impl
;
import
cn.qg.holmes.service.auto.AutoUtilsService
;
import
cn.qg.holmes.utils.RedisUtils
;
import
com.alibaba.fastjson.JSON
;
import
com.jayway.jsonpath.JsonPath
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
import
java.util.Map
;
/**
* @author libo
* created at 2021-03-30
*/
@Service
@Slf4j
public
class
AutoUtilsServiceImpl
implements
AutoUtilsService
{
@Autowired
RedisUtils
redisUtils
;
/**
* 将请求headers中的变量替换成对应的值
* @param headers 请求头json
* @param variables 参数json
* @return
*/
public
Map
<
String
,
String
>
replaceHeaders
(
String
headers
,
String
variables
)
{
log
.
info
(
"开始执行请求头替换!"
);
Map
<
String
,
String
>
headersMap
=
JSON
.
parseObject
(
headers
,
Map
.
class
);
Map
<
String
,
String
>
varMap
=
JSON
.
parseObject
(
variables
,
Map
.
class
);
log
.
info
(
"替换之前的headers:{}"
,
headersMap
);
log
.
info
(
"参数列表:{}"
,
varMap
);
for
(
String
key:
varMap
.
keySet
())
{
String
value
=
varMap
.
get
(
key
);
headersMap
.
put
(
key
,
redisUtils
.
get
(
value
.
substring
(
1
)).
toString
());
}
log
.
info
(
"替换之后的headers:{}"
,
headersMap
);
return
headersMap
;
}
/**
* 将请求体中的变量替换成对应的值
* @param parameters 请求参数json
* @param variables 变量json
* @return 替换后的参数Map
*/
public
Map
<
String
,
String
>
replaceParameters
(
String
parameters
,
String
variables
)
{
log
.
info
(
"开始执行请求参数替换!"
);
Map
<
String
,
String
>
parameterMap
=
JSON
.
parseObject
(
parameters
,
Map
.
class
);
Map
<
String
,
String
>
varMap
=
JSON
.
parseObject
(
variables
,
Map
.
class
);
log
.
info
(
"替换之前的参数:{}"
,
parameterMap
);
log
.
info
(
"参数列表:{}"
,
varMap
);
for
(
String
key:
varMap
.
keySet
())
{
String
value
=
varMap
.
get
(
key
);
parameterMap
.
put
(
key
,
redisUtils
.
get
(
value
.
substring
(
1
)).
toString
());
}
log
.
info
(
"替换之后的参数:{}"
,
parameterMap
);
return
parameterMap
;
}
/**
* 将响应中的值解析出来并存储到redis值
* @param response 响应json
* @param extract 解析的字段及保存到redis的key
* @return true-解析成功,false-解析失败
*/
public
boolean
extractResponse
(
String
response
,
String
extract
)
{
Map
<
String
,
String
>
extractMap
=
JSON
.
parseObject
(
extract
,
Map
.
class
);
try
{
for
(
String
key:
extractMap
.
keySet
())
{
String
value
=
extractMap
.
get
(
key
);
redisUtils
.
set
(
key
,
JsonPath
.
read
(
response
,
value
));
redisUtils
.
expire
(
key
,
120
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
false
;
}
return
true
;
}
/**
* 响应断言
* @return
*/
public
boolean
assertResponse
(
String
response
,
List
<
Map
>
validateList
)
{
for
(
Map
<
String
,
String
>
map:
validateList
)
{
String
comparator
=
map
.
get
(
"comparator"
);
String
checkpoint
=
JsonPath
.
read
(
response
,
map
.
get
(
"check"
));
String
expectValue
=
map
.
get
(
"expect"
);
boolean
result
=
singleAssertResponse
(
response
,
comparator
,
checkpoint
,
expectValue
);
if
(!
result
)
{
return
false
;
}
}
return
false
;
}
/**
*
* @param response
* @param comparator
* @param checkpoint
* @param expectValue
* @return
*/
public
boolean
singleAssertResponse
(
String
response
,
String
comparator
,
String
checkpoint
,
String
expectValue
)
{
switch
(
comparator
)
{
case
"eq"
:
return
JsonPath
.
read
(
response
,
checkpoint
).
equals
(
expectValue
);
case
"gt"
:
return
Integer
.
parseInt
(
JsonPath
.
read
(
response
,
checkpoint
))
>
Integer
.
parseInt
(
expectValue
);
case
"lt"
:
return
Integer
.
parseInt
(
JsonPath
.
read
(
response
,
checkpoint
))
<
Integer
.
parseInt
(
expectValue
);
case
"neq"
:
return
!
JsonPath
.
read
(
response
,
checkpoint
).
equals
(
expectValue
);
default
:
log
.
info
(
"暂不支持该比较符号:{}"
,
comparator
);
break
;
}
return
false
;
}
}
src/main/java/cn/qg/holmes/service/auto/impl/InterfaceServiceImpl.java
0 → 100644
View file @
0897055e
package
cn
.
qg
.
holmes
.
service
.
auto
.
impl
;
import
cn.qg.holmes.entity.auto.Interface
;
import
cn.qg.holmes.mapper.auto.InterfaceMapper
;
import
cn.qg.holmes.service.auto.InterfaceService
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
org.springframework.stereotype.Service
;
@Service
public
class
InterfaceServiceImpl
extends
ServiceImpl
<
InterfaceMapper
,
Interface
>
implements
InterfaceService
{
}
src/main/java/cn/qg/holmes/service/auto/impl/ProjectServiceImpl.java
0 → 100644
View file @
0897055e
package
cn
.
qg
.
holmes
.
service
.
auto
.
impl
;
import
cn.qg.holmes.entity.auto.Project
;
import
cn.qg.holmes.mapper.auto.ProjectMapper
;
import
cn.qg.holmes.service.auto.ProjectService
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
org.springframework.stereotype.Service
;
@Service
public
class
ProjectServiceImpl
extends
ServiceImpl
<
ProjectMapper
,
Project
>
implements
ProjectService
{
}
src/main/java/cn/qg/holmes/service/auto/impl/SceneServiceImpl.java
0 → 100644
View file @
0897055e
package
cn
.
qg
.
holmes
.
service
.
auto
.
impl
;
import
cn.qg.holmes.entity.auto.Scene
;
import
cn.qg.holmes.mapper.auto.SceneMapper
;
import
cn.qg.holmes.service.auto.SceneService
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
org.springframework.stereotype.Service
;
@Service
public
class
SceneServiceImpl
extends
ServiceImpl
<
SceneMapper
,
Scene
>
implements
SceneService
{
}
src/main/java/cn/qg/holmes/service/auto/impl/SceneTestcaseServiceImpl.java
0 → 100644
View file @
0897055e
package
cn
.
qg
.
holmes
.
service
.
auto
.
impl
;
import
cn.qg.holmes.entity.auto.Interface
;
import
cn.qg.holmes.entity.auto.SceneTestcase
;
import
cn.qg.holmes.mapper.auto.SceneTestcaseMapper
;
import
cn.qg.holmes.service.auto.AutoUtilsService
;
import
cn.qg.holmes.service.auto.InterfaceService
;
import
cn.qg.holmes.service.auto.SceneTestcaseService
;
import
cn.qg.holmes.service.auto.TestcaseService
;
import
cn.qg.holmes.utils.HttpClientUtils
;
import
com.alibaba.fastjson.JSON
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
/**
* @author libo
* created at 2021-03-30
*/
@Service
@Slf4j
public
class
SceneTestcaseServiceImpl
extends
ServiceImpl
<
SceneTestcaseMapper
,
SceneTestcase
>
implements
SceneTestcaseService
{
@Autowired
SceneTestcaseMapper
sceneTestcaseMapper
;
@Autowired
TestcaseService
testcaseService
;
@Autowired
InterfaceService
interfaceService
;
@Autowired
AutoUtilsService
autoUtilsService
;
@Override
public
void
executeSceneTestcase
(
Integer
sceneId
)
{
QueryWrapper
queryWrapper
=
new
QueryWrapper
();
queryWrapper
.
eq
(
"scene_id"
,
sceneId
);
queryWrapper
.
orderByAsc
(
"sequence"
);
List
<
SceneTestcase
>
sceneTestcaseList
=
sceneTestcaseMapper
.
selectList
(
queryWrapper
);
for
(
SceneTestcase
sceneTestcase:
sceneTestcaseList
)
{
sceneTestcaseExecution
(
sceneId
,
sceneTestcase
.
getInterfaceId
());
}
}
public
String
sceneTestcaseExecution
(
Integer
sceneId
,
Integer
interfaceId
)
{
QueryWrapper
queryWrapper
=
new
QueryWrapper
();
queryWrapper
.
eq
(
"scene_id"
,
sceneId
);
queryWrapper
.
eq
(
"interface_id"
,
interfaceId
);
SceneTestcase
sceneTestcase
=
sceneTestcaseMapper
.
selectOne
(
queryWrapper
);
Interface
anInterface
=
interfaceService
.
getById
(
interfaceId
);
String
url
=
anInterface
.
getUrl
();
log
.
info
(
"开始执行接口:{}"
,
url
);
String
method
=
anInterface
.
getMethod
().
toUpperCase
();
String
paramType
=
anInterface
.
getParamType
();
String
headers
=
sceneTestcase
.
getHeaders
();
String
parameters
=
sceneTestcase
.
getParameters
();
String
variables
=
sceneTestcase
.
getVariables
();
String
extract
=
sceneTestcase
.
getExtract
();
String
validate
=
sceneTestcase
.
getValidate
();
Map
<
String
,
String
>
parameterMap
=
JSON
.
parseObject
(
parameters
,
Map
.
class
);
Map
<
String
,
String
>
headersMap
=
JSON
.
parseObject
(
headers
,
Map
.
class
);
if
(
variables
!=
null
&&
!
variables
.
isEmpty
()
&&
parameters
!=
null
&&
!
parameters
.
isEmpty
())
{
parameterMap
=
autoUtilsService
.
replaceParameters
(
parameters
,
variables
);
}
if
(
variables
!=
null
&&
!
variables
.
isEmpty
()
&&
headers
!=
null
&&
!
headers
.
isEmpty
())
{
headersMap
=
autoUtilsService
.
replaceParameters
(
headers
,
variables
);
}
List
<
Map
>
validateList
=
new
ArrayList
<>();
if
(
validate
!=
null
&&
!
validate
.
isEmpty
())
{
validateList
=
JSON
.
parseArray
(
validate
,
Map
.
class
);
}
String
response
=
""
;
switch
(
method
)
{
case
"GET"
:
response
=
HttpClientUtils
.
doGet
(
url
,
headersMap
,
parameterMap
);
break
;
case
"POST"
:
if
(
paramType
.
equals
(
"json"
))
{
response
=
HttpClientUtils
.
doPostJson
(
url
,
headersMap
,
JSON
.
toJSONString
(
parameterMap
));
}
else
if
(
paramType
.
equals
(
"form"
))
{
response
=
HttpClientUtils
.
doPost
(
url
,
headersMap
,
parameterMap
);
}
break
;
default
:
log
.
info
(
"暂不支持该请求方法:{}"
,
method
);
break
;
}
// 进行断言
if
(!
validateList
.
isEmpty
())
{
autoUtilsService
.
assertResponse
(
response
,
validateList
);
}
// 解析响应
if
(
extract
!=
null
&&
!
extract
.
isEmpty
())
{
autoUtilsService
.
extractResponse
(
response
,
extract
);
}
return
response
;
}
}
src/main/java/cn/qg/holmes/service/auto/impl/TestcaseServiceImpl.java
0 → 100644
View file @
0897055e
package
cn
.
qg
.
holmes
.
service
.
auto
.
impl
;
import
cn.qg.holmes.entity.auto.Interface
;
import
cn.qg.holmes.entity.auto.Testcase
;
import
cn.qg.holmes.mapper.auto.TestcaseMapper
;
import
cn.qg.holmes.service.auto.AutoUtilsService
;
import
cn.qg.holmes.service.auto.InterfaceService
;
import
cn.qg.holmes.service.auto.TestcaseService
;
import
cn.qg.holmes.utils.HttpClientUtils
;
import
com.alibaba.fastjson.JSON
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
/**
* @author libo
* created at 2021-03-30
*/
@Service
@Slf4j
public
class
TestcaseServiceImpl
extends
ServiceImpl
<
TestcaseMapper
,
Testcase
>
implements
TestcaseService
{
@Autowired
TestcaseMapper
testcaseMapper
;
@Autowired
InterfaceService
interfaceService
;
@Autowired
AutoUtilsService
autoUtilsService
;
@Override
public
String
singleTestcaseExecutor
(
Integer
testcaseId
)
{
Testcase
testcase
=
testcaseMapper
.
selectById
(
testcaseId
);
Interface
anInterface
=
interfaceService
.
getById
(
testcase
.
getInterfaceId
());
String
url
=
anInterface
.
getUrl
();
String
method
=
anInterface
.
getMethod
().
toUpperCase
();
String
paramType
=
anInterface
.
getParamType
();
String
headers
=
testcase
.
getHeaders
();
String
parameters
=
testcase
.
getParameters
();
String
testcaseName
=
testcase
.
getName
();
String
variables
=
testcase
.
getVariables
();
String
extract
=
testcase
.
getExtract
();
String
validate
=
testcase
.
getValidate
();
// 参数准备
Map
<
String
,
String
>
parameterMap
=
JSON
.
parseObject
(
parameters
,
Map
.
class
);
Map
<
String
,
String
>
headersMap
=
JSON
.
parseObject
(
headers
,
Map
.
class
);
if
(
variables
!=
null
&&
!
variables
.
isEmpty
()
&&
parameters
!=
null
&&
!
parameters
.
isEmpty
())
{
parameterMap
=
autoUtilsService
.
replaceParameters
(
parameters
,
variables
);
}
if
(
variables
!=
null
&&
!
variables
.
isEmpty
()
&&
headers
!=
null
&&
!
headers
.
isEmpty
())
{
headersMap
=
autoUtilsService
.
replaceParameters
(
headers
,
variables
);
}
List
<
Map
>
validateList
=
new
ArrayList
<>();
if
(
validate
!=
null
&&
!
validate
.
isEmpty
())
{
validateList
=
JSON
.
parseArray
(
validate
,
Map
.
class
);
}
String
response
=
""
;
// 发起http请求
switch
(
method
)
{
case
"GET"
:
response
=
HttpClientUtils
.
doGet
(
url
,
headersMap
,
parameterMap
);
break
;
case
"POST"
:
if
(
paramType
.
equals
(
"json"
))
{
response
=
HttpClientUtils
.
doPostJson
(
url
,
headersMap
,
JSON
.
toJSONString
(
parameterMap
));
}
else
if
(
paramType
.
equals
(
"form"
))
{
response
=
HttpClientUtils
.
doPost
(
url
,
headersMap
,
parameterMap
);
}
break
;
default
:
log
.
info
(
"暂不支持该请求方法:{}"
,
method
);
break
;
}
log
.
info
(
"用例:{}, 返回为:{}"
,
testcaseName
,
response
);
// 进行断言
if
(!
validateList
.
isEmpty
())
{
autoUtilsService
.
assertResponse
(
response
,
validateList
);
}
// 解析响应
if
(
extract
!=
null
&&
!
extract
.
isEmpty
())
{
autoUtilsService
.
extractResponse
(
response
,
extract
);
}
return
response
;
}
}
src/main/java/cn/qg/holmes/utils/BankCardUtils.java
View file @
0897055e
package
cn
.
qg
.
holmes
.
utils
;
package
cn
.
qg
.
holmes
.
utils
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
/**
/**
...
@@ -9,8 +10,8 @@ public class BankCardUtils {
...
@@ -9,8 +10,8 @@ public class BankCardUtils {
public
static
String
getCardCode
(
String
cardNo
)
{
public
static
String
getCardCode
(
String
cardNo
)
{
String
url
=
"https://ccdcapi.alipay.com/validateAndCacheCardInfo.json?_input_charset=utf-8&cardNo="
+
cardNo
+
"&cardBinCheck=true"
;
String
url
=
"https://ccdcapi.alipay.com/validateAndCacheCardInfo.json?_input_charset=utf-8&cardNo="
+
cardNo
+
"&cardBinCheck=true"
;
JSONObject
resposne
=
HttpClientUtils
.
doGetReturnJson
(
url
);
String
resposne
=
HttpClientUtils
.
doGet
(
url
);
return
resposne
.
get
(
"bank"
).
toString
();
return
JSON
.
parseObject
(
resposne
)
.
get
(
"bank"
).
toString
();
}
}
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
...
...
src/main/java/cn/qg/holmes/utils/HttpClientUtils.java
View file @
0897055e
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
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