Commit 13d49538 authored by wangxiaoshuang's avatar wangxiaoshuang

wxs

parent 32fa9d8c
package http.cases.SeckillTest.新秒杀;
import base.DuibaTestBase;
import cn.com.duiba.wolf.utils.DateUtils;
import http.service.Authorization;
import http.service.app.MobileService;
import http.service.app.SeckillNewService;
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 utils.MatcherString;
import java.sql.SQLException;
import java.util.Date;
public class 秒杀商品_自有新优惠券兑换 extends DuibaTestBase {
@Autowired
SeckillNewService seckillNewService;
@Autowired
MobileService mobileService;
@Autowired
Authorization authorization;
//指定用户
private static int uid = 6926;
//单次循环的起始时间
Date date=new Date();
String starttime = DateUtils.getDayStr(date) + " 08:59:59";
String endtiem = DateUtils.getDayStr(date) + " 23:59:59";
@BeforeMethod
public void beforeMethod(){
try {
//秒杀
// jdbc.update("UPDATE tb_stock set stock = 100 where stock_id = 965636062781920123");//每次设置商品库存,防止售罄无法兑换
// jdbc.update("UPDATE tb_seckill_act_sku_data set sec_limit = 9999 where act_id = 25 and id = 14");//每次设置活动秒杀上限数,防止兑换达到上限无法兑换
// jdbc.update("UPDATE seckill.tb_seckill_act_conf set gmt_start = '"+starttime+"', gmt_end = '"+endtiem+"' WHERE id = 25 and app_id =22563 and app_item_id=195538");
//秒杀限制
jdbc.update("UPDATE seckill.tb_seckill_act_conf set gmt_start = '"+starttime+"', gmt_end = '"+endtiem+"' WHERE id = 17 and app_id =22563 and app_item_id=195468");
//sku上限
jdbc.update("UPDATE seckill.tb_seckill_act_conf set gmt_start = '"+starttime+"', gmt_end = '"+endtiem+"' WHERE id = 19 and app_id =22563 and app_item_id=195533");
//商品售罄
jdbc.update("UPDATE seckill.tb_seckill_act_conf set gmt_start = '"+starttime+"', gmt_end = '"+endtiem+"' WHERE id = 20 and app_id =22563 and app_item_id=195534");
} catch (SQLException e) {
e.printStackTrace();
}
}
@Test(description = "优惠券正常秒杀")
public void 优惠券秒杀() throws Exception{
String appItemId="195538";
String itemId=null;
String skuId = "124";
String message = "";
String actId = "25";
String pageId = "63";
//秒杀
Response response = seckillNewService.exchange(itemId,appItemId,uid,skuId,actId);
String orderId = response.jsonPath().getString("data.orderId");
response = seckillNewService.orderStatus(orderId,uid);
String status = response.jsonPath().getString("data.status");
String payCreditsStatus = response.jsonPath().getString("data.payCreditsStatus");
int i = 10;
//异步接口,直到兑换成功
while (i> 0 && status.equals("processing")) {
Thread.sleep(1000);
response = seckillNewService.orderStatus(orderId,uid);
response.prettyPrint();
status = response.jsonPath().getString("data.status");
i--;
}
//校验成功
if(status.equals("wait_delivery")){
Assert.assertEquals(status,"wait_delivery","校验轮询结果status失败");
Assert.assertEquals(payCreditsStatus,"1","校验轮询结果payCreditsStatus失败");
}
else if(status.equals("success")) {
Assert.assertEquals(status,"success","校验轮询结果status失败");
Assert.assertEquals(payCreditsStatus,"1","校验轮询结果payCreditsStatus失败");
}
logger.info("校验秒杀商品--秒杀成功");
}
@Test(description = "优惠券商品售罄")
public void 优惠券商品售罄() throws Exception{
String appItemId="195534";
String itemId=null;
String message = "";
String actId = "20";
String skuId = "120";
String pageId = "63";
//查询商品详情页按钮
Response detailResponse = seckillNewService.detail(actId,pageId,uid);
String remaining = MatcherString.getString(detailResponse.asString(), "\"remaining\":(.*?),", 1);
// logger.info("商品兑换按钮返回值:" + remaining);
Response response=null;
String orderId="";
try{
//秒杀下单
response = seckillNewService.exchange(itemId,appItemId,uid,skuId,actId);
orderId= response.jsonPath().getString("data.orderId");
}catch (Exception e){
message = e.toString();
}
Thread.sleep(1000);
Response resultres= seckillNewService.payResult(orderId,uid);
String failedReason = resultres.jsonPath().getString("data.failedReason");
String result = resultres.jsonPath().getString("data.result");
//数据校验
Assert.assertEquals(remaining,"0","校验兑换按钮失败");
Assert.assertEquals(failedReason,"兑换劵已经用完","校验兑换按钮失败");
Assert.assertEquals(result,"3","校验兑换按钮失败");
logger.info("校验秒杀商品--售罄成功");
}
@Test(description = "优惠券sku已达上限数")
public void sku已达上限数() throws Exception{
String appItemId="195533";
String itemId=null;
String message = "";
String actId = "19";
String skuId = "119";
String pageId = "63";
//查询商品详情页按钮
Response detailResponse = seckillNewService.detail(actId,pageId,uid);
String secRemaining = MatcherString.getString(detailResponse.asString(), "\"secRemaining\":(.*?),", 1);
logger.info("商品兑换按钮:" + secRemaining);
Response response=null;
try{
//秒杀下单
response = seckillNewService.exchange(itemId,appItemId,uid,skuId,actId);
}catch (Exception e){
message = e.toString();
}
String msg = response.jsonPath().getString("msg");
Assert.assertEquals(msg,"已秒光","校验兑换按钮失败");
Assert.assertEquals(secRemaining,"0","校验兑换按钮失败");
logger.info("校验秒杀商品--sku已达购买上限成功");
}
@Test(description = "优惠券秒杀限购")
public void 优惠券秒杀限购() throws Exception{
String appItemId="195468";
String itemId=null;
String message = "";
String skuId = "117";
String actId = "17";
String pageId = "63";
//查询商品详情页按钮
Response detailResponse = seckillNewService.queryBtnStatus(appItemId,actId,pageId,uid);
String exchangeText = detailResponse.jsonPath().getString("data.seckillBtnVO.exchangeBtnVO.exchangeText");
logger.info("商品兑换按钮:" + exchangeText);
Response response=null;
try{
//秒杀兑换
response = seckillNewService.exchange(itemId,appItemId,uid,skuId,actId);
response.prettyPrint();
}catch (Exception e){
message = e.toString();
}
String msg = response.jsonPath().getString("msg");
Assert.assertEquals(msg,"已达单人限购上限","校验兑换按钮失败");
Assert.assertEquals(exchangeText,"已达购买上限","校验兑换按钮失败");
logger.info("校验秒杀商品--限购设置--达到上限成功");
}
}
package http.cases.SeckillTest.新秒杀;
import base.DuibaTestBase;
import cn.com.duiba.wolf.utils.DateUtils;
import http.service.Authorization;
import http.service.app.MobileService;
import http.service.app.SeckillNewService;
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 utils.MatcherString;
import java.sql.SQLException;
import java.util.Date;
public class 秒杀商品_自有新商家充值兑换 extends DuibaTestBase {
@Autowired
SeckillNewService seckillNewService;
@Autowired
MobileService mobileService;
@Autowired
Authorization authorization;
//指定用户
private static int uid = 6926;
//单次循环的起始时间
Date date=new Date();
String starttime = DateUtils.getDayStr(date) + " 08:59:59";
String endtiem = DateUtils.getDayStr(date) + " 23:59:59";
@BeforeMethod
public void beforeMethod(){
try {
//正常秒杀
// jdbc.update("UPDATE tb_stock set stock = 100 where stock_id = 965636062781920123");//每次设置商品库存,防止售罄无法兑换
// jdbc.update("UPDATE tb_seckill_act_sku_data set sec_limit = 9999 where act_id = 26 and id = 15");//每次设置活动秒杀上限数,防止兑换达到上限无法兑换
// jdbc.update("UPDATE seckill.tb_seckill_act_conf set gmt_start = '"+starttime+"', gmt_end = '"+endtiem+"' WHERE id = 26 and app_id =22563 and app_item_id=195539");
//秒杀限制
jdbc.update("UPDATE seckill.tb_seckill_act_conf set gmt_start = '"+starttime+"', gmt_end = '"+endtiem+"' WHERE id = 23 and app_id =22563 and app_item_id=195536");
//sku上限
jdbc.update("UPDATE seckill.tb_seckill_act_conf set gmt_start = '"+starttime+"', gmt_end = '"+endtiem+"' WHERE id = 22 and app_id =22563 and app_item_id=195535");
//商品售罄
jdbc.update("UPDATE seckill.tb_seckill_act_conf set gmt_start = '"+starttime+"', gmt_end = '"+endtiem+"' WHERE id = 21 and app_id =22563 and app_item_id=195532");
} catch (SQLException e) {
e.printStackTrace();
}
}
@Test(description = "商家充值正常秒杀")
public void 商家充值秒杀() throws Exception{
String appItemId="195539";
String itemId=null;
String skuId = "125";
String message = "";
String actId = "26";
String pageId = "63";
//秒杀
Response response = seckillNewService.exchange(itemId,appItemId,uid,skuId,actId);
String orderId = response.jsonPath().getString("data.orderId");
response = seckillNewService.orderStatus(orderId,uid);
String status = response.jsonPath().getString("data.status");
String payCreditsStatus = response.jsonPath().getString("data.payCreditsStatus");
int i = 10;
//异步接口,直到兑换成功
while (i> 0 && status.equals("processing")) {
Thread.sleep(1000);
response = seckillNewService.orderStatus(orderId,uid);
response.prettyPrint();
status = response.jsonPath().getString("data.status");
i--;
}
//校验成功
Assert.assertEquals(status,"wait_delivery","校验轮询结果status失败");
Assert.assertEquals(payCreditsStatus,"1","校验轮询结果payCreditsStatus失败");
logger.info("校验秒杀商品--秒杀成功");
}
@Test(description = "商家充值商品售罄")
public void 商家充值商品售罄() throws Exception{
String appItemId="195532";
String itemId=null;
String message = "";
String actId = "21";
String skuId = "118";
String pageId = "63";
//查询商品详情页按钮
Response detailResponse = seckillNewService.detail(actId,pageId,uid);
String remaining = MatcherString.getString(detailResponse.asString(), "\"remaining\":(.*?),", 1);
// logger.info("商品兑换按钮返回值:" + remaining);
Response response=null;
String orderId="";
try{
//秒杀下单
response = seckillNewService.exchange(itemId,appItemId,uid,skuId,actId);
orderId= response.jsonPath().getString("data.orderId");
}catch (Exception e){
message = e.toString();
}
Thread.sleep(1000);
Response resultres= seckillNewService.payResult(orderId,uid);
String failedReason = resultres.jsonPath().getString("data.failedReason");
String result = resultres.jsonPath().getString("data.result");
//数据校验
Assert.assertEquals(remaining,"0","校验兑换按钮失败");
Assert.assertEquals(failedReason,"库存不足","校验兑换按钮失败");
Assert.assertEquals(result,"3","校验兑换按钮失败");
logger.info("校验秒杀商品--售罄成功");
}
@Test(description = "商家充值sku已达上限数")
public void 商家充值sku已达上限数() throws Exception{
String appItemId="195535";
String itemId=null;
String message = "";
String actId = "22";
String skuId = "121";
String pageId = "63";
//查询商品详情页按钮
Response detailResponse = seckillNewService.detail(actId,pageId,uid);
String secRemaining = MatcherString.getString(detailResponse.asString(), "\"secRemaining\":(.*?),", 1);
logger.info("商品兑换按钮:" + secRemaining);
Response response=null;
try{
//秒杀下单
response = seckillNewService.exchange(itemId,appItemId,uid,skuId,actId);
}catch (Exception e){
message = e.toString();
}
String msg = response.jsonPath().getString("msg");
Assert.assertEquals(msg,"已秒光","校验兑换按钮失败");
Assert.assertEquals(secRemaining,"0","校验兑换按钮失败");
logger.info("校验秒杀商品--sku已达购买上限成功");
}
@Test(description = "商家充值秒杀限购")
public void 商家充值秒杀限购() throws Exception{
String appItemId="195536";
String itemId=null;
String message = "";
String skuId = "122";
String actId = "23";
String pageId = "63";
//查询商品详情页按钮
Response detailResponse = seckillNewService.queryBtnStatus(appItemId,actId,pageId,uid);
String exchangeText = detailResponse.jsonPath().getString("data.seckillBtnVO.exchangeBtnVO.exchangeText");
logger.info("商品兑换按钮:" + exchangeText);
Response response=null;
try{
//秒杀兑换
response = seckillNewService.exchange(itemId,appItemId,uid,skuId,actId);
response.prettyPrint();
}catch (Exception e){
message = e.toString();
}
String msg = response.jsonPath().getString("msg");
Assert.assertEquals(msg,"已达单人限购上限","校验兑换按钮失败");
Assert.assertEquals(exchangeText,"已达购买上限","校验兑换按钮失败");
logger.info("校验秒杀商品--限购设置--达到上限成功");
}
}
package http.cases.SeckillTest.新秒杀;
import base.DuibaTestBase;
import cn.com.duiba.wolf.utils.DateUtils;
import http.service.Authorization;
import http.service.app.MobileService;
import http.service.app.SeckillNewService;
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 utils.MatcherString;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class 秒杀商品_自有新实物兑换 extends DuibaTestBase {
@Autowired
SeckillNewService seckillNewService;
@Autowired
MobileService mobileService;
@Autowired
Authorization authorization;
//指定用户
private static int uid = 6926;
//单次循环的起始时间
Date date=new Date();
String starttime = DateUtils.getDayStr(date) + " 08:59:59";
String endtiem = DateUtils.getDayStr(date) + " 23:59:59";
@BeforeMethod
public void beforeMethod(){
try {
//正常秒杀
jdbc.update("UPDATE tb_stock set stock = 100 where stock_id = 965636062781920123");//每次设置商品库存,防止售罄无法兑换
jdbc.update("UPDATE tb_seckill_act_sku_data set sec_limit = 9999 where act_id = 24 and id = 13");//每次设置活动秒杀上限数,防止兑换达到上限无法兑换
jdbc.update("UPDATE seckill.tb_seckill_act_conf set gmt_start = '"+starttime+"', gmt_end = '"+endtiem+"' WHERE id = 13 and app_id =22563 and app_item_id=195537");
//秒杀限制
jdbc.update("UPDATE seckill.tb_seckill_act_conf set gmt_start = '"+starttime+"', gmt_end = '"+endtiem+"' WHERE id = 13 and app_id =22563 and app_item_id=195387");
//sku上限
jdbc.update("UPDATE seckill.tb_seckill_act_conf set gmt_start = '"+starttime+"', gmt_end = '"+endtiem+"' WHERE id = 14 and app_id =22563 and app_item_id=195385");
//商品售罄
jdbc.update("UPDATE seckill.tb_seckill_act_conf set gmt_start = '"+starttime+"', gmt_end = '"+endtiem+"' WHERE id = 15 and app_id =22563 and app_item_id=195410");
} catch (SQLException e) {
e.printStackTrace();
}
}
@Test(description = "实物正常秒杀")
public void 实物秒杀() throws Exception{
String appItemId="195537";
String itemId=null;
String skuId = "123";
String message = "";
String actId = "24";
String pageId = "63";
//秒杀
Response response = seckillNewService.exchange(itemId,appItemId,uid,skuId,actId);
String orderId = response.jsonPath().getString("data.orderId");
response = seckillNewService.orderStatus(orderId,uid);
String status = response.jsonPath().getString("data.status");
String payCreditsStatus = response.jsonPath().getString("data.payCreditsStatus");
int i = 10;
//异步接口,直到兑换成功
while (i> 0 && status.equals("processing")) {
Thread.sleep(1000);
response = seckillNewService.orderStatus(orderId,uid);
response.prettyPrint();
status = response.jsonPath().getString("data.status");
i--;
}
//校验成功
Assert.assertEquals(status,"wait_delivery","校验轮询结果status失败");
Assert.assertEquals(payCreditsStatus,"1","校验轮询结果payCreditsStatus失败");
logger.info("校验秒杀商品--秒杀成功");
}
@Test(description = "实物秒杀限购")
public void 实物秒杀限购() throws Exception{
String appItemId="195387";
String itemId=null;
String message = "";
String skuId = "114";
String actId = "13";
String pageId = "63";
//查询商品详情页按钮
Response detailResponse = seckillNewService.queryBtnStatus(appItemId,actId,pageId,uid);
String exchangeText = detailResponse.jsonPath().getString("data.seckillBtnVO.exchangeBtnVO.exchangeText");
logger.info("商品兑换按钮:" + exchangeText);
Response response=null;
try{
//秒杀兑换
response = seckillNewService.exchange(itemId,appItemId,uid,skuId,actId);
response.prettyPrint();
}catch (Exception e){
message = e.toString();
}
String msg = response.jsonPath().getString("msg");
Assert.assertEquals(msg,"已达单人限购上限","校验兑换按钮失败");
Assert.assertEquals(exchangeText,"已达购买上限","校验兑换按钮失败");
logger.info("校验秒杀商品--限购设置--达到上限成功");
}
@Test(description = "实物sku已达上限数")
public void 实物sku已达上限数() throws Exception{
String appItemId="195385";
String itemId=null;
String message = "";
String actId = "14";
String skuId = "112";
String pageId = "63";
//查询商品详情页按钮
Response detailResponse = seckillNewService.detail(actId,pageId,uid);
String secRemaining = MatcherString.getString(detailResponse.asString(), "\"secRemaining\":(.*?),", 1);
logger.info("商品兑换按钮:" + secRemaining);
Response response=null;
try{
//秒杀下单
response = seckillNewService.exchange(itemId,appItemId,uid,skuId,actId);
}catch (Exception e){
message = e.toString();
}
String msg = response.jsonPath().getString("msg");
Assert.assertEquals(msg,"已秒光","校验兑换按钮失败");
Assert.assertEquals(secRemaining,"0","校验兑换按钮失败");
logger.info("校验秒杀商品--sku已达购买上限成功");
}
@Test(description = "实物商品售罄")
public void 实物商品售罄() throws Exception{
String appItemId="195410";
String itemId=null;
String message = "";
String actId = "15";
String skuId = "116";
String pageId = "63";
//查询商品详情页按钮
Response detailResponse = seckillNewService.detail(actId,pageId,uid);
String remaining = MatcherString.getString(detailResponse.asString(), "\"remaining\":(.*?),", 1);
// logger.info("商品兑换按钮返回值:" + remaining);
Response response=null;
String orderId="";
try{
//秒杀下单
response = seckillNewService.exchange(itemId,appItemId,uid,skuId,actId);
orderId= response.jsonPath().getString("data.orderId");
}catch (Exception e){
message = e.toString();
}
//兑换结果接口
Thread.sleep(1000);
Response resultres= seckillNewService.payResult(orderId,uid);
String failedReason = resultres.jsonPath().getString("data.failedReason");
String result = resultres.jsonPath().getString("data.result");
//数据校验
Assert.assertEquals(remaining,"0","校验兑换按钮失败");
Assert.assertEquals(failedReason,"库存不足","校验兑换按钮失败");
Assert.assertEquals(result,"3","校验兑换按钮失败");
logger.info("校验秒杀商品--售罄成功");
}
}
package http.service.app;
import base.DuibaLog;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
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.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static io.restassured.RestAssured.given;
@Service
public class SeckillNewService {
@Value("${seckill.host}")
private String seckillHost;
@Value("${home.host}")
private String homeHost;
@Value("${activity.host}")
String activityHost;
@Autowired
Authorization authorization;
private static DuibaLog logger = DuibaLog.getLogger();
//实物秒杀下单接口
public Response exchange (String itemId,String appItemId, Integer uid,String skuId,String actId) throws Exception {
String url = activityHost + "/seckw/v2/exchange";
logger.info("***********"+url);
Map<String,Object> map = new HashMap<>();
Map<String,Object> mapList = new HashMap<>();
List<Map> list = new ArrayList<>();
mapList.put("itemId",itemId);
mapList.put("skuId",skuId);
mapList.put("appItemId",appItemId);
mapList.put("credits","1");
mapList.put("price",0);
list.add(mapList);
map.put("remark","");
map.put("degreeId","");
map.put("actualPrice","0");
map.put("actualCredits","1");
map.put("itemParam",list.toArray());
map.put("payType","3");
map.put("expressPrice","0");
map.put("actId",actId);
map.put("validate","Y6f1ebInCWb.uJg8Sh_F.p7EUq4SG_Spr8ibD.2TTrytcOBpASsIHf6P9zNbkQxRq7vVDPkZw0vaRMpcxkbCx0n1ZKJZQgtFaKfbI0S2X7fws.jz8IjFUIM2l56YTh_g5xCso65S6ivQM0-54iEzTkSC01MIM5ZPoBdKiE9hVyooLa9OIM9oXOi-EtNx.IyxZyOBBqdCiYFieZe_ewBvWHlZ7SfInfFIaS8ulQMqybaSptmqYH9CyIa5nclj5C849IluQPnJH-0qpse7RL729VEtzZrS9KvoXmjCyTc4uq9IMozueqJG9PclV0gB1r8adms7Ef-QVEVSsnVu9xlY2YBAzPvBM9snEb447snvAgAi51CyL1SanGUCVDtmfe7GmronomRkWDvzknJFGm9vHNCWJGuZsJyYYPmlQ8NTrrsMdzwLcUs716uUm7RR1HM4_n9xC_PrGImrMFwnnV1MLlr_UEjITFq1A5_lHigcU7xyK-vE8hdtYDEV57X3");
JSONObject jsonParam = JSONObject.parseObject(JSON.toJSONString(map));
Response response = given().contentType("application/json; charset=UTF-8").cookies(authorization.dafuwengLogin(uid)).body(jsonParam).post(url);
// response.prettyPrint();
return response;
}
//秒杀状态页
public Response queryBtnStatus(String appItemId,String actId,String pageId,Integer uid) {
String url = activityHost + "/seckw/v2/queryBtnStatus";
Map<String,Object> map = new HashMap<>();
map.put("appItemId",appItemId);
map.put("actId",actId);
map.put("pageId",pageId);
Response response = given().cookies(authorization.dafuwengLogin(uid)).params(map).get(url);
// response.prettyPrint();
return response;
}
//秒杀详情页
public Response detail(String actId,String pageId,Integer uid) {
String url = activityHost + "/seckw/v2/detail";
Map<String,Object> map = new HashMap<>();
map.put("actId",actId);
map.put("pageId",pageId);
Response response = given().cookies(authorization.dafuwengLogin(uid)).params(map).get(url);
// response.prettyPrint();
return response;
}
//实物下单后获取状态
public Response orderStatus(String orderId,Integer uid) {
String url = activityHost + "/taw/h5/orderStatus";
Map<String,Object> map = new HashMap<>();
map.put("orderId",orderId);
Response response = given().cookies(authorization.dafuwengLogin(uid)).params(map).get(url);
response.prettyPrint();
return response;
}
//查询结果页面
public Response payResult(String orderId,Integer uid) {
String url = activityHost + "/taw/h5/payResult";
Map<String,Object> map = new HashMap<>();
map.put("orderId",orderId);
Response response = given().cookies(authorization.dafuwengLogin(uid)).params(map).get(url);
// response.prettyPrint();
return response;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment