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
3c63574c
Commit
3c63574c
authored
Jan 30, 2019
by
Li Yongyu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
09
parent
e54e43ac
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
0 additions
and
685 deletions
+0
-685
HttpRequest.java
nwn_Api_auto_test/src/com/offcn/TestUnti/HttpRequest.java
+0
-163
IoResponse.java
nwn_Api_auto_test/src/com/offcn/TestUnti/IoResponse.java
+0
-310
addStuden.java
...pi_auto_test/src/com/offcn/api/nwn/service/addStuden.java
+0
-212
No files found.
nwn_Api_auto_test/src/com/offcn/TestUnti/HttpRequest.java
deleted
100644 → 0
View file @
e54e43ac
package
com
.
offcn
.
TestUnti
;
import
io.restassured.response.Response
;
import
java.io.BufferedReader
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.io.OutputStreamWriter
;
import
java.io.PrintWriter
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URL
;
import
java.net.URLConnection
;
import
java.util.List
;
import
java.util.Map
;
public
class
HttpRequest
{
/**
* 向指定URL发送GET方法的请求
*
* @param url
* 发送请求的URL
* @param param
* 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
* @return URL 所代表远程资源的响应结果
*/
public
static
void
main
(
String
[]
args
)
{
Response
s
=
HttpRequest
.
sendGet
(
"http://beta.alitest.eoffcn.com/template/addStuden/sign/5d114486999208096dace001ae4bc45a"
,
"user_info=[{\"package_id\":391634,\"username\":\"aaa\",\"phone\":15656333337,\"sso_id\":1}]×tamp=1548828632&appid=jiaowu"
);
System
.
out
.
println
(
s
.
getStatusCode
());
System
.
out
.
println
(
s
.
asString
());
// try {
// String s1=new String(s.getBytes(),"utf-8");
// System.out.println(s1);
// } catch (UnsupportedEncodingException e) {
// e.printStackTrace();
// }
}
public
static
Response
sendGet
(
String
url
,
String
param
)
{
String
result
=
""
;
String
val
=
""
;
BufferedReader
in
=
null
;
Response
re
=
null
;
try
{
// String urlNameString = url ;
String
urlNameString
=
url
+
"?"
+
param
;
URL
realUrl
=
new
URL
(
urlNameString
);
// 打开和URL之间的连接
URLConnection
connection
=
realUrl
.
openConnection
();
// 设置通用的请求属性
connection
.
setRequestProperty
(
"Authorization"
,
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6NSwicGhvbmUiOiIxODUxMTg1MjA0OSIsImlhdCI6MTQ4NzEzMjU0OX0.2aZ8FcfE52CYpXc4VUYjdfzzLzXwVOE-J8CnMlhUPic"
);
connection
.
setRequestProperty
(
"Content-Type"
,
"application/json"
);
// 建立实际的连接
connection
.
connect
();
// 获取所有响应头字段
Map
<
String
,
List
<
String
>>
map
=
connection
.
getHeaderFields
();
// 遍历所有的响应头字段
for
(
String
key
:
map
.
keySet
())
{
String
va
=
map
.
get
(
key
).
toString
();
System
.
out
.
println
(
key
+
"--->"
+
va
);
if
(
va
.
contains
(
"HTTP/1.1"
)){
val
=
va
.
toString
().
substring
(
10
,
va
.
toString
().
length
()-
4
);
System
.
out
.
println
(
val
);
}
}
// 定义 BufferedReader输入流来读取URL的响应
in
=
new
BufferedReader
(
new
InputStreamReader
(
connection
.
getInputStream
()));
String
line
;
while
((
line
=
in
.
readLine
())
!=
null
)
{
// o.write(line+"\r\n");
result
+=
line
;
result
+=
"\r\n"
;
}
// o.close();
IoResponse
ir
=
new
IoResponse
();
re
=
ir
.
setResponseValue
(
val
,
result
);
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"发送GET请求出现异常!"
+
e
);
e
.
printStackTrace
();
}
// 使用finally块来关闭输入流
finally
{
try
{
if
(
in
!=
null
)
{
in
.
close
();
}
}
catch
(
Exception
e2
)
{
e2
.
printStackTrace
();
}
}
return
re
;
}
/**
* 向指定 URL 发送POST方法的请求
*
* @param url
* 发送请求的 URL
* @param param
* 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
* @return 所代表远程资源的响应结果
*/
public
static
String
sendPost
(
String
url
,
String
param
)
{
PrintWriter
out
=
null
;
BufferedReader
in
=
null
;
String
result
=
""
;
try
{
URL
realUrl
=
new
URL
(
url
);
// 打开和URL之间的连接
URLConnection
conn
=
realUrl
.
openConnection
();
// 设置通用的请求属性
conn
.
setRequestProperty
(
"Authorization"
,
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6NSwicGhvbmUiOiIxODUxMTg1MjA0OSIsImlhdCI6MTQ4NzEzMjU0OX0.2aZ8FcfE52CYpXc4VUYjdfzzLzXwVOE-J8CnMlhUPic"
);
conn
.
setRequestProperty
(
"Content-Type"
,
"application/json"
);
// 发送POST请求必须设置如下两行
conn
.
setDoOutput
(
true
);
conn
.
setDoInput
(
true
);
// 获取URLConnection对象对应的输出流
out
=
new
PrintWriter
(
conn
.
getOutputStream
());
// 发送请求参数
out
.
print
(
param
);
// flush输出流的缓冲
out
.
flush
();
// 定义BufferedReader输入流来读取URL的响应
in
=
new
BufferedReader
(
new
InputStreamReader
(
conn
.
getInputStream
()));
String
line
;
while
((
line
=
in
.
readLine
())
!=
null
)
{
result
+=
line
;
result
+=
"\r\n"
;
}
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"发送 POST 请求出现异常!"
+
e
);
e
.
printStackTrace
();
}
//使用finally块来关闭输出流、输入流
finally
{
try
{
if
(
out
!=
null
){
out
.
close
();
}
if
(
in
!=
null
){
in
.
close
();
}
}
catch
(
IOException
ex
){
ex
.
printStackTrace
();
}
}
return
result
;
}
}
nwn_Api_auto_test/src/com/offcn/TestUnti/IoResponse.java
deleted
100644 → 0
View file @
e54e43ac
package
com
.
offcn
.
TestUnti
;
import
java.io.InputStream
;
import
java.util.Map
;
import
java.util.concurrent.TimeUnit
;
import
io.restassured.http.Cookie
;
import
io.restassured.http.Cookies
;
import
io.restassured.http.Headers
;
import
io.restassured.mapper.ObjectMapper
;
import
io.restassured.mapper.ObjectMapperType
;
import
io.restassured.path.json.JsonPath
;
import
io.restassured.path.json.config.JsonPathConfig
;
import
io.restassured.path.xml.XmlPath
;
import
io.restassured.path.xml.XmlPath.CompatibilityMode
;
import
io.restassured.path.xml.config.XmlPathConfig
;
import
io.restassured.response.Response
;
import
io.restassured.response.ResponseBody
;
import
io.restassured.response.ValidatableResponse
;
public
class
IoResponse
{
public
static
void
main
(
String
[]
args
)
{
// TODO Auto-generated method stub
}
public
Response
setResponseValue
(
String
StatusCode
,
String
asString
){
Response
re
=
new
Response
()
{
@Override
public
ValidatableResponse
then
()
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
long
timeIn
(
TimeUnit
arg0
)
{
// TODO Auto-generated method stub
return
0
;
}
@Override
public
long
time
()
{
// TODO Auto-generated method stub
return
0
;
}
@Override
public
Response
thenReturn
()
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
String
statusLine
()
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
int
statusCode
()
{
// TODO Auto-generated method stub
return
0
;
}
@Override
public
String
sessionId
()
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
Headers
headers
()
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
String
header
(
String
arg0
)
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
long
getTimeIn
(
TimeUnit
arg0
)
{
// TODO Auto-generated method stub
return
0
;
}
@Override
public
long
getTime
()
{
// TODO Auto-generated method stub
return
0
;
}
@Override
public
String
getStatusLine
()
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
int
getStatusCode
()
{
return
Integer
.
valueOf
(
StatusCode
);
}
@Override
public
String
getSessionId
()
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
Headers
getHeaders
()
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
String
getHeader
(
String
arg0
)
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
Cookies
getDetailedCookies
()
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
Cookie
getDetailedCookie
(
String
arg0
)
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
Map
<
String
,
String
>
getCookies
()
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
String
getCookie
(
String
arg0
)
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
String
getContentType
()
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
ResponseBody
getBody
()
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
Cookies
detailedCookies
()
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
Cookie
detailedCookie
(
String
arg0
)
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
Map
<
String
,
String
>
cookies
()
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
String
cookie
(
String
arg0
)
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
String
contentType
()
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
ResponseBody
body
()
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
Response
andReturn
()
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
String
asString
()
{
// TODO Auto-generated method stub
return
asString
;
}
@Override
public
InputStream
asInputStream
()
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
byte
[]
asByteArray
()
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
XmlPath
xmlPath
(
CompatibilityMode
arg0
)
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
XmlPath
xmlPath
(
XmlPathConfig
arg0
)
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
XmlPath
xmlPath
()
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
<
T
>
T
path
(
String
arg0
,
String
...
arg1
)
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
JsonPath
jsonPath
(
JsonPathConfig
arg0
)
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
JsonPath
jsonPath
()
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
XmlPath
htmlPath
()
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
<
T
>
T
as
(
Class
<
T
>
arg0
,
ObjectMapper
arg1
)
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
<
T
>
T
as
(
Class
<
T
>
arg0
,
ObjectMapperType
arg1
)
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
<
T
>
T
as
(
Class
<
T
>
arg0
)
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
String
print
()
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
String
prettyPrint
()
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
Response
prettyPeek
()
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
Response
peek
()
{
// TODO Auto-generated method stub
return
null
;
}
};
return
re
;
}
}
nwn_Api_auto_test/src/com/offcn/api/nwn/service/addStuden.java
deleted
100644 → 0
View file @
e54e43ac
package
com
.
offcn
.
api
.
nwn
.
service
;
import
io.restassured.path.json.JsonPath
;
import
io.restassured.response.Response
;
import
java.io.UnsupportedEncodingException
;
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.HttpRequest
;
import
com.offcn.TestUnti.Log
;
import
com.offcn.TestUnti.MapUtil
;
import
com.offcn.TestUnti.RequestDataUtils
;
import
com.offcn.TestUnti.StringUtils
;
import
com.offcn.api.nwn.md5.nwngetsign
;
import
com.offcn.interfaces.API
;
import
com.offcn.process.NWN
;
import
com.offcn.process.TK
;
import
com.offcn.TestUnti.ListUtil
;
/**
* 添加学员信息
*
* @author liyy
*
*/
public
class
addStuden
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
();
timestamp
=
MapUtil
.
getParameter_get
(
parameter
,
"timestamp"
).
trim
();
if
((!
template_id_1
.
equals
(
""
))
&&
template_id_1
.
equals
(
"template_id"
))
{
template_id_1
=
"["
+
template_id
+
","
+(
Integer
.
parseInt
(
template_id
)-
1
)+
"]"
;
parameter
=
parameter
.
replace
(
"template_id=template_id"
,
"template_id="
+
template_id_1
);
}
if
((!
timestamp
.
equals
(
""
))
&&
timestamp
.
equals
(
"timestamp"
))
{
Long
timeString
=
System
.
currentTimeMillis
();
timestamp
=
timeString
.
toString
().
substring
(
0
,
10
);
parameter
=
parameter
.
replace
(
"timestamp=timestamp"
,
"timestamp="
+
timestamp
);
}
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);
<<<<<<<
HEAD
//response=HttpRequest.sendGet("http://beta.alitest.eoffcn.com/template/addStuden/sign/5d114486999208096dace001ae4bc45a",
// "user_info=[{\"package_id\":391634,\"username\":\"aaa\",\"phone\":15656333337,\"sso_id\":1}]×tamp=1548828632&appid=jiaowu");
System
.
out
.
println
(
"parameter===="
+
parameter
);
System
.
out
.
println
(
"url==="
+
Url
);
response
=
HttpRequest
.
sendGet
(
"http://beta.alitest.eoffcn.com"
+
Url
,
parameter
);
try
{
String
s1
=
new
String
(
response
.
getBytes
(),
"utf-8"
);
System
.
out
.
println
(
s1
);
}
catch
(
UnsupportedEncodingException
e
)
{
e
.
printStackTrace
();
}
return
null
;
=======
Response
re
=
HttpRequest
.
sendGet
(
"http://beta.alitest.eoffcn.com/template/addStuden/sign/5d114486999208096dace001ae4bc45a"
,
"user_info=[{\"package_id\":391634,\"username\":\"aaa\",\"phone\":15656333337,\"sso_id\":1}]×tamp=1548828632&appid=jiaowu"
);
return
re
;
>>>>>>>
branch
'
master
'
of
git
@gitlab
.
eoffcn
.
com
:
ys65701
/
nwn_Api_auto_test
.
git
}
@Override
public
String
handleOutput
(
Response
re
,
HashMap
<
String
,
Object
>
data
)
{
JsonPath
jp
=
new
JsonPath
(
re
.
asString
());
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) {
String data_res=jp.getString("data").substring(0,jp.getString("data").length());
System.out.println("data_res====="+ data_res );
try {
String sql="SELECT MAX(id) AS id FROM `n_package` WHERE template_id = " + template_id;
//SELECT id FROM n_template ORDER BY id DESC LIMIT 1
ResultSet rs_bankcard = this.sqlFromDB(sql);
rs_bankcard.last();
System.out.println("after findedupack ============"+ rs_bankcard.getString("id"));
if(Integer.parseInt(rs_bankcard.getString("id")) >= Integer.parseInt("1"))
{
n_package_idList.add(rs_bankcard.getString("id"));
}else {
result = result && false;
failReason = failReason + "edupack info in DB is wrong;";
}
} catch (Exception e) {
result = result && false;
failReason = failReason + "cannot verify edupack 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