Commit 3a2b1786 authored by 赵然's avatar 赵然

Merge branch 'develop'

parents 6bf144cd 4827eb11
......@@ -41,7 +41,12 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.sourceforge.jexcelapi</groupId>
<artifactId>jxl</artifactId>
<version>2.6.12</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
......@@ -165,6 +170,43 @@
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>cn.com.duiba.activity-center</groupId>
<artifactId>activity-center-api</artifactId>
<version>2.7.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.com.duiba.activity-comm-center</groupId>
<artifactId>activity-common-api</artifactId>
<version>1.0.7.black3-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.18</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9.9</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
......@@ -219,6 +261,31 @@
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>copy-xmls</id>
<phase>process-sources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/data</outputDirectory>
<resources>
<resource>
<directory>${basedir}/data</directory>
<includes>
<include>**/*.xls</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
......@@ -226,6 +293,7 @@
<resource>
<directory>data/*</directory>
</resource>
<resource>
<directory>lib/*</directory>
</resource>
......
......@@ -10,7 +10,7 @@ import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
* Created by mabo on 2018/9/20
*/
@Configuration
@ComponentScan(basePackages = {"ui","http","base"})
@ComponentScan(basePackages = {"ui","http","base","utils"})
@PropertySource(value = {"duiba.properties"})
public class Config {
@Bean
......
/**
* Copyright (C), 2015-2018
* FileName: 集卡_出奖方式测试_DuibaTest
* Author: qianwenjun
* Date: 2018/3/6 20:29
* Description:
*/
package http.cases.CollectActivityTest;
import base.DuibaLog;
import base.DuibaTestBase;
import http.service.Activity.NewActivityService;
import http.service.Manager.EditManagerInfoService;
import http.service.Manager.GetManagerInfoService;
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/3/6
* @since 1.0.0
*/
public class 集卡_出奖方式测试_DuibaTest extends DuibaTestBase {
@Autowired
NewActivityService newActivityService;
@Autowired
GetManagerInfoService getManagerInfoService;
@Autowired
EditManagerInfoService editManagerInfoService;
private static DuibaLog logger = DuibaLog.getLogger();
@Test
public void 集卡_直接出奖_中奖() throws Exception {
//获取集卡活动配置的奖品信息
Response awardResponse = getManagerInfoService.getCollectAwardsInfo("239");
String data = awardResponse.jsonPath().getString("data.config.rewards[0]");
String awardsName = awardResponse.jsonPath().getString("data.config.rewards[0].rlName");
String awardsType = awardResponse.jsonPath().getString("data.config.rewards[0].rlType");
//自定义活动游戏 结果
Response response = playNewActivityResult("19929", "r3oq9gqkf", "239",2720);
//校验中奖结果类型
Assert.assertEquals(String.valueOf(response.jsonPath().getString("lottery.type")), "collectGoods", "校验中奖类型失败");
logger.info("校验中奖类型成功,自定义活动游戏中奖奖品类型为" + response.jsonPath().getString("lottery.type"));
//集卡获取信息
// Response collectGoodsInfo = newActivityService.getCollectGoodsInfo("239");
// logger.info("收集的中奖卡的信息如下:");
// collectGoodsInfo.prettyPrint();
//集卡结束后开奖--开奖类型:直接开奖
Response openResponse = playCollectResult("239", "19929",2720);
Assert.assertEquals(openResponse.jsonPath().getString("lottery.title"), awardsName, "校验奖项失败");
Assert.assertEquals(openResponse.jsonPath().getString("lottery.type"), awardsType, "校验奖项失败");
logger.info("校验活动中奖信息name和type成功,奖品信息为:" + openResponse.jsonPath().getString("lottery.title"));
}
@Test
public void 集卡_直接出奖_库存不足_不中奖() throws Exception {
//获取集卡活动配置的奖品信息
Response awardResponse = getManagerInfoService.getCollectAwardsInfo("242");
String data = awardResponse.jsonPath().getString("data.config.rewards[0]");
String awardsName = awardResponse.jsonPath().getString("data.config.rewards[0].name");
String awardsType = awardResponse.jsonPath().getString("data.config.rewards[0].rlType");
//自定义活动游戏 结果
Response response = playNewActivityResult("19932", "r3oq9gqkf", "4",2720);
Assert.assertEquals(String.valueOf(response.jsonPath().getString("lottery.type")), "collectGoods", "校验中奖类型失败");
logger.info("校验中奖奖品信息成功,自定义活动游戏中奖奖品类型" + response.jsonPath().getString("lottery.type"));
//集卡结束后开奖--开奖类型:直接开奖
Response openResponse = newActivityService.openCollectGoodsPrize2("242", "19932","服务器异常 请稍后再次领奖");
logger.info("集卡奖品缺货,开奖失败,校验错误信息成功,错误信息为" + openResponse.jsonPath().getString("message"));
}
@Test
public void 集卡_插件出奖_中奖() throws Exception {
//获取集卡活动配置的奖品信息--插件235的奖品信息
Response awardResponse = getManagerInfoService.getPluginInfo("235");
String data = awardResponse.jsonPath().getString("prizes");
String awardsDescription = awardResponse.jsonPath().getString("prizes[1].description");
String awardsType = awardResponse.jsonPath().getString("prizes[1].type");
//自定义活动游戏 结果
Response response = this.playNewActivityResult("19930", "r3oq9gqkf", "240",2720);
//校验中奖结果类型
Assert.assertEquals(String.valueOf(response.jsonPath().getString("lottery.type")), "collectGoods", "校验中奖类型失败");
logger.info("校验中奖奖品类型成功,自定义活动游戏中奖奖品类型" + response.jsonPath().getString("lottery.type"));
Response openResponse = this.playCollectResult("240", "19930",2720);
Assert.assertEquals(openResponse.jsonPath().getString("lottery.title"), awardsDescription, "校验奖项失败");
Assert.assertEquals(openResponse.jsonPath().getString("lottery.type"), awardsType, "校验奖项失败");
Assert.assertTrue(openResponse.jsonPath().getString("lottery.link").contains("/activity/takePrizeNew?recordId"));
logger.info("集卡开奖奖品类型校验成功,奖品信息为:" + openResponse.jsonPath().getString("lottery.title"));
}
@Test
public void 集卡_插件出奖_缺货_不中奖() throws Exception {
//获取集卡活动配置的奖品信息--插件235的奖品信息
Response awardResponse = getManagerInfoService.getPluginInfo("240");
String data = awardResponse.jsonPath().getString("prizes");
String awardsDescription = awardResponse.jsonPath().getString("prizes[0].description");
String awardsType = awardResponse.jsonPath().getString("prizes[0].type");
//自定义活动游戏 结果
Response response = this.playNewActivityResult("19931", "r3oq9gqkf", "241",2720);
//校验中奖结果类型
Assert.assertEquals(String.valueOf(response.jsonPath().getString("lottery.type")), "collectGoods", "校验中奖类型失败");
logger.info("校验中奖奖品类型成功,自定义活动游戏中奖奖品类型" + response.jsonPath().getString("lottery.type"));
Response openResponse = this.playCollectResult("241", "19931",2720);
Assert.assertEquals(openResponse.jsonPath().getString("lottery.type"), awardsType, "校验奖项失败");
logger.info("校验奖品信息type成功, 奖品信息为:" + openResponse.jsonPath().getString("lottery.type"));
}
public Response playNewActivityResult(String activityId, String token, String collectRuleId,Integer uid) throws Exception {
Response response = newActivityService.doJoin4(activityId, token, collectRuleId, uid);
Response playResponse = response;
//playResponse.prettyPrint();
String orderId = playResponse.jsonPath().getString("orderId");
Response statusResponse = newActivityService.getOrderStatus21(orderId,uid);
// statusResponse.prettyPrint();
String playResult = statusResponse.jsonPath().getString("result");
int i = 30;
while (i > 0 && (playResult.equals("0"))) {
Thread.sleep(1000);
statusResponse = newActivityService.getOrderStatus21(orderId,uid);
// statusResponse.prettyPrint();
playResult = String.valueOf(statusResponse.jsonPath().getString("result"));
i--;
// statusResponse.prettyPrint();
}
return statusResponse;
}
public Response playCollectResult(String collectRuleId, String activityId,Integer uid) throws Exception {
Response openResponse = newActivityService.openCollectGoodsPrize3(collectRuleId, activityId,uid);
// openResponse.prettyPrint();
String orderId = openResponse.jsonPath().getString("orderId");
Response statusResponse = newActivityService.getOrderStatus31(orderId,uid);
// logger.info("开奖结果如下1:");
// statusResponse.prettyPrint();
String playResult = String.valueOf(statusResponse.jsonPath().getString("result"));
int i = 8;
while (i > 0 && (playResult.equals("0"))) {
Thread.sleep(1000);
statusResponse = newActivityService.getOrderStatus31(orderId,uid);
playResult = String.valueOf(statusResponse.jsonPath().getString("result"));
i--;
// logger.info("开奖结果如下2:");
// statusResponse.prettyPrint();
}
return statusResponse;
}
}
\ No newline at end of file
package http.cases.CollectActivityTest;
import base.DuibaLog;
import base.DuibaTestBase;
import http.service.Activity.ManagerService;
import http.service.Activity.NewActivityService;
import io.restassured.response.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.lang.reflect.Method;
/**
* 〈集卡助力抽奖〉
*
* @author zhaoran
* @create 2018/07/04
* @since 1.0.0
*/
public class 集卡_助力集卡测试_DuibaTest extends DuibaTestBase {
@Autowired
NewActivityService newActivityService;
@Autowired
ManagerService managerService;
private static DuibaLog logger = DuibaLog.getLogger();
// private MysqlUtils jdbc;
private static String shareCode;
@BeforeMethod
//获取2720用户书旗活动邀请码
public void before() throws Exception {
shareCode=null;
Response response = newActivityService.getShareCode("25902","hdtool");
shareCode = String.valueOf(response.jsonPath().getString("shareCode"));
logger.info("2720用户书旗活动邀请码为:"+shareCode);
// jdbc = MysqlUtils.mysqlDuiba("act_com_conf");
try {
jdbc.update("delete from act_com_conf.tb_share_code_record where invited_consumer_id = '100028002' and share_code = '11nknk8'", null);
} catch (Exception e) {
e.printStackTrace();
}
}
// @AfterClass
// public void after(){
// jdbc.releaseConn();
// }
@DataProvider
public Object[][] providerMethod(Method method){
Object[][] result = null;
if(method.getName().equals("助力集卡抽奖")) {
result = new Object[][]{
new Object[]{1, 2720, "自己为自己助力"},
new Object[]{2, 2721, "他人为自己重复助力"},
new Object[]{3, 2721, "分享码无效"},
new Object[]{4, 2722, "分享助力成功抽卡"}
};
}
return result;
}
@Test(dataProvider = "providerMethod")
public void 助力集卡抽奖(int casenum,int userId,String casename) throws Exception {
logger.info("-------------------------------------"+casename+"-------------------------------------");
logger.info("2720用户书旗活动邀请码为:"+shareCode);
Assert.assertEquals(shareCode, "11nknk8", "校验shareCode失败");
//获取2720用户集卡信息
Response response = newActivityService.getCollectGoodsInfo("2364");
String count = String.valueOf(response.jsonPath().getString("collectGoods[3].count"));
logger.info("助力前2720用户修仙卡数量为:"+count);
count = String.valueOf(Integer.valueOf(count)+1);
//根据case选择对应的校验项
switch(casenum){
case 1:
response = newActivityService.helpShareCodeV2(userId,"780","25902","hdtool",shareCode);
Assert.assertEquals(response.jsonPath().getString("errorCode"),"100005","校验errorCode失败");
Assert.assertEquals(response.jsonPath().getString("success"),"false","校验success失败");
Assert.assertEquals(response.jsonPath().getString("message"),"不能为自己助力,请输入他人的分享码!","校验message失败");
logger.info("校验项:errorCode,message,success成功");
break;
case 2:
response = newActivityService.helpShareCodeV2(userId,"780","25902","hdtool",shareCode);
Assert.assertEquals(response.jsonPath().getString("errorCode"),"100007","校验errorCode失败");
Assert.assertEquals(response.jsonPath().getString("success"),"false","校验success失败");
Assert.assertEquals(response.jsonPath().getString("message"),"不能重复助力!","校验message失败");
logger.info("校验项:errorCode,message,success成功");
break;
case 3:
response = newActivityService.helpShareCodeV2(userId,"780","25902","hdtool","asdasfsadsad");
Assert.assertEquals(response.jsonPath().getString("errorCode"),"100006","校验errorCode失败");
Assert.assertEquals(response.jsonPath().getString("success"),"false","校验success失败");
Assert.assertEquals(response.jsonPath().getString("message"),"分享码无效,请输入正确的分享码!","校验message失败");
logger.info("校验项:errorCode,message,success成功");
break;
case 4:
response = newActivityService.helpShareCodeV2(userId,"780","25902","hdtool",shareCode);
//logger.info("XXXXXXXXX"+response.asString());
Assert.assertEquals(response.jsonPath().getString("itmeId"),"29085","校验itmeId失败");
Assert.assertEquals(response.jsonPath().getString("success"),"true","校验success失败");
Assert.assertEquals(response.jsonPath().getString("message"),"请求成功","校验message失败");
logger.info("校验项:itmeId,message,success成功,助力出卡成功");
//获取2720用户集卡信息
response = newActivityService.getCollectGoodsInfo("2364");
String countNew = String.valueOf(response.jsonPath().getString("collectGoods[3].count"));
logger.info("助力后2720用户修仙卡数量为:"+countNew);
Assert.assertEquals(countNew,count,"分享助力出卡未加上分享者账号");
break;
}
}
}
\ No newline at end of file
/**
* Copyright (C), 2015-2018
* FileName: 集卡_多奖项_用户中奖限制测试_DuibaTest
* Author: qianwenjun
* Date: 2018/3/14 21:01
* Description: 多奖项-中奖限制测试
*/
package http.cases.CollectActivityTest;
import base.DuibaLog;
import base.DuibaTestBase;
import cn.com.duiba.activity.center.api.dto.activity.CLRewardDto;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import http.model.CollectGoodsInfo;
import http.service.Activity.ManagerService;
import http.service.Activity.NewActivityService;
import http.service.Manager.EditManagerInfoService;
import http.service.Manager.GetManagerInfoService;
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.AfterMethod;
import org.testng.annotations.Test;
import java.util.List;
/**
* 〈多奖项-中奖限制测试〉
*
* @author qianwenjun
* @create 2018/3/14
* @since 1.0.0
*/
public class 集卡_多奖项_用户中奖限制测试 extends DuibaTestBase {
@Autowired
NewActivityService newActivityService;
@Autowired
ManagerService managerService;
@Autowired
GetManagerInfoService getManagerInfoService;
@Autowired
EditManagerInfoService editManagerInfoService;
private static DuibaLog logger = DuibaLog.getLogger();
// @BeforeMethod
//每个方法之前清理数据库数据,保证无脏数据影响测试结果
public void clearDb() {
try {
Boolean clearResult1 = jdbc.update("delete from ckvtable.tb_kvtable_0687 where consumer_id = 100025007 and vkey like '%activity-centerwinOptionNum_100025007_19934_hdtool%'",null);
Boolean clearResult2 = jdbc.update("delete from ckvtable.tb_kvtable_0687 where consumer_id = 100025007 and vkey like '%cl_good_cid_Crule_grade_100025007_244%'",null);
Boolean clearResult3 = jdbc.update("delete from ckvtable.tb_kvtable_0687 where consumer_id = 100025007 and vkey in ('cl_good_cid_itemId_100025007_27218','cl_good_cid_itemId_100025007_27219')",null);
Boolean clearResult4 = jdbc.update("delete from ckvtable.tb_kvtable_0687 where consumer_id = 100025007 and vkey = 'activity-centerjoinNum_100025007_19934'",null);
} catch (Exception e) {
e.printStackTrace();
}
}
//规则id=244,设置多奖项开关-打开
//奖项:1-集卡6;2-集卡7
//用例设计:
//第一次游戏中奖-奖项1
//校验点:1、奖项2不能中奖,7卡不能收集,只能中谢谢参与
@Test
public void 集卡_多奖项_中奖限制测试() throws Exception{
//获取集卡活动配置的奖品信息
Response awardResponse = getManagerInfoService.getCollectAwardsInfo("244");
List<CLRewardDto> cLRewards = awardResponse.jsonPath().getJsonObject("data.config.rewards");
CLRewardDto cLReward0 = JSONObject.parseObject(JSON.toJSONString(cLRewards.get(1)),CLRewardDto.class);
logger.info("奖品信息"+cLReward0);
Response response = playNewActivityResult("19934", "r3oq9gqkf", "244",2720);
Assert.assertEquals(String.valueOf(response.jsonPath().getString("lottery.type")), "collectGoods", "校验中奖类型失败");
logger.info("中奖卡片id为"+response.jsonPath().getString("lottery.itemId"));
Response myCollectInfoResponse = newActivityService.getCollectGoodsInfo2("244",2720);
List<CollectGoodsInfo> myCollectInfos = myCollectInfoResponse.jsonPath().getList("collectGoods",CollectGoodsInfo.class);
logger.info("myCollectInfo的信息为"+JSON.toJSONString(myCollectInfos));
Response openResponse = playCollectResult("244", "19934",2720);
Assert.assertEquals(openResponse.jsonPath().getString("lottery.title"), cLReward0.getName(), "校验奖项失败");
Assert.assertEquals(openResponse.jsonPath().getString("lottery.type"), cLReward0.getRlType(), "校验奖项失败");
//
// for(int i=0;i<2;i++){
// if (i==0){
// //第一次中集卡商品A,开奖得到奖项1的奖品
// Response response = playNewActivityResult("19934", "r3oq9gqkf", "244",2721);
// Assert.assertEquals(String.valueOf(response.jsonPath().getString("lottery.type")), "collectGoods", "校验中奖类型失败");
// //集卡获取信息
// Response collectGoodsInfo = newActivityService.getCollectGoodsInfo("244");
// logger.info("收集的中奖卡的信息如下:");
// collectGoodsInfo.prettyPrint();
//// 集卡结束后开奖--开奖类型:直接开奖
// Response openResponse = playCollectResult("244", "19934",2721);
// Assert.assertEquals(openResponse.jsonPath().getString("lottery.title"), cLReward0.getRlName(), "校验奖项失败");
// Assert.assertEquals(openResponse.jsonPath().getString("lottery.type"), cLReward0.getRlType(), "校验奖项失败");
//
// logger.info("校验集卡活动中奖项1信息成功,奖品信息为:" + openResponse.jsonPath().getString("lottery.title"));
// }else if (i==1){
// Response setResponse = editManagerInfoService.
// saveCustomHdtool3("3949", "【勿动】自动化-集卡-多奖项限制测试", "129","14154",
// "27218_0_A6_【勿动】自动化-集卡商品-A6_14155",
// "27219_100_A7_【勿动】自动化-集卡商品-A7_14156");
// Thread.sleep(60000);
// Response response = playNewActivityResult("19934", "r3oq9gqkf", "244",2721);
// String type = String.valueOf(response.jsonPath().getString("lottery.type"));
// Assert.assertTrue((type.contains("thanks"))||(type.contains("lucky")));
// logger.info("校验多奖项限制,第二次抽奖奖品为谢谢参与成功,奖品类型为" + response.jsonPath().getString("lottery.type"));
// }
//
// }
// //为第二次循环执行准备
// Response setResponse = editManagerInfoService.
// saveCustomHdtool3("3949", "【勿动】自动化-集卡-多奖项限制测试", "129","14154",
// "27218_100_A6_【勿动】自动化-集卡商品-A6_14155",
// "27219_0_A7_【勿动】自动化-集卡商品-A7_14156");
// Thread.sleep(60000);
}
public Response playNewActivityResult(String activityId, String token, String collectRuleId,Integer uid) throws Exception {
Response response = newActivityService.doJoin4(activityId, token, collectRuleId, uid);
Response playResponse = response;
// playResponse.prettyPrint();
String orderId = playResponse.jsonPath().getString("orderId");
Response statusResponse = newActivityService.getOrderStatus21(orderId,uid);
statusResponse.prettyPrint();
String playResult = statusResponse.jsonPath().getString("result");
int i = 8;
while (i > 0 && (playResult.equals("0"))) {
Thread.sleep(1000);
statusResponse = newActivityService.getOrderStatus21(orderId,uid);
playResult = String.valueOf(statusResponse.jsonPath().getString("result"));
i--;
// statusResponse.prettyPrint();
}
return statusResponse;
}
public Response playCollectResult(String collectRuleId, String activityId,Integer uid) throws Exception {
Response openResponse = newActivityService.openCollectGoodsPrize3(collectRuleId, activityId,uid);
openResponse.prettyPrint();
String orderId = openResponse.jsonPath().getString("orderId");
Response statusResponse = newActivityService.getOrderStatus31(orderId,uid);
// logger.info("开奖结果如下1:");
// statusResponse.prettyPrint();
String playResult = String.valueOf(statusResponse.jsonPath().getString("result"));
int i = 8;
while (i > 0 && (playResult.equals("0"))) {
Thread.sleep(1000);
statusResponse = newActivityService.getOrderStatus31(orderId,uid);
playResult = String.valueOf(statusResponse.jsonPath().getString("result"));
i--;
// logger.info("开奖结果如下2:");
// statusResponse.prettyPrint();
}
return statusResponse;
}
@AfterMethod
//每个方法之前清理数据库数据,保证无脏数据影响测试结果
public void tearDb() {
try {
Boolean clearResult1 = jdbc.update("delete from ckvtable.tb_kvtable_0687 where consumer_id = 100025007 and vkey like '%activity-centerwinOptionNum_100025007_19934_hdtool%'",null);
Boolean clearResult2 = jdbc.update("delete from ckvtable.tb_kvtable_0687 where consumer_id = 100025007 and vkey like '%cl_good_cid_Crule_grade_100025007_244%'",null);
Boolean clearResult3 = jdbc.update("delete from ckvtable.tb_kvtable_0687 where consumer_id = 100025007 and vkey in ('cl_good_cid_itemId_100025007_27218','cl_good_cid_itemId_100025007_27219')",null);
Boolean clearResult4 = jdbc.update("delete from ckvtable.tb_kvtable_0687 where consumer_id = 100025007 and vkey = 'activity-centerjoinNum_100025007_19934'",null);
} catch (Exception e) {
e.printStackTrace();
}
}
}
\ No newline at end of file
/**
* Copyright (C), 2015-2018
* FileName: 集卡_指定卡片_不同奖项中奖条件测试
* Author: qianwenjun
* Date: 2018/3/13 17:06
* Description: 设置不同条件-中奖
*/
package http.cases.CollectActivityTest;
import base.DuibaLog;
import base.DuibaTestBase;
import http.service.Activity.NewActivityService;
import http.service.Manager.EditManagerInfoService;
import http.service.Manager.GetManagerInfoService;
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.BeforeMethod;
import org.testng.annotations.Test;
/**
* 〈设置不同条件-中奖〉
*
* @author qianwenjun
* @create 2018/3/13
* @since 1.0.0
*/
public class 集卡_指定卡片_DuibaTest extends DuibaTestBase {
@Autowired
NewActivityService newActivityService;
@Autowired
GetManagerInfoService getManagerInfoService;
@Autowired
EditManagerInfoService editManagerInfoService;
private static DuibaLog logger = DuibaLog.getLogger();
@BeforeMethod
//每个方法之前清理数据库数据,保证无脏数据影响测试结果
public void clearDb() {
try {
Boolean clearResult1 = jdbc.update("delete from ckvtable.tb_kvtable_0687 where consumer_id = 100025007 and vkey like '%activity-centerwinOptionNum_100025007_19936_hdtool%'",null);
Boolean clearResult2 = jdbc.update("delete from ckvtable.tb_kvtable_0687 where consumer_id = 100025007 and vkey like '%cl_good_cid_Crule_grade_100025007_246%'",null);
Boolean clearResult3 = jdbc.update("delete from ckvtable.tb_kvtable_0687 where consumer_id = 100025007 and vkey in ('cl_good_cid_itemId_100025007_27221')",null);
Boolean clearResult4 = jdbc.update("delete from ckvtable.tb_kvtable_0687 where consumer_id = 100025007 and vkey = 'activity-centerjoinNum_100025007_19936'",null);
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void 集卡_中奖条件集卡A_3() throws Exception {
//获取集卡活动配置的奖品信息
Response awardResponse = getManagerInfoService.getCollectAwardsInfo("246");
String data = awardResponse.jsonPath().getString("data.config.rewards[0]");
String awardsName = awardResponse.jsonPath().getString("data.config.rewards[0].rlName");//"【勿动】自动化测试虚拟商品"
String awardsType = awardResponse.jsonPath().getString("data.config.rewards[0].rlType");//virtual
//自定义活动游戏 结果
for(int i=0;i<3;i++) {
Response response = playNewActivityResult("19936", "r3oq9gqkf", "246");
//校验中奖结果类型
Assert.assertEquals(String.valueOf(response.jsonPath().getString("lottery.type")), "collectGoods", "校验中奖类型失败");
logger.info("校验中奖奖品类型成功,自定义活动游戏中奖奖品类型" + response.jsonPath().getString("lottery.type"));
}
// Thread.sleep(8000);
Response collectGoodsInfoResponse = newActivityService.getCollectGoodsInfo2("246",2720);
collectGoodsInfoResponse.prettyPrint();
//集卡结束后开奖--开奖类型:直接开奖
Response openResponse = playCollectResult("246", "19936");
Assert.assertEquals(openResponse.jsonPath().getString("lottery.title"), awardsName, "校验奖项失败");
Assert.assertEquals(openResponse.jsonPath().getString("lottery.type"), awardsType, "校验奖项失败");
logger.info("校验集卡抽奖奖项type、name成功,奖品信息为:" + openResponse.jsonPath().getString("lottery.title"));
}
@Test
public void 集卡_不满足开奖条件() throws Exception{
for(int i=0;i<1;i++){
Response response = playNewActivityResult("19936", "r3oq9gqkf", "246");
//校验中奖结果类型
Assert.assertEquals(String.valueOf(response.jsonPath().getString("lottery.type")), "collectGoods", "校验中奖类型失败");
logger.info("校验中奖奖品类型成功,自定义活动游戏中奖奖品类型" + response.jsonPath().getString("lottery.type"));
}
//集卡结束后开奖--开奖类型:直接开奖
Response openResponse = newActivityService.openCollectGoodsPrize2("246", "19936","未满足 中奖条件");
openResponse.prettyPrint();
logger.info("开奖结果是:" + openResponse.jsonPath().getString("lottery.message"));
}
public Response playNewActivityResult(String activityId, String token, String collectRuleId) throws Exception {
Response playResponse = newActivityService.doJoin3(activityId, token, collectRuleId);
playResponse.prettyPrint();
String orderId = playResponse.jsonPath().getString("orderId");
Response statusResponse = newActivityService.getOrderStatus2(orderId);
// statusResponse.prettyPrint();
String playResult = statusResponse.jsonPath().getString("result");
int i = 30;
while (i > 0 && (playResult.equals("0"))) {
Thread.sleep(1000);
statusResponse = newActivityService.getOrderStatus2(orderId);
playResult = String.valueOf(statusResponse.jsonPath().getString("result"));
i--;
// statusResponse.prettyPrint();
}
return statusResponse;
}
public Response playCollectResult(String collectRuleId, String activityId) throws Exception {
Response openResponse = newActivityService.openCollectGoodsPrize(collectRuleId, activityId);
openResponse.prettyPrint();
String orderId = openResponse.jsonPath().getString("orderId");
Response statusResponse = newActivityService.getOrderStatus3(orderId);
// logger.info("开奖结果如下1:");
// statusResponse.prettyPrint();
String playResult = String.valueOf(statusResponse.jsonPath().getString("result"));
int i = 30;
while (i > 0 && (playResult.equals("0"))) {
Thread.sleep(1000);
statusResponse = newActivityService.getOrderStatus3(orderId);
playResult = String.valueOf(statusResponse.jsonPath().getString("result"));
i--;
// logger.info("开奖结果如下2:");
// statusResponse.prettyPrint();
}
return statusResponse;
}
// @AfterMethod
//每个方法之前清理数据库数据,保证无脏数据影响测试结果
public void tearDb() {
try {
Boolean clearResult1 = jdbc.update("delete from ckvtable.tb_kvtable_0687 where consumer_id = 100025007 and vkey like '%activity-centerwinOptionNum_100025007_19936_hdtool%'",null);
Boolean clearResult2 = jdbc.update("delete from ckvtable.tb_kvtable_0687 where consumer_id = 100025007 and vkey like '%cl_good_cid_Crule_grade_100025007_246%'",null);
Boolean clearResult3 = jdbc.update("delete from ckvtable.tb_kvtable_0687 where consumer_id = 100025007 and vkey in ('cl_good_cid_itemId_100025007_27221')",null);
Boolean clearResult4 = jdbc.update("delete from ckvtable.tb_kvtable_0687 where consumer_id = 100025007 and vkey = 'activity-centerjoinNum_100025007_19936'",null);
} catch (Exception e) {
e.printStackTrace();
}
}
}
\ No newline at end of file
/**
* Copyright (C), 2015-2018
* FileName: 集卡_指定卡片_不同奖项中奖条件测试
* Author: qianwenjun
* Date: 2018/3/13 17:06
* Description: 设置不同条件-中奖
*/
package http.cases.CollectActivityTest;
import base.DuibaLog;
import base.DuibaTestBase;
import com.alibaba.fastjson.JSON;
import http.model.CollectGoodsInfo;
import http.service.Activity.NewActivityService;
import http.service.Manager.EditManagerInfoService;
import http.service.Manager.GetManagerInfoService;
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.BeforeMethod;
import org.testng.annotations.Test;
import java.util.List;
/**
* 〈设置不同条件-中奖〉
*
* @author qianwenjun
* @create 2018/3/13
* @since 1.0.0
*/
public class 集卡_随机卡片_DuibaTest extends DuibaTestBase {
@Autowired
NewActivityService newActivityService;
@Autowired
GetManagerInfoService getManagerInfoService;
@Autowired
EditManagerInfoService editManagerInfoService;
private static DuibaLog logger = DuibaLog.getLogger();
@BeforeMethod
//每个方法之前清理数据库数据,保证无脏数据影响测试结果
public void clearDb() {
try {
Boolean clearResult2 = jdbc.update("delete from ckvtable.tb_kvtable_0687 where consumer_id = 100025007 and vkey like '%cl_good_cid_Crule_grade_100025007_247%'",null);
Boolean clearResult3 = jdbc.update("delete from ckvtable.tb_kvtable_0687 where consumer_id = 100025007 and vkey in ('cl_good_cid_itemId_100025007_27222','cl_good_cid_itemId_100025007_27223')",null);
Boolean clearResult4 = jdbc.update("delete from ckvtable.tb_kvtable_0687 where consumer_id = 100025007 and vkey = 'activity-centerjoinNum_100025007_19937'",null);
Boolean clearResult1 = jdbc.update("delete from ckvtable.tb_kvtable_0687 where consumer_id = 100025007 and vkey in ('cl_good_cid_itemId_100025007_27226')",null);
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void 集卡_中奖条件随机卡_2() throws Exception {
//获取集卡活动配置的奖品信息
Response awardResponse = getManagerInfoService.getCollectAwardsInfo("247");
String data = awardResponse.jsonPath().getString("data.config.rewards[0]");
String awardsName = awardResponse.jsonPath().getString("data.config.rewards[0].rlName");//"【勿动】自动化测试虚拟商品"
String awardsType = awardResponse.jsonPath().getString("data.config.rewards[0].rlType");//virtual
//自定义活动游戏 结果
Response playResponse = playNewActivityResult("19937", "r3oq9gqkf", "247");
playResponse.prettyPrint();
//校验中奖结果类型
String itemId= playResponse.jsonPath().getString("lottery.itemId");
Assert.assertEquals(String.valueOf(playResponse.jsonPath().getString("lottery.type")), "collectGoods", "校验中奖类型失败");
logger.info("校验中奖奖品类型成功,自定义活动游戏中奖奖品类型" + playResponse.jsonPath().getString("lottery.type"));
logger.info("中奖卡片id为" + itemId);
Response myCollectInfoResponse = newActivityService.getCollectGoodsInfo2("247",2720);
List<CollectGoodsInfo> myCollectInfos = myCollectInfoResponse.jsonPath().getList("collectGoods",CollectGoodsInfo.class);
logger.info("myCollectInfo的信息为"+JSON.toJSONString(myCollectInfos));
for (CollectGoodsInfo info:myCollectInfos){
if (info.getId().equals(itemId)){
Assert.assertEquals(info.getCount(),"1","校验卡片数量失败");
}else {
break;
}
}
//集卡结束后开奖--开奖类型:直接开奖
Response openResponse = playCollectResult("247", "19937");
Assert.assertEquals(openResponse.jsonPath().getString("lottery.title"), awardsName, "校验奖项失败");
Assert.assertEquals(openResponse.jsonPath().getString("lottery.type"), awardsType, "校验奖项失败");
logger.info("校验集卡抽奖奖项type、name成功,奖品信息为:" + openResponse.jsonPath().getString("lottery.title"));
Response myCollectInfoResponse2 = newActivityService.getCollectGoodsInfo2("247",2720);
List<CollectGoodsInfo> myCollectInfos2 = myCollectInfoResponse2.jsonPath().getList("collectGoods",CollectGoodsInfo.class);
logger.info("开奖之后,myCollectInfo的信息为"+JSON.toJSONString(myCollectInfos2));
for (CollectGoodsInfo info:myCollectInfos2){
if (info.getId().equals(itemId)){
Assert.assertEquals(info.getCount(),"0","校验开奖后卡片数量减少失败");
}else {
break;
}
}
}
@Test
public void 集卡_随机卡_不满足开奖条件() throws Exception{
String itemId = null;
for(int i=0;i<2;i++){
Response playResponse = playNewActivityResult("19938", "r3oq9gqkf", "248");
//校验中奖结果类型
itemId= playResponse.jsonPath().getString("lottery.itemId");
Assert.assertEquals(String.valueOf(playResponse.jsonPath().getString("lottery.type")), "collectGoods", "校验中奖类型失败");
logger.info("校验中奖奖品类型成功,自定义活动游戏中奖奖品类型" + playResponse.jsonPath().getString("lottery.type"));
logger.info("中奖卡片id为" + itemId);
}
Response myCollectInfoResponse = newActivityService.getCollectGoodsInfo2("248",2720);
List<CollectGoodsInfo> myCollectInfos = myCollectInfoResponse.jsonPath().getList("collectGoods",CollectGoodsInfo.class);
logger.info("myCollectInfo的信息为"+JSON.toJSONString(myCollectInfos));
for (CollectGoodsInfo info:myCollectInfos){
if (info.getId().equals(itemId)){
Assert.assertEquals(info.getCount(),"2","校验卡片数量失败");
}else {
break;
}
}
//集卡结束后开奖--开奖类型:直接开奖
Response openResponse = newActivityService.openCollectGoodsPrize2("248", "19938","未满足 中奖条件");
openResponse.prettyPrint();
logger.info("开奖结果是:" + openResponse.jsonPath().getString("lottery.message"));
}
public Response playNewActivityResult(String activityId, String token, String collectRuleId) throws Exception {
Response playResponse = newActivityService.doJoin3(activityId, token, collectRuleId);
playResponse.prettyPrint();
String orderId = playResponse.jsonPath().getString("orderId");
Response statusResponse = newActivityService.getOrderStatus2(orderId);
// statusResponse.prettyPrint();
String playResult = statusResponse.jsonPath().getString("result");
int i = 8;
while (i > 0 && (playResult.equals("0"))) {
Thread.sleep(1000);
statusResponse = newActivityService.getOrderStatus2(orderId);
playResult = String.valueOf(statusResponse.jsonPath().getString("result"));
i--;
// statusResponse.prettyPrint();
}
return statusResponse;
}
public Response playCollectResult(String collectRuleId, String activityId) throws Exception {
Response openResponse = newActivityService.openCollectGoodsPrize(collectRuleId, activityId);
openResponse.prettyPrint();
String orderId = openResponse.jsonPath().getString("orderId");
Response statusResponse = newActivityService.getOrderStatus3(orderId);
// logger.info("开奖结果如下1:");
// statusResponse.prettyPrint();
String playResult = String.valueOf(statusResponse.jsonPath().getString("result"));
int i = 8;
while (i > 0 && (playResult.equals("0"))) {
Thread.sleep(1000);
statusResponse = newActivityService.getOrderStatus3(orderId);
playResult = String.valueOf(statusResponse.jsonPath().getString("result"));
i--;
// logger.info("开奖结果如下2:");
// statusResponse.prettyPrint();
}
return statusResponse;
}
// @AfterMethod
//每个方法之前清理数据库数据,保证无脏数据影响测试结果
public void tearDb() {
try {
//清除自定义活动-中奖奖品数量信息(5种)
Boolean clearResult1 = jdbc.update("delete from ckvtable.tb_kvtable_0687 where consumer_id = 100025007 and vkey like '%activity-centerwinOptionNum_100025007_19123_hdtool%'",null);
//清除集卡规则n等级奖项-中奖次数(集卡规则id:8)
Boolean clearResult2 = jdbc.update("delete from ckvtable.tb_kvtable_0687 where consumer_id = 100025007 and vkey like '%cl_good_cid_Crule_grade_100025007_8%'",null);
//清除收集的集卡商品数量(集卡商品id:27148,27147,27146,27145,27144)
Boolean clearResult3 = jdbc.update("delete from ckvtable.tb_kvtable_0687 where consumer_id = 100025007 and vkey in ('cl_good_cid_itemId_100025007_27154','cl_good_cid_itemId_100025007_27155','cl_good_cid_itemId_100025007_27156','cl_good_cid_itemId_100025007_27157','cl_good_cid_itemId_100025007_27158')",null);
//清除用户参与活动次数(活动id:19009)
Boolean clearResult4 = jdbc.update("delete from ckvtable.tb_kvtable_0687 where consumer_id = 100025007 and vkey = 'activity-centerjoinNum_100025007_19123'",null);
} catch (Exception e) {
e.printStackTrace();
}
}
}
\ No newline at end of file
/**
* Copyright (C), 2015-2018
* FileName: 集卡商品测试_DuibaTest
* Author: qianwenjun
* Date: 2018/10/29 20:27
* Description:
*/
package http.cases.CollectRuleTest;
import base.DuibaLog;
import base.DuibaTestBase;
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.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static io.restassured.RestAssured.given;
/**
* 〈〉
*
* @author qianwenjun
* @create 2018/10/29
* @since 1.0.0
*/
public class 集卡商品测试_DuibaTest extends DuibaTestBase {
private DuibaLog logger = DuibaLog.getLogger();
@Value("${manager.host}")
//ManagerHost = mng.duibatest.com.cn
String ManagerHost;
@Autowired
Authorization authorization;
private List<String> ids = new ArrayList<>();
private List<String> extrIds = new ArrayList<>();
@Test(description = "普通集卡商品")
public void 新建普通集卡商品测试() throws Exception{
String url = ManagerHost + "/AItem/doUpdateCollectGoods";
Map<String,Object> map = new HashMap<>();
map.put("name","qwj集卡自动化测试");
map.put("subtitle","qwj集卡自动化测试");
map.put("description","qwj集卡自动化测试");
map.put("smallImage","//yun.duiba.com.cn/developer/img/default_img.jpg");
map.put("bannerImgNew","//yun.duiba.com.cn/developer/img/default_img.jpg");
map.put("collectType","0");
map.put("remaining","99999");
map.put("limitCount","888");
map.put("limitScope","forever");
map.put("saveType","save");
Response response = given().contentType("application/x-www-form-urlencoded;charset=UTF-8").cookies(authorization.ssoLogin()).params(map).post("http://"+url);
response.prettyPrint();//http接口访问结果为空,不需要校验response结果
List<Map<String,Object>> results = jdbc.findModeResult("select * from goods.item where description = ?","qwj集卡自动化测试");
Assert.assertFalse((results.size()==0),"创建失败,存数据库数据为空");
for (int i=0;i<results.size();i++){
ids.add(results.get(i).get("id").toString());
Assert.assertEquals(results.get(i).get("remaining").toString(),"99999","保存的库存数据校验失败");
Assert.assertEquals(results.get(i).get("type").toString(),"collectGoods","保存的商品类型校验失败");
Map<String,Object> result1 = jdbc.findSimpleResult("select * from goods.tb_item_new_extra where item_id = ? and prop_name = 'collectGoodsType'\n",results.get(i).get("id").toString());
Assert.assertEquals(result1.get("prop_value").toString(),"0","校验保存集卡商品类型失败");
}
}
@Test(description = "新建随机-全局红包集卡商品")
public void 新建全局红包集卡商品测试() throws Exception{
String url = ManagerHost + "/AItem/doUpdateCollectGoods";
Map<String,Object> map = new HashMap<>();
map.put("name","qwj集卡自动化测试-全局红包参数");
map.put("subtitle","qwj集卡自动化测试-全局红包参数");
map.put("description","qwj集卡自动化测试-全局红包参数");
map.put("smallImage","//yun.duiba.com.cn/developer/img/default_img.jpg");
map.put("bannerImgNew","//yun.duiba.com.cn/developer/img/default_img.jpg");
//用于全局红包玩法的参数
map.put("collectType","1");//商品类型-随机红包
map.put("rewardType","0");//账户类型-全局红包
map.put("bonusAreaA","5");
map.put("bonusAreaB","100");
map.put("remaining","99999");
map.put("limitScope","forever");
map.put("saveType","save");
map.put("stockWarnValue","10");//库存预警和通知人
map.put("adminId","1");
map.put("ownerAppId","1,2,3");
Response response = given().contentType("application/x-www-form-urlencoded;charset=UTF-8").cookies(authorization.ssoLogin()).params(map).post("http://"+url);
response.prettyPrint();
List<Map<String,Object>> results = jdbc.findModeResult("select * from goods.item where description = ?","qwj集卡自动化测试-全局红包参数");
Assert.assertFalse((results.size()==0),"创建失败,存数据库数据为空");
for (int i=0;i<results.size();i++){
ids.add(results.get(i).get("id").toString());
Assert.assertEquals(results.get(i).get("remaining").toString(),"99999","保存的库存数据校验失败");
Assert.assertEquals(results.get(i).get("type").toString(),"collectGoods","保存的商品类型校验失败");
Map<String,Object> result1 = jdbc.findSimpleResult("select * from goods.item_extra where item_id = ?\n",results.get(i).get("id").toString());
Assert.assertEquals(result1.get("owner_app_ids").toString(),"1,2,3","保存的定向的app数据校验失败");
Assert.assertEquals(result1.get("bonus_area").toString(),"500,10000","保存的红包区间数据校验失败");
extrIds.add(result1.get("id").toString());
Map<String,Object> result2 = jdbc.findSimpleResult("select * from goods.tb_item_new_extra where item_id = ? and prop_name = 'collectGoodsType'\n",results.get(i).get("id").toString());
Assert.assertEquals(result2.get("prop_value").toString(),"1","校验保存集卡商品类型失败");
Map<String,Object> result3 = jdbc.findSimpleResult("select * from goods.tb_item_new_extra where item_id = ? and prop_name = 'rewardType'\n",results.get(i).get("id").toString());
Assert.assertEquals(result3.get("prop_value").toString(),"0","校验保存集卡商品类型失败");
}
}
@Test(description = "新建随机-手气红包集卡商品")
public void 新建手气红包集卡商品测试() throws Exception{
String url = ManagerHost + "/AItem/doUpdateCollectGoods";
Map<String,Object> map = new HashMap<>();
map.put("name","qwj集卡自动化测试-手气红包参数");
map.put("subtitle","qwj集卡自动化测试-手气红包参数");
map.put("description","qwj集卡自动化测试-手气红包参数");
map.put("smallImage","//yun.duiba.com.cn/developer/img/default_img.jpg");
map.put("bannerImgNew","//yun.duiba.com.cn/developer/img/default_img.jpg");
//用于全局红包玩法的参数
map.put("collectType","1");//商品类型-随机红包
map.put("rewardType","1");//账户类型-手气红包
map.put("bonusAreaA","10");
map.put("bonusAreaB","90");
map.put("remaining","99999");
map.put("limitScope","forever");
map.put("saveType","save");
map.put("stockWarnValue","10");//库存预警和通知人
map.put("adminId","1");
map.put("ownerAppId","1,2");
Response response = given().contentType("application/x-www-form-urlencoded;charset=UTF-8").cookies(authorization.ssoLogin()).params(map).post("http://"+url);
response.prettyPrint();
//普通商品存储
List<Map<String,Object>> results = jdbc.findModeResult("select * from goods.item where description = ?","qwj集卡自动化测试-手气红包参数");
Assert.assertFalse((results.size()==0),"创建失败,存数据库数据为空");
for (int i=0;i<results.size();i++){
ids.add(results.get(i).get("id").toString());
Assert.assertEquals(results.get(i).get("remaining").toString(),"99999","保存的库存数据校验失败");
Assert.assertEquals(results.get(i).get("type").toString(),"collectGoods","保存的商品类型校验失败");
Map<String,Object> result1 = jdbc.findSimpleResult("select * from goods.item_extra where item_id = ?\n",results.get(i).get("id").toString());
Assert.assertEquals(result1.get("owner_app_ids").toString(),"1,2","保存的定向的app数据校验失败");
Assert.assertEquals(result1.get("bonus_area").toString(),"1000,9000","保存的红包区间数据校验失败");
extrIds.add(result1.get("id").toString());
Map<String,Object> result2 = jdbc.findSimpleResult("select * from goods.tb_item_new_extra where item_id = ? and prop_name = 'collectGoodsType'\n",results.get(i).get("id").toString());
Assert.assertEquals(result2.get("prop_value").toString(),"1","校验保存集卡商品类型失败");
Map<String,Object> result3 = jdbc.findSimpleResult("select * from goods.tb_item_new_extra where item_id = ? and prop_name = 'rewardType'\n",results.get(i).get("id").toString());
Assert.assertEquals(result3.get("prop_value").toString(),"1","校验保存集卡商品类型失败");
}
}
@AfterClass
public void tearDown() {
try {
// Boolean result5 = jdbc.update("delete from goods.item where description = ?","qwj集卡自动化测试-手气红包参数");
// Boolean result4 = jdbc.update("delete from goods.item where description = ?","qwj集卡自动化测试-全局红包参数");
for (int i=0;i<ids.size();i++){
Boolean result1 = jdbc.update("delete from goods.item where id = ?",ids.get(i));
Boolean result2 = jdbc.update("delete from goods.item_extra where item_id = ?",ids.get(i));
Boolean result3 = jdbc.update("delete from goods.tb_item_new_extra where item_id = ?",ids.get(i));
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
\ No newline at end of file
/**
* Copyright (C), 2015-2018
* FileName: 集卡规则_中奖属性配置_DuibaTest
* Author: qianwenjun
* Date: 2018/10/29 20:32
* Description:
*/
package http.cases.CollectRuleTest;
import base.DuibaLog;
import base.DuibaTestBase;
import cn.com.duiba.activity.center.api.dto.activity.CLRuleDto;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import http.service.Authorization;
import io.restassured.response.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static io.restassured.RestAssured.given;
/**
* 〈〉
*
* @author qianwenjun
* @create 2018/10/29
* @since 1.0.0
*/
public class 集卡规则_中奖属性配置_DuibaTest extends DuibaTestBase {
private DuibaLog logger = DuibaLog.getLogger();
@Value("${manager.host}")
//ManagerHost = mng.duibatest.com.cn
String ManagerHost;
@Autowired
Authorization authorization;
private List<Map<String,Object>> propKeys;
private List<Map<String,Object>> rules;
private String newId;
@Test(priority = 1,description = "新建集卡中奖属性配置")
public void createClCardPropTest() throws Exception{
String savePropertyUrl = ManagerHost + "/newmanager/clcard/saveProperty";
this.prepareData("create");
Map<String,Object> map = new HashMap<>();
map.put("clName","集卡规则-中奖属性-新建测试");
map.put("propsKeyList",propKeys);
map.put("rules",rules);
JSONObject jsonParam = JSONObject.parseObject(JSON.toJSONString(map));
// logger.info("jsonParam的信息为"+ jsonParam);
Response response = given().contentType("application/json;charset=UTF-8").cookies(authorization.ssoLogin()).body(jsonParam).post("http://"+savePropertyUrl);
response.prettyPrint();
Assert.assertEquals(response.jsonPath().getString("success"),"true","新建集卡属性配置失败");
newId = response.jsonPath().getString("data");
logger.info("校验新建集卡属性配置成功,新建的中奖属性配置id为"+newId);
// logger.info("新建的规则id为"+newId);
}
@Test(priority = 2,description = "修改集卡中奖属性配置")
public void editClCardPropTest() throws Exception{
String savePropertyUrl = ManagerHost + "/newmanager/clcard/saveProperty";
this.prepareData("edit");
Map<String,Object> map = new HashMap<>();
map.put("clName","集卡规则-中奖属性-修改测试");
map.put("propsKeyList",propKeys);
map.put("rules",rules);
map.put("id",newId);
JSONObject jsonParam = JSONObject.parseObject(JSON.toJSONString(map));
// logger.info("jsonParam的信息为"+ jsonParam);
Response response = given().contentType("application/json;charset=UTF-8").cookies(authorization.ssoLogin()).body(jsonParam).post("http://"+savePropertyUrl);
response.prettyPrint();
//校验修改内容
Map<String,Object> selectResult = jdbc.findSimpleResult("select * from act_com_conf.tb_clcard_config where id =?",newId);
List<String> rules = JSONArray.parseArray(selectResult.get("rules").toString(),String.class);
CLRuleDto dto1 = JSONObject.parseObject(rules.get(0),CLRuleDto.class);
CLRuleDto dto2 = JSONObject.parseObject(rules.get(1),CLRuleDto.class);
// logger.info("dto1的信息为"+JSON.toJSONString(dto1));
Assert.assertEquals(selectResult.get("cl_name").toString(),"集卡规则-中奖属性-修改测试","修改cl_name失败");
Assert.assertEquals(dto1.getProperyVal().toString(),"3","修改propsVaul失败");
Assert.assertEquals(dto2.getTitle().toString(),"D5-修改","修改title失败");
logger.info("校验修改propsVaul、title成功");
}
@Test(priority = 3,description = "删除集卡中奖属性配置")
public void deleteClCardPropTest() throws Exception{
String deleteUrl = ManagerHost + "/newmanager/clcard/deleteById";
Map<String,String> map = new HashMap<>();
map.put("id",newId);
Response response = given().contentType("application/x-www-form-urlencoded;charset=UTF-8").cookies(authorization.ssoLogin()).params(map).get("http://"+deleteUrl);
response.prettyPrint();
Assert.assertTrue(response.jsonPath().get("success"),"删除中奖配置失败");
//校验修改内容
Map<String,Object> selectResult = jdbc.findSimpleResult("select * from act_com_conf.tb_clcard_config where id =?",newId);
Assert.assertEquals(selectResult.get("deleted").toString(),"true","删除中奖条件失败");
logger.info("校验删除属性配置成功");
}
public void prepareData(String type) throws Exception {
propKeys = new ArrayList<>();
Map<String,Object> propKey1 = new HashMap<>();
propKey1.put("name","增加倍数");
propKey1.put("value","plus_multiple");
Map<String,Object> propKey2 = new HashMap<>();
propKey2.put("name","减少倍数");
propKey2.put("value","plus_score");
Map<String,Object> propKey3 = new HashMap<>();
propKey3.put("name","增加分数");
propKey3.put("value","plus_multiple");
Map<String,Object> propKey4 = new HashMap<>();
propKey4.put("name","减少分数");
propKey4.put("value","reduce_score");
propKeys.add(propKey1);
propKeys.add(propKey2);
propKeys.add(propKey3);
propKeys.add(propKey4);
rules = new ArrayList<>();
Map<String,Object> rule1 = new HashMap<>();
Map<String,Object> propKey11 = new HashMap<>();
if (type.equals("edit")){
rule1.put("propName","增加倍数");
rule1.put("type","collectGoods");
propKey11.put("properyVal","3");
rule1.put("properyVal","3");//修改
}else if (type.equals("create")){
propKey11.put("properyVal","5");
rule1.put("properyVal","5");
}
propKey11.put("propName","增加倍数");
propKey11.put("properyKey","plus_multiple");
rule1.put("id","27179");
rule1.put("img","//yun.dui88.com/images/201804/6llpke07o7.png");
rule1.put("name","【勿动】自动化-E5");
rule1.put("propery",JSONObject.parseObject(JSON.toJSONString(propKey11)));
rule1.put("properyKey","plus_multiple");
rule1.put("selImg","//yun.dui88.com/images/201804/4o6m5hym9f.png");
rule1.put("title","E5");
Map<String,Object> rule2 = new HashMap<>();
Map<String,Object> propKey22 = new HashMap<>();
if (type.equals("edit")){
rule2.put("propName","减少倍数");
rule2.put("type","collectGoods");
rule2.put("title","D5-修改");//修改
}else if (type.equals("create")){
rule2.put("title","D5");
}
propKey22.put("propName","减少倍数");
propKey22.put("properyKey","plus_score");
propKey22.put("properyVal","3");
rule2.put("id","27178");
rule2.put("img","//yun.dui88.com/images/201804/fzi156of2i.png");
rule2.put("name","【勿动】自动化-D5");
rule2.put("propery",JSONObject.parseObject(JSON.toJSONString(propKey22)));
rule2.put("properyKey","reduce_multiple");
rule2.put("properyVal","3");
rule2.put("selImg","//yun.dui88.com/images/201804/eqyz7bkicr.png");
Map<String,Object> rule3 = new HashMap<>();
Map<String,Object> propKey33 = new HashMap<>();
propKey33.put("propName","增加分数");
propKey33.put("properyKey","plus_multiple");
propKey33.put("properyVal","100");
rule3.put("id","27177");
rule3.put("img","//yun.dui88.com/images/201804/iml7vof7pl.png");
rule3.put("name","【勿动】自动化-C5");
rule3.put("propery",JSONObject.parseObject(JSON.toJSONString(propKey3)));
rule3.put("properyKey","plus_score");
rule3.put("properyVal","100");
rule3.put("selImg","//yun.dui88.com/images/201804/v2bkoqt94t.png");
rule3.put("title","C5");
if (type.equals("edit")){
rule3.put("propName","增加分数");
rule3.put("type","collectGoods");
}
Map<String,Object> rule4 = new HashMap<>();
Map<String,Object> propKey44 = new HashMap<>();
propKey44.put("propName","减少分数");
propKey44.put("properyKey","reduce_score");
propKey44.put("properyVal","50");
rule4.put("id","27176");
rule4.put("img","//yun.dui88.com/images/201804/mof8hzzh95.png");
rule4.put("name","【勿动】自动化-B5");
rule4.put("propery",JSONObject.parseObject(JSON.toJSONString(propKey4)));
rule4.put("properyKey","reduce_score");
rule4.put("properyVal","50");
rule4.put("selImg","//yun.dui88.com/images/201804/gzfoni8w0i.png");
rule4.put("title","B5");
if (type.equals("edit")){
rule4.put("propName","减少分数");
rule4.put("type","collectGoods");
}
rules.add(rule1);
rules.add(rule2);
rules.add(rule3);
rules.add(rule4);
}
@AfterClass
public void tearDown() {
try {
Boolean result = jdbc.update("delete from act_com_conf.tb_clcard_config where id =?",newId);
} catch (SQLException e) {
e.printStackTrace();
}
}
}
\ No newline at end of file
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 base.DuibaLog;
import http.enums.ActivityDataTypeEnum;
import http.model.AwardVO;
import http.model.CustomHdToolVO;
import http.service.hd.CustomHdToolCtrlService;
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
package http.cases.GameTest;
import base.DuibaLog;
import http.service.Activity.ManagerService;
import http.service.Activity.NgapiService;
import http.service.Authorization;
import http.service.hd.ActivityService;
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 utils.ExcelDataProvider;
import utils.MatcherString;
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:游戏测试:马上使用跳转福袋的链接
*/
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
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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