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
9bff54ef
Commit
9bff54ef
authored
Jul 03, 2019
by
wff66504
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
20190703
parent
251f25b6
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
879 additions
and
1 deletions
+879
-1
CaseMakeWff.xls
nwn_Api_auto_test/TestData/CaseMakeWff.xls
+0
-0
DataAllWff.xls
nwn_Api_auto_test/TestData/DataAllWff.xls
+0
-0
getPracticeModuleDetail.java
...rc/com/offcn/api/nwn/service/getPracticeModuleDetail.java
+215
-0
getQuestionRecord.java
...test/src/com/offcn/api/nwn/service/getQuestionRecord.java
+213
-0
getUserManageList.java
...test/src/com/offcn/api/nwn/service/getUserManageList.java
+214
-0
getUserPracticeInfo.java
...st/src/com/offcn/api/nwn/service/getUserPracticeInfo.java
+233
-0
NWN.java
nwn_Api_auto_test/src/com/offcn/process/NWN.java
+4
-1
No files found.
nwn_Api_auto_test/TestData/CaseMakeWff.xls
View file @
9bff54ef
No preview for this file type
nwn_Api_auto_test/TestData/DataAllWff.xls
View file @
9bff54ef
No preview for this file type
nwn_Api_auto_test/src/com/offcn/api/nwn/service/getPracticeModuleDetail.java
0 → 100644
View file @
9bff54ef
package
com
.
offcn
.
api
.
nwn
.
service
;
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.system.MyRequest
;
import
com.offcn.TestUnti.ListUtil
;
import
net.sf.json.JSONObject
;
/**
*
* @Description: 29.教务系统练习组件详情列表
* @author: wff
* @date: 2019年7月1日 下午20:22:17
* @version V1.0
*/
public
class
getPracticeModuleDetail
extends
NWN
implements
API
{
public
String
parameter
;
//参数集合
public
String
user_sso_id
;
//当前用户的sso_id
public
String
package_id
;
//学习包id
public
String
page
;
//页码
public
String
size
;
//每页数量
@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
();
user_sso_id
=
MapUtil
.
getParameter_get
(
parameter
,
"user_sso_id"
).
trim
();
page
=
MapUtil
.
getParameter_get
(
parameter
,
"page"
).
trim
();
size
=
MapUtil
.
getParameter_get
(
parameter
,
"size"
).
trim
();
if
((!
package_id
.
equals
(
""
))
&&
package_id
.
equals
(
"code"
))
{
package_id
=
ListUtil
.
getListValue
(
n_package_idList
,
0
);
parameter
=
parameter
.
replace
(
"package_id=code"
,
"package_id="
+
package_id
);
}
if
((!
user_sso_id
.
equals
(
""
))
&&
user_sso_id
.
equals
(
"code"
))
{
user_sso_id
=
"1"
+
new
Random
().
nextInt
(
9000000
);
parameter
=
parameter
.
replace
(
"user_sso_id=code"
,
"user_sso_id="
+
user_sso_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, "");
Map
<
String
,
String
>
cookies
=
new
HashMap
<
String
,
String
>();
cookies
.
put
(
"PHPSESSID"
,
PHPSESSID
);
/*Map<String,String> token=new HashMap<String,String>();
token.put("Authorization", tk_token);*/
MyRequest
myRequest
=
new
MyRequest
();
myRequest
.
setParameter
(
parameter
);
myRequest
.
setUrl
(
Url
);
myRequest
.
setRequest
(
Request
);
myRequest
.
setCookies
(
cookies
);
Response
re
=
RequestDataUtils
.
RestAssuredApi
(
data
,
myRequest
);
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=========="
+
StringUtils
.
decodeUnicode
(
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"
)
+
"."
;
}
/*System.out.println((data.get("msg") != null));
System.out.println((msg != null));
System.out.println(data.get("msg").toString().length());
System.out.println(msg.length());
*/
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/service/getQuestionRecord.java
0 → 100644
View file @
9bff54ef
package
com
.
offcn
.
api
.
nwn
.
service
;
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.system.MyRequest
;
import
com.offcn.TestUnti.ListUtil
;
import
net.sf.json.JSONObject
;
/**
*
* @Description: 26 .获取主观题学员做题记录
* @author: wff
* @date: 2019年7月1日 下午1:57:04
* @version V1.0
*/
public
class
getQuestionRecord
extends
NWN
implements
API
{
public
String
parameter
;
//参数集合
public
String
package_id
;
//学习包id
public
String
question_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
();
question_id
=
MapUtil
.
getParameter_get
(
parameter
,
"question_id"
).
trim
();
if
((!
package_id
.
equals
(
""
))
&&
package_id
.
equals
(
"code"
))
{
// package_id=ListUtil.getListValue(n_package_idList, 0);
package_id
=
"4027309"
;
parameter
=
parameter
.
replace
(
"package_id=code"
,
"package_id="
+
package_id
);
}
if
((!
question_id
.
equals
(
""
))
&&
question_id
.
equals
(
"code"
))
{
question_id
=
"106048"
;
parameter
=
parameter
.
replace
(
"question_id=code"
,
"question_id="
+
question_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, "");
Map
<
String
,
String
>
cookies
=
new
HashMap
<
String
,
String
>();
cookies
.
put
(
"PHPSESSID"
,
PHPSESSID
);
/*Map<String,String> token=new HashMap<String,String>();
token.put("Authorization", tk_token);*/
MyRequest
myRequest
=
new
MyRequest
();
myRequest
.
setParameter
(
parameter
);
myRequest
.
setUrl
(
Url
);
myRequest
.
setRequest
(
Request
);
myRequest
.
setCookies
(
cookies
);
Response
re
=
RequestDataUtils
.
RestAssuredApi
(
data
,
myRequest
);
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=========="
+
StringUtils
.
decodeUnicode
(
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"
)
+
"."
;
}
/*System.out.println((data.get("msg") != null));
System.out.println((msg != null));
System.out.println(data.get("msg").toString().length());
System.out.println(msg.length());
*/
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/service/getUserManageList.java
0 → 100644
View file @
9bff54ef
package
com
.
offcn
.
api
.
nwn
.
service
;
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.system.MyRequest
;
import
com.offcn.TestUnti.ListUtil
;
import
net.sf.json.JSONObject
;
/**
*
* @Description: 28.教务系统获取学员管理-学员列表
* @author: wff
* @date: 2019年7月1日 下午19:57:04
* @version V1.0
*/
public
class
getUserManageList
extends
NWN
implements
API
{
public
String
parameter
;
//参数集合
public
String
package_id
;
//学习包id
public
String
user_name
;
//学员姓名
public
String
page
;
//页码(默认1)
public
String
size
;
//每页的数量(默认15)
public
String
phone
;
//学员手机号
// 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
();
user_name
=
MapUtil
.
getParameter_get
(
parameter
,
"user_name"
).
trim
();
page
=
MapUtil
.
getParameter_get
(
parameter
,
"page"
).
trim
();
size
=
MapUtil
.
getParameter_get
(
parameter
,
"size"
).
trim
();
phone
=
MapUtil
.
getParameter_get
(
parameter
,
"phone"
).
trim
();
if
((!
package_id
.
equals
(
""
))
&&
package_id
.
equals
(
"code"
))
{
// package_id=ListUtil.getListValue(n_package_idList, 0);
package_id
=
"4027309"
;
parameter
=
parameter
.
replace
(
"package_id=code"
,
"package_id="
+
package_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, "");
Map
<
String
,
String
>
cookies
=
new
HashMap
<
String
,
String
>();
cookies
.
put
(
"PHPSESSID"
,
PHPSESSID
);
/*Map<String,String> token=new HashMap<String,String>();
token.put("Authorization", tk_token);*/
MyRequest
myRequest
=
new
MyRequest
();
myRequest
.
setParameter
(
parameter
);
myRequest
.
setUrl
(
Url
);
myRequest
.
setRequest
(
Request
);
myRequest
.
setCookies
(
cookies
);
Response
re
=
RequestDataUtils
.
RestAssuredApi
(
data
,
myRequest
);
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=========="
+
StringUtils
.
decodeUnicode
(
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"
)
+
"."
;
}
/*System.out.println((data.get("msg") != null));
System.out.println((msg != null));
System.out.println(data.get("msg").toString().length());
System.out.println(msg.length());
*/
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/service/getUserPracticeInfo.java
0 → 100644
View file @
9bff54ef
package
com
.
offcn
.
api
.
nwn
.
service
;
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.system.MyRequest
;
import
com.offcn.TestUnti.ListUtil
;
import
net.sf.json.JSONObject
;
/**
*
* @Description: 27.获取练习主件(练习册/试卷)的某一个用户的答
* @author: wff
* @date: 2019年7月1日 下午4:29:51
* @version V1.0
*/
public
class
getUserPracticeInfo
extends
NWN
implements
API
{
public
String
parameter
;
//参数集合
public
String
sso_id
;
//该用户的sso_id
public
String
module_type
;
//组建类型
public
String
exam_id
;
//试卷id
public
String
record_id
;
//记录id
public
String
practice_id
;
//练习册id
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
);
sso_id
=
MapUtil
.
getParameter_get
(
parameter
,
"sso_id"
).
trim
();
module_type
=
MapUtil
.
getParameter_get
(
parameter
,
"module_type"
).
trim
();
exam_id
=
MapUtil
.
getParameter_get
(
parameter
,
"exam_id"
).
trim
();
record_id
=
MapUtil
.
getParameter_get
(
parameter
,
"record_id"
).
trim
();
practice_id
=
MapUtil
.
getParameter_get
(
parameter
,
"practice_id"
).
trim
();
package_id
=
MapUtil
.
getParameter_get
(
parameter
,
"package_id"
).
trim
();
if
((!
sso_id
.
equals
(
""
))
&&
sso_id
.
equals
(
"code"
))
{
sso_id
=
"1"
+
new
Random
().
nextInt
(
9000000
);
parameter
=
parameter
.
replace
(
"sso_id=code"
,
"sso_id="
+
sso_id
);
}
if
((!
exam_id
.
equals
(
""
))
&&
exam_id
.
equals
(
"code"
))
{
exam_id
=
"4321"
;
parameter
=
parameter
.
replace
(
"exam_id=code"
,
"exam_id="
+
exam_id
);
}
if
((!
record_id
.
equals
(
""
))
&&
record_id
.
equals
(
"code"
))
{
record_id
=
"14517"
;
parameter
=
parameter
.
replace
(
"record_id=code"
,
"record_id="
+
record_id
);
}
if
((!
practice_id
.
equals
(
""
))
&&
practice_id
.
equals
(
"code"
))
{
practice_id
=
"111"
;
parameter
=
parameter
.
replace
(
"practice_id=code"
,
"practice_id="
+
practice_id
);
}
if
((!
package_id
.
equals
(
""
))
&&
package_id
.
equals
(
"code"
))
{
package_id
=
ListUtil
.
getListValue
(
n_package_idList
,
0
);
parameter
=
parameter
.
replace
(
"package_id=code"
,
"package_id="
+
package_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, "");
Map
<
String
,
String
>
cookies
=
new
HashMap
<
String
,
String
>();
cookies
.
put
(
"PHPSESSID"
,
PHPSESSID
);
/*Map<String,String> token=new HashMap<String,String>();
token.put("Authorization", tk_token);*/
MyRequest
myRequest
=
new
MyRequest
();
myRequest
.
setParameter
(
parameter
);
myRequest
.
setUrl
(
Url
);
myRequest
.
setRequest
(
Request
);
myRequest
.
setCookies
(
cookies
);
Response
re
=
RequestDataUtils
.
RestAssuredApi
(
data
,
myRequest
);
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=========="
+
StringUtils
.
decodeUnicode
(
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"
)
+
"."
;
}
/*System.out.println((data.get("msg") != null));
System.out.println((msg != null));
System.out.println(data.get("msg").toString().length());
System.out.println(msg.length());
*/
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/process/NWN.java
View file @
9bff54ef
...
@@ -215,7 +215,10 @@ public class NWN extends BasicsGM{
...
@@ -215,7 +215,10 @@ public class NWN extends BasicsGM{
List
<
String
>
user_List
=
new
ArrayList
<
String
>();
List
<
String
>
user_List
=
new
ArrayList
<
String
>();
for
(
int
i
=
0
;
i
<
n_package_idList
.
size
();
i
++){
for
(
int
i
=
0
;
i
<
n_package_idList
.
size
();
i
++){
try
{
try
{
deleteFromDB
(
"n_package"
,
"id"
,
n_package_idList
.
get
(
i
));
//硬删除
// deleteFromDB("n_package", "id", n_package_idList.get(i));
//软删除
// updateOrderStatus("n_package", "", n_package_idList.get(i));
//deleteFromDB("n_packcode", "package_id", n_package_idList.get(i));
//deleteFromDB("n_packcode", "package_id", n_package_idList.get(i));
//deleteFromDB("n_packcode_record", "package_id", n_package_idList.get(i));
//deleteFromDB("n_packcode_record", "package_id", n_package_idList.get(i));
user_List
.
add
(
n_package_idList
.
get
(
i
));
user_List
.
add
(
n_package_idList
.
get
(
i
));
...
...
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