Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nwn_Api_auto_test
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
shuai
nwn_Api_auto_test
Commits
e1385b4b
Commit
e1385b4b
authored
Sep 29, 2019
by
wff66504
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
20190929
parent
33f23c6d
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
372 additions
and
2 deletions
+372
-2
CaseMakeWff.xls
nwn_Api_auto_test/TestData/CaseMakeWff.xls
+0
-0
DataAllWff.xls
nwn_Api_auto_test/TestData/DataAllWff.xls
+0
-0
zhibo.xlsx
nwn_Api_auto_test/out/zhibo.xlsx
+0
-0
RequestDataUtils.java
...pi_auto_test/src/com/offcn/TestUnti/RequestDataUtils.java
+29
-1
exportLive.java
nwn_Api_auto_test/src/com/offcn/api/nwn/ht/exportLive.java
+148
-0
importLive.java
nwn_Api_auto_test/src/com/offcn/api/nwn/ht/importLive.java
+173
-0
MyRequest.java
nwn_Api_auto_test/src/com/offcn/system/MyRequest.java
+22
-1
No files found.
nwn_Api_auto_test/TestData/CaseMakeWff.xls
View file @
e1385b4b
No preview for this file type
nwn_Api_auto_test/TestData/DataAllWff.xls
View file @
e1385b4b
No preview for this file type
nwn_Api_auto_test/out/zhibo.xlsx
0 → 100644
View file @
e1385b4b
File added
nwn_Api_auto_test/src/com/offcn/TestUnti/RequestDataUtils.java
View file @
e1385b4b
...
...
@@ -74,6 +74,9 @@ public class RequestDataUtils {
if
(
myRequest
.
getFormParameter
()!=
null
){
return
Post_form_data
(
data
,
myRequest
);
}
if
(
myRequest
.
getFormFileParameter
()!=
null
){
return
Post_form_data_file
(
data
,
myRequest
);
}
return
Post_JSON
(
data
,
myRequest
);
}
...
...
@@ -138,7 +141,6 @@ public class RequestDataUtils {
// 设置参数格式
int
state
=
0
;
Response
re
=
null
;
while
(
state
<
5
)
{
try
{
state
++;
...
...
@@ -159,6 +161,32 @@ public class RequestDataUtils {
}
return
re
;
}
public
static
Response
Post_form_data_file
(
HashMap
<
String
,
Object
>
data
,
MyRequest
myRequest
)
{
// 设置参数格式
int
state
=
0
;
Response
re
=
null
;
while
(
state
<
5
)
{
try
{
state
++;
File
filen
=
new
File
(
"out/"
+
myRequest
.
getFormFile
());
re
=
jobApi
(
data
,
myRequest
)
.
params
(
myRequest
.
getFormFileParameter
())
.
when
().
multiPart
(
"file"
,
filen
)
.
post
(
myRequest
.
getUrl
())
.
thenReturn
();
if
(!
"200"
.
equals
(
re
.
getStatusCode
()+
""
))
{
Log
.
logError
(
"请求返回"
+
re
.
getStatusCode
()
+
"次。"
);
// } else {
}
return
re
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
Log
.
logError
(
"请求超时,"
+
state
+
"次。"
);
}
}
return
re
;
}
//不带token的post请求
@SuppressWarnings
(
"static-access"
)
...
...
nwn_Api_auto_test/src/com/offcn/api/nwn/ht/exportLive.java
0 → 100644
View file @
e1385b4b
package
com
.
offcn
.
api
.
nwn
.
ht
;
import
io.restassured.path.json.JsonPath
;
import
io.restassured.response.Response
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Random
;
import
org.json.simple.JSONArray
;
import
com.offcn.TestUnti.ListUtil
;
import
com.offcn.TestUnti.Log
;
import
com.offcn.TestUnti.MapUtil
;
import
com.offcn.TestUnti.MyDateUtil
;
import
com.offcn.TestUnti.MySqlUtil
;
import
com.offcn.TestUnti.ReadProperties
;
import
com.offcn.TestUnti.RequestDataUtils
;
import
com.offcn.TestUnti.StringUtils
;
import
com.offcn.interfaces.API
;
import
com.offcn.process.NWN
;
import
com.offcn.system.MyRequest
;
import
net.sf.json.JSONObject
;
/**
*
* @Description: 83.下载教务包内直播组件信息
* @author: wff
* @date: 2019年9月29日 上午10:46:54
* @version V1.0
*/
public
class
exportLive
extends
NWN
implements
API
{
public
String
parameter
;
//参数集合
public
String
package_id
;
//教务包或者学习包ID 强转int 默认 0
@Override
public
void
initialize
(
HashMap
<
String
,
Object
>
data
)
{
}
@Override
public
HashMap
<
String
,
Object
>
handleInput
(
HashMap
<
String
,
Object
>
data
)
{
// 获取parameter对应的内容
parameter
=
MapUtil
.
getValue
(
"parameter"
,
data
);
package_id
=
MapUtil
.
getParameter_get
(
parameter
,
"package_id"
).
trim
();
if
((!
package_id
.
equals
(
""
))
&&
package_id
.
equals
(
"code"
))
{
package_id
=
"4027605"
;
parameter
=
parameter
.
replace
(
"package_id=code"
,
"package_id="
+
package_id
);
}
data
.
put
(
"parameter"
,
parameter
);
return
data
;
}
// public static void main(String[] args) {
// String start_time = MyDateUtil.getTime(2, 2, 2);
// System.out.println(start_time);
// }
@Override
public
Response
SendRequest
(
HashMap
<
String
,
Object
>
data
,
String
Url
,
String
Request
)
{
Map
<
String
,
String
>
cookie
=
new
HashMap
<
String
,
String
>();
cookie
.
put
(
"PHPSESSID"
,
PHPSESSID
);
MyRequest
myRequest
=
new
MyRequest
();
myRequest
.
setRequest
(
Request
);
myRequest
.
setUrl
(
Url
);
myRequest
.
setParameter
(
parameter
);
myRequest
.
setCookies
(
cookie
);
Response
re
=
RequestDataUtils
.
RestAssuredApi
(
data
,
myRequest
);
return
re
;
}
@Override
public
String
handleOutput
(
Response
re
,
HashMap
<
String
,
Object
>
data
)
{
JsonPath
jp
=
re
.
body
().
jsonPath
();
boolean
result
=
true
;
String
failReason
=
""
;
String
json
=
re
.
asString
();
if
((
data
.
get
(
"statusCode"
)
!=
null
)
&&
(!
data
.
get
(
"statusCode"
).
toString
()
.
equals
(
String
.
valueOf
(
re
.
getStatusCode
()))))
{
result
=
result
&&
false
;
failReason
=
failReason
+
"statusCode is expected "
+
data
.
get
(
"statusCode"
).
toString
()
+
" but actually "
+
String
.
valueOf
(
re
.
getStatusCode
())
+
". "
;
}
if
(
json
.
length
()
!=
0
)
{
String
msg
=
jp
.
getString
(
"message"
);
String
code
=
jp
.
getString
(
"retcode"
);
if
((
data
.
get
(
"code"
)
!=
null
)
&&
(
code
!=
null
)
&&
(!
code
.
equals
(
data
.
get
(
"code"
).
toString
())))
{
result
=
result
&&
false
;
failReason
=
failReason
+
"code is expected "
+
data
.
get
(
"code"
).
toString
()
+
" but actually "
+
jp
.
getString
(
"code"
)
+
"."
;
}
if
((
data
.
get
(
"msg"
)
!=
null
)
&&
(
msg
!=
null
)
&&
(!
msg
.
equals
(
data
.
get
(
"msg"
).
toString
())))
{
result
=
result
&&
false
;
failReason
=
failReason
+
"msg is expected "
+
data
.
get
(
"msg"
).
toString
()
+
" but actually "
+
jp
.
getString
(
"msg"
)
+
"."
;
}
if
(
data
.
get
(
"custom"
)
!=
null
&&
jp
.
getString
(
"data.live_name"
)!=
null
){
String
custom
=
data
.
get
(
"custom"
).
toString
();
String
[]
ArrayString
=
StringUtils
.
getArrayString
(
custom
,
","
);
// System.out.println(jp.getString("custom"));
// System.out.println(Arrays.toString(ArrayString));
if
(!
StringUtils
.
VerificationString
(
jp
.
getString
(
"data"
),
ArrayString
)){
result
=
result
&&
false
;
failReason
=
failReason
+
"custom is expected "
+
data
.
get
(
"custom"
).
toString
()
+
" but actually "
+
jp
.
getString
(
"data"
)
+
"."
;
}
}
if
(
"0"
.
equals
(
jp
.
getString
(
"retcode"
))){
}
}
if
(
result
)
return
"Pass"
;
else
return
"Fail:"
+
failReason
;
}
}
nwn_Api_auto_test/src/com/offcn/api/nwn/ht/importLive.java
0 → 100644
View file @
e1385b4b
package
com
.
offcn
.
api
.
nwn
.
ht
;
import
io.restassured.path.json.JsonPath
;
import
io.restassured.response.Response
;
import
java.sql.ResultSet
;
import
java.util.HashMap
;
import
java.util.Map
;
import
com.offcn.TestUnti.MapUtil
;
import
com.offcn.TestUnti.RequestDataUtils
;
import
com.offcn.TestUnti.StringUtils
;
import
com.offcn.interfaces.API
;
import
com.offcn.process.NWN
;
import
com.offcn.system.MyRequest
;
/**
*
* @Description: 80.批量导入直播组件
* @author: wff
* @date: 2019年9月27日 上午9:38:55
* @version V1.0
*/
public
class
importLive
extends
NWN
implements
API
{
public
String
parameter
;
//参数集合
public
String
template_id_1
;
//母版id
public
String
parent_id
;
//父级id
public
String
file
;
//excel文件
@Override
public
void
initialize
(
HashMap
<
String
,
Object
>
data
)
{
}
@Override
public
HashMap
<
String
,
Object
>
handleInput
(
HashMap
<
String
,
Object
>
data
)
{
// 获取parameter对应的内容
parameter
=
MapUtil
.
getValue
(
"parameter"
,
data
);
template_id_1
=
MapUtil
.
getParameter
(
parameter
,
"template_id"
).
trim
();
parent_id
=
MapUtil
.
getParameter
(
parameter
,
"parent_id"
).
trim
();
file
=
MapUtil
.
getParameter
(
parameter
,
"file"
).
trim
();
if
((!
template_id_1
.
equals
(
""
))
&&
template_id_1
.
equals
(
"code"
))
{
template_id_1
=
template_id
;
parameter
=
parameter
.
replace
(
"\"template_id\":code"
,
"\"template_id\":\""
+
template_id_1
+
"\""
);
}
if
((!
parent_id
.
equals
(
""
))
&&
parent_id
.
equals
(
"code"
))
{
parent_id
=
"0"
;
parameter
=
parameter
.
replace
(
"\"parent_id\":code"
,
"\"parent_id\":\""
+
parent_id
+
"\""
);
}
if
((!
file
.
equals
(
""
))
&&
file
.
equals
(
"code"
))
{
file
=
"zhibo.xlsx"
;
parameter
=
parameter
.
replace
(
"\"file\":code"
,
"\"file\":\""
+
file
+
"\""
);
}
data
.
put
(
"parameter"
,
parameter
);
return
data
;
}
@Override
public
Response
SendRequest
(
HashMap
<
String
,
Object
>
data
,
String
Url
,
String
Request
)
{
Map
<
String
,
String
>
formFileParameter
=
new
HashMap
<
String
,
String
>();
formFileParameter
.
put
(
"template_id"
,
template_id_1
);
formFileParameter
.
put
(
"parent_id"
,
parent_id
);
// formFileParameter.put("file", "/out"+ file);
Map
<
String
,
String
>
cookie
=
new
HashMap
<
String
,
String
>();
cookie
.
put
(
"PHPSESSID"
,
PHPSESSID
);
MyRequest
myRequest
=
new
MyRequest
();
myRequest
.
setRequest
(
Request
);
myRequest
.
setUrl
(
Url
);
myRequest
.
setFormFileParameter
(
formFileParameter
);
myRequest
.
setCookies
(
cookie
);
myRequest
.
setFormFile
(
file
);
Response
re
=
RequestDataUtils
.
RestAssuredApi
(
data
,
myRequest
);
return
re
;
}
@Override
public
String
handleOutput
(
Response
re
,
HashMap
<
String
,
Object
>
data
)
{
JsonPath
jp
=
re
.
body
().
jsonPath
();
boolean
result
=
true
;
String
failReason
=
""
;
String
json
=
re
.
asString
();
if
((
data
.
get
(
"statusCode"
)
!=
null
)
&&
(!
data
.
get
(
"statusCode"
).
toString
()
.
equals
(
String
.
valueOf
(
re
.
getStatusCode
()))))
{
result
=
result
&&
false
;
failReason
=
failReason
+
"statusCode is expected "
+
data
.
get
(
"statusCode"
).
toString
()
+
" but actually "
+
String
.
valueOf
(
re
.
getStatusCode
())
+
". "
;
}
if
(
json
.
length
()
!=
0
)
{
String
msg
=
jp
.
getString
(
"message"
);
String
code
=
jp
.
getString
(
"retcode"
);
if
((
data
.
get
(
"code"
)
!=
null
)
&&
(
code
!=
null
)
&&
(!
code
.
equals
(
data
.
get
(
"code"
).
toString
())))
{
result
=
result
&&
false
;
failReason
=
failReason
+
"code is expected "
+
data
.
get
(
"code"
).
toString
()
+
" but actually "
+
jp
.
getString
(
"code"
)
+
"."
;
}
if
((
data
.
get
(
"msg"
)
!=
null
)
&&
(
msg
!=
null
)
&&
(!
msg
.
equals
(
data
.
get
(
"msg"
).
toString
())))
{
result
=
result
&&
false
;
failReason
=
failReason
+
"msg is expected "
+
data
.
get
(
"msg"
).
toString
()
+
" but actually "
+
jp
.
getString
(
"msg"
)
+
"."
;
}
if
(
data
.
get
(
"custom"
)
!=
null
&&
jp
.
getString
(
"data"
)!=
null
){
String
custom
=
data
.
get
(
"custom"
).
toString
();
String
[]
ArrayString
=
StringUtils
.
getArrayString
(
custom
,
","
);
// System.out.println(jp.getString("custom"));
// System.out.println(Arrays.toString(ArrayString));
if
(!
StringUtils
.
VerificationString
(
jp
.
getString
(
"data"
),
ArrayString
)){
result
=
result
&&
false
;
failReason
=
failReason
+
"custom is expected "
+
data
.
get
(
"custom"
).
toString
()
+
" but actually "
+
jp
.
getString
(
"data"
)
+
"."
;
}
}
if
(
"0"
.
equals
(
jp
.
getString
(
"retcode"
))){
//讲义对应的menuid
menuId
=
jp
.
getString
(
"data.level_id"
);
//是否验证数据库
if
(!
isProduct
)
{
try
{
String
sql
=
"SELECT MAX(id) id,menu_id,name FROM n_handouts"
;
ResultSet
rs_bankcard
=
this
.
sqlFromDB
(
sql
);
rs_bankcard
.
last
();
//添加讲义的主键id
handoutsId
=
rs_bankcard
.
getString
(
"id"
);
//// System.out.println(rs_bankcard.getString("name"));
//// if(!(rs_bankcard.getString("name")).equals(handouts_name)){
//// result = result && false;
//// failReason = failReason + "template_id info in DB is wrong;";
//// }
// System.out.println(menuId);
// System.out.println(liveId);
//
}
catch
(
Exception
e
)
{
result
=
result
&&
false
;
failReason
=
failReason
+
"cannot verify template_id info in DB;"
;
e
.
printStackTrace
();
}
}
}
}
if
(
result
)
return
"Pass"
;
else
return
"Fail:"
+
failReason
;
}
}
nwn_Api_auto_test/src/com/offcn/system/MyRequest.java
View file @
e1385b4b
...
...
@@ -12,6 +12,9 @@ public class MyRequest {
private
Map
<
String
,
String
>
formParameter
;
//form_data请求方式的参数、或file请求方式的参数
private
String
file
;
private
String
fileType
;
private
Map
<
String
,
String
>
formFileParameter
;
//fromda带file请求参数
private
String
formFile
;
//fromda带file请求参数
public
String
getRequest
()
{
return
Request
;
}
...
...
@@ -60,9 +63,25 @@ public class MyRequest {
public
void
setFileType
(
String
fileType
)
{
this
.
fileType
=
fileType
;
}
public
Map
<
String
,
String
>
getFormFileParameter
()
{
return
formFileParameter
;
}
public
void
setFormFileParameter
(
Map
<
String
,
String
>
formFileParameter
)
{
this
.
formFileParameter
=
formFileParameter
;
}
public
String
getFormFile
()
{
return
formFile
;
}
public
void
setFormFile
(
String
formFile
)
{
this
.
formFile
=
formFile
;
}
public
MyRequest
(
String
request
,
String
url
,
Map
<
String
,
String
>
cookies
,
Map
<
String
,
String
>
headers
,
String
parameter
,
Map
<
String
,
String
>
formParameter
,
String
file
,
String
fileType
)
{
Map
<
String
,
String
>
formParameter
,
String
file
,
String
fileType
,
Map
<
String
,
String
>
formFileParameter
,
String
formFile
)
{
super
();
Request
=
request
;
Url
=
url
;
...
...
@@ -72,6 +91,8 @@ public class MyRequest {
this
.
formParameter
=
formParameter
;
this
.
file
=
file
;
this
.
fileType
=
fileType
;
this
.
formFileParameter
=
formFileParameter
;
this
.
formFile
=
formFile
;
}
public
MyRequest
()
{
}
...
...
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