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

lv

parent e579132d
......@@ -263,7 +263,6 @@ public class 优惠券_兑换流程测试_ExchangeTest extends CheckTemplet {
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();
......@@ -400,8 +399,8 @@ public class 优惠券_兑换流程测试_ExchangeTest extends CheckTemplet {
//获取按钮状态
Response detailResponse = mobileService.detail(authorization.dafuwengLogin(uid),"29293");
detailResponse.prettyPrint();
String exchangeText = MatcherString.getString(detailResponse.asString(), "\"exchangeText\":\"(.*?)\",", 1);
logger.info("兑换按钮:"+ exchangeText);
Assert.assertEquals(response.jsonPath().getString("message"),"已达兑换次数上限","校验用户兑换限制失败");
Assert.assertEquals(exchangeText,"已达兑换次数上限","校验马上兑换按钮状态失败");
......@@ -424,16 +423,18 @@ public class 优惠券_兑换流程测试_ExchangeTest extends CheckTemplet {
@Test
public void 优惠券用户每日兑换限制测试() throws Exception{
String appItemId = "191781";
String itemId = "32377";
Map<String,String> map = new HashMap<>();
map.put("appItemId","171478");
map.put("itemId","29531");
map.put("appItemId",appItemId);
map.put("itemId",itemId);
map.put("token","yrJRr7Cddp2YeQd");
try{
//优惠券兑换,用户兑换限制次数1次
Response response = this.优惠券兑换("171478","29531", uid);
Response response = this.优惠券兑换(appItemId,itemId, uid);
Assert.assertEquals(response.jsonPath().getString("status"),"success","校验兑换失败");
logger.info("用户成功兑换一次");
//再次兑换
Thread.sleep(3000);
......@@ -441,13 +442,13 @@ public class 优惠券_兑换流程测试_ExchangeTest extends CheckTemplet {
response.prettyPrint();
//获取按钮状态
Response detailResponse = mobileService.detail(authorization.dafuwengLogin(uid),"29531");
detailResponse.prettyPrint();
Response detailResponse = mobileService.detail(authorization.dafuwengLogin(uid),itemId);
String exchangeText = MatcherString.getString(detailResponse.asString(), "\"exchangeText\":\"(.*?)\",", 1);
logger.info("兑换按钮:"+ exchangeText);
Assert.assertEquals(response.jsonPath().getString("message"),"今日已达兑换上限","校验用户兑换限制失败");
Assert.assertEquals(exchangeText,"今日已达兑换上限","校验马上兑换按钮状态失败");
logger.info("校验优惠券用户每兑换限制成功");
logger.info("校验优惠券用户每兑换限制成功");
}catch (Exception e){
......@@ -455,12 +456,53 @@ public class 优惠券_兑换流程测试_ExchangeTest extends CheckTemplet {
}finally {
jdbc.update("DELETE FROM credits_dev.consumer_limit_record WHERE item_id = '29531'");
jdbc.update("DELETE FROM credits_dev.consumer_limit_record WHERE item_id = '"+itemId+"'");
}
}
@Test
public void 优惠券用户批次兑换限制测试() throws Exception{
String appItemId = "191782";
String itemId = "32378";
Map<String,String> map = new HashMap<>();
map.put("appItemId",appItemId);
map.put("itemId",itemId);
map.put("token","yrJRr7Cddp2YeQd");
try{
//优惠券兑换,用户兑换限制次数1次
Response response = this.优惠券兑换(appItemId,itemId, uid);
Assert.assertEquals(response.jsonPath().getString("status"),"success","校验兑换失败");
//再次兑换
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),itemId);
String exchangeText = MatcherString.getString(detailResponse.asString(), "\"exchangeText\":\"(.*?)\",", 1);
logger.info("兑换按钮:"+ exchangeText);
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 = '"+itemId+"'");
}
}
@Test
public void 优惠券每日兑换上限测试() throws Exception{
......@@ -474,7 +516,6 @@ public class 优惠券_兑换流程测试_ExchangeTest extends CheckTemplet {
//优惠券兑换,用户兑换限制次数1次
Response response= this.优惠券兑换("170295","29294", uid);
Assert.assertEquals(response.jsonPath().getString("status"),"success","校验兑换失败");
logger.info("用户成功兑换一次");
//再次兑换
Thread.sleep(3000);
......@@ -483,8 +524,8 @@ public class 优惠券_兑换流程测试_ExchangeTest extends CheckTemplet {
//获取按钮状态
Response detailResponse = mobileService.detail(authorization.dafuwengLogin(uid),"29294");
detailResponse.prettyPrint();
String exchangeText = MatcherString.getString(detailResponse.asString(), "\"exchangeText\":\"(.*?)\",", 1);
logger.info("兑换按钮:" + exchangeText);
Assert.assertEquals(response.jsonPath().getString("message"),"今日已兑完,明天再来哦(14)","校验每日兑换上限失败");
......@@ -719,6 +760,33 @@ public class 优惠券_兑换流程测试_ExchangeTest extends CheckTemplet {
}
@Test
public void 会员等级测试()throws Exception{
String appItemId = "191778";
String itemId = "32374";
String message = "";
//会员等级无法兑换
try{
Response response = couponExchangeService.objectExchange(authorization.dafuwengLogin(uid), appItemId, itemId, "null", "yrJRr7Cddp2YeQd", "null");
response.prettyPrint();
}catch (Exception e){
message = e.toString();
}
logger.info(message);
//会员等级可兑换,vip=5
Response response = couponExchangeService.objectExchange(authorization.generateSignAutoLogin("2wGQc3MZaQsqYFWcX4gguya5PnnS",3402),appItemId,itemId,"null","yrJRr7Cddp2YeQd","null");
response.prettyPrint();
Assert.assertTrue(message.contains("会员等级不符,请挑选其他吧(15)"),"校验message失败");
Assert.assertTrue(message.contains("\"success\":false"),"校验success失败");
Assert.assertEquals(response.jsonPath().getString("success"),"true","校验兑换结果失败");
logger.info("校验实物会员等级成功");
}
/**
* @param caseNum 用例编号
......
......@@ -22,13 +22,16 @@ import org.testng.Assert;
import org.testng.annotations.Test;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import utils.RedisUtil;
import static io.restassured.RestAssured.given;
/**
* Created by yeqinqin on 2018/6/11.
*/
public class 实物_兑换流程测试_ExchangeTest extends CheckTemplet {
public class 兑吧老实物_兑换流程测试_ExchangeTest extends CheckTemplet {
@Autowired
private MobileService mobileService;
......@@ -51,6 +54,8 @@ public class 实物_兑换流程测试_ExchangeTest extends CheckTemplet {
private DuibaLog logger = DuibaLog.getLogger();
//指定用户
private static int uid = 3770;
private String url = "http://activity.m.duibatest.com.cn";
@BeforeClass
public void before(){
......@@ -83,6 +88,25 @@ public class 实物_兑换流程测试_ExchangeTest extends CheckTemplet {
}
@DataProvider
public Object[][] providerMethod(Method method) {
Object[][] result = null;
if (method.getName().equals("日期兑换限制测试")) {
result = new Object[][]{
new Object[]{1, "191775", "32371", "yrJRr7Cddp2YeQd", "实物日期兑换限制未开始测试"}, //case1
new Object[]{2, "191776", "32372", "yrJRr7Cddp2YeQd", "实物日期兑换限制进行中测试"}, //case2
new Object[]{3, "191777", "32373", "yrJRr7Cddp2YeQd", "实物日期兑换限制已结束"}, //case3
};
}
if (method.getName().equals("库存不足测试")) {
result = new Object[][]{
new Object[]{"191779", "32375", "yrJRr7Cddp2YeQd", "实物库存不足测试"}, //case1
new Object[]{"191780", "32376", "yrJRr7Cddp2YeQd", "实物定向库存不足测试"}, //case2
};
}
return result;
}
//实物兑换积分不足
@Test(description = "实物兑换积分不足")
public void 积分不足() throws Exception {
......@@ -325,7 +349,7 @@ public class 实物_兑换流程测试_ExchangeTest extends CheckTemplet {
Assert.assertTrue(message.contains("\"success\":false"),"校验success失败");
Assert.assertEquals(exchangeText,"今日已达兑换上限","校验兑换按钮失败");
logger.info("校验实物每日限制消费成功");
logger.info("校验实物用户每日限制消费成功");
}catch (Exception e){
......@@ -382,7 +406,7 @@ public class 实物_兑换流程测试_ExchangeTest extends CheckTemplet {
Assert.assertTrue(message.contains("\"success\":false"),"校验success失败");
Assert.assertEquals(exchangeText,"已达兑换次数上限","校验兑换按钮失败");
logger.info("校验实物每日限制消费成功");
logger.info("校验实物用户永久限制消费成功");
}catch (Exception e){
......@@ -399,7 +423,177 @@ public class 实物_兑换流程测试_ExchangeTest extends CheckTemplet {
}
@Test
public void 每日兑换上限测试() throws Exception {
String appItemId = "191774";
String itemId = "32370";
try{
//第一次兑换
Response response = couponExchangeService.objectExchange(authorization.dafuwengLogin(uid), appItemId, itemId, "null", "yrJRr7Cddp2YeQd", "null");
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--;
}
Response detailResponse = mobileService.detail(authorization.dafuwengLogin(uid),itemId);
String exchangeText = MatcherString.getString(detailResponse.asString(), "\"exchangeText\":\"(.*?)\",", 1);
logger.info("商品兑换按钮:" + exchangeText);
//第二次兑换
Thread.sleep(3000);
try{
response = couponExchangeService.objectExchange(authorization.dafuwengLogin(uid), appItemId, itemId, "null", "yrJRr7Cddp2YeQd", "null");
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("校验实物每日兑换上限成功");
}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 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 + "/objectExchange/exchange");
response.prettyPrint();
//获取按钮状态
Response detailResponse = mobileService.detail(authorization.dafuwengLogin(uid),itemId);
String exchangeText = MatcherString.getString(detailResponse.asString(), "\"exchangeText\":\"(.*?)\",", 1);
logger.info("商品兑换按钮:" + exchangeText);
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{
String appItemId = "191778";
String itemId = "32374";
String message = "";
//会员等级无法兑换
try{
Response response = couponExchangeService.objectExchange(authorization.dafuwengLogin(uid), appItemId, itemId, "null", "yrJRr7Cddp2YeQd", "null");
response.prettyPrint();
}catch (Exception e){
message = e.toString();
}
logger.info(message);
//会员等级可兑换,vip=5
Response response = couponExchangeService.objectExchange(authorization.generateSignAutoLogin("2wGQc3MZaQsqYFWcX4gguya5PnnS",3402),appItemId,itemId,"null","yrJRr7Cddp2YeQd","null");
response.prettyPrint();
Assert.assertTrue(message.contains("会员等级不符,请挑选其他吧(15)"),"校验message失败");
Assert.assertTrue(message.contains("\"success\":false"),"校验success失败");
Assert.assertEquals(response.jsonPath().getString("success"),"true","校验兑换结果失败");
logger.info("校验实物会员等级成功");
}
/**
* @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 + "/objectExchange/exchange");
response.prettyPrint();
//获取按钮状态
Response detailResponse = mobileService.detail(authorization.dafuwengLogin(uid),itemId);
String exchangeText = MatcherString.getString(detailResponse.asString(), "\"exchangeText\":\"(.*?)\",", 1);
logger.info("兑换按钮:" + exchangeText);
Assert.assertEquals(response.jsonPath().getString("message"),"今日已兑完,明天再来哦(14)","校验message失败");
Assert.assertEquals(exchangeText,"商品售罄","校验马上兑换按钮状态失败");
logger.info("校验实物库存和定向库存不足成功");
}
}
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