Commit d45778de authored by 吕雯燕's avatar 吕雯燕

lv

parent 35c82808
......@@ -25,7 +25,7 @@ import static io.restassured.RestAssured.given;
* Created by panyuli on 2018/07/06.
*/
public class 优惠券_兑换异常测试_ExchangeTest extends CheckTemplet {
public class 自有老优惠券_兑换流程测试_ExchangeTest extends CheckTemplet {
@Autowired
......
......@@ -8,11 +8,17 @@ import io.restassured.response.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import utils.MatcherString;
import java.lang.reflect.Method;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import static io.restassured.RestAssured.given;
/**
* Created by mabo on 2019/2/28
*/
......@@ -21,25 +27,40 @@ public class 话费_兑换限制测试_ExchangeTest extends CheckTemplet{
private MobileService mobileService;
@Autowired
private Authorization authorization;
//指定用户 hd:13193311222
private static int uid = 6537;
@Autowired
private CouponExchangeService couponExchangeService;
@Autowired
private CrecordService crecordService;
//指定用户 hd:13193311222
private static int uid = 6537;
private String url = "http://activity.m.duibatest.com.cn";
@BeforeMethod
public void beforeMethod(){
try {
jdbc.update("DELETE FROM credits_dev.consumer_limit_record where item_id=1662 and consumer_id = 100136046");
jdbc.update("DELETE FROM credits_dev.consumer_limit_record where item_id=1663 and consumer_id = 100136046");
jdbc.update("DELETE FROM credits_dev.consumer_limit_record_only where item_id=1663 and consumer_id = 100136046");
jdbc.update("DELETE FROM goods.tb_everyday_limit where item_id = 1664");
} catch (SQLException e) {
e.printStackTrace();
}
}
@DataProvider
public Object[][] providerMethod(Method method) {
Object[][] result = null;
if (method.getName().equals("兑换日期限制测试")) {
result = new Object[][]{
new Object[]{1, "191795", "1661", "2", "话费兑换日期限制未开始测试"}, //case1,2元话费
new Object[]{3, "191792", "1665", "50", "话费兑换日期限制已结束测试"}, //case3,50元话费
};
}
return result;
}
@Test(description = "每个用户每日兑换限制")
......@@ -81,6 +102,8 @@ public class 话费_兑换限制测试_ExchangeTest extends CheckTemplet{
Assert.assertTrue(e.getMessage().contains("今日已达兑换上限"),"校验每日限制势失败");
}
}
@Test(description = "永久兑换限制")
public void phonebill_永久() throws Exception {
Thread.sleep(2000);
......@@ -120,4 +143,107 @@ public class 话费_兑换限制测试_ExchangeTest extends CheckTemplet{
Assert.assertTrue(e.getMessage().contains("已达兑换次数上限"),"校验永久限制失败");
}
}
@Test
public void 每日兑换上限测试() throws Exception{
String appItemId = "191793";
String itemId = "1664";
//20元话费兑换
Response response = couponExchangeService.phonebillExchange(authorization.dafuwengLogin(uid),appItemId,itemId,"20");
response.prettyPrint();
String orderId = response.jsonPath().getString("orderId");
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 detailResponse = mobileService.detail(authorization.dafuwengLogin(uid),itemId);
String exchangeText = MatcherString.getString(detailResponse.asString(), "\"exchangeText\":\"(.*?)\",", 1);
logger.info("商品兑换按钮:" + exchangeText);
//第二次兑换
try{
response = couponExchangeService.phonebillExchange(authorization.dafuwengLogin(uid),appItemId,itemId,"20");
response.prettyPrint();
}catch (Exception e){
message = e.toString();
}
logger.info(message);
Assert.assertTrue(message.contains("今日已兑完,明天再来哦(14)"),"校验message失败");
Assert.assertTrue(message.contains("\"success\":false"),"校验success失败");
Assert.assertEquals(exchangeText,"每日限量已兑完","校验兑换按钮失败");
logger.info("校验话费每日兑换上限成功");
}
/**
* @param caseNum 用例编号
* @param appItemId 商品入库Id
* @param itemId 商品id
* @param degreeId 档位
* @param caseName 用例名称打印
* @throws Exception
*/
@Test(dataProvider = "providerMethod")
public void 兑换日期限制测试(int caseNum, String appItemId, String itemId, String degreeId, String caseName) throws Exception{
logger.info(caseName);
String message = "";
try{
Response response = couponExchangeService.phonebillExchange(authorization.dafuwengLogin(uid),appItemId,itemId,degreeId);
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("请在限定时间内兑换哦(13)"),"校验message失败");
Assert.assertEquals(exchangeText,"即将开始","校验马上兑换按钮状态失败");
logger.info("校验话费兑换日期限制未开始成功");
break;
case 2:
Assert.assertTrue(message.contains("已结束"),"校验message失败");
Assert.assertEquals(exchangeText,"已结束","校验马上兑换按钮状态失败");
logger.info("校验话费兑换日期限制已结束成功");
break;
}
}
}
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