Commit 67a68e6e authored by 马博's avatar 马博

add

parent a44c0dc8
package http.cases.ExchangeTest;
import http.service.Authorization;
import http.service.app.CouponExchangeService;
import http.service.app.CrecordService;
import http.service.app.MobileService;
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.Test;
import java.sql.SQLException;
import java.util.Map;
/**
* Created by mabo on 2019/2/28
*/
public class 话费_兑换限制测试_ExchangeTest extends CheckTemplet{
@Autowired
private MobileService mobileService;
@Autowired
private Authorization authorization;
//指定用户 hd:13193311222
private static int uid = 6537;
@Autowired
private CouponExchangeService couponExchangeService;
@Autowired
private CrecordService crecordService;
@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");
} catch (SQLException e) {
e.printStackTrace();
}
}
@Test(description = "每个用户每日兑换限制")
public void phonebill_每日() throws Exception {
Thread.sleep(2000);
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), "1662");
Map<String, String> map = authorization.dafuwengLogin(uid);
Assert.assertEquals(String.valueOf(response.getStatusCode()), "200", "活动详情页请求异常");
//1元话费兑换
response = couponExchangeService.phonebillExchange(authorization.dafuwengLogin(uid), "191656", "1662","5");
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--;
}
try{
response = couponExchangeService.phonebillExchange(authorization.dafuwengLogin(uid), "191656", "1662","5");
}catch (Exception e){
Assert.assertTrue(e.getMessage().contains("今日已达兑换上限"),"校验每日限制势失败");
}
}
@Test(description = "永久兑换限制")
public void phonebill_永久() throws Exception {
Thread.sleep(2000);
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), "1663");
Map<String, String> map = authorization.dafuwengLogin(uid);
Assert.assertEquals(String.valueOf(response.getStatusCode()), "200", "活动详情页请求异常");
//1元话费兑换
response = couponExchangeService.phonebillExchange(authorization.dafuwengLogin(uid), "191657", "1663","10");
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--;
}
try{
response = couponExchangeService.phonebillExchange(authorization.dafuwengLogin(uid), "191657", "1663","10");
}catch (Exception e){
Assert.assertTrue(e.getMessage().contains("已达兑换次数上限"),"校验永久限制失败");
}
}
}
package http.cases.MoveBrickTest;
import http.cases.ExchangeTest.CheckTemplet;
import http.service.app.MoveBrickService;
import io.restassured.response.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import utils.RedisUtil;
import java.sql.SQLException;
import java.util.Map;
/**
* Created by mabo on 2019/3/5
*/
public class 搬砖工实物兑换 extends CheckTemplet {
private int uid = 6539;
@Autowired
MoveBrickService moveBrickService;
@AfterMethod
public void afterBefore(){
//初始化兑换记录
RedisUtil.setKey("biz_tool_K077_1_1","1");
try {
jdbc.update("update stock.tb_stock set stock=99999 where stock_id =925751405062120171");
} catch (SQLException e) {
e.printStackTrace();
}
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@Test
public void A_等于兑换数量() throws Exception {
//更新砖块数量
jdbc.update("UPDATE act_record.tb_duiba_brick_account set brick_num =900000 WHERE consumer_id = 100136049 and brick_config_id = 1");
Response response = moveBrickService.exchange(uid,"1");
response.prettyPrint();
Assert.assertEquals(response.jsonPath().getString("desc"),"兑换实物成功","兑换desc失败");
Assert.assertEquals(response.jsonPath().getString("data.brickPrizeId"),"1","兑换brickPrizeId失败");
Assert.assertEquals(response.jsonPath().getString("data.prizeType"),"1","兑换prizeType失败");
Assert.assertEquals(response.jsonPath().getString("data.prizeImage"),"//yun.dui88.com/images/201903/pphoykl8fo.jpg","兑换prizeImage失败");
Assert.assertEquals(response.jsonPath().getString("data.exchangeBrick"),"900000","兑换exchangeBrick失败");
Assert.assertEquals(response.jsonPath().getString("data.redPacket"),"0","兑换redPacket失败");
Assert.assertTrue(response.jsonPath().getString("data.prizeUrl").contains("//activity.m.duibatest.com.cn/activity/takePrizeNew?recordId="),"兑换prizeUrl失败");
Map<String,Object> map = jdbc.findSimpleResult("SELECT * FROM act_record.tb_duiba_brick_account WHERE consumer_id = 100136049 and brick_config_id = 1");
String brickNum = map.get("brick_num").toString();
Assert.assertTrue("0".equals(brickNum),"验证剩余砖块数量不正确");
}
@Test
public void B_未达到兑换数量() throws Exception{
jdbc.update("UPDATE act_record.tb_duiba_brick_account set brick_num =899999 WHERE consumer_id = 100136049 and brick_config_id = 1");
Response response = moveBrickService.exchange(uid,"1");
response.prettyPrint();
Assert.assertEquals(response.jsonPath().getString("desc"),"兑换奖品的砖块数不足","兑换desc失败");
Assert.assertEquals(response.jsonPath().getString("success"),"false","兑换desc失败");
Map<String,Object> map = jdbc.findSimpleResult("SELECT * FROM act_record.tb_duiba_brick_account WHERE consumer_id = 100136049 and brick_config_id = 1");
String brickNum = map.get("brick_num").toString();
Assert.assertTrue("899999".equals(brickNum),"验证剩余砖块数量不正确");
}
@Test
public void C_超过兑换数量() throws Exception{
jdbc.update("UPDATE act_record.tb_duiba_brick_account set brick_num =900001 WHERE consumer_id = 100136049 and brick_config_id = 1");
Response response = moveBrickService.exchange(uid,"1");
response.prettyPrint();
Assert.assertEquals(response.jsonPath().getString("desc"),"兑换实物成功","兑换desc失败");
Assert.assertEquals(response.jsonPath().getString("data.brickPrizeId"),"1","兑换brickPrizeId失败");
Assert.assertEquals(response.jsonPath().getString("data.prizeType"),"1","兑换prizeType失败");
Assert.assertEquals(response.jsonPath().getString("data.prizeImage"),"//yun.dui88.com/images/201903/pphoykl8fo.jpg","兑换prizeImage失败");
Assert.assertEquals(response.jsonPath().getString("data.exchangeBrick"),"900000","兑换exchangeBrick失败");
Assert.assertEquals(response.jsonPath().getString("data.redPacket"),"0","兑换redPacket失败");
Assert.assertTrue(response.jsonPath().getString("data.prizeUrl").contains("//activity.m.duibatest.com.cn/activity/takePrizeNew?recordId="),"兑换prizeUrl失败");
Map<String,Object> map = jdbc.findSimpleResult("SELECT * FROM act_record.tb_duiba_brick_account WHERE consumer_id = 100136049 and brick_config_id = 1");
String brickNum = map.get("brick_num").toString();
Assert.assertTrue("1".equals(brickNum),"验证剩余砖块数量不正确");
}
@Test
public void D_中奖人数达到限制() throws Exception {
//key=biz_tool_K077_brickConfigId_brickPrizeId
RedisUtil.setKey("biz_tool_K077_1_1","9998");
//兑换成功
jdbc.update("UPDATE act_record.tb_duiba_brick_account set brick_num =900000 WHERE consumer_id = 100136049 and brick_config_id = 1");
Response response = moveBrickService.exchange(uid,"1");
response.prettyPrint();
Assert.assertEquals(response.jsonPath().getString("desc"),"兑换实物成功","兑换desc失败");
Map<String,Object> map = jdbc.findSimpleResult("SELECT * FROM act_record.tb_duiba_brick_account WHERE consumer_id = 100136049 and brick_config_id = 1");
String brickNum = map.get("brick_num").toString();
Assert.assertTrue("0".equals(brickNum),"验证剩余砖块数量不正确");
//达到奖品限制,兑换失败
jdbc.update("UPDATE act_record.tb_duiba_brick_account set brick_num =900000 WHERE consumer_id = 100136049 and brick_config_id = 1");
response = moveBrickService.exchange(uid,"1");
Assert.assertEquals(response.jsonPath().getString("desc"),"奖品已失效","兑换desc失败");
map = jdbc.findSimpleResult("SELECT * FROM act_record.tb_duiba_brick_account WHERE consumer_id = 100136049 and brick_config_id = 1");
brickNum = map.get("brick_num").toString();
Assert.assertTrue("900000".equals(brickNum),"验证剩余砖块数量不正确");
//初始化兑换记录
RedisUtil.setKey("biz_tool_K077_1_1","1");
}
@Test
public void E_奖品没有库存() throws Exception {
jdbc.update("update stock.tb_stock set stock=1 where stock_id =925751405062120171");
//兑换成功
jdbc.update("UPDATE act_record.tb_duiba_brick_account set brick_num =900000 WHERE consumer_id = 100136049 and brick_config_id = 1");
Thread.sleep(2000);
Response response = moveBrickService.exchange(uid,"1");
Assert.assertEquals(response.jsonPath().getString("desc"),"兑换实物成功","兑换desc失败");
Map<String,Object> map = jdbc.findSimpleResult("SELECT * FROM act_record.tb_duiba_brick_account WHERE consumer_id = 100136049 and brick_config_id = 1");
String brickNum = map.get("brick_num").toString();
Assert.assertTrue("0".equals(brickNum),"验证剩余砖块数量不正确");
//库存为零,兑换失败
jdbc.update("UPDATE act_record.tb_duiba_brick_account set brick_num =900000 WHERE consumer_id = 100136049 and brick_config_id = 1");
response = moveBrickService.exchange(uid,"1");
Assert.assertEquals(response.jsonPath().getString("desc"),"奖品已失效","兑换desc失败");
map = jdbc.findSimpleResult("SELECT * FROM act_record.tb_duiba_brick_account WHERE consumer_id = 100136049 and brick_config_id = 1");
brickNum = map.get("brick_num").toString();
Assert.assertTrue("900000".equals(brickNum),"验证剩余砖块数量不正确");
jdbc.update("update stock.tb_stock set stock=99999 where stock_id =925751405062120171");
}
}
package http.cases.MoveBrickTest;
import http.cases.ExchangeTest.CheckTemplet;
import http.service.app.MoveBrickService;
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 mabo on 2019/3/5
*/
public class 搬砖工红包兑换 extends CheckTemplet {
private int uid = 6545;
@Autowired
MoveBrickService moveBrickService;
@Test
public void 等于兑换数量() throws Exception {
jdbc.update("UPDATE act_record.tb_duiba_brick_account set brick_num =300000 WHERE consumer_id = 100136061 and brick_config_id = 2");
Map<String,Object> map = jdbc.findSimpleResult("SELECT * FROM consumer_accounts.tb_consumer_account_0125 where partner_user_id = ?",uid);
int account = Integer.valueOf(map.get("balance_amount").toString());
//第一次兑换
Response response = moveBrickService.exchange(uid,"2");
response.prettyPrint();
String redPacket1 = response.jsonPath().getString("data.redPacket");
//第二次兑换
response = moveBrickService.exchange(uid,"2");
response.prettyPrint();
String redPacket2 = response.jsonPath().getString("data.redPacket");
//第三次兑换
response = moveBrickService.exchange(uid,"2");
response.prettyPrint();
String redPacket3 = response.jsonPath().getString("data.redPacket");
//第四次兑换
response = moveBrickService.exchange(uid,"2");
response.prettyPrint();
String redPacket4 = response.jsonPath().getString("data.redPacket");
//第五次兑换
response = moveBrickService.exchange(uid,"2");
response.prettyPrint();
String redPacket5 = response.jsonPath().getString("data.redPacket");
//校验红包账户余额
map = jdbc.findSimpleResult("SELECT * FROM consumer_accounts.tb_consumer_account_0125 where partner_user_id = ?",uid);
int accountNew = Integer.valueOf(map.get("balance_amount").toString());
Assert.assertEquals(accountNew,account+1500);
//校验账户剩余砖块数
map = jdbc.findSimpleResult("SELECT * FROM act_record.tb_duiba_brick_account WHERE consumer_id = 100136061 and brick_config_id = 2");
String brickNum = map.get("brick_num").toString();
Assert.assertTrue("0".equals(brickNum),"验证剩余砖块数量不正确");
}
@Test
public void 未达到兑换数量() throws Exception{
jdbc.update("UPDATE act_record.tb_duiba_brick_account set brick_num =299999 WHERE consumer_id = 100136061 and brick_config_id = 2");
Map<String,Object> map = jdbc.findSimpleResult("SELECT * FROM consumer_accounts.tb_consumer_account_0125 where partner_user_id = ?",uid);
int account = Integer.valueOf(map.get("balance_amount").toString());
//第一次兑换
Response response = moveBrickService.exchange(uid,"2");
response.prettyPrint();
String redPacket1 = response.jsonPath().getString("data.redPacket");
//第二次兑换
response = moveBrickService.exchange(uid,"2");
response.prettyPrint();
String redPacket2 = response.jsonPath().getString("data.redPacket");
//第三次兑换
response = moveBrickService.exchange(uid,"2");
response.prettyPrint();
String redPacket3 = response.jsonPath().getString("data.redPacket");
//第四次兑换
response = moveBrickService.exchange(uid,"2");
response.prettyPrint();
String redPacket4 = response.jsonPath().getString("data.redPacket");
//第五次兑换
response = moveBrickService.exchange(uid,"2");
response.prettyPrint();
Assert.assertEquals(response.jsonPath().getString("desc"),"兑换奖品的砖块数不足","兑换校验失败");
//校验红包账户余额
map = jdbc.findSimpleResult("SELECT * FROM consumer_accounts.tb_consumer_account_0125 where partner_user_id = ?",uid);
int accountNew = Integer.valueOf(map.get("balance_amount").toString());
Assert.assertEquals(accountNew,account+1100);
account=accountNew;
//校验账户剩余砖块数
map = jdbc.findSimpleResult("SELECT * FROM act_record.tb_duiba_brick_account WHERE consumer_id = 100136061 and brick_config_id = 2 and exchanged =2");
String brickNum = map.get("brick_num").toString();
Assert.assertTrue("79999".equals(brickNum),"验证剩余砖块数量不正确");
String redPacket5 = response.jsonPath().getString("data.redPacket");
jdbc.update("UPDATE act_record.tb_duiba_brick_account set brick_num =80000 WHERE consumer_id = 100136061 and brick_config_id = 2 and exchanged =2");
response = moveBrickService.exchange(uid,"2");
Assert.assertEquals(response.jsonPath().getString("desc"),"兑换成功","兑换校验失败");
//校验红包账户余额
map = jdbc.findSimpleResult("SELECT * FROM consumer_accounts.tb_consumer_account_0125 where partner_user_id = ?",uid);
accountNew = Integer.valueOf(map.get("balance_amount").toString());
Assert.assertEquals(accountNew,account+400);
//校验账户剩余砖块数
map = jdbc.findSimpleResult("SELECT * FROM act_record.tb_duiba_brick_account WHERE consumer_id = 100136061 and brick_config_id = 2");
brickNum = map.get("brick_num").toString();
Assert.assertTrue("0".equals(brickNum),"验证剩余砖块数量不正确");
}
@Test
public void 超过兑换数量() throws Exception{
jdbc.update("UPDATE act_record.tb_duiba_brick_account set brick_num =300001 WHERE consumer_id = 100136061 and brick_config_id = 2");
Map<String,Object> map = jdbc.findSimpleResult("SELECT * FROM consumer_accounts.tb_consumer_account_0125 where partner_user_id = ?",uid);
int account = Integer.valueOf(map.get("balance_amount").toString());
//第一次兑换
Response response = moveBrickService.exchange(uid,"2");
response.prettyPrint();
String redPacket1 = response.jsonPath().getString("data.redPacket");
//第二次兑换
response = moveBrickService.exchange(uid,"2");
response.prettyPrint();
String redPacket2 = response.jsonPath().getString("data.redPacket");
//第三次兑换
response = moveBrickService.exchange(uid,"2");
response.prettyPrint();
String redPacket3 = response.jsonPath().getString("data.redPacket");
//第四次兑换
response = moveBrickService.exchange(uid,"2");
response.prettyPrint();
String redPacket4 = response.jsonPath().getString("data.redPacket");
//第五次兑换
response = moveBrickService.exchange(uid,"2");
response.prettyPrint();
String redPacket5 = response.jsonPath().getString("data.redPacket");
//校验红包账户余额
map = jdbc.findSimpleResult("SELECT * FROM consumer_accounts.tb_consumer_account_0125 where partner_user_id = ?",uid);
int accountNew = Integer.valueOf(map.get("balance_amount").toString());
Assert.assertEquals(accountNew,account+1500);
//校验账户剩余砖块数
map = jdbc.findSimpleResult("SELECT * FROM act_record.tb_duiba_brick_account WHERE consumer_id = 100136061 and brick_config_id = 2");
String brickNum = map.get("brick_num").toString();
Assert.assertTrue("1".equals(brickNum),"验证剩余砖块数量不正确");
}
}
...@@ -18,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -18,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import utils.CheckPublic;
import utils.MatcherString; import utils.MatcherString;
import java.util.Map; import java.util.Map;
...@@ -29,7 +30,7 @@ import java.util.Map; ...@@ -29,7 +30,7 @@ import java.util.Map;
* @create 2018/5/31 * @create 2018/5/31
* @since 1.0.0 * @since 1.0.0
*/ */
public class 兑吧_优惠券秒杀商品兑换测试 extends DuibaTestBase { public class 兑吧_优惠券秒杀商品兑换测试_SeckillTest extends DuibaTestBase {
@Autowired @Autowired
...@@ -50,6 +51,11 @@ public class 兑吧_优惠券秒杀商品兑换测试 extends DuibaTestBase { ...@@ -50,6 +51,11 @@ public class 兑吧_优惠券秒杀商品兑换测试 extends DuibaTestBase {
public void 兑吧秒杀优惠券商品兑换测试() { public void 兑吧秒杀优惠券商品兑换测试() {
try { try {
Map<String,String> map = CheckPublic.beforeGet(jdbc,"consumer_0010",String.valueOf(uid_Nomal),1);
Map<String,Object> itemStockResult = jdbc.findSimpleResult("select * from stock.tb_stock where stock_id =(select stock_id from goods.tb_goods_batch where gid = ?)",28423); Map<String,Object> itemStockResult = jdbc.findSimpleResult("select * from stock.tb_stock where stock_id =(select stock_id from goods.tb_goods_batch where gid = ?)",28423);
Long itemStock = Long.parseLong(itemStockResult.get("stock").toString()); Long itemStock = Long.parseLong(itemStockResult.get("stock").toString());
...@@ -89,11 +95,16 @@ public class 兑吧_优惠券秒杀商品兑换测试 extends DuibaTestBase { ...@@ -89,11 +95,16 @@ public class 兑吧_优惠券秒杀商品兑换测试 extends DuibaTestBase {
",type="+MatcherString.getString(queryResponse.asString(),"\"type\":\"(.*?)\",",1)); ",type="+MatcherString.getString(queryResponse.asString(),"\"type\":\"(.*?)\",",1));
String orderId = MatcherString.getString(queryResponse.asString(),"\"orderId\":\"(.*?)\",",1);
Map<String,Object> itemStockResult1 = jdbc.findSimpleResult("select * from stock.tb_stock where stock_id =(select stock_id from goods.tb_goods_batch where gid = ?)",28423); Map<String,Object> itemStockResult1 = jdbc.findSimpleResult("select * from stock.tb_stock where stock_id =(select stock_id from goods.tb_goods_batch where gid = ?)",28423);
String itemStock1 = itemStockResult1.get("stock").toString(); String itemStock1 = itemStockResult1.get("stock").toString();
Assert.assertEquals(itemStock1,String.valueOf(itemStock-1),"校验库存失败"); Assert.assertEquals(itemStock1,String.valueOf(itemStock-1),"校验库存失败");
logger.info("扣库存校验成功,原库存="+itemStock+",现在库存="+itemStock1); logger.info("扣库存校验成功,原库存="+itemStock+",现在库存="+itemStock1);
CheckPublic.afterAssert(map,jdbc,"orders_0589",orderId);
//清理take_order_queue_record表数据,防止连续兑换报错 //清理take_order_queue_record表数据,防止连续兑换报错
Boolean tearResult = jdbc.update("delete from credits_dev.take_order_queue_record where queue_id = ?",queueId); Boolean tearResult = jdbc.update("delete from credits_dev.take_order_queue_record where queue_id = ?",queueId);
Boolean tearResult2 = jdbc.update("delete from credits_dev.take_order_queue_record\n"); Boolean tearResult2 = jdbc.update("delete from credits_dev.take_order_queue_record\n");
......
/**
* Copyright (C), 2015-2018
* FileName: 兑吧_优惠券秒杀商品兑换测试
* Author: qianwenjun
* Date: 2018/5/31 17:57
* Description: 开发者自有秒杀商品测试
*/
package http.cases.SeckillTest;
import base.DuibaLog;
import base.DuibaTestBase;
import com.alibaba.fastjson.JSON;
import http.service.Authorization;
import http.service.app.SeckillService;
import io.restassured.response.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.testng.Assert;
import org.testng.annotations.Test;
import utils.MatcherString;
import java.util.Map;
/**
* 〈开发者自有秒杀商品测试〉
*
* @author qianwenjun
* @create 2018/5/31
* @since 1.0.0
*/
public class 兑吧_实物秒杀商品兑换测试 extends DuibaTestBase {
@Autowired
SeckillService seckillService;
@Autowired
Authorization authorization;
private static DuibaLog logger = DuibaLog.getLogger();
private static final Integer uid_Nomal = 4112;
private static final String consumer_Nomal = "100092492";
@Test
public void 兑吧实物秒杀商品兑换测试() {
try {
Map<String,Object> user = jdbc.findSimpleResult("select * from dafuweng.user where id=?\n",uid_Nomal);
Map<String,Object> consumer = jdbc.findSimpleResult("select * from new_consumer.consumer_0010 where id=?\n",consumer_Nomal);
Long userCredit = Long.parseLong(user.get("credits").toString());
Long consumerCredit = Long.parseLong(consumer.get("credits").toString());
Map<String,Object> itemStockResult = jdbc.findSimpleResult("select * from stock.tb_stock where stock_id in (select stock_id from goods.item where id = ?)\n","28205");
Long itemStock = Long.parseLong(itemStockResult.get("stock").toString());
Response response = seckillService.exchange1("165895","28205",uid_Nomal);
response.prettyPrint();
String queueId = response.jsonPath().getString("data.queueId");
Response queryResponse = seckillService.queueQuery(queueId,uid_Nomal);
queryResponse.prettyPrint();
String title = MatcherString.getString(queryResponse.asString(),"<title>(.*?)</title>",1);
String exchangeStatus = MatcherString.getString(queryResponse.asString(),"\"exchangeStatus\":\"(.*?)\",",1);
for (int i=36;i >0;i--){
if ((title.equals("等待中"))||(exchangeStatus.equals("process"))){
Thread.sleep(3000);
queryResponse = seckillService.queueQuery(queueId,uid_Nomal);
queryResponse.prettyPrint();
title = MatcherString.getString(queryResponse.asString(),"<title>(.*?)</title>",1);
exchangeStatus = MatcherString.getString(queryResponse.asString(),"\"kind\":\"(.*?)\",",1);
}else {
break;
}
}
logger.info("response的结果信息为:"+"\nStatusCode="+String.valueOf(queryResponse.getStatusCode())+";exchangeStatus="+exchangeStatus);
// int statusCode = response.getStatusCode();
// Headers header = queryResponse.getHeaders();
// logger.info("header=" + header.toString() + ";statusCode=" + statusCode);
Assert.assertEquals(String.valueOf(queryResponse.getStatusCode()),"200","校验响应状态码失败");
logger.info("queueId="+queueId+",queryResponse的信息为"+ JSON.toJSONString(queryResponse));
Assert.assertEquals(MatcherString.getString(queryResponse.asString(),"\"exchangeStatus\":\"(.*?)\",",1),"wait_ship","校验exchangeStatus失败");
Assert.assertEquals(MatcherString.getString(queryResponse.asString(),"\"exchangeStatusText\":\"(.*?)\",",1),"待发货","校验exchangeStatusText失败");
Assert.assertEquals(MatcherString.getString(queryResponse.asString(),"\"addrName\":\"(.*?)\",",1),"胡梦新","校验addrName失败");
Assert.assertEquals(MatcherString.getString(queryResponse.asString(),"\"addrPhone\":\"(.*?)\",",1),"18258853242","校验addrPhone失败");
Assert.assertEquals(MatcherString.getString(queryResponse.asString(),"\"addrProvince\":\"(.*?)\",",1),"浙江省","校验addrProvince失败");
Assert.assertEquals(MatcherString.getString(queryResponse.asString(),"\"addrCity\":\"(.*?)\",",1),"杭州市","校验addrCity失败");
Assert.assertEquals(MatcherString.getString(queryResponse.asString(),"\"addrArea\":\"(.*?)\",",1),"西湖区","校验addrArea失败");
Assert.assertEquals(MatcherString.getString(queryResponse.asString(),"\"addrDetail\":\"(.*?)\",",1),"数娱大厦","校验addrDetail失败");
Assert.assertEquals(MatcherString.getString(queryResponse.asString(),"\"actualPay\":\"(.*?)\"}",1),"20积分","校验actualPay失败");
logger.info("兑吧实物秒杀商品兑换结果校验成功");
logger.info("exchangeStatusText="+MatcherString.getString(queryResponse.asString(),"\"exchangeStatusText\":\"(.*?)\",",1)+
",actualPay消耗积分="+MatcherString.getString(queryResponse.asString(),"\"actualPay\":\"(.*?)\"}",1)+
",收货人信息="+MatcherString.getString(queryResponse.asString(),"\"addrName\":\"(.*?)\",",1)+
",地址信息="+MatcherString.getString(queryResponse.asString(),"\"addrDetail\":\"(.*?)\",",1));
Map<String,Object> itemStockResult1 = jdbc.findSimpleResult("select * from stock.tb_stock where stock_id in (select stock_id from goods.item where id = ?)\n","28205");
String itemStock1 = itemStockResult.get("stock").toString();
// Assert.assertEquals(itemStock1,String.valueOf(itemStock-1),"校验库存失败");
Thread.sleep(3000);
Map<String,Object> user1 = jdbc.findSimpleResult("select * from dafuweng.user where id=?\n",uid_Nomal);
Map<String,Object> consumer1 = jdbc.findSimpleResult("select * from new_consumer.consumer_0010 where id=?\n",consumer_Nomal);
String userCredit1 = user1.get("credits").toString();
String consumerCredit1 = consumer1.get("credits").toString();
Assert.assertEquals(userCredit1,String.valueOf(userCredit-20),"user积分扣除校验失败");
Assert.assertEquals(consumerCredit1,String.valueOf(consumerCredit-20),"consumer积分扣除校验失败");
logger.info("校验积分消耗成功,原积分值="+userCredit+",消耗后积分值为"+userCredit1);
//清理take_order_queue_record表数据,防止连续兑换报错
Boolean tearResult = jdbc.update("delete from credits_dev.take_order_queue_record where queue_id = ?",queueId);
Boolean tearResult2 = jdbc.update("delete from credits_dev.take_order_queue_record\n");
} catch (Exception e) {
e.printStackTrace();
}
}
}
\ No newline at end of file
/**
* Copyright (C), 2015-2018
* FileName: 兑吧_优惠券秒杀商品兑换测试
* Author: qianwenjun
* Date: 2018/5/31 17:57
* Description: 开发者自有秒杀商品测试
*/
package http.cases.SeckillTest;
import base.DuibaLog;
import base.DuibaTestBase;
import com.alibaba.fastjson.JSON;
import http.service.Authorization;
import http.service.app.SeckillService;
import io.restassured.response.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.testng.Assert;
import org.testng.annotations.Test;
import utils.CheckPublic;
import utils.MatcherString;
import java.util.Map;
/**
* 〈开发者自有秒杀商品测试〉
*
* @author qianwenjun
* @create 2018/5/31
* @since 1.0.0
*/
public class 兑吧_实物秒杀商品兑换测试_SeckillTest extends DuibaTestBase {
@Autowired
SeckillService seckillService;
@Autowired
Authorization authorization;
private static DuibaLog logger = DuibaLog.getLogger();
private static final Integer uid_Nomal = 4112;
private static final String consumer_Nomal = "100092492";
@Test
public void 兑吧实物秒杀商品兑换测试() {
try {
Map<String,String> map = CheckPublic.beforeGet(jdbc,"consumer_0010",String.valueOf(uid_Nomal),20);
Map<String,Object> itemStockResult = jdbc.findSimpleResult("select * from stock.tb_stock where stock_id in (select stock_id from goods.item where id = ?)\n","28205");
Long itemStock = Long.parseLong(itemStockResult.get("stock").toString());
Response response = seckillService.exchange1("165895","28205",uid_Nomal);
response.prettyPrint();
String queueId = response.jsonPath().getString("data.queueId");
Response queryResponse = seckillService.queueQuery(queueId,uid_Nomal);
queryResponse.prettyPrint();
String title = MatcherString.getString(queryResponse.asString(),"<title>(.*?)</title>",1);
String exchangeStatus = MatcherString.getString(queryResponse.asString(),"\"exchangeStatus\":\"(.*?)\",",1);
for (int i=36;i >0;i--){
if ((title.equals("等待中"))||(exchangeStatus.equals("process"))){
Thread.sleep(3000);
queryResponse = seckillService.queueQuery(queueId,uid_Nomal);
queryResponse.prettyPrint();
title = MatcherString.getString(queryResponse.asString(),"<title>(.*?)</title>",1);
exchangeStatus = MatcherString.getString(queryResponse.asString(),"\"kind\":\"(.*?)\",",1);
}else {
break;
}
}
logger.info("response的结果信息为:"+"\nStatusCode="+String.valueOf(queryResponse.getStatusCode())+";exchangeStatus="+exchangeStatus);
Assert.assertEquals(String.valueOf(queryResponse.getStatusCode()),"200","校验响应状态码失败");
logger.info("queueId="+queueId+",queryResponse的信息为"+ JSON.toJSONString(queryResponse));
String orderId = MatcherString.getString(queryResponse.asString(),"orderId: '(.*?)'",1);
Map<String,Object> itemStockResult1 = jdbc.findSimpleResult("select * from stock.tb_stock where stock_id in (select stock_id from goods.item where id = ?)\n","28205");
String itemStock1 = itemStockResult1.get("stock").toString();
Assert.assertEquals(itemStock1,String.valueOf(itemStock-1),"校验库存失败");
Thread.sleep(3000);
CheckPublic.afterAssert(map,jdbc,null,null);
String order = "orders_0588";
Map<String,Object> mapOrder = jdbc.findSimpleResult("SELECT * FROM orders_consumer."+order+" where id="+orderId);
String flowwork_stage = String.valueOf(mapOrder.get("flowwork_stage"));
Assert.assertTrue(flowwork_stage.equals("SupplierExchange-started"),"订单状态校验失败");
//清理take_order_queue_record表数据,防止连续兑换报错
Boolean tearResult = jdbc.update("delete from credits_dev.take_order_queue_record where queue_id = ?",queueId);
Boolean tearResult2 = jdbc.update("delete from credits_dev.take_order_queue_record\n");
} catch (Exception e) {
e.printStackTrace();
}
}
}
\ No newline at end of file
...@@ -18,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -18,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import utils.CheckPublic;
import utils.MatcherString; import utils.MatcherString;
import java.util.Map; import java.util.Map;
...@@ -29,7 +30,7 @@ import java.util.Map; ...@@ -29,7 +30,7 @@ import java.util.Map;
* @create 2018/5/31 * @create 2018/5/31
* @since 1.0.0 * @since 1.0.0
*/ */
public class 自有_优惠券秒杀商品兑换测试 extends DuibaTestBase { public class 自有_优惠券秒杀商品兑换测试_SeckillTest extends DuibaTestBase {
@Autowired @Autowired
...@@ -46,6 +47,10 @@ public class 自有_优惠券秒杀商品兑换测试 extends DuibaTestBase { ...@@ -46,6 +47,10 @@ public class 自有_优惠券秒杀商品兑换测试 extends DuibaTestBase {
public void 自有秒杀优惠券商品兑换测试(){ public void 自有秒杀优惠券商品兑换测试(){
try { try {
Map<String,String> map = CheckPublic.beforeGet(jdbc,"consumer_0010",String.valueOf(uid_Nomal),10);
Map<String,Object> itemStockResult = jdbc.findSimpleResult("select * from stock.tb_stock where stock_id =(select stock_id from goods.tb_goods_batch where gid = ?)",167879); Map<String,Object> itemStockResult = jdbc.findSimpleResult("select * from stock.tb_stock where stock_id =(select stock_id from goods.tb_goods_batch where gid = ?)",167879);
Long itemStock = Long.parseLong(itemStockResult.get("stock").toString()); Long itemStock = Long.parseLong(itemStockResult.get("stock").toString());
...@@ -78,10 +83,15 @@ public class 自有_优惠券秒杀商品兑换测试 extends DuibaTestBase { ...@@ -78,10 +83,15 @@ public class 自有_优惠券秒杀商品兑换测试 extends DuibaTestBase {
Assert.assertEquals(MatcherString.getString(queryResponse.asString(),"\"actualPay\":\"(.*?)\",",1),"10积分","校验actualPay失败"); Assert.assertEquals(MatcherString.getString(queryResponse.asString(),"\"actualPay\":\"(.*?)\",",1),"10积分","校验actualPay失败");
Assert.assertEquals(MatcherString.getString(queryResponse.asString(),"\"type\":\"(.*?)\",",1),"coupon","校验type失败"); Assert.assertEquals(MatcherString.getString(queryResponse.asString(),"\"type\":\"(.*?)\",",1),"coupon","校验type失败");
String orderId = MatcherString.getString(queryResponse.asString(),"\"orderId\":\"(.*?)\",",1);
Map<String,Object> itemStockResult1 = jdbc.findSimpleResult("select * from stock.tb_stock where stock_id =(select stock_id from goods.tb_goods_batch where gid = ?)",167879); Map<String,Object> itemStockResult1 = jdbc.findSimpleResult("select * from stock.tb_stock where stock_id =(select stock_id from goods.tb_goods_batch where gid = ?)",167879);
String itemStock1 = itemStockResult1.get("stock").toString(); String itemStock1 = itemStockResult1.get("stock").toString();
Assert.assertEquals(itemStock1,String.valueOf(itemStock-1),"校验库存失败"); Assert.assertEquals(itemStock1,String.valueOf(itemStock-1),"校验库存失败");
CheckPublic.afterAssert(map,jdbc,"orders_0592",orderId);
//清理take_order_queue_record表数据,防止连续兑换报错 //清理take_order_queue_record表数据,防止连续兑换报错
Boolean tearResult = jdbc.update("delete from credits_dev.take_order_queue_record where queue_id = ?",queueId); Boolean tearResult = jdbc.update("delete from credits_dev.take_order_queue_record where queue_id = ?",queueId);
Boolean tearResult2 = jdbc.update("delete from credits_dev.take_order_queue_record\n"); Boolean tearResult2 = jdbc.update("delete from credits_dev.take_order_queue_record\n");
......
...@@ -18,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -18,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import utils.CheckPublic;
import utils.MatcherString; import utils.MatcherString;
import java.util.Map; import java.util.Map;
...@@ -29,7 +30,7 @@ import java.util.Map; ...@@ -29,7 +30,7 @@ import java.util.Map;
* @create 2018/5/31 * @create 2018/5/31
* @since 1.0.0 * @since 1.0.0
*/ */
public class 自有_实物秒杀商品兑换测试 extends DuibaTestBase { public class 自有_实物秒杀商品兑换测试_SeckillTest extends DuibaTestBase {
@Autowired @Autowired
...@@ -46,7 +47,7 @@ public class 自有_实物秒杀商品兑换测试 extends DuibaTestBase { ...@@ -46,7 +47,7 @@ public class 自有_实物秒杀商品兑换测试 extends DuibaTestBase {
// @Test @Test
public void 自有秒杀实物商品兑换测试() { public void 自有秒杀实物商品兑换测试() {
...@@ -54,6 +55,9 @@ public class 自有_实物秒杀商品兑换测试 extends DuibaTestBase { ...@@ -54,6 +55,9 @@ public class 自有_实物秒杀商品兑换测试 extends DuibaTestBase {
Map<String,Object> itemStockResult = jdbc.findSimpleResult("select * from stock.tb_stock where stock_id in (select stock_id from goods.app_item where id = ?)\n","167880"); Map<String,Object> itemStockResult = jdbc.findSimpleResult("select * from stock.tb_stock where stock_id in (select stock_id from goods.app_item where id = ?)\n","167880");
Long itemStock = Long.parseLong(itemStockResult.get("stock").toString()); Long itemStock = Long.parseLong(itemStockResult.get("stock").toString());
Map<String,String> map = CheckPublic.beforeGet(jdbc,"consumer_0010",String.valueOf(uid_Nomal),20);
Response response = seckillService.exchange1("167880","undefined",uid_Nomal); Response response = seckillService.exchange1("167880","undefined",uid_Nomal);
response.prettyPrint(); response.prettyPrint();
String queueId = response.jsonPath().getString("data.queueId"); String queueId = response.jsonPath().getString("data.queueId");
...@@ -79,20 +83,24 @@ public class 自有_实物秒杀商品兑换测试 extends DuibaTestBase { ...@@ -79,20 +83,24 @@ public class 自有_实物秒杀商品兑换测试 extends DuibaTestBase {
logger.info("response的结果信息为:"+"\nStatusCode="+String.valueOf(queryResponse.getStatusCode())+";exchangeStatus="+exchangeStatus); logger.info("response的结果信息为:"+"\nStatusCode="+String.valueOf(queryResponse.getStatusCode())+";exchangeStatus="+exchangeStatus);
Assert.assertEquals(String.valueOf(queryResponse.getStatusCode()),"200","校验响应状态码失败"); Assert.assertEquals(String.valueOf(queryResponse.getStatusCode()),"200","校验响应状态码失败");
logger.info("queueId="+queueId+",queryResponse的信息为"+ JSON.toJSONString(queryResponse)); logger.info("queueId="+queueId+",queryResponse的信息为"+ JSON.toJSONString(queryResponse));
Assert.assertEquals(MatcherString.getString(queryResponse.asString(),"\"exchangeStatus\":\"(.*?)\",",1),"wait_ship","校验exchangeStatus失败");
Assert.assertEquals(MatcherString.getString(queryResponse.asString(),"\"exchangeStatusText\":\"(.*?)\",",1),"待发货","校验exchangeStatusText失败");
Assert.assertEquals(MatcherString.getString(queryResponse.asString(),"\"addrName\":\"(.*?)\",",1),"胡梦新","校验addrName失败"); String orderId = MatcherString.getString(queryResponse.asString(),"orderId: '(.*?)'",1);
Assert.assertEquals(MatcherString.getString(queryResponse.asString(),"\"addrPhone\":\"(.*?)\",",1),"18258853242","校验addrPhone失败");
Assert.assertEquals(MatcherString.getString(queryResponse.asString(),"\"addrProvince\":\"(.*?)\",",1),"浙江省","校验addrProvince失败"); CheckPublic.afterAssert(map,jdbc,null,null);
Assert.assertEquals(MatcherString.getString(queryResponse.asString(),"\"addrCity\":\"(.*?)\",",1),"杭州市","校验addrCity失败");
Assert.assertEquals(MatcherString.getString(queryResponse.asString(),"\"addrArea\":\"(.*?)\",",1),"西湖区","校验addrArea失败"); String order = "orders_0593";
Assert.assertEquals(MatcherString.getString(queryResponse.asString(),"\"addrDetail\":\"(.*?)\",",1),"数娱大厦","校验addrDetail失败");
Assert.assertEquals(MatcherString.getString(queryResponse.asString(),"\"actualPay\":\"(.*?)\"}",1),"20积分","校验actualPay失败"); Map<String,Object> mapOrder = jdbc.findSimpleResult("SELECT * FROM orders_consumer."+order+" where id="+orderId);
String flowwork_stage = String.valueOf(mapOrder.get("flowwork_stage"));
Assert.assertTrue(flowwork_stage.equals("SupplierExchange-started"),"订单状态校验失败");
// Thread.sleep(8000); // Thread.sleep(8000);
Map<String,Object> itemStockResult1 = jdbc.findSimpleResult("select * from stock.tb_stock where stock_id in (select stock_id from goods.app_item where id = ?)\n","167880"); Map<String,Object> itemStockResult1 = jdbc.findSimpleResult("select * from stock.tb_stock where stock_id in (select stock_id from goods.app_item where id = ?)\n","167880");
String itemStock1 = itemStockResult.get("stock").toString(); String itemStock1 = itemStockResult1.get("stock").toString();
// Assert.assertEquals(itemStock1,String.valueOf(itemStock-1),"校验库存失败"); Assert.assertEquals(itemStock1,String.valueOf(itemStock-1),"校验库存失败");
//清理take_order_queue_record表数据,防止连续兑换报错 //清理take_order_queue_record表数据,防止连续兑换报错
Boolean tearResult = jdbc.update("delete from credits_dev.take_order_queue_record where queue_id = ?",queueId); Boolean tearResult = jdbc.update("delete from credits_dev.take_order_queue_record where queue_id = ?",queueId);
......
...@@ -19,6 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -19,6 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import utils.CheckPublic;
import utils.MatcherString; import utils.MatcherString;
import java.util.Map; import java.util.Map;
...@@ -30,7 +31,7 @@ import java.util.Map; ...@@ -30,7 +31,7 @@ import java.util.Map;
* @create 2018/5/31 * @create 2018/5/31
* @since 1.0.0 * @since 1.0.0
*/ */
public class 自有_虚拟商品秒杀商品兑换测试 extends DuibaTestBase { public class 自有_虚拟商品秒杀商品兑换测试_SeckillTest extends DuibaTestBase {
@Autowired @Autowired
...@@ -49,6 +50,12 @@ public class 自有_虚拟商品秒杀商品兑换测试 extends DuibaTestBase { ...@@ -49,6 +50,12 @@ public class 自有_虚拟商品秒杀商品兑换测试 extends DuibaTestBase {
try { try {
Map<String,Object> mapuser = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid_Nomal);
String dafuwengCredits = String.valueOf(mapuser.get("credits"));
logger.info("兑换前dafuweng积分:"+dafuwengCredits);
dafuwengCredits = String.valueOf(Long.valueOf(dafuwengCredits)-2);
Map<String,Object> itemStockResult = jdbc.findSimpleResult("select * from stock.tb_stock where stock_id in (select stock_id from goods.app_item where id = ?)\n","178072"); Map<String,Object> itemStockResult = jdbc.findSimpleResult("select * from stock.tb_stock where stock_id in (select stock_id from goods.app_item where id = ?)\n","178072");
Long itemStock = Long.parseLong(itemStockResult.get("stock").toString()); Long itemStock = Long.parseLong(itemStockResult.get("stock").toString());
...@@ -77,26 +84,28 @@ public class 自有_虚拟商品秒杀商品兑换测试 extends DuibaTestBase { ...@@ -77,26 +84,28 @@ public class 自有_虚拟商品秒杀商品兑换测试 extends DuibaTestBase {
logger.info("exchangeStatusText="+MatcherString.getString(queryResponse.asString(),"\"exchangeStatusText\":\"(.*?)\",",1)+";type="+MatcherString.getString(queryResponse.asString(),"\"type\":\"(.*?)\",",1)); logger.info("exchangeStatusText="+MatcherString.getString(queryResponse.asString(),"\"exchangeStatusText\":\"(.*?)\",",1)+";type="+MatcherString.getString(queryResponse.asString(),"\"type\":\"(.*?)\",",1));
Assert.assertEquals(String.valueOf(queryResponse.getStatusCode()),"200","校验响应状态码失败"); Assert.assertEquals(String.valueOf(queryResponse.getStatusCode()),"200","校验响应状态码失败");
logger.info("queueId="+queueId+",queryResponse的信息为"+ JSON.toJSONString(queryResponse)); logger.info("queueId="+queueId+",queryResponse的信息为"+ JSON.toJSONString(queryResponse));
Assert.assertEquals(MatcherString.getString(queryResponse.asString(),"\"exchangeStatus\":\"(.*?)\",",1),"success","校验exchangeStatus失败");
Assert.assertEquals(MatcherString.getString(queryResponse.asString(),"\"exchangeStatusText\":\"(.*?)\",",1),"兑换成功","校验exchangeStatusText失败"); String orderId = MatcherString.getString(queryResponse.asString(),"orderId: '(.*?)'",1);
Assert.assertEquals(MatcherString.getString(queryResponse.asString(),"\"type\":\"(.*?)\",",1),"virtual","校验type失败");
Assert.assertEquals(MatcherString.getString(queryResponse.asString(),"\"exchangeSucDesc\":\"(.*?)\",",1),"【勿动】秒杀虚拟商品","校验exchangeSucDesc失败");
Assert.assertEquals(MatcherString.getString(queryResponse.asString(),"\"actualPay\":\"(.*?)\"}",1),"2积分","校验actualPay失败");
String orderId = MatcherString.getString(queryResponse.asString(),"\"orderId\":\"(.*?)\",",1);
// Thread.sleep(8000);
Map<String,Object> itemStockResult1 = jdbc.findSimpleResult("select * from stock.tb_stock where stock_id in (select stock_id from goods.app_item where id = ?)\n","178072"); Map<String,Object> itemStockResult1 = jdbc.findSimpleResult("select * from stock.tb_stock where stock_id in (select stock_id from goods.app_item where id = ?)\n","178072");
String itemStock1 = itemStockResult.get("stock").toString(); String itemStock1 = itemStockResult1.get("stock").toString();
// Assert.assertEquals(itemStock1,String.valueOf(itemStock-1),"校验库存失败");
Assert.assertEquals(itemStock1,String.valueOf(itemStock-1),"校验库存失败");
mapuser = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid_Nomal);
String creditsNew = String.valueOf(mapuser.get("credits"));
logger.info("兑换后dafuweng积分:"+creditsNew);
//校验比较,兑换前后积分
Assert.assertEquals(dafuwengCredits,creditsNew);
logger.info("校验dafuweng兑换前后积分正确");
String order = "orders_0594";
Map<String,Object> res = jdbc.findSimpleResult("select * from orders_consumer.orders_0594 where id = ?\n",orderId); Map<String,Object> mapOrder = jdbc.findSimpleResult("SELECT * FROM orders_consumer."+order+" where id="+orderId);
logger.info("数据库订单信息为"+ JSONObject.toJSONString(res)); String status = String.valueOf(mapOrder.get("status"));
Assert.assertEquals(res.get("status"),"success","校验订单状态失败");
Assert.assertEquals(res.get("type"),"virtual","中奖奖品类型失败");
Assert.assertEquals(res.get("brief"),"【勿动】秒杀虚拟商品","brief校验失败");
// Assert.assertEquals(res.get("biz_params"),"qwjTest","校验虚拟商品标识符失败"); Assert.assertTrue(status.equals("success"),"订单状态校验失败");
//清理take_order_queue_record表数据,防止连续兑换报错 //清理take_order_queue_record表数据,防止连续兑换报错
Boolean tearResult = jdbc.update("delete from credits_dev.take_order_queue_record where queue_id = ?",queueId); Boolean tearResult = jdbc.update("delete from credits_dev.take_order_queue_record where queue_id = ?",queueId);
......
...@@ -170,6 +170,33 @@ public class CouponExchangeService { ...@@ -170,6 +170,33 @@ public class CouponExchangeService {
} }
public Response phonebillExchange(Map cookies,String appItemId,String itemId,String degreeId) throws Exception {
Map<String,String> map = new HashMap<>();
map.put("appItemId",appItemId);
map.put("itemId",itemId);
map.put("token","yrJRr7Cddp2YeQd");
map.put("degreeId",degreeId);
map.put("phone","18012341234");
map.put("phoneCatName","中国电信");
map.put("phoneProvince","江苏");
map.put("type","phonebillDingzhi");
logger.info("请求/phonebillExchange/exchange接口");
Response response = given().contentType("application/x-www-form-urlencoded;charset=UTF-8").cookies(cookies).params(map).post("http://"+goodsHost+"/phonebillExchange/exchange");//phonebillExchange
// response.prettyPrint();
try{
Assert.assertEquals(response.jsonPath().getString("success"),"true");
}catch(Exception e){
throw new Exception("/phonebillExchange/exchange接口返回异常,返回信息:"+response.asString());
}catch(Error er){
throw new Exception("/phonebillExchange/exchange接口返回异常,返回信息:"+response.asString());
}
return response;
}
//流量兑换 //流量兑换
public Response phoneflowExchange(Map cookies,String degreeId,String itemId,String phone,String phoneCatName,String phoneProvince) throws Exception { public Response phoneflowExchange(Map cookies,String degreeId,String itemId,String phone,String phoneCatName,String phoneProvince) throws Exception {
Map<String,String> map = new HashMap<>(); Map<String,String> map = new HashMap<>();
......
package http.service.app;
import http.service.Authorization;
import io.restassured.response.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.testng.Assert;
import java.util.HashMap;
import java.util.Map;
import static io.restassured.RestAssured.given;
/**
* Created by mabo on 2019/3/5
*/
@Service
public class MoveBrickService {
@Value("${activity.host}")
private String activityHost;
@Autowired
Authorization authorization;
//优惠券使用按钮
public Response exchange(int uid, String brickConfigId) throws Exception {
Map<String,String> map = new HashMap<>();
map.put("brickConfigId",brickConfigId);
Response response = given().cookies(authorization.dafuwengLogin(uid)).params(map).post(activityHost+"/aaw/movebrick/exchange");
try {
Assert.assertEquals(String.valueOf(response.getStatusCode()), "200", "/aaw/movebrick/exchange接口失败");
} catch (Exception e) {
throw new Exception("/aaw/movebrick/exchange接口失败,返回信息:" + response.asString());
} catch (Error er) {
throw new Exception("/aaw/movebrick/exchange接口失败,返回信息:" + response.asString());
}
return response;
}
}
...@@ -40,12 +40,10 @@ public class 优惠券_Activity_ui extends DuibaBaseUi{ ...@@ -40,12 +40,10 @@ public class 优惠券_Activity_ui extends DuibaBaseUi{
Assert.assertTrue(isExistByText("ui自动化-优惠券(活动)")); Assert.assertTrue(isExistByText("ui自动化-优惠券(活动)"));
Assert.assertTrue(isExistByText("券码:")); Assert.assertTrue(isExistByText("卡号:"));
Assert.assertTrue(isExistByText("1111111")); Assert.assertTrue(isExistByText("1111111"));
Assert.assertTrue(isExistByText("密码:")); Assert.assertTrue(isExistByText("密码:"));
Assert.assertTrue(isExistByText("22222222")); Assert.assertTrue(isExistByText("22222222"));
Assert.assertTrue(isExistByText("\n" +
" ui自动化-优惠券-使用说明"),"没有商品详情文本");
} }
......
...@@ -28,12 +28,12 @@ public class 实物_Activity_ui extends DuibaBaseUi{ ...@@ -28,12 +28,12 @@ public class 实物_Activity_ui extends DuibaBaseUi{
screenshot(); screenshot();
Assert.assertTrue(isExistByText("收货人:uitest  "),"出奖弹层校验失败"); Assert.assertTrue(isExistByText("uitest"),"出奖弹层校验失败");
Assert.assertTrue(isExistByText("13111133322"),"出奖弹层校验失败");//北京市北京市东城区东华门街道test Assert.assertTrue(isExistByText("13111133322"),"出奖弹层校验失败");//北京市北京市东城区东华门街道test
Assert.assertTrue(isExistByText("北京市北京市东城区东华门街道test "),"出奖弹层校验失败"); Assert.assertTrue(isExistByText("北京市北京市东城区东华门街道test "),"出奖弹层校验失败");
Assert.assertTrue(isExistByText("待发货"),"出奖弹层校验失败"); Assert.assertTrue(isExistByText("\n" +
Assert.assertTrue(isExistByText("ui自动化-实物(活动)"),"出奖弹层校验失败"); "\t\t\t\t\t\t\tui自动化-实物(活动)\n" +
Assert.assertTrue(isExistByText("订单来源:抽奖"),"出奖弹层校验失败"); "\t\t\t\t\t\t"),"出奖弹层校验失败");
} }
} }
...@@ -26,11 +26,11 @@ public class 首页插件_Plugin_ui extends DuibaBaseUi{ ...@@ -26,11 +26,11 @@ public class 首页插件_Plugin_ui extends DuibaBaseUi{
sleep(2); sleep(2);
screenshot(); screenshot();
Assert.assertTrue(isExistByText("ui自动化-优惠券(活动)")); Assert.assertTrue(isExistByText("ui自动化-优惠券(活动)"));
Assert.assertTrue(isExistByText("券码:")); Assert.assertTrue(isExistByText("交易成功"));
Assert.assertTrue(isExistByText("卡号:"));
Assert.assertTrue(isExistByText("1111111")); Assert.assertTrue(isExistByText("1111111"));
Assert.assertTrue(isExistByText("密码:")); Assert.assertTrue(isExistByText("密码:"));
Assert.assertTrue(isExistByText("22222222")); Assert.assertTrue(isExistByText("22222222"));
Assert.assertTrue(isExistByText("商品详情"),"没有商品详情文本");
} }
......
package utils;
import base.DuibaLog;
import base.MysqlConnPool;
import org.testng.Assert;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
/**
* Created by mabo on 2019/3/4
*/
public class CheckPublic {
private static DuibaLog logger = DuibaLog.getLogger();
/**
*
* @param jdbc
* @param database cid/1000
* @param uid
* @param credits
* @return
* @throws SQLException
*/
public static Map<String,String> beforeGet(MysqlConnPool jdbc,String database,String uid,int credits) throws SQLException {
Map<String,Object> mapuser = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid);
String dafuwengCredits = String.valueOf(mapuser.get("credits"));
logger.info("兑换前dafuweng积分:"+dafuwengCredits);
dafuwengCredits = String.valueOf(Long.valueOf(dafuwengCredits)-credits);
mapuser = jdbc.findSimpleResult("select * from new_consumer."+database+" where partner_user_id="+uid);
String consumerCredits = String.valueOf(mapuser.get("credits"));
logger.info("兑换前consumer积分:"+consumerCredits);
consumerCredits = String.valueOf(Long.valueOf(consumerCredits)-credits);
Map<String,String> map = new HashMap<>();
map.put("dafuwengCredits",dafuwengCredits);
map.put("consumerCredits",consumerCredits);
map.put("database",database);
map.put("uid",uid);
return map;
}
public static void afterAssert(Map<String,String> map,MysqlConnPool jdbc,String order,String orderId) throws SQLException {
Map<String,Object> mapuser = jdbc.findSimpleResult("select * from dafuweng.user where id="+map.get("uid"));
String creditsNew = String.valueOf(mapuser.get("credits"));
logger.info("兑换后dafuweng积分:"+creditsNew);
//校验比较,兑换前后积分
Assert.assertEquals(map.get("dafuwengCredits"),creditsNew);
logger.info("校验dafuweng兑换前后积分正确");
mapuser = jdbc.findSimpleResult("select * from new_consumer."+map.get("database")+" where partner_user_id="+map.get("uid"));
String creditsNews = String.valueOf(mapuser.get("credits"));
logger.info("兑换后consumer积分:"+creditsNews);
//校验比较,兑换前后积分
Assert.assertEquals(map.get("consumerCredits"),creditsNews);
logger.info("校验consumer兑换前后积分正确");
if(order!=null&&order.length()!=0){
Map<String,Object> mapOrder = jdbc.findSimpleResult("SELECT * FROM orders_consumer."+order+" where id="+orderId);
String status = String.valueOf(mapOrder.get("status"));
Assert.assertTrue(status.equals("success"),"订单状态校验失败");
}
}
}
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