Commit 052ec99e authored by 吕雯燕's avatar 吕雯燕

lv

parent 474374c1
......@@ -5,10 +5,12 @@ import base.DuibaBases;
import base.DuibaTestBase;
import http.service.Authorization;
import http.service.Manager.ADeveloperService;
import http.service.app.AlipayExchangeService;
import http.service.app.gawService;
import http.service.app.tawService;
import http.service.app.MobileService;
import http.service.hd.DeveloperAccountService;
import http.service.hd.DsOrderService;
import org.apache.http.auth.AUTH;
import utils.MatcherString;
import base.DuibaLog;
import io.restassured.response.Response;
......@@ -20,6 +22,9 @@ import org.testng.annotations.Test;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.Date;
import java.util.Calendar;
import java.text.SimpleDateFormat;
import static io.restassured.RestAssured.given;
......@@ -29,6 +34,148 @@ import static io.restassured.RestAssured.given;
public class 新支付宝_兑换流程测试_ExchangeTest extends CheckTemplet {
@Autowired
gawService gawService;
@Autowired
Authorization authorization;
@Autowired
tawService tawService;
@Autowired
MobileService mobileService;
@Test(description = "1元支付宝用户兑换限制永久1次")
public void 支付宝用户永久兑换限制测试() throws Exception{
int uid = 7262;
String actualCredits = "100";
String degreeId = "1";
String appItemId = "195996";
String credits = "100";
String message = "";
try{
//支付宝兑换
Response response = this.支付宝兑换(uid,actualCredits,degreeId,appItemId,credits);
Assert.assertEquals(response.jsonPath().getString("data.payCreditsStatus"),"1","校验兑换失败");
logger.info("用户成功兑换一次");
//再次兑换
Thread.sleep(3000);
try{
response = gawService.alipayExchange(uid,actualCredits,degreeId,appItemId,credits);
response.prettyPrint();
}catch (Exception e){
message = e.toString();
}
logger.info(message);
//获取按钮状态
Response detailResponse = mobileService.detail(authorization.dafuwengLogin(uid),"55");
String btnText = MatcherString.getString(detailResponse.asString(), "\"1\":\\{\"btnText\":\"(.*?)\",", 1);
logger.info("再次兑换按钮:" + btnText);
Assert.assertTrue(message.contains("\"desc\":\"已兑完\""),"校验用户兑换限制失败");
Assert.assertEquals(btnText,"已兑换","校验马上兑换按钮状态失败");
logger.info("校验支付宝1元用户永久兑换限制成功");
}catch (Exception e){
throw new Exception("异常信息打印:" + e);
}finally {
jdbc.update("DELETE FROM credits_dev.consumer_limit_record_only WHERE item_id = 55 AND consumer_id = 100147103");
jdbc.update("DELETE FROM credits_dev.consumer_limit_record WHERE item_id = 55 AND consumer_id = 100147103");
}
}
@Test(description = "2元支付宝用户兑换限制每天1次")
public void 支付宝用户每天兑换限制测试() throws Exception{
int uid = 7270;
String actualCredits = "200";
String degreeId = "2";
String appItemId = "195996";
String credits = "200";
String message = "";
try{
//支付宝兑换
Response response = this.支付宝兑换(uid,actualCredits,degreeId,appItemId,credits);
Assert.assertEquals(response.jsonPath().getString("data.payCreditsStatus"),"1","校验兑换失败");
logger.info("用户成功兑换一次");
//再次兑换
Thread.sleep(3000);
try{
response = gawService.alipayExchange(uid,actualCredits,degreeId,appItemId,credits);
response.prettyPrint();
}catch (Exception e){
message = e.toString();
}
logger.info(message);
//获取按钮状态
Response detailResponse = mobileService.detail(authorization.dafuwengLogin(uid),"55");
String btnText = MatcherString.getString(detailResponse.asString(), "\"2\":\\{\"btnText\":\"(.*?)\",", 1);
logger.info("再次兑换按钮:" + btnText);
Assert.assertTrue(message.contains("\"desc\":\"已兑完\""),"校验用户兑换限制失败");
Assert.assertEquals(btnText,"今日已兑换","校验马上兑换按钮状态失败");
logger.info("校验支付宝2元用户每天兑换限制成功");
}catch (Exception e){
throw new Exception("异常信息打印:" + e);
}finally {
//获取当前日期时间,再减一天
Date date=new Date();
Calendar calendar=Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DAY_OF_MONTH, -1);
SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
logger.info("当前时间-1天:" + dateFormat.format(calendar.getTime()));
//更新表记录,修改记录为前一天
String sql = "UPDATE credits_dev.consumer_limit_record SET gmt_create = '" + dateFormat.format(calendar.getTime()) +"' WHERE item_id = 55 and consumer_id = 100147117 ORDER BY id DESC LIMIT 1";
jdbc.update(sql);
}
}
public Response 支付宝兑换(int uid, String actualCredits, String degreeId, String appItemId,String credits) throws Exception {
Response response = gawService.alipayExchange(uid, actualCredits, degreeId, appItemId, credits);
response.prettyPrint();
String orderId = response.jsonPath().getString("data.orderId");
//查看兑换结果
response = tawService.orderStatus(orderId,uid);
response.prettyPrint();
String status = response.jsonPath().getString("data.status");
//异步接口
int i = 10;
while (i > 0 && status.equals("processing")) {
Thread.sleep(1000);
response = tawService.orderStatus(orderId,uid);
response.prettyPrint();
status = response.jsonPath().getString("data.status");
i--;
}
return response;
}
......
......@@ -17,6 +17,7 @@ import java.util.List;
import java.util.Map;
import static io.restassured.RestAssured.given;
import static io.restassured.RestAssured.post;
@Service
public class gawService {
......@@ -345,6 +346,47 @@ public class gawService {
}
//新支付宝兑换接口
public Response alipayExchange(int uid, String actualCredits, String degreeId, String appItemId,String credits) throws Exception {
Map<String,Object> map = new HashMap<>();
Map<String,Object> mapList = new HashMap<>();
List<Map> list = new ArrayList<>();
mapList.put("appItemId",appItemId);
mapList.put("credits",credits);
list.add(mapList);
map.put("actualCredits",actualCredits); //总积分
map.put("actualPrice","0");
map.put("alipay","15858196010");
map.put("degreeId",degreeId);
map.put("realname","测试");
map.put("remark","");
map.put("token","yrJRr7Cddp2YeQd");
map.put("validate","");
map.put("itemParam",list.toArray());
JSONObject jsonParam = JSONObject.parseObject(JSON.toJSONString(map));
logger.info("请求支付宝兑换接口:"+ "/gaw/alipayExchange/create");
Response response = given().contentType("application/json; charset=UTF-8").cookies(authorization.dafuwengLogin(uid)).body(jsonParam).post("http://"+goodsHost+"/gaw/alipayExchange/create");
try{
Assert.assertEquals(response.jsonPath().getString("success"),"true");
}catch(Exception e){
throw new Exception("/gaw/alipayExchange/create接口返回异常,返回信息:"+response.asString());
}catch(Error er){
throw new Exception("/gaw/alipayExchange/create接口返回异常,返回信息:"+response.asString());
}
return response;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment