Commit 991f23ed authored by 赵然's avatar 赵然

zr

parent 5bd9f3d2
......@@ -7,59 +7,141 @@ 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.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.Map;
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 红包提现() throws Exception {
//修改账户过期时间,确保账户余额不会过期清零
jdbc.update("update consumer_account_log.tb_expire_consumer_account set gmt_modified ='"+getTime(0)+"' where account_id = '100092758_6_0'");
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;
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,"提现","数据库业务描述校验失败");
Assert.assertEquals(balance,balanceNew,"全局红包增加账户余额失败");
//获取订单创建时间
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();
String orderId = response.jsonPath().getString("orderId");
orderId = response.jsonPath().getString("orderId");
response = walletAccountService.getOrderStatus(cookies,orderId);
response.prettyPrint();
String orderStatus = String.valueOf(response.jsonPath().getString("orderStatus"));
......@@ -85,6 +167,28 @@ public class 账户正常提现 extends DuibaTestBase{
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接口失败");
......@@ -86,7 +86,7 @@ public class WalletAccountService {
Map<String,String> map = new HashMap<>();
map.put("orderId",orderId);
Response response = given().cookies(cookies).get(activityHost+"/walletAccount/getOrderStatus");
Response response = given().cookies(cookies).params(map).post(activityHost+"/walletAccount/getOrderStatus");
try{
Assert.assertEquals(response.jsonPath().getString("success"),"true","/walletAccount/getOrderStatus接口失败");
......@@ -99,4 +99,30 @@ public class WalletAccountService {
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