Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
study
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
Li Yongyu
study
Commits
01a550b0
Commit
01a550b0
authored
Feb 28, 2019
by
Li Yongyu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
delete tk
parent
218d4578
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
173 additions
and
354 deletions
+173
-354
OAuthTokenUnti.java
..._Api_auto_test/src/com/offcn/TestUnti/OAuthTokenUnti.java
+0
-50
APITest_study.java
...enter_Api_auto_test/src/com/offcn/test/APITest_study.java
+173
-173
APITest_tk.java
studycenter_Api_auto_test/src/com/offcn/test/APITest_tk.java
+0
-131
No files found.
studycenter_Api_auto_test/src/com/offcn/TestUnti/OAuthTokenUnti.java
deleted
100644 → 0
View file @
218d4578
package
com
.
offcn
.
TestUnti
;
import
org.springframework.http.converter.HttpMessageConverter
;
import
org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
;
import
org.springframework.security.oauth2.client.DefaultOAuth2ClientContext
;
import
org.springframework.security.oauth2.client.OAuth2RestTemplate
;
import
org.springframework.security.oauth2.client.token.DefaultAccessTokenRequest
;
import
org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails
;
import
org.springframework.security.oauth2.common.OAuth2AccessToken
;
import
com.offcn.process.BasicsGM
;
import
com.offcn.system.system
;
import
com.offcn.test.APITest_tk
;
import
java.util.Arrays
;
public
class
OAuthTokenUnti
{
public
APITest_tk
RAPI
;
// private static OAuth2AccessToken token;
public
static
OAuth2AccessToken
token
;
public
static
void
main
(
String
[]
args
)
{
String
strToken
=
OAuthTokenUnti
.
getOathToken
(
"gmysx"
).
getValue
();
System
.
out
.
println
(
"strToken="
+
strToken
);
}
public
static
OAuth2AccessToken
getOathToken
(
String
system
){
if
(
token
==
null
){
OAuth2RestTemplate
restTemplate
=
new
OAuth2RestTemplate
(
getResource
(
system
),
new
DefaultOAuth2ClientContext
(
new
DefaultAccessTokenRequest
()));
MappingJackson2HttpMessageConverter
converter
=
new
MappingJackson2HttpMessageConverter
();
restTemplate
.
setMessageConverters
(
Arrays
.<
HttpMessageConverter
<?>>
asList
(
converter
));
token
=
restTemplate
.
getAccessToken
();
}
return
token
;
}
private
static
ClientCredentialsResourceDetails
getResource
(
String
system
){
ClientCredentialsResourceDetails
resource
=
new
ClientCredentialsResourceDetails
();
system
tem
=(
system
)(
BasicsGM
.
map
.
get
(
system
));
resource
.
setAccessTokenUri
(
tem
.
getAccess_token_uri
());
resource
.
setClientId
(
tem
.
getClient_id
());
resource
.
setClientSecret
(
tem
.
getClient_secret
());
resource
.
setGrantType
(
tem
.
getGrant_type
());
return
resource
;
}
}
studycenter_Api_auto_test/src/com/offcn/test/APITest_study.java
View file @
01a550b0
package
com
.
offcn
.
test
;
package
com
.
offcn
.
test
;
import
io.restassured.response.Response
;
import
io.restassured.response.Response
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
net.sf.json.JSONObject
;
import
net.sf.json.JSONObject
;
import
org.testng.Assert
;
import
org.testng.Assert
;
import
org.testng.annotations.AfterClass
;
import
org.testng.annotations.AfterClass
;
import
com.offcn.TestData.offcn_api_testData
;
import
com.offcn.TestData.offcn_api_testData
;
import
com.offcn.TestUnti.Log
;
import
com.offcn.TestUnti.Log
;
import
com.offcn.TestUnti.Mail
;
import
com.offcn.TestUnti.Mail
;
import
com.offcn.TestUnti.MapUtil
;
import
com.offcn.TestUnti.MapUtil
;
import
com.offcn.TestUnti.OAuthTokenUnti
;
import
com.offcn.TestUnti.ReadProperties
;
import
com.offcn.TestUnti.ReadProperties
;
import
com.offcn.TestUnti.Reflect_api
;
import
com.offcn.TestUnti.Reflect_api
;
import
com.offcn.TestUnti.SheetUtils
;
import
com.offcn.TestUnti.SheetUtils
;
import
com.offcn.TestUnti.StringUtils
;
import
com.offcn.TestUnti.StringUtils
;
import
com.offcn.TestUnti.XMLread
;
import
com.offcn.TestUnti.XMLread
;
import
com.offcn.interfaces.API
;
import
com.offcn.interfaces.API
;
import
com.offcn.listener.ProcessTestng
;
import
com.offcn.listener.ProcessTestng
;
import
com.offcn.listener.ResultTestng
;
import
com.offcn.listener.ResultTestng
;
import
com.offcn.process.BasicsGM
;
import
com.offcn.process.BasicsGM
;
import
com.offcn.process.STUDY
;
import
com.offcn.process.STUDY
;
import
com.offcn.process.TK
;
import
com.offcn.process.TK
;
import
com.offcn.process.XYZB
;
import
com.offcn.process.XYZB
;
import
org.testng.annotations.BeforeClass
;
import
org.testng.annotations.BeforeClass
;
import
org.testng.annotations.Listeners
;
import
org.testng.annotations.Listeners
;
import
org.testng.annotations.Test
;
import
org.testng.annotations.Test
;
@Listeners
({
ProcessTestng
.
class
,
ResultTestng
.
class
})
@Listeners
({
ProcessTestng
.
class
,
ResultTestng
.
class
})
public
class
APITest_study
extends
STUDY
{
public
class
APITest_study
extends
STUDY
{
@BeforeClass
@BeforeClass
public
void
beforeClass
()
{
public
void
beforeClass
()
{
//测试开始删除测试所用的数据
//测试开始删除测试所用的数据
if
(!
isClearMysql
)
{
if
(!
isClearMysql
)
{
System
.
out
.
println
(
"start del **************"
);
System
.
out
.
println
(
"start del **************"
);
// this.cleann_n_admin_card_no_List_FromDB_beforeTest();
// this.cleann_n_admin_card_no_List_FromDB_beforeTest();
System
.
out
.
println
(
"end del **************"
);
System
.
out
.
println
(
"end del **************"
);
}
}
Log
.
logInfo
(
"========测试开始========"
);
Log
.
logInfo
(
"========测试开始========"
);
}
}
@Test
(
dataProvider
=
"renmai"
,
dataProviderClass
=
offcn_api_testData
.
class
)
@Test
(
dataProvider
=
"renmai"
,
dataProviderClass
=
offcn_api_testData
.
class
)
public
void
f
(
HashMap
<
String
,
Object
>
data
)
{
public
void
f
(
HashMap
<
String
,
Object
>
data
)
{
Log
.
logInfo
(
data
.
get
(
"TCNO"
).
toString
()
+
" Step "
+
data
.
get
(
"Description"
).
toString
()
+
" is running......"
);
Log
.
logInfo
(
data
.
get
(
"TCNO"
).
toString
()
+
" Step "
+
data
.
get
(
"Description"
).
toString
()
+
" is running......"
);
API
obj
=
new
Reflect_api
().
Reflections
(
data
);
API
obj
=
new
Reflect_api
().
Reflections
(
data
);
BasicsGM
.
map
=
new
XMLread
().
getSystem
();
BasicsGM
.
map
=
new
XMLread
().
getSystem
();
obj
.
initialize
(
data
);
obj
.
initialize
(
data
);
data
=
obj
.
handleInput
(
data
);
data
=
obj
.
handleInput
(
data
);
//静态和动态参数自动添加
//静态和动态参数自动添加
data
=
setPublicParameter
(
data
);
data
=
setPublicParameter
(
data
);
data
=
setDynamicParameter
(
data
);
data
=
setDynamicParameter
(
data
);
String
parameter
=
MapUtil
.
getValue
(
"parameter"
,
data
);
String
parameter
=
MapUtil
.
getValue
(
"parameter"
,
data
);
System
.
out
.
println
(
"parameter====="
+
parameter
);
System
.
out
.
println
(
"parameter====="
+
parameter
);
// System.out.println(!data.get("Request").toString().contains("get"));
// System.out.println(!data.get("Request").toString().contains("get"));
// System.out.println(data.get("system").toString().equals("nwn_service"));
// System.out.println(data.get("system").toString().equals("nwn_service"));
/* if(data.get("system").toString().equals("nwn_service") ){
/* if(data.get("system").toString().equals("nwn_service") ){
String serviceUrl = MapUtil.getValue("serviceUrl", data);
String serviceUrl = MapUtil.getValue("serviceUrl", data);
//url后面获取sign值
//url后面获取sign值
serviceUrl = serviceUrl + "/sign/" ;
serviceUrl = serviceUrl + "/sign/" ;
data.put("serviceUrl", serviceUrl);
data.put("serviceUrl", serviceUrl);
}
}
*/
*/
Long
startTime
=
System
.
currentTimeMillis
();
Long
startTime
=
System
.
currentTimeMillis
();
Response
re
=
obj
.
SendRequest
(
data
,
data
.
get
(
"serviceUrl"
).
toString
(),
data
.
get
(
"Request"
).
toString
());
Response
re
=
obj
.
SendRequest
(
data
,
data
.
get
(
"serviceUrl"
).
toString
(),
data
.
get
(
"Request"
).
toString
());
Long
endTime
=
System
.
currentTimeMillis
();
Long
endTime
=
System
.
currentTimeMillis
();
String
time
=(
endTime
-
startTime
)+
"毫秒"
;
String
time
=(
endTime
-
startTime
)+
"毫秒"
;
String
codeORerrcode
=
""
;
String
codeORerrcode
=
""
;
String
msgORerrmsy
=
""
;
String
msgORerrmsy
=
""
;
String
result
=
""
;
String
result
=
""
;
String
body
=
""
;
String
body
=
""
;
if
(
re
!=
null
){
if
(
re
!=
null
){
body
=
re
.
asString
();
body
=
re
.
asString
();
if
(
body
.
contains
(
"<title>"
)){
if
(
body
.
contains
(
"<title>"
)){
int
Alength
=
"<title>"
.
length
();
int
Alength
=
"<title>"
.
length
();
int
start
=
body
.
indexOf
(
"<title>"
);
int
start
=
body
.
indexOf
(
"<title>"
);
int
end
=
body
.
indexOf
(
"</title>"
)+
1
;
int
end
=
body
.
indexOf
(
"</title>"
)+
1
;
body
=
"页面标题:"
+
body
.
substring
(
start
+
Alength
,
end
-
1
);
body
=
"页面标题:"
+
body
.
substring
(
start
+
Alength
,
end
-
1
);
result
=
body
;
result
=
body
;
if
(
data
.
get
(
"Description"
).
toString
().
contains
(
"流程"
)){
if
(
data
.
get
(
"Description"
).
toString
().
contains
(
"流程"
)){
result
=
obj
.
handleOutput
(
re
,
data
);
result
=
obj
.
handleOutput
(
re
,
data
);
}
}
}
else
if
(
body
.
contains
(
"<html>"
)){
}
else
if
(
body
.
contains
(
"<html>"
)){
body
=
"返回html页面,状态码:"
+
re
.
getStatusCode
();
body
=
"返回html页面,状态码:"
+
re
.
getStatusCode
();
if
(
data
.
get
(
"Description"
).
toString
().
contains
(
"流程"
)){
if
(
data
.
get
(
"Description"
).
toString
().
contains
(
"流程"
)){
result
=
obj
.
handleOutput
(
re
,
data
);
result
=
obj
.
handleOutput
(
re
,
data
);
}
}
}
}
}
}
result
=
obj
.
handleOutput
(
re
,
data
);
result
=
obj
.
handleOutput
(
re
,
data
);
codeORerrcode
=
getCode
(
re
);
codeORerrcode
=
getCode
(
re
);
msgORerrmsy
=
getMsg
(
re
);
msgORerrmsy
=
getMsg
(
re
);
Log
.
logInfo
(
"返回结果="
+
StringUtils
.
decodeUnicode
(
body
));
Log
.
logInfo
(
"返回结果="
+
StringUtils
.
decodeUnicode
(
body
));
System
.
out
.
println
();
System
.
out
.
println
();
//数据回写
//数据回写
/* // HashMap<String, Object> ExpectResult=MapUtil.Expect(data);
/* // HashMap<String, Object> ExpectResult=MapUtil.Expect(data);
SheetUtils sheet = new SheetUtils("DataAll.xls", "Output");
SheetUtils sheet = new SheetUtils("DataAll.xls", "Output");
sheet.writeExcel(
sheet.writeExcel(
data.get("NO").toString(),
data.get("NO").toString(),
data.get("TCNO").toString() + "_Step" + data.get("Step").toString(),
data.get("TCNO").toString() + "_Step" + data.get("Step").toString(),
data.get("Description").toString(),
data.get("Description").toString(),
parameter,
parameter,
// JSONObject.fromObject(ExpectResult).toString(),
// JSONObject.fromObject(ExpectResult).toString(),
re.getStatusCode()+"",
re.getStatusCode()+"",
// StringUtils.decodeUnicode(re==null?"":re.asString()),
// StringUtils.decodeUnicode(re==null?"":re.asString()),
StringUtils.decodeUnicode(body),
StringUtils.decodeUnicode(body),
codeORerrcode,
codeORerrcode,
msgORerrmsy,
msgORerrmsy,
result,
result,
time
time
);*/
);*/
if
(
result
.
indexOf
(
"Fail"
)!=-
1
){
if
(
result
.
indexOf
(
"Fail"
)!=-
1
){
String
Expect1
=
data
.
get
(
"code"
)==
null
?
""
:
data
.
get
(
"code"
).
toString
();
String
Expect1
=
data
.
get
(
"code"
)==
null
?
""
:
data
.
get
(
"code"
).
toString
();
String
Expect2
=
data
.
get
(
"msg"
)==
null
?
""
:
data
.
get
(
"msg"
).
toString
();
String
Expect2
=
data
.
get
(
"msg"
)==
null
?
""
:
data
.
get
(
"msg"
).
toString
();
String
Expect3
=
data
.
get
(
"custom"
)==
null
?
""
:
data
.
get
(
"custom"
).
toString
();
String
Expect3
=
data
.
get
(
"custom"
)==
null
?
""
:
data
.
get
(
"custom"
).
toString
();
if
(
body
.
contains
(
"HTML"
)){
if
(
body
.
contains
(
"HTML"
)){
body
=
"异常页面信息"
;
body
=
"异常页面信息"
;
}
}
Assert
.
assertEquals
(
StringUtils
.
decodeUnicode
(
body
),
Expect1
+
","
+
Expect2
+
","
+
Expect3
);
Assert
.
assertEquals
(
StringUtils
.
decodeUnicode
(
body
),
Expect1
+
","
+
Expect2
+
","
+
Expect3
);
}
else
{
}
else
{
Assert
.
assertTrue
(
true
);
Assert
.
assertTrue
(
true
);
}
}
}
}
@AfterClass
@AfterClass
public
void
afterClass
()
{
public
void
afterClass
()
{
//测试结束删除测试所用的数据
//测试结束删除测试所用的数据
if
(!
isClearMysql
)
{
if
(!
isClearMysql
)
{
this
.
cleann_getcode_id_List_FromDB
();
this
.
cleann_getcode_id_List_FromDB
();
try
{
try
{
if
(
stmt
!=
null
){
if
(
stmt
!=
null
){
stmt
.
close
();
stmt
.
close
();
}
}
if
(
conn
!=
null
){
if
(
conn
!=
null
){
conn
.
close
();
conn
.
close
();
}
}
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
}
}
Log
.
logInfo
(
"========测试结束========"
);
Log
.
logInfo
(
"========测试结束========"
);
}
}
}
}
studycenter_Api_auto_test/src/com/offcn/test/APITest_tk.java
deleted
100644 → 0
View file @
218d4578
package
com
.
offcn
.
test
;
import
io.restassured.response.Response
;
import
java.sql.SQLException
;
import
java.util.HashMap
;
import
net.sf.json.JSONObject
;
import
org.testng.Assert
;
import
org.testng.annotations.AfterClass
;
import
com.offcn.TestData.offcn_api_testData
;
import
com.offcn.TestUnti.Log
;
import
com.offcn.TestUnti.Mail
;
import
com.offcn.TestUnti.MapUtil
;
import
com.offcn.TestUnti.OAuthTokenUnti
;
import
com.offcn.TestUnti.ReadProperties
;
import
com.offcn.TestUnti.Reflect_api
;
import
com.offcn.TestUnti.SheetUtils
;
import
com.offcn.TestUnti.StringUtils
;
import
com.offcn.TestUnti.XMLread
;
import
com.offcn.interfaces.API
;
import
com.offcn.listener.ProcessTestng
;
import
com.offcn.listener.ResultTestng
;
import
com.offcn.process.BasicsGM
;
import
com.offcn.process.TK
;
import
com.offcn.process.XYZB
;
import
org.testng.annotations.Listeners
;
import
org.testng.annotations.Test
;
@Listeners
({
ProcessTestng
.
class
,
ResultTestng
.
class
})
public
class
APITest_tk
extends
TK
{
@Test
(
dataProvider
=
"renmai"
,
dataProviderClass
=
offcn_api_testData
.
class
)
public
void
f
(
HashMap
<
String
,
Object
>
data
)
{
Log
.
logInfo
(
data
.
get
(
"TCNO"
).
toString
()
+
" Step "
+
data
.
get
(
"Description"
).
toString
()
+
" is running......"
);
API
obj
=
new
Reflect_api
().
Reflections
(
data
);
BasicsGM
.
map
=
new
XMLread
().
getSystem
();
obj
.
initialize
(
data
);
data
=
obj
.
handleInput
(
data
);
String
parameter
=
MapUtil
.
getValue
(
"parameter"
,
data
);
Long
startTime
=
System
.
currentTimeMillis
();
Response
re
=
obj
.
SendRequest
(
data
,
data
.
get
(
"serviceUrl"
).
toString
(),
data
.
get
(
"Request"
).
toString
());
Long
endTime
=
System
.
currentTimeMillis
();
String
time
=(
endTime
-
startTime
)+
"毫秒"
;
String
body
=
re
.
asString
();
String
codeORerrcode
=
""
;
String
msgORerrmsy
=
""
;
String
result
=
""
;
if
(
body
.
contains
(
"<title>"
)){
int
Alength
=
"<title>"
.
length
();
int
start
=
body
.
indexOf
(
"<title>"
);
int
end
=
body
.
indexOf
(
"</title>"
)+
1
;
body
=
"页面标题:"
+
body
.
substring
(
start
+
Alength
,
end
-
1
);
result
=
body
;
if
(
data
.
get
(
"Description"
).
toString
().
contains
(
"流程"
)){
result
=
obj
.
handleOutput
(
re
,
data
);
}
}
else
{
result
=
obj
.
handleOutput
(
re
,
data
);
}
codeORerrcode
=
getCode
(
re
);
msgORerrmsy
=
getMsg
(
re
);
Log
.
logInfo
(
"返回结果="
+
StringUtils
.
decodeUnicode
(
body
));
System
.
out
.
println
();
//数据回写
// HashMap<String, Object> ExpectResult=MapUtil.Expect(data);
// SheetUtils sheet = new SheetUtils("DataAll.xls", "Output");
// sheet.writeExcel(
// data.get("NO").toString(),
// data.get("TCNO").toString() + "_Step" + data.get("Step").toString(),
// data.get("Description").toString(),
// parameter,
// JSONObject.fromObject(ExpectResult).toString(),
// StringUtils.decodeUnicode(re.asString()),
// codeORerrcode,
// msgORerrmsy,
// result,
// time
// );
if
(
result
.
indexOf
(
"Fail"
)!=-
1
){
String
Expect1
=
data
.
get
(
"code"
)==
null
?
""
:
data
.
get
(
"code"
).
toString
();
String
Expect2
=
data
.
get
(
"msg"
)==
null
?
""
:
data
.
get
(
"msg"
).
toString
();
String
Expect3
=
data
.
get
(
"custom"
)==
null
?
""
:
data
.
get
(
"custom"
).
toString
();
if
(
body
.
contains
(
"HTML"
)){
body
=
"异常页面信息"
;
}
Assert
.
assertEquals
(
StringUtils
.
decodeUnicode
(
body
),
Expect1
+
","
+
Expect2
+
","
+
Expect3
);
}
else
{
Assert
.
assertTrue
(
true
);
}
}
@AfterClass
public
void
afterClass
()
{
//测试结束删除测试所用的数据
if
(!
isClearMysql
)
{
cleanUser_FromDB
();
//清除注册user_id,
cleanexam_FromDB
();
//清除用户地区操作表t_exam_area
try
{
if
(
stmt
!=
null
){
stmt
.
close
();
}
if
(
conn
!=
null
){
conn
.
close
();
}
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
Log
.
logInfo
(
"========测试结束========"
);
}
}
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