Commit b32a9224 authored by 赵然's avatar 赵然

Merge branch 'zr' into develop

parents d02e8686 991f23ed
package http.cases.WalletTest;
import base.DuibaTestBase;
import utils.RedisUtil;
import http.service.Activity.SeedRedPacketService;
import http.service.Activity.WalletAccountService;
import http.service.Authorization;
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.math.BigDecimal;
import java.util.List;
import java.util.Map;
/**
* Created by mabo on 2018/8/15
*/
public class 种红包_AccessTest extends DuibaTestBase{
@Autowired
SeedRedPacketService seedRedPacketService;
@Autowired
WalletAccountService walletAccountService;
@Autowired
Authorization authorization;
private DuibaLog logger = DuibaLog.getLogger();
@Test
public void 种红包() throws Exception {
//redis设置种植次数为1
RedisUtil.setKey("AC_K057_19380_1_100066444","1");
//查询数据库
Map<String,Object> map = jdbc.findSimpleResult("select * from consumer_accounts.tb_consumer_account_0140 where account_id = '100066444_6_0'");
//除以100
BigDecimal account =new BigDecimal(map.get("balance_amount").toString()).divide(new BigDecimal("100"));
//dafuweng登陆获取cookies
Map cookies = authorization.dafuwengLogin(3454);
//调用获取getWalletAccount,获取账户金额
Response response = walletAccountService.getWalletAccount(cookies);
String balanceAmount = response.jsonPath().getString("balanceAmount");
//校验,与数据对比
Assert.assertTrue(new BigDecimal(balanceAmount).compareTo(account)==0,"钱包账户异常");
//调用getLandList接口
response = seedRedPacketService.getLandList(cookies,"1","424");
String numberIsFull = response.jsonPath().getString("data.numberIsFull");
//校验可种植状态
Assert.assertEquals(numberIsFull,"false","可种植状态异常");
Thread.sleep(2000);
//调用种植seed
response = seedRedPacketService.seed(cookies,"1","424","1");
numberIsFull = response.jsonPath().getString("data.numberIsFull");
//校验可种植状态
Assert.assertEquals(numberIsFull,"false","可种植状态异常");
//种子号
String orderId = response.jsonPath().getString("data.orderNum");
Assert.assertNotNull(orderId,"订单号为空");
//生长时间
String grownNeedTime = response.jsonPath().getString("data.grownNeedTime");
Assert.assertEquals(grownNeedTime,"1","获取红包时间间隔异常");
Thread.sleep(2000);
//获取种植结果状态getOrderStatus,异步接口,while循环,status为2处理完成,1处理中
response = seedRedPacketService.getOrderStatus(cookies,orderId);
String status = response.jsonPath().getString("data");
int i =5;
while(i>0&&status.equals("1")){
response = seedRedPacketService.getOrderStatus(cookies,orderId);
status = response.jsonPath().getString("data");
i--;
}
//获取种植获得金额
response = seedRedPacketService.reap(cookies,"1",orderId);
response.prettyPrint();
String addAccount = response.jsonPath().getString("data.redPacketAmount");
//获得金额与原金额相加
BigDecimal newAccount = new BigDecimal(addAccount).add(account);
//数据库查询校验账户增加是否正常
map = jdbc.findSimpleResult("select * from consumer_accounts.tb_consumer_account_0140 where account_id = '100066444_6_0'");
account = new BigDecimal(map.get("balance_amount").toString()).divide(new BigDecimal("100"));
Assert.assertTrue(account.compareTo(newAccount)==0,"钱包账户增加异常");
}
@Test
public void 每日种红包限制() throws Exception {
RedisUtil.setKey("AC_K057_19380_1_100066444","8");
String data = RedisUtil.getKey("AC_K057_19380_1_100066444");
Map cookies = authorization.dafuwengLogin(3454);
Response response = seedRedPacketService.getLandList(cookies,"1","424");
String numberIsFull = response.jsonPath().getString("data.numberIsFull");
Assert.assertEquals(numberIsFull,"true","可种植状态异常");
response = seedRedPacketService.seed(cookies,"1","424","1");
numberIsFull = response.jsonPath().getString("data.numberIsFull");
Assert.assertEquals(numberIsFull,"true","可种植状态异常");
}
@Test
public void 解锁土地() throws Exception {
Response response = seedRedPacketService.updateUserLand("19380","1","2","100066444","2");
Map cookies = authorization.dafuwengLogin(3454);
response = seedRedPacketService.unlockLand(cookies,"1","424","2");
response = seedRedPacketService.getLandList(cookies,"1","424");
List<Map> list = response.jsonPath().getList("data.landList",Map.class);
int landStatus = (int)list.get(1).get("landStatus");
Assert.assertEquals(landStatus,3,"解锁失败");
logger.info("解锁土地成功");
}
}
package http.cases.WalletTest;
import base.DuibaTestBase;
import http.service.Activity.SeedRedPacketService;
import http.service.Activity.WalletAccountService;
import http.service.Authorization;
import base.DuibaLog;
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.BeforeClass;
import org.testng.annotations.Test;
import utils.HbaseService;
import utils.PublicMethod;
import java.text.SimpleDateFormat;
import java.util.*;
import static io.restassured.RestAssured.given;
/**
* Created by mabo on 2018/8/15
*/
public class 账户正常提现 extends DuibaTestBase{
@Value("${activity.host}")
String activityHost;
@Autowired
SeedRedPacketService seedRedPacketService;
@Autowired
WalletAccountService walletAccountService;
@Autowired
Authorization authorization;
@Autowired
HbaseService hbaseService;
private DuibaLog logger = DuibaLog.getLogger();
//指定用户
private static int uid = 4244;
private static String consumerId = "100092758";
private static String orderId;
@AfterClass
public void afterclass() {
try {
//修改红包提现用户登录天数
String y_m = getTime2(0);
String key = "k01_AAWH_K003_"+y_m+"_"+consumerId;
hbaseService.updateHBASEKey(key,"","1");
// Thread.sleep(300000);
//修改账户过期时间,确保账户余额不会过期清零
jdbc.update("update consumer_account_log.tb_expire_consumer_account set gmt_modified ='"+getTime(0)+"' where account_id = '"+consumerId+"_6_0'");
} catch (Exception e) {
logger.info("数据后面置操作异常");
}
}
@Test
public void a_正常提现() throws Exception {
//获取原账户余额
Map<String, Object> selectResult = jdbc.findSimpleResult("select * from consumer_accounts.tb_consumer_account_0854 where account_id = '100092758_6_0' ");
int balance = Integer.parseInt(String.valueOf(selectResult.get("balance_amount")));
logger.info("账户原有余额为"+balance);
balance = balance - 1;
//账户支付宝提现
Map cookies = authorization.dafuwengLogin(uid);
this.账户提现(cookies,"peeulk6392@sandbox.com","沙箱环境");
Thread.sleep(2000);
//获取新账户余额
selectResult = jdbc.findSimpleResult("select * from consumer_accounts.tb_consumer_account_0854 where account_id = '100092758_6_0' ");
int balanceNew = Integer.parseInt(String.valueOf(selectResult.get("balance_amount")));
logger.info("账户新余额为"+balanceNew);
Assert.assertEquals(balanceNew,balance,"全局红包增加账户余额失败");
logger.info("用户账户余额校验成功");
}
@Test
public void b_余额明细校验() throws Exception {
//获取原账户余额
Map<String, Object> selectResult = jdbc.findSimpleResult("select * from consumer_account_log.tb_consumer_accounts_log where biz_id ="+orderId);
String change_money = String.valueOf(selectResult.get("change_money"));
String action_type = String.valueOf(selectResult.get("action_type"));
String sub_type = String.valueOf(selectResult.get("sub_type"));
String biz_description = String.valueOf(selectResult.get("biz_description"));
Assert.assertEquals(change_money,"1","数据库扣款金额校验失败");
Assert.assertEquals(action_type,"0","数据库账户动作校验失败");
Assert.assertEquals(sub_type,"0","数据库日志类型校验失败");
Assert.assertEquals(biz_description,"提现","数据库业务描述校验失败");
//获取订单创建时间
String gmt_create = String.valueOf(selectResult.get("gmt_create"));
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = fmt.parse(gmt_create); //将从数据库读出来的 timestamp 类型的时间转换为java的Date类型
//String gmt_create_data = fmt.format(date); //将这个时间格式化,转换为String类型
String gmt_create_data = getTime3(date,-14);
logger.info("数据库订单创建时间为:"+gmt_create_data);
//获取最新的提现记录
Map cookies = authorization.dafuwengLogin(uid);
Response response = walletAccountService.walletDetail(cookies);
String gmtCreate = response.jsonPath().getString("data[0].gmtCreate");
String money = response.jsonPath().getString("data[0].money");
String subType = response.jsonPath().getString("data[0].subType");
Assert.assertEquals(money,"0.01","扣款金额校验失败");
Assert.assertEquals(subType,"0","日志类型校验失败");
Assert.assertEquals( PublicMethod.stampToDate(gmtCreate),gmt_create_data,"订单生成时间校验失败");
logger.info("订单列表提现记录校验成功");
}
@Test
public void c_提现失败_登录次数不足() throws Exception {
//获取原账户余额
Map<String, Object> selectResult = jdbc.findSimpleResult("select * from consumer_accounts.tb_consumer_account_0854 where account_id = '100092758_6_0' ");
int balance = Integer.parseInt(String.valueOf(selectResult.get("balance_amount")));
logger.info("账户原有余额为"+balance);
//账户支付宝提现
logger.info("请求doTakePrize");
Map<String,String> map = new HashMap<>();
map.put("alipay","peeulk6392@sandbox.com");
map.put("realname","沙箱环境");
Response response = given().contentType("application/x-www-form-urlencoded;charset=UTF-8").cookies(authorization.dafuwengLogin(uid)).params(map).post(activityHost+"/walletAccount/doTakePrize");
Assert.assertEquals(response.jsonPath().getString("success"),"false","/walletAccount/doTakePrize接口失败");
Assert.assertEquals(response.jsonPath().getString("message"),"连续登录天数不足","/walletAccount/doTakePrize接口失败");
//获取新账户余额
selectResult = jdbc.findSimpleResult("select * from consumer_accounts.tb_consumer_account_0854 where account_id = '100092758_6_0' ");
int balanceNew = Integer.parseInt(String.valueOf(selectResult.get("balance_amount")));
logger.info("账户新余额为"+balanceNew);
Assert.assertEquals(balanceNew,balance,"全局红包增加账户余额失败");
logger.info("用户账户余额校验成功");
}
public void 账户提现(Map cookies,String alipay,String realname) throws Exception {
Response response = walletAccountService.doTakePrize(cookies,alipay,realname);
response.prettyPrint();
orderId = response.jsonPath().getString("orderId");
response = walletAccountService.getOrderStatus(cookies,orderId);
response.prettyPrint();
String orderStatus = String.valueOf(response.jsonPath().getString("orderStatus"));
int i= 30;
while(i>0&&(orderStatus.equals("0"))){
Thread.sleep(1000);
response = walletAccountService.getOrderStatus(cookies,orderId);
orderStatus = String.valueOf(response.jsonPath().getString("orderStatus"));
i--;
response.prettyPrint();
}
}
// 获取时间方法
public String getTime(int amount){
SimpleDateFormat dateFormat = new SimpleDateFormat("YYYY-MM-dd", Locale.ENGLISH);
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DAY_OF_MONTH, amount);
date = calendar.getTime();
// System.out.println(dateFormat.format(date));
String time = dateFormat.format(date)+" 08:00:00";
// System.out.println(time);
return time;
}
public String getTime2(int amount){
SimpleDateFormat dateFormat = new SimpleDateFormat("YYYY-MM", Locale.ENGLISH);
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DAY_OF_MONTH, amount);
date = calendar.getTime();
// System.out.println(dateFormat.format(date));
String time = dateFormat.format(date);
// System.out.println(time);
return time;
}
public String getTime3( Date date ,int amount){
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH);
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.HOUR_OF_DAY, amount);
date = calendar.getTime();
String time = dateFormat.format(date);
return time;
}
}
......@@ -58,9 +58,9 @@ public class WalletAccountService {
public Response doTakePrize(Map cookies,String alipay,String realname) throws Exception {
logger.info("请求doTakePrize");
Map<String,String> map = new HashMap<>();
map.put("alipay","peeulk6392@sandbox.com");
map.put("realname","沙箱环境");
Response response = given().cookies(cookies).get(activityHost+"/walletAccount/doTakePrize");
map.put("alipay",alipay);
map.put("realname",realname);
Response response = given().contentType("application/x-www-form-urlencoded;charset=UTF-8").cookies(cookies).params(map).post(activityHost+"/walletAccount/doTakePrize");
try{
Assert.assertEquals(response.jsonPath().getString("success"),"true","/walletAccount/doTakePrize接口失败");
......@@ -73,4 +73,56 @@ public class WalletAccountService {
return response;
}
/**
* 红包账户提现
* @param cookies
* @param orderId
* @return
* @throws Exception
*/
public Response getOrderStatus(Map cookies,String orderId) throws Exception {
logger.info("请求getOrderStatus");
Map<String,String> map = new HashMap<>();
map.put("orderId",orderId);
Response response = given().cookies(cookies).params(map).post(activityHost+"/walletAccount/getOrderStatus");
try{
Assert.assertEquals(response.jsonPath().getString("success"),"true","/walletAccount/getOrderStatus接口失败");
}catch(Exception e){
throw new Exception("/walletAccount/getOrderStatus接口失败,返回信息:"+response.asString());
}catch(Error er){
throw new Exception("/walletAccount/getOrderStatus接口失败,返回信息:"+response.asString());
}
return response;
}
/**
* 红包账户提现记录
* @param cookies
* @return
* @throws Exception
*/
public Response walletDetail(Map cookies) throws Exception {
logger.info("请求walletDetail");
Map<String,String> map = new HashMap<>();
map.put("pageNo","1");
map.put("pageSize","12");
Response response = given().cookies(cookies).params(map).get(activityHost+"/walletAccount/walletDetail");
try{
Assert.assertEquals(response.jsonPath().getString("success"),"true","/walletAccount/walletDetail接口失败");
}catch(Exception e){
throw new Exception("/walletAccount/walletDetail接口失败,返回信息:"+response.asString());
}catch(Error er){
throw new Exception("/walletAccount/walletDetail接口失败,返回信息:"+response.asString());
}
return response;
}
}
......@@ -12,6 +12,7 @@ import io.restassured.response.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.testng.Assert;
import java.util.HashMap;
import java.util.Map;
......@@ -48,6 +49,18 @@ public class HbaseService {
}
public Response getHBASEKey2(String key) {
String url = activtyHost + "/aaw/hb/get";
Map<String,Object> parm = new HashMap<>();
parm.put("key",key);
Response response = given().params(parm).get(url);
return response;
}
public void deleteHBASEKey(String key) {
......@@ -63,5 +76,40 @@ public class HbaseService {
}
public Response deleteHBASEKey2(String key) throws Exception {
String url = activtyHost + "/aaw/hb/delete";
Map<String,Object> parm = new HashMap<>();
parm.put("key",key);
Response response = given().params(parm).get(url);
// response.prettyPrint();
try {
Assert.assertEquals(response.jsonPath().getString("data"), "删除完毕");
} catch (Exception e) {
throw new Exception("/aaw/hb/delete接口失败,返回信息:" + response.asString());
} catch (Error er) {
throw new Exception("/aaw/hb/delete接口失败,返回信息:" + response.asString());
}
return response;
}
public void updateHBASEKey(String key,String svalue,String lvalue) {
String url = activtyHost + "/aaw/hb/update";
Map<String,Object> parm = new HashMap<>();
parm.put("key",key);
if(!svalue.equals("")) {
parm.put("svalue", svalue);
}
if(!lvalue.equals("")) {
parm.put("lvalue", lvalue);
}
Response response = given().params(parm).get(url);
// response.prettyPrint();
// return response;
}
}
\ No newline at end of file
package utils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
/**
* Created by zhaoran on 2018/4/10.
......@@ -18,4 +21,48 @@ public class PublicMethod {
String date = df.format(new Date());// new Date()为获取当前系统时间,也可使用当前时间戳
return date;
}
/**
* 将时间转换为时间戳
*/
public static String dateToStamp(String s) throws ParseException {
String res;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = simpleDateFormat.parse(s);
long ts = date.getTime();
res = String.valueOf(ts);
return res;
}
/**
* 将时间戳转换为时间
*/
public static String stampToDate(String s){
String res;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long lt = new Long(s);
Date date = new Date(lt);
res = simpleDateFormat.format(date);
return res;
}
/**
* Date类型向前向后滚动固定时长
*
* @param date
* 调整前的时间对象
* @param i
* 需要滚动哪一个字段,写法: 年->Calendar.YEAR 月->Calendar.MONTH
* 日->Calendar.DATE 时->Calendar.HOUR_OF_DAY(24小时制)
* 分->Calendar.MINUTE 秒->Calendar.SECOND 毫秒->Calendar.MILLISECOND
* @param d
* 滚动多少,向前(以前)就用负数,向后(未来)就用正数
*/
public static Date DateRoll(Date date,int i,int d){
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(i, d);
date = calendar.getTime();
return date;
}
}
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