Commit 0983193c authored by 吕雯燕's avatar 吕雯燕

lv

parent 79012c81
......@@ -42,17 +42,30 @@ public class 兑吧新实物_兑换流程测试_ExchangeTest extends CheckTemple
@Autowired
Authorization authorization;
private DuibaLog logger = DuibaLog.getLogger();
int uid = 6866;
@DataProvider
public Object[][] providerMethod(Method method) {
Object[][] result = null;
if (method.getName().equals("日期兑换限制测试")) {
result = new Object[][]{
new Object[]{1, "193805", "32506", "兑吧新实物日期兑换限制未开始"}, //case1
new Object[]{2, "193806", "32507", "兑吧新实物日期兑换限制进行中"}, //case2
new Object[]{3, "193807", "32508", "兑吧新实物日期兑换限制已结束"}, //case3
};
}
return result;
}
@Test(description = "兑吧新实物每人限购每日限制")
@Test(description = "兑吧新实物每人限购每日")
public void 每人限购每日限制测试() throws Exception {
String appItemId = "192950";
String itemId = "32439";
String message = "";
try{
//第一次兑换
Response response = gawService.objectExchange(uid,appItemId,itemId);
String orderId = response.jsonPath().getString("data.orderId");
......@@ -60,7 +73,16 @@ public class 兑吧新实物_兑换流程测试_ExchangeTest extends CheckTemple
response = tawService.orderStatus(orderId,uid);
response.prettyPrint();
String status = response.jsonPath().getString("data.status");
Assert.assertEquals(status,"wait_delivery");
int i = 10;
//异步接口,直到兑换成功
while (i > 0 && status.equals("processing")) {
Thread.sleep(1000);
response = tawService.orderStatus(orderId,uid);
response.prettyPrint();
status = response.jsonPath().getString("data.status");
i--;
}
Assert.assertEquals(status,"wait_delivery","校验轮询结果status失败");
Response detailResponse = mobileService.detail(authorization.dafuwengLogin(uid),itemId);
String exchangeText = MatcherString.getString(detailResponse.asString(), "\"exchangeText\":\"(.*?)\",", 1);
......@@ -81,7 +103,67 @@ public class 兑吧新实物_兑换流程测试_ExchangeTest extends CheckTemple
Assert.assertTrue(message.contains("\"success\":false"),"校验success失败");
Assert.assertEquals(exchangeText,"今日已达兑换上限","校验兑换按钮失败");
logger.info("校验实物用户每日限制消费成功");
logger.info("校验实物每人限购每日限制成功");
}catch (Exception e){
throw new Exception("异常信息打印:" + e);
}finally {
jdbc.update("DELETE FROM credits_dev.consumer_limit_record WHERE item_id = '"+itemId+"'");
}
}
@Test(description = "兑吧新实物每人限购永久")
public void 每人限购永久限制测试() throws Exception {
String appItemId = "193756";
String itemId = "32500";
String message = "";
try{
//第一次兑换
Response response = gawService.objectExchange(uid,appItemId,itemId);
String orderId = response.jsonPath().getString("data.orderId");
//获取兑换结果
response = tawService.orderStatus(orderId,uid);
response.prettyPrint();
String status = response.jsonPath().getString("data.status");
int i = 10;
//异步接口,直到兑换成功
while (i > 0 && status.equals("processing")) {
Thread.sleep(1000);
response = tawService.orderStatus(orderId,uid);
response.prettyPrint();
status = response.jsonPath().getString("data.status");
i--;
}
Assert.assertEquals(status,"wait_delivery","校验轮询结果status失败");
Response detailResponse = mobileService.detail(authorization.dafuwengLogin(uid),itemId);
String exchangeText = MatcherString.getString(detailResponse.asString(), "\"exchangeText\":\"(.*?)\",", 1);
logger.info("商品兑换按钮:" + exchangeText);
//第二次兑换
Thread.sleep(3000);
try{
response = gawService.objectExchange(uid,appItemId,itemId);
response.prettyPrint();
}catch (Exception e){
message = e.toString();
}
logger.info(message);
Assert.assertTrue(message.contains("已达兑换次数上限"),"校验message失败");
Assert.assertTrue(message.contains("\"success\":false"),"校验success失败");
Assert.assertEquals(exchangeText,"已达兑换次数上限","校验兑换按钮失败");
logger.info("校验实物每人限购永久限制成功");
}catch (Exception e){
......@@ -89,6 +171,8 @@ public class 兑吧新实物_兑换流程测试_ExchangeTest extends CheckTemple
}finally {
jdbc.update("DELETE FROM credits_dev.consumer_limit_record WHERE item_id = '"+itemId+"'");
jdbc.update("DELETE FROM credits_dev.consumer_limit_record_only WHERE item_id = '"+itemId+"'");
}
......@@ -96,7 +180,210 @@ public class 兑吧新实物_兑换流程测试_ExchangeTest extends CheckTemple
}
@Test(description = "兑吧新实物每人限购周期")
public void 每人限购周期限制测试() throws Exception {
String appItemId = "193757";
String itemId = "32501";
String message = "";
try{
//第一次兑换
Response response = gawService.objectExchange(uid,appItemId,itemId);
String orderId = response.jsonPath().getString("data.orderId");
//获取兑换结果
response = tawService.orderStatus(orderId,uid);
response.prettyPrint();
String status = response.jsonPath().getString("data.status");
int i = 10;
//异步接口,直到兑换成功
while (i > 0 && status.equals("processing")) {
Thread.sleep(1000);
response = tawService.orderStatus(orderId,uid);
response.prettyPrint();
status = response.jsonPath().getString("data.status");
i--;
}
Assert.assertEquals(status,"wait_delivery","校验轮询结果status失败");
Response detailResponse = mobileService.detail(authorization.dafuwengLogin(uid),itemId);
String exchangeText = MatcherString.getString(detailResponse.asString(), "\"exchangeText\":\"(.*?)\",", 1);
logger.info("商品兑换按钮:" + exchangeText);
//第二次兑换
Thread.sleep(3000);
try{
response = gawService.objectExchange(uid,appItemId,itemId);
response.prettyPrint();
}catch (Exception e){
message = e.toString();
}
logger.info(message);
Assert.assertTrue(message.contains("已达兑换次数上限"),"校验message失败");
Assert.assertTrue(message.contains("\"success\":false"),"校验success失败");
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 = '"+itemId+"'");
jdbc.update("DELETE FROM credits_dev.consumer_limit_record_only WHERE item_id = '"+itemId+"'");
}
}
@Test(description = "兑吧新实物每日限量")
public void 每日限量测试() throws Exception {
String appItemId = "193801";
String itemId = "32505";
String message = "";
try{
//第一次兑换
Response response = gawService.objectExchange(uid,appItemId,itemId);
String orderId = response.jsonPath().getString("data.orderId");
//获取兑换结果
response = tawService.orderStatus(orderId,uid);
response.prettyPrint();
String status = response.jsonPath().getString("data.status");
int i = 10;
//异步接口,直到兑换成功
while (i > 0 && status.equals("processing")) {
Thread.sleep(1000);
response = tawService.orderStatus(orderId,uid);
response.prettyPrint();
status = response.jsonPath().getString("data.status");
i--;
}
Assert.assertEquals(status,"wait_delivery","校验轮询结果status失败");
Response detailResponse = mobileService.detail(authorization.dafuwengLogin(uid),itemId);
String exchangeText = MatcherString.getString(detailResponse.asString(), "\"exchangeText\":\"(.*?)\",", 1);
logger.info("商品兑换按钮:" + exchangeText);
//第二次兑换
Thread.sleep(3000);
try{
response = gawService.objectExchange(uid,appItemId,itemId);
response.prettyPrint();
}catch (Exception e){
message = e.toString();
}
logger.info(message);
Assert.assertTrue(message.contains("商品售罄"),"校验message失败");
Assert.assertTrue(message.contains("\"success\":false"),"校验success失败");
Assert.assertEquals(exchangeText,"每日限量已兑完","校验兑换按钮失败");
logger.info("校验实物每日限量成功");
}catch (Exception e){
throw new Exception("异常信息打印:" + e);
}finally {
jdbc.update("DELETE FROM goods.tb_everyday_limit WHERE item_id = '"+itemId+"'");
}
}
/**
* @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{
String message = "";
logger.info(caseName);
//兑换
try{
Response response = gawService.objectExchange(uid,appItemId,itemId);
response.prettyPrint();
}catch (Exception e){
message = e.toString();
}
logger.info(message);
//获取按钮状态
Response detailResponse = mobileService.detail(authorization.dafuwengLogin(uid),itemId);
String exchangeText = MatcherString.getString(detailResponse.asString(), "\"exchangeText\":\"(.*?)\",", 1);
logger.info("商品兑换按钮:" + exchangeText);
switch (caseNum){
case 1:
Assert.assertTrue(message.contains("限2021-04-01至2021-04-08日期内兑换"),"校验message失败");
Assert.assertEquals(exchangeText,"限2021-04-01至2021-04-08日期内兑换","校验马上兑换按钮状态失败");
logger.info("校验实物日期兑换限制未开始成功");
break;
case 2:
Assert.assertTrue(message.contains(""),"校验message失败");
Assert.assertEquals(exchangeText,"马上兑换","校验马上兑换按钮状态失败");
logger.info("校验实物日期兑换限制进行中成功");
break;
case 3:
Assert.assertTrue(message.contains("限2019-03-20至2019-03-20日期内兑换"),"校验日期兑换限制失败");
Assert.assertEquals(exchangeText,"限2019-03-20至2019-03-20日期内兑换","校验马上兑换按钮状态失败");
logger.info("校验实物日期兑换限制已结束成功");
break;
}
}
@Test(description = "兑吧新实物会员等级限制")
public void 会员等级测试()throws Exception{
String appItemId = "193808";
String itemId = "32509";
String message = "";
//会员等级无法兑换
try{
Response response =gawService.objectExchange(uid,appItemId,itemId);
response.prettyPrint();
}catch (Exception e){
message = e.toString();
}
logger.info(message);
//会员等级可兑换,vip=5
Response response = gawService.objectExchange(authorization.generateSignAutoLogin("vc2HvzM439YBQiB6LVy4uxC4uWm",7001),appItemId,itemId);
response.prettyPrint();
Assert.assertTrue(message.contains("未达到会员等级要求"),"校验message失败");
Assert.assertTrue(message.contains("\"success\":false"),"校验success失败");
Assert.assertEquals(response.jsonPath().getString("success"),"true","校验兑换结果失败");
logger.info("校验实物会员等级成功");
}
}
......@@ -76,4 +76,48 @@ public class gawService {
}
public Response objectExchange(Map cookies, String appItemId,String itemId) throws Exception {
Map<String,Object> map = new HashMap<>();
Map<String,Object> mapList = new HashMap<>();
List<Map> list = new ArrayList<>();
mapList.put("itemId",itemId);
mapList.put("skuId",16);
mapList.put("appItemId",appItemId);
mapList.put("credits","100");
mapList.put("price",0);
list.add(mapList);
map.put("remark",""); //买家留言
map.put("degreeId","");
map.put("actualPrice","0"); //总金额
map.put("actualCredits","100"); //总积分
map.put("itemParam",list.toArray());
map.put("payType","3");
map.put("expressPrice","0");
map.put("validate","");
map.put("token","yrJRr7Cddp2YeQd");
JSONObject jsonParam = JSONObject.parseObject(JSON.toJSONString(map));
logger.info("请求实物兑换接口:"+ "/gaw/objectExchange/create");
Response response = given().contentType("application/json; charset=UTF-8").cookies(cookies).body(jsonParam).post("http://"+goodsHost+"/gaw/objectExchange/create");
// Response saveResponse = given().contentType("application/x-www-form-urlencoded;charset=UTF-8").cookies(authorization.dafuwengLogin(uid)).params(map).post("http://"+goodsHost+"/gaw/objectExchange/create");
// response.prettyPrint();
try{
Assert.assertEquals(response.jsonPath().getString("success"),"true");
}catch(Exception e){
throw new Exception("/gaw/objectExchange/create接口返回异常,返回信息:"+response.asString());
}catch(Error er){
throw new Exception("/gaw/objectExchange/create接口返回异常,返回信息:"+response.asString());
}
return response;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment