Commit 3fa9d5b7 authored by 赵然's avatar 赵然

Merge branch 'develop'

parents 719330f9 aa0becb3
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.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.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(),"兑换失败,用户积分余额不足","校验自有虚拟商品积分不足");
}
}
......@@ -267,13 +267,16 @@ public class 新集卡_助力发集卡_DuibaTest extends DuibaTestBase {
Long dbPostfix = Long.valueOf(consumerId)%b;
String dbName = null;
System.out.println(dbPostfix);
if (dbPostfix.intValue()<100){
dbName = dbPrex +"_00"+ dbPostfix;
}else if (dbPostfix.intValue()<1000){
dbName = dbPrex +"_0"+ dbPostfix;
}else {
dbName = dbPrex +"_"+ dbPostfix;
}
// if (dbPostfix.intValue()<100){
// dbName = dbPrex +"_00"+ dbPostfix;
// }else if (dbPostfix.intValue()<1000){
// dbName = dbPrex +"_0"+ dbPostfix;
// }else {
// dbName = dbPrex +"_"+ dbPostfix;
// }
String tag = String.format("%04d", Long.parseLong(consumerId) % 1024);
dbName = dbPrex +"_"+ tag;
logger.info("该用户的表名为:"+dbName);
return dbName;
}
......
......@@ -19,7 +19,7 @@ import java.util.List;
* Created by humengxin on 2018/8/21.
*/
@ContextConfiguration(classes = Config.class)
public class 自定义分类 extends AbstractTestNGSpringContextTests {
public class 自定义分类_DuibaTest extends AbstractTestNGSpringContextTests {
@Autowired
ZdyflService zdyflService;
......
package http.cases.SingleLotteryTest;
import base.DuibaTestBase;
import utils.PublicMethod;
import http.service.Activity.ManagerService;
import http.service.Activity.SingleLotteryService;
import http.service.Authorization;
import http.service.hd.DeveloperService;
import utils.MatcherString;
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.DataProvider;
import org.testng.annotations.Test;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
/**
* Created by zhaoran on 2018/4/17.
*/
public class 单品抽奖_中鼓励奖_AccessTest extends DuibaTestBase {
@Autowired
SingleLotteryService singleLotteryService;
@Autowired
DeveloperService developerService;
@Autowired
Authorization authorization;
@Autowired
ManagerService managerService;
@Value("${activity.host}")
String activityHost;
private static DuibaLog logger = DuibaLog.getLogger();
private static String actId;
private static String data;
//指定用户
private static int uid = 2709;
@DataProvider
public Object[][] providerMethod(Method method){
Object[][] result = null;
if(method.getName().equals("鼓励奖限制测试")) {
result = new Object[][]{
new Object[]{1, "27128", "1", "","鼓励奖优惠券数量1,数量用完则判断是否可中主奖"},
new Object[]{2, "27000", "99999", "1","鼓励奖限制,数量用完后用户无法再中鼓励奖"},
};
}
return result;
}
@Test(dataProvider = "providerMethod")
public void 鼓励奖限制测试(int caseNum,String inciteItemId,String inciteItemRemaining,String inciteItemConsumerWinLimit,String casename) throws Exception {
logger.info("-------------------------------------"+casename+"-------------------------------------");
//创建活动
this.创建并上架活动(inciteItemId, inciteItemRemaining, inciteItemConsumerWinLimit);
Response response = developerService.list2("【自动化】鼓励奖限制"+data);
String activityId = response.jsonPath().getString("data.list[0].id");
//当天首次抽奖中鼓励奖
response = this.单品抽奖入参(activityId,activityId,"asdsad");
//根据case选择对应的校验项
switch(caseNum){
case 1:
Assert.assertEquals(response.jsonPath().getString("descrption"),"【勿动】自动化优惠券——商家落地页","校验优惠券标题失败");
Assert.assertEquals(response.jsonPath().getString("lotteryType"), "coupon", "校验奖品类型失败");
Assert.assertEquals(response.jsonPath().getString("showUse"), "true", "校验奖品类型失败");
Assert.assertEquals(response.jsonPath().getString("message"), "成功", "校验message失败");
Assert.assertEquals(response.jsonPath().getString("status"), "1", "校验status失败");
logger.info("第一次抽奖,校验descrption,showUse,lotteryType,message,status成功");
logger.info("当天首次抽奖中鼓励奖—优惠券");
break;
case 2:
Assert.assertEquals(response.jsonPath().getString("descrption"),"自动化测试活动实物","校验优惠券标题失败");
Assert.assertEquals(response.jsonPath().getString("lotteryType"), "object", "校验奖品类型失败");
Assert.assertEquals(response.jsonPath().getString("message"), "成功", "校验message失败");
Assert.assertEquals(response.jsonPath().getString("status"), "1", "校验status失败");
logger.info("第一次抽奖,校验descrption,lotteryType,message,status成功");
logger.info("当天首次抽奖中鼓励奖—实物");
break;
}
//当天第二次抽奖
response = this.单品抽奖入参(activityId,activityId,"asdsad");
Assert.assertEquals(response.jsonPath().getString("descrption"),"支付宝充值","校验优惠券标题失败");
Assert.assertEquals(response.jsonPath().getString("lotteryType"), "alipay", "校验奖品类型失败");
Assert.assertEquals(response.jsonPath().getString("message"), "成功", "校验message失败");
Assert.assertEquals(response.jsonPath().getString("status"), "1", "校验status失败");
logger.info("第二次抽奖lotteryType,useBtnText,success");
logger.info("当天第二次抽奖中主奖—支付宝");
//删除测试数据
this.删除活动();
try {
jdbc.update("delete from credits_dev.duiba_single_lottery where title=?", "【自动化】鼓励奖限制"+data);
jdbc.update("delete from credits_dev.operating_activity where title=?", "【自动化】鼓励奖限制"+data);
} catch (Exception e) {
System.out.println(e);
}
}
public Response 单品抽奖入参(String operationAcitvityId,String oaId,String token) throws Exception {
//进行接口测试传参
Response response =singleLotteryService.doJoin(uid,operationAcitvityId,oaId,token);
//response.prettyPrint();
String id =MatcherString.getString(response.asString(), "singleLotteryOrderId\":(.*?),", 1);
response = singleLotteryService.getOrderStatus(uid,id,"iOS");
int i = 10;
while ("处理中".equals(response.jsonPath().getString("message")) && i > 0) {
Thread.sleep(500);
response = singleLotteryService.getOrderStatus(uid,id,"iOS");
i--;
}
return response;
}
public void 创建并上架活动(String inciteItemId,String inciteItemRemaining,String inciteItemConsumerWinLimit) throws Exception {
data = PublicMethod.data();
String title = "【自动化】鼓励奖限制"+data;
//创建单品抽奖活动
//构建鼓励奖
Map<String,String> incite = new HashMap<>();
incite.put("inciteItemId",inciteItemId);
incite.put("inciteItemRate","100");
incite.put("inciteItemRemaining",inciteItemRemaining);
incite.put("preInciteItemRemaining","99999");
incite.put("inciteItemConsumerWinLimit",inciteItemConsumerWinLimit);
incite.put("inciteItemMinComein","");
singleLotteryService.SingleLottery_create(title,incite);
//获取新建活动id
Response response = singleLotteryService.manager_index();
actId = MatcherString.getString(response.asString(), "<td>(.*?)</td>\n", 1);
//管理后台开启活动
singleLotteryService.changeStatus(actId,"1");
//开发者上架活动
developerService.joinIn(actId,"2");
logger.info("创建活动并上架成功");
}
public void 删除活动() throws Exception{
//管理后台删除单品抽奖活动
singleLotteryService.delete(actId);
//开发者删除推荐位活动
Response response = developerService.list2("【自动化】鼓励奖限制"+data);
String actId = response.jsonPath().getString("data.list[0].id");
developerService.delActivity(actId);
}
}
package http.cases.SingleLotteryTest;
import base.DuibaTestBase;
import utils.PublicMethod;
import http.service.Activity.ManagerService;
import http.service.Activity.SingleLotteryService;
import http.service.Authorization;
import http.service.hd.ActivityService;
import http.service.hd.DeveloperService;
import utils.MatcherString;
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.AfterClass;
import org.testng.annotations.Test;
import java.util.HashMap;
import java.util.Map;
/**
* Created by zhaoran on 2018/4/17.
*/
public class 单品抽奖_出奖限制_AccessTest extends DuibaTestBase {
@Autowired
SingleLotteryService singleLotteryService;
@Autowired
DeveloperService developerService;
@Autowired
Authorization authorization;
@Autowired
ManagerService managerService;
@Autowired
ActivityService activityService;
@Value("${activity.host}")
String activityHost;
private static DuibaLog logger = DuibaLog.getLogger();
private static String actId;
private static String data;
//指定用户
private static int uid = 3777;
@AfterClass
public void after() throws Exception{
//数据库删除
try {
jdbc.update("delete from credits_dev.operating_activity where title=?","【自动化】出奖限制"+data);
jdbc.update("delete from credits_dev.duiba_single_lottery where title=?","【自动化】出奖限制"+data);
} catch (Exception e) {
System.out.println(e);
}
}
@Test(description = "每个用户可抽中奖品数上限为1")
public void 出奖限制测试() throws Exception {
this.创建并上架活动();
Response response = developerService.list2("【自动化】出奖限制"+data);
String activityId = response.jsonPath().getString("data.list[0].id");
//当天首次抽奖
response = this.单品抽奖入参(activityId,activityId,"asdsad");
Assert.assertEquals(response.jsonPath().getString("descrption"),"支付宝充值","校验优惠券标题失败");
Assert.assertEquals(response.jsonPath().getString("lotteryType"), "alipay", "校验奖品类型失败");
Assert.assertEquals(response.jsonPath().getString("message"), "成功", "校验message失败");
Assert.assertEquals(response.jsonPath().getString("status"), "1", "校验status失败");
logger.info("第一次抽奖,校验descrption,lotteryType,message,status成功");
//当天第二次抽奖
response = this.单品抽奖入参(activityId,activityId,"asdsad");
logger.info("tuia-engine服务启动成功");
Assert.assertEquals(response.jsonPath().getString("lotteryType"), "lucky", "校验奖品类型失败");
Assert.assertEquals(response.jsonPath().getString("lottery.useBtnText"), "马上使用", "校验是否展示马上使用失败");
Assert.assertEquals(response.jsonPath().getString("success"), "true", "校验success失败");
logger.info("第二次抽奖lotteryType,useBtnText,success");
this.删除活动();
}
public Response 单品抽奖入参(String operationAcitvityId,String oaId,String token) throws Exception {
//进行接口测试传参
Response response =singleLotteryService.doJoin(uid,operationAcitvityId,oaId,token);
//response.prettyPrint();
String id =MatcherString.getString(response.asString(), "singleLotteryOrderId\":(.*?),", 1);
response = singleLotteryService.getOrderStatus(uid,id,"iOS");
int i = 10;
while ("处理中".equals(response.jsonPath().getString("message")) && i > 0) {
Thread.sleep(500);
response = singleLotteryService.getOrderStatus(uid,id,"iOS");
i--;
}
return response;
}
public void 创建并上架活动() throws Exception {
data = PublicMethod.data();
String title = "【自动化】出奖限制"+data;
//创建单品抽奖活动
//构建鼓励奖
Map<String,String> incite = new HashMap<>();
incite.put("inciteItemId","");
incite.put("inciteItemRate","");
incite.put("inciteItemRemaining","");
incite.put("preInciteItemRemaining","");
incite.put("inciteItemConsumerWinLimit","");
incite.put("inciteItemMinComein","");
singleLotteryService.SingleLottery_create(title,incite);
//获取新建活动id
Response response = singleLotteryService.manager_index();
actId = MatcherString.getString(response.asString(), "<td>(.*?)</td>\n", 1);
//管理后台开启活动
singleLotteryService.changeStatus(actId,"1");
//开发者上架活动
developerService.joinIn(actId,"2");
logger.info("创建活动并上架成功");
}
public void 删除活动() throws Exception{
//管理后台删除单品抽奖活动
singleLotteryService.delete(actId);
//开发者删除推荐位活动
Response response = developerService.list2("【自动化】出奖限制"+data);
String actId = response.jsonPath().getString("data.list[0].id");
developerService.delActivity(actId);
}
}
package http.cases.SingleLotteryTest;
import base.Config;
import http.service.Activity.ManagerService;
import http.service.Activity.SingleLotteryService;
import http.service.Authorization;
import http.service.hd.DeveloperService;
import utils.MatcherString;
import base.DuibaLog;
import io.restassured.response.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
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 zhaoran on 2018/4/17.
*/
@ContextConfiguration(classes = Config.class)
public class 单品抽奖_异常场景_AccessTest extends AbstractTestNGSpringContextTests {
@Autowired
SingleLotteryService singleLotteryService;
@Autowired
DeveloperService developerService;
@Autowired
Authorization authorization;
@Autowired
ManagerService managerService;
@Value("${activity.host}")
String activityHost;
private static DuibaLog logger = DuibaLog.getLogger();
//指定用户
private static int uid = 2709;
@DataProvider
public Object[][] providerMethod(Method method){
Object[][] result = null;
if(method.getName().equals("限制抽奖测试")) {
result = new Object[][]{
new Object[]{1, "20065", "积分不足"},
new Object[]{2, "20066", "永久次数抽完"},
new Object[]{3, "20073", "当日次数抽完"},
};
}
if(method.getName().equals("中奖限制测试")) {
result = new Object[][]{
new Object[]{"每人限中1次,次数用完无法中奖", "1340","20915"},
new Object[]{"活动奖品剩余不足,无法中奖", "1341","20927"},
new Object[]{"活动奖品库存不足,无法中奖", "1342","20941"},
};
}
return result;
}
@Test(description = "开发者关闭活动,用户调接口抽奖场景")
public void 活动关闭测试() throws Exception {
//关闭活动
Response HdResponse = developerService.closeActivity("20046","2239");
//参加抽奖
Response response = this.单品抽奖异常场景传参("20046");
//判断结果
Assert.assertEquals(response.jsonPath().getString("success"), "false", "校验success失败");
Assert.assertEquals(response.jsonPath().getString("message"), "活动已结束", "校验message失败");
logger.info("活动状态关闭后的抽奖页面验证成功");
//打开活动
HdResponse = developerService.openActivity("20046","2239");
}
@Test(dataProvider = "providerMethod")
public void 限制抽奖测试(int casenum,String activityId,String casename) throws Exception {
logger.info("-------------------------------------"+casename+"-------------------------------------");
//参加抽奖
Response response = this.单品抽奖异常场景传参(activityId);
//根据case选择对应的校验项
switch(casenum){
case 1:
Assert.assertEquals(response.jsonPath().getString("message"),"积分不足","校验message失败");
logger.info("积分不足测试校验项:messag成功");
break;
case 2:
Assert.assertEquals(response.jsonPath().getString("message"),"已抽完","校验message失败");
Assert.assertEquals(response.jsonPath().getString("lotteryButtonStatus"),"2","校验lotteryButtonStatus失败");
logger.info("永久次数不足测试校验项:message,lotteryButtonStatus成功");
break;
case 3:
String success = MatcherString.getString(response.asString(), "\"success\": (.*?),", 1);
int i= 8;
while(i>0&&(success.equals("true"))){
response = this.单品抽奖异常场景传参(activityId);
success = MatcherString.getString(response.asString(), "\"success\": (.*?),", 1);
i--;
}
Assert.assertEquals(response.jsonPath().getString("message"),"今日已抽完","校验message失败");
Assert.assertEquals(response.jsonPath().getString("lotteryButtonStatus"),"8","校验lotteryButtonStatus失败");
logger.info("今日次数不足测试校验项:message,lotteryButtonStatus成功");
break;
}
//通用校验项
Assert.assertEquals(response.jsonPath().getString("success"),"false","校验success失败");
logger.info("通用校验项:success成功");
}
@Test
public void 未登录抽奖测试() throws Exception {
//获取未登录场景cookie
Response responses = authorization.autoLogin();
//进行接口测试传参
Response response = singleLotteryService.init(responses.getDetailedCookies(),"18873");
//校验项
Assert.assertEquals(response.jsonPath().getString("lotteryButtonStatus"),"7","校验lotteryButtonStatus失败");
logger.info("未登录状态下无免费次数抽奖校验:lotteryButtonStatus成功");
}
@Test(dataProvider = "providerMethod")
public void 中奖限制测试(String casename,String actId,String activityId) throws Exception {
logger.info("-------------------------------------"+casename+"-------------------------------------");
//获取管理员后台活动信息
Response ManagerResponse = singleLotteryService.AdminDuibaSingleLottery(actId);
logger.info("预设中奖商品为:实物类");
logger.info("预设中奖几率为:"+MatcherString.getString(ManagerResponse.asString(), "mainItemRate\" value=\"(.*?)\"", 1)+"%");
logger.info("预设中奖每人限制:"+MatcherString.getString(ManagerResponse.asString(), "consumerWinLimit\" value=\"(.*?)\"", 1));
logger.info("预设剩余奖品数:"+MatcherString.getString(ManagerResponse.asString(), "mainItemRemaining\" value=\"(.*?)\"", 1));
//获取奖品剩余库存
String appItemId = MatcherString.getString(ManagerResponse.asString(), "mainItemId\" value=\"(.*?)\"", 1);
String Objremaind = this.getremind(appItemId);
logger.info("预设奖品库存:"+Objremaind+"个");
//进行接口测试传参
Response response =singleLotteryService.doJoin(uid,activityId,activityId,"asdsad");
//response.prettyPrint();
String id =MatcherString.getString(response.asString(), "singleLotteryOrderId\":(.*?),", 1);
response = singleLotteryService.getOrderStatus(uid,id,"iOS");
int i = 10;
while ("处理中".equals(response.jsonPath().getString("message")) && i > 0) {
Thread.sleep(500);
response = singleLotteryService.getOrderStatus(uid,id,"iOS");
i--;
}
String type = String.valueOf(response.jsonPath().getString("lotteryType"));
if (type.equals("lucky")){
Assert.assertTrue(response.jsonPath().getString("lottery.link").contains("//activity.m.duibatest.com.cn/crecord/recordLuckDetailNew?"));
Assert.assertEquals(response.jsonPath().getString("lottery.useBtnText"),"马上使用","校验useBtnText失败");
Assert.assertEquals(response.jsonPath().getString("isAppLucky"),"true","校验谢谢参与转福袋失败");
logger.info("校验中奖限制测试:link,useBtnText,isAppLucky成功");
logger.info("校验中奖限制测试成功,未返回预设必中实物奖品");
}
if (type.equals("thanks")){
logger.info("福袋库存不足会降级成谢谢参与!");//福袋库存不足会降级成谢谢参与!
}
if (type.equals("object")&&MatcherString.getString(ManagerResponse.asString(), "mainItemRemaining\" value=\"(.*?)\"", 1).equals("0")){
throw new Exception("用例失败,不应返回实物信息:"+response.asString());
}
}
@Test(description = "该单品抽奖已在大富翁app上架可参与")
public void 开发者未上架单品抽奖() {
Response response = this.单品抽奖异常场景传参("33488");
//logger.info("CCCCC"+response.asString());
Assert.assertEquals(response.jsonPath().getString("success"),"false");
Assert.assertEquals(response.jsonPath().getString("message"),"无权访问");
}
public Response 单品抽奖异常场景传参(String activityId) {
Map<String, String> map = new HashMap<>();
map.put("operationAcitvityId", activityId);
map.put("oaId", activityId);
map.put("token", "hdfjks");
Response response = given().cookies(authorization.dafuwengLogin(uid)).params(map).post(activityHost + "/singleLottery/doJoin");
response.prettyPrint();
return response;
}
public String getremind(String gid) throws Exception{
Response ManagerResponse = managerService.CouponConfig(gid);
ManagerResponse.prettyPrint();
String remind = MatcherString.getString(ManagerResponse.asString(), "remaining\" value=\"(.*?)\"", 1);
return remind;
}
}
package http.cases.SingleLotteryTest;
import base.DuibaTestBase;
import http.service.Activity.SingleLotteryService;
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.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.lang.reflect.Method;
import java.util.Map;
/**
* Created by zhaoran on 2018/6/8.
*/
public class 自有单品抽奖_AccessTest extends DuibaTestBase {
@Autowired
SingleLotteryService singleLotteryService;
private static DuibaLog logger = DuibaLog.getLogger();
//指定用户
private static int uid = 2709;
@BeforeClass
public void before() {
try {
jdbc.update("delete from orders_consumer.orders_0616 where consumer_id = 100011624 and biz_params = 'DUIBA_SELF'", null);
} catch (Exception e) {
e.printStackTrace();
}
}
@DataProvider
public Object[][] providerMethod(Method method){
Object[][] result = null;
if(method.getName().equals("自有单品抽奖")) {
result = new Object[][]{
new Object[]{1, "26476", "ix18rh", "单品抽奖之优惠券","iOS"},
new Object[]{2, "26477", "ix18rh", "单品抽奖之实物","android"},
new Object[]{3, "26480", "40g83xb5", "单品抽奖之话费充值","iOS"},
new Object[]{4, "26478", "40g83xb5", "单品抽奖之支付宝充值","iOS"},
new Object[]{5, "26479", "9fm5ohz", "单品抽奖之Q币充值","iOS"},
new Object[]{6, "26481", "x62stnum", "单品抽奖之虚拟商品","iOS"},
};
}
return result;
}
@Test(dataProvider = "providerMethod" )
public void 自有单品抽奖(int caseNum,String activityId,String token,String casename,String device) throws Exception {
logger.info("-------------------------------------"+casename+"-------------------------------------");
//查询数据库,当前积分(抽奖扣积分流程校验)
Map<String,Object> mapuser = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid);
String credits = String.valueOf(mapuser.get("credits"));
logger.info("抽奖前积分:"+credits);
//扣去1积分
credits = String.valueOf(Integer.valueOf(credits)-1);
Response response =singleLotteryService.doJoin(uid,activityId,activityId,token);
//response.prettyPrint();
String id =MatcherString.getString(response.asString(), "singleLotteryOrderId\":(.*?),", 1);
response = singleLotteryService.getOrderStatus(uid,id,device);
int i = 10;
while ("处理中".equals(response.jsonPath().getString("message")) && i > 0) {
Thread.sleep(500);
response = singleLotteryService.getOrderStatus(uid,id,device);
i--;
}
//根据case选择对应的校验项
switch(caseNum){
case 1:
Assert.assertEquals(response.jsonPath().getString("descrption"),"【自动化】优惠券-普通","校验优惠券标题失败");
Assert.assertEquals(response.jsonPath().getString("lotteryType"), "coupon", "校验奖品类型失败");
Assert.assertEquals(response.jsonPath().getString("showUse"), "true", "校验是否展示马上使用失败");
Assert.assertEquals(response.jsonPath().getString("useBtnText"), "马上使用", "校验按钮文案展示失败");
if ( device.equals("iOS")) {
Assert.assertEquals(response.jsonPath().getString("iosDownloadUrl"), "www.baidu.com", "校验Url失败");
}else{
Assert.assertEquals(response.jsonPath().getString("androidDownloadUrl"),"www.baidu.com","校验Url失败");
}
logger.info("校验链接券码项:openUrl,useBtnText成功");
break;
case 2:
Assert.assertEquals(response.jsonPath().getString("descrption"),"【自动化测试误删】实物奖品","校验实物标题失败");
Assert.assertTrue(response.jsonPath().getString("url").contains("/activity/takePrizeNew?recordId"),"兑换记录页url与实际url不匹配");
Assert.assertEquals(response.jsonPath().getString("lotteryType"), "object", "校验奖品类型失败");
logger.info("校验商家落地项:descrption,url,lotteryType成功");
break;
case 3:
Assert.assertEquals(response.jsonPath().getString("descrption"),"多档位话费充值","校验实物标题失败");
Assert.assertEquals(response.jsonPath().getString("itemId"), "1", "校验实物ID失败");
Assert.assertEquals(response.jsonPath().getString("lotteryType"), "phonebill", "校验奖品类型失败");
Assert.assertTrue(response.jsonPath().getString("url").contains("/activity/takePrizeNew?recordId"),"兑换记录页url与实际url不匹配");
logger.info("校验商家落地项:descrption,itemId,lotteryType,url成功");
break;
case 4:
Assert.assertEquals(response.jsonPath().getString("descrption"),"支付宝充值","校验实物标题失败");
Assert.assertEquals(response.jsonPath().getString("itemId"), "55", "校验实物ID失败");
Assert.assertEquals(response.jsonPath().getString("lotteryType"), "alipay", "校验奖品类型失败");
Assert.assertTrue(response.jsonPath().getString("url").contains("/activity/takePrizeNew?recordId"),"兑换记录页url与实际url不匹配");
logger.info("校验商家落地项:descrption,itemId,lotteryType,url成功");
break;
case 5:
Assert.assertEquals(response.jsonPath().getString("descrption"),"Q币充值","校验实物标题失败");
Assert.assertEquals(response.jsonPath().getString("itemId"), "2", "校验实物ID失败");
Assert.assertEquals(response.jsonPath().getString("lotteryType"), "qb", "校验奖品类型失败");
Assert.assertTrue(response.jsonPath().getString("url").contains("/activity/takePrizeNew?recordId"),"兑换记录页url与实际url不匹配");
logger.info("校验商家落地项:descrption,itemId,lotteryType,url成功");
break;
case 6:
Assert.assertEquals(response.jsonPath().getString("descrption"),"【自动化】自有虚拟商品","校验优惠券标题失败");
Assert.assertEquals(response.jsonPath().getString("lotteryType"), "virtual", "校验奖品类型失败");
Assert.assertTrue(response.jsonPath().getString("url").contains("//activity.m.duibatest.com.cn/crecord/recordDetailNew"),"兑换记录页url与实际url不匹配");
logger.info("校验链接券码项:openUrl,useBtnText成功");
Thread.sleep(2000);
Map<String, Object> selectResult = jdbc.findSimpleResult("select * from orders_consumer.orders_0616 where consumer_id = 100011624 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"));
break;
}
//通用校验项
Assert.assertEquals(response.jsonPath().getString("message"), "成功", "校验信息失败");
Assert.assertEquals(response.jsonPath().getString("status"), "1", "校验状态失败");
//查询数据库,获取当前积分
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("校验领奖前后积分正确");
}
}
\ No newline at end of file
package http.cases.SingleLotteryTest;
import base.DuibaTestBase;
import http.service.Activity.SingleLotteryService;
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 zhaoran on 2018/6/8.
*/
public class 自有库存不足_AccessTest extends DuibaTestBase {
@Autowired
SingleLotteryService singleLotteryService;
private static DuibaLog logger = DuibaLog.getLogger();
//指定用户
private static int uid = 3927;
@Test
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);
//扣去1积分
credits = String.valueOf(Integer.valueOf(credits)-1);
Response response =singleLotteryService.doJoin(uid,"34541","34541","238wmftdc");
//response.prettyPrint();
String id =MatcherString.getString(response.asString(), "singleLotteryOrderId\":(.*?),", 1);
response = singleLotteryService.getOrderStatus(uid,id,"iOS");
int i = 10;
while ("处理中".equals(response.jsonPath().getString("message")) && i > 0) {
Thread.sleep(500);
response = singleLotteryService.getOrderStatus(uid,id,"iOS");
i--;
}
Assert.assertEquals(response.jsonPath().getString("lotteryType"), "lucky", "校验奖品类型失败");
Assert.assertEquals(response.jsonPath().getString("lottery.showUse"), "true", "校验是否展示马上使用失败");
Assert.assertEquals(response.jsonPath().getString("lottery.useBtnText"), "马上使用", "校验按钮文案展示失败");
//通用校验项
Assert.assertEquals(response.jsonPath().getString("message"), "成功", "校验信息失败");
Assert.assertEquals(response.jsonPath().getString("status"), "1", "校验状态失败");
//查询数据库,获取当前积分
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("校验领奖前后积分正确");
}
}
\ No newline at end of file
......@@ -172,7 +172,7 @@ public class ZdyflService {
return response;
}
//自定义分类-活动移出分类
//自定义分类_DuibaTest-活动移出分类
public Response removeClassifyAppItem1(String classifyId,String operatingActivityId) throws Exception {
String url=hdHost+"/devItem/removeClassifyAppItem";
......@@ -191,7 +191,7 @@ public class ZdyflService {
return response;
}
//自定义分类-商品移出分类
//自定义分类_DuibaTest-商品移出分类
public Response removeClassifyAppItem2(String classifyId,String appItemId) throws Exception {
String url=hdHost+"/devItem/removeClassifyAppItem";
......
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