Commit 0296e0c9 authored by 钱雯君's avatar 钱雯君

Merge branch 'develop' into qwj_181029

parents 59a41de3 a4e80b31
package http.cases.DefinedActivityTest;
import com.alibaba.fastjson.JSON;
import base.DuibaTestBase;
import http.enums.ActivityDataTypeEnum;
import http.model.AwardVO;
import http.model.CustomHdToolVO;
import http.service.hd.CustomHdToolCtrlService;
import base.DuibaLog;
import io.restassured.response.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* Created by hubinbin on 2018/4/12.
*/
//@ContextConfiguration(classes = DuibaConfig.class)
public class 游戏前置开奖_创建游戏前置开奖活动_DuibaTest extends DuibaTestBase {
private DuibaLog logge1 = DuibaLog.getLogger();
@Autowired
CustomHdToolCtrlService customHdToolCtrlService;
long actId;
//@Test
public void 创建游戏前置开奖活动() throws Exception{
logger.info("创建游戏前置开奖活动");
CustomHdToolVO customHdToolVO = new CustomHdToolVO();
customHdToolVO.setActId(null);
customHdToolVO.setTitle("自动化游戏前置开奖"+ new Date().getTime());
customHdToolVO.setFacePrice("0.1");
customHdToolVO.setBrickId(422L);
customHdToolVO.setFactoryKey(ActivityDataTypeEnum.GAME.getKey());
AwardVO awardVO1 = AwardVO.谢谢参与();
AwardVO awardVO2 = AwardVO.幸运福袋();
AwardVO awardVO3 = AwardVO.支付宝充值(55,"支付宝充值","支付宝1元","100","1.0");
List<AwardVO> list = new ArrayList<AwardVO>();
list.add(awardVO1);
list.add(awardVO2);
list.add(awardVO3);
String awards = JSON.toJSONString(list);
logger.info("设置的奖品信息:"+awards);
customHdToolVO.setAwards(awards);
customHdToolVO.setRule("自动化-游戏前置开奖-龙抬头");
customHdToolVO.setSelectQuestions("[282]");
Response response = customHdToolCtrlService.saveOrEdit(customHdToolVO);
Assert.assertTrue(response.jsonPath().getBoolean("success"));
actId = response.jsonPath().getLong("data.actId"); //活动id
//校验
Map<String, Object> duibaHdToolMap = jdbc.findSimpleResult(" SELECT * FROM hdtool_conf.duiba_hdtool where id="+actId);
Assert.assertEquals(duibaHdToolMap.get("title"),customHdToolVO.getTitle());
Assert.assertEquals(Double.valueOf(duibaHdToolMap.get("credits_price").toString())/100,Double.valueOf(customHdToolVO.getFacePrice()));
Assert.assertEquals(duibaHdToolMap.get("duiba_brick_id"),customHdToolVO.getBrickId());
Assert.assertEquals(duibaHdToolMap.get("factory_key"),customHdToolVO.getFactoryKey());
Assert.assertEquals(duibaHdToolMap.get("free_rule"),customHdToolVO.getRule());
Assert.assertEquals(duibaHdToolMap.get("type"),6);
//答题活动的校验
if(customHdToolVO.getFactoryKey().equals(ActivityDataTypeEnum.QUESTION.getKey())) {
//自定义活动扩展信息校验
Map<String,Object> extendJsonOBJ = JSON.parseObject(duibaHdToolMap.get("extend_json").toString());
Assert.assertEquals(Integer.valueOf(extendJsonOBJ.get("question_num").toString()),customHdToolVO.getQuestionNum());
Assert.assertEquals(extendJsonOBJ.get("select_question_bank").toString(),customHdToolVO.getSelectQuestions());
}
}
@AfterClass
public void 清理数据() throws Exception{
jdbc.update("delete from hdtool_conf.duiba_hdtool where id="+actId);
logger.info("清理答题活动数据成功,活动id:"+actId);
}
}
package http.cases.DefinedActivityTest;
/**
* Created by hubinbin on 2018/4/12.
*/
public class 游戏前置开奖_手机端_DuibaTest {
public void 游戏前置开奖() {}
}
package http.cases.DefinedActivityTest;
import com.alibaba.fastjson.JSON;
import base.DuibaTestBase;
import com.duiba.qa.duiba.enums.ActivityDataTypeEnum;
import com.duiba.qa.duiba.model.AwardVO;
import com.duiba.qa.duiba.model.CustomHdToolVO;
import com.duiba.qa.duiba.service.hd.CustomHdToolCtrlService;
import base.DuibaLog;
import io.restassured.response.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* Created by hubinbin on 2018/4/3.
*/
//@ContextConfiguration(classes = DuibaConfig.class)
public class 答题_创建答题活动_DuibaTest extends DuibaTestBase {
private DuibaLog logge = DuibaLog.getLogger();
@Autowired
CustomHdToolCtrlService customHdToolCtrlService;
Long actId ;
@Test
public void 创建答题活动() throws Exception{
logger.info("创建答题活动");
CustomHdToolVO customHdToolVO = new CustomHdToolVO();
customHdToolVO.setActId(null);
customHdToolVO.setTitle("自动化答题"+ new Date().getTime());
customHdToolVO.setFacePrice("0.1");
customHdToolVO.setBrickId(95L);
customHdToolVO.setFactoryKey(ActivityDataTypeEnum.QUESTION.getKey());
AwardVO awardVO1 = AwardVO.谢谢参与();
AwardVO awardVO2 = AwardVO.幸运福袋();
AwardVO awardVO3 = AwardVO.答题题目数开奖设置奖品("coupon","答对2题优惠券","答对2题奖品",true,"2","答题自动化优惠券1",27183);
List<AwardVO> list = new ArrayList<AwardVO>();
list.add(awardVO1);
list.add(awardVO2);
list.add(awardVO3);
String awards = JSON.toJSONString(list);
logger.info("设置的奖品信息:"+awards);
customHdToolVO.setAwards(awards);
customHdToolVO.setQuestionNum(2);
customHdToolVO.setRule("自动化-答题-题目数出奖规则说明");
customHdToolVO.setSelectQuestions("[282]");
Response response = customHdToolCtrlService.saveOrEdit(customHdToolVO);
Assert.assertTrue(response.jsonPath().getBoolean("success"));
actId = response.jsonPath().getLong("data.actId"); //活动id
//校验
Map<String, Object> duibaHdToolMap = jdbc.findSimpleResult(" SELECT * FROM hdtool_conf.duiba_hdtool where id="+actId);
Assert.assertEquals(duibaHdToolMap.get("title"),customHdToolVO.getTitle());
Assert.assertEquals(Double.valueOf(duibaHdToolMap.get("credits_price").toString())/100,Double.valueOf(customHdToolVO.getFacePrice()));
Assert.assertEquals(duibaHdToolMap.get("duiba_brick_id"),customHdToolVO.getBrickId());
Assert.assertEquals(duibaHdToolMap.get("factory_key"),customHdToolVO.getFactoryKey());
Assert.assertEquals(duibaHdToolMap.get("free_rule"),customHdToolVO.getRule());
Assert.assertEquals(duibaHdToolMap.get("type"),6);
//自定义活动扩展信息校验
Map<String,Object> extendJsonOBJ = JSON.parseObject(duibaHdToolMap.get("extend_json").toString());
Assert.assertEquals(Integer.valueOf(extendJsonOBJ.get("question_num").toString()),customHdToolVO.getQuestionNum());
Assert.assertEquals(extendJsonOBJ.get("select_question_bank").toString(),customHdToolVO.getSelectQuestions());
}
@AfterClass
public void 清理数据() throws Exception{
jdbc.update("delete from hdtool_conf.duiba_hdtool where id="+actId);
logger.info("清理答题活动数据成功,活动id:"+actId);
}
}
package http.cases.DefinedActivityTest;
import base.Config;
import http.service.hd.ActivityCtrlService;
import io.restassured.response.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.Assert;
import org.testng.annotations.Test;
/**
* Created by hubinbin on 2018/4/4.
*/
@ContextConfiguration(classes = Config.class)
public class 答题_手机端出题_DuibaTest extends AbstractTestNGSpringContextTests {
@Autowired
ActivityCtrlService activityCtrlService;
@Test
public void 答题_手机端出题() {
String hdType = "duiba";
Long hdToolId = 3669L;
boolean preview= false;//是否预览模式
Long actId = 19543L;
Response response = activityCtrlService.ajaxElement(hdType,hdToolId,preview,actId);
Assert.assertTrue(response.jsonPath().getBoolean("success"));
Assert.assertEquals(response.jsonPath().getString("type"),"question");
}
}
package http.cases.DefinedActivityTest;
/**
* Created by hubinbin on 2018/3/29.
*/
public class 答题_概率抽奖_DuibaTest {
}
package http.cases.DefinedActivityTest;
import base.Config;
import http.service.hd.ActivityCtrlService;
import utils.ExcelDataProvider;
import base.DuibaLog;
import io.restassured.response.Response;
import org.springframework.beans.factory.annotation.Autowired;
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.Iterator;
import java.util.Map;
/**
* Created by hubinbin on 2018/3/29.
*/
@ContextConfiguration(classes = Config.class)
public class 答题_答对题数抽奖_DuibaTest extends AbstractTestNGSpringContextTests {
String token = null; //线下环境token直接传入null即可
String activityId = "19609";
private DuibaLog logger = DuibaLog.getLogger();
@Autowired
ActivityCtrlService activityCtrlService;
@Test(dataProvider = "答题题目数出奖")
public void 提交答案_答对题目数出奖(Map<String,String> data) throws Exception {
String caseId = data.get("caseId");
String caseDesc = data.get("caseDesc");
String answerData = data.get("answers");
boolean expect = Boolean.parseBoolean(data.get("expect"));
int rightCount = Integer.valueOf(data.get("rightCount"));
String message = data.get("message");
String prize = data.get("prize");
// if(!caseId.equals("2")) {
// return;
// }
logger.info("开始执行第"+caseId+"测试用例,测试场景:"+caseDesc);
//产生参加订单
Response doJoinResponse = activityCtrlService.doJoin(activityId,token);
Assert.assertTrue(doJoinResponse.jsonPath().getBoolean("success"));
long orderId = doJoinResponse.jsonPath().getLong("orderId");
//提交答案
Response submitResponse = activityCtrlService.submit(orderId,answerData,token);
logger.info("测试场景【:"+caseDesc+"】执行结果:"+submitResponse.asString());
//校验
Assert.assertEquals(submitResponse.jsonPath().getBoolean("success"),expect);
if(!expect) { //异常场景的提示语
Assert.assertEquals(submitResponse.jsonPath().getString("message"),message);
} else {
Assert.assertEquals(submitResponse.jsonPath().getInt("rightCount"),rightCount);
for (int i =1; i <= 5; i++) {
//获取中奖结果,校验中奖结果
Response lotterysResponse = activityCtrlService.getOrderStatus(orderId);
int result = lotterysResponse.jsonPath().getInt("result");
if(result != 0) {
Assert.assertTrue(lotterysResponse.jsonPath().getBoolean("success"));
// Assert.assertEquals(lotterysResponse.jsonPath().getString("lottery.type"),prize);
Assert.assertTrue(prize.contains(lotterysResponse.jsonPath().getString("lottery.type")));
break;
}
Thread.sleep(500);
}
Assert.assertFalse(false,caseDesc+" 测试失败,轮询5次未请求到中奖结果");
}
}
// @Test
// public void 提交答案_答案内容为空() {
// //产生参加订单
// Response doJoinResponse = activityCtrlService.doJoin(activityId,token);
// Assert.assertTrue(doJoinResponse.jsonPath().getBoolean("success"));
// Long orderId = doJoinResponse.jsonPath().getLong("orderId");
// String answerData = null;
//
// //提交空答案
// Response submitResponse = activityCtrlService.submit(orderId,answerData,token);
//
// //校验
// Assert.assertFalse(submitResponse.jsonPath().getBoolean("success"));
// Assert.assertEquals(submitResponse.jsonPath().getString("message"),"参数错误");
// }
// @Test
// public void 提交答案_答对1题出奖() {
// //产生参加订单
// Response doJoinResponse = activityCtrlService.doJoin(activityId,token);
// Assert.assertTrue(doJoinResponse.jsonPath().getBoolean("success"));
// Long orderId = doJoinResponse.jsonPath().getLong("orderId");
//
// List<QuestionAnswerVO> quesList = new ArrayList<QuestionAnswerVO>();
// QuestionAnswerVO ques1 = new QuestionAnswerVO(480,2);
// QuestionAnswerVO ques2 = new QuestionAnswerVO(479,2);
// QuestionAnswerVO ques3 = new QuestionAnswerVO(478,2);
// QuestionAnswerVO ques4 = new QuestionAnswerVO(477,2);
// QuestionAnswerVO ques5 = new QuestionAnswerVO(476,2);
// quesList.add(ques1);
// quesList.add(ques2);
// quesList.add(ques3);
// quesList.add(ques4);
// quesList.add(ques5);
// String answerData = JSON.toJSONString(quesList);
//
// //提交答案
// Response submitResponse = activityCtrlService.submit(orderId,answerData,token);
//
// Assert.assertTrue(submitResponse.jsonPath().getBoolean("success"));
// Assert.assertEquals(doJoinResponse.jsonPath().getString("orderId"),orderId);
// Assert.assertEquals(doJoinResponse.jsonPath().getInt("rightCount"),2);
// }
// @Test
// public void 提交答案_答对2题出奖() {
// //产生参加订单
// Response doJoinResponse = activityCtrlService.doJoin(activityId,token);
// Assert.assertTrue(doJoinResponse.jsonPath().getBoolean("success"));
// long orderId = doJoinResponse.jsonPath().getLong("orderId");
//
// //暂时定死题目来做,后期运行看是否存在问题,再根据实际情况调成动态生成答题题目
// List<QuestionAnswerVO> quesList = new ArrayList<QuestionAnswerVO>();
// QuestionAnswerVO ques1 = new QuestionAnswerVO(480,2);
// QuestionAnswerVO ques2 = new QuestionAnswerVO(479,2);
// QuestionAnswerVO ques3 = new QuestionAnswerVO(478,1);
// QuestionAnswerVO ques4 = new QuestionAnswerVO(477,1);
// QuestionAnswerVO ques5 = new QuestionAnswerVO(476,1);
// quesList.add(ques1);
// quesList.add(ques2);
// quesList.add(ques3);
// quesList.add(ques4);
// quesList.add(ques5);
// String answerData = JSON.toJSONString(quesList);
//
// //提交答案
// Response submitResponse = activityCtrlService.submit(orderId,answerData,token);
//
// Assert.assertTrue(submitResponse.jsonPath().getBoolean("success"));
// Assert.assertEquals(submitResponse.jsonPath().getLong("orderId"),orderId);
// Assert.assertEquals(submitResponse.jsonPath().getInt("rightCount"),2);
// }
// @Test
// public void 提交答案_全答对出奖() {
// //产生参加订单
// Response doJoinResponse = activityCtrlService.doJoin(activityId,token);
// Assert.assertTrue(doJoinResponse.jsonPath().getBoolean("success"));
// long orderId = doJoinResponse.jsonPath().getLong("orderId");
//
// //暂时定死题目来做,后期运行看是否存在问题,再根据实际情况调成动态生成答题题目
// List<QuestionAnswerVO> quesList = new ArrayList<QuestionAnswerVO>();
// QuestionAnswerVO ques1 = new QuestionAnswerVO(480,2);
// QuestionAnswerVO ques2 = new QuestionAnswerVO(479,2);
// QuestionAnswerVO ques3 = new QuestionAnswerVO(478,2);
// QuestionAnswerVO ques4 = new QuestionAnswerVO(477,2);
// QuestionAnswerVO ques5 = new QuestionAnswerVO(476,2);
// quesList.add(ques1);
// quesList.add(ques2);
// quesList.add(ques3);
// quesList.add(ques4);
// quesList.add(ques5);
// String answerData = JSON.toJSONString(quesList);
//
// //提交答案
// Response submitResponse = activityCtrlService.submit(orderId,answerData,token);
//
// Assert.assertTrue(submitResponse.jsonPath().getBoolean("success"));
// Assert.assertEquals(submitResponse.jsonPath().getLong("orderId"),orderId);
// Assert.assertEquals(submitResponse.jsonPath().getInt("rightCount"),5);
//
// Response lotterysResponse = activityCtrlService.getOrderStatus(orderId);
// Assert.assertEquals(lotterysResponse.jsonPath().getInt("lottery.id"),13772);
// }
@DataProvider(name = "答题题目数出奖")
public Iterator<Object[]> data(Method method) throws IOException {
return new ExcelDataProvider("duiba/答题题目数出奖");
}
}
package http.cases.DefinedActivityTest;
import base.DuibaTestBase;
import http.service.hd.DefinedActivityService;
import utils.MatcherString;
import utils.ExcelDataProvider;
import base.DuibaLog;
import io.restassured.response.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Date;
import java.util.Iterator;
import java.util.Map;
/**
* Created by hubinbin on 2018/3/29.
*/
//@ContextConfiguration(classes = DuibaConfig.class)
public class 答题_题目设置_DuibaTest extends DuibaTestBase {
private DuibaLog logger = DuibaLog.getLogger();
@Autowired
DefinedActivityService definedActivityService;
Integer bankId;
@Test
public void a_初始化数据() {
//1、创建新题库
Response response = definedActivityService.doCreate("自动化测试-题库" + new Date().getTime());
bankId = Integer.parseInt(MatcherString.getString(response.asString(), "id\":(.*?),", 1));
// bankId = response.jsonPath().getInt("id");
logger.info("题库ID=" +bankId);
}
@Test(dataProvider = "答题设置题目")
public void b_设置题目(Map<String,String> data) throws Exception{
String caseId = data.get("caseId");
String caseDesc = data.get("caseDesc");
String name = data.get("name");
String answers = data.get("answers");
Integer answer = Integer.valueOf(data.get("answer"));
String type = data.get("type");
logger.info("开始执行第"+caseId+"个用例,场景:"+caseDesc+",题库id="+bankId);
Response response = definedActivityService.doCreateQuestionRecord(bankId, name, answers, answer, type);
int qid = response.jsonPath().getInt("id");
int allCount = response.jsonPath().getInt("allCount");
Map<String, Object> actualtMap = jdbc.findSimpleResult("SELECT * FROM hdtool_conf.duiba_question_record where id = "+qid);
int actualCount = Integer.parseInt(jdbc.findSimpleResult("SELECT count(*) as cnum FROM hdtool_conf.duiba_question_record where bank_id=? and deleted=0",bankId).get("cnum").toString());
Assert.assertTrue(response.jsonPath().getBoolean("success"));
Assert.assertEquals(actualtMap.get("name"),name);
Assert.assertEquals(Integer.valueOf(actualtMap.get("right_answer").toString()),answer);
Assert.assertEquals(actualtMap.get("type"),type);
Assert.assertEquals(allCount,actualCount);
}
@AfterClass
public void 清理数据() throws Exception{
logger.info("清理题库和题目数据,题库id="+bankId);
jdbc.update("delete from hdtool_conf.duiba_question_bank where id="+bankId);
jdbc.update("delete from hdtool_conf.duiba_question_record where bank_id="+bankId);
}
@DataProvider(name = "答题设置题目")
public Iterator<Object[]> data(Method method) throws IOException{
return new ExcelDataProvider("duiba/答题设置题目");
}
}
\ No newline at end of file
package http.cases.DefinedActivityTest;
import base.DuibaTestBase;
import http.service.hd.DefinedActivityService;
import io.restassured.response.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.util.Date;
import java.util.Map;
/**
* Created by hubinbin on 2018/4/2.
*/
//@ContextConfiguration(classes = DuibaConfig.class)
public class 题库_创建题库_DuibaTest extends DuibaTestBase {
@Autowired
DefinedActivityService definedActivityService;
@Test
public void 创建题库() throws Exception{
Integer id = null ;
try {
String name = "自动化测试-题库" + new Date().getTime();
Response response = definedActivityService.doCreate(name);
Map<String, Object> expectMap = jdbc.findSimpleResult("SELECT * FROM hdtool_conf.duiba_question_bank where name = '"+name+"'");
id = response.jsonPath().getInt("id");
Assert.assertTrue(response.jsonPath().getBoolean("success"));
Assert.assertEquals(response.jsonPath().getString("id"),expectMap.get("id").toString());
Assert.assertEquals(response.jsonPath().getString("link"),getlink(id,name));
} finally {
//清理数据
jdbc.update("delete from hdtool_conf.duiba_question_bank where id="+id);
}
}
@Test
public void 编辑题库() throws Exception{
Integer id = null;
try {
//1、创建题库
String name1 = "自动化测试-题库" + new Date().getTime();
Response doCreateresponse = definedActivityService.doCreate(name1);
id = doCreateresponse.jsonPath().getInt("id");
//2、编辑题库
String name2 = "自动化测试编辑题库" + new Date().getTime();
Response doEditresponse = definedActivityService.doEdit(id,name2);
//3、验证
Map<String, Object> expectMap = jdbc.findSimpleResult("SELECT * FROM hdtool_conf.duiba_question_bank where name = '"+name2+"'");
Assert.assertTrue(doEditresponse.jsonPath().getBoolean("success"));
Assert.assertEquals(expectMap.get("name").toString(),name2);
} finally {
//4、清理数据
jdbc.update("delete from hdtool_conf.duiba_question_bank where id="+id);
}
}
private String getlink (Integer id,String name) {
return "/QuestionRecord/index?id=${id}&bankName=${name}".replace("${id}",id.toString()).replace("${name}",name);
}
}
package http.cases.DeveloperTest;
import base.DuibaTestBase;
import http.service.Activity.NewActivityService;
import http.service.Authorization;
import http.service.hd.DeveloperService;
import base.DuibaLog;
import io.restassured.response.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.util.Map;
/**
* Created by mabo on 2018/5/17
*/
public class 手动开奖出奖_DuibaTest extends DuibaTestBase {
@Autowired
NewActivityService newActivityService;
@Autowired
Authorization authorization;
@Autowired
DeveloperService developerService;
private static DuibaLog logger = DuibaLog.getLogger();
@Test
public void 手动开奖出奖() throws Exception {
//用户参与手动开奖活动
Response response = developerService.doLottery("26482");
response.prettyPrint();
String orderId = response.jsonPath().getString("orderId");
response = developerService.ajaxCheckOrderStatus(orderId);
response.prettyPrint();
String status = String.valueOf(response.jsonPath().getString("status"));
int i= 8;
while(i>0&&(status.equals("0"))){
Thread.sleep(1000);
response = developerService.ajaxCheckOrderStatus(orderId);
status = String.valueOf(response.jsonPath().getString("result"));
i--;
}
Map<String, Object> selectResult = jdbc.findSimpleResult("select * from credits_dev.manual_lottery_order where consumer_id = 100025007 order by gmt_create desc limit 1",null);
Assert.assertEquals( String.valueOf(selectResult.get("exchange_status")),"1","订单状态出错!预期为未中奖状态");
//后台手动开奖
//检查是否有参与记录
response = developerService.ajaxGetLotteryList("26482");
String recordId = response.jsonPath().getString("data.list[0].recordId");
Assert.assertEquals(orderId,recordId,"校验订单失败");
//开奖
developerService.submitAwardList("26482",orderId);
//检查数据库是否生成订单
Map<String, Object> selectResult2 = jdbc.findSimpleResult("select * from credits_dev.manual_lottery_order where consumer_id = 100025007 order by gmt_create desc limit 1",null);
Assert.assertEquals( String.valueOf(selectResult2.get("exchange_status")),"2","订单状态出错!预期为中奖状态");
//检查用户是否中奖
// response =developerService.winRecord();
// //response.prettyPrint();
// String result = MatcherString.getString(response.asString(), "status\":(.*?)};", 1);
// int n= 20;
// while(i>0&&(result.equals("1"))){
// Thread.sleep(1000);
// response =developerService.winRecord();
// response.prettyPrint();
// result = MatcherString.getString(response.asString(), "status\":(.*?)};", 1);
// n--;
// }
// Assert.assertEquals(result,"3","用户中奖失败!");
logger.info("用户手动开奖中奖成功!");
}
}
package http.cases.DeveloperTest;
import base.Config;
import http.service.Activity.ManagerService;
import http.service.Activity.NewActivityService;
import http.service.Activity.SingleLotteryService;
import http.service.hd.DeveloperService;
import http.service.hd.SigninService;
import base.DuibaLog;
import io.restassured.response.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.Assert;
import org.testng.annotations.Test;
/**
* Created by zhaoran on 2018/5/19.
*/
@ContextConfiguration(classes = Config.class)
public class 活动中奖限制_DuibaTest extends AbstractTestNGSpringContextTests {
@Autowired
SigninService signinService;
@Autowired
DeveloperService developerService;
@Autowired
ManagerService managerService;
@Autowired
NewActivityService newActivityService;
@Autowired
SingleLotteryService singleLotteryService;
private static DuibaLog logger = DuibaLog.getLogger();
@Test(description = "自有活动设置中奖限制为1次")
public void 中奖限制() throws Exception {
//进行接口测试传参
Response response = this.自有活动接口传参("21939","abcde","iOS");
String type = String.valueOf(response.jsonPath().getString("lottery.type"));
if (type.equals("lucky")){
Assert.assertTrue(response.jsonPath().getString("lottery.link").contains("//activity.m.duibatest.com.cn/crecord/recordLuckDetailNew?"));
Assert.assertEquals(response.jsonPath().getString("lottery.useBtnText"),"马上使用","校验useBtnText失败");
logger.info("校验中奖限制测试:link,useBtnText成功");
logger.info("校验中奖限制测试成功,未返回预设必中优惠券信息");
}
if (type.equals("thanks")){
logger.info("福袋库存不足会降级成谢谢参与!");//福袋库存不足会降级成谢谢参与!
}
if (type.equals("coupon")){
throw new Exception("用例失败,不应返回优惠券信息:"+response.asString());
}
}
public Response 自有活动接口传参(String activityId,String token,String device) throws Exception {
Response response = newActivityService.doJoin2(activityId,token);
response.prettyPrint();
String orderId = response.jsonPath().getString("orderId");
response = newActivityService.getOrderStatus2(orderId,device);
response.prettyPrint();
String result = String.valueOf(response.jsonPath().getString("result"));
int i= 8;
while(i>0&&(result.equals("0"))){
Thread.sleep(1000);
response = newActivityService.getOrderStatus2(orderId,device);
result = String.valueOf(response.jsonPath().getString("result"));
i--;
response.prettyPrint();
}
return response;
}
}
\ No newline at end of file
package http.cases.DeveloperTest;
import base.Config;
import http.service.Activity.NewActivityService;
import http.service.hd.DeveloperService;
import base.DuibaLog;
import io.restassured.response.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.lang.reflect.Method;
/**
* Created by zhaoran on 2018/3/15
*/
@ContextConfiguration(classes = Config.class)
public class 活动次数测试_DuibaTest extends AbstractTestNGSpringContextTests {
@Autowired
NewActivityService newActivityService;
@Autowired
DeveloperService developerService;
private static DuibaLog logger = DuibaLog.getLogger();
@DataProvider
public Object[][] providerMethod(Method method){
Object[][] result = null;
if(method.getName().equals("活动次数测试")) {
result = new Object[][]{
new Object[]{1, "5","10","限制5次,免费10次"},
new Object[]{2, "8","3","限制8次,免费3次"},
new Object[]{3, "","6","无限制次数,免费6次"},
new Object[]{4, "7","","限制7次,无免费次数"},
};
}
if(method.getName().equals("活动次数测试2")) {
result = new Object[][]{
new Object[]{1, "26248","限制5次,免费10次"},
new Object[]{2, "26249","限制8次,免费3次"},
new Object[]{3, "26250","无限制次数,免费6次"},
new Object[]{4, "21001","限制7次,无免费次数"},
};
}
return result;
}
//@Test(dataProvider = "providerMethod")
public void 活动次数测试(int casenum,String limitCount,String freeLimit,String casename) throws Exception {
logger.info("-------------------------------------"+casename+"-------------------------------------");
//编辑自有活动工具
developerService.save_hd("21001","【自动化】自有_次数测试",limitCount,freeLimit);
//获取免费次数
Response response = newActivityService.ajaxElement("dev","21001","21001","false");
switch(casenum){
case 1:
int i = 30;
while (!response.jsonPath().getString("element.freeLimit").equals("5") && i > 0) {
Thread.sleep(3000);
response = newActivityService.ajaxElement("dev","21001","21001","false");
i--;
}
Assert.assertEquals(response.jsonPath().getString("element.freeLimit"), "5", "校验freeLimit失败");
Assert.assertEquals(response.jsonPath().getString("element.status"), "7", "校验显示status失败");
break;
case 2:
int n = 30;
while (!response.jsonPath().getString("element.freeLimit").equals("3") && n > 0) {
Thread.sleep(3000);
response = newActivityService.ajaxElement("dev","21001","21001","false");
n--;
}
Assert.assertEquals(response.jsonPath().getString("element.freeLimit"), "3", "校验freeLimit失败");
Assert.assertEquals(response.jsonPath().getString("element.status"), "7", "校验显示status失败");
break;
case 3:
int l = 30;
while (!response.jsonPath().getString("element.freeLimit").equals("6") && l > 0) {
Thread.sleep(3000);
response = newActivityService.ajaxElement("dev","21001","21001","false");
l--;
}
Assert.assertEquals(response.jsonPath().getString("element.freeLimit"), "6", "校验freeLimit失败");
Assert.assertEquals(response.jsonPath().getString("element.status"), "7", "校验显示status失败");
break;
case 4:
int m = 30;
while (!response.jsonPath().getString("element.freeLimit").equals("7") && m > 0) {
Thread.sleep(3000);
response = newActivityService.ajaxElement("dev","21001","21001","false");
m--;
}
Assert.assertEquals(response.jsonPath().getString("element.freeLimit"), "7", "校验freeLimit失败");
Assert.assertEquals(response.jsonPath().getString("element.status"), "6", "校验显示status失败");
break;
}
logger.info("校验ajax接口的游戏次数正常:freeLimit,status");
}
@Test(dataProvider = "providerMethod")
public void 活动次数测试2(int casenum,String activityId,String casename) throws Exception {
logger.info("-------------------------------------"+casename+"-------------------------------------");
//获取免费次数
Response response = newActivityService.ajaxElement("dev","", activityId,"false");
switch(casenum){
case 1:
Assert.assertEquals(response.jsonPath().getString("element.freeLimit"), "5", "校验freeLimit失败");
Assert.assertEquals(response.jsonPath().getString("element.status"), "7", "校验显示status失败");
break;
case 2:
Assert.assertEquals(response.jsonPath().getString("element.freeLimit"), "3", "校验freeLimit失败");
Assert.assertEquals(response.jsonPath().getString("element.status"), "7", "校验显示status失败");
break;
case 3:
Assert.assertEquals(response.jsonPath().getString("element.freeLimit"), "6", "校验freeLimit失败");
Assert.assertEquals(response.jsonPath().getString("element.status"), "7", "校验显示status失败");
break;
case 4:
Assert.assertEquals(response.jsonPath().getString("element.freeLimit"), "7", "校验freeLimit失败");
Assert.assertEquals(response.jsonPath().getString("element.status"), "6", "校验显示status失败");
break;
}
logger.info("校验ajax接口的游戏次数正常:freeLimit,status");
}
}
package http.cases.DeveloperTest;
import base.Config;
import http.service.Activity.ManagerService;
import http.service.Activity.NewActivityService;
import base.DuibaLog;
import io.restassured.response.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.Assert;
import org.testng.annotations.Test;
/**
* Created by zhaoran on 2018/1/2
*/
@ContextConfiguration(classes = Config.class)
public class 独立活动测试_DuibaTest extends AbstractTestNGSpringContextTests {
@Autowired
NewActivityService newActivityService;
@Autowired
ManagerService managerService;
private static DuibaLog logger = DuibaLog.getLogger();
@Test(description = "积分模式下的自有独立活动测试")
public void 独立活动测试() throws Exception {
//校验ajax接口关键字段返回
logger.info("请求/hdtool/ajaxElement接口");
Response response_ajax = newActivityService.ajaxElement("","23316");
Assert.assertEquals(response_ajax.jsonPath().getString("element.isCreditsTypeOpen"),"true","校验isCreditsTypeOpen失败");
Assert.assertEquals(response_ajax.jsonPath().getString("element.status"),"7","校验status失败");
Assert.assertEquals(response_ajax.jsonPath().getString("element.needCredits"),"0","校验status失败");
logger.info("ajax校验项:isCreditsTypeOpen,status成功");
String freeLimit = response_ajax.jsonPath().getString("element.freeLimit");
logger.info("抽奖前当日免费次数剩余:"+freeLimit);
freeLimit = String.valueOf(Integer.valueOf(freeLimit)-1);
logger.info("抽奖后预期免费次数剩余:"+freeLimit);
logger.info("请求/hdtool/doJoin接口");
Response response = newActivityService.doJoin2("23316","ia9a7");
String orderId = response.jsonPath().getString("orderId");
response = newActivityService.getOrderStatus2(orderId);
String result = response.jsonPath().getString("result");
int i = 30;
while(i>0&&result.equals("0")){
Thread.sleep(1000);
response = newActivityService.getOrderStatus2(orderId);
result = response.jsonPath().getString("result");
i--;
}
Assert.assertEquals(response.jsonPath().getString("element.isCreditsTypeOpen"),"true","校验isCreditsTypeOpen失败");
Assert.assertEquals(response.jsonPath().getString("element.status"),"7","校验status失败");
Assert.assertEquals(response.jsonPath().getString("lottery.title"),"支付宝","校验title失败");
Assert.assertEquals(response.jsonPath().getString("lottery.type"),"alipay","校验type失败");
Assert.assertEquals(response.jsonPath().getString("success"),"true","校验success失败");
logger.info("doJoin校验项:isCreditsTypeOpen,status,title,type,success成功");
String freeLimitNew = response.jsonPath().getString("element.freeLimit");
logger.info("抽奖后实际免费次数剩余:"+freeLimitNew);
Assert.assertEquals(freeLimitNew,freeLimit,"扣免费次数失败");
}
}
\ No newline at end of file
package http.cases.DeveloperTest;
import base.Config;
import base.DuibaTestBase;
import http.service.Activity.ManagerService;
import http.service.Activity.NewActivityService;
import http.service.Activity.SingleLotteryService;
import http.service.hd.ActivityService;
import http.service.hd.DeveloperService;
import http.service.hd.SigninService;
import base.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.DataProvider;
import org.testng.annotations.Test;
import java.lang.reflect.Method;
import java.util.Map;
/**
* Created by zhaoran on 2018/5/19.
*/
@ContextConfiguration(classes = Config.class)
public class 自有答题测试_DuibaTest extends DuibaTestBase {
@Autowired
SigninService signinService;
@Autowired
DeveloperService developerService;
@Autowired
ManagerService managerService;
@Autowired
NewActivityService newActivityService;
@Autowired
SingleLotteryService singleLotteryService;
@Autowired
ActivityService activityService;
private static DuibaLog logger = DuibaLog.getLogger();
//指定用户
private static int uid = 3741;
@DataProvider
public Object[][] providerMethod(Method method){
Object[][] result = null;
if(method.getName().equals("自有答题活动抽奖")) {
result = new Object[][]{
new Object[]{1, "1","2", "两题全答对"},
new Object[]{2, "1","1", "只答对1题"},
new Object[]{3, "2","1", "全部答错"}
};
}
return result;
}
@Test(dataProvider = "providerMethod")
public void 自有答题活动抽奖(int casenum,String ans1,String ans2,String casename) throws Exception {
logger.info("-------------------------------------"+casename+"-------------------------------------");
//查询数据库,当前积分(抽奖扣积分流程校验)
Map<String,Object> mapuser = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid);
String credits = String.valueOf(mapuser.get("credits"));
logger.info("抽奖前积分:"+credits);
//扣去1积分
credits = String.valueOf(Integer.valueOf(credits)-1);
//ajax接口测试
Response response = newActivityService.ajaxElement(uid,"dev","26464","26464","false");
String status = response.jsonPath().getString("element.status");
String needCredits1 = response.jsonPath().getString("element.needCredits");
Assert.assertEquals(status,"6","ajax状态不正确");
Assert.assertEquals(needCredits1,"1","消耗积分不正确");
//进行接口测试传参
response = newActivityService.doJoin5(uid,"26464");
String needCredits = response.jsonPath().getString("needCredits");
String questions1 = response.jsonPath().getString("questions[0].name");
String type1 = response.jsonPath().getString("questions[0].type");
String questions2 = response.jsonPath().getString("questions[1].name");
String type2 = response.jsonPath().getString("questions[1].type");
Assert.assertEquals(needCredits,"1","消耗积分不正确");
Assert.assertEquals(questions1,"选A","问题1题目不正确");
Assert.assertEquals(type1,"text","问题1类型不正确");
Assert.assertEquals(questions2,"选B","问题2题目不正确");
Assert.assertEquals(type2,"image","问题2类型不正确");
String orderId = response.jsonPath().getString("orderId");
String token = response.jsonPath().getString("submitToken");
response = newActivityService.submit(uid,orderId,token,ans1,ans2);
//response.prettyPrint();
int i = 30;
while("处理中。。。".equals(response.jsonPath().getString("message"))&&i>0){
Thread.sleep(1000);
response = newActivityService.submit(uid,orderId,token,ans1,ans2);
i--;
}
//根据case选择对应的校验项
switch(casenum){
case 1:
Assert.assertEquals(response.jsonPath().getString("rightCount"),"2","校验答题数失败");
logger.info("校验答题正确数成功");
response = newActivityService.getOrderStatus(uid,orderId);
//推啊出券系统检测
// if(activityService.isRunning("10.110.10.12","17791","tuia-engine")){
logger.info("tuia-engine服务启动成功");
Assert.assertEquals(response.jsonPath().getString("lottery.type"),"lucky","校验奖品类型失败");
Assert.assertEquals(response.jsonPath().getString("lottery.useBtnText"),"马上使用","校验奖品文案失败");
Assert.assertEquals(response.jsonPath().getString("result"),"2","校验抽奖结果失败");
// }else{
// logger.info("tuia-engine服务启动未成功,福袋降级成谢谢参与!");
// }
break;
case 2:
Assert.assertEquals(response.jsonPath().getString("rightCount"),"1","校验答题数失败");
logger.info("校验答题正确数成功");
response = newActivityService.getOrderStatus(uid,orderId);
Assert.assertEquals(response.jsonPath().getString("result"),"0","校验抽奖结果失败");
break;
case 3:
Assert.assertEquals(response.jsonPath().getString("rightCount"),"0","校验答题数失败");
logger.info("校验答题正确数成功");
response = newActivityService.getOrderStatus(uid,orderId);
Assert.assertEquals(response.jsonPath().getString("result"),"0","校验抽奖结果失败");
break;
}
//查询数据库,获取当前积分
Thread.sleep(2000);
mapuser = jdbc.findSimpleResult("select * from dafuweng.user where id="+uid);
String creditsNew = String.valueOf(mapuser.get("credits"));
logger.info("user表用户抽奖后积分:"+creditsNew);
//校验比较,抽奖前后积分
Assert.assertEquals(credits,creditsNew);
logger.info("校验领奖前后积分正确");
}
}
\ 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