Commit 629bee8c authored by 赵然's avatar 赵然

zr

parent c7a95f64
package http.cases.ExchangeTest;
public class Database {
//主订单库
public static String orders_consumer = "orders_consumer";
//主订单分表
public static String orders = "orders_0614";
public static String orders2 = "orders_0874";
public static String orders3 = "orders_0693";
public static String orders4 = "orders_0208";
public static String orders5 = "orders_0209";
public static String orders6 = "orders_0210";
public static String orders7 = "orders_0211";
}
package http.cases.ExchangeTest;
import base.DuibaTestBase;
import http.service.Activity.ManagerService;
import http.service.Authorization;
import http.service.app.CouponExchangeService;
import http.service.app.MobileService;
import http.service.app.SeckillService;
import http.service.hd.PlatformCouponService;
import base.DuibaLog;
import io.restassured.response.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.util.Map;
//@ContextConfiguration(classes = DuibaConfig.class)
public class Exchange_ExchangeTest extends DuibaTestBase{
@Value("${manager.host}")
String ManagerHost;
@Autowired
private MobileService mobileService;
@Autowired
private Authorization authorization;
@Autowired
private CouponExchangeService couponExchangeService;
@Autowired
private PlatformCouponService platformCouponService;
@Autowired
private SeckillService SeckillService;
@Autowired
ManagerService managerService;
private DuibaLog logger = DuibaLog.getLogger();
// private MysqlUtils jdbc;
//指定用户
private static int uid = 3766;
// @BeforeClass
// public void before(){
// jdbc = MysqlUtils.mysqlDuiba("dafuweng");
// }
// @AfterClass
// public void after(){
// jdbc.releaseConn();
//
// }
//实物兑换并发货
@Test(description = "实物兑换")
public void goods() throws Exception {
//查询数据库,当前积分
Map<String,Object> mapuser = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid);
String credits = String.valueOf(mapuser.get("credits"));
logger.info("兑换前积分:"+credits);
//扣去100积分
credits = String.valueOf(Integer.valueOf(credits)-100);
//活动详情页
Response response =mobileService.detail(authorization.dafuwengLogin(uid),"26762");
Map<String,String> map = authorization.dafuwengLogin(uid);
Assert.assertEquals(String.valueOf(response.getStatusCode()),"200","活动详情页请求异常");
//实物兑换
response = couponExchangeService.objectExchange(map,"159143","2619","null","z9sydmcs","null");
// response.prettyPrint();
//校验兑换成功
// Assert.assertEquals(response.jsonPath().getString("success"),"true");
//获取orderId
String orderId = response.jsonPath().getString("orderId");
//获取兑换结果
response = mobileService.orderAmbStatusQuery(uid,orderId);
response.prettyPrint();
String message = response.jsonPath().getString("data.message");
int i=10;
//异步接口,直到兑换成功
while(i>0&&"兑换正在处理中...".equals(message)){
Thread.sleep(1000);
response = mobileService.orderAmbStatusQuery(uid,orderId);
response.prettyPrint();
message = response.jsonPath().getString("data.message");
i--;
}
//查询数据库,获取当前积分
Thread.sleep(3000);
mapuser = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid);
String creditsNew = String.valueOf(mapuser.get("credits"));
logger.info("兑换后积分:"+creditsNew);
//校验比较,兑换前后积分
Assert.assertEquals(credits,creditsNew);
logger.info("校验兑换前后积分正确");
//兑吧管理后台发货
managerService.expressSend(orderId);
logger.info("实物兑换订单成功");
}
//秒杀
@Test(description = "秒杀兑换")
public void seckill(){
Response response = SeckillService.ajaxSubmit("18556");
response.prettyPrint();
Assert.assertEquals(response.jsonPath().getString("success"),"true");
}
//优惠券兑换
@Test(description = "优惠券兑换")
public void coupon() throws Exception {
//查询数据库,当前积分
Map<String,Object> mapuser = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid);
String credits = String.valueOf(mapuser.get("credits"));
logger.info("兑换前积分:"+credits); //扣去100积分
credits = String.valueOf(Integer.valueOf(credits)-100);
//优惠券兑换
Response response = couponExchangeService.couponExchange(authorization.dafuwengLogin(uid),"157070","27050");
String orderId = response.jsonPath().getString("orderId");
//查看兑换结果
response = mobileService.orderStatusQuery(response.getDetailedCookies(),uid,orderId);
String status = response.jsonPath().getString("status");
//异步接口
int i=10;
while(i>0&&"processing".equals(status)){
Thread.sleep(1000);
response = mobileService.orderStatusQuery(response.getDetailedCookies(),uid,orderId);
response.prettyPrint();
status = response.jsonPath().getString("status");
i--;
}
//查询数据库,获取当前积分
Thread.sleep(3000);
mapuser = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid);
String creditsNew = String.valueOf(mapuser.get("credits"));
logger.info("兑换后积分:"+creditsNew);
//校验比较,兑换前后积分
Assert.assertEquals(credits.trim(),creditsNew,"优惠券兑换后积分扣除异常");
logger.info("校验兑换前后积分正确");
}
}
package http.cases.ExchangeTest;
import base.DuibaTestBase;
import http.service.Activity.ManagerService;
import http.service.Authorization;
import http.service.app.*;
import utils.ExcelDataProvider;
import base.DuibaLog;
import io.restassured.response.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.Map;
/**
* Created by yeqinqin on 2018/4/24.
*/
public class ObjectExchange_ExchangeTest extends DuibaTestBase{
@Autowired
private MobileService mobileService;
@Autowired
private Authorization authorization;
@Autowired
private CouponExchangeService couponExchangeService;
@Autowired
private CrecordService crecordService;
@Autowired
ManagerService managerService;
@Autowired
VirtualExchangeService virtualExchangeService;
@Autowired
QbExchangeService qbExchangeService;
private DuibaLog logger = DuibaLog.getLogger();
//指定用户
private static int uid = 2707;
@BeforeClass
public void before() {
managerService.update(uid,"5555555");
// jdbc = MysqlUtils.mysqlDuiba("orders_consumer");
try {
jdbc.update("delete from orders_consumer.orders_0614 where consumer_id = 100011622 and biz_params = 'DUIBA_SELF'", null);
} catch (Exception e) {
e.printStackTrace();
}
}
// @AfterClass
// public void after() {
// jdbc.releaseConn();
//
// }
//实物兑换并发货
//@Test(description = "实物兑换")
public void goods() throws Exception {
//查询数据库,当前积分
Map<String, Object> mapuser = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid);
String credits = String.valueOf(mapuser.get("credits"));
logger.info("兑换前积分:" + credits);
//扣去100积分
credits = String.valueOf(Integer.valueOf(credits) - 100);
//活动详情页
Response response = mobileService.detail(authorization.dafuwengLogin(uid), "26762");
Map<String, String> map = authorization.dafuwengLogin(uid);
Assert.assertEquals(String.valueOf(response.getStatusCode()), "200", "活动详情页请求异常");
//实物兑换
response = couponExchangeService.objectExchange(map, "159143", "2619", "null", "z9sydmcs", "null");
// response.prettyPrint();
//校验兑换成功
// Assert.assertEquals(response.jsonPath().getString("success"),"true");
//获取orderId
String orderId = response.jsonPath().getString("orderId");
//获取兑换结果
response = mobileService.orderAmbStatusQuery(uid,orderId);
response.prettyPrint();
String message = response.jsonPath().getString("data.message");
int i = 10;
//异步接口,直到兑换成功
while (i > 0 && "兑换正在处理中...".equals(message)) {
Thread.sleep(1000);
response = mobileService.orderAmbStatusQuery(uid,orderId);
response.prettyPrint();
message = response.jsonPath().getString("data.message");
i--;
}
//查询数据库,获取当前积分
mapuser = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid);
String creditsNew = String.valueOf(mapuser.get("credits"));
logger.info("兑换后积分:" + creditsNew);
//校验比较,兑换前后积分
Assert.assertEquals(credits, creditsNew);
logger.info("校验兑换前后积分正确");
//兑吧管理后台发货
managerService.expressSend(orderId);
logger.info("实物兑换订单成功");
}
//优惠券兑换
//@Test(description = "优惠券兑换")
public void coupon() throws Exception {
//查询数据库,当前积分
Map<String, Object> mapuser = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid);
String credits = String.valueOf(mapuser.get("credits"));
logger.info("兑换前积分:" + credits); //扣去100积分
credits = String.valueOf(Integer.valueOf(credits) - 100);
//优惠券兑换
Response response = couponExchangeService.couponExchange(authorization.dafuwengLogin(uid), "157070", "27050");
String orderId = response.jsonPath().getString("orderId");
//查看兑换结果
response = mobileService.orderStatusQuery(response.getDetailedCookies(), uid,orderId);
String status = response.jsonPath().getString("status");
//异步接口
int i = 10;
while (i > 0 && "processing".equals(status)) {
Thread.sleep(1000);
response = mobileService.orderStatusQuery(response.getDetailedCookies(),uid, orderId);
response.prettyPrint();
status = response.jsonPath().getString("status");
i--;
}
//查询数据库,获取当前积分
mapuser = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid);
Map<String,Object> mapConsumer = jdbc.findSimpleResult("SELECT * FROM new_consumer.consumer_0010 WHERE `app_id` = 2239 AND id = 100011622");
String creditsNew = String.valueOf(mapuser.get("credits"));
String creditsCon = String.valueOf(mapConsumer.get("credits"));
logger.info("兑换后积分:" + creditsNew);
//校验比较,兑换前后积分
Assert.assertEquals(credits.trim(), creditsNew, "优惠券兑换后积分扣除异常");
Assert.assertEquals(creditsCon,creditsNew,"本地积分与用户积分不符");
logger.info("校验兑换前后积分正确");
}
//直充类单档话费兑换_1元话费
@Test(description = "直充类单档话费兑换")
public void phonebillDingzhi() throws Exception {
Map<String, Object> mapuser = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid);
String credits = String.valueOf(mapuser.get("credits"));
logger.info("兑换前积分:" + credits);
//扣去100积分
credits = String.valueOf(Integer.valueOf(credits) - 100);
//兑换详情页
Response response = mobileService.detail(authorization.dafuwengLogin(uid), "1660");
Map<String, String> map = authorization.dafuwengLogin(uid);
Assert.assertEquals(String.valueOf(response.getStatusCode()), "200", "活动详情页请求异常");
//1元话费兑换
response = couponExchangeService.phonebillExchange(authorization.dafuwengLogin(uid), "156497", "1660");
response.prettyPrint();
//获取orderId
String orderId = response.jsonPath().getString("orderId");
//获取提交结果
response = mobileService.orderStatusQuery(response.getDetailedCookies(), uid,orderId);
response.prettyPrint();
String message = response.jsonPath().getString("message");
int i = 10;
//异步接口,兑换提交成功!待处理
while (i > 0 && "兑换正在处理中...".equals(message)) {
Thread.sleep(1000);
response = mobileService.orderStatusQuery(response.getDetailedCookies(),uid, orderId);
response.prettyPrint();
message = response.jsonPath().getString("message");
i--;
}
//获取兑换结果
response = crecordService.recordFresh(uid,orderId);
response.prettyPrint();
String isProcess = response.jsonPath().getString("isProcess");
int j = 10;
//异步接口,兑换成功
while (j > 0 && "兑换正在处理中...".equals(isProcess)) {
Thread.sleep(1000);
response = crecordService.recordFresh(uid,orderId);
response.prettyPrint();
isProcess = response.jsonPath().getString("isProcess");
j--;
}
//查询数据库,获取当前积分
mapuser = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid);
String creditsNew = String.valueOf(mapuser.get("credits"));
logger.info("兑换后积分:" + creditsNew);
//校验比较,兑换前后积分
Assert.assertEquals(credits.trim(), creditsNew, "话费兑换后积分扣除异常");
logger.info("校验兑换前后积分正确");
}
//多档位话费兑换_10元话费
@Test(dataProvider = "providerMethod")
public void 多档位兑换(Map<String,String> data) throws Exception {
Map<String, Object> mapuser = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid);
String credits = String.valueOf(mapuser.get("credits"));
logger.info("兑换前积分:" + credits);
//扣去100积分
credits = String.valueOf(Integer.valueOf(credits) - Integer.valueOf(data.get("credits")));
//兑换详情页
Response response = mobileService.detail(authorization.dafuwengLogin(uid), "1");
Map<String, String> map = authorization.dafuwengLogin(uid);
Assert.assertEquals(String.valueOf(response.getStatusCode()), "200", "活动详情页请求异常");
//10元话费兑换
response = couponExchangeService.phonebillExchange(authorization.dafuwengLogin(uid), data.get("degreeId"));
response.prettyPrint();
//获取orderId
String orderId = response.jsonPath().getString("orderId");
//获取提交结果
response = mobileService.orderStatusQuery(response.getDetailedCookies(),uid, orderId);
response.prettyPrint();
String message = response.jsonPath().getString("message");
int i = 10;
//异步接口,兑换提交成功!待处理
while (i > 0 && "兑换正在处理中...".equals(message)) {
Thread.sleep(1000);
response = mobileService.orderStatusQuery(response.getDetailedCookies(),uid, orderId);
response.prettyPrint();
message = response.jsonPath().getString("message");
i--;
}
//获取兑换结果
response = crecordService.recordFresh(uid,orderId);
response.prettyPrint();
String isProcess = response.jsonPath().getString("isProcess");
int j = 10;
//异步接口,兑换成功
while (j > 0 && "兑换正在处理中...".equals(isProcess)) {
Thread.sleep(1000);
response = crecordService.recordFresh(uid,orderId);
response.prettyPrint();
isProcess = response.jsonPath().getString("isProcess");
j--;
}
//查询数据库,获取当前积分
Thread.sleep(3000);
mapuser = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid);
String creditsNew = String.valueOf(mapuser.get("credits"));
logger.info("兑换后积分:" + creditsNew);
//校验比较,兑换前后积分
Assert.assertEquals(credits.trim(), creditsNew, "话费兑换后积分扣除异常");
logger.info("校验兑换前后积分正确");
}
//自有实物兑换并发货
@Test(description = "实物兑换")
public void 自有实物兑换() throws Exception {
//查询数据库,当前积分
Map<String, Object> mapuser = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid);
Map<String, Object> mapStock = jdbc.findSimpleResult("select * from stock.tb_stock where stock_id = 674900860200090332");
String credits = String.valueOf(mapuser.get("credits"));
logger.info("兑换前积分:" + credits);
//扣去100积分
credits = String.valueOf(Integer.valueOf(credits) - 1);
String stock = String.valueOf(mapStock.get("stock"));
logger.info("兑换前库存:" + stock);
//扣去1
stock = String.valueOf(Integer.valueOf(stock) - 1);
//活动详情页
Response response = mobileService.detail(authorization.dafuwengLogin(uid), "27970");
Map<String, String> map = authorization.dafuwengLogin(uid);
Assert.assertEquals(String.valueOf(response.getStatusCode()), "200", "活动详情页请求异常");
//实物兑换
response = couponExchangeService.objectExchange(map, "161100", null, "null", "z9sydmcs", "null");
// response.prettyPrint();
//校验兑换成功
// Assert.assertEquals(response.jsonPath().getString("success"),"true");
//获取orderId
String orderId = response.jsonPath().getString("orderId");
//获取兑换结果
response = mobileService.orderAmbStatusQuery(uid,orderId);
response.prettyPrint();
String message = response.jsonPath().getString("data.message");
int i = 10;
//异步接口,直到兑换成功
while (i > 0 && "兑换正在处理中...".equals(message)) {
Thread.sleep(1000);
response = mobileService.orderAmbStatusQuery(uid,orderId);
response.prettyPrint();
message = response.jsonPath().getString("data.message");
i--;
}
//查询数据库,获取当前积分
mapuser = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid);
String creditsNew = String.valueOf(mapuser.get("credits"));
logger.info("兑换后积分:" + creditsNew);
//校验比较,兑换前后库存
Assert.assertEquals(credits, creditsNew,"积分校验失败");
logger.info("校验兑换前后积分正确");
mapStock = jdbc.findSimpleResult("select * from stock.tb_stock where stock_id = 674900860200090332");
String stockNew = String.valueOf(mapStock.get("stock"));
logger.info("兑换后库存:" + stockNew);
//校验比较,兑换前后积分
Assert.assertEquals(stock, stockNew,"库存校验失败");
logger.info("校验兑换前后库存正确");
//兑吧管理后台发货
// response = managerService.expressSend(orderId);
// logger.info("实物兑换订单成功");
}
//自有优惠券兑换_重复券
@Test(description = "自有优惠券兑换")
public void 自有优惠券() throws Exception {
//查询数据库,当前积分
Map<String, Object> mapuser = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid);
//select * from goods.tb_goods_batch where gid=159857 查询库存id gid=itemid
Map<String, Object> mapStock = jdbc.findSimpleResult("select * from stock.tb_stock where stock_id = 607824566024920113");
String stock = String.valueOf(mapStock.get("stock"));
logger.info("兑换前库存:" + stock);
//扣去1
stock = String.valueOf(Integer.valueOf(stock) - 1);
String credits = String.valueOf(mapuser.get("credits"));
logger.info("兑换前积分:" + credits); //扣去100积分
credits = String.valueOf(Integer.valueOf(credits) - 1);
//优惠券兑换
Response response = couponExchangeService.couponExchange(authorization.dafuwengLogin(uid), "159857", null);
String orderId = response.jsonPath().getString("orderId");
//查看兑换结果
response = mobileService.orderStatusQuery(response.getDetailedCookies(), uid,orderId);
String status = response.jsonPath().getString("status");
//异步接口
int i = 10;
while (i > 0 && "processing".equals(status)) {
Thread.sleep(1000);
response = mobileService.orderStatusQuery(response.getDetailedCookies(),uid, orderId);
response.prettyPrint();
status = response.jsonPath().getString("status");
i--;
}
response.prettyPrint();
//查询数据库,获取当前积分
mapuser = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid);
String creditsNew = String.valueOf(mapuser.get("credits"));
logger.info("兑换后积分:" + creditsNew);
//校验比较,兑换前后积分
Assert.assertEquals(credits.trim(), creditsNew, "优惠券兑换后积分扣除异常");
logger.info("校验兑换前后积分正确");
mapStock = jdbc.findSimpleResult("select * from stock.tb_stock where stock_id = 607824566024920113");
String stockNew = String.valueOf(mapStock.get("stock"));
logger.info("兑换后库存:" + stockNew);
//校验比较,兑换前后积分
Assert.assertEquals(stock, stockNew,"库存校验失败");
logger.info("校验兑换前后库存正确");
}
//自有虚拟商品单档兑换
@Test(description = "自有虚拟商品单档兑换")
public void 自有虚拟商品单档兑换() throws Exception {
//查询数据库,当前积分
Map<String, Object> mapuser = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid);
String credits = String.valueOf(mapuser.get("credits"));
logger.info("兑换前积分:" + credits); //扣去100积分
credits = String.valueOf(Integer.valueOf(credits) - 1);
Map<String, Object> mapStock = jdbc.findSimpleResult("select * from stock.tb_stock where stock_id = 674900860200070105");
String stock = String.valueOf(mapStock.get("stock"));
logger.info("兑换前库存:" + stock);
//扣去1
stock = String.valueOf(Integer.valueOf(stock) - 1);
//优惠券兑换
Response response = virtualExchangeService.exchange(authorization.dafuwengLogin(uid), "159849", "DUIBA_SELF");
String orderId = response.jsonPath().getString("orderId");
//查看兑换结果
response = mobileService.orderStatusQuery(response.getDetailedCookies(), uid,orderId);
String status = response.jsonPath().getString("status");
//异步接口
int i = 10;
while (i > 0 && "processing".equals(status)) {
Thread.sleep(1000);
response = mobileService.orderStatusQuery(response.getDetailedCookies(), uid,orderId);
response.prettyPrint();
status = response.jsonPath().getString("status");
i--;
}
Thread.sleep(1000);
//查询数据库,获取当前积分
mapuser = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid);
String creditsNew = String.valueOf(mapuser.get("credits"));
logger.info("兑换后积分:" + creditsNew);
//校验比较,兑换前后积分
Assert.assertEquals(credits.trim(), creditsNew, "优惠券兑换后积分扣除异常");
logger.info("校验兑换前后积分正确");
mapStock = jdbc.findSimpleResult("select * from stock.tb_stock where stock_id = 674900860200070105");
String stockNew = String.valueOf(mapStock.get("stock"));
logger.info("兑换后库存:" + stockNew);
//校验比较,兑换前后积分
Assert.assertEquals(stock, stockNew,"库存校验失败");
logger.info("校验兑换前后库存正确");
Thread.sleep(2000);
Map<String, Object> selectResult = jdbc.findSimpleResult("select * from orders_consumer.orders_0614 where consumer_id = 100011622 and biz_params = 'DUIBA_SELF' ",null);
//logger.info("selectResult结果为:"+selectResult);
Assert.assertEquals( selectResult.get("biz_params"),"DUIBA_SELF","虚拟商品出奖标识DUIBA_SELF校验失败");
logger.info("数据库存储虚拟商品标记结果为:"+selectResult.get("biz_params"));
}
//直充类流量兑换
@Test(description = "直充类流量兑换")
public void 流量兑换() throws Exception {
Map<String, Object> mapuser = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid);
String credits = String.valueOf(mapuser.get("credits"));
logger.info("兑换前积分:" + credits);
//扣去100积分
credits = String.valueOf(Integer.valueOf(credits) - 600);
//兑换详情页
Response response = mobileService.detail(authorization.dafuwengLogin(uid), "3");
Map<String, String> map = authorization.dafuwengLogin(uid);
Assert.assertEquals(String.valueOf(response.getStatusCode()), "200", "活动详情页请求异常");
//流量兑换
response = couponExchangeService.phoneflowExchange(authorization.dafuwengLogin(uid), "51200", "3","13193354550","中国联通","陕西");
response.prettyPrint();
//获取orderId
String orderId = response.jsonPath().getString("orderId");
//获取提交结果
response = mobileService.orderStatusQuery(response.getDetailedCookies(),uid, orderId);
response.prettyPrint();
String message = response.jsonPath().getString("message");
int i = 10;
//异步接口,兑换提交成功!待处理
while (i > 0 && "兑换正在处理中...".equals(message)) {
Thread.sleep(1000);
response = mobileService.orderStatusQuery(response.getDetailedCookies(),uid, orderId);
response.prettyPrint();
message = response.jsonPath().getString("message");
i--;
}
//获取兑换结果
response = crecordService.recordFresh(uid,orderId);
response.prettyPrint();
String isProcess = response.jsonPath().getString("isProcess");
int j = 10;
//异步接口,兑换成功
while (j > 0 && "兑换正在处理中...".equals(isProcess)) {
Thread.sleep(1000);
response = crecordService.recordFresh(uid,orderId);
response.prettyPrint();
isProcess = response.jsonPath().getString("isProcess");
j--;
}
//查询数据库,获取当前积分
mapuser = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid);
String creditsNew = String.valueOf(mapuser.get("credits"));
logger.info("兑换后积分:" + creditsNew);
//校验比较,兑换前后积分
Assert.assertEquals(credits.trim(), creditsNew, "话费兑换后积分扣除异常");
logger.info("校验兑换前后积分正确");
}
//直充类支付宝兑换
@Test(description = "直充类支付宝兑换")
public void 支付宝兑换() throws Exception {
Map<String, Object> mapuser = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid);
String credits = String.valueOf(mapuser.get("credits"));
logger.info("兑换前积分:" + credits);
//扣去100积分
credits = String.valueOf(Integer.valueOf(credits) - 100);
//兑换详情页
Response response = mobileService.detail(authorization.dafuwengLogin(uid), "55");
Map<String, String> map = authorization.dafuwengLogin(uid);
Assert.assertEquals(String.valueOf(response.getStatusCode()), "200", "活动详情页请求异常");
//支付宝(1元)兑换
response = couponExchangeService.alipayExchange(uid,"55");
response.prettyPrint();
//获取orderId
String orderId = response.jsonPath().getString("orderId");
//获取提交结果
response = mobileService.orderStatusQuery(response.getDetailedCookies(), uid,orderId);
response.prettyPrint();
String message = response.jsonPath().getString("message");
int i = 10;
//异步接口,兑换提交成功!待处理
while (i > 0 && "兑换正在处理中...".equals(message)) {
Thread.sleep(1000);
response = mobileService.orderStatusQuery(response.getDetailedCookies(),uid, orderId);
response.prettyPrint();
message = response.jsonPath().getString("message");
i--;
}
//获取兑换结果
response = crecordService.recordFresh(uid,orderId);
response.prettyPrint();
String isProcess = response.jsonPath().getString("isProcess");
int j = 10;
//异步接口,兑换成功
while (j > 0 && "兑换正在处理中...".equals(isProcess)) {
Thread.sleep(1000);
response = crecordService.recordFresh(uid,orderId);
response.prettyPrint();
isProcess = response.jsonPath().getString("isProcess");
j--;
}
//查询数据库,获取当前积分
mapuser = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid);
String creditsNew = String.valueOf(mapuser.get("credits"));
logger.info("兑换后积分:" + creditsNew);
//校验比较,兑换前后积分
Assert.assertEquals(credits.trim(), creditsNew, "支付宝兑换后积分扣除异常");
logger.info("校验兑换前后积分正确");
}
// @Test(description = "qb 兑换",dataProvider = "providerMethodQb")
public void qbExchange(Map<String,String> data) throws Exception {
Map<String, Object> mapuser = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid);
String credits = String.valueOf(mapuser.get("credits"));
logger.info("兑换前积分:" + credits);
Response response = qbExchangeService.doTakePrize(authorization.dafuwengLogin(uid),"1234345554",data.get("degreeId"));
// response.prettyPrint();
String orderId = (String)response.jsonPath().get("orderId");
response = mobileService.orderStatusQuery(authorization.dafuwengLogin(uid),orderId);
String message = response.jsonPath().getString("message");
int i=10;
while(!message.equals("兑换提交成功!待处理")&&i>0){
Thread.sleep(1000);
response = mobileService.orderStatusQuery(authorization.dafuwengLogin(uid),orderId);
message = response.jsonPath().getString("message");
i--;
}
//查询数据库,获取当前积分
Thread.sleep(3000);
mapuser = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid);
logger.info("兑换后积分:" + mapuser.get("credits"));
String creditsNew = String.valueOf((Long)mapuser.get("credits")+Integer.valueOf(data.get("credits")));
//校验比较,兑换前后积分
Assert.assertEquals(credits.trim(), creditsNew, "qb兑换后积分扣除异常");
logger.info("校验兑换前后积分正确");
//订单状态校验
Thread.sleep(5000);
Map<String, Object> orderMap = jdbc.findSimpleResult("SELECT * from orders_consumer.orders_0614 where id ="+orderId);
String status = (String)orderMap.get("status");
Assert.assertTrue(status.equals("success"),"校验订单状态失败");
logger.info("校验兑换订单状态正确");
}
@DataProvider
public Iterator<Object[]> providerMethod(Method method) throws IOException {
Iterator<Object[]> result = null;
result = new ExcelDataProvider("duiba/多档位兑换");
return result;
}
@DataProvider
public Iterator<Object[]> providerMethodQb(Method method) throws IOException {
Iterator<Object[]> result = null;
result = new ExcelDataProvider("duiba/qb兑换");
return result;
}
}
package http.cases.ExchangeTest;
import base.DuibaTestBase;
import http.service.Activity.ManagerService;
import http.service.Authorization;
import http.service.app.*;
import http.service.hd.DeveloperAccountService;
import http.service.hd.DsOrderService;
import utils.MatcherString;
import utils.ExcelDataProvider;
import base.DuibaLog;
import io.restassured.response.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.io.IOException;
import java.lang.reflect.Method;
import java.sql.SQLException;
import java.util.Iterator;
import java.util.Map;
/**
* Created by mabo on 2018/9/13
*/
public class Qb_兑换流程测试_ExchangeTest extends DuibaTestBase {
@Autowired
private MobileService mobileService;
@Autowired
private Authorization authorization;
@Autowired
private CouponExchangeService couponExchangeService;
@Autowired
private CrecordService crecordService;
@Autowired
ManagerService managerService;
@Autowired
VirtualExchangeService virtualExchangeService;
@Autowired
QbExchangeService qbExchangeService;
@Autowired
DeveloperAccountService developerAccountService;
@Autowired
DsOrderService dsOrderService;
@Autowired
SupplierExchangeTemplateService supplierExchangeTemplateService;
private DuibaLog logger = DuibaLog.getLogger();
@BeforeClass
public void beforeClass(){
//模版设置成处理后成功
supplierExchangeTemplateService.use("476");
}
@BeforeMethod
public void beforeMethod() throws SQLException {
jdbc.update("DELETE FROM credits_dev.consumer_limit_record_only WHERE item_id = '2'");
jdbc.update("DELETE FROM credits_dev.consumer_limit_record WHERE item_id = '2'");
}
@DataProvider
public Iterator<Object[]> providerMethodQb(Method method) throws IOException {
Iterator<Object[]> result = null;
result = new ExcelDataProvider("duiba/qb兑换");
return result;
}
@Test
public void qbExchange() throws Exception {
int uid = 3767;
Map<String, Object> mapuser = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid);
String credits = String.valueOf(mapuser.get("credits"));
logger.info("兑换前积分:" + credits);
Response response = qbExchangeService.doTakePrize(authorization.dafuwengLogin(uid),"1234345554","3");
String orderId = (String)response.jsonPath().get("orderId");
logger.info("订单号:"+orderId);
response = mobileService.orderStatusQuery(authorization.dafuwengLogin(uid),orderId);
String message = response.jsonPath().getString("message");
int i=10;
while(!message.equals("兑换提交成功!待处理")&&i>0){
Thread.sleep(1000);
response = mobileService.orderStatusQuery(authorization.dafuwengLogin(uid),orderId);
message = response.jsonPath().getString("message");
i--;
}
//查询数据库,获取当前积分
Thread.sleep(3000);
mapuser = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid);
logger.info("兑换后积分:" + mapuser.get("credits"));
String creditsNew = String.valueOf((Long)mapuser.get("credits")+30);
//校验比较,兑换前后积分
Assert.assertEquals(credits.trim(), creditsNew, "qb兑换后积分扣除异常");
logger.info("校验兑换前后积分正确");
//订单状态校验
Thread.sleep(5000);
Map<String, Object> orderMap = jdbc.findSimpleResult("SELECT * from orders_consumer.orders_0207 where id ="+orderId);
String status = (String)orderMap.get("status");
logger.info("订单状态:"+status);
Assert.assertTrue(status.equals("success"),"校验订单状态失败");
logger.info("校验兑换订单状态正确");
}
@Test
public void qbExchange_积分不足() throws Exception {
int uid = 3086;
Response response = qbExchangeService.doTakePrize(authorization.dafuwengLogin(uid),"1234345554","5");
String orderId = (String)response.jsonPath().get("orderId");
response = mobileService.orderStatusQuery(authorization.dafuwengLogin(uid),orderId);
String message = response.jsonPath().getString("message");
int i=10;
while(!message.equals("兑换失败,用户积分余额不足")&&i>0){
Thread.sleep(1000);
response = mobileService.orderStatusQuery(authorization.dafuwengLogin(uid),orderId);
message = response.jsonPath().getString("message");
i--;
}
Map<String, Object> orderMap = jdbc.findSimpleResult("SELECT * from orders_consumer.orders_0693 where id ="+orderId);
String orderStatus = String.valueOf(orderMap.get("status"));
Assert.assertEquals(message,"兑换失败,用户积分余额不足","校验message失败");
Assert.assertEquals(orderStatus,"fail","校验订单状态失败");
logger.info("积分不足兑换校验成功");
}
@Test
public void 开发者余额不足测试() throws Exception{
int uid = 3490;
//开发者余额, 开发者账户:xuyan_8707@163.com
Response accountResponse = developerAccountService.accountInfoCommon("xuyan_8707@163.com");
String remainMoney = accountResponse.jsonPath().getString("data.remainMoney");
logger.info("兑换前的开发者账户余额:" + remainMoney);
Response detailResponse = mobileService.detail(authorization.dafuwengLogin(uid),"2");
String exchangeText = MatcherString.getString(detailResponse.asString(), "\"exchangeText\":\"(.*?)\",", 1);
String message=null;
String succcess = null;
try{
Response response = qbExchangeService.doTakePrize(authorization.dafuwengLogin(uid),"1234345554","1");
}catch (Exception e){
message = e.toString();
}
logger.info(message);
Assert.assertTrue(message.contains("没有兑换成功"));
Assert.assertTrue(message.contains("\"success\":false"));
}
@Test
public void 每日兑换限制() throws Exception {
int uid = 3767;
//第一次兑换
Response response = qbExchangeService.doTakePrize(authorization.dafuwengLogin(uid),"1234345554","1");
String orderId = (String)response.jsonPath().get("orderId");
response = mobileService.orderStatusQuery(authorization.dafuwengLogin(uid),orderId);
String message = response.jsonPath().getString("message");
int i=10;
while(!message.equals("兑换提交成功!待处理")&&i>0){
Thread.sleep(1000);
response = mobileService.orderStatusQuery(authorization.dafuwengLogin(uid),orderId);
message = response.jsonPath().getString("message");
i--;
}
//第二次兑换
try{
response = qbExchangeService.doTakePrize(authorization.dafuwengLogin(uid),"1234345554","1");
}catch (Exception e){
message = e.toString();
}
logger.info(message);
Assert.assertTrue(message.contains("已兑完"));
Assert.assertTrue(message.contains("\"success\":false"));
}
@Test
public void 永久兑换限制() throws Exception {
int uid = 3767;
//第一次兑换
Response response = qbExchangeService.doTakePrize(authorization.dafuwengLogin(uid),"1234345554","2");
String orderId = (String)response.jsonPath().get("orderId");
response = mobileService.orderStatusQuery(authorization.dafuwengLogin(uid),orderId);
String message = response.jsonPath().getString("message");
int i=10;
while(!message.equals("兑换提交成功!待处理")&&i>0){
Thread.sleep(1000);
response = mobileService.orderStatusQuery(authorization.dafuwengLogin(uid),orderId);
message = response.jsonPath().getString("message");
i--;
}
//第二次兑换
try{
response = qbExchangeService.doTakePrize(authorization.dafuwengLogin(uid),"1234345554","2");
}catch (Exception e){
message = e.toString();
}
logger.info(message);
Assert.assertTrue(message.contains("已兑完"));
Assert.assertTrue(message.contains("\"success\":false"));
}
@Test
public void 审核通过测试() throws Exception {
//查询兑换前的开发者账户余额
// Response accountResponse = developerAccountService.accountInfo();
// String remainMoney = accountResponse.jsonPath().getString("data.remainMoney");
// logger.info("兑换前的开发者账户余额:" + remainMoney);
// String remainMoneyNew =String.valueOf(Integer.valueOf(remainMoney) - 9600) ;
int uid = 2709;
Response response = qbExchangeService.doTakePrize(authorization.dafuwengLogin(uid),"1234345554","100");
String orderId = (String)response.jsonPath().get("orderId");
response.prettyPrint();
//订单审核,判断是否在待审核节点
Map<String,Object> mapOrder = jdbc.findSimpleResult("SELECT * from orders_consumer.orders_0616 where id ="+orderId);
String flowWork = String.valueOf(mapOrder.get("flowwork_stage"));
logger.info("数据库订单节点:" + flowWork);
String orderIdmain = String.valueOf(mapOrder.get("order_num"));
logger.info("兑吧订单号为:" + orderIdmain);
int i =10;
while (i > 0 && !flowWork.equals("Audit-started")) {
Thread.sleep(300);
mapOrder = jdbc.findSimpleResult("SELECT * from orders_consumer.orders_0616 where id ="+orderId);
flowWork = String.valueOf(mapOrder.get("flowwork_stage"));
logger.info("数据库订单节点:" + flowWork);
i--;
}
Response auditResponse = dsOrderService.submitAudit(orderId,"pass");
auditResponse.prettyPrint();
//判断订单是否审核成功,如果订单没有成功则继续审核
int j =10;
while (j > 0 && !flowWork.equals("Success-complete")) {
Thread.sleep(1000);
auditResponse = dsOrderService.submitAudit(orderId,"pass");
mapOrder = jdbc.findSimpleResult("SELECT * from orders_consumer.orders_0616 where id ="+orderId);
flowWork = String.valueOf(mapOrder.get("flowwork_stage"));
logger.info("数据库订单节点:" + flowWork);
j--;
}
String status = String.valueOf(mapOrder.get("status"));
//兑换后的开发者账户余额
// accountResponse = developerAccountService.accountInfo();
// remainMoney = accountResponse.jsonPath().getString("data.remainMoney");
// logger.info("兑换后的开发者账户余额:" + remainMoney);
// Assert.assertEquals(remainMoney,remainMoneyNew,"校验开发者账户余额失败");
//校验开发者账户余额变动
Response accountResponse = developerAccountService.cashDetail(orderIdmain);
String remainMoney = String.valueOf(Integer.valueOf(accountResponse.jsonPath().getString("data.list[0].balance"))+Integer.valueOf(accountResponse.jsonPath().getString("data.list[0].moneyChange")));
logger.info("兑换前的开发者账户余额:" + remainMoney);
remainMoney =String.valueOf(Integer.valueOf(remainMoney) - 9600) ;
String remainMoneyNew = accountResponse.jsonPath().getString("data.list[0].balance");
logger.info("兑换后的开发者账户余额:" + remainMoneyNew);
Assert.assertEquals(remainMoneyNew,remainMoney,"校验开发者账户余额失败");
Assert.assertEquals(status,"success","校验订单状态失败");
logger.info("校验支付宝扣费订单成功");
}
@Test
public void 审核不通过测试() throws Exception{
//查询兑换前的开发者账户余额
// Response accountResponse = developerAccountService.accountInfo();
// String remainMoney = accountResponse.jsonPath().getString("data.remainMoney");
// logger.info("兑换前的开发者账户余额:" + remainMoney);
//qb兑换
int uid = 2709;
Response response = qbExchangeService.doTakePrize(authorization.dafuwengLogin(uid),"1234345554","100");
String orderId = (String)response.jsonPath().get("orderId");
//订单审核,判断是否在待审核节点
Map<String,Object> mapOrder = jdbc.findSimpleResult("SELECT * from orders_consumer.orders_0616 where id ="+orderId);
String flowWork = String.valueOf(mapOrder.get("flowwork_stage"));
logger.info("数据库订单节点:" + flowWork);
String orderIdmain = String.valueOf(mapOrder.get("order_num"));
logger.info("兑吧订单号为:" + orderIdmain);
int i =10;
while (i > 0 && !flowWork.equals("Audit-started")) {
Thread.sleep(300);
mapOrder = jdbc.findSimpleResult("SELECT * from orders_consumer.orders_0616 where id ="+orderId);
flowWork = String.valueOf(mapOrder.get("flowwork_stage"));
logger.info("数据库订单节点:" + flowWork);
i--;
}
//订单审核
Response auditResponse = dsOrderService.submitAudit(orderId,"reject");
auditResponse.prettyPrint();
//判断订单是否审核失败
int j =10;
while (j > 0 && !flowWork.equals("Fail-complete")) {
Thread.sleep(1000);
auditResponse = dsOrderService.submitAudit(orderId,"reject");
mapOrder = jdbc.findSimpleResult("SELECT * from orders_consumer.orders_0616 where id ="+orderId);
flowWork = String.valueOf(mapOrder.get("flowwork_stage"));
logger.info("当前订单节点:" + flowWork);
j--;
}
String status = String.valueOf(mapOrder.get("status"));
//兑换后的开发者账户余额
// accountResponse = developerAccountService.accountInfo();
// String remainMoneyNew = accountResponse.jsonPath().getString("data.remainMoney");
// logger.info("兑换后的开发者账户余额:" + remainMoneyNew);
// Assert.assertEquals(remainMoneyNew,remainMoney,"校验开发者账户余额失败");
Assert.assertEquals(status,"fail","校验订单状态失败");
//校验开发者账户余额变动
Response accountResponse = developerAccountService.cashDetail(orderIdmain);
String remainMoney = String.valueOf(Integer.valueOf(accountResponse.jsonPath().getString("data.list[1].balance"))+Integer.valueOf(accountResponse.jsonPath().getString("data.list[1].moneyChange")));
logger.info("兑换前的开发者账户余额:" + remainMoney);
String remainMoneyNew = accountResponse.jsonPath().getString("data.list[0].balance");
logger.info("兑换后的开发者账户余额:" + remainMoneyNew);
Assert.assertEquals(remainMoneyNew,remainMoney,"校验开发者账户余额失败");
logger.info("校验支付宝审核订单失败返还金额成功");
}
}
package http.cases.ExchangeTest;
import base.DuibaTestBase;
import utils.RedisUtil;
import http.service.Activity.ManagerService;
import http.service.Authorization;
import http.service.app.*;
import http.service.hd.DeveloperAccountService;
import http.service.hd.DsOrderService;
import utils.MatcherString;
import base.DuibaLog;
import io.restassured.response.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import static io.restassured.RestAssured.given;
/**
* Created by lvwenyan on 2018/07/06.
*/
public class 优惠券_兑换流程测试_ExchangeTest extends DuibaTestBase {
@Autowired
private MobileService mobileService;
@Autowired
private Authorization authorization;
@Autowired
private CouponExchangeService couponExchangeService;
@Autowired
private DsOrderService dsOrderService;
@Autowired
ManagerService managerService;
@Autowired
DeveloperAccountService developerAccountService;
@Autowired
CrecordService crecordService;
private DuibaLog logger = DuibaLog.getLogger();
// private MysqlUtils jdbc;
private String url = "http://activity.m.duibatest.com.cn";
//指定用户
private static int uid = 3768;
// @BeforeClass
// public void before(){
//
// jdbc = MysqlUtils.mysqlDuiba("");
//
// }
//
// @AfterClass
// public void after(){
//
// jdbc.releaseConn();
// }
@DataProvider
public Object[][] providerMethod(Method method) {
Object[][] result = null;
if (method.getName().equals("优惠券日期兑换限制测试")) {
result = new Object[][]{
new Object[]{1, "171479", "29538", "69xjl0a", "优惠券日期兑换限制未开始"}, //case1
new Object[]{2, "171480", "29539", "z9sydmcs", "优惠券日期兑换限制进行中"}, //case2
new Object[]{3, "171481", "29540", "cmixdqn", "优惠券日期兑换限制已结束"}, //case2
};
}
if (method.getName().equals("优惠券库存不足测试")) {
result = new Object[][]{
new Object[]{"169775", "29180", "69xjl0a", "优惠券商品库存不足测试"}, //case1
new Object[]{"172163", "29677", "z9sydmcs", "优惠券定向库存不足测试"}, //case2
new Object[]{"174773","30286","qyarwreq","优惠券预分配库存不足测试"},
};
}
if (method.getName().equals("优惠券审核通过测试")) {
result = new Object[][]{
new Object[]{1,"169698", "29156", "兑吧优惠券审核通过测试"}, //case1
new Object[]{2,"172178", "", "自有优惠券审核通过测试"}, //case2
};
}
if (method.getName().equals("优惠券马上使用按钮测试")){
result = new Object[][]{
new Object[]{1,"172292", "29708", "优惠券商家落地页下载按钮测试"}, //case1
new Object[]{2,"172293", "29709", "优惠券兑换记录页下载按钮测试"}, //case2
new Object[]{3,"172294","29710","优惠券链接券按钮测试"}, //case3
};
}
if (method.getName().equals("自有优惠券会员等级测试")){
result = new Object[][]{
new Object[]{1,"172713","pmqy9","优惠券会员等级范围测试"}, //case1
new Object[]{2,"172715","3bam907y", "优惠券会员特定等级测试"}, //case2
};
}
if (method.getName().equals("优惠券地区兑换限制测试")){
result = new Object[][]{
new Object[]{1,"175459","30434","pmqy9","优惠券地区黑名单不可兑测试"}, //case1
new Object[]{2,"175603","30435","3bam907y", "优惠券地区黑名单可兑测试"}, //case2
new Object[]{3,"175604","30436","6dc8ntp", "优惠券地区白名单可兑测试"}, //case3
new Object[]{4,"175605","30437","tvtgya6","优惠券地区白名单不可兑测试"}, //case4
};
}
return result;
}
@Test
public void 优惠券扣库存测试() throws Exception {
//查询优惠券兑换前的库存
Map<String,Object> mapStock = jdbc.findSimpleResult("SELECT * FROM stock.tb_stock WHERE stock_id ='705804724784620492'");
String stock = String.valueOf(mapStock.get("stock")) ;
logger.info("兑换前的优惠券库存:" + stock);
stock = String.valueOf(Integer.parseInt(stock) - 1) ;
//优惠券兑换
this.优惠券兑换("169713","29164",uid);
//查询优惠券兑换后的库存
mapStock = jdbc.findSimpleResult("SELECT * FROM stock.tb_stock WHERE stock_id ='705804724784620492'");
String stockNew = String.valueOf(mapStock.get("stock")) ;
logger.info("兑换后的优惠券库存:" + stockNew);
Assert.assertEquals(stockNew,stock,"校验优惠券库存失败");
logger.info("优惠券兑换扣库存校验成功");
}
@Test
public void 优惠券预分配库存测试() throws Exception{
Map<String,Object> mapStock = jdbc.findSimpleResult("SELECT * FROM goods.pre_stock WHERE point_id = '584'");
String stock = String.valueOf(mapStock.get("stock")) ;
logger.info("兑换前的优惠券预分配库存:" + stock);
stock = String.valueOf(Integer.valueOf(stock)-1);
//查询优惠券兑换前的积分,增加等待时间,同步更新积分
Thread.sleep(1000);
Map<String,Object> mapuser = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid);
String credits = String.valueOf(mapuser.get("credits"));
logger.info("兑换前的积分:"+credits);
credits = String.valueOf(Integer.valueOf(credits)-10);
//优惠券兑换
this.优惠券兑换("174797","30290",uid);
//查询优惠券兑换后的预分配库存和积分
mapStock = jdbc.findSimpleResult("SELECT * FROM goods.pre_stock WHERE point_id = '584'");
String stockNew = String.valueOf(mapStock.get("stock")) ;
logger.info("兑换后的优惠券预分配库存:" + stockNew);
Thread.sleep(1000);
mapuser = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid);
String creditsNew = String.valueOf(mapuser.get("credits"));
logger.info("兑换后积分:"+creditsNew);
Assert.assertEquals(stockNew,stock,"校验优惠券预分配库存失败");
Assert.assertEquals(creditsNew,credits,"校验优惠券预分配最小兑换价格失败");
logger.info("校验惠券预分配库存和最小兑换积分成功");
}
@Test
public void 优惠券共享库存测试() throws Exception{
Map<String,Object> mapStock = jdbc.findSimpleResult("SELECT * FROM goods.pre_stock WHERE point_id = '586'");
String stock = String.valueOf(mapStock.get("stock")) ;
logger.info("兑换前的优惠券共享库存:" + stock);
stock = String.valueOf(Integer.valueOf(stock)-1);
//优惠券兑换
this.优惠券兑换("174923","30318",uid);
//查询优惠券兑换后的共享库存
mapStock = jdbc.findSimpleResult("SELECT * FROM goods.pre_stock WHERE point_id = '586'");
String stockNew = String.valueOf(mapStock.get("stock")) ;
logger.info("兑换后的优惠券共享库存:" + stockNew);
Assert.assertEquals(stockNew,stock,"校验优惠券共享库存库存失败");
logger.info("校验优惠券共享库存扣除成功");
}
@Test
public void 优惠券预分配每日限额测试() throws Exception{
//获取当前的时间
Date dNow = new Date();
SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
String ftDate = ft.format(dNow);
try {
//优惠券第一次兑换
this.优惠券兑换("174928","30319",uid);
//每日限额用完,无法再次兑换
Thread.sleep(3000);
Map<String,String> map = new HashMap<>();
map.put("appItemId","174928");
map.put("itemId","30319");
map.put("token","uvbhjc");
Response response = given().contentType("application/x-www-form-urlencoded;charset=UTF-8").cookies(authorization.dafuwengLogin(uid)).params(map).post(url + "/couponExchange/exchange");
response.prettyPrint();
//获取按钮状态
Response detailResponse = mobileService.detail(authorization.dafuwengLogin(uid),"30319");
detailResponse.prettyPrint();
String exchangeText = MatcherString.getString(detailResponse.asString(), "\"exchangeText\":\"(.*?)\",", 1);
Assert.assertEquals(response.jsonPath().getString("message"),"今日已兑完,明天再来哦(14)","校验message失败");
Assert.assertEquals(exchangeText,"今日已兑完","校验马上兑换按钮状态失败");
logger.info("校验优惠券预分配每日限额兑换成功");
}catch (Exception e){
throw new Exception("异常信息打印:" + e);
}finally {
//清除兑换数据和 redis
jdbc.update("DELETE FROM goods.pre_stock_consume_detail WHERE point_id = 588");
RedisUtil.clearObjectKey("121-588");
RedisUtil.clearKey("everydayStock" + ftDate + "588");
}
}
/**
* @param appItemId 商品入库Id
* @param itemId 商品id
* @param token 活动token
* @param caseName 用例名称打印
* @throws Exception
*/
@Test(dataProvider = "providerMethod")
public void 优惠券库存不足测试( String appItemId, String itemId, String token, String caseName) throws Exception{
logger.info(caseName);
Map<String,String> map = new HashMap<>();
map.put("appItemId",appItemId);
map.put("itemId",itemId);
map.put("token",token);
//优惠券兑换
Response response = given().contentType("application/x-www-form-urlencoded;charset=UTF-8").cookies(authorization.dafuwengLogin(uid)).params(map).post(url + "/couponExchange/exchange");
response.prettyPrint();
//获取按钮状态
Response detailResponse = mobileService.detail(authorization.dafuwengLogin(uid),"29180");
detailResponse.prettyPrint();
String exchangeText = MatcherString.getString(detailResponse.asString(), "\"exchangeText\":\"(.*?)\",", 1);
Assert.assertEquals(response.jsonPath().getString("message"),"今日已兑完,明天再来哦(14)","校验message失败");
Assert.assertEquals(exchangeText,"已兑完","校验马上兑换按钮状态失败");
logger.info("校验优惠券商品库存不足和预分配库存不足场景成功");
}
@Test
public void 优惠券积分不足测试() throws Exception{
//获取按钮状态
Response detailResponse = mobileService.detail(authorization.dafuwengLogin(3086,true),"29164");
detailResponse.prettyPrint();
String exchangeText = MatcherString.getString(detailResponse.asString(), "\"exchangeText\":\"(.*?)\",", 1);
//优惠券兑换
Response response = this.优惠券兑换("169713","29164",3086);
Assert.assertEquals(exchangeText,"积分不足","校验马上兑换按钮状态失败");
Assert.assertEquals(response.jsonPath().getString("message"),"兑换失败,用户积分余额不足","校验message失败");
logger.info("校验优惠券商品积分不足场景成功");
}
/**
* @param caseNum 用例id
* @param appItemId 商品入库Id
* @param itemId 商品id
* @param caseName 用例名称打印
* @throws Exception
*/
@Test(dataProvider = "providerMethod")
public void 优惠券审核通过测试(int caseNum, String appItemId, String itemId, String caseName) throws Exception{
logger.info(caseName);
//查询兑换前的开发者余额
// Response accountResponse = developerAccountService.accountInfo();
// String remainMoney = accountResponse.jsonPath().getString("data.remainMoney");
// logger.info("兑换前的开发者余额:" + remainMoney);
// String remainMoneyNew =String.valueOf(Integer.valueOf(remainMoney) - 1000) ;
//优惠券兑换
String orderId = this.优惠券兑换订单(appItemId,itemId,uid);
logger.info("订单号:" + orderId);
//订单审核,判断是否在待审核节点
Map<String,Object> mapOrder = jdbc.findSimpleResult("SELECT * FROM "+Database.orders_consumer+"."+Database.orders4+" WHERE id = " + orderId);
String flowWork = String.valueOf(mapOrder.get("flowwork_stage"));
logger.info("数据库订单节点:" + flowWork);
String orderIdmain = String.valueOf(mapOrder.get("order_num"));
logger.info("兑吧订单号为:" + orderIdmain);
int i =10;
while (i > 0 && !flowWork.equals("Audit-started")) {
Thread.sleep(300);
mapOrder = jdbc.findSimpleResult("SELECT * FROM "+Database.orders_consumer+"."+Database.orders4+" WHERE id = " + orderId);
flowWork = String.valueOf(mapOrder.get("flowwork_stage"));
logger.info("数据库订单节点:" + flowWork);
i--;
}
Response auditResponse = dsOrderService.submitAudit(orderId,"pass");
auditResponse.prettyPrint();
//判断订单是否审核成功,如果订单没有成功则继续审核
int j =10;
while (j > 0 && !flowWork.equals("Success-complete")) {
Thread.sleep(1000);
auditResponse = dsOrderService.submitAudit(orderId,"pass");
mapOrder = jdbc.findSimpleResult("SELECT * FROM "+Database.orders_consumer+"."+Database.orders4+" WHERE id = " + orderId);
flowWork = String.valueOf(mapOrder.get("flowwork_stage"));
logger.info("数据库订单节点:" + flowWork);
j--;
}
String status = String.valueOf(mapOrder.get("status"));
switch (caseNum){
case 1:
//查询兑换后的开发者余额
// accountResponse = developerAccountService.accountInfo();
// remainMoney = accountResponse.jsonPath().getString("data.remainMoney");
// logger.info("兑换后的开发者余额:" + remainMoney);
Assert.assertEquals(status,"success","订单状态校验失败");
//校验开发者账户余额变动
Response accountResponse = developerAccountService.cashDetail(orderIdmain);
String remainMoney = String.valueOf(Integer.valueOf(accountResponse.jsonPath().getString("data.list[0].balance"))+Integer.valueOf(accountResponse.jsonPath().getString("data.list[0].moneyChange")));
logger.info("兑换前的开发者账户余额:" + remainMoney);
remainMoney =String.valueOf(Integer.valueOf(remainMoney) - 1000) ;
String remainMoneyNew = accountResponse.jsonPath().getString("data.list[0].balance");
logger.info("兑换后的开发者账户余额:" + remainMoneyNew);
Assert.assertEquals(remainMoneyNew,remainMoney,"校验开发者账户余额失败");
logger.info("校验兑吧优惠券审核通过扣费成功");
break;
case 2:
Assert.assertEquals(status,"success","订单状态校验失败");
logger.info("校验自有优惠券审核通过成功");
}
}
@Test
public void 优惠券用户永久兑换限制测试() throws Exception{
Map<String,String> map = new HashMap<>();
map.put("appItemId","170294");
map.put("itemId","29293");
map.put("token","69xjl0a");
try{
//优惠券兑换,用户兑换限制次数1次
Response response = this.优惠券兑换("170294","29293",uid);
Assert.assertEquals(response.jsonPath().getString("status"),"success","校验兑换失败");
logger.info("用户成功兑换一次");
//再次兑换
Thread.sleep(3000);
response = given().contentType("application/x-www-form-urlencoded;charset=UTF-8").cookies(authorization.dafuwengLogin(uid)).params(map).post(url + "/couponExchange/exchange");
response.prettyPrint();
//获取按钮状态
Response detailResponse = mobileService.detail(authorization.dafuwengLogin(uid),"29293");
detailResponse.prettyPrint();
String exchangeText = MatcherString.getString(detailResponse.asString(), "\"exchangeText\":\"(.*?)\",", 1);
Assert.assertEquals(response.jsonPath().getString("message"),"已兑换","校验用户兑换限制失败");
Assert.assertEquals(exchangeText,"已兑换","校验马上兑换按钮状态失败");
logger.info("校验优惠券用户永久兑换限制成功");
}catch (Exception e){
throw new Exception("异常信息打印:" + e);
}finally {
jdbc.update("DELETE FROM credits_dev.consumer_limit_record_only WHERE item_id = '29293'");
jdbc.update("DELETE FROM credits_dev.consumer_limit_record WHERE item_id = '29293'");
}
}
@Test
public void 优惠券用户每日兑换限制测试() throws Exception{
Map<String,String> map = new HashMap<>();
map.put("appItemId","171478");
map.put("itemId","29531");
map.put("token","69xjl0a");
try{
//优惠券兑换,用户兑换限制次数1次
Response response = this.优惠券兑换("171478","29531", uid);
Assert.assertEquals(response.jsonPath().getString("status"),"success","校验兑换失败");
logger.info("用户成功兑换一次");
//再次兑换
Thread.sleep(3000);
response = given().contentType("application/x-www-form-urlencoded;charset=UTF-8").cookies(authorization.dafuwengLogin(uid)).params(map).post(url + "/couponExchange/exchange");
response.prettyPrint();
//获取按钮状态
Response detailResponse = mobileService.detail(authorization.dafuwengLogin(uid),"29531");
detailResponse.prettyPrint();
String exchangeText = MatcherString.getString(detailResponse.asString(), "\"exchangeText\":\"(.*?)\",", 1);
Assert.assertEquals(response.jsonPath().getString("message"),"今日已兑换","校验用户兑换限制失败");
Assert.assertEquals(exchangeText,"今日已兑换","校验马上兑换按钮状态失败");
logger.info("校验优惠券用户每天兑换限制成功");
}catch (Exception e){
throw new Exception("异常信息打印:" + e);
}finally {
jdbc.update("DELETE FROM credits_dev.consumer_limit_record WHERE item_id = '29531'");
}
}
@Test
public void 优惠券每日兑换上限测试() throws Exception{
Map<String,String> map = new HashMap<>();
map.put("appItemId","170295");
map.put("itemId","29294");
map.put("token","69xjl0a");
try{
//优惠券兑换,用户兑换限制次数1次
Response response= this.优惠券兑换("170295","29294", uid);
Assert.assertEquals(response.jsonPath().getString("status"),"success","校验兑换失败");
logger.info("用户成功兑换一次");
//再次兑换
Thread.sleep(3000);
response = given().contentType("application/x-www-form-urlencoded;charset=UTF-8").cookies(authorization.dafuwengLogin(uid)).params(map).post(url + "/couponExchange/exchange");
response.prettyPrint();
//获取按钮状态
Response detailResponse = mobileService.detail(authorization.dafuwengLogin(uid),"29294");
detailResponse.prettyPrint();
String exchangeText = MatcherString.getString(detailResponse.asString(), "\"exchangeText\":\"(.*?)\",", 1);
Assert.assertEquals(response.jsonPath().getString("message"),"今日已兑完,明天再来哦(14)","校验每日兑换上限失败");
Assert.assertEquals(exchangeText,"今日已兑完","校验马上兑换按钮状态失败");
logger.info("校验优惠券每日兑换上限成功");
}catch (Exception e){
throw new Exception("异常信息打印:" + e);
}finally {
jdbc.update("DELETE FROM goods.tb_everyday_limit WHERE item_id = '29294'");
}
}
/**
* @param caseNum 用例编号
* @param appItemId 商品入库Id
* @param itemId 商品id
* @param token 活动token
* @param caseName 用例名称打印
* @throws Exception
*/
@Test(dataProvider = "providerMethod")
public void 优惠券日期兑换限制测试(int caseNum, String appItemId, String itemId, String token, String caseName) throws Exception{
logger.info(caseName);
Map<String,String> map = new HashMap<>();
map.put("appItemId",appItemId);
map.put("itemId",itemId);
map.put("token",token);
//兑换
Response response = given().contentType("application/x-www-form-urlencoded;charset=UTF-8").cookies(authorization.dafuwengLogin(uid)).params(map).post(url + "/couponExchange/exchange");
response.prettyPrint();
//获取按钮状态
Response detailResponse = mobileService.detail(authorization.dafuwengLogin(uid),itemId);
detailResponse.prettyPrint();
String exchangeText = MatcherString.getString(detailResponse.asString(), "\"exchangeText\":\"(.*?)\",", 1);
switch (caseNum){
case 1:
Assert.assertEquals(response.jsonPath().getString("message"),"请在限定时间内兑换哦(13)","校验日期兑换限制失败");
Assert.assertEquals(exchangeText,"即将开始","校验马上兑换按钮状态失败");
logger.info("校验优惠券日期兑换限制未开始成功");
break;
case 2:
Assert.assertEquals(response.jsonPath().getString("success"),"true","校验日期兑换限制失败");
Assert.assertEquals(exchangeText,"马上兑换","校验马上兑换按钮状态失败");
logger.info("校验优惠券日期兑换限制进行中成功");
break;
case 3:
Assert.assertEquals(response.jsonPath().getString("message"),"已结束","校验日期兑换限制失败");
Assert.assertEquals(exchangeText,"已结束","校验马上兑换按钮状态失败");
logger.info("校验优惠券日期兑换限制已结束成功");
break;
}
}
@Test
public void 优惠券限时兑换测试() throws Exception{
Map<String,String> map = new HashMap<>();
map.put("appItemId","172079");
map.put("itemId","29667");
map.put("token","69xjl0a");
//兑换
Response response = given().contentType("application/x-www-form-urlencoded;charset=UTF-8").cookies(authorization.dafuwengLogin(uid)).params(map).post(url + "/couponExchange/exchange");
response.prettyPrint();
//获取按钮状态
Response detailResponse = mobileService.detail(authorization.dafuwengLogin(uid),"29667");
detailResponse.prettyPrint();
String exchangeText = MatcherString.getString(detailResponse.asString(), "\"exchangeText\":\"(.*?)\",", 1);
Calendar cal = Calendar.getInstance();
int hour = cal.get(Calendar.HOUR_OF_DAY);
logger.info("当前时间是:" + hour + "时");
if(hour >= 0 && hour < 15 ){
//限时兑换未开始
Assert.assertEquals(response.jsonPath().getString("message"),"请在限定时间内兑换哦(13)","校验限时兑换失败");
Assert.assertEquals(exchangeText,"即将开始","校验马上兑换按钮状态失败");
logger.info("校验优惠券限时兑换未开始场景成功");
}else if(hour >= 15 && hour < 19){
Assert.assertEquals(response.jsonPath().getString("success"),"true","校验限时兑换失败");
Assert.assertEquals(exchangeText,"马上兑换","校验马上兑换按钮状态失败");
logger.info("校验优惠券限时兑换进行中场景成功");
}else{
Assert.assertEquals(response.jsonPath().getString("message"),"今日已兑完,明天再来哦(14)","校验日期兑换限制失败");
Assert.assertEquals(exchangeText,"今日已结束","校验马上兑换按钮状态失败");
logger.info("校验优惠券限时兑换结束场景成功");
}
}
/**
* @param caseNum 用例编号
* @param appItemId 商品入库Id
* @param itemId 商品id
* @param caseName 用例名称打印
* @throws Exception
*/
@Test(dataProvider = "providerMethod")
public void 优惠券马上使用按钮测试(int caseNum, String appItemId, String itemId, String caseName)throws Exception{
logger.info(caseName);
//优惠券兑换
String orderId = this.优惠券兑换订单(appItemId,itemId,uid);
//优惠券兑换结果页
Response resultResponse = crecordService.recordDetail(orderId,uid);
resultResponse.prettyPrint();
String btnText = MatcherString.getString(resultResponse.asString(),"\"btnText\":\"(.*?)\",",1);
String actualPay = MatcherString.getString(resultResponse.asString(),"\"actualPay\":\"(.*?)\",",1);
String androidDownload = MatcherString.getString(resultResponse.asString(),"\"androidDownload\":\"(.*?)\",",1);
String androidDownloadUrl = MatcherString.getString(resultResponse.asString(),"\"androidDownloadUrl\":\"(.*?)\",",1);
//优惠券兑换记录页
Thread.sleep(3000);
Response recordResponse = crecordService.recordDetailNew(orderId,uid);
recordResponse.prettyPrint();
String useButtonText = MatcherString.getString(recordResponse.asString(),"\"useButtonText\":\"(.*?)\",",1);
String androidDownloadUrl2 = MatcherString.getString(recordResponse.asString(),"\"androidDownloadUrl\":\"(.*?)\",",1);
switch (caseNum){
case 1:
Assert.assertEquals(btnText,"马上使用","校验结果页按钮文案失败");
Assert.assertEquals(actualPay,"10积分","校验结果页积分文案失败");
Assert.assertEquals(androidDownload,"https://m2.mobike.com/active/fission_packet_joint/index.html","校验结果页按钮链接失败");
Assert.assertEquals(useButtonText,"马上使用","校验兑换记录页按钮文案失败");
Assert.assertEquals(androidDownloadUrl2,"//activity.m.duibatest.com.cn/log/redirect?url=https%3A%2F%2Fm2.mobike.com%2Factive%2Ffission_packet_joint%2Findex.html&amp;dpm=2239.25.2.0&amp;dcm=101.29708.172292.0","校验兑换记录页按钮跳转链接失败");
logger.info("校验优惠券商家落地页下载链接页面成功");
break;
case 2:
Assert.assertEquals(btnText,"马上领取","校验结果页按钮文案失败");
Assert.assertEquals(actualPay,"20积分","校验结果页积分文案失败");
Assert.assertEquals(androidDownload,"https://u.163.com/aoshzxiaoshouxiaoshou4","校验结果页按钮链接失败");
Assert.assertEquals(useButtonText,"马上领取","校验兑换记录页按钮文案失败");
Assert.assertEquals(androidDownloadUrl2,"//activity.m.duibatest.com.cn/log/redirect?url=https%3A%2F%2Fu.163.com%2Faoshzxiaoshouxiaoshou4&amp;dpm=2239.25.2.0&amp;dcm=101.29709.172293.0","校验兑换记录页按钮跳转链接失败");
logger.info("校验优惠券兑换记录页下载链接页面成功");
break;
case 3:
Assert.assertEquals(btnText,"马上下载","校验结果页按钮文案失败");
Assert.assertEquals(actualPay,"30积分","校验结果页积分文案失败");
Assert.assertEquals(androidDownloadUrl,"//activity.m.duibatest.com.cn/log/redirect?url=https%3A%2F%2Fm.wkzuche.com%2Fh5%2F%23%2Factivity%2Fshare%3Fchannel%3Ddb%402018&amp;dpm=2239.25.1.0&amp;dcm=101.29710.172294.0","校验结果页按钮链接失败");
Assert.assertEquals(useButtonText,"马上下载","校验兑换记录页按钮文案失败");
Assert.assertEquals(androidDownloadUrl2,"//activity.m.duibatest.com.cn/log/redirect?url=https%3A%2F%2Fm.wkzuche.com%2Fh5%2F%23%2Factivity%2Fshare%3Fchannel%3Ddb%402018&amp;dpm=2239.25.2.0&amp;dcm=101.29710.172294.0","校验兑换记录页按钮跳转链接失败");
logger.info("校验优惠券链接券页面成功");
break;
}
}
/**
* @param caseNum 用例编号
* @param appItemId 商品入库Id
* @param token token
* @param caseName 用例名称打印
* @throws Exception
*/
@Test(dataProvider = "providerMethod")
public void 自有优惠券会员等级测试(int caseNum, String appItemId, String token,String caseName) throws Exception{
logger.info(caseName);
Map<String,String> map = new HashMap<>();
map.put("appItemId",appItemId);
map.put("token",token);
//会员等级不符,详情页按钮“如何获得兑换资格”
Response detailResponse = mobileService.appItemDetail(appItemId,uid);
detailResponse.prettyPrint();
//会员等级不符,兑换
Response failResponse = given().contentType("application/x-www-form-urlencoded;charset=UTF-8").cookies(authorization.dafuwengLogin(uid)).params(map).post(url + "/couponExchange/exchange");
failResponse.prettyPrint();
//会员等级符合条件,兑换,vip=5
Response response = couponExchangeService.couponExchange(authorization.generateSignAutoLogin("2wGQc3MZaQsqYFWcX4gguya5PnnS",3402),appItemId,"");
response.prettyPrint();
switch (caseNum){
case 1:
Assert.assertEquals(detailResponse.asString().contains("如何获得兑换资格"),true);
Assert.assertEquals(failResponse.jsonPath().getString("success"),"false","校验兑换结果失败");
Assert.assertEquals(failResponse.jsonPath().getString("message"),"会员等级不符,请挑选其他吧(15)","校验兑换结果消息失败");
Assert.assertEquals(response.jsonPath().getString("success"),"true","校验兑换结果失败");
logger.info("校验优惠券会员等级范围成功");
break;
case 2:
Assert.assertEquals(detailResponse.asString().contains("如何获得兑换资格"),true);
Assert.assertEquals(failResponse.jsonPath().getString("success"),"false","校验兑换结果失败");
Assert.assertEquals(failResponse.jsonPath().getString("message"),"会员等级不符,请挑选其他吧(15)","校验兑换结果消息失败");
Assert.assertEquals(response.jsonPath().getString("success"),"true","校验兑换结果失败");
logger.info("校验优惠券会员特定等级成功");
break;
}
}
/**
* @param caseNum 用例编号
* @param appItemId 商品入库Id
* @param itemId 商品id
* @param token token
* @param caseName 用例名称打印
* @throws Exception
*/
@Test(dataProvider = "providerMethod")
public void 优惠券地区兑换限制测试(int caseNum, String appItemId, String itemId, String token,String caseName) throws Exception{
logger.info(caseName);
Map<String,String> map = new HashMap<>();
map.put("appItemId",appItemId);
map.put("itemId",itemId);
map.put("token",token);
//商品详情页兑换按钮
Response detailResponse = mobileService.detail(authorization.dafuwengLogin(uid),itemId);
detailResponse.prettyPrint();
String exchangeText = MatcherString.getString(detailResponse.asString(),"\"exchangeText\":\"(.*?)\"",1);
//优惠券兑换
Response response = given().contentType("application/x-www-form-urlencoded;charset=UTF-8").cookies(authorization.dafuwengLogin(uid)).params(map).post(url + "/couponExchange/exchange");
response.prettyPrint();
switch (caseNum){
case 1:
Assert.assertEquals(exchangeText,"所处区域不可兑换","校验兑换按钮失败");
Assert.assertEquals(response.jsonPath().getString("message"),"不在可兑换区域哦,请挑选其他吧(30)","校验兑换结果失败");
logger.info("校验优惠券地区黑名单不可兑换成功");
break;
case 2:
Assert.assertEquals(exchangeText,"马上兑换","校验兑换按钮失败");
Assert.assertEquals(response.jsonPath().getString("success"),"true","校验兑换结果失败");
logger.info("校验优惠券地区黑名单以外可兑换成功");
break;
case 3:
Assert.assertEquals(exchangeText,"马上兑换","校验兑换按钮失败");
Assert.assertEquals(response.jsonPath().getString("success"),"true","校验兑换结果失败");
logger.info("校验优惠券地区白名单可兑换成功");
break;
case 4:
Assert.assertEquals(exchangeText,"所处区域不可兑换","校验兑换按钮失败");
Assert.assertEquals(response.jsonPath().getString("message"),"不在可兑换区域哦,请挑选其他吧(30)","校验兑换结果失败");
logger.info("校验优惠券地区白名单以外不可兑换成功");
break;
}
}
//优惠券兑换接口抽离
public Response 优惠券兑换(String appItemId,String itemId,int uid) throws Exception {
Response response = couponExchangeService.couponExchange(authorization.dafuwengLogin(uid),appItemId,itemId);
String orderId = response.jsonPath().getString("orderId");
logger.info("订单号:" + orderId);
//查看兑换结果
response = mobileService.orderStatusQuery(authorization.dafuwengLogin(uid), orderId);
response.prettyPrint();
String status = response.jsonPath().getString("status");
//异步接口
int i = 10;
while (i > 0 && status.equals("processing")) {
Thread.sleep(1000);
response = mobileService.orderStatusQuery(authorization.dafuwengLogin(uid), orderId);
response.prettyPrint();
status = response.jsonPath().getString("status");
i--;
}
return response;
}
public String 优惠券兑换订单(String appItemId,String itemId,int uid) throws Exception {
Response response = couponExchangeService.couponExchange(authorization.dafuwengLogin(uid),appItemId,itemId);
String orderId = response.jsonPath().getString("orderId");
//查看兑换结果
response = mobileService.orderStatusQuery(authorization.dafuwengLogin(uid), orderId);
response.prettyPrint();
String status = response.jsonPath().getString("status");
//异步接口
int i = 10;
while (i > 0 && status.equals("processing")) {
Thread.sleep(1000);
response = mobileService.orderStatusQuery(authorization.dafuwengLogin(uid), orderId);
response.prettyPrint();
status = response.jsonPath().getString("status");
i--;
}
return orderId;
}
}
package http.cases.ExchangeTest;
import base.DuibaTestBase;
import http.service.Activity.ManagerService;
import http.service.Authorization;
import http.service.app.AlipayExchangeService;
import http.service.app.ConfirmService;
import http.service.app.CouponExchangeService;
import http.service.app.MobileService;
import http.service.hd.DeveloperAccountService;
import http.service.hd.DsOrderService;
import base.DuibaLog;
import io.restassured.response.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.util.Map;
/**
* Created by lvwenyan on 2018/06/08.
*/
public class 商品订单失败测试_ExchangeTest extends DuibaTestBase {
@Autowired
private CouponExchangeService couponExchangeService;
@Autowired
private ManagerService managerService;
@Autowired
private MobileService mobileService;
@Autowired
private DsOrderService dsOrderService;
@Autowired
private ConfirmService confirmService;
@Autowired
private AlipayExchangeService alipayExchangeService;
@Autowired
private Authorization authorization;
@Autowired
private DeveloperAccountService developerAccountService;
private DuibaLog logger = DuibaLog.getLogger();
//指定用户
private static int uid = 3769;
@Test
public void 实物扣积分失败测试() throws Exception{
managerService.index();
try {
//修改活动扣积分模板 consumeTemplateId: 1-扣积分成功;2-扣积分失败
managerService.doEdit2("2");
//实物兑换
//Response response= this.实物兑换("166813","28430");
Response response= this.实物兑换("170875","27970");
Assert.assertEquals(response.jsonPath().getString("data.message"),"兑换失败,扣积分-失败测试","校验message失败");
Assert.assertEquals(response.jsonPath().getString("data.status"),"fail","校验status失败");
Map<String,Object> mapOrderId = jdbc.findSimpleResult("SELECT * FROM "+Database.orders_consumer+"."+ Database.orders2 + " ORDER BY finish_time DESC LIMIT 1;");
String orderStatus = String.valueOf(mapOrderId.get("status"));
String orderError = String.valueOf(mapOrderId.get("error4consumer"));
Assert.assertEquals(orderStatus,"fail","校验数据库status失败");
Assert.assertEquals(orderError,"兑换失败,扣积分-失败测试","校验数据库error失败");
logger.info("校验实物扣积分失败成功");
}catch (Exception e){
throw new Exception("异常信息打印:" + e);
}finally {
//还原活动扣积分模板 consumeTemplateId: 1-扣积分成功;2-扣积分失败
managerService.doEdit2("1");
}
}
@Test
public void 实物审核不通过测试() throws Exception{
//获取当前库存和积分
Map<String,Object> mapStock = jdbc.findSimpleResult("SELECT * FROM stock.tb_stock WHERE stock_id =683671791616420831");
String stock = String.valueOf(mapStock.get("stock"));
logger.info("当前商品库存:" + stock);
Map<String,Object> mapCredits = jdbc.findSimpleResult("SELECT user.id,user.credits,consumer.credits FROM dafuweng.`user` as user , new_consumer.consumer_0010 as consumer WHERE consumer.partner_user_id=user.id and user.id="+uid);
String userCredits = String.valueOf(mapCredits.get("credits"));
String conCredits = String.valueOf(mapCredits.get("credits(2)"));
logger.info("当前用户积分: " + userCredits);
//实物兑换
String orderId = this.实物兑换订单(uid,"167007","28479");
logger.info("订单号:" + orderId);
//订单审核,判断是否在待审核节点
Map<String,Object> mapOrder = jdbc.findSimpleResult("SELECT * FROM "+Database.orders_consumer+"."+Database.orders5+" WHERE id = " + orderId);
String flowWork = String.valueOf(mapOrder.get("flowwork_stage"));
logger.info("数据库订单节点:" + flowWork);
int i =10;
while (i > 0 && !flowWork.equals("Audit-started")) {
Thread.sleep(300);
mapOrder = jdbc.findSimpleResult("SELECT * FROM "+Database.orders_consumer+"."+Database.orders5+" WHERE id = " + orderId);
flowWork = String.valueOf(mapOrder.get("flowwork_stage"));
logger.info("数据库订单节点:" + flowWork);
i--;
}
//订单审核
Response auditResponse = dsOrderService.submitAudit(orderId,"reject");
auditResponse.prettyPrint();
//判断订单是否审核失败
int j =10;
while (j > 0 && !flowWork.equals("Fail-complete")) {
Thread.sleep(1000);
auditResponse = dsOrderService.submitAudit(orderId,"reject");
mapOrder = jdbc.findSimpleResult("SELECT * FROM "+Database.orders_consumer+"."+Database.orders5+" WHERE id = " + orderId);
flowWork = String.valueOf(mapOrder.get("flowwork_stage"));
logger.info("当前订单节点:" + flowWork);
j--;
}
String orderStatus = String.valueOf(mapOrder.get("status"));
String orderError = String.valueOf(mapOrder.get("error4consumer"));
//再次获取当前库存和积分
Thread.sleep(1000);
mapStock = jdbc.findSimpleResult("SELECT * FROM stock.tb_stock WHERE stock_id =683671791616420831");
String stockNew = String.valueOf(mapStock.get("stock"));
mapCredits = jdbc.findSimpleResult("SELECT user.id,user.credits,consumer.credits FROM dafuweng.`user` as user , new_consumer.consumer_0010 as consumer WHERE consumer.partner_user_id=user.id and user.id="+uid);
String userCreditsNew = String.valueOf(mapCredits.get("credits"));
String conCreditsNew = String.valueOf(mapCredits.get("credits(2)"));
//校验订单状态,校验返回库存和积分
Assert.assertEquals(orderStatus,"fail","校验数据库status失败");
Assert.assertEquals(orderError,"审核不通过(备注:测试订单审核不通过)","校验数据库error失败");
logger.info("校验实物订单审核不通过成功");
Assert.assertEquals(stockNew,stock,"校验stock失败");
Assert.assertEquals(userCreditsNew,userCredits,"校验userCredits失败");
Assert.assertEquals(conCreditsNew,conCredits,"校验conCredits失败");
logger.info("校验实物订单失败返还库存和积分成功");
}
@Test
public void 实物发货撤销测试() throws Exception{
//实物兑换【勿动】自动化兑吧实物
String orderId = this.实物兑换订单(uid,"166813","28430");
logger.info("订单号:" + orderId);
//管理端订单发货撤销
Response response = managerService.cancelOrder(orderId);
response.prettyPrint();
//获取数据库订单状态
Map<String,Object> mapOrder = jdbc.findSimpleResult("SELECT * FROM "+Database.orders_consumer+"."+Database.orders5+" WHERE id = " + orderId);
String flowWork = String.valueOf(mapOrder.get("flowwork_stage"));
int i =10;
while (i > 0 && !flowWork.equals("Fail-complete")) {
Thread.sleep(300);
mapOrder = jdbc.findSimpleResult("SELECT * FROM "+Database.orders_consumer+"."+Database.orders5+" WHERE id = " + orderId);
flowWork = String.valueOf(mapOrder.get("flowwork_stage"));
logger.info("数据库订单节点:" + flowWork);
i--;
}
String orderStatus = String.valueOf(mapOrder.get("status"));
String orderError = String.valueOf(mapOrder.get("error4consumer"));
Assert.assertEquals(response.jsonPath().getString("success"),"true","校验管理端订单发货撤销失败");
Assert.assertEquals(orderStatus,"fail","校验数据库status失败");
Assert.assertEquals(orderError,"测试订单发货撤销","校验数据库error失败");
logger.info("校验实物订单发货撤销成功");
}
@Test
public void 实物加钱购取消订单测试() throws Exception{
//实物兑换
Response objectResponse = couponExchangeService.objectExchange(uid,"167080","null");
String orderId = objectResponse.jsonPath().getString("orderId");
logger.info("订单id:" + orderId);
//手机端取消订单,需等待订单流程到付款节点
Map<String,Object> mapOrder = jdbc.findSimpleResult("SELECT * FROM "+Database.orders_consumer+"."+Database.orders5+" WHERE id = " + orderId);
String flowWork = String.valueOf(mapOrder.get("flowwork_stage"));
logger.info("数据库订单节点: "+ flowWork);
int i =10;
while (i > 0 && !flowWork.equals("ConsumerPay-started")) {
Thread.sleep(300);
mapOrder = jdbc.findSimpleResult("SELECT * FROM "+Database.orders_consumer+"."+Database.orders5+" WHERE id = " + orderId);
flowWork = String.valueOf(mapOrder.get("flowwork_stage"));
logger.info("数据库订单节点:" + flowWork);
i--;
}
Response cancelResponse = confirmService.cancelOrder(uid,orderId);
cancelResponse.prettyPrint();
//获取数据库订单最终状态j
int j =10;
while (j > 0 && !flowWork.equals("Fail-complete")) {
Thread.sleep(300);
mapOrder = jdbc.findSimpleResult("SELECT * FROM "+Database.orders_consumer+"."+Database.orders5+" WHERE id = " + orderId);
flowWork = String.valueOf(mapOrder.get("flowwork_stage"));
logger.info("数据库订单节点:" + flowWork);
j--;
}
String orderStatus = String.valueOf(mapOrder.get("status"));
String orderError = String.valueOf(mapOrder.get("error4consumer"));
Assert.assertEquals(cancelResponse.jsonPath().getString("success"),"true","校验取消订单操作失败");
Assert.assertEquals(orderStatus,"fail","校验数据库status失败");
Assert.assertEquals(orderError,"取消订单","校验数据库error失败");
logger.info("校验实物加钱购取消订单成功");
}
@Test
public void 支付宝兑换失败测试() throws Exception{
//支付宝兑换,使用异常的支付宝账户
Response alipayResponse = alipayExchangeService.exchange(uid,"fail_acctunusual@126.com","测试","1");
String orderId = alipayResponse.jsonPath().getString("orderId");
logger.info("订单id:" + orderId);
Response statusResponse = mobileService.orderStatusQuery(uid,orderId);
statusResponse.prettyPrint();
String message = statusResponse.jsonPath().getString("message");
int i = 30;
//异步接口,直到兑换成功
while (i > 0 && message.equals("兑换正在处理中...")) {
Thread.sleep(1000);
statusResponse = mobileService.orderStatusQuery(uid,orderId);
statusResponse.prettyPrint();
message = statusResponse.jsonPath().getString("message");
i--;
}
//异步接口,判断订单状态,直到处理完成
while (i > 0 && message.equals("兑换提交成功!待处理")) {
Thread.sleep(1000);
statusResponse = mobileService.orderStatusQuery(uid,orderId);
statusResponse.prettyPrint();
message = statusResponse.jsonPath().getString("message");
i--;
}
//获取数据库订单数据
Map<String,Object> mapOrder = jdbc.findSimpleResult("SELECT * FROM "+Database.orders_consumer+"."+Database.orders5+" WHERE id = " + orderId);
String flowWork = String.valueOf(mapOrder.get("flowwork_stage"));
logger.info("数据库订单节点:" + flowWork);
int j =10;
while (j > 0 && !flowWork.equals("Fail-complete")) {
Thread.sleep(300);
mapOrder = jdbc.findSimpleResult("SELECT * FROM "+Database.orders_consumer+"."+Database.orders5+" WHERE id = " + orderId);
flowWork = String.valueOf(mapOrder.get("flowwork_stage"));
logger.info("数据库订单节点:" + flowWork);
j--;
}
String orderStatus = String.valueOf(mapOrder.get("status"));
String orderError = String.valueOf(mapOrder.get("error4consumer"));
Assert.assertEquals(statusResponse.jsonPath().getString("message"),"40004:Business Failed_PAYEE_NOT_EXIST:收款账号不存在","校验message失败");
Assert.assertEquals(orderStatus,"fail","校验数据库status失败");
Assert.assertEquals(orderError,"40004:Business Failed_PAYEE_NOT_EXIST:收款账号不存在","校验数据库error失败");
logger.info("校验支付宝异常账户兑换失败成功");
}
@Test
public void 支付宝审核不通过测试() throws Exception{
//查询兑换前的开发者账户余额
// Response accountResponse = developerAccountService.accountInfo();
// String remainMoney = accountResponse.jsonPath().getString("data.remainMoney");
// logger.info("兑换前的开发者账户余额:" + remainMoney);
//支付宝兑换
String orderId = this.支付宝兑换订单(uid,"peeulk6392@sandbox.com","沙箱环境","10");
logger.info("订单号:" + orderId);
//订单审核,判断是否在待审核节点
Map<String,Object> mapOrder = jdbc.findSimpleResult("SELECT * FROM "+Database.orders_consumer+"."+Database.orders5+" WHERE id = " + orderId);
String flowWork = String.valueOf(mapOrder.get("flowwork_stage"));
logger.info("数据库订单节点:" + flowWork);
String orderIdmain = String.valueOf(mapOrder.get("order_num"));
logger.info("兑吧订单号为:" + orderIdmain);
int i =10;
while (i > 0 && !flowWork.equals("Audit-started")) {
Thread.sleep(300);
mapOrder = jdbc.findSimpleResult("SELECT * FROM "+Database.orders_consumer+"."+Database.orders5+" WHERE id = " + orderId);
flowWork = String.valueOf(mapOrder.get("flowwork_stage"));
logger.info("数据库订单节点:" + flowWork);
i--;
}
//订单审核
Response auditResponse = dsOrderService.submitAudit(orderId,"reject");
auditResponse.prettyPrint();
//判断订单是否审核失败
int j =10;
while (j > 0 && !flowWork.equals("Fail-complete")) {
Thread.sleep(1000);
auditResponse = dsOrderService.submitAudit(orderId,"reject");
mapOrder = jdbc.findSimpleResult("SELECT * FROM "+Database.orders_consumer+"."+Database.orders5+" WHERE id = " + orderId);
flowWork = String.valueOf(mapOrder.get("flowwork_stage"));
logger.info("当前订单节点:" + flowWork);
j--;
}
String status = String.valueOf(mapOrder.get("status"));
//兑换后的开发者账户余额
// accountResponse = developerAccountService.accountInfo();
// String remainMoneyNew = accountResponse.jsonPath().getString("data.remainMoney");
// logger.info("兑换后的开发者账户余额:" + remainMoneyNew);
//校验开发者账户余额变动
Response accountResponse = developerAccountService.cashDetail(orderIdmain);
String remainMoney = String.valueOf(Integer.valueOf(accountResponse.jsonPath().getString("data.list[1].balance"))+Integer.valueOf(accountResponse.jsonPath().getString("data.list[1].moneyChange")));
logger.info("兑换前的开发者账户余额:" + remainMoney);
String remainMoneyNew = accountResponse.jsonPath().getString("data.list[0].balance");
logger.info("兑换后的开发者账户余额:" + remainMoneyNew);
Assert.assertEquals(remainMoneyNew,remainMoney,"校验开发者账户余额失败");
Assert.assertEquals(status,"fail","校验订单状态失败");
logger.info("校验支付宝审核订单失败返还金额成功");
}
// 上游不稳定,暂时关闭
// 上游不稳定,暂时关闭
// @Test
// public void 话费上游兑换失败测试() throws Exception{
//
// try {
// //修改大富翁上游兑换模板(phonebill-oufei)
// managerService.use("104");
// Thread.sleep(500);
// //话费兑换
// Response phoneResponse= couponExchangeService.phonebillExchange(authorization.dafuwengLogin(uid),"156497","1660");
// String orderId = phoneResponse.jsonPath().getString("orderId");
// logger.info("订单id:" + orderId);
//
// Response statusResponse = mobileService.orderStatusQuery(uid,orderId);
// statusResponse.prettyPrint();
// String message = statusResponse.jsonPath().getString("message");
// int i = 10;
// //异步接口,直到兑换成功
// while (i > 0 && message.equals("兑换正在处理中...")) {
// Thread.sleep(1000);
// statusResponse = mobileService.orderStatusQuery(uid,orderId);
// statusResponse.prettyPrint();
// message = statusResponse.jsonPath().getString("message");
// i--;
// }
//
// //获取数据库订单数据,上游订单处理失败需增加等待时间
// Map<String,Object> mapOrder = jdbc.findSimpleResult("SELECT * FROM "+Database.orders_consumer+"."+Database.orders+" WHERE id = " + orderId);
// String flowWork = String.valueOf(mapOrder.get("flowwork_stage"));
// logger.info("数据库订单节点:" + flowWork);
// int j =10;
// while (j > 0 && !flowWork.equals("Fail-complete")) {
// Thread.sleep(1000);
// mapOrder = jdbc.findSimpleResult("SELECT * FROM "+Database.orders_consumer+"."+Database.orders+" WHERE id = " + orderId);
// flowWork = String.valueOf(mapOrder.get("flowwork_stage"));
// logger.info("数据库订单节点:" + flowWork);
// j--;
// }
// String orderStatus = String.valueOf(mapOrder.get("status"));
// String orderError = String.valueOf(mapOrder.get("error4consumer"));
// String orderErrorDev = String.valueOf(mapOrder.get("error4developer"));
//
// Assert.assertEquals(statusResponse.jsonPath().getString("message"),"兑换提交成功!待处理");
// Assert.assertEquals(orderStatus,"fail","校验数据库status失败");
// Assert.assertEquals(orderError,"兑换失败,请稍后重试","校验数据库error4consumer失败");
// Assert.assertEquals(orderErrorDev,"上游兑换失败","校验数据库error4developer失败");
//
// logger.info("校验话费上游兑换失败成功");
//
//
// }catch (Exception e){
// throw new Exception("异常信息打印:" + e);
//
// }finally {
// //还原活动扣积分模板 consumeTemplateId: 1-扣积分成功;2-扣积分失败
// managerService.use("102");
//
// }
//
// }
public Response 实物兑换(String appItemId, String itemId) throws Exception{
Response objectResponse = couponExchangeService.objectExchange(3268,appItemId,itemId);
objectResponse.prettyPrint();
String orderId = objectResponse.jsonPath().getString("orderId");
Response statusResponse = mobileService.orderAmbStatusQuery(3268,orderId);
statusResponse.prettyPrint();
String message = statusResponse.jsonPath().getString("data.message");
int i = 10;
//异步接口,直到兑换成功
while (i > 0 && message.equals("兑换正在处理中...")) {
Thread.sleep(1000);
statusResponse = mobileService.orderAmbStatusQuery(3268,orderId);
statusResponse.prettyPrint();
message = statusResponse.jsonPath().getString("data.message");
i--;
}
return statusResponse;
}
public String 实物兑换订单(int uid, String appItemId, String itemId) throws Exception{
Response objectResponse = couponExchangeService.objectExchange(uid,appItemId,itemId);
objectResponse.prettyPrint();
String orderId = objectResponse.jsonPath().getString("orderId");
Response statusResponse = mobileService.orderAmbStatusQuery(uid,orderId);
statusResponse.prettyPrint();
String message = statusResponse.jsonPath().getString("data.message");
int i = 10;
//异步接口,直到兑换成功
while (i > 0 && message.equals("兑换正在处理中...")) {
Thread.sleep(1000);
statusResponse = mobileService.orderAmbStatusQuery(uid,orderId);
statusResponse.prettyPrint();
message = statusResponse.jsonPath().getString("data.message");
i--;
}
return orderId;
}
//支付宝兑换接口抽离
public String 支付宝兑换订单(int uid,String alipay,String realname,String degreeId) throws Exception {
Response response = alipayExchangeService.exchange(uid,alipay,realname,degreeId);
String orderId = response.jsonPath().getString("orderId");
//查看兑换结果
response = mobileService.orderStatusQuery(authorization.dafuwengLogin(uid), orderId);
response.prettyPrint();
String status = response.jsonPath().getString("status");
//异步接口
int i = 10;
while (i > 0 && status.equals("processing")) {
Thread.sleep(1000);
response = mobileService.orderStatusQuery(authorization.dafuwengLogin(uid), orderId);
response.prettyPrint();
status = response.jsonPath().getString("status");
i--;
}
return orderId;
}
}
package http.cases.ExchangeTest;
import base.DuibaTestBase;
import http.service.Activity.ManagerService;
import http.service.Authorization;
import http.service.app.CouponExchangeService;
import http.service.app.CrecordService;
import http.service.app.MobileService;
import http.service.app.VirtualExchangeService;
import http.service.hd.DeveloperAccountService;
import utils.MatcherString;
import base.DuibaLog;
import io.restassured.response.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.util.Map;
/**
* Created by yeqinqin on 2018/6/11.
*/
public class 实物_兑换异常测试_ExchangeTest extends DuibaTestBase {
@Autowired
private MobileService mobileService;
@Autowired
private Authorization authorization;
@Autowired
private CouponExchangeService couponExchangeService;
@Autowired
private CrecordService crecordService;
@Autowired
ManagerService managerService;
@Autowired
VirtualExchangeService virtualExchangeService;
@Autowired
DeveloperAccountService developerAccountService;
private DuibaLog logger = DuibaLog.getLogger();
//指定用户
private static int uid = 3770;
//实物兑换积分不足
@Test(description = "实物兑换积分不足")
public void 积分不足() throws Exception {
//活动详情页
Response response = mobileService.detail(authorization.dafuwengLogin(3086), "28515");
Map<String, String> map = authorization.dafuwengLogin(3086);
Assert.assertEquals(String.valueOf(response.getStatusCode()), "200", "活动详情页请求异常");
//实物兑换
response = couponExchangeService.objectExchange(map, "167141", "28515", "null", "z9sydmcs", "null");
response.prettyPrint();
//校验兑换成功
// Assert.assertEquals(response.jsonPath().getString("success"),"true");
//获取orderId
String orderId = response.jsonPath().getString("orderId");
//获取兑换结果
response = mobileService.orderAmbStatusQuery(3086,orderId);
response.prettyPrint();
String message = response.jsonPath().getString("data.message");
int i = 10;
//异步接口,直到兑换成功
while (i > 0 && "兑换正在处理中...".equals(message)) {
Thread.sleep(1000);
response = mobileService.orderAmbStatusQuery(3086,orderId);
response.prettyPrint();
message = response.jsonPath().getString("data.message");
i--;
}
//校验messaga字段返回值
String message2 = response.jsonPath().getString("data.message");
Assert.assertEquals(message2,"兑换失败,用户积分余额不足","message字段校验失败-期望是积分不足");
// authorization.dafuwengLogin(2720,true);
}
//实物兑换限制消费
@Test(description = "实物兑换已兑换")
public void 已兑换() throws Exception {
//活动详情页
Response response = mobileService.detail(authorization.dafuwengLogin(uid), "28633");
// response.prettyPrint();
Map<String, String> map = authorization.dafuwengLogin(uid);
Assert.assertEquals(String.valueOf(response.getStatusCode()), "200", "活动详情页请求异常");
//实物兑换
Response response1 = couponExchangeService.objectExchange1(map, "167611", "28633", "null", "z9sydmcs", "null");
response1.prettyPrint();
//校验兑换成功
// Assert.assertEquals(response.jsonPath().getString("success"),"true");
//获取orderId
// String orderId = response1.jsonPath().getString("orderId");
// //获取兑换结果
// Response response3 = mobileService.orderAmbStatusQuery(orderId);
// response3.prettyPrint();
// String message = response3.jsonPath().getString("data.message");
// int i = 10;
// //异步接口,直到兑换成功
// while (i > 0 && "兑换正在处理中...".equals(message)) {
// Thread.sleep(1000);
// response3 = mobileService.orderAmbStatusQuery(orderId);
// response3.prettyPrint();
// message = response3.jsonPath().getString("data.message");
// i--;
// }
//校验messaga字段返回值
String message2 = response1.jsonPath().getString("message");
Assert.assertEquals(message2,"已兑换","message字段校验失败-期望是已兑换");
}
@Test
public void 开发者余额不足测试() throws Exception{
int uid = 3490;
//开发者余额, 开发者账户:xuyan_8707@163.com
Response accountResponse = developerAccountService.accountInfoCommon("xuyan_8707@163.com");
String remainMoney = accountResponse.jsonPath().getString("data.remainMoney");
logger.info("兑换前的开发者账户余额:" + remainMoney);
Response detailResponse = mobileService.detail(authorization.dafuwengLogin(uid),"31050");
String exchangeText = MatcherString.getString(detailResponse.asString(), "\"exchangeText\":\"(.*?)\",", 1);
logger.info("~~~"+exchangeText);
Assert.assertTrue(exchangeText.contains("已兑完"));
String message=null;
String succcess = null;
try{
Response response = couponExchangeService.objectExchange1(authorization.dafuwengLogin(uid), "178880", "31050", "null", "z9sydmcs", "null");
message = response.jsonPath().getString("message");
}catch (Exception e){
message = e.toString();
}
logger.info(message);
Assert.assertTrue(message.contains("没有兑换成功"));
}
// @Test
public void 每日兑换限制() throws Exception {
int uid = 3490;
//第一次兑换
Response response = couponExchangeService.objectExchange(authorization.dafuwengLogin(uid), "178879", "31049", "null", "z9sydmcs", "null");
response.prettyPrint();
String orderId = response.jsonPath().getString("orderId");
//获取兑换结果
response = mobileService.orderAmbStatusQuery(uid,orderId);
response.prettyPrint();
String message = response.jsonPath().getString("data.message");
int i = 10;
//异步接口,直到兑换成功
while (i > 0 && "兑换正在处理中...".equals(message)) {
Thread.sleep(1000);
response = mobileService.orderAmbStatusQuery(uid,orderId);
response.prettyPrint();
message = response.jsonPath().getString("data.message");
i--;
}
//第二次兑换
try{
response = couponExchangeService.objectExchange(authorization.dafuwengLogin(uid), "178879", "31049", "null", "z9sydmcs", "null");
response.prettyPrint();
}catch (Exception e){
// message = e.toString();
}
// logger.info(message);
// Assert.assertTrue(message.contains("已兑完"));
// Assert.assertTrue(message.contains("\"success\":false"));
}
}
package http.cases.ExchangeTest;
import base.DuibaTestBase;
import http.service.Authorization;
import http.service.app.AppPlatformCouponService;
import http.service.app.CrecordService;
import utils.MatcherString;
import base.DuibaLog;
import io.restassured.response.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import static io.restassured.RestAssured.given;
/**
* Created by lvwenyan on 2018/08/09.
*/
//@ContextConfiguration(classes = DuibaConfig.class)
public class 平台券_兑换流程测试_ExchangeTest extends DuibaTestBase {
@Autowired
AppPlatformCouponService appPlatformCouponService;
@Autowired
Authorization authorization;
@Autowired
CrecordService crecordService;
private DuibaLog logger = DuibaLog.getLogger();
private static int uid = 3770;
private String url = "http://activity.m.duibatest.com.cn";
// private MysqlUtils jdbc;
// @BeforeClass
// public void before(){
//
// jdbc = MysqlUtils.mysqlDuiba("");
//
// }
//
// @AfterClass
// public void after(){
//
// jdbc.releaseConn();
// }
@DataProvider
public Object[][] providerMethod(Method method) {
Object[][] result = null;
if (method.getName().equals("平台券库存不足测试")) {
result = new Object[][]{
new Object[]{"73734759122009","n990y8dac","平台券商品库存不足测试"}, //case1
new Object[]{"73734793724984", "s4c0zy","平台券预分配库存不足测试"}, //case2
};
}
if(method.getName().equals("平台券预分配库存测试")){
result = new Object[][]{
new Object[]{"73734759122009","n990y8dac","平台券商品库存不足测试"}, //case1
};
}
if(method.getName().equals("平台券马上使用按钮测试")){
result = new Object[][]{
new Object[]{1,"74372992121534","平台券商家落地页链接测试"}, //case1
new Object[]{2,"74922024942959","平台券兑换记录页链接测试"}, //case2
new Object[]{3,"74378122799009","平台券链接券测试"}, //case3
};
}
return result;
}
@Test
public void 平台券扣积分和库存测试() throws Exception {
//查询平台券兑换前的库存和积分
Map<String,Object> mapStock = jdbc.findSimpleResult("SELECT * FROM stock.tb_stock WHERE stock_id =737253124770670925");
String stock = String.valueOf(mapStock.get("stock")) ;
logger.info("兑换前的平台券库存:" + stock);
stock = String.valueOf(Integer.parseInt(stock) - 1) ;
Map<String,Object> mapuser = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid);
String credits = String.valueOf(mapuser.get("credits"));
logger.info("兑换前积分:"+credits); //扣去100积分
credits = String.valueOf(Integer.valueOf(credits)-10);
//平台券兑换
String orderId = this.平台券兑换订单(uid,"73725292586909");
logger.info("订单号:" + orderId);
//查询优惠券兑换后的库存和积分
mapStock = jdbc.findSimpleResult("SELECT * FROM stock.tb_stock WHERE stock_id =737253124770670925");
String stockNew = String.valueOf(mapStock.get("stock")) ;
logger.info("兑换后的优惠券库存:" + stockNew);
Thread.sleep(3000);
mapuser = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid);
String creditsNew = String.valueOf(mapuser.get("credits"));
logger.info("兑换后积分:"+creditsNew);
//查询订单状态
Map<String,Object> mapOrder = jdbc.findSimpleResult("SELECT * FROM "+Database.orders_consumer+"."+Database.orders6+" WHERE id = " + orderId);
String status = String.valueOf(mapOrder.get("status"));
Assert.assertEquals(stockNew,stock,"校验平台券库存失败");
Assert.assertEquals(creditsNew,credits,"校验平台券扣积分失败");
Assert.assertEquals(status,"success","校验订单状态失败");
logger.info("平台券兑换扣库存和积分校验成功");
}
/**
* @param pcgId 平台券Id
* @param token token
* @param caseName 用例名称打印
* @throws Exception
*/
@Test(dataProvider = "providerMethod")
public void 平台券库存不足测试(String pcgId, String token, String caseName) throws Exception{
logger.info(caseName);
Map<String,String> map = new HashMap<>();
map.put("pcgId",pcgId);
map.put("token",token);
//平台券兑换
Response response = given().contentType("application/x-www-form-urlencoded").cookies(authorization.dafuwengLogin(uid)).params(map).post(url + "/platformCoupon/takeOrder");
response.prettyPrint();
//平台券页面兑换按钮
Response detailResponse = appPlatformCouponService. platformDetail(uid,pcgId);
detailResponse.prettyPrint();
Assert.assertEquals(response.jsonPath().getString("message"),"库存不足","校验message失败");
Assert.assertEquals(detailResponse.asString().contains("已兑完"),true);
logger.info("校验平台券库存不足成功");
}
@Test
public void 平台券积分不足测试() throws Exception{
Map<String,String> map = new HashMap<>();
map.put("pcgId","73725292586909");
map.put("token","dnsog");
//获取按钮状态
Response detailResponse = appPlatformCouponService.platformDetail(3086,true,"73725292586909");
detailResponse.prettyPrint();
String exchangeText = MatcherString.getString(detailResponse.asString(),"exchangeText: '(.*?)',",1);
//平台券兑换
Response response = given().contentType("application/x-www-form-urlencoded").cookies(authorization.dafuwengLogin(3086)).params(map).post(url + "/platformCoupon/takeOrder");
response.prettyPrint();
//exchangetext=2: 积分不足
Assert.assertEquals(exchangeText,"2","校验按钮状态失败");
Assert.assertEquals(response.jsonPath().getString("success"),"false","校验success失败");
logger.info("校验平台券商品积分不足场景成功");
//切换回正常用户
//authorization.dafuwengLogin(uid,true);
}
@Test
public void 平台券预分配库存测试() throws Exception{
Map<String,Object> mapStock = jdbc.findSimpleResult("SELECT * FROM stock.tb_stock WHERE stock_id = 741004276004170604");
String stock = String.valueOf(mapStock.get("stock")) ;
logger.info("兑换前的平台券预分配库存:" + stock);
stock = String.valueOf(Integer.valueOf(stock)-1);
Map<String,Object> mapuser = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid);
String credits = String.valueOf(mapuser.get("credits"));
logger.info("兑换前的积分:"+credits);
credits = String.valueOf(Integer.valueOf(credits)-10);
//平台券兑换
this.平台券兑换(uid,"74100364718684");
//查询兑换后的库存和积分
mapStock = jdbc.findSimpleResult("SELECT * FROM stock.tb_stock WHERE stock_id = 741004276004170604");
String stockNew = String.valueOf(mapStock.get("stock")) ;
logger.info("兑换后的平台券预分配库存:" + stockNew);
Thread.sleep(3000);
mapuser = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid);
String creditsNew = String.valueOf(mapuser.get("credits"));
logger.info("兑换后积分:"+creditsNew);
Assert.assertEquals(stockNew,stock,"校验平台券预分配库存失败");
Assert.assertEquals(creditsNew,credits,"校验平台券预分配最小兑换价格失败");
logger.info("校验平台券预分配库存和最小兑换积分成功");
}
@Test
public void 平台券共享库存测试() throws Exception{
Map<String,Object> mapStock = jdbc.findSimpleResult("SELECT * FROM stock.tb_stock WHERE stock_id = 743716478156171001");
String stock = String.valueOf(mapStock.get("stock")) ;
logger.info("兑换前的平台券共享库存:" + stock);
stock = String.valueOf(Integer.valueOf(stock)-1);
//优惠券兑换
this.平台券兑换(uid,"74371604856809");
//查询兑换后的库存
mapStock = jdbc.findSimpleResult("SELECT * FROM stock.tb_stock WHERE stock_id = 743716478156171001");
String stockNew = String.valueOf(mapStock.get("stock")) ;
logger.info("兑换后的平台券共享库存:" + stockNew);
Assert.assertEquals(stockNew,stock,"校验平台券共享库存库存失败");
logger.info("校验平台券共享库存扣除成功");
}
@Test
public void 平台券预分配每日限额测试() throws Exception{
try {
//平台券第一次兑换
this.平台券兑换(uid,"74735076603359");
//每日限额用完,无法再次兑换
Map<String,String> map = new HashMap<>();
map.put("pcgId","74735076603359");
map.put("token","dnsog");
//获取按钮状态
Response detailResponse = appPlatformCouponService.platformDetail(uid,"74735076603359");
detailResponse.prettyPrint();
String exchangeText = MatcherString.getString(detailResponse.asString(),"exchangeText: '(.*?)',",1);
//平台券兑换
Response response = given().contentType("application/x-www-form-urlencoded").cookies(authorization.dafuwengLogin(uid)).params(map).post(url + "/platformCoupon/takeOrder");
response.prettyPrint();
//exchangetext=3: 已兑完
Assert.assertEquals(exchangeText,"3","校验按钮状态失败");
Assert.assertEquals(response.jsonPath().getString("message"),"库存不足","校验message失败");
logger.info("校验平台券预分配每日限额兑换成功");
}catch (Exception e){
throw new Exception("异常信息打印:" + e);
}finally {
//清除兑换数据和 redis
jdbc.update("DELETE FROM stock.tb_sales_volume WHERE relation_id = 74735076603359");
}
}
@Test
public void 平台券用户兑换限制测试() throws Exception{
try{
//平台券第一次兑换
this.平台券兑换(uid,"74371944595109");
//用户限制次数用完,无法兑换
Map<String,String> map = new HashMap<>();
map.put("pcgId","74371944595109");
map.put("token","dnsog");
//获取按钮状态
Response detailResponse = appPlatformCouponService.platformDetail(uid,"74371944595109");
detailResponse.prettyPrint();
String exchangeText = MatcherString.getString(detailResponse.asString(),"exchangeText: '(.*?)',",1);
Response response = given().contentType("application/x-www-form-urlencoded").cookies(authorization.dafuwengLogin(uid)).params(map).post(url + "/platformCoupon/takeOrder");
response.prettyPrint();
//exchangetext=1: 已兑换
Assert.assertEquals(exchangeText,"1","校验按钮状态失败");
Assert.assertEquals(response.jsonPath().getString("message"),"用户已兑换","校验message失败");
logger.info("校验平台券用户兑换限制成功");
}catch (Exception e){
throw new Exception("异常信息打印:" + e);
}finally {
jdbc.update("DELETE FROM goods.tb_goods_limit_record WHERE gid = 74371944595109 AND consumer_id = 100088018");
}
}
/**
* @param caseNum 用例编号
* @param pcgId 平台券id
* @param caseName 用例名称打印
* @throws Exception
*/
@Test(dataProvider = "providerMethod")
public void 平台券马上使用按钮测试(int caseNum, String pcgId, String caseName)throws Exception{
logger.info(caseName);
String orderId = this.平台券兑换订单(uid,pcgId);
logger.info("订单号: "+ orderId);
//平台券兑换结果页,需要等待订单刷新成功
Thread.sleep(3000);
Response resultResponse = crecordService.recordDetail(orderId,uid);
resultResponse.prettyPrint();
String btnText = MatcherString.getString(resultResponse.asString(),"\"btnText\":\"(.*?)\",",1);
String androidDownloadUrl = MatcherString.getString(resultResponse.asString(),"\"androidDownloadUrl\":\"(.*?)\",",1);
//平台券兑换记录页
Thread.sleep(3000);
Response recordResponse = crecordService.recordDetailNew(orderId,uid);
recordResponse.prettyPrint();
String useButtonText = MatcherString.getString(recordResponse.asString(),"\"useButtonText\":\"(.*?)\",",1);
String androidDownloadUrl2 = MatcherString.getString(recordResponse.asString(),"\"androidDownloadUrl\":\"(.*?)\",",1);
switch (caseNum){
case 1:
Assert.assertEquals(btnText,"马上使用","校验结果页按钮文案失败");
Assert.assertEquals(androidDownloadUrl,"//activity.m.duibatest.com.cn/log/redirect?url=https%3A%2F%2Fm.aomygod.com%2Fact-richang-meidehuierwaitui.html&amp;dpm=2239.25.1.0&amp;dcm=103.74372992121534.0.0","校验结果页按钮链接失败");
Assert.assertEquals(useButtonText,"马上使用","校验兑换记录页按钮文案失败");
Assert.assertEquals(androidDownloadUrl2,"//activity.m.duibatest.com.cn/log/redirect?url=https%3A%2F%2Fm.aomygod.com%2Fact-richang-meidehuierwaitui.html&amp;dpm=2239.25.2.0&amp;dcm=103.74372992121534.0.0","校验兑换记录页按钮跳转链接失败");
logger.info("校验平台券商家落地页下载链接页面成功");
break;
case 2:
Assert.assertEquals(btnText,"马上下载","校验结果页按钮文案失败");
Assert.assertEquals(androidDownloadUrl,"//activity.m.duibatest.com.cn/log/redirect?url=http%3A%2F%2Fm.lrts.me%2Fapp&amp;dpm=2239.25.1.0&amp;dcm=103.74922024942959.0.0","校验结果页按钮链接失败");
Assert.assertEquals(useButtonText,"马上下载","校验兑换记录页按钮文案失败");
Assert.assertEquals(androidDownloadUrl2,"//activity.m.duibatest.com.cn/log/redirect?url=http%3A%2F%2Fm.lrts.me%2Fapp&amp;dpm=2239.25.2.0&amp;dcm=103.74922024942959.0.0","校验兑换记录页按钮跳转链接失败");
logger.info("校验平台券兑换记录页下载链接页面成功");
break;
case 3:
Assert.assertEquals(btnText,"马上使用","校验结果页按钮文案失败");
Assert.assertEquals(androidDownloadUrl,"//activity.m.duibatest.com.cn/log/redirect?url=https%3A%2F%2Fm.4008123123.com%2F&amp;dpm=2239.25.1.0&amp;dcm=103.74378122799009.0.0","校验结果页按钮链接失败");
Assert.assertEquals(useButtonText,"马上使用","校验兑换记录页按钮文案失败");
Assert.assertEquals(androidDownloadUrl2,"//activity.m.duibatest.com.cn/log/redirect?url=https%3A%2F%2Fm.4008123123.com%2F&amp;dpm=2239.25.2.0&amp;dcm=103.74378122799009.0.0","校验兑换记录页按钮跳转链接失败");
logger.info("校验平台券链接券页面成功");
break;
}
}
//平台券兑换接口抽离
public Response 平台券兑换(int uid,String pcgId) throws Exception {
Response response = appPlatformCouponService.takeOrder(uid,pcgId);
String orderId = response.jsonPath().getString("orderId");
logger.info("订单号:" + orderId);
//查看兑换结果
response = appPlatformCouponService.getOrderStatus(uid,orderId);
response.prettyPrint();
return response;
}
public String 平台券兑换订单(int uid,String pcgId) throws Exception {
Response response = appPlatformCouponService.takeOrder(uid,pcgId);
String orderId = response.jsonPath().getString("orderId");
//查看兑换结果
response = appPlatformCouponService.getOrderStatus(uid,orderId);
response.prettyPrint();
return orderId;
}
}
package http.cases.ExchangeTest;
import base.DuibaTestBase;
import http.service.Authorization;
import http.service.Manager.ADeveloperService;
import http.service.app.AlipayExchangeService;
import http.service.app.MobileService;
import http.service.hd.DeveloperAccountService;
import http.service.hd.DsOrderService;
import utils.MatcherString;
import base.DuibaLog;
import io.restassured.response.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import static io.restassured.RestAssured.given;
/**
* Created by lvwenyan on 2018/08/24.
*/
public class 支付宝_兑换流程测试_ExchangeTest extends DuibaTestBase {
@Autowired
AlipayExchangeService alipayExchangeService;
@Autowired
MobileService mobileService;
@Autowired
Authorization authorization;
@Autowired
DsOrderService dsOrderService;
@Autowired
DeveloperAccountService developerAccountService;
@Autowired
ADeveloperService aDeveloperService;
private static int uid = 3771;
private DuibaLog logger = DuibaLog.getLogger();
// private MysqlUtils jdbc;
private String url = "http://activity.m.duibatest.com.cn";
// @BeforeClass
// public void before(){
//
// jdbc = MysqlUtils.mysqlDuiba("");
//
// }
//
// @AfterClass
// public void after(){
//
// jdbc.releaseConn();
// }
@DataProvider
public Object[][] providerMethod(Method method) {
Object[][] result = null;
if (method.getName().equals("支付宝用户兑换限制测试")) {
result = new Object[][]{
new Object[]{1, "peeulk6392@sandbox.com", "沙箱环境", "2", "支付宝用户永久兑换限制测试"}, //case1
new Object[]{2, "peeulk6392@sandbox.com", "沙箱环境", "3", "支付宝用户每日兑换限制测试"}, //case2
};
}
return result;
}
@Test
public void 支付宝审核通过测试() throws Exception{
//查询兑换前的开发者账户余额
// Response accountResponse = developerAccountService.accountInfo();
// String remainMoney = accountResponse.jsonPath().getString("data.remainMoney");
// logger.info("兑换前的开发者账户余额:" + remainMoney);
// String remainMoneyNew =String.valueOf(Integer.valueOf(remainMoney) - 1020) ;
//支付宝兑换
String orderId = this.支付宝兑换订单(uid,"peeulk6392@sandbox.com","沙箱环境","10");
logger.info("订单号:" + orderId);
//订单审核,判断是否在待审核节点
Map<String,Object> mapOrder = jdbc.findSimpleResult("SELECT * FROM "+Database.orders_consumer+"."+Database.orders7+" WHERE id = " + orderId);
String flowWork = String.valueOf(mapOrder.get("flowwork_stage"));
logger.info("数据库订单节点:" + flowWork);
String orderIdmain = String.valueOf(mapOrder.get("order_num"));
logger.info("兑吧订单号为:" + orderIdmain);
int i =10;
while (i > 0 && !flowWork.equals("Audit-started")) {
Thread.sleep(300);
mapOrder = jdbc.findSimpleResult("SELECT * FROM "+Database.orders_consumer+"."+Database.orders7+" WHERE id = " + orderId);
flowWork = String.valueOf(mapOrder.get("flowwork_stage"));
logger.info("数据库订单节点:" + flowWork);
i--;
}
Response auditResponse = dsOrderService.submitAudit(orderId,"pass");
auditResponse.prettyPrint();
//判断订单是否审核成功,如果订单没有成功则继续审核
int j =10;
while (j > 0 && !flowWork.equals("Success-complete")) {
Thread.sleep(1000);
auditResponse = dsOrderService.submitAudit(orderId,"pass");
mapOrder = jdbc.findSimpleResult("SELECT * FROM "+Database.orders_consumer+"."+Database.orders7+" WHERE id = " + orderId);
flowWork = String.valueOf(mapOrder.get("flowwork_stage"));
logger.info("数据库订单节点:" + flowWork);
j--;
}
String status = String.valueOf(mapOrder.get("status"));
//兑换后的开发者账户余额
// accountResponse = developerAccountService.accountInfo();
// remainMoney = accountResponse.jsonPath().getString("data.remainMoney");
// logger.info("兑换后的开发者账户余额:" + remainMoney);
//校验开发者账户余额变动
Response accountResponse = developerAccountService.cashDetail(orderIdmain);
String remainMoney = String.valueOf(Integer.valueOf(accountResponse.jsonPath().getString("data.list[0].balance"))+Integer.valueOf(accountResponse.jsonPath().getString("data.list[0].moneyChange")));
logger.info("兑换前的开发者账户余额:" + remainMoney);
remainMoney =String.valueOf(Integer.valueOf(remainMoney) - 1020) ;
String remainMoneyNew = accountResponse.jsonPath().getString("data.list[0].balance");
logger.info("兑换后的开发者账户余额:" + remainMoneyNew);
Assert.assertEquals(remainMoneyNew,remainMoney,"校验开发者账户余额失败");
Assert.assertEquals(status,"success","校验订单状态失败");
logger.info("校验支付宝扣费订单成功");
}
@Test
public void 支付宝积分不足测试() throws Exception{
//获取按钮状态
Response detailResponse = mobileService.detail(authorization.dafuwengLogin(3086,true),"55");
detailResponse.prettyPrint();
String exchangeText = MatcherString.getString(detailResponse.asString(), "\"exchangeText\":\"(.*?)\",", 1);
//支付宝兑换
Response response = alipayExchangeService.exchange(3086,"peeulk6392@sandbox.com","沙箱环境","10");
String orderId = response.jsonPath().getString("orderId");
logger.info("订单号:" + orderId);
//查看兑换结果
response = mobileService.orderStatusQuery(authorization.dafuwengLogin(3086), orderId);
response.prettyPrint();
String status = response.jsonPath().getString("status");
//异步接口
int i = 10;
while (i > 0 && !status.equals("fail")) {
Thread.sleep(1000);
response = mobileService.orderStatusQuery(authorization.dafuwengLogin(3086), orderId);
response.prettyPrint();
status = response.jsonPath().getString("status");
i--;
}
//订单状态
Map<String,Object> mapOrder = jdbc.findSimpleResult("SELECT * FROM "+Database.orders_consumer+"."+Database.orders3+" WHERE id = " + orderId);
String flowWork = String.valueOf(mapOrder.get("flowwork_stage"));
logger.info("数据库订单节点:" + flowWork);
int j =10;
while (j > 0 && !flowWork.equals("Fail-complete")) {
Thread.sleep(300);
mapOrder = jdbc.findSimpleResult("SELECT * FROM "+Database.orders_consumer+"."+Database.orders3+" WHERE id = " + orderId);
flowWork = String.valueOf(mapOrder.get("flowwork_stage"));
logger.info("数据库订单节点:" + flowWork);
j--;
}
String orderStatus = String.valueOf(mapOrder.get("status"));
Assert.assertEquals(exchangeText,"积分不足","校验马上兑换按钮状态失败");
Assert.assertEquals(response.jsonPath().getString("message"),"兑换失败,用户积分余额不足","校验message失败");
Assert.assertEquals(orderStatus,"fail","校验订单状态失败");
logger.info("校验支付宝商品积分不足场景成功");
}
@Test
public void 支付宝余额不足测试() throws Exception{
//开发者余额, 开发者账户:xuyan_8707@163.com
Response accountResponse = developerAccountService.accountInfoCommon("xuyan_8707@163.com");
String remainMoney = accountResponse.jsonPath().getString("data.remainMoney");
logger.info("兑换前的开发者账户余额:" + remainMoney);
//兑换按钮状态
Response detailResponse = mobileService.detail(authorization.dafuwengLogin(3490),"55");
detailResponse.prettyPrint();
String exchangeText = MatcherString.getString(detailResponse.asString(), "\"exchangeText\":\"(.*?)\",", 1);
//支付宝兑换
Map<String,String> map = new HashMap<>();
map.put("alipay","peeulk6392@sandbox.com");
map.put("realname","沙箱环境");
map.put("degreeId","10");
map.put("itemId","55");
map.put("token","fw7qga0");
Response response = given().contentType("application/x-www-form-urlencoded;charset=UTF-8").cookies(authorization.dafuwengLogin(3490)).params(map).post(url+"/alipayExchange/exchange");
response.prettyPrint();
accountResponse = developerAccountService.accountInfoCommon("xuyan_8707@163.com");
String remainMoneyNew = accountResponse.jsonPath().getString("data.remainMoney");
logger.info("兑换后的开发者账户余额:" + remainMoneyNew);
Assert.assertEquals(exchangeText,"已兑完","校验马上兑换按钮状态失败");
Assert.assertEquals(response.jsonPath().getString("message"),"对不起,没有兑换成功,请挑选其他吧(2)","校验message失败");
Assert.assertEquals(remainMoneyNew,remainMoney,"校验开发者账户余额失败");
logger.info("校验支付宝商品余额不足成功");
}
@Test
public void 支付宝自定义档位扣积分测试() throws Exception{
//兑换前的积分
Map<String,Object> mapCredits = jdbc.findSimpleResult("SELECT * FROM dafuweng.`user` WHERE id = "+uid);
String credits = String.valueOf(mapCredits.get("credits"));
logger.info("兑换前的用户积分:" + credits);
credits = String.valueOf(Integer.valueOf(credits)-10);
this.支付宝兑换(uid,"peeulk6392@sandbox.com","沙箱环境","10");
//兑换后的积分
mapCredits = jdbc.findSimpleResult("SELECT * FROM dafuweng.`user` WHERE id = "+uid);
String creditsNew = String.valueOf(mapCredits.get("credits"));
logger.info("兑换后的用户积分:" + creditsNew);
Assert.assertEquals(creditsNew,credits,"校验支付宝扣积分失败");
logger.info("校验支付宝自定义档位扣积分成功");
}
@Test
public void 支付宝会员等级测试() throws Exception{
//开发者账号马博专用,appId=18740
Map<String,String> map = new HashMap<>();
map.put("alipay","peeulk6392@sandbox.com");
map.put("realname","沙箱环境");
map.put("degreeId","1");
map.put("itemId","55");
map.put("token","fw7qga0");
//会员符合条件,兑换
Response successResponse = this.支付宝兑换(3574,"peeulk6392@sandbox.com","沙箱环境","1");
//会员不符合条件,兑换,vip=5
Response failResponse = given().contentType("application/x-www-form-urlencoded;charset=UTF-8").cookies(authorization.generateSignAutoLogin("3nG61oCgKyPNcHCyxwSmxsF6tNfj",3575)).params(map).post(url + "/alipayExchange/exchange");
failResponse.prettyPrint();
Assert.assertEquals(successResponse.jsonPath().getString("status"),"success","校验支付宝兑换状态失败");
Assert.assertEquals(failResponse.jsonPath().getString("message"),"会员等级不符,请挑选其他吧(15)","校验支付宝兑换状态失败");
logger.info("校验支付宝会员等级兑换成功");
}
/**
* @param caseNum 用例编号
* @param alipay 支付宝账号
* @param realName 支付宝姓名
* @param degreeId 档位
* @param caseName 用例名称打印
* @throws Exception
*/
@Test(dataProvider = "providerMethod")
public void 支付宝用户兑换限制测试(int caseNum, String alipay, String realName, String degreeId, String caseName) throws Exception{
Map<String,String> map = new HashMap<>();
map.put("alipay",alipay);
map.put("realname",realName);
map.put("degreeId",degreeId);
map.put("itemId","55");
map.put("token","fw7qga0");
try{
//支付宝兑换
Response response = this.支付宝兑换(uid,alipay,realName,degreeId);
Assert.assertEquals(response.jsonPath().getString("status"),"success","校验兑换失败");
logger.info("用户成功兑换一次");
//再次兑换
Thread.sleep(3000);
response = given().contentType("application/x-www-form-urlencoded;charset=UTF-8").cookies(authorization.dafuwengLogin(uid)).params(map).post(url + "/alipayExchange/exchange");
response.prettyPrint();
//获取按钮状态
Response detailResponse = mobileService.detail(authorization.dafuwengLogin(uid),"55");
// detailResponse.prettyPrint();
String btnText2 = MatcherString.getString(detailResponse.asString(), "\"2\":\\{\"btnText\":\"(.*?)\",", 1);
String btnText3 = MatcherString.getString(detailResponse.asString(), "\"3\":\\{\"btnText\":\"(.*?)\",", 1);
switch (caseNum){
case 1:
logger.info("再次兑换按钮:" + btnText2);
Assert.assertEquals(response.jsonPath().getString("message"),"已兑完","校验用户兑换限制失败");
Assert.assertEquals(btnText2,"已兑换","校验马上兑换按钮状态失败");
logger.info("校验支付宝用户永久兑换限制成功");
break;
case 2:
logger.info("再次兑换按钮:" + btnText3);
Assert.assertEquals(response.jsonPath().getString("message"),"已兑完","校验用户兑换限制失败");
Assert.assertEquals(btnText3,"今日已兑换","校验马上兑换按钮状态失败");
logger.info("校验支付宝用户每日兑换限制成功");
break;
}
}catch (Exception e){
throw new Exception("异常信息打印:" + e);
}finally {
jdbc.update("DELETE FROM credits_dev.consumer_limit_record_only WHERE item_id = '55'");
jdbc.update("DELETE FROM credits_dev.consumer_limit_record WHERE item_id = '55'");
}
}
//支付宝兑换接口抽离
public String 支付宝兑换订单(int uid,String alipay,String realname,String degreeId) throws Exception {
Response response = alipayExchangeService.exchange(uid,alipay,realname,degreeId);
String orderId = response.jsonPath().getString("orderId");
//查看兑换结果
response = mobileService.orderStatusQuery(authorization.dafuwengLogin(uid), orderId);
response.prettyPrint();
String status = response.jsonPath().getString("status");
//异步接口
int i = 10;
while (i > 0 && status.equals("processing")) {
Thread.sleep(1000);
response = mobileService.orderStatusQuery(authorization.dafuwengLogin(uid), orderId);
response.prettyPrint();
status = response.jsonPath().getString("status");
i--;
}
return orderId;
}
public Response 支付宝兑换(int uid,String alipay,String realname,String degreeId) throws Exception {
Response response = alipayExchangeService.exchange(uid,alipay,realname,degreeId);
String orderId = response.jsonPath().getString("orderId");
//查看兑换结果
response = mobileService.orderStatusQuery(authorization.dafuwengLogin(uid), orderId);
response.prettyPrint();
String status = response.jsonPath().getString("status");
//异步接口
int i = 10;
while (i > 0 && status.equals("processing")) {
Thread.sleep(1000);
response = mobileService.orderStatusQuery(authorization.dafuwengLogin(uid), orderId);
response.prettyPrint();
status = response.jsonPath().getString("status");
i--;
}
return response;
}
}
package http.cases.ExchangeTest;
import base.DuibaTestBase;
import http.service.Activity.ManagerService;
import http.service.Authorization;
import http.service.app.MobileService;
import http.service.app.VirtualExchangeService;
import base.DuibaLog;
import io.restassured.response.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.util.Map;
/**
* Created by yeqinqin on 2018/6/11.
*/
public class 虚拟商品_兑换异常测试 extends DuibaTestBase {
@Autowired
private MobileService mobileService;
@Autowired
private Authorization authorization;
@Autowired
ManagerService managerService;
@Autowired
VirtualExchangeService virtualExchangeService;
private DuibaLog logger = DuibaLog.getLogger();
//指定用户
private static int uid = 0;
//实物兑换积分不足
@Test(description = "自有虚拟商品积分不足")
public void 积分不足() throws Exception {
//活动详情页
Response response = mobileService.appItemDetail(authorization.dafuwengLogin(uid), "181159");
Map<String, String> map = authorization.dafuwengLogin(uid,true);
Assert.assertEquals(String.valueOf(response.getStatusCode()), "200", "商品详情页面");
response.prettyPrint();
System.out.println(response.asString());
System.out.println("女汉子");
//自有虚拟商品兑换
response = virtualExchangeService.exchange(authorization.dafuwengLogin(uid), "181159", "123");
//获取orderId
String orderId = response.jsonPath().getString("orderId");
response = mobileService.orderAmbStatusQuery(uid,orderId);
response.prettyPrint();
String message = response.jsonPath().getString("data.message");
//异步接口,直到兑换成功
int i=10;
//异步接口,直到兑换成功
while(i>0&&"兑换正在处理中...".equals(message)){
Thread.sleep(1000);
response = mobileService.orderAmbStatusQuery(uid,orderId);
response.prettyPrint();
message = response.jsonPath().getString("data.message");
i--;
}
Assert.assertEquals(message.trim(),"兑换失败,用户积分余额不足","校验自有虚拟商品积分不足");
}
}
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