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
0982c646
Commit
0982c646
authored
Jan 21, 2019
by
Li Yongyu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改接口导致的错误和新接口
parent
db44930a
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
1874 additions
and
0 deletions
+1874
-0
.project
.project
+11
-0
769F9010
nwn_Api_auto_test/TestData/769F9010
+0
-0
DataAll - 20190117.xls
nwn_Api_auto_test/TestData/DataAll - 20190117.xls
+0
-0
addChildModuleMovie_template.java
...t/src/com/offcn/api/nwn/addChildModuleMovie_template.java
+165
-0
addUserPackage.java
nwn_Api_auto_test/src/com/offcn/api/nwn/addUserPackage.java
+155
-0
createLevel.java
nwn_Api_auto_test/src/com/offcn/api/nwn/createLevel.java
+190
-0
createTemplate.java
nwn_Api_auto_test/src/com/offcn/api/nwn/createTemplate.java
+206
-0
editOutlinie.java
nwn_Api_auto_test/src/com/offcn/api/nwn/editOutlinie.java
+202
-0
editTemp.java
nwn_Api_auto_test/src/com/offcn/api/nwn/editTemp.java
+201
-0
getAllYears.java
nwn_Api_auto_test/src/com/offcn/api/nwn/getAllYears.java
+152
-0
getTempInfo.java
nwn_Api_auto_test/src/com/offcn/api/nwn/getTempInfo.java
+196
-0
outLineList.java
nwn_Api_auto_test/src/com/offcn/api/nwn/outLineList.java
+190
-0
templateList.java
nwn_Api_auto_test/src/com/offcn/api/nwn/templateList.java
+206
-0
No files found.
.project
0 → 100644
View file @
0982c646
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>
nwn_Api_auto_test
</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>
nwn_Api_auto_test/TestData/769F9010
0 → 100644
View file @
0982c646
File added
nwn_Api_auto_test/TestData/DataAll - 20190117.xls
0 → 100644
View file @
0982c646
File added
nwn_Api_auto_test/src/com/offcn/api/nwn/addChildModuleMovie_template.java
0 → 100644
View file @
0982c646
package
com
.
offcn
.
api
.
nwn
;
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.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.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.process.XYZB
;
import
net.sf.json.JSONObject
;
/**
* 课程大纲列表-添加组件-视频
*
* @author puhui
*
*/
public
class
addChildModuleMovie_template
extends
NWN
implements
API
{
public
String
parameter
;
//参数集合
public
String
template_id_1
;
//学习包id
public
String
movie_name
;
//视频名称
public
String
parent_id
;
//父级id ,第一级为 0, 子级为 上级的id
public
String
movie_id
;
//视频idmda-gjvkfu3jwwjxz84e\mda-gjvk3kgfbhmdvcmb\mda-gjvkrnzry73rd2hi\mda-gjvk6pncebf5whzx
@Override
public
void
initialize
(
HashMap
<
String
,
Object
>
data
)
{
try
{
String
sql
=
"SELECT DISTINCT(video_id) FROM n_video "
;
//SELECT id FROM n_template ORDER BY id DESC LIMIT 1
ResultSet
rs_bankcard
=
this
.
sqlFromDB
(
sql
);
rs_bankcard
.
last
();
movie_id_list
.
add
(
rs_bankcard
.
getString
(
"video_id"
));
System
.
out
.
println
(
"movie_id_list===="
+
movie_id_list
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
@Override
public
HashMap
<
String
,
Object
>
handleInput
(
HashMap
<
String
,
Object
>
data
)
{
// 获取parameter对应的内容
parameter
=
MapUtil
.
getValue
(
"parameter"
,
data
);
template_id_1
=
MapUtil
.
getParameter_get
(
parameter
,
"template_id"
).
trim
();
movie_id
=
MapUtil
.
getParameter_get
(
parameter
,
"movie_id"
).
trim
();
if
((!
template_id_1
.
equals
(
""
))
&&
template_id_1
.
equals
(
"template_id"
))
{
template_id_1
=
template_id
;
System
.
out
.
println
(
"template_id_1==="
+
template_id_1
);
parameter
=
parameter
.
replace
(
"template_id=template_id"
,
"template_id="
+
template_id_1
);
}
if
((!
movie_id
.
equals
(
""
))
&&
movie_id
.
equals
(
"movie_id"
))
{
movie_id
=
ListUtil
.
getListValue
(
movie_id_list
,
0
);
System
.
out
.
println
(
"movie_id==="
+
movie_id
);
parameter
=
parameter
.
replace
(
"movie_id=movie_id"
,
"movie_id="
+
movie_id
);
}
data
.
put
(
"parameter"
,
parameter
);
return
data
;
}
@Override
public
Response
SendRequest
(
HashMap
<
String
,
Object
>
data
,
String
Url
,
String
Request
)
{
Response
re
=
RequestDataUtils
.
Get_one_cookie_pre
(
data
,
Url
,
"PHPSESSID"
,
PHPSESSID
);
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"
))){
//是否验证数据库
if
(!
isProduct
)
{
}
}
}
if
(
result
)
return
"Pass"
;
else
return
"Fail:"
+
failReason
;
}
}
nwn_Api_auto_test/src/com/offcn/api/nwn/addUserPackage.java
0 → 100644
View file @
0982c646
package
com
.
offcn
.
api
.
nwn
;
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.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Random
;
import
org.json.simple.JSONArray
;
import
com.offcn.TestUnti.Log
;
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.process.TK
;
import
com.offcn.TestUnti.ListUtil
;
import
net.sf.json.JSONObject
;
/**
* 添加用户信息(客户端单独)
*
* @author liyy
*
*/
public
class
addUserPackage
extends
NWN
implements
API
{
public
String
parameter
;
//参数集合
public
String
package_id
;
//搜索-学习包id
public
String
phone
;
//层级包id
@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
();
phone
=
MapUtil
.
getParameter_get
(
parameter
,
"phone"
).
trim
();
if
((!
package_id
.
equals
(
""
))
&&
package_id
.
equals
(
"package_id"
))
{
package_id
=
ListUtil
.
getListValue
(
n_package_idList
,
0
);
parameter
=
parameter
.
replace
(
"package_id=package_id"
,
"package_id="
+
package_id
);
}
if
((!
phone
.
equals
(
""
))
&&
phone
.
equals
(
"phone"
))
{
phone
=
"135"
+(
new
Random
().
nextInt
(
90000000
)+
10000000
);
System
.
out
.
println
(
"phone======"
+
phone
);
parameter
=
parameter
.
replace
(
"phone=phone"
,
"phone="
+
phone
);
}
data
.
put
(
"parameter"
,
parameter
);
return
data
;
}
@Override
public
Response
SendRequest
(
HashMap
<
String
,
Object
>
data
,
String
Url
,
String
Request
)
{
Response
re
=
RequestDataUtils
.
Get_one_cookie_pre
(
data
,
Url
,
"PHPSESSID"
,
PHPSESSID
);
//Response re = RequestDataUtils.Get_one_cookie(data, serviceURL, cookie1Name, cookie1value) //只能无参
// Response re = RequestDataUtils.Get_token(data, Url, "");
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
=
StringUtils
.
decodeUnicode
(
getMsg
(
re
));
String
code
=
getCode
(
re
);
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
&&
json
!=
null
){
//如果自定义结果包含多个希望结果,也就是有逗号,那么就切割,包含比较。
if
(
data
.
get
(
"custom"
).
toString
().
contains
(
","
)){
String
[]
strCustomStrings
=
data
.
get
(
"custom"
).
toString
().
split
(
","
);
System
.
out
.
println
(
strCustomStrings
.
length
);
for
(
int
i
=
0
;
i
<
strCustomStrings
.
length
;
i
++){
if
(!
json
.
contains
(
strCustomStrings
[
i
])){
result
=
result
&&
false
;
failReason
=
failReason
+
"custom is expected "
+
data
.
get
(
"custom"
).
toString
()
+
" but actually "
+
strCustomStrings
[
i
]
+
"."
;
break
;
}
}
}
else
{
//如果只有一个希望结果,就直接包含比较。
if
(!
json
.
contains
(
data
.
get
(
"custom"
).
toString
())){
result
=
result
&&
false
;
failReason
=
failReason
+
"custom is expected "
+
data
.
get
(
"custom"
).
toString
()
+
" but actually "
+
data
.
get
(
"custom"
).
toString
()
+
"."
;
}
}
}
if
(
"添加成功!"
.
equals
(
msg
)){
//是否验证数据库
if
(!
isProduct
)
{
}
}
}
if
(
result
)
return
"Pass"
;
else
return
"Fail:"
+
failReason
;
}
}
nwn_Api_auto_test/src/com/offcn/api/nwn/createLevel.java
0 → 100644
View file @
0982c646
package
com
.
offcn
.
api
.
nwn
;
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.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Random
;
import
org.json.simple.JSONArray
;
import
com.offcn.TestUnti.Log
;
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.process.TK
;
import
com.offcn.TestUnti.ListUtil
;
import
net.sf.json.JSONObject
;
/**
* 添加母版层级
*
* @author liyy
*
*/
public
class
createLevel
extends
NWN
implements
API
{
public
String
parameter
;
//参数集合
public
String
template_id_1
;
//母板ID
// public String phone;//层级包id
@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_get
(
parameter
,
"template_id"
).
trim
();
if
((!
template_id_1
.
equals
(
""
))
&&
template_id_1
.
equals
(
"template_id"
))
{
template_id_1
=
template_id
;
parameter
=
parameter
.
replace
(
"template_id=template_id"
,
"template_id="
+
template_id_1
);
}
data
.
put
(
"parameter"
,
parameter
);
return
data
;
}
@Override
public
Response
SendRequest
(
HashMap
<
String
,
Object
>
data
,
String
Url
,
String
Request
)
{
// Map<String,String> m=new HashMap<String,String>();
// m.put("user_info", parameter);
//Response re = RequestDataUtils.Post_cooike_form_data(data, Url,"PHPSESSID",PHPSESSID,m);
Response
re
=
RequestDataUtils
.
Get_one_cookie_pre
(
data
,
Url
,
"PHPSESSID"
,
PHPSESSID
);
//Response re = RequestDataUtils.Get_one_cookie(data, serviceURL, cookie1Name, cookie1value) //只能无参
// Response re = RequestDataUtils.Get_token(data, Url, "");
return
re
;
}
@Override
public
String
handleOutput
(
Response
re
,
HashMap
<
String
,
Object
>
data
)
{
JsonPath
jp
=
re
.
body
().
jsonPath
();
System
.
out
.
println
(
"jp===="
+
jp
);
boolean
result
=
true
;
String
failReason
=
""
;
String
json
=
re
.
asString
();
System
.
out
.
println
(
"response=========="
+
json
);
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
=
StringUtils
.
decodeUnicode
(
getMsg
(
re
));
String
code
=
getCode
(
re
);
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
(
"retcode"
)
+
"."
;
}
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
&&
json
!=
null
){
//如果自定义结果包含多个希望结果,也就是有逗号,那么就切割,包含比较。
if
(
data
.
get
(
"custom"
).
toString
().
contains
(
","
)){
String
[]
strCustomStrings
=
data
.
get
(
"custom"
).
toString
().
split
(
","
);
System
.
out
.
println
(
strCustomStrings
.
length
);
for
(
int
i
=
0
;
i
<
strCustomStrings
.
length
;
i
++){
if
(!
json
.
contains
(
strCustomStrings
[
i
])){
result
=
result
&&
false
;
failReason
=
failReason
+
"custom is expected "
+
data
.
get
(
"custom"
).
toString
()
+
" but actually "
+
strCustomStrings
[
i
]
+
"."
;
break
;
}
}
}
else
{
//如果只有一个希望结果,就直接包含比较。
if
(!
json
.
contains
(
data
.
get
(
"custom"
).
toString
())){
result
=
result
&&
false
;
failReason
=
failReason
+
"custom is expected "
+
data
.
get
(
"custom"
).
toString
()
+
" but actually "
+
data
.
get
(
"custom"
).
toString
()
+
"."
;
}
}
}
if
(
"0"
.
equals
(
code
)){
/*//是否验证数据库
if (!isProduct) {
template_id=jp.getString("data.id").substring(0,jp.getString("data.id").length());
System.out.println("template_id====="+ template_id );
try {
String sql="SELECT MAX(id) AS id FROM n_template ";
//SELECT id FROM n_template ORDER BY id DESC LIMIT 1
ResultSet rs_bankcard = this.sqlFromDB(sql);
rs_bankcard.last();
System.out.println("after db_templateid============"+ rs_bankcard.getString("id"));
if(Integer.parseInt(rs_bankcard.getString("id")) > Integer.parseInt("1") )
{
if(!template_id.equals(rs_bankcard.getString("id")))
{
result = result && false;
failReason = failReason + "template_id info in DB is wrong;";
}else {
Log.logInfo("template_id info in DB is correct;");
}
}else {
result = result && false;
failReason = failReason + "template_id info in DB is wrong;";
}
} 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/api/nwn/createTemplate.java
0 → 100644
View file @
0982c646
package
com
.
offcn
.
api
.
nwn
;
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.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Random
;
import
org.json.simple.JSONArray
;
import
com.offcn.TestUnti.Log
;
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.process.TK
;
import
com.offcn.TestUnti.ListUtil
;
import
net.sf.json.JSONObject
;
/**
* 添加用户信息(客户端单独)
*
* @author liyy
*
*/
public
class
createTemplate
extends
NWN
implements
API
{
public
String
parameter
;
//参数集合
public
String
id
;
//母板ID
// public String phone;//层级包id
@Override
public
void
initialize
(
HashMap
<
String
,
Object
>
data
)
{
try
{
String
sql
=
"SELECT MAX(id) AS id FROM n_template "
;
//SELECT id FROM n_template ORDER BY id DESC LIMIT 1
ResultSet
rs_bankcard
=
this
.
sqlFromDB
(
sql
);
rs_bankcard
.
last
();
id
=
rs_bankcard
.
getString
(
"id"
);
System
.
out
.
println
(
"db_templateid============"
+
rs_bankcard
.
getString
(
"id"
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
@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();
phone = MapUtil.getParameter_get(parameter, "phone").trim();
if ((!package_id.equals("")) && package_id.equals("package_id")) {
package_id=ListUtil.getListValue(n_package_idList, 0);
parameter = parameter.replace("package_id=package_id", "package_id="+ package_id );
}
if ((!phone.equals("")) && phone.equals("phone")) {
phone="135"+(new Random().nextInt(90000000)+ 10000000);
System.out.println("phone======"+phone);
parameter = parameter.replace("phone=phone", "phone="+ phone );
}
data.put("parameter", parameter);*/
return
data
;
}
@Override
public
Response
SendRequest
(
HashMap
<
String
,
Object
>
data
,
String
Url
,
String
Request
)
{
// Map<String,String> m=new HashMap<String,String>();
// m.put("user_info", parameter);
//Response re = RequestDataUtils.Post_cooike_form_data(data, Url,"PHPSESSID",PHPSESSID,m);
Response
re
=
RequestDataUtils
.
Post_cooike
(
data
,
Url
,
"PHPSESSID"
,
PHPSESSID
);
//Response re = RequestDataUtils.Get_one_cookie(data, serviceURL, cookie1Name, cookie1value) //只能无参
// Response re = RequestDataUtils.Get_token(data, Url, "");
return
re
;
}
@Override
public
String
handleOutput
(
Response
re
,
HashMap
<
String
,
Object
>
data
)
{
JsonPath
jp
=
re
.
body
().
jsonPath
();
System
.
out
.
println
(
"jp===="
+
jp
);
boolean
result
=
true
;
String
failReason
=
""
;
String
json
=
re
.
asString
();
System
.
out
.
println
(
"response=========="
+
json
);
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
=
StringUtils
.
decodeUnicode
(
getMsg
(
re
));
String
code
=
getCode
(
re
);
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
(
"retcode"
)
+
"."
;
}
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
&&
json
!=
null
){
//如果自定义结果包含多个希望结果,也就是有逗号,那么就切割,包含比较。
if
(
data
.
get
(
"custom"
).
toString
().
contains
(
","
)){
String
[]
strCustomStrings
=
data
.
get
(
"custom"
).
toString
().
split
(
","
);
System
.
out
.
println
(
strCustomStrings
.
length
);
for
(
int
i
=
0
;
i
<
strCustomStrings
.
length
;
i
++){
if
(!
json
.
contains
(
strCustomStrings
[
i
])){
result
=
result
&&
false
;
failReason
=
failReason
+
"custom is expected "
+
data
.
get
(
"custom"
).
toString
()
+
" but actually "
+
strCustomStrings
[
i
]
+
"."
;
break
;
}
}
}
else
{
//如果只有一个希望结果,就直接包含比较。
if
(!
json
.
contains
(
data
.
get
(
"custom"
).
toString
())){
result
=
result
&&
false
;
failReason
=
failReason
+
"custom is expected "
+
data
.
get
(
"custom"
).
toString
()
+
" but actually "
+
data
.
get
(
"custom"
).
toString
()
+
"."
;
}
}
}
if
(
"0"
.
equals
(
code
)){
//是否验证数据库
if
(!
isProduct
)
{
template_id
=
jp
.
getString
(
"data.id"
).
substring
(
0
,
jp
.
getString
(
"data.id"
).
length
());
System
.
out
.
println
(
"template_id====="
+
template_id
);
try
{
String
sql
=
"SELECT MAX(id) AS id FROM n_template "
;
//SELECT id FROM n_template ORDER BY id DESC LIMIT 1
ResultSet
rs_bankcard
=
this
.
sqlFromDB
(
sql
);
rs_bankcard
.
last
();
System
.
out
.
println
(
"after db_templateid============"
+
rs_bankcard
.
getString
(
"id"
));
if
(
Integer
.
parseInt
(
rs_bankcard
.
getString
(
"id"
))
>
Integer
.
parseInt
(
id
)
)
{
if
(!
template_id
.
equals
(
rs_bankcard
.
getString
(
"id"
)))
{
result
=
result
&&
false
;
failReason
=
failReason
+
"template_id info in DB is wrong;"
;
}
else
{
Log
.
logInfo
(
"template_id info in DB is correct;"
);
}
}
else
{
result
=
result
&&
false
;
failReason
=
failReason
+
"template_id info in DB is wrong;"
;
}
}
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/api/nwn/editOutlinie.java
0 → 100644
View file @
0982c646
package
com
.
offcn
.
api
.
nwn
;
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.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Random
;
import
org.json.simple.JSONArray
;
import
com.offcn.TestUnti.Log
;
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.process.TK
;
import
com.offcn.TestUnti.ListUtil
;
import
net.sf.json.JSONObject
;
/**
* 编辑母板层级
*
* @author liyy
*
*/
public
class
editOutlinie
extends
NWN
implements
API
{
public
String
parameter
;
//参数集合
public
String
id
;
//层级ID
public
String
c_id
;
//层级ID
public
String
template_id_1
;
public
String
n_template_menu
;
// public String phone;//层级包id
@Override
public
void
initialize
(
HashMap
<
String
,
Object
>
data
)
{
try
{
String
sql
=
"SELECT MAX(id) AS id FROM n_template "
;
//SELECT id FROM n_template ORDER BY id DESC LIMIT 1
ResultSet
rs_bankcard
=
this
.
sqlFromDB
(
sql
);
rs_bankcard
.
last
();
id
=
rs_bankcard
.
getString
(
"id"
);
System
.
out
.
println
(
"db_templateid============"
+
rs_bankcard
.
getString
(
"id"
));
// Thread.sleep(5000);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
try
{
if
(
Integer
.
parseInt
(
id
)
<
100
)
{
n_template_menu
=
"n_template_menu_"
+
id
;
System
.
out
.
println
(
"n_template_menu==="
+
n_template_menu
);
}
else
{
n_template_menu
=
"n_template_menu_"
+
Integer
.
parseInt
(
id
)%
100
;
System
.
out
.
println
(
"n_template_menu==="
+
n_template_menu
);
}
String
sql
=
"SELECT MAX(id) AS id FROM "
+
n_template_menu
+
" where template_id ="
+
id
;
//SELECT id FROM n_template ORDER BY id DESC LIMIT 1
System
.
out
.
println
(
"sql==="
+
sql
);
ResultSet
rs_bankcard
=
this
.
sqlFromDB_template
(
sql
);
rs_bankcard
.
last
();
c_id
=
rs_bankcard
.
getString
(
"id"
);
System
.
out
.
println
(
"db_templateid============"
+
rs_bankcard
.
getString
(
"id"
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
@Override
public
HashMap
<
String
,
Object
>
handleInput
(
HashMap
<
String
,
Object
>
data
)
{
// 获取parameter对应的内容
parameter
=
MapUtil
.
getValue
(
"parameter"
,
data
);
template_id_1
=
MapUtil
.
getParameter_get
(
parameter
,
"template_id"
).
trim
();
id
=
MapUtil
.
getParameter_get
(
parameter
,
"id"
).
trim
();
if
((!
template_id_1
.
equals
(
""
))
&&
template_id_1
.
equals
(
"template_id"
))
{
template_id_1
=
template_id
;
parameter
=
parameter
.
replace
(
"template_id=template_id"
,
"template_id="
+
template_id_1
);
}
if
((!
id
.
equals
(
""
))
&&
id
.
equals
(
"id"
))
{
id
=
c_id
;
parameter
=
parameter
.
replace
(
"id=id"
,
"id="
+
c_id
);
}
data
.
put
(
"parameter"
,
parameter
);
return
data
;
}
@Override
public
Response
SendRequest
(
HashMap
<
String
,
Object
>
data
,
String
Url
,
String
Request
)
{
// Map<String,String> m=new HashMap<String,String>();
// m.put("user_info", parameter);
//Response re = RequestDataUtils.Post_cooike_form_data(data, Url,"PHPSESSID",PHPSESSID,m);
Response
re
=
RequestDataUtils
.
Get_one_cookie_pre
(
data
,
Url
,
"PHPSESSID"
,
PHPSESSID
);
//Response re = RequestDataUtils.Get_one_cookie(data, serviceURL, cookie1Name, cookie1value) //只能无参
// Response re = RequestDataUtils.Get_token(data, Url, "");
return
re
;
}
@Override
public
String
handleOutput
(
Response
re
,
HashMap
<
String
,
Object
>
data
)
{
JsonPath
jp
=
re
.
body
().
jsonPath
();
System
.
out
.
println
(
"jp===="
+
jp
);
boolean
result
=
true
;
String
failReason
=
""
;
String
json
=
re
.
asString
();
System
.
out
.
println
(
"response=========="
+
json
);
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
=
StringUtils
.
decodeUnicode
(
getMsg
(
re
));
String
code
=
getCode
(
re
);
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
(
"retcode"
)
+
"."
;
}
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
&&
json
!=
null
){
//如果自定义结果包含多个希望结果,也就是有逗号,那么就切割,包含比较。
if
(
data
.
get
(
"custom"
).
toString
().
contains
(
","
)){
String
[]
strCustomStrings
=
data
.
get
(
"custom"
).
toString
().
split
(
","
);
System
.
out
.
println
(
strCustomStrings
.
length
);
for
(
int
i
=
0
;
i
<
strCustomStrings
.
length
;
i
++){
if
(!
json
.
contains
(
strCustomStrings
[
i
])){
result
=
result
&&
false
;
failReason
=
failReason
+
"custom is expected "
+
data
.
get
(
"custom"
).
toString
()
+
" but actually "
+
strCustomStrings
[
i
]
+
"."
;
break
;
}
}
}
else
{
//如果只有一个希望结果,就直接包含比较。
if
(!
json
.
contains
(
data
.
get
(
"custom"
).
toString
())){
result
=
result
&&
false
;
failReason
=
failReason
+
"custom is expected "
+
data
.
get
(
"custom"
).
toString
()
+
" but actually "
+
data
.
get
(
"custom"
).
toString
()
+
"."
;
}
}
}
if
(
"0"
.
equals
(
code
)){
//是否验证数据库
if
(!
isProduct
)
{
}
}
}
if
(
result
)
return
"Pass"
;
else
return
"Fail:"
+
failReason
;
}
}
nwn_Api_auto_test/src/com/offcn/api/nwn/editTemp.java
0 → 100644
View file @
0982c646
package
com
.
offcn
.
api
.
nwn
;
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.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Random
;
import
org.json.simple.JSONArray
;
import
com.offcn.TestUnti.Log
;
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.process.TK
;
import
com.offcn.TestUnti.ListUtil
;
import
net.sf.json.JSONObject
;
/**
* 45. 母版信息编辑
*
* @author liyy
*
*/
public
class
editTemp
extends
NWN
implements
API
{
public
String
parameter
;
//参数集合
public
String
id
;
//母板ID
// public String phone;//层级包id
@Override
public
void
initialize
(
HashMap
<
String
,
Object
>
data
)
{
try
{
String
sql
=
"SELECT MAX(id) AS id FROM n_template "
;
//SELECT id FROM n_template ORDER BY id DESC LIMIT 1
ResultSet
rs_bankcard
=
this
.
sqlFromDB
(
sql
);
rs_bankcard
.
last
();
id
=
rs_bankcard
.
getString
(
"id"
);
System
.
out
.
println
(
"db_templateid============"
+
rs_bankcard
.
getString
(
"id"
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
@Override
public
HashMap
<
String
,
Object
>
handleInput
(
HashMap
<
String
,
Object
>
data
)
{
// 获取parameter对应的内容
parameter
=
MapUtil
.
getValue
(
"parameter"
,
data
);
id
=
MapUtil
.
getParameter
(
parameter
,
"id"
).
trim
();
if
((!
id
.
equals
(
""
))
&&
id
.
equals
(
"template_id"
))
{
id
=
template_id
;
parameter
=
parameter
.
replace
(
"\"id\":template_id"
,
"\"id\":"
+
id
);
}
data
.
put
(
"parameter"
,
parameter
);
return
data
;
}
@Override
public
Response
SendRequest
(
HashMap
<
String
,
Object
>
data
,
String
Url
,
String
Request
)
{
// Map<String,String> m=new HashMap<String,String>();
// m.put("user_info", parameter);
//Response re = RequestDataUtils.Post_cooike_form_data(data, Url,"PHPSESSID",PHPSESSID,m);
Response
re
=
RequestDataUtils
.
Post_cooike
(
data
,
Url
,
"PHPSESSID"
,
PHPSESSID
);
//Response re = RequestDataUtils.Get_one_cookie(data, serviceURL, cookie1Name, cookie1value) //只能无参
// Response re = RequestDataUtils.Get_token(data, Url, "");
return
re
;
}
@Override
public
String
handleOutput
(
Response
re
,
HashMap
<
String
,
Object
>
data
)
{
JsonPath
jp
=
re
.
body
().
jsonPath
();
System
.
out
.
println
(
"jp===="
+
jp
);
boolean
result
=
true
;
String
failReason
=
""
;
String
json
=
re
.
asString
();
System
.
out
.
println
(
"response=========="
+
json
);
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
=
StringUtils
.
decodeUnicode
(
getMsg
(
re
));
String
code
=
getCode
(
re
);
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
(
"retcode"
)
+
"."
;
}
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
&&
json
!=
null
){
//如果自定义结果包含多个希望结果,也就是有逗号,那么就切割,包含比较。
if
(
data
.
get
(
"custom"
).
toString
().
contains
(
","
)){
String
[]
strCustomStrings
=
data
.
get
(
"custom"
).
toString
().
split
(
","
);
System
.
out
.
println
(
strCustomStrings
.
length
);
for
(
int
i
=
0
;
i
<
strCustomStrings
.
length
;
i
++){
if
(!
json
.
contains
(
strCustomStrings
[
i
])){
result
=
result
&&
false
;
failReason
=
failReason
+
"custom is expected "
+
data
.
get
(
"custom"
).
toString
()
+
" but actually "
+
strCustomStrings
[
i
]
+
"."
;
break
;
}
}
}
else
{
//如果只有一个希望结果,就直接包含比较。
if
(!
json
.
contains
(
data
.
get
(
"custom"
).
toString
())){
result
=
result
&&
false
;
failReason
=
failReason
+
"custom is expected "
+
data
.
get
(
"custom"
).
toString
()
+
" but actually "
+
data
.
get
(
"custom"
).
toString
()
+
"."
;
}
}
}
if
(
"0"
.
equals
(
code
)){
/* //是否验证数据库
if (!isProduct) {
template_id=jp.getString("data.id").substring(0,jp.getString("data.id").length());
System.out.println("template_id====="+ template_id );
try {
String sql="SELECT MAX(id) AS id FROM n_template ";
//SELECT id FROM n_template ORDER BY id DESC LIMIT 1
ResultSet rs_bankcard = this.sqlFromDB(sql);
rs_bankcard.last();
System.out.println("after db_templateid============"+ rs_bankcard.getString("id"));
if(Integer.parseInt(rs_bankcard.getString("id")) == Integer.parseInt(id) )
{
if(!template_id.equals(rs_bankcard.getString("id")))
{
result = result && false;
failReason = failReason + "template_id info in DB is wrong;";
}else {
Log.logInfo("template_id info in DB is correct;");
}
}else {
result = result && false;
failReason = failReason + "template_id info in DB is wrong;";
}
} 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/api/nwn/getAllYears.java
0 → 100644
View file @
0982c646
package
com
.
offcn
.
api
.
nwn
;
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.text.SimpleDateFormat
;
import
java.util.Arrays
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Random
;
import
org.json.simple.JSONArray
;
import
com.offcn.TestUnti.Log
;
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.process.TK
;
import
com.offcn.TestUnti.ListUtil
;
import
net.sf.json.JSONObject
;
/**
* 添加用户信息(客户端单独)
*
* @author liyy
*
*/
public
class
getAllYears
extends
NWN
implements
API
{
public
String
parameter
;
//参数集合
public
String
package_id
;
//搜索-学习包id
public
String
phone
;
//层级包id
@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();
phone = MapUtil.getParameter_get(parameter, "phone").trim();
if ((!package_id.equals("")) && package_id.equals("package_id")) {
package_id=ListUtil.getListValue(n_package_idList, 0);
parameter = parameter.replace("package_id=package_id", "package_id="+ package_id );
}
if ((!phone.equals("")) && phone.equals("phone")) {
phone="135"+(new Random().nextInt(90000000)+ 10000000);
System.out.println("phone======"+phone);
parameter = parameter.replace("phone=phone", "phone="+ phone );
}
data.put("parameter", parameter);*/
return
data
;
}
@Override
public
Response
SendRequest
(
HashMap
<
String
,
Object
>
data
,
String
Url
,
String
Request
)
{
Response
re
=
RequestDataUtils
.
Get_one_cookie_pre
(
data
,
Url
,
"PHPSESSID"
,
PHPSESSID
);
//Response re = RequestDataUtils.Get_one_cookie(data, serviceURL, cookie1Name, cookie1value) //只能无参
// Response re = RequestDataUtils.Get_token(data, Url, "");
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
=
StringUtils
.
decodeUnicode
(
getMsg
(
re
));
String
code
=
getCode
(
re
);
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
&&
json
!=
null
){
//如果自定义结果包含多个希望结果,也就是有逗号,那么就切割,包含比较。
if
(
data
.
get
(
"custom"
).
toString
().
contains
(
","
)){
String
[]
strCustomStrings
=
data
.
get
(
"custom"
).
toString
().
split
(
","
);
System
.
out
.
println
(
strCustomStrings
.
length
);
for
(
int
i
=
0
;
i
<
strCustomStrings
.
length
;
i
++){
if
(!
json
.
contains
(
strCustomStrings
[
i
])){
result
=
result
&&
false
;
failReason
=
failReason
+
"custom is expected "
+
data
.
get
(
"custom"
).
toString
()
+
" but actually "
+
strCustomStrings
[
i
]
+
"."
;
break
;
}
}
}
else
{
//如果只有一个希望结果,就直接包含比较。
if
(!
json
.
contains
(
data
.
get
(
"custom"
).
toString
())){
result
=
result
&&
false
;
failReason
=
failReason
+
"custom is expected "
+
data
.
get
(
"custom"
).
toString
()
+
" but actually "
+
data
.
get
(
"custom"
).
toString
()
+
"."
;
}
}
}
if
(
"0"
.
equals
(
code
)){
}
}
if
(
result
)
return
"Pass"
;
else
return
"Fail:"
+
failReason
;
}
}
nwn_Api_auto_test/src/com/offcn/api/nwn/getTempInfo.java
0 → 100644
View file @
0982c646
package
com
.
offcn
.
api
.
nwn
;
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.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Random
;
import
org.json.simple.JSONArray
;
import
com.offcn.TestUnti.Log
;
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.process.TK
;
import
com.offcn.TestUnti.ListUtil
;
import
net.sf.json.JSONObject
;
/**
* 44. 获取单个母版信息
*
* @author liyy
*
*/
public
class
getTempInfo
extends
NWN
implements
API
{
public
String
parameter
;
//参数集合
public
String
id
;
//母板ID
// public String phone;//层级包id
@Override
public
void
initialize
(
HashMap
<
String
,
Object
>
data
)
{
}
@Override
public
HashMap
<
String
,
Object
>
handleInput
(
HashMap
<
String
,
Object
>
data
)
{
// 获取parameter对应的内容
parameter
=
MapUtil
.
getValue
(
"parameter"
,
data
);
id
=
MapUtil
.
getParameter_get
(
parameter
,
"id"
).
trim
();
if
((!
id
.
equals
(
""
))
&&
id
.
equals
(
"template_id"
))
{
id
=
template_id
;
parameter
=
parameter
.
replace
(
"id=template_id"
,
"id="
+
id
);
}
if
((!
id
.
equals
(
""
))
&&
id
.
equals
(
"template_id+random"
))
{
id
=
template_id
+
"aa"
;
parameter
=
parameter
.
replace
(
"id=template_id"
,
"id="
+
id
);
}
data
.
put
(
"parameter"
,
parameter
);
return
data
;
}
@Override
public
Response
SendRequest
(
HashMap
<
String
,
Object
>
data
,
String
Url
,
String
Request
)
{
// Map<String,String> m=new HashMap<String,String>();
// m.put("user_info", parameter);
//Response re = RequestDataUtils.Post_cooike_form_data(data, Url,"PHPSESSID",PHPSESSID,m);
Response
re
=
RequestDataUtils
.
Get_one_cookie_pre
(
data
,
Url
,
"PHPSESSID"
,
PHPSESSID
);
//Response re = RequestDataUtils.Get_one_cookie(data, serviceURL, cookie1Name, cookie1value) //只能无参
// Response re = RequestDataUtils.Get_token(data, Url, "");
return
re
;
}
@Override
public
String
handleOutput
(
Response
re
,
HashMap
<
String
,
Object
>
data
)
{
JsonPath
jp
=
re
.
body
().
jsonPath
();
System
.
out
.
println
(
"jp===="
+
jp
);
boolean
result
=
true
;
String
failReason
=
""
;
String
json
=
re
.
asString
();
System
.
out
.
println
(
"response=========="
+
json
);
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
=
StringUtils
.
decodeUnicode
(
getMsg
(
re
));
String
code
=
getCode
(
re
);
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
(
"retcode"
)
+
"."
;
}
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
&&
json
!=
null
){
//如果自定义结果包含多个希望结果,也就是有逗号,那么就切割,包含比较。
if
(
data
.
get
(
"custom"
).
toString
().
contains
(
","
)){
String
[]
strCustomStrings
=
data
.
get
(
"custom"
).
toString
().
split
(
","
);
System
.
out
.
println
(
strCustomStrings
.
length
);
for
(
int
i
=
0
;
i
<
strCustomStrings
.
length
;
i
++){
if
(!
json
.
contains
(
strCustomStrings
[
i
])){
result
=
result
&&
false
;
failReason
=
failReason
+
"custom is expected "
+
data
.
get
(
"custom"
).
toString
()
+
" but actually "
+
strCustomStrings
[
i
]
+
"."
;
break
;
}
}
}
else
{
//如果只有一个希望结果,就直接包含比较。
if
(!
json
.
contains
(
data
.
get
(
"custom"
).
toString
())){
result
=
result
&&
false
;
failReason
=
failReason
+
"custom is expected "
+
data
.
get
(
"custom"
).
toString
()
+
" but actually "
+
data
.
get
(
"custom"
).
toString
()
+
"."
;
}
}
}
if
(
"0"
.
equals
(
code
)){
/*//是否验证数据库
if (!isProduct) {
template_id=jp.getString("data.id").substring(0,jp.getString("data.id").length());
System.out.println("template_id====="+ template_id );
try {
String sql="SELECT MAX(id) AS id FROM n_template ";
//SELECT id FROM n_template ORDER BY id DESC LIMIT 1
ResultSet rs_bankcard = this.sqlFromDB(sql);
rs_bankcard.last();
System.out.println("after db_templateid============"+ rs_bankcard.getString("id"));
if(Integer.parseInt(rs_bankcard.getString("id")) > Integer.parseInt("1") )
{
if(!template_id.equals(rs_bankcard.getString("id")))
{
result = result && false;
failReason = failReason + "template_id info in DB is wrong;";
}else {
Log.logInfo("template_id info in DB is correct;");
}
}else {
result = result && false;
failReason = failReason + "template_id info in DB is wrong;";
}
} 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/api/nwn/outLineList.java
0 → 100644
View file @
0982c646
package
com
.
offcn
.
api
.
nwn
;
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.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Random
;
import
org.json.simple.JSONArray
;
import
com.offcn.TestUnti.Log
;
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.process.TK
;
import
com.offcn.TestUnti.ListUtil
;
import
net.sf.json.JSONObject
;
/**
* 添加母版层级
*
* @author liyy
*
*/
public
class
outLineList
extends
NWN
implements
API
{
public
String
parameter
;
//参数集合
public
String
template_id_1
;
//母板ID
// public String phone;//层级包id
@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_get
(
parameter
,
"template_id"
).
trim
();
if
((!
template_id_1
.
equals
(
""
))
&&
template_id_1
.
equals
(
"template_id"
))
{
template_id_1
=
template_id
;
parameter
=
parameter
.
replace
(
"template_id=template_id"
,
"template_id="
+
template_id_1
);
}
data
.
put
(
"parameter"
,
parameter
);
return
data
;
}
@Override
public
Response
SendRequest
(
HashMap
<
String
,
Object
>
data
,
String
Url
,
String
Request
)
{
// Map<String,String> m=new HashMap<String,String>();
// m.put("user_info", parameter);
//Response re = RequestDataUtils.Post_cooike_form_data(data, Url,"PHPSESSID",PHPSESSID,m);
Response
re
=
RequestDataUtils
.
Get_one_cookie_pre
(
data
,
Url
,
"PHPSESSID"
,
PHPSESSID
);
//Response re = RequestDataUtils.Get_one_cookie(data, serviceURL, cookie1Name, cookie1value) //只能无参
// Response re = RequestDataUtils.Get_token(data, Url, "");
return
re
;
}
@Override
public
String
handleOutput
(
Response
re
,
HashMap
<
String
,
Object
>
data
)
{
JsonPath
jp
=
re
.
body
().
jsonPath
();
System
.
out
.
println
(
"jp===="
+
jp
);
boolean
result
=
true
;
String
failReason
=
""
;
String
json
=
re
.
asString
();
System
.
out
.
println
(
"response=========="
+
json
);
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
=
StringUtils
.
decodeUnicode
(
getMsg
(
re
));
String
code
=
getCode
(
re
);
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
(
"retcode"
)
+
"."
;
}
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
&&
json
!=
null
){
//如果自定义结果包含多个希望结果,也就是有逗号,那么就切割,包含比较。
if
(
data
.
get
(
"custom"
).
toString
().
contains
(
","
)){
String
[]
strCustomStrings
=
data
.
get
(
"custom"
).
toString
().
split
(
","
);
System
.
out
.
println
(
strCustomStrings
.
length
);
for
(
int
i
=
0
;
i
<
strCustomStrings
.
length
;
i
++){
if
(!
json
.
contains
(
strCustomStrings
[
i
])){
result
=
result
&&
false
;
failReason
=
failReason
+
"custom is expected "
+
data
.
get
(
"custom"
).
toString
()
+
" but actually "
+
strCustomStrings
[
i
]
+
"."
;
break
;
}
}
}
else
{
//如果只有一个希望结果,就直接包含比较。
if
(!
json
.
contains
(
data
.
get
(
"custom"
).
toString
())){
result
=
result
&&
false
;
failReason
=
failReason
+
"custom is expected "
+
data
.
get
(
"custom"
).
toString
()
+
" but actually "
+
data
.
get
(
"custom"
).
toString
()
+
"."
;
}
}
}
if
(
"0"
.
equals
(
code
)){
/*//是否验证数据库
if (!isProduct) {
template_id=jp.getString("data.id").substring(0,jp.getString("data.id").length());
System.out.println("template_id====="+ template_id );
try {
String sql="SELECT MAX(id) AS id FROM n_template ";
//SELECT id FROM n_template ORDER BY id DESC LIMIT 1
ResultSet rs_bankcard = this.sqlFromDB(sql);
rs_bankcard.last();
System.out.println("after db_templateid============"+ rs_bankcard.getString("id"));
if(Integer.parseInt(rs_bankcard.getString("id")) > Integer.parseInt("1") )
{
if(!template_id.equals(rs_bankcard.getString("id")))
{
result = result && false;
failReason = failReason + "template_id info in DB is wrong;";
}else {
Log.logInfo("template_id info in DB is correct;");
}
}else {
result = result && false;
failReason = failReason + "template_id info in DB is wrong;";
}
} 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/api/nwn/templateList.java
0 → 100644
View file @
0982c646
package
com
.
offcn
.
api
.
nwn
;
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.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Random
;
import
org.json.simple.JSONArray
;
import
com.offcn.TestUnti.Log
;
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.process.TK
;
import
com.offcn.TestUnti.ListUtil
;
import
net.sf.json.JSONObject
;
/**
* 添加用户信息(客户端单独)
*
* @author liyy
*
*/
public
class
templateList
extends
NWN
implements
API
{
public
String
parameter
;
//参数集合
public
String
id
;
//母板ID
// public String phone;//层级包id
@Override
public
void
initialize
(
HashMap
<
String
,
Object
>
data
)
{
try
{
String
sql
=
"SELECT MAX(id) AS id FROM n_template "
;
//SELECT id FROM n_template ORDER BY id DESC LIMIT 1
ResultSet
rs_bankcard
=
this
.
sqlFromDB
(
sql
);
rs_bankcard
.
last
();
id
=
rs_bankcard
.
getString
(
"id"
);
System
.
out
.
println
(
"db_templateid============"
+
rs_bankcard
.
getString
(
"id"
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
@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();
phone = MapUtil.getParameter_get(parameter, "phone").trim();
if ((!package_id.equals("")) && package_id.equals("package_id")) {
package_id=ListUtil.getListValue(n_package_idList, 0);
parameter = parameter.replace("package_id=package_id", "package_id="+ package_id );
}
if ((!phone.equals("")) && phone.equals("phone")) {
phone="135"+(new Random().nextInt(90000000)+ 10000000);
System.out.println("phone======"+phone);
parameter = parameter.replace("phone=phone", "phone="+ phone );
}
data.put("parameter", parameter);*/
return
data
;
}
@Override
public
Response
SendRequest
(
HashMap
<
String
,
Object
>
data
,
String
Url
,
String
Request
)
{
// Map<String,String> m=new HashMap<String,String>();
// m.put("user_info", parameter);
//Response re = RequestDataUtils.Post_cooike_form_data(data, Url,"PHPSESSID",PHPSESSID,m);
Response
re
=
RequestDataUtils
.
Get_one_cookie_pre
(
data
,
Url
,
"PHPSESSID"
,
PHPSESSID
);
//Response re = RequestDataUtils.Get_one_cookie(data, serviceURL, cookie1Name, cookie1value) //只能无参
// Response re = RequestDataUtils.Get_token(data, Url, "");
return
re
;
}
@Override
public
String
handleOutput
(
Response
re
,
HashMap
<
String
,
Object
>
data
)
{
JsonPath
jp
=
re
.
body
().
jsonPath
();
System
.
out
.
println
(
"jp===="
+
jp
);
boolean
result
=
true
;
String
failReason
=
""
;
String
json
=
re
.
asString
();
System
.
out
.
println
(
"response=========="
+
json
);
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
=
StringUtils
.
decodeUnicode
(
getMsg
(
re
));
String
code
=
getCode
(
re
);
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
(
"retcode"
)
+
"."
;
}
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
&&
json
!=
null
){
//如果自定义结果包含多个希望结果,也就是有逗号,那么就切割,包含比较。
if
(
data
.
get
(
"custom"
).
toString
().
contains
(
","
)){
String
[]
strCustomStrings
=
data
.
get
(
"custom"
).
toString
().
split
(
","
);
System
.
out
.
println
(
strCustomStrings
.
length
);
for
(
int
i
=
0
;
i
<
strCustomStrings
.
length
;
i
++){
if
(!
json
.
contains
(
strCustomStrings
[
i
])){
result
=
result
&&
false
;
failReason
=
failReason
+
"custom is expected "
+
data
.
get
(
"custom"
).
toString
()
+
" but actually "
+
strCustomStrings
[
i
]
+
"."
;
break
;
}
}
}
else
{
//如果只有一个希望结果,就直接包含比较。
if
(!
json
.
contains
(
data
.
get
(
"custom"
).
toString
())){
result
=
result
&&
false
;
failReason
=
failReason
+
"custom is expected "
+
data
.
get
(
"custom"
).
toString
()
+
" but actually "
+
data
.
get
(
"custom"
).
toString
()
+
"."
;
}
}
}
if
(
"0"
.
equals
(
code
)){
//是否验证数据库
if
(!
isProduct
)
{
/* template_id=jp.getString("data.id").substring(0,jp.getString("data.id").length());
System.out.println("template_id====="+ template_id );
try {
String sql="SELECT MAX(id) AS id FROM n_template ";
//SELECT id FROM n_template ORDER BY id DESC LIMIT 1
ResultSet rs_bankcard = this.sqlFromDB(sql);
rs_bankcard.last();
System.out.println("after db_templateid============"+ rs_bankcard.getString("id"));
if(Integer.parseInt(rs_bankcard.getString("id")) > Integer.parseInt(id) )
{
if(!template_id.equals(rs_bankcard.getString("id")))
{
result = result && false;
failReason = failReason + "template_id info in DB is wrong;";
}else {
Log.logInfo("template_id info in DB is correct;");
}
}else {
result = result && false;
failReason = failReason + "template_id info in DB is wrong;";
}
} 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
;
}
}
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