Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
A
automated-testing
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
黄承天
automated-testing
Commits
c63bc857
提交
c63bc857
authored
2月 20, 2020
作者:
黄承天
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加测试报告下载接口
上级
e09e9cc8
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
180 行增加
和
16 行删除
+180
-16
pom.xml
pom.xml
+4
-0
ReportController.java
...om/zjty/automatedtesting/controller/ReportController.java
+32
-9
TransHelper.java
...n/java/com/zjty/automatedtesting/service/TransHelper.java
+2
-1
FileUtil.java
src/main/java/com/zjty/automatedtesting/util/FileUtil.java
+137
-2
JsonUtil.java
src/main/java/com/zjty/automatedtesting/util/JsonUtil.java
+3
-2
application.properties
src/main/resources/application.properties
+2
-2
没有找到文件。
pom.xml
浏览文件 @
c63bc857
...
...
@@ -26,6 +26,10 @@
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-jpa
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-thymeleaf
</artifactId>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-lang3
</artifactId>
...
...
src/main/java/com/zjty/automatedtesting/controller/ReportController.java
浏览文件 @
c63bc857
...
...
@@ -3,15 +3,21 @@ package com.zjty.automatedtesting.controller;
import
com.google.common.collect.ImmutableMap
;
import
com.zjty.automatedtesting.pojo.report.ReportVo
;
import
com.zjty.automatedtesting.service.ReportService
;
import
com.zjty.automatedtesting.util.FileUtil
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.OutputStream
;
import
java.net.URLEncoder
;
import
java.util.List
;
import
java.util.Map
;
@Slf4j
@SuppressWarnings
(
"SpringJavaAutowiredFieldsWarningInspection"
)
@RequestMapping
(
"/report"
)
@RestController
...
...
@@ -23,28 +29,45 @@ public class ReportController {
ReportService
reportService
;
@ApiOperation
(
value
=
"获取全部测试报告."
)
@GetMapping
(
value
=
"/get"
)
public
ResponseEntity
<
List
<
ReportVo
>>
get
(){
@GetMapping
(
value
=
"/get"
)
public
ResponseEntity
<
List
<
ReportVo
>>
get
()
{
return
ResponseEntity
.
ok
(
reportService
.
findAll
());
}
@ApiOperation
(
value
=
"按分页获取测试报告.页码从0开始."
)
@GetMapping
(
value
=
"/get/page/{page}"
)
public
ResponseEntity
<
List
<
ReportVo
>>
get
(
@PathVariable
Integer
page
){
@GetMapping
(
value
=
"/get/page/{page}"
)
public
ResponseEntity
<
List
<
ReportVo
>>
get
(
@PathVariable
Integer
page
)
{
return
ResponseEntity
.
ok
(
reportService
.
findByPage
(
page
));
}
@ApiOperation
(
value
=
"获取单个测试报告."
)
@GetMapping
(
value
=
"/get/{id}"
)
public
ResponseEntity
<
ReportVo
>
getById
(
@PathVariable
Integer
id
){
@GetMapping
(
value
=
"/get/{id}"
)
public
ResponseEntity
<
ReportVo
>
getById
(
@PathVariable
Integer
id
)
{
return
ResponseEntity
.
ok
(
reportService
.
findById
(
id
));
}
@ApiOperation
(
value
=
"删除测试报告."
)
@DeleteMapping
(
value
=
"/delete/{id}"
)
public
ResponseEntity
<
Map
<
String
,
String
>>
findTestText
(
@PathVariable
Integer
id
)
{
@DeleteMapping
(
value
=
"/delete/{id}"
)
public
ResponseEntity
<
Map
<
String
,
String
>>
delete
(
@PathVariable
Integer
id
)
{
reportService
.
delete
(
id
);
return
ResponseEntity
.
ok
(
ImmutableMap
.
of
(
"message"
,
"success"
));
return
ResponseEntity
.
ok
(
ImmutableMap
.
of
(
"message"
,
"success"
));
}
@ApiOperation
(
value
=
"下载测试报告."
)
@GetMapping
(
value
=
"/download/{id}"
)
public
ResponseEntity
<
Map
<
String
,
String
>>
download
(
@PathVariable
Integer
id
,
HttpServletResponse
response
)
{
try
{
response
.
setHeader
(
"content-type"
,
"application/octet-stream"
);
response
.
setContentType
(
"application/octet-stream"
);
String
filename
=
"report-"
+
id
.
toString
()
+
".html"
;
response
.
setHeader
(
"Content-Disposition"
,
"attachment;filename="
+
URLEncoder
.
encode
(
filename
,
"UTF-8"
));
OutputStream
os
=
response
.
getOutputStream
();
String
reportHtmlContent
=
FileUtil
.
getRepotHtmlContent
(
reportService
.
findById
(
id
));
FileUtil
.
output
(
reportHtmlContent
,
os
);
}
catch
(
Exception
e
)
{
log
.
error
(
"error:"
+
e
);
return
ResponseEntity
.
ok
(
ImmutableMap
.
of
(
"message"
,
"error:"
+
e
.
getMessage
()));
}
return
ResponseEntity
.
ok
(
null
);
}
}
src/main/java/com/zjty/automatedtesting/service/TransHelper.java
浏览文件 @
c63bc857
package
com
.
zjty
.
automatedtesting
.
service
;
import
com.alibaba.fastjson.JSON
;
import
com.zjty.automatedtesting.pojo.report.Measure
;
import
com.zjty.automatedtesting.pojo.report.Report
;
import
com.zjty.automatedtesting.pojo.report.ReportVo
;
...
...
@@ -48,7 +49,7 @@ public class TransHelper {
}
public
ReportVo
toReportVo
(
Report
report
){
List
<
Measure
>
measures
=
J
sonUtil
.
readValueToList
(
report
.
getMeasures
(),
Measure
.
class
);
List
<
Measure
>
measures
=
J
SON
.
parseArray
(
report
.
getMeasures
(),
Measure
.
class
);
return
new
ReportVo
(
report
.
getId
(),
report
.
getTitle
(),
...
...
src/main/java/com/zjty/automatedtesting/util/FileUtil.java
浏览文件 @
c63bc857
package
com
.
zjty
.
automatedtesting
.
util
;
import
com.zjty.automatedtesting.pojo.report.Measure
;
import
com.zjty.automatedtesting.pojo.report.Report
;
import
com.zjty.automatedtesting.pojo.report.ReportVo
;
import
com.zjty.automatedtesting.pojo.test.Case
;
import
lombok.extern.slf4j.Slf4j
;
import
java.io.IOException
;
import
java.io.*
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.file.Files
;
import
java.nio.file.Paths
;
import
java.util.List
;
...
...
@@ -13,15 +18,145 @@ import java.util.List;
* <p>Date : 2020/1/16 15:27
* <p>@author : C
*/
@Slf4j
public
class
FileUtil
{
private
final
static
String
WORK_PATH
=
System
.
getProperty
(
"user.dir"
)
+
"\\"
;
private
Case
parseFilToTestCase
(
String
fileName
)
throws
IOException
{
private
final
static
String
REPORT_HTML_TEMP_FIRST_PART
=
"<html>\n"
+
"<head>\n"
+
"<style>\n"
+
".table15_12 table {\n"
+
"\twidth:100%;\n"
+
"\tmargin:15px 0;\n"
+
"\tborder:0;\n"
+
"}\n"
+
".table15_12 th {\n"
+
"\tfont-weight:bold;\n"
+
"\tbackground-color:#d8f1fe;\n"
+
"\tcolor:#20a0fe\n"
+
"}\n"
+
".table15_12,.table15_12 th,.table15_12 td {\n"
+
"\tfont-size:0.95em;\n"
+
"\ttext-align:center;\n"
+
"\tpadding:4px;\n"
+
"\tborder-collapse:collapse;\n"
+
"}\n"
+
".table15_12 th {\n"
+
"\tborder: 1px solid #d8f1fe;\n"
+
"\tborder-width:1px\n"
+
"}\n"
+
".table15_12 td {\n"
+
"\tborder: 1px solid #d8f1fe;\n"
+
"\tborder-width:1px\n"
+
"}\n"
+
".table15_12 tr {\n"
+
"\tborder: 1px solid #ffffff;\n"
+
"}\n"
+
".table15_12 tr:nth-child(odd){\n"
+
"\tbackground-color:#f7f7f7;\n"
+
"}\n"
+
".table15_12 tr:nth-child(even){\n"
+
"\tbackground-color:#ffffff;\n"
+
"}\n"
+
"</style>\n"
+
"</head>\n"
+
"<body>\n"
+
"<div>ID:#{id}</div>\n"
+
"<div>标题:#{title}</div>\n"
+
"<div>浏览器:#{browser}</div>\n"
+
"<div>地址:#{url}</div>\n"
+
"\n"
+
"<br/>\n"
+
"<div>测试步骤详情</div>\n"
+
"<table class=table15_12>\n"
+
"<tr>\n"
+
"\t<th>编号</th>\n"
+
"\t<th>步骤名</th>\n"
+
"\t<th>预期值</th>\n"
+
"\t<th>实际值</th>\n"
+
"\t<th>结果</th>\n"
+
"\t<th>相关信息</th>\n"
+
"</tr>\n"
;
private
final
static
String
REPORT_HTML_TEMP_LAST_PART
=
"\n"
+
"</table>\n"
+
"\n"
+
"</body>\n"
+
"\n"
+
"</html>"
;
private
Case
parseFileToTestCase
(
String
fileName
)
throws
IOException
{
List
<
String
>
lines
=
Files
.
readAllLines
(
Paths
.
get
(
WORK_PATH
+
fileName
));
StringBuilder
builder
=
new
StringBuilder
();
lines
.
forEach
(
builder:
:
append
);
String
data
=
builder
.
toString
();
return
JsonUtil
.
readValue
(
data
,
Case
.
class
);
}
public
static
String
getRepotHtmlContent
(
ReportVo
reportVo
)
{
StringBuilder
content
=
new
StringBuilder
();
String
first_part
=
REPORT_HTML_TEMP_FIRST_PART
.
replace
(
"#{id}"
,
reportVo
.
getId
().
toString
())
.
replace
(
"#{title}"
,
reportVo
.
getTitle
())
.
replace
(
"#{browser}"
,
reportVo
.
getBrowser
())
.
replace
(
"#{url}"
,
reportVo
.
getUrl
());
content
.
append
(
first_part
);
String
rowTemp
=
"<tr>\n"
+
"\t<td>#{order}</td>\n"
+
"\t<td>#{title}</td>\n"
+
"\t<td>#{expected}</td>\n"
+
"\t<td>#{practice}</td>\n"
+
"\t<td>#{success}</td>\n"
+
"\t<td>#{message}</td>\n"
+
"</tr>\n"
;
List
<
Measure
>
measures
=
reportVo
.
getMeasures
();
for
(
Measure
measure
:
measures
)
{
String
row
=
rowTemp
.
replace
(
"#{order}"
,
measure
.
getOrder
().
toString
())
.
replace
(
"#{title}"
,
measure
.
getTitle
())
.
replace
(
"#{expected}"
,
measure
.
getExpected
())
.
replace
(
"#{practice}"
,
measure
.
getPractice
())
.
replace
(
"#{success}"
,
measure
.
getSuccess
()
?
"成功"
:
"失败"
)
.
replace
(
"#{message}"
,
measure
.
getMessage
());
content
.
append
(
row
);
}
content
.
append
(
REPORT_HTML_TEMP_LAST_PART
);
return
content
.
toString
();
}
public
static
void
output
(
String
text
,
OutputStream
os
)
{
byte
[]
buffer
=
new
byte
[
1024
];
InputStream
is
=
null
;
BufferedInputStream
bis
=
null
;
try
{
is
=
new
ByteArrayInputStream
(
text
.
getBytes
(
StandardCharsets
.
UTF_8
));
bis
=
new
BufferedInputStream
(
is
);
int
i
=
bis
.
read
(
buffer
);
while
(
i
!=
-
1
)
{
os
.
write
(
buffer
,
0
,
i
);
i
=
bis
.
read
(
buffer
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
"error:{}"
,
e
.
getMessage
());
}
finally
{
if
(
bis
!=
null
)
{
try
{
bis
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
if
(
is
!=
null
)
{
try
{
is
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
}
}
src/main/java/com/zjty/automatedtesting/util/JsonUtil.java
浏览文件 @
c63bc857
...
...
@@ -2,6 +2,7 @@ package com.zjty.automatedtesting.util;
import
com.fasterxml.jackson.core.type.TypeReference
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.google.common.collect.Lists
;
import
java.util.Arrays
;
import
java.util.Collections
;
...
...
@@ -41,9 +42,9 @@ public final class JsonUtil {
public
static
<
T
>
List
<
T
>
readValueToList
(
String
jsonStr
,
Class
<
T
>
valueType
)
{
T
[]
arrays
=
readValue
(
jsonStr
,
new
TypeReference
<
T
[]>()
{
});
List
<
T
>
list
=
Collections
.
empt
yList
();
List
<
T
>
list
=
Lists
.
newArra
yList
();
if
(
arrays
!=
null
)
{
list
=
Arrays
.
as
List
(
arrays
);
list
=
Lists
.
newArray
List
(
arrays
);
}
return
list
;
}
...
...
src/main/resources/application.properties
浏览文件 @
c63bc857
#
server.address=0.0.0.0
server.address
=
0.0.0.0
server.port
=
13500
spring.datasource.driver-class-name
=
com.mysql.cj.jdbc.Driver
spring.datasource.url
=
jdbc:mysql://localhost:3306/automated_testing?useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true
spring.datasource.url
=
jdbc:mysql://localhost:3306/automated_testing?useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true
&characterEncoding=utf-8
spring.datasource.username
=
root
spring.datasource.password
=
root
spring.jpa.hibernate.ddl-auto
=
update
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论