Skip to content

Commit 7b19096

Browse files
author
liuyanw.liu
committed
完成showIconsrn接口测试case
1 parent 89aaf4e commit 7b19096

3 files changed

Lines changed: 105 additions & 5 deletions

File tree

src/main/resources/param.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ newIndexImprove.url=https://pay.qunar.com/mobile/h5/personalcenter/newIndexImpro
22
recommend.url=https://pay.qunar.com/mobile/h5/personalcenter/recommend.htm
33
showIcons.url=https://pay.qunar.com/mobile/h5/personalcenter/showIcons.htm
44
redpoint.url=https://pay.qunar.com/mobile/h5/personalcenter/redpoint.htm
5+
showIconsrn.url=https://pay.qunar.com/mobile/h5/personalcenter/showIconsrn.htm

src/test/java/test/MyIndexTest.java

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import util.HttpClientUtil;
77
import util.PropertiesUtil;
88

9+
import java.util.HashMap;
10+
import java.util.Map;
911
import java.util.logging.Level;
1012
import java.util.logging.Logger;
1113

@@ -17,11 +19,19 @@ public class MyIndexTest {
1719
* 测试代码
1820
*/
1921
public static void main (String[] args){
20-
String url =PropertiesUtil.getProperty("redpoint.url");
21-
String responseStr = HttpClientUtil.doPost(url);
22+
String url =PropertiesUtil.getProperty("showIconsrn.url");
23+
Map<String,String> param = new HashMap<String,String>();
24+
param.put("scheme","qunaraphone");
25+
param.put("isRN","true");
26+
param.put("qpVersion","32");
27+
Map<String,String> hearder = new HashMap<String,String>();
28+
hearder.put("Cookie","QN1=000015000600105c80c0fe20; QN48=tc_3149f483c5f4e96c_168ac300f4d_4784; QN300=organic; QN235=2019-02-18; _i=ue-xY4nyAVjXXXhy46BjDAKxT4yX; _vi=hNwn1H4wgZCT2xfQFk7XaJPgFNj2hU8sofoCjpYMQVE6H8ny_fF3O6O365rmcrPLmMaDfFuQrTmnAEm8soAdM2TKrvRdsWWYqJoZZlqhGfhzzrdNAQZG2cwivz7ahoOvogPxVNdyN7jEDAPtcvBxZ2q75OEtsH64Smt462DO9vZZ; fid=20132569-ea87-46b8-a3f1-eca497d4010b; QN241=; QN270=1111%2C60001246%2CC5065%2CAA3A1BAC-8FE5-D291-7A30-EA36647C4D48%2C10010; csrfToken=ULW1fDPwz3pSJDK; _v=GfCYmRk0kYhpRxMB3ZoDVKxVj_dnUDyJmlWzLRhPk2soqmnRl1eQMpxqqHadx8avmeJscPx0QasxuMX2uESWc9kYHIlyf0npzRXIwIAQEaFlyRwhCvtzYPjXwNAfdCrycI-z1z0GxLiPR3k5cpv8b_6UYKR9J_DmIIpEyfIbmKLH; _t=26080242; _q=U.gscsldt7224; _s=s_HJHX5SDL6UJ6WUIEPDYAOSCV4Q");
29+
//mobile/h5/personalcenter/showIconsrn.htm?scheme=qunaraphone&isRN=true&qpVersion=32
30+
String responseStr = HttpClientUtil.doGet(url,param,hearder);
31+
//HttpClientUtil.doPost(url);
2232
JSONObject obj = JSON.parseObject(responseStr);
2333
String status = obj.getString("status");
24-
System.out.println(responseStr);
34+
System.out.println("responseStr:" + responseStr);
2535
System.out.println(status);
2636
}
2737

@@ -86,4 +96,28 @@ public void redpoint(){
8696
logger.info("redpoint.status:"+ status);
8797
assertTrue("0".equals(obj.getString("status")));
8898
}
99+
100+
101+
/**
102+
* 我的页面,showIconsrn(Iconsrn接口)测试-已登录
103+
*/
104+
@Test
105+
public void showIconsrn(){
106+
String url = PropertiesUtil.getProperty("showIconsrn.url");
107+
Map<String,String> param = new HashMap<String,String>();
108+
param.put("scheme","qunaraphone");
109+
param.put("isRN","true");
110+
param.put("qpVersion","32");
111+
Map<String,String> hearder = new HashMap<String,String>();
112+
hearder.put("Cookie","QN1=000015000600105c80c0fe20; QN48=tc_3149f483c5f4e96c_168ac300f4d_4784; QN300=organic; QN235=2019-02-18; _i=ue-xY4nyAVjXXXhy46BjDAKxT4yX; _vi=hNwn1H4wgZCT2xfQFk7XaJPgFNj2hU8sofoCjpYMQVE6H8ny_fF3O6O365rmcrPLmMaDfFuQrTmnAEm8soAdM2TKrvRdsWWYqJoZZlqhGfhzzrdNAQZG2cwivz7ahoOvogPxVNdyN7jEDAPtcvBxZ2q75OEtsH64Smt462DO9vZZ; fid=20132569-ea87-46b8-a3f1-eca497d4010b; QN241=; QN270=1111%2C60001246%2CC5065%2CAA3A1BAC-8FE5-D291-7A30-EA36647C4D48%2C10010; csrfToken=ULW1fDPwz3pSJDK; _v=GfCYmRk0kYhpRxMB3ZoDVKxVj_dnUDyJmlWzLRhPk2soqmnRl1eQMpxqqHadx8avmeJscPx0QasxuMX2uESWc9kYHIlyf0npzRXIwIAQEaFlyRwhCvtzYPjXwNAfdCrycI-z1z0GxLiPR3k5cpv8b_6UYKR9J_DmIIpEyfIbmKLH; _t=26080242; _q=U.gscsldt7224; _s=s_HJHX5SDL6UJ6WUIEPDYAOSCV4Q");
113+
//mobile/h5/personalcenter/showIconsrn.htm?scheme=qunaraphone&isRN=true&qpVersion=32
114+
String responseStr = HttpClientUtil.doGet(url,param,hearder);
115+
JSONObject obj = JSON.parseObject(responseStr);
116+
String status = obj.getString("status");
117+
logger.setLevel(Level.INFO);
118+
logger.info("showIconsrn:" + responseStr);
119+
logger.info("showIconsrn.stauts:" + status);
120+
assertTrue("0".equals(obj.getString("status")));
121+
}
122+
89123
}

