Commit 1e07db92 authored by 钱雯君's avatar 钱雯君

add

parent 2480dc64
package http.cases.PluginActivityTest;
import base.DuibaLog;
import base.SFExpress;
import base.ServiceDoctor;
import org.testng.SkipException;
import org.testng.annotations.BeforeSuite;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by hanzhanli on 2017/9/21.
*/
public class Server_pluginTest {
private DuibaLog logger = DuibaLog.getLogger();
private Map<String,String> fromMap=new HashMap<>();
private Map<String,List<String>> logMap=new HashMap<>();
@BeforeSuite
public void onStart() {
//logger.info("job-name:"+System.getProperty("JOB_NAME"));
//logger.info("属性:"+System.getProperties());
logger.info("duiba-server开始检测");
ServiceDoctor serviceDoctor=new ServiceDoctor("duiba-server.properties");
SFExpress.addToBeTestedServices(serviceDoctor.getToBeTestedServices());
//fromMap.putAll(serviceDoctor.getLogLenth());
SFExpress.addExceptionService(serviceDoctor.getExceptionService(60*2));
logger.info("duiba-server检测完毕");
logger.info("duiba-server-center开始检测");
serviceDoctor=new ServiceDoctor("duiba-server-center.properties");
SFExpress.addToBeTestedServices(serviceDoctor.getToBeTestedServices());
//fromMap.putAll(serviceDoctor.getLogLenth());
SFExpress.addExceptionService(serviceDoctor.getExceptionService(60*2));
logger.info("duiba-server-center检测完毕");
if(SFExpress.getExceptionServices().size()>0){
logger.info("服务未启动:"+SFExpress.getExceptionServices().toString());
throw new SkipException("被测服务未全部启动");
}
}
public static void main(String[] args) {
// String s = "最近变更:2018-1-3 13:48:07-activity-access-web:疯狂打气球—jiangxixi/疯狂打气球—jiangxixi/\n";
// String name = s.split("—")[1].split("/")[0];
// System.out.println(name);
// List<String> list = new ArrayList<>();
// list.clear();
// Map<String,Object> map = new HashMap<>();
// map.put("name",list);
ServiceDoctor serviceDoctor=new ServiceDoctor("duiba-server.properties");
}
}
package http.cases.PluginActivityTest;
import base.DuibaLog;
import base.DuibaTestBase;
import http.service.Activity.ActivityPlugin;
import http.service.Activity.ManagerService;
import http.service.Authorization;
import http.service.hd.ActivityService;
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 utils.MatcherString;
import java.lang.reflect.Method;
/**
* Created by lvwenyan on 2018/3/6.
*/
public class 插件_优惠券测试_pluginTest extends DuibaTestBase {
@Autowired
ActivityPlugin activityPlugin;
@Autowired
ManagerService managerService;
@Autowired
ActivityService activityService;
@Autowired
Authorization authorization;
private static DuibaLog logger = DuibaLog.getLogger();
//指定用户
private static int uid = 2721;
@DataProvider
public Object[][] providerMethod(Method method){
Object[][] result = null;
if(method.getName().equals("插件活动出券测试")) {
result = new Object[][]{
new Object[]{1, "26775", "236", "100026000","chome","iOS","马上使用跳转优惠券链接券码的链接"}, //case1
new Object[]{2, "27128", "237", "100026000", "chome","iOS","马上使用跳转优惠券商家落地页的链接(iOS登录)"}, //case2
new Object[]{2, "27128", "237", "100026000","chome","Android","马上使用跳转优惠券商家落地页的链接(Android登录)"},//case2
new Object[]{3, "27129", "238", "100026000","chome","iOS","马上使用跳转优惠券兑换记录页的链接"}, //case3
new Object[]{4,"27129","239","100026000","chome","iOS","马上使用跳转福袋的链接"} //case4
};
}
return result;
}
/**
* @param caseNum 用例编号
* @param couponId 优惠券Id
* @param activityId 活动Id
* @param consumerId 用户Id
* @param url 入参url
* @param device 设备(iOS/Android)
* @param casename 用例名称打印
* @throws Exception
*/
@Test(dataProvider = "providerMethod" )
public void 插件活动出券测试(int caseNum,String couponId,String activityId,String consumerId,String url,String device,String casename) throws Exception {
logger.info("-----------------------------"+casename+"-----------------------------");
//获取管理员后台待校验项
Response managerResponse = managerService.CouponConfig(couponId);
Response linkResponse = managerService.ShowCoupons(couponId);
String cptitle = 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 usebtn = 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.插件活动抽奖(uid,consumerId,activityId,url,device);
response.prettyPrint();
//根据case选择对应的校验项
switch(caseNum){
case 1:
Assert.assertEquals(response.jsonPath().getString("lottery.iosDownloadUrl"),linkUrl,"校验Url失败");
Assert.assertEquals(response.jsonPath().getString("lottery.useBtnText"),usebtn,"校验useBtnText失败");
Assert.assertEquals(response.jsonPath().getString("lottery.title"),cptitle,"校验title失败");
logger.info("校验链接券码成功");
break;
case 2:
if ( device.equals("iOS")) {
Assert.assertEquals(response.jsonPath().getString("lottery.iosDownloadUrl"), iOSDL, "校验Url失败");
}else{
Assert.assertEquals(response.jsonPath().getString("lottery.androidDownloadUrl"),androidDL,"校验Url失败");
}
Assert.assertEquals(response.jsonPath().getString("lottery.useBtnText"),usebtn,"校验useBtnText失败");
Assert.assertEquals(response.jsonPath().getString("lottery.title"),cptitle,"校验title失败");
logger.info("校验商家落地页下载链接券码成:q~功");
break;
case 3:
Assert.assertTrue(response.jsonPath().getString("lottery.iosDownloadUrl").contains(actLinkEx),"兑换记录页url与实际url不匹配");
Assert.assertEquals(response.jsonPath().getString("lottery.useBtnText"),"查看使用方法","校验useBtnText失败");
Assert.assertEquals(response.jsonPath().getString("lottery.title"),cptitle,"校验title失败");
logger.info("校验兑换记录页下载链接券码成功");
break;
case 4:
// if (response.jsonPath().getString("lottery.type").equals("lucky")) {
Assert.assertTrue(response.jsonPath().getString("lottery.iosDownloadUrl").contains("//activity.tuiatest.cn/activity/redirect?orderId=plugin"), "福袋url与实际url不匹配");
Assert.assertTrue(response.jsonPath().getString("lottery.iosDownloadUrl").contains("activityId=239&appId=2239&consumerId=100026000"), "福袋url与实际url不匹配");
Assert.assertEquals(response.jsonPath().getString("lottery.type"), "lucky", "校验type失败");
Assert.assertEquals(response.jsonPath().getString("lottery.showUse"), "true", "校验显示按钮失败");
Assert.assertEquals(response.jsonPath().getString("lottery.useBtnText"), "马上使用", "校验useBtnText失败");
// } else if (response.jsonPath().getString("lottery.type").equals("thanks")){
// logger.info("福袋异常,降级谢谢参与");//福袋库存不足会降级成谢谢参与!
// }
// if(activityService.isRunning("10.110.10.12","17791","tuia-engine")){
// logger.info("tuia-engine服务启动成功");
// Assert.assertEquals(response.jsonPath().getString("lottery.type"), "lucky", "校验类型失败");
// Assert.assertTrue(response.jsonPath().getString("lottery.link").contains("//activity.m.duibatest.com.cn/crecord/recordLuckDetailNew?"));
// Assert.assertTrue(response.jsonPath().getString("lottery.iosDownloadUrl").contains("activityId=239&appId=2239&consumerId=100026000"));
// Assert.assertTrue(response.jsonPath().getString("lottery.iosDownloadUrl").contains("//activity.tuiatest.cn/activity/redirect?orderId=plugin"));
// Assert.assertEquals(response.jsonPath().getString("lottery.showUse"), "true", "校验显示按钮失败");
// Assert.assertEquals(response.jsonPath().getString("lottery.useBtnText"),"马上使用","校验useBtnText失败");
// logger.info("校验福袋:link,id,useBtnText成功");
// }else{
// logger.info("tuia-engine服务启动未成功");
// Assert.assertEquals(response.jsonPath().getString("lottery.type"), "thanks", "校验类型失败");
// logger.info("校验福袋降级谢谢参与成功");
// }
break;
}
}
//活动抽奖接口传参单独抽离
public Response 插件活动抽奖(int uid,String consumerId,String activityId,String url,String device) throws Exception {
Response response = activityPlugin.doJoin(uid,consumerId,activityId,url);
response.prettyPrint();
String orderId = response.jsonPath().getString("orderNum");
response = activityPlugin.getOrderStatus2(uid,consumerId,orderId,device);
String result = String.valueOf(response.jsonPath().getString("result"));
int i= 8;
while(i>0&&(result.equals("0"))){
Thread.sleep(1000);
response = activityPlugin.getOrderStatus2(uid,consumerId,orderId,device);
result = String.valueOf(response.jsonPath().getString("result"));
i--;
}
response.prettyPrint();
return response;
}
}
/**
* Copyright (C), 2015-2018
* FileName: 插件_抽奖扣积分测试_PluginTest
* Author: qianwenjun
* Date: 2018/10/29 15:36
* Description:
*/
package http.cases.PluginActivityTest;
import base.DuibaLog;
import base.DuibaTestBase;
import http.service.Activity.ActivityPlugDrawInfoService;
import http.service.hd.DeveloperConfigService;
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;
/**
* 〈〉
*
* @author qianwenjun
* @create 2018/10/29
* @since 1.0.0
*/
public class 插件_抽奖扣积分测试_PluginTest extends DuibaTestBase {
@Autowired
ActivityPlugDrawInfoService activityPlugDrawInfoService;
@Autowired
DeveloperConfigService developerConfigService;
private int uid = 3982;
private String consumerId = "100092192";
private static DuibaLog logger = DuibaLog.getLogger();
@Test
public void 插件_扣积分测试() throws Exception{
//appid=18816的后台配置积分汇率为50积分/元;
//插件的积分价值1元
// Response appInfo = developerConfigService.getAppInfo("18816");
// String creditsRate = appInfo.jsonPath().getString("data.creditsRate");
Map<String,Object> res = jdbc.findSimpleResult("select * from credits_dev.app where id = '18816'");
String creditsRate = res.get("credits_rate").toString();
logger.info("appId=18816的积分汇率为:"+creditsRate);
Map<String,Object> user = jdbc.findSimpleResult("select * from dafuweng.user where id=?\n",uid);
Map<String,Object> consumer = jdbc.findSimpleResult("select * from new_consumer.consumer_0010 where id=?\n",consumerId);
Long userCredit = Long.parseLong(user.get("credits").toString());
Long consumerCredit = Long.parseLong(consumer.get("credits").toString());
Response playResponse = this.playPlugin(uid,"2796");
Assert.assertEquals(playResponse.jsonPath().getString("lottery.type"),"alipay","插件抽奖的奖品类型校验失败");
Map<String,Object> user1 = jdbc.findSimpleResult("select * from dafuweng.user where id=?\n",uid);
Map<String,Object> consumer1 = jdbc.findSimpleResult("select * from new_consumer.consumer_0010 where id=?\n",consumerId);
String userCredit1 = user1.get("credits").toString();
String consumerCredit1 = consumer1.get("credits").toString();
Assert.assertEquals(userCredit1,String.valueOf(userCredit-50),"user积分扣除校验失败");
Assert.assertEquals(consumerCredit1,String.valueOf(consumerCredit-50),"consumer积分扣除校验失败");
logger.info("校验积分消耗成功,原积分值="+userCredit+",消耗后积分值为"+userCredit1);
}
public Response playPlugin(int uid, String activityId) throws Exception {
Response response = activityPlugDrawInfoService.doJoinPlugdraw(uid,activityId);
response.prettyPrint();
String orderId = response.jsonPath().getString("orderId");
response = activityPlugDrawInfoService.getOrderStatusPlugdraw(uid,orderId);
String result = String.valueOf(response.jsonPath().getString("lotteryCode"));
int i= 30;
while(i>0&&(result.equals("0"))){
Thread.sleep(1000);
response = activityPlugDrawInfoService.getOrderStatusPlugdraw(uid,orderId);
result = String.valueOf(response.jsonPath().getString("lotteryCode"));
i--;
}
response.prettyPrint();
return response;
}
}
\ No newline at end of file
/**
* Copyright (C), 2015-2018
* FileName: 插件_限制次数测试_pluginTest
* Author: qianwenjun
* Date: 2018/7/17 13:41
* Description:
*/
package http.cases.PluginActivityTest;
import base.DuibaLog;
import base.DuibaTestBase;
import http.service.Activity.ActivityPlugDrawInfoService;
import io.restassured.response.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.testng.Assert;
import org.testng.annotations.Test;
import utils.MatcherString;
import java.util.Map;
/**
* 〈〉
*
* @author qianwenjun
* @create 2018/7/17
* @since 1.0.0
*/
public class 插件_限制次数测试_pluginTest extends DuibaTestBase {
@Autowired
ActivityPlugDrawInfoService activityPlugDrawInfoService;
private static DuibaLog logger = DuibaLog.getLogger();
//指定用户
private static int uid = 2721;
private static final Integer uid_SubCredits = 3280;
@Test
public void 插件限制永久2_免费无限测试() {
try {
tear1();
for (int i=0;i<2;i++){
Response response = playPlugin(uid,"2199");
response.prettyPrint();
}
Map<String,Object> freeTimes = jdbc.findSimpleResult("select * from ckvtable.tb_kvtable_0656 where vkey = 'activity-centerjoinPlugdrawNum_100026000_plugdraw_2199'\n");
Map<String,Object> actcommcTimes = jdbc.findSimpleResult("select * from ckvtable.tb_kvtable_0656 where vkey = 'ACTCOMMC_K075_100026000_plugdraw_2199'\n");
// Assert.assertEquals(freeTimes.get("int_value").toString(),"2","免费次数记录校验失败");
Assert.assertEquals(actcommcTimes.get("int_value").toString(),"2","限制次数记录校验失败");
Response doJoinResponse = activityPlugDrawInfoService.doJoinPlugdraw_false(uid,"2199");
doJoinResponse.prettyPrint();
Assert.assertEquals(MatcherString.getString(doJoinResponse.asString(),"\"success\":(.*?)}",1),"false","校验达到限制后参加活动结果失败");
Assert.assertEquals(MatcherString.getString(doJoinResponse.asString(),"\"message\":\"(.*?)\",",1),"插件剩余限制次数为0","达到限制次数校验失败");
tear1();
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void 插件限制永久2_免费1_无积分消耗测试() {
try {
tear2();
Response response = playPlugin(uid,"2206");
response.prettyPrint();
Map<String,Object> freeTimes = jdbc.findSimpleResult("select * from ckvtable.tb_kvtable_0656 where vkey = 'activity-centerjoinPlugdrawNum_100026000_plugdraw_2206'\n");
Map<String,Object> actcommcTimes = jdbc.findSimpleResult("select * from ckvtable.tb_kvtable_0656 where vkey = 'ACTCOMMC_K075_100026000_plugdraw_2206'\n");
Assert.assertEquals(freeTimes.get("int_value").toString(),"1","免费次数记录校验失败");
Assert.assertEquals(actcommcTimes.get("int_value").toString(),"1","限制次数记录校验失败");
Response doJoinResponse = activityPlugDrawInfoService.doJoinPlugdraw_false(uid,"2206");
doJoinResponse.prettyPrint();
Assert.assertEquals(MatcherString.getString(doJoinResponse.asString(),"\"success\":(.*?)}",1),"false","校验达到参加免费次数限制后参加活动结果失败");
Assert.assertEquals(MatcherString.getString(doJoinResponse.asString(),"\"message\":\"(.*?)\",",1),"永久次数已用完","免费次数用完校验失败");
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void 插件限制永久2_免费1_有积分消耗测试() {
try {
tear3();
Response response = playPlugin(uid_SubCredits,"2207");
response.prettyPrint();
Map<String,Object> freeTimes = jdbc.findSimpleResult("select * from ckvtable.tb_kvtable_0935 where vkey = 'activity-centerjoinPlugdrawNum_100060071_plugdraw_2207'\n");
Map<String,Object> actcommcTimes = jdbc.findSimpleResult("select * from ckvtable.tb_kvtable_0935 where vkey = 'ACTCOMMC_K075_100060071_plugdraw_2207'\n");
Assert.assertEquals(freeTimes.get("int_value").toString(),"1","免费次数记录校验失败");
Assert.assertEquals(actcommcTimes.get("int_value").toString(),"1","限制次数记录校验失败");
Map<String,Object> user = jdbc.findSimpleResult("select * from dafuweng.user where id=?\n",uid_SubCredits);
Map<String,Object> consumer = jdbc.findSimpleResult("select * from new_consumer.consumer_0010 where id=?\n","100060071");
Long userCredit = Long.parseLong(user.get("credits").toString());
Long consumerCredit = Long.parseLong(consumer.get("credits").toString());
Response response1 = playPlugin(uid_SubCredits,"2207");
response1.prettyPrint();
Map<String,Object> freeTimes1 = jdbc.findSimpleResult("select * from ckvtable.tb_kvtable_0935 where vkey = 'activity-centerjoinPlugdrawNum_100060071_plugdraw_2207'\n");
Map<String,Object> actcommcTimes1 = jdbc.findSimpleResult("select * from ckvtable.tb_kvtable_0935 where vkey = 'ACTCOMMC_K075_100060071_plugdraw_2207'\n");
Assert.assertEquals(freeTimes1.get("int_value").toString(),"1","免费次数记录校验失败");
Assert.assertEquals(actcommcTimes1.get("int_value").toString(),"2","限制次数记录校验失败");
Map<String,Object> user1 = jdbc.findSimpleResult("select * from dafuweng.user where id=?\n",uid_SubCredits);
Map<String,Object> consumer1 = jdbc.findSimpleResult("select * from new_consumer.consumer_0010 where id=?\n","100060071");
String userCredit1 = user1.get("credits").toString();
String consumerCredit1 = consumer1.get("credits").toString();
Assert.assertEquals(userCredit1,String.valueOf(userCredit-100),"user积分扣除校验失败");
Assert.assertEquals(consumerCredit1,String.valueOf(consumerCredit-100),"consumer积分扣除校验失败");
logger.info("校验积分消耗成功,原积分值="+userCredit+",消耗后积分值为"+userCredit1);
Response doJoinResponse = activityPlugDrawInfoService.doJoinPlugdraw_false(uid,"2207");
doJoinResponse.prettyPrint();
Assert.assertEquals(MatcherString.getString(doJoinResponse.asString(),"\"success\":(.*?)}",1),"false","校验达到限制后参加活动结果失败");
Assert.assertEquals(MatcherString.getString(doJoinResponse.asString(),"\"message\":\"(.*?)\",",1),"插件剩余限制次数为0","达到限制次数校验失败");
} catch (Exception e) {
e.printStackTrace();
}
}
public Response playPlugin(int uid, String activityId) throws Exception {
Response response = activityPlugDrawInfoService.doJoinPlugdraw(uid,activityId);
response.prettyPrint();
String orderId = response.jsonPath().getString("orderId");
response = activityPlugDrawInfoService.getOrderStatusPlugdraw(uid,orderId);
String result = String.valueOf(response.jsonPath().getString("lotteryCode"));
logger.info("lotteryCode="+result);
int i= 8;
while(i>0&&(result.equals("0"))){
Thread.sleep(1000);
response = activityPlugDrawInfoService.getOrderStatusPlugdraw(uid,orderId);
result = String.valueOf(response.jsonPath().getString("lotteryCode"));
i--;
}
response.prettyPrint();
return response;
}
public void tear1() {
try {
Boolean result1 = jdbc.update("delete from ckvtable.tb_kvtable_0656 where vkey = 'activity-centerjoinPlugdrawNum_100026000_plugdraw_2199'\n");
Boolean result2 = jdbc.update("delete from ckvtable.tb_kvtable_0656 where vkey = 'ACTCOMMC_K075_100026000_plugdraw_2199'\n");
}catch (Exception e){
e.printStackTrace();
}
}
public void tear2() {
try {
Boolean result1 = jdbc.update("delete from ckvtable.tb_kvtable_0656 where vkey = 'activity-centerjoinPlugdrawNum_100026000_plugdraw_2206'\n");
Boolean result2 = jdbc.update("delete from ckvtable.tb_kvtable_0656 where vkey = 'ACTCOMMC_K075_100026000_plugdraw_2206'\n");
}catch (Exception e){
e.printStackTrace();
}
}
public void tear3() {
try {
Boolean result1 = jdbc.update("delete from ckvtable.tb_kvtable_0935 where vkey = 'activity-centerjoinPlugdrawNum_100060071_plugdraw_2207'\n");
Boolean result2 = jdbc.update("delete from ckvtable.tb_kvtable_0935 where vkey = 'ACTCOMMC_K075_100060071_plugdraw_2207'\n");
}catch (Exception e){
e.printStackTrace();
}
}
}
\ No newline at end of file
package http.cases.PluginActivityTest;
import base.DuibaLog;
import base.DuibaTestBase;
import http.service.Activity.ActivityPlugin;
import http.service.Authorization;
import http.service.Manager.PluginService;
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.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.lang.reflect.Method;
import java.util.Map;
/**
*Created by lvwenyan on 2018/05/02.
*/
//@ContextConfiguration(classes = DuibaConfig.class)
public class 插件场景测试_pluginTest extends DuibaTestBase {
@Autowired
PluginService pluginService;
@Autowired
ActivityPlugin activityPlugin;
@Autowired
Authorization authorization;
private static DuibaLog logger = DuibaLog.getLogger();
// private MysqlUtils jdbc;
//指定用户
private static int uid = 2721;
@BeforeClass
public void before(){
// jdbc = MysqlUtils.mysqlDuiba("");
try {
jdbc.update("insert into `dafuweng`.`user` ( `enable`, `app_id`, `gmt_modified`, `gmt_create`, `credits`, `version`, `name`) values ( b'0', '57', '2018-05-23 16:43:44', '2018-05-23 16:43:44', '10000', '0', 'auto-test');");
} catch (Exception e) {
System.out.println("insert failed");
}
}
@AfterClass
public void after(){
try {
jdbc.update("DELETE FROM `dafuweng`.`user` ORDER BY id DESC LIMIT 1");
jdbc.update("DELETE FROM credits_activity.tb_activity_plugin where title = '【勿动】自动化-插件活动'");
} catch (Exception e) {
System.out.println();
}
// jdbc.releaseConn();
}
@DataProvider
public Object[][] providerMethod(Method method){
Object[][] result = null;
if(method.getName().equals("插件应用场景测试")) {
result = new Object[][]{
new Object[]{1,"","chome","插件应用场景首页"},
new Object[]{2,"307","platformCoupon","插件应用场景券库"},
new Object[]{3,"309","subpage/197","插件应用场景活动子页面"},
new Object[]{4,"310","mainMeeting/47","插件应用场景主会场"},
};
}else
if(method.getName().equals("插件触发事件测试")){
result = new Object[][]{
new Object[]{1,"0","chome","插件触发事件有效期内首次访问"},
new Object[]{2,"4","chome","插件触发事件未登录用户访问"},
};
}
return result;
}
@Test(dataProvider = "providerMethod")
public void 插件应用场景测试(int caseNum,String activityId,String url,String caseName) throws Exception {
logger.info(caseName);
Response ajaxResponse = activityPlugin.ajaxBanners(uid,url);
switch (caseNum) {
case 1:
//创建插件活动
pluginService.pluginSave();
//先定向再开启
Map<String, Object> mapId = jdbc.findSimpleResult("SELECT * FROM credits_activity.tb_activity_plugin ORDER BY gmt_create DESC LIMIT 1");
String id = String.valueOf(mapId.get("id"));
logger.info(id);
pluginService.addSpecify(id);
pluginService.changeStatus(id, "1");
int i =40;
while(!ajaxResponse.jsonPath().getString("default.activityId").equals(id) && i > 0){
Thread.sleep(3000);
ajaxResponse = activityPlugin.ajaxBanners(uid,url);
i--;
}
Assert.assertEquals(ajaxResponse.jsonPath().getString("default.activityId"), id, "校验id失败");
Assert.assertEquals(ajaxResponse.jsonPath().getString("default.appId"), "2239", "校验id失败");
logger.info("校验插件活动应用场景:首页成功");
//先关闭再删除活动
pluginService.changeStatus(id, "3");
pluginService.delete(id);
logger.info("成功删除插件活动");
break;
case 2:
Assert.assertEquals(ajaxResponse.jsonPath().getString("default.activityId"), activityId, "校验id失败");
Assert.assertEquals(ajaxResponse.jsonPath().getString("default.appId"), "2239", "校验id失败");
logger.info("校验插件活动应用场景:券库成功");
break;
case 3:
Assert.assertEquals(ajaxResponse.jsonPath().getString("default.activityId"), activityId, "校验id失败");
Assert.assertEquals(ajaxResponse.jsonPath().getString("default.appId"), "2239", "校验id失败");
logger.info("校验插件活动应用场景:活动子页面成功");
break;
case 4:
Assert.assertEquals(ajaxResponse.jsonPath().getString("default.activityId"), activityId, "校验id失败");
Assert.assertEquals(ajaxResponse.jsonPath().getString("default.appId"), "2239", "校验id失败");
logger.info("校验插件活动应用场景:主会场成功");
break;
}
}
@Test(dataProvider = "providerMethod")
public void 插件触发事件测试(int caseNum,String signType,String url,String caseName) throws Exception {
logger.info(caseName);
//获取未登录场景cookie
Response notloginResponse = authorization.autoLogin();
//创建插件活动
pluginService.pluginSave(signType);
//先定向再开启
Map<String, Object> mapId = jdbc.findSimpleResult("SELECT * FROM credits_activity.tb_activity_plugin ORDER BY gmt_create DESC LIMIT 1");
String id = String.valueOf(mapId.get("id"));
logger.info(id);
pluginService.addSpecify(id);
pluginService.changeStatus(id, "1");
switch (caseNum) {
case 1:
Response ajaxResponse = activityPlugin.ajaxBanners(uid,url);
int i =40;
while(!ajaxResponse.jsonPath().getString("default.activityId").equals(id) && i > 0){
Thread.sleep(3000);
ajaxResponse = activityPlugin.ajaxBanners(uid,url);
i--;
}
Assert.assertEquals(ajaxResponse.jsonPath().getString("default.activityId"), id, "校验activityId失败");
Assert.assertEquals(ajaxResponse.jsonPath().getString("default.appId"), "2239", "校验appId失败");
//再次访问,不会触发
ajaxResponse = activityPlugin.ajaxBanners(uid,url);
Assert.assertNotEquals(ajaxResponse.jsonPath().getString("default.activityId"),id,"校验id失败");
logger.info("校验插件活动触发事件:有效期内首次访问成功");
break;
case 2:
Response ajaxResponse2 = activityPlugin.ajaxBanners(notloginResponse.getDetailedCookies(),url);
int j = 40;
while(!ajaxResponse2.jsonPath().getString("success").equals("true") && j > 0){
Thread.sleep(3000);
ajaxResponse2 = activityPlugin.ajaxBanners(notloginResponse.getDetailedCookies(),url);
j--;
}
Assert.assertEquals(ajaxResponse2.jsonPath().getString("default.activityId"), id, "校验activityId失败");
Assert.assertEquals(ajaxResponse2.jsonPath().getString("default.appId"), "2239", "校验appId失败");
//未登录再次访问,不会触发
ajaxResponse2 = activityPlugin.ajaxBanners(notloginResponse.getDetailedCookies(),url);
Assert.assertNotEquals(ajaxResponse2.jsonPath().getString("default.activityId"),id,"校验id失败");
logger.info("校验插件活动触发事件:未登录用户访问成功");
break;
}
//先关闭再删除活动
pluginService.changeStatus(id, "3");
pluginService.delete(id);
logger.info("成功删除插件活动");
}
//@Test
public void 插件触发新人福利() throws Exception {
logger.info("插件触发事件新人福利测试");
//获取新的uid
Map<String,Object> user = jdbc.findSimpleResult("SELECT * FROM dafuweng.`user` ORDER BY id DESC LIMIT 1");
String uid = String.valueOf(user.get("id"));
Response ajaxResponse = activityPlugin.ajaxBanners(Integer.parseInt(uid),"chome");
Response statusResponse = activityPlugin.getCollectStatus(Integer.parseInt(uid),"735");
//校验新人福利弹窗
Assert.assertEquals(ajaxResponse.jsonPath().getString("default.activityId"),"721","校验activityId失败");
Assert.assertEquals(ajaxResponse.jsonPath().getString("default.appId"), "2239", "校验appId失败");
Assert.assertEquals(statusResponse.jsonPath().getString("data.popup"), "true", "校验popup失败");
Assert.assertEquals(statusResponse.jsonPath().getString("data.cardId"), "1", "校验cardId失败");
//再次请求,不会再触发
ajaxResponse = activityPlugin.ajaxBanners(Integer.parseInt(uid),"chome");
Assert.assertNotEquals(ajaxResponse.jsonPath().getString("default.activityId"),"721","校验id失败");
logger.info("校验插件活动触发事件:积分商城3.0新人福利成功");
//切换回2720用户
authorization.dafuwengLogin(2720,true);
}
}
package http.cases.PluginActivityTest;
import base.DuibaLog;
import base.DuibaTestBase;
import http.service.Activity.ActivityPlugDrawInfoService;
import http.service.Authorization;
import http.service.Manager.PluginService;
import io.restassured.response.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import static io.restassured.RestAssured.given;
/**
* Created by lvwenyan on 2018/5/29.
*/
//@ContextConfiguration(classes = DuibaConfig.class)
public class 插件工具抽奖测试_pluginTest extends DuibaTestBase {
@Autowired
ActivityPlugDrawInfoService activityPlugDrawInfoService;
@Autowired
PluginService pluginService;
@Autowired
Authorization authorization;
private static DuibaLog logger = DuibaLog.getLogger();
// private MysqlUtils jdbc;
private String url = "http://activity.m.duibatest.com.cn";
//指定用户
private static int uid = 2721;
// @BeforeClass
// public void before(){
//
// jdbc=MysqlUtils.mysqlDuiba("");
// }
//
// @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,"1100","插件出奖开心码测试"},
// new Object[]{2,"881","插件工具积分消耗"},
// new Object[]{3,"1137","插件工具免费次数使用"},
};
}
return result;
}
/**
* @param caseNum 用例编号
* @param activityId 活动Id
* @param caseName 用例名称打印
* @throws Exception
*/
@Test(dataProvider = "providerMethod")
public void 插件工具抽奖测试(int caseNum, String activityId, 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);
//积分扣除100
credits = String.valueOf(Integer.valueOf(credits)-100);
Map<String,String> map = new HashMap<>();
map.put("activityId",activityId);
map.put("token","n42agd4");
switch (caseNum){
case 1:
Response response = this.插件工具抽奖(uid,activityId);
Assert.assertEquals(response.jsonPath().getString("lottery.type"),"happyCode","校验type失败");
Assert.assertEquals(response.jsonPath().getString("lottery.title"),"开心码奖品","校验title失败");
Assert.assertEquals(response.jsonPath().getString("lottery.phaseNumber"),"18060401","校验phaseNumber当前期数失败");
logger.info("校验插件工具出奖开心码成功");
break;
case 2:
Response responseCredits = this.插件工具抽奖扣积分(uid,activityId);
//获取抽奖后的积分
mapUser = jdbc.findSimpleResult("SELECT * FROM dafuweng.`user` WHERE id = "+uid);
String creditsNew = String.valueOf(mapUser.get("credits"));
logger.info("抽奖后的用户表积分:" + creditsNew);
//获取consumer表的积分
Map<String,Object> mapConsumer = jdbc.findSimpleResult("SELECT * FROM new_consumer.consumer_0010 WHERE `app_id` = 2239 AND id = 100026000");
String creditsCon = String.valueOf(mapConsumer.get("credits"));
logger.info("consumer表用户积分" + creditsCon);
Assert.assertEquals(creditsNew,credits,"校验扣积分失败");
Assert.assertEquals(creditsCon,creditsNew,"校验积分同步失败");
logger.info("校验抽奖工具扣积分成功");
break;
case 3:
//插件工具配置免费次数永久1次,第一次成功抽奖
try{
Response responseFree = this.插件工具抽奖(uid,activityId);
Assert.assertEquals(responseFree.jsonPath().getString("lottery.type"),"alipay","校验type失败");
//再次抽奖提示次数用完
responseFree = given().cookies(authorization.dafuwengLogin(uid)).params(map).post(url+"/activityPlugDrawInfo/doJoinPlugdraw");
responseFree.prettyPrint();
Assert.assertEquals(responseFree.jsonPath().getString("message"),"永久次数已用完","校验message失败");
logger.info("校验插件工具免费次数成功");
}catch (Exception e){
System.out.println(e);
}finally {
//清除kvtable数据,可重新抽奖
jdbc.update("UPDATE ckvtable.tb_kvtable_0656 SET int_value = '0' WHERE id = '268'");
}
}
}
//活动抽奖接口传参单独抽离
public Response 插件工具抽奖(int uid,String activityId) throws Exception {
Response response = activityPlugDrawInfoService.doJoinPlugdraw(uid,activityId);
String orderId = response.jsonPath().getString("orderId");
response = activityPlugDrawInfoService.getOrderStatusPlugdraw(uid,orderId);
response.prettyPrint();
String result = String.valueOf(response.jsonPath().getString("result"));
int i= 30;
while(i>0&&(result.equals("0"))){
Thread.sleep(1000);
response = activityPlugDrawInfoService.getOrderStatusPlugdraw(uid,orderId);
result = String.valueOf(response.jsonPath().getString("result"));
i--;
}
// response.prettyPrint();
return response;
}
public Response 插件工具抽奖扣积分(int uid,String activityId) throws Exception {
Response response = activityPlugDrawInfoService.doJoinPlugdraw_credits(uid,activityId);
response.prettyPrint();
String orderId = response.jsonPath().getString("orderId");
response = activityPlugDrawInfoService.getOrderStatusPlugdraw(uid,orderId);
response.prettyPrint();
String result = String.valueOf(response.jsonPath().getString("lotteryCode"));
int i= 30;
while(i>0&&(result.equals("0"))){
Thread.sleep(1000);
response = activityPlugDrawInfoService.getOrderStatusPlugdraw(uid,orderId);
result = String.valueOf(response.jsonPath().getString("lotteryCode"));
response.prettyPrint();
i--;
}
return response;
}
}
/**
* Copyright (C), 2015-2018
* FileName: 插件抽奖工具中虚拟商品测试_pluginTest
* Author: qianwenjun
* Date: 2018/7/3 15:40
* Description:
*/
package http.cases.PluginActivityTest;
import base.DuibaLog;
import base.DuibaTestBase;
import http.service.Activity.ActivityPlugDrawInfoService;
import http.service.Authorization;
import http.service.Manager.PluginService;
import io.restassured.response.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.Assert;
import org.testng.annotations.Test;
import utils.MatcherString;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 〈〉
*
* @author qianwenjun
* @create 2018/7/3
* @since 1.0.0
*/
public class 插件抽奖工具中虚拟商品测试_pluginTest extends DuibaTestBase {
@Autowired
ActivityPlugDrawInfoService activityPlugDrawInfoService;
@Autowired
PluginService pluginService;
@Autowired
Authorization authorization;
private static DuibaLog logger = DuibaLog.getLogger();
private List<Map<String,String>> virtualOrderIds = new ArrayList<>();
//指定用户
private static int uid = 2721;
@Test
public void 插件_0积分抽奖测试() {
try {
Map<String,Object> itemStockResult = jdbc.findSimpleResult("select * from stock.tb_stock where stock_id in (select stock_id from goods.item where id = ?)\n",29069);
Long itemStock = Long.parseLong(itemStockResult.get("stock").toString());
Response response = playPlugin(uid,"1953");
response.prettyPrint();
Map<String,Object> itemStockResult1 = jdbc.findSimpleResult("select * from stock.tb_stock where stock_id in (select stock_id from goods.item where id = ?)\n",29069);
String itemStock1 = itemStockResult1.get("stock").toString();
Assert.assertEquals(MatcherString.getString(response.asString(),"\"type\":\"(.*?)\"},",1),"virtual","奖品type校验失败");
Assert.assertEquals(MatcherString.getString(response.asString(),"\"itemId\":(.*?),",1),"29069","奖品itemId校验失败");
Assert.assertEquals(itemStock1,String.valueOf(itemStock-1),"奖项库存校验失败");
Assert.assertTrue(MatcherString.getString(response.asString(),"\"link\":\"(.*?)\",",1).contains("//activity.m.duibatest.com.cn/activity/takePrizeNew?recordId="));
String orderId = "";
// for (Map<String,String> m : virtualOrderIds){
// logger.info("m="+m.keySet());
// Set<String> activityIds = m.keySet();
// for (String activityId:activityIds){
// logger.info("activityId="+activityId);
// if (activityId.equals("1953")){
// orderId = m.get("1953");
// logger.info("orderId="+orderId);
// }
// }
// }
for (Map<String,String> m : virtualOrderIds){
logger.info("m="+m.keySet());
for (Map.Entry<String,String> entry:m.entrySet()){
logger.info("entry="+entry);
if (entry.getKey().equals("1953")){
orderId = entry.getValue();
logger.info("orderId="+orderId);
}
}
}
Map<String,Object> result1 = jdbc.findSimpleResult("select * from activity_order.tb_trade_center_activity_order where order_num = ?",orderId);
Assert.assertEquals(result1.get("face_price").toString(),"qwjTest","校验游戏中奖虚拟商品主订单的标识符失败");
Assert.assertEquals(result1.get("activity_option_type").toString(),"virtual","校验游戏主订单中奖商品类型失败");
} catch (Exception e) {
e.printStackTrace();
}
}
public Response playPlugin(int uid,String activityId) throws Exception {
Response response = activityPlugDrawInfoService.doJoinPlugdraw(uid,activityId);
response.prettyPrint();
String orderId = response.jsonPath().getString("orderId");
Map<String,String> virtualOrderId = new HashMap<>();
virtualOrderId.put(activityId,orderId);
virtualOrderIds.add(virtualOrderId);
response = activityPlugDrawInfoService.getOrderStatusPlugdraw(uid,orderId);
String result = String.valueOf(response.jsonPath().getString("lotteryCode"));
int i= 30;
while(i>0&&(result.equals("0"))){
Thread.sleep(1000);
response = activityPlugDrawInfoService.getOrderStatusPlugdraw(uid,orderId);
result = String.valueOf(response.jsonPath().getString("lotteryCode"));
i--;
}
response.prettyPrint();
return response;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment