接口测试"/>
java实现https接口测试
51Testing软件测试网;[IN!^UU3f%^T1]
package com.sysinfo.users;T#GB8V C/G051Testing软件测试网0zP&]!V#d!e)}4\Z!y
import java.sql.Connection;51Testing软件测试网H@$Cv@Hla$J(w
import java.sql.ResultSet;
[e&CtGB;LR0import java.sql.Statement;51Testing软件测试网w1V7b2k\.y[ [
import java.util.Properties;51Testing软件测试网sc"|-x,xY8Ozrp
import net.sf.json.JSONObject;51Testing软件测试网iEb$c[*r p51Testing软件测试网Fjgg~.z\/`X
import org.testng.Assert;
S#y4ZG4ywB{0import org.testng.annotations.BeforeClass;
*N^*put5_leEX/S0import org.testng.annotations.Test;a$TBRPI0
2v
ZSp,tX G;I?v0import com.mfexchange.util.*;W!E7r+W H{~x'fR051Testing软件测试网7mp/BE7PAJ^a;r
@Test51Testing软件测试网&ew}0qY5L*LR
public class TCA001LoginUser {
"wq[ct0 String test;
"]'wA_?0 public static String apiIp = null;
5dt.Q1`(m.pow-i0 public static String auths = null;51Testing软件测试网5xIRL`
nK+wL-b
Properties testdataconfig = LibDataConfig.getInstance().getProperties();
%R\,@$^:T6?]0 private static final LibLogger logger = LibLogger
Z^Y%alBS*T0 .getLogger(TCA001LoginUser.class);V:K Fc6E~051Testing软件测试网X6V^{1Rr
@BeforeClass51Testing软件测试网SG/kH^1tXw7C
public void setUp() throws Exception {51Testing软件测试网hx;Yo3S?
wL
logger.log(" Auto Test Data Init ! ");@i7V7P6u'V0
XYU8n_?.ij0 Connection conn = null;51Testing软件测试网_qVp!q%zoq
Statement statement = null;51Testing软件测试网8~@$uu7}
ResultSet rs = null;
_$_&}MA@&~0 int rs_del = 0;0Pu[:|;d051Testing软件测试网[~osr4h |Vk4R
try {
E?4e5M#v|`#i0 conn = LibJDBC.getConnection();
s:[4{\yy7KNk.R0 statement = conn.createStatement();
0B.RsOd0 String sql1 = "UPDATE users set phone_number=15811297594 ,password='fcbdf647ea2ae6bff9c859e0403cd219648349d27e11d9fc0304c0d681538eb4' WHERE user_id='3618'";
@
uWuW*x.l0 rs_del = statement.executeUpdate(sql1);
A9VFY5WC Xh$zr0 } catch (Exception e1) {51Testing软件测试网8UCW6d#z.O%z
e1.printStackTrace();51Testing软件测试网j{kL:W
wPx{fD
} finally {51Testing软件测试网'e#jCK'CZM
LibJDBC.release(rs, statement, conn);
5j:g/Q+r*yZ(I S^0 }
z5ydiiU%o%T0 }51Testing软件测试网"DS{,p~nT9l
a$f#Ycht0 public String gettest() {
(ai3iT7D8wU0 return test;
/i@;_/rx~0 }51Testing软件测试网r ie0l3P(`-Xf51Testing软件测试网$B&~h9s&e\8X
public String getLoginResultInfo(String userName, String passwd) {0jsR(P5PSy.@x&n051Testing软件测试网|6rj&G#UD2}c-`U
if (apiIp == null) {51Testing软件测试网Q0TMM\e(`!~F
apiIp = testdataconfig.getProperty("testMURL.apiIp");
;qnJh/_}g$N0 }
7Mi1_I+F:f|MC0 String actualResults;
&V/^X9o%x5U0 String callUrls = "loginUserSystem.do";51Testing软件测试网DcJ"k%mV
String auths = "info={'username':'"
+q9FX6?I:Us0 + userName51Testing软件测试网k0jKqx:X
+ "','loginPwd':'"51Testing软件测试网V"~#a(n^.nV/`Z5r
+ passwd
,pJ'vPk8j_,Y0 + "'}&auth="51Testing软件测试网ewPBeu"F&OV2T
+ "{'source':'7','vendor':'100000','appver':'1','version':'20'}";51Testing软件测试网A(Rg A$G!u
StringBuffer sbs = new StringBuffer();
@G)C'V
U0 sbs.append(apiIp).append(callUrls).append("?");
[5yi%u3CG0 String results2 = HttpUtils.doPostBody(sbs.toString(), auths, null,51Testing软件测试网8iO@2Y([
"utf-8", false);
stn]0j8C6K*] @-i0 actualResults = results2.replace('\"', '\'');51Testing软件测试网;d*@U
UNO
return actualResults;
}fw8TD+~a+[0 }
O8I[O2X$}0 // 为其它接口需要获取UserSession使用
3kt(p
lIu']&X0 public String getUserSession(String userName, String passwd) {51Testing软件测试网0K:b;RtJCw
TCA001LoginUser LoginUser = new TCA001LoginUser();51Testing软件测试网X@5xX`%a
String actualResults = LoginUser.getLoginResultInfo(userName, passwd);
t'e5]g$I{0 logger.log("Login actualResults is:" + actualResults);
9j3?[6ajm0 JSONObject dataJson = JSONObject.fromObject(actualResults);
xXz(D]0 String resultInfo = dataJson.getString("result");51Testing软件测试网"`y_V0gF!l0s
+E0x[v%x0 JSONObject resultInfoBody = JSONObject.fromObject(resultInfo);51Testing软件测试网s(l.aXw%Ht1V;u
String userSession = resultInfoBody.getString("userSession");51Testing软件测试网9I&a4g;ym,|'a+_
// logger.log("resultInfo is :" +resultInfo );
;R-?o0e4a!b([,m0 if( userSession.equals("null")){
&^0w#A[zjI0 logger.log("userSession is :" + userSession);
msOs.z8fI h0 return null;51Testing软件测试网Nj_I)S{+p
}51Testing软件测试网(D"h8JB,w
return userSession;51Testing软件测试网X|um)R%nPkK4`T,E
}9cUb}&P'H(@xu051Testing软件测试网RhZ8L^
]1U^
NO(g0]X9~0 public String getUserId(String userName, String passwd) {
U%GMW#tu+{6b#[%}0 TCA001LoginUser LoginUser = new TCA001LoginUser();51Testing软件测试网6sK3q?1~x%{
String actualResults = LoginUser.getLoginResultInfo(userName, passwd);
3@(G%VkN;\)Qk!N0 JSONObject dataJson = JSONObject.fromObject(actualResults);51Testing软件测试网#Jw0rtUle9E*H
String resultInfo = dataJson.getString("result");51Testing软件测试网%I$y1Uq9O?y(q|
JSONObject resultInfoBody = JSONObject.fromObject(resultInfo);
mA8lY@^L0 String userId = resultInfoBody.getString("userId");51Testing软件测试网M h1jH2? l`
return userId;51Testing软件测试网3O'v(K q.Ge
}v'yWQt051Testing软件测试网AaHe^:[zC
51Testing软件测试网(eW#Sq0hD:r'K;o$My
public boolean loginUser(String userName, String passwd) {
I!h5dbvV$\0 if (apiIp == null) {
\FH1p,s0 apiIp = testdataconfig.getProperty("testMURL.apiIp");51Testing软件测试网 bvo,B#o
logger.log(" apiIp is : " + apiIp);
4uKNed0 }51Testing软件测试网Bv/n~$Y
String actualResults;
]9_!]Q~ma2O6oe0 String callUrls = "loginUserSystem.do";
`^1_'t8mmH:b0 String auths = "info={'username':'"
__;ZyJ6c0 + userName
!R{ ?pK't0 + "','loginPwd':'"51Testing软件测试网 e` q Y5CN
+ passwd
:Yb-[3l4s~7a'o3w0 + "'}&auth="
zY;b/UD4l+Ln0 + "{'source':'7','vendor':'100000','appver':'1','version':'20'}";51Testing软件测试网3LDE(?V`&z
StringBuffer sbs = new StringBuffer();51Testing软件测试网%SU,pkC6l"S
sbs.append(apiIp).append(callUrls).append("?");
a2Y6G#tl)R0 logger.log("sbs.toString() :"+sbs.toString());51Testing软件测试网 }_{]0kcG
String results2 = HttpUtils.doPostBody(sbs.toString(), auths, null,
更多推荐
java实现https接口测试
发布评论