Commit 96cb313b authored by 赵然's avatar 赵然

zr

parent 98e1f910
......@@ -25,7 +25,7 @@ import org.testng.annotations.Test;
import java.util.Map;
public class 瓜分积分_作弊瓜分 extends DuibaTestBase {
public class 瓜分积分_作弊瓜分_AccessTest extends DuibaTestBase {
@Autowired
PkDevelopService pkDevelopService;
......
......@@ -27,7 +27,7 @@ import java.util.List;
import java.util.Map;
public class 瓜分积分_实际瓜分 extends DuibaTestBase {
public class 瓜分积分_实际瓜分_AccessTest extends DuibaTestBase {
@Autowired
PkDevelopService pkDevelopService;
......
/**
* Copyright (C), 2015-2018
* FileName: 瓜分积分测试_AccessTest
* Author: zhaoran
* Date: 2018/12/10 19:45
* Description:
*/
package http.cases.PkMoudleTest;
import base.DuibaLog;
import base.DuibaTestBase;
import com.alibaba.fastjson.JSONObject;
import http.service.Activity.PkService;
import http.service.Manager.PkActivityService;
import http.service.hd.PkDevelopService;
import io.restassured.response.Response;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.util.Map;
public class 瓜分积分_实际瓜分_主胜方_AccessTest extends DuibaTestBase {
@Autowired
PkDevelopService pkDevelopService;
@Autowired
PkService pkService;
@Autowired
PkActivityService pkActivityService;
private DuibaLog logger = DuibaLog.getLogger();
private static Integer uid1 = 5171;
private static Integer uid2 = 5172;
private static Integer uid3 = 5173;
private static String betId;
private static String optionId1;
private static String optionId2;
@Test
public void 创建PK活动() throws Exception{
Response response = pkDevelopService.betEditor_right("18157163293","21832","4",null,"1","30","false","true");
Assert.assertEquals(response.jsonPath().getString("desc"),"成功","创建组件化pk活动失败");
response = pkService.getBetList(uid1);
response.print();
int i= 30;
while(i>0&&(response.jsonPath().getString("data.unbetList").equals("[]"))){
Thread.sleep(5000);
response = pkService.getBetList(uid1);
response.print();
i--;
}
betId = response.jsonPath().getString("data.unbetList[0].betConfig.id");
optionId1 = response.jsonPath().getString("data.unbetList[0].options[0].optionId");
optionId2 = response.jsonPath().getString("data.unbetList[0].options[1].optionId");
if(betId.equals(null)){
throw new Exception("楼层查询pk组件活动失败!");
}else {
logger.info("pk活动id 为:" + betId + ",投注id1为:" + optionId1 + ",投注id2为:" + optionId2);
}
}
@Test(dependsOnMethods = { "创建PK活动" })
public void 投注() throws Exception {
//查询数据库,投注前积分(抽奖扣积分流程校验)
Map<String,Object> mapuser1 = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid1);
Map<String,Object> mapuser2 = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid2);
Map<String,Object> mapuser3 = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid3);
String credits1 = String.valueOf(mapuser1.get("credits"));
String credits2 = String.valueOf(mapuser2.get("credits"));
String credits3 = String.valueOf(mapuser3.get("credits"));
logger.info("用户1投注前积分:"+credits1);
logger.info("用户2投注前积分:"+credits2);
logger.info("用户3投注前积分:"+credits3);
//扣去1积分
credits1 = String.valueOf(Integer.valueOf(credits1)-1);
credits2 = String.valueOf(Integer.valueOf(credits2)-1);
credits3 = String.valueOf(Integer.valueOf(credits3)-1);
Response res1 = pkService.doJoin(uid1,betId,optionId1);
Response res2 = pkService.doJoin(uid2,betId,optionId1);
Response res3 = pkService.doJoin(uid3,betId,optionId2);
//查询数据库,投注前积分(抽奖扣积分流程校验)
mapuser1 = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid1);
mapuser2 = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid2);
mapuser3 = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid3);
String credits4 = String.valueOf(mapuser1.get("credits"));
String credits5 = String.valueOf(mapuser2.get("credits"));
String credits6 = String.valueOf(mapuser3.get("credits"));
logger.info("用户1投注后积分:"+credits4);
logger.info("用户2投注后积分:"+credits5);
logger.info("用户3投注后积分:"+credits6);
Assert.assertEquals(credits4,credits1);
Assert.assertEquals(credits5,credits2);
Assert.assertEquals(credits6,credits3);
}
@Test(dependsOnMethods = { "投注" })
public void 开奖() throws Exception {
//查询数据库,开奖前积分
Map<String,Object> mapuser1 = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid1);
Map<String,Object> mapuser2 = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid2);
Map<String,Object> mapuser3 = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid3);
String credits1 = String.valueOf(mapuser1.get("credits"));
String credits2 = String.valueOf(mapuser2.get("credits"));
String credits3 = String.valueOf(mapuser3.get("credits"));
logger.info("用户1开奖前积分:"+credits1);
logger.info("用户2开奖前积分:"+credits2);
logger.info("用户3开奖前积分:"+credits3);
//增加积分: 30/(1+2)
credits3 = String.valueOf(Integer.valueOf(credits3)+6);
//修改开奖时间
this.modifyOpenPrizeTime(betId,60);
//调用开奖接口
Response doDrowRresponse = pkActivityService.doDraw();
Assert.assertEquals(doDrowRresponse.jsonPath().getString("success"),"true","开奖结果校验失败");
Assert.assertEquals(doDrowRresponse.jsonPath().getString("data"),"开奖中。。。","开奖messag校验失败");
Thread.sleep(8000);
//查询数据库,开奖后积分
mapuser1 = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid1);
mapuser2 = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid2);
mapuser3 = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid3);
String credits4 = String.valueOf(mapuser1.get("credits"));
String credits5 = String.valueOf(mapuser2.get("credits"));
String credits6 = String.valueOf(mapuser3.get("credits"));
logger.info("用户1开奖后积分:"+credits4);
logger.info("用户2开奖后积分:"+credits5);
logger.info("用户3开奖后积分:"+credits6);
Assert.assertEquals(credits4,credits1);
Assert.assertEquals(credits5,credits2);
Assert.assertEquals(credits6,credits3);
logger.info("投注者瓜分金额校验正确");
//校验点
//1、pk活动表配置的状态更新为4;2、订单表的addCredits字段为瓜分的红包值;3、先押注 的选项为胜方,胜负的额押注人数>负方的押注人数
Map<String,Object> betConfig = jdbc.findSimpleResult("select * from act_com_conf.tb_bet_config where id = ?",betId);
logger.info("betConfig的信息为:"+ JSONObject.toJSONString(betConfig));
Assert.assertEquals(betConfig.get("config_status").toString(),"4","配置表状态更新失败");
Map<String,Object> betGroupRelation = jdbc.findSimpleResult("select * from act_com_conf.tb_bet_group_relation where bet_id = ?\n",betId);
Assert.assertEquals(betGroupRelation.get("config_status").toString(),"4","pk关系表开奖状态更新失败");
logger.info("pk活动配置表状态更新为:"+betConfig.get("config_status").toString()+",pk关系表活动状态更新为:"+betGroupRelation.get("config_status").toString());
Map<String,Object> user01_order = jdbc.findSimpleResult("select * from activity_order_con.tb_trade_center_activity_order_0614 where consumer_id = '100114022' and duiba_activity_id = ?\n",betId);
Assert.assertEquals(user01_order.get("add_credits").toString(),"6","开奖后发奖值校验失败");
Map<String,Object> user02_order = jdbc.findSimpleResult("select * from activity_order_con.tb_trade_center_activity_order_0623 where consumer_id = '100114031' and duiba_activity_id = ?\n",betId);
Assert.assertEquals(user02_order.get("add_credits").toString(),"","开奖后发奖值校验失败");
logger.info("用户01获取的积分值为:"+user01_order.get("add_credits").toString()+",用户03获取的积分值为:"+user02_order.get("add_credits").toString());
Map<String,Object> bet1Result = jdbc.findSimpleResult("select * from bet_activity.tb_bet_result where bet_id = ? and option_id = ?\n",betId,optionId1);
Assert.assertEquals(bet1Result.get("rank").toString(),"2","开始押注的选项获胜校验失败");
Map<String,Object> bet2Result = jdbc.findSimpleResult("select * from bet_activity.tb_bet_result where bet_id = ? and option_id = ?\n",betId,optionId2);
Assert.assertEquals(bet2Result.get("rank").toString(),"1","开始押注的选项获胜校验失败");
Long bet1Times = Long.valueOf(bet1Result.get("bet_times").toString());
Long bet2Times = Long.valueOf(bet2Result.get("bet_times").toString());
Assert.assertTrue(bet1Times<bet2Times,"活动获胜人数比失败人数多校验失败");
logger.info("选项1的押注人数为:"+bet1Result.get("bet_times").toString()+",选项2的押注人数为:"+bet2Result.get("bet_times").toString());
}
public void modifyOpenPrizeTime(String betId,int x) throws Exception{
DateTime time1 = new DateTime();
// int x=20+(int)(Math.random()*100);
DateTime endTime = time1.minusMillis(x);
DateTimeFormatter format = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
// String endTimeStr = format.print(endTime.getMillis()).toString();
String endTimeStr = "2018-11-26 20:24:39";
logger.info("\ntime1="+ format.print(time1.getMillis())+"\n设置的开奖时间endTime="+ endTimeStr);
Boolean result1 = jdbc.update("update act_com_conf.tb_bet_config set end_time = ? where id = ?\n",endTimeStr,betId);
Boolean result2 = jdbc.update("update act_com_conf.tb_bet_group_relation set end_time = ? where bet_id = ?\n",endTimeStr,betId);
}
}
\ No newline at end of file
......@@ -27,7 +27,7 @@ import java.text.DecimalFormat;
import java.util.Map;
public class 瓜分红包_作弊瓜分 extends DuibaTestBase {
public class 瓜分红包_作弊瓜分_AccessTest extends DuibaTestBase {
@Autowired
PkDevelopService pkDevelopService;
......
......@@ -27,7 +27,7 @@ import java.text.DecimalFormat;
import java.util.Map;
public class 瓜分红包_实际瓜分 extends DuibaTestBase {
public class 瓜分红包_实际瓜分_AccessTest extends DuibaTestBase {
@Autowired
PkDevelopService pkDevelopService;
......
......@@ -56,6 +56,7 @@ public class Authorization {
private static Map<String,String> hdCookiesMabo;
private static Map<String,String> hdCookiesSaas;
private static Map<String,Map> hdCookiesSaasByApp = new ConcurrentHashMap<>();
private static Map<String,Map> hdCookiesSaasNew = new ConcurrentHashMap<>();
private static Map<String,Map> hdCookiesCommon = new ConcurrentHashMap<>();
private static Map<String,String> openbsCookies;
private Map<String,String> ssoCookies =null;
......@@ -241,6 +242,7 @@ public class Authorization {
return hdCookiesMabo;
}
//密码为wxs123456 (支持账号 wxs@duiba.com.cn,尽量不要用)
public Map hdLoginSaas(){
int i=10;
while((hdCookiesSaas==null||hdCookiesSaas.size()==0)&&i>0) {
......@@ -261,6 +263,7 @@ public class Authorization {
return hdCookiesSaas;
}
//密码为wxs123456 (支持 账号为wxs@duiba.com.cn 下的任意appId)
public Map hdLoginSaas(String appId){
int i=10;
logger.info("hdCookiesSaasByApp cookies:"+hdCookiesSaasByApp.toString());
......@@ -292,7 +295,44 @@ public class Authorization {
logger.info("hdCookiesSaasByApp cookies集合:"+hdCookiesSaasByApp.toString());
return hdCookies;
}
//密码为duibaduiba123
//密码为duibaduiba123(支持任意手机账号下的任意APPId)
public Map hdLoginSaasNew(String account,String appId){
String path = "/doLoginNew";
int i=10;
logger.info("hdCookiesSaasByApp cookies:"+hdCookiesSaasNew.toString());
Map<String,String> hdCookies = hdCookiesSaasNew.get(appId);
while((hdCookies==null||hdCookies.size()==0)&&i>0) {
Response token=this.hdGetToken();
String url = PROTOCOL + hdHost + path;
Map<String,String> cookies=token.getCookies();
Map<String, String> paras = new HashMap<>();
paras.put("account", account);
paras.put("password", SecurityUtils.getMD5("Dct7xTdGPvbUL1eOtSWoB9ySZNY="+from(token.asString()).getString("data.loginsToken")));
paras.put("redirect", "/redirectApp");
paras.put("isAutoLogin", "true");
paras.put("validate","22");
Response response = given().cookies(cookies).params(paras).post(url);
response.prettyPrint();
Map<String,String> map = response.getCookies();
logger.info("cookies:"+map.toString());
hdCookies=new HashMap<>(response.getCookies());
if(hdCookies!=null||hdCookies.size()!=0) {
//取消安全校验
hdCookies.remove("csrf_token");
hdCookies.put("appId", appId);
hdCookies.put("duibaAppId", appId);
logger.info("cookies2:"+hdCookies.toString());
hdCookiesSaasNew.put(appId,hdCookies);
}
i--;
}
logger.info("hdCookiesSaasByApp cookies集合:"+hdCookiesSaasNew.toString());
return hdCookies;
}
//密码为duibaduiba123 (支持任意邮箱账号)
public Map hdLoginCommon(String email){
int i=10;
Map<String,String> hdCookies = hdCookiesCommon.get(email);
......@@ -344,7 +384,6 @@ public class Authorization {
i--;
}
//取消安全校验
// logger.info(hdCookies);
return hdCookies;
}
......
......@@ -40,8 +40,6 @@ public class PkDevelopService {
@Autowired
Authorization authorization;
private DuibaLog logger = DuibaLog.getLogger();
public Response betEditor(String appId,String bonusType,String bonusAmount,String creditsValue,String shareExp) throws Exception{
String data = PublicMethod.data();
......@@ -100,6 +98,64 @@ public class PkDevelopService {
return betResponse;
}
public Response betEditor_right(String account,String appId,String bonusType,String bonusAmount,String creditsValue,String shareExp,String loser,String winner) throws Exception{
String data = PublicMethod.data();
String url = "http://" + hdHost + "/visual-editor/bet/post";
//创建投注项
List<BetOptionVo> betOptionVoList = new ArrayList<>();
BetOptionVo betOptionVo1 = new BetOptionVo();
BetOptionVo betOptionVo2 = new BetOptionVo();
betOptionVo1.setOptionImg("//yun.dui88.com/images/201812/75j84chnkg.jpg");
betOptionVo1.setOptionName("1");
betOptionVo1.setRightAnswer(loser);
betOptionVo2.setOptionImg("//yun.dui88.com/images/201812/4f51vmzfpu.png");
betOptionVo2.setOptionName("2");
betOptionVo2.setRightAnswer(winner);
betOptionVoList.add(betOptionVo1);
betOptionVoList.add(betOptionVo2);
//创建活动配置
List<BetDevelopVo> betDevelopVoList = new ArrayList<>();
BetDevelopVo betDevelopVo = new BetDevelopVo();
betDevelopVo.setBetOptionDtoList(betOptionVoList);
betDevelopVo.setBetType("1");
betDevelopVo.setBonusType(bonusType);
if (bonusType.equals("2")){
betDevelopVo.setTitle("【自动化】组件pk_瓜分红包"+data);
}else if (bonusType.equals("4")){
betDevelopVo.setTitle("【自动化】组件pk_瓜分积分"+data);
}
betDevelopVo.setBonusAmount(bonusAmount);
betDevelopVo.setConfigStatus("3");
betDevelopVo.setCreditsValue(creditsValue);
betDevelopVo.setEndTime("2029-12-31 00:00");
betDevelopVo.setShareExp(shareExp);
betDevelopVoList.add(betDevelopVo);
Map<String,Object> para = new HashMap<>();
para.put("list",betDevelopVoList);
para.put("rules","自动化规则自动化规则");
para.put("title","组件pk自动化_主胜方");
JSONObject jsonParam = JSONObject.parseObject(JSON.toJSONString(para));
Response betResponse = given().contentType("application/json;charset=UTF-8").cookies(authorization.hdLoginSaasNew(account,appId)).body(jsonParam).post(url);
betResponse.prettyPrint();
try{
Assert.assertEquals(betResponse.jsonPath().getString("success"),"true");
}catch(Exception e){
throw new Exception("创建pk活动接口失败,返回信息:"+betResponse.asString());
}catch(Error er){
throw new Exception("创建pk活动接口失败,返回信息:"+betResponse.asString());
}
return betResponse;
}
public Response doDraw() throws Exception{
String url = "http://" + ManagerHost + "/newmanager/betOpenPrize/doDraw";
Map<String,Object> para = new HashMap<>();
......
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