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
77f068e1
Commit
77f068e1
authored
Jan 30, 2019
by
shuai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加response与http关联方法
parent
c2745fc8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
340 additions
and
21 deletions
+340
-21
HttpRequest.java
nwn_Api_auto_test/src/com/offcn/TestUnti/HttpRequest.java
+26
-10
IoResponse.java
nwn_Api_auto_test/src/com/offcn/TestUnti/IoResponse.java
+310
-0
addStuden.java
...pi_auto_test/src/com/offcn/api/nwn/service/addStuden.java
+4
-11
No files found.
nwn_Api_auto_test/src/com/offcn/TestUnti/HttpRequest.java
View file @
77f068e1
...
@@ -2,6 +2,8 @@ package com.offcn.TestUnti;
...
@@ -2,6 +2,8 @@ package com.offcn.TestUnti;
import
io.restassured.response.Response
;
import
java.io.BufferedReader
;
import
java.io.BufferedReader
;
import
java.io.FileInputStream
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.FileOutputStream
;
...
@@ -26,19 +28,23 @@ public class HttpRequest {
...
@@ -26,19 +28,23 @@ public class HttpRequest {
* @return URL 所代表远程资源的响应结果
* @return URL 所代表远程资源的响应结果
*/
*/
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
String
s
=
HttpRequest
.
sendGet
(
"http://beta.alitest.eoffcn.com/template/addStuden/sign/5d114486999208096dace001ae4bc45a"
,
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"
);
"user_info=[{\"package_id\":391634,\"username\":\"aaa\",\"phone\":15656333337,\"sso_id\":1}]×tamp=1548828632&appid=jiaowu"
);
try
{
System
.
out
.
println
(
s
.
getStatusCode
());
String
s1
=
new
String
(
s
.
getBytes
(),
"utf-8"
);
System
.
out
.
println
(
s
.
asString
());
System
.
out
.
println
(
s1
);
// try {
}
catch
(
UnsupportedEncodingException
e
)
{
// String s1=new String(s.getBytes(),"utf-8");
e
.
printStackTrace
();
// System.out.println(s1);
}
// } catch (UnsupportedEncodingException e) {
// e.printStackTrace();
// }
}
}
public
static
String
sendGet
(
String
url
,
String
param
)
{
public
static
Response
sendGet
(
String
url
,
String
param
)
{
String
result
=
""
;
String
result
=
""
;
String
val
=
""
;
BufferedReader
in
=
null
;
BufferedReader
in
=
null
;
Response
re
=
null
;
try
{
try
{
// String urlNameString = url ;
// String urlNameString = url ;
String
urlNameString
=
url
+
"?"
+
param
;
String
urlNameString
=
url
+
"?"
+
param
;
...
@@ -54,7 +60,13 @@ public class HttpRequest {
...
@@ -54,7 +60,13 @@ public class HttpRequest {
Map
<
String
,
List
<
String
>>
map
=
connection
.
getHeaderFields
();
Map
<
String
,
List
<
String
>>
map
=
connection
.
getHeaderFields
();
// 遍历所有的响应头字段
// 遍历所有的响应头字段
for
(
String
key
:
map
.
keySet
())
{
for
(
String
key
:
map
.
keySet
())
{
System
.
out
.
println
(
key
+
"--->"
+
map
.
get
(
key
));
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的响应
// 定义 BufferedReader输入流来读取URL的响应
in
=
new
BufferedReader
(
new
InputStreamReader
(
in
=
new
BufferedReader
(
new
InputStreamReader
(
...
@@ -82,6 +94,10 @@ public class HttpRequest {
...
@@ -82,6 +94,10 @@ public class HttpRequest {
}
}
// o.close();
// o.close();
IoResponse
ir
=
new
IoResponse
();
re
=
ir
.
setResponseValue
(
val
,
result
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"发送GET请求出现异常!"
+
e
);
System
.
out
.
println
(
"发送GET请求出现异常!"
+
e
);
e
.
printStackTrace
();
e
.
printStackTrace
();
...
@@ -96,7 +112,7 @@ public class HttpRequest {
...
@@ -96,7 +112,7 @@ public class HttpRequest {
e2
.
printStackTrace
();
e2
.
printStackTrace
();
}
}
}
}
return
re
sult
;
return
re
;
}
}
/**
/**
...
...
nwn_Api_auto_test/src/com/offcn/TestUnti/IoResponse.java
0 → 100644
View file @
77f068e1
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
View file @
77f068e1
...
@@ -39,7 +39,6 @@ public class addStuden extends NWN implements API {
...
@@ -39,7 +39,6 @@ public class addStuden extends NWN implements API {
public
String
template_id_1
;
//母板ID
public
String
template_id_1
;
//母板ID
public
String
response
;
//返回结果
// public String phone;//层级包id
// public String phone;//层级包id
@Override
@Override
public
void
initialize
(
HashMap
<
String
,
Object
>
data
)
{
public
void
initialize
(
HashMap
<
String
,
Object
>
data
)
{
...
@@ -78,25 +77,19 @@ public class addStuden extends NWN implements API {
...
@@ -78,25 +77,19 @@ public class addStuden extends NWN implements API {
//Response re = RequestDataUtils.Post_cooike_form_data(data, Url,"PHPSESSID",PHPSESSID,m);
//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_pre(data, Url, "PHPSESSID",PHPSESSID);
response
=
HttpRequest
.
sendGet
(
"http://beta.alitest.eoffcn.com/template/addStuden/sign/5d114486999208096dace001ae4bc45a"
,
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"
);
"user_info=[{\"package_id\":391634,\"username\":\"aaa\",\"phone\":15656333337,\"sso_id\":1}]×tamp=1548828632&appid=jiaowu"
);
try
{
return
re
;
String
s1
=
new
String
(
response
.
getBytes
(),
"utf-8"
);
System
.
out
.
println
(
s1
);
}
catch
(
UnsupportedEncodingException
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
}
@Override
@Override
public
String
handleOutput
(
Response
re
,
HashMap
<
String
,
Object
>
data
)
{
public
String
handleOutput
(
Response
re
,
HashMap
<
String
,
Object
>
data
)
{
JsonPath
jp
=
new
JsonPath
(
re
sponse
);
JsonPath
jp
=
new
JsonPath
(
re
.
asString
()
);
System
.
out
.
println
(
"jp===="
+
jp
);
System
.
out
.
println
(
"jp===="
+
jp
);
boolean
result
=
true
;
boolean
result
=
true
;
String
failReason
=
""
;
String
failReason
=
""
;
String
json
=
re
sponse
;
String
json
=
re
.
asString
()
;
System
.
out
.
println
(
"response=========="
+
StringUtils
.
decodeUnicode
(
json
));
System
.
out
.
println
(
"response=========="
+
StringUtils
.
decodeUnicode
(
json
));
if
((
data
.
get
(
"statusCode"
)
!=
null
)
if
((
data
.
get
(
"statusCode"
)
!=
null
)
...
...
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