Commit e74e522e authored by 钱雯君's avatar 钱雯君

add

parent 5842d60f
package http.cases.GameTest;
import com.duiba.qa.duiba.common.DuibaConfig;
import com.duiba.qa.duiba.service.Activity.ManagerService;
import com.duiba.qa.duiba.service.Activity.NgapiService;
import com.duiba.qa.duiba.service.Authorization;
import com.duiba.qa.duiba.service.hd.ActivityService;
import com.duiba.qa.duiba.utils.MatcherString;
import com.duiba.qa.publics.datadriver.ExcelDataProvider;
import com.duiba.qa.publics.util.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.io.IOException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
/**
* Created by zhaoran on 2018/1/9.
* case1:游戏测试:马上使用跳转优惠券链接券码的链接
* case2:游戏测试:马上使用跳转优惠券商家落地页的链接(iOS、Android)
* case3:游戏测试:马上使用跳转优惠券兑换记录页的链接
* case4:游戏测试:马上使用跳转福袋的链接
*/
@ContextConfiguration(classes = DuibaConfig.class)
public class Game_AccessTest extends AbstractTestNGSpringContextTests {
@Autowired
NgapiService ngapiService;
@Autowired
ManagerService managerService;
@Autowired
ActivityService activityService;
@Autowired
Authorization authorization;
@Value("${activity.host}")
String activityHost;
private static DuibaLog logger = DuibaLog.getLogger();
private static final Integer uid = 2708;
@DataProvider(name = "providerMethod")
public Iterator<Object[]> dataShop(Method method) throws IOException {
return new ExcelDataProvider("duiba/游戏优惠券");
}
@Test(dataProvider = "providerMethod")
public void 优惠券测试(Map<String,String> data) throws Exception {
logger.info("-------------------------------------"+data.get("casename")+"-------------------------------------");
//获取管理员后台待校验项
Response ManagerResponse = managerService.CouponConfig(data.get("couponId"));
Response LinkResponse = managerService.ShowCoupons(data.get("couponId"));
String acttitle = MatcherString.getString(ManagerResponse.asString(), "name=\"name\" value=\"(.*?)\">", 1);
String androidDL = MatcherString.getString(ManagerResponse.asString(), "androidurl: '(.*?)',", 1);
String iOSDL = MatcherString.getString(ManagerResponse.asString(), "iosurl: '(.*?)',", 1);
String actusebtn = MatcherString.getString(ManagerResponse.asString(), "usebtn: '(.*?)',", 1);
String actLinkEx = "//activity.m.duibatest.com.cn/crecord/recordDetailNew/";
String linkUrl = MatcherString.getString(LinkResponse.asString(), "target=\"_blank\" href=\"(.*?)\">", 1);
//进行接口测试传参
Response response = this.游戏接口传参(data.get("activityId"),data.get("token"),data.get("device"));
int casenum = Integer.parseInt(data.get("casenum"));
//根据case选择对应的校验项
switch(casenum){
case 1:
Assert.assertEquals(response.jsonPath().getString("option.lottery.iosDownloadUrl"),linkUrl,"校验Url失败");
Assert.assertEquals(response.jsonPath().getString("option.lottery.useBtnText"),actusebtn,"校验useBtnText失败");
logger.info("校验链接券码项:openUrl,useBtnText成功");
break;
case 2:
if ( data.get("device").equals("iOS")) {
Assert.assertEquals(response.jsonPath().getString("option.lottery.iosDownloadUrl"), iOSDL, "校验Url失败");
}else{
Assert.assertEquals(response.jsonPath().getString("option.lottery.androidDownloadUrl"),androidDL,"校验Url失败");
}
Assert.assertEquals(response.jsonPath().getString("option.lottery.useBtnText"),actusebtn,"校验useBtnText失败");
logger.info("校验商家落地项:openUrl,useBtnText成功");
break;
case 3:
Assert.assertTrue(response.jsonPath().getString("option.lottery.iosDownloadUrl").contains(actLinkEx),"兑换记录页url与实际url不匹配");
Assert.assertEquals(response.jsonPath().getString("option.lottery.useBtnText"),"查看使用方法","校验useBtnText失败");
logger.info("校验兑换记录项:openUrl,useBtnText成功");
break;
}
//通用校验项
Assert.assertEquals(response.jsonPath().getString("option.lottery.title"),acttitle,"校验title失败");
logger.info("校验通用项:title成功");
}
@Test(description = "马上使用跳转福袋的链接")
public void 福袋测试() throws Exception {
//进行接口测试传参
Response response = this.游戏接口传参("18572","vdiy2qy","iOS");
Assert.assertEquals(response.jsonPath().getString("option.type"), "lucky", "校验类型失败");
Assert.assertTrue(response.jsonPath().getString("option.lottery.link").contains("//activity.m.duibatest.com.cn/crecord/recordLuckDetailNew?"));
Assert.assertEquals(response.jsonPath().getString("option.lottery.useBtnText"), "马上使用", "校验useBtnText失败");
Assert.assertTrue(response.jsonPath().getString("option.lottery.iosDownloadUrl").contains("activityId=18572"));
Assert.assertTrue(response.jsonPath().getString("option.lottery.iosDownloadUrl").contains("//activity.tuiatest.cn/activity/redirect"));
Assert.assertEquals(response.jsonPath().getString("option.lottery.showUse"), "true", "校验显示按钮失败");
logger.info("校验:link,useBtnText成功");
}
@Test(description = "该游戏已在大富翁app上架可参与")
public void 开发者未上架游戏() {
Map<String,String> map = new HashMap<>();
map.put("id","33487");
map.put("token","to5s8");
logger.info("请求dostart接口,activityId=33487");
Response response = given().cookies(authorization.dafuwengLogin(uid)).params(map).post(activityHost+"/ngapi/dostart");
Assert.assertEquals(response.jsonPath().getString("success"),"false");
Assert.assertEquals(response.jsonPath().getString("message"),"无权访问");
}
public Response 游戏接口传参(String activityId,String token,String device) throws Exception {
Response response = ngapiService.dostart(uid,activityId,token);
//response.prettyPrint();
response.then().body("success", equalTo(true));
String ticketId = response.jsonPath().getString("ticketId");
// String ticketId = MatcherString.getString(response.asString(),"\"ticketId\": \"(.*?)\",",1);
logger.info("请求dostart接口,ticketId="+ticketId);
response = ngapiService.getStartStatus(uid,ticketId);
response.prettyPrint();
String message = String.valueOf(response.jsonPath().getString("message"));
int i= 5;
while(i>0&&(message.equals("处理中"))){
Thread.sleep(1000);
response = ngapiService.getStartStatus(uid,ticketId);
message = String.valueOf(response.jsonPath().getString("message"));
i--;
response.prettyPrint();
}
Assert.assertEquals(response.jsonPath().getString("message"),"处理成功","校验message失败");
response = ngapiService.submit(uid,ticketId,device);
response.prettyPrint();
return response;
}
}
\ No newline at end of file
/**
* Copyright (C), 2015-2018
* FileName: 游戏_不同奖项_AccessTest
* Author: qianwenjun
* Date: 2018/5/13 15:38
* Description:
*/
package http.cases.GameTest;
import base.DuibaLog;
import base.DuibaTestBase;
import http.service.Activity.NewGameService;
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.AfterClass;
import org.testng.annotations.Test;
import utils.MatcherString;
import java.util.Map;
/**
* 〈〉
*
* @author qianwenjun
* @create 2018/5/13
* @since 1.0.0
*/
public class 游戏_中奖优惠券_AccessTest extends DuibaTestBase {
@Autowired
NewGameService newGameService;
private static DuibaLog logger = DuibaLog.getLogger();
private String virtualOrderIds = null;
private static final Integer uid_Nomal = 2708;
private static final String consumerId = "100011623";
@Test
public void 游戏_普通优惠券中奖测试() throws Exception{
try {
//查询游戏前奖项库存信息
Map<String,Object> ngameOptionResult = jdbc.findSimpleResult("select * from ngame.duiba_ngame_options where duiba_game_id = ?\n","1328");
Integer optionId = Integer.parseInt(ngameOptionResult.get("id").toString());
Integer itemId = Integer.parseInt(ngameOptionResult.get("item_id").toString());
//奖项库存
Map<String,Object> ngameStockResult = jdbc.findSimpleResult("select * from ngame.ngame_stock where game_option_id = ?\n",optionId);
Long optionStock = Long.parseLong(ngameStockResult.get("stock").toString());
Map<String,Object> itemStockResult = jdbc.findSimpleResult("select * from stock.tb_stock where stock_id =(select stock_id from goods.tb_goods_batch where gid = ?)",itemId);
Long itemStock = Long.parseLong(itemStockResult.get("stock").toString());
Response response = this.playGame("20178","z0eyz5d3","88",uid_Nomal);
//游戏后的奖项库存
Map<String,Object> ngameStockResult1 = jdbc.findSimpleResult("select * from ngame.ngame_stock where game_option_id = ?\n",optionId);
String optionStock1 = ngameStockResult1.get("stock").toString();
Map<String,Object> itemStockResult1 = jdbc.findSimpleResult("select * from stock.tb_stock where stock_id =(select stock_id from goods.tb_goods_batch where gid = ?)",itemId);
String itemStock1 = itemStockResult1.get("stock").toString();
String type = MatcherString.getString(response.asString(),"\"type\": \"(.*?)\",",1);
logger.info("type = "+type);
Assert.assertEquals(MatcherString.getString(response.asString(),"\"type\": \"(.*?)\"",1),"coupon","奖品type校验失败");
Assert.assertEquals(MatcherString.getString(response.asString(),"\"itemId\": (.*?),",1),String.valueOf(itemId),"奖品itemId校验失败");
Assert.assertEquals(optionStock1,String.valueOf(optionStock-1),"奖项库存校验失败");
Assert.assertTrue(MatcherString.getString(response.asString(),"\"link\": \"(.*?)\",",1).contains("//activity.m.duibatest.com.cn/crecord/recordDetailNew?orderId="));
Assert.assertEquals(MatcherString.getString(response.asString(),"\"useBtnText\": \"(.*?)\",",1),"马上使用","优惠券弹层按钮校验失败");
Assert.assertEquals(itemStock1,String.valueOf(itemStock-1),"商品库存校验失败");
logger.info("校验成功,奖品类型:"+response.jsonPath().getString("data.option.type")+",奖品原库存:"+optionStock+",中奖后奖品库存:"+optionStock1);
logger.info("校验兑换项库存消耗成功,原兑换项库存:"+itemStock+",消耗后的兑换项库存:"+itemStock1);
} catch (Exception e) {
}
}
public Response playGame(String activityId, String token, String score, Integer uid) throws Exception{
String ticketId = null;
Response response =null;
ticketId = doStart(activityId,token,uid);
response = submit(activityId,score,ticketId,uid,response);
return response;
}
public String doStart(String activityId,String token,Integer uid) throws Exception{
Response doStartResponse = newGameService.doStart(activityId,token,uid);
// doStartResponse.prettyPrint();
// int i=8;
// while ((!checkNomal("doStart",doStartResponse))&&i>0){
// Thread.sleep(1000);
// doStartResponse = newGameService.doStart(activityId,token,uid);
// doStartResponse.prettyPrint();
// i--;
// }
// logger.info("doStartResponse的信息为"+ doStartResponse.asString());
String startSuccess = MatcherString.getString(doStartResponse.asString(),"\"success\": (.*?),",1);
String ticketId = MatcherString.getString(doStartResponse.asString(),"\"ticketId\": \"(.*?)\",",1);
Assert.assertEquals(startSuccess,"true","dostart接口执行失败");
Response statusResponse = newGameService.getStartStatus(ticketId,uid);
statusResponse.prettyPrint();
String statusSuccess = MatcherString.getString(statusResponse.asString(),"\"success\": (.*?),",1);
String message = MatcherString.getString(statusResponse.asString(),"\"message\": \"(.*?)\"",1);
int j=8;
while (j>0&&((!checkNomal("getStartStatus",statusResponse))||(message.equals("处理中")))){
Thread.sleep(1000);
statusResponse = newGameService.getStartStatus(ticketId,uid);
statusResponse.prettyPrint();
statusSuccess = MatcherString.getString(statusResponse.asString(),"\"success\": (.*?),",1);
message = MatcherString.getString(statusResponse.asString(),"\"message\": \"(.*?)\"",1);
j--;
}
// logger.info("statusResponse的信息为"+ statusResponse.asString());
Assert.assertEquals(statusSuccess,"true","getStartStatus接口执行失败");
Assert.assertEquals(statusResponse.jsonPath().getString("message"),"处理成功","获取状态成功");
return ticketId;
}
public Response submit(String activityId,String score,String ticketId,Integer uid,Response response) throws Exception{
Response submitResponse = newGameService.submit(ticketId,score,uid);
// submitResponse.prettyPrint();
// int i=8;
// while ((!checkNomal("submit",submitResponse))&&i>0){
// Thread.sleep(1000);
// submitResponse = newGameService.submit(ticketId,score,uid);
// submitResponse.prettyPrint();
// i--;
// }
// logger.info("submitResponse的信息为"+ submitResponse.asString());
// String submitSuccess = MatcherString.getString(submitResponse.asString(),"\"success\": (.*?),",1);
// Assert.assertEquals(submitSuccess,"true","submit接口执行失败");
String orderId = MatcherString.getString(submitResponse.asString(),"\"orderId\": (.*?),",1);
if (activityId.equals("20192")){
virtualOrderIds = orderId;
logger.info("orderIds的信息为"+virtualOrderIds);
}
Response submitResultResponse = newGameService.getSubmitResult(orderId,uid);
// submitResultResponse.prettyPrint();
// int j=8;
// while (j>0&&(!checkNomal("getSubmitResult",submitResultResponse))){
// Thread.sleep(1000);
// submitResultResponse = newGameService.getStartStatus(ticketId,uid);
// submitResultResponse.prettyPrint();
// j--;
// }
// String submitResultSuccess = MatcherString.getString(submitResultResponse.asString(),"\"success\": (.*?),",1);
// Assert.assertEquals(submitResultSuccess,"true","getSubmitResult接口执行失败");
String flag = MatcherString.getString(submitResultResponse.asString(),"\"flag\": (\\D{4})",1);
for(int z=0;z<8;z++){
if ((flag.equals("true"))){
submitResultResponse = newGameService.getSubmitResult(orderId,uid);
submitResultResponse.prettyPrint();
flag = MatcherString.getString(submitResultResponse.asString(),"\"flag\": (\\D{4})",1);
String optionName = MatcherString.getString(submitResultResponse.asString(),"\"name\": \"(.*?)\",",1);
for (int k=0;k<8;k++){
if (optionName.isEmpty()){
submitResultResponse = newGameService.getSubmitResult(orderId,uid);
submitResultResponse.prettyPrint();
optionName = MatcherString.getString(submitResultResponse.asString(),"\"name\": \"(.*?)\",",1);
}
}
}
}
// logger.info("submitResultResponse的信息为"+submitResultResponse.asString());
response=submitResultResponse;
return response;
}
public Boolean checkNomal(String api,Response response) {
Boolean isNomal = false;
String title = MatcherString.getString(response.asString(),"<div class=\"title\">(.*?)</div>",1);
if (title.equals("当前网络貌似出了点问题")){
logger.info(api+"接口调用异常,重新调用"+"错误信息为"+title);
return isNomal;
}else {
isNomal = true;
}
return isNomal;
}
@AfterClass
public void tearDown() {
try {
Boolean result = jdbc.update("update ngame.ngame_consumer_record set auto_open_prize_id = '' where consumer_id = ? and duiba_ngame_id in('1328','1330','1331','1332')\n",consumerId);
} catch (Exception e) {
e.printStackTrace();
}
}
}
\ No newline at end of file
/**
* Copyright (C), 2015-2018
* FileName: 游戏_中奖实物_AccessTest
* Author: qianwenjun
* Date: 2018/6/7 14:10
* Description:
*/
package http.cases.GameTest;
import base.DuibaLog;
import base.DuibaTestBase;
import http.service.Activity.NewGameService;
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.AfterClass;
import org.testng.annotations.Test;
import utils.MatcherString;
import java.util.Map;
/**
* 〈〉
*
* @author qianwenjun
* @create 2018/6/7
* @since 1.0.0
*/
public class 游戏_中奖实物_AccessTest extends DuibaTestBase {
@Autowired
NewGameService newGameService;
private static DuibaLog logger = DuibaLog.getLogger();
private String virtualOrderIds = null;
private static final Integer uid_Nomal = 2708;
private static final String consumerId = "100011623";
@Test
//OK
public void 游戏_实物中奖测试() throws Exception{
try {
//查询游戏前奖项库存信息
Map<String,Object> ngameOptionResult = jdbc.findSimpleResult("select * from ngame.duiba_ngame_options where duiba_game_id = ?\n","1329");
Integer optionId = Integer.parseInt(ngameOptionResult.get("id").toString());
Integer itemId = Integer.parseInt(ngameOptionResult.get("item_id").toString());
//奖项库存
Map<String,Object> ngameStockResult = jdbc.findSimpleResult("select * from ngame.ngame_stock where game_option_id = ?\n",optionId);
Long optionStock = Long.parseLong(ngameStockResult.get("stock").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",itemId);
Long itemStock = Long.parseLong(itemStockResult.get("stock").toString());
Response response = this.playGame("20188","z0eyz5d3","88",uid_Nomal);
//游戏后的奖项库存
Map<String,Object> ngameStockResult1 = jdbc.findSimpleResult("select * from ngame.ngame_stock where game_option_id = ?\n",optionId);
String optionStock1 = ngameStockResult1.get("stock").toString();
Map<String,Object> itemStockResult1 = jdbc.findSimpleResult("select * from stock.tb_stock where stock_id in (select stock_id from goods.item where id = ?)\n",itemId);
String itemStock1 = itemStockResult1.get("stock").toString();
Assert.assertEquals(MatcherString.getString(response.asString(),"\"type\": \"(.*?)\",",1),"object","奖品type校验失败");
Assert.assertEquals(MatcherString.getString(response.asString(),"\"itemId\": (.*?),",1),String.valueOf(itemId),"奖品itemId校验失败");
Assert.assertEquals(optionStock1,String.valueOf(optionStock-1),"奖项库存校验失败");
Assert.assertTrue(MatcherString.getString(response.asString(),"\"link\": \"(.*?)\",",1).contains("//activity.m.duibatest.com.cn/activity/takePrizeNew?recordId="));
Assert.assertEquals(itemStock1,String.valueOf(itemStock-1),"商品库存校验失败");
logger.info("校验成功,奖品类型:"+response.jsonPath().getString("data.option.type")+",奖品原库存:"+optionStock+",中奖后奖品库存:"+optionStock1);
logger.info("校验兑换项库存消耗成功,原兑换项库存:"+itemStock+",消耗后的兑换项库存:"+itemStock1);
} catch (Exception e) {
e.printStackTrace();
}
}
public Response playGame(String activityId, String token, String score, Integer uid) throws Exception{
String ticketId = null;
Response response =null;
ticketId = doStart(activityId,token,uid);
response = submit(activityId,score,ticketId,uid,response);
return response;
}
public String doStart(String activityId,String token,Integer uid) throws Exception{
Response doStartResponse = newGameService.doStart(activityId,token,uid);
String startSuccess = MatcherString.getString(doStartResponse.asString(),"\"success\": (.*?),",1);
String ticketId = MatcherString.getString(doStartResponse.asString(),"\"ticketId\": \"(.*?)\",",1);
Assert.assertEquals(startSuccess,"true","dostart接口执行失败");
Response statusResponse = newGameService.getStartStatus(ticketId,uid);
statusResponse.prettyPrint();
String statusSuccess = MatcherString.getString(statusResponse.asString(),"\"success\": (.*?),",1);
String message = MatcherString.getString(statusResponse.asString(),"\"message\": \"(.*?)\"",1);
int j=8;
while (j>0&&((!checkNomal("getStartStatus",statusResponse))||(message.equals("处理中")))){
Thread.sleep(1000);
statusResponse = newGameService.getStartStatus(ticketId,uid);
statusResponse.prettyPrint();
statusSuccess = MatcherString.getString(statusResponse.asString(),"\"success\": (.*?),",1);
message = MatcherString.getString(statusResponse.asString(),"\"message\": \"(.*?)\"",1);
j--;
}
// logger.info("statusResponse的信息为"+ statusResponse.asString());
Assert.assertEquals(statusSuccess,"true","getStartStatus接口执行失败");
Assert.assertEquals(statusResponse.jsonPath().getString("message"),"处理成功","获取状态成功");
return ticketId;
}
public Response submit(String activityId,String score,String ticketId,Integer uid,Response response) throws Exception{
Response submitResponse = newGameService.submit(ticketId,score,uid);
String orderId = MatcherString.getString(submitResponse.asString(),"\"orderId\": (.*?),",1);
if (activityId.equals("20192")){
virtualOrderIds = orderId;
logger.info("orderIds的信息为"+virtualOrderIds);
}
Response submitResultResponse = newGameService.getSubmitResult(orderId,uid);
String flag = MatcherString.getString(submitResultResponse.asString(),"\"flag\": (\\D{4})",1);
for(int z=0;z<8;z++){
if ((flag.equals("true"))){
submitResultResponse = newGameService.getSubmitResult(orderId,uid);
submitResultResponse.prettyPrint();
flag = MatcherString.getString(submitResultResponse.asString(),"\"flag\": (\\D{4})",1);
String optionName = MatcherString.getString(submitResultResponse.asString(),"\"name\": \"(.*?)\",",1);
for (int k=0;k<8;k++){
if (optionName.isEmpty()){
submitResultResponse = newGameService.getSubmitResult(orderId,uid);
submitResultResponse.prettyPrint();
optionName = MatcherString.getString(submitResultResponse.asString(),"\"name\": \"(.*?)\",",1);
}
}
}
}
// logger.info("submitResultResponse的信息为"+submitResultResponse.asString());
response=submitResultResponse;
return response;
}
public Boolean checkNomal(String api,Response response) {
Boolean isNomal = false;
String title = MatcherString.getString(response.asString(),"<div class=\"title\">(.*?)</div>",1);
if (title.equals("当前网络貌似出了点问题")){
logger.info(api+"接口调用异常,重新调用"+"错误信息为"+title);
return isNomal;
}else {
isNomal = true;
}
return isNomal;
}
@AfterClass
public void tearDown() {
try {
Boolean result = jdbc.update("update ngame.ngame_consumer_record set auto_open_prize_id = '' where consumer_id = ? and duiba_ngame_id ='1329'\n",consumerId);
} catch (Exception e) {
e.printStackTrace();
}
}
}
\ No newline at end of file
/**
* Copyright (C), 2015-2018
* FileName: 游戏_中奖异常流程测试_AccessTest
* Author: qianwenjun
* Date: 2018/4/24 14:11
* Description: 异常流程
*/
package http.cases.GameTest;
import com.duiba.qa.duiba.common.DuibaConfig;
import com.duiba.qa.duiba.common.DuibaTestBase;
import com.duiba.qa.duiba.service.Activity.NewGameService;
import com.duiba.qa.duiba.utils.MatcherString;
import com.duiba.qa.publics.util.DuibaLog;
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 java.util.Map;
/**
* 〈异常流程〉
*
* @author qianwenjun
* @create 2018/4/24
* @since 1.0.0
*/
@ContextConfiguration(classes = DuibaConfig.class)
public class 游戏_中奖异常流程测试_AccessTest extends DuibaTestBase{
@Autowired
NewGameService newGameService;
private static DuibaLog logger = DuibaLog.getLogger();
private static final Integer uid_Nomal = 2708;
//ok
@Test(description = "奖品剩余数量不足,不中奖")
public void 游戏_奖品数不足不中奖() throws Exception{
try {
Map<String,Object> ngameOptionResult = jdbc.findSimpleResult("select * from ngame.ngame_stock where game_option_id = (select id from ngame.duiba_ngame_options where duiba_game_id = ? and deleted = 0)\n","1334");
Map<String,Object> itemStockResult = jdbc.findSimpleResult("select * from goods.item where id = ?","27234");
Long optionStock = Long.parseLong(ngameOptionResult.get("stock").toString());
Long itemStock = Long.parseLong(itemStockResult.get("remaining").toString());
Response response = this.playGame("20194","z0eyz5d3","88",uid_Nomal);
Assert.assertEquals(response.jsonPath().getString("data.flag"),"false","submitResult结果标志位flag校验失败");
Assert.assertNull(response.jsonPath().getString("data.option"),"奖项为空校验失败");
logger.info("校验奖项库存不足,option为空成功,游戏剩余奖品数量为"+optionStock+"实际商品的数量为"+itemStock);
} catch (Exception e) {
e.printStackTrace();
}
}
@Test(description = "商品库存不足,不中奖")
public void 游戏_库存不足不中奖() throws Exception{
try {
Map<String,Object> ngameOptionResult = jdbc.findSimpleResult("select * from ngame.ngame_stock where game_option_id = (select id from ngame.duiba_ngame_options where duiba_game_id = ? and deleted = 0)\n","1335");
Map<String,Object> itemStockResult = jdbc.findSimpleResult("select * from stock.tb_stock where stock_id in (select stock_id from goods.item where id = ?","27235");
Long optionStock = Long.parseLong(ngameOptionResult.get("stock").toString());
Long itemStock = Long.parseLong(itemStockResult.get("stock").toString());
logger.info("奖项原库存值为"+optionStock+"商品原库存为"+itemStock);
for (Long i=itemStock;i>0;i--){
Response response1 = this.playGame("20195","z0eyz5d3","88",uid_Nomal);
logger.info("奖项原库存值为"+optionStock+"商品原库存为"+itemStock);
}
Response response = this.playGame("20195","z0eyz5d3","88",uid_Nomal);
Assert.assertEquals(response.jsonPath().getString("data.flag"),"false","submitResult结果标志位flag校验失败");
Assert.assertNull(response.jsonPath().getString("data.option"),"奖项为空校验失败");
logger.info("校验兑换项库存不足,option为空成功,游戏剩余奖品数量为"+optionStock+"实际商品的数量为"+itemStock);
} catch (Exception e) {
e.printStackTrace();
}
}
public Response playGame(String activityId, String token, String score, Integer uid) throws Exception{
String ticketId = null;
Response response =null;
ticketId = doStart(activityId,token,uid);
response = submit(activityId,score,ticketId,uid,response);
return response;
}
public String doStart(String activityId,String token,Integer uid) throws Exception{
Response doStartResponse = newGameService.doStart(activityId,token,uid);
String startSuccess = MatcherString.getString(doStartResponse.asString(),"\"success\": (.*?),",1);
String ticketId = MatcherString.getString(doStartResponse.asString(),"\"ticketId\": \"(.*?)\",",1);
Assert.assertEquals(startSuccess,"true","dostart接口执行失败");
Response statusResponse = newGameService.getStartStatus(ticketId,uid);
statusResponse.prettyPrint();
String statusSuccess = MatcherString.getString(statusResponse.asString(),"\"success\": (.*?),",1);
String message = MatcherString.getString(statusResponse.asString(),"\"message\": \"(.*?)\"",1);
int j=8;
while (j>0&&((!checkNomal("getStartStatus",statusResponse))||(message.equals("处理中")))){
Thread.sleep(1000);
statusResponse = newGameService.getStartStatus(ticketId,uid);
statusResponse.prettyPrint();
statusSuccess = MatcherString.getString(statusResponse.asString(),"\"success\": (.*?),",1);
message = MatcherString.getString(statusResponse.asString(),"\"message\": \"(.*?)\"",1);
j--;
}
// logger.info("statusResponse的信息为"+ statusResponse.asString());
Assert.assertEquals(statusSuccess,"true","getStartStatus接口执行失败");
Assert.assertEquals(statusResponse.jsonPath().getString("message"),"处理成功","获取状态成功");
return ticketId;
}
public Response submit(String activityId,String score,String ticketId,Integer uid,Response response) throws Exception{
Response submitResponse = newGameService.submit(ticketId,score,uid);
String orderId = MatcherString.getString(submitResponse.asString(),"\"orderId\": (.*?),",1);
Response submitResultResponse = newGameService.getSubmitResult(orderId,uid);
String flag = MatcherString.getString(submitResultResponse.asString(),"\"flag\": (\\D{4})",1);
for(int z=0;z<8;z++){
if ((flag.equals("true"))){
submitResultResponse = newGameService.getSubmitResult(orderId,uid);
submitResultResponse.prettyPrint();
flag = MatcherString.getString(submitResultResponse.asString(),"\"flag\": (\\D{4})",1);
String optionName = MatcherString.getString(submitResultResponse.asString(),"\"name\": \"(.*?)\",",1);
for (int k=0;k<8;k++){
if (optionName.isEmpty()){
submitResultResponse = newGameService.getSubmitResult(orderId,uid);
submitResultResponse.prettyPrint();
optionName = MatcherString.getString(submitResultResponse.asString(),"\"name\": \"(.*?)\",",1);
}
}
}
}
// logger.info("submitResultResponse的信息为"+submitResultResponse.asString());
response=submitResultResponse;
return response;
}
public Boolean checkNomal(String api,Response response) {
Boolean isNomal = false;
String title = MatcherString.getString(response.asString(),"<div class=\"title\">(.*?)</div>",1);
if (title.equals("当前网络貌似出了点问题")){
logger.info(api+"接口调用异常,重新调用"+"错误信息为"+title);
return isNomal;
}else {
isNomal = true;
}
return isNomal;
}
public Response playGame1(String activityId, String token, String score, Integer uid) throws Exception{
Response doStartResponse = newGameService.doStart(activityId,token,uid);
doStartResponse.prettyPrint();
// String ticketId = doStartResponse.jsonPath().getString("ticketId");
String ticketId = MatcherString.getString(doStartResponse.asString(),"\"ticketId\": \"(.*?)\",",1);
Response statusResponse = newGameService.getStartStatus(ticketId,uid);
String message = String.valueOf(statusResponse.jsonPath().getString("message"));
int i= 5;
while(i>0&&(message.equals("处理中"))){
Thread.sleep(1000);
statusResponse = newGameService.getStartStatus(ticketId,uid);
message = String.valueOf(statusResponse.jsonPath().getString("message"));
i--;
// statusResponse.prettyPrint();
}
Assert.assertEquals(statusResponse.jsonPath().getString("message"),"处理成功","获取状态成功");
Response submitResponse = newGameService.submit(ticketId,score,uid);
String orderId = submitResponse.jsonPath().getString("data.orderId");
Response submitResultResponse = newGameService.getSubmitResult(orderId,uid);
String flag = submitResultResponse.jsonPath().getString("data.flag");
String option = submitResultResponse.jsonPath().getString("data.option");
for(int j=0;j<8;j++){
if ((flag.equals("true"))){
submitResultResponse = newGameService.getSubmitResult(orderId,uid);
}
}
// submitResultResponse.prettyPrint();
return submitResultResponse;
}
}
\ No newline at end of file
/**
* Copyright (C), 2015-2018
* FileName: 游戏_区间中奖_AccessTest
* Author: qianwenjun
* Date: 2018/5/13 14:14
* Description:
*/
package http.cases.GameTest;
import com.duiba.qa.duiba.common.DuibaConfig;
import com.duiba.qa.duiba.common.DuibaTestBase;
import com.duiba.qa.duiba.service.Activity.NewGameService;
import com.duiba.qa.duiba.utils.MatcherString;
import com.duiba.qa.publics.util.DuibaLog;
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.AfterClass;
import org.testng.annotations.Test;
import java.util.List;
import java.util.Map;
/**
* 〈〉
*
* @author qianwenjun
* @create 2018/5/13
* @since 1.0.0
*/
@ContextConfiguration(classes = DuibaConfig.class)
public class 游戏_区间中奖_AccessTest extends DuibaTestBase{
@Autowired
NewGameService newGameService;
private static DuibaLog logger = DuibaLog.getLogger();
private static final Integer uid_Nomal = 2708;
private static final String consumerId = "100011623";
@Test
public void 游戏_区间1中奖测试() throws Exception{
try {
//查出游戏奖品的库存数据和对应的商品表的库存数据
List<Map<String, Object>> dbs = jdbc.findModeResult("select * from ngame.ngame_stock where game_option_id in (select id from ngame.duiba_ngame_options where duiba_game_id = ? and deleted = 0)\n","1336");
Long optionStock = 0L;
for (int i=0;i<dbs.size();i++){
String optionId = dbs.get(i).get("game_option_id").toString();
if(optionId.equals("3314")){
//奖项库存
Map<String,Object> ngameStockResult = jdbc.findSimpleResult("select * from ngame.ngame_stock where game_option_id = ?\n",optionId);
optionStock = Long.parseLong(ngameStockResult.get("stock").toString());
}
}
Response response = this.playGame("20196","z0eyz5d3","33",uid_Nomal);
//奖项库存
Map<String,Object> ngameStockResult = jdbc.findSimpleResult("select * from ngame.ngame_stock where game_option_id = ?\n","3314");
String optionStock1 = ngameStockResult.get("stock").toString();
//区间1奖品中奖,奖品为实物类型,校验奖项库存和商品库存
Assert.assertEquals(response.jsonPath().getString("data.option.type"),"phonebill","奖品type校验失败");
Assert.assertEquals(response.jsonPath().getString("data.option.itemId"),"1","奖品itemId校验失败");
Assert.assertEquals(optionStock1,String.valueOf(optionStock-1),"奖项1库存校验失败");
logger.info("区间1分数,中区间1奖品校验成功");
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void 游戏_区间3中奖测试() throws Exception{
try {
//查出游戏奖品的库存数据和对应的商品表的库存数据
List<Map<String, Object>> dbs = jdbc.findModeResult("select * from ngame.ngame_stock where game_option_id in (select id from ngame.duiba_ngame_options where duiba_game_id = ? and deleted = 0)\n","1336");
Long optionStock = 0L;
for (int i=0;i<dbs.size();i++){
String optionId = dbs.get(i).get("game_option_id").toString();
if(optionId.equals("3316")){
optionStock = Long.parseLong(dbs.get(i).get("stock").toString());
}
}
Response response = this.playGame("20196","z0eyz5d3","110",uid_Nomal);
Map<String,Object> roptionResult = jdbc.findSimpleResult("select * from ngame.ngame_stock where game_option_id = (select id from ngame.duiba_ngame_options where duiba_game_id = ? and item_id = ? and deleted = 0)\n","1336","1");
String optionStock1 = roptionResult.get("stock").toString();
//区间3中奖,奖品为话费充值,只需校验奖项库存
Assert.assertEquals(response.jsonPath().getString("data.option.type"),"phonebill","奖品type校验失败");
Assert.assertEquals(response.jsonPath().getString("data.option.itemId"),"1","奖品itemId校验失败");
Assert.assertEquals(optionStock1,String.valueOf(optionStock-1),"奖项3库存校验失败");
logger.info("区间3分数,中区间3奖品校验成功");
} catch (Exception e) {
e.printStackTrace();
}
}
public Response playGame(String activityId, String token, String score, Integer uid) throws Exception{
String ticketId = null;
Response response =null;
ticketId = doStart(activityId,token,uid);
response = submit(activityId,score,ticketId,uid,response);
return response;
}
public String doStart(String activityId,String token,Integer uid) throws Exception{
Response doStartResponse = newGameService.doStart(activityId,token,uid);
String startSuccess = MatcherString.getString(doStartResponse.asString(),"\"success\": (.*?),",1);
String ticketId = MatcherString.getString(doStartResponse.asString(),"\"ticketId\": \"(.*?)\",",1);
Assert.assertEquals(startSuccess,"true","dostart接口执行失败");
Response statusResponse = newGameService.getStartStatus(ticketId,uid);
statusResponse.prettyPrint();
String statusSuccess = MatcherString.getString(statusResponse.asString(),"\"success\": (.*?),",1);
String message = MatcherString.getString(statusResponse.asString(),"\"message\": \"(.*?)\"",1);
int j=8;
while (j>0&&((!checkNomal("getStartStatus",statusResponse))||(message.equals("处理中")))){
Thread.sleep(1000);
statusResponse = newGameService.getStartStatus(ticketId,uid);
statusResponse.prettyPrint();
statusSuccess = MatcherString.getString(statusResponse.asString(),"\"success\": (.*?),",1);
message = MatcherString.getString(statusResponse.asString(),"\"message\": \"(.*?)\"",1);
j--;
}
// logger.info("statusResponse的信息为"+ statusResponse.asString());
Assert.assertEquals(statusSuccess,"true","getStartStatus接口执行失败");
Assert.assertEquals(statusResponse.jsonPath().getString("message"),"处理成功","获取状态成功");
return ticketId;
}
public Response submit(String activityId,String score,String ticketId,Integer uid,Response response) throws Exception{
Response submitResponse = newGameService.submit(ticketId,score,uid);
String orderId = MatcherString.getString(submitResponse.asString(),"\"orderId\": (.*?),",1);
Response submitResultResponse = newGameService.getSubmitResult(orderId,uid);
String flag = MatcherString.getString(submitResultResponse.asString(),"\"flag\": (\\D{4})",1);
String optionName = MatcherString.getString(submitResultResponse.asString(),"\"name\": \"(.*?)\",",1);
logger.info("第一次请求submit结果的信息,flag="+flag+";optionname="+optionName);
for(int z=0;z<8;z++){
if ((flag.equals("true"))){
Thread.sleep(1000);
submitResultResponse = newGameService.getSubmitResult(orderId,uid);
submitResultResponse.prettyPrint();
flag = MatcherString.getString(submitResultResponse.asString(),"\"flag\": (\\D{4})",1);
optionName = MatcherString.getString(submitResultResponse.asString(),"\"name\": \"(.*?)\",",1);
logger.info("第"+(z+2)+"次请求submit结果的信息,flag="+flag+";optionname="+optionName);
for (int k=0;k<8;k++){
if (optionName.isEmpty()){
Thread.sleep(1000);
submitResultResponse = newGameService.getSubmitResult(orderId,uid);
submitResultResponse.prettyPrint();
optionName = MatcherString.getString(submitResultResponse.asString(),"\"name\": \"(.*?)\",",1);
}else {
break;
}
}
}else {
for (int k=0;k<8;k++){
if (optionName.isEmpty()){
Thread.sleep(1000);
submitResultResponse = newGameService.getSubmitResult(orderId,uid);
submitResultResponse.prettyPrint();
optionName = MatcherString.getString(submitResultResponse.asString(),"\"name\": \"(.*?)\",",1);
}else {
break;
}
}
}
}
// logger.info("submitResultResponse的信息为"+submitResultResponse.asString());
response=submitResultResponse;
return response;
}
public Boolean checkNomal(String api,Response response) {
Boolean isNomal = false;
String title = MatcherString.getString(response.asString(),"<div class=\"title\">(.*?)</div>",1);
if (title.equals("当前网络貌似出了点问题")){
logger.info(api+"接口调用异常,重新调用"+"错误信息为"+title);
return isNomal;
}else {
isNomal = true;
}
return isNomal;
}
@AfterClass
public void tearDown() {
try {
Boolean result = jdbc.update("update ngame.ngame_consumer_record set auto_open_prize_id = '' where consumer_id = ? and duiba_ngame_id = '1336'\n",consumerId);
} catch (Exception e) {
e.printStackTrace();
}
}
}
\ No newline at end of file
/**
* Copyright (C), 2015-2018
* FileName: 游戏_区间外不中奖_AccessTest
* Author: qianwenjun
* Date: 2018/6/7 14:20
* Description:
*/
package http.cases.GameTest;
import com.duiba.qa.duiba.common.DuibaConfig;
import com.duiba.qa.duiba.common.DuibaTestBase;
import com.duiba.qa.duiba.service.Activity.NewGameService;
import com.duiba.qa.duiba.utils.MatcherString;
import com.duiba.qa.publics.util.DuibaLog;
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;
/**
* 〈〉
*
* @author qianwenjun
* @create 2018/6/7
* @since 1.0.0
*/
@ContextConfiguration(classes = DuibaConfig.class)
public class 游戏_区间外不中奖_AccessTest extends DuibaTestBase {
@Autowired
NewGameService newGameService;
private static DuibaLog logger = DuibaLog.getLogger();
private static final Integer uid_Nomal = 2708;
@Test
public void 游戏_区间外分数不中奖测试() throws Exception{
try {
Response response = this.playGame("20196","z0eyz5d3","200",uid_Nomal);
//case=4的,区间外分数不中奖
Assert.assertNull(response.jsonPath().getString("data.option"),"奖项为空校验失败");
logger.info("区间外分数不中奖,奖项option为空校验成功");
} catch (Exception e) {
e.printStackTrace();
}
}
public Response playGame(String activityId, String token, String score, Integer uid) throws Exception{
String ticketId = null;
Response response =null;
ticketId = doStart(activityId,token,uid);
response = submit(activityId,score,ticketId,uid,response);
return response;
}
public String doStart(String activityId,String token,Integer uid) throws Exception{
Response doStartResponse = newGameService.doStart(activityId,token,uid);
String startSuccess = MatcherString.getString(doStartResponse.asString(),"\"success\": (.*?),",1);
String ticketId = MatcherString.getString(doStartResponse.asString(),"\"ticketId\": \"(.*?)\",",1);
Assert.assertEquals(startSuccess,"true","dostart接口执行失败");
Response statusResponse = newGameService.getStartStatus(ticketId,uid);
statusResponse.prettyPrint();
String statusSuccess = MatcherString.getString(statusResponse.asString(),"\"success\": (.*?),",1);
String message = MatcherString.getString(statusResponse.asString(),"\"message\": \"(.*?)\"",1);
int j=8;
while (j>0&&((!checkNomal("getStartStatus",statusResponse))||(message.equals("处理中")))){
Thread.sleep(1000);
statusResponse = newGameService.getStartStatus(ticketId,uid);
statusResponse.prettyPrint();
statusSuccess = MatcherString.getString(statusResponse.asString(),"\"success\": (.*?),",1);
message = MatcherString.getString(statusResponse.asString(),"\"message\": \"(.*?)\"",1);
j--;
}
// logger.info("statusResponse的信息为"+ statusResponse.asString());
Assert.assertEquals(statusSuccess,"true","getStartStatus接口执行失败");
Assert.assertEquals(statusResponse.jsonPath().getString("message"),"处理成功","获取状态成功");
return ticketId;
}
public Response submit(String activityId,String score,String ticketId,Integer uid,Response response) throws Exception{
Response submit = newGameService.submit(ticketId, score, uid);
Response submitResponse = submit;
String orderId = MatcherString.getString(submitResponse.asString(),"\"orderId\": (.*?),",1);
Response submitResultResponse = newGameService.getSubmitResult(orderId,uid);
String flag = MatcherString.getString(submitResultResponse.asString(),"\"flag\": (\\D{4})",1);
for(int z=0;z<8;z++){
if ((flag.equals("true"))){
submitResultResponse = newGameService.getSubmitResult(orderId,uid);
submitResultResponse.prettyPrint();
flag = MatcherString.getString(submitResultResponse.asString(),"\"flag\": (\\D{4})",1);
String optionName = MatcherString.getString(submitResultResponse.asString(),"\"name\": \"(.*?)\",",1);
for (int k=0;k<8;k++){
if (optionName.isEmpty()){
submitResultResponse = newGameService.getSubmitResult(orderId,uid);
submitResultResponse.prettyPrint();
optionName = MatcherString.getString(submitResultResponse.asString(),"\"name\": \"(.*?)\",",1);
}
}
}
}
// logger.info("submitResultResponse的信息为"+submitResultResponse.asString());
response=submitResultResponse;
return response;
}
public Boolean checkNomal(String api,Response response) {
Boolean isNomal = false;
String title = MatcherString.getString(response.asString(),"<div class=\"title\">(.*?)</div>",1);
if (title.equals("当前网络貌似出了点问题")){
logger.info(api+"接口调用异常,重新调用"+"错误信息为"+title);
return isNomal;
}else {
isNomal = true;
}
return isNomal;
}
}
\ No newline at end of file
/**
* Copyright (C), 2015-2018
* FileName: 游戏_区间奖品不足测试_AccessTest
* Author: qianwenjun
* Date: 2018/6/8 12:42
* Description:
*/
package http.cases.GameTest;
import com.duiba.qa.duiba.common.DuibaConfig;
import com.duiba.qa.duiba.common.DuibaTestBase;
import com.duiba.qa.duiba.service.Activity.NewGameService;
import com.duiba.qa.duiba.utils.MatcherString;
import com.duiba.qa.publics.util.DuibaLog;
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 java.util.List;
import java.util.Map;
/**
* 〈〉
*
* @author qianwenjun
* @create 2018/6/8
* @since 1.0.0
*/
@ContextConfiguration(classes = DuibaConfig.class)
public class 游戏_区间奖品不足测试_AccessTest extends DuibaTestBase {
@Autowired
NewGameService newGameService;
private static DuibaLog logger = DuibaLog.getLogger();
private static final Integer uid_Nomal = 2708;
@Test
public void 游戏_区间2奖品不足测试() throws Exception{
try {
//查出游戏奖品的库存数据和对应的商品表的库存数据
List<Map<String, Object>> dbs = jdbc.findModeResult("select * from ngame.ngame_stock where game_option_id in (select id from ngame.duiba_ngame_options where duiba_game_id = ? and deleted = 0)\n","1336");
Long optionStock = 0L;
Long goodStock = 0L;
for (int i=0;i<dbs.size();i++){
String optionId = dbs.get(i).get("game_option_id").toString();
if(optionId.equals("3315")){
optionStock = Long.parseLong(dbs.get(i).get("stock").toString());
Map<String,Object> itemStockResult = jdbc.findSimpleResult("select * from goods.item where id = ?","27070");
goodStock = Long.parseLong(itemStockResult.get("remaining").toString());
logger.info("optionStock="+optionStock+",goodStock="+goodStock);
}
}
Response response = this.playGame("20196","z0eyz5d3","88",uid_Nomal);
Assert.assertNull(response.jsonPath().getString("data.option"),"奖项为空校验失败");
Assert.assertEquals(String.valueOf(optionStock),"0","奖项2库存校验失败");
logger.info("区间2分数,区间2奖项库存不足,奖项option为空校验成功");
} catch (Exception e) {
e.printStackTrace();
}
}
public Response playGame(String activityId, String token, String score, Integer uid) throws Exception{
String ticketId = null;
Response response =null;
ticketId = doStart(activityId,token,uid);
response = submit(activityId,score,ticketId,uid,response);
return response;
}
public String doStart(String activityId,String token,Integer uid) throws Exception{
Response doStartResponse = newGameService.doStart(activityId,token,uid);
String startSuccess = MatcherString.getString(doStartResponse.asString(),"\"success\": (.*?),",1);
String ticketId = MatcherString.getString(doStartResponse.asString(),"\"ticketId\": \"(.*?)\",",1);
Assert.assertEquals(startSuccess,"true","dostart接口执行失败");
Response statusResponse = newGameService.getStartStatus(ticketId,uid);
statusResponse.prettyPrint();
String statusSuccess = MatcherString.getString(statusResponse.asString(),"\"success\": (.*?),",1);
String message = MatcherString.getString(statusResponse.asString(),"\"message\": \"(.*?)\"",1);
int j=8;
while (j>0&&((!checkNomal("getStartStatus",statusResponse))||(message.equals("处理中")))){
Thread.sleep(1000);
statusResponse = newGameService.getStartStatus(ticketId,uid);
statusResponse.prettyPrint();
statusSuccess = MatcherString.getString(statusResponse.asString(),"\"success\": (.*?),",1);
message = MatcherString.getString(statusResponse.asString(),"\"message\": \"(.*?)\"",1);
j--;
}
// logger.info("statusResponse的信息为"+ statusResponse.asString());
Assert.assertEquals(statusSuccess,"true","getStartStatus接口执行失败");
Assert.assertEquals(statusResponse.jsonPath().getString("message"),"处理成功","获取状态成功");
return ticketId;
}
public Response submit(String activityId,String score,String ticketId,Integer uid,Response response) throws Exception{
Response submitResponse = newGameService.submit(ticketId,score,uid);
String orderId = MatcherString.getString(submitResponse.asString(),"\"orderId\": (.*?),",1);
Response submitResultResponse = newGameService.getSubmitResult(orderId,uid);
String flag = MatcherString.getString(submitResultResponse.asString(),"\"flag\": (\\D{4})",1);
for(int z=0;z<8;z++){
if ((flag.equals("true"))){
submitResultResponse = newGameService.getSubmitResult(orderId,uid);
submitResultResponse.prettyPrint();
flag = MatcherString.getString(submitResultResponse.asString(),"\"flag\": (\\D{4})",1);
String optionName = MatcherString.getString(submitResultResponse.asString(),"\"name\": \"(.*?)\",",1);
for (int k=0;k<8;k++){
if (optionName.isEmpty()){
submitResultResponse = newGameService.getSubmitResult(orderId,uid);
submitResultResponse.prettyPrint();
optionName = MatcherString.getString(submitResultResponse.asString(),"\"name\": \"(.*?)\",",1);
}
}
}
}
// logger.info("submitResultResponse的信息为"+submitResultResponse.asString());
response=submitResultResponse;
return response;
}
public Boolean checkNomal(String api,Response response) {
Boolean isNomal = false;
String title = MatcherString.getString(response.asString(),"<div class=\"title\">(.*?)</div>",1);
if (title.equals("当前网络貌似出了点问题")){
logger.info(api+"接口调用异常,重新调用"+"错误信息为"+title);
return isNomal;
}else {
isNomal = true;
}
return isNomal;
}
}
\ No newline at end of file
/**
* Copyright (C), 2015-2018
* FileName: 游戏_奖项限制测试_AccessTest
* Author: qianwenjun
* Date: 2018/5/28 10:13
* Description:
*/
package http.cases.GameTest;
import base.DuibaLog;
import base.DuibaTestBase;
import com.alibaba.fastjson.JSONObject;
import http.service.Activity.NewGameService;
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.AfterClass;
import org.testng.annotations.Test;
import utils.MatcherString;
import java.util.Map;
/**
* 〈〉
*
* @author qianwenjun
* @create 2018/5/28
* @since 1.0.0
*/
public class 游戏_奖项限制测试_AccessTest extends DuibaTestBase {
@Autowired
NewGameService newGameService;
private static DuibaLog logger = DuibaLog.getLogger();
private static final Integer uid_Nomal = 2708;
private static final String consumerId = "100011623";
@Test
public void 游戏多奖项限制测试() {
try {
Map<String,Object> gameConfig = jdbc.findSimpleResult("select * from ngame.duiba_ngame where id = '1345'\n");
// logger.info("extend_json="+JSON.toJSONString(gameConfig.get("extend_json")));
// JSONObject extend_json =JSONObject.parseObject(JSON.toJSONString(gameConfig.get("extend_json")));
JSONObject extend_json =JSONObject.parseObject(String.valueOf(gameConfig.get("extend_json")));
//查询多奖项限制的次数,和加入多奖项限制的奖项id
String mutliPrizeLimitCount = extend_json.getString("mutliPrizeLimitCount");
String mutliPrizeLimitIds = extend_json.getString("mutliPrizeLimitIds");
// logger.info("mutliPrizeLimitCount的信息为"+mutliPrizeLimitCount+"mutliPrizeLimitIds的信息为"+mutliPrizeLimitIds);
Response response1 = this.playGame("22615","z0eyz5d3","99",uid_Nomal);
Assert.assertEquals(MatcherString.getString(response1.asString(),"\"name\": \"(.*?)\",",1),"小奖1","中奖信息校验失败");
Response response2 = this.playGame("22615","z0eyz5d3","150",uid_Nomal);
Assert.assertEquals(MatcherString.getString(response2.asString(),"\"name\": \"(.*?)\",",1),"小奖2","中奖信息校验失败");
Map<String,Object> result = jdbc.findSimpleResult("select * from ngame.ngame_consumer_record where consumer_id = '100011623' and duiba_ngame_id = '1345'\n");
String[] auto_open_prize_ids = result.get("auto_open_prize_id").toString().split(",");
// logger.info("auto_open_prize_ids的信息为"+ JSON.toJSONString(auto_open_prize_ids)+"auto_open_prize_ids的长度为"+auto_open_prize_ids.length);
//校验,达到中奖限制后,不允许中奖在多奖项限制里的奖项,可以中奖其他的奖项
if (auto_open_prize_ids.length==Integer.valueOf(mutliPrizeLimitCount)){
Response response3 = this.playGame("22615","z0eyz5d3","250",uid_Nomal);
Assert.assertEquals(MatcherString.getString(response3.asString(),"\"option\": (.*?),",1),"null","奖项限制,没中奖校验失败");
Response response4 = this.playGame("22615","z0eyz5d3","350",uid_Nomal);
Assert.assertEquals(MatcherString.getString(response4.asString(),"\"name\": \"(.*?)\",",1),"小奖4","校验非奖项限制的中奖失败");
}
} catch (Exception e) {
e.printStackTrace();
}
}
public Response playGame(String activityId, String token, String score, Integer uid) throws Exception{
String ticketId = null;
Response response =null;
ticketId = doStart(activityId,token,uid);
response = submit(activityId,score,ticketId,uid,response);
return response;
}
public String doStart(String activityId,String token,Integer uid) throws Exception{
Response doStartResponse = newGameService.doStart(activityId,token,uid);
String startSuccess = MatcherString.getString(doStartResponse.asString(),"\"success\": (.*?),",1);
String ticketId = MatcherString.getString(doStartResponse.asString(),"\"ticketId\": \"(.*?)\",",1);
Assert.assertEquals(startSuccess,"true","dostart接口执行失败");
Response statusResponse = newGameService.getStartStatus(ticketId,uid);
statusResponse.prettyPrint();
String statusSuccess = MatcherString.getString(statusResponse.asString(),"\"success\": (.*?),",1);
String message = MatcherString.getString(statusResponse.asString(),"\"message\": \"(.*?)\"",1);
int j=8;
while (j>0&&((!checkNomal("getStartStatus",statusResponse))||(message.equals("处理中")))){
Thread.sleep(1000);
statusResponse = newGameService.getStartStatus(ticketId,uid);
statusResponse.prettyPrint();
statusSuccess = MatcherString.getString(statusResponse.asString(),"\"success\": (.*?),",1);
message = MatcherString.getString(statusResponse.asString(),"\"message\": \"(.*?)\"",1);
j--;
}
// logger.info("statusResponse的信息为"+ statusResponse.asString());
Assert.assertEquals(statusSuccess,"true","getStartStatus接口执行失败");
Assert.assertEquals(statusResponse.jsonPath().getString("message"),"处理成功","获取状态成功");
return ticketId;
}
public Response submit(String activityId,String score,String ticketId,Integer uid,Response response) throws Exception{
Response submitResponse = newGameService.submit(ticketId,score,uid);
String orderId = MatcherString.getString(submitResponse.asString(),"\"orderId\": (.*?),",1);
Response submitResultResponse = newGameService.getSubmitResult(orderId,uid);
String flag = MatcherString.getString(submitResultResponse.asString(),"\"flag\": (\\D{4})",1);
for(int z=0;z<8;z++){
if ((flag.equals("true"))){
submitResultResponse = newGameService.getSubmitResult(orderId,uid);
submitResultResponse.prettyPrint();
flag = MatcherString.getString(submitResultResponse.asString(),"\"flag\": (\\D{4})",1);
String optionName = MatcherString.getString(submitResultResponse.asString(),"\"name\": \"(.*?)\",",1);
for (int k=0;k<8;k++){
if (optionName.isEmpty()){
submitResultResponse = newGameService.getSubmitResult(orderId,uid);
submitResultResponse.prettyPrint();
optionName = MatcherString.getString(submitResultResponse.asString(),"\"name\": \"(.*?)\",",1);
}
}
}
}
// logger.info("submitResultResponse的信息为"+submitResultResponse.asString());
response=submitResultResponse;
return response;
}
public Boolean checkNomal(String api,Response response) {
Boolean isNomal = false;
String title = MatcherString.getString(response.asString(),"<div class=\"title\">(.*?)</div>",1);
if (title.equals("当前网络貌似出了点问题")){
logger.info(api+"接口调用异常,重新调用"+"错误信息为"+title);
return isNomal;
}else {
isNomal = true;
}
return isNomal;
}
@AfterClass
public void tearDown() {
try {
Boolean result = jdbc.update("update ngame.ngame_consumer_record set auto_open_prize_id = '' where consumer_id = ? and duiba_ngame_id = '1345'\n",consumerId);
} catch (Exception e) {
e.printStackTrace();
}
}
}
\ No newline at end of file
/**
* Copyright (C), 2015-2018
* FileName: 游戏_推币机换回超过可兑换上限测试_AccessTest
* Author: qianwenjun
* Date: 2018/9/3 11:48
* Description:
*/
package http.cases.GameTest;
import com.duiba.qa.duiba.common.DuibaConfig;
import com.duiba.qa.duiba.common.DuibaTestBase;
import com.duiba.qa.duiba.service.Activity.NewGameService;
import com.duiba.qa.duiba.utils.MatcherString;
import com.duiba.qa.publics.util.DuibaLog;
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 java.util.Map;
/**
* 〈〉
*
* @author qianwenjun
* @create 2018/9/3
* @since 1.0.0
*/
@ContextConfiguration(classes = DuibaConfig.class)
public class 游戏_推币机回收率低测试_AccessTest extends DuibaTestBase{
@Autowired
NewGameService newGameService;
private static DuibaLog logger = DuibaLog.getLogger();
private static final Integer uid1 = 3645;
private static final String consumerId1 = "100084020";
private static final Integer uid2 = 3646;
private static final String consumerId2 = "100084021";
private static final Integer uid3 = 3647;
private static final String consumerId3 = "100084022";
private static final Integer uid4 = 3648;
private static final String consumerId4 = "100084023";
@Test(description = "回收率较低,用户基本上可以赚取积分值")
public void 游戏_推币机回收率低测试() throws Exception{
//参加前活动用户积分值
// Response consumerCredits = newGameService.getCredits(uid1);
// consumerCredits.prettyPrint();
// Long beforeCredits = Long.valueOf(consumerCredits.jsonPath().getString("data.credits"));
Map<String,Object> consumerInfo = jdbc.findSimpleResult("select * from new_consumer.consumer_0010 where id = ?\n",consumerId1);
Long beforeCondumerCredits = Long.valueOf(consumerInfo.get("credits").toString());
Map<String,Object> userInfo = jdbc.findSimpleResult("select * from dafuweng.user where id = ?\n",uid1);
Long beforeUserCredits = Long.valueOf(userInfo.get("credits").toString());
logger.info("用户参加活动,consumer表积分为:"+beforeCondumerCredits+",user表积分为:"+beforeUserCredits);
Long subCredits = 60l;
Response doStartResponse = newGameService.doStartForCoin("31346","z0eyz5d3",uid1,String.valueOf(subCredits));
String startSuccess = MatcherString.getString(doStartResponse.asString(),"\"success\": (.*?),",1);
String ticketId = MatcherString.getString(doStartResponse.asString(),"\"ticketId\": \"(.*?)\",",1);
Assert.assertEquals(startSuccess,"true","dostart接口执行失败");
//校验扣除的实际积分值
Assert.assertEquals(MatcherString.getString(doStartResponse.asString(),"\"credits\": (.*?),",1),String.valueOf(subCredits),"dostart接口执行失败");
logger.info("用户参加活动扣除积分值:"+subCredits);
Response statusResponse = this.getOrderStatus(uid1,ticketId);
Assert.assertEquals(MatcherString.getString(statusResponse.asString(),"\"success\": (.*?),",1),"true","getStartStatus接口执行失败");
Assert.assertEquals(MatcherString.getString(statusResponse.asString(),"\"message\": \"(.*?)\"",1),"处理成功","获取状态成功");
//推币机游戏无回收率, 则最高退回的积分值为兑换的积分值
//大盘回收率1%,只要回收的值有大于1%则用户可以赚钱积分
Long creditsUpperLimit = Long.valueOf(MatcherString.getString(statusResponse.asString(),"\"creditsUpperLimit\": (.*?),",1));
Assert.assertTrue((creditsUpperLimit>=subCredits),"获取状态成功");
logger.info("最大换回积分值creditsUpperLimit="+creditsUpperLimit+"比兑换积分值大,校验成功");
//提交换回的金币
Long addCredits = 10L;
Response submitResponse = newGameService.submitForCoin(ticketId,String.valueOf(addCredits),uid1);
String orderId = MatcherString.getString(submitResponse.asString(),"\"orderId\": (.*?),",1);
String submitResponseCredits = MatcherString.getString(submitResponse.asString(),"\"credits\": (.*?),",1);
logger.info("活动结束用户换回积分值:"+addCredits);
logger.info("submit之后用户积分值:"+submitResponseCredits);
Thread.sleep(20000);
//活动结束后用户积分值
Map<String,Object> consumerInfo1 = jdbc.findSimpleResult("select * from new_consumer.consumer_0010 where id = ?\n",consumerId1);
String afterCondumerCredits = consumerInfo1.get("credits").toString();
Map<String,Object> userInfo1 = jdbc.findSimpleResult("select * from dafuweng.user where id = ?\n",uid1);
String afterUserCredits = userInfo1.get("credits").toString();
logger.info("用户参加活动,consumer表积分为:"+afterCondumerCredits+",user表积分为:"+afterUserCredits);
String except = String.valueOf(beforeUserCredits-subCredits+addCredits);
logger.info("except积分值为:"+except);
Assert.assertEquals(afterUserCredits,except,"积分换回校验失败");
logger.info("积分换回成功"+"\nbeforeUserCredits="+beforeUserCredits+"\nafterUserCredits="+afterUserCredits);
this.tearDown("2946",consumerId1);
}
public Response getOrderStatus(Integer uid,String ticketId) throws Exception{
Response statusResponse = newGameService.getStartStatusForCoin(ticketId,uid);
statusResponse.prettyPrint();
String statusSuccess = MatcherString.getString(statusResponse.asString(),"\"success\": (.*?),",1);
String message = MatcherString.getString(statusResponse.asString(),"\"message\": \"(.*?)\"",1);
int j=8;
while (j>0&&((!checkNomal("getStartStatus",statusResponse))||(message.equals("处理中")))){
Thread.sleep(1000);
statusResponse = newGameService.getStartStatusForCoin(ticketId,uid);
statusResponse.prettyPrint();
message = MatcherString.getString(statusResponse.asString(),"\"message\": \"(.*?)\"",1);
j--;
}
// logger.info("statusResponse的信息为"+ statusResponse.asString());
return statusResponse;
}
public Response getSubmitResult(String orderId,Integer uid) throws Exception{
Response submitResultResponse = newGameService.getSubmitResult(orderId,uid);
String flag = MatcherString.getString(submitResultResponse.asString(),"\"flag\": (\\D{4})",1);
for(int z=0;z<8;z++){
if ((flag.equals("true"))){
submitResultResponse = newGameService.getSubmitResult(orderId,uid);
submitResultResponse.prettyPrint();
flag = MatcherString.getString(submitResultResponse.asString(),"\"flag\": (\\D{4})",1);
String optionName = MatcherString.getString(submitResultResponse.asString(),"\"name\": \"(.*?)\",",1);
for (int k=0;k<8;k++){
if (optionName.isEmpty()){
submitResultResponse = newGameService.getSubmitResult(orderId,uid);
submitResultResponse.prettyPrint();
optionName = MatcherString.getString(submitResultResponse.asString(),"\"name\": \"(.*?)\",",1);
}
}
}
}
// logger.info("submitResultResponse的信息为"+submitResultResponse.asString());
return submitResultResponse;
}
public Boolean checkNomal(String api,Response response) {
Boolean isNomal = false;
String title = MatcherString.getString(response.asString(),"<div class=\"title\">(.*?)</div>",1);
if (title.equals("当前网络貌似出了点问题")){
logger.info(api+"接口调用异常,重新调用"+"错误信息为"+title);
return isNomal;
}else {
isNomal = true;
}
return isNomal;
}
public void tearDown(String gameId,String consumerId) {
try {
Boolean result1 = jdbc.update("update ngame.ngame_consumer_record set auto_open_prize_id = '' where duiba_ngame_id = ? and consumer_id = ?\n",gameId,consumerId);
} catch (Exception e) {
e.printStackTrace();
}
}
}
\ No newline at end of file
/**
* Copyright (C), 2015-2018
* FileName: 游戏_推币机换回超过可兑换上限测试_AccessTest
* Author: qianwenjun
* Date: 2018/9/3 11:48
* Description:
*/
package http.cases.GameTest;
import base.DuibaLog;
import base.DuibaTestBase;
import http.service.Activity.NewGameService;
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/9/3
* @since 1.0.0
*/
public class 游戏_推币机回收率高测试_AccessTest extends DuibaTestBase {
@Autowired
NewGameService newGameService;
private static DuibaLog logger = DuibaLog.getLogger();
private static final Integer uid_Nomal = 2708;
private static final String consumerId = "100011623";
private static final Integer uid1 = 3645;
private static final String consumerId1 = "100084020";
private static final Integer uid2 = 3646;
private static final String consumerId2 = "100084021";
private static final Integer uid3 = 3647;
private static final String consumerId3 = "100084022";
private static final Integer uid4 = 3648;
private static final String consumerId4 = "100084023";
@Test(description = "回收率较高,用户为消耗积分状态,最高兑换积分值为扣除积分值")
public void 游戏_推币机回收率高测试() throws Exception{
//参加前活动用户积分值
// Response consumerCredits = newGameService.getCredits(uid2);
// consumerCredits.prettyPrint();
// Long beforeCredits = Long.valueOf(consumerCredits.jsonPath().getString("data.credits"));
Map<String,Object> consumerInfo = jdbc.findSimpleResult("select * from new_consumer.consumer_0010 where id = ?\n",consumerId2);
Long beforeCondumerCredits = Long.valueOf(consumerInfo.get("credits").toString());
Map<String,Object> userInfo = jdbc.findSimpleResult("select * from dafuweng.user where id = ?\n",uid2);
Long beforeUserCredits = Long.valueOf(userInfo.get("credits").toString());
logger.info("用户参加活动,consumer表积分为:"+beforeCondumerCredits+",user表积分为:"+beforeUserCredits);
Long subCredits = 60l;
Response doStartResponse = newGameService.doStartForCoin("31347","z0eyz5d3",uid2,String.valueOf(subCredits));
String startSuccess = MatcherString.getString(doStartResponse.asString(),"\"success\": (.*?),",1);
String ticketId = MatcherString.getString(doStartResponse.asString(),"\"ticketId\": \"(.*?)\",",1);
Assert.assertEquals(startSuccess,"true","dostart接口执行失败");
//校验扣除的实际积分值
Assert.assertEquals(MatcherString.getString(doStartResponse.asString(),"\"credits\": (.*?),",1),String.valueOf(subCredits),"dostart接口执行失败");
logger.info("用户参加活动扣除积分值:"+subCredits);
Response statusResponse = this.getOrderStatus(uid2,ticketId);
Assert.assertEquals(MatcherString.getString(statusResponse.asString(),"\"success\": (.*?),",1),"true","getStartStatus接口执行失败");
Assert.assertEquals(MatcherString.getString(statusResponse.asString(),"\"message\": \"(.*?)\"",1),"处理成功","获取状态成功");
//推币机游戏无回收率, 则最高退回的积分值为兑换的积分值
//大盘回收率1%,只要回收的值有大于1%则用户可以赚钱积分
Long creditsUpperLimit = Long.valueOf(MatcherString.getString(statusResponse.asString(),"\"creditsUpperLimit\": (.*?),",1));
Assert.assertEquals(creditsUpperLimit,subCredits,"获取状态成功");
logger.info("最大换回积分值creditsUpperLimit="+creditsUpperLimit+"不能超过兑换积分值,校验成功");
//提交换回的金币
Long addCredits = 50L;
Response submitResponse = newGameService.submitForCoin(ticketId,String.valueOf(addCredits),uid2);
String orderId = MatcherString.getString(submitResponse.asString(),"\"orderId\": (.*?),",1);
String submitResponseCredits = MatcherString.getString(submitResponse.asString(),"\"credits\": (.*?),",1);
logger.info("活动结束用户换回积分值:"+addCredits);
logger.info("submit之后用户积分值:"+submitResponseCredits);
Thread.sleep(20000);
//活动结束后用户积分值
Map<String,Object> consumerInfo1 = jdbc.findSimpleResult("select * from new_consumer.consumer_0010 where id = ?\n",consumerId2);
String afterCondumerCredits = consumerInfo1.get("credits").toString();
Map<String,Object> userInfo1 = jdbc.findSimpleResult("select * from dafuweng.user where id = ?\n",uid2);
String afterUserCredits = userInfo1.get("credits").toString();
logger.info("用户参加活动,consumer表积分为:"+afterCondumerCredits+",user表积分为:"+afterUserCredits);
String except = String.valueOf(beforeUserCredits-subCredits+addCredits);
logger.info("except积分值为:"+except);
Assert.assertEquals(afterUserCredits,except,"积分换回校验失败");
logger.info("积分换回成功"+"\nbeforeUserCredits="+beforeUserCredits+"\nafterUserCredits="+afterUserCredits);
this.tearDown("2947",consumerId2);
}
public Response getOrderStatus(Integer uid,String ticketId) throws Exception{
Response statusResponse = newGameService.getStartStatusForCoin(ticketId,uid);
statusResponse.prettyPrint();
String statusSuccess = MatcherString.getString(statusResponse.asString(),"\"success\": (.*?),",1);
String message = MatcherString.getString(statusResponse.asString(),"\"message\": \"(.*?)\"",1);
int j=8;
while (j>0&&((!checkNomal("getStartStatus",statusResponse))||(message.equals("处理中")))){
Thread.sleep(1000);
statusResponse = newGameService.getStartStatusForCoin(ticketId,uid);
statusResponse.prettyPrint();
message = MatcherString.getString(statusResponse.asString(),"\"message\": \"(.*?)\"",1);
j--;
}
// logger.info("statusResponse的信息为"+ statusResponse.asString());
return statusResponse;
}
public Response getSubmitResult(String orderId,Integer uid) throws Exception{
Response submitResultResponse = newGameService.getSubmitResult(orderId,uid);
String flag = MatcherString.getString(submitResultResponse.asString(),"\"flag\": (\\D{4})",1);
for(int z=0;z<8;z++){
if ((flag.equals("true"))){
submitResultResponse = newGameService.getSubmitResult(orderId,uid);
submitResultResponse.prettyPrint();
flag = MatcherString.getString(submitResultResponse.asString(),"\"flag\": (\\D{4})",1);
String optionName = MatcherString.getString(submitResultResponse.asString(),"\"name\": \"(.*?)\",",1);
for (int k=0;k<8;k++){
if (optionName.isEmpty()){
submitResultResponse = newGameService.getSubmitResult(orderId,uid);
submitResultResponse.prettyPrint();
optionName = MatcherString.getString(submitResultResponse.asString(),"\"name\": \"(.*?)\",",1);
}
}
}
}
// logger.info("submitResultResponse的信息为"+submitResultResponse.asString());
return submitResultResponse;
}
public Boolean checkNomal(String api,Response response) {
Boolean isNomal = false;
String title = MatcherString.getString(response.asString(),"<div class=\"title\">(.*?)</div>",1);
if (title.equals("当前网络貌似出了点问题")){
logger.info(api+"接口调用异常,重新调用"+"错误信息为"+title);
return isNomal;
}else {
isNomal = true;
}
return isNomal;
}
public void tearDown(String gameId,String consumerId) {
try {
Boolean result1 = jdbc.update("update ngame.ngame_consumer_record set auto_open_prize_id = '' where duiba_ngame_id = ? and consumer_id = ?\n",gameId,consumerId);
} catch (Exception e) {
e.printStackTrace();
}
}
}
\ No newline at end of file
/**
* Copyright (C), 2015-2018
* FileName: 游戏_推币机换回超过可兑换上限测试_AccessTest
* Author: qianwenjun
* Date: 2018/9/3 11:48
* Description:
*/
package http.cases.GameTest;
import base.DuibaLog;
import base.DuibaTestBase;
import com.alibaba.fastjson.JSONObject;
import http.service.Activity.NewGameService;
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/9/3
* @since 1.0.0
*/
public class 游戏_推币机换回超过可兑换上限测试_AccessTest extends DuibaTestBase {
@Autowired
NewGameService newGameService;
private static DuibaLog logger = DuibaLog.getLogger();
private static final Integer uid_Nomal = 2708;
private static final String consumerId = "100011623";
private static final Integer uid1 = 3645;
private static final String consumerId1 = "100084020";
private static final Integer uid2 = 3646;
private static final String consumerId2 = "100084021";
private static final Integer uid3 = 3647;
private static final String consumerId3 = "100084022";
private static final Integer uid4 = 3648;
private static final String consumerId4 = "100084023";
@Test(description = "换回值超过可换回上限,兑换失败")
public void 推币机游戏_换回超过可兑换上限测试() throws Exception{
//参加前清掉未结算的订单数据
Boolean result = jdbc.update("delete from ngame.ngame_orders where operating_activity_id = '31345' and order_status = '1' \n");
Boolean result2 = jdbc.update("delete from ngame_con.ngame_orders_0311 where operating_activity_id = '31345' and order_status = '1' and order_status = '3'\n");
//参加前活动用户积分值
// Response consumerCredits = newGameService.getCredits(uid4);
// consumerCredits.prettyPrint();
// Long beforeCredits = Long.valueOf(consumerCredits.jsonPath().getString("data.credits"));
Map<String,Object> consumerInfo = jdbc.findSimpleResult("select * from new_consumer.consumer_0010 where id = ?\n",consumerId4);
Long beforeCondumerCredits = Long.valueOf(consumerInfo.get("credits").toString());
Map<String,Object> userInfo = jdbc.findSimpleResult("select * from dafuweng.user where id = ?\n",uid4);
Long beforeUserCredits = Long.valueOf(userInfo.get("credits").toString());
logger.info("用户参加活动,consumer表积分为:"+beforeCondumerCredits+",user表积分为:"+beforeUserCredits);
Long subCredits = 60l;
Response doStartResponse = newGameService.doStartForCoin("31345","z0eyz5d3",uid4,String.valueOf(subCredits));
String startSuccess = MatcherString.getString(doStartResponse.asString(),"\"success\": (.*?),",1);
String ticketId = MatcherString.getString(doStartResponse.asString(),"\"ticketId\": \"(.*?)\",",1);
Assert.assertEquals(startSuccess,"true","dostart接口执行失败");
//校验扣除的实际积分值
Assert.assertEquals(MatcherString.getString(doStartResponse.asString(),"\"credits\": (.*?),",1),String.valueOf(subCredits),"dostart接口执行失败");
logger.info("用户参加活动扣除积分值:"+subCredits);
Response statusResponse = this.getOrderStatus(uid4,ticketId);
Assert.assertEquals(MatcherString.getString(statusResponse.asString(),"\"success\": (.*?),",1),"true","getStartStatus接口执行失败");
Assert.assertEquals(MatcherString.getString(statusResponse.asString(),"\"message\": \"(.*?)\"",1),"处理成功","获取状态成功");
//推币机游戏无回收率, 则最高退回的积分值为兑换的积分值
//大盘回收率1%,只要回收的值有大于1%则用户可以赚钱积分
Long creditsUpperLimit = Long.valueOf(MatcherString.getString(statusResponse.asString(),"\"creditsUpperLimit\": (.*?),",1));
Assert.assertEquals(creditsUpperLimit,subCredits,"获取状态成功");
logger.info("最大换回积分值creditsUpperLimit="+creditsUpperLimit+"不能超过兑换积分值,校验成功");
//提交换回的金币
Long addCredits = creditsUpperLimit + 50L;
Response submitResponse = newGameService.submitForCoin2(ticketId,String.valueOf(addCredits),uid4);
submitResponse.prettyPrint();
Assert.assertEquals(MatcherString.getString(submitResponse.asString(),"\"success\": (.*?),",1),"false","getStartStatus接口执行失败");
Assert.assertEquals(MatcherString.getString(submitResponse.asString(),"\"desc\": \"(.*?)\",",1),"结算失败","getStartStatus接口执行失败");
Assert.assertEquals(MatcherString.getString(submitResponse.asString(),"\"code\": \"(.*?)\",",1),"100000","getStartStatus接口执行失败");
logger.info("活动结束用户换回积分值:"+addCredits);
Map<String,Object> ngameOrder = jdbc.findSimpleResult("select * from ngame_con.ngame_orders_0311 where id = ?\n",ticketId);
logger.info("ngameOrder的信息为:" +JSONObject.toJSONString(ngameOrder));
String orderStatus = ngameOrder.get("order_status").toString();
String score = ngameOrder.get("score").toString();
Assert.assertEquals(orderStatus,"1","订单状态校验失败");
Assert.assertTrue(score.isEmpty(),"校验结算失败分数字段为null失败");
Thread.sleep(20000);
//活动结束后用户积分值
Map<String,Object> consumerInfo1 = jdbc.findSimpleResult("select * from new_consumer.consumer_0010 where id = ?\n",consumerId4);
String afterCondumerCredits = consumerInfo1.get("credits").toString();
Map<String,Object> userInfo1 = jdbc.findSimpleResult("select * from dafuweng.user where id = ?\n",uid4);
String afterUserCredits = userInfo1.get("credits").toString();
logger.info("用户参加活动,consumer表积分为:"+afterCondumerCredits+",user表积分为:"+afterUserCredits);
String except = String.valueOf(beforeUserCredits-subCredits);
logger.info("except积分值为:"+except);
Assert.assertEquals(afterUserCredits,except,"积分换回校验失败");
logger.info("积分换回成功"+"\nbeforeUserCredits="+beforeUserCredits+"\nafterUserCredits="+afterUserCredits);
this.tearDown("2945",consumerId4);
}
public Response getOrderStatus(Integer uid,String ticketId) throws Exception{
Response statusResponse = newGameService.getStartStatusForCoin(ticketId,uid);
statusResponse.prettyPrint();
String statusSuccess = MatcherString.getString(statusResponse.asString(),"\"success\": (.*?),",1);
String message = MatcherString.getString(statusResponse.asString(),"\"message\": \"(.*?)\"",1);
int j=8;
while (j>0&&((!checkNomal("getStartStatus",statusResponse))||(message.equals("处理中")))){
Thread.sleep(1000);
statusResponse = newGameService.getStartStatusForCoin(ticketId,uid);
statusResponse.prettyPrint();
message = MatcherString.getString(statusResponse.asString(),"\"message\": \"(.*?)\"",1);
j--;
}
// logger.info("statusResponse的信息为"+ statusResponse.asString());
return statusResponse;
}
public Response getSubmitResult(String orderId,Integer uid) throws Exception{
Response submitResultResponse = newGameService.getSubmitResult(orderId,uid);
String flag = MatcherString.getString(submitResultResponse.asString(),"\"flag\": (\\D{4})",1);
for(int z=0;z<8;z++){
if ((flag.equals("true"))){
submitResultResponse = newGameService.getSubmitResult(orderId,uid);
submitResultResponse.prettyPrint();
flag = MatcherString.getString(submitResultResponse.asString(),"\"flag\": (\\D{4})",1);
String optionName = MatcherString.getString(submitResultResponse.asString(),"\"name\": \"(.*?)\",",1);
for (int k=0;k<8;k++){
if (optionName.isEmpty()){
submitResultResponse = newGameService.getSubmitResult(orderId,uid);
submitResultResponse.prettyPrint();
optionName = MatcherString.getString(submitResultResponse.asString(),"\"name\": \"(.*?)\",",1);
}
}
}
}
// logger.info("submitResultResponse的信息为"+submitResultResponse.asString());
return submitResultResponse;
}
public Boolean checkNomal(String api,Response response) {
Boolean isNomal = false;
String title = MatcherString.getString(response.asString(),"<div class=\"title\">(.*?)</div>",1);
if (title.equals("当前网络貌似出了点问题")){
logger.info(api+"接口调用异常,重新调用"+"错误信息为"+title);
return isNomal;
}else {
isNomal = true;
}
return isNomal;
}
public void tearDown(String gameId,String consumerId) {
try {
Boolean result1 = jdbc.update("update ngame.ngame_consumer_record set auto_open_prize_id = '' where duiba_ngame_id = ? and consumer_id = ?\n",gameId,consumerId);
} catch (Exception e) {
e.printStackTrace();
}
}
}
\ No newline at end of file
/**
* Copyright (C), 2015-2018
* FileName: 游戏_推币机换回超过可兑换上限测试_AccessTest
* Author: qianwenjun
* Date: 2018/9/3 11:48
* Description:
*/
package http.cases.GameTest;
import base.DuibaLog;
import base.DuibaTestBase;
import http.service.Activity.NewGameService;
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/9/3
* @since 1.0.0
*/
public class 游戏_推币机无回收率测试_AccessTest extends DuibaTestBase {
@Autowired
NewGameService newGameService;
private static DuibaLog logger = DuibaLog.getLogger();
private static final Integer uid_Nomal = 2708;
private static final String consumerId = "100011623";
private static final Integer uid1 = 3645;
private static final String consumerId1 = "100084020";
private static final Integer uid2 = 3646;
private static final String consumerId2 = "100084021";
private static final Integer uid3 = 3647;
private static final String consumerId3 = "100084022";
private static final Integer uid4 = 3648;
private static final String consumerId4 = "100084023";
@Test
public void 游戏_推币机无回收率测试() throws Exception{
//参加前活动用户积分值
// Response consumerCredits = newGameService.getCredits(uid3);
// consumerCredits.prettyPrint();
// Long beforeCredits = Long.valueOf(consumerCredits.jsonPath().getString("data.credits"));
Map<String,Object> consumerInfo = jdbc.findSimpleResult("select * from new_consumer.consumer_0010 where id = ?\n",consumerId3);
Long beforeCondumerCredits = Long.valueOf(consumerInfo.get("credits").toString());
Map<String,Object> userInfo = jdbc.findSimpleResult("select * from dafuweng.user where id = ?\n",uid3);
Long beforeUserCredits = Long.valueOf(userInfo.get("credits").toString());
logger.info("用户参加活动,consumer表积分为:"+beforeCondumerCredits+",user表积分为:"+beforeUserCredits);
Long subCredits = 60l;
Response doStartResponse = newGameService.doStartForCoin("31345","z0eyz5d3",uid3,String.valueOf(subCredits));
String startSuccess = MatcherString.getString(doStartResponse.asString(),"\"success\": (.*?),",1);
String ticketId = MatcherString.getString(doStartResponse.asString(),"\"ticketId\": \"(.*?)\",",1);
Assert.assertEquals(startSuccess,"true","dostart接口执行失败");
//校验扣除的实际积分值
Assert.assertEquals(MatcherString.getString(doStartResponse.asString(),"\"credits\": (.*?),",1),String.valueOf(subCredits),"dostart接口执行失败");
logger.info("用户参加活动扣除积分值:"+subCredits);
Response statusResponse = this.getOrderStatus(uid3,ticketId);
Assert.assertEquals(MatcherString.getString(statusResponse.asString(),"\"success\": (.*?),",1),"true","getStartStatus接口执行失败");
Assert.assertEquals(MatcherString.getString(statusResponse.asString(),"\"message\": \"(.*?)\"",1),"处理成功","获取状态成功");
//推币机游戏无回收率, 则最高退回的积分值为兑换的积分值
Long creditsUpperLimit = Long.valueOf(MatcherString.getString(statusResponse.asString(),"\"creditsUpperLimit\": (.*?),",1));
Assert.assertEquals(creditsUpperLimit,subCredits,"获取状态成功");
logger.info("最大换回积分值creditsUpperLimit="+creditsUpperLimit+"不能超过兑换积分值,校验成功");
//提交换回的金币
Long addCredits = 10L;
Response submitResponse = newGameService.submitForCoin(ticketId,String.valueOf(addCredits),uid3);
String orderId = MatcherString.getString(submitResponse.asString(),"\"orderId\": (.*?),",1);
String submitResponseCredits = MatcherString.getString(submitResponse.asString(),"\"credits\": (.*?),",1);
logger.info("活动结束用户换回积分值:"+addCredits);
logger.info("submit之后用户积分值:"+submitResponseCredits);
Thread.sleep(20000);
//活动结束后用户积分值
Map<String,Object> consumerInfo1 = jdbc.findSimpleResult("select * from new_consumer.consumer_0010 where id = ?\n",consumerId3);
String afterCondumerCredits = consumerInfo1.get("credits").toString();
Map<String,Object> userInfo1 = jdbc.findSimpleResult("select * from dafuweng.user where id = ?\n",uid3);
String afterUserCredits = userInfo1.get("credits").toString();
logger.info("用户参加活动,consumer表积分为:"+afterCondumerCredits+",user表积分为:"+afterUserCredits);
String except = String.valueOf(beforeUserCredits-subCredits+addCredits);
logger.info("except积分值为:"+except);
Assert.assertEquals(afterUserCredits,except,"积分换回校验失败");
logger.info("积分换回成功"+"\nbeforeUserCredits="+beforeUserCredits+"\nafterUserCredits="+afterUserCredits);
this.tearDown("2945",consumerId3);
}
public Response getOrderStatus(Integer uid,String ticketId) throws Exception{
Response statusResponse = newGameService.getStartStatusForCoin(ticketId,uid);
statusResponse.prettyPrint();
String statusSuccess = MatcherString.getString(statusResponse.asString(),"\"success\": (.*?),",1);
String message = MatcherString.getString(statusResponse.asString(),"\"message\": \"(.*?)\"",1);
int j=8;
while (j>0&&((!checkNomal("getStartStatus",statusResponse))||(message.equals("处理中")))){
Thread.sleep(1000);
statusResponse = newGameService.getStartStatusForCoin(ticketId,uid);
statusResponse.prettyPrint();
message = MatcherString.getString(statusResponse.asString(),"\"message\": \"(.*?)\"",1);
j--;
}
// logger.info("statusResponse的信息为"+ statusResponse.asString());
return statusResponse;
}
public Response getSubmitResult(String orderId,Integer uid) throws Exception{
Response submitResultResponse = newGameService.getSubmitResult(orderId,uid);
String flag = MatcherString.getString(submitResultResponse.asString(),"\"flag\": (\\D{4})",1);
for(int z=0;z<8;z++){
if ((flag.equals("true"))){
submitResultResponse = newGameService.getSubmitResult(orderId,uid);
submitResultResponse.prettyPrint();
flag = MatcherString.getString(submitResultResponse.asString(),"\"flag\": (\\D{4})",1);
String optionName = MatcherString.getString(submitResultResponse.asString(),"\"name\": \"(.*?)\",",1);
for (int k=0;k<8;k++){
if (optionName.isEmpty()){
submitResultResponse = newGameService.getSubmitResult(orderId,uid);
submitResultResponse.prettyPrint();
optionName = MatcherString.getString(submitResultResponse.asString(),"\"name\": \"(.*?)\",",1);
}
}
}
}
// logger.info("submitResultResponse的信息为"+submitResultResponse.asString());
return submitResultResponse;
}
public Boolean checkNomal(String api,Response response) {
Boolean isNomal = false;
String title = MatcherString.getString(response.asString(),"<div class=\"title\">(.*?)</div>",1);
if (title.equals("当前网络貌似出了点问题")){
logger.info(api+"接口调用异常,重新调用"+"错误信息为"+title);
return isNomal;
}else {
isNomal = true;
}
return isNomal;
}
// @AfterClass
public void tearDown(String gameId,String consumerId) {
try {
Boolean result1 = jdbc.update("update ngame.ngame_consumer_record set auto_open_prize_id = '' where duiba_ngame_id = ? and consumer_id = ?\n",gameId,consumerId);
} catch (Exception e) {
e.printStackTrace();
}
}
}
\ No newline at end of file
/**
* Copyright (C), 2015-2018
* FileName: 游戏_参加游戏测试_AccessTest
* Author: qianwenjun
* Date: 2018/5/1 18:24
* Description: doStart异常场景测试
*/
package http.cases.GameTest;
import base.DuibaLog;
import base.DuibaTestBase;
import http.service.Activity.ManagerService;
import http.service.Activity.NewGameService;
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.test.context.ContextConfiguration;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
import utils.MatcherString;
import java.util.HashMap;
import java.util.Map;
import static io.restassured.RestAssured.given;
/**
* 〈doStart异常场景测试〉
*
* @author qianwenjun
* @create 2018/5/1
* @since 1.0.0
*/
public class 游戏_用户达到每日限制参加_AccessTest extends DuibaTestBase {
@Autowired
ManagerService managerService;
@Autowired
NewGameService newGameService;
@Autowired
Authorization authorization;
@Value("${activity.host}")
String activityHost;//http://activity.m.duibatest.com.cn
private DuibaLog logger = DuibaLog.getLogger();
private static final Integer uid_Nomal = 2708;
// private static final Integer uid_Nomal = 3792;//调试
private static final Integer uid_LackIntgral = 3087;
private static final Integer uid_SubCredits = 3280;
private static final String consumerId_Nomal = "100011623";
private static final String consumerId_SubCredits = "100060071";
@Test
public void 游戏_用户达到每日次数限制参加测试() throws Exception{
Response response = newGameService.getInfoResult("31380",uid_Nomal);
if (response.jsonPath().getString("data.status.code").equals("0")){
this.playGame("31380","z0eyz5d3","88",uid_Nomal);
response = newGameService.getInfoResult("31380",uid_Nomal);
}
logger.info("获取游戏信息接口的返回如下:");
logger.info("success="+response.jsonPath().getString("success")+";btnDisable="+response.jsonPath().getString("data.status.btnDisable")
+";code="+response.jsonPath().getString("data.status.code")+";text="+response.jsonPath().getString("data.status.text"));
Assert.assertEquals(response.jsonPath().getString("success"),"true","getInfo接口执行失败");
// Assert.assertEquals(response.jsonPath().getString("data.consumerId"),"100011623","consumerId信息校验失败");
Assert.assertEquals(response.jsonPath().getString("data.status.btnDisable"),"true","btnDisable信息校验失败");
Assert.assertEquals(response.jsonPath().getString("data.status.btnText"),"明天再玩吧","btnText信息校验失败");
Assert.assertEquals(response.jsonPath().getString("data.status.code"),"3","code信息校验失败");
Assert.assertEquals(response.jsonPath().getString("data.status.text"),"游戏次数已用完","text信息校验失败");
String doStartUrl = activityHost + "/ngapi/dostart";
Map<String,Object> map = new HashMap<>();
map.put("id", "31380");
map.put("token","z0eyz5d3");
Response doStartResponse = given().cookies(authorization.dafuwengLogin(uid_Nomal,true)).params(map).post(doStartUrl);
logger.info("达到限制后参加游戏的结果如下:");
logger.info("success="+doStartResponse.jsonPath().getString("success")+";message="+doStartResponse.jsonPath().getString("message"));
Assert.assertEquals(doStartResponse.jsonPath().getString("success"),"false");
Assert.assertEquals(doStartResponse.jsonPath().getString("message"),"今日游戏次数已用完","错误信息校验失败");
logger.info("校验success和message成功,success="+doStartResponse.jsonPath().getString("success")+",message="+doStartResponse.jsonPath().getString("message"));
}
public Response playGame(String activityId, String token, String score, Integer uid) throws Exception{
Response doStartResponse = newGameService.doStart(activityId,token,uid);
// doStartResponse.prettyPrint();
// logger.info("doStartResponse的结果为="+doStartResponse.prettyPrint());
String ticketId = MatcherString.getString(doStartResponse.asString(),"\"ticketId\": \"(.*?)\",",1);
String doStartResponseSuccess = MatcherString.getString(doStartResponse.asString(),"\"success\": (.*?),",1);
Assert.assertEquals(doStartResponseSuccess,"true","dostart接口执行失败");
Response statusResponse = newGameService.getStartStatus(ticketId,uid);
statusResponse.prettyPrint();
String statusResponseSuccess = MatcherString.getString(statusResponse.asString(),"\"success\": (.*?),",1);
Assert.assertEquals(statusResponseSuccess,"true","getStartStatus接口执行失败");
String message = MatcherString.getString(statusResponse.asString(),"\"message\": \"(.*?)\"",1);
int i= 5;
while(i>0&&(message.equals("处理中"))){
Thread.sleep(1000);
statusResponse = newGameService.getStartStatus(ticketId,uid);
message = String.valueOf(statusResponse.jsonPath().getString("message"));
i--;
}
Assert.assertEquals(statusResponse.jsonPath().getString("message"),"处理成功","获取状态成功");
Response submitResponse = newGameService.submit(ticketId,score,uid);
submitResponse.prettyPrint();
String submitResponseSuccess = MatcherString.getString(submitResponse.asString(),"\"success\": (.*?),",1);
Assert.assertEquals(submitResponseSuccess,"true","submit接口执行失败");
String orderId = MatcherString.getString(submitResponse.asString(),"\"orderId\": (.*?),",1);
Response submitResultResponse = newGameService.getSubmitResult(orderId,uid);
submitResultResponse.prettyPrint();
String submitResultResponseSuccess = MatcherString.getString(submitResultResponse.asString(),"\"success\": (.*?),",1);
Assert.assertEquals(submitResultResponseSuccess,"true","getSubmitResult接口执行失败");
String flag = MatcherString.getString(submitResultResponse.asString(),"\"flag\": (\\D{4})",1);
for(int j=0;j<8;j++){
if ((flag.equals("true"))){
submitResultResponse = newGameService.getSubmitResult(orderId,uid);
submitResultResponse.prettyPrint();
flag = MatcherString.getString(submitResultResponse.asString(),"\"flag\": (\\D{4})",1);
// logger.info("submitResultResponse.asString()="+submitResultResponse.asString());
}
// logger.info("submitResultResponse.asString()="+submitResultResponse.asString());
}
return submitResultResponse;
}
@AfterClass
public void tearDown() {
try {
Boolean result = jdbc.update("update ngame.ngame_consumer_record set auto_open_prize_id = '' where consumer_id = ? and duiba_ngame_id = '2953'\n",consumerId_Nomal);
Boolean result1 = jdbc.update("update ngame.ngame_consumer_record set auto_open_prize_id = '' where consumer_id = ? and duiba_ngame_id = '2953'\n",consumerId_SubCredits);
} catch (Exception e) {
e.printStackTrace();
}
}
}
\ No newline at end of file
/**
* Copyright (C), 2015-2018
* FileName: 游戏_参加游戏测试_AccessTest
* Author: qianwenjun
* Date: 2018/5/1 18:24
* Description: doStart异常场景测试
*/
package http.cases.GameTest;
import com.duiba.qa.duiba.common.DuibaConfig;
import com.duiba.qa.duiba.common.DuibaTestBase;
import com.duiba.qa.duiba.service.Activity.ManagerService;
import com.duiba.qa.duiba.service.Activity.NewGameService;
import com.duiba.qa.duiba.service.Authorization;
import com.duiba.qa.duiba.utils.MatcherString;
import com.duiba.qa.publics.util.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.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
import java.util.HashMap;
import java.util.Map;
import static io.restassured.RestAssured.given;
/**
* 〈doStart异常场景测试〉
*
* @author qianwenjun
* @create 2018/5/1
* @since 1.0.0
*/
@ContextConfiguration(classes = DuibaConfig.class)
public class 游戏_用户达到永久限制参加_AccessTest extends DuibaTestBase{
@Autowired
ManagerService managerService;
@Autowired
NewGameService newGameService;
@Autowired
Authorization authorization;
@Value("${activity.host}")
String activityHost;//http://activity.m.duibatest.com.cn
private DuibaLog logger = DuibaLog.getLogger();
private static final Integer uid_Nomal = 2708;
private static final Integer uid_LackIntgral = 3086;
private static final Integer uid_SubCredits = 3280;
private static final String consumerId_Nomal = "100011623";
private static final String consumerId_SubCredits = "100060071";
@Test
public void 游戏_用户达到永久次数限制参加测试() {
String doStartUrl = activityHost + "/ngapi/dostart";
Map<String,Object> map = new HashMap<>();
map.put("id", "31379");
map.put("token","z0eyz5d3");
Response doStartResponse = given().cookies(authorization.dafuwengLogin(uid_Nomal,true)).params(map).post(doStartUrl);
// doStartResponse.prettyPrint();
Assert.assertEquals(doStartResponse.jsonPath().getString("success"),"false");
Assert.assertEquals(doStartResponse.jsonPath().getString("message"),"游戏次数已用完","错误信息校验失败");
logger.info("校验success和message成功,success="+doStartResponse.jsonPath().getString("success")+",message="+doStartResponse.jsonPath().getString("message"));
}
public Response playGame(String activityId, String token, String score, Integer uid) throws Exception{
Response doStartResponse = newGameService.doStart(activityId,token,uid);
doStartResponse.prettyPrint();
String ticketId = MatcherString.getString(doStartResponse.asString(),"\"ticketId\": \"(.*?)\",",1);
String doStartResponseSuccess = MatcherString.getString(doStartResponse.asString(),"\"success\": (.*?),",1);
Assert.assertEquals(doStartResponseSuccess,"true","dostart接口执行失败");
Response statusResponse = newGameService.getStartStatus(ticketId,uid);
statusResponse.prettyPrint();
String statusResponseSuccess = MatcherString.getString(statusResponse.asString(),"\"success\": (.*?),",1);
Assert.assertEquals(statusResponseSuccess,"true","getStartStatus接口执行失败");
String message = MatcherString.getString(statusResponse.asString(),"\"message\": \"(.*?)\"",1);
int i= 5;
while(i>0&&(message.equals("处理中"))){
Thread.sleep(1000);
statusResponse = newGameService.getStartStatus(ticketId,uid);
message = String.valueOf(statusResponse.jsonPath().getString("message"));
i--;
}
Assert.assertEquals(statusResponse.jsonPath().getString("message"),"处理成功","获取状态成功");
Response submitResponse = newGameService.submit(ticketId,score,uid);
submitResponse.prettyPrint();
String submitResponseSuccess = MatcherString.getString(submitResponse.asString(),"\"success\": (.*?),",1);
Assert.assertEquals(submitResponseSuccess,"true","submit接口执行失败");
String orderId = MatcherString.getString(submitResponse.asString(),"\"orderId\": (.*?),",1);
Response submitResultResponse = newGameService.getSubmitResult(orderId,uid);
submitResultResponse.prettyPrint();
String submitResultResponseSuccess = MatcherString.getString(submitResultResponse.asString(),"\"success\": (.*?),",1);
Assert.assertEquals(submitResultResponseSuccess,"true","getSubmitResult接口执行失败");
String flag = MatcherString.getString(submitResultResponse.asString(),"\"flag\": (\\D{4})",1);
for(int j=0;j<8;j++){
if ((flag.equals("true"))){
submitResultResponse = newGameService.getSubmitResult(orderId,uid);
submitResultResponse.prettyPrint();
flag = MatcherString.getString(submitResultResponse.asString(),"\"flag\": (\\D{4})",1);
// logger.info("submitResultResponse.asString()="+submitResultResponse.asString());
}
// logger.info("submitResultResponse.asString()="+submitResultResponse.asString());
}
return submitResultResponse;
}
@AfterClass
public void tearDown() {
try {
Boolean result = jdbc.update("update ngame.ngame_consumer_record set auto_open_prize_id = '' where consumer_id = ? and duiba_ngame_id = '2952'\n",consumerId_Nomal);
Boolean result1 = jdbc.update("update ngame.ngame_consumer_record set auto_open_prize_id = '' where consumer_id = ? and duiba_ngame_id = '2952'\n",consumerId_SubCredits);
} catch (Exception e) {
e.printStackTrace();
}
}
}
\ No newline at end of file
/**
* Copyright (C), 2015-2018
* FileName: 游戏_获取游戏信息测试_AccessTest
* Author: qianwenjun
* Date: 2018/5/13 18:38
* Description:
*/
package http.cases.GameTest;
import base.DuibaLog;
import base.DuibaTestBase;
import http.service.Activity.NewGameService;
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;
/**
* 〈〉
*
* @author qianwenjun
* @create 2018/5/13
* @since 1.0.0
*/
public class 游戏_获取游戏信息测试_AccessTest extends DuibaTestBase {
@Autowired
NewGameService newGameService;
private static DuibaLog logger = DuibaLog.getLogger();
private static final Integer uid_Nomal = 2708;
private static final Integer uid_NoTimes = 3086;
private static final Integer uid_LackIntgral = 3086;
@Test
public void 游戏含免费次数_获取信息测试() {
Response response = newGameService.getInfoResult("20509",uid_Nomal);
Assert.assertEquals(response.jsonPath().getString("success"),"true","getInfo接口执行失败");
Assert.assertEquals(response.jsonPath().getString("data.consumerId"),"100011623","consumerId信息校验失败");
Assert.assertEquals(response.jsonPath().getString("data.status.btnDisable"),"false","btnDisable信息校验失败");
Assert.assertEquals(response.jsonPath().getString("data.status.btnText"),"开始游戏","btnText信息校验失败");
Assert.assertEquals(response.jsonPath().getString("data.status.code"),"0","code信息校验失败");
Assert.assertEquals(response.jsonPath().getString("data.status.text"),"100积分/次","text信息校验失败");
}
@Test
public void 游戏无免费次数_获取信息测试() {
Response response = newGameService.getInfoResult("20509",uid_NoTimes);
Assert.assertEquals(response.jsonPath().getString("success"),"true","getInfo接口执行失败");
Assert.assertEquals(response.jsonPath().getString("data.consumerId"),"100055733","consumerId信息校验失败");
Assert.assertEquals(response.jsonPath().getString("data.status.btnDisable"),"true","btnDisable信息校验失败");
Assert.assertEquals(response.jsonPath().getString("data.status.btnText"),"积分不足","btnText信息校验失败");
Assert.assertEquals(response.jsonPath().getString("data.status.code"),"2","code信息校验失败");
Assert.assertEquals(response.jsonPath().getString("data.status.text"),"100积分/次","text信息校验失败");
Response response1 = newGameService.getInfoResult("20509",uid_Nomal);
}
@Test
public void 游戏等待开奖页面_获取信息测试() {
Response response = newGameService.getInfoResult("22650",uid_Nomal);
Assert.assertEquals(response.jsonPath().getString("success"),"true","getInfo接口执行失败");
Assert.assertEquals(response.jsonPath().getString("data.consumerId"),"100011623","consumerId信息校验失败");
Assert.assertEquals(response.jsonPath().getString("data.status.btnDisable"),"true","btnDisable信息校验失败");
Assert.assertEquals(response.jsonPath().getString("data.status.btnText"),"等待开奖","btnText信息校验失败");
Assert.assertEquals(response.jsonPath().getString("data.status.code"),"4","code信息校验失败");
}
@Test
public void 游戏_获取index接口测试() {
Response response = newGameService.getIndexInfo("20509",uid_Nomal);
response.prettyPrint();
Assert.assertEquals(MatcherString.getString(response.asString(),"<title>(.*?)</title>\n",1),"【勿动】自动化-游戏_积分充足","游戏页面打开异常");
}
@Test
public void 游戏_预览测试() {
Response response = newGameService.preview("1338",uid_Nomal);
response.prettyPrint();
Assert.assertEquals(MatcherString.getString(response.asString(),"\"success\": (.*?),",1),"true","校验预览结果失败");
String url = MatcherString.getString(response.asString(),"\"url\": \"(.*?)\"",1);
Assert.assertTrue(url.contains("http://activity.m.duibatest.com.cn/autoLogin/autologin?appKey=jlg88lyxz7siqtmr&uid=duiba-preview-user"),"校验获取的链接失败");
String[] redirect = url.split("redirect=");
// logger.info("redirect的信息为" +redirect[1]);
Assert.assertTrue(String.valueOf(redirect[1]).contains("id%3D1338"),"校验重定向的活动id失败");
}
@Test
public void 游戏_开奖中页面信息测试() {
Response response = newGameService.getInfoResult("22650",uid_Nomal);
// response.prettyPrint();
Assert.assertEquals(response.jsonPath().getString("success"),"true","getInfo接口执行失败");
Assert.assertEquals(response.jsonPath().getString("data.consumerId"),"100011623","consumerId信息校验失败");
Assert.assertEquals(response.jsonPath().getString("data.status.btnDisable"),"true","btnDisable信息校验失败");
Assert.assertEquals(response.jsonPath().getString("data.status.btnText"),"等待开奖","btnText信息校验失败");
Assert.assertEquals(response.jsonPath().getString("data.status.code"),"4","code信息校验失败");
}
@Test
public void 游戏_积分不足首页信息测试() {
Response response = newGameService.getInfoResult("20509",uid_LackIntgral);
// response.prettyPrint();
Assert.assertEquals(response.jsonPath().getString("success"),"true","getInfo接口执行失败");
Assert.assertEquals(response.jsonPath().getString("data.consumerId"),"100055733","consumerId信息校验失败");
Assert.assertEquals(response.jsonPath().getString("data.status.btnDisable"),"true","btnDisable信息校验失败");
Assert.assertEquals(response.jsonPath().getString("data.status.btnText"),"积分不足","btnText信息校验失败");
Assert.assertEquals(response.jsonPath().getString("data.status.code"),"2","code信息校验失败");
}
@Test
public void 游戏_达到永久次数限制首页信息测试() {
Response response = newGameService.getInfoResult("31379",uid_Nomal);
// response.prettyPrint();
Assert.assertEquals(response.jsonPath().getString("success"),"true","getInfo接口执行失败");
Assert.assertEquals(response.jsonPath().getString("data.consumerId"),"100011623","consumerId信息校验失败");
Assert.assertEquals(response.jsonPath().getString("data.status.btnDisable"),"true","btnDisable信息校验失败");
Assert.assertEquals(response.jsonPath().getString("data.status.btnText"),"下次再玩吧","btnText信息校验失败");
Assert.assertEquals(response.jsonPath().getString("data.status.code"),"3","code信息校验失败");
Assert.assertEquals(response.jsonPath().getString("data.status.text"),"游戏次数已用完","text信息校验失败");
}
}
\ No newline at end of file
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