src/test/java/util/HttpClientUtil.java

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package util;
22

3+
import org.apache.http.HttpEntity;
4+
import org.apache.http.HttpResponse;
35
import org.apache.http.NameValuePair;
6+
import org.apache.http.client.ClientProtocolException;
47
import org.apache.http.client.entity.UrlEncodedFormEntity;
58
import org.apache.http.client.methods.CloseableHttpResponse;
69
import org.apache.http.client.methods.HttpGet;
@@ -12,6 +15,7 @@
1215
import org.apache.http.util.EntityUtils;
1316

1417
import java.io.IOException;
18+
import java.io.UnsupportedEncodingException;
1519
import java.net.URI;
1620
import java.util.ArrayList;
1721
import java.util.List;
@@ -24,7 +28,7 @@ public class HttpClientUtil {
2428
* @param param 请求参数
2529
* @return 结果
2630
*/
27-
public static String doGet(String url, Map<String, String> param) {
31+
public static String doGet(String url, Map<String, String> param,Map<String, String> headers) {
2832

2933
// 创建Httpclient对象
3034
CloseableHttpClient httpclient = HttpClients.createDefault();
@@ -39,10 +43,18 @@ public static String doGet(String url, Map<String, String> param) {
3943
builder.addParameter(key, param.get(key));
4044
}
4145
}
46+
4247
URI uri = builder.build();
48+
String urlStr = uri.toString();
49+
System.out.println("urlStr:" + urlStr);
4350

4451
// 创建http GET请求
4552
HttpGet httpGet = new HttpGet(uri);
53+
if(headers!=null){
54+
for(Map.Entry<String,String> en:headers.entrySet()){
55+
httpGet.setHeader(en.getKey(), en.getValue());
56+
}
57+
}
4658

4759
// 执行请求
4860
response = httpclient.execute(httpGet);
@@ -65,13 +77,21 @@ public static String doGet(String url, Map<String, String> param) {
6577
return resultString;
6678
}
6779

80+
81+
82+
83+
84+
85+
86+
87+
6888
/**
6989
* 无参数的get请求
7090
* @param url 请求地址
7191
* @return 返回结果
7292
*/
7393
public static String doGet(String url) {
74-
return doGet(url, null);
94+
return doGet(url, null,null);
7595
}
7696

7797
/**
@@ -115,6 +135,49 @@ public static String doPost(String url, Map<String, String> param) {
115135
return resultString;
116136
}
117137

138+
139+
public static String doPost(String url,Map<String,String> params,Map<String,String> headers) {
140+
CloseableHttpClient client = HttpClients.createDefault();
141+
HttpPost httpPost = new HttpPost(url);
142+
UrlEncodedFormEntity entity;
143+
List<NameValuePair> paramPairs = new ArrayList<NameValuePair>();
144+
if(params!=null){
145+
for(Map.Entry<String,String> en:params.entrySet()){
146+
paramPairs.add(new BasicNameValuePair(en.getKey(), en.getValue()));
147+
}
148+
}
149+
if(headers!=null){
150+
for(Map.Entry<String,String> en:headers.entrySet()){
151+
httpPost.setHeader(en.getKey(), en.getValue());
152+
}
153+
}
154+
try {
155+
entity = new UrlEncodedFormEntity(paramPairs, "UTF-8");
156+
httpPost.setEntity(entity);
157+
HttpResponse resp = client.execute(httpPost);
158+
HttpEntity respEntity = resp.getEntity();
159+
if (null != respEntity) {
160+
return EntityUtils.toString(respEntity, "UTF-8");
161+
}
162+
163+
} catch (UnsupportedEncodingException e) {
164+
e.printStackTrace();
165+
} catch (ClientProtocolException e) {
166+
e.printStackTrace();
167+
} catch (IOException e) {
168+
e.printStackTrace();
169+
} finally {
170+
try {
171+
client.close();
172+
} catch (Exception e) {
173+
e.printStackTrace();
174+
}
175+
}
176+
return null;
177+
}
178+
179+
180+
118181
/**
119182
* 无参的post请求
120183
* @param url 请求url
@@ -123,4 +186,6 @@ public static String doPost(String url, Map<String, String> param) {
123186
public static String doPost(String url) {
124187
return doPost(url, null);
125188
}
189+
190+
126191
}

0 commit comments

Comments
 (0